code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
N=int(input())
S=[]
T=[]
total=0
for i in range(N):
s,t=map(str,input().split())
t=int(t)
total+=t
S.append(s)
T.append(t)
X=input()
flag=True
a=0
j=0
while flag:
a+=T[j]
if S[j]==X:
flag=False
j+=1
print(total-a) | import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
def main():
N = int(input())
word = []
time = []
for _ in range(N):
a,b = input().split()
word.append(a)
time.append(int(b))
X = input()
s = -1
for i in range(N):
if word[i] == X:
s = i + 1
ans = sum(time[s:])
print(ans)
if __name__ == '__main__':
main() | 1 | 96,656,165,299,100 | null | 243 | 243 |
while 1:
m, f, r = map(int, raw_input().split())
if m == -1 and f == -1 and r == -1:
break
else:
if m == -1 or f == -1:
print 'F'
elif m+f >= 80:
print 'A'
elif m+f >= 65 and m+f < 80:
print 'B'
elif m+f >= 50 and m+f < 65:
print 'C'
elif m+f >= 30 and m+f < 50:
if r >= 50:
print 'C'
else:
print 'D'
else:
print 'F' | A=[]
while True:
#midterm exam score(50) : m
#final exam score(50) : f
#retest score(100) : r
m,f,r = [int(i) for i in input().split()]
if m == f == r == -1:
break
elif m==-1 or f==-1:
A.append('F')
elif m+f >= 80:
A.append('A')
elif 65<=m+f<80:
A.append('B')
elif (50<=m+f<65) or ((30<=m+f<50) and (50<=r)):
A.append('C')
elif (30<=m+f<50):
A.append('D')
else:
A.append('F')
for i in range(len(A)):
print(A[i]) | 1 | 1,211,636,369,460 | null | 57 | 57 |
from collections import deque
n = int(input())
x = input()
memo = {0: 0}
def solve(X):
x = X
stack = deque([])
while x:
if x in memo:
break
stack.append(x)
x = x % bin(x).count("1")
cnt = memo[x] + 1
while stack:
x = stack.pop()
memo[x] = cnt
cnt += 1
return cnt - 1
ans = []
px = x.count("1")
memo1 = [1 % (px - 1)] if px > 1 else []
memo2 = [1 % (px + 1)]
x1 = 0
x2 = 0
for i in range(n):
if px > 1:
memo1.append(memo1[-1] * 2 % (px-1))
memo2.append(memo2[-1] * 2 % (px+1))
for i in range(n):
if x[-i-1] == '1':
if px > 1:
x1 += memo1[i]
x1 %= (px-1)
x2 += memo2[i]
x1 %= (px+1)
for i in range(n):
if x[-i-1] == "1":
if px > 1:
ans.append(solve((x1-memo1[i])%(px-1)) + 1)
else:
ans.append(0)
else:
ans.append(solve((x2+memo2[i])%(px+1)) + 1)
for ansi in reversed(ans):
print(ansi)
| import sys
sys.setrecursionlimit(1000000)
N = int(input())
X = input()
pc = X.count('1')
if pc == 0:
print(*[1]*N, sep='\n')
exit()
elif pc == 1:
if int(X, 2) == 1:
for i in range(N-1):
print(2)
print(0)
exit()
else:
for i in range(N):
if i == N-1:
print(2)
elif X[i] == '0':
print(1)
else:
print(0)
exit()
mod_plus_1, mod_minus_1 = 0, 0
for i in range(N):
mod_plus_1 = (mod_plus_1*2+int(X[i])) % (pc+1)
mod_minus_1 = (mod_minus_1*2+int(X[i])) % (pc-1)
def f(x):
if x == 0:
return 0
else:
return f(x % bin(x).count('1'))+1
mods_p1, mods_m1 = [1 % (pc+1)], [1 % (pc-1)]
for i in range(N-1):
mods_p1.append(mods_p1[-1]*2 % (pc+1))
mods_m1.append(mods_m1[-1]*2 % (pc-1))
mods_p1 = mods_p1[::-1]
mods_m1 = mods_m1[::-1]
for i in range(N):
if X[i] == '0':
x = mod_plus_1 + mods_p1[i]
x %= (pc+1)
else:
x = mod_minus_1 - mods_m1[i]
x %= (pc-1)
if x == 0:
print(1)
else:
print(f(x)+1)
| 1 | 8,229,131,737,792 | null | 107 | 107 |
n,k=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(2*n):f+=[f[-1]*(i+1)%mod]
def comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod
ans=comb(2*n-1,n-1)
for i in range(n-1,k,-1):ans=(ans-comb(n,n-i)*comb(n-1,i))%mod
print(ans)
| n, k = map(int, input().split())
def modinv(a, mod=10**9+7):
return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
r = min(r, n-r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
def com(n, r, mod):
r = min(r, n - r)
if r == 0:
return 1
res = ilist[n] * iinvlist[n-r] * iinvlist[r] % mod
return res
mod = 10**9+7
ilist = [0]
iinvlist = [1]
tmp = 1
for i in range(1, n+1):
tmp *= i
tmp %= mod
ilist.append(tmp)
iinvlist.append(modinv(tmp, mod))
ans = 0
k = min(n-1, k)
for i in range(k+1):
tmp = com(n, i, mod)
tmp *= com(n-1, i, mod)
ans += tmp
ans %= mod
print(ans) | 1 | 67,346,748,324,648 | null | 215 | 215 |
x1, x2, x3, x4, x5 = map(int,input().split())
print(15-x1-x2-x3-x4-x5) | from collections import defaultdict, deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
cumA = [0] * (N + 1)
for i in range(1, N + 1):
cumA[i] = cumA[i - 1] + A[i - 1]
cnt = defaultdict(int)
que = deque([])
ans = 0
for i, c in enumerate(cumA):
while que and que[0][0] <= i - K:
cnt[que.popleft()[1]] -= 1
diff = (i - c) % K
ans += cnt[diff]
cnt[diff] += 1
que.append((i, diff))
print(ans) | 0 | null | 75,776,095,202,912 | 126 | 273 |
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
s = sum(a)
print('Yes' if len(list(filter(lambda x : x >= s * (1/(4*m)), a))) >= m else 'No') | n,m = map(int, input().split())
A = list(map(int, input().split()))
rank = sum(A) / (4*m)
cnt =0
for a in A:
cnt += rank <= a
if cnt >= m:
print('Yes')
else:
print('No') | 1 | 38,717,928,442,204 | null | 179 | 179 |
x = raw_input().split()
m = map(int,x)
a = m[0]
b = m[1]
if a > b:
print "a > b"
elif a < b:
print "a < b"
else:
print "a == b" | import sys
a, b = map(int, sys.stdin.readline().split())
if(a < b):
print("a < b")
elif(a > b):
print("a > b")
else:
print("a == b") | 1 | 357,830,552,108 | null | 38 | 38 |
# -*- coding: utf-8 -*-
def main():
import sys
input = sys.stdin.readline
a, b, c = map(int, input().split())
k = int(input())
count = 0
while True:
if a >= b:
b *= 2
count += 1
else:
break
while True:
if b >= c:
c *= 2
count += 1
else:
break
if count <= k:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| A,B = list(input().split())
A = int(A)
B = int((float(B)+0.005)*100)
print(A*B//100) | 0 | null | 11,836,513,082,820 | 101 | 135 |
def main():
n, k = map(int, input().split())
results = tuple(map(int, input().split()))
for i in range(n-k):
print('Yes' if results[i] < results[i+k] else 'No')
if __name__ == '__main__':
main()
| s = input()
if s == 'AAA':
print('No')
elif s == 'BBB':
print('No')
else:
print('Yes') | 0 | null | 31,039,122,311,402 | 102 | 201 |
import math
a,b,c = map(float,input().split())
H = b * math.sin(math.radians(c))
S = (a*(b*math.sin(math.radians(c))))/2
L = a + b + ((a**2) + (b**2) -(((2*a)*b)*math.cos(math.radians(c))))**0.5
print(float(S))
print(float(L))
print(float(H))
| #k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]
N = int(input())
seq = list(map(int, input().split()))
s = 0
for i in range(N):
s += seq[i]
s2 =0
for i in range(N):
s2 += seq[i]**2
s0 = (s**2 -s2)//2
print(s0%(10**9+7))
| 0 | null | 1,985,550,326,874 | 30 | 83 |
[n,m,l] = map(int, input().split())
a = []
b = []
c = [[0 for k in range(l)] for i in range(n)]
for i in range(n):
a.append(list(map(int, input().split())))
for j in range(m):
b.append(list(map(int, input().split())))
for i in range(n):
for k in range(l):
s = 0
for j in range(m):
s += a[i][j] * b[j][k]
c[i][k] = s
for i in range(n):
for k in range(l):
print(c[i][k],end='')
if k!= l-1:
print(' ',end='')
else:
print() | n,m,l=map(int,input().split())
e=[list(map(int,input().split()))for _ in[0]*(n+m)]
for c in e[:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])
| 1 | 1,418,561,432,288 | null | 60 | 60 |
def judge(m,f,r):
ret = 'F'
score = m + f
if -1 in (m,f): pass
elif score >= 80: ret = 'A'
elif score >= 65: ret = 'B'
elif score >= 50: ret = 'C'
elif score >= 30:
ret = 'D'
if r >= 50:ret = 'C'
return ret
while True:
m,f,r=map(int,input().split())
if m==f==r==-1: break
print(judge(m,f,r)) | while 1:
m,f,r=map(int, raw_input().split())
if m==f==r==-1: break
s=m+f
if m==-1 or f==-1 or s<30: R="F"
elif s>=80: R="A"
elif s>=65: R="B"
elif s>=50: R="C"
elif r>=50: R="C"
else: R="D"
print R | 1 | 1,230,985,598,080 | null | 57 | 57 |
numbers = []
while True:
x=int(input())
if x==0:
break
numbers.append(x)
for i in range(len(numbers)):
print("Case ",i+1,": ",numbers[i],sep="")
| # coding: utf-8
n = int(input())
R = [ int(input()) for i in range(n)]
MIN = R[0]
MAXdiff = R[1]-R[0]
for i in range(1,n):
MAXdiff = max(MAXdiff,R[i]-MIN)
MIN = min(MIN,R[i])
print(MAXdiff)
| 0 | null | 242,143,792,538 | 42 | 13 |
import numpy as np
MOD = 998244353
def main():
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = np.zeros((n+1, s+1), dtype=np.int64)
dp[0][0] = 1
for i in range(n):
dp[i][dp[i] >= MOD] %= MOD
dp[i+1] += dp[i]*2
if a[i] <= s:
dp[i+1][a[i]:] += dp[i][:-a[i]]
print(dp[n][s]%MOD)
if __name__ == "__main__":
main() | for a in range(1,10):
for b in range(1,10):
print(str(a)+"x"+str(b)+"="+str(a*b))
| 0 | null | 8,772,408,122,738 | 138 | 1 |
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") | # ()の問題は折れ線で捉えると良い
N = int(input())
ls = [] # 増減が正のもの(0を含む)
rs = [] # 増減が負のもの
tot = 0
for i in range(N):
s = input()
h = 0
b = 0
for c in s:
if c == "(":
h += 1
else:
h -= 1
b = min(b, h)
if h >= 0:
# 折れ線に対して上っていく奴ら
ls.append([b, h])
else:
# 折れ線に対して下っていく奴ら
# 右から(hから見るので、最下点は-hする)
rs.append([b-h, -h])
tot += h
ls.sort(key = lambda x:x[0], reverse=True)
rs.sort(key = lambda x:x[0], reverse=True)
def check(s):
h = 0
for p in s:
if h+p[0] < 0:
return False
h += p[1]
return True
if check(ls) and check(rs) and tot == 0:
print("Yes")
else:
print("No") | 1 | 23,577,211,084,900 | null | 152 | 152 |
N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
U = 10**12
L = -1
while U - L > 1:
x = (U+L)//2
cnt = 0
for i in range(N):
if x//F[i] < A[i]:
cnt += A[i] - x//F[i]
if cnt > K:
L = x
else:
U = x
print(U) | import sys
input = sys.stdin.readline
MI=lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
N,K=MI()
A=LI()
A.sort(reverse=True)
F=LI()
F.sort()
def check(x):
# x分以内に食べきれるための修行回数はK回以下か
k=0
for i in range(N):
k+=max(int(0--(A[i]-x//F[i])//1),0)
return k<=K
ok=10**13
ng=-1
while abs(ok-ng)>1:
mid=(ok+ng)//2
if check(mid):
ok=mid
else:
ng=mid
print(ok) | 1 | 164,722,887,752,710 | null | 290 | 290 |
a = input().split()
b = str(a[0])
c = str(a[1])
print(c+b) | while(True):
x, y = map(int, input().split())
if(x == y == 0):
break
if(x <= y):
print("%d %d" % (x, y))
else:
print("%d %d" % (y, x)) | 0 | null | 52,007,813,295,452 | 248 | 43 |
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
n = int(input())
A = list(map(int, input().split()))
xor = 0
for a in A:
xor ^= a
ans = [a ^ xor for a in A]
print(*ans)
resolve() | n = int(input())
a = list(map(int, input().split()))
def nim(x):
bx = [format(i,'030b') for i in x]
bz = ''.join([str( sum([int(bx[xi][i]) for xi in range(len(x))]) % 2) for i in range(30)])
return int(bz, 2)
nima = nim(a)
ans = [ str(nim([nima,aa])) for aa in a ]
print(' '.join(ans) ) | 1 | 12,487,636,766,880 | null | 123 | 123 |
import math
n,k = (int(x) for x in input().split())
An = [int(i) for i in input().split()]
left = 0
right = max(An)
def check(x):
chk = 0
for i in range(n):
chk += math.ceil(An[i]/x)-1
return chk
while right-left!=1:
x = (left+right)//2
if check(x)<=k:
right = x
else:
left = x
print(right) | def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
while True:
try:
a, b = map(int, raw_input().strip().split(' '))
print "%d %d" % (gcd(a, b), a*b/gcd(a, b))
except EOFError:
break | 0 | null | 3,238,887,028,818 | 99 | 5 |
from sys import stdin
input = stdin.readline
from time import time
from random import randint
from copy import deepcopy
start_time = time()
def calcScore(t, s, c):
scores = [0]*26
lasts = [0]*26
for i in range(1, len(t)):
scores[t[i]] += s[i][t[i]]
dif = i - lasts[t[i]]
scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2
lasts[t[i]] = i
for i in range(26):
dif = len(t) - lasts[i]
scores[i] -= c[i] * dif * (dif-1) // 2
return scores
def greedy(c, s):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
return socres, t
def subGreedy(c, s, t, day):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
if day <= i:
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
else:
scores[t[i]] += s[i][t[i]]
lasts[t[i]] = i
for j in range(26):
dif = i - lasts[j]
scores[j] -= c[j] * dif
return socres, t
def shuffle(t):
rng = len(t)//2
for _ in range(50):
idx = randint(1, rng)
t[idx], t[idx+1] = t[idx+1], t[idx]
return t
D = int(input())
c = list(map(int, input().split()))
s = [[0]*26 for _ in range(D+1)]
for i in range(1, D+1):
s[i] = list(map(int, input().split()))
scores, t = greedy(c, s)
t = shuffle(t)
scores = calcScore(t, s, c)
sum_score = sum(scores)
while time() - start_time < 1.86:
typ = randint(1, 100)
if typ <= 70:
for _ in range(100):
tmp_t = deepcopy(t)
tmp_t[randint(1, D)] = randint(0, 25)
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 97:
for _ in range(100):
tmp_t = deepcopy(t)
dist = randint(1, 15)
p = randint(1, D-dist)
q = p + dist
tmp_t[p], tmp_t[q] = tmp_t[q], tmp_t[p]
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 100:
tmp_t = deepcopy(t)
day = randint(D//4*3, D)
tmp_scores, tmp_t = subGreedy(c, s, tmp_t, day)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
for v in t[1:]:
print(v+1)
| while True:
a = input()
if "?" in a:
break
print(eval(a.replace("/", "//"))) | 0 | null | 5,209,018,689,464 | 113 | 47 |
from collections import deque
infinity=10**6
import sys
input = sys.stdin.readline
N,u,v = map(int,input().split())
u -= 1
v -= 1
G=[[] for i in range(N)]
for i in range(N-1):
A,B = map(int,input().split())
A -= 1
B -= 1
G[A].append(B)
G[B].append(A)
ends = []
for i in range(N):
if len(G[i]) == 1:
ends.append(i)
#幅優先探索
def BFS (s):
queue = deque()
d = [infinity]*N
queue.append(s)
d[s]= 0
while len(queue)!=0:
u = queue.popleft()
for v in G[u]:
if d[v] == infinity:
d[v] = d[u]+1
queue.append(v)
return d
d_nigeru = BFS(u)
d_oni = BFS(v)
ans=0
for u in ends:
if d_nigeru[u] < d_oni[u]:
ans = max(ans,d_oni[u]-1)
print(ans) | """
高橋君はとりあえず、青木君から最も遠い木の端を目指すのがベスト。
また、目指すべき木の端までの距離に関しては、高橋くんよりも自分の方が近くなくてはならない。
また、高橋君が捕まるときは、必ず木の端の一歩手前のノードになる。
つまり、青木君が移動しなくてはいけない最大距離は、高橋君が目指す木の端までの距離-1、ということになる。
とりま、高橋くん、青木君の初期位置から各ノードまでの距離を調べて、上記の条件にマッチする端を見つける。
"""
from collections import deque
N,u,v = map(int,input().split())
edges = [[] for _ in range(N+1)]
for _ in range(N-1):
a,b = map(int,input().split())
edges[a].append(b)
edges[b].append(a)
takahashi = [None]*(N+1)
que = deque([(0,u,0)])
while que:
step,cur,par = que.popleft()
takahashi[cur] = step
for nx in edges[cur]:
if nx == par:
continue
que.append((step+1,nx,cur))
aoki = [None]*(N+1)
que = deque([(0,v,0)])
while que:
step,cur,par = que.popleft()
aoki[cur] = step
for nx in edges[cur]:
if nx == par:
continue
que.append((step+1,nx,cur))
ans = 0
for i in range(1,N+1):
if takahashi[i] < aoki[i]:
ans = max(ans,aoki[i]-1)
print(ans) | 1 | 117,030,111,148,380 | null | 259 | 259 |
N,D = map(int, input().split())
XY = [map(int, input().split()) for _ in range(N)]
X,Y = [list(i) for i in zip(*XY)]
s=0
for i in range (N):
if X[i]*X[i]+Y[i]*Y[i]<=D*D:
s=s+1
print(s) | import numpy as np
from collections import Counter
def solve(string):
n, *a = map(int, string.split())
table = np.array([True] * (10**6 + 1))
ma = max(a)
for _a in a:
if table[_a]:
table[2*_a:ma + 1:_a]=False
i = np.array([k for k,v in Counter(a).items() if v==1],dtype=np.int)
return str(table[i].sum())
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 0 | null | 10,188,341,176,970 | 96 | 129 |
l=[]
for mark in ["S","H","C","D"]:
for i in range(1,14):
l.append(mark+" "+str(i))
n=input()
for i in range(int(n)):
l.remove(input())
for i in l:
print(i) | n = int(input())
full_set=set([x for x in range(1,14)])
cards={"S":[],"H":[],"C":[],"D":[]}
for i in range(n):
suit,num = input().split()
cards[suit].append(int(num))
for suit in ["S","H","C","D"]:
suit_set = set(cards[suit])
for num in sorted(list(full_set - suit_set)): print(suit,num) | 1 | 1,056,611,604,872 | null | 54 | 54 |
N = int(input())
div = 2
dic = {}
while div**2 <= N:
if N % div == 0:
count = 0
while N % div == 0:
N = N // div
count += 1
dic[div] = count
div += 1
if N != 1:
dic[N] = 1
ans = 0
for v in dic.values():
tmp = 1
while v >= tmp:
v -= tmp
tmp += 1
ans += 1
print(ans) | def find_primes(n):
ps = []
t = [True] * n
t[0] = t[1] = False
for i in range(2, n):
if not t[i]:
continue
ps.append(i)
for j in range(i, n, i):
t[j] = False
return ps
def solve(string):
n = int(string)
if n == 1:
return "0"
rn = int(n**0.5 + 1)
ps = find_primes(rn)
ans = 0
for i in ps:
k = 1
while n % (i**k) == 0:
ans += 1
n //= i**k
k += 1
return str(ans + (n >= rn))
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 1 | 16,845,044,125,764 | null | 136 | 136 |
### ----------------
### ここから
### ----------------
import sys
import math
from io import StringIO
import unittest
def yn(b):
print("Yes" if b==1 else "No")
return
def resolve():
readline=sys.stdin.readline
a,b,x=map(int, readline().rstrip().split())
if x <= a*a*b/2:
l = x*2/b/a
print(math.degrees(math.atan(b/l)))
return
l = (2*x)/(a*a)-b
print(math.degrees(math.atan((b-l)/a)))
#arr=list(map(int, readline().rstrip().split()))
#n=int(readline())
#ss=readline().rstrip()
#yn(1)
return
if 'doTest' not in globals():
resolve()
sys.exit()
### ----------------
### ここまで
### ---------------- | N=int(input())
print(len(set([input() for _ in range(N)]))) | 0 | null | 96,828,924,301,074 | 289 | 165 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, M = mapint()
S = list(input())
def solve():
now = N
choice = []
while 1:
if now==0:
return choice[::-1]
for m in range(M, 0, -1):
nx = now-m
if nx<0: continue
if S[nx]=='1': continue
now = nx
choice.append(m)
break
else:
return [-1]
print(*solve()) | n,m=map(int,input().split())
*s,=map(int,input()[::-1])
i=0
a=[]
while i<n:
j=min(n,i+m)
while s[j]:j-=1
if j==i:
print(-1)
exit()
a+=j-i,
i=j
print(*a[::-1]) | 1 | 138,736,540,742,804 | null | 274 | 274 |
G = [120001,60001,30001,15001,3001,901,601,301,91,58,31,7,4,1]
def insertion_sort(array,g):
for i in range(g,len(array)-1):
v = array[i]
j = i-g
while j>=0 and array[j] > v:
array[j+g] = array[j]
j = j-g
array[-1] += 1
array[j+g] = v
def shell_sort(array,G):
for i in G:
insertion_sort(array,i)
n = int(input())
arr = [int(input()) for i in range(n)] + [0]
Gn = [i for i in G if i <= n]
shell_sort(arr,Gn)
print(len(Gn))
print(' '.join([str(i) for i in Gn]))
print(arr[-1])
[print(i) for i in arr[:-1]] | # -*- coding:utf-8 -*-
import math
def insertion_sort(num_list, length, interval):
cnt = 0
for i in range(interval, length):
v = num_list[i]
j = i - interval
while j >= 0 and num_list[j] > v:
num_list[j+interval] = num_list[j]
j = j - interval
cnt = cnt + 1
num_list[j+interval] = v
return cnt
def shell_sort(num_list, length):
cnt = 0
h = 4
intervals = [1,]
while length > h:
intervals.append(h)
h = 3 * h + 1
for i in reversed(range(len(intervals))):
cnt = cnt + insertion_sort(num_list, length, intervals[i])
print(len(intervals))
show_list(intervals)
print(cnt)
def show_list(list):
i = len(list) - 1;
while i > 0:
print(list[i], end=" ")
i = i - 1
print(list[i])
input_num = int(input())
input_list = list()
for i in range(input_num):
input_list.append(int(input()))
shell_sort(input_list, input_num)
for num in input_list:
print(num) | 1 | 29,723,963,214 | null | 17 | 17 |
def answer(x: int) -> int:
dict = {500: 1000, 5: 5}
happiness = 0
for coin in sorted(dict, reverse=True):
q, x = divmod(x, coin)
happiness += dict[coin] * q
return happiness
def main():
x = int(input())
print(answer(x))
if __name__ == '__main__':
main() | X = int(input())
A = X // 500
B = X % 500
C = B // 5
ans = A * 1000 + C * 5
print(ans) | 1 | 42,657,789,059,090 | null | 185 | 185 |
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, t = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
res = 0
dp = [[0] * (t + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
a, b = AB[i - 1]
for j in range(1, t + 1):
if j - a >= 0:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a] + b)
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j])
now = dp[i - 1][t - 1] + b
res = max(res, now)
print(res)
if __name__ == '__main__':
resolve()
| # -*- coding: utf-8 -*-
modelmap = list(input())
S1 = []
S2 = []
A = 0
for i, l in enumerate(modelmap):
if l == "\\":
S1.append(i)
elif l == "/" and len(S1) > 0:
ip = S1.pop()
A += i - ip
L = i - ip
while len(S2) > 0 and S2[-1][0] > ip:
L += S2.pop()[1]
S2.append([ip, L])
print(A)
text2 = "{}".format(len(S2))
for s in S2:
text2 += " " + str(s[1])
print(text2) | 0 | null | 76,125,219,533,532 | 282 | 21 |
class Dice:
__slots__ = ['n1', 'n2', 'n3', 'n4', 'n5', 'n6']
def __init__(self, n_tup):
self.n1 = n_tup[0]
self.n2 = n_tup[1]
self.n3 = n_tup[2]
self.n4 = n_tup[3]
self.n5 = n_tup[4]
self.n6 = n_tup[5]
def roll(self, direction):
if direction == "N":
self.n1, self.n2, self.n6, self.n5 \
= self.n2, self.n6, self.n5, self.n1
elif direction == "E":
self.n1, self.n3, self.n6, self.n4 \
= self.n4, self.n1, self.n3, self.n6
if direction == "S":
self.n1, self.n2, self.n6, self.n5 \
= self.n5, self.n1, self.n2, self.n6
if direction == "W":
self.n1, self.n3, self.n6, self.n4 \
= self.n3, self.n6, self.n4, self.n1
dice = Dice([int(x) for x in input().split()])
cmd = input()
for i in range(len(cmd)):
dice.roll(cmd[i])
print(dice.n1) | class Dice:
def __init__(self,l1,l2,l3,l4,l5,l6):
self.l1 = l1
self.l2 = l2
self.l3 = l3
self.l4 = l4
self.l5 = l5
self.l6 = l6
self.top = 1
self.front = 2
self.right = 3
def get_top(self):
return eval("self." + 'l' + str(self.top))
def move(self, order):
if order == 'S':
pretop = self.top
self.top = 7 - self.front
self.front = pretop
elif order == 'E':
pretop = self.top
self.top = 7 - self.right
self.right = pretop
elif order == 'N':
pretop = self.top
self.top = self.front
self.front = 7 - pretop
elif order == 'W':
pretop = self.top
self.top = self.right
self.right = 7 - pretop
l = list(map(int,input().split()))
orders = input()
d = Dice(l[0],l[1],l[2],l[3],l[4],l[5])
for order in orders:
d.move(order)
print(d.get_top()) | 1 | 235,316,384,800 | null | 33 | 33 |
# -*- coding: utf-8 -*-
class Card:
def __init__(self, str):
self.suit = str[0]
self.value = int(str[1])
def __str__(self):
return self.suit + str(self.value)
def swap(A, i, j):
tmp = A[i]
A[i] = A[j]
A[j] = tmp
def BubbleSort(C, N):
for i in range(N):
for j in range(N-1, i, -1):
if C[j].value < C[j-1].value:
swap(C, j, j-1) # C[j] と C[j-1] を交換
def SelectionSort(C, N):
for i in range(N):
minj = i
for j in range(i, N):
if C[j].value < C[minj].value:
minj = j
swap(C, i, minj) # C[i] と C[minj] を交換
def isStable(A, B):
for i in range(1, len(B)):
if B[i-1].value == B[i].value:
for j in range(len(A)):
if A[j] == B[i-1]: break
if A[j] == B[i]: return False
return True
N = int(input())
A = [Card(t) for t in input().split()]
if len(A) != N: raise
B = A[:]
S = A[:]
BubbleSort(B, N)
SelectionSort(S, N)
print(' '.join(map(str, B)))
print('Stable' if isStable(A, B) else 'Not stable')
print(' '.join(map(str, S)))
print('Stable' if isStable(A, S) else 'Not stable')
| a,b,k=map(int,input().split())
if a>=k:
a-=k
elif a+b>=k:
b-=k-a
a=0
else:
a=0
b=0
print('{} {}'.format(a,b))
| 0 | null | 52,280,439,849,156 | 16 | 249 |
val = map(int, raw_input().split())
ans1 = val[0] / val[1]
ans2 = val[0] % val[1]
ans3 = format(val[0] / float(val[1]), '.5f')
print("{} {} {}".format(ans1, ans2, ans3)) | n = int(input())
dna = set()
for i in range(n):
command = input().split()
if command[0] == 'insert':
dna.add(command[1])
else:
print('yes' if command[1] in dna else 'no') | 0 | null | 336,420,629,710 | 45 | 23 |
n = int(input())
a = 0
for i in range(n+1):
if i%3== 0: continue
elif i%5 == 0:continue
elif i%3 ==0 and i %5 ==0:continue
else: a+=i
print(a) | # coding: utf-8
# Here your code !
import collections
s=int(input())
deq =collections.deque()
for i in range(s):
n=input().split()
if n[0]=="insert":
deq.appendleft(n[1])
elif n[0]=="delete":
try:
deq.remove(n[1])
except ValueError:
pass
elif n[0]=="deleteFirst":
deq.popleft()
elif n[0]=="deleteLast":
deq.pop()
print(" ".join(list(deq))) | 0 | null | 17,511,358,446,482 | 173 | 20 |
import sys
n=int(input())
s=[list(input()) for i in range(n)]
L1=[]
L2=[]
for i in range(n):
ct3=0
l=[0]
for j in s[i]:
if j=='(':
ct3+=1
l.append(ct3)
else:
ct3-=1
l.append(ct3)
if l[-1]>=0:
L1.append((min(l),l[-1]))
else:
L2.append((min(l)-l[-1],-l[-1]))
L1.sort()
L1.reverse()
ct4=0
for i in L1:
if ct4+i[0]<0:
print('No')
sys.exit()
ct4+=i[1]
L2.sort()
L2.reverse()
ct5=0
for i in L2:
if ct5+i[0]<0:
print('No')
sys.exit()
ct5+=i[1]
if ct4!=ct5:
print('No')
sys.exit()
print('Yes') | #!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
values = []
total = 0
open_chars = 0
close_chars = 0
for _ in range(int(input())):
s = input().strip()
open_required = len(s)
close_required = len(s)
open_close = 0
for i, c in enumerate(s):
if c == '(':
open_required = min(i, open_required)
open_close += 1
else:
close_required = min(len(s) - i - 1, close_required)
open_close -= 1
if open_required == 0 and close_required == 0 and open_close == 0:
continue
elif open_close == len(s):
open_chars += len(s)
continue
elif -open_close == len(s):
close_chars += len(s)
continue
total += open_close
values.append([open_required, close_required, open_close, 0])
if total + open_chars - close_chars != 0:
print('No')
return
fvals = values.copy()
bvals = values
fvals.sort(key=lambda x: (x[0], -x[2]))
bvals.sort(key=lambda x: (x[1], x[2]))
findex = 0
bindex = 0
while True:
while findex < len(fvals) and fvals[findex][3] != 0:
findex += 1
while bindex < len(bvals) and bvals[bindex][3] != 0:
bindex += 1
if findex >= len(fvals) and bindex >= len(bvals):
break
fvals[findex][3] = 1
bvals[bindex][3] = -1
values = [v for v in fvals if v[3] == 1] + [v for v in bvals if v[3] == -1][::-1]
open_close_f = 0
open_close_b = 0
for (oreq_f, _, ocval_f, _), (_, creq_b, ocval_b, _) in zip(values, values[::-1]):
if oreq_f > open_close_f + open_chars:
print('No')
return
if creq_b > open_close_b + close_chars:
print('No')
return
open_close_f += ocval_f
open_close_b -= ocval_b
print('Yes')
if __name__ == '__main__':
main()
| 1 | 23,698,589,621,980 | null | 152 | 152 |
h = int(input())
cnt = 0
ans = 0
while h > 1:
h = h//2
cnt += 1
ans += 2**cnt
print(ans+1) | h = int(input())
count = 0
ans = 0
while h > 0:
h //= 2
count += 1
for i in range(count):
ans = ans*2 + 1
print(ans) | 1 | 80,021,125,575,520 | null | 228 | 228 |
import math
result = 100000
for i in range(int(input())):
result *= 1.05
result = math.ceil(result/1000)*1000
print(result) | A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if not V > W:
print("NO")
elif (V-W)*T >= abs(B-A):
print("YES")
else:
print("NO")
| 0 | null | 7,491,122,229,320 | 6 | 131 |
#169D
#Div Game
n=int(input())
def factorize(n):
fct=[]
b,e=2,0
while b**2<=n:
while n%b==0:
n/=b
e+=1
if e>0:
fct.append([b,e])
b+=1
e=0
if n>1:
fct.append([n,1])
return fct
l=factorize(n)
ans=0
for i in l:
c=1
while i[1]>=c:
ans+=1
i[1]-=c
c+=1
print(ans) | from collections import Counter
n = int(input())
ans = 0
dp = []
cl = []
n1 = n
if n == 1:
ans = 0
else:
for i in range(2, int(n**0.5)+1):
if n%i == 0:
cl.append(i)
while n%i == 0:
n = n/i
dp.append(i)
if n == 1:
break
if n != 1:
ans = 1
c = Counter(dp)
for i in cl:
cnt = 1
while c[i] >= cnt:
c[i] -= cnt
ans += 1
cnt += 1
print(ans)
| 1 | 17,073,145,131,000 | null | 136 | 136 |
def solve(a, v, b, w, t):
return "YES" if 0 < (v-w) and abs(b-a) / (v-w) <= t else "NO"
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
print(solve(a, v, b, w, t)) | A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
diff = abs(A - B)
dspeed = V - W
if dspeed * T >= diff:
print("YES")
else:
print("NO")
| 1 | 15,224,480,056,850 | null | 131 | 131 |
if __name__ == "__main__":
while True:
score = [int(i) for i in input().split()]
if score[0] == score[1] == score[2] == -1:
break
if score[0] == -1 or score[1] == -1:
print ('F')
else:
if score[0] + score[1] >= 80:
print ('A')
elif score[0] + score[1] >= 65:
print ('B')
elif score[0] + score[1] >= 50:
print ('C')
elif score[0] + score[1] >= 30:
if score[2] == -1:
print ('D')
else:
if score[2] >= 50:
print ('C')
else:
print ('D')
else:
print ('F') | from collections import deque
n=int(input())
que=deque()
for i in range(n):
command=input()
if command=="deleteFirst":
que.popleft()
elif command=="deleteLast":
que.pop()
else:
command,num=command.split()
num=int(num)
if command=="insert":
que.appendleft(num)
else:
if num in que:
que.remove(num)
print(*que,sep=" ")
| 0 | null | 634,754,336,580 | 57 | 20 |
N, K = map(int,input().split())
mod = 10**9+7
gcd_num = [1]*(K+1)
for i in range(K//2, 0, -1):
gcd_num[i] = pow((K//i), N, mod)
for j in range(2, K//i + 1):
gcd_num[i] -= gcd_num[i*j]
gcd_num[i] = gcd_num[i]%mod
ans = 0
for i in range(1,K+1):
ans += i * gcd_num[i] % mod
print(ans%mod) | n,x,t=[int(i) for i in input().split()]
k=n//x
if n%x:
print((k+1)*t)
else:
print(k*t) | 0 | null | 20,633,549,702,360 | 176 | 86 |
n=int(input())
a=list(map(int,input().split()))
f={}
f2={}
for i in range(n):
z=i+a[i]
z1=i-a[i]
#print(z,z1)
try:
f[z]+=1
except:
f[z]=1
try:
f2[z1]+=1
except:
f2[z1]=1
s=0
for i in f.keys():
if(i in f2):
s+=f[i]*f2[i]
print(s)
| import math
n = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
p1 = 0
p2 = 0
p3 = 0
p4 = []
for i in range(n):
p1 += math.pow(abs(x[i]-y[i]),1)
for i in range(n):
p2 += math.pow(abs(x[i]-y[i]),2)
for i in range(n):
p3 += math.pow(abs(x[i]-y[i]),3)
for i in range(n):
p4.append(abs(x[i]-y[i]))
print(p1)
print(math.sqrt(p2))
print(math.pow((p3),1/3))
print(max(p4))
| 0 | null | 13,069,011,807,208 | 157 | 32 |
n,m=map(int,input().split())
s=input()
res=[]
now=n
while now!=0:
j=False
for i in range(max(0,now-m),now):
if s[i]=="0":
j=True
res.append(now-i)
now=i
break
if not j:
print(-1)
exit()
for i in range(len(res)-1,-1,-1):
print(res[i],end=" ") | x, y = map(int, input().split())
a = max(x, y)
b = min(x, y)
while a%b != 0:
temp = a
a = b
b = temp%b
print(b) | 0 | null | 69,242,800,166,080 | 274 | 11 |
n = int(input())
a = list(map(int,input().split()))
maxketa = max([len(bin(a[i])) for i in range(n)])-2
mod = 10**9+7
ans = 0
for i in range(maxketa):
ones = 0
for j in range(n):
if (a[j] >> i) & 1:
ones += 1
ans = (ans + (n-ones)*ones*(2**i)) % mod
print(ans) | x1, x2, y1, y2 = map(float, input().split())
ans = ((x1 - y1)**2 + (x2 - y2)**2)**0.5
print("{:.5f}".format(ans)) | 0 | null | 61,454,225,557,232 | 263 | 29 |
n, m, k = map(int, input().split(" "))
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
A = [0]
B = [0]
for i in a:
if A[-1] > k:
break
A.append(A[-1] + i)
for i in b:
if B[-1] > k:
break
B.append(B[-1] + i)
ans = 0
j = len(B) - 1
for i in range(len(A)):
if A[i] > k:
break
while A[i] + B[j] > k:
j -= 1
ans = max(ans, i + j)
print(ans)
| import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n, m, k = map(int, readline().rstrip().split())
A = list(map(int, readline().rstrip().split()))
B = list(map(int, readline().rstrip().split()))
a, b = [0], [0]
for i in range(n):
a.append(a[i] + A[i])
for i in range(m):
b.append(b[i] + B[i])
ans = 0
j = m
for i in range(n + 1):
if a[i] > k:
break
while b[j] > k - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == '__main__':
main()
| 1 | 10,702,267,319,710 | null | 117 | 117 |
n, r= input().split()
n, r= int(n), int(r)
eq=r
if n < 10:
eq=0
eq= r+(100*(10-n))
print(eq)
| n, dr = list(map(int, input().split()))
if n >= 10:
print(dr)
else:
print(dr+(100*(10-n))) | 1 | 63,315,949,394,140 | null | 211 | 211 |
n = input()
digit1 = int(n[-1])
ans = ''
if digit1 in {2, 4, 5, 7, 9}:
ans = 'hon'
elif digit1 in {0, 1, 6, 8}:
ans = 'pon'
elif digit1 in {3}:
ans = 'bon'
print(ans)
| N = int(input())
N = N % 10
if N == 2 or N == 4 or N == 5 or N == 7 or N ==9 :
print("hon")
elif N == 0 or N == 1 or N == 6 or N == 8 :
print("pon")
elif N == 3 :
print("bon") | 1 | 19,098,093,726,598 | null | 142 | 142 |
n = int(raw_input())
A = map(int, raw_input().strip().split(' '))
q = int(raw_input())
M = map(int, raw_input().strip().split(' '))
S = [0]*len(A)
flags = [False]*len(M)
def brute_force(n):
if n == len(S):
ans = 0
for i in range(len(S)):
if S[i] == 1: ans += A[i]
for i in range(len(M)):
if ans == M[i]: flags[i] = True
else:
S[n] = 0
brute_force(n+1)
S[n] = 1
brute_force(n+1)
brute_force(0)
for flag in flags:
if flag: print "yes"
else: print "no" | a,b,c=input().split();print(c,a,b) | 0 | null | 19,091,146,553,138 | 25 | 178 |
from sys import stdin
lis = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
S = input()
k = 0
for i in range(7):
if lis[i] == S:
k = i
print(7 - k)
| youbi = ['SUN','MON','TUE','WED','THU','FRI','SAT']
y = input()
for i in range(7):
if y == youbi[i]:
print(7-i) | 1 | 132,968,905,690,070 | null | 270 | 270 |
import re
data = input().split()
stack = []
for elem in data:
if re.match('\d+', elem):
stack.append(int(elem))
else:
a = stack.pop()
b = stack.pop()
if elem == "+":
stack.append(b+a)
elif elem == "-":
stack.append(b-a)
elif elem == "*":
stack.append(b*a)
print(stack[0]) | from sys import stdin
def main():
#入力
readline=stdin.readline
n=int(readline())
dp=[0]*(n+1)
for i in range(n+1):
if i==0 or i==1:
dp[i]=1
else:
dp[i]=dp[i-1]+dp[i-2]
print(dp[n])
if __name__=="__main__":
main()
| 0 | null | 20,141,935,362 | 18 | 7 |
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# b,r = map(str, readline().split())
# A,B = map(int, readline().split())
br = LS()
AB = LI()
U = _S()
def main():
brAB = zip(br, AB)
tmp=[]
for c,n in brAB:
if c==U:
tmp.append(n - 1)
else:
tmp.append(n)
return str(tmp[0])+' '+str(tmp[1])
print(main())
| N, M = map(int, input().split())
L = [list(input().split()) for _ in range(M)]
D_1 = {str(c):False for c in range(1, N+1)}
D_2 = {str(c):0 for c in range(1, N+1)}
for l in L:
if l[1]=="WA" and D_1[l[0]]==False:
D_2[l[0]] += 1
else:
D_1[l[0]]=True
S_1 = sum(D_2[k] for k, v in D_1.items() if v)
S_2 = sum(D_1.values())
print(S_2, S_1) | 0 | null | 82,644,798,286,460 | 220 | 240 |
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba
def run():
H, N = map(int, sysread().split())
AB = list(map(int, read().split()))
A = AB[::2]
B = AB[1::2]
Amax = max(A)
INF = float('inf')
dp = [[INF] * (H+Amax+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
for j in range(H+Amax+1):
tmp = j - A[i]
if tmp >= 0:
dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
elif j == H and tmp < 0:
dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
else:
dp[i+1][j] = dp[i][j]
ret = min(dp[N][H:])
print(ret)
if __name__ == "__main__":
run() | h, n = map(int, input().split())
magics = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a,b in magics)
dp = [0] * (h+max_a)
for i in range(1,h+max_a):
dp[i] = min(dp[i-a]+b for a, b in magics)
print(dp[h]) | 1 | 80,997,017,081,340 | null | 229 | 229 |
import heapq
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
L = []
ans = 0
heapq.heappush(L, -A[0])
for i in range(1, N):
max = heapq.heappop(L)
max *= -1
ans += max
heapq.heappush(L, -A[i])
heapq.heappush(L, -A[i])
print(ans)
| n = int(input())
ls = list(map(int,input().split()))
ls.sort(reverse=True)
p = len(ls)
if len(ls)%2 == 1:
p += 1
p //= 2
q = 0
for i in range(1,p+1):
if i == 1:
q += ls[0]
else:
if i == p:
if len(ls)%2 == 1:
q += ls[p-1]
else:
q += 2*ls[p-1]
else:
q += 2*ls[i-1]
print(q) | 1 | 9,191,061,931,102 | null | 111 | 111 |
n = int(input())
ans = int(n/2) + n%2
print(ans) | def count_(n):
cnt = 0
k = 1
while(n-k >= 0):
n = n - k
k = k + 1
cnt = cnt + 1
return cnt
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
if __name__ == '__main__':
n = int(input())
s_li = (factorization(n))
if s_li[0][0] == 1:
print(0)
else:
ans = 0
for s_ in s_li:
ans = ans + count_(s_[1])
print(ans) | 0 | null | 38,070,730,486,868 | 206 | 136 |
ans = 0
for i in xrange(input()):
n = int(raw_input())
if n <= 1:
continue
j = 2
while j*j <= n:
if n%j == 0:
break
j += 1
else:
ans += 1
print ans | #!/usr/bin/env python3
def main():
A, B = map(int, open(0).read().split())
if (A < 10 and B < 10):
print(A * B)
else:
print('-1')
main() | 0 | null | 78,975,331,609,960 | 12 | 286 |
seq = int(input())
a = int(10**9 + 7)
answer = (10**seq - 9**seq - 9**seq + 8**seq)%a
print(answer) | n=int(input())
num=10**n-9**n-9**n+8**n
ans=num%(10**9+7)
print(ans) | 1 | 3,171,442,100,034 | null | 78 | 78 |
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
for j in range(N):
for k in range(N):
if i < j < k and L[i] < L[j] < L[k] and L[i] + L[j] > L[k]:
ans += 1
print(ans)
| N,K = map(int,input().split())
A = [int(a) for a in input().split()]
n = 0
for i in range(K,N):
if A[i] > A[n] :
print("Yes")
else:
print("No")
n+=1
| 0 | null | 6,126,922,396,910 | 91 | 102 |
a,b,x=list(map(int,input().split()))
import math
x=x/a
if a*b/2<x:
print(math.degrees(math.atan(2*(a*b-x)/a**2)))
else:
print(math.degrees(math.atan(b**2/(2*x)))) | from sys import stdin
input = stdin.readline
import math
from functools import lru_cache
MOD = 10**9 + 7
@lru_cache(None)
def fac(n):
return math.factorial(n)
def comb(k,n):
return fac(n)//fac(k)//fac(n-k)
def solve():
s = int(input())
if s < 3:
print(0)
return
maxn = s // 3
res = 0
for i in range(1,s//3 + 1):
res += (comb(i-1,s-2*i-1))%MOD
print(res%MOD)
if __name__ == '__main__':
solve()
| 0 | null | 83,360,343,913,880 | 289 | 79 |
def ins(A,N):
for i in range(N):
v=A[i]
j=i-1
while j>=0 and A[j]>v:
A[j+1]=A[j]
j-=1
A[j+1]=v
for k in range(len(A)):
if k==len(A)-1:
print(A[k])
else:
print(A[k],end=" ")
N=int(input())
A=list(map(int,input().split(" ")))
ins(A,N) | class Dice:
def __init__(self, state):
self.state = state
def vertical(self, direction):
s = self.state
state = [s[1], s[5], s[0], s[4]]
if direction < 0:
s[0], s[1], s[4], s[5] = state
elif 0 < direction:
s[0], s[1], s[4], s[5] = reversed(state)
return self
def lateral(self, direction):
s = self.state
state = [s[2], s[5], s[0], s[3]]
if direction < 0:
s[0], s[2], s[3], s[5] = state
elif 0 < direction:
s[0], s[2], s[3], s[5] = reversed(state)
return self
def north(self):
self.vertical(-1)
return self
def south(self):
self.vertical(1)
return self
def east(self):
self.lateral(1)
return self
def west(self):
self.lateral(-1)
return self
init_state = input().split()
for i in range(int(input())):
dice = Dice(init_state)
up, front = input().split()
if up == dice.state[0] \
and front == dice.state[1]:
print(dice.state[2])
else:
for c in list('NNNNWNNNWNNNENNNENNNWNNN'):
if c == 'N':
dice.north()
elif c == 'S':
dice.south()
elif c == 'W':
dice.west()
elif c == 'E':
dice.east()
if up == dice.state[0] \
and front == dice.state[1]:
print(dice.state[2])
break
| 0 | null | 134,629,801,920 | 10 | 34 |
n, k = list(map(int, input().split()))
# 先頭に0番要素を追加すれば、配列の要素番号と入力pが一致する
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))
ans = -float('inf')
# 開始ノードをsi
for si in range(1, n+1):
# 閉ループのスコアを取り出す
x = si
s = list() # ノードの各スコアを保存
#s_len = 0
tot = 0 # ループ1周期のスコア
while 1:
x = p[x]
s.append(c[x])
#s[s_len] = c[x]
#s_len += 1
tot += c[x]
if (x == si): break # 始点に戻ったら終了
# siを開始とする閉ループのスコア(s)を全探
s_len = len(s)
t = 0
for i in range(s_len):
t += s[i] # i回移動したときのスコア
if (i+1 > k): break # 移動回数の上限を超えたら終了
# 1周期のスコアが正ならば、可能な限り周回する
if tot > 0:
e = (k-(i+1))//s_len # 周回数
now = t + tot*e # i回移動と周回スコアの合計
else:
now = t
ans = max(ans, now)
print(ans)
| import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def end_of_loop():raise StopIteration
def main():
N, K = MI()
P = LI()
C = LI()
#1週下再に加算されるスコア並びにあるますから出発した際に1マス進んだ際のスコアがわかればよい。
#初期化
ans = []
result = -float('inf')
#開始点
for i in range(N):
result2= 0
# start
temp = i
d = [-float('inf')] * N
for j in range(N):
temp = P[temp]-1
result2+=C[temp]
d[j] = result2
if temp == i:
index = j+1
score = result2
if index < K:
amari = K % index
syou = K // index
if amari !=0:
result = max(result, syou*score, syou*score+max(d[0:amari]), (syou-1)*score+max(d[0:index-1]), max(d), (syou-1)*score+max(d[0:index-1]))
else:
result = max(result, syou*score, max(d), (syou-1)*score+max(d[0:index-1]))
break
else:
result = max(result, max(d[0:K]))
break
print(result)
if __name__ == "__main__":
main() | 1 | 5,387,198,786,008 | null | 93 | 93 |
import math
n = int(input())
a = list(map(int,input().split()))
MAX = 1000005
is_prime = [1]*MAX
D = [None]*MAX
is_prime[0],is_prime[1] = 0,0
for i in range(2,MAX):
if is_prime[i]:
D[i] = i
for j in range(i*2,MAX,i):
is_prime[j] = 0
D[j] = i
counts = [0]*MAX
pair = True
for a_i in a:
if a_i == 1:
continue
pf = {}
while True:
p = D[a_i]
if counts[p]>0:
pair = False
pf[p] = pf.get(p,0)+1
if p == a_i:
break
else:
a_i //= p
for p in pf.keys():
counts[p] += 1
if pair:
print('pairwise coprime')
else:
g = a_i
for a_i in a:
g = math.gcd(a_i,g)
if g == 1:
print('setwise coprime')
else:
print('not coprime') | # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
def sum_count(arr):
mem = arr[:]
while True:
if len(mem) == 1:break
tmp = []
while True:
if len(mem) == 1:
tmp.append(mem[-1])
mem = tmp[:]
break
if len(mem) == 0:
mem = tmp[:]
break
x1, x2 = mem.pop(), mem.pop()
tmp.append(int(x1) + int(x2))
return int(mem[0])
def run():
N = int(input())
X = list(input())[::-1]
lis_bf = []
lis_af = []
count1 = sum_count(X)
sum_val_bf, sum_val_af = 0, 0
if count1 <= 1:
for i in range(N):
tmp_af = 0
if int(X[i]):
tmp_af = pow(2, i, count1 + 1)
lis_af.append(tmp_af)
sum_val_af += tmp_af
sum_val_af %= count1 + 1
for i in list(range(N))[::-1]:
ans = 0
if X[i] == '1':
print(0)
continue
else:
next_val = (sum_val_af + pow(2, i, count1 + 1)) % (count1 + 1)
# print(next_val)
ans += 1
# print(f'i : {i}, next_val : {next_val}')
while True:
if next_val == 0: break
val = next_val
count_n = sum_count(list(bin(val)[2:]))
next_val = val % count_n
ans += 1
# print(f'next_val : {next_val}')
print(ans)
return None
for i in range(N):
tmp_bf, tmp_af = 0,0
if int(X[i]):
tmp_bf = pow(2, i , count1-1)
tmp_af = pow(2, i, count1+1)
lis_bf.append(tmp_bf)
lis_af.append(tmp_af)
sum_val_bf += tmp_bf
sum_val_bf %= count1-1
sum_val_af += tmp_af
sum_val_af %= count1 + 1
for i in list(range(N))[::-1]:
ans = 0
if X[i] == '1':
next_val = (sum_val_bf - lis_bf[i]) % (count1-1)
else:
next_val = (sum_val_af + pow(2, i, count1+1)) % (count1+1)
#print(next_val)
ans += 1
#print(f'i : {i}, next_val : {next_val}')
while True:
if next_val == 0:break
val = next_val
count_n = sum_count(list(bin(val)[2:]))
next_val = val % count_n
ans += 1
#print(f'next_val : {next_val}')
print(ans)
if __name__ == "__main__":
run()
| 0 | null | 6,128,290,181,690 | 85 | 107 |
n,m,l = map(int,input().split())
a = [[0 for i2 in range(m)] for i1 in range(n)]
b = [[0 for i2 in range(l)] for i1 in range(m)]
for i in range(n):
row = list(map(int,input().split()))
for j in range(m):
a[i][j] = row[j]
for i in range(m):
row = list(map(int,input().split()))
for j in range(l):
b[i][j] = row[j]
c = [[0 for i2 in range(l)] for i1 in range(n)]
for i in range(n):
for j in range(l):
for k in range(m):
c[i][j] += a[i][k]*b[k][j]
for i in range(n):
for j in range(l-1):
print(c[i][j],end = ' ')
print(c[i][-1]) | d,t,s = map(float,input().split())
if t >= d/s:
print("Yes")
else:
print("No") | 0 | null | 2,471,720,099,826 | 60 | 81 |
n=int(input())
a=list(map(int,input().split()))
l=[3]+[0]*(10**5)
m=10**9+7
x=1
for i in a:
if l[i]:
x=(x*l[i])%m
l[i]-=1
l[i+1]+=1
else:
x=0
break
print(x) | n=int(input())
an=0
for j in range(1,n):
an+=int((n-1)/j)
print(an) | 0 | null | 66,665,279,906,628 | 268 | 73 |
n = int(input())
data=[list(input().split()) for _ in range(n)]
s = input()
ans = 0
c = False
for i in range(n):
if c:
ans += int(data[i][1])
if data[i][0] == s:
c = True
print(ans) | N=int(input())
p=[list(map(str,input().split())) for _ in range(N)]
X=input()
flag=0
cnt=0
for i in range(N):
if flag==1:
cnt=cnt+int(p[i][1])
if p[i][0]==X:
flag=1
print(cnt) | 1 | 97,178,473,953,702 | null | 243 | 243 |
def selectionSort(A,N):
count = 0
for i in range(0,N-1):
minj = i
for j in range(i+1,N):
if A[j] < A[minj]:
minj = j
tmp = A[minj]
A[minj] = A[i]
A[i] = tmp
if i != minj:
count += 1
return A,count
N = int(input())
A = list(map(int,input().split(' ')))
A,count = selectionSort(A,N)
for i in range(len(A)): # output
if i == len(A) - 1:
print(A[i])
else:
print(A[i], end=' ')
print(count) | n=int(input())
c=0
a=list(map(int,input().split()))
for i in range(n):
m=i
for j in range(i,n):
if a[m]>a[j]:m=j
if i!=m:a[m],a[i]=a[i],a[m];c+=1
print(*a)
print(c) | 1 | 20,698,827,732 | null | 15 | 15 |
n = int(input())
sumOfN = sum(int(i) for i in list(str(n)))
print("No" if sumOfN%9 else "Yes") | A = list(map(int,input().split()))
B = list(map(int,input().split()))
T = int(input())
distance = abs(A[0] - B[0])
A[1] = A[1] * T
B[1] = B[1] * T
if distance <= (A[1] - B[1]):
print('YES')
else:
print('NO') | 0 | null | 9,817,591,956,380 | 87 | 131 |
n=int(input())
num=[1,1]
for i in range(43):
b=(num[-2])+(num[-1])
num.append(b)
print(num[(n)])
| def solve(n):
if n <= 1:
print(1)
return
a, b = 1, 1
for _ in range(2, n + 1):
c = a + b
b = a
a = c
print(c)
if __name__ == "__main__":
n = int(input())
solve(n)
| 1 | 1,499,813,578 | null | 7 | 7 |
import math
n, d, a = map(int,input().split())
e = [[] for i in range(n)]
for i in range(n):
x, h = map(int,input().split())
e[i] = [x,h]
num = 0
e.sort()
sd = [0 for i in range(n)]
l = [i for i in range(n)]
for i in range(n):
for j in range(l[i-1],i):
if e[i][0]-e[j][0] <= 2*d:
l[i] = j
break
for i in range(n):
res = e[i][1] - sd[i-1] + sd[l[i]-1]
if res < 0:
sd[i] = sd[i-1]
else:
k = math.ceil(res/a)
sd[i] = sd[i-1]+k*a
num += k
print(num)
| while 1:
r=0
S=0
n=int(input())
if n==0:break
s=list(map(int,input().split()))
a=(sum(s)/n)
for i in s:
S=((a-i)**2)/n
r+=S
print(r**0.5) | 0 | null | 41,039,802,160,972 | 230 | 31 |
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
print(1 if M2 == M1 + 1 and D2 == 1 else 0) | st = input().split(' ')
print(st[1]+st[0]) | 0 | null | 113,815,800,704,332 | 264 | 248 |
import sys
# import bisect
# import numpy as np
# from collections import deque
from collections import deque
# map(int, sys.stdin.read().split())
# import heapq
import bisect
import math
def input():
return sys.stdin.readline().rstrip()
def main():
N =int(input())
S = input()
pre ="A"
count=0
for i in S:
if i !=pre:
count+=1
pre = i
print(count)
if __name__ == "__main__":
main()
| s=input()
l=[ "SUN","MON","TUE","WED","THU","FRI","SAT"]
ind=l.index(s)
if ind==0:
print(7)
else:
print(7-ind) | 0 | null | 152,226,520,500,008 | 293 | 270 |
def main():
K, X = map(int, input().split())
print('Yes' if 500 * K >= X else 'No')
if __name__ == "__main__":
main()
| import itertools
import math
import fractions
import functools
k, x = map(int, input().split())
if 500*k >= x:
print("Yes")
else:
print("No") | 1 | 98,100,656,561,362 | null | 244 | 244 |
a,b,c = [int(i) for i in input().split()]
print("Yes" if(a * a + b * b + c * c - 2 * a * b - 2 * b * c - 2 * c * a > 0 and c - a - b > 0) else "No") | def mod_pow(a, n):
res = 1
while n > 0:
if n & 1:
res = res * a % mod
a = a * a % mod
n >>= 1
return res
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
cnt = [0] * 60
for v in a:
for i in range(60):
if (v >> i) & 1:
cnt[i] += 1
pow_2 = [1]
for i in range(60):
pow_2.append(pow_2[-1] * 2 % mod)
res = 0
for v in a:
for i in range(60):
if (v >> i) & 1:
res = (res + (n - cnt[i]) * pow_2[i] % mod) % mod
else:
res = (res + cnt[i] * pow_2[i] % mod) % mod
print(res * mod_pow(2, mod - 2) % mod) | 0 | null | 87,356,450,375,018 | 197 | 263 |
from math import pi
r = float(input())
print (format(r**2*pi, '.6f'),format(r*pi*2, '.6f')) | pi = 3.141592653589793
r = float(input())
print('{0:f} {1:f}'.format(r*r*pi, 2 * r * pi)) | 1 | 648,651,764,852 | null | 46 | 46 |
x = int(input())
a = 0
b = 0
flg = True
while True:
a += 1
for i in range(a):
if a**5 - i**5 == x:
a = a
b = i
flg = False
break
elif a**5 + i**5 == x:
a = a
b = -i
flg = False
break
if flg == False:
break
a = str(a)
b = str(b)
print(a+' '+b) | def main():
X = int(input())
for i in range(-1000, 1000):
for j in range(-1000, 1000):
if i ** 5 - j ** 5 == X:
print(i, j)
return
main()
| 1 | 25,577,133,939,780 | null | 156 | 156 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
n, *a = map(int, read().split())
p = np.array(a)
minp = np.minimum.accumulate(p)
r = np.count_nonzero(minp >= p)
print(r)
if __name__ == '__main__':
main() |
def resolve():
MOD = 1000000007
N = int(input())
A = list(map(int, input().split()))
C = [0]*(N+1)
C[0] = 3
ans = 1
for i in range(N):
a = A[i]
ans *= C[a]
ans %= MOD
C[a] -= 1
C[a+1] += 1
print(ans)
if __name__ == "__main__":
resolve() | 0 | null | 108,335,842,230,790 | 233 | 268 |
import sys
input = sys.stdin.buffer.readline
def main():
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
l = (A1-B1)*T1 + (A2-B2)*T2
if l == 0:
print("infinity")
elif l > 0:
if A1 > B1:
print(0)
else:
d = (B1-A1)*T1
if d%l == 0:
ans = 2*(d//l)
else:
ans = 1+2*(d//l)
print(ans)
else:
l *= -1
if B1 > A1:
print(0)
else:
d = (A1-B1)*T1
if d%l == 0:
ans = 2*(d//l)
else:
ans = 1+2*(d//l)
print(ans)
if __name__ == "__main__":
main()
| T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2
if SA == SB or A1 == B1:
print('infinity')
exit()
if SA > SB and A1 < B1:
M = (B1 - A1) * T1
d = SA - SB
cnt = M // d
ans = cnt * 2
if M % d != 0:
ans += 1
print(max(0, ans))
elif SB > SA and B1 < A1:
M = (A1 - B1) * T1
d = SB - SA
cnt = M // d
ans = cnt * 2
if M % d != 0:
ans += 1
print(max(0, ans))
else:
print(0)
| 1 | 131,516,529,023,428 | null | 269 | 269 |
import sys
R, C, K = map(int, sys.stdin.readline().split())
grid = [[0 for _ in range(C)] for _ in range(R)]
for _ in range(K):
r, c, v = map(int, sys.stdin.readline().split())
grid[r-1][c-1] = v
# r行目、c列目にいるときに、その行でアイテムをi個取得している場合の最大価値
dp0 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp1 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp2 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp3 = [[0 for _ in range(C+1)] for _ in range(R+1)]
# print(dp)
for r in range(R):
for c in range(C):
# 取らない
dp0[r+1][c] = max((dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]))
dp1[r][c+1] = max(dp1[r][c], dp1[r][c])
dp2[r][c+1] = max(dp2[r][c], dp2[r][c])
dp3[r][c+1] = max(dp3[r][c], dp3[r][c])
if grid[r][c] == 0:
continue
# 取る
dp0[r+1][c] = max(dp0[r][c] + grid[r][c], dp0[r+1][c])
dp0[r+1][c] = max(dp1[r][c] + grid[r][c], dp0[r+1][c])
dp0[r+1][c] = max(dp2[r][c] + grid[r][c], dp0[r+1][c])
dp1[r][c+1] = max(dp0[r][c] + grid[r][c], dp1[r][c+1])
dp2[r][c+1] = max(dp1[r][c] + grid[r][c], dp2[r][c+1])
dp3[r][c+1] = max(dp2[r][c] + grid[r][c], dp3[r][c+1])
# print(dp0)
# print(dp1)
# print(dp2)
# print(dp3)
# print(max((dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])))
print(dp0[R][C-1]) | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
def solve(N: int, A: "List[int]"):
c = collections.Counter(A+[i+1 for i in range(N)])
return "\n".join([f'{c[i+1]-1}' for i in range(N)])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N - 2 + 1)] # type: "List[int]"
print(solve(N, A))
if __name__ == '__main__':
main()
| 0 | null | 19,162,897,312,910 | 94 | 169 |
def isPrime(num):
if num <= 1:
return False
elif num == 2 or num == 3:
return True
elif num % 2 == 0:
return False
else:
count = 3
while True:
if num % count and count ** 2 <= num:
count += 2
continue
elif num % count == 0:
return False
else:
break
return True
if __name__ == '__main__':
count = 0
N = int(input())
for i in range(N):
i = int(input())
if isPrime(i):
count += 1
print(count)
| import math
pi=math.pi
r = int(input().strip())
print(2*r*pi) | 0 | null | 15,581,586,919,628 | 12 | 167 |
x , y = map(int,input().split())
def GCD(x,y):
while y > 0:
x ,y = y , x %y
else:
return x
ans = GCD(x,y)
print(ans) | def gcd(x, y):
if x < y:
x, y = y, x
while y > 0:
r = x%y
x = y
y = r
return x
x, y = map(int, raw_input().split())
print gcd(x, y) | 1 | 7,872,483,608 | null | 11 | 11 |
import itertools
H, W, K = map(int, input().split())
A = [[int(x) for x in input()] for _ in range(H)]
def solve(blocks):
n_block = len(blocks)
n_cut = n_block - 1
sums = [0 for _ in range(n_block)]
for c in range(W):
adds = [block[c] for block in blocks]
if any(a > K for a in adds):
return H * W
sums = [s + a for s, a in zip(sums, adds)]
if any(s > K for s in sums):
n_cut += 1
sums = adds
return n_cut
ans = H * W
for mask in itertools.product([0, 1], repeat=H - 1):
mask = [1] + list(mask) + [1]
pivots = [r for r in range(H + 1) if mask[r]]
blocks = [A[p1:p2] for p1, p2 in zip(pivots[:-1], pivots[1:])]
blocks = [[sum(row[c] for row in block) for c in range(W)] for block in blocks]
ans = min(ans, solve(blocks))
print(ans)
| import itertools
H, W, K = map(int, input().split())
S = []
for _ in range(H):
S.append([int(s) for s in input()])
ans = 2000
#itertoolsproductでビット全探索が簡潔に書ける
for t in itertools.product([0, 1], repeat=H - 1):
cnt = t.count(1)
#横方向の分割の回数を数えている
lst = [[s for s in S[0]]]
#リストを新たな要素として加えるか、それとも中身を足し合わせるだけか
for h in range(H - 1):
if t[h]:
lst.append(S[h + 1])
else:
lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]
L = len(lst)
sum_lst = [0] * L
for w in range(W):
if max(lst[i][w] for i in range(L)) > K:
break
#横方向の分割を終えた時点で一列にK+1個以上あるとアウト
tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
if max(tmp) > K:
cnt += 1
sum_lst = [lst[i][w] for i in range(L)]
else:
sum_lst = tmp
else:
ans = min(ans, cnt)
print(ans)
#このコードはループをうまくリストに入れ込んでるので短く見えてすごい
#5月24日
| 1 | 48,475,870,366,880 | null | 193 | 193 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,k = map(int, input().split())
M = 10**9+7
nums = [0]*(k+1) # gcd==kなる数列の個数
for i in range(k, 0, -1):
nums[i] = pow(k//i, n, M)
for j in range(2*i, k+1, i):
nums[i] -= nums[j]
nums[i] %= M
ans = sum(i*item for i,item in enumerate(nums))%M
print(ans) | MOD = 1000000007
def fast_power(base, power):
"""
Returns the result of a^b i.e. a**b
We assume that a >= 1 and b >= 0
Remember two things!
- Divide power by 2 and multiply base to itself (if the power is even)
- Decrement power by 1 to make it even and then follow the first step
"""
result = 1
while power > 0:
# If power is odd
if power % 2 == 1:
result = (result * base) % MOD
# Divide the power by 2
power = power // 2
# Multiply base to itself
base = (base * base) % MOD
return result
n,k = [int(j) for j in input().split()]
d = dict()
ans = k
d[k] = 1
sum_so_far = 1
for i in range(k-1, 0, -1):
d[i] = fast_power(k//(i),n)
for mul in range(i*2, k+1, i):
d[i]-=d[mul]
# d[i] = max(1, d[i])
ans+=(i*d[i])%MOD
# if d[i]>1:
# sum_so_far += d[i]
print(ans%MOD)
| 1 | 36,715,935,348,640 | null | 176 | 176 |
N, M = map(int, input().split())
for i in range((M + 1) // 2):
print(i + 1, i + (M - 2 * i) + 1)
for i in range(M - (M + 1) // 2):
print(M + 1 + i + 1, M + 1 + i + (M - 1 - 2 * i) + 1) | N = int(input())
locs = []
S = 0
for _ in range(N):
locs.append(list(map(int,input().split())))
for i in range(N):
for j in range(i+1,N):
dis = ((locs[i][0]-locs[j][0])**2 + (locs[i][1]-locs[j][1])**2)**(1/2)
S += dis
print(2*S/N) | 0 | null | 88,620,780,527,900 | 162 | 280 |
d = list(map(int, input().split()))
op = list(input())
for o in op:
b = [x for x in d]
if o == "S":
b[0] = d[4]
b[1] = d[0]
b[4] = d[5]
b[5] = d[1]
elif o == "E":
b[0] = d[3]
b[2] = d[0]
b[3] = d[5]
b[5] = d[2]
elif o == "W":
b[0] = d[2]
b[2] = d[5]
b[3] = d[0]
b[5] = d[3]
elif o == "N":
b[0] = d[1]
b[1] = d[5]
b[4] = d[0]
b[5] = d[4]
for i in range(6):
d[i] = b[i]
print(d[0])
| L=int(input())
answer=(round(L/3,10))**3
print(answer) | 0 | null | 23,531,904,384,220 | 33 | 191 |
md = list(map(int,input().split()))
mmd = list(map(int,input().split()))
if md[0] != mmd[0]:
print(1)
else:
print(0) | m,d=map(int,input().split())
n,e=map(int,input().split())
print(1 if m!=n else 0) | 1 | 124,099,683,829,620 | null | 264 | 264 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
a.sort()
a = a[::-1]
print('Yes' if s <= 4 * m * a[m - 1] else 'No')
| def main():
n,m = map(int, input().split())
a = sorted(list(map(int, input().split())),reverse = True)
all = sum(a)
cnt = 0
for i in(a):
if(i * 4 * m >= all and cnt < m):
cnt += 1
if cnt >= m:
print('Yes')
else:
print('No')
main() | 1 | 38,633,574,290,002 | null | 179 | 179 |
N = int(input())
A = list(map(int, input().split()))
M = [0] * N
S = 0
for i in range(N):
S = S^A[i]
for i in range(N):
M[i] = S^A[i]
print(*M)
| def solve():
N = int(input())
A = list(map(int, input().split()))
total = 0
for a in A:
total ^= a
ans = []
for a in A:
ans.append(total^a)
return ans
print(*solve())
| 1 | 12,523,143,332,860 | null | 123 | 123 |
import sys
def main():
cnt = {}
for i in range(97,123):
cnt[chr(i)] = 0
# print(cnt)
for passages in sys.stdin:
for psg in passages:
psglower = psg.lower()
for s in psglower:
if s.isalpha():
cnt[s] += 1
for i in range(97,123):
s = chr(i)
print(s, ':', cnt[s])
if __name__ == '__main__':
main()
| al = 'abcdefghijklmnopqrstuvwxyz'
text = ''
while True:
try:
text += input().lower()
except EOFError:
break
for i in al:
print('{} : {}'.format(i, text.count(i)))
| 1 | 1,665,712,339,658 | null | 63 | 63 |
A,B=map(int,input().split())
ma,mi=0,0
ma=max(A,B)
mi=min(A,B)
if A%B==0 or B%A==0:
print(ma)
else :
for i in range(2,ma+1):
if (ma*i)%mi==0:
print(ma*i)
break
i+=(mi-1)
| import fractions
a, b = map(int, input().split())
def lcm(a,b):
return (a*b)//fractions.gcd(a,b)
print(lcm(a,b)) | 1 | 113,578,350,213,750 | null | 256 | 256 |
N = int(input())
# 以下がとてもわかりやすい
# https://drken1215.hatenablog.com/entry/2020/06/20/231600
for i in range(-200, 200, 1):
for j in range(-200, 200, 1):
if i ** 5 - j ** 5 == N:
print(f'{i} {j}')
exit(0) | X = int(input())
for A in range(-1000, 1001):
for B in range(-1000, 1001):
if A**5-B**5 == X:
print(A, B); exit() | 1 | 25,711,362,973,088 | null | 156 | 156 |
N,M=list(map(int,input().split()))
import math
if N==1 or M==1:
print(1)
else:
print(int(math.ceil(N*M/2))) | H,W=[int(i) for i in input().split()]
if H==1 or W==1:
print(1)
else:
print(int(H*W/2)+(H*W)%2)
| 1 | 50,793,438,045,492 | null | 196 | 196 |
n = int(input())
a = list(map(int, input().split()))
count = 0
flag = True
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]
count += 1
flag = True
print(' '.join(list(map(str, a))))
print(count) | def abc164_d():
# 解説放送
s = str(input())
n = len(s)
m = 2019
srev = s[::-1] # 下の位から先に見ていくために反転する
x = 1 # 10^i ??
total = 0 # 累積和 (mod 2019 における累積和)
cnt = [0] * m # cnt[k] : 累積和がkのものが何個あるか
ans = 0
for i in range(n):
cnt[total] += 1
total += int(srev[i]) * x
total %= m
ans += cnt[total]
x = x*10 % m
print(ans)
abc164_d() | 0 | null | 15,427,255,092,552 | 14 | 166 |
h = int(input())
w = int(input())
n = int(input())
r = max(h,w)
count = 0
x = 0
while x < n:
count += 1
x += r
print(count) | def main():
H = int( input())
W = int( input())
N = int( input())
if H < W:
H, W = W, H
ans = N//H
if N%H != 0:
ans += 1
print(ans)
if __name__ == '__main__':
main() | 1 | 88,633,599,927,192 | null | 236 | 236 |
n,k = map(int,input().split())
h = [int(s) for s in input().split()]
h.sort(key=int)
for _ in range(min(k,len(h))):del h[-1]
print(sum(h)) | N, K = map(int, input().split())
H = list(map(int, input().split()))
if N <= K:
print(0)
else:
H = sorted(H)
ans = 0
for i in range(N-K):
ans += H[i]
print(ans) | 1 | 79,192,301,084,200 | null | 227 | 227 |
import sys
import math
import fractions
from collections import defaultdict
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
S=ns().split()
print(S[1]+S[0]) | n,k = map(int,input().split())
p = [int(x) for x in input().split()]
p.sort()
s = 0
for i in range(k):
s+=p[i]
print(s)
| 0 | null | 57,172,283,604,578 | 248 | 120 |
A, B, M = map(int, input().split())
price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))
ans = min(price_A)+min(price_B)
for m in range(M):
x, y, c = map(int, input().split())
p1 = price_A[x-1] + price_B[y-1] - c
if p1 <= ans: ans=p1
print(ans) | import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def solve():
ans = 0
flag = True
for rep in discount:
pay = a[rep[0]-1] + b[rep[1]-1] - rep[2]
if flag:
ans = pay
flag = False
else:
ans = min(ans,pay)
ans = min(ans,min(a)+min(b))
print(ans)
return
if __name__=='__main__':
A,B,M = IL()
a = list(IL())
b = list(IL())
discount = [list(IL()) for _ in range(M)]
solve() | 1 | 53,719,726,928,480 | null | 200 | 200 |
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np # Pythonのみ!
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components # Pythonのみ!
# ↑cf. https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
S = list(input())
K = int(input())
l = []
cnt = 0
if len(S)==1:
print(K//2)
else:
gr = groupby(S)
for key, group in gr:
l.append(list(group))
if len(l)==1:
print(len(S)*K//2)
else:
for i in range(len(l)):
cnt += len(l[i]) // 2
if l[0][0] == l[-1][0]:
dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2
else:
dev = 0
print(cnt * K - dev * (K - 1))
resolve() | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#main code here!
s=SI()
k=I()
u=len(s)
seq=0
x=1
for i in range(u-1):
if s[i]==s[i+1]:
x+=1
else:
seq+=x//2
x=1
seq+=x//2
#print(seq)
a=1
for i in range(u-1):
if s[0]==s[i+1]:
a+=1
else:
break
b=1
for i in range(u-1):
if s[-1]==s[u-1-(1+i)]:
b+=1
else:
break
#print(a,b)
if x==u:
ans=(u*k)//2
else:
if s[0]!=s[-1]:
ans=(seq)*k
else:
ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1)
print(ans)
if __name__=="__main__":
main()
| 1 | 175,051,135,457,230 | null | 296 | 296 |
def solve():
A, B, C, K = map(int, input().split())
ans = min(A,K)-max(0,K-A-B)
return ans
print(solve()) | A, B, C, K = (int(x) for x in input().split())
AB = A + B
if K < A:
print(K)
elif AB < K:
print(A - (K-AB))
else:
print(A)
| 1 | 21,764,333,776,160 | null | 148 | 148 |
if __name__ == '__main__':
def linearSearch(t):
S.append(t)
#print(S)
i=0
while S[i]!=t:
i+=1
del S[n]
return 1 if i!=n else 0
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=set(map(int,input().split()))
ans=0
for t in T:
ans+=linearSearch(t)
#print(t,ans)
print(ans)
|
n = int(input())
s = [int(i) for i in input().split()]
q = int(input())
t = [int(i) for i in input().split()]
ans = 0
for si in set(s):
if si in t:
ans += 1
print(ans)
| 1 | 67,553,974,560 | null | 22 | 22 |
N,M=map(int,input().split())
x=[-1]*N
for _ in range(M):
s,c=map(int,input().split())
s-=1
if (s==c==0 and N>1 or
x[s]!=-1 and x[s]!=c):
print(-1)
exit()
x[s]=c
if x[0]==-1:
x[0]=0+(N>1)
for i in range(N):
if x[i]==-1: x[i]=0
print(''.join(map(str,x)))
| # n,m = map(int, input().split())
# sc = [map(int, input().split()) for _ in range(m)]
# s, c = [list(i) for i in zip(*sc)]
#
#
#
# for i in range(10**n):
# ans = str(i)
# if len(i) == n and all([i[s[j]-1] == str(c[j]) for j in range(m)]):
# print(ans)
# exit()
#
#
# print(-1)
n, m = map(int, input().split())
s, c = [], []
for _ in range(m):
s_, c_ = map(int, input().split())
s.append(s_)
c.append(c_)
for i in range(10 ** n):
ans = str(i)
if len(ans) == n and all([ans[s[j] - 1] == str(c[j]) for j in range(m)]):
print(ans)
exit()
print(-1)
| 1 | 60,529,746,730,510 | null | 208 | 208 |
k = int(input())
s = input()
if k>=len(s):
print(s)
else: print(s[:k] + "...") | k = int(input())
s = input()
if len(s) <= k:
print(s)
else:
print("{}...".format(s[0:k]))
| 1 | 19,698,710,562,452 | null | 143 | 143 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
for Ai in A:
N -= Ai
if N < 0:
print(-1)
break
if N >= 0:
print(N) | n,m=map(int,input().split())
a =map(int,input().split())
x = sum(a)
if x > n:
print('-1')
else:
print(n-x) | 1 | 31,973,676,246,902 | null | 168 | 168 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.