code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
# 入力
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
# ライブラリ
import itertools
l = [i+1 for i in range(n)]
perms = itertools.permutations(l, n)
# 処理
a = 0
b = 0
for i, perm in enumerate(perms):
perm = list(perm)
if perm == p:
a = i
if perm == q:
b = i
import numpy as np
print(np.abs(a-b))
|
import itertools
n = int(input())
s = ""
for i in range(n):
s += str(i+1)
l = list(itertools.permutations(s, n))
p = tuple(input().split())
q = tuple(input().split())
a = l.index(p)
b = l.index(q)
print(abs(a-b))
| 1 | 100,679,386,023,208 | null | 246 | 246 |
S, T = input().split()
A, B = list(map(int, input().split()))
U = input()
if S == U:
print("{} {}".format(A - 1, B))
else:
print("{} {}".format(A, B - 1))
|
def main():
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 0
L = 100
for l in range(L):
one = 0
zero = 0
for a in A:
if (a & (1<<(L - l - 1))):
one += 1
else:
zero += 1
ans += (one * zero) * 2 ** (L - l - 1)
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 97,899,133,320,242 | 220 | 263 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
x = inp()
if x < 600:
ans = 8
elif x < 800:
ans = 7
elif x < 1000:
ans = 6
elif x < 1200:
ans = 5
elif x < 1400:
ans = 4
elif x < 1600:
ans = 3
elif x < 1800:
ans = 2
elif x < 2000:
ans = 1
print(ans)
|
n = int(input())
a = 8 - ( (n -400) // 200)
print (a)
| 1 | 6,747,987,133,800 | null | 100 | 100 |
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(input())-1])
|
w = str.lower(raw_input())
t = []
while True:
line = raw_input()
if line == "END_OF_TEXT":
break
else:
t += (map(str.lower, line.split(" ")))
count = 0
for i in xrange(len(t)):
if w == t[i]:
count += 1
print count
| 0 | null | 26,022,806,902,972 | 195 | 65 |
N = int(input())
X = input()
val = int(X,2)
C = X.count("1")
if C==1:
for i in range(N):
if X[i]=='1':
print(0)
elif i==N-1:
print(2)
else:
print(1)
exit()
# xをpopcountで割ったあまりに置き換える
def f(x):
if x==0: return 0
return 1 + f(x % bin(x).count("1"))
# 初回のpopcountでの割り方は、(C+1) or (C-1)
Y = val%(C+1)
if C-1 != 0:
Z = val%(C-1)
else:
Z = 0
for i in range(N):
if X[i] == "1":
if Z - 1 == 0:
print(0)
continue
k = (Z - pow(2,N-i-1,C-1)) % (C-1)
else:
k = (Y + pow(2,N-i-1,C+1)) % (C+1)
print(f(k)+1)
|
list =input().split()
list = [int(i) for i in list]
D=list[0]
S=list[1]
T=list[2]
if(D/S<=T):
print("Yes")
else:
print("No")
| 0 | null | 5,961,793,924,040 | 107 | 81 |
x = int(input())
for i in range(2,10):
if i <= x/200 < i+1:
print(10-i)
|
N, = map(int, input().split())
print(10-N//200)
| 1 | 6,699,739,592,700 | null | 100 | 100 |
import itertools
N = int(input())
L = []
for i in range(N):
x,y = map(int,input().split())
L.append([x,y])
cnt = 0
total = 0
for v in itertools.permutations(L):
for i in range(N-1):
x_1 = v[i][0]
y_1 = v[i][1]
x_2 = v[i+1][0]
y_2 = v[i+1][1]
total += ((x_2 - x_1) ** 2 + (y_2 - y_1) ** 2) ** 0.5
cnt += 1
print(total/cnt)
|
import numpy as np
from itertools import combinations
from itertools import permutations
from math import factorial
N = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in xy:
for j in xy:
cnt += np.linalg.norm(i - j)
print(cnt / N)
| 1 | 147,779,487,650,700 | null | 280 | 280 |
#176-B
N = input()
sum = 0
for i in range(1,len(N)+1):
sum += int(N[-i])
if int(sum) % 9 == 0:
print('Yes')
else:
print('No')
|
N = input()
tmp = 0
for s in N:
tmp += int(s)
if tmp%9 == 0:
print("Yes")
else:
print("No")
| 1 | 4,386,409,722,190 | null | 87 | 87 |
H1, M1, H2, M2, K = map(int, input().split())
getUpTime = H1 * 60 + M1
goToBed = H2 * 60 + M2
DisposableTime = goToBed - getUpTime
if K > DisposableTime:
print(0)
else:
print(DisposableTime - K)
|
string = input()
height = 0
height_list = [[0, False]]
for s in string:
if s == '\\':
height += -1
elif s == '/':
height += 1
else:
pass
height_list.append([height, False])
highest = 0
for i in range(1, len(height_list)):
if height_list[i-1][0] < height_list[i][0] <= highest:
height_list[i][1] = True
highest = max(highest, height_list[i][0])
puddles = []
area = 0
surface_level = None
for i in range(len(height_list)-1, -1, -1):
if surface_level != None:
area += surface_level - height_list[i][0]
if surface_level == height_list[i][0]:
puddles += [area]
surface_level = None
area = 0
if surface_level == None and height_list[i][1]:
surface_level = height_list[i][0]
puddles = puddles[::-1]
print(sum(puddles))
print(len(puddles), *puddles)
| 0 | null | 9,070,329,233,602 | 139 | 21 |
S=input()
T=input()
Slen=len(S)
Tlen=len(T)
ans=5000
for i in range(0,Slen-Tlen+1):
tans=0
for j in range(0,Tlen):
if S[i+j]!=T[j]:
tans+=1
if tans<ans:
ans=tans
print(ans)
|
N,K=map(int,input().split())
A=list(map(lambda x:int(x)%K,input().split()))
cum=[0]*(N+1)
for i in range(N):
cum[i+1]=(cum[i]+A[i])
x=[(cum[i]-i)%K for i in range(N+1)]
dic={}
ans=0
for i in range(N+1):
if i>=K:
dic[x[i-K]]-=1
ans+=dic.get(x[i],0)
if not x[i] in dic:
dic[x[i]]=1
else:
dic[x[i]]+=1
print(ans)
| 0 | null | 70,851,645,655,580 | 82 | 273 |
n = int(input())
s,t = input().split()
ans = ''
for i in range(n):
ans += s[i]
ans += t[i]
print(ans)
|
N = int(input())
S, T = list(map(str, input().split()))
A = ''
for i in range(N):
A += S[i]
A += T[i]
print(A)
| 1 | 112,359,409,369,830 | null | 255 | 255 |
import sys,collections as cl,bisect as bs
Max = 10**18
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def wa(d):
for k in range(len(d)):
for i in range(len(d)):
for j in range(len(d)):
d[i][j] = min(d[i][j],d[i][k]+d[k][j])
return d
def on():
N,M,L = m()
e = [[Max for i in range(N)]for j in range(N)]
for i in range(M):
a,b,c = m()
e[a-1][b-1] = c
e[b-1][a-1] = c
for i in range(N):
e[i][i] = 0
d = wa(e)
E = [[Max for i in range(N)]for j in range(N)]
for i in range(N):
for j in range(N):
if d[i][j] <= L:
E[i][j] = 1
for i in range(N):
E[i][i] = 0
E = wa(E)
q = onem()
for i in range(q):
s,t = m()
if E[s-1][t-1] == Max:
print(-1)
else:
print(E[s-1][t-1]-1)
if __name__ == "__main__":
on()
|
A, B = map(int, input().split())
for i in range(1, A+1):
if B*i % A == 0:
print(B*i)
break
| 0 | null | 143,549,601,514,240 | 295 | 256 |
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
import numpy as np
ans=0
dp=np.zeros(t,np.int64)
# dp[i]:時間合計i以内に食べれる料理のおいしさ総和の最大
for i in range(n):
a,b=ab[i]
ans=max(ans,dp[-1]+b)
dp[a:]=np.maximum(dp[a:],dp[:-a]+b)
print(ans)
|
n,t=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]
ab.sort()
dp=[(6007)*[0]for _ in range(n+1)]
dp[0][0]=0
ans=0
for i in range(n):
for j in range(6007):
dp[i+1][j]=max(dp[i+1][j],dp[i][j])
if j<t:dp[i+1][j+ab[i][0]]=max(dp[i][j]+ab[i][1],dp[i][j+ab[i][0]])
ans=max(ans,dp[i+1][j])
print(ans)
| 1 | 152,282,925,209,708 | null | 282 | 282 |
class SwappingTwoNumbers:
def output(self, n):
n.sort()
print "%d %d" % (n[0], n[1])
if __name__ == "__main__":
stn = SwappingTwoNumbers();
while True:
n = map(int, raw_input().split())
if n[0] == 0 and n[1] == 0:
break
stn.output(n)
|
n, m = map(int, input().split())
ans = 0
if n >= 2: ans += n * (n - 1) / 2
if m >= 2: ans += m * (m - 1) / 2
print(int(ans))
| 0 | null | 22,925,736,837,290 | 43 | 189 |
S,H,C,D = set(),set(),set(),set()
W = set([1,2,3,4,5,6,7,8,9,10,11,12,13])
n = int(input())
for i in range(n):
N = input().split()
if N[0] == 'S':
S.add(int(N[1]))
elif N[0] == 'H':
H.add(int(N[1]))
elif N[0] == 'C':
C.add(int(N[1]))
elif N[0] == 'D':
D.add(int(N[1]))
s,h,c,d = [],[],[],[]
st = W - S
while st != set():
s.append(st.pop())
s.sort()
ht = W - H
ct = W - C
dt = W - D
while ht != set():
h.append(ht.pop())
h.sort()
while ct != set():
c.append(ct.pop())
c.sort()
while dt != set():
d.append(dt.pop())
d.sort()
for i in s:
print('S {0}'.format(i))
for i in h:
print('H {0}'.format(i))
for i in c:
print('C {0}'.format(i))
for i in d:
print('D {0}'.format(i))
|
import sys
from copy import copy
def main():
length = int(sys.stdin.readline())
given_cards = []
for i in range(length):
given_cards.append(sys.stdin.readline().strip())
cards = []
for i in ('S ', 'H ', 'C ', 'D '):
for j in range(13):
cards.append(i + str(j + 1))
for card in copy(cards):
if card in given_cards:
del cards[cards.index(card)]
for card in cards:
print(card)
return
if __name__ == '__main__':
main()
| 1 | 1,049,077,417,970 | null | 54 | 54 |
from sys import stdin
import math
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(stdin.readline().rstrip())
print(l[k-1])
|
a, b, c = map(int, raw_input().split())
count = 0
for i in range(a, b + 1):
if c % i == 0:
count = count + 1
print '%s' % str(count)
| 0 | null | 25,318,225,105,090 | 195 | 44 |
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
lst=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(lst[k-1])
|
import math
a, b = list(map(int, input().split()))
c = math.gcd(a, b)
d = a * b / c
d = math.floor(d)
print(d)
| 0 | null | 81,388,103,038,440 | 195 | 256 |
import sys
n=int(input())
s=[input() for i in range(n)]
t=[2*(i.count("("))-len(i) for i in s]
if sum(t)!=0:
print("No")
sys.exit()
st=[[t[i]] for i in range(n)]
for i in range(n):
now,mi=0,0
for j in s[i]:
if j=="(":
now+=1
else:
now-=1
mi=min(mi,now)
st[i].append(mi)
#st.sort(reverse=True,key=lambda z:z[1])
u,v,w=list(filter(lambda x:x[1]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st))
v.sort(reverse=True)
v.sort(reverse=True,key=lambda z:z[1])
w.sort(key=lambda z:z[0]-z[1],reverse=True)
lu=len(u)
lv=len(v)
now2=0
for i in range(n):
if i<lu:
now2+=u[i][0]
elif i<lu+lv:
if now2+v[i-lu][1]<0:
print("No")
break
now2+=v[i-lu][0]
else:
#いや、間違ってるのここなんかーーい
if now2+w[i-lu-lv][1]<0:
print("No")
break
now2+=w[i-lu-lv][0]
else:
print("Yes")
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
s = [input() for _ in range(n)]
x = [] #(の方が多いもの
y = [] #)の方が多いもの
for i in range(n):
cnt1 = 0
cnt2 = 0
for j in range(len(s[i])):
if s[i][j] == '(':
cnt1 += 1
else:
cnt2 += 1
if cnt1 - cnt2 > 0:
x.append([cnt2, cnt1, s[i]])
else:
y.append([cnt1, cnt2, s[i]])
x.sort() #)が少ない順
y.sort(reverse=True) #(が多い順
tmp = 0
que = deque()
for i, j, k in x:
for l in k:
if l == '(':
tmp += 1
else:
if tmp > 0:
tmp -= 1
else:
print('No')
quit()
for i, j, k in y:
for l in k:
if l == '(':
tmp += 1
else:
if tmp > 0:
tmp -= 1
else:
print('No')
quit()
if tmp != 0:
print('No')
else:
print('Yes')
| 1 | 23,652,179,743,012 | null | 152 | 152 |
l = input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
d = []
for i in range(a,b+1):
if c % i == 0:
d.append(i)
print(len(d))
|
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
n=int(input())
ar=lis()
temp=[0]*(n+5)
for i in range(n-1):
#print(ar[i],temp)
temp[ar[i]]+=1
for i in range(1,n+1):
print(temp[i])
| 0 | null | 16,640,091,266,680 | 44 | 169 |
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a_sum = [0 for i in range(N+1)]
for i in range(N):
a_sum[i+1] = a_sum[i] + A[i]
b_sum = [0 for i in range(M+1)]
for i in range(M):
b_sum[i+1] = b_sum[i] + B[i]
ans = 0
for i in range(N+1):
t = a_sum[i]
l = 0
r = len(b_sum)
while(l+1<r):
c = (l+r)//2
if t+b_sum[c]<=K:
l = c
else:
r = c
if a_sum[i]+b_sum[l]<=K:
ans = max(ans,i+l)
print(ans)
|
while True:
H, W = [int(x) for x in input().split()]
if H == W == 0:
break
for i in range(H):
cnt = i % 2
for j in range(W):
if (cnt % 2) == 0:
print('#', end="")
else:
print('.', end="")
cnt += 1
print()
print()
| 0 | null | 5,759,825,823,968 | 117 | 51 |
'''
ITP-1_9-B
?????£?????????
???????????¢????????????????????????????????? n ???????????????????±±????????£?????????????????????
1???????????£???????????§??????????????? h ???????????????????????¨???????????????????????????????????£????????????????±±??????????????????????????????
?????????????±±?????\???????????????????????????????????§?????????????????????
abcdeefab
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????°???????????? h ??? 4 ??§?????£?????????????????¨????????????4?????? abcd ????????????????????? eefab ???????°??????£?????????????????§??\??????????????????????????????
eefababcd
???????????£???????????????????????°??????????????????
?????????????±±???????????????????????????????????¨ h ????????????????????????????????????????????????????????????????????????????????°?????????????????????????????????
Constraints
?????????????????????200????¶??????????
?????£?????????????????°???100????¶??????????
???Input
?????°??????????????????????????\?????¨?????????????????????????????????????????????????????\????????¢?????§?????????????????????
????????????????????¨????????????
?????£??????????????° m
h1
h2
.
.
hm
????????????????????¨??????????????? "-" ?????¨?????\?????????????????¨????????????
???Output
??????????????????????????????????????????????????????????????????????????????????????????????????????
'''
while(True):
# inputData
cards = input()
# endCheck
if cards == '-':
break
# shuffleCnt
shufflCnt = int(input())
for i in range(shufflCnt):
# shuffleData
shuffleData = int(input())
cards = cards[shuffleData:] + cards[0:shuffleData]
# outputData
print(cards)
|
from collections import deque
while True:
s = input()
if s == '-': break
else: ds = deque(s)
ds.rotate(sum([int(input()) for _ in range(int(input()))])*-1)
print(''.join(ds))
| 1 | 1,916,007,031,392 | null | 66 | 66 |
h= []
w= []
while True:
a,b= map(int,input().split())
if(not (a==0 or b==0)):
h.append(a)
w.append(b)
elif(a==b==0):
break
n= 0
for e in h:
c= 0
for f in range(e):
if(w[n]%2==0):
if(c== 0):
print('#.'*(w[n]//2))
c= 1
else:
print('.#'*(w[n]//2))
c= 0
else:
if(c== 0):
print('#.'*(w[n]//2)+'#')
c= 1
else:
print('.#'*(w[n]//2)+'.')
c= 0
print()
n+= 1
|
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n,a,b=map(int, input().split())
if (abs(a-b))%2==0:
print((abs(a-b))//2)
else:
ue=max(a,b)-1
sita=n-min(a,b)
hokasita=((n-max(a,b))*2+1+abs(b-a))//2
hokaue=(((min(a,b))-1)*2+1+abs(b-a))//2
print(min(ue,sita,hokasita,hokaue))
resolve()
| 0 | null | 55,280,542,859,360 | 51 | 253 |
import itertools,numpy as np,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = LI()
sum_A = sum(A)
accumulate_A = np.array(list(itertools.accumulate(A)))
sub_A1 = sum_A-accumulate_A
sub_A2 = sum_A-sub_A1
print(np.abs(sub_A1-sub_A2).min())
|
N=int(input())
#m1,d1=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
S=list(input())
d=list('0123456789')
ans=0
for d1 in d:
for d2 in d:
for d3 in d:
v=d1+d2+d3
i=0
p=0
while i < N :
if v[p]==S[i]:
p+=1
if p == 3:
break
i+=1
if p==3 :
ans+=1
print(ans)
| 0 | null | 134,739,240,833,636 | 276 | 267 |
N = int(input())
from math import sin, cos, pi
th = pi/3
def koch(d, p1, p2):
if d == 0:
return
s = [0, 0]
t = [0, 0]
u = [0, 0]
s[0] = (2 * p1[0] + p2[0])/3
s[1] = (2 * p1[1] + p2[1])/3
t[0] = (2 * p2[0] + p1[0])/3
t[1] = (2 * p2[1] + p1[1])/3
u[0] = (t[0] - s[0]) * cos(th) - (t[1] - s[1]) * sin(th) + s[0]
u[1] = (t[0] - s[0]) * sin(th) + (t[1] - s[1]) * cos(th) + s[1]
koch(d-1, p1, s)
print(*s)
koch(d-1, s, u)
print(*u)
koch(d-1, u, t)
print(*t)
koch(d-1, t, p2)
p_start = [0.0, 0.0]
p_end = [100.0, 0.0]
print(*p_start)
koch(N, p_start, p_end)
print(*p_end)
|
# coding: utf-8
import math
n = int(raw_input())
def vector_rot(vector, radian):
new_x = vector[0] * math.cos(radian) - vector[1] * math.sin(radian)
new_y = vector[0] * math.sin(radian) + vector[1] * math.cos(radian)
return [new_x, new_y]
def vector_add(v1, v2):
new_v = []
for i in range(2):
add = v1[i] + v2[i]
new_v.append(add)
return new_v
def makepoint(p_A1, p_A2):
x_p_C1 = (p_A2[0] - p_A1[0]) / 3 + p_A1[0]
y_p_C1 = (p_A2[1] - p_A1[1]) / 3 + p_A1[1]
x_p_C3 = (p_A2[0] - p_A1[0]) * 2 / 3 + p_A1[0]
y_p_C3 = (p_A2[1] - p_A1[1]) * 2 / 3 + p_A1[1]
p_C1 = [x_p_C1, y_p_C1]
p_C3 = [x_p_C3, y_p_C3]
v01 = [x_p_C1 - p_A1[0], y_p_C1 - p_A1[1]]
rot_v01 = vector_rot(v01, 60 * math.pi / 180)
v02 = vector_add(v01, rot_v01)
p_C2 = vector_add(p_A1, v02)
C = [p_C1, p_C2, p_C3]
return C
A = [[0., 0.],[100., 0.]]
for i in range(n):
B = []
for j in range(len(A)-1): #A[j]??¨A[j+1]
C = makepoint(A[j], A[j+1]) #C = [p_C1, p_C2, p_C3]
B.append(A[j])
for p in C:
B.append(p)
#A[j+1]????¬????makepoint?????????append??????
B.append(A[-1]) #??????????????\?????\??????
A = B
for x in A:
print("{:.8f}".format(x[0])),
print("{:.8f}".format(x[1]))
| 1 | 129,010,806,730 | null | 27 | 27 |
#import numpy as np
from copy import deepcopy
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))
N = int(input())
#AB = [list(map(int, input().split())) for _ in range(N-1)]
edge = [[] for i in range(N)]
seen = [0]*N
colors = [0]*(N-1)
#for val in AB:
for i in range(N-1):
x, y = list(map(int, input().split()))
edge[x-1].append((i, y-1))
edge[y-1].append((i, x-1))
lenedge = [len(val) for val in edge]
mledge = max(lenedge)
root = lenedge.index(mledge)
print(mledge)
que = deque()
que.append([(root, -1)])
while que[0]:
nque = []
cque = que.popleft()
#print('cstack:', cstack)
for tupl in cque:
index, pcolor = tupl
seen[index] = 1
color = 1
if (color == pcolor): color += 1
for tupl2 in edge[index]:
findex, edgei = tupl2
if seen[edgei] == 0:
nque.append((edgei, color))
colors[findex] = color
color += 1
if (color == pcolor): color += 1
que.append(nque)
#pri(color)
for color in colors:
print(color)
|
N = int(input())
ans = [0] * (N-1)
to = [[] for i in range(N-1)]
used = [0] * N
for i in range(N-1):
a, b = map(int, input().split())
to[a-1].append([b-1, i])
for i in range(N-1):
unable = used[i]
c = 1
for j, id in to[i]:
if c == unable:
c += 1
ans[id] = c
used[j] = c
c += 1
print(max(used))
for i in range(N-1):
print(ans[i])
| 1 | 135,869,966,502,458 | null | 272 | 272 |
n=str(input())
a=list(n)
b=0
for i in a:
b=b+int(i)
if b%9==0:
print("Yes")
else:
print("No")
|
N = list(map(int, input().split()))
if sum(N) % 9: print('No')
else: print('Yes')
| 1 | 4,378,442,477,540 | null | 87 | 87 |
midScore =[0]*50
finScore = [0]*50
reScore = [0]*50
personNum = 0
while True:
m,f,r = map(int,input().split())
midScore[personNum] = m
finScore[personNum] = f
reScore[personNum] = r
personNum += 1
if m is f is r is -1:
break
for person in range(personNum):
totalScore = midScore[person] + finScore[person]
if midScore[person] is finScore[person] is reScore[person] is -1:
pass
elif midScore[person] == -1 or finScore[person] == -1:
print("F")
elif 80<=totalScore:
print("A")
elif 65<=totalScore<80:
print("B")
elif 50<=totalScore<65:
print("C")
elif 30<=totalScore<50:
if 50<=reScore[person]:
print("C")
else:
print("D")
elif totalScore<30:
print("F")
|
while True:
m, f, r = list(map(int, input().split()))
if m == -1 and f == -1 and r == -1:
break
if (m == -1 or f == -1) or m+f < 30:
print('F')
elif 80 <= m+f:
print('A')
elif 65 <= m+f < 80:
print('B')
elif (50 <= m+f <65) or (30 <= m+f <50 and 50 <= r):
print('C')
elif 30 <= m+f <50:
print('D')
| 1 | 1,228,006,316,670 | null | 57 | 57 |
N = int(input())
S = input()
tmp = S[0]
ans = 1
for n in range(1,N):
if S[n] != tmp:
ans += 1
tmp = S[n]
print(ans)
|
N = int(input())
S = input()
ans = 1
for i in range(N-1):
if(S[i] != S[i+1]):
ans += 1
print(ans)
| 1 | 170,757,451,525,780 | null | 293 | 293 |
n, m = map(int, input().split())
def ark(a, b):
return min(abs(a - b), n - abs(a - b))
a, b = n, 1
S = set()
for i in range(m):
if 2 * ark(a, b) == n or ark(a, b) in S:
a -= 1
print(a, b)
S.add(ark(a, b))
a -= 1
b += 1
|
n,m = map(int,input().split())
if n%2 ==1:
for i in range(1,m+1):
print(i,n-i)
else:
left_end = 1+m if m%2 == 1 else m
left_start = left_end//2
right_start = left_end+m//2
for i in range(1,m+1):
if i%2 == 1:
print(left_start,left_start+i)
left_start-=1
else:
print(right_start,right_start+i)
right_start-=1
| 1 | 28,604,526,909,290 | null | 162 | 162 |
data=input()
x = data.split(" ")
tmp=x[2]
x[2]=x[1]
x[1]=x[0]
x[0]=tmp
print(x[0],x[1],x[2])
|
X, K, D = map(int, input().split())
X = abs(X)
if K%2 == 1:
K -= 1
X -= D
K_ = K // 2
min_Y = X - K_ * (2 * D)
if min_Y > 0:
print(min_Y)
else:
min_Y_p = X % (2 * D)
min_Y_m = 2 * D - X % (2 * D)
print(min(min_Y_p, min_Y_m ))
| 0 | null | 21,681,259,825,160 | 178 | 92 |
n = int(input())
A = [int(i) for i in input().split()]
flag = 1
count = 0
while flag:
flag = 0
for j in range(n-1,0,-1):
if A[j] < A[j-1]:
A[j],A[j-1] = A[j-1],A[j]
flag = 1
count += 1
print(" ".join(map(str,A)))
print(count)
|
def bubble_sort(A):
flag = 1
count = 0
while flag:
flag = 0
for i in range(len(A) - 1, 0, -1):
if A[i - 1] > A[i]:
A[i - 1], A[i] = A[i], A[i - 1]
flag = 1
count += 1
return count
def show(A):
for i in range(len(A) - 1):
print(A[i], end=" ")
print(A[len(A) - 1])
n = int(input())
line = input()
A = list(map(int, line.split()))
count = bubble_sort(A)
show(A)
print(count)
| 1 | 16,490,542,292 | null | 14 | 14 |
'''
We can show that if u and v belong to the same connected component, then they are friends w/ each other
So everyone in a given connected component is friends with one another
So everyone in a given connected component must be separated into different groups
If we have a CC of with sz nodes in it, then we need at least sz different groups
So, the minimum number of groups needed is max sz(CC)
'''
n, m = map(int,input().split())
adj = [[] for u in range(n+1)]
for i in range(m):
u, v = map(int,input().split())
adj[u].append(v)
adj[v].append(u)
vis = [False for u in range(n+1)]
def bfs(s):
sz = 0
queue = [s]
ptr = 0
while ptr < len(queue):
u = queue[ptr]
if not vis[u]:
vis[u] = True
sz += 1
for v in adj[u]:
queue.append(v)
ptr += 1
return sz
CCs = []
for u in range(1,n+1):
if not vis[u]:
CCs.append(bfs(u))
print(max(CCs))
|
# coding: utf-8
# Your code here!
a = input()
big = ["A","B","C","D","E","F","G","H","I","J","K","L",
"M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
small = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
if a in big:
print("A")
else:
print("a")
| 0 | null | 7,632,712,331,178 | 84 | 119 |
N=int(input())
A=list(map(int, input().split()))
q=int(input())
Q=[list(map(int, input().split())) for _ in range(q)]
L=[0]*(10**5+1)
S=0
for i in range(N):
L[A[i]]+=1
S+=A[i]
for i in range(q):
S+=L[Q[i][0]]*(Q[i][1]-Q[i][0])
L[Q[i][1]]+=L[Q[i][0]]
L[Q[i][0]]=0
# print(L)
print(S)
|
import collections
n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = [[int(i) for i in input().split()] for _ in range(q)]
total = sum(a)
s = collections.Counter(a)
for x in range(q):
if bc[x][0] in s and bc[x][1] in s:
s[bc[x][1]] += s[bc[x][0]]
total += (bc[x][1]-bc[x][0]) * s[bc[x][0]]
del s[bc[x][0]]
elif bc[x][0] in s and bc[x][1] not in s:
s[bc[x][1]] = s[bc[x][0]]
total += (bc[x][1]-bc[x][0]) * s[bc[x][0]]
del s[bc[x][0]]
print(total)
| 1 | 12,109,886,070,816 | null | 122 | 122 |
import queue
n,u,v = map(int, input().split())
u -= 1
v -= 1
path = [[] for i in range(n)]
for i in range(n-1):
a,b = map(int, input().split())
a -= 1
b -= 1
path[a].append(b)
path[b].append(a)
t = [10**9]*n
t[u]=0
q = queue.Queue()
q.put(u)
while not q.empty():
p = q.get()
for x in path[p]:
if t[x]>t[p]+1:
q.put(x)
t[x]=t[p]+1
a = [10**9]*n
a[v]=0
q = queue.Queue()
q.put(v)
while not q.empty():
p = q.get()
for x in path[p]:
if a[x]>a[p]+1:
q.put(x)
a[x]=a[p]+1
c = [a[i] for i in range(n) if a[i]>t[i]]
print(max(c)-1)
|
import sys
sys.setrecursionlimit(10 ** 5)
n, u, v = map(int, input().split())
u -= 1
v -= 1
es = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
es[a-1].append(b-1)
es[b-1].append(a-1)
def dfs(v, dist, p=-1, d=0):
dist[v] = d
for nv in es[v]:
if nv == p:
continue
dfs(nv, dist, v, d+1)
def calc_dist(x):
dist = [-1] * n
dfs(x, dist)
return dist
dist_t = calc_dist(u)
dist_a = calc_dist(v)
mx = 0
for i in range(n):
if dist_t[i] < dist_a[i]:
mx = max(mx, dist_a[i])
ans = mx - 1
print(ans)
| 1 | 117,351,526,938,364 | null | 259 | 259 |
L,R,d = (int(X) for X in input().split())
print(sum([True for T in range(L,R+1) if T%d==0]))
|
n,m = map(int,input().split())
#行列a、ベクトルb、行列積cの初期化
a = [0 for i in range(n)]
b = [0 for j in range(m)]
c = []
#a,bの読み込み
for i in range(n):
a[i] = input().split()
a[i] = [int(x) for x in a[i]]
for j in range(m):
b[j] = int(input())
#行列積計算
temp = 0
for i in range(n):
for j in range(m):
temp += a[i][j]*b[j]
c.append(temp)
temp = 0
#結果の表示
for num in c:print(num)
| 0 | null | 4,327,722,275,880 | 104 | 56 |
R=int(input())
N=R*2*3.141592
print(N)
|
import math
R = float(input())
print(float(2*R*math.pi))
| 1 | 31,336,347,591,078 | null | 167 | 167 |
import math
if __name__ == "__main__":
r = float(input())
print("%.6f %.6f"%(math.pi*r**2,math.pi*2*r))
|
import math
r=float(input())
print('%f %f' %(math.pi*r*r, 2*math.pi*r))
| 1 | 635,319,796,828 | null | 46 | 46 |
s = input()
stack = []
n = len(s)
ans = 0
prev = 0
each = []
for i in range(n):
if s[i] == '\\':
stack.append(i)
elif s[i] == '_':
pass
else:
if len(stack) != 0:
idx = stack.pop()
ans += (i - idx)
if len(stack) == 0:
each.append(ans - prev)
prev = ans
each2 = []
stack2 = []
ans2 = 0
prev2 = 0
if len(stack) >= 1:
for i in range(n-1,stack[0],-1):
if s[i] == '/':
stack2.append(i)
elif s[i] == '_':
pass
else:
if len(stack2) != 0:
idx = stack2.pop()
ans2 += (idx - i)
if len(stack2) == 0:
each2.append(ans2 - prev2)
prev2 = ans2
each2.reverse()
each.extend(each2)
print(ans)
if len(each) == 0:
print(len(each))
else:
print(len(each),end=" ")
print(*each)
|
from collections import deque
slope = input()
down_slope = deque()
total_slopes = deque()
for i in range(len(slope)):
if slope[i] == '\\':
down_slope.append(i)
elif slope[i] == '/':
area = 0
if len(down_slope) > 0:
while len(total_slopes) > 0 and total_slopes[-1][0] > down_slope[-1]:
area += total_slopes[-1][1]
total_slopes.pop()
area += i-down_slope[-1]
total_slopes.append([down_slope[-1],area])
down_slope.pop()
if len(total_slopes) > 0:
total_slopes = [i[1] for i in total_slopes]
print(sum(total_slopes))
print(len(total_slopes),end=' ')
print(' '.join(map(str,total_slopes)))
else:
print(0)
print(0)
| 1 | 59,652,262,460 | null | 21 | 21 |
n=int(input())
s = input()
ans = 0
if n%2 != 0:
print('No')
if n%2 == 0:
for i in range(n//2):
if s[i] == s[i+n//2]:
ans += 1
if ans == n//2:
print('Yes')
if ans != n//2:
print('No')
|
def main():
import sys
readline = sys.stdin.buffer.readline
n = int(readline())
s = readline().rstrip().decode('utf-8')
print('Yes' if s[:n//2] == s[n//2:] else 'No')
if __name__ == '__main__':
main()
| 1 | 146,668,340,841,178 | null | 279 | 279 |
k=int(input())
que=[i for i in range(1,10)]
# print(que)
for i in range(k):
now=que.pop(0)
too=now%10
if too!=0:
que.append(now*10+too-1)
que.append(now*10+too)
if too!=9:
que.append(now*10+too+1)
print(now)
|
N, K = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
P2 = [(((P[i]+1)) / 2) for i in range(N)]
# i番目は1~P[i]の値を出す
# P[i]が大きいものからK個選んで期待値を求める
# 幅が最大のところを見つける
s = 0
init = 0
for i in range(K):
s += P2[i]
tmp = s
for i in range(1, N-K+1):
tmp = tmp - P2[i-1] + P2[i+K-1]
if s < tmp:
s = tmp
init = i
print(s)
| 0 | null | 57,282,561,551,332 | 181 | 223 |
n,m=map(int,raw_input().split())
A=[]
b=[]
for i in range(n):
A.append(map(int,raw_input().split()))
for i in range(m):
b.append(input())
for i in range(n):
sum=0
for j in range(m):
sum+=A[i][j]*b[j]
print('%d'%sum)
|
N = int(input())
a = list(map(int, input().split()))
n = 1
C = 0
for ai in a:
if ai != n:
C += 1
else:
n += 1
if n == 1:
print('-1')
else:
print(C)
| 0 | null | 57,807,995,445,162 | 56 | 257 |
import sys
N,A,B = map(int,input().split())
if not ( 1 <= N <= 10**18 and 0 <= A and 0 <= B and 0 < A + B <= 10**18 ): sys.exit()
if not ( isinstance(N,int) and isinstance(A,int) and isinstance(B,int) ): sys.exit()
count = N // (A+B)
remind = N % (A+B) if N % (A+B) <= A else A
print(count * A + remind)
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
A,B = map(int,S().split())
if A<=9 and B<=9:
print(A*B)
else:
print(-1)
| 0 | null | 106,926,411,435,980 | 202 | 286 |
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
for test in range(int(input())):
'''
inf = 100000000000000000 # 1e17
s = input().strip()
if s[2] == s[3] and s[4] == s[5]:
print("Yes")
else:
print("No")
|
S = input()
if (S[2] == S[3]) and (S[4] == S[5]):
print('Yes')
else:
print('No')
| 1 | 42,125,103,556,272 | null | 184 | 184 |
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
s=input()
lns=len(s)
lst=[0]*(lns+1)
start=[]
if s[0]=="<":
start.append(0)
for i in range(lns-1):
if s[i]==">" and s[i+1]=="<":
start.append(i+1)
if s[lns-1]==">":
start.append(lns)
for i in start:
d=deque([[i,0],[i,1]])
while d:
now,lr=d.popleft()
# print(now)
if now-1>=0 and lr==0 and s[now-1]==">":
lst[now-1]=max(lst[now-1],lst[now]+1)
d.append([now-1,0])
if now+1<=lns and lr==1 and s[now]=="<":
lst[now+1]=max(lst[now+1],lst[now]+1)
d.append([now+1,1])
# print(lst)
# print(start)
# print(lst)
print(sum(lst))
|
s=input()
n=len(s)
l=[[0,0] for i in range(n+1)]
ri,le=0,0
for i in range(n):
l[i][0]=le
l[-1-i][1]=ri
if "<"==s[i]:le+=1
else:le=0
if ">"==s[-1-i]:
ri+=1
else:ri=0
l[n][0]=le
l[0][1]=ri
print(sum(max(a,s) for a,s in l))
| 1 | 156,443,252,811,812 | null | 285 | 285 |
def bubblesort(N, A):
c, flag = 0, 1
while flag:
flag = False
for j in range(N-1, 0, -1):
if A[j] < A[j-1]:
A[j], A[j-1] = A[j- 1], A[j]
c += 1
flag = True
return (A, c)
A, c = bubblesort(int(input()), list(map(int, input().split())))
print(' '.join([str(v) for v in A]))
print(c)
|
n = int(input())
ll = list(map(int, input().split()))
def bubble_sort(a, n):
flag = True
count = 0
while flag:
flag = False
for i in range(n-2, -1, -1):
if a[i] > a[i+1]:
a[i], a[i+1] = a[i+1], a[i]
flag = True
count += 1
print(" ".join(map(str, a)))
print(count)
bubble_sort(ll, n)
| 1 | 17,079,581,080 | null | 14 | 14 |
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8[:],i8[:],i8[:],i8[:]), cache=True)
def main(lis_h,lis_w,bomb_h,bomb_w):
bomb = {}
for h,w in zip(bomb_h,bomb_w):
bomb[(h,w)] = 1
m_h = max(lis_h)
m_w = max(lis_w)
m_h_lis = []
m_w_lis = []
for i,l in enumerate(lis_h):
if l==m_h:
m_h_lis.append(i)
for i,l in enumerate(lis_w):
if l==m_w:
m_w_lis.append(i)
ans = m_h+m_w
for h in m_h_lis:
for w in m_w_lis:
if (h,w) not in bomb:
return ans
return ans-1
H, W, M = map(int, input().split())
bombh = np.zeros(M, np.int64)
bombw = np.zeros(M, np.int64)
lis_h = np.zeros(H, np.int64)
lis_w = np.zeros(W, np.int64)
for i in range(M):
h,w = map(int, input().split())
h -= 1
w -= 1
bombh[i], bombw[i] = h,w
lis_h[h] += 1
lis_w[w] += 1
print(main(lis_h,lis_w,bombh,bombw))
|
N,M,K=map(int,input().split())
adj=[set() for _ in range(N)]
for _ in range(M):
A,B=map(int,input().split())
A,B=A-1,B-1
adj[A].add(B)
adj[B].add(A)
blk=[{*()} for _ in range(N)]
for _ in range(K):
A,B=map(int,input().split())
A,B=A-1,B-1
blk[A].add(B)
blk[B].add(A)
#print(adj)
#print(blk)
colors=[-1]*N
ct={}
color=-1
for u in range(N):
if colors[u]!=-1:
continue
color+=1
colors[u]=color
stk=[u]
while stk:
u=stk.pop()
ct[color]=ct.get(color,0)+1
for v in adj[u]:
if colors[v]==-1:
colors[v]=color
stk.append(v)
ans=[0]*N
for u in range(N):
c=colors[u]
k=ct[c]-1-len(adj[u])
for v in blk[u]:
if colors[v]==c:
k-=1
ans[u]=k
print(*ans)
| 0 | null | 33,058,741,250,668 | 89 | 209 |
asd=input()
dfg=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
print(dfg[dfg.index(asd)+1])
|
n = int(input())
s = input()
temp = ''
cnt = 0
for i in s:
if i != temp:
cnt += 1
temp = i
print(cnt)
| 0 | null | 131,448,396,898,700 | 239 | 293 |
n = input()
len_n = len(n)
dp = [[0,2] for i in range(len_n+1)]
for k,v in enumerate(n[::-1]):
v = int(v)
dp[k+1][0] = min(dp[k][0] + v, dp[k][1] + v)
dp[k+1][1] = min(dp[k][0] + 10 - v + 1, dp[k][1] + 10 - v - 1)
print(min(dp[len_n]))
|
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import deque
from collections import defaultdict
def main():
N = S()
N = N[::-1]
N += '0'
cnt = 0
next = 0
for i in range(len(N)):
num = int(N[i])
num += next
if num <= 4:
cnt += num
next = 0
elif num >= 6:
cnt += 10 - num
next = 1
else:
if int(N[i + 1]) <= 4:
cnt += num
next = 0
else:
cnt += 10 - num
next = 1
print(cnt)
if __name__ == "__main__":
main()
| 1 | 70,911,752,720,168 | null | 219 | 219 |
# -*- coding: utf-8 -*-
def num2alpha(num):
if num <= 26:
return chr(64+num)
elif num % 26 == 0:
return num2alpha(num//26-1)+chr(90)
else:
return num2alpha(num // 26) + chr(64 + num % 26)
def base_10_to_n(X, n):
if (int(X/n)):
return base_10_to_n(int(X/n), n)+str(X % n)
return str(X % n)
def main():
n = int(input())
alpha = num2alpha(n)
print(alpha.lower())
if __name__ == "__main__":
main()
|
d = {chr(i):i-96 for i in range(97,123)}
D = {val:key for key,val in d.items()}
N = int(input())
x = ""
while N>0:
a = N%26
if a!=0:
x += D[a]
N = N//26
else:
x += "z"
N = N//26
N -= 1
print(x[::-1])
| 1 | 12,018,423,146,600 | null | 121 | 121 |
n=int(input())
even=n//2
a=(n-even)/n
print(a)
|
N = int(input())
count = 0
for i in range(1,N+1):
if(i % 2 == 1):
count += 1
print(count/N)
| 1 | 176,932,641,666,752 | null | 297 | 297 |
s = str(input())
p = str(input())
s = s + s
if p in s:
print("Yes")
else:
print("No")
|
s = input()
p = input()
found = False
for i in range(len(s)):
ring = s[i:] + s[:i]
if p in ring:
print('Yes')
found = True
break
if not found:
print('No')
| 1 | 1,763,950,996,640 | null | 64 | 64 |
x,k,d = list(map(int,input().split()))
x = abs(x)
m = x // d
if m >= k:
ans = x - (d*k)
elif (k-m) % 2 == 0:
ans = x - (d*m)
else:
ans = x - (d*m) - d
print(abs(ans))
|
X,K,D = map(int,input().split())
X = abs(X)
ans = 0
if X>=D and D*K<=X:
ans = X - D*K
if X>=D and D*K>X:
K=K-int(X/D)
X=X%D
if K%2==0:
ans=X
else:
ans = abs(X-D)
if X<D:
if K%2==0:
ans = X
else:
ans = abs(X-D)
print(ans)
| 1 | 5,214,220,396,868 | null | 92 | 92 |
from math import ceil
t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a1 -= b1
a2 -= b2
a1 *= t1
a2 *= t2
if a1 + a2 == 0:
print("infinity")
exit()
if a1*(a1+a2) > 0:
print(0)
exit()
x = -a1/(a1+a2)
n = ceil(x)
if n == x:
print(2*n)
else:
print(2*n-1)
|
S = input()
ans = 'Yes'
while len(S) > 0:
if S[:2] == 'hi':
S = S[2:]
else:
ans = 'No'
break
print(ans)
| 0 | null | 92,318,323,820,438 | 269 | 199 |
A, B, C, D = map(int, input().split())
takahashi = 0
aoki = 0
while C > 0:
C -= B
takahashi += 1
while A > 0:
A -= D
aoki += 1
if takahashi <= aoki:
print("Yes")
else:
print("No")
|
# -*- coding: utf-8 -*-
n = int(raw_input())
tp = hp = 0
for i in range(n):
ts, hs = map(str, raw_input().split())
if ts > hs:
tp += 3
elif ts < hs:
hp += 3
else:
tp += 1
hp += 1
print "%d %d" %(tp, hp)
| 0 | null | 15,864,261,170,030 | 164 | 67 |
R=int(input())
print(2*R*3.1419)
|
from math import pi
def readinput():
r=int(input())
return r
def main(r):
return 2*pi*r
if __name__=='__main__':
r=readinput()
ans=main(r)
print(ans)
| 1 | 31,400,288,855,840 | null | 167 | 167 |
#coding:utf-8
#1_3_C 2015.3.24
while True:
x,y = map(int,input().split())
if (x,y) == (0,0):
break
elif x > y:
x,y = y,x
print('{} {}'.format(x,y))
|
while 1:
a,b = sorted(map(int,raw_input().split()))
if (not a) & (not b):
break
print ('{} {}'.format(a,b))
| 1 | 527,650,958,920 | null | 43 | 43 |
X = int(input())
# 500円硬貨 1枚につき 1000、5円硬貨 1枚につき 5 の 嬉しさ を得ます。
# X円を持っています。嬉しさの最大値を出力せよ。
s = X // 500
a = X % 500
t = a // 5
print(s*1000 + t*5)
|
x=int(input())
y=x//500*1000+(x%500)//5*5
print(y)
| 1 | 42,778,054,856,614 | null | 185 | 185 |
bit=[0]*9
fa=[1]*9
for n in range(1,9):fa[n]=fa[n-1]*n
def up(id):
while id<9:
bit[id]+=1
id+=id&(-id)
def qr(id):
res=0
while id:
res+=bit[id]
id-=id&(-id)
return res
x=int(input())
s=list(map(int,input().split()))
z=list(map(int,input().split()))
v=''
for n in s:
a=qr(n)
vl=n-1-a
v+=str(vl)
up(n)
v=v[::-1]
r1=0
for n in range(len(v)):
r1+=int(v[n])*fa[n]
r2=0
v=''
bit=[0]*9
for n in z:
a=qr(n)
vl=n-1-a
v+=str(vl)
up(n)
v=v[::-1]
for n in range(len(v)):
r2+=int(v[n])*fa[n]
print(abs(r1-r2))
|
N=int(input())
import math
print(360//math.gcd(360,N))
| 0 | null | 57,043,543,678,940 | 246 | 125 |
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction
def comb(n, r, mod):
ans = 1
for i in range(max(r, n - r) + 1, n + 1):
ans *= i
ans %= mod
for i in range(1, min(r, n - r) + 1):
ans *= pow(i, mod - 2, mod)
ans %= mod
return ans
def main():
x, y = map(int, input().split())
if (x + y) % 3 != 0:
print(0)
sys.exit()
tate = (2 * y - x) // 3
yoko = (2 * x - y) // 3
if tate < 0 or yoko < 0:
print(0)
sys.exit()
mod = 10 ** 9 + 7
ans = comb(tate + yoko, tate, mod)
print(ans)
if __name__ == '__main__':
main()
|
from functools import reduce
def comb(n, r, mod=10 ** 9 + 7):
numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
return numerator * pow(denominator, mod - 2, mod) % mod
n, a, b = map(int, input().split())
mod = 1000000007
print((pow(2, n, mod) - 1 - comb(n, a, mod) - comb(n, b, mod)) % mod)
| 0 | null | 107,950,468,125,278 | 281 | 214 |
N, A, B = map(int, input().split())
h = N//(A+B)
i = N%(A+B)
ans = h*A + min(i, A)
print(ans)
|
n,a,b = map(int,input().split())
if n%(a+b)<=a:
print(n//(a+b)*a+n%(a+b))
else:
print(n//(a+b)*a+a)
| 1 | 55,443,692,488,570 | null | 202 | 202 |
if int(input())%9==0:
print('Yes')
else:
print('No')
|
s = str(input())
t = str(input())
num = 0
for i in range(len(s)):
if s[i] != t[i]:
num += 1
print(num)
| 0 | null | 7,455,209,398,978 | 87 | 116 |
from sys import stdin
s = int(stdin.readline().rstrip())
h = s//3600
m = (s%3600)//60
sec = (s%3600)%60
print("{}:{}:{}".format(h, m, sec))
|
import sys
import math
A,B,H,M = list(map(int, input().split()))
a = (H/12+M/720) * 360
b = M/60 * 360
a = a-b
if a > 180:
a = 360 - a
c = math.sqrt(A**2 + B**2 - (2 * A * B * math.cos(math.radians(a))))
print(c)
| 0 | null | 10,303,763,209,360 | 37 | 144 |
def main():
n, k = map(int, input().split())
# ダブリング
d = 60
to = [[0 for _ in range(n)]
for _ in range(d)] # to[i][j] : 町jから2**i回ワープした町
to[0] = list(map(int, input().split()))
for i in range(1, d):
for j in range(n):
to[i][j] = to[i - 1][to[i - 1][j] - 1]
v = 1
for i in range(d, -1, -1):
l = 2 ** i # 2**i回ワープする
if l <= k:
v = to[i][v - 1]
k -= l
if k == 0:
break
print(v)
if __name__ == "__main__":
main()
|
if __name__ == '__main__':
n = int(input())
a = list(map(int, input().split()))
ans = 0
x, y, z = [0], [0], [0]
for i in range(n):
if a[i] == 0:
if x[-1] == 0:
x.append(1)
y.append(y[-1])
z.append(z[-1])
elif y[-1] == 0:
x.append(x[-1])
y.append(1)
z.append(z[-1])
else:
x.append(x[-1])
y.append(y[-1])
z.append(1)
else:
if x[-1] == a[i]:
x.append(x[-1] + 1)
y.append(y[-1])
z.append(z[-1])
elif y[-1] == a[i]:
x.append(x[-1])
y.append(y[-1] + 1)
z.append(z[-1])
else:
x.append(x[-1])
y.append(y[-1])
z.append(z[-1] + 1)
ans = 1
for i in range(n):
ans *= [x[i], y[i], z[i]].count(a[i])
ans %= (10 ** 9 + 7)
print(ans)
| 0 | null | 76,166,039,070,902 | 150 | 268 |
x = input()
X = int(x)
Pow = X*X*X
print (Pow)
|
s = input()
num = int(s)
print(str(num**3))
| 1 | 278,628,926,976 | null | 35 | 35 |
a,b=map(str,input().split())
print(b+a)
|
n, k = map(int, input().split())
check = [False] * n
d = []
a = []
for i in range(k):
d = int(input())
a.append(list(map(int, input().split())))
for i in range(k):
for j in range(len(a[i])):
check[a[i][j]-1] = True
print(check.count(False))
| 0 | null | 63,828,037,316,540 | 248 | 154 |
n = int(input())
rates = [1,1,3,6]
cnt = [0]*10001
def g(x,y,z):
return x**2 + y**2 + z**2 + x*y + x*z + y*z
for x in range(1,101):
for y in range(x,101):
for z in range(y,101):
rate = rates[len(set([x,y,z]))]
gv = g(x,y,z)
if gv < 10001:
cnt[gv]+=rate
for i in range(1,n+1):
print(cnt[i])
|
import math
N = int(input())
ans = [0] * N
n = int(math.sqrt(N))
for x in range(1, n+1):
for y in range(1, x+1):
for z in range(1, y+1):
i = x**2 + y**2 + z**2 + x*y + y*z + z*x
if i <= N:
if x == y == z:
ans[i-1] += 1
elif x == y or y == z:
ans[i-1] += 3
else:
ans[i-1] += 6
for j in range(N):
print(ans[j])
| 1 | 8,008,458,754,478 | null | 106 | 106 |
n = input()
card = []
for i in range(n):
card.append(raw_input())
for a in ['S','H','C','D']:
for b in range(1,14):
check = a + " " + str(b)
for c in card:
if check == c:
flg = 0
break
else:
flg = 1
if flg == 1:
print check
|
result = [(temp1 + str(temp2)) for temp1 in ('S ','H ','C ','D ') for temp2 in range(1,14)]
for check in range(int(input())) :
result.remove(input())
for temp in result :
print(temp)
| 1 | 1,065,444,915,110 | null | 54 | 54 |
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
R = [i+1 for i in range(N)]
RPS = sorted(list(itertools.permutations(R)))
print(abs(RPS.index(P)-RPS.index(Q)))
|
N = int(input())
A = list(map(int, input().split()))
dicA = {}
for i in range(1, N+1):
dicA[i] = A[i-1]
sort_dicA = sorted(dicA.items(), key=lambda x:x[1])
for i in range(N):
print(sort_dicA[i][0], end=' ')
| 0 | null | 140,383,622,016,988 | 246 | 299 |
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
MOD = 998244353
P = [tuple(map(int, input().split())) for _ in range(K)]
E = [0] * N
def update(i, v):
while i < N:
E[i] = (E[i] + v) % MOD
i |= i+1
def query(i):
r = 0
while i > 0:
r += E[i-1]
i &= i-1
return r % MOD
update(0, 1)
update(1, -1)
for i in range(N-1):
v = query(i+1)
for L, R in P:
if i + L < N:
update(i+L, v)
if i + R + 1 < N:
update(i+R+1, -v)
print(query(N))
|
n,k=map(int,input().split())
k_list=[]
for i in range(k):
l,r=map(int,input().split())
k_list.append([l,r])
dp=[0]*(n+1)
dp[1]=1
dpsum=[0]*(n+1)
dpsum[1]=1
for i in range(1,n):
dpsum[i]=dp[i]+dpsum[i-1]
for j in range(k):
l,r=k_list[j]
li=i+l
ri=i+r+1
if li<=n:
dp[li]+=dpsum[i]
dp[li]=dp[li]%998244353
if ri<=n:
dp[ri]-=dpsum[i]
dp[ri]=dp[ri]%998244353
print(dp[n])
| 1 | 2,705,470,930,698 | null | 74 | 74 |
import sys,math,collections
from collections import defaultdict
#from itertools import permutations,combinations
def file():
sys.stdin = open('input.py', 'r')
sys.stdout = open('output.py', 'w')
def get_array():
l=list(map(int, input().split()))
return l
def get_2_ints():
a,b=map(int, input().split())
return a,b
def get_3_ints():
a,b,c=map(int, input().split())
return a,b,c
def sod(n):
n,c=str(n),0
for i in n:
c+=int(i)
return c
def getFloor(A, x):
(left, right) = (0, len(A) - 1)
floor = -1
while left <= right:
mid = (left + right) // 2
if A[mid] == x:
return A[mid]
elif x < A[mid]:
right = mid - 1
else:
floor = A[mid]
left = mid + 1
return floor
#file()
def main():
l,r,n=get_3_ints()
c=0
for i in range(min(l,r),max(l,r)+1):
#print(i)
if(i%n==0):
c+=1
print(c)
if __name__ == '__main__':
main()
|
import itertools
n=int(input())
a= list(map(int, input().split()))
# aを偶数奇数の要素で振り分け
a1=[]
a2=[]
for i in range(n):
if i%2==0:
a1.append(a[i])
else:
a2.append(a[i])
# 累積和も作っておく
a3=list(itertools.accumulate(a1))
a4=list(itertools.accumulate(a2))
x1=sum(a1)
x2=sum(a2)
if n%2==0:
ans=-float('inf')
for i in range(n//2):
ans=max(a3[i]+x2-a4[i],ans)
print(max(ans,x1,x2))
else:
# 奇数番目だけの要素を選んだ時の最大値
ans1=sum(a1)-min(a1)
# dp1[i]=奇数偶数奇数or偶数奇数と移動した時のi番目までのMAX
dp1 = [-float('inf')] * (n // 2 + 1)
dp1[0] = a1[0]
# dp2[i]=奇数偶数or偶数のみと移動した時のi番目までのMAX
dp2 = [-float('inf')] * (n // 2)
dp2[0] = a2[0]
for i in range(n // 2 - 1):
dp2[i + 1] = max(a3[i] + a2[i + 1], dp2[i] + a2[i + 1])
if i==0:
dp1[i + 2] = dp2[i] + a1[i + 2]
else:
dp1[i + 2] = max(dp2[i] + a1[i + 2], dp1[i + 1] + a1[i + 2])
print(max(dp1[-1], dp2[-1],ans1))
| 0 | null | 22,304,716,388,320 | 104 | 177 |
h, n = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
#(a,b):=(ダメージ,消費魔力)
dp = [float('inf')] * (h + 1)
dp[0] = 0
for i in range(h + 1):
for j in range(n):
if dp[i] == float('inf'):continue
temp_a = i + ab[j][0] if i + ab[j][0] < h else h
temp_b = dp[i] + ab[j][1]
dp[temp_a] = min(dp[temp_a], temp_b)
print(dp[-1])
#print(dp)
|
import math
n = int(input())
x = n * (n + 1) / 2
f = math.floor(n / 3)
fizzsum = f * (f + 1) / 2 * 3
b = math.floor(n / 5)
buzzsum = b * (b + 1) / 2 * 5
fb = math.floor(n / 15)
fizzbuzzsum = fb * (fb + 1) / 2 * 15
print(int(x - fizzsum - buzzsum + fizzbuzzsum))
| 0 | null | 57,778,979,886,040 | 229 | 173 |
n = int(input())
ans = -1
for k in range(n, 0, -1):
if n == k * 108 // 100:
ans = k
break
if ans > 0: print(ans)
else: print(':(')
|
N = int(input())
S, T = input().split()
s_list = list(S)
t_list = list(T)
ans = ''
for i in range(N):
ans += s_list[i]
ans += t_list[i]
print(ans)
| 0 | null | 118,624,525,434,770 | 265 | 255 |
print('ARC' if input() == 'ABC' else 'ABC')
|
N, K = map(int, input().split())
P = [(int(x)+1)/2 for x in input().split()]
total=ans=sum(P[:K])
for n in range(K,N):
total+=P[n]-P[n-K]
ans=max(ans, total)
print(ans)
| 0 | null | 49,717,823,522,328 | 153 | 223 |
n = int(input())
a = list(map(int, input().split()))
def selectionSort(a, n):
count = 0
for i in range(n):
mini = i
for j in range(i, n):
if a[j] < a[mini]:
mini = j
if i != mini:
a[i],a[mini] = a[mini],a[i]
count += 1
print(*a)
print(count)
selectionSort(a,n)
|
class SegmentTree():
def segfunc(self, x, y):
return x|y #関数
def __init__(self, a): #a:リスト
n = len(a)
self.ide_ele = 0 #単位元
self.num = 2**((n-1).bit_length()) #num:n以上の最小の2のべき乗
self.seg = [self.ide_ele]*2*self.num
#set_val
for i in range(n):
self.seg[i+self.num-1] = a[i]
#built
for i in range(self.num-2,-1,-1):
self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])
def update(self, k, s):
x = 1<<(ord(s)-97)
k += self.num-1
self.seg[k] = x
while k:
k = (k-1)//2
self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num-1
q += self.num-2
res = self.ide_ele
while q - p > 1:
if p&1 == 0:
res = self.segfunc(res, self.seg[p])
if q&1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = self.segfunc(res,self.seg[p])
else:
res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
return res
def popcount(x):
'''xの立っているビット数をカウントする関数
(xは64bit整数)'''
# 2bitごとの組に分け、立っているビット数を2bitで表現する
x = x - ((x >> 1) & 0x5555555555555555)
# 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
x = x + (x >> 8) # 16bitごと
x = x + (x >> 16) # 32bitごと
x = x + (x >> 32) # 64bitごと = 全部の合計
return x & 0x0000007f
N = int(input())
S = list(input())
for i in range(N):
S[i] = 1<<(ord(S[i])-97)
Seg = SegmentTree(S)
Q = int(input())
for i in range(Q):
x, y, z = input().split()
if int(x) == 1:
Seg.update(int(y)-1, z)
else:
print(popcount(Seg.query(int(y)-1, int(z))))
| 0 | null | 31,404,169,920,992 | 15 | 210 |
print("Yes" if int(input()) >= 30 else "No")
|
#!/usr/bin/env python3
def main():
if int(input()) >= 30:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| 1 | 5,782,417,693,964 | null | 95 | 95 |
S = input()
T = input()
largest = 0
for i in range(len(S) - len(T)+1):
count = 0
for j in range(len(T)):
if S[i+j] == T[j]:
count += 1
if largest < count:
largest = count
print(len(T) - largest)
|
s=input()
t=input()
ans=int(len(s))
for i in range(len(s)-len(t)+1):
now=int(0)
for j in range(len(t)):
if s[i+j]!=t[j]:
now+=1
ans=min(now,ans)
print(ans)
| 1 | 3,693,228,856,788 | null | 82 | 82 |
import math
import itertools
from collections import deque
import bisect
import heapq
def IN(): return int(input())
def sIN(): return input()
def lIN(): return list(input())
def MAP(): return map(int,input().split())
def LMAP(): return list(map(int,input().split()))
def TATE(n): return [input() for i in range(n)]
ans = 0
def bfs(sx,sy):
d = [[-1] * w for i in range(h)]
MAX = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
que = deque([])
que.append((sx, sy))#スタート座標の記録
d[sx][sy] = 0#スタートからスタートへの最短距離は0
while que:#中身がなくなるまで
p = que.popleft()
for m in range(4):#現在地から4方向の移動を考える
nx = p[0] + dx[m]
ny = p[1] + dy[m]
if 0 <= nx < h and 0 <= ny < w:
if maze[nx][ny] != "#" and d[nx][ny] == -1:
que.append((nx, ny))#↑格子点からでない&壁でない&まだ通ってない
d[nx][ny] = d[p[0]][p[1]] + 1
for k in range(h):
MAX = max(max(d[k]),MAX)
return MAX
h, w = map(int, input().split())
maze = [lIN() for i in range(h)]
for i in range(h):#sx座標指定0~h-1
for j in range(w):#sy座標指定0~w-1
if maze[i][j] == '.':
ans = max(bfs(i,j),ans)
print(ans)
|
from collections import deque
h,w=map(int,input().split())
l=list()
l.append('#'*(w+2))#壁
for i in range(h):
l.append('#'+input()+'#')
l.append('#'*(w+2))#壁
p=0
for i in range(1,h+1):
for j in range(1,w+1):
if l[i][j]=='#':
continue
s=[[-1 for a in b] for b in l]
q=deque([[i,j]])
s[i][j]=0
while len(q)>0:
a,b=q.popleft()
for x,y in [[1,0],[0,1],[-1,0],[0,-1]]:
if l[a+x][b+y]=='#' or s[a+x][b+y]>-1:
continue
q.append([a+x,b+y])
s[a+x][b+y]=s[a][b]+1
r=0
for x in s:
for y in x:
r=max(y,r)
p=max(r,p)
print(p)
| 1 | 94,746,197,321,630 | null | 241 | 241 |
n, k = map(int,input().split())
f = [int(x)-1 for x in input().split()]
def tortoise_and_hare(s,f):
tortoise = f[s]
hare = f[f[s]]
while tortoise != hare:
tortoise = f[tortoise]
hare = f[f[hare]]
rho = 0
tortoise = s
while tortoise != hare:
tortoise = f[tortoise]
hare = f[hare]
rho += 1
lamb = 1
hare = f[hare]
while tortoise != hare:
hare = f[hare]
lamb += 1
return rho,lamb
rho, lamb = tortoise_and_hare(0,f)
if k <= rho:
s = 0
for i in range(k):
s = f[s]
else:
s = 0
for i in range(rho):
s = f[s]
k = (k-rho)%lamb
for i in range(k):
s = f[s]
print(s+1)
|
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*(N+1)
B[0]=1;c=0;d=0
if B[0] in A:c=B[0]
for i in range(1,N+1):
B[i]=A[B[i-1]-1]
d=B.index(B[-1])+1
if K<=N:print(B[K]);exit()
#if (K+1-d)%(N+1-d)==0:print(B[-1])
print(B[d-1+(K+1-d)%(N+1-d)])
| 1 | 22,763,214,670,272 | null | 150 | 150 |
N,M,L = map(int,input().split())
A = [list(map(int,input().split()))for i in range(N)]
B = [list(map(int,input().split()))for i in range(M)]
ANS = [[0]*L for i in range(N)]
for x in range(N):
for y in range(L):
for z in range(M):
ANS[x][y]+=B[z][y]*A[x][z]
for row in range(N):
print("%d"%ANS[row][0],end="")
for col in range(1,L):
print(" %d"%(ANS[row][col]),end="")
print()
|
import sys
array_data = map(int, raw_input().split())
n = array_data[0]
m = array_data[1]
l = array_data[2]
a = []
for i in range(n):
partial_a = map(int, raw_input().split())
a.append(partial_a)
b = []
for j in range(m):
partial_b = map(int, raw_input().split())
b.append(partial_b)
c = []
for i in range(n):
c.append([])
for j in range(l):
c[i].append([])
wa = 0
for k in range(m):
wa += a[i][k] * b[k][j]
c[i][j] = wa
for i in range(len(c)):
for j in range(len(c[i])):
if j != len(c[i])-1:
sys.stdout.write("{:} ".format(c[i][j]))
else:
print(c[i][j])
| 1 | 1,418,786,194,750 | null | 60 | 60 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
h,n = readInts()
A = [readInts() for _ in range(n)]
dp = [INF] * (h+1)
dp[h] = 0
for idx in range(h,-1,-1):
for i in range(n):
a,b = A[i]
dp[max(0,idx-a)] = min(dp[max(0,idx-a)], dp[idx] + b)
print(dp[0])
|
H,N = map(int,input().split())
Q = []
for _ in range(N):
a,b = map(int,input().split())
Q.append((a,b))
INF = float("inf")
dp = [INF]*(H+1)
dp[0] = 0
for i in range(H+1):
for a,b in Q:
if i+a>=H:
dp[H] = min(dp[H],dp[i]+b)
else:
dp[i+a] = min(dp[i+a],dp[i]+b)
print(dp[-1])
| 1 | 81,309,093,569,210 | null | 229 | 229 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
MOD = 10 ** 9 + 7
N, K = lr()
answer = 0
for i in range(K, N+2):
low = i * (i-1) // 2
high = i * (N+N-i+1) // 2
answer += high - low + 1
answer %= MOD
print(answer%MOD)
|
N ,K = map(int, input().split())
lst = [i for i in range(N+1)]
rlst = [i for i in range(N,-1,-1)]
P = 10**9 + 7
rlt = 0
mini = sum(lst[:K-1])
maxi = sum(rlst[:K-1])
for i in range(N -K + 2):
mini += lst[K+i-1]
maxi += rlst[K+i-1]
rlt += maxi -mini + 1
rlt %= P
print(rlt)
| 1 | 32,977,915,855,940 | null | 170 | 170 |
#!/usr/bin/env python3
import sys
import math
def solve(H: int, W: int):
if W == 1 or H == 1:
# coner case
print(1)
else:
print(math.ceil(W * H / 2))
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
H = int(next(tokens)) # type: int
W = int(next(tokens)) # type: int
solve(H, W)
if __name__ == "__main__":
main()
|
N = int(input())
x = [[0] * (N-1) for _ in range(N)]
y = [[0] * (N-1) for _ in range(N)]
A = [0] * N
for i in range(N):
A[i] = int(input())
for j in range(A[i]):
x[i][j], y[i][j] = list(map(int, input().split()))
n = 2 ** N
Flag = 0
ans = 0
while(n < 2 ** (N+1)):
Flag = 0
for i in range(N):
if(int(bin(n)[i + 3]) == 1):
for j in range(A[i]):
if(y[i][j] != int(bin(n)[x[i][j] + 2])):
Flag = 1
break
if(Flag == 1):
break
else:
ans = max(ans, sum(list(map(int,bin(n)[3:]))))
n += 1
print(ans)
| 0 | null | 86,381,073,722,570 | 196 | 262 |
def main():
n = int(input())
if n % 1000 == 0:
print(0)
else:
print(1000 - int(n%1000))
if __name__ == '__main__':
main()
|
N = int(input())
S = sorted([input() for x in range(N)])
word = [S[0]]+[""]*(N-1) #単語のリスト
kaisuu = [0]*N #単語の出た回数のリスト
k = 0 #今wordリストのどこを使っているか
for p in range(N): #wordとkaisuuのリスト作成
if word[k] != S[p]:
k += 1
word[k] = S[p]
kaisuu[k] += 1
else:
kaisuu[k] += 1
m = max(kaisuu) #m:出た回数が最大のもの
ansnum = [] #出た回数が最大のもののwordリストでの位置
for q in range(N):
if kaisuu[q] == m:
ansnum += [q]
for r in range(len(ansnum)):
print(word[ansnum[r]])
| 0 | null | 39,421,831,794,060 | 108 | 218 |
#3 Range Flip Find Route
h,w = map(int,input().split())
s= [None for i in range(h)]
for i in range(h):
s[i] = input()
dp = [[0]*w for i in range(h)]
dp[0][0] = int(s[0][0]=="#")
for i in range(1,w):
dp[0][i]=dp[0][i-1] + (s[0][i-1]=="." and s[0][i]=="#")
for i in range(1,h):
dp[i][0]=dp[i-1][0] + (s[i-1][0]=="." and s[i][0]=="#")
for i in range(1,h):
for j in range(1,w):
cand1 = dp[i-1][j] + (s[i-1][j]=="." and s[i][j]=="#")
cand2 = dp[i][j-1] + (s[i][j-1]=="." and s[i][j]=="#")
dp[i][j]=min(cand1,cand2)
print(dp[-1][-1])
|
from collections import deque
H,W = map(int,input().split())
A = [input().strip() for _ in range(H)]
d = 0
if A[0][0]=="#":
d += 1
que = deque([(0,0,d)])
hist = [[H*W for _ in range(W)] for _ in range(H)]
hist[0][0] = d
while que:
i,j,d = que.popleft()
if j+1<W and A[i][j+1]==A[i][j]:
if hist[i][j+1]>d:
hist[i][j+1] = d
que.append((i,j+1,d))
elif j+1<W and A[i][j+1]!=A[i][j]:
if hist[i][j+1]>d+1:
hist[i][j+1] = d+1
que.append((i,j+1,d+1))
if i+1<H and A[i+1][j]==A[i][j]:
if hist[i+1][j]>d:
hist[i+1][j] = d
que.append((i+1,j,d))
elif i+1<H and A[i+1][j]!=A[i][j]:
if hist[i+1][j]>d+1:
hist[i+1][j] = d+1
que.append((i+1,j,d+1))
m = hist[H-1][W-1]
print((m+1)//2)
| 1 | 49,025,683,222,212 | null | 194 | 194 |
# パナソニック2020D
import sys
write = lambda x: sys.stdout.write(x+"\n")
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
s, m = q.pop()
if len(s)==n:
write(s)
elif len(s)>=n+1:
break
for o in range(ord("a"), ord(m)+2):
if ord(m)<o:
m = chr(o)
q.appendleft((s + chr(o), m))
|
n = int(input())
first_list = ['AC', 'WA', 'TLE', 'RE']
list = []
for _ in range(n):
list.append(input())
for i in first_list:
print(i, 'x', list.count(i))
| 0 | null | 30,703,647,081,288 | 198 | 109 |
N = int(input())
A = [int(i) for i in input().split()]
counter = 0
flag = 1 #????????£??\????´?????????¨??????
while flag:
flag = 0
for j in range(N-1, 0, -1):
if A[j] < A[j-1]:
v = A[j]
A[j] = A[j-1]
A[j-1] = v
flag = 1
counter += 1
print(' '.join([str(A[i]) for i in range(0, N)]))
print(counter)
|
def main():
N = int(input())
A = tuple(map(int, input().split()))
a = list(A)
ans, n = bubbleSort(a, N)
print(*ans, sep=' ')
print(n)
def bubbleSort(a, n):
j = 0
flag = 1
while flag:
flag = 0
for i in range(1, n):
if a[i] < a[i-1]:
a[i], a[i-1] = a[i-1], a[i]
flag = 1
j += 1
return a, j
main()
| 1 | 16,924,933,850 | null | 14 | 14 |
#16D8101023J 久保田凌弥 kubotarouxxx python3
x,y=map(int, input().split())
if x>y:
while 1:
if (x%y)==0:
print(y)
break
a=x%y
x=y
y=a
else:
while 1:
if (y%x)==0:
print(x)
break
a=y%x
y=x
x=a
|
K, N = map(int, input().split(' '))
A_ls = list(map(int, input().split(' ')))
max_dist = 0
for i in range(N):
nxt = (i + 1 ) % N
dist = A_ls[nxt] - A_ls[i]
if dist < 0:
dist += K
max_dist = max(max_dist, dist)
print(K - max_dist)
| 0 | null | 21,814,604,684,290 | 11 | 186 |
import math
def main():
n = int(input())
A = list(map(int, input().split()))
max_node = [0 for i in range(n+1)]
min_node = [0 for i in range(n+1)]
res = 0
for i in range(n, -1, -1):
if i == n:
max_node[i] = A[i]
min_node[i] = A[i]
elif i == 0:
max_node[i] = 1
min_node[i] = 1
elif i == 1 and n != 1:
max_node[i] = 2
min_node[i] = math.ceil(min_node[i+1] /2) + A[i]
else:
max_node[i] = max_node[i+1] + A[i]
min_node[i] = math.ceil(min_node[i+1] / 2) + A[i]
for i in range(n):
if i == 0:
if n != 0 and A[i] != 0:
res = -1
break
else:
if max_node[i] > 2 * (max_node[i-1] - A[i-1]):
max_node[i] = 2 * (max_node[i-1] - A[i-1])
if max_node[i] < min_node[i]:
res = -1
break
if res == -1:
print(res)
else:
if n == 0 and A[i] != 1:
print(-1)
else:
print(sum(max_node))
if __name__ == '__main__':
main()
|
n=int(input())
A=list(map(int,input().split()))
s=0
cap=[]
flag=False
for i,a in enumerate(A):
s*=2
s+=a
cap.append(min(2**i-s,(n+1-i)*10**8))
if s>2**i:
flag=True
break
if flag:
print(-1)
else:
remain=2**n-s
ans=0
node=0
for i in range(n,-1,-1):
a=A[i]
c=cap[i]
node=min(c,node)+a
ans+=node
print(ans)
| 1 | 18,730,518,837,788 | null | 141 | 141 |
while True:
string = input()
if string == "-":
break
else:
s = 0
for i in range(int(input())):
s += int(input())
s = s % len(string)
print(string[s:] + string[:s])
|
while True:
x=input()
if x == "-":
break
y=int(input())
for i in range(y):
z=int(input())
x=x[z:]+x[:z]
print(x)
| 1 | 1,899,454,506,582 | null | 66 | 66 |
st = input()
code = ord(st)
next_code = code + 1
print(chr(next_code))
|
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
s = input()
print(chr(ord(s)+1))
| 1 | 91,938,672,934,780 | null | 239 | 239 |
import math
a, b, c = map(float, input().split())
c = math.radians(c)
S = 0.5 * a * b * math.sin(c)
L = (a ** 2 + b ** 2 - 2 * a * b * math.cos(c)) ** 0.5 + a + b
h = S / a * 2
print(S)
print(L)
print(h)
|
from itertools import*
c=[f'{x} {y}'for x,y in product('SHCD',range(1,14))]
exec('c.remove(input());'*int(input()))
if c:print(*c,sep='\n')
| 0 | null | 616,198,345,052 | 30 | 54 |
nums = []
while True:
in_line = raw_input().split()
if int(in_line[0]) == 0 and int(in_line[1]) == 0:
break
nums.append([int(in_line[0]),int(in_line[1])])
for n in nums:
n.sort()
print n[0],
print n[1]
|
h,m,H,M,K=map(int,input().split())
pre=60*h+m
post=60*H+M
print(post-pre-K)
| 0 | null | 9,204,256,399,712 | 43 | 139 |
x=input()
if x[-1]==("s"):
print(x+"es")
elif x[-1]!=("s"):
print(x+"s")
|
a = input().split()
sum = 0
for n in a:
sum += int(n)
print('bust') if sum >= 22 else print('win')
| 0 | null | 60,852,983,201,700 | 71 | 260 |
N,A,B=map(int,input().split())
div=N//(A+B)
mod=N%(A+B)
print(div*A+min(mod,A))
|
n, a, b = map(int, input().split())
q = n // (a + b)
mod = n % (a + b)
if mod > a:
remain = a
else:
remain = mod
print(q * a + remain)
| 1 | 55,710,672,540,978 | null | 202 | 202 |
a,b,c,d,k=map(int,input().split())
A=60*a+b
B=60*c+d
print(B-A-k)
|
H1,M1,H2,M2,K = (int(x) for x in input().split())
print(H2*60+M2-H1*60-M1-K)
| 1 | 17,943,402,450,622 | null | 139 | 139 |
from math import gcd
def main():
a, b = map(int, input().split())
ans = a * b // gcd(a, b)
print(ans)
if __name__ == "__main__":
main()
|
aa, bb = map(int,input().split())
a = aa
b = bb
r = 0
# 最大公約数を求める
while 1:
a, b = max(a,b), min(a,b)
a = a % b
if a == 0:
r = b
break
print(aa//r*bb)
| 1 | 113,361,484,188,178 | null | 256 | 256 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n, m = map(int, readline().split())
if m % 2 == 0:
rem = m
for i in range(m // 2):
print(i + 1, m + 1 - i)
rem -= 1
if rem == 0:
return
for i in range(n):
print(m + 2 + i, 2 * m + 1 - i)
rem -= 1
if rem == 0:
return
else:
rem = m
for i in range((m - 1) // 2):
print(i + 1, m - i)
rem -= 1
if rem == 0:
return
for i in range(n):
print(m + 1 + i, 2 * m + 1 - i)
rem -= 1
if rem == 0:
return
if __name__ == '__main__':
main()
|
n,m = map(int,input().split())
if(n%2==1):
for i in range(1,m+1):
print(' '.join(map(str,[i,n+1-i])))
exit()
m1,m2 = (m+1)//2 ,m//2
sum1 = 1 + n//2
sum2 = (n//2+1) + (n-1)
for i in range(m1):
print(' '.join(map(str,[1+i,n//2 -i])))
for i in range(m2):
print(' '.join(map(str,[n//2+1+i,n-1-i])))
| 1 | 28,680,348,032,710 | null | 162 | 162 |
N, K = map(int, input().split())
A = N // K
B = N % K
if B > abs(B-K):
print(abs(B-K))
else:
print(B)
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
p = (a1 - b1) * t1
q = (a2 - b2) * t2
if p > 0:
p = -p
q = -q
if p + q == 0:
print('infinity')
elif p + q < 0:
print(0)
else:
print((-p // (p + q)) * 2 + bool(-p % (p + q)))
| 0 | null | 85,341,402,577,140 | 180 | 269 |
import sys
from collections import deque
def read():
return sys.stdin.readline().rstrip()
def main():
n, m, k = map(int, read().split())
friend = [[] for _ in range(n)]
block = [set() for _ in range(n)]
potential = [set() for _ in range(n)]
for _ in range(m):
a, b = [int(i) - 1 for i in read().split()]
friend[a].append(b)
friend[b].append(a)
for _ in range(k):
c, d = [int(i) - 1 for i in read().split()]
block[c].add(d)
block[d].add(c)
sd = set()
for u in range(n):
if u in sd:
continue
sn = deque([u])
pf = set()
while sn:
p = sn.pop()
if p in sd:
continue
sd.add(p)
pf.add(p)
for f in friend[p]:
sn.append(f)
for pfi in pf:
potential[pfi] = pf
print(*[len(potential[i]) - len(block[i] & potential[i]) - len(friend[i]) - 1 for i in range(n)])
if __name__ == '__main__':
main()
|
w, h, x, y, r= map(int, raw_input().split())
if (r <= x <= w-r) and (r <= y <= h - r):
print 'Yes'
else:
print 'No'
| 0 | null | 30,994,287,092,960 | 209 | 41 |
import sys
input = sys.stdin.readline
M1,D1 = map(int, input().split())
M2,D2 = map(int, input().split())
if(M1+1==M2):print(1)
else: print(0)
|
print(1*(input()[:2]!=input()[:2]))
| 1 | 124,156,009,327,140 | null | 264 | 264 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.