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
|
---|---|---|---|---|---|---|
class D_Linked_List:
class Node:
def __init__(self, key, next = None, prev = None):
self.next = next
self.prev = prev
self.key = key
def __init__(self):
self.nil = D_Linked_List.Node(None)
self.nil.next = self.nil
self.nil.prev = self.nil
def insert(self, key):
node_x = D_Linked_List.Node(key, self.nil.next, self.nil)
self.nil.next.prev = node_x
self.nil.next = node_x
def _listSearch(self, key):
cur_node = self.nil.next
while (cur_node != self.nil) and (cur_node.key != key):
cur_node = cur_node.next
return cur_node
def _deleteNode(self, node):
if node == self.nil:
return None
node.prev.next = node.next
node.next.prev = node.prev
def deleteFirst(self):
self._deleteNode(self.nil.next)
def deleteLast(self):
self._deleteNode(self.nil.prev)
def deleteKey(self, key):
node = self._listSearch(key)
self._deleteNode(node)
def show_keys(self):
cur_node = self.nil.next
keys = []
while cur_node != self.nil:
keys.append(cur_node.key)
cur_node = cur_node.next
print(' '.join(keys))
import sys
d_ll = D_Linked_List()
for i in sys.stdin:
if 'insert' in i:
x = i[7:-1]
d_ll.insert(x)
elif 'deleteFirst' in i:
d_ll.deleteFirst()
elif 'deleteLast' in i:
d_ll.deleteLast()
elif 'delete' in i:
x = i[7:-1]
d_ll.deleteKey(x)
else:
pass
d_ll.show_keys() | from collections import deque
dq=deque()
n=int(input())
for i in range(n):
com=input().split()
if com[0]=='insert':
dq.appendleft(com[1])
elif com[0]=='deleteFirst':
dq.popleft()
elif com[0]=='deleteLast':
dq.pop()
else:
if com[1] in dq:
dq.remove(com[1])
print(' '.join(dq)) | 1 | 49,314,510,788 | null | 20 | 20 |
l = [1,2,3]
A = int(input())
B = int(input())
for i in range(3):
if l[i]!=A and l[i]!=B:
print(l[i]) | N, D, A = map(int, input().split())
data = []
for _ in range(N):
data.append(tuple(map(int, input().split())))
data.sort()
queue = []
i = 0
j = 0
total = 0
height = 0
while i < N:
if j >= len(queue) or data[i][0] <= queue[j][0]:
x, h = data[i]
i += 1
if height < h:
count = (h - height + A - 1) // A
total += count
height += count * A
queue.append((x + D * 2, count * A))
else:
height -= queue[j][1]
j += 1
print(total)
| 0 | null | 96,419,586,798,912 | 254 | 230 |
def gcd(x, y):
if x < y:
x, y = y, x
while y != 0:
x, y = y, x % y
return x
if __name__ == "__main__":
x, y = list(map(int, input().split()))
print(gcd(x, y)) | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B
x, y = map(int, input().split())
if y > x:
w = y
y = x
x = w
while y > 0:
amari = x % y
x = y
y = amari
print(x) | 1 | 7,769,556,552 | null | 11 | 11 |
n = int(input())
stone = list(input())
l = 0
r = n-1
ans = 0
while l < r:
if stone[l]=='W':
if stone[r]=='R':
ans += 1
l += 1
r -= 1
else:
r -= 1
else:
l += 1
if stone[r]=='W':
r -= 1
print(ans) | import collections
n = int(input())
a = list(map(int, input().split()))
l = []
r = []
for i in range(n):
l.append(i+a[i])
r.append(i-a[i])
count_l = collections.Counter(l)
count_r = collections.Counter(r)
ans = 0
for i in count_l:
ans += count_r.get(i,0) * count_l[i]
print(ans) | 0 | null | 16,164,739,799,912 | 98 | 157 |
x = [int(x) for x in input().split()]
print(x[2],x[0],x[1])
| n = int(input())
s = input().split()
q = int(input())
t = input().split()
res = 0
for i in t:
if i in s:
res +=1
print(res)
| 0 | null | 19,114,462,575,132 | 178 | 22 |
h, n = [int(i) for i in input().split()]
magics = [None]
class Magic:
def __init__(self, attack, cost):
self.attack = attack
self.cost = cost
maxA = 0
for i in range(n):
attack, cost = [int(i) for i in input().split()]
maxA = max(maxA, attack)
magics.append(Magic(attack, cost))
dp = [[10 ** 9 for i in range(h + maxA)] for j in range(n + 1)]
for i in range(n + 1):
for j in range(h + maxA):
if j == 0:
dp[i][j] = 0
elif i == 0:
continue
elif j - magics[i].attack >= 0:
dp[i][j] = min(dp[i - 1][j], dp[i][j - magics[i].attack] + magics[i].cost)
else:
dp[i][j] = dp[i - 1][j]
print(min(dp[-1][h:]))
| N = list(map(int, input().split(' ')))
W = N[0]
H = N[1]
x = N[2]
y = N[3]
r = N[4]
if r <= x < W and (x + r) <= W and r <= y < W and (y + r) <= H:
print('Yes')
else:
print('No') | 0 | null | 40,969,664,129,618 | 229 | 41 |
n, m = (int(i) for i in input().split())
tot = sum(int(i) for i in input().split())
if tot > n:
print(-1)
else:
print(n - tot)
| import math
def main():
n,m = map(int,input().split())
a = list(map(int,input().strip().split()))
if n >= sum(a):
print(n-sum(a))
return
else:
print(-1)
return
main()
| 1 | 31,909,004,910,822 | null | 168 | 168 |
K = int(input())
A, B = map(int, input().split())
ans = "NG"
for i in range(A, B + 1):
if i % K == 0:
ans = "OK"
break
print(ans) | k = int(input())
a, b = map(int, input().split())
i = 1
ans = "NG"
while k*i <= b:
if a <= k*i:
ans = "OK"
break
i += 1
print(ans) | 1 | 26,592,202,369,138 | null | 158 | 158 |
if __name__ == '__main__':
n = int(input())
s = set(input().split())
if len(s) == n:
print("YES")
else:
print("NO")
| #!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
S = LI()
if len(set(S)) == N:
print("YES")
else:
print("NO")
main()
| 1 | 73,689,198,367,570 | null | 222 | 222 |
data = []
for i in range(10):
data.append(int(raw_input()))
data.sort(reverse = True)
print data[0]
print data[1]
print data[2] | n = input()
for i in xrange(n):
tmp = map(int, raw_input().split())
if tmp[0]**2 + tmp[1]**2 == tmp[2]**2 or tmp[1]**2 + tmp[2]**2 == tmp[0]**2 or tmp[2]**2 + tmp[0]**2 == tmp[1]**2:
print "YES"
else:
print "NO" | 0 | null | 133,039,820 | 2 | 4 |
A, B =map(float,input().split())
A = int(A)
B = int(B*100+0.5)
ans = A*B//100
print(ans) | import math
a, b = map(str, input().split())
a2 = int(a)
b2 = int(b.replace('.', ''))
print(int((a2 * b2)//100)) | 1 | 16,542,905,916,350 | null | 135 | 135 |
def divisor(n):
i = 1
table = []
while i * i <= n:
if n%i == 0:
table.append(i)
table.append(n//i)
i += 1
table = list(set(table))
return table
n = int(input())
ans = n
divisor_num = divisor(n)
for i in divisor_num:
j = n // i
tmp = i + j - 2
ans = min(ans, tmp)
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) | 0 | null | 139,535,378,951,580 | 288 | 259 |
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
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())
def conv_num2x(num, x):
if (int(num/x)):
return conv_num2x(int(num/x), x)+str(num%x)
return str(num%x)
def main():
N,K = LI()
num_k = conv_num2x(N,K)
print(len(str(num_k)))
main()
| N, K = list(map(int, input().rstrip().split()))
r = 0
while 0 < N:
r += 1
N = int(N / K)
print(r)
| 1 | 64,057,438,805,890 | null | 212 | 212 |
# ai の大きい方から左端か右端
# はるかに問題なのはそこから先だがDP
n=int(input())
*a,=map(int, input().split( ))
dp = [0]
#周回が総数、dpのindexが左に置いた数
aii = [(ai,i) for i,ai in enumerate(a)]
aii.sort(key= lambda x:-x[0])
for j,(ai,i) in enumerate(aii):
dp2 = [0]*(j+2)
dp2[0]=dp[0]+ai*abs(n-j-1-i)
dp2[-1]=dp[-1]+ai*abs(j-i)
for k in range(j):
dp2[k+1] = max(dp[k]+ai*abs(k-i), dp[k+1]+ai*abs((n-(j-k-1)-1)-i))##abs((n-(j-k-1)-1)-i)
dp = dp2
print(max(dp)) | N=int(input())
A=list(map(int,input().split()))
B=[]
for k in range(N):
B.append([A[k],k+1])
B.sort(key=lambda x: x[0], reverse=True)
dp=[[0 for k in range(N+1)]for k in range(N+1)]
dp[1][0]=dp[0][0]+B[0][0]*(B[0][1]-1)
dp[0][1]=dp[0][0]+B[0][0]*(N-B[0][1])
for k in range(1,N):
#j=0
dp[0][k+1]=dp[0][k]+B[k][0]*(N-k-B[k][1])
dp[1][k]=max(dp[0][k]+B[k][0]*(B[k][1]-1), dp[1][k-1]+B[k][0]*(N-k+1-B[k][1]))
#j=k
dp[k+1][0]=dp[k][0]+B[k][0]*(B[k][1]-k-1)
dp[k][1]=max(dp[k-1][+1]+B[k][0]*(B[k][1]-k), dp[k][0]+B[k][0]*(N-B[k][1]))
for j in range(1,k):
dp[j+1][k-j]=max(dp[j][k-j]+B[k][0]*(B[k][1]-j-1), dp[j+1][k-j-1]+B[k][0]*(N-k+j+1-B[k][1]))
dp[j][k-j+1]=max(dp[j-1][k-j+1]+B[k][0]*(B[k][1]-j), dp[j][k-j]+B[k][0]*(N-k+j-B[k][1]))
ans=[]
for k in range(N+1):
ans.append(dp[k][N-k])
print(max(ans)) | 1 | 33,532,826,748,018 | null | 171 | 171 |
N, M, L = map(int, input().split())
D = [[1000000000000]*N for i in range(N)]
for i in range(N):
D[i][i] = 0
for i in range(M):
A, B, C = map(int, input().split())
A, B = A-1, B-1
D[A][B] = C
D[B][A] = C
for k in range(N):
for i in range(N):
for j in range(N):
D[i][j] = min(D[i][j], D[i][k]+D[k][j])
E = [[1000000000000]*N for i in range(N)]
for i in range(N):
E[i][i] = 0
for i in range(N):
for j in range(N):
if D[i][j] <= L:
E[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(N):
E[i][j] = min(E[i][j], E[i][k]+E[k][j])
Q = int(input())
for i in range(Q):
s, t = map(int, input().split())
s, t = s-1, t-1
if E[s][t] == 1000000000000:
r = -1
else:
r = E[s][t]-1
print(r)
| given = input()
data = given.strip().split()
X = int(data[0])
Y = int(data[1])
i = 0
ashi = 0
while (i <= X):
ashi = 2 * (X - i) + 4 * i
if ashi == Y:
print("Yes")
break
i = i + 1
if i == X + 1 and ashi != Y:
print("No") | 0 | null | 93,585,763,547,250 | 295 | 127 |
import os
import sys
import numpy as np
def solve(N, M, A):
# n 以上上がる方法だけを試した時に、M 回以上の握手を行うことができるか
ok = 0
ng = 202020
while ok + 1 < ng:
c = ok+ng >> 1
cnt = 0
idx_A = N-1
for a1 in A:
while idx_A >= 0 and A[idx_A]+a1 < c:
idx_A -= 1
cnt += idx_A + 1
if cnt >= M:
ok = c
else:
ng = c
idx_A = N-1
cum_A = np.zeros(len(A)+1, dtype=np.int64)
cum_A[1:] = np.cumsum(A)
ans = 0
cnt = 0
for a1 in A:
while idx_A >= 0 and A[idx_A]+a1 < ok:
idx_A -= 1
cnt += idx_A + 1
ans += cum_A[idx_A+1] + (idx_A+1)*a1
ans -= (cnt-M) * ok
return ans
# >>> numba compile >>>
numba_config = [
[solve, "i8(i8,i8,i8[:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
vars()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
from numba import njit
for func, signature in numba_config:
vars()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
# <<< numba compile <<<
def main():
N, M = map(int, input().split())
A = np.array(sorted(map(int, input().split()), reverse=True), dtype=np.int64)
ans = solve(N, M, A)
print(ans)
main()
| k = int(input())
mod = 7 % k
counter = 1
memo = 1
mod_map = set()
mod_map.add(mod)
while mod != 0:
mod = ((mod * 10) % k + 7) % k
if mod not in mod_map:
mod_map.add(mod)
else:
counter = -1
break
counter += 1
if mod == 0:
break
print(counter)
| 0 | null | 57,364,251,392,680 | 252 | 97 |
X, K, D = map(int, input().split())
value = abs(X)
if (value / D) >= K:
print(value - D * K)
else:
min_count = value // D
mod_value = K - min_count
if mod_value % 2 == 0:
print(value % D)
else:
print(abs(value % D - D)) | import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
x,k,d = map(int,readline().split())
x = abs(x)
if (x >= k*d):
print(x-k*d)
elif ((k-x//d)%2):
print(abs(x%d-d))
else:
print(x%d)
| 1 | 5,256,717,873,092 | null | 92 | 92 |
N = int(input())
results = [input() for _ in range(N)]
C = [0] * 4
dic = ['AC', 'WA', 'TLE', 'RE']
for result in results:
for i in range(4):
if result == dic[i]:
C[i] += 1
break
for j in range(4):
print(dic[j] + ' x ' + str(C[j])) | n=int(input())
s=input().split()
q=int(input())
t=input().split()
cnt=0
for i in range(q):
for j in range(n):
if s[j]==t[i]:
cnt+=1
break
print(cnt)
| 0 | null | 4,354,395,655,980 | 109 | 22 |
# from fractions import gcd
# P = 10**9+7
# N = int(input())
# S = list(map(int, input().split()))
# l = {2:0}
# for num in S:
# temp = num
# M = temp//2+2
# cnt = 0
# while temp%2 == 0:
# cnt += 1
# temp //= 2
# l[2] = max(l[2], cnt)
# i = 3
# while temp > 1 and i < M:
# cnt = 0
# while temp%i == 0:
# cnt += 1
# temp //= i
# if cnt > 0:
# if i in l:
# l[i] = max(l[i], cnt)
# else:
# l[i] = cnt
# i += 2
# if temp > 1:
# if temp in l:
# l[temp] = max(l[temp], 1)
# else:
# l[temp] = 1
# ans = 0
# for i in range(N):
# ans = (temp//S[i]+ans)%P
# print(ans)
from fractions import gcd
P = 10**9+7
N = int(input())
S = list(map(int, input().split()))
temp = S[0]
for i in range(1, N):
temp = temp*S[i] // gcd(temp, S[i])
temp %= P
ans = 0
for num in S:
ans = ((temp*pow(num, P-2, P))%P+ans)%P
print(ans) | x=[]
y=[]
while True:
i,j=map(int,raw_input().split())
if (i,j)==(0,0):
break;
x.append(i)
y.append(j)
X=iter(x)
Y=iter(y)
for a in X:
b=Y.next()
if a<b:
print('%d %d'%(a,b))
else:
print('%d %d'%(b,a)) | 0 | null | 44,263,289,670,028 | 235 | 43 |
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
# bit all search
pattern = []
for i in range(2 ** n):
bit_set = []
for j in range(n):
if ((i >> j) & 1):
bit_set.append(A[j])
pattern.append(sum(bit_set))
#print(pattern)
for m in m:
if m in pattern:
print('yes')
else:
print('no')
| #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from itertools import combinations
def enum_sum_numbers(sets, s_range, r):
for cmb in combinations(sets, r):
yield sum(cmb)
if r <= s_range:
for s in enum_sum_numbers(sets, s_range, r+1):
yield s
stdin.readline()
a = [int(s) for s in stdin.readline().split()]
stdin.readline()
ms = [int(s) for s in stdin.readline().split()]
sets = {s for s in enum_sum_numbers(a, len(a), 1)}
for m in ms:
print('yes' if m in sets else 'no') | 1 | 101,653,613,120 | null | 25 | 25 |
from math import gcd
def readinput():
n,m=map(int,input().split())
a=list(map(int,input().split()))
return n,m,a
def lcm(a,b):
return a*b//gcd(a,b)
def main(n,m,a):
#s=set(a)
#print(s)
x=a[0]//2
for i in range(1,n):
x=lcm(x,a[i]//2)
#print(x)
gusubai=False
kisubai=False
for i in range(n):
if x%a[i]!=0:
gusubai=True
else:
kisubai=True
y=m//x
#print(y,x,m)
if gusubai and not kisubai:
ans=y//2+y%2
elif gusubai and kisubai:
ans=0
else:
ans=y
return ans
if __name__=='__main__':
n,m,a=readinput()
ans=main(n,m,a)
print(ans)
| def gcd(x, y):
while y > 0:
r = x % y
x = y
y = r
return x
def lcm(x, y):
return x // gcd(x, y) * y
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = 1
for i in range(n):
a[i] //= 2
l = lcm(a[i], l)
flg = True
for x in a:
if (l // x) % 2 == 0:
flg = False
break
if flg:
print(m // l - m // (l * 2))
else:
print(0) | 1 | 101,306,014,282,000 | null | 247 | 247 |
H, W = map(int, input().split())
if H >= 2 and W >= 2:
if H % 2 == 0:
print((H * W) // 2)
else:
print(((H - 1) * W) // 2 + (W + 1) // 2)
else:
print(1)
| x = list(map(int,input().split()))
H = x[0]
W = x[1]
if H == 1 or W == 1:
print(1)
else:
if W % 2 == 0:
print(int(H*W/2))
else:
if H % 2 == 0:
print(int(H*(W-1)/2 + H/2))
else:
print(int(H*(W-1)/2 + (H+1)/2))
| 1 | 50,822,338,126,222 | null | 196 | 196 |
import math
import itertools
n=int(input())
d=[list(map(int,input().split())) for _ in range(n)]
ans=cnt=0
for i in itertools.permutations([_ for _ in range(n)]):
for j in range(n-1):
x1,x2=d[i[j]][0],d[i[j+1]][0]
y1,y2=d[i[j]][1],d[i[j+1]][1]
ans+=math.sqrt((x1-x2)**2+(y1-y2)**2)
cnt+=1
#print(j,ans,cnt)
print(ans/cnt) | 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) | 1 | 148,271,325,900,060 | null | 280 | 280 |
#!/usr/bin/env python3
import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random # random, uniform, randint, randrange, shuffle, sample
# import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce # reduce(f, iter[, init])
# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate # accumulate(iter[, f])
# from operator import itemgetter # itemgetter(1), itemgetter('key')
# from fractions import Fraction # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10)
def main():
mod = 1000000007 # 10^9+7
inf = float('inf') # sys.float_info.max = 1.79e+308
# inf = 2 ** 63 - 1 # (for fast JIT compile in PyPy) 9.22e+18
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def isp(): return input().split()
def mi(): return map(int, input().split())
def mi_0(): return map(lambda x: int(x)-1, input().split())
def lmi(): return list(map(int, input().split()))
def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
def li(): return list(input())
L = list(map(int, reversed(li())))
n = len(L)
payment = L[:]
payment.append(0)
ans = 0
carry = False
for i in range(n):
if 5 < payment[i] or (5 == payment[i] and 5 <= payment[i+1]):
ans += 9 - L[i] if carry else 10 - L[i]
payment[i] = 0
payment[i+1] += 1
carry = True
else:
carry = False
# print(L)
# print(list(reversed(payment)))
ans += sum(payment)
# ans = 0
# ans += sum(payment)
# a = int(''.join(list(map(str, reversed(L)))))
# b = int(''.join(list(map(str, reversed(payment)))))
# # print(f"required {a}, paid: {b}")
# ans += sum(map(int, list(str(b - a))))
print(ans)
if __name__ == "__main__":
main()
| def main():
s = input()
dp = [0, 1]
for c in s:
x = int(c)
a = dp[0] + x
if a > dp[1] + 10 - x:
a = dp[1] + 10 - x
b = dp[0] + x + 1
if b > dp[1] + 10 - x - 1:
b = dp[1] + 10 - x - 1
dp[0] = a
dp[1] = b
dp[1] += 1
print(min(dp))
if __name__ == "__main__":
main()
| 1 | 70,769,263,563,040 | null | 219 | 219 |
from collections import Counter
N = int(input())
As = list(map(int,input().split()))
cnt = Counter(As)
for i in range(1,N+1):
print(cnt[i]) | def main():
N = int(input())
A = list(map(int,input().split()))
list_a = [0]*N
for i in range(len(A)):
list_a[A[i]-1] += 1
for i in range(N):
print(list_a[i])
main()
| 1 | 32,540,864,878,548 | null | 169 | 169 |
from itertools import permutations
from math import factorial
n = int(input())
p = tuple(map(int, input().split(' ')))
q = tuple(map(int, input().split(' ')))
l = [i for i in range(1, n+1)]
ls = list(permutations(l))
for i in range(factorial(n)):
if p==ls[i]:
a = i
if q==ls[i]:
b = i
print(abs(a-b)) | n = int(input())
lis = list(map(int,input().split()))
sum = 0
for i in range(n-1):
if int(lis[i])>int(lis[i+1]):
sum += lis[i]-lis[i+1]
lis[i+1] = lis[i]
else:
continue
print(sum) | 0 | null | 52,425,523,084,428 | 246 | 88 |
from sys import stdin
def ans():
_in = [_.rstrip() for _ in stdin.readlines()]
S = _in[0] # type:str
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
if S[-1] == 's':
S += 'es'
else:
S += 's'
ans = S
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
def main():
_in = [_.rstrip() for _ in stdin.readlines()]
S = list(_in[0]) # type:str
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
ans = 0
if S[-1] == 's':
S[-1] += 'es'
else:
S[-1] += 's'
ans = ''.join(S)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
if __name__ == "__main__":
#main()
ans()
| x,y,z= map(str, input().split())
print(z,x,y, sep=' ') | 0 | null | 20,120,638,634,272 | 71 | 178 |
s = list(input())
if s.count('A') == 3 or s.count('B') == 3:
print('No')
else:
print('Yes') | def solve():
s = input()
if s in ("AAA", "BBB"):
print("No")
else:
print("Yes")
if __name__ == "__main__":
solve() | 1 | 55,068,108,968,262 | null | 201 | 201 |
class Dice:
def __init__(self,num):
self.num = num.copy()
def east(self):
temp = self.num.copy()
self.num[1-1] = temp[4-1]
self.num[4-1] = temp[6-1]
self.num[6-1] = temp[3-1]
self.num[3-1] = temp[1-1]
def north(self):
temp = self.num.copy()
self.num[1-1] = temp[2-1]
self.num[2-1] = temp[6-1]
self.num[6-1] = temp[5-1]
self.num[5-1] = temp[1-1]
def south(self):
temp = self.num.copy()
self.num[1-1] = temp[5-1]
self.num[5-1] = temp[6-1]
self.num[6-1] = temp[2-1]
self.num[2-1] = temp[1-1]
def west(self):
temp = self.num.copy()
self.num[1-1] = temp[3-1]
self.num[3-1] = temp[6-1]
self.num[6-1] = temp[4-1]
self.num[4-1] = temp[1-1]
def right(self):
temp = self.num.copy()
self.num[2-1] = temp[4-1]
self.num[4-1] = temp[5-1]
self.num[5-1] = temp[3-1]
self.num[3-1] = temp[2-1]
num = list(map(int,input().split()))
dice = Dice(num)
q = int(input())
for _ in range(q):
top,front = map(int,input().split())
while not (top == dice.num[0] or front == dice.num[1]): dice.north()
while top != dice.num[0]: dice.east()
while front != dice.num[1]: dice.right()
print(dice.num[2])
| n = int(input())
found = False
for i in range(1, n + 1):
x = int ( i * 1.08 )
if x == n :
print(i)
found = True
break
if not found:
print(":(") | 0 | null | 62,940,935,859,200 | 34 | 265 |
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()))[::-1]
# 成績 Σ{i=1~n}a[i]*f[i]
# a[i]小さいの、f[i]でかいの組み合わせるとよい(交換しても悪化しない)
def c(x):
need = 0
for i in range(n):
if a[i] * f[i] > x:
# f[i]を何回減らしてx以下にできるか
diff = a[i] * f[i] - x
need += 0 - - diff // f[i]
return need <= k
l = 0
r = 1 << 60
while r != l:
mid = (l + r) >> 1
if c(mid):
r = mid
else:
l = mid + 1
print(l)
| from math import ceil
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
F = sorted(list(map(int, input().split())))
def is_valid(A, F, K, T):
for a, f in zip(A, F):
if a*f > T:
k = ceil(a - T/f)
if k <= K:
K -= k
else:
return False
return True
def solve(N, K, A, F):
i = 0
left, right = 0, 10**12
while left < right:
mid = (left + right) // 2
if is_valid(A, F, K, mid):
right = mid
else:
left = mid + 1
if is_valid(A, F, K, mid-1) and (not is_valid(A, F, K, mid)):
return mid-1
elif is_valid(A, F, K, mid):
return mid
else:
return mid+1
print(solve(N, K, A, F))
| 1 | 164,875,791,571,168 | null | 290 | 290 |
s = input()
rs = s[::-1]
ans = 0
for i in range(len(s)//2):
ans += (s[i] != rs[i])
print(ans) | import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline # 文字列読み込む時はこっち
ra = range
enu = enumerate
def exit(*argv, **kwarg):
print(*argv, **kwarg)
sys.exit()
def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def a_int(): return int(readline())
def ints(): return list(map(int, readline().split()))
def read_col(H):
'''H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合'''
ret = []
for _ in range(H):
ret.append(list(map(int, readline().split())))
return tuple(map(list, zip(*ret)))
def read_tuple(H):
'''H is number of rows'''
ret = []
for _ in range(H):
ret.append(tuple(map(int, readline().split())))
return ret
def read_matrix(H):
'''H is number of rows'''
ret = []
for _ in range(H):
ret.append(list(map(int, readline().split())))
return ret
# return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため
class UnionFind:
def __init__(self, N):
self.N = N # ノード数
self.n_groups = N # グループ数
# 親ノードをしめす。負は自身が親ということ。
self.parent = [-1] * N # idxが各ノードに対応。
def root(self, A):
# print(A)
# ノード番号を受け取って一番上の親ノードの番号を帰す
if (self.parent[A] < 0):
return A
self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き
return self.parent[A]
def size(self, A):
# ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
return -self.parent[self.root(A)]
def unite(self, A, B):
# ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
# 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
A = self.root(A)
B = self.root(B)
# すでにくっついている場合
if (A == B):
return False
# 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
if (self.size(A) < self.size(B)):
A, B = B, A
# くっつける
self.parent[A] += self.parent[B] # sizeの更新
self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる
self.n_groups -= 1
return True
def is_in_same(self, A, B):
return self.root(A) == self.root(B)
MOD = 10**9 + 7
INF = 2**31 # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right # , insort_left, insort_right
from functools import reduce
from math import gcd
def lcm(a, b):
# 最小公倍数
g = gcd(a, b)
return a // g * b
N, M = ints()
uf = UnionFind(N)
for _ in range(M):
a, b = mina(*ints())
uf.unite(a, b)
# あとはなるべく別々になるように
# →サイズを1ずつ引いて1グループ
# いやmaxのsizeか
print(-min(uf.parent))
| 0 | null | 62,229,827,027,320 | 261 | 84 |
A, B = input().split()
A = int(A)
B = round(float(B) * 100)
ans = (A * B) // 100
print(int(ans)) | p = input()
num = int(input())
for i in range(num):
order = list(map(str,input().split()))
a = int(order[1])
b = int(order[2])
if order[0] == 'print':
print(p[a:b+1])
elif order[0] == 'replace':
rep = order[3]
p = p[:a] + rep + p[b+1:]
else:
p = p[:a] + p[a:b+1][::-1] + p[b+1:]
| 0 | null | 9,341,643,167,098 | 135 | 68 |
n = input()
c = input()
i = 0
while 1:
l = c.find('W')
r = c.rfind('R')
if l == -1 or r == -1 or l >= r:
break
c = c[:l] + 'R' + c[l + 1:r] + 'W' + c[r + 1:]
i += 1
print(i)
| N = int(input())
C = input()
W_total = C.count("W")
R_total = N - W_total
w_cur = 0
r_cur = R_total
ans = R_total
cur = 0
for i in range(N):
if C[i] == "W":
w_cur += 1
else:
r_cur -= 1
ans = min(ans, min(w_cur, r_cur) + abs(w_cur - r_cur))
print(ans) | 1 | 6,272,417,997,350 | null | 98 | 98 |
a = [[[0 for r in range (10)] for f in range(3)] for b in range(4)]
ans = ""
n = input()
for i in range(0, n):
b, f, r, v = map(int, raw_input().split(" "))
a[b-1][f-1][r-1] += v
for b in range(4):
for f in range(3):
for r in range(10):
ans += " "+str(a[b][f][r])
if (b!=3 or f!=2 or r!=9):
ans += "\n"
if (b != 3):
ans += "#"*20+"\n"
print(ans) | n = int(input())
info = []
for _ in range(n):
temp = [int(x) for x in input().split( )]
info.append(temp)
state = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for a in info:
state[a[0]-1][a[1]-1][a[2]-1] += a[3]
for b in range(4):
for f in range(3):
string = ''
for k in range(10):
string += ' ' + str(state[b][f][k])
print(string)
if b < 3:
print('#'*20)
| 1 | 1,113,698,171,332 | null | 55 | 55 |
def main():
import sys, itertools as ite
n = int(sys.stdin.readline())
A = tuple(map(int, sys.stdin.readline().split()))
#print(A)
q = int(sys.stdin.readline())
M = map(int, sys.stdin.readline().split())
bit = ite.product([0,1], repeat=n)
ans = []
for b in bit:
tmp = 0
for i in range(n):
tmp +=b[i]*A[i]
ans += [tmp]
for m in M:
if m in ans:
print('yes')
else:
print('no')
if __name__=='__main__':
main()
| N = int(input())
result = ["a"]
alph = "abcdefghijklmn"
def gen(w):
ret = []
s = len(set(w))
for ch in alph[:s+1]:
ret.append(w+ch)
return ret
i = 0
w = result[i]
while len(w) <= N:
w = result[i]
result.extend(gen(w))
i += 1
if len(w) == N:
print(w)
| 0 | null | 26,053,091,454,222 | 25 | 198 |
def merge(A, l, m, r):
L = A[l:m] + [SENTINEL]
R = A[m:r] + [SENTINEL]
i = 0
j = 0
for k in range(l, r):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
global count
count += r - l
def merge_sort(A, l, r):
if l + 1 < r:
m = (l + r) // 2
merge_sort(A, l, m)
merge_sort(A, m, r)
merge(A, l, m, r)
SENTINEL = float('inf')
n = int(input())
A = list(map(int, input().split()))
count = 0
merge_sort(A, 0, len(A))
print(" ".join(map(str, A)))
print(count) | from array import array
def readinput():
n=int(input())
a=array('L',list(map(int,input().split())))
return n,a
count=0
def merge(a,left,mid,right):
INFTY=10**9+1
global count
n1=mid-left
n2=right-mid
#L=[a[left+i] for i in range(n1)]
L=a[left:mid]
L.append(INFTY)
#R=[a[mid+i] for i in range(n2)]
R=a[mid:right]
R.append(INFTY)
i=0;j=0
for k in range(left,right):
if(L[i]<=R[j]):
a[k]=L[i]
i+=1
else:
a[k]=R[j]
j+=1
count+=1
def mergeSort(a,left,right):
if(left+1<right):
mid=(left+right)//2
mergeSort(a,left,mid)
mergeSort(a,mid,right)
merge(a,left,mid,right)
return
def main(n,a):
global count
mergeSort(a,0,n)
return a,count
if __name__=='__main__':
n,a=readinput()
a,count=main(n,a)
print(' '.join(map(str,a)))
print(count)
| 1 | 114,926,996,768 | null | 26 | 26 |
from sys import stdin
data = stdin.readlines()
n = int(data[0].split()[0])
l = []
for i in range(n):
l.append(data[i+1].split()[0])
print(len(set(l))) | n = int(input())
s = []
for _ in range(n):
s.append(input())
s.sort()
ans = n
for i in range(n-1):
if s[i] == s[i+1]:
ans -= 1
print(ans) | 1 | 30,415,693,711,632 | null | 165 | 165 |
import sys
import math
def gcd(x, y):
if y == 0:
return x
return gcd(y, x%y)
x, y = map(int, raw_input().split())
print gcd(min(x, y), max(x, y)) | N = int(input())
s = [""] * N
t = [0] * N
for i in range(N):
a, b = map(str, input().split())
s[i] = a
t[i] = int(b)
X = input()
sleep_index = s.index(X)
ans = 0
for i in range(sleep_index+1, N):
ans += t[i]
print(ans) | 0 | null | 48,479,705,543,592 | 11 | 243 |
import sys
import math
import heapq
import bisect
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
res = [1]
for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
return res
def gcd(x, y):
if x < y: x, y = y, x
div = x % y
while div != 0:
x, y = y, div
div = x % y
return y
N,M=LI()
As=LI()
As.sort()
len_As = len(As)
Acum=[As[0]]
for i in range(1, len_As):
Acum.append(Acum[i-1]+As[i])
# print(As)
# print(Acum)
ok = 0
ng = 2*max(As)+1
pat = 0
sm = 0
while ng - ok > 1:
mid_sum = (ok + ng)//2
pat = 0
sm = 0
for A in As:
A2 = mid_sum - A
# print(A2)
lft = bisect.bisect_left(As, A2)
pat += len_As - lft
sm += Acum[len_As-1] - (lft and Acum[lft-1]) + (len_As - lft)*A
# print(pat, M, ok, ng)
if pat < M: ng = mid_sum
else: ok = mid_sum
pat = 0
sm = 0
for A in As:
A2 = ok - A
# print(A2)
lft = bisect.bisect_left(As, A2)
pat += len_As - lft
sm += Acum[len_As-1] - (lft and Acum[lft-1]) + (len_As - lft)*A
# print("lo:{} hi:{} pat:{} sum:{}".format(ok, ng, pat, sm))
print(sm - (pat-M)*ok)
| import numpy as np
n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = 2**18
f = np.array([0]*d)
for i in a:
f[i]+=1
tf = np.fft.fft(f)
f = np.fft.ifft(tf*tf)
f = [int(i+0.5) for i in f]
ans=0
for i in range(len(f)-1,0,-1):
if f[i]<=m:
ans+=i*f[i]
m-=f[i]
elif f[i]>m:
ans+=i*m
break
print(ans) | 1 | 108,136,129,156,578 | null | 252 | 252 |
def solve(a, b):
if a % b == 0:
return b
else:
return solve(b, a % b)
while True:
try:
a, b = map(int, input().split())
lcm = solve(a,b)
print(lcm, a * b // lcm)
except:
break
| import fractions
lst = []
for i in range(200):
try:
lst.append(input())
except EOFError:
break
nums = [list(map(int, elem.split(' '))) for elem in lst]
# gcd
res_gcd = [fractions.gcd(num[0], num[1]) for num in nums]
# lcm
res_lcm = [nums[i][0] * nums[i][1] // res_gcd[i] for i in range(len(nums))]
for (a, b) in zip(res_gcd, res_lcm):
print('{} {}'.format(a, b)) | 1 | 586,371,778 | null | 5 | 5 |
x = int(input())
ans = 0
m = 100
while m < x:
m += m // 100
ans += 1
print(ans)
| #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys
INF = float('inf')
def solve(N: int):
h, p, b = 'h', 'p', 'b'
return [p, p, h, b, h, h, p, h, p, h][N % 10] + 'on'
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
print(solve(N))
if __name__ == '__main__':
main()
| 0 | null | 23,163,264,173,202 | 159 | 142 |
t = int(input())
if t >= 30:
print('Yes')
else:
print('No') | x=int(input())
if x>29:
print("Yes")
else:
print("No") | 1 | 5,760,815,555,168 | null | 95 | 95 |
from decimal import *
import math
A, B = input().split()
a = Decimal(A)
b = Decimal(B)
ib = Decimal(100*b)
print(math.floor((a*ib)/Decimal(100))) | H = int(input())
num = 1
ans = 0
while H > 0:
H //= 2
ans += num
num *= 2
print(ans) | 0 | null | 48,277,212,952,768 | 135 | 228 |
n = int(input())
s_l = [ input() for _ in range(n) ]
d = {}
for s in s_l:
try:
d[s] += 1
except:
d[s] = 1
max_c = max([ v for _,v in d.items() ])
ans = [ i for i, v in d.items() if v == max_c ]
for i in sorted(ans):
print(i) | from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
cnt = Counter(s)
li = sorted(cnt.items(), key=lambda x: (-x[1], x[0]))
m = li[0][1]
for i in range(len(li)):
if li[i][1] < m:
break
print(li[i][0])
| 1 | 69,752,098,725,440 | null | 218 | 218 |
class Stack():
def __init__(self):
self.el = []
def add(self, el):
self.el.append(el)
def pop(self):
return self.el.pop()
def isEmpty(self):
if len(self.el) == 0:
return True
else:
return False
a = raw_input().split()
#print a
st = Stack()
for index in range(len(a)):
#print a[index]
if a[index] in ['+', '-', '*']:
num1 = st.pop()
num2 = st.pop()
if a[index] == '+':
st.add(int(num1) + int(num2))
elif a[index] == '-':
st.add(int(num2) - int(num1))
else:
st.add(int(num1) * int(num2))
else:
st.add(a[index])
#print st.el
ans = st.pop()
print ans | n = int(input())
print((n//2)/n if n%2==0 else (n//2+1)/n) | 0 | null | 88,400,576,613,470 | 18 | 297 |
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
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())
a, v = M() # おに
b, w = M() # にげる
t = I()
ans = 'NO'
if v-w > 0:
b_hiku_a = abs(b - a)
v_hiku_w = v - w
if b_hiku_a <= t * (v-w):
ans = 'YES'
print(ans) | # https://atcoder.jp/contests/abc163/tasks/abc163_d
def main():
MOD = 10**9 + 7
n, k = [int(i) for i in input().strip().split()]
table = [0] * (n + 2)
table[1] = 1
for i in range(2, n + 1):
table[i] = table[i - 1] + i
ans = 0
for i in range(k, n + 1):
_min = table[i - 1]
_max = table[n] - table[n - i]
ans += _max - _min + 1
ans %= MOD
print((ans + 1) % MOD)
if __name__ == "__main__":
main()
| 0 | null | 24,228,810,957,568 | 131 | 170 |
def resolve():
R, C, K = map(int, input().split())
G = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K):
r, c, v = map(int, input().split())
G[r][c] = v
dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R + 1):
for j in range(C + 1):
for k in range(4):
here = dp[k][i][j]
# 次の行に移動する場合
if i + 1 <= R:
# 移動先のアイテムを取らない場合
dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
# 移動先のアイテムを取る場合
dp[1][i + 1][j] = max(dp[1][i + 1][j], here + G[i + 1][j])
# 次の列に移動する場合
if j + 1 <= C:
# 移動先のアイテムを取らない場合
dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
# 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
if k < 3:
dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + G[i][j + 1])
ans = 0
for k in range(4):
ans = max(ans, dp[k][-1][-1])
print(ans)
if __name__ == "__main__":
resolve() | n,k=map(int,input().split(' '))
l=list(map(int, input().split(' ')))
l=sorted(l)
print(sum(l[:max(n-k,0)])) | 0 | null | 42,446,084,245,938 | 94 | 227 |
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(61):
count0=0
count1=0
for j in a:
if not (j>>i & 1):
count0+=1
if j>>i & 1:
count1+=1
ans+=((count0*count1)*(2**i))%mod
print(ans%mod) | N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
D = {}
for a in A:
bit = bin(a)[2:][::-1]
for i in range(len(bit)):
if bit[i] == '1':
if i not in D:
D[i] = 1
else:
D[i] += 1
ans = 0
for k, v in D.items():
ans += (N-v)*v*2**k % mod
ans = ans % mod
print(ans) | 1 | 122,937,664,217,402 | null | 263 | 263 |
import sys
S,T = input().split()
if not ( S.islower() and T.islower() ): sys.exit()
if not ( 1 <= len(S) <= 100 and 1 <= len(S) <= 100 ): sys.exit()
print(T,S,sep='') | n=int(input())
def make(floor,kind,name): #floor=何階層目か,kind=何種類使ってるか
if floor==n+1:
print(name)
return
num=min(floor,kind+1)
for i in range(num):
use=0 #新しい文字使ってるか
if kind-1<i:
use=1
make(floor+1,kind+use,name+chr(i+97))
make(1,0,"") | 0 | null | 78,188,191,027,430 | 248 | 198 |
a,b=map(int,input().split(' '))
count=0
if a==b:
print("Yes")
else:
print("No")
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
print("Yes" if n == m else "No")
if __name__ == '__main__':
solve()
| 1 | 83,372,761,673,884 | null | 231 | 231 |
MOD = 10 ** 9 + 7
# エラトステネスの篩(コピペ用)
table_len = 1010
prime_list = [] # 必要に応じて
isprime = [True] * (1010)
isprime[0] = isprime[1] = False
for i in range(table_len):
if isprime[i]:
for j in range(2*i, table_len, i):
isprime[j] = False
prime_list.append(i) # 必要に応じて
N = int(input())
As = list(map(int, input().split()))
factor_counts = [0] * len(prime_list)
big_factors = set() # 1000より大きな素数がAの素因数として含まれるとき、その素因数は一乗のみだから
for A in As:
for i, p in enumerate(prime_list):
count = 0
while A % p == 0:
A //= p
count += 1
factor_counts[i] = max(factor_counts[i], count)
if A == 1:
break
else:
big_factors.add(A)
A_lcm = 1
for p, count in zip(prime_list, factor_counts):
A_lcm *= pow(p, count, MOD)
A_lcm %= MOD
for p in big_factors:
A_lcm *= p
A_lcm %= MOD
ans = 0
for A in As:
ans += A_lcm * pow(A, MOD - 2, MOD) % MOD
ans %= MOD
print(ans) | 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
from collections import defaultdict
#nの素因数分解,[[a1,b1],[a2,b2]...] aがb個,
def factorization(n):
if n==1:
return [[1,0]]
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
lcm_dd = defaultdict(int)
N=I()
A=LI()
for i in range(N):
a=A[i]
arr=factorization(a)
for v in arr:
p,cnt=v
lcm_dd[p]=max(lcm_dd[p],cnt)
lcm=1
for k,v in lcm_dd.items():
temp=pow(k,v,mod)
lcm=(lcm*temp)%mod
ans=0
for i in range(N):
temp=(lcm*pow(A[i],mod-2,mod))%mod
ans=(ans+temp)%mod
print(ans%mod)
main()
| 1 | 87,176,400,252,612 | null | 235 | 235 |
from math import ceil
debt = 100000
n = int(input())
for _ in range(n):
tmp = ceil(debt*1.05)
debt = ceil((tmp/1000))*1000
print(debt) | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
week = int(input())
base = 100000
x = base
for i in range(week):
x = round(x * 1.05)
if x % 1000 > 0:
x = (x // 1000) *1000 +1000
print(x)
if __name__ == '__main__':
main() | 1 | 976,890,600 | null | 6 | 6 |
def main():
import sys
readline = sys.stdin.buffer.readline
n = int(readline())
d = list(map(int, readline().split()))
e = sum(d)
ans = 0
for i in d:
e -= i
ans += i*e
print(ans)
if __name__ == '__main__':
main() | n=int(input())
a=[int(i) for i in input().split()]
sum=0
for i in range(0,len(a)-1):
for j in range(i+1,len(a)):
sum=sum+(a[i]*a[j])
print(sum) | 1 | 168,793,123,318,720 | null | 292 | 292 |
S = input()
L = len(S)
L //= 2
answer = 0
for i in range(L):
if S[i] != S[-i-1]:
answer += 1
print(answer) | S = input()
N=len(S)
h=0
for i in range(0,N//2):
if S[i]!=S[N-1-i]:
h+=1
print(h) | 1 | 120,353,153,142,862 | null | 261 | 261 |
N = int(input())
ans = pow(10, N, mod=1000000007) - pow(9, N, mod=1000000007) - pow(9, N, mod=1000000007) + pow(8, N, mod=1000000007)
ans %= 1000000007
print(ans)
| import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
def modpow(n, p, m):
if p == 0:
return 1
if p % 2 == 0:
t = modpow(n, p // 2, m)
return t * t % m
return n * modpow(n, p - 1, m) % m
n = ni()
A = modpow(9, n, mod)
B = A
C = modpow(8, n, mod)
D = modpow(10, n, mod)
ans = (D - A - B + C) % mod
print(ans) | 1 | 3,155,904,814,772 | null | 78 | 78 |
x1,y1,x2,y2=map(float,input().split())
print('{0:.6f}'.format(((x1-x2)**2 + (y1-y2)**2 )**(.5))) | N=int(input())
if N % 2 or N < 10:
print(0)
exit()
ans = 0
i = 1
while 2*5**i<=N:
ans += N // (2*5**i)
i += 1
print(ans) | 0 | null | 58,266,222,825,660 | 29 | 258 |
import bisect
N = int(input())
L = [int(n) for n in input().split()]
L = sorted(L)
total = 0
for i in range(N - 2):
a = L[i]
for j in range(i + 1, N - 1):
b = L[j]
right_endpoint = bisect.bisect_left(L, a+b, j)
total += right_endpoint - j - 1
print(total) | A, B, C, D = list(map(int, input().split()))
import math
if math.ceil(A / D) >= math.ceil(C / B):
print('Yes')
else:
print('No') | 0 | null | 100,515,926,346,848 | 294 | 164 |
k=int(input())
a,b=map(int,input().split())
flag=0
for i in range(1001):
if a<=k*i<=b:
print("OK")
flag+=1
break
if flag==0:
print("NG") | n = int(input())
ans = 0
if n % 2 == 1:
ans = 0
else:
ans += n//10
n = n//10
while n > 1:
ans += n//5
n = n//5
# print(n)
print(ans)
| 0 | null | 71,192,065,145,614 | 158 | 258 |
n=int(input())
i=0
x=100000
for i in range(n):
x=int(x*1.05)
if x%1000==0:
x=x
else:
x=x+1000-x%1000
i+=1
print(x)
| from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
n,k = list(map(int, input().split()))
# C,Pを求める前処理
m = 4*10**5
mod = 10**9 + 7
fact = [0]*(m+5)
fact_inv = [0]*(m+5)
inv = [0]*(m+5)
fact[0] = fact[1] = 1
fact_inv[0] = fact_inv[1] = 1
inv[1] = 1
for i in range(2,m+5):
fact[i] = fact[i-1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
fact_inv[i] = fact_inv[i-1] * inv[i] % mod
# nCkをmod(素数)で割った余りを求める.ただしn<10**7
# 前処理はm=n+5まで
def cmb(n,k,mod):
return fact[n] * (fact_inv[k] * fact_inv[n-k] % mod) % mod
if k >= n-1:
print(cmb(2*n-1, n-1, mod)%mod)
else:
ans = 0
for i in range(0,k+1):
ans += cmb(n,i,mod)*cmb(n-1,n-i-1,mod)%mod
ans %= mod
print(ans)
| 0 | null | 33,520,604,344,910 | 6 | 215 |
n, m = map(int, input().split())
a = []
for _ in range(n):
a.append(list(map(int, input().split())))
b = []
for _ in range(m):
b.append(int(input()))
c = []
for i in range(n):
c.append(sum([a[i][j] * b[j] for j in range(m)]))
for i in c:
print(i)
| #-*-coding:utf-8-*-
import sys
def main():
n = int(input())
ans=0
b=0
for a in range(1,n):
#A*B+C=n → A <= n-c//b
#cは1<=c<=nなのでbで可変
b=(n-1)//a
ans+=b
print(ans)
if __name__ == "__main__":
main() | 0 | null | 1,910,727,690,340 | 56 | 73 |
import sys
from collections import Counter
from collections import deque
import math
import fractions
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
n,r=mp()
if n>=10:
print(r)
else:
print(100*(10-n)+r) | import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
n, r = inm()
print(r if n >= 10 else r + 100 * (10 - n)) | 1 | 63,553,925,596,992 | null | 211 | 211 |
# A * B
A,B = map(int,input().split())
answer = A * B
print(answer) | dif = -1E9
n = int(input())
mn = int(input())
for i in range(n - 1):
r = int(input())
if r - mn > dif:
dif = r - mn
if r < mn:
mn = r
print(dif) | 0 | null | 7,898,631,437,088 | 133 | 13 |
# coding: utf-8
while True:
try:
data = map(int, raw_input().split())
if data[0] > data[1]:
a = data[0]
b = data[1]
else:
a = data[1]
b = data[0]
r = 1
while r > 0:
q = a / b
r = a - b * q
a = b
b = r
gcd = a
lcm = data[0] * data[1] / gcd
print("{:} {:}".format(gcd, lcm))
except EOFError:
break | N, M = map(int, raw_input().split())
matrix = [map(int, raw_input().split()) for n in range(N)]
array = [input() for m in range(M)]
for n in range(N):
c = 0
for m in range(M):
c += matrix[n][m] * array[m]
print c | 0 | null | 581,780,362,590 | 5 | 56 |
#!/usr/bin/env python3
import statistics
import sys
def main():
while True:
n = int(sys.stdin.readline())
if n == 0:
sys.exit(0)
print(statistics.pstdev([int(num) for num
in sys.stdin.readline().split()]))
if __name__ == '__main__':
main() | n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
総投票数 = sum(a)
x = 総投票数 / (4 * m)
for i in range(m):
if a[i] < x:
flag = 0
break
else:
flag = 1
print(["No", "Yes"][flag]) | 0 | null | 19,523,338,291,492 | 31 | 179 |
import random
class Dice(object):
def __init__(self, *args):
self.faces = [None]
self.faces.extend(args)
self.top = self.faces[1]
self.up = self.faces[5]
self.down = self.faces[2]
self.left = self.faces[4]
self.right = self.faces[3]
def roll(self, direction):
if direction == "N":
self.top, self.up, self.down = self.down, self.top, self.faces[7 - self.faces.index(self.top)]
elif direction == "S":
self.top, self.up, self.down = self.up, self.faces[7 - self.faces.index(self.top)], self.top
elif direction == "W":
self.top, self.left, self.right = self.right, self.top, self.faces[7 - self.faces.index(self.top)]
elif direction == "E":
self.top, self.left, self.right = self.left, self.faces[7 - self.faces.index(self.top)], self.top
else:
raise ValueError("{} is not valid direction.".format(direction))
f = [int(i) for i in input().split()]
dice = Dice(*f)
n = int(input())
for i in range(n):
top, down = [int(i) for i in input().split()]
while dice.top != top:
dice.roll(random.choice("NSWE"))
if dice.down == down:
print(dice.right)
elif dice.right == down:
print(dice.up)
elif dice.up == down:
print(dice.left)
elif dice.left == down:
print(dice.down)
else:
raise ValueError()
| class Dice:
def __init__(self):
# 初期値がない場合
# 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定
self.t = 1
self.s = 2
self.e = 3
self.w = 4
self.n = 5
self.b = 6
self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}
def __init__(self, t, s, e, w, n, b):
# 初期値が指定される場合
self.t = t
self.s = s
self.e = e
self.w = w
self.n = n
self.b = b
self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}
def rot(self, way):
if way == 0:
self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
elif way == 1:
self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
elif way == 2:
self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
elif way == 3:
self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
def main():
import random
t,s,e,w,n,b = map(int, input().split())
dice2 = Dice(t,s,e,w,n,b)
q = int(input())
for _ in range(q):
top, front = map(int, input().split())
while True:
if dice2.t == top and dice2.s == front:
break
else:
seed = random.randint(0, 3)
dice2.rot(seed)
print(dice2.e)
if __name__ == '__main__':
main()
| 1 | 255,844,146,840 | null | 34 | 34 |
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
lis = ['0']*N
time = [0]*N
for i in range(N):
lis[i],time[i] = input().split()
sing = input()
index = -1
for i in range(N):
if lis[i] == sing:
index = i
break
ans = 0
for i in range(index+1,N):
ans += int(time[i])
print(ans) | n = int(input())
title = []
length = []
for i in range(n):
a,b = map(str, input().split())
title.append(a)
length.append(int(b))
x = input()
ind = title.index(x)
print(sum(length[ind+1:])) | 1 | 96,540,591,242,242 | null | 243 | 243 |
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
if i == 0:
max = A[i]
else:
if max > A[i]:
ans += max - A[i]
else:
max = A[i]
print(ans) | cnt = 0
def merge(L,R):
global cnt
A = []
i = j = 0
n = len(L)+len(R)
L.append(float("inf"))
R.append(float("inf"))
for _ in range(n):
cnt += 1
if L[i] <= R[j]:
A.append(L[i])
i += 1
else:
A.append(R[j])
j += 1
return A
def mergeSort(A):
if len(A)==1: return A
m = len(A)//2
return merge(mergeSort(A[:m]),mergeSort(A[m:]))
if __name__=='__main__':
n=int(input())
A=list(map(int,input().split()))
print(*mergeSort(A))
print(cnt) | 0 | null | 2,358,027,030,720 | 88 | 26 |
import itertools
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
a = [i for i in range(1,N+1)]
cnt = 0
ans_a, ans_b = 0, 0
for target in itertools.permutations(a):
cnt += 1
if list(target) == P:
ans_a = cnt
if list(target) == Q:
ans_b = cnt
print(abs(ans_a-ans_b)) | # coding: utf-8
# Here your code !
def func():
try:
word=input().rstrip().lower()
words=[]
while(True):
line=input().rstrip()
if(line == "END_OF_TEXT"):
break
else:
words.extend(line.lower().split(" "))
except:
return inputError()
print(words.count(word))
def inputError():
print("input Error")
return -1
func() | 0 | null | 51,281,332,796,540 | 246 | 65 |
r=range
s=str
for i in r(1,10):
for u in r(1,10):
print(s(i)+'x'+s(u)+'='+s(i*u)) | i=[1,2,3,4,5,6,7,8,9]
j=[1,2,3,4,5,6,7,8,9]
for i1 in i:
for j1 in j:
answer=i1*j1
print(str(i1)+"x"+str(j1)+"="+str(answer))
| 1 | 281,632 | null | 1 | 1 |
n = int(input())
s = input()
#print(s)
tot = s.count('R') * s.count('G') * s.count('B')
#print(tot)
for i in range(n):
for d in range(1,n):
j = i+d
k = j+d
if k > n-1:
break
if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
tot -= 1
print(tot) | def inN():
return int(input())
def inL():
return list(map(int,input().split()))
def inNL(n):
return [list(map(int,input().split())) for i in range(n)]
n = inN()
s = input()
r = s.count('R')
b = s.count('B')
g = s.count('G')
cnt = 0
for i in range(n):
for j in range(i+1,n):
k = 2*j - i
if k < n:
if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
cnt += 1
print(r*g*b - cnt) | 1 | 36,281,568,902,922 | null | 175 | 175 |
n,m=map(int,input().split())
ac=[0]*n
wa=[0]*n
acc,wac=0,0
for i in range(m):
p,s=input().split()
p=int(p)
if ac[p-1]==1:
continue
else:
if s=="AC":
ac[p-1]=1
else:
wa[p-1]+=1
for i in range(n):
if ac[i]==1:
acc+=1
wac+=wa[i]
print(acc,wac) | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
solved = [False] * (n + 1)
wa = [0] * (n + 1)
for i in range(m):
p_str, s = input().split()
p = int(p_str)
if s == "AC":
solved[p] = True
else:
if not solved[p]:
wa[p] += 1
ac = 0
pe = 0
for i in range(1, n+1):
if solved[i]:
ac += 1
pe += wa[i]
print(ac, pe) | 1 | 93,355,282,769,968 | null | 240 | 240 |
def insert_sort():
n = int(input())
A = [int(x) for x in input().split()]
print(*A)
for i in range(1,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
print(*A)
if __name__ == "__main__":
insert_sort() | n = int(input())
nums = list(map(int, input().split()))
def insertion_sort(lis, num):
print(' '.join(map(str, lis)))
for i in range(1, num):
v = lis[i]
j = i - 1 # j は iの前の数
while j >= 0 and lis[j] > v: # jが0以上で配列のj番目の要素が現在の要素より大きい場合
lis[j + 1] = lis[j] # 配列j+1番目の要素に配列j番目の要素を格納
# print(' '.join(lis))
j -= 1 # jを-1
lis[j + 1] = v # 配列j+1番目の要素にvを格納
print(' '.join(map(str, lis)))
return lis
insertion_sort(nums, n)
| 1 | 5,161,119,080 | null | 10 | 10 |
import math
a, b, ca = map(float, input().split())
ca = math.radians(ca)
s = a * b * math.sin(ca) / 2
c = (a ** 2 + b ** 2 - 2 * a * b * math.cos(ca)) ** 0.5
h = b * math.sin(ca)
print("{:.5f}".format(s))
print("{:.5f}".format(a + b + c))
print("{:.5f}".format(h))
| #!/usr/bin/env python3
def main():
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
if N >= sum(A):
print(N - sum(A))
else:
print(-1)
if __name__ == '__main__':
main()
| 0 | null | 16,143,158,276,348 | 30 | 168 |
from math import gcd
n = int(input())
a = list(map(int, input().split()))
# 解説AC(a*loga)
ans = 0
cnt = [0] * (max(a) + 1)
for ai in a:
ans = gcd(ans, ai)
cnt[ai] += 1
if ans != 1:
print('not coprime')
elif any(sum(cnt[i::i]) > 1 for i in range(2, max(a) + 1)):
print('setwise coprime')
else:
print('pairwise coprime')
| import math
def div(s):
i=1
while(i<=math.sqrt(s)):
if(s%i==0):
if(s//i==i):
if(i!=1):
if(i in d):
return False
else:
d[i]=1
else:
if(i!=1):
if(i in d):
return False
else:
d[i]=1
if(s//i!=1):
if(s//i in d):
return False
else:
d[s//i]=1
i+=1
#print(d,s)
return True
n=int(input())
l=list(map(int,input().split()))
d=dict()
setwise=False
pairWise=True
pairWise&=div(l[0])
pairWise&=div(l[1])
val=math.gcd(l[0],l[1])
for i in range(2,n):
pairWise&=div(l[i])
val=math.gcd(val,l[i])
if(pairWise):
print('pairwise coprime')
elif(val==1):
print('setwise coprime')
else:
print('not coprime')
| 1 | 4,167,827,166,578 | null | 85 | 85 |
import math
def main():
H = {int(input()): 1}
ans = 0
while True:
new_H = {}
for h, freq in H.items():
ans += freq
if h > 1:
new_H[h // 2] = 2 * freq
if len(new_H) == 0:
break
else:
H = new_H
print(ans)
if __name__ == '__main__':
main()
| for x in range(9):
x = x + 1
for y in range(9):
y = y + 1
print(x.__str__() + 'x' + y.__str__() + '=' + (x * y).__str__() ) | 0 | null | 39,843,997,356,800 | 228 | 1 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
from collections import Counter
def factorial(n):
prime_count = Counter()
for i in range(2, int(n**0.5) + 2):
while n % i == 0:
n /= i
prime_count[i] += 1
if n > 1:
prime_count[int(n)] += 1
return prime_count
def num_divisors(prime_count):
num = 1
for prime, count in prime_count.items():
num *= (count + 1)
return num
def divisors(n):
ret = set()
for i in range(1, int(n ** 0.5) + 1):
d, m = divmod(n, i)
if m == 0:
ret.add(i)
ret.add(d)
return sorted(ret)
def solve(N: int):
f = factorial(N-1)
ans = num_divisors(f)-1
divs = divisors(N)
for k in divs:
if k == 1:
continue
n = N
while n % k == 0:
n = n//k
if n == 1:
break
if n % k == 1:
ans += 1
print(ans)
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
solve(N)
if __name__ == '__main__':
main()
| n = int(input())
nums = list(map(int, input().split()))
ans = 0
for idx in range(1, n):
if nums[idx] - nums[idx-1] < 0:
ans += abs(nums[idx] - nums[idx-1])
nums[idx] = nums[idx-1]
print(ans) | 0 | null | 22,985,542,813,860 | 183 | 88 |
t = int(input())
print('Yes' if t >= 30 else 'No') | #!/usr/bin/env python
# -*- coding: utf-8 -*-
temperature = int(input())
if temperature >= 30:
print('Yes')
else:
print('No')
| 1 | 5,738,106,378,642 | null | 95 | 95 |
H,W = map(int,input().split())
if H==1 or W==1:
print(1)
elif H%2==0 and W%2==0 or H%2==0 and W%2==1 or H%2==1 and W%2==0:
print((H*W)//2)
else:
print(((H*W)+1)//2) | def solve(i, m):
if i >= n:
combs.add(m)
return
solve(i+1, m)
solve(i+1, m+A[i])
def main():
global n
global A
global combs
n = int(input())
A = list(map(int, input().split()))
_ = int(input())
Q = list(map(int, input().split()))
# 先に全部の組み合わせを計算しておくことで時間短縮
combs = set()
solve(0, 0)
for q in Q:
if q in combs:
print("yes")
else:
print("no")
if __name__ == '__main__':
main()
| 0 | null | 25,269,927,246,212 | 196 | 25 |
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d = [abs(x[i] - y[i]) for i in range(n)]
for i in range(1,4):
print('{0:f}'.format(sum(j ** i for j in d) ** (1 / i)))
print('{0:f}'.format(max(d))) | # B
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n-2):
for j in range(i+1, n-1):
for k in range(j+1, n):
if l[i] != l[j] != l[k] and l[i]+l[j] > l[k]:
ans += 1
print(ans)
| 0 | null | 2,629,632,322,282 | 32 | 91 |
import sys
from io import StringIO
import unittest
import os
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 実装を行う関数
def resolve(test_def_name=""):
h, w, k = map(int, input().split())
s_s = [list(input()) for i in range(h)]
# パターン数分の情報を作成(横に切る = 最大2^10個)
# 全パターンの・・横に切る回数、と切る場所
side = []
for i in range(1 << h - 1):
cut_cnt = 0
point_s = []
# パターンの桁数分ループ
for j in range(h - 1):
# フラグが立つ(bitが1)の場合の処理を以下に記載。
if i & 1 << j:
cut_cnt += 1
point_s.append(j + 1)
point_s.append(h)
# 得た情報をリストに追加
side.append([point_s, cut_cnt])
## 横切り必須にもかかわらず、横木入りしていないパターンを排除できていない・・と思われる。
x_s_s = list(zip(*s_s))
ans = 999999
for side_cut_point_s, cut_cnt in side:
# 横切りを実施した後の塊を取得
cnt_s = [0 for i in range(cut_cnt + 1)]
for x_s in x_s_s:
start = 0
for cnt, side_cut_point in enumerate(side_cut_point_s):
cnt_s[cnt] += x_s[start: side_cut_point].count("1")
start = side_cut_point
# 切る必要がある場合は切る
if max(cnt_s) > k:
cut_cnt += 1
start = 0
for cnt, side_cut_point in enumerate(side_cut_point_s):
cnt_s[cnt] = x_s[start: side_cut_point].count("1")
start = side_cut_point
if max(cnt_s) > k:
cut_cnt += 99999
ans = min(ans, cut_cnt)
print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3 5 4
11100
10001
00111"""
output = """2"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """3 5 8
11100
10001
00111"""
output = """0"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """4 10 4
1110010010
1000101110
0011101001
1101000111"""
output = """3"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def test_1original_1(self):
test_input = """10 10 1
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000"""
output = """9"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| from itertools import product
INF = float("inf")
H, W, K = map(int, input().split())
S = [[int(i) for i in input()] for _ in range(H)]
T = [t for t in zip(*S)]
if sum(map(sum, T)) <= K:
print(0)
quit()
ans = INF
for P in product([0, 1], repeat=H - 1):
cnt = sum(P)
if cnt >= ans:
continue
II = [[0]]
for i, p in enumerate(P, 1):
if p:
II.append([])
II[-1].append(i)
A = [0] * len(II)
for t in T:
for i, I in enumerate(II):
A[i] += sum(t[x] for x in I)
if any(a > K for a in A):
cnt += 1
if cnt >= ans:
break
A = [sum(t[x] for x in I) for I in II]
if any(a > K for a in A):
cnt = INF
break
ans = min(ans, cnt)
print(ans) | 1 | 48,581,472,157,178 | null | 193 | 193 |
a,b,c,k=map(int,input().split())
if(k<=a):
print(k)
else:
print(a-(k-a-b)) | def main():
N = int(input())
points = [None] * N
for i in range(N):
x, y = map(int, input().split())
points[i] = (x, y)
ans = 0
points.sort(reverse=True)
topright = points[0][0] + points[0][1]
bottomright = points[0][0] - points[0][1]
for i in range(N):
tr = points[i][0] + points[i][1]
br = points[i][0] - points[i][1]
ans = max([ans, abs(topright - tr), abs(bottomright - br)])
topright = max(topright, tr)
bottomright = max(bottomright, br)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 12,653,104,435,902 | 148 | 80 |
from collections import deque
H, W = map(int, input().split())
L = [str(input()) for _ in range(H)]
ans = 0
for h in range(H):
for w in range(W):
if L[h][w] == '#':
continue
else:
flag = [[-1] * W for _ in range(H)]
depth = [[0] * W for _ in range(H)]
flag[h][w] = 0
q = deque([(h, w)])
while q:
i, j = q.popleft()
d = depth[i][j]
if i != H - 1:
if L[i+1][j] == '.' and flag[i+1][j] < 0:
flag[i+1][j] = 0
depth[i+1][j] = d + 1
q.append((i+1, j))
if i != 0:
if L[i-1][j] == '.' and flag[i-1][j] < 0:
flag[i-1][j] = 0
depth[i-1][j] = d + 1
q.append((i-1, j))
if j != W - 1:
if L[i][j+1] == '.' and flag[i][j+1] < 0:
flag[i][j+1] = 0
depth[i][j+1] = d + 1
q.append((i, j+1))
if j != 0:
if L[i][j-1] == '.' and flag[i][j-1] < 0:
flag[i][j-1] = 0
depth[i][j-1] = d + 1
q.append((i, j-1))
ans = max(ans, d)
print(ans)
| from collections import deque
h, w = map(int, input().split())
meiro = [list(input()) for i in range(h)]
# meiro[y][x]
def bfs(a, b): # a縦b横
mx_dist = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
dist = [[-1] * w for i in range(h)]
dist[a][b] = 0
que = deque([])
que.append((a, b))
while que:
y, x = que.popleft()
D = dist[y][x]
for i in range(4):
X = x + dx[i]
Y = y + dy[i]
if 0 <= Y and Y <= h - 1 and X <= w - 1 and 0 <= X:
if meiro[Y][X] == ".":
if dist[Y][X] == -1:
dist[Y][X] = D + 1
que.append((Y, X))
mx_dist = max(mx_dist, D + 1)
return mx_dist
saidai = 0
for i in range(h):
for j in range(w):
if meiro[i][j] == ".":
saidai = max(saidai, bfs(i, j))
print(saidai)
| 1 | 94,554,946,472,790 | null | 241 | 241 |
import sys; input = sys.stdin.readline
n = int(input())
lis = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j+1, n):
if lis[i] == lis[j] or lis[j] == lis[k] or lis[i] == lis[k]: continue
s = sorted([lis[i], lis[j], lis[k]])
if s[2] < s[1] + s[0]: ans += 1
print(ans) | cnt = int(input())
chain = 0
first = 0
second = 0
for i in range(cnt):
nList = list(map(int, input().split()))
first = nList.pop()
second = nList.pop()
if first == second:
chain = chain + 1
if chain >= 3:
break
else:
chain = 0
if chain >= 3:
print("Yes")
else:
print("No")
| 0 | null | 3,818,486,096,612 | 91 | 72 |
N,K=map(int, raw_input().split())
mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1,N+1):
fact_tmp *= i
fact_tmp %= mod
fact.append(fact_tmp)
inv_fact.append(pow(fact_tmp, mod-2, mod))
def ncr(n,r):
if n < 0 or r < 0 or n < r: return 0
else: return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod
can_zero_num=min(N-1,K)
ans=0
for zero_num in range(can_zero_num+1):
ans+=ncr(N,zero_num)*ncr(N-1,N-zero_num-1)
print ans%mod | n,k=map(int,input().split())
mod=10**9+7
U = 4*10**5+1
MOD = 10**9+7
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
for i in range(1,U+1):
fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U],MOD-2,MOD)
for i in range(U,0,-1):
fact_inv[i-1] = (fact_inv[i]*i)%MOD
def comb(n,k):
if k < 0 or k > n:
return 0
x = fact[n]
x *= fact_inv[k]
x %= MOD
x *= fact_inv[n-k]
x %= MOD
return x
if n-1<=k:
print(comb(2*n-1,n-1))
else:
ans=0
for i in range(1+k):
ans+=comb(n,i)*comb(n-1,n-i-1)
ans%=mod
print(ans)
| 1 | 67,180,838,905,178 | null | 215 | 215 |
import sys
x,k,d=map(int,input().split())
x=abs(x)
a=x//d
if a>=k:
ans=x-k*d
elif (k-a)%2==0:
ans=x-d*a
else:
ans=x-d*a-d
print(abs(ans)) | x,k,d = map(int, input().split())
if x == 0:
if k % 2 == 1:
x = d
elif x > 0:
if x >= k*d:
x -= k*d
else:
n = x//d
x -= n*d
k -= n
if k%2 ==1:
x -= d
else:
if x <= -(k*d):
x += k*d
else:
n = abs(x)//d
x += n*d
k -= n
if k%2 ==1:
x += d
print(abs(x)) | 1 | 5,182,269,176,380 | null | 92 | 92 |
# -*- coding: utf-8 -*-
import sys
import os
a, b = list(map(int, input().split()))
d = a // b
r = a % b
f = a / b
print('{} {} {:.10f}'.format(d, r, f)) | import math
from decimal import *
import random
mod = int(1e9)+7
s = str(input())
n =len(s)
if(n%2==0):
s1, s2 = s[:n//2], s[n//2:][::-1]
ans =0
for i in range(len(s1)):
if(s1[i]!= s2[i]):
ans+=1
print(ans)
else:
s1, s2 = s[:(n-1)//2], s[(n-1)//2:][::-1]
ans = 0
for i in range(len(s1)):
if(s1[i]!= s2[i]):
ans+=1
print(ans)
| 0 | null | 60,696,211,991,932 | 45 | 261 |
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
class Math():
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n ** 0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
@staticmethod
def fact(N):
res = {}
tmp = N
for i in range(2, int(N ** 0.5 + 1) + 1):
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if cnt > 0:
res[i] = cnt
if tmp != 1:
res[tmp] = 1
if res == {}:
res[N] = 1
return res
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
MOD = int(1e09) + 7
INF = int(1e15)
def modinv(a):
b = MOD
u = 1
v = 0
while b:
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
u %= MOD
if u < 0:
u += MOD
return u
def factorial(N):
if N == 0 or N == 1:
return 1
res = N
for i in range(N - 1, 1, -1):
res *= i
res %= MOD
return res
def solve():
X, Y = Scanner.map_int()
if (X + Y) % 3 != 0:
print(0)
return
B = (2 * Y - X) // 3
A = (2 * X - Y) // 3
if A < 0 or B < 0:
print(0)
return
n = factorial(A + B)
m = factorial(A)
l = factorial(B)
ans = n * modinv(m * l % MOD) % MOD
print(ans)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
| a,b,c=map(int,raw_input().split())
if a<b<c: print "Yes"
else: print "No" | 0 | null | 74,827,965,924,400 | 281 | 39 |
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
s = str(readline().rstrip().decode('utf-8'))
res = []
start = n
while True:
b = False
for j in range(max(0, start - m), start):
if s[j] == "0":
res.append(start - j)
start = j
b = True
break
if not b:
print(-1)
exit()
else:
if j == 0:
res.reverse()
print(*res)
exit()
if __name__ == '__main__':
solve()
| ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n,m = ma()
s = input()
dp = [-1]*(n+1) #dp[i]:: i番目にたどり着く最小コスト
dp[0]=0
r=0
while r<=n-1:
l=0
tmp=0
while l+1<=m and r+l+1<=n:
l+=1
if s[r+l]=="0":
tmp=l
dp[r+l]=dp[r]+1
r+=tmp
#if r==n:break
if tmp==0:
print(-1)
exit()
d = dp[-1]
rt = []
dp = dp[::-1]
r=0
while r<=n-1:
l=0
tmp=0
while l+1<=m and r+l+1<=n:
l+=1
if dp[r+l]==d-1:
tmp=l
rt.append(tmp)
d-=1
r+=tmp
print(*reversed(rt))
| 1 | 138,630,205,941,728 | null | 274 | 274 |
def insert(S, string):
S.add(string)
def find(S, string):
if string in S:
print 'yes'
else:
print 'no'
n = input()
S = set()
for i in range(n):
tmp1, tmp2 = map(str, raw_input().split())
if tmp1 == 'insert':
insert(S, tmp2)
elif tmp1 == 'find':
find(S, tmp2)
else:
print 'error!' | n = int(input())
d = {}
ans = []
for i in range(n):
order = list(map(str, input().split()))
if order[0] == 'insert':
d[order[1]] = i
else:
if d.__contains__(order[1]):
ans.append('yes')
else:
ans.append('no')
print(*ans, sep='\n')
| 1 | 77,319,134,050 | null | 23 | 23 |
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
L = [0 for _ in range(S+1)]
L[0] = 1
F = {0}
for i in range(N):
X = [[i, L[i]] for i in F]
for j in F:
L[j] *= 2
L[j] %= mod
for j in X:
if A[i] + j[0] <= S:
L[A[i]+j[0]] += j[1]
L[A[i]+j[0]] %= mod
F.add(A[i]+j[0])
print(L[S])
| def main():
H, N = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
if H > s:
print('No')
else:
print('Yes')
main() | 0 | null | 48,095,318,532,612 | 138 | 226 |
n = int(input())
a = []
x = []
y = []
for i in range(n):
ai = int(input())
a.append(ai)
xi = []
yi = []
for j in range(ai):
xij, yij = map(int, input().split(' '))
xi.append(xij)
yi.append(yij)
x.append(xi)
y.append(yi)
ans = 0
for case in range(2**n):
truth_t = 0 #正直者の真の数
truth = 0 #正直者の確認した数
for i in range(n): #人ごとに矛盾が生じないか確認
if (case>>i)&1: #正直者であれば証言に矛盾がないか確認
truth_t+=1
proof=0
for j in range(a[i]):
if ((case>>(x[i][j]-1))&1)==y[i][j]:
proof+=1
if proof==a[i]:
truth += 1
if truth==truth_t:
if ans<truth:
ans = truth
print(ans)
| ls = list(map(int, input().split(' ')))
if sum(ls) >= 22:
print('bust')
else:
print('win') | 0 | null | 119,799,629,587,104 | 262 | 260 |
cnt=0
radi=0
x=int(input())
while True:
cnt+=1
radi+=x
radi%=360
if radi==0:
print(cnt)
break | x=int(input())
i=0
while True:
360*i%x!=0
i+=1
if 360*i%x==0:
break
k=360*i/x
print(int(k))
| 1 | 13,099,690,647,680 | null | 125 | 125 |
N=int(input())
ls={}
max_ch=0
for i in range(N):
ch=input()
if not ch in ls:
ls[ch]=1
else:
ls[ch]+=1
if max_ch<ls[ch]:
max_ch=ls[ch]
S=[]
for j in ls:
if max_ch==ls[j]:
S.append(j)
S=sorted(S)
for i in S:
print(i) | def main():
n = int(input())
ans = 0
for a in range(1, n):
for b in range(1, n):
c = n - a * b
if c <= 0:
break
ans += 1
return ans
if __name__ == '__main__':
print(main())
| 0 | null | 36,191,007,592,672 | 218 | 73 |
l = int(input())
x = l/3
ans = x**3
print(str(ans)) | L = float(input())
print((L/3.)**3.) | 1 | 46,760,324,953,782 | null | 191 | 191 |
from collections import deque
n,d,a = map(int,input().split())
c,cc = 0,0
deq = deque()
dl = [tuple(map(int,input().split())) for i in range(n)]
dl.sort()
for i in dl:
x,h = i
while deq:
if deq[0][0] < x-2*d:
cc -= deq.popleft()[1]
else:
break
h -= a*cc
if h > 0:
c += (h-1)//a + 1
cc += (h-1)//a + 1
deq.append((x,(h-1)//a + 1))
print(c) | def resolve():
S = input()
print(S[:3])
resolve()
| 0 | null | 48,623,859,261,318 | 230 | 130 |
mylist1 = [2,4,5,7,9]
mylist2 = [0,1,6,8]
N = int(input())
X = N % 10
if X in mylist1:
print('hon')
elif X in mylist2:
print('pon')
else:
print('bon') | def main():
n = input()
hon = ['2', '4', '5', '7', '9']
pon = ['0', '1', '6', '8']
bon = ['3']
if n[len(n)-1] in hon:
print('hon')
elif n[len(n)-1] in pon:
print('pon')
else:
print('bon')
if __name__ == "__main__":
main()
| 1 | 19,298,639,743,218 | null | 142 | 142 |
variables = [int(i) for i in input().split()]
for i in range(5) :
if variables[i]==0 :
print(i+1) | import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
N, M = lr()
if N%2 == 1:
for i in range(0, M):
print(f'{2+i} {1+2*M-i}')
else:
k = N//4
for i in range(M):
if i < k:
print(f'{i+1} {N-i}')
else:
print(f'{i+2} {N-i}')
resolve() | 0 | null | 20,882,664,973,370 | 126 | 162 |
numbers = []
n = raw_input()
numbers = n.split(" ")
for i in range(2):
numbers[i] = int(numbers[i])
if numbers[0] > numbers[1]:
print "a > b"
elif numbers[0] < numbers[1]:
print "a < b"
elif numbers[0] == numbers[1]:
print "a == b" | n=int(input())
a=[]
for i in range(n):
s,t=input().split()
a.append([s,int(t)])
x=input()
sum1=0
for j in range(n):
if a[j][0]!=x:
sum1+=a[j][1]
else:
sum1+=a[j][1]
break
sum2=0
for i in range(n):
sum2+=a[i][1]
print(sum2-sum1)
| 0 | null | 48,920,960,657,052 | 38 | 243 |
import sys
def input(): return sys.stdin.readline().strip()
mod = 998244353
def main():
"""
各トークンを(最下点、最終的な高さ)に分けるのはできた。
そしてそれらを最下点位置が浅い順に並べるのも悪くはなかった、増加パートに関しては。
減少パートは減少度合が小さい順に付け加えたとしても高さが負に潜り込むケースがある。
(例)高さ3から下るとして、(-1, -1), (-2, 0), (-3, -2)が各トークンとすると
この順にくっつけると(-3, -2)を加えるときにアウトだが、
(-2, 0), (-3, -2), (-1, -1)の順だったらOK
なので下る場合には増加パートとは違う方法でくっつけないといけない。
結論としては、これは左右反転させれば増加していることになるので、右からくっつけるようにすればいい。
"""
N = int(input())
S_up = []
S_down = []
for _ in range(N):
s = input()
max_depth = 0
height = 0
for c in s:
if c == '(':
height += 1
else:
height -= 1
max_depth = min(max_depth, height)
if height > 0: S_up.append((max_depth, height - max_depth))
else: S_down.append((-(height - max_depth), -max_depth))
S_up.sort(key=lambda x: (x[0], x[1]))
S_down.sort(key=lambda x: (x[0], x[1]))
height_left = 0
while S_up:
d, h = S_up.pop()
#print("({}, {})".format(d, h))
if height_left + d < 0:
print("No")
return
height_left += d+h
height_right = 0
while S_down:
d, h = S_down.pop()
#print("({}, {})".format(d, h))
if height_right + d < 0:
print("No")
return
height_right += d+h
if height_left != height_right: print("No")
else: print("Yes")
if __name__ == "__main__":
main()
| s = input()
flg = False
for i in range(1,6):
if s == 'hi' *i:
flg = True
break
print('Yes' if flg else 'No') | 0 | null | 38,717,537,337,780 | 152 | 199 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(M):
x, y, c = map(int, input().split())
p = a[x-1] + b[y-1] - c
if p < ans:
ans = p
print(ans) | h,n = map(str,input().split())
#li = [int(x) for x in input().split()]
print(n+h) | 0 | null | 78,567,751,336,254 | 200 | 248 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.