code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
bunshi=1
bunbo=1
for i in range(r):
bunbo = bunbo*(i+1)%mod
bunshi = bunshi*(n-i)%mod
return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
n,m = MI()
graph = [[] for _ in range(n+1)]
for i in range(m):
a,b = MI()
graph[a].append(b)
graph[b].append(a)
dist = [-1]*(n+1)
dist[0] = 0
dist[1] = 0
d = deque()
d.append(1)
ans = [0]*(n+1)
while d:
v = d.popleft()
for i in graph[v]:
if dist[i] != -1:
continue
ans[i] = v
dist[i] = 0
d.append(i)
print("Yes")
for i in ans[2:]:
print(i) | import sys
def resolve(in_, out):
n = int(in_.readline())
b = [0] * (n + 1)
for a in map(int, in_.readline().split()):
b[a] += 1
out.write('\n'.join(map(str, b[1:])))
def main():
resolve(sys.stdin.buffer, sys.stdout)
if __name__ == '__main__':
main() | 0 | null | 26,416,678,973,520 | 145 | 169 |
def main():
A = map(int, input().split())
print('bust' if sum(A) >= 22 else 'win')
if __name__ == '__main__':
main()
| s,t = input().split()
print(t,s,sep='') | 0 | null | 111,140,731,623,150 | 260 | 248 |
string = input()
if string[len(string)-1] == "s":
print(string+'es')
else:
print(string+'s')
| #!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
n = int(sys.stdin.readline())
s = list(map(int, sys.stdin.readline().split()))
q = int(sys.stdin.readline())
t = list(map(int, sys.stdin.readline().split()))
s_set = set(s)
total = 0
for x in t:
if x in s_set:
total += 1
print(total)
| 0 | null | 1,245,598,437,800 | 71 | 22 |
s = input()
p = input()
s = s + s
if p in s:
print('Yes')
else:
print('No')
| # ????????°??¶???????????? s ???????????????????????????????¨????????????£?¶????????????????????????????????????§???????????? p ??????????????????????????????????????°??????
# ????????°??¶????????????s????¨??????\?????????????????????
s = list(input())
# ??????????±??????????p????¨??????\?????????????????????
p = list(input())
# ?????????s??????????????????????????????????????????s?????????s?????????
s = s + s
# print(s)
# ???????????????????????????????????????????????°
flag = 0
for i in range(len(s) // 2):
if s[i] == p[0]:
for j in range(len(p)):
if s[i + j] != p[j]:
break
if j == len(p) - 1:
flag = 1
if flag == 1:
print("Yes")
else:
print("No") | 1 | 1,729,718,730,190 | null | 64 | 64 |
import math
n = int(input())
S = list(map(int,input().split()))
M = 10**9 + 1
def merge(A, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
L = A[left:left + n1]
R = A[mid:mid + n2]
L.append(M)
R.append(M)
i = 0
j = 0
for k in range(left,right):
count += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 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)
count = 0
mergeSort(S,0,len(S))
print(*S)
print(count) | r, c = map(int, input().split())
rows = []
for i in range(r):
row = list(map(int, input().split()))
row.append(sum(row))
rows.append(row)
erow = [0 for i in range(c + 1)]
for row1 in rows:
print(" ".join(str(s) for s in row1))
for i in range(c + 1):
erow[i] += row1[i]
print(" ".join(str(s) for s in erow)) | 0 | null | 719,921,559,058 | 26 | 59 |
n = int(input())
print(int(n**2)) | print(pow(int(input()), 2))
| 1 | 145,959,226,205,602 | null | 278 | 278 |
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
G = [0]*3
ans = 1
for i in range(N):
x = 0
cnt = 0
for j, g in enumerate(G):
if g == A[i]:
x = j if cnt == 0 else x
cnt += 1
G[x] += 1
ans *= cnt
ans = ans % mod
print(ans) | import sys
n=int(input())
A=list(map(int,input().split()))
p=10**9+7
status=[1,0,0]
ans=3
if A[0]!=0:
print(0)
sys.exit()
for i in range(1,n):
count=status.count(A[i])
if count==0:
print(0)
sys.exit()
ans=(ans*count)%p
status[status.index(A[i])]+=1
print(ans) | 1 | 130,371,652,456,538 | null | 268 | 268 |
A=input()
if str.isupper(A):
print('A')
else:
print('a')
| N = int(input())
def kccv(a, b, c, d):
return [a*2/3 + c/3, b*2/3 + d/3, a/2 + b*(3**0.5)/6 + c/2 - d*(3**0.5)/6, -a*(3**0.5)/6 + b/2 + c*(3**0.5)/6 + d/2, a/3 + c*2/3, b/3 + d*2/3]
ans = [[[0,0],[100,0]]]
for i in range(1,N+1):
m = len(ans[i-1])
newset = []
for j in range(m-1):
newset.append(ans[i-1][j])
newdot = kccv(ans[i-1][j][0], ans[i-1][j][1], ans[i-1][j+1][0], ans[i-1][j+1][1])
x1 = newdot[0]
y1 = newdot[1]
x2 = newdot[2]
y2 = newdot[3]
x3 = newdot[4]
y3 = newdot[5]
newset.append([x1,y1])
newset.append([x2,y2])
newset.append([x3,y3])
newset.append(ans[i-1][m-1])
ans.append(newset)
for i in range(len(ans[N])):
print(ans[N][i][0],ans[N][i][1])
| 0 | null | 5,750,166,890,512 | 119 | 27 |
def solve():
A, B, C = map(int, input().split())
if A == B and A != C:
print('Yes')
elif A == C and A != B:
print('Yes')
elif B == C and A != B:
print('Yes')
else:
print('No')
if __name__ == '__main__':
solve()
| X = int(input())
for k in range(3, 361):
if (k*X)%360==0:
print(k)
exit() | 0 | null | 40,715,588,606,912 | 216 | 125 |
x = input()
x = int(x)
num = 1
while x:
print("Case {0}: {1}".format(num, x))
x = input()
x = int(x)
num += 1 | case_index = 0
while True:
case_index += 1
n = int(raw_input())
if 0 == n:
break
print 'Case %d: %d'%(case_index, n) | 1 | 474,243,302,732 | null | 42 | 42 |
s = input()
t = input()
c = 0
for i in range(len(s)) :
if s[i] != t[i] :
c = 1
if c == 1 :
print('No')
else :
print('Yes') | x,k,d = list(map(int,input().split()))
x = abs(x)
m = x // d
if m >= k:
ans = x - (d*k)
elif (k-m) % 2 == 0:
ans = x - (d*m)
else:
ans = x - (d*m) - d
print(abs(ans)) | 0 | null | 13,341,006,907,618 | 147 | 92 |
n=int(input())
for i in range(1,361):
if (n*i)%360==0:
print(i);exit() | N = int(input())
pi = 360
while True:
if pi % N == 0:
print(pi//N)
exit()
else:
pi+=360 | 1 | 13,147,125,561,170 | null | 125 | 125 |
# coding: utf-8
# Your code here!
import sys
import math
n=int(input())
ans=n
for i in range(1,int(math.sqrt(n))+1):
if n%i==0:
a=i
b=int(n/i)
if a+b-2<ans:
ans=a+b-2
print(ans)
| #144_C
import math
n = int(input())
m = math.floor(math.sqrt(n))
div = 1
for i in range(1,m+1):
if n % i == 0:
div = i
print(int(div + n/div -2)) | 1 | 162,208,038,397,340 | null | 288 | 288 |
print(int(input())**2) | from collections import Counter
word = input()
count = 0
while True:
text = input()
if text == 'END_OF_TEXT':
break
count += Counter(text.lower().split())[word.lower()]
print(count) | 0 | null | 73,202,832,037,958 | 278 | 65 |
h,n=map(int,input().split())
a,b=[],[]
for i in range(n):
A,B=map(int,input().split())
a.append(A)#ダメージ量
b.append(B)#消費魔力
dp=[float('inf')]*(h+1)
dp[0]=0
for i in range(h):
for j in range(n):
next=i+a[j] if i+a[j]<=h else h
dp[next]=min(dp[next],dp[i]+b[j])
print(dp[-1])
| H, N = list(map(int,input().split()))
A = []
B = []
for i in range(N):
in1, in2 = list(map(int,input().split()))
A.append(in1)
B.append(in2)
# dp[i]: モンスターの体力がiのときの最適値
INF = 10 ** 9 + 7
dp = [INF for _ in range(H + 1)]
dp[0] = 0
for i in range(1, H + 1):
for j in range(N):
dp[i] = min(dp[i], dp[max(0, i - A[j])] + B[j])
print(dp[H]) | 1 | 81,064,433,334,020 | null | 229 | 229 |
d=input().split()
for o in list(input()):
s={'N':(0,1,5,4),'W':(0,2,5,3),'E':(0,3,5,2),'S':(0,4,5,1)}[o]
for i in range(3):d[s[i+1]],d[s[i]]=d[s[i]],d[s[i+1]]
print(d[0])
| class Dice:
def __init__(self):
self.top = 1
self.front = 2
self.left = 4
@property
def bottom(self):
return 7 - self.top
@property
def back(self):
return 7 - self.front
@property
def right(self):
return 7 - self.left
def move(self, direction):
if direction == 'N':
bottom = self.bottom
self.top = self.front
self.front = bottom
elif direction == 'W':
right = self.right
self.left = self.top
self.top = right
elif direction == 'E':
bottom = self.bottom
self.top = self.left
self.left = bottom
elif direction == 'S':
back = self.back
self.front = self.top
self.top = back
def __repr__(self):
print(self.__dict__)
dice = Dice()
numbers = input().split()
for cmd in input():
dice.move(cmd)
print(numbers[dice.top - 1]) | 1 | 225,360,081,660 | null | 33 | 33 |
a, b, c, d = map(int, input().split())
x = [a, b]
y = [c, d]
ans = -1e30
for i in x:
for j in y:
ans = max(ans, i*j)
print(ans) | a,b,c,d = map(int,input().split())
A = [a,b]
B = [c,d]
INF = float("INF")
M = -INF
for i in A:
for j in B:
M = max(i*j,M)
print(M) | 1 | 3,067,622,534,690 | null | 77 | 77 |
#!/usr/bin/env python3
import numpy as np
# def input():
# return sys.stdin.readline().rstrip()
def main():
n, k = map(int, input().split())
warps = list(map(int, input().split()))
warps = [0] + warps
# warps = np.array(warps, dtype=int)
# order_num = np.zeros(len(warps) + 1, dtype=int)
order_num = [0 for i in range(len(warps))]
path_history = []
node = 1
while order_num[node] == 0:
path_history.append(node)
order_num[node] = len(path_history)
node = warps[node]
# print(order_num)
# print(path_history)
begin = order_num[node]
# print(tail)
if k <= begin:
print(path_history[k])
else:
# path_history = path_history[tail:]
# print(path_history)
leng = len(path_history) - order_num[node] + 1
# print(leng)
index = (k - (begin - 1)) % leng
# print(index)
print(path_history[begin - 1 + index])
main()
| n=int(input())
s=input()
ans=0
for i in range(1000):
i='0'*(3-len(str(i)))+str(i)
if i[0] in s:
if i[1] in s[s.index(i[0])+1:]:
if i[2]in s[s.index(i[0])+s[s.index(i[0])+1:].index(i[1])+2:]:
ans+=1
print(ans) | 0 | null | 75,770,312,474,660 | 150 | 267 |
a,b,c= list(map(int,input().split()))
n = int(input())
ans = "No"
for i in range(n):
if b <= a:
b = 2*b
elif c <= b:
c = 2*c
if a<b<c:
ans = "Yes"
print(ans) | def judge(k, N, A):
p = N - 1
t = 0
for i in A:
while p >= 0 and A[p] + i < k:
p -= 1
t += (p + 1)
return t
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
t = A[0] * 2
b = 0
X = None
while t - b > 1:
m = (t + b)//2
i = judge(m, N, A)
if i == M:
X = m
break
if i > M:
ip = judge(m + 1, N, A)
if ip == M:
X = m + 1
break
if ip < M:
X = m
break
b = m + 1
if i < M:
im = judge(m - 1, N, A)
if im >= M:
X = m - 1
break
t = m - 1
if X is None:
X = b
r = 0
p = N - 1
k = sum(A)
for i in A:
while p >= 0 and A[p] + i < X :
k -= A[p]
p -= 1
r += i * (p + 1) + k
return r - (judge(X, N, A) - M) * X
print(main())
| 0 | null | 57,307,465,400,150 | 101 | 252 |
import itertools
n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
N = [i for i in range(1,n+1)]
N_dict = {v:(i+1) for i,v in enumerate(itertools.permutations(N, n))}
#print(N_dict)
print(abs(N_dict[P] - N_dict[Q])) | #!/usr/bin/env python3
import sys
import itertools
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
l = [i + 1 for i in range(N)]
p = itertools.permutations(l, N)
q = itertools.permutations(l, N)
c = 1
d = 1
a = 0
b = 0
for i in p:
x = 0
for j in range(N):
if i[j] == P[j]:
x += 1
else:
break
if x == N:
a = c
break
c += 1
for i in q:
x = 0
for j in range(N):
if i[j] == Q[j]:
x += 1
else:
break
if x == N:
b = d
break
d += 1
ans = abs(a - b)
print(ans)
if __name__ == '__main__':
main()
| 1 | 100,900,118,449,720 | null | 246 | 246 |
N,K = map(int,input().split())
P = list(map(int,input().split()))
a = 0
for i in range(K):
a += min(P)
del P[P.index(min(P))]
print(a) | a, b = map(int, input().split())
c = list(map(int, input().split()))
d = sorted(c)
result = 0
for i in range(b):
result += d[i]
print(result)
| 1 | 11,616,769,047,742 | null | 120 | 120 |
a, b, c = [int(x) for x in input().split()]
k = int(input())
while b <= a:
b *= 2
k -= 1
while c <= b:
c *= 2
k -= 1
print("Yes" if k >= 0 else "No") | N, K = map(int, input().split())
A = tuple(int(x) - 1 for x in input().split())
done = {0}
rt = [0]
loop_point = 0
while True:
p = rt[-1]
np = A[p]
if np in done:
loop_point = np
break
done.add(np)
rt.append(np)
if K < len(rt):
ans = rt[K] + 1
else:
K -= len(rt)
rt = rt[rt.index(loop_point):]
ans = rt[K%len(rt)] + 1
print(ans) | 0 | null | 14,886,848,044,070 | 101 | 150 |
n = int(input())
a = list(map(int, input().split()))
q = int(input())
mp = {}
for i in a:
mp[i] = mp.get(i, 0) + 1
total = sum(list(map(lambda item: item[0]*item[1], mp.items())))
for i in range(q):
b, c = map(int, input().split())
total -= b * mp.get(b, 0)
total += c * mp.get(b, 0)
mp[c] = mp.get(c, 0) + mp.get(b, 0)
mp[b] = 0
print(total) | N = int(input())
A = list(map(int,input().split()))
a = {}
for i in A:
if i in a:
a[i] += 1
else:
a[i] = 1
Q = int(input())
ans = sum(A)
for i in range(Q):
B,C = map(int,input().split())
if B in a:
ans += (C-B) * a[B]
if C in a:
a[C] += a[B]
else:
a[C] = a[B]
a[B] = 0
print(ans) | 1 | 12,209,305,339,488 | null | 122 | 122 |
def main():
N = int(input())
def check():
for i in range(1, 10):
for j in range(1, 10):
if i * j == N:
return True
return False
cond = check()
print('Yes' if cond else 'No')
if __name__ == '__main__':
main()
| N = int(input())
answer = 'No'
for i in range(1, 10):
if N % i == 0:
sho = N // i
if sho < 10:
answer = 'Yes'
break
print(answer) | 1 | 159,792,047,573,420 | null | 287 | 287 |
import sys
n = int(input())
for i in range(n):
a = sorted(list(map(int, sys.stdin.readline().split())))
print('YES' if a[0] ** 2 + a[1] ** 2 == a[2] ** 2 else 'NO') | import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
m = (l + r) // 2
res = n * n - a.searchsorted(m - a).sum()
if res >= k:
l = m
else:
r = m
b = np.array([0] * (n + 1))
for i in range(1, n + 1):
b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
t = n - a.searchsorted(l - x)
ans += b[t] + x * t
cnt += t
print(ans - (cnt - k) * l)
| 0 | null | 54,117,509,434,940 | 4 | 252 |
def solve():
N, K = map(int, input().split())
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))
As.sort()
Fs.sort(reverse=True)
def isOK(score):
d = 0
for A, F in zip(As, Fs):
if A*F > score:
d += -(-(A*F-score) // F)
return d <= K
ng, ok = -1, 10**12
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
solve()
| n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a=sorted(a)
f=sorted(f,reverse=True)
def is_lessthanK(X):
ans=0
for A,F in zip(a,f):
if A*F>X:
ans+=A-X//F
if ans > k:
return False
return True
ng=-1
ok=a[-1]*f[0]
while ok-ng>1:
mid=(ok+ng)//2
if is_lessthanK(mid):
ok=mid
else:
ng=mid
print(ok)
| 1 | 164,915,905,793,070 | null | 290 | 290 |
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))
count = 0
L, R = "", ""
for i in range(Q):
if Query[i][0] == "1": count += 1
else:
if Query[i][1] == "1":
if count % 2 == 0: L = Query[i][2] + L
else: R += Query[i][2]
else:
if count % 2 == 0: R += Query[i][2]
else: L = Query[i][2] + L
if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1]) | import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7
def lcm(x,y):
return x*y//gcd(x,y)
def mint():
return map(int,input().split())
def lint():
return list(map(int,input().split()))
def ilint():
return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
def lprint(l, sep='\n'):
for x in l:
print(x, end=sep)
def ston(c, c0='a'):
return ord(c)-ord(c0)
def ntos(x, c0='a'):
return chr(x+ord(c0))
class counter(dict):
def __init__(self, *args):
super().__init__(args)
def add(self,x):
self.setdefault(x,0)
self[x] += 1
S = input()
L = deque()
for i in range(len(S)):
L.append(S[i])
Q = int(input())
rev = False
for _ in range(Q):
q = input()
if q[0]=='1':
rev = not rev
else:
_,f,c = q.split()
if rev==(f=='1'):
L.append(c)
else:
L.appendleft(c)
L = list(L)
if rev:
L = L[::-1]
print(''.join(L)) | 1 | 57,265,918,525,850 | null | 204 | 204 |
alpha = input()
if(alpha.isupper()):
print("A")
else:
print("a") | n = int(input())
playList = []
sumTerm = 0
for i in range(n) :
song = input().split()
song[1] = int(song[1])
playList.append(song)
sumTerm += song[1]
x = input()
tmpSumTerm = 0
for i in range(n) :
tmpSumTerm += playList[i][1]
if playList[i][0] == x :
print(sumTerm - tmpSumTerm)
break
| 0 | null | 54,400,078,496,738 | 119 | 243 |
N = int(input())
nums = map(int, input().split(" "))
for n in nums:
if n % 2 != 0:
continue
if n % 3 == 0 or n % 5 == 0:
continue
else:
print("DENIED")
exit(0)
print("APPROVED") | N,A,B=map(int,input().split())
if (B-A)%2==0:
ans =(B-A)//2
else:
if A-1 > N-B:
ans = N-B+1
A+=ans
ans+=(N-A)//2
else:
ans =A
B-=ans
ans+=(B-1)//2
print(ans)
| 0 | null | 89,326,192,399,232 | 217 | 253 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
w = sum(A)
ans = N - w
if ans >= 0:
print(ans)
else:
print(-1) | # coding: utf-8
stack = []
f = input().split()
for s in f:
if s in ('+', '-', '*'):
stack.append(str(eval("{1}{2}{0}".format(stack.pop(), stack.pop(), s))))
else:
stack.append(s)
print(*stack) | 0 | null | 15,912,957,024,860 | 168 | 18 |
n,m = map(int,input().split())
od_od = n*(n-1)/2
ev_ev = m*(m-1)/2
print(int(od_od+ev_ev))
| def main() -> None:
t = input()
print(t.replace('?','D'))
return
if __name__ == '__main__':
main()
| 0 | null | 31,950,643,891,320 | 189 | 140 |
data = [
[[0 for k in range(10)] for j in range(3)] for i in range(4)
]
count = int(input())
for x in range(count):
(b,f,r,v) = [int(i) for i in input().split()]
data[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
print(' ',end='')
for r in range(10):
if r == 9:
print(data[b][f][r], end='')
else:
print(data[b][f][r], '', end='')
print()
if b == 3:
break
for x in range(20):
print('#',end='')
print() | n = int(input())
person = [[0 for _ in range(10)] for _ in range(12)]
for _ in range(n):
b, f, r, v = [int(m) for m in input().split()]
person[3*(b-1)+f-1][r-1] += v
for index, p in enumerate(person):
print(" "+" ".join([str(m) for m in p]))
if (index+1)%3 == 0 and index < len(person)-1:
print("####################") | 1 | 1,100,956,064,248 | null | 55 | 55 |
n = (int)(input())
base = (int)(n**(1/2))
a=0
b=0
for i in range(base, 0, -1):
if n % i == 0:
a = i
b = n // i
break
#print(a,b)
print(a + b - 2) | from math import sqrt
from math import floor
n = int(input())
ans = 10 ** 12
m = floor(sqrt(n))
for i in range(1,m+1):
if n % i == 0:
j = n // i
ans = min(ans,i+j-2)
print(ans) | 1 | 161,501,656,936,742 | null | 288 | 288 |
from collections import defaultdict
def main():
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
s = str(i)
a = s[0]
b = s[-1]
d[a, b] += 1
ans = 0
d_items = list(d.items())
for (a, b), v in d_items:
ans += v * d[b,a]
print(ans)
if __name__ == '__main__':
main() | import collections
n = int(raw_input())
def g( a, b , n):
count = 0
## CASE 1
if a == b and a <=n :
count +=1
## CASE 2
if a *10 + b <= n:
count +=1
if len(str(n)) <=2:
return count
## CASE 3
s = str(n)
if len(s) - 3 >= 1:
count += 10 ** (len(s) - 3)
## CASE 4
s = str(n)
if a == int(s[0]):
m = s[1:-1]
if m != '':
#0,m-1
count += int(m)
if b <= int(s[-1]):
count +=1
elif a < int(s[0]):
count += 10 ** (len(s) - 2)
return count
h = collections.Counter()
for k in range(1, n+1):
ks = str(k)
a,b = int(ks[0]), int(ks[-1])
h[(a,b)] +=1
s= 0
for a in range(1,10):
for b in range(1,10):
s += h[(a,b)] * h[(b,a)]
print s
| 1 | 86,568,713,238,620 | null | 234 | 234 |
from collections import deque
n,q = map(int,input().split())
Q = deque()
for i in range(n):
a = input().split()
Q.append([a[0],int(a[1])])
s = 0
while Q:
qt = Q.popleft()
if qt[1] > q:
Q.append([qt[0],qt[1]-q])
s += q
else:
s += qt[1]
print(qt[0],s) | import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A_odd = A[::2]
print(np.sum(A_odd % 2)) | 0 | null | 3,901,997,400,828 | 19 | 105 |
N = int(input())
ST = []
cnt = 0
for _ in range(N):
s, t = input().split()
ST.append([s, t])
cnt += int(t)
X = input()
for i in range(N):
s, t = ST[i]
cnt -= int(t)
if s == X:
break
print(cnt)
| N = int(input())
music = []
time = []
for i in range(N):
m,t = input().split()
music.append(m)
time.append(int(t))
S = input()
ans = 0
ans += sum(time[music.index(S)+1:])
print(ans) | 1 | 97,035,027,748,110 | null | 243 | 243 |
K,N=map(int, input().split())
A=list(map(int, input().split()))
B=[0]*N
for i in range(N-1):
B[i]=A[i+1]-A[i]
B[-1]=A[0]+K-A[-1]
B=sorted(B)
ans = sum(B[0:-1])
print(ans) | K, N = map(int, input().split())
A = list(map(int, input().split()))
ans = K
for i in range(N):
start = A[i]
end = K+A[i-1] if A[i-1] < A[i] else A[i-1]
path = end-start
ans = min(path, ans)
print(ans) | 1 | 43,344,338,025,462 | null | 186 | 186 |
N = int(input())
A = {int(x): key for key, x in enumerate(input().split(), 1)}
sort_a = sorted(A.items(), key=lambda x: x[0])
print(' '.join([str(key) for x, key in sort_a]))
| def main():
n, m = (int(i) for i in input().split())
graph = { i: [] for i in range(1, n+1) }
for i in range(m):
src, dst = (int(i) for i in input().split())
graph[src].append(dst)
graph[dst].append(src)
def bfs():
st = [1]
pptr = { 1: 0 }
while st:
room = st.pop(0)
for dest_room in graph[room]:
if dest_room in pptr:
continue
st.append(dest_room)
pptr[dest_room] = room
return pptr
pptr = bfs()
if len(pptr) != n:
print('No')
else:
print('Yes')
for i in sorted(pptr.keys()):
if i == 1:
continue
print(pptr[i])
main()
| 0 | null | 100,334,423,053,008 | 299 | 145 |
def cin():
in_ = list(map(int,input().split()))
if len(in_) == 1: return in_[0]
else: return in_
N = cin()
A = cin()
INF = 10 ** 9 + 7
res = [0 for _ in range(65)]
for i in range(65):
c0, c1 = 0, 0
for j in range(N):
if bool(A[j] & (1 << i)): c1 += 1
else: c0 += 1
res[i] = c0 * c1
ans = 0
for i in range(65): ans = (ans + (1 << i) * res[i]) % INF
print(ans) | N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
count = 0
max = A[-1]
if max == 0:
print(0)
exit()
import math
V = [0]*(math.floor(math.log(max, 2))+1)
for i in range (0, N):
B = A[i]
vount = 0
while B > 0:
if B%2 == 0:
B = B//2
vount+=1
else:
B = (B-1)//2
V[vount]+=1
vount+=1
for i in range (0, len(V)):
count+=((V[i]*(N-V[i]))*(2**i))
print(count%(10**9+7)) | 1 | 122,923,179,525,200 | null | 263 | 263 |
def main():
a = int(input())
ans = a + a**2 + a**3
print(ans)
main() | """ Atcorder practice 20200719 """
# test programm for practice
def __main__():
""" def for calc """
num_input = int(input())
if num_input < 1 or num_input > 10:
raise ValueError
#elif num_input % 1 != 0:
#raise ValueError
else:
print(num_input + num_input**2 + num_input**3)
if __name__ == "__main__":
__main__()
| 1 | 10,253,489,151,182 | null | 115 | 115 |
mount = []
for i in range(0, 10):
n = input()
mount.append(n)
mount.sort(reverse = True)
for i in range(0, 3):
print mount[i] | heights = [int(input()) for i in range(0, 10)]
heights.sort(reverse=True)
for height in heights[:3]:
print(height) | 1 | 27,054,412 | null | 2 | 2 |
h,w,k = list(map(int, input().split()))
s = [input() for _ in range(h)]
strawberry = []
for i in s:
if '#' in i:
strawberry.append(True)
else: strawberry.append(False)
ans = [[0]*w for _ in range(h)]
num = 0
for i in range(h):
flag = 0
if strawberry[i]:
num += 1
for j in range(w):
if s[i][j]=='#':
flag += 1
if flag==2:
num += 1
flag = 1
ans[i][j] = num
tmp = strawberry.index(True)
for i in range(h):
if strawberry[i]==False:
ans[i] = ans[tmp]
else:
tmp = i
for i in ans:
print(' '.join(map(str,i)))
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
H, W, K = MAP()
s = [input() for _ in range(H)]
tmp = 1
ans = [[0]*W for _ in range(H)]
for i in range(H):
if not "#" in s[i]:
if i != 0:
ans[i] = ans[i-1]
continue
else:
continue
is_first = True
for j in range(W):
if s[i][j] == "#":
if is_first:
is_first = False
else:
tmp += 1
ans[i][j] = tmp
tmp += 1
for i in range(H-2, -1, -1):
if 0 in ans[i]:
ans[i] = ans[i+1]
for i in range(H):
print(*ans[i])
| 1 | 143,500,694,342,708 | null | 277 | 277 |
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = [int(input()) for _ in range(D)]
ans = []
val = 0
sch = [0]*26
for d in range(D):
day = d+1
t = T[d]-1
sch[t] = day
down = 0
for i in range(26):
down += C[i]*(day - sch[i])
val = val + S[d][t] - down
ans.append(val)
print(*ans, sep="\n") | D=int(input())
c=[int(x) for x in input().split()]
s=[[0]*i for i in range(D)]
t=[]
last_d=[0]*26
for i in range(D):
s[i]=[int(x) for x in input().split()]
for i in range(D):
t.append(int(input()))
v=0
for i in range(D):
a=0
for j in range(26):
if j!=t[i]-1:
n=i+1-last_d[j]
a+=c[j]*n
v=v+s[i][t[i]-1]-a
print(v)
last_d[t[i]-1]=i+1 | 1 | 9,898,155,481,410 | null | 114 | 114 |
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
import heapq as hp
s = x+y
u = []
hp.heapify(u)
for i in range(a):
hp.heappush(u,[-p[i],'r'])
for i in range(c):
hp.heappush(u,[-r[i],'m'])
v = []
hp.heapify(v)
for i in range(b):
hp.heappush(v,[-q[i],'g'])
for i in range(c):
hp.heappush(v,[-r[i],'m'])
z = []
ans = 0
hp.heapify(z)
for i in range(a):
hp.heappush(z,[-p[i],'r'])
for i in range(b):
hp.heappush(z,[-q[i],'g'])
for i in range(c):
hp.heappush(z,[-r[i],'m'])
while s and x and y:
t = hp.heappop(z)
ans += -t[0]
if t[1] == 'r':
x -= 1
s -=1
elif t[1] == 'g':
y -= 1
s -= 1
else:
s -= 1
if s > 0 and x > 0:
while s:
t = hp.heappop(z)
if t[1] == 'g':
continue
else:
ans += -t[0]
s -= 1
elif s > 0 and y > 0:
while s:
t = hp.heappop(z)
if t[1] == 'r':
continue
else:
ans += -t[0]
s -= 1
print(ans) | #!/usr/bin/env python3
import sys
import collections as cl
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():
x, y, a, b, c = MI()
p = LI()
q = LI()
r = LI()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p_selected = p[:x]
q_selected = q[:y]
ans = [*p_selected, *q_selected]
ans.sort()
i = 0
while i < x + y and i < c and ans[i] < r[i]:
ans[i] = r[i]
i += 1
print(sum(ans))
main()
| 1 | 44,715,797,313,852 | null | 188 | 188 |
N, K = map(int, input().split())
L = []
R = []
for _ in range(K):
l, r = map(int, input().split())
L.append(l)
R.append(r)
dp = [0]*(N+5)
dp[1] = 1
for i in range(2, N+1):
dp[i] = dp[i-1]
for j in range(K):
if i-L[j] >= 0:
dp[i] += dp[i-L[j]]
if i-R[j]-1 >= 0:
dp[i] -= dp[i-R[j]-1]
dp[i] %= 998244353
print((dp[N]-dp[N-1])%998244353) | import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict
# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846
def read_str(): return sys.stdin.readline().strip()
def read_int(): return int(sys.stdin.readline().strip())
def read_ints(): return map(int, sys.stdin.readline().strip().split())
def read_ints2(x): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)
def Main():
n = read_int()
a = read_int_list()
ans = 1
cnt = [3] + [0] * n
for x in a:
ans = ans * cnt[x] % MOD
cnt[x] -= 1
cnt[x + 1] += 1
print(ans)
if __name__ == '__main__':
Main() | 0 | null | 66,258,483,337,148 | 74 | 268 |
N = int(input())
kk_list = []
for a in range(1, 10):
for b in range(1, 10):
kk_list.append(a * b)
if N in kk_list:
print("Yes")
else:
print("No")
| n = int(input())
a = 0
for i in range(1,10):
for j in range(1,10):
if(n==i*j):
a+=1
if(a>=1):
print("Yes")
else:
print("No") | 1 | 160,003,889,143,482 | null | 287 | 287 |
def main():
N = int(input())
num = 0
B = 1
for A in range(1, N):
for B in range(1, N):
if N - A * B >= 1:
num = num + 1
else:
break
print(num)
main()
|
def resolve():
N = int(input())
ans = 0
for i in range(1, N):
ans += (N - 1) // i
print(ans)
if __name__ == "__main__":
resolve() | 1 | 2,569,816,911,220 | null | 73 | 73 |
operand = ["+", "-", "*"]
src = [x if x in operand else int(x) for x in input().split(" ")]
stack = []
for s in src:
if isinstance(s, int):
stack.append(s)
elif s == "+":
b, a = stack.pop(), stack.pop()
stack.append(a+b)
elif s == "-":
b, a = stack.pop(), stack.pop()
stack.append(a-b)
elif s == "*":
b, a = stack.pop(), stack.pop()
stack.append(a*b)
print(stack[0]) | S = []
A = raw_input().split()
for i in range(len(A)):
if A[i] == '+':
S.append(int(S.pop()) + int(S.pop()))
elif A[i] == '-':
S.append(-int(S.pop()) + int(S.pop()))
elif A[i] == '*':
S.append(int(S.pop()) * int(S.pop()))
else:
S.append(A[i])
print S[0] | 1 | 37,451,801,762 | null | 18 | 18 |
# シェルソート
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_D&lang=jp
# 挿入ソートを応用してn個の整数を含む数列Aを昇順に整列するプログラム
def show(array):
for i in range(len(array)):
if (i+1) >= len(array):
print(array[i])
else:
print(array[i], end=' ')
def insertion_sort(c, g):
n = len(c)
count = 0
for i in range(g, n):
v = c[i]
j = i - g
while j >= 0 and c[j] > v:
c[j+g] = c[j]
j = j - g
count += 1
c[j+g] = v
return c, count
def shell_sort(c, G):
counts = 0
for g in G:
co, count = insertion_sort(c, g)
counts += count
return co, counts
def main():
n = int(input())
c = [int(input()) for _ in range(n)]
# For making G
n = len(c)
g = []
for m in range(1, 100):
t = (3 ** m - 1) // 2
if t > n:
break
g.append(t)
g = g[::-1]
result, count = shell_sort(c, g)
print(m-1)
show(g)
print(count)
for num in result:
print(num)
main()
| import copy as cp
n = int(input())
A = list()
for i in range(n):
A.append(int(input()))
count = 0
#print(A)
def insertionsort(A,n,g):
global count
for i in range(g,n):
v = A[i]
j = i-g
while (j >= 0 and A[j] > v):
A[j+g] = A[j]
A[j] = v
j = j - g
v = A[j+g]
count += 1
#decision of m and g
G = list()
G.append(int(1))
i = 0
while (G[i] <= n):
G.append(3*G[i] + 1)
i += 1
del G[-1]
G.reverse()
m = len(G)
#print(G,m)
#shellsort
for i in range(m):
insertionsort(A,n,G[i])
#output
print(m)
for k in range(m-1):
print(str(G[k])+" ",end = "")
print(str(G[m-1]))
print(count)
for k in range(n):
print(str(A[k]))
| 1 | 28,666,615,922 | null | 17 | 17 |
N, M = list(map(int,input().split()))
e = True
c = [-1 for i in range(N)]
for i in range(M):
si, ci = list(map(int,input().split()))
if c[si-1]>-1 and c[si-1]!=ci:
e = False
c[si-1] = ci
if e and (N==1 or c[0]!=0):
print(max(0 if N==1 else 1, c[0]),end="")
for i in range(1,N):
print(max(0,c[i]),end="")
print()
else:
print(-1) | #ABC167
A,B,C,K=map(int,input().split())
#----------以上入力----------
if A > K:
print(K)
elif A+B >= K:
print(A)
else:
print(A-(K-A-B)) | 0 | null | 41,038,857,645,954 | 208 | 148 |
import sys
def gcd(m, n):
r = m % n
if r == 0:
return n
else:
return gcd(n, r)
lines = sys.stdin.readlines()
for line in lines:
a, b = map(int, line.split())
m = max(a, b)
n = min(a, b)
print(gcd(m, n), m * n // gcd(m, n)) | v = 0
i = 0
a = []
while v == 0:
x = input()
if 0 == int(x):
v = 1
else:
a.append(int(x))
i = int(i) + 1
for j in range(int(i)):
print('Case %d: %d' % (int(j)+1,a[int(j)] ))
| 0 | null | 249,055,343,780 | 5 | 42 |
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
if n: return [0 for _ in range(n)]
else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
if n: return ["" for _ in range(n)]
else: return sinput().split()
def adj(n): return [[] for _ in range(n)]
#整数問題セット
def gcd(numbers): return func.reduce(frac.gcd, numbers)
def lcm(numbers): return func.reduce(LCM, numbers)
def inv(a): return pow(a, MOD-2, MOD) #逆元
def comb(n,r):
ans = 1
for i in range(r): ans *= n-i; ans *= inv(r-i); ans %= MOD
return ans
n,a,b = imap()
ans = pow(2,n,MOD) - comb(n,a) - comb(n,b) - 1
print(ans%MOD)
| k = int(input())
s = str(input())
if len(s) <= k:
print(s)
else:
ans = s[0:k] + '...'
print(ans) | 0 | null | 42,874,114,018,720 | 214 | 143 |
# coding: utf-8
alphabet = 'abcdefghijklmnopqrstuvwxyz'
S = ''
while True:
try:
n = input()
S += n
except EOFError:
break
ans_dict = {}
for char in alphabet:
ans_dict[char] = S.count(char)
ans_dict[char] += S.count(char.upper())
for k, v in sorted(ans_dict.items(), key=lambda x: x[0]):
print('{} : {}'.format(k, v)) | #!/usr/bin/env python
#coding: UTF-8
import sys
a = sys.stdin.readlines()
b = []
for i in a:
for j in i:
b.append(j.lower())
for i in range(97, 97+26):
print chr(i)+" : "+str(b.count(chr(i))) | 1 | 1,689,161,258,470 | null | 63 | 63 |
x, y = map(int, input().split())
ans = 0
def calc(z):
ans = 0
if z == 1:
ans += 300000
elif z == 2:
ans += 200000
elif z == 3:
ans += 100000
return ans
if x == 1 and y == 1:
ans += 400000
print(ans+calc(x)+calc(y)) | #ALDS1_1_D
N = int(input())
min,dif = 10000000000, -10000000000
for i in range(N):
a = int(input())
if (a - min) > dif:
dif = a - min
if a < min:
min = a
print(dif)
| 0 | null | 70,522,738,700,908 | 275 | 13 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
A=LI()
from collections import defaultdict
dd = defaultdict(int)
for i in range(N):
dd[A[i]]+=1
ans=0
for k,v in dd.items():
ans+=(v*(v-1))//2
for i in range(N):
a=A[i]
v=dd[A[i]]
temp=ans
temp-=(v*(v-1))//2
temp+=((v-1)*(v-2))//2
print(temp)
main()
| def gcd(a, b):
if b == 0: return a
else: return gcd(b, a % b)
def lcm(a, b):
return a * b / gcd(a, b)
while True:
try:
a, b = map(int, input().split())
print(int(gcd(a, b)), int(lcm(a, b)))
except EOFError:
break | 0 | null | 23,786,381,907,318 | 192 | 5 |
H,N = map(int,input().split())
A = list(map(int,input().split()))
for i in range(N):
H -= A[i]
if H > 0:
print('No')
else:
print('Yes') | h,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
res = "No"
for i in range(n):
h -= a[i]
if h <= 0:
res = "Yes"
print(res) | 1 | 77,919,888,240,338 | null | 226 | 226 |
N=int(input())
print("Yes" if N%9==0 else "No") | n = [int(x) for x in input()]
s = sum(n)
if s % 9 == 0:
print('Yes')
else:
print('No') | 1 | 4,425,006,698,322 | null | 87 | 87 |
import sys
N = int(input())
S = input()
array_S = list(S)
if not ( 3 <= N <= 50 and S.isupper() ): sys.exit()
count = 0
for I in range(N-2):
if ''.join(array_S[I:I+3]) == 'ABC':
count += 1
print(count) | N=int(input())
ans=0
for i in range(1,N):
if N%i!=0:
for j in range(1,N//i+1):
ans+=1
else:
for j in range(1,N//i):
ans+=1
print(ans) | 0 | null | 50,959,250,460,068 | 245 | 73 |
S = input()
K = int(input())
def func(S):
inner = 0
S = list(S)
for i in range(len(S) - 1):
if S[i] == S[i + 1]:
S[i + 1] = '#'
inner += 1
return inner
if len(set(list(S))) == 1:
print(len(S) * K // 2)
else:
inner = func(S)
inter = func(S * 2) - func(S) * 2
print(inner * K + inter * (K - 1)) | s = list(input())
k = int(input())
if len(set(s)) == 1:
print((len(s)*k)//2)
exit()
def n_change(sss):
s = sss.copy()
x = 0
for i in range(1, len(s)):
if s[i] == s[i-1]:
s[i] = "X"
x += 1
return x
print(n_change(s) + (k-1) * (n_change(2*s) - n_change(s))) | 1 | 175,442,315,780,410 | null | 296 | 296 |
m,d=map(int,input().split())
if m in [1,3,5,7,8,10,12] and d==31:
print(1)
elif m ==2 and d==28:
print(1)
elif m in [4,6,9,11] and d==30:
print(1)
else:
print(0) | s1 = list(map(int,input().split()))
s2 = list(map(int,input().split()))
if int(s1[0])+1 == int(s2[0]):
print(1)
else:
print(0) | 1 | 125,061,183,233,940 | null | 264 | 264 |
S = input()
L = S.split()
a = L[0]
a = int(a)
b = L[1]
b = int(b)
if a < b:
print('a < b')
elif a > b:
print('a > b')
elif a == b:
print('a == b') | n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
from itertools import permutations
import math
m = math.factorial(n)
per = permutations(xy,n)
d = 0
c = 0
for j in per :
for i in range(n-1):
d += ((j[i+1][0]-j[i][0])**2 + (j[i+1][1]-j[i][1])**2) ** 0.5
print(d/m)
| 0 | null | 74,639,995,131,142 | 38 | 280 |
s = input()
target = s[:(len(s)-1)//2]
target2 = s[(len(s)+3)//2-1:]
if target == target2:
l, r = 0, len(s)-1
flag = True
while l <= r:
if s[l] == s[r]:
l += 1
r -= 1
else:
print('No')
exit(0)
print("Yes")
else:
print('No')
| def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
s=input()
n=len(s)
a=s[:n//2]
b=s[n//2 +1 : ]
if s==s[::-1] and a==a[::-1] and b==b[::-1]:
print("Yes")
else:
print("No") | 1 | 46,281,422,688,430 | null | 190 | 190 |
A,B,M=map(int,input().split())
a=[int(i)for i in input().split()]
b=[int(i)for i in input().split()]
xyc=[[int(i)for i in input().split()]for j in range(M)]
res=min(a)+min(b)
for x,y,c in xyc:
tmp=a[x-1]+b[y-1]-c
res=min(res,tmp)
print(res) | A, B, M = map(int, input().split())
a = [int(a) for a in input().split()]
b = [int(b) for b in input().split()]
X = [0] * M
Y = [0] * M
C = [0] * M
for i in range(M):
X[i], Y[i], C[i] = map(int, input().split())
all_prices = []
for x, y, c in zip(X, Y, C):
all_prices.append(a[x-1] + b[y-1] - c)
prices = [min(a) + min(b), min(all_prices)]
print(min(prices)) | 1 | 54,094,654,658,740 | null | 200 | 200 |
n = int(input())
a = ["a","b","c","d","e","f","g","h","i","j"]
def dfs(s):
m = len(s)
if m == n:
ans = ""
for i in range(n):
ans += a[int(s[i])]
print(ans)
else:
for i in range(int(max(list(s)))+2):
dfs(s+str(i))
dfs("0") | 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 = getN()
str_l = 'abcdefghij'
ans = [0]
ans_str = []
def alter(array):
s = ""
for i in array:
s += str_l[i]
return s
def dfs(array):
if len(array) == N:
ans_str.append(alter(array))
return
for i in range(max(array) + 2):
new_array = copy.deepcopy(array)
new_array.append(i)
dfs(new_array)
dfs(ans)
ans_str.sort()
for i in ans_str:
print(i) | 1 | 52,388,514,539,790 | null | 198 | 198 |
while True:
data = input().split()
m = int(data[0])
f = int(data[1])
r = int(data[2])
if m == -1 and f == -1 and r == -1:
break
elif m == -1 or f == -1:
print('F')
else:
if m + f >= 80:
print('A')
elif m + f >= 65:
print('B')
elif m + f >= 50:
print('C')
elif m + f >= 30:
if r >= 50:
print('C')
else:
print('D')
else:
print('F') | 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()
A = LI()
c = collections.Counter(A)
cnt = 0
for _ in c:
cnt += c[_] * (c[_] - 1) // 2
for i in range(N):
a = c[A[i]]
print(cnt - (a - 1))
| 0 | null | 24,631,931,569,058 | 57 | 192 |
import math
point = map(float, raw_input().split())
x1 = point[0]
y1 = point[1]
x2 = point[2]
y2 = point[3]
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
print distance | N,K,S=map(int,input().split())
a=[10**9 if S==1 else S-1]*N
for i in range(K):a[i]=S
print(' '.join(map(str,a))) | 0 | null | 45,674,731,355,012 | 29 | 238 |
N, K= map(int, input().strip().split())
p = list(map(int, input().strip().split()))
p=sorted(p)
q=0
for i in range(K):
q=q+p[i]
print(q)
| #B
N, K = map(int,input().split())
P = list(map(int, input().split()))
P_sort=sorted(P)
P_sum=0
for i in range(K):
P_sum+=P_sort[i]
print(P_sum) | 1 | 11,537,136,873,740 | null | 120 | 120 |
import fileinput
def main():
numbers = []
for line in fileinput.input():
numbers.append(int(line))
numbers = sorted(numbers, reverse=True)
for n in numbers[0:3]:
print n
main() | a = [int(input()) for i in range(10)]
a.sort()
for i in range(1, 4):
print(a[-i]) | 1 | 30,680,676 | null | 2 | 2 |
import math
def print_list_split_whitespace(a):
for x in a[:-1]:
print(x, end=' ')
print(a[-1])
def insertion_sort(a, n, g, cnt):
for i in range(g, n, 1):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j + g] = a[j]
j -= g
cnt += 1
a[j+g] = v
return cnt
def shell_sort(a, n):
cnt = 0
m = math.floor(math.log(2 * n + 1, 3))
print(m)
gs = [1]
for i in range(1, m, 1):
gs.append(gs[i - 1] * 3 + 1)
gs.reverse()
print_list_split_whitespace(gs)
for i in range(m):
cnt = insertion_sort(a, n, gs[i], cnt)
print(cnt)
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
shell_sort(a, n)
for x in a:
print(x)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
a = LI()
s = sum(a)
if s >= 22:
print('bust')
else:
print('win') | 0 | null | 59,507,179,315,480 | 17 | 260 |
import math
if __name__ == "__main__":
deg = int(input())
print(360//math.gcd(deg, 360)) | import sys
x = int(input())
ans = 2
while(True):
if x*ans % 360 == 0:
print(ans)
sys.exit()
ans +=1 | 1 | 13,242,750,052,192 | null | 125 | 125 |
import math
A, B = map(int, input().split())
r = -1
for i in range(1, 1111):
if A == math.floor(i*0.08) and B == math.floor(i*0.10):
r = i
break
print(r)
| # coding: utf-8
def main():
A, B = map(int, input().split())
ans = -1
for i in range(10001):
if i * 8 // 100 == A and i // 10 == B:
ans = i
break
print(ans)
if __name__ == "__main__":
main()
| 1 | 56,508,745,028,970 | null | 203 | 203 |
s = input()
k = int(input())
if len(set(s)) == 1:
print(len(s) * k // 2)
exit()
s += "🐧"
wow = 0
yeah = []
for i in range(len(s)-1):
if s[i] != s[i+1]:
wow += 1
yeah.append((s[i], wow))
wow = 0
else:
wow += 1
ans = sum(c // 2 for _, c in yeah) * k
if s[0] == s[-2]:
katakuna = yeah[0][1]
ijippari = yeah[-1][1]
te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2
ans -= te * (k - 1)
print(ans) | s = input()
k = int(input())
di = []
cnt = 1
ans = 0
if len(s) > 1:
for i in range(1,len(s)):
if s[i] == s[i-1]:
cnt += 1
else:
di.append(cnt)
cnt = 1
di.append(cnt)
if di[0] != len(s):
for j in di:
ans += j//2
ans *= k
if s[0] == s[-1] and di[-1] % 2 == 1 and di[0] % 2 == 1:
ans += k - 1
else:
ans = k*len(s)//2
else:
ans = k//2
print(ans) | 1 | 175,015,387,775,926 | null | 296 | 296 |
x = int(input())
ans = 0
a = int(x / 500)
ans = ans + a * 1000
x = x % 500
b = int(x / 5)
ans = ans + b * 5
print(ans) | # row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
def make_divisors(n: int):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors, upper_divisors[::-1]
def resolve():
import sys
input = sys.stdin.readline
n = int(input().rstrip())
lower_divisors, _ = make_divisors(n)
print(min(lower_divisor + (n // lower_divisor) - 2 for lower_divisor in lower_divisors))
if __name__ == "__main__":
resolve()
| 0 | null | 102,066,158,738,432 | 185 | 288 |
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
s = 0
B = [0]
C = {0:[0]}
for i, a in enumerate(A):
s = (s+a)%K
n = (s-i-1)%K
B.append(n)
if n not in C: C[n] = []
C[n].append(i+1)
ans = 0
for k, v in C.items():
if len(v)<=1: continue
ans_k = 0
ir=0
for il in range(0,len(v)-1):
l = v[il]
while(ir<len(v) and v[ir]-l<=K-1): ir+=1
ans_k+=(ir-1)-il
ans+=ans_k
print(ans) | A, B, C, D = map(int, input().split())
is_turn_of_takahashi = True
while A > 0 and C > 0:
if is_turn_of_takahashi:
C -= B
else:
A -= D
is_turn_of_takahashi = not is_turn_of_takahashi
print("Yes" if A > 0 else "No")
| 0 | null | 84,025,406,215,960 | 273 | 164 |
def main():
N,K=map(int,input().split())
M={}
mod=pow(10,9)+7
res=0
for i in range(K,0,-1):
syou=K//i
mc=pow(syou,N,mod)
if syou>=2:
for sub_m in range(2,syou+1):
mc-=M[sub_m*i]
res+=(i*mc)%mod
M[i]=mc
print(res%mod)
if __name__=="__main__":
main() | n,k=map(int,input().split())
mod=10**9+7
count=[0]*(k+1)
def getnum(m):
ret = pow(k//m,n,mod)
mul=2
while m*mul<=k:
ret-=count[m*mul]
mul+=1
return ret%mod
ans=0
for i in range(1,k+1)[::-1]:
g=getnum(i)
count[i]=g
ans+=g*i
ans%=mod
print(ans) | 1 | 36,592,885,489,578 | null | 176 | 176 |
H, N = map(int, input().split())
AB = []
for _ in range(N):
A, B = map(int, input().split())
AB.append([A, B])
AB = sorted(AB, key=lambda x:x[0], reverse=True)
INF = float("inf")
dp = [INF for _ in range(H+1)]
dp[0] = 0
# DP
for i in range(1, H+1):
for a, b in AB:
if a >= i:
dp[i] = min(dp[i], b)
continue
else:
dp[i] = min(dp[i], dp[i-a]+b)
print(dp[-1]) | import math
H, N = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
dp = [0]*(H+1)
dp[0] = 0
for i in range(1,H+1):
dp_min = math.inf
for j in range(N):
dp_min = min(dp_min, dp[max(0,i-A[j])] + B[j])
dp[i] = dp_min
print(dp[H]) | 1 | 81,153,026,866,702 | null | 229 | 229 |
h, n = map(int, input().split())
A = list(map(int, input().split()))
for a in A:
h -= a
print("Yes" if h <= 0 else "No") | from collections import defaultdict
MOD = 10**9+7
from math import gcd
n = int(input())
ans = 1
C = defaultdict(int)
z = 0
r = 0
for i in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
r += 1
elif b == 0:
z += 1
elif a == 0:
C[0] += 1
else:
g = gcd(abs(a), abs(b))
a //= g
b //= g
if a < 0:
a, b = -a, -b
C[(a, b)] += 1
D = tuple(C.items())
used = {0}
for c, v in D:
if c in used:
continue
a, b = c
if b > 0:
d, e = b, -a
else:
d, e = -b, a
ans *= pow(2, v, MOD)+pow(2, C[(d, e)], MOD)-1
ans %= MOD
used.add((d, e))
ans *= pow(2, C[0], MOD)+pow(2, z, MOD)-1
ans += r
ans -= 1
ans %= MOD
print(ans) | 0 | null | 49,653,404,984,160 | 226 | 146 |
print('a' if input() >= 'a' else 'A')
| a=input()
if a in "abcdefgeijklmnopqrstuvwxyz":
print('a')
else:
print('A') | 1 | 11,367,239,734,940 | null | 119 | 119 |
x,y=map(int,input().split())
ans=0
if x==1:
ans=ans+300000
if y==1:
ans=ans+300000
if x==2:
ans=ans+200000
if y==2:
ans=ans+200000
if x==3:
ans=ans+100000
if y==3:
ans=ans+100000
if x==1 and y==1:
ans=ans+400000
print(ans) | S = input()
#print(S.count("R"))
con = S.count("R")
if con == 1:
print(1)
elif con == 3:
print(3)
elif con == 2:
for j in range(3):
if S[j] =="R":
if S[j+1] =="R":
print(2)
break
else:
print(1)
break
elif con == 0:
print(0)
| 0 | null | 72,629,546,882,088 | 275 | 90 |
def num():
from sys import stdin
h, n = map(int, input().split())
magic = [list(map(int, stdin.readline().split())) for _ in range(n)]
INF = float('inf')
ans = [INF]*(h+1)
ans[-1] = 0
for i in range(h, 0, -1):
if ans[i] != INF:
for j, k in magic:
if i-j < 0:
num = ans[i]+k
if ans[0] > num:
ans[0] = num
else:
num = ans[i]+k
if ans[i-j] > num:
ans[i-j] = num
return ans[0]
print(num())
| (h,n),*t=[[*map(int,t.split())]for t in open(0)]
d=[0]*9**8
for i in range(h):d[i+1]=min(b+d[i-a+1]for a,b in t)
print(d[h]) | 1 | 80,862,623,556,788 | null | 229 | 229 |
a, b, c = (int(i) for i in ((input()).split()))
if a < b < c:
print('Yes')
else:
print('No') | n = raw_input()
m =n.split(" ")
a = int(m[0])
b = int(m[1])
c = int(m[2])
if a < b < c :print "Yes"
else :print "No" | 1 | 399,173,777,160 | null | 39 | 39 |
N,X,Y=map(int,input().split())
#i<X<Y<j
#このときはX->を通るほうが良い
#X<=i<j<=Y
#このときはループのどちらかを通れば良い
#X<=i<=Y<j
#このときはiとYの最短距離+Yとjの最短距離
#i<X<=j<=Y
#同上
#i<j<X
#パスは1通りしか無い
def dist(i,j):
if i>j:
return dist(j,i)
if i==j:
return 0
if i<X:
if j<X:
return j-i
if X<=j and j<=Y:
return min(j-i,(X-i)+1+(Y-j))
if Y<j:
return (X-i)+1+(j-Y)
if X<=i and i<=Y:
if j<=Y:
return min(j-i,(i-X)+1+(Y-j))
if Y<j:
return min((i-X)+1+(j-Y),j-i)
if Y<i:
return (j-i)
ans=[0 for i in range(N)]
for i in range(1,N+1):
for j in range(i+1,N+1):
ans[dist(i,j)]+=1
for k in range(1,N):
print(ans[k]) | import sys
for i in sys.stdin.readlines()[:-1]:
h,w = map(int,i.strip().split())
for i in range(h):
for j in range(w):
if (i+j) % 2 == 0:
print('#',end='')
else:
print('.',end='')
print()
print() | 0 | null | 22,356,093,709,194 | 187 | 51 |
N=[]
while True:
n=raw_input()
if n=='0':
break
N.append(n)
for i in range(len(N)):
print('%d'%sum(map(int,N[i]))) | n = int(input())
a = list(map(int,input().split()))
j = 1
ans = 0
for i in a:
if i == j:
j += 1
else:
ans += 1
if j == 1:
print('-1')
else:
print(ans)
| 0 | null | 58,222,206,102,320 | 62 | 257 |
x1, y1, x2, y2 = map(float, input().split())
print(abs(complex(x1-x2, y1-y2)))
| r, c = map(int, input().split())
sumOfCols = [0] * c
for i in range(r):
cols = list(map(int, input().split()))
s = sum(cols)
sumOfCols = [p + q for p,q in zip(sumOfCols, cols)]
print(' '.join(map(str, cols)), end=' ')
print(s)
s = sum(sumOfCols)
print(' '.join(map(str, sumOfCols)), end=' ')
print(s) | 0 | null | 769,884,250,810 | 29 | 59 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 1
mod = 10 ** 9 + 7
if 0 <= A[0]:
# All the values are positive -> Use the highest values
for i in range(N - 1, N - K - 1, -1):
ans = (ans * A[i]) % mod
elif A[-1] <= 0:
# All the values are negative -> Check if the result becomes positive or negative
if K % 2:
# The result becomes negative -> Use the highest values
for i in range(N - 1, N - K - 1, -1):
ans = (ans * A[i]) % mod
else:
# The result becomes negative -> Use the highest values
for i in range(K):
ans = (ans * A[i]) % mod
else:
# There exist both positive and negative values
# If K is an odd number, make K even by extracting A[-1] in advance
l, r = 0, N - 1
if K % 2:
ans = A[-1]
r -= 1
K -= 1
# Compare A[l] * A[l + 1] and A[r -1] * A[r] -> use the bigger one
# Why: a single negative value makes the result negative
while K:
if A[l] * A[l + 1] < A[r] * A[r - 1]:
ans = (ans * A[r] * A[r - 1]) % mod
r -= 2
else:
ans = (ans * A[l] * A[l + 1]) % mod
l += 2
K -= 2
print(ans)
| def solve():
can_positive = False
if len(P) > 0:
if k < n: can_positive = True
else: can_positive = len(M)%2 == 0
else: can_positive = k%2 == 0
if not can_positive: return sorted(P+M, key=lambda x:abs(x))[:k]
P.sort()
M.sort(reverse=True)
a = [P.pop()] if k%2 else [1]
while len(P) >= 2: a.append(P.pop() * P.pop())
while len(M) >= 2: a.append(M.pop() * M.pop())
return a[:1] + sorted(a[1:], reverse=True)[:(k-k%2)//2]
n, k = map(int, input().split())
P, M = [], []
for a in map(int, input().split()):
if a < 0: M.append(a)
else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)
| 1 | 9,508,705,370,790 | null | 112 | 112 |
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
n,a,b = LMIIS()
def cmb(n,r):
if r == 0:
return 0
res = 1
r = min(r,n-r)
for i in range(n-r+1,n+1):
res *= i
res %= MOD
for i in range(1,r+1):
res *= pow(i,(MOD-2),MOD)
res %= MOD
return res
print((pow(2,n,MOD)-cmb(n,a)-cmb(n,b)-1)%MOD)
if __name__ == '__main__':
main() | mod = 10**9+7
n,a,b = map(int,input().split())
base = pow(2,n,mod)-1
def comb(n,k):
comb = 1
for i in range(n-k+1,n+1):
comb *= i
comb %= mod
for i in range(1, k+1):
comb *= pow(i,mod-2,mod)
comb %= mod
return comb
print((base-comb(n,a)-comb(n,b))%mod) | 1 | 66,409,417,357,000 | null | 214 | 214 |
from string import ascii_lowercase as LOW
from string import ascii_uppercase as UP
a = {l:u for l,u in zip(list(LOW),list(UP))}
b = {u:l for u,l in zip(list(UP),list(LOW))}
a.update(b)
data = input()
data = [a[s] if s in a else s for s in data]
data = ''.join(data)
print(data) | import numpy as np
k = int(input())
x = np.arange(1,k+1)
# np.ufunc.outer: c_ij = f(a_i, b_j)
a = np.gcd.outer(np.gcd.outer(x,x),x)
print(a.sum()) | 0 | null | 18,605,013,723,560 | 61 | 174 |
s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
s = s.replace(' ','')
a = list(s.split(','))
n = int(input())
print(a[n-1]) | number_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
out = number_list[k-1]
print(out) | 1 | 50,220,201,981,828 | null | 195 | 195 |
N, A, B = map(int, input().split())
dif = abs(A - B)
ans = 0
if dif % 2 == 0:
ans = dif // 2
else:
ans = min(A - 1, N - B) + 1 + dif // 2
print(ans) | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n,a,b=map(int, input().split())
if (abs(a-b))%2==0:
print((abs(a-b))//2)
else:
ue=max(a,b)-1
sita=n-min(a,b)
hokasita=((n-max(a,b))*2+1+abs(b-a))//2
hokaue=(((min(a,b))-1)*2+1+abs(b-a))//2
print(min(ue,sita,hokasita,hokaue))
resolve()
| 1 | 109,514,633,928,034 | null | 253 | 253 |
from sys import stdin
r, c = [int(x) for x in stdin.readline().rstrip().split()]
table = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(r)]
for row in range(r):
table[row] += [sum(table[row])]
print(*table[row])
col_sum = [sum(x) for x in zip(*table)]
print(*col_sum)
| a,b,c=map(int,input().split())
if (b*c >= a):
print('Yes')
else:
print('No') | 0 | null | 2,430,875,643,038 | 59 | 81 |
N,K=map(int,input().split())
h=list(map(int, input().split()))
A=0
for i in h:
if i>=K:
A=A+1
print(A) | n,k = map(int, input().split())
h = list(map(int, input().split()))
nk = [h for h in h if h >= k]
print(len(nk)) | 1 | 178,353,658,224,370 | null | 298 | 298 |
import math
def div(x, y): #x>y
A = 1
for i in range(1, int(math.sqrt(x))+1):
if x % i == 0 and y % i == 0:
A = max(A, i)
j = int(x/i)
if x % j == 0 and y % j == 0:
A = max(A, j)
return A
x, y = map(int, input().split(" "))
print(div(x,y))
| num = map(int, raw_input().split())
if num[0] > num[1]:
x = num[0]
y = num[1]
else:
y = num[0]
x = num[1]
while y > 0:
z = x % y
x = y
y = z
print x | 1 | 7,584,319,072 | null | 11 | 11 |
a = int(input())
n = 3.141592
print((a + a) * n) | import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
uf_t = numba.types.UniTuple(i8[:], 2)
@njit((uf_t, i8), cache=True)
def find_root(uf, x):
root = uf[0]
while root[x] != x:
root[x] = root[root[x]]
x = root[x]
return x
@njit((uf_t, i8, i8), cache=True)
def merge(uf, x, y):
root, size = uf
x, y = find_root(uf, x), find_root(uf, y)
if x == y:
return False
if size[x] < size[y]:
x, y = y, x
size[x] += size[y]
root[y] = root[x]
return True
@njit((i8, i8, i8[:]), cache=True)
def main(N, M, AB):
ans = N - 1
root = np.arange(N + 1, dtype=np.int64)
size = np.ones_like(root)
uf = (root, size)
for i in range(0, len(AB), 2):
a, b = AB[i:i + 2]
if merge(uf, a, b):
ans -= 1
return ans
N, M = map(int, readline().split())
AB = np.array(read().split(), np.int64)
print(main(N, M, AB)) | 0 | null | 16,741,413,452,192 | 167 | 70 |
def main():
N = int(input())
A = list(map(int, input().split()))
SUM = 1
if 0 in A:
print(0)
return
for a in A:
SUM = SUM * a
if SUM > 1000000000000000000:
print(-1)
return
print(SUM)
main() | N=int(input())
A=list(map(int,input().split()))
A.sort()
sum=1
for i in range(N):
sum=sum*A[i]
if sum>10**18:
sum=-1
break
print(sum) | 1 | 16,218,197,642,482 | null | 134 | 134 |
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
# 値がiであるようなA_iの個数を格納する
val_count = [0] * (10 ** 5 + 1)
total_A = 0
for a in A:
total_A += a
val_count[a] += 1
S = []
for i in range(Q):
B, C = map(int, input().split())
B_count = val_count[B]
total_A -= B * B_count
total_A += C * B_count
S.append(total_A)
val_count[B] = 0
val_count[C] += B_count
for s in S:
print(s)
| """
import numpy as np
from collections import Counter
n = map(int,input().split())
a = list(map(int,input().split()))
Q = int(input())
a_count = dict(Counter(a))
def change_dict_key(d, old_key, new_key, default_value=None):
d[new_key] = d.pop(old_key, default_value)
#change_dict_key(a_count, 1, 5)
#print(a_count)
for q in range(Q):
num = list(map(int,input().split()))
if(num[0] not in a_count):
print(np.dot( np.array(list(a_count.keys())) , np.array(list(a_count.values()) ) ) )
continue
if(num[1] not in a_count):
change_dict_key(a_count,num[0],num[1])
else :
a_count[num[1]] += a_count[num[0]]
del a_count[num[0]]
#print(a_count.values())
print(np.dot( np.array(list(a_count.keys())) , np.array(list(a_count.values()) ) ) )
#print((sum(list_a)) )
"""
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B, C = [0]*Q, [0]*Q
for i in range(Q):
B[i], C[i] = list(map(int, input().split()))
bucket = [0]*100001
for i in A:
bucket[i] += 1
sum = sum(A)
for i in range(Q):
sum += (C[i] - B[i]) * bucket[B[i]]
bucket[C[i]] += bucket[B[i]]
bucket[B[i]] = 0
print(sum)
| 1 | 12,241,910,847,960 | null | 122 | 122 |
n = int(input())
P = [(0.0,0.0), (100.0, 0)]
import copy
import math
sin60 = math.sin(math.radians(60))
cos60 = math.cos(math.radians(60))
for _ in range(n):
next_p = []
for p1, p2 in zip(P[:-1], P[1:]):
l = (p1[0]*2/3+p2[0]*1/3, p1[1]*2/3+p2[1]*1/3)
r = (p1[0]*1/3+p2[0]*2/3, p1[1]*1/3+p2[1]*2/3)
x = cos60*(r[0]-l[0])-sin60*(r[1]-l[1])+l[0]
y = sin60*(r[0]-l[0])+cos60*(r[1]-l[1])+l[1]
next_p.append(p1)
next_p.append(l)
next_p.append((x, y))
next_p.append(r)
next_p.append(P[-1])
P = copy.copy(next_p)
for p in P:
print(p[0], p[1])
| r, c = map(int, input().split())
data = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
data[i].append(sum(data[i]))
data.append([sum(data[j][i] for j in range(r)) for i in range(c + 1)])
for i in range(r + 1):
for j in range(c + 1):
print(data[i][j], end='')
if j != c:
print(' ', end='')
print('') | 0 | null | 754,440,633,440 | 27 | 59 |
import math
x = int(input())
# -100 ~ 100 ^ 5
pow5 = {}
for i in range(-1000, 1001):
pow5[i] = int(math.pow(i, 5))
for i in range(-1000, 1001):
a = x + pow5[i]
for j in range(-1000, 1001):
if a == pow5[j]:
print(j, i)
exit()
| import math
x = int(input())
x_pow = round(math.pow(x, 1/5))
ok = 0
for a in range(-300,300):
for b in range(-300,300):
if a**5 - b**5 == x:
print(a,b)
ok = 1
exit() | 1 | 25,417,755,017,710 | null | 156 | 156 |
N = int(input())
X = list(map(int, input().split()))
ans = 100 ** 100
for p in range(1, 101):
now = 0
for x in X:
now += (p - x) ** 2
ans = min(ans, now)
print(ans)
| n = int(input())
for _ in range(n):
num = sorted(map(int, input().split()))
print("YES" if num[2]**2 == num[1]**2 + num[0]**2 else "NO") | 0 | null | 32,731,261,834,910 | 213 | 4 |
X, Y, A, B, C = map(int, input().split())
Ap = list(map(int, input().split()))
Bq = list(map(int, input().split()))
Cr = list(map(int, input().split()))
Ap.sort()
Bq.sort()
print(sum(sorted(Ap[A-X:] + Bq[B-Y:] + Cr)[C:])) | import sys
sys.setrecursionlimit(10**9)
def main():
X,Y,A,B,C = map(int,input().split())
P = sorted(list(map(int,input().split())),reverse=True)
Q = sorted(list(map(int,input().split())),reverse=True)
R = list(map(int,input().split()))
print(sum(sorted(P[:X]+Q[:Y]+R,reverse=True)[:X+Y]))
if __name__ == "__main__":
main()
| 1 | 44,787,600,994,020 | null | 188 | 188 |
from math import gcd
N = int(input())
A = list(map(int, input().split()))
prime = list(range(max(A) + 1))
for i in range(2, len(prime)):
if prime[i] != i:
continue
for j in range(i, len(prime), i):
if prime[j] != j:
continue
prime[j] = i
used = set()
pc = True
for a in A:
used_this = set()
while a != 1:
div = prime[a]
if div in used:
pc = False
break
used_this.add(div)
a //= div
used.update(used_this)
if pc:
print('pairwise coprime')
exit()
buf = A[0]
for a in A[1:]:
buf = gcd(buf, a)
if buf == 1:
print('setwise coprime')
else:
print('not coprime') | h,a = map(int,input().split())
if h % a == 0:
print(h//a)
else:
print(h//a+1)
| 0 | null | 40,794,434,299,480 | 85 | 225 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.