code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
n, m = map(int, input().split()) a = map(int, input().split()) res = n - sum(a) if res < 0: print(-1) else: print(res)
from os.path import split def main(): X, Y, Z = map(int, input().split()) print(Z, X, Y) if __name__ == '__main__': main()
0
null
35,125,991,925,920
168
178
def rollDice(dice, direction): buf = [x for x in dice] if direction == "S": buf[0] = dice[4] buf[1] = dice[0] buf[4] = dice[5] buf[5] = dice[1] elif direction == "E": buf[0] = dice[3] buf[2] = dice[0] buf[3] = dice[5] buf[5] = dice[2] elif direction == "W": buf[0] = dice[2] buf[2] = dice[5] buf[3] = dice[0] buf[5] = dice[3] elif direction == "N": buf[0] = dice[1] buf[1] = dice[5] buf[4] = dice[0] buf[5] = dice[4] for i in range(6): dice[i] = buf[i] def rollDiceSide(dice): buf = [x for x in dice] buf[1] = dice[2] buf[2] = dice[4] buf[3] = dice[1] buf[4] = dice[3] for i in range(6): dice[i] = buf[i] d = list(map(int, input().split())) n = int(input()) for i in range(n): q1, q2 = list(map(int, input().split())) wq = d.index(q1) if wq == 1: rollDice(d, "N") elif wq == 2: rollDice(d, "W") elif wq == 3: rollDice(d, "E") elif wq == 4: rollDice(d, "S") elif wq == 5: rollDice(d, "S") rollDice(d, "S") wq = d.index(q2) if wq == 2: rollDiceSide(d) elif wq == 3: rollDiceSide(d) rollDiceSide(d) rollDiceSide(d) elif wq == 4: rollDiceSide(d) rollDiceSide(d) print(d[2])
N=int(input()) a=list(map(int,input().split())) a_all=0 for i in range(N): a_all^=a[i] ans=[] for j in range(N): ans.append(a_all^a[j]) print(*ans)
0
null
6,417,291,610,432
34
123
n = int(input()) l = list(map(int,input().split())) dp = [[-float("INF")]*(3) for i in range(n+1)] dp[0][0] = 0 dp[1][-1] = 0 dp[1][1] = l[0] for i in range(1,n): dp[i+1][-1] = max(dp[i][0],dp[i-1][-1]+l[i]) dp[i+1][0] = max(dp[i][1],dp[i-1][0]+l[i]) dp[i+1][1] = dp[i-1][1]+l[i] print(max(dp[-1][0],dp[-1][-1]))
from collections import defaultdict INF = -1000000000000001 n = int(input()) l = list(map(int, input().split())) a = int(n/2) dpa = defaultdict(lambda: -INF) #dpa = [[0 for j in range(a+1)] for i in range(n+1)] dpa[(0,0)] = 0 dpa[(1,0)] = 0 dpa[(1,1)] = l[0] j = 1 for i in range(2,n+1): if i == j*2: dpa[(i,j)] = max(dpa[(i-2,j-1)]+l[i-1],dpa[(i-1,j)]) # print(i,j,dpa[(i,j)]) else: dpa[(i,j)] = max(dpa[(i-2,j-1)]+l[i-1],dpa[(i-1,j)]) # print(i,j,dpa[(i,j)]) if (i != n): j += 1 # print(i,j,dpa[(i,j)]) # print(" ",i-2,j-1,dpa[(i-2,j-1)],"") dpa[(i,j)] = dpa[(i-2,j-1)]+l[i-1] #print(dpa) print(dpa[n,a])
1
37,411,295,612,328
null
177
177
n = map(int,raw_input().split()) for i in range(0,3): for k in range(i,3): if n[i]>n[k]: temp = n[i] n[i] = n[k] n[k]= temp for j in range(0,3): print str(n[j]),
if __name__ == "__main__": lis = [] while True: a, b = map( int, input().split() ) if a == b == 0: break lis.append([a,b]) for i in lis: for j in range(i[0]): print('#'*i[1]) print()
0
null
608,380,589,242
40
49
import math x=int(input()) ans=0 for i in range (1,x+1): for j in range(1,x+1): chk=math.gcd(i,j) for k in range (1,x+1): ans=ans+math.gcd(chk,k) print(ans)
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=998244353 N,S=MI() A=LI() dp=[[0]*(S+1) for _ in range(N+1)] #dp[i][j]はi番目までで,和がjになるのが何個作れるか. #ただし,その数を使わない場合,選択するかしないか選べるのでダブルでカウント dp[0][0]=1 for i in range(N): #dp[i][0]+=1 for j in range(S+1): dp[i+1][j]+=dp[i][j]*2 dp[i+1][j]%=mod if j+A[i]<=S: dp[i+1][j+A[i]]+=dp[i][j] dp[i+1][j+A[i]]%=mod print(dp[-1][-1]) main()
0
null
26,523,861,026,572
174
138
from itertools import accumulate R, C, K = map(int, input().split()) vss = [[None]*C for _ in range(R)] for _ in range(K): r, c, v = map(int, input().split()) vss[r-1][c-1] = v dp = [] for y in range(R): ndp = [] for x in range(C): tmp = [] uemax = 0 if y > 0: uemax = max(dp[x]) if vss[y][x] is None: if x > 0: left = ndp[-1] tmp.append(left[0] if left[0] > uemax else uemax) tmp.append(left[1]) tmp.append(left[2]) tmp.append(left[3]) else: tmp.append(uemax) tmp.append(0) tmp.append(0) tmp.append(0) else: v = vss[y][x] if x > 0: left = ndp[-1] tmp.append(left[0] if left[0] > uemax else uemax) tmp.append(max(left[0]+v, left[1], uemax+v)) tmp.append(left[1]+v if left[1]+v > left[2] else left[2]) tmp.append(left[2]+v if left[2]+v > left[3] else left[3]) else: tmp.append(uemax) tmp.append(uemax + v) tmp.append(0) tmp.append(0) ndp.append(tmp) dp = ndp print(max(dp[-1]))
import sys R, C, K = map(int, input().split()) item = [[0] * (C + 1) for _ in range(R + 1)] # dp配列と合わせるために, 0行目, 0列目を追加している. for s in sys.stdin.readlines(): r, c, v = map(int, s.split()) item[r][c] = v dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] for i in range(R + 1): for j in range(C + 1): for k in range(4): here = dp[k][i][j] # 次の行に移動する場合 if i + 1 <= R: # 移動先のアイテムを取らない場合 dp[0][i + 1][j] = max(dp[0][i + 1][j], here) # 移動先のアイテムを取る場合 dp[1][i + 1][j] = max(dp[1][i + 1][j], here + item[i + 1][j]) # 次の列に移動する場合 if j + 1 <= C: # 移動先のアイテムを取らない場合 dp[k][i][j + 1] = max(dp[k][i][j + 1], here) # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能 if k < 3: dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + item[i][j + 1]) ans = 0 for k in range(4): ans = max(ans, dp[k][-1][-1]) print(ans)
1
5,574,353,522,268
null
94
94
import sys sys.setrecursionlimit(10000000) n = int(input()) G = [[] for i in range(n)] d = [0 for i in range(n)] f = [0 for i in range(n)] color = [0 for i in range(n)] stamp = 0 def dfs(u): global stamp if d[u]: return stamp += 1 d[u] = stamp for v in G[u]: if color[v] != 0: continue color[v] = 1 dfs(v) color[u] = 2 stamp += 1 f[u] = stamp color[0] = 1 for i in range(n): inp = list(map(int, input().split())) u = inp[0] u -= 1 k = inp[1] for j in range(k): v = inp[j+2] v -= 1 G[u].append(v) #G[v].append(u) for i in range(n): dfs(i) for i in range(n): print("{0} {1} {2}".format(i+1, d[i], f[i]))
N=int(input()) L=[[10**9]for i in range(N+1)] for i in range(N): l=list(map(int,input().split())) for j in range(l[1]): L[i+1].append(l[2+j]) #print(L) for i in range(N+1): L[i].sort(reverse=True) #print(L) ans=[] for i in range(N+1): ans.append([0,0]) from collections import deque Q=deque() cnt=1 for i in range(N): Q.append([0,N-i]) for i in range(10**7): if len(Q)==0: break q0,q1=Q.pop() #print(q0,q1) if q1!=10**9: if ans[q1][0]==0: ans[q1][0]=cnt cnt+=1 for j in L[q1]: Q.append([q1,j]) else: ans[q0][1]=cnt cnt+=1 #print(ans,Q) for i in range(1,N+1): print(i,ans[i][0],ans[i][1])
1
2,927,436,876
null
8
8
AB = list(map(int, input().split())) print(AB[0]*AB[1])
N=input() n=int(N) k=int(n%1000) if k==0: print(0) else: print(1000-k)
0
null
12,202,110,299,388
133
108
n = int(input()) a = set(input().split()) print('YES' if (len(a) == n) else 'NO')
N = int(input()) S = [input() for i in range(N)] LR = [] for s in S: left, right = 0, 0 for ss in s: if ss == "(": left += 1 else: if left: left -= 1 else: right += 1 LR.append([left, right]) #print(LR) plus = [] minus = [] for l, r in LR: if l >= r: plus.append([l, r]) else: minus.append([l, r]) plus.sort(key = lambda x: x[1]) minus.sort(key = lambda x: -x[0]) cnt = 0 for l, r in plus + minus: cnt -= r if cnt < 0: print("No") exit() cnt += l if cnt == 0: print("Yes") else: print("No")
0
null
48,626,346,402,188
222
152
n=int(input()) A=list(input()) w=0 ; r=A.count("R") ; ans=10**7 for i in range(n+1): ans=min(ans, max(w,r)) if i==n:print(ans);exit() if A[i]=="R": r-=1 else: w+=1
x = int(input()) k = 1 while k*x%360: k += 1 print(k)
0
null
9,680,826,859,500
98
125
h,w=input().split(" ") h,w=int(h),int(w) if h==1 or w==1: print(1) elif h*w%2==0: print(int(h*w/2)) else: print(int(h*w//2+1))
h,w=map(int,input().split()) if h==1 or w==1: print(1) exit() print(((h+1)//2)*((w+1)//2)+(h//2)*(w//2))
1
50,599,104,123,300
null
196
196
#from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 #R = 998244353 def ddprint(x): if DBG: print(x) l,r,d = inm() sm = 0 for i in range(l,r+1): if i%d==0: sm += 1 print(sm)
def main(): A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) d = abs(A - B) s = V - W print('YES' if T * s >= d else 'NO') if __name__ == '__main__': main()
0
null
11,376,045,044,026
104
131
x,y = map(int,input().split()) mod = 10**9+7 def comb(N,x): numerator = 1 for i in range(N-x+1,N+1): numerator = numerator * i % mod denominator = 1 for j in range(1,x+1): denominator = denominator * j % mod d = pow(denominator,mod-2,mod) return numerator * d % mod if (x+y) % 3 == 0: a = (2*y-x) //3 b = (2*x-y) //3 if a >= 0 and b >= 0: print(comb(a+b,a)) exit() print(0)
MOD = 1000000007 def mod_inv(mod, a): old_t, t = 0, 1 old_r, r = mod, a while r != 0: quotient = old_r // r old_r, r = r, old_r - quotient * r old_t, t = t, old_t - quotient * t return old_t % mod def combine(n, k, mod): if k > n // 2: k = n - k u = 1 for i in range(n - k + 1, n + 1): u = u * i % mod v = 1 for i in range(1, k + 1): v = v * i % mod return u * mod_inv(mod, v) % MOD def main(): X, Y = map(int, input().split()) m1 = X + Y if m1 % 3 == 0: m = m1 // 3 if X < m or Y < m: print(0) else: print(combine(m, X - m, MOD)) else: print(0) if __name__ == '__main__': main()
1
150,570,302,987,100
null
281
281
import numpy as np import sys K = int(input()) A, B = list(map(int, input().split())) array = np.arange(A, B+1) for _ in array: if(_%K == 0): print("OK") sys.exit(0) print("NG")
K =int(input()) A,B = map(int,input().split()) q, mod = divmod(A, K) if mod == 0: print("OK") elif K*(q+1) <= B: print("OK") else: print("NG")
1
26,457,632,335,752
null
158
158
# coding: utf-8 def bubbleSort(C, N): for i in xrange(N): for j in xrange(N-1, i, -1): if C[j-1][1] > C[j][1]: C[j], C[j-1] = C[j-1], C[j] return C def selectionSort(C, N): for i in xrange(N): minj = i for j in xrange(i, N): if C[minj][1] > C[j][1]: minj = j C[i], C[minj] = C[minj], C[i] return C def isStable(in_, out_, N): for i in xrange(N): for j in xrange(i + 1, N): for a in xrange(N): for b in xrange(a + 1, N): if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]: return False return True def main(): N = input() cards = raw_input().split() bubble = bubbleSort(cards[:], N) selection = selectionSort(cards[:], N) print ' '.join(bubble) print 'Stable' if isStable(cards, bubble, N) else 'Not stable' print ' '.join(selection) print 'Stable' if isStable(cards, selection, N) else 'Not stable' if __name__ == '__main__': main()
import sys ERROR_INPUT = 'input is invalid' def main(): n = get_length() arr = get_array(length=n) bubbleLi = bubbleSort(li=arr.copy(), length=n) selectionLi = selectionSort(li=arr.copy(), length=n) print(*list(map(lambda c: c.card, bubbleLi))) print(checkStable(inp=arr, out=bubbleLi)) print(*list(map(lambda c: c.card, selectionLi))) print(checkStable(inp=arr, out=selectionLi)) return 0 def get_length(): n = int(input()) if n < 1 or n > 36: print(ERROR_INPUT) sys.exit(1) else: return n def get_array(length): nums = input().split(' ') return [Card(n) for n in nums] def bubbleSort(li, length): for n in range(length): for n in range(1, length - n): if li[n].num < li[n - 1].num: li[n], li[n - 1] = li[n - 1], li[n] return li def selectionSort(li, length): for i in range(0, length - 1): min_index = i for j in range(i, length): if li[j].num < li[min_index].num: min_index = j if i != min_index: li[i], li[min_index] = li[min_index], li[i] return li def checkStable(inp, out): small_num = out[0].num for n in range(1, len(out)): if out[n].num == small_num: if inp.index(out[n]) < inp.index(out[n - 1]): return 'Not stable' elif small_num < out[n].num: small_num = out[n].num continue return 'Stable' class Card: def __init__(self, disp): li = list(disp) self.card = disp self.chara = li[0] self.num = int(li[1]) return main()
1
25,562,451,200
null
16
16
N = int(input()) music = [] for i in range(N): music.append(input().split()) X = (input()) Time = 0 kama = False for s,t in music: if kama: Time += int(t) if s == X: kama = True print(Time)
from sys import stdin rs = lambda : stdin.readline().strip() ri = lambda : int(rs()) ril = lambda : list(map(int, rs().split())) def main(): N = ri() s = [] t = [] for i in range(N): x, y = input().split() s.append(x) t.append(int(y)) X = rs() a = sum(t) b = 0 for x, y in zip(s, t): b += y if x == X: break print(a - b) if __name__ == '__main__': main()
1
97,194,340,097,690
null
243
243
# -*-coding:utf-8-*- def get_input(): while True: try: yield "".join(input()) except EOFError: break if __name__=="__main__": array = list(get_input()) for i in range(len(array)): temp = array[i].split() a = int(temp[0]) b = int(temp[1]) ans = a + b print(len(str(ans)))
import math lst = [] while True: try: a, b = map(int, input().split()) lst.append(int(math.log10(a+b))+1) except EOFError: for i in lst: print(i) break
1
103,782,158
null
3
3
import sys inint = lambda: int(sys.stdin.readline()) inintm = lambda: map(int, sys.stdin.readline().split()) inintl = lambda: list(inintm()) instrm = lambda: map(str, sys.stdin.readline().split()) instrl = lambda: list(instrm()) n = inint() P = inintl() min_l = [] now_min = P[0] ans = 0 for p in P: if p < now_min: now_min = p min_l.append(now_min) for i in range(n): if min_l[i] == P[i]: ans += 1 print(ans)
N = int(input()) P = list(map(int,input().split())) a = 0 s = 10**6 for p in P: if p<s: a+=1 s = min(s,p) print(a)
1
85,108,639,957,950
null
233
233
A,B=map(int,input().split()) print("safe" if A>B else "unsafe")
def resolve(): s, w = map(int, input().split()) if s <= w: print("unsafe") else: print("safe") resolve()
1
29,275,876,588,608
null
163
163
import itertools n = int(input()) L = list(map(int, input().split())) L.sort(reverse = True) li = list(itertools.combinations(L, 3)) ans = 0 for v in li: if v[0] != v[1] and v[1] != v[2] and v[0] - v[1] < v[2]: ans += 1 print(ans)
N=int(input()) S,T=map(list,input().split()) U=[] for i in range(N): U.append("") for i in range(N): U[i]=S[i]+T[i] print(''.join(U))
0
null
58,406,057,299,392
91
255
import itertools n, m = [int(w) for w in input().split()] wa_n = [0] * n ac_n = [0] * n for i in range(m): p, s = input().split() p = int(p) - 1 if s == "AC": ac_n[p] = 1 else: if ac_n[p] == 1: continue else: wa_n[p] += 1 print(sum(ac_n), sum(list(itertools.compress(wa_n, ac_n))))
n,m = map(int,input().split()) prb = [[0] for _ in range(n+1)] for _ in range(m): sub = input().split() p, s = int(sub[0]), sub[1] lst = prb[p] if lst[-1] == 1: pass elif s == "WA": lst.append(0) elif s == "AC": lst.append(1) prb[p] = lst ac_prb = [lst for lst in prb if lst[-1] == 1] ac_num = len(ac_prb) pe_num = -2*ac_num for prb in ac_prb: pe_num += len(prb) print(ac_num, pe_num)
1
93,094,721,090,312
null
240
240
n = int(input()) a = list(map(int, input().split())) ch = 0 for i in range(n): if a[i] % 2 == 0: if a[i] % 3 != 0 and a[i] % 5 != 0: ch = 1 if ch == 0: ans = 'APPROVED' else: ans = 'DENIED' print(ans)
n = int(input()) P = list(map(int, input().split())) minSoFar = 2 * 10**5 + 1 ans = 0 for i in range(n): if P[i] < minSoFar: ans += 1 minSoFar = min(minSoFar, P[i]) print(ans)
0
null
77,065,931,486,330
217
233
English_sentence='' try: while True: line=input() if line=='': break English_sentence+=line except EOFError: pass lowercase=['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'] uppercase=['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'] number=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] for _ in range(26): for _2 in English_sentence: if _2==lowercase[_] or _2==uppercase[_]: number[_]+=1 for ans in range(26): print("{0} : {1}".format(lowercase[ans],number[ans]))
n, t = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort(key=lambda x: x[0]) dp = [[0] * (n+1) for i in range(t)] ans = 0 for time in range(1, t): for i in range(n): if ab[i][0] <= time: if dp[time][i] < (ab[i][1] + dp[time - ab[i][0]][i]): dp[time][i+1] = (ab[i][1] + dp[ time - ab[i][0] ][i]) else: dp[time][i+1] = dp[time][i] else: dp[time][i+1] = dp[time][i] if i < n-1: ans = max(ans, dp[time][i+1] + ab[i+1][1]) print(ans)
0
null
76,545,454,345,598
63
282
# -*- coding: utf-8 -*- S = input() if 'RRR' in S: print("3") elif 'RR' in S: print("2") elif 'R' in S: print("1") else: print("0")
x = input() if x == "RRR": print(3) elif x == "RRS": print(2) elif x == "SRR": print(2) elif x == "SSS": print(0) else: print(1)
1
4,878,774,768,296
null
90
90
# -*- coding: utf-8 -*- """ Created on Mon Sep 7 02:42:25 2020 @author: liang """ """ n進数問題 【原則】 大きな数の計算をしない  ⇒ 1の桁から計算する 171-C いびつなn進数 27 -> a(26)a(1)となる  ⇒先にa(1)だけもらってN%26とすることで解決 ASCII化 ord() 文字化 chr() """ N = int(input()) res = str() while N > 0: N -= 1 #"a"として予め設置 res += chr(ord("a") + N%26) N //= 26 print(res[::-1])
print("Yes" if int(input()) >= 30 else "No")
0
null
8,912,129,696,538
121
95
import sys from bisect import bisect_left,bisect_right sys.setrecursionlimit(10**9) INF=10**18 def input(): return sys.stdin.readline().rstrip() def main(): N,M=map(int,input().split()) A=sorted(list(map(int,input().split()))) S=[0]*(N+1) for i in range(N): S[i+1]=S[i]+A[i] def nibutan(ok,ng): while abs(ok-ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid return ok def solve(mid): c=0 for i in range(N): c+=N-bisect_left(A,mid-A[i]) if c>=M: return True else: return False x=nibutan(0,10**11) ans=0 count=0 for i in range(N): b_l=bisect_left(A,x-A[i]) count+=(N-b_l) ans+=S[N]-S[b_l]+A[i]*(N-b_l) if count==M: print(ans) else: print(ans+(M-count)*x) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- from collections import deque n = int(raw_input()) que = deque() for i in range(n): com = str(raw_input()) if com == "deleteFirst": del que[0] elif com == "deleteLast": del que[-1] else: c, p = com.split() if c == "insert": que.appendleft(p) else: try: que.remove(p) except: pass print " ".join(map(str, que))
0
null
53,906,529,991,248
252
20
i=1 x = int(input()) while x != 0 : print("Case {0}: {1}".format(i, x)) x = int(input()) i=i+1
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) d1 = T1*(A1-B1) d2 = T2*(A2-B2) if d1>d2: d1 *= -1 d2 *= -1 if (d1>0 and d1+d2>0) or (d1<0 and d1+d2<0): print(0) elif d1+d2==0: print("infinity") else: v = (abs(d1)//(d1+d2)) ans = v*2 pos = d1+v*(d1+d2) if pos<0 and pos+d2>=0: ans += 1 print(ans)
0
null
66,106,651,552,360
42
269
import math def findNumberOfDigits(n, b): dig = (math.floor(math.log(n) /math.log(b)) + 1) return dig n, k = map(int, input().strip().split()) print(findNumberOfDigits(n, k))
a,b = map(int,raw_input().split()) print a/b, a%b, "{0:.10f}".format(a/float(b))
0
null
32,288,740,407,330
212
45
n = int(input()) r = s = 0 for i in range(n): a, b = input().split() if a > b: r += 3 elif a < b: s += 3 else: r += 1; s += 1 print(r,s)
n = int(input()) data = list(map(int, input().split())) def insertion_sort(A, N): print(*A) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(*A) insertion_sort(data, n)
0
null
998,089,388,830
67
10
import itertools n = int(input()) test = list(itertools.permutations([i for i in range(n)])) data = [] for i in range(n): x,y = map(int,input().split()) data.append([x,y]) total = 0 for i in test: for k in range(n-1): total += ((data[i[k]][0] - data[i[k+1]][0])**2 + (data[i[k]][1] - data[i[k+1]][1])**2 )**0.5 print(total/len(test))
X = input() l = len(X) m = l//2 if (X == 'hi'*m): print("Yes") else: print("No")
0
null
100,417,805,860,780
280
199
R,C,K = map(int,input().split()) item = [[0] * (C + 1) for _ in range(R + 1)] for i in range(K): r,c,v = map(int,input().split()) item[r][c] = v dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] for h in range(R+1): for w in range(C+1): for k in range(4): position = dp[k][h][w] if h+1 <= R: # 移動先のアイテムを取らない場合 dp[0][h+1][w] = max(dp[0][h+1][w], position) # 移動先のアイテムを取る場合 dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w]) if w+1 <= C: # 移動先のアイテムを取らない場合 dp[k][h][w+1] = max(dp[k][h][w+1], position) # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能 if k < 3: dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1]) ans = 0 for k in range(4): ans = max(ans, dp[k][-1][-1]) print(ans)
while True: (H,W) = [int(x) for x in input().split()] if H == W == 0: break for hc in range(H): print('#'*W) print()
0
null
3,165,453,585,752
94
49
N = int(input()) Adj = [[0 for i in range(N)] for j in range(N)] for i in range(N): u = list(map(int, input().split())) if u[1] > 0: for k in u[2: 2+u[1]]: Adj[u[0] - 1][k - 1] = 1 color = [0] * N #1: visited, 0: not visited, 2: completed s = [0] * N # start f = [0] * N # finish time = 0 def DFS(u): global time color[u-1] = 1 time += 1 s[u-1] = time for i in range(1, N+1): if Adj[u-1][i-1] == 1 and color[i-1] == 0: DFS(i) color[u-1] = 2 time += 1 f[u-1] = time for i in range(1, N+1): if color[i-1] == 0: DFS(i) for i in range(N): print('{} {} {}'.format(i+1, s[i], f[i]))
N=int(input()) S,T=input().split() ans=S[0]+T[0] for i in range(1,N): ans=ans+S[i]+T[i] print(ans)
0
null
55,744,561,453,000
8
255
import sys s = sys.stdin.readline().rstrip("\n") print(s[:3])
import sys N=int(input()) A = list(map(int,input().split())) import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) def gcd_list(numbers): return reduce(math.gcd, numbers) if gcd_list(A) > 1: print("not coprime") sys.exit() D = [i for i in range(max(A)+1)] #iを割り切る最小の素数を格納 p = 2 while(p*p<=max(A)): if D[p]==p: for i in range(2*p,max(A)+1,p): if D[i]==i: D[i]=p p+=1 prime = set() for a in A: tmp=D[a] L=set() while(a>1): a=a//tmp L.add(tmp) tmp=D[a] for l in L: if l in prime: print("setwise coprime") sys.exit() else: prime.add(l) print("pairwise coprime")
0
null
9,351,752,944,768
130
85
_ = input() arr = list(map(int, input().split())) min = arr[0] max = arr[0] sum = 0 for a in arr: if a < min: min = a if max < a: max = a sum += a print(min, max, sum)
hoge = int(input()) l = [int(i) for i in input().split()] mn = min(l) mx = max(l) sm = sum(l) print(mn,mx,sm)
1
745,413,613,930
null
48
48
n,x,t = map(int,input().split()) if n % x ==0: print(int(n/x*t)) else: print(int((n//x+1)*t))
def do_calc(data): from collections import deque s = deque() # ??????????????¨?????????????????? while data: elem = data[0] data = data[1:] if elem == '+' or elem == '-' or elem == '*': a = s.pop() b = s.pop() if elem == '+': s.append(b + a) elif elem == '-': s.append(b - a) elif elem == '*': s.append(b * a) else: s.append(int(elem)) return s.pop() if __name__ == '__main__': # ??????????????\??? data = [x for x in input().split(' ')] # data = ['1', '2', '+', '3', '4', '-', '*'] # ??????????????? result = do_calc(data) # ??????????????? print(result)
0
null
2,114,820,920,850
86
18
cnt=0 def mer(l,r): global cnt ll=len(l) rr=len(r) md=[] i,j=0,0 l.append(float('inf')) r.append(float('inf')) for k in range(ll+rr): cnt+=1 if l[i]<=r[j]: md.append(l[i]) i+=1 else: md.append(r[j]) j+=1 return md def mergesort(a): m=len(a) if m<=1: return a m=m//2 l=mergesort(a[:m]) r=mergesort(a[m:]) return mer(l,r) n=int(input()) a=list(map(int, input().split())) b=mergesort(a) for i in range(n-1): print(b[i],end=" ") print(b[n-1]) print(cnt)
import sys input = sys.stdin.readline n = int(input()) L = [int(x) for x in input().split()] cnt = 0 def Merge(S, l, m, r): global cnt cnt += r - l L = S[l:m] + [float('inf')] R = S[m:r] + [float('inf')] i, j = 0, 0 for k in range(l, r): if L[i] < R[j]: S[k] = L[i] i += 1 else: S[k] = R[j] j += 1 return def MergeSort(S, l, r): if r - l > 1: m = (l + r) // 2 MergeSort(S, l, m) MergeSort(S, m, r) Merge(S, l, m, r) return MergeSort(L, 0, n) print(*L) print(cnt)
1
113,600,686,432
null
26
26
n = input() m = len(n) x = 0 for i in range(m): x += int(n[i]) print("Yes" if x % 9 == 0 else "No")
N = int(input()) n = str(N) le = len(n) M = 0 for i in range(le): nn = int(n[i]) M += nn if M % 9 == 0: print("Yes") else: print("No")
1
4,399,178,799,330
null
87
87
# https://atcoder.jp/contests/abc145/tasks/abc145_d X, Y = list(map(int, input().split())) MOD = int(1e9 + 7) def combination(n, r, mod=MOD): def modinv(a, mod=MOD): return pow(a, mod-2, mod) # nCr with MOD r = min(r, n - r) res = 1 for i in range(r): res = res * (n - i) * modinv(i+1, mod) % mod return res # 1回の移動で3増えるので,X+Yは3の倍数 (0, 0) start if (X + Y) % 3 != 0: ans = 0 print(0) else: # X+Yは3の倍数 # (+1, +2)をn回,(+2, +1)をm回実行 # n + 2m = X # 2n + m = Y # 3 m = 2 X - Y # m = (2 X - Y) // 3 # n = X - 2 * m m = (2 * X - Y) // 3 n = X - 2 * m if m < 0 or n < 0: print(0) else: print(combination(m + n, m, MOD))
class Factorial(): def __init__(self, mod=10**9 + 7): self.mod = mod self._factorial = [1] self._size = 1 self._factorial_inv = [1] self._size_inv = 1 def __call__(self, n): return self.fact(n) def fact(self, n): ''' n! % mod ''' if n >= self.mod: return 0 self._make(n) return self._factorial[n] def fact_inv(self, n): ''' n!^-1 % mod ''' if n >= self.mod: raise ValueError('Modinv is not exist! arg={}'.format(n)) self._make(n) if self._size_inv < n+1: self._factorial_inv += [-1] * (n+1-self._size_inv) self._size_inv = n+1 if self._factorial_inv[n] == -1: self._factorial_inv[n] = self.modinv(self._factorial[n]) return self._factorial_inv[n] def comb(self, n, r): ''' nCr % mod ''' if r > n: return 0 t = self.fact_inv(n-r)*self.fact_inv(r) % self.mod return self(n)*t % self.mod def comb_with_repetition(self, n, r): ''' nHr % mod ''' t = self.fact_inv(n-1)*self.fact_inv(r) % self.mod return self(n+r-1)*t % self.mod def perm(self, n, r): ''' nPr % mod ''' if r > n: return 0 return self(n)*self.fact_inv(n-r) % self.mod @staticmethod def xgcd(a, b): ''' Return (gcd(a, b), x, y) such that a*x + b*y = gcd(a, b) ''' x0, x1, y0, y1 = 0, 1, 1, 0 while a != 0: (q, a), b = divmod(b, a), a y0, y1 = y1, y0 - q * y1 x0, x1 = x1, x0 - q * x1 return b, x0, y0 def modinv(self, n): g, x, _ = self.xgcd(n, self.mod) if g != 1: raise ValueError('Modinv is not exist! arg={}'.format(n)) return x % self.mod def _make(self, n): if n >= self.mod: n = self.mod if self._size < n+1: for i in range(self._size, n+1): self._factorial.append(self._factorial[i-1]*i % self.mod) self._size = n+1 def _make_inv(self, n): if n >= self.mod: n = self.mod self._make(n) if self._size_inv < n+1: for i in range(self._size_inv, n+1): self._factorial_inv.append(self.modinv(self._factorial[i])) self._size_inv = n+1 x, y = sorted(map(int, input().split())) q, r = divmod(x+y, 3) if r != 0: print(0) else: comb = Factorial().comb print(comb(q, y-q))
1
149,902,691,109,950
null
281
281
from collections import deque def main(): doubly_liked_list = deque() n = int(input()) for i in range(n): command = input() if command == 'deleteFirst': doubly_liked_list.popleft() elif command == 'deleteLast': doubly_liked_list.pop() else: command = command.split() if command[0] == 'insert': doubly_liked_list.appendleft(int(command[1])) elif command[0] == 'delete': try: doubly_liked_list.remove(int(command[1])) except: pass print(*doubly_liked_list) if __name__ == "__main__": main()
import sys import collections N = int(input()) L = collections.deque() for _ in range(N): com = (sys.stdin.readline().rstrip()).split() if com[0] == 'insert': L.appendleft(int(com[1])) elif com[0] == 'delete': try: L.remove(int(com[1])) except: pass elif com[0] == 'deleteFirst': L.popleft() elif com[0] == 'deleteLast': L.pop() print(*L)
1
49,770,187,928
null
20
20
#!/usr/bin/env python3 #import import math #import numpy as np N = int(input()) L = list(map(int, input().split())) L.sort() def is_ok(arg, cmin, cmax): return L[arg] > cmin and L[arg] < cmax def meguru_bisect(ok, ng, cmin, cmax): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(mid, cmin, cmax): ok = mid else: ng = mid return ok ans = 0 for i in range(N - 2): for j in range(i + 1, N - 1): a = L[i] b = L[j] cmin = b - a cmax = a + b t = meguru_bisect(j, N, cmin, cmax) ans += t - j print(ans)
import bisect N = int(input()) Ls = list(map(int, input().split(" "))) Ls.sort() ans = 0 for i in range(0,N-2): for j in range(i+1,N-1): k = bisect.bisect_left(Ls,Ls[i]+Ls[j]) ans += k - (j + 1) print(ans)
1
171,339,778,521,660
null
294
294
a = int(input()) b = int(input()) l = [a, b] if not 1 in l: print('1') elif not 2 in l: print('2') else: print('3')
def resolve(): n = int(input()) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors divisors = make_divisors(n) min_pair = 10**19 for i in divisors: pair_i = n//i min_pair = min(min_pair, ((i-1)+(pair_i-1))) print(min_pair) resolve()
0
null
136,322,708,304,640
254
288
def freq(my_list): count = {} for i in my_list: count[i] = count.get(i, 0) + 1 return count n = int(input()) l = list(map(int, input().split())) s,f = sum(l), freq(l) for _ in range(int(input())): x, y = map(int, input().split()) if x in f: v = f[x] if y in f: f[y]+=v f.pop(x) else: f[y]=f.pop(x) s += (y-x)*v print(s)
n = int(input()) a = sorted(list(map(int, input().split()))) q = int(input()) l = [0]*(10**5+10) for i in a: l[i] += 1 s = sum(a) for _ in range(q): b, c = map(int, input().split()) s += (c - b) * l[b] l[c] += l[b] l[b] = 0 print(s)
1
12,301,268,299,108
null
122
122
import collections N=int(input()) P=[input() for i in range(N)] c=collections.Counter(P) print(len(c))
import itertools n=int(input()) l=[int(i) for i in range(n)] ans=chk=p=0 w=[] for i in range(n): x,y=map(int,input().split()) w.append((x,y)) for i in list(itertools.permutations(l,n)): chk=0 for j in range(n-1): chk+=((w[i[j]][0]-w[i[j+1]][0])**2+(w[i[j]][1]-w[i[j+1]][1])**2)**0.5 ans+=chk p+=1 print(ans/p)
0
null
89,474,278,738,276
165
280
import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline from collections import defaultdict n,m=map(int,input().split()) visited=[0]*n d=defaultdict(list) def dfs(n): visited[n]=1 #print(visited) for i in d[n]: if visited[i]==0: dfs(i) for i in range(m): a,b=map(int,input().split()) a,b=a-1,b-1 d[a].append(b) d[b].append(a) r=-1 for i in range (n): if visited[i]==0: dfs(i) r+=1 print(r)
A,B=map(int,input().split()) if 10>A>0 and 10>B>0: print(A*B) else: print(-1)
0
null
80,163,898,301,510
70
286
from math import pi r = float(raw_input()) print '%f %f' % (pi * r ** 2, 2 * pi * r)
import math r = float(input()) S = math.pi * r * r L = 2 * math.pi * r print("{0:.10f}".format(S),end=" ") print("{0:.10f}".format(L))
1
643,875,962,508
null
46
46
n,k = list(map(int,input().split())) r,s,p = list(map(int,input().split())) t = str(input()) t_list = [] for i in range(k): t_list.append(t[i]) for i in range(k,n): if t[i] != t_list[i-k] or t_list[i-k] == 'all': t_list.append(t[i]) else: t_list.append('all') print(t_list.count('r') * p + t_list.count('s') * r + t_list.count('p') * s)
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if W>=V: print('NO') exit() if abs(A-B)/(V-W) > T: print('NO') exit() print('YES')
0
null
60,615,021,193,110
251
131
def main(): N=int(input()) A=list(map(int,input().split())) s=sum(A) Q=int(input()) d=[0]*(10**5 +1)#各数字の個数 for i in A: d[i]+=1 for i in range(Q): B,C=map(int,input().split()) s += (C-B)*d[B] print(s) d[C]+=d[B] d[B]=0 if __name__ == "__main__": main()
n = int(input()) lst = [0]*(10**5) l = list(map(int,input().split())) total = sum(l) for x in l: lst[x-1] += 1 m = int(input()) for i in range(m): x,y = map(int,input().split()) lst[y-1] += lst[x-1] total += (y-x) * lst[x-1] lst[x-1] = 0 print(total)
1
12,098,978,285,618
null
122
122
D,T,S = map(int,input().split()) x = S*T if x >= D : print("Yes") else: print("No")
x = int(input()) a = 100 i = 0 while a < x: i += 1 a += a // 100 print(i)
0
null
15,397,488,314,208
81
159
# -*- coding:utf-8 -*- stack = list() def deal_expression(x): if x.isdigit(): stack.append(int(x)) else: a = stack.pop() b = stack.pop() if x == '+': stack.append(b + a) elif x == '-': stack.append(b - a) elif x == '*': stack.append(b * a) elif x == '/': stack.append(b / a) for x in input().split(): deal_expression(x) print(stack[0])
operators = ['+', '-', '*', '/'] stack = list(input().split()) # stack = list(open('input.txt').readline().split()) def calc(ope): c = stack.pop() a = c if c not in operators else calc(c) c = stack.pop() b = c if c not in operators else calc(c) return str(eval(b+ope+a)) print(calc(stack.pop()))
1
36,444,875,100
null
18
18
c = 1 while True: a = int(raw_input()) if a == 0: break print "Case %d: %d" % (c,a) c = c + 1
def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n //= i table.append(i) i += 1 if n > 1: table.append(n) return table from itertools import groupby N = int(input()) P = prime_decomposition(N) ans = 0 for v, g in groupby(P): n = len(list(g)) for i in range(1, 100000): n -= i if n >= 0: ans += 1 else: break print(ans)
0
null
8,648,592,636,070
42
136
X,N = map(int,input().split()) p = list(map(int,input().split())) if not X in p: print(X) else: for i in range(100): if not (X-i) in p: print(X-i) break elif not (X+i) in p: print(X+i) break
(X,N) = map(int,input().split()) if N == 0: print(X) else: p = list(map(int,input().split())) for i in range(N+1): if (X - i) not in p: print(X-i) break elif(X+i) not in p: print(X+i) break
1
13,997,120,123,328
null
128
128
import sys n,m = map(int, input().split()) num = [0]*n al = [-1]*n Ans = 0 for i in range(m): s,c = map(int, input().split()) if num[s-1] != 0 and num[s-1] != c: print(-1) sys.exit() else: num[s-1] = c al[s-1] = c if al.count(0)==n and n >= 2: print(-1) sys.exit() if al[0] == 0and n >= 2: print(-1) sys.exit() if num[0] == 0 and n >= 2: num[0] = 1 for i in range(len(num)): Ans = Ans + num[i] * (10 ** (n-i-1)) if Ans == 0 and n >= 2: print(-1) else: print(Ans)
import math n = int(input()) R = 2*n*math.pi print(R)
0
null
45,808,128,976,142
208
167
n = int(input()) p = list(map(int, input().split())) mini = p[0] ans = 0 for i in p: if i <= mini: ans += 1 mini = min(mini,i) print(ans)
import sys read = sys.stdin.read readlines = sys.stdin.readlines import numpy as np def main(): n, *a = map(int, read().split()) p = np.array(a) minp = np.minimum.accumulate(p) r = np.count_nonzero(minp >= p) print(r) if __name__ == '__main__': main()
1
85,420,356,550,430
null
233
233
# 3 A,B,C=map(int,input().split()) K=int(input()) def f(a,b,c,k): if k==0: return a<b<c return f(a*2,b,c,k-1) or f(a,b*2,c,k-1) or f(a,b,c*2,k-1) print('Yes' if f(A,B,C,K) else 'No')
A, B, C = map(int, input().split()) K = int(input()) while A >= B and K > 0: B *= 2 K -= 1 while B >= C and K > 0: C *= 2 K -= 1 # print(A, B, C, K) if A < B and B < C: print("Yes") else: print("No")
1
6,842,227,758,368
null
101
101
import math def main(): n,m = map(int,input().split()) a = list(map(int,input().strip().split())) if n >= sum(a): print(n-sum(a)) return else: print(-1) return main()
N = int(input()) S = dict() for i in range(N): s = input() if s in S: S[s] += 1 else: S[s] = 1 max_val = max(S.values()) max_key = [key for key in S if S[key] == max_val] print("\n".join(sorted(max_key)))
0
null
50,804,905,630,980
168
218
N = int(input()) A = list([int(x) for x in input().split()]) xor_base = A[0] for a in A[1:]: xor_base ^= a result = [] for a in A: result.append(a ^ xor_base) print(*result)
N, *XL = map(int, open(0).read().split()) XL = sorted((x + l, x - l) for x, l in zip(*[iter(XL)] * 2)) curr = -float("inf") ans = 0 for right, left in XL: if left >= curr: curr = right ans += 1 print(ans)
0
null
51,033,370,044,732
123
237
line = input() length = len(line) sum = 0 for i in range(length): sum += int(line[i]) if sum % 9 == 0: print("Yes") else: print("No")
a=int(input("")) if a>=30: print("Yes") elif a<30: print("No")
0
null
5,061,152,576,568
87
95
import numpy as np pi = np.pi a = int(input()) print(2 * a * pi)
r = int(input()) pi = 3.14159265359 print(r*2*pi)
1
31,360,944,899,468
null
167
167
import sys N,K = map(int,input().split()) array = [ a for a in range(1,N+1) ] for I in range(K): _ = input() sweets = list(map(int,input().split())) for K in sweets: if K in array: array.remove(K) print(len(array))
n, k = map(int, input().split()) check = [False] * n d = [] a = [] for i in range(k): d = int(input()) a.append(list(map(int, input().split()))) for i in range(k): for j in range(len(a[i])): check[a[i][j]-1] = True print(check.count(False))
1
24,659,241,365,420
null
154
154
num = list(map(int, input().split())) if num[1] < num[0]: print("No") else: print("Yes")
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush import math #inf = 10**17 mod = 10**9 + 7 def ncr(n, r, mod): r = min(r, n-r) numer = denom = 1 for i in range(1, r+1): numer = numer * (n+1-i) % mod denom = denom * i % mod return numer * pow(denom, mod-2, mod) % mod n = input().rstrip() k = int(input()) ln = len(n) if ln < k: print(0) exit() res = 0 if k == 1: if ln >= 2: res += ncr(ln-1, 1, mod) * 9 res += int(n[0]) if k == 2: if ln >= 3: res += ncr(ln-1, 2, mod) * (9**k) res += ncr(ln-1, 1, mod) * 9 * (int(n[0])-1) for i in range(1, ln): if n[i] != '0': if i == ln-1: res += int(n[i]) else: res += ncr(ln-i-1, 1, mod) * 9 res += int(n[i]) break if k == 3: if ln >= 4: res += ncr(ln-1, 3, mod) * (9**k) res += ncr(ln-1, 2, mod) * 81 * (int(n[0])-1) for i in range(1, ln-1): if n[i] != '0': if ln-i-1 >= 2: res += ncr(ln-i-1, 2, mod) * 81 res += ncr(ln-i-1, 1, mod) * 9 * (int(n[i])-1) for j in range(i+1, ln): if n[j] != '0': if j != ln-1: res += ncr(ln-j-1, 1, mod) * 9 res += int(n[j]) break break print(res) if __name__ == '__main__': main()
0
null
79,617,216,055,088
231
224
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import operator import sys INF = float('inf') def solve(N: int, P: "List[int]", Q: "List[int]"): return abs(operator.sub(*[list(itertools.permutations(range(1, N+1))).index(tuple(i)) for i in [P, Q]])) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int P = [int(next(tokens)) for _ in range(N)] # type: "List[int]" Q = [int(next(tokens)) for _ in range(N)] # type: "List[int]" print(f'{solve(N, P, Q)}') if __name__ == '__main__': main()
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall i8 = np.int64 i4 = np.int32 def main(): stdin = open('/dev/stdin') pin = np.fromstring(stdin.read(), i8, sep=' ') N = pin[0] M = pin[1] L = pin[2] ABC = pin[3: M * 3 + 3].reshape((-1, 3)) A = ABC[:, 0] - 1 B = ABC[:, 1] - 1 C = ABC[:, 2] Q = pin[M * 3 + 3] st = (pin[M * 3 + 4: 2 * Q + M * 3 + 4] - 1).reshape((-1, 2)) s = st[:, 0] t = st[:, 1] graph = csr_matrix((C, (A, B)), shape=(N, N)) dist = np.array(floyd_warshall(graph, directed=False)) dist[dist > L + 0.5] = 0 dist[dist > 0] = 1 min_dist = np.array(floyd_warshall(dist)) min_dist[min_dist == np.inf] = 0 min_dist = (min_dist + .5).astype(int) x = min_dist[s, t] - 1 print('\n'.join(x.astype(str).tolist())) if __name__ == '__main__': main()
0
null
136,952,433,920,078
246
295
r,c = map(int,input().split()) a = [list(map(int,input().split(" "))) for i in range(r)] for i in range(r): r_total = sum(a[i]) a[i].append(r_total) c_total = [] for j in range(c+1): s = 0 for k in range(r): s += a[k][j] c_total.append(s) a.append(c_total) for z in range(r+1): for w in range(c+1): print(a[z][w],end="") if w != c: print(" ",end="") print()
r, c = map(int, input().split()) matrix = [list(map(int, input().split())) for _ in range(r)] for i in range(r): matrix[i].append(sum(matrix[i])) matrix.append(list(map(sum, zip(*matrix)))) # matrix.append([sum(i) for i in zip(*matrix)]) for row in matrix: print(' '.join(str(e) for e in row))
1
1,376,295,947,458
null
59
59
A=range(1,10) for i in A: x=i for j in A: print "%dx%d=%d" %(i,j,x) x+=i
[print('{}x{}={}'.format(i, j, i * j)) for i in range(1, 10) for j in range(1, 10)]
1
55,260
null
1
1
r=input().split() N=int(r[0]) K=int(r[1]) d=[int(s) for s in input().split()] ans=0 for i in range(N): if d[i]>=K: ans+=1 print(ans)
def main(): N = input_int() S = input() count = 1 for i in range(1, N): if S[i-1] != S[i]: count += 1 print(count) def input_int(): return int(input()) def input_int_tuple(): return map(int, input().split()) def input_int_list(): return list(map(int, input().split())) main()
0
null
174,577,323,914,344
298
293
def gcd(a, b): if (a == 0): return b return gcd(b%a, a) def lcm(a, b): return (a*b)//gcd(a, b) n = int(input()) numbers = list(map(int, input().split())) l = numbers[0] for i in range(1, n): l = lcm(l, numbers[i]) ans = 0 for i in range(n): ans += l//numbers[i] MOD = 1000000007 print(ans%MOD)
import math N = int(input()) A = list(map(int, input().split())) mod = 10**9+7 def lcm(x, y): return (x // math.gcd(x, y)) * y LCM = A[0] for i in range(N-1): LCM = lcm(LCM, A[i+1]) #LCM %= mod ans = 0 for a in A: ans += LCM * pow(a, mod-2, mod) % mod ans %= mod print(ans)
1
88,015,093,363,500
null
235
235
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(readline()) m = map(int,read().split()) xl = zip(m,m) c = [(x-l,x+l) for x,l in xl] from operator import itemgetter c.sort() c.sort(key=itemgetter(1)) ans = 1 chk = c[0][1] for i,j in c: if i >= chk: ans +=1 chk = j print(ans)
a=input() i=0 j="" Case="Case" while a>0 or a<0: i+=1 print Case, print str(i)+":", print a a=input()
0
null
45,174,670,799,820
237
42
import sys input = sys.stdin.readline n, s = map(int,input().split()) A = list(map(int,input().split())) mod = 998244353 l = 3050 M = [1] # i!のmod m = 1 for i in range(1, l): m = (m * i) % mod M.append(m) def pow(x, y, mod): # x**y の mod を返す関数 ans = 1 while y > 0: if y % 2 == 1: ans = (ans * x) % mod x = (x**2) % mod y //= 2 return ans def inv(x, mod): # x の mod での逆元を返す関数 return pow(x, mod-2, mod) D = [0] * 3050 M2 = [1] M2I = [0] * l for i in range(l-1): M2.append((M2[-1] * 2) % mod) for i in range(l): M2I[i] = inv(M2[i], mod) i2 = inv(2,mod) D[0] = M2[n] for i in range(n): for j in range(l-1,-1,-1): if j - A[i] >= 0: D[j] = (D[j] + D[j-A[i]] * i2) % mod # print(D[:10]) print(D[s])
# coding: utf-8 # Your code here! import numpy as np import copy D = int(input()) C = list(map(int,input().split())) contest = [list(map(int,input().split())) for i in range(D)] inputs = [int(input()) for i in range(D)] # print(contest) # print(inputs) lists = np.array([0 for i in range(26)]) Y = 0 for i,j in zip(contest,inputs): lists += 1 lists[j-1] = 0 X = C * lists.T # print(X) # print(sum(X)) # x = sum(C[:j-1])+sum(C[j:]) # y = i[j-1]-x+solve Y = i[j-1]-sum(X)+Y print(Y) Y = copy.deepcopy(Y)
0
null
13,936,353,829,902
138
114
import math while True: n=int(input()) if n==0: break s=list(map(int,input().split())) m=sum(s)/len(s) a=0 for i in range(n): a+=(s[i]-m)**2 b=math.sqrt(a/n) print('{:.5f}'.format(b))
H=int(input()) W=int(input()) N=int(input()) B=max(H,W) ans=(N+B-1)//B print(ans)
0
null
44,338,396,587,328
31
236
d='SUN,MON,TUE,WED,THU,FRI,SAT'.split(',') s=input() print(7 - d.index(s))
N = input() S = {"SUN":"7", "MON": "6", "TUE": "5", "WED": "4", "THU": "3", "FRI": "2", "SAT": "1"} print(S[N])
1
133,032,572,700,730
null
270
270
N = int(input()) result = 0 for i in range(1, (N + 1)): if i % 15 == 0: 'Fizz Buzz' elif i % 3 == 0: 'Fizz' elif i % 5 == 0: 'Buzz' else: result = result + i print(result)
n = int(input()) s = [] for i in range(1, n+1): if i % 3 == 0: continue elif i % 5 == 0: continue else: s.append(i) print(sum(s))
1
34,957,811,395,520
null
173
173
import sys sys.setrecursionlimit(10 ** 9) def solve(pick, idx): if pick == 0: return 0 if idx >= n: return -float('inf') if (pick, idx) in dp: return dp[pick, idx] if n-idx+2 < pick*2: return -float('inf') total = max(A[idx] + solve(pick-1, idx+2), solve(pick, idx+1)) dp[(pick, idx)] = total return total n = int(input()) A = list(map(int, input().split())) dp = {} pick = n//2 print(solve(pick, 0))
# 写経AC from collections import defaultdict N = int(input()) A = [int(i) for i in input().split()] # dp[(i, x, flag)]:= i番目まででx個選んでいる時の最大値 # flag: i番目をとるフラグ dp = defaultdict(lambda: -float("inf")) # 初期条件 dp[(0, 0, 0)] = 0 # 貰うDP for i, a in enumerate(A, 1): # i番目までで選ぶ個数 for x in range((i // 2) - 1, (i + 1) // 2 + 1): dp[(i, x, 0)] = max(dp[(i - 1, x, 0)], dp[(i - 1, x, 1)]) dp[(i, x, 1)] = dp[(i - 1, x - 1, 0)] + a print(max(dp[(N, N // 2, 0)], dp[(N, N // 2, 1)]))
1
37,550,990,927,190
null
177
177
N = int(input()) A = [int(x) for x in input().split()] totalChooseNum = N // 2 dp = {0 : 0} for i in range(0, N): ai = A[i] canChooseNum = (N - i + 1) // 2 mustChooseNum = max(totalChooseNum - canChooseNum, 0) next = {} for j in range(mustChooseNum, N): if j > 0 and (2 * (j - 1)) in dp: next[2 * j + 1] = dp[2 * (j - 1)] + ai if 2 * j in dp: if 2 * j + 1 in dp: next[2 * j] = max(dp[2 * j] , dp[2 * j + 1]) else: next[2 * j] = dp[2 * j] elif 2 * j + 1 in dp: next[2 * j] = dp[2 * j + 1] else: break dp = next result = max(dp[totalChooseNum * 2] , dp[totalChooseNum * 2 + 1]) print(result)
import sys for i in sys.stdin: lst = i.split(' ') lst = map(int, lst) lst.sort() n = 1 maxn = 1 while n*n <= lst[0]: if lst[0]%n == 0 and lst[1]%(lst[0]/n) == 0: print lst[0]/n break elif lst[0]%n == 0 and lst[1]%n == 0: maxn = n n = n+1 else: print maxn sys.exit(0)
0
null
18,582,484,960,238
177
11
n = int(input()) count_taro = 0 count_hanako = 0 for i in range(n): taro,hanako = map(str, input().split()) if taro > hanako: count_taro += 3 if hanako > taro: count_hanako += 3 if hanako == taro: count_hanako += 1 count_taro += 1 print(count_taro, count_hanako)
n,k = map(int, input().split()) i=0 a=[] while n!=0: a.append(n%k) n=n//k i=i+1 print(len(a))
0
null
33,190,002,384,420
67
212
n = int(input()) a = list(map(int, input().split())) b = list(enumerate(a)) c = sorted(b, key=lambda x:x[1]) print(*[c[i][0]+1 for i in range(n)])
import itertools def main(): N = int(input()) BIT = list(itertools.product([True,False], repeat=N)) P = [[(0,0)]] for i in range(1,N+1): A = int(input()) L = [] for _ in range(A): x,y = map(int,input().split()) L.append((x,y)) P.append(L) ans = 0 for b in BIT: cnt = 0 flag = True HU = [-1]*(N+1) for i in range(1,N+1): if b[i-1]: cnt += 1 for hu in P[i]: if b[hu[0]-1] != (hu[1]==1): flag = False break if flag: ans = max(ans,cnt) print(ans) if __name__ == '__main__': main()
0
null
151,086,337,151,632
299
262
n = int(raw_input()) i = 0 s = [] h = [] c = [] d = [] def order_list(list): l = len(list) for i in xrange(l): j = i + 1 while j < l: if list[i] > list[j]: temp = list[i] list[i] = list[j] list[j] = temp j += 1 return list def not_enough_cards(mark, list): list = order_list(list) # line = "########################################" # print line # print mark + ":" # print list # print line i = 0 for x in xrange(1, 14): # print "x = " + str(x) + ", i = " + str(i) if i >= len(list): print mark + " " + str(x) elif x != list[i]: print mark + " " + str(x) else: i += 1 while i < n: line = raw_input().split(" ") line[1] = int(line[1]) if line[0] == "S": s.append(line[1]) elif line[0] == "H": h.append(line[1]) elif line[0] == "C": c.append(line[1]) elif line[0] == "D": d.append(line[1]) i += 1 not_enough_cards("S", s) not_enough_cards("H", h) not_enough_cards("C", c) not_enough_cards("D", d)
def resolve(): ''' code here ''' import collections import numpy as np H, W = [int(item) for item in input().split()] grid = [[item for item in input()] for _ in range(H)] dp = [[300 for _ in range(W+1)] for _ in range(H+1)] for i in range(H): for j in range(W): if i == 0 and j == 0: if grid[0][0] == '#': dp[i+1][j+1] = 1 else: dp[i+1][j+1] = 0 else: add_v = 0 add_h = 0 if grid[i][j] != grid[i][j-1]: add_h = 1 if grid[i][j] != grid[i-1][j]: add_v = 1 dp[i+1][j+1] = min(dp[i+1][j]+add_h, dp[i][j+1]+add_v) # print(dp) if grid[H-1][W-1] == '#': print(dp[H][W]//2+1) else: print(dp[H][W]//2) if __name__ == "__main__": resolve()
0
null
25,245,500,530,250
54
194
n, m, l = map(int, input().split()) a = [] b = [] ans = [[0 for _ in range(l)] for _ in range(n)] for _ in range(n): a.append(list(map(int, input().split()))) for _ in range(m): b.append(list(map(int, input().split()))) for i in range(n): for j in range(l): for k in range(m): ans[i][j] = ans[i][j] + a[i][k] * b[k][j] for ans_row in ans: print(*ans_row)
n = int(input()) a = list(map(int, input().split())) count = {} for i in range(len(a)):#番号と身長を引く minus = (i+1) - a[i] if minus in count: count[minus] += 1 else: count[minus] = 1 total = 0 for i in range(len(a)): plus = a[i] + (i+1) if plus in count: total += count[plus] print(total)
0
null
13,758,678,809,960
60
157
cnt = 0 x = int(input()) m = 100 for i in range(4000): if m >= x: print(i) exit() else: m += m//100
def main(): X=int(input()) tmp=100 for year in range(1,4000): tmp += tmp//100 if tmp >= X: print(year) exit() main()
1
27,091,912,983,420
null
159
159
INF = 10 ** 20 n, m = map(int, input().split()) c_lst = list(map(int, input().split())) dp = [INF for _ in range(n + 1)] dp[0] = 0 for coin in c_lst: for price in range(coin, n + 1): dp[price] = min(dp[price], dp[price - coin] + 1) print(dp[n])
import itertools ##print(ord("A")) a,b,= map(int,input().split()) ans= a-b*2 if ans <=0: print(0) else: print(ans)
0
null
83,395,394,261,510
28
291
import sys import math import numpy as np import functools import operator import collections import itertools X=int(input()) ans=1 for i in range(1,100000): if (X*i)%360==0: print(ans) sys.exit() ans+=1
import math x = int(input()) y = 360 lcm = x * y // math.gcd(x, y) print(lcm//x)
1
13,259,678,984,340
null
125
125
N=input() i=0 while 1: for a in N: if a=="7": print("Yes") i=1 break if i==1: break print("No") break
import math n,m,x = map(int,input().split()) book = [list(map(int,input().split())) for _ in range(n)] best = math.inf for i in range(2**n): und = [0]*m money = 0 for j in range(n): if (i>>j) & 1: money += book[j][0] for k in range(m): und[k] += book[j][k+1] if all(s>=x for s in und) and best>money: best = money if best==math.inf: print(-1) else: print(best)
0
null
28,497,950,981,788
172
149
import math from collections import defaultdict ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) ips=lambda:input().split() """========main code===============""" n=ii() a=ll() xor=0 for i in a: xor^=i for i in a: print(xor^i,end=" ")
N,K=map(int,input().split()) P=list(map(int,input().split())) C=list(map(int,input().split())) P=[i-1 for i in P] idle_max=-10**27 for s in range(0,N): k=K-1 score=0 s=P[s] score+=C[s] count=1 idle_max=max(idle_max,score) visited={s:[count,score]} while k and not P[s] in visited: k-=1 count+=1 s=P[s] score+=C[s] visited[s]=[count,score] idle_max=max(idle_max,score) #print(visited) if k: c1,score1=visited[s] c2,score2=visited[P[s]] c1+=1 s=P[s] score1+=C[s] score+=C[s] k-=1 n=c1-c2 score+=(score1-score2)*(k//n) k%=n idle_max=max(idle_max,score) while k: k-=1 s=P[s] score+=C[s] idle_max=max(idle_max,score) print(idle_max)
0
null
8,939,080,595,698
123
93
n=int(input()) a=list(map(int,input().split())) X=[] b=a[0] for i in range(1,n) : b^=a[i] for i in range(n) : x=b^a[i] X.append(x) for i in X : print(i,end=" ")
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n, *a = map(int, read().split()) allxor = a[0] for ae in a[1:]: allxor = allxor ^ ae for ae in a: print(allxor ^ ae, end = ' ') if __name__ == '__main__': main()
1
12,586,460,950,700
null
123
123
N = int(input()) S = input() list = [] for i in range(len(S)): a = ord(S[i]) + N if a > 90: a -= 26 list.append(chr(a)) print("".join(list))
N=int(input()) S=input() print(bytes((s-65+N)%26+65 for s in S.encode()).decode())
1
134,148,832,042,050
null
271
271
n=int(input()) a=[[[0 for _ in range(10)]for _ in range(3)]for _ in range(4)] for i in range(n): b,f,r,v=map(int, input().split()) a[b-1][f-1][r-1]+=v for bb in range(4): for ff in range(3): print(*[""]+a[bb][ff]) if bb==3: break else: print("#"*20)
import sys n=input() house=[[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]] for i in range(4): for j in range(3): for k in range(10): house[i][j].append(0) for i in range(n): b,f,r,v=map(int,raw_input().split()) house[b-1][f-1][r-1]+=v for i in range(4): for j in range(3): for k in range(10): sys.stdout.write(' %d'%house[i][j][k]) print('') if i!=3: print('#'*20)
1
1,081,307,461,926
null
55
55
class Unionfind(): def __init__(self, n): self.n = n self.parents = [-1] * (n+1) def find(self, x): if(self.parents[x] < 0): return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if(x == y): return if(self.parents[x] > self.parents[y]): x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}:{}'.format(r, self.members(r)) for r in self.roots()) N, M, K = map(int, input().split()) uf = Unionfind(N) f = [0 for _ in range(N)] n = [0 for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 uf.union(a, b) f[a] += 1 f[b] += 1 for _ in range(K): c, d = map(int, input().split()) c -= 1 d -= 1 if(uf.same(c, d)): n[c] += 1 n[d] += 1 ans = [] for i in range(N): ans.append(uf.size(i)-f[i]-n[i]-1) print(*ans)
n,m,k=map(int,input().split()) par=[i for i in range(n)] size=[1 for i in range(n)] def find(x): if par[x]==x: return x else: par[x]=find(par[x]) return par[x] def union(a,b): x=find(a) y=find(b) if x!=y: if size[x]<size[y]: par[x]=par[y] size[y]+=size[x] else: par[y]=par[x] size[x]+=size[y] else: return graph=[[] for i in range(n)] for i in range(m): a,b=map(int,input().split()) union(a-1,b-1) graph[a-1].append(b-1) graph[b-1].append(a-1) for i in range(k): a,b=map(int,input().split()) if find(a-1)==find(b-1): graph[a-1].append(b-1) graph[b-1].append(a-1) ans=[] for i in range(n): cnt=size[find(i)] xxx=list(set(graph[i])) cnt-=len(xxx) cnt-=1 ans+=[str(cnt)] print(' '.join(ans))
1
61,664,406,078,628
null
209
209
l = int(input()) ans = float(l ** 3 / 27) print(ans)
h = int(input()) w = int(input()) n = int(input()) p = max(h, w) print((n+p-1)//p)
0
null
68,144,814,008,832
191
236
nm = input().split(" ") n = int(nm[0]) m = int(nm[1]) if n == m: print("Yes") else: print("No")
#入力:N,M(int:整数) def input2(): return map(str,input().split()) #入力:[n1,n2,...nk](int:整数配列) def input_array(): return list(map(int,input().split())) s,t=input2() print("{}{}".format(t,s))
0
null
92,889,869,813,372
231
248
D = int(input()) Cs = list(map(int,input().split())) Ss = [list(map(int,input().split())) for i in range(D)] ts = [] for i in range(D): ts.append(int(input())) last = [0]*26 satisfy = 0 for day,t in enumerate(ts): day += 1 last[t-1] = day satisfy += Ss[day-1][t-1] for i in range(26): satisfy -= Cs[i]*(day-last[i]) print(satisfy)
n = int(input()) a = [int(i) for i in input().split()] max_a = max(a) cnt_d = [0] * (max_a + 1) for ai in a: for multi in range(ai, max_a + 1, ai): cnt_d[multi] += 1 print(sum(cnt_d[ai] == 1 for ai in a))
0
null
12,277,023,869,440
114
129
import math def main(): r = int(input()) print(r * math.pi * 2) main()
def main(): import sys input = sys.stdin.readline N = int(input()) arms = [] for i in range(N): x, l = map(int,input().split()) t = min(x+l,10**9) s = max(x-l,0) arms.append((t,s)) arms.sort() ans = 0 tmp = -1 for t,s in arms: if s >= tmp: tmp = t ans += 1 print(ans) main()
0
null
60,506,898,093,080
167
237
N = input() print("Yes" if N.count("7") > 0 else "No")
print('Yes' if '7' in input() else 'No')
1
34,191,678,301,980
null
172
172
n,x,m = map(int, input().split()) be = x % m ans = be memo = [[0,0] for i in range(m)] am = [be] memo[be-1] = [1,0] #len-1 for i in range(n-1): be = be**2 % m if be == 0: break elif memo[be-1][0] == 1: kazu = memo[be-1][1] l = len(am) - kazu syou = (n-i-1) // l amari = (n-i-1)%l sum = 0 for k in range(kazu, len(am)): sum += am[k] ans = ans + syou*sum if amari > 0: for j in range(kazu,kazu + amari): ans += am[j] break else: ans += be am.append(be) memo[be-1][0] = 1 memo[be-1][1] = len(am) -1 print(ans)
import string import sys table = {c: 0 for c in string.ascii_lowercase} for raw in sys.stdin.read(): c = raw.lower() if c in string.ascii_lowercase: table[c] += 1 for key in string.ascii_lowercase: print('{:s} : {:d}'.format(key, table[key]))
0
null
2,246,300,248,192
75
63
import collections N,*S = open(0).read().split() C = collections.Counter(S) i = C.most_common()[0][1] print(*sorted([k for k,v in C.most_common() if v == i]), sep='\n')
from operator import * li = [] for s in input().split(): if s.isdigit(): li.append(int(s)) else: b = li.pop() a = li.pop() li.append({"+":add, "-":sub, "*":mul}[s](a, b)) print(li[-1])
0
null
34,932,735,994,958
218
18
A, B = list(map(int,input().split())) if A - 2 * B >= 0: print(A - 2 * B) else: print(0)
A,B = map(int,input().split()) print(A - 2*B if A > 2*B else 0)
1
166,231,797,561,180
null
291
291
def d(x): dl=[] for i in range(1, int(x**0.5)+1): if x%i==0: dl.append(i) if i!=x//i: dl.append(x//i) return dl n=int(input()) ans=0 t=d(n) for i in t: if i==1: continue tn=n while tn>=i: if tn%i==0: tn//=i else: tn%=i if tn==1: ans+=1 ans+=len(d(n-1))-1 print(ans)
def find_divisors(n): divisors = set() div = 1 while div ** 2 <= n: if n % div == 0: divisors.add(div) divisors.add(n // div) div += 1 return divisors def main(): n = int(input()) res = 0 for k in find_divisors(n) - {1}: t = n while t % k == 0: t //= k if t % k == 1: res += 1 res += len(find_divisors(n - 1)) - 1 print(res) main()
1
41,252,215,482,048
null
183
183
# -*- coding: utf-8 -*- def main(): import sys input = sys.stdin.readline x = int(input()) print(10 - x // 200) if __name__ == '__main__': main()
s = input() if len(s) == 1: print(0) exit() ans = 0 for i in range(len(s)//2): if s[i] != s[(-1)*(i+1)]: ans += 1 else: pass print(ans)
0
null
63,808,409,643,648
100
261
s=input() for i in range(len(s)): print('x',end='')
S = input() l = len(S) a = '' for i in range(len(S)): a = a + 'x' print(a)
1
72,545,853,655,070
null
221
221
def main(): n = input() A = [] s = [] B = [[0,0] for i in xrange(n)] for i in xrange(n): A.append(map(int,raw_input().split())) color = [-1]*n d = [0]*n f = [0]*n t = 0 for i in xrange(n): if color[i] == -1: t = dfs(i,t,color,d,f,A,n) for i in xrange(n): print i+1, d[i], f[i] def dfs(u,t,color,d,f,A,n): t += 1 color[u] = 0 d[u] = t for i in A[u][2:]: if (color[i-1] == -1): t = dfs(i-1,t,color,d,f,A,n) color[u] = 1 t += 1 f[u] = t return t if __name__ == '__main__': main()
INF = 10**10 def merge(ary, left, mid, right): lry = ary[left:mid] rry = ary[mid:right] lry.append(INF) rry.append(INF) i = 0 j = 0 for k in range(left, right): if lry[i] <= rry[j]: ary[k] = lry[i] i += 1 else: ary[k] = rry[j] j += 1 return right - left def merge_sort(ary, left, right): cnt = 0 if left + 1 < right: mid = (left + right) // 2 cnt += merge_sort(ary, left, mid) cnt += merge_sort(ary, mid, right) cnt += merge(ary, left, mid, right) return cnt if __name__ == '__main__': n = int(input()) ary = [int(_) for _ in input().split()] cnt = merge_sort(ary, 0, n) print(*ary) print(cnt)
0
null
57,357,673,828
8
26
A = list(map(int, input().split())) if sum(A) < 22: print("win") else: print("bust")
a = list(map(int, input().split())) sum_a = sum(a) if sum_a >= 22: print('bust') else: print('win')
1
118,236,948,432,928
null
260
260
while 1: x, y = map(int, raw_input().split()) if x == 0 and y == 0: break if x > y: print "%d %d" % (y, x) else: print "%d %d" % (x, y)
while True: x,y = map(int, input().split()) if not x and not y: break else: if x > y: print(y,x) else: print(x,y)
1
532,320,945,710
null
43
43
N = int(input()) if N % 2 == 1: print(0) exit() ans = 0 N //= 2 i = 1 while N >= 5 ** i: ans += (N // 5 ** i) i += 1 print(ans)
n = int(input()); dict = {} for i in range(n): s = input(); if not s in dict: dict[s] = 1 sum = 0 for i in dict: sum += 1 print(sum)
0
null
73,173,029,424,780
258
165