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())
if n % 2 == 1:
print(0)
exit()
cnt = 0
x = 1
while n > 5**x:
cnt += n//5**x//2
x += 1
print(cnt) | # coding: utf-8
# Here your code !
import sys
def culc_division(x) :
"""
??\???x????´???°?????°??????????????§??????
"""
culc_list = []
for i in range(1,x+1) :
if x % i == 0 :
culc_list.append(i)
return culc_list
in_std = list(map(int, sys.stdin.readline().split(" ")))
a = in_std[0]
b = in_std[1]
c = culc_division(in_std[2])
counter = 0
for idx in range(a, b+1):
if idx in c:
counter += 1
print(counter) | 0 | null | 58,360,829,613,280 | 258 | 44 |
s = int(input())
a = [0] * (s+1)
if s == 1:
print(0)
else:
a[0]=1
a[1]=0
a[2]=0
mod = 10**9+7
for i in range(3,s+1):
a[i] = a[i-1]+a[i-3]
print(int(a[s] % mod)) | mod = 10 ** 9 + 7
s = int(input())
dp = []
for i in range(s):
v = 0
if i >= 2:
v += 1
v += sum(dp[:i - 2])
v %= mod
dp.append(v)
print(dp[-1])
| 1 | 3,272,317,778,230 | null | 79 | 79 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
def yes():
print("Yes") # type: str
def no():
print("No") # type: str
def solve(N: int, S: "List[str]"):
def seq_positive(ls):
state = 0
for l, st in ls:
if state+l < 0:
return False
state += st
return True
# 部分括弧列の特徴量を計算する。
# 経過中の最小値と、最終到達値
left_seq = []
right_seq = []
total = 0
for s in S:
state = 0
lower = 0
for c in s:
if c == "(":
state += 1
else:
state -= 1
lower = min(lower, state)
if state > 0:
left_seq.append((lower, state))
else:
right_seq.append((lower-state, -state))
total += state
left_seq.sort(reverse=True)
right_seq.sort(reverse=True)
# print(left_seq)
# print(right_seq)
if seq_positive(left_seq) and seq_positive(right_seq) and total == 0:
yes()
else:
no()
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = [next(tokens) for _ in range(N)] # type: "List[str]"
solve(N, S)
if __name__ == '__main__':
main()
| from operator import itemgetter
from itertools import chain
N = int(input())
L = []
R = []
for i in range(N):
S = input()
low = 0
var = 0
for s in S:
if s == '(':
var += 1
else:
var -= 1
low = min(low, var)
if var >= 0:
L.append((low, var))
else:
R.append((low, var))
L.sort(key=itemgetter(0), reverse=True)
R.sort(key=lambda x: x[0] - x[1])
pos = 0
for i, (low, var) in enumerate(chain(L, R)):
if pos + low < 0:
ans = 'No'
break
pos += var
else:
ans = 'Yes' if pos == 0 else 'No'
print(ans)
| 1 | 23,574,000,151,740 | null | 152 | 152 |
# B - Tax Rate
N = int(input())
ans = ':('
for x in range(50000):
if (108*x)//100==N:
ans = x
break
print(ans) | n=int(input())
ans=':('
for i in range(1,n+1):
if int((i*1.08)//1)==n:
ans=i
break
print(ans)
| 1 | 125,909,760,181,618 | null | 265 | 265 |
def check_weather(weathers: str) -> int:
count = 0
l_n = [0]
for index, i in enumerate(weathers):
if weathers[-1] == 'R' and index == len(weathers) - 1:
count += 1
l_n.append(count)
break
if i == 'R':
count += 1
else:
if max(l_n) <= count:
l_n.append(count)
count = 0
return max(l_n)
if __name__ == '__main__':
print(check_weather(input())) | # coding: utf-8
# Here your code !
import sys
def culc_division(x) :
"""
??\???x????´???°?????°??????????????§??????
"""
culc_list = []
for i in range(1,x+1) :
if x % i == 0 :
culc_list.append(i)
return culc_list
in_std = list(map(int, sys.stdin.readline().split(" ")))
a = in_std[0]
b = in_std[1]
c = culc_division(in_std[2])
counter = 0
for idx in range(a, b+1):
if idx in c:
counter += 1
print(counter) | 0 | null | 2,714,682,212,800 | 90 | 44 |
x, n = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while True:
if x-i not in p:
print(x-i)
break
if x+i not in p:
print(x+i)
break
i += 1 | #!/usr/bin/env python3
n = int(input())
n /= 3
print(n**3) | 0 | null | 30,670,903,084,680 | 128 | 191 |
import sys
n = int(input())
for i in range(1, n + 1):
x = i
if x % 3 == 0:
sys.stdout.write(" %d" % i)
else:
while x > 1:
if x % 10 == 3:
sys.stdout.write(" %d" % i)
break
x //= 10
print() | n=int(input())
l=""
for i in range(1,n+1):
if i % 3==0 or i % 10 == 3 or (i % 100)//10 == 3 or (i % 1000)//100 == 3 or (i % 10000)//1000 == 3:
l+=" "+str(i)
print(l)
| 1 | 923,601,170,472 | null | 52 | 52 |
import sys
stdin = sys.stdin
ni = lambda: int(ns())
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))
# code here
N, R = na()
if N >= 10:
print(R)
else:
print(R + 100*(10-N))
| n, r = map(int, input().split())
print(r + 100 * max(0, (10 - n)))
| 1 | 63,268,029,545,330 | null | 211 | 211 |
a = int(input())
b = input().split()
c = "APPROVED"
for i in range(a):
if int(b[i]) % 2 == 0:
if int(b[i]) % 3 == 0 or int(b[i]) % 5 == 0:
c = "APPROVED"
else:
c = "DENIED"
break
print(c) | N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(len(A)):
if A[i]%2==0:
if A[i]%3==0 or A[i]%5==0:
count+=1
else:
count+=1
if count==len(A):
print("APPROVED")
else:
print("DENIED") | 1 | 68,919,609,918,002 | null | 217 | 217 |
a = raw_input().split(" ")
a.sort()
print "%s %s %s" % (a[0],a[1],a[2]) | n=int(input())
s=input()
c=0
for i in range(n-2):
if s[i]=="A":
if s[i+1]=="B":
if s[i+2]=="C":
c+=1
else:
pass
else:
pass
else:
pass
print(c) | 0 | null | 49,649,825,621,792 | 40 | 245 |
a = input()
b = a.split(' ')
W = int(b[0])
H = int(b[1])
x = int(b[2])
y = int(b[3])
r = int(b[4])
if -100 <= x < 0:
print('No')
elif -100 <= y < 0:
print('No')
elif W >= x + r and H >= y + r:
print('Yes')
else:
print('No') | n = int(input())
a_ls = list(map(int, input().split()))
s_ls = [0] * n
Sum = 0
for i in range(n):
Sum = Sum ^ a_ls[i]
for i in range(n):
s_ls[i] = Sum ^ a_ls[i]
print(*s_ls) | 0 | null | 6,465,755,476,190 | 41 | 123 |
import math
K = int(input())
# gcd(a, b, c)=gcd(gcd(a,b), c) が成り立つ
s = 0
for a in range(1, K+1):
for b in range(1, K+1):
d = math.gcd(a, b) # gcd(a, b)は先に計算しておく
for c in range(1, K+1):
s += math.gcd(d, c)
print(s) | for i in range(9):
for j in range(9):
print "%dx%d=%d" %(i+1,j+1, (i+1)*(j+1)) | 0 | null | 17,673,523,895,332 | 174 | 1 |
n = int(input())
A = list(map(int, input().split()))
from collections import defaultdict
dic = defaultdict(int)
ans = 0
for i in range(n):
if i - A[i] in dic:
ans += dic[i-A[i]]
dic[i+A[i]] += 1
print(ans)
| import sys
import collections
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007
#+++++
def main():
n = int(input())
#b , c = tin()
#s = input()
al = lin()
aal=[i-v for i,v in enumerate(al)]
ccl = collections.Counter(aal)
ret = 0
for i, v in enumerate(al):
ccl[i-v] -= 1
if i+v in ccl:
ret += ccl[i+v]
print(ret)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret) | 1 | 25,950,788,044,984 | null | 157 | 157 |
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
def main():
N = I()
a = LI()
dp = [0] * N
dp[1] = max(a[0], a[1])
c = a[0]
for i in range(2, N):
if i % 2 == 0:
c += a[i]
dp[i] = max(dp[i-2] + a[i], dp[i-1])
else:
dp[i] = max(dp[i-2] + a[i], c)
print(dp[-1])
if __name__ == '__main__':
main()
| n = int(input())
a = list(map(int, input().split()))
INF = 10 ** 18
if n % 2:
dp = [[[-INF,-INF,-INF] for i in range(2)] for i in range(n+1)]
dp[0][0][0] = 0
# 初期化条件考える
for i,v in enumerate(a):
for j in range(2):
if j:
dp[i+1][0][0] = max(dp[i+1][0][0],dp[i][1][0])
dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][1][1])
dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][1][2])
else:
dp[i+1][1][0] = max(dp[i+1][1][0],dp[i][0][0] + v)
dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][0][0])
dp[i+1][1][1] = max(dp[i+1][1][1],dp[i][0][1] + v)
dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][0][1])
dp[i+1][1][2] = max(dp[i+1][1][2],dp[i][0][2] + v)
print(max(max(dp[n][0]),max(dp[n][1][1:])))
else:
odd_sum,even_sum = 0,0
cumsum = []
for k,v in enumerate(a):
if k % 2:
odd_sum += v
cumsum.append(odd_sum)
else:
even_sum += v
cumsum.append(even_sum)
ans = max(cumsum[n-2],cumsum[n-1])
for i in range(2,n,2):
ans = max(ans, cumsum[i-2]+cumsum[n-1]-cumsum[i-1])
print(ans) | 1 | 37,272,122,172,600 | null | 177 | 177 |
import sys
input = sys.stdin.readline
n = int(input())
ans = 0
for i in range(1, n):
ans += (n-1) // i
print(ans) |
n = int(input())
cnt = 0
for i in range(1,n):
cnt += int((n-1)/i)
print(cnt)
| 1 | 2,636,313,809,470 | null | 73 | 73 |
a = list(map(int,input().split()))
if sum(a)<= 21:
print("win")
else:
print("bust")
| print(['bust','win'][sum(map(int,input().split()))<22]) | 1 | 118,592,572,696,510 | null | 260 | 260 |
W=input()
count=0
while True:
text=input()
if text == 'END_OF_TEXT':
break
else:
ls = list(map(str, text.split()))
for s in ls:
if s.lower() == W.lower():
count += 1
print(count) | A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
D1 = abs(A-B)
D2 = (V-W)*T
if (D1 - D2) <=0:
print("YES")
else:
print("NO")
| 0 | null | 8,375,448,648,180 | 65 | 131 |
s,t=list(input().split())
a,b=list(map(int,input().split()))
u=input()
ball={s:a,t:b}
ball[u] =max(0,ball[u]-1)
print(ball[s],ball[t]) | S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:
A -= 1
else:
B -= 1
print(A, B, sep=' ') | 1 | 71,978,699,555,008 | null | 220 | 220 |
s = input()
while s[:2] == 'hi':
s = s[2:]
if s == '': print('Yes')
else: print('No') | import sys
sys.setrecursionlimit(10**5)
N,u,v=map(int,input().split())
du,dv=[0]*-~N,[0]*-~N
T=[list() for i in range(-~N)]
def dfs(p,t,v,d):
d[v]=t
for i in T[v]:
if i!=p:
dfs(v,t+1,i,d)
for i in range(N-1):
a,b=map(int,input().split())
T[a].append(b)
T[b].append(a)
dfs(0,0,u,du)
dfs(0,0,v,dv)
c=0
for i in range(1,-~N):
if len(T[i])==1 and i!=v:
if du[i]<dv[i]:
c=max(c,~-dv[i])
print(c)
| 0 | null | 85,545,933,821,486 | 199 | 259 |
n = int(input())
can = False
for i in range(1, n + 1):
x = int(i * 1.08)
if(x == n):
print(i)
can = True
break
if(can == False):
print(":(")
| n = int(input())
lst = [0]*(10**5)
l = list(map(int,input().split()))
total = sum(l)
for x in l:
lst[x-1] += 1
m = int(input())
for i in range(m):
x,y = map(int,input().split())
lst[y-1] += lst[x-1]
total += (y-x) * lst[x-1]
lst[x-1] = 0
print(total)
| 0 | null | 69,069,680,267,818 | 265 | 122 |
H, N, *AB = map(int, open(0).read().split())
A = AB[::2]
B = AB[1::2]
dp = [float("inf")] * (H + 1)
dp[0] = 0
for i in range(N):
for h in range(H):
dec_health = min(h + A[i], H)
dp[dec_health] = min(dp[dec_health], dp[h] + B[i])
print(dp[-1])
| from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 8)
h,n=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda abi:(abi[1]/abi[0],abi[0]))
@lru_cache(maxsize=None)
def dp(i):
if i<=0:
return 0
else:
ans=float('inf')
for a,b in ab:
val=b+dp(i-a)
if val<ans:
ans=val
else:
break
return ans
print(dp(h)) | 1 | 81,213,013,334,126 | null | 229 | 229 |
def main():
import itertools
n,m,q = map(int,input().split())
Q = []
for i in range(q):
Q.append(list(map(int,input().split())))
cmb = [i for i in range(1,m+1)]
ans = 0
for que in itertools.combinations_with_replacement(cmb,n):
m = 0
for i in range(q):
[a,b,c,d] = Q[i]
if que[b-1]-que[a-1]==c:
m += d
if m>ans:
ans = m
print(ans)
if __name__ == "__main__":
main()
| class Fib():
f = [1] * 50
def fib(self, n):
for i in range(2, n + 1):
self.f[i] = self.f[i - 1] + self.f[i - 2]
return(self.f[n])
x = Fib()
print(x.fib(int(input()))) | 0 | null | 13,721,681,311,910 | 160 | 7 |
n = int(input())
a = list(map(int, input().split()))
number_buka = [0]*n
for i in a:
number_buka[i-1] += 1
for j in number_buka:
print(j) | S = int(input())
h = int(S/3600)
m = int((S-h*3600)/60)
s = int(S-h*3600-m*60)
time = [h, m, s]
time_str = map(str,time)
print(":".join(time_str)) | 0 | null | 16,556,911,411,810 | 169 | 37 |
H, W = map(int, input().split())
S = [input() for _ in range(H)]
INF = H + W
dp = [[INF] * W for _ in range(H)]
if S[0][0] == '#':
dp[0][0] = 1
else:
dp[0][0] = 0
for i in range(H):
for j in range(W):
if i - 1 >= 0:
if S[i][j] == '#' and S[i-1][j] == '.':
dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
else:
dp[i][j] = min(dp[i][j], dp[i-1][j])
if j - 1 >= 0:
if S[i][j] == '#' and S[i][j-1] == '.':
dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
else:
dp[i][j] = min(dp[i][j], dp[i][j-1])
print(dp[H-1][W-1]) | def read_int():
return int(input())
def read_ints():
return map(int, input().split(' '))
r, c = read_ints()
s = []
for i in range(r):
s.append(input())
inf = int(1e9)
dp = [[inf for j in range(c)] for i in range(r)]
dp[0][0] = 1 if s[0][0] == '#' else 0
for i in range(r):
for j in range(c):
if i > 0:
dp[i][j] = dp[i - 1][j]
if s[i][j] == '#' and s[i - 1][j] == '.':
dp[i][j] += 1
if j > 0:
another = dp[i][j - 1]
if s[i][j] == '#' and s[i][j - 1] == '.':
another += 1
dp[i][j] = min(dp[i][j], another)
print(dp[r - 1][c - 1])
| 1 | 49,221,010,465,900 | null | 194 | 194 |
MOD = 10**9+7
def resolve():
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(input())
score = 0
hands = {
"r": ("p", P),
"s": ("r", R),
"p": ("s", S)
}
hist = []
for i, t in enumerate(T):
hand, point = hands[t]
if i >= K and hand == hist[-K]:
hist.append("*")
continue
score += point
hist.append(hand)
#print(hist)
print(score)
if '__main__' == __name__:
resolve() | def gcd(x, y):
if x < y:
tmp = x
x = y
y = tmp
while y > 0:
r = x % y
x = y
y = r
return print(x)
x_y = input()
tmp = list(map(int, x_y.split()))
x = tmp[0]
y = tmp[1]
gcd(x, y)
| 0 | null | 53,650,283,052,220 | 251 | 11 |
x,y = map(int,input().split())
mod = 10**9+7
def comb(a,b):
comb = 1
chld = 1
for i in range(b):
comb = comb*(a-i)%mod
chld = chld*(b-i)%mod
return (comb*pow(chld,mod-2,mod))%mod
if (x+y)%3!=0:
print(0)
else:
nm = (x+y)//3
n = y-nm
m = x-nm
if n>=0 and m>=0:
print(comb(n+m,m))
else:
print(0) | x,y = map(int,input().split())
mod = 10**9+7
def comb(N,x):
numerator = 1
for i in range(N-x+1,N+1):
numerator = numerator * i % mod
denominator = 1
for j in range(1,x+1):
denominator = denominator * j % mod
d = pow(denominator,mod-2,mod)
return numerator * d % mod
if (x+y) % 3 == 0:
a = (2*y-x) //3
b = (2*x-y) //3
if a >= 0 and b >= 0:
print(comb(a+b,a))
exit()
print(0) | 1 | 150,233,476,869,318 | null | 281 | 281 |
h, w = map(int, input().split())
s = [input() for _ in range(h)]
def bfs(x, y):
q = []
dp = {}
def qpush(x, y, t):
if 0 <= x < w and 0 <= y < h and s[y][x] != '#' and (x, y) not in dp:
q.append((x, y))
dp[(x, y)] = t
qpush(x, y, 0)
while len(q) > 0:
(x, y) = q.pop(0)
qpush(x + 1, y, dp[(x, y)] + 1)
qpush(x, y - 1, dp[(x, y)] + 1)
qpush(x - 1, y, dp[(x, y)] + 1)
qpush(x, y + 1, dp[(x, y)] + 1)
return dp.get((x, y), 0)
t = 0
for y in range(h):
for x in range(w):
t = max(t, bfs(x, y))
print(t) | def divisor(N:int):
res = set()
i = 1
while i * i <= N:
if N % i == 0:
res.add(i)
if i != N // i:
res.add(N // i)
i += 1
return res
def check(N:int, K:int):
while N % K == 0:
N //= K
return True if N % K == 1 else False
def main():
N = int(input())
ans = set()
for K in divisor(N):
if K == 1: continue
if check(N, K):
ans.add(K)
ans |= divisor(N - 1)
ans.remove(1)
print(len(ans))
if __name__ == "__main__":
main() | 0 | null | 68,154,373,913,120 | 241 | 183 |
N = int(input())
A = [int(x) for x in input().split()]
# M以下の整数の素因数分解を高速に
# 前処理O(MloglogM)
# 一計算O(logK)
def mae_syori(M):
D = [0] * (M + 1)
for i in range(2, M+1):
if D[i] != 0: continue
# print(i, list(range(i*2, M + 1, i)))
for j in range(i*2, M+1, i):
if D[j] == 0:
D[j] = i
return D
def p_bunkai(K):
assert 2 <= K <= len(D)-1
k = K
ret = []
while True:
if k == 1:
break
if D[k] == 0:
ret.append((k, 1))
break
else:
p = D[k]
count = 0
while k % p == 0:
count += 1
k //= p
ret.append((p, count))
return ret
# 最大公約数
# ユークリッドの互除法
def my_gcd(a, b):
if b == 0:
return a
else:
return my_gcd(b, a%b)
c_gcd = A[0]
for a in A:
c_gcd = my_gcd(c_gcd, a)
if c_gcd == 1:
max_A = max(A)
D = mae_syori(max_A)
yakusu = set()
ok = True
for a in A:
if a == 1: continue
p_bunkai_result = p_bunkai(a)
p_list = [p[0] for p in p_bunkai_result]
for p in p_list:
if p not in yakusu:
yakusu.add(p)
else:
ok = False
if not ok:
break
if ok:
print('pairwise coprime')
else:
print('setwise coprime')
else:
print('not coprime') | import sys
import math
from functools import reduce
N = str(input())
A = list(map(int, input().split()))
M = 10 ** 6
sieve = [0] * (M+1)
for a in A:
sieve[a] += 1
def gcd(*numbers):
return reduce(math.gcd, numbers)
d = 0
for i in range(2, M+1):
tmp = 0
for j in range(i,M+1,i):
tmp += sieve[j]
if tmp > 1:
d = 1
break
if d == 0:
print('pairwise coprime')
exit()
if gcd(*A) == 1:
print('setwise coprime')
exit()
print('not coprime')
| 1 | 4,140,077,894,318 | null | 85 | 85 |
import numpy as np
n=int(input())
A=np.array(input().split(),np.int64)
A.sort()
A=A[::-1]
ans=int(0)
for i in range(n-1):
ans+=A[(i+1)//2]
print(ans)
| # -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
class Mod:
def __init__(self, m):
self.m = m
def add(self, a, b):
return (a + b) % self.m
def sub(self, a, b):
return (a - b) % self.m
def mul(self, a, b):
return ((a % self.m) * (b % self.m)) % self.m
def div(self, a, b):
return self.mul(a, pow(b, self.m-2, self.m))
def pow(self, a, b):
return pow(a, b, self.m)
class Bisect:
def __init__(self, func):
self.__func = func
def bisect_left(self, x, lo, hi):
while lo < hi:
mid = (lo+hi)//2
if self.__func(mid) < x:
lo = mid+1
else:
hi = mid
return lo
def bisect_right(self, x, lo, hi):
while lo < hi:
mid = (lo+hi)//2
if x < self.__func(mid):
hi = mid
else:
lo = mid+1
return lo
def f(n):
r = 1
for i in range(1, n+1):
r *= i
return r
@mt
def slv(N, K, A, F):
A.sort()
F.sort(reverse=True)
def f(x):
y = 0
for a, f in zip(A, F):
b = a - x//f
if b > 0:
y += b
if y <= K:
return 1
return 0
return Bisect(f).bisect_left(1, 0, 10**18)
def main():
N, K = read_int_n()
A = read_int_n()
F = read_int_n()
print(slv(N, K, A, F))
if __name__ == '__main__':
main()
| 0 | null | 87,138,081,059,512 | 111 | 290 |
if __name__ == '__main__':
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
s = sum(A)
cnt = 0
for i in range(M):
if s<=4*M*A[i]:
cnt += 1
if cnt==M:
print("Yes")
else:
print("No")
| X,Y,Z=map(str,input().split())
XX=Y
Y=X
X=XX
XX=Z
Z=X
X=XX
print(X,Y,Z) | 0 | null | 38,300,512,134,612 | 179 | 178 |
s = input()
k = int(input())
if len(s) == 1:
print(k//2)
exit()
rep = [1]
prev = s[0]
for i in range(1, len(s)):
if s[i] == prev:
rep[-1] += 1
else:
rep.append(1)
prev = s[i]
if len(rep) == 1:
print(rep[0]*k//2)
exit()
cnt = 0
for r in rep:
cnt += r//2
if s[0] == s[-1]:
ans = cnt*k + ((rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2)*(k-1)
print(ans)
else:
print(cnt*k)
| x = []
while True:
if 0 in x:
break
x.append(int(input()))
x.pop()
for i, v in enumerate(x):
print(('Case %d: %d') % (i+1, v)) | 0 | null | 87,826,109,596,150 | 296 | 42 |
#create date: 2020-06-30 14:42
import sys
stdin = sys.stdin
from itertools import combinations_with_replacement
def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def main():
n, m, q = na()
matrix = list()
for i in range(q):
matrix.append(na())
l = list(combinations_with_replacement(range(1, m+1), n))
ans = 0
for li in l:
res = 0
for q in matrix:
a, b, c, d = q
if li[b-1] - li[a-1] == c:
res += d
ans = max(ans, res)
print(ans)
if __name__ == "__main__":
main() | n = input()
k = int(n[-1])
if k == 3:
print("bon")
elif k == 0 or k == 1 or k == 6 or k == 8:
print("pon")
else:
print("hon")
| 0 | null | 23,570,469,192,334 | 160 | 142 |
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
INF = -1
def main(T1, T2, A1, A2, B1, B2):
D1 = T1 * (A1 - B1)
D2 = D1 + T2 * (A2 - B2)
if D1 * D2 > 0:
return 0
if abs(D1) == abs(D2) or D2 == 0:
return INF
d, m = divmod(abs(D1), abs(D2))
return (1 if m else 0) + 2 * d
if __name__ == '__main__':
input = sys.stdin.readline
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
ans = main(T1, T2, A1, A2, B1, B2)
print(ans if ans >= 0 else 'infinity')
| N, K = map(int, input().split())
mod = 10 ** 9 + 7
cnt = [0] * (K + 1)
answer = 0
for i in range(K, 0, -1):
tmp = pow(K // i, N, mod) - sum(cnt[::i])
cnt[i] = tmp
answer = (answer + tmp * i) % mod
print(answer)
| 0 | null | 84,404,916,889,468 | 269 | 176 |
def main():
n=int(input())
s,t= list(map(str,input().split()))
ans=""
for i in range(0,n):
ans+=s[i]+t[i]
print(ans)
main() | import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()
from math import *
K=k()
ans=0
for i in range(1,K+1):
for j in range(1,K+1):
for k in range(1,K+1):
ans+=gcd(k,gcd(i,j))
print(ans)
| 0 | null | 73,769,896,178,550 | 255 | 174 |
N=int(input())
l=[[[0 for i in range(10)]for j in range(3)]for k in range(4)]
for i in range(N):
b, f, r, v = map(lambda x: int(x)-1, input().split())
l[b][f][r]+=v+1
for j in range(4):
for k in l[j]:
print(" "+" ".join(map(str, k)))
if j < 3:
print("####################") | n = int(input())
s = list(input())
r = s.count('R')
g = s.count('G')
b = n - r - g
ans = r*g*b
for i in range(n-2):
for j in range(i+1,i+((n-i-1)//2)+1):
if s[i] != s[j] and s[i] != s[2*j - i] and s[j] != s[2*j - i]:
ans -= 1
print(ans) | 0 | null | 18,750,652,528,128 | 55 | 175 |
def nibutan(n, M):
ok = 0
ng = M + 1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
#print("value:", mid)
if nasu(mid) >= n:
ok = mid
else:
ng = mid
return ok
def nasu(x):
ans = 0
for i in A:
#print("L:", i, end = " ")
t = N - hogetan(x - i)
#print("n:", t)
ans += t
return ans
def hogetan(n):
ok = N
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if A[mid] >= n:
ok = mid
else:
ng = mid
return ok
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
MAX = A[-1] + A[-1]
inf = MAX + 10
t = nibutan(M, MAX)
mi = inf
cnt = 0
ans = 0
for i in A:
k = hogetan(t - i)
n = N - k
cnt += n
if n != 0:
mi = min(mi, i + A[k])
ans += n * 2 * i
ans -= mi * (cnt - M)
print(ans) | import numpy as np
from numpy.fft import fft
from numpy.fft import ifft
class FFT:
def exe(s, A, B):
N, M = 1, len(A) + len(B) - 1
while N < M: N <<= 1
A, B = s.arrN(N, A), s.arrN(N, B)
A = fft(A) * fft(B)
A = ifft(A).real[:M] + 0.5
return list(map(int, A))
def arrN(s, N, L):
return np.zeros(N) + (L + [0] * (N - len(L)))
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
MAX = max(A)
L = [0] * (MAX + 1)
for i in A:
L[i] += 1
f = FFT()
L = f.exe(L, L)
ans = 0
for i in range(len(L) - 1, -1, -1):
if L[i] < M:
ans += i * L[i]
M -= L[i]
else:
ans += i * M
break
print(ans) | 1 | 108,097,670,592,090 | null | 252 | 252 |
N = int(input())
A = tuple(map(int, input().split(' ')))
MOD = 10 ** 9 + 7
zeros = [0] * 60
ones = [0] * 60
for a in A:
for i, bit in enumerate(reversed(format(a, '060b'))):
if bit == '0':
zeros[i] += 1
else:
ones[i] += 1
base = 1
ans = 0
for i in range(len(zeros)):
ans += zeros[i] * ones[i] * base
ans %= MOD
base *= 2
base %= MOD
print(ans)
| a, b, c = map(int, input().split())
if a >= b:
if b >= c:
print(c, b, a)
elif a <= c:
print(b, a, c)
else:
print(b, c, a)
else:
if a >= c:
print(c, a, b)
elif b >= c:
print(a, c, b)
else:
print(a, b, c) | 0 | null | 61,634,796,251,222 | 263 | 40 |
#!/usr/bin/env python3
from networkx.utils import UnionFind
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n,m=map(int, input().split())
uf = UnionFind()
for i in range(1,n+1):
_=uf[i]
for _ in range(m):
a,b=map(int, input().split())
uf.union(a, b) # aとbをマージ
print(len(list(uf.to_sets()))-1)
#for group in uf.to_sets(): # すべてのグループのリストを返す
#print(group)
if __name__ == '__main__':
main()
| import networkx as nx
n, m = map(int, input().split())
nodes = [0 for i in range(n)]
L = []
for i in range(m):
a, b = map(int, input().split())
L.append((a,b))
nodes[a-1] += 1
nodes[b-1] += 1
num = 0
for node in nodes:
if node == 0:
num += 1
graph = nx.from_edgelist(L)
num += len(list(nx.connected_components(graph)))
print(num-1) | 1 | 2,273,889,192,708 | null | 70 | 70 |
num = list(map(int,input().split()))
sum = 500*num[0]
if num[1] <= sum:
print("Yes")
else:
print("No") | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
K, X = map(int, input().split())
if 500 * K >= X:
print('Yes')
else:
print('No') | 1 | 97,891,272,590,552 | null | 244 | 244 |
lst = []
num = int(input())
while num != 0:
lst.append(num)
num = int(input())
it = zip(range(len(lst)), lst)
for (c, v) in it:
print("Case " + str(c+1) + ": " + str(v)) | i = 0
while 1:
i += 1
x = input()
if x == '0': break
print(f"Case {i}: {x}")
| 1 | 487,373,743,548 | null | 42 | 42 |
import sys
n = int(input())
ans = n*100/108
for i in [int(ans), int(ans)+1]:
if int(i*1.08) == n:
print(i)
sys.exit()
print(":(")
| n = int(input())
rate = 1.08
for i in range(1,n+1):
val = int(i*rate)
if val == n:
print(i)
exit()
print(":(") | 1 | 126,065,935,350,430 | null | 265 | 265 |
while True:
x,y = map(int,raw_input().split())
if x==0:
break
else:
for i in xrange(x):
print y*"#"
print "" | while True:
H,W = map(int,input().split(" "))
if H == 0 and W == 0:
break
[print(*["#"*W]) for _ in range(H)]
print()
| 1 | 790,921,347,680 | null | 49 | 49 |
t = input()
leng = len(t)
print('x' * leng) | S = input()
N = len(S)
s = 'x'*N
print(s) | 1 | 73,188,832,479,200 | null | 221 | 221 |
def main():
N = int(input())
X = []
Y = []
for _ in range(N):
x, y = (int(i) for i in input().split())
X.append(x + y)
Y.append(x - y)
ans = max(max(X) - min(X), max(Y) - min(Y))
print(ans)
if __name__ == '__main__':
main()
| def main():
n, *xy = map(int, open(0).read().split())
f = [(i - j, i + j) for i, j in zip(xy[::2], xy[1::2])]
a = max(x[0] for x in f)
b = min(x[0] for x in f)
c = max(x[1] for x in f)
d = min(x[1] for x in f)
ans = max(a - b, c - d)
print(ans)
if __name__ == '__main__':
main() | 1 | 3,459,055,172,918 | null | 80 | 80 |
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N, u, v = map(int, input().split())
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b = map(int, input().split())
edge[a].append(b)
edge[b].append(a)
def calc_dist(s):
dist = [-1] * (N + 1)
dist[s] = 0
node = [s]
while node:
s = node.pop()
d = dist[s]
for t in edge[s]:
if dist[t] != -1:
continue
dist[t] = d + 1
node.append(t)
return dist[1:]
taka = calc_dist(u)
aoki = calc_dist(v)
ans = 0
for x, y in zip(taka, aoki):
if x <= y:
ans = max(ans, y - 1)
print(ans)
| nii=lambda:map(int,input().split())
from collections import deque
n,u,v=nii()
u-=1
v-=1
tree=[[] for i in range(n)]
for i in range(n-1):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
def BFS(s):
dist=[-1 for i in range(n)]
dist[s]=0
que=deque()
que.append(s)
while que:
x=que.popleft()
for i in tree[x]:
if dist[i]==-1:
que.append(i)
dist[i]=dist[x]+1
return dist
dist_t=BFS(u)
dist_a=BFS(v)
ans=0
for i in range(n):
if dist_a[i]>dist_t[i]:
ans=max(ans,dist_a[i]-1)
print(ans) | 1 | 117,655,119,167,712 | null | 259 | 259 |
X=int(input(""))
if 30<=X:
print("Yes")
else:
print("No")
| from itertools import combinations_with_replacement as R
N,M,Q = map(int, input().split())
L = [tuple(map(int, input().split())) for _ in range(Q)]
print(max([sum((d if S[b-1] - S[a-1] == c else 0) for a,b,c,d in L) for S in R(range(1, M+1), N)])) | 0 | null | 16,791,274,574,450 | 95 | 160 |
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
la = 10**6+1
cnt = [0] * la
for u in a:
cnt[u] += 1
for i in range(1, la):
cnt[i] += cnt[i-1]
def judge(x):
y = k
for i in range(n):
goal = x//f[i]
if a[i] > goal:
y -= a[i] - goal
if y < 0:
return False
return y >= 0
left = -1
right = 10**12 + 1
while left + 1 < right:
mid = (left + right)//2
if judge(mid):
right = mid
else:
left = mid
print(right)
| import math
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
F = sorted(list(map(int,input().split())),reverse=True)
high = 0
for i in range(N):
high = max(high,A[i]*F[i])
low = -1
while high-low>1:
mid = (high+low)//2
flag = 1
T = K
for i in range(N):
if A[i]*F[i]<=mid:continue
else:
T -= math.ceil(A[i]-mid/F[i])
if T<0:
flag = 0
break
if flag==1:
high = mid
else:
low = mid
print(high) | 1 | 165,467,502,536,096 | null | 290 | 290 |
def main():
num = list(map(int,input().split()))
if num[0]+num[1]+num[2]<22:
print('win')
else:
print('bust')
main() | def select(S):
for i in range(0, n):
minj = i
for j in range(i, n):
if int(S[j][1]) < int(S[minj][1]):
minj = j
(S[i], S[minj]) = (S[minj], S[i])
return S
def bubble(B):
flag = True
while flag:
flag = False
for j in reversed(range(1, n)):
if int(B[j][1]) < int(B[j-1][1]):
(B[j-1], B[j]) = (B[j], B[j-1])
flag = True
return B
def isStable(inA, out):
for i in range(0, n):
for j in range(i+1, n):
for a in range(0, n):
for b in range(a+1, n):
if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
return "Not stable"
return "Stable"
n = int(input())
A = input().split(' ')
B = bubble(A[:])
print(" ".join(B))
print(isStable(A, B))
S = select(A[:])
print(" ".join(S))
print(isStable(A, S)) | 0 | null | 59,367,520,518,810 | 260 | 16 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
P=LI()
Q=LI()
import itertools
cnt=0
p=0
q=0
for ite in itertools.permutations(range(1,N+1)):
if P==list(ite):
p=cnt
if Q==list(ite):
q=cnt
cnt+=1
print(abs(p-q))
main()
| S = input().split( )
a=int(S[0])
b=int(S[1])
c=int(S[2])
k=int(S[3])
t=2*a+b-k
if k <= a:
print(str(k))
elif a < k <= a + b:
print(str(a))
else: print(str(t))
| 0 | null | 61,305,369,675,488 | 246 | 148 |
n = int(input())
lst = list(map(int,input().split()))
lst2 = [0 for i in range(n)]
for i in range(n):
x = lst[i]
lst2[x - 1] = i + 1
for i in range(n):
if (i != n - 1):
print(lst2[i], end = ' ')
else:
print(lst2[i])
| #!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
a,b = LI()
A[i] = a
B[i] = b
A.sort()
B.sort()
if N % 2 == 1:
min_mid = A[(N - 1) // 2]
else:
min_mid = (A[N //2 - 1] + A[N//2]) / 2
if N % 2 == 1:
max_mid = B[(N - 1) // 2]
else:
max_mid = (B[N //2 - 1] + B[N//2]) / 2
if N % 2 == 0:
print(int((max_mid - min_mid) / 0.5 + 1))
else:
print(math.ceil(max_mid) - math.floor(min_mid) + 1)
| 0 | null | 98,997,358,846,682 | 299 | 137 |
xs=map(int,input().split())
print(' '.join(map(str, sorted(xs)))) | n = int(input())
s = 0
for i in range(1,n+1):
if i!=3 and i!=5 and i%3!=0 and i%5!=0:
s+=i
print(s) | 0 | null | 17,524,211,740,112 | 40 | 173 |
import sys
#input = sys.stdin.buffer.readline
N = int(input())
temp = 5
ans = 0
if N%2:
print(0)
quit()
else:
N = N//2
while temp <= N:
ans += N//temp
temp *= 5
print(ans) | line = input()
num_query = int(input())
for loop in range(num_query):
input_str = list(input().split())
if input_str[0] == 'replace':
left = int(input_str[1])
right = int(input_str[2])
right += 1
line = line[:left] + input_str[3] + line[right:]
elif input_str[0] == 'reverse':
left = int(input_str[1])
right = int(input_str[2])
right += 1
line = line[:left] + line[left:right][::-1] + line[right:]
else: # print
left = int(input_str[1])
right = int(input_str[2])
right += 1
for i in range(left, right):
print(line[i], end="")
print()
| 0 | null | 59,029,612,764,758 | 258 | 68 |
# B 1%
import math
X = int(input())
Y = 100
cnt = 0
while Y < X:
cnt += 1
# Y = math.floor(Y*1.01)
Y = Y + Y//100
print(cnt) | import math
x = int(input())
a = 100
year = 0
while a < x:
a = (a * 101)//100
year += 1
print(year) | 1 | 27,120,900,115,540 | null | 159 | 159 |
n,q = map(int,input().split())
A = []
B = []
C = []
t = 0
for i in range(n):
x,y = input().split()
A.append([x,int(y)])
while len(A)>0:
f = A[0][1]
if f<=q:
t += f
B.append(A[0][0])
C.append(t)
else:
t += q
A[0][1] -= q
A.append(A[0])
A.pop(0)
for j in range(len(B)):
print(B[j],C[j])
| n,k=map(int,input().split())
cnt=0
while(1):
if n//(k**cnt) == 0:
print(cnt)
break
cnt += 1 | 0 | null | 32,190,365,316,018 | 19 | 212 |
h= int(input())
w = int(input())
n = int(input())
a = max(h,w)
print(-(-n//a)) | S=input()
K=int(input())
if list(S).count(S[0])==len(S):
print(len(S)*K//2)
else:
S_count=0
i=0
while i<len(S)-1:
if S[i]==S[i+1]:
S_count+=1
i+=1
i+=1
if S[0]==S[-1]:
a=1
i=0
while i<len(S)-1:
if S[i]==S[i+1]:
a+=1
i+=1
else:
break
b=1
i=len(S)-1
while i>0:
if S[i]==S[i-1]:
b+=1
i+=-1
else:
break
S_count*=K
S_count-=(K-1)*(a//2 + b//2 - (a+b)//2)
else:
S_count*=K
print(S_count)
| 0 | null | 131,811,271,865,240 | 236 | 296 |
scores = []
while True:
a_score = [int(x) for x in input().split( )]
if a_score[0] == a_score[1] == a_score[2] == -1:
break
else:
scores.append(a_score)
for s in scores:
m,f,r = [int(x) for x in s]
if m == -1 or f == -1:
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65:
print('B')
elif m + f >= 50 or r >= 50:
print('C')
elif m + f >= 30:
print('D')
else:
print('F')
| # -*- coding: utf-8 -*-
while True:
score = list(map(int, input().split()))
if score[0] == -1 and score[1] == -1 and score[2] == -1:
break
elif -1 in (score[0], score[1]) or (score[0] + score[1]) < 30:
print('F')
elif (score[0] + score[1]) >= 80:
print('A')
elif 65 <= (score[0] + score[1]) < 80:
print('B')
elif 50 <= (score[0] + score[1]) < 65 or (30 <= (score[0] + score[1]) < 50 <= score[2]):
print('C')
elif 30 <= (score[0] + score[1]) < 50:
print('D')
| 1 | 1,236,539,494,820 | null | 57 | 57 |
N = list(input().split())
A = int(N[0])
b1,b2 = N[1].split('.')
B = int(b1+b2)
prd = list(str(A*B))
ans = 0
if len(prd) < 3:
ans = 0
else:
prd.pop()
prd.pop()
ans = int(''.join(prd))
print(ans)
| def main():
A, B = input().split()
A = int(A)
B100 = int(B[0] + B[2:])
print(A*B100//100)
if __name__ == "__main__":
main()
| 1 | 16,628,662,598,830 | null | 135 | 135 |
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7
def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def _get(T, a, b, k, l, r):
if r <= a or b <= l:
return set()
if a <= l and r <= b:
return T[k]
else:
s1 = _get(T, a, b, 2 * k + 1, l, (l + r) // 2)
s2 = _get(T, a, b, 2 * k + 2, (l + r) // 2, r)
return s1.union(s2)
def get(T, d, a, b):
return _get(T, a, b, 0, 0, 2 ** d)
def main():
N = int(input())
S = input().strip()
Q = [input().strip().split() for _ in range(int(input()))]
d = N.bit_length()
T = [set() for _ in range(2 ** (d + 1) - 1)]
for i, s in enumerate(S):
T[i + 2 ** d - 1].add(s)
for i in range(2 ** d - 2, -1, -1):
T[i] =T[2 * i + 1] .union(T[2 * i + 2])
for s, a, b in Q:
if s == "1":
a = int(a) - 1
i = a + 2 ** d - 1
if b in T[i]:
continue
T[i] = {b}
while i > 0:
i = (i - 1) // 2
T[i] = T[2 * i + 1] .union(T[2 * i + 2])
elif s == "2":
a = int(a) - 1
b = int(b) - 1
S = get(T, d, a, b + 1)
print(len(S))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
class SegmentTree():
def __init__(self, S, n):
self.size = n
self.array = [set()] * (2**(self.size + 1) - 1)
for i, c in enumerate(S):
self.array[i + 2**self.size - 1] = {c}
for i in range(2**self.size - 1)[::-1]:
self.array[i] = self.array[2 * i + 1] | self.array[2 * i + 2]
def subquery(self, l, r, k, i, j):
if j <= l or r <= i:
return set()
elif l <= i and j <= r:
return self.array[k]
else:
l_set = self.subquery(l, r, 2 * k + 1, i, (i + j) // 2)
r_set = self.subquery(l, r, 2 * k + 2, (i + j) // 2, j)
return l_set | r_set
def query(self, l, r):
return len(self.subquery(l, r, 0, 0, 2**self.size))
def update(self, i, c):
tmp = i + 2**self.size - 1
self.array[tmp] = {c}
while tmp > 0:
tmp = (tmp - 1) // 2
self.array[tmp] = self.array[2 * tmp + 1] | self.array[2 * tmp + 2]
n = int(input())
S = [ord(c) for c in list(input())]
segtree = SegmentTree(S, 19)
for _ in range(int(input())):
t, i, c = input().split()
if t == '1':
segtree.update(int(i)-1, ord(c))
if t == '2':
print(segtree.query(int(i)-1, int(c)))
| 1 | 62,324,431,787,394 | null | 210 | 210 |
import sys
from collections import defaultdict, Counter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = map(int, read().split())
N_MAX = 10 ** 6
min_factor = list(range(N_MAX + 1))
min_factor[2::2] = [2] * (N_MAX // 2)
for i in range(3, int(N_MAX ** 0.5) + 2, 2):
if min_factor[i] != i:
continue
for j in range(i * i, N_MAX + 1, 2 * i):
if min_factor[j] > i:
min_factor[j] = i
def prime_factorize_fast(n):
a = Counter()
while n != 1:
a[min_factor[n]] += 1
n //= min_factor[n]
return a
lcm_prime = Counter()
for a in A:
for p, n in prime_factorize_fast(a).items():
if lcm_prime[p] < n:
lcm_prime[p] = n
l = 1
for p, n in lcm_prime.items():
l = l * pow(p, n, MOD) % MOD
ans = 0
for a in A:
ans = (ans + pow(a, MOD - 2, MOD)) % MOD
ans = ans * l % MOD
print(ans)
return
if __name__ == '__main__':
main()
| 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]) | 0 | null | 63,114,738,651,018 | 235 | 178 |
while True:
h,w = map(int,raw_input().split())
if h==0 and w==0:
break
sside=""
for x in xrange(w):
sside += "#"
for x in xrange(h):
print sside
print | while True:
a,b = map(int, input().split())
if a == 0 and b == 0:
break
if a > 0 and b > 0:
for i in range(a):
for j in range(b):
print("#", end="")
print()
print()
| 1 | 789,118,150,888 | null | 49 | 49 |
a, b, k = map(int, input().split())
if a>=k:
print(a-k,b)
elif a<k and a+b>k:
print(0,b-(k-a))
else:
print(0,0) | def solve(a,b,k):
if k <= a: return a - k, b
elif k <= a + b: return 0, b - (k - a)
else: return 0, 0
a,b,k = map(int,input().split())
ans_1, ans_2 = solve(a,b,k)
print(f"{ans_1} {ans_2}") | 1 | 104,288,311,854,362 | null | 249 | 249 |
def insertion_sort(data, g):
global cnt
for i in range(g, len(data)):
v, j = data[i], i - g
while j >= 0 and data[j] > v:
data[j + g] = data[j]
j = j - g
cnt += 1
data[j + g] = v
def shell_sort(data):
global G
for i in range(1, 100):
tmp = (3 ** i - 1) // 2
if tmp > len(data):
break
G.append(tmp)
for g in list(reversed(G)):
insertion_sort(data, g)
G, cnt = [], 0
n = int(input())
data = list(int(input()) for _ in range(n))
shell_sort(data)
print(len(G))
print(' '.join(map(str, list(reversed(G)))))
print(cnt)
print('\n'.join(map(str, data))) | a = 0
b = 0
c = 0
d = 0
N = int(input())
S = []
for i in range(N):
S.append(input())
for j in range(N):
if S[j] == 'AC':
a += 1
elif S[j] == 'WA':
b += 1
elif S[j] == 'TLE':
c += 1
elif S[j] == 'RE':
d += 1
print('AC x', a)
print('WA x', b)
print('TLE x', c)
print('RE x', d) | 0 | null | 4,405,780,647,840 | 17 | 109 |
N=int(input())
M=1000
if N%M==0:
print(0)
else:
print(M-N%M) | import sys
N = input()
num = [int(x) for x in input().split()]
multiply = 1
if (0 in num):
print(0)
sys.exit()
for i in num:
multiply *= i
if (multiply > 10**18):
print(-1)
sys.exit()
if (0 < multiply and multiply <= 10**18):
print(multiply) | 0 | null | 12,311,444,838,630 | 108 | 134 |
k=int(input())
e="ACL"
et=""
for i in range(k):
et+=e
print(et) | n=int(input())
output=''
for _ in range(n):
output+='ACL'
print(output) | 1 | 2,199,526,540,640 | null | 69 | 69 |
import heapq
H, N = map(int, input().split())
A = [] #W
B = [] #V
for i in range(N):
ai, bi = map(int, input().split())
A += [ai]
B += [bi]
maxA = max(A)
dp = [[0 for j in range(H+maxA+1)]for i in range(N+1)]
for j in range(1, H+maxA+1):
dp[0][j] = float('inf')
for i in range(N):
for j in range(H+maxA+1):
if j - A[i] < 0:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + B[i])
ans = float('inf')
for j in range(H, H+maxA+1):
ans = min(ans, dp[N][j])
print(ans) | import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
sys.setrecursionlimit(10**5)
def main():
n, d, a = geta(int)
mon = []
ans = 0
for _ in range(n):
x, h = geta(int)
mon.append([x, (h + a - 1) // a])
mon.sort()
bom = deque()
cur = 0
for i, mi in enumerate(mon):
while len(bom) != 0 and bom[0][0] < mi[0]:
b = bom.popleft()
cur -= b[1]
if mi[1] <= cur:
continue
else:
b1 = mi[1] - cur
bom.append((mi[0] + 2 * d, b1))
cur += b1
ans += b1
print(ans)
if __name__ == "__main__":
main() | 0 | null | 81,732,061,141,248 | 229 | 230 |
#QQ
for i in range(1,10):
for n in range(1, 10):
print("%dx%d=%d" % (i, n, i * n)) | i=1
k=1
for k in range(1,10):
for i in range(1,10):
print(str(k)+"x"+str(i)+"="+str(k*i)) | 1 | 50,720 | null | 1 | 1 |
# -*- coding: utf-8 -*-
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
def shellSort(A, n):
def func(m):
if m == 0:
return 1
else:
return func(m-1)*3 + 1
G = []
i = 0
while True:
gi = func(i)
if gi <= n:
G.append(gi)
i += 1
else:
break
G = G[::-1]
for g in G:
insertionSort(A, n , g)
return A, G
if __name__ == '__main__':
n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
A, G = shellSort(A, n)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for i in range(n):
print(A[i])
| A = int(input())
B = int(input())
if A+B == 3:
print(3)
elif A+B == 4:
print(2)
else:
print(1) | 0 | null | 55,077,697,618,266 | 17 | 254 |
n,t = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
x.sort()
# n-1品目までで、t-1分までで達成できる美味しさ計算
dp = [[0]*t for i in range(n)]
for i in range(1,n):
a,b = x[i-1]
for j in range(1,t):
if j-a>=0:
dp[i][j] = max(dp[i-1][j-a]+b, dp[i][j-1], dp[i-1][j])
else:
dp[i][j] = max(dp[i][j-1], dp[i-1][j])
# 最後に一番時間かかるの食べるときの美味しさを計算
ans = 0
for i in range(n):
ans = max(ans, dp[n-1-i][t-1]+x[-i-1][1])
print(ans) | import sys
input = sys.stdin.readline
def solve():
N, T = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(N)]
items.sort()
capW = T-1
dp = [0] * (capW+1)
ans = 0
for wi, vi in items:
ans = max(ans, dp[-1]+vi)
for w in reversed(range(wi, capW+1)):
v0 = dp[w-wi] + vi
if v0 > dp[w]:
dp[w] = v0
print(ans)
solve()
| 1 | 151,475,960,801,240 | null | 282 | 282 |
import sys
input = lambda: sys.stdin.readline().rstrip()
INF = 10 ** 9 + 7
H, N = map(int, input().split())
AB = [[] for _ in range(N)]
for i in range(N):
AB[i] = list(map(int, input().split()))
def solve():
dp = [INF] * (H + 1)
dp[H] = 0
for h in range(H, 0, -1):
if dp[h] == INF:
continue
next_dp = dp
for i in range(N):
a, b = AB[i]
hh = max(0, h - a)
next_dp[hh] = min(dp[hh], dp[h] + b)
dp = next_dp
print(dp[0])
if __name__ == '__main__':
solve()
| (h, n), *m = [[*map(int, i.split())] for i in open(0)]
dp = [0] + [10**9] * h
for i in range(1, h + 1):
for a, b in m:
dp[i] = min(dp[i], dp[max(i-a,0)]+b)
print(dp[-1])
| 1 | 81,025,383,033,820 | null | 229 | 229 |
[N,K,S] = list(map(int,input().split()))
cnt = 0
output = []
if S != 10**9:
for i in range(K):
output.append(S)
for i in range(N-K):
output.append(S+1)
else:
for i in range(K):
output.append(S)
for i in range(N-K):
output.append(1)
print(*output) | n,k = map(int,input().split())
h = list(map(int, input().split()))
if n <= k:
print(0)
exit()
h.sort()
print(sum(h[:n-k])) | 0 | null | 85,219,690,561,812 | 238 | 227 |
n=int(input())
num_line=list(map(int,input().split()))
num_line.reverse()
print(" ".join(map(str,num_line)))
| n = int(input())
a = list(map(int, input().split()))
#print(a)
a.reverse()
print(*a)
| 1 | 963,967,019,808 | null | 53 | 53 |
def fibonacci(F,n):
F[0] = 1
F[1] = 1
for i in range(2,n+1,1):
F[i] = F[i-1] + F[i-2]
return F[n]
def main():
n = int(input())
F = [0]*(n+1)
ans = fibonacci(F,n)
return ans
print(main())
| #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
def fibo(n):
a, b = 1, 1
while n:
a, b = b, a + b
n -= 1
return a
print(fibo(int(stdin.readline()))) | 1 | 1,983,842,760 | null | 7 | 7 |
import math
T_1, T_2 = map(int, input().split())
A_1, A_2 = map(int, input().split())
B_1, B_2 = map(int, input().split())
ans = 0
if T_1 * A_1 + T_2 * A_2 == T_1 * B_1 + T_2 * B_2:
print("infinity")
else:
# 速いほうをAと仮定
if T_1 * A_1 + T_2 * A_2 < T_1 * B_1 + T_2 * B_2:
A_1, A_2, B_1, B_2 = B_1, B_2, A_1, A_2
if A_1 < B_1:
sa_12 = T_1 * A_1 + T_2 * A_2 - (T_1 * B_1 + T_2 * B_2) # 1サイクルでできる差
sa_1 = -T_1 * A_1 + T_1 * B_1 # T_1でできる差
if sa_1 % sa_12 == 0:
ans = int((sa_1 / sa_12)*2)
else:
kari = math.ceil(sa_1 / sa_12)
ans = (kari-1)*2+1
print(ans)
| mod = 10**9 + 7
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
print(0)
exit()
a = (2*Y-X)//3
b = (2*X-Y)//3
if a < 0 or b < 0:
print(0)
exit()
m = min(a, b)
ifact = 1
for i in range(2, m+1):
ifact = (ifact * i) % mod
ifact = pow(ifact, mod-2, mod)
fact = 1
for i in range(a+b, a+b-m, -1):
fact = (fact * i) % mod
print(fact*ifact % mod)
| 0 | null | 140,749,267,089,670 | 269 | 281 |
from collections import deque
N,M=map(int,input().split())
S=input()
j=N
ans=deque()
while j>0:
for i in range(M,0,-1):
if j-i==0:
ans.appendleft(i)
print(*ans)
elif j-i<0:
continue
if S[j-i]=="0":
ans.appendleft(i)
j-=i
break
if i==1 and S[j-i]=="1":
print(-1)
exit()
| n, m = map(int, input().split())
s = input()
x = n
roulette = []
while x > m:
for i in range(m, 0, -1):
if s[x-i] == '0':
x -= i
roulette.append(i)
break
else:
print(-1)
exit()
roulette.append(x)
roulette.reverse()
print(' '.join(map(str, roulette))) | 1 | 138,944,992,249,362 | null | 274 | 274 |
#変b数のまとめの入力についてsplitとインデックスで価を特定させる
youbi = "SUN,MON,TUE,WED,THU,FRI,SAT".split(",")
a = input()
print(7 - youbi.index(a)) | a = input()
if a == 'SUN':
print(7)
elif a == 'MON':
print(6)
elif a == 'TUE':
print(5)
elif a == 'WED':
print(4)
elif a == 'THU':
print(3)
elif a == 'FRI':
print(2)
else:
print(1)
| 1 | 132,820,917,368,960 | null | 270 | 270 |
I = input()
for i in range(len(I)):
if 'a' <= I[i] <= 'z':
print(I[i].upper(), end = '')
continue
if 'A' <= I[i] <= 'Z':
print(I[i].lower(), end = '')
continue
print(I[i], end = '')
print() | in_str = input().rstrip()
print(in_str.swapcase()) | 1 | 1,523,626,917,682 | null | 61 | 61 |
x = int(input())
a = 360
for _ in range(360):
if a%x == 0:
print(a//x)
break
else:
a += 360 | import math
x = int(input())
if 360 % x == 0:
print(360 // x)
else:
common = 360 * x // math.gcd(360, x)
ans = common // x
print(ans)
| 1 | 13,211,099,524,348 | null | 125 | 125 |
a,b=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
# print(c)
sum=0
for i in range(b):
sum+=c[i]
print(sum) | n, k = map(int, input().split())
p = sorted(map(int, input().split()))
print(sum(p[:k]))
| 1 | 11,670,831,311,138 | null | 120 | 120 |
a=[]
for i in range(10):
inp=input()
a.append(inp)
if i>=3:
a.sort()
del a[0]
print a[2]
print a[1]
print a[0] | from math import floor
H = int(input())
ans = 0
r = H
n = 0
while not (r == 1):
n += 1
ans += 2 ** n
r = floor(r / 2)
ans += 1
print(ans)
| 0 | null | 40,015,740,981,118 | 2 | 228 |
n = int(input())
s = [input() for _ in range(n)]
l = 0
r = 0
m = []
def fin():
print("No")
exit()
for word in s:
stack = []
for e in word:
if stack and stack[-1] == "(" and e == ")":
stack.pop()
else:
stack.append(e)
if stack:
if stack[0] == ")" and stack[-1] == "(":
m.append(stack)
elif stack[0] == ")":
r += len(stack)
else:
l += len(stack)
ml = []
mm = 0
mr = []
for word in m:
ll = word.index("(")
rr = len(word) - ll
if ll > rr:
mr.append([ll, rr])
elif ll < rr:
ml.append([ll, rr])
else:
mm = max(mm, ll)
ml.sort()
for ll, rr in ml:
l -= ll
if l < 0:
fin()
l += rr
mr.sort(key=lambda x: x[1])
for ll, rr in mr:
r -= rr
if r < 0:
fin()
r += ll
if mm <= l or mm <= r:
if l == r:
print("Yes")
exit()
fin()
| #!/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,823,426,447,872 | null | 152 | 152 |
import math
n=int(input())
ans=-1
for x in range(0,50000):
if n==math.floor(x*1.08):
ans=x
break
if ans==-1:
print(":(")
else:
print(ans) | n = int(input())
for i in range(50001):
if int(i * 1.08) == n:
print(i)
exit()
print(":(") | 1 | 125,658,423,976,710 | null | 265 | 265 |
n=int(input())
a=list(map(int,input().split()))
num=[i for i in range(1,n+1)]
order=dict(zip(num,a))
order2=sorted(order.items(),key=lambda x:x[1])
ans=[]
for i in range(n):
ans.append(order2[i][0])
print(' '.join([str(n) for n in ans])) | N = int(input())
A = list(map(int, input().split()))
dic = {i:0 for i in range(1, N + 1)}
for i in range(N):
a = A[i]
dic[a] = i + 1
for i in range(1, N + 1):
print(dic[i], end="")
if i != N:
print(" ", end="")
print() | 1 | 180,168,373,670,432 | null | 299 | 299 |
N = int(input())
a = []
typ = ["S ", "H ", "C ", "D "]
for i in range(N):
a.append(input())
for i in range(4):
for j in range(1, 14):
if typ[i] + str(j) not in a:
print(typ[i] + str(j)) | N = int(input())
S = input()
#print(ord("A"))
#print(ord("B"))
#print(ord("Z"))
for i in range(len(S)):
ascii = ord(S[i]) + N #Sのi文字目のアスキーコードを計算してしれにNを足してづらす
if ascii > ord("Z"): #アスキーコードがよりも大きくなった時はA初まりにづらす
ascii = ascii - (ord("Z") - ord("A") + 1)
print(chr(ascii),end = "") #,end = "" は1行ごとに改行しないでプリントする仕組み
| 0 | null | 68,053,697,786,270 | 54 | 271 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 10**9
for i in range(M):
x, y, c = map(int, input().split())
if ans > a[x-1] + b[y-1] - c:
ans = a[x-1] + b[y-1] - c
if min(a) + min(b) < ans:
ans = min(a) + min(b)
print(ans)
| N, K = map(int, input().split())
S = [i+1 for i in range(N)]
H = [0 for i in range(N)]
for i in range(K):
d = int(input())
A = list(map(int, input().split()))
for j in A:
for k in S:
if j==k:
H[k-1] += 1
ans = 0
for i in H:
if i==0:
ans += 1
print(ans) | 0 | null | 39,310,397,793,110 | 200 | 154 |
n = int(input())
s = input()
abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' * 2
ans = ''
for i in s:
ans += abc[abc.index(i)+n]
print(ans) | n = int(input())
s = input()
[print(chr((ord(s[i])+n-65)%26+65),end="") for i in range(len(s))]
| 1 | 134,441,160,302,560 | null | 271 | 271 |
N,M=map(int,input().split())
ans=['0']*N
I=[]
for _ in range(M):
s,c=input().split()
index=int(s)-1
if index==0 and N>1 and c=='0':
print(-1)
break
if index in I and ans[index]!=c:
print(-1)
break
ans[index]=c
I.append(index)
else:
if 0 not in I and N>1:
ans[0]='1'
print(''.join(ans)) | if __name__ == '__main__':
n,m = map(int,input().split())
A = [-1 for _ in range(n)]
B = []
for i in range(m):
x,y = map(int,input().split())
B.append([x,y])
flg = True
for a in B:
x = a[0]
y = a[1]
if A[x-1] == -1:
A[x-1] = y
else:
if A[x-1] != y:
flg = False
break
ans = 0
if flg:
#穴埋め
for i,j in enumerate(A):
if j == -1:
if i == 0 and len(A) != 1:
A[i] = 1
else:
A[i] = 0
tmp = ""
for k in range(n):
tmp += str(A[k])
tmp = str(int(tmp))
if len(tmp) == n :
ans = int(tmp)
else:
ans = -1
else:
ans = -1
print(ans)
| 1 | 60,486,146,986,144 | null | 208 | 208 |
X = int(input())
money = 100
time = 0
while money < X:
time += 1
money = money * 101 // 100
print(time) | x=int(input())
c=100
i=0
while True:
i+=1
c=c+c//100
if x<=c:
print(i)
exit()
| 1 | 27,119,190,857,888 | null | 159 | 159 |
#!/usr/bin/env python
import math
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
def lcm(a, b):
return a*b//math.gcd(a, b)
l = a[0]
for i in range(n):
l = lcm(l, a[i])
l %= mod
ans = 0
for i in range(n):
inv = pow(a[i], mod-2, mod)
ans += (l*inv)%mod
print(ans%mod)
| from collections import defaultdict
ps = []
for i in range(2, 1000):
is_p = True
for j in range(2, i):
if i % j == 0:
is_p = False
break
if is_p:
ps.append(i)
def factorization(n):
arr = defaultdict(int)
temp = n
for i in ps:
if i > int(-(-n**0.5//1))+1:
break
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr[i] = cnt
if temp!=1:
arr[temp] = 1
if arr==[]:
arr[n] = 1
return arr
aa = defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
fs = [[]] * 1000001
for i in a:
if not fs[i]:
fs[i] = factorization(i)
for i in a:
for k, v in fs[i].items():
aa[k] = max(aa[k], v)
mod = 10 ** 9 + 7
t = 1
for k, v in aa.items():
t = (t * (k ** v)) % mod
ans = 0
for i in a:
ans += t * pow(i, mod - 2, mod)
ans %= mod
print(ans)
| 1 | 87,642,689,038,492 | null | 235 | 235 |
M = 1046527
POW = [pow(4, i) for i in range(13)]
def insert(dic, string):
# i = 0
# while dic[(hash1(string) + i*hash2(string)) % M]:
# i += 1
# dic[(hash1(string) + i*hash2(string)) % M] = string
dic[get_key(string)] = string
def find(dic, string):
# i = 0
# while dic[(hash1(string) + i*hash2(string)) % M] and dic[(hash1(string) + i*hash2(string)) % M] != string:
# i += 1
# return True if dic[(hash1(string) + i*hash2(string)) % M] == string else False
# print(dic[get_key(string)], string)
return True if dic[get_key(string)] == string else False
def get_num(char):
if char == "A":
return 1
elif char == "C":
return 2
elif char == "G":
return 3
else:
return 4
def get_key(string):
num = 0
for i in range(len(string)):
num += POW[i] * get_num(string[i])
return num
def main():
n = int(input())
dic = [None] * POW[12]
# print(dic)
for i in range(n):
order, string = input().split()
if order == "insert":
insert(dic, string)
else:
if find(dic, string):
print('yes')
else:
print('no')
if __name__ == "__main__":
main()
| for i in range(input()):
q = map(int,raw_input().split())
q.sort()
a = "YES" if q[0]**2 + q[1]**2 == q[2]**2 else "NO"
print a | 0 | null | 39,900,057,168 | 23 | 4 |
a=int(input())
b,c=input().split()
b=int(b)
c=int(c)
if b%a==0 or c%a==0:
print("OK")
else:
if int(b/a)==int(c/a):
print("NG")
else:
print("OK") | n = int(input())
lim_min, lim_max = map(int, input().split())
if lim_min % n == 0 :
print('OK')
elif lim_min + n - (lim_min % n) <= lim_max:
print('OK')
else:
print('NG')
| 1 | 26,503,119,825,792 | null | 158 | 158 |
n,q = map(int,input().split())
queue = []
for i in range(n):
name,time = input().split()
queue.append((name, int(time)))
t = 0
while queue:
name,time = queue.pop(0)
t += min(q, time)
if time > q:
queue.append((name, time-q))
else:
print(name,t)
| a=input()
num=[]
for x in range(int(a)+1):
if x!=0 and x%3==0 or x%10==3 or "3" in str(x):
num.append(x)
str_list=map(str,num)
print(" "+" ".join(str_list)) | 0 | null | 490,703,816,174 | 19 | 52 |
r, c, k = map(int, input().split())
atlas = [[0]*c for i in range(r)]
dp = [[[0]*c for i in range(r)] for j in range(4)]
for i in range(k):
x, y, v = map(int, input().split())
atlas[x-1][y-1] = v
def max_sum(r, c, atlas):
global dp
if atlas[0][0] > 0:
dp[1][0][0] = atlas[0][0]
for i in range(r):
for j in range(c):
for h in range(4):
if j+1 < c:
dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
if atlas[i][j+1] > 0 and h < 3:
dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
if i+1 < r:
dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
if atlas[i+1][j] > 0:
dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
return dp
max_sum(r, c, atlas)
ans = 0
for i in range(4):
ans = max(ans, dp[i][r-1][c-1])
print(ans) | s = input()
res = 0
if s == "SUN":
res = 7
elif s == "MON":
res = 6
elif s == "TUE":
res = 5
elif s == "WED":
res = 4
elif s == "THU":
res = 3
elif s == "FRI":
res = 2
elif s == "SAT":
res = 1
print(res) | 0 | null | 69,295,707,649,480 | 94 | 270 |
def main():
N = int(input())
s={""}
for _ in range(N):
s.add(input())
return len(s)-1
if __name__ == '__main__':
print(main()) | n = int(input())
s = [[] for _ in range(n)]
for i in range(n):
s[i] = input()
s = set(s)
print(len(s))
| 1 | 30,089,056,097,170 | null | 165 | 165 |
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
if A[i] < A[i-1]:
step = A[i-1] - A[i]
A[i] += step
ans += step
print(ans) | # get input from user and convert in to int
current_temp = int(input())
# Check that the restriction per task instruction is met
if (current_temp <= 40) and (current_temp >= -40):
# Check if current_temp is greater than or equal to 30
if current_temp >= 30:
print("Yes")
else:
print("No") | 0 | null | 5,154,970,070,902 | 88 | 95 |
n=int(input())
a=list(map(int,input().split()))
toki=a[0]
shigi=0
for i in range(1,n):
if toki>a[i]:
shigi += toki-a[i]
else:toki=a[i]
print(shigi)
| n,m = tuple(int(i) for i in input().split())
A = [[int(j) for j in input().split()] for k in range(n)]
b = [int(input()) for p in range(m)]
R = [sum([A[p][q] * b[q] for q in range(m)]) for p in range(n)]
for r in R:
print(str(r))
| 0 | null | 2,845,489,475,140 | 88 | 56 |
import math
R = int(input())
round_R = 2 * R * math.pi
print(round(round_R, 10)) | # coding: utf-8
n = int(input().rstrip())
count = 0
for i in range(1,n//2+1):
m = n - i
if i != m:
count += 1
print(count) | 0 | null | 92,165,544,675,370 | 167 | 283 |
a,b=map(int,input().split())
x=str(a)*b
y=str(b)*a
if x<y:
print(x)
else:
print(y) | n = int(input())
mydict = {}
answer_list = []
for i in range(n) :
query, wd = input().split()
if query == "insert" :
mydict[wd] = 1
else :
if wd in mydict.keys() : answer_list.append("yes")
else : answer_list.append("no")
for i in answer_list :
print(i)
| 0 | null | 42,187,546,893,142 | 232 | 23 |
flag = True
count = 0
l = []
for s in input():
if flag:
if s == "R":
count += 1
l.append(count)
else:
l.append(0)
count = 0
print(max(l))
| def main():
s = input()
mod = 2019
mod_count = {i: 0 for i in range(mod)}
now_num = 0
base = 1
for i in range(len(s) - 1, -1, -1):
mod_count[now_num] += 1
now_num += base * int(s[i])
now_num %= mod
base *= 10
base %= mod
ans = 0
mod_count[now_num % mod] += 1
for i in range(mod):
ans += mod_count[i] * (mod_count[i] - 1) // 2
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 17,906,503,294,944 | 90 | 166 |
n = int(input())
numbers = list(map(int, input().split()))
print(' '.join(str(x) for x in numbers))
for i in range(1, n):
key = numbers[i]
j = i - 1
while 0 <= j and key < numbers[j]:
numbers[j+1] = numbers[j]
j -= 1
numbers[j+1] = key
print(' '.join(str(x) for x in numbers)) | n=int(input())
a,b=map(str, input().split())
l = []
for i in range(n):
l.append(a[i])
l.append(b[i])
print(''.join(l)) | 0 | null | 55,837,466,163,442 | 10 | 255 |
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
def get_inv(n, modp):
return pow(n, modp-2, modp)
def factorials_list(n, modp): # 10**6
fs = [1]
for i in range(1, n+1):
fs.append(fs[-1] * i % modp)
return fs
def invs_list(n, fs, modp): # 10**6
invs = [get_inv(fs[-1], modp)]
for i in range(n, 1-1, -1):
invs.append(invs[-1] * i % modp)
invs.reverse()
return invs
def comb(n, k, modp):
num = 1
for i in range(n, n-k, -1):
num = num * i % modp
den = 1
for i in range(2, k+1):
den = den * i % modp
return num * get_inv(den, modp) % modp
def comb_from_list(n, k, modp, fs, invs):
return fs[n] * invs[n-k] * invs[k] % modp
#
class UnionFindEx:
def __init__(self, size):
#正なら根の番号、負ならグループサイズ
self.roots = [-1] * size
def getRootID(self, i):
r = self.roots[i]
if r < 0: #負なら根
return i
else:
r = self.getRootID(r)
self.roots[i] = r
return r
def getGroupSize(self, i):
return -self.roots[self.getRootID(i)]
def connect(self, i, j):
r1, r2 = self.getRootID(i), self.getRootID(j)
if r1 == r2:
return False
if self.getGroupSize(r1) < self.getGroupSize(r2):
r1, r2 = r2, r1
self.roots[r1] += self.roots[r2] #サイズ更新
self.roots[r2] = r1
return True
Yes = 'Yes'
No = 'No'
def main():
N=ii()
up = []
down = []
for _ in range(N):
S = input()
h = 0
b = 0
for s in S:
if s=='(':
h += 1
else:
h -= 1
b = min(b, h)
#
if h>=0:
up.append((h, b))
else:
down.append((h, b))
#
up.sort(key=lambda t: t[1], reverse=True)
down.sort(key=lambda t: t[0]-t[1], reverse=True)
H = 0
for h, b in up:
if H+b>=0:
H += h
else:
print(No)
return
for h, b in down:
if H+b>=0:
H += h
else:
print(No)
return
#
if H == 0:
print(Yes)
else:
print(No)
main()
| from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N = int(input())
L = []
Slist1 = []
Slist2 = []
R = []
l = 0; r = 0
for i in range(N):
M = 0; end = None
var = 0
S = input()
for j in S:
if j == "(":
var += 1
l += 1
else:
var -= 1
r += 1
M = min(var, M)
end = var
if M == 0:
L.append([M, end])
elif M == end:
R.append([M, end])
elif M < 0 and end > 0:
Slist1.append([-M, end])
else:
Slist2.append([M - end, M, end])
Slist1 = sorted(Slist1)
Slist2 = sorted(Slist2)
if l != r:
print("No")
return
cnt = 0
X = len(L)
for i in range(X):
cnt += L[i][1]
judge = "Yes"
X = len(Slist1)
for i in range(X):
M = Slist1[i][0]
cnt -= M
if cnt < 0:
judge = "No"
break
else:
cnt += M + Slist1[i][1]
X = len(Slist2)
for i in range(X):
cnt += Slist2[i][1]
if cnt < 0:
judge = "No"
break
else:
cnt -= Slist2[i][0]
print(judge)
if __name__ == '__main__':
main() | 1 | 23,597,292,726,072 | null | 152 | 152 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.