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
|
---|---|---|---|---|---|---|
from itertools import product
H, W, K = map(int, input().split())
choco = [list(input()) for _ in range(H)]
def cnt(array):
count = [0] * H
split_cnt = 0
for w in range(W):
for h in range(H):
if choco[h][w] == "1":
count[array[h]] += 1
if any(i > K for i in count):
split_cnt += 1
count = [0] * H
for h in range(H):
if choco[h][w] == "1":
count[array[h]] += 1
if any(i > K for i in count):
return 10 ** 20
return split_cnt
def get_array(array):
l = len(array)
ret = [0] * l
for i in range(1, l):
ret[i] = ret[i-1] + array[i]
return ret
ans = 10 ** 20
for p in product(range(2), repeat=H-1):
p = get_array([0]+list(p))
ans = min(ans, cnt(p)+max(p))
print(ans)
| n = int(input())
al = list(map(int, input().split()))
flg = True
for a in al:
if a%2 == 0:
if a%3 == 0 or a%5 == 0:
continue
else:
flg = False
break
if flg:
print('APPROVED')
else:
print('DENIED') | 0 | null | 58,831,087,438,020 | 193 | 217 |
import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n, m, k = map(int, readline().rstrip().split())
A = list(map(int, readline().rstrip().split()))
B = list(map(int, readline().rstrip().split()))
a, b = [0], [0]
for i in range(n):
a.append(a[i] + A[i])
for i in range(m):
b.append(b[i] + B[i])
ans = 0
j = m
for i in range(n + 1):
if a[i] > k:
break
while b[j] > k - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == '__main__':
main()
| from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
# 素因数分解、リストで返す
#############################################################
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
a.sort()
return a
#############################################################
primes = defaultdict(int)
for i in range(N):
p = prime_factorize(A[i])
p_set = set(p)
for pi in p_set:
primes[pi] += 1
# 全て1の時、primesが空になってmaxが取れない
if len(primes) == 0:
print("pairwise coprime")
exit()
max_cnt = max(primes.values())
# min_cnt = min(primes.values())
if max_cnt == 1:
print("pairwise coprime")
elif max_cnt != N:
print("setwise coprime")
else:
print("not coprime")
| 0 | null | 7,403,345,733,540 | 117 | 85 |
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
K,N,M=len(B),len(A),len(B[0])
return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
N=len(v)
size=len(M)
return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def main():
mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
N = int(input())
#N, K = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
s = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
l=[(s[i][0]+s[i][1],s[i][0]-s[i][1]) for i in range(N)]
l.sort()
cur=l[0][0]
ans=1
for rob in l[1:]:
if cur>rob[1]:
continue
ans+=1
cur=rob[0]
print(ans)
if __name__ == "__main__":
main() | from operator import itemgetter
n = int(input())
s = []
for i in range(n):
l = list(map(int, input().split()))
rang = [l[0] - l[1], l[0] + l[1]]
s.append(rang)
s_sort = sorted(s, key=itemgetter(1))
ans = 0
last = -float("inf")
for i in range(n):
if last <= s_sort[i][0]:
ans += 1
last = s_sort[i][1]
print(ans)
| 1 | 89,682,134,951,908 | null | 237 | 237 |
from fractions import gcd
n, m = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
a_h_list = [a // 2 for a in a_list]
count = set()
for a_h in a_h_list:
temp = bin(a_h)
count.add(len(temp) - temp.rfind("1"))
if len(count) == 1:
temp = 1
for a_h in a_h_list:
temp *= a_h // gcd(a_h, temp)
ans = (m // temp + 1) // 2
else:
ans = 0
print(ans) | import math
N=int(input())
M =int(math.sqrt(N))
for i in range(M):
if N%(M-i)==0:
K=N//(M-i)
L=M-i
break
print(L+K-2)
| 0 | null | 131,511,394,738,500 | 247 | 288 |
input_data = [int(i) for i in input().split()]
if input_data[0] > input_data[1]:
print("a > b")
elif input_data[0] < input_data[1]:
print("a < b")
else :
print("a == b") | l=int(input())
ll=l/3
print(ll**3) | 0 | null | 23,822,736,315,452 | 38 | 191 |
N=int(input())
Taro=0
Hanako=0
for i in range(N):
T,H=map(str,input().split())
if T<H:
Hanako+=3
elif H<T:
Taro+=3
else:
Hanako+=1
Taro+=1
print(Taro,Hanako)
| A, B = 0, 0
num = int(input())
for i in range(num):
a, b = input().split()
if a < b:
B += 3
elif a > b:
A += 3
else:
A += 1
B += 1
print(A, B)
| 1 | 1,986,231,795,482 | null | 67 | 67 |
n = int(input())
S = ['']*n
T = []
for i in range(n):
S[i] = input()
S.sort()
if n == 1:
print(S[0])
exit()
cnt = 1
mxcnt = 1
for i in range(n-1):
if S[i] == S[i+1]:
cnt += 1
else:
cnt = 1
mxcnt = max(mxcnt,cnt)
cnt = 1
for i in range(n-1):
if S[i] == S[i+1]:
cnt += 1
else:
cnt = 1
if cnt == mxcnt:
T.append(S[i])
if mxcnt == 1:
T.append(S[-1])
for t in T:
print(t) | N=int(input())
S=list(input() for _ in range(N))
from collections import Counter
cnt=Counter(S)
max_cnt=cnt.most_common()[0][1]
ans=[]
for k, v in cnt.items():
if v!=max_cnt:
continue
ans.append(k)
print(*sorted(ans), sep="\n") | 1 | 70,034,296,407,448 | null | 218 | 218 |
n = int(input())
S = list(map(int, input().split()))
def merge(A, left, mid, right):
cnt = 0
n1 = mid - left
n2 = right - mid
L = [0]*(n1+1)
R = [0]*(n2+1)
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
L[n1] = float("inf")
R[n2] = float("inf")
i = 0
j = 0
for k in range(left, right):
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return cnt
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right)//2
cnt_left = merge_sort(A, left, mid)
cnt_right = merge_sort(A, mid, right)
cnt_merge = merge(A, left, mid, right)
cnt = cnt_left + cnt_right + cnt_merge
else:
cnt = 0
return cnt
cnt = merge_sort(S, 0, n)
print(' '.join( map(str, S) ))
print(cnt)
| num = int(input())
s = list(map(int, input().split()))
cnt = 0
def merge(A, left, mid, right):
global cnt
L = A[left:mid] + [10**9 + 1]
R = A[mid:right] + [10**9 + 1]
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
cnt += right - left
def merge_sort(A, left, right):
if (left + 1) < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
merge_sort(s, 0, num)
print(*s)
print(cnt)
| 1 | 109,460,870,232 | null | 26 | 26 |
n = int(input())
input_line = input().split()
member = [int(input_line[i]) for i in range(n)]
stands = 0
for i in range(1,n):
stand = member[i-1] - member[i]
if stand > 0:
stands += stand
member[i] += stand
print(stands) | number = int(input())
tall = list(map(int, input().split()))
addition = 0
for each in range(1, number):
difference = tall[each - 1] - tall[each]
if difference >= 0:
addition += difference
tall[each] += difference
print(addition) | 1 | 4,522,021,901,250 | null | 88 | 88 |
import sys
input = sys.stdin.readline
from collections import *
def bfs(s):
q = deque([s])
dist = [-1]*N
dist[s] = 0
leaf = set()
while q:
v = q.popleft()
flag = True
for nv in G[v]:
if dist[nv]==-1:
dist[nv] = dist[v]+1
q.append(nv)
flag = False
if flag:
leaf.add(v)
return dist, leaf
N, u, v = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
A, B = map(int, input().split())
G[A-1].append(B-1)
G[B-1].append(A-1)
d1, _ = bfs(u-1)
d2, leaf = bfs(v-1)
ans = 0
for i in range(N):
if i not in leaf and d1[i]<=d2[i]:
ans = max(ans, d2[i])
print(ans) | N, U, V = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N + 1)]
for A, B in AB:
graph[A].append(B)
graph[B].append(A)
INF = 10 ** 15
dist_U = [INF] * (N + 1)
dist_V = [INF] * (N + 1)
def dfs(start, dist):
stack = [start]
dist[start] = 0
while stack:
s = stack.pop()
for g in graph[s]:
if dist[g] > dist[s] + 1:
dist[g] = dist[s] + 1
stack.append(g)
dfs(U, dist_U)
dfs(V, dist_V)
#print("dist_U", dist_U)
#print("dist_V", dist_V)
answer = []
for i in range(1, N + 1):
if dist_U[i] < dist_V[i]:
answer.append(dist_V[i] - 1)
print(max(answer)) | 1 | 117,165,804,793,728 | null | 259 | 259 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(K,N):
if A[i] > A[i-K]:
print("Yes")
else:
print("No") |
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
#%%
for i in range(K, N):
if A[i - K] < A[i]:
print("Yes")
else:
print("No") | 1 | 7,097,449,023,868 | null | 102 | 102 |
import sys
X, K, D = map(int, input().split())
X = abs(X)
if X // D >= K:
print(X - K*D)
sys.exit()
K = K - (X // D)
A = X - X//D*D
if K % 2 == 0:
print(A)
else:
print(abs(A - D)) | import sys
for l in sys.stdin:
x,y=map(int, l.split())
m=x*y
while x%y:x,y=y,x%y
print "%d %d"%(y,m/y) | 0 | null | 2,640,470,658,384 | 92 | 5 |
import sys
import math
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
x = Ii()
ans = 0
k = 100
while x > k:
tax = k//100
k += tax
ans += 1
print(ans) | a=int(input())
cnt=0
t=100
while t<a:
t=(t*101)//100
cnt+=1
print(cnt) | 1 | 27,153,522,748,128 | null | 159 | 159 |
A,B = input().split()
A = int(A)
x = ""
for i in range(len(B)):
if B[i]!=".":
x += B[i]
B = int(x)
C = A*B
C = C//100
print(C) | import math
import numpy as np
A,B = np.array(input().split(),dtype = int)
def gcd(x,y):
if y == 0:
return x
else:
return gcd(y,x%y)
print(int(A*B/(gcd(A,B)))) | 0 | null | 65,118,099,560,516 | 135 | 256 |
def main():
K = int(input())
A,B = map(int,input().split())
for i in range(A,B+1):
if i%K == 0:
return('OK')
return('NG')
print(main())
| n, m = map(int, input().split())
a = list(map(int, input().split()))
x = 0
for i in range(m):
x += a[i]
if n - x >= 0:
print(n - x)
else:
print(-1) | 0 | null | 29,064,179,439,322 | 158 | 168 |
n, m, l = list(map(int, input().split()))
#a = [0]*n
#b = [0]*m
#c = [[0 for col in range(l)] for row in range(n)]
#for i in range(n):
# a[i] = list(map(int,input().split()))
#for i in range(m):
# b[i] = list(map(int,input().split()))
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(m)]
#for i in range(n):
# for j in range(l):
# for k in range(m):
# c[i][j] += a[i][k]*b[k][j]
for i in range(n):
print(*[sum([a[i][k]*b[k][j] for k in range(m)]) for j in range(l)]) | from itertools import accumulate
from bisect import *
n, m, *a = map(int, open(0).read().split())
a = [-x for x in a]
a.sort()
acc = list(accumulate(a)) + [0]
l = 0
r = 2 * 10 ** 5 + 1
while r - l > 1:
mid = (l + r) // 2
border = n - 1
cnt = 0
for x in a:
while x + a[border] > -mid:
border -= 1
if border < 0:
break
if border < 0:
break
cnt += border + 1
if cnt >= m:
break
if cnt >= m:
l = mid
else:
r = mid
ans = tot = 0
for x in a:
b = bisect(a, -l - x)
tot += b
ans += acc[b - 1] + x * b
ans += l * (tot - m)
print(-ans)
| 0 | null | 54,790,046,765,590 | 60 | 252 |
X = int(input())
x500 = X//500
amari = X - x500 * 500
x5 = amari // 5
print(x500*1000+x5*5) | W = input().lower()
T = ""
while True:
inp = input().strip()
if inp == 'END_OF_TEXT':
break
T += inp.strip().lower()+' '
print(T.split().count(W)) | 0 | null | 22,298,150,176,522 | 185 | 65 |
h,w,m=map(int,input().split())
HW=[list(map(int,input().split())) for _ in range(m)]
H,W=[0 for _ in range(h)],[0 for _ in range(w)]
for i,j in HW:
i,j=i-1,j-1
H[i] +=1
W[j] +=1
max_h,max_w=max(H),max(W)
ans=max_h+max_w
cnt=H.count(max_h)*W.count(max_w)
for i,j in HW:
if H[i-1]==max_h and W[j-1]==max_w:
cnt -=1
print(ans if cnt!=0 else ans-1) | from collections import Counter
ans = 0
H, W, M = map(int, input().split())
HW = set()
Hlist, Wlist = [], []
for _ in range(M):
h, w = map(int, input().split())
Hlist.append(h)
Wlist.append(w)
HW.add((h,w))
cntH = Counter(Hlist)
cntW = Counter(Wlist)
maxhk, maxhv = cntH.most_common()[0]
ans = max(ans, maxhv)
for i in range(1,1+W):
tmp = cntW[i]
if (maxhk, i) in HW:
tmp -= 1
ans = max(ans, tmp+maxhv)
maxwk, maxwv = cntW.most_common()[0]
ans = max(ans, maxwv)
for i in range(1,1+H):
tmp = cntH[i]
if (i, maxwk) in HW:
tmp -= 1
ans = max(ans, tmp+maxwv)
print(ans)
| 1 | 4,704,998,108,522 | null | 89 | 89 |
def __main():
x = 1;
while x <= 9 :
y = 1;
while y <= 9 :
z = x * y;
print(str(x) + "x" + str(y) + "=" + str(z) )
y = y + 1
x = x + 1
__main()
| NK = list(map(int, input().split()))
P = list(map(int, input().split()))
sum = 0
P.sort()
for i in range(NK[1]):
sum+=P[i]
print(sum) | 0 | null | 5,829,086,910,208 | 1 | 120 |
# A - Takahashikun, The Strider
x = int(input())
i = 1
while True:
if 360 * i % x == 0:
print(360 * i // x)
break
else:
i += 1 | a, b, c = map(int,input().split())
if 4*a*b + 2*a*c + 2*b*c < a**2 + b**2 + c**2+ 2*a*b and c-a-b>0:
print("Yes")
else:
print("No") | 0 | null | 32,407,451,820,690 | 125 | 197 |
from collections import Counter
N = int(input())
S = input()
cnt = Counter(S)
ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請1を満たす(i, j, k)の組の数を入れておき,ここから,要請2を満たさないものを除いていく。
for i in range(N-2):
for j in range(i+1, N-1):
k = j + (j - i)
#kは j - i = k - j を満たす。ただし,(i, j, k)が要請1を満たしているとは限らない。
if k < N:
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
ans -= 1
print(ans) | n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
for j in range(i, n-1):
if s[i] != s[j]:
if 2*j-i <= n-1 and s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
ans -= 1
print(ans) | 1 | 36,246,126,965,060 | null | 175 | 175 |
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n = int(lines.pop(0))
s = lines.pop(0)
count = 0
prev_c = None
for c in s:
if c != prev_c:
count += 1
prev_c = c
print(count)
| def main():
sectionalview = input()
stack = []
a_surface = 0
surfaces = []
for cindex in range(len(sectionalview)):
if sectionalview[cindex] == "\\":
stack.append(cindex)
elif sectionalview[cindex] == "/" and 0 < len(stack):
if 0 < len(stack):
left_index = stack.pop()
a = cindex - left_index
a_surface += a
while 0 < len(surfaces):
if left_index < surfaces[-1][0]:
a += surfaces.pop()[1]
else:
break
surfaces.append((cindex, a))
t = [i[1] for i in surfaces]
print(sum(t))
print(" ".join(map(str, [len(t)] + t)))
if __name__ == "__main__":
import os
import sys
if len(sys.argv) > 1:
if sys.argv[1] == "-d":
fd = os.open("input.txt", os.O_RDONLY)
os.dup2(fd, sys.stdin.fileno())
main()
else:
main() | 0 | null | 84,766,727,449,020 | 293 | 21 |
n, xs = int(input()), map(int,raw_input().split())
print min(xs), max(xs), sum(xs) | n,k=map(int,input().split())
k_list=[]
for i in range(k):
l,r=map(int,input().split())
k_list.append([l,r])
dp=[0]*(n+1)
dp[1]=1
dpsum=[0]*(n+1)
dpsum[1]=1
for i in range(1,n):
dpsum[i]=dp[i]+dpsum[i-1]
for j in range(k):
l,r=k_list[j]
li=i+l
ri=i+r+1
if li<=n:
dp[li]+=dpsum[i]
dp[li]=dp[li]%998244353
if ri<=n:
dp[ri]-=dpsum[i]
dp[ri]=dp[ri]%998244353
print(dp[n])
| 0 | null | 1,724,802,941,026 | 48 | 74 |
S,W=map(int,input().split())
if S<=W:
print("unsafe")
exit(0)
print("safe") | combined = input().split(" ")
s = int(combined[0])
w = int(combined[1])
if w >= s:
print("unsafe")
else:
print("safe")
| 1 | 29,246,916,702,592 | null | 163 | 163 |
while True:
m, f, r = map(int, raw_input().split(" "))
if m==f==r==-1:
break
if m==-1 or f==-1:
print("F")
elif m+f >= 80:
print("A")
elif 65 <= m+f < 80:
print("B")
elif 50 <= m+f < 65:
print("C")
elif 30 <= m+f < 50:
if r >= 50:
print("C")
else:
print("D")
elif m+f < 30:
print("F") | def insertionSortForShell(lst, n, g):
cnt = 0
for i in range(g, n):
v = lst[i]
j = i - g
while j >= 0 and lst[j] > v:
lst[j+g] = lst[j]
j = j - g
cnt += 1
lst[j+g] = v
return cnt
def cleate_split_lst(n):
lst = []
while 1:
n = int(n/2)
if n <= 1:
lst.append(1)
break
else:
lst.append(n)
return lst
def shellSort(lst, n):
cnt = 0
G = cleate_split_lst(n)
for i in range(0, len(G)):
cnt += insertionSortForShell(lst, n, G[i])
print(len(G))
print(" ".join([str(g) for g in G]))
print(cnt)
for n in lst:
print(n)
if __name__ == "__main__":
n = int(input())
lst = []
for i in range(0, n):
lst.append(int(input()))
shellSort(lst, n) | 0 | null | 633,058,752,930 | 57 | 17 |
x = input().split()
a,b,c=[int(x) for x in x]
ans=0
for x in range(a,b+1):
if c%x==0:ans+=1
print(ans)
| a,b,c = map(int, input().split())
p = 0
for j in range(a,b + 1):
if c%j==0:
p = p+1
print(p)
| 1 | 562,436,578,780 | null | 44 | 44 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n, k, *p = map(int, read().split())
p.sort()
r = sum(p[:k])
print(r)
if __name__ == '__main__':
main()
| n, x, m = map(int, input().split())
ans = 0
prev_set = set()
prev_list = list()
ans_hist = list()
r = x
for i in range(n):
if i == 0:
pass
else:
r = (r * r) % m
if r == 0:
break
if r in prev_set:
index = prev_list.index(r)
period = i - index
count = (n - index) // period
rest = (n - index) % period
ans = sum(prev_list[:index])
ans += sum(prev_list[index:i]) * count
# ans += (ans - ans_hist[index - 1]) * (count - 1)
ans += sum(prev_list[index:index+rest])
# ans += (ans_hist[index + rest - 1] - ans_hist[index - 1])
break
else:
ans += r
prev_set.add(r)
prev_list.append(r)
ans_hist.append(ans)
print(ans)
| 0 | null | 7,194,090,160,554 | 120 | 75 |
n=int(input())
a=list(map(int,input().split()))
l=[]
flag=0
for aa in a:
if aa%2==0:
flag=1
l.append(aa)
if flag==1:
for ll in l:
if ll % 3!=0 and ll % 5!=0:
flag=2
if flag==0:
print('APPROVED')
elif flag==1:
print('APPROVED')
elif flag==2:
print('DENIED')
| #155_B
n = int(input())
a = list(map(int, input().split()))
judge = True
for i in range(n):
if a[i]%2 == 0:
if a[i]%3 != 0 and a[i]%5 != 0:
judge = False
break
if judge:
print('APPROVED')
else:
print('DENIED') | 1 | 69,276,012,327,730 | null | 217 | 217 |
a ,b = map(int,input().split())
li = list(map(int,input().split()))
sum = 0
for i in li:
sum += i
if a > sum:
print(a - sum)
elif a == sum:
print(0)
else:
print(-1) | n=int(input())
arr=list(map(int,input().strip().split()))
ans=[0]*n
for i in range(n):
ans[arr[i]-1]=i+1
print(*ans,sep=" ") | 0 | null | 106,255,495,992,558 | 168 | 299 |
import sys
input = sys.stdin.readline
A, B = map(int, input().split())
print(A - B * 2) if A > B * 2 else print(0)
| def gcd(x,y):
if x%y==0: return y
else : return gcd(y,x%y)
if __name__=='__main__':
x,y=list(map(int,input().split()))
print(gcd(x,y)) | 0 | null | 83,617,891,696,690 | 291 | 11 |
S = input()
print("Yes" if S.count("A") and S.count("A") < 3 or S.count("B") and S.count("B") < 3 else "No") | #k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
s = input()
if s[0] != s[1] or s[1] != s[2] or s[0] != s[2]:
print ("Yes")
else:
print("No")
| 1 | 54,514,698,502,940 | null | 201 | 201 |
import math
N = int(input())
digit = math.ceil(math.log((25 * N / 26 + 1), 26))
alphabet = list("abcdefghijklmnopqrstuvwxyz")
name = []
for i in range(digit):
name.append((N % 26 - 1) % 26)
N = (N - (N % 26 - 1) % 26) // 26
name.reverse()
print("".join([alphabet[s] for s in name]))
| alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
n = int(input())
str = ''
count = 0
while True:
n -= 26 ** count
if n < 26 ** (count + 1):
while count != 0:
mod = 26 ** count
num_1 = n // mod
n %= mod
str = str + alph[num_1]
count -= 1
break
count += 1
str = str + alph[n]
print(str) | 1 | 11,823,155,810,840 | null | 121 | 121 |
n=int(input())
s=100000
for i in range(n):
s*=1.05
m = s % 1000
if m!=0:
s=s-m+1000
print(int(s))
| import math
res = 100
N = int(input())
for i in range(N):
res = math.ceil(res * 1.05)
print("%d000" % res)
| 1 | 1,261,114,960 | null | 6 | 6 |
data = list(map(int,input().split()))
data.sort()
print("{0} {1} {2}".format(data[0],data[1],data[2]))
| num_lis = list(map(int,input().split()))
amount = sum(num_lis)
if amount >= 22:
print("bust")
else:
print("win") | 0 | null | 59,508,961,449,842 | 40 | 260 |
import sys
X = int(input())
a = 100
d = 0
while(a<X):
a = a * 101 // 100
d += 1
print(d)
| import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
A = rl()
if sum(A) >= 22:
print('bust')
else:
print('win')
| 0 | null | 72,674,125,362,552 | 159 | 260 |
S = str(input())
ans = 'Yes'
from collections import Counter
SC = Counter(list(S))
h,i = 0,0
for a,b in SC.items():
if a == 'h':
h = b
elif a == 'i':
i = b
else:
ans = 'No'
break
if h == i:
for i in range(0,len(S)-1,2):
if S[i]+S[i+1] != 'hi':
ans = 'No'
break
else:
ans = 'No'
print(ans) | n=int(input())
pointx=0
pointy=0
for i in range(n):
x,y=[j for j in input().split()]
p=1
if len(x)<len(y):
for j in range(len(x)):
if ord(list(x)[j])>ord(list(y)[j]):
pointx=pointx+3
p=0
break
elif ord(list(x)[j])<ord(list(y)[j]):
pointy=pointy+3
p=0
break
if p:
pointy=pointy+3
elif len(x)==len(y):
for j in range(len(x)):
if ord(list(x)[j])>ord(list(y)[j]):
pointx=pointx+3
p=0
break
elif ord(list(x)[j])<ord(list(y)[j]):
pointy=pointy+3
p=0
break
if p:
pointx=pointx+1
pointy=pointy+1
else:
for j in range(len(y)):
if ord(list(x)[j])>ord(list(y)[j]):
pointx=pointx+3
p=0
break
elif ord(list(x)[j])<ord(list(y)[j]):
pointy=pointy+3
p=0
break
if p:
pointx=pointx+3
print("{0} {1}".format(pointx,pointy)) | 0 | null | 27,789,515,747,872 | 199 | 67 |
k = int(input())
a, b = map(int, input().split())
ans = 0
for i in range(a, b+1, 1):
if i%k == 0:
ans = 1
break
if ans == 1:
print("OK")
else:
print("NG") | s = str(input())
num = [int(s[-1])]
for i in range(1, len(s)):
tmp = num[-1] + pow(10, i, 2019) * int(s[-i - 1])
num.append(tmp % 2019)
mod = [1] + [0] * 2018
ans = 0
for i in num:
ans += mod[i]
mod[i] += 1
print(ans)
| 0 | null | 28,748,592,008,980 | 158 | 166 |
N = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(N-1):
if i == j:
break
else:
ans = ans + d[i]*d[j]
print(ans)
| n = int(input())
d = list(map(int, input().split()))
s = 0
for i in range(n):
for j in range(n):
if i != j:
s += d[i]*d[j]
s //= 2
print(s)
| 1 | 167,911,573,673,050 | null | 292 | 292 |
X,N = map(int,input().split())
p = list(map(int, input().split()))
i = 0
if X not in p:
print(X)
else:
while True:
i += 1
if X - i not in p:
print(X-i)
break
if X+i not in p:
print(X+i)
break
| n = int(input())
print(int(n / 2) - (1 - (n % 2))) | 0 | null | 83,414,614,617,542 | 128 | 283 |
n=int(input())
if n%2 == 0:
n=n-1
print(int(n/2)) | from collections import Counter
N = int(input())
A = list(map(int, input().split()))
s = [i+a for i, a in enumerate(A)]
t = [j-a for j, a in enumerate(A)]
d = Counter(s)
ans = 0
for i in t:
ans += d[i]
print(ans) | 0 | null | 89,430,809,742,820 | 283 | 157 |
import bisect # 配列二分法
from collections import defaultdict
N = int(input())
S = [*input()]
Q = int(input())
d = defaultdict(list)
# 各アルファベットの出現場所を記録
for i, c in enumerate(S):
d[c] += [i]
# この時点でどのアルファベットについてもソート済み
# print(d)
for _ in range(Q):
q, y, z = input().split()
if q == '1':
i = int(y) - 1 # 文字の変更位置
if S[i] == z: continue # 同じ文字の場合は処理終了
# 削除 O(N)
b = bisect.bisect(d[S[i]], i) # 2分法で i の出現位置を(log N)で探す
d[S[i]].pop(b - 1) # 削除
# 追加 O(N) かかる?
S[i] = z
bisect.insort(d[z], i)
else:
left = int(y) - 1
right = int(z) - 1
count = 0
for v in d.values():
count += 1 if bisect.bisect(v, right) - bisect.bisect_left(v, left) > 0 else 0
print(count) | import bisect
n = int(input())
s = list(input())
q = int(input())
alphabet = [chr(ord('a') + i) for i in range(26)]
d = {alphabet[i]: [] for i in range(26)}
for i, a in enumerate(s):
d[a].append(i)
ans = []
for i in range(q):
query = input().split()
if query[0] == '1':
idx, c = int(query[1]) - 1, query[2]
if s[idx] == c:
continue
d[s[idx]].remove(idx)
bisect.insort_left(d[c], idx)
s[idx] = c
else:
l, r = int(query[1]) - 1, int(query[2]) - 1
res = 0
for c in alphabet:
if bisect.bisect_right(d[c], r) > bisect.bisect_left(d[c], l):
res += 1
ans.append(res)
for i in ans:
print(i) | 1 | 62,401,676,166,106 | null | 210 | 210 |
def main():
a = int(input())
b = int(input())
print(6 - a - b)
if __name__ == "__main__":
main()
| def roundone(a, b):
abc = "123"
return abc.replace(a, "").replace(b, "")
def main():
a = str(input())
b = str(input())
print(roundone(a, b))
if __name__ == '__main__':
main() | 1 | 110,896,160,579,890 | null | 254 | 254 |
import sys
def main():
N, K = map(int, sys.stdin.readline().rstrip().split())
L = [0] * 10
R = [0] * 10
for i in range(K):
l, r = map(int, sys.stdin.readline().rstrip().split())
L[i], R[i] = l, r
dp = [0] * (N + 1)
up = [0] * (N + 1)
up[0] = 1
up[1] = -1
for i in range(1, N + 1):
dp[i] = dp[i - 1] + up[i - 1]
for j in range(K):
if i + (L[j] - 1) < N + 1:
up[i + (L[j] - 1)] += dp[i]
if i + R[j] < N + 1:
up[i + R[j]] -= dp[i]
dp[i] %= 998244353
print(dp[N])
main()
| # -*- coding: utf-8 -*-
N, K = map(int, input().split())
kukan = list()
for i in range(K):
l, r = map(int, input().split())
kukan.append((l, r))
dp = [0] * (N+1)
dp[1] = 1
dp_sum = [0] * (N+1)
dp_sum[1] = 1
for i in range(0, N+1):
for j in range(K):
from_l = i - kukan[j][1]
from_r = i - kukan[j][0]
if from_r < 0:
continue
else:
from_l = max(1, from_l)
dp[i] += dp_sum[from_r] - dp_sum[from_l - 1]
dp[i] %= 998244353
dp_sum[i] = dp[i] + dp_sum[i-1]
print(dp[N] % 998244353) | 1 | 2,691,883,730,524 | null | 74 | 74 |
N, M = map(int, input().split())
# [ACしたかどうか, 初ACは何回目の提出か]
prob = [[0] * 2 for _ in range(N + 1)]
# print(prob)
ps_list = [[0, 0]]
for i in range(1, M + 1):
p, s = input().split()
p = int(p)
ps_list.append([p, s])
if s == "AC" and prob[p] == [0, 0]:
prob[p] = [1, i]
# print(prob)
# この段階でACは数えられる
ac = 0
for item in prob:
if item[0] == 1:
ac += 1
penalty = 0
for i in range(1, M + 1):
p = ps_list[i][0]
s = ps_list[i][1]
if s == "WA" and i < prob[p][1]:
penalty += 1
print(ac, penalty)
| N = int(input())
A = []
for i in range(N+1):
if i % 15 == 0:
pass
elif i % 3 == 0:
pass
elif i % 5 == 0:
pass
else:
A.append(i)
print(sum(A)) | 0 | null | 64,149,420,213,632 | 240 | 173 |
n = int(input())
(*a, ) = map(int, input().split())
q = int(input())
(*m, ) = map(int, input().split())
s = set()
for j in range(2 << n):
c = 0
for k in range(n):
if j >> k & 1:
c += a[k]
s.add(c)
for i in m:
print("yneos"[i not in s::2])
| n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(input().split())
for i in range(m):
B[i] = int(B[i])
def solve(x,y):
if x==n:
S[y] = 1
else:
solve(x+1,y)
if y+A[x] < 2001:
solve(x+1,y+A[x])
S = [0 for i in range(2001)]
solve(0,0)
for i in range(m):
if S[B[i]] == 1:
print("yes")
else:
print("no")
| 1 | 102,626,295,560 | null | 25 | 25 |
# coding:UTF-8
import sys
from math import factorial
MOD = 998244353
INF = 10000000000
def main():
n, k = list(map(int, input().split())) # スペース区切り連続数字
lrList = [list(map(int, input().split())) for _ in range(k)] # スペース区切り連続数字(行列)
s = []
for l, r in lrList:
for i in range(l, r+1):
s.append(i)
s.sort()
sum = [0] * (n + 1)
Interm = [0] * (2 * n + 1)
sum[1] = 1
for i in range(1, n):
for j in range(k):
l, r = lrList[j][0], lrList[j][1]
Interm[i+l] += sum[i]
Interm[i+r+1] -= sum[i]
sum[i+1] = (sum[i] + Interm[i+1]) % MOD
# result = Interm[n]
result = (sum[n] - sum[n-1]) % MOD
# ------ 出力 ------#
print("{}".format(result))
if __name__ == '__main__':
main()
| N = int(input())
S = input()
res = 0
f = S[0]
for i in range(N):
if S[i] != f:
f = S[i]
res += 1
print(res+1) | 0 | null | 86,348,189,691,870 | 74 | 293 |
import statistics
while True:
n = int(input())
if n == 0:
break
else:
data = [float(s) for s in input().split()]
print(statistics.pstdev(data)) | #coding: UTF-8
import statistics as st
while True:
N = int(input())
if N == 0:
break
buf = list(map(float, input().split()))
sd = st.pstdev(buf)
print("%.8f"%sd)
| 1 | 189,204,324,712 | null | 31 | 31 |
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
k+=(s*int(S[a-i-1]))
k%=mod
s*=10
s%=mod
if k in c:
c[k]+=1
else:
c[k]=1
for i in c:
ans+=c[i]*(c[i]-1)//2
print(ans) | import sys
input = sys.stdin.readline
P = 2019
def main():
S = input().rstrip()
N = len(S)
count = [0] * P
count[0] += 1
T = 0
for i in range(N):
T = (T + int(S[(N - 1) - i]) * pow(10, i, mod=P)) % P
count[T] += 1
ans = 0
for k in count:
ans = (ans + k * (k - 1) // 2)
print(ans)
if __name__ == "__main__":
main()
| 1 | 30,832,452,856,752 | null | 166 | 166 |
N,*a = map(int,open(0).read().split())
max_num = a[0]
count = 0
for i in a:
if max_num>=i:
count+=1
max_num = min(i,max_num)
print(count) | from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n = INT()
ans = 0
if n % 2 == 0:
c5 = 0
c2 = 0
for i in range(30,0,-1):
c5 += i*(n//(2*5**i) - n//(2*5**(i+1)))
for i in range(60,0,-1):
c2 += i*(n//(2**i) - n//(2**(i+1)))
ans = min(c5, c2)
print(ans) | 0 | null | 101,116,896,844,348 | 233 | 258 |
N,S=map(int,input().split())
*a,=map(int,input().split())
mod=998244353
dp=[[0]*(S+1) for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
for j in range(S+1):
dp[i+1][j]=2*dp[i][j]
if j>=a[i]:
dp[i+1][j]+=dp[i][j-a[i]]
dp[i+1][j]%=mod
print(dp[N][S]) | '''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
# mod = 998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
INF = 1<<32-1
# INF = 10**18
def main():
n = int(ipt())
x,y = map(int,ipt().split())
mas = [x+y,x-y,-x-y,y-x]
ma = 0
for _ in range(n-1):
x,y = map(int,ipt().split())
cpr = [-y-x,y-x,x+y,x-y]
for i in range(4):
if mas[i]+cpr[i] > ma:
ma = mas[i]+cpr[i]
for i in range(4):
if mas[i] < cpr[i-2]:
mas[i] = cpr[i-2]
print(ma)
return None
if __name__ == '__main__':
main()
| 0 | null | 10,486,110,687,350 | 138 | 80 |
def main():
from math import gcd
def lcm(a, b):
return a // gcd(a, b) * b
x = int(input())
print(lcm(x, 360) // x)
if __name__ == '__main__':
main()
| N = int(input())
S = input()
if N % 2 !=0:
print('No')
else:
n = int(N/2)
s1 = S[:n]
s2 = S[n:]
if s1 == s2:
print('Yes')
else:
print('No') | 0 | null | 79,862,492,398,650 | 125 | 279 |
#!/usr/bin/env python3
import sys
import numpy as np
import numba
from numba import i8
input = sys.stdin.buffer.readline
mod = 998244353
def I():
return int(input())
def MI():
return map(int, input().split())
@numba.njit((i8, i8[:]), cache=True)
def main(N, LR):
L, R = LR[::2], LR[1::2]
K = len(L)
dp = np.zeros(N + 1, np.int64)
dpsum = np.zeros(N + 1, np.int64)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
for k in range(K):
li = i - R[k]
ri = i - L[k]
if ri < 0:
continue
li = max(li, 1)
dp[i] += dpsum[ri] - dpsum[li - 1]
dp[i] %= mod
dpsum[i] = dpsum[i - 1] + dp[i]
dpsum[i] %= mod
return dp[N]
N, K = MI()
LR = np.array(sys.stdin.buffer.read().split(), np.int64)
print(main(N, LR))
| import math
x1,y1,x2,y2 = map(float, input().split())
a1 = (x2-x1)**2
a2 = (x1-x2)**2
b1 = (y2-y1)**2
b2 = (y1-y2)**2
if x1<x2:
if y1<y2:
print(math.sqrt(a1+b1))
else:
print(math.sqrt(a1+b2))
else:
if y1<y2:
print(math.sqrt(a2+b1))
else:
print(math.sqrt(a2+b2))
| 0 | null | 1,447,103,354,252 | 74 | 29 |
N = int(input())
A = []
XY = []
for i in range(N):
a = int(input())
A.append(a)
xy = [list(map(int,input().split())) for j in range(a)]
XY.append(xy)
ans = 0
for i in range(2**N):
b = [i>>j&1 for j in range(N)]
f = 0
for j in range(N):
if b[j] == 1:
for k in range(A[j]):
x = XY[j][k][0] -1
y = XY[j][k][1]
if b[x] != y:
f = 1
break
if f:
break
else:
ans = max(ans,b.count(1))
print(ans) | import itertools
N = int(input())
xy_ls = []
for i in range(N):
A = int(input())
xy = [list(map(int,input().split())) for j in range(A)]
xy_ls.append(xy)
ans_ls = list(itertools.product([0,1], repeat=N))
max_ans = 0
for ans in ans_ls:
flg = True
for i in range(len(ans)):
if ans[i]==1:
for xy in xy_ls[i]:
if ans[xy[0]-1] == xy[1]:
pass
else:
flg = False
break
if flg == True:
max_ans = max(max_ans,sum(ans))
print(max_ans) | 1 | 121,313,564,664,348 | null | 262 | 262 |
"""AtCoder."""
n = int(input()[-1])
s = None
if n in (2, 4, 5, 7, 9):
s = 'hon'
elif n in (0, 1, 6, 8):
s = 'pon'
elif n in (3,):
s = 'bon'
print(s)
| import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()
from math import sqrt
def factor(n):
"""
nの約数を個数と共にリストにして返す。
ただしあとの都合上1は除外する。
"""
if n == 1:
return 0, []
if n == 2:
return 1, [2]
if n == 3:
return 1, [3]
d = int(sqrt(n))
num = 1
factor_pre = []
factor_post = [n]
for i in range(2, d):
if n % i == 0:
factor_pre.append(i)
factor_post.append(n // i)
num += 2
if d * d == n:
factor_pre.append(d)
num += 1
elif n % d == 0:
factor_pre.append(d)
factor_post.append(n // d)
num += 2
factor_post.reverse()
return num, factor_pre + factor_post
def main():
N = int(input())
"""
題を満たすKは、
N = K^e * n、(n, K) = 1
として
n = K * m + 1 (m ¥in ¥mathbb{N})
とかければ良い。
2つ目の式からnとKが互いに素なのは明らかなので、問題文は
N = K^e * (K * m + 1) (m ¥in ¥mathbb{N})
なるKを求めることに同値。
なのでまずはNの約数を全列挙して、あとはNをそれで割った商がKで割って1余るか確かめれば良い。
"""
_, fact = factor(N)
ans, ans_list = factor(N - 1)
# print(ans_list)
# print("Now we check the list {}".format(fact))
for K in fact:
n = N
while n % K == 0:
n //= K
if n % K == 1:
ans += 1
ans_list.append(K)
# print("{} added".format(K))
# print("ans={}: {}".format(ans, ans_list))
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 30,157,937,442,958 | 142 | 183 |
from collections import deque
n=int(input())
alpha=['a','b','c','d','e','f','g','h','i','j','k']
q=deque(['a'])
for i in range(n-1):
qi_ans=[]
while(len(q)>0):
qi=q.popleft()
qiword_maxind=0
for j in range(len(qi)):
qi_ans.append(qi+qi[j])
qij_ind=alpha.index(qi[j])
if(qiword_maxind<qij_ind):
qiword_maxind=qij_ind
else:
qi_ans.append(qi+alpha[qiword_maxind+1])
qi_ans=sorted(list(set(qi_ans)))
# print(qi_ans)
q.extend(qi_ans)
lenq=len(q)
for i in range(lenq):
print(q.popleft())
| n=int(input())
a=list(map(int,input().split()))
c=a[0]
for i in range(1,n):
c=c^a[i]
for i in range(n):
print(c^a[i]) | 0 | null | 32,383,024,975,122 | 198 | 123 |
import math
deg = int(input())
li_x = list(map(int,input().split()))
li_y = list(map(int, input().split()))
p1_dis = 0.0
p2_dis = 0.0
p2_temp = 0.0
p3_dis = 0.0
p3_temp = 0.0
p4_dis = 0.0
p4_temp = [ ]
for i in range(deg):
p1_dis += math.fabs(li_x[i] - li_y[i])
p2_temp += (li_x[i] - li_y[i]) **2.0
p3_temp += math.fabs(li_x[i] - li_y[i]) **3.0
p4_temp.append( math.fabs(li_x[i] - li_y[i]) )
p2_dis = math.sqrt( p2_temp )
p3_dis = math.pow(p3_temp, 1.0/3.0)
p4_dis = max(p4_temp)
print('{0:.6f}'.format(p1_dis))
print('{0:.6f}'.format(p2_dis))
print('{0:.6f}'.format(p3_dis))
print('{0:.6f}'.format(p4_dis)) | #! python3
# standard_deviation.py
import math
while True:
n = int(input())
if n == 0: break
s = [int(x) for x in input().split(' ')]
sum = 0
for num in s:
sum += num
m = sum/n
tmp_sum = 0
for num in s:
tmp_sum += pow(num - m, 2)
print("%.5f"%(math.sqrt(tmp_sum/n)))
| 0 | null | 200,766,357,220 | 32 | 31 |
import itertools
import numpy as np
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
score = []
ans = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
for i in range(Q):
a = abcd[i][0]
b = abcd[i][1]
c = abcd[i][2]
d = abcd[i][3]
if A[b-1]-A[a-1] == c:
score.append(d)
if ans <= sum(score):
ans = sum(score)
score.clear()
print(ans) | from collections import deque
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
da = deque()
i = 0
tmpK = 0
while tmpK <= K and i < N:
tmpK += A[i]
da.append(A[i])
i += 1
# 一冊多い場合がある
if (tmpK > K):
i -= 1
tmpK -= da.pop()
# Bを増やしていく
db = deque()
j = 0
while tmpK <= K and j < M:
tmpK += B[j]
db.append(B[j])
j += 1
# 一冊多い場合がある
if (tmpK > K):
j -= 1
tmpK -= db.pop()
tmptot = i+j
while len(da) > 0:
tmpK -= da.pop()
i -= 1
while tmpK <= K and j < M:
tmpK += B[j]
db.append(B[j])
j += 1
# 一冊多い場合がある
if (tmpK > K):
j -= 1
tmpK -= db.pop()
if tmptot < i+j:
tmptot = i+j
print(tmptot) | 0 | null | 19,231,160,540,380 | 160 | 117 |
def main():
a, b, c = map(int,input().split())
_set = set()
if a <= c and b >= c: _set.add(c)
if c // 2 < b:
b = c // 2
if c % 2 == 0:
_set = _set | set(range(a, b+1))
else:
if a % 2 == 0:
_set = _set | set(range(a+1, b+1, 2))
else:
_set = _set | set(range(a, b+1, 2))
print(sum(map(lambda x: c % x == 0, _set)))
main() | A, B, K = map(int, input().split())
if A >= K:
A = A - K
else:
B = B - (K - A)
A = 0
if B < 0:
B = 0
print(str(A) + " " + str(B)) | 0 | null | 52,706,227,884,452 | 44 | 249 |
import sys
import math
import cmath
sys.setrecursionlimit(1000000)
def dft_divide(f, l):
if l == 1:
return
ll = l // 2
f0 = [f[2 * i] for i in range(ll)]
f1 = [f[2 * i + 1] for i in range(ll)]
dft_divide(f0, ll)
dft_divide(f1, ll)
dft_solve(f, f0, f1, l)
return
def dft_solve(f, f0, f1, l):
ll = l // 2
for i in range(l):
z = cmath.exp(2j * i * cmath.pi / l)
f[i] = f0[i % ll] + z * f1[i % ll]
return
def idft_divide(f, l):
if l == 1:
return
ll = l // 2
f0 = [f[2 * i] for i in range(ll)]
f1 = [f[2 * i + 1] for i in range(ll)]
idft_divide(f0, ll)
idft_divide(f1, ll)
idft_solve(f, f0, f1, l)
return
def idft_solve(f, f0, f1, l):
ll = l // 2
for i in range(l):
z = cmath.exp(-2j * i * cmath.pi / l)
f[i] = f0[i % ll] + z * f1[i % ll]
return
def multiply(f, g):
lf, lg = len(f), len(g)
m = 2 ** (int(math.log2(lf + lg)) + 1)
for i in range(m - lf):
f.append(0)
for i in range(m - lg):
g.append(0)
dft_divide(f, m)
dft_divide(g, m)
fg = [f[i] * g[i] for i in range(m)]
idft_divide(fg, m)
c = [round(fg[i].real / m) for i in range(m)]
return c, m
n, m = map(int, input().split())
a = list(map(int, input().split()))
ma = max(a)
happiness1 = [0] * (ma + 1)
happiness2 = [0] * (ma + 1)
for i in a:
happiness1[i] += 1
happiness2[i] += 1
c, lc = multiply(happiness1, happiness2)
cnt = 0
ans = 0
for i in range(min(200000, lc - 1), -1, -1):
if c[i] + cnt >= m:
ans += (m - cnt) * i
cnt += (m - cnt)
else:
ans += c[i] * i
cnt += c[i]
if cnt == m:
break
print(ans) | n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
import bisect
def func(x):
C = 0
for p in l:
q = x -p
j = bisect.bisect_left(l, q)
C += n-j
if C >= m:
return True
else:
return False
l_ = 0
r_ = 2*10**5 +1
while l_+1 < r_:
c_ = (l_+r_)//2
if func(c_):
l_ = c_
else:
r_ = c_
ans = 0
cnt = 0
lr = sorted(l, reverse=True)
from itertools import accumulate
cum = [0] + list(accumulate(lr))
for i in lr:
j = bisect.bisect_left(l, l_-i)
ans += i*(n-j) + cum[n-j]
cnt += n -j
ans -= (cnt-m)*l_
print(ans) | 1 | 108,247,726,619,890 | null | 252 | 252 |
S=int(input())
dp=[]#答えの方
assim=[]#累積和
mod=10**9+7
for i in range(2001):
if i<3:
dp.append(0)
elif i==3:
dp.append(1)
else:
dp.append((assim[-3])%mod)
if i==0:
assim.append(0)
else:
assim.append((assim[-1]+dp[-1])%mod)
print(assim[S]) | k=int(input())
a,b=map(int,input().split())
if b//k-(a-1)//k==0 : print("NG")
else : print("OK") | 0 | null | 14,891,146,835,710 | 79 | 158 |
A,B=input().split()
A=int(A)
B=int(100*float(B)+0.5)
print(int(A*B/100)) | b, c = map(int, input().split())
print(b * c) | 1 | 15,781,650,471,128 | null | 133 | 133 |
class Calc:
def __init__(self, max_value, mod):
"""combination(max_value, all)"""
fact = [-1] * (max_value + 1)
fact[0] = 1
fact[1] = 1
for x in range(2, max_value + 1):
fact[x] = x * fact[x - 1] % mod
invs = [1] * (max_value + 1)
invs[max_value] = pow(fact[max_value], mod - 2, mod)
for x in range(max_value - 1, 0, -1):
invs[x] = invs[x + 1] * (x + 1) % mod
self.fact = fact
self.invs = invs
self.mod = mod
def combination(self, n, r):
if n - r < r:
return self.combination(n, n - r)
if r < 0:
return 0
if r == 0:
return 1
if r == 1:
return n
return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod
def factorial(self, n):
return self.fact[n]
def main():
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
K = min(K, N - 1) # K=最大空室数->N部屋空室は不可能
calc = Calc(max_value=N * 2, mod=MOD)
ans = 0
for v in range(K + 1): # 空室数
ans = (ans + (calc.combination(N, v) * calc.combination(v + (N - v) - 1, v)) % MOD) % MOD
print(ans)
if __name__ == '__main__':
main()
| def cmb(n, r, mod):
if (r < 0) or (n < r):
return 0
r = min(r, n-r)
return fact[n]*factinv[r]*factinv[n-r]%mod
mod = 10**9+7
N = 10**6 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N+1):
fact.append((fact[-1]*i)%mod)
inv.append((-inv[mod%i]*(mod//i))%mod)
factinv.append((factinv[-1]*inv[-1])%mod)
n, k = map(int,input().split())
ans = 0
for i in range(0, min(n, k+1)):
#0がi個
ans = (ans + cmb(n, i, mod) * cmb(n-1, i, mod)) % mod
print(ans) | 1 | 67,028,490,258,180 | null | 215 | 215 |
def main():
num = [int(input()) for i in range(2)]
print(6-num[0]-num[1])
main() | a = int(input())
b = int(input())
for i in range(1,4):
if i !=a and i!= b:
print(i) | 1 | 110,355,952,903,742 | null | 254 | 254 |
def calcGaps(n):
gaps = [1]
while 3 * gaps[-1] + 1 < n:
gaps.append(3 * gaps[-1] + 1)
return gaps[::-1]
def insertionSort(a, n, gap, cnt):
for i in range(gap, n):
v = a[i]
j = i - gap
while j >= 0 and a[j] > v:
a[j + gap] = a[j]
j = j - gap
cnt += 1
a[j + gap] = v
return a, cnt
def shellSort(a, n):
cnt = 0
Gaps = calcGaps(n)
for gap in Gaps:
a, cnt = insertionSort(a, n, gap, cnt)
print(len(Gaps))
print(*Gaps)
print(cnt)
print(*a, sep='\n')
n = int(input())
A = [int(input()) for _ in range(n)]
shellSort(A, n)
| s,t = input().split()
a,b = (int(x) for x in input().split())
u = input()
if u == s:
print(a - 1,b)
else:
print(a,b - 1)
| 0 | null | 35,879,328,866,808 | 17 | 220 |
from collections import deque
def bfs(sy,sx):
q=deque([[sy,sx]])
visited[sy][sx]=0
while q:
y,x=q.popleft()
for dy,dx in ([1,0],[-1,0],[0,1],[0,-1]):
ny,nx=y+dy,x+dx
if ny<0 or ny>h-1 or nx<0 or nx>w-1 or path[ny][nx]=="#":continue
if path[ny][nx]=="." and visited[ny][nx]==-1:
visited[ny][nx]=visited[y][x]+1
q.append([ny,nx])
res=-1
for i in range(h):
for j in range(w):
res=max(visited[i][j],res)
return res
h,w=map(int,input().split())
path=[input() for i in range(h)]
visited=[[-1]*w for i in range(h)]
sy,sx=0,0
gy,gx=0,0
ans=0
for i in range(h):
for j in range(w):
if path[i][j]=="#":continue
sy=i
sx=j
visited=[[-1]*w for _ in range(h)]
t=bfs(sy,sx)
ans=max(t,ans)
print(ans)
| while 1:
l=raw_input()
if l.find("?")==-1:
print eval(l)
else:
break | 0 | null | 47,750,798,648,750 | 241 | 47 |
from numba import jit
@jit
def solve():
n, k = map(int,input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
max_score = -10**10
for i in range(n):
count = 1
val = c[i]
next_i = p[i] -1
while next_i != i:
count += 1
val += c[next_i]
next_i = p[next_i] - 1
if val > 0:
loop_num = (k//count -1)
tmp_score = loop_num * val
max_score = max(tmp_score, max_score)
num = k%count+count
else:
tmp_score = 0
num = min(k, count)
next_i = i
for _ in range(num):
next_i = p[next_i] - 1
tmp_score += c[next_i]
max_score = max(tmp_score, max_score)
print(max_score)
solve() | def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N, K = getNM()
P = [i - 1 for i in getList()]
C = getList()
ignore = [-1] * N
ans = -float('inf')
for i in range(N):
if ignore[i] >= 0:
continue
### ループ生成 ###
ignore[i] = 1
opt_l = [i]
to = P[i]
while ignore[to] == -1:
opt_l.append(to)
ignore[to] = 1
to = P[to]
###
### 作成したループで得点リスト生成 ###
n = len(opt_l)
point = [0] * n
for i in range(n):
point[i] = C[opt_l[i]]
###
### 得点リスト内の連続する区間の総和のうちの最大値を累積和を使って求める ###
sum_roop = sum(point)
# ループの累積和作成
imos = [0]
point += point
for i in range(len(point)):
imos.append(imos[i] + point[i])
#
ran = min(n, K)
for i in range(n):
# 区間の大きさran以下についての総和を求める
for j in range(1, ran + 1):
if sum_roop >= 0:
opt = imos[i + j] - imos[i] + ((K - j) // n) * sum_roop
else:
opt = imos[i + j] - imos[i]
ans = max(ans, opt)
###
print(ans) | 1 | 5,378,199,594,340 | null | 93 | 93 |
a, b, c = map(int, raw_input().split(' '))
num = 0
for i in range(a,b+1):
if c % i == 0:
num = num + 1
print(num) | import sys
from collections import defaultdict
from queue import Queue
def main():
input = sys.stdin.buffer.readline
n = int(input())
g = defaultdict(list)
for i in range(n):
line = list(map(int, input().split()))
if line[1] > 0:
g[line[0]] = line[2:]
q = Queue()
q.put(1)
dist = [-1] * (n + 1)
dist[1] = 0
while not q.empty():
p = q.get()
for nxt in g[p]:
if dist[nxt] == -1:
dist[nxt] = dist[p] + 1
q.put(nxt)
for i in range(1, n + 1):
print(i, dist[i])
if __name__ == "__main__":
main()
| 0 | null | 283,226,692,662 | 44 | 9 |
while 1:
h,w=map(int,raw_input().split())
if (h,w)==(0,0):
break
print ("#"*w+"\n")*h | while True:
(H,W) = [int(x) for x in input().split()]
if H == W == 0:
break
for h in range(0, H):
for w in range(0, W):
print("#", end="")
if w == W - 1:
print()
break
print() | 1 | 770,190,471,150 | null | 49 | 49 |
S,H,C,D = set(),set(),set(),set()
W = set([1,2,3,4,5,6,7,8,9,10,11,12,13])
n = int(input())
for i in range(n):
N = input().split()
if N[0] == 'S':
S.add(int(N[1]))
elif N[0] == 'H':
H.add(int(N[1]))
elif N[0] == 'C':
C.add(int(N[1]))
elif N[0] == 'D':
D.add(int(N[1]))
s,h,c,d = [],[],[],[]
st = W - S
while st != set():
s.append(st.pop())
s.sort()
ht = W - H
ct = W - C
dt = W - D
while ht != set():
h.append(ht.pop())
h.sort()
while ct != set():
c.append(ct.pop())
c.sort()
while dt != set():
d.append(dt.pop())
d.sort()
for i in s:
print('S {0}'.format(i))
for i in h:
print('H {0}'.format(i))
for i in c:
print('C {0}'.format(i))
for i in d:
print('D {0}'.format(i)) | n, m = map(int, input().split())
lis = sorted(list(map(int, input().split())), reverse=True)
con = 0
for i in range(n):
if lis[i] >= sum(lis) * (1/(4*m)):
con += 1
if con == m:
print("Yes")
exit()
print("No") | 0 | null | 19,833,136,378,130 | 54 | 179 |
n,k=map(int,input().split())
sunu=[0]*n
for i in range(k):
d=int(input())
a=list(map(int,input().split()))
for j in range(d):
sunu[a[j]-1]+=1
ans=0
for i in range(len(sunu)):
if sunu[i]==0:
ans+=1
print(ans) | Moji = 'ACL'
K = int(input())
Answer = (Moji * K)
print(Answer)
| 0 | null | 13,396,274,985,920 | 154 | 69 |
from collections import deque
def bfs(s):
color[s] = 'GRAY'
d[s] = 0
Q.append(0)
while len(Q) != 0:
u = Q.popleft()
for v in range(n):
if M[u][v] and color[v] == 'WHITE':
color[v] = 'GRAY'
d[v] = d[u] + 1
Q.append(v)
color[u] = 'BLACK'
n = int(input())
M = [[0] * n for _ in range(n)]
color = ['WHITE'] * n
d = [-1] * n
Q = deque()
for _ in range(n):
a = list(map(int, input().split()))
u = a[0]
v = a[2:]
for j in v:
M[u - 1][j - 1] = 1
bfs(0)
for i in range(n):
out = ''
out += '{} {}'.format(i + 1, d[i])
print(out) | from collections import deque
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n):
u, k, *V = list(map(int, input().split()))
V.sort()
for v in V:
g[u-1].append(v-1)
# g[v-1].append(u-1)
d = [-1] * n
d[0] = 0
que = deque([])
que.append(0)
while que:
v = que.popleft()
for i in g[v]:
if d[i] == -1:
d[i] = d[v] + 1
que.append(i)
for i in range(n):
print(f'{i+1} {d[i]}')
| 1 | 4,350,397,822 | null | 9 | 9 |
a = []
while True:
num = int(input())
if num == 0:
break
a.append(num)
i=1
for x in a:
print('Case {}: {}'.format(i,x))
i += 1 | if __name__ == '__main__':
current_no = 1
while True:
input_num = int(input())
if input_num != 0:
print('Case {0}: {1}'.format(current_no, input_num))
current_no += 1
else:
break | 1 | 499,261,070,560 | null | 42 | 42 |
n=int(input())
a=[]
for i in range(1,n+1):
if not(i%3==0 or i%5==0):
a.append(i)
print(sum(a)) | import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
cnt = 0
for i in range(1,N + 1):
if i % 3 != 0 and i % 5 != 0:
cnt += i
print(cnt) | 1 | 34,885,524,670,400 | null | 173 | 173 |
x = int(input())
for i in range(243):
for j in range(243):
if (i-121)**5 - (j-121)**5 == x:
print(i-121,j-121)
exit() | # D - Alter Altar
N = int(input())
c = input()
white_l = 0
red_r = 0
for i in range(N):
if c[i]=='R':
red_r += 1
ans = red_r
for i in range(N):
if c[i]=='W':
white_l += 1
else:
red_r -= 1
ans = min(ans, max(red_r,white_l))
print(ans) | 0 | null | 15,965,407,624,320 | 156 | 98 |
d,t,s=[int(i) for i in input().split()]
if d<=t*s:
print("Yes")
else:
print("No") |
# Can't Wait for Holiday
S = input()
if S == 'SUN':
a = 0
elif S == 'MON':
a = 1
elif S == 'TUE':
a = 2
elif S == 'WED':
a = 3
elif S == 'THU':
a = 4
elif S == 'FRI':
a = 5
elif S == 'SAT':
a = 6
answer = 7 - a
print(answer) | 0 | null | 68,283,525,549,762 | 81 | 270 |
k , x = (int(a) for a in input().split())
if k*500 >= x :
print("Yes")
else : print("No") | k, y = [int(i) for i in input().split()]
print('Yes' if 500 * k >= y else 'No') | 1 | 98,148,255,206,662 | null | 244 | 244 |
for i in range(1,10):
for j in range(1,10):
ans = "%dx%d=%d"%(i,j,i*j)
print(ans) | for a in range(1,10):
for b in range(1,10):
ans = a*b
print("%dx%d=%d" % (a, b, ans)) | 1 | 1,441,232 | null | 1 | 1 |
a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while a >= b:
cnt += 1
b *= 2
while b >= c:
cnt += 1
c *= 2
if cnt <= k: print("Yes")
else: print("No") | N=int(input())
S=input()
new = S[0]
for i in range(1,N):
if S[i]!=S[i-1]:new = new + S[i]
print(len(new)) | 0 | null | 88,399,199,348,668 | 101 | 293 |
a, b =map(int, input().split())
m = a*b
lst = []
for i in range(1, b+1):
if m < a*i:
break
lst.append(a*i)
for j in lst:
if j%b == 0:
print(j)
break | import math
import numpy as np
A,B = np.array(input().split(),dtype = int)
def gcd(x,y):
if y == 0:
return x
else:
return gcd(y,x%y)
print(int(A*B/(gcd(A,B)))) | 1 | 113,330,638,362,668 | null | 256 | 256 |
n,m,q = [int(_) for _ in input().split()]
a = []
b = []
c = []
d = []
for q in range(q):
tmplist = [int(_) for _ in input().split()]
a.append(tmplist[0])
b.append(tmplist[1])
c.append(tmplist[2])
d.append(tmplist[3])
# Aという数列を再帰関数で求める
# {} → {A1, A2, A3...AN} の数
result=[]
def score(A):
max_score = 0
for i in range(q+1):
if A[b[i]-1] - A[a[i]-1] != c[i]: # なぜマイナス1をしているのか?:q
continue
else:
max_score+= d[i]
return max_score
def dfs(A):
if len(A) == n+1: # 配列の個数はN個
return score(A)
result = 0
past_data = A[-1]
for v in range(past_data,m+1):
A.append(v)
result = max(result,dfs(A))
A.pop()
return result
print(dfs([1]))
| from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
abcds = [tuple(map(int, input().split()))for _ in range(Q)]
def cal_score(A):
score = 0
for a, b, c, d in abcds:
if A[b-1] - A[a-1] == c:
score += d
return score
ans = 0
for A in combinations_with_replacement([i for i in range(M)], N):
ans = max(ans, cal_score(A))
print(ans)
| 1 | 27,472,150,657,746 | null | 160 | 160 |
# 入力
# 値は全てint
# Nは本数、Kは切る回数、AはN本の木のそれぞれの長さ(リスト)
N,K = map(int,input().split())
A = list(map(int,input().split()))
# 二分探索
# lが左端、rが右端
l,r = 0, 10**9
# 整数で返すので、差が1より大きい時はループする
while r - l > 1:
# 真ん中を設定
x = (r+l) // 2
# 切る回数をc
c = 0
for a in A:
# それぞれの丸太の(長さ-1)をxで割った値の合計が、切る回数
c += (a-1) // x
# 切る回数がKよりも小さい時はOKなので右端を寄せる
if c <= K:
r = x
else:
l = x
print(r)
| n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
mid = (ok+ng)//2
cur = 0
for i in range(n):
cur += L[i]//mid
if cur > k:
ok = mid
elif cur <= k:
ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
res = 0
if K[i] > 0:
for j in range(n):
res += (L[j]-1)//K[i]
if res <= k:
P.append(K[i])
print(min(P))
| 1 | 6,489,206,233,640 | null | 99 | 99 |
s, t = map(str, input().split())
a, b = map(int, input().split())
u = input()
st = {}
st[s] = a
st[t] = b
st[u] -= 1
print('{} {}'.format(st[s], st[t])) | def main():
S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:
return " ".join(map(str, [A-1, B]))
else:
return " ".join(map(str, [A, B-1]))
if __name__ == '__main__':
print(main())
| 1 | 72,106,298,309,008 | null | 220 | 220 |
K,X=input().split()
K=int(K)
X=int(X)
if 500*K>=X:
print('Yes')
else:
print('No') | k,x = map(int,input().split())
if 500*k >= x:
print("Yes")
else:
print("No") | 1 | 98,309,191,324,602 | null | 244 | 244 |
def selectionSort(a, n):
count = 0
for i in range(0, n):
minj = i
for j in range(i, n):
if a[j] < a[minj]:
minj = j
a[i], a[minj] = a[minj], a[i]
if i != minj:
count += 1
return count
def main():
n = int(input())
a = [int(x) for x in input().split(' ')]
count = selectionSort(a, n)
print(' '.join([str(x) for x in a]))
print(count)
if __name__ == '__main__':
main() | #coding:utf-8
#1_2_B
def selection_sort(ary, n):
count = 0
for i in range(n):
minj = i
for j in range(i, n):
if ary[minj] > ary[j]:
minj = j
if ary[minj] != ary[i]:
ary[minj], ary[i] = ary[i], ary[minj]
count += 1
print(*ary)
print(count)
n = int(input())
selection_sort(list(map(int, input().split())), n) | 1 | 20,841,700,300 | null | 15 | 15 |
N, K = map(int, input().split())
result = 1
for i in range(K, N+1):
tmp_min = (i - 1) * i // 2
tmp_max = (N * (N + 1) - (N - i) * (N - i + 1)) // 2
result += tmp_max - tmp_min + 1
result %= 10 ** 9 + 7
print(result)
| n = int(input())
for i in range(50001):
if int(i * 1.08) == n:
print(i)
exit()
print(":(") | 0 | null | 79,792,691,780,312 | 170 | 265 |
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
a[i], b[i] = [int(j) for j in input().split()]
a.sort()
b.sort()
if n % 2 == 1:
print(b[n//2] - a[n//2] + 1)
else:
print(b[n//2] + b[n//2-1] - a[n//2] - a[n//2-1] + 1) | from statistics import median
N = int(input())
A = []
B = []
for n in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
#AB = sorted(AB, key=lambda x: x[0])
#print(AB)
cenA = median(A)
cenB = median(B)
if N % 2 == 1:
print(int(cenB - cenA + 1))
elif N % 2 == 0:
print(int((cenB - cenA)*2 + 1))
else:
print('RE') | 1 | 17,263,109,902,172 | null | 137 | 137 |
import sys
def make_all_cards():
mark = ['S', 'H', 'C', 'D']
cards = []
for i in mark:
for n in range(1, 14):
cards.append(i + ' ' + str(n))
return cards
if __name__ == '__main__':
all_cards = make_all_cards()
n = int(sys.stdin.readline().strip())
for _ in range(n):
card = sys.stdin.readline().strip()
all_cards.remove(card)
for i in all_cards:
print(i)
| print(10 - int(float(input())/200)) | 0 | null | 3,840,103,038,748 | 54 | 100 |
m = 100
x = int(input())
y = 0
while x >= m:
if x == m:
break
m = m + m // 100
y += 1
print(y)
| x = int(input())
sum = 100
year = 0
while x > sum:
sum += sum//100
year += 1
print(year)
| 1 | 26,991,521,695,610 | null | 159 | 159 |
import numpy as np
H,W = input().split()
H,W=int(H),int(W)
P=[0]*H
for i in range(H):
P[i] = input()
dp=np.zeros((H,W),dtype='u8')
if P[0][0]=='#':
dp[0][0]=1
else:
dp[0][0]=0
def DP(y,x):
global dp
if 0<=x<=W-1 and 0<=y<=H-1:
return dp[y][x]
else:
return 9999999
for l in range(1,H+W):
for i in range(l+1):
if i<H and l-i<W:
if P[i][l-i]=='#':
a=DP(i-1,l-i)
b=DP(i,l-i-1)
if a < 9999999:
if P[i-1][l-i]=='.':
a+=1
if b < 9999999:
if P[i][l-i-1]=='.':
b+=1
dp[i][l-i]=min(a,b)
else:
#print(i,l-i,DP(i-1,l-i),DP(i,l-i-1))
dp[i][l-i]=min(DP(i-1,l-i),DP(i,l-i-1))
print(dp[H-1][W-1]) | import sys
from collections import deque
input = sys.stdin.readline
H, W = map(int, input().split())
grid = []
for _ in range(H):
grid.append(list(input().strip()))
q = deque()
# x, y, count, pre color
q.append((0, 0, 1 if grid[0][0] == "#" else 0, grid[0][0]))
visited = [[-1 for _ in range(W)] for _ in range(H)]
ans = float("inf")
while q:
x, y, count, pre = q.popleft()
# print(x, y, count, pre)
v_score = visited[y][x]
if v_score != -1 and v_score <= count:
continue
visited[y][x] = count
for dx, dy in ((1, 0), (0, 1)):
nx = x + dx
ny = y + dy
nc = count
if nx < 0 or W <= nx or ny < 0 or H <= ny:
continue
n_color = grid[ny][nx]
if n_color != pre and n_color == "#":
nc += 1
if nx == W-1 and ny == H-1:
ans = min(ans, nc)
print(ans)
sys.exit()
else:
if visited[ny][nx] != -1 and visited[ny][nx] <= nc:
continue
if count == nc:
q.appendleft((nx, ny, nc, n_color))
else:
q.append((nx, ny, nc, n_color))
# print(visited)
print(ans) | 1 | 49,165,519,097,666 | null | 194 | 194 |
from copy import deepcopy
N, M = map(int, input().split())
pairs = [0] * M
for i in range(M):
pairs[i] = list(map(int, input().split()))
# N = 5
# pairs = [[1,2], [3,4], [5,1]]
class UnionFind:
def __init__(self, N):
self.r = [-1] * N
def root(self, x):
if self.r[x] < 0:
return x
self.r[x] = self.root(self.r[x])
return self.r[x]
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.r[x] > self.r[y]:
x, y = y, x
self.r[x] += self.r[y]
self.r[y] = x
return True
def size(self, x):
return -self.r[self.root(x)]
uf = UnionFind(N)
for pair in pairs:
a = pair[0] - 1
b = pair[1] - 1
uf.unite(a, b)
ans = 0
for i in range(N):
ans = max(ans, uf.size(i))
print(ans)
| N = input()
s1 = []
s2 = []
res = []
ans = []
cnt = 0
for i in range(len(N)):
if N[i] == "\\":
s1.append(i)
elif N[i] == "/" and s1:
idx = s1.pop()
tmp = i - idx
cnt += tmp
while s2 and idx < s2[-1][0]:
tmp += s2.pop()[1]
s2.append((idx, tmp))
res.append(len(s2))
for i in range(len(s2)):
ans.append(s2[i][1])
res.extend(ans)
print(cnt)
print(" ".join(map(str, res)))
| 0 | null | 2,035,983,576,202 | 84 | 21 |
def lcm(x, y):
from fractions import gcd
return (x * y) // gcd(x, y)
a,b = map(int,input().split())
print(lcm(a,b)) | def gcd(a, b):
return b if a % b == 0 else gcd(b, a % b)
def lcm(a, b):
return a // gcd(a, b) * b
a, b = map(int, input().split())
print(lcm(a, b))
| 1 | 113,525,470,384,320 | null | 256 | 256 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numba
def main():
@numba.njit
def solve(n):
r = 0
for i1 in range(1, n + 1):
y = n // i1
r += y * (y + 1) // 2 * i1
return r
no = int(input())
print(solve(no))
if __name__ == '__main__':
main() | from numba import njit
n = int(input())
@njit
def solve():
f = [1] * (n + 1)
for i in range(2, n + 1):
if f[i] != 1: continue
m = i
while m <= n:
tmp = m
cnt = 0
while tmp % i == 0:
tmp = tmp // i
cnt += 1
f[m] *= cnt + 1
m += i
ans = 0
for i in range(1, n + 1):
ans += i * f[i]
return ans
print(solve()) | 1 | 11,053,853,621,262 | null | 118 | 118 |
a,b,c = raw_input().strip().split(" ")
if int(a) < int(b) < int(c):
print "Yes"
else:
print "No" | a,b,c = input().split(' ')
a=int(a)
b=int(b)
c=int(c)
ret="Yes" if a<b<c else "No"
print(ret) | 1 | 389,621,300,132 | null | 39 | 39 |
N,M = map(int,input().split())
A = list(map(int,input().split()))
for i in range(M):
N -= A[i]
if N<0:
print("-1")
exit()
elif N>=0 and i+1 == M:
print(N)
exit() | N = int(input())
A = [input() for _ in range(N)]
count = [0] * 4
for a in A:
if a == 'AC':
count[0] += 1
elif a == 'WA':
count[1] += 1
elif a == 'TLE':
count[2] += 1
else:
count[3] += 1
print(f"AC x {count[0]}")
print(f"WA x {count[1]}")
print(f"TLE x {count[2]}")
print(f"RE x {count[3]}") | 0 | null | 20,210,771,599,018 | 168 | 109 |
l = [int(x) for x in input().split()]
X, N = l[0], l[1]
p = [int(x) for x in input().split()]
delta = 0
while True:
if not X - delta in p:
print(X-delta)
break
if not X + delta in p:
print(X + delta)
break
delta += 1 | X,N = map(int,input().split())
min = 100
if N !=0:
Plist = list(map(int,input().split()))
anslist = [i for i in range(102)]
anslist.append(-1)
#anslist.remove(0)
Plist = sorted(Plist)
#print (anslist)
for i in range(N):
anslist.remove(Plist[i])
temp =100
for i in range(len(anslist)):
if min >abs(anslist[i]-X) :
min = abs(anslist[i]-X)
temp = anslist[i]
print (temp)
else :
print (X) | 1 | 14,036,673,320,448 | null | 128 | 128 |
n = int(input())
P = list(map(int,input().split()))
tmp = float('inf')
cnt = 0
for i,p in enumerate(P):
if p <=tmp:
cnt += 1
tmp = min(tmp,p)
print(cnt)
| n = int(input())
p = list(map(int, input().split()))
min_val = n + 1
count = 0
for x in p:
if x < min_val:
min_val = x
count += 1
print(count)
| 1 | 85,423,340,798,602 | null | 233 | 233 |
N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))
S = set(S)
T = set(T)
C = list(S & T)
print(len(C)) | w = input()
t = []
count = 0
while True:
line = input()
if line == 'END_OF_TEXT':
break
for x in line.split():
if w.lower() == x.lower():
count += 1
print(count) | 0 | null | 964,101,203,748 | 22 | 65 |
S = input()
T = input()
# S = "cabacc"
# T = "abc"
lt = len(T)
def diff(s1, s2):
d = len(s1)
d -= len([i for i,j in zip(s1, s2) if i == j])
return d
dlen = 1000000000
for i in range(len(S)):
if i + lt <= len(S):
dlen = min(dlen, diff(T, S[i:i+lt]))
print(dlen)
| s = input()
t = input()
max = 0
for i in range(len(s) -len(t) + 1):
target = s[i:i+len(t)]
matched = 0
for j in range(len(target)):
if target[j] == t[j]:
matched += 1
if matched > max:
max = matched
print(len(t) - max)
| 1 | 3,719,466,629,960 | null | 82 | 82 |
n = int(input())
if n%2 == 1:
print(0)
exit()
num = 5
i = 1
ans = 0
while num**i < n:
ans += n//num**i//2
i += 1
print(ans) | import math as m
EPS = 0.0000000001
def f(a, b, theta):
if theta > m.pi/2 - EPS:
return 0
if a * m.tan(theta) <= b:
ret = a * a * b - a * a * a * m.tan(theta) / 2
else:
ret = b * b / m.tan(theta) * a / 2
return ret
def solve():
a, b, x = map(int, input().split())
ok = m.pi / 2
ng = 0
for _ in range(100):
mid = (ok + ng) / 2
if f(a, b, mid) < x:
ok = mid
else:
ng = mid
print(ok * 180 / m.pi)
if __name__ == "__main__":
solve() | 0 | null | 139,947,717,194,220 | 258 | 289 |
while True:
try:a,b=map(int,input().split())
except:break
c=a+b
ans=0
while c>9:
c=c//10
ans+=1
ans+=1
print(ans)
| a, b, c = (int(i) for i in ((input()).split()))
if a < b < c:
print('Yes')
else:
print('No') | 0 | null | 199,061,461,380 | 3 | 39 |