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
def main(): A, B, C = map(int, input().split()) K = int(input()) while K > 0 and A >= B: B *= 2 K -= 1 while K > 0 and B >= C: C *= 2 K -= 1 if A < B < C: print("Yes") else: print("No") if __name__ == "__main__": main()
a,b,c = map(int,input().split()) k = int(input()) for i in range(k): if(a >= b): b*=2 continue if(b >= c): c*=2 continue if(a<b and b<c): print("Yes") exit() else: print("No")
1
6,881,136,691,562
null
101
101
def main(): s = input() n = int(input()) for i in range(n): cmds = input().split(' ') if 'reverse' == cmds[0]: a = int(cmds[1]) b = int(cmds[2])+1 s = s[:a]+''.join(reversed(s[a:b]))+s[b:] if 'replace' == cmds[0]: a = int(cmds[1]) b = int(cmds[2])+1 res = cmds[3] s = s[:a]+res+s[b:] if 'print' == cmds[0]: a = int(cmds[1]) b = int(cmds[2])+1 print(s[a:b]) if __name__ == '__main__': main()
str=input() n=int(input()) for i in range(n): s=input().split() a=int(s[1]) b=int(s[2]) if s[0] == 'replace': str=str[:a]+s[3]+str[b+1:] elif s[0] == 'reverse': str=str[:a]+str[a:b+1][::-1]+str[b+1:] else: print(str[a:b+1])
1
2,095,737,952,322
null
68
68
MAX_A = 10**6 + 1 is_prim = [True] * MAX_A is_prim[0] = is_prim[1] = False for i in range(2, MAX_A): if not is_prim[i]: continue for j in range(i+i, MAX_A, i): is_prim[j] = False def solve(): C = [0] * MAX_A for a in A: C[a] += 1 pairwise = True for p in [i for i in range(MAX_A) if is_prim[i]]: if sum(C[p::p]) > 1: pairwise = False if pairwise: return 'pairwise' from math import gcd g = 0 for a in A: g = gcd(g, a) if g == 1: return 'setwise' return 'not' n = int(input()) A = [*map(int, input().split())] print(solve(), 'coprime')
N = int(input()) A = list(map(int, input().split())) B = [0 for i in range(max(A)+1)] for i in range(2, len(B)): if B[i] != 0: continue for j in range(i, len(B), i): B[j] = i def func(X): buf = set() while X>1: x = B[X] buf.add(x) while X%x==0: X = X//x #print(buf) return buf set1 = func(A[0]) set2 = func(A[0]) totallen = len(set1) for a in A[1:]: set3 = func(a) totallen += len(set3) #print(a, set1, set2) set1 |= set3 set2 &= set3 #print(set1, set2, set3) #print(totallen, set1, set2) if len(set2)!=0: print("not coprime") elif len(set1)==totallen: print("pairwise coprime") else: print("setwise coprime")
1
4,096,367,686,532
null
85
85
n = input() a = n[-1] if a in '3': print('bon') elif a in '0168': print('pon') else: print('hon')
"""AtCoder.""" n = int(input()[-1]) s = None if n in (2, 4, 5, 7, 9): s = 'hon' elif n in (0, 1, 6, 8): s = 'pon' elif n in (3,): s = 'bon' print(s)
1
19,146,737,868,520
null
142
142
N=int(input()) DP=[] DP.append(1) DP.append(1) for i in range(2,N+1): DP.append(DP[i-1]+DP[i-2]) print(DP[N])
def run_length(data, init=''): length = [] tmp = init cnt = 0 for c in data: if tmp != c: length.append(cnt) cnt = 0 tmp = c cnt += 1 length.append(cnt) return length def resolve(): s = input() if s[0] != '<': s = '<' + s if s[-1] != '>': s = s + '>' array = run_length(s) ans = 0 for i in range(1, len(array), 2): a,b = array[i], array[i+1] mn = min(a,b) - 1 mx = max(a,b) ans += (mn+1) * (mn) // 2 + mx * (mx+1) // 2 # print(a,b, (mn+1) * (mn) // 2 + mx * (mx+1) // 2) # print(array) print(ans) if __name__ == "__main__": resolve()
0
null
77,942,782,374,632
7
285
# B - Substring S = str(input()) T = str(input()) s = len(S) t = len(T) ans = 10**18 for i in range(s-t+1): tmp = 0 for j in range(t): if S[i+j] == T[j]: continue else: tmp += 1 ans = min(ans, tmp) print(ans)
s = input() t = input() ans = len(t) for i in range(len(s) - len(t) + 1): tmp = s[i:i+len(t)] count = 0 for t1, t2 in zip(tmp, t): if t1 != t2: count += 1 ans = min(ans, count) print(ans)
1
3,676,173,729,968
null
82
82
x = int(input()) r = 100 ans = 0 while r < x: r = int(r * 101)//100 ans += 1 print(ans)
X = int(input()) money = 100 y = 0 while True: money = 101 * money // 100 # print(money) y += 1 if money >= X: print(y) break
1
27,099,268,101,440
null
159
159
N=int(input()) def cf(n): a=[] for f in range(1,int(n**(1/2)+1)): if n%f==0: a.append(f) if n//f!=f: a.append(n//f) return a def pf(n): a=[] while n%2==0: a.append(2) n//=2 f=3 while f*f<=n: if n%f==0: a.append(f) n//=f else: f+=2 if n!=1: a.append(n) return sorted(a) def main(): c,p,t=1,N+1,1 for f in pf(N-1): if p==f: t+=1 else: c*=t t=2 p=f c=c*t-1 for f in cf(N): t=N if f!=1: while t%f==0: t//=f if t%f==1: c+=1 print(c) main()
print('NYoe s'['AAA'<input()<'BBB'::2])
0
null
48,031,646,193,970
183
201
s=list(input()) t=list(input()) ans=[] for i in range(len(s)-len(t)+1): u=s[i:len(t)+i] a=0 for j in range(len(t)): if not t[j-1]==u[j-1]: a=a+1 ans.append(a) print(min(ans))
S = input() T = input() ans = len(S) for i in range(len(S)-len(T)+1): tmp = 0 for j in range(len(T)): if S[i+j] != T[j]: tmp += 1 ans = min(ans, tmp) print(ans)
1
3,675,878,206,812
null
82
82
n = int(input()) l = list(map(int,input().split()))+[0] l.sort(reverse=True) ans = 0 for i in range(n-2): for j in range(i+1,n-1): left = j right = n while right - left > 1: middle = (left + right)//2 if l[i]-l[j] < l[middle]: left = middle else: right = middle ans += (left-j) print(ans)
import bisect n = int(input()) l = list(map(int, input().split())) l = sorted(l) cnt = 0 for i in range(n): for j in range(i+1, n): x = bisect.bisect_left(l, l[i]+l[j]) cnt += x-j-1 print(cnt)
1
171,585,170,200,818
null
294
294
n = int(input()) a = [int(i) for i in input().split()] summ = 0 for i in range(n): summ += a[i] a.sort() print(str(a[0])+" "+str(a[n-1])+" "+str(summ))
n = input() a = map(int, raw_input().split()) min = a[0] max = a[0] sum = 0 for i in range(n): if min > a[i]: min = a[i] if max < a[i]: max = a[i] sum += a[i] print min, max, sum
1
743,397,223,040
null
48
48
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict from fractions import gcd import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): a,b,m = readInts() A = readInts() B = readInts() ans = float('inf') for i in range(m): x,y,c = readInts() x -=1 y -=1 ans = min(ans,A[x] + B[y] - c) # Aの商品の中で1番最小のやつを買うだけでもいいかもしれない # Bの商品の中で1番最小のやつを買うだけでもいいかもしれない ans = min(ans,min(A) + min(B)) print(ans) if __name__ == '__main__': main()
def seekDistance(n,nodes): max_z,min_z = searchMaxAndMinZ(n,nodes) max_w,min_w = searchMaxAndMinW(n,nodes) return max(max_z-min_z,max_w-min_w) def searchMaxAndMinZ(n,nodes): max_z = -1 min_z = 2 * 10 ** 9 for i in range(n): curr_z = nodes[i][0] + nodes[i][1] if(curr_z > max_z): max_z = curr_z if(curr_z < min_z): min_z = curr_z return max_z,min_z def searchMaxAndMinW(n,nodes): max_w = -10**9 min_w = 2 * 10 ** 9 for i in range(n): curr_w = nodes[i][0] - nodes[i][1] if (curr_w > max_w): max_w = curr_w if (curr_w < min_w): min_w = curr_w return max_w, min_w n = int(input()) nodes = [list(map(int,input().split())) for i in range(n)] print(seekDistance(n,nodes))
0
null
28,836,481,723,752
200
80
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n = I() a = LI() memo = [0] * (10**6 + 1) f = defaultdict(int) for i in a: if f[i] > 1: continue f[i] += 1 for j in range(i, 10**6+1, i): memo[j] += 1 ans = 0 for i in a: if memo[i] == 1: ans += 1 print(ans)
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 t1, t2 = list(map(int, sys.stdin.buffer.readline().split())) a1, a2 = list(map(int, sys.stdin.buffer.readline().split())) b1, b2 = list(map(int, sys.stdin.buffer.readline().split())) da1 = t1 * a1 da2 = t2 * a2 db1 = t1 * b1 db2 = t2 * b2 if da1 + da2 > db1 + db2: a1, b1 = b1, a1 a2, b2 = b2, a2 da1, db1 = db1, da1 da2, db2 = db2, da2 # b のほうがはやい # 無限 if da1 + da2 == db1 + db2: print('infinity') exit() # 1回も会わない if da1 < db1: print(0) exit() # t1 で出会う回数 cnt = abs(da1 - db1) / abs(da1 + da2 - db1 - db2) ans = int(cnt) * 2 + 1 if cnt == int(cnt): ans -= 1 print(ans)
0
null
72,758,682,683,804
129
269
#!/usr/bin/env python # coding: utf-8 # In[15]: N = int(input()) # In[16]: ans = 0 if N%2 != 0: print(ans) else: i = 1 while 1: tmp = (5**i)*2 if tmp <= N: ans += N//tmp i += 1 else: break print(ans) # In[ ]:
n = int(input()) if n % 2 == 1: print(0) exit() cnt = 0 x = 1 while n > 5**x: cnt += n//5**x//2 x += 1 print(cnt)
1
115,836,167,974,228
null
258
258
from sys import stdin from math import sqrt x1, y1, x2, y2 = [float(x) for x in stdin.readline().rstrip().split()] print(sqrt((x2-x1)**2 + (y2-y1)**2))
import math px, py, qx, qy = map(float,input().split()) pq = (qx - px) ** 2 + (qy - py) ** 2 print(math.sqrt(pq))
1
159,934,844,640
null
29
29
n,m=map(int,input().split()) g=[[] for i in range(n)] for _ in range(m): a, b = [int(x) for x in input().split()] g[a-1].append(b) g[b-1].append(a) from collections import deque x=[0]*n s=1 for i in range(1,n+1): if x[i-1]==0: x[i-1]=s q=deque([i]) while q: v = q.popleft() for j in g[v-1]: if x[j-1]==0: q.append(j) x[j-1]=s s+=1 print(s-2)
class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if(x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める elif(self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] n,m = map(int,input().split()) uf = UnionFind(n) for i in range(m): a,b = map(int,input().split()) a -= 1 b -= 1 uf.Unite(a,b) s = set() for i in range(n): s.add(uf.Find_Root(i)) print(len(s)-1)
1
2,285,297,610,860
null
70
70
# coding: utf-8 input() s = list(map(int,input().split())) input() t = list(map(int,input().split())) cnt = 0 for i in t: if i in s: cnt += 1 print(cnt)
a=100000 for _ in range(int(input())): a=((a*1.05)//1000+1)*1000 if (a*1.05)%1000 else a*1.05 print(int(a))
0
null
35,563,141,028
22
6
n = int(input()) a_list = [] for _ in range(n): mini_list = [] a = int(input()) for _ in range(a): mini_list.append(list(map(int, input().split()))) a_list.append(mini_list) ans = 0 for i in range(2**n): ans_list = [0]*n cnt=0 while i!=0: ans_list[cnt] = i%2 cnt+=1 i//=2 flg = True for j, syogens in enumerate(a_list): if ans_list[j]==0: pass else: for syogen in syogens: person = syogen[0]-1 status = syogen[1] if ans_list[person] != status: flg=False if flg: ans = max(ans,sum(ans_list)) print(ans)
from itertools import * N = int(input()) H = [] A = [] for i in range(N): for j in range(int(input())): x,y = map(int, input().split()) H+=[[i,x-1,y]] for P in product([0,1],repeat=N): for h in H: if P[h[0]]==1 and P[h[1]]!=h[2]: break else: A+=[sum(P)] print(max(A))
1
121,726,838,215,930
null
262
262
c = 0 while 1: c += 1 t = int(input()) if t==0: break print("Case "+str(c)+":",t)
sum = 0 while 1: x = raw_input() sum = sum + 1 if x == '0': break print 'Case %s: %s' %(sum, x)
1
478,297,491,492
null
42
42
# 10^100のクソデカ数値がクソデカすぎるため、+0,+1..+Nが束になってもいたくも痒くもない # なのでもはや無視していい # 最初の例でいうと、2つ選ぶのは[0,1,2,3]からなので、和のバリエーションは最小値1~最大値5の5つ # 3つ選ぶのは最小値3~最大値6の4つ # 4つ選ぶのは1つ # 毎回最大値と最小値を計算して差+1を加えてやるとできあがり # 計算には数列の和を使う n, k = map(int, input().split()) mod = 10**9 + 7 ans = 1 for i in range(k, n + 1): # 初項0,公差1,末項i-1までの和 min_s = i * (i - 1) // 2 # 初項n+1-i, 公差1, 末項i-1までの和 max_s = i * (2 * (n + 1 - i) + (i - 1)) // 2 ans += max_s - min_s + 1 ans %= mod print(ans)
data=input() x = data.split(" ") tmp=x[2] x[2]=x[1] x[1]=x[0] x[0]=tmp print(x[0],x[1],x[2])
0
null
35,773,212,507,630
170
178
#AC from collections import deque n=int(input()) G=[[]] for i in range(n): G.append(list(map(int,input().split()))[2:]) #bfs(木でないかも) L=[-1]*(n+1) q=deque() L[1]=0 q.append(1) while q: now=q.popleft() L.append(now) for next in G[now]: #探索済み if L[next]>=0: continue #探索予定(なくて良い) #if next in q: # continue q.append(next) L[next]=L[now]+1 for i in range(1,n+1): print(i,L[i])
n = int(raw_input()) graph = [[] for i in range(n)] for i in range(n): entry = map(int,raw_input().strip().split(' ')) u = entry[0]-1 for v in entry[2:]: v -= 1 graph[u].append(v) d = [-1 for i in range(n)] d[0] = 0 t = 1 q = [] q.append(0) while len(q) > 0: u = q[0] for v in graph[u]: if d[v] == -1: q.append(v) d[v] = d[u]+1 del q[0] for i in range(n): print i+1,d[i]
1
4,270,489,330
null
9
9
def Binary_Search_Small_Count(A,x,equal=False,sort=False): """2分探索によって,x未満の要素の個数を調べる. A:リスト x:調べる要素 sort:ソートをする必要があるかどうか(Trueで必要) equal:Trueのときはx"未満"がx"以下"になる """ if sort: A.sort() if A[0]>x or ((not equal) and A[0]==x): return 0 L,R=0,len(A) while R-L>1: C=L+(R-L)//2 if A[C]<x or (equal and A[C]==x): L=C else: R=C return L+1 def Binary_Search_Equal_Count(A,x,sort=False): """2分探索によって,xの個数を調べる. A:リスト x:調べる要素 sort:ソートをする必要があるかどうか(Trueで必要) equal:Trueのときはx"を超える"がx"以上"になる """ if sort: A.sort() if x<A[0] or A[-1]<x: return 0 X=Binary_Search_Small_Count(A,x,equal=True) Y=Binary_Search_Small_Count(A,x,equal=False) return X-Y #================================================ N=int(input()) A=["*"]+list(map(int,input().split())) B=[0]*N for j in range(1,N+1): B[j-1]=j-A[j] B.sort() K=0 del A[0] for i in range(1,N+1): K+=Binary_Search_Equal_Count(B,i+A[i-1],False) print(K)
N = int(input()) a = b = 1 while N: a, b = b, a+b N -= 1 print(a)
0
null
13,121,724,169,124
157
7
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) xyc= [list(map(int, input().split())) for _ in range(M)] minmoney = min(a) + min(b) for obj in xyc: summoney = a[obj[0] - 1] + b[obj[1] - 1] - obj[2] minmoney = min(minmoney, summoney) print(minmoney)
A, B, M = map(int,input().split()) A = [a for a in map(int,input().split())] B = [b for b in map(int,input().split())] C = [] for m in range(M): C.append([c for c in map(int,input().split())]) ans = min(A) + min(B) for c in C: if (A[c[0]-1]+B[c[1]-1]-c[2])<ans: ans = A[c[0]-1]+B[c[1]-1]-c[2] print(ans)
1
53,708,965,052,064
null
200
200
N, K = map(int, input().split()) p=list(map(int,input().split())) for i in range(N): p[i]=(1+p[i])/2 ans=[0]*(N-K+1) ans[0]=sum(p[:K]) for i in range(1, N-K+1): ans[i]=ans[i-1]-p[i-1]+p[i+K-1] print(max(ans))
import sys # \n def input(): return sys.stdin.readline().rstrip() def main(): N,K=map(int,input().split()) A=list(map(int,input().split())) current = sum(A[:K]) ans =(current+K)/2 for i in range(1,N-K+1): current = current - A[i-1] + A[i+K-1] ans = max(ans, (current+K)/2 ) print(ans) if __name__ == "__main__": main()
1
74,982,206,475,682
null
223
223
# -*- coding: utf-8 -*- import sys from itertools import accumulate read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, K = map(int, readline().split()) P = [0] + list(map(int,readline().split())) C = [0] + list(map(int,readline().split())) ans = -10 ** 10 for i in range(1,N+1): l = 1 j = P[i] s = C[j] ans = max(ans, s) #iを始まりとして while j != i: # 1周期もしないときの最大値 j = P[j] s += C[j] l += 1 if K >= l: ans = max(ans, s) c = 1 j = P[j] t = C[j] ans = max(ans, t + ((K - c) // l) * s) # 1回と周期分 while j != i: j = P[j] t += C[j] c += 1 if K >= c: ans = max(ans, t + ((K - c) // l) * s) # c回と周期分 print(ans)
a, b, m = map(int, input().split()) list_a = list(map(int, input().split())) list_b = list(map(int, input().split())) total = min(list_a) + min(list_b) for i in range(m): x, y, c = map(int, input().split()) price = list_a[x - 1] + list_b[y - 1] - c total = min(price, total) print(total)
0
null
29,742,401,652,070
93
200
a,b = input().split() A = (a*int(b)) B = (b*int(a)) if A < B: print(A) else: print(B)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): a, b = map(int, readline().split()) print(str(min(a, b)) * max(a, b)) if __name__ == '__main__': main()
1
84,117,792,843,722
null
232
232
from collections import deque H, W = map(int, input().split()) L = [] for _ in range(H): s = input() a = [] for i in range(len(s)): a.append(s[i]) L.append(a) dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] def bfs(x, y): dp = [[10000000] * W for _ in range(H)] dp[y][x] = 0 if L[y][x] == '#': return dp else: d = deque() d.append([x, y]) while len(d) > 0: s = d.popleft() for i in range(4): if (s[1] + dy[i] >= 0 and s[1] + dy[i] < H and s[0] + dx[i] >= 0 and s[0] + dx[i] < W): if L[s[1] + dy[i]][s[0] + dx[i]] == '.' and dp[s[1] + dy[i]][s[0] + dx[i]] == 10000000: d.append([s[0] + dx[i], s[1] + dy[i]]) dp[s[1] + dy[i]][s[0] + dx[i]] = dp[s[1]][s[0]] + 1 return dp max_num = 0 for i in range(H): for j in range(W): dp = bfs(j, i) for k in dp: for p in k: if (p == 10000000): continue max_num = max(max_num, p) print(max_num)
n = int(input()) s = input() cnt = 0 for i in range(len(s)): if s[i] == "A" and i+2 <= len(s)-1: if s[i+1] == "B": if s[i+2] == "C": cnt += 1 print(cnt)
0
null
96,865,925,587,802
241
245
n=int(raw_input()) i=1 print "", while i<=n: x=i if x%3==0: print i, else: while x: if x%10==3: print i, break x/=10 i+=1
n = int(input()) result = [] for i in range(3, n+1): if i % 3 == 0 or '3' in str(i): result.append(i) print(" ", end="") print(*result)
1
916,272,575,426
null
52
52
x=int(input()) a=0 while True: for b in range(10**3): if a**5-b**5==x: print(a,b) exit() elif a**5+b**5==x: print(a,-b) exit() elif -a**5+b**5==x: print(-a,-b) exit() a+=1
import sys x = int(input()) box = [a**5 for a in range(0,200)] for i in range(200): for j in range(200): if box[i] - box[j] == x: print(i,j) sys.exit() for k in range(200): for l in range(200): if (-1)*box[k] + box[l] == x: print(-(k),-(l)) sys.exit() for s in range(200): for t in range(200): if box[s] + box[t] == x: print(s,-(t)) sys.exit()
1
25,739,373,625,908
null
156
156
r = list(map(float, input().split())) print('{0:f}'.format(((r[2] - r[0]) ** 2 + (r[3] - r[1]) ** 2) ** 0.5))
x = raw_input() print(str(int(x) ** 3))
0
null
218,055,179,860
29
35
from collections import Counter s = input() n = len(s) dp = [0] mod = 2019 a = 0 for i in range(n): a = a + int(s[n-i-1]) * pow(10, i, mod) a %= mod dp.append(a%mod) ans = 0 c = Counter(dp) for value in c.values(): ans += value * (value-1) / 2 print(int(ans))
#coding:utf-8 buff = [int(x) for x in input().split()] a = buff[0] b = buff[1] c = buff[2] print(len([x for x in [x+a for x in range(b - a + 1)] if c%x==0]))
0
null
15,683,817,467,994
166
44
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ???????????? ???????????????????¨???????????????????????????????????????????????¨???°????????°??????????????°??????????¨???°???????¨??????§?????? ????????°????????¬?????????????¨??????§?¨???°???????????°??? (1+2)*(5+4) ?????? ???????????????????¨??????§??? 1 2 + 5 4 + * ??¨?¨???°??????????????? ???????????????????¨??????§?????????????¨??????§????????¨????????¬??§???????????§???????????¨???????????????????????????????????? ???????????????????¨??????§?????????????????°???????¨???????????????????????????????????????? """ # ????????? INP = list(input().strip().split()) TMP = [] res = 0 for i in INP: if i == "+": b = TMP.pop() a = TMP.pop() TMP.append(a + b) # print("{} - {} = {}".format(a,b,a+b)) elif i == "-": b = TMP.pop() a = TMP.pop() TMP.append(a - b) # print("{} - {} = {}".format(a,b,a-b)) elif i == "*": b = TMP.pop() a = TMP.pop() TMP.append(a * b) # print("{} * {} = {}".format(a,b,a*b)) else: TMP.append(int(i)) print(TMP.pop())
a = list(input().split()) n = len(a) s = [] for i in a: if i=="+": a = s.pop() b = s.pop() s.append(b + a) elif i=="-": a = s.pop() b = s.pop() s.append(b - a) elif i=="*": a = s.pop() b = s.pop() s.append(b * a) else: s.append(int(i)) print(s[0])
1
37,685,688,708
null
18
18
a , b , k = map(int,input().split()) if k - a >= b: a = 0 b = 0 elif k >= a and k - a < b: k -= a a = 0 b -= k - a else: a -= k print(a, b)
A,B,K = map(int,input().split()) if A>=K: answer = A-K,B elif A+B>=K: answer = 0,B-(K-A) else: answer = 0,0 print(answer[0],answer[1])
1
104,719,601,470,660
null
249
249
N = input().strip() INFTY = 10**8 dp = [[INFTY for _ in range(2)] for _ in range(len(N)+1)] a = int(N[-1]) for i in range(10): if i<a: dp[1][1] = min(dp[1][1],i+10-a) else: dp[1][0] = min(dp[1][0],i+i-a) for k in range(2,len(N)+1): a = int(N[-k]) for i in range(10): if i>=a: dp[k][0] = min(dp[k][0],dp[k-1][0]+i+i-a) if i-1>=a: dp[k][0] = min(dp[k][0],dp[k-1][1]+i+i-1-a) if i<a: dp[k][1] = min(dp[k][1],dp[k-1][0]+i+10-a) if i==0: dp[k][1] = min(dp[k][1],dp[k-1][1]+9-a) if 0<=i-1<a: dp[k][1] = min(dp[k][1],dp[k-1][1]+i+10-a+i-1) print(min(dp[len(N)][0],dp[len(N)][1]+1))
S = input() S = list(S) N = len(S) count = 0 for i in range(N//2): if S[i] != S[(N-1)-i]: S[i] = S[(N-1)-i] count += 1 print(count)
0
null
95,369,666,123,762
219
261
data=str(input("")).split(" ") D=int(data[0]) T=int(data[1]) S=int(data[2]) if D<=T*S: print("Yes") else: print("No")
import sys # A - Don't be late D, T, S = map(int, input().split()) if S * T >= D: print('Yes') else: print('No')
1
3,562,274,662,620
null
81
81
n,k,c=map(int,input().split()) ; c+=1 s=input() A=[i+1 for i in range(n) if s[i]=="o"] #働ける日付 L=[1 for i in range(k)] #働く日数[l] はL[l]以降 R=[n for i in range(k)] #L[l]以前 import bisect for i in range(1,k): L[i]= A[bisect.bisect_left(A,L[i-1]+c)] R[-i-1]= A[bisect.bisect_right(A,R[-i]-c)-1] for i in range(k): if L[i]==R[i]: print(L[i])
n = int(input()) a = list(map(int, input().split())) a.sort() m = a[-1] c = [0] * (m + 1) for ai in a: for i in range(ai, m + 1, ai): c[i] += 1 ans = 0 for ai in a: if c[ai] == 1: ans += c[ai] print(ans)
0
null
27,690,048,243,958
182
129
x = int(input()) a = 360 for _ in range(360): if a%x == 0: print(a//x) break else: a += 360
X = int(input()) cnt = 0 x = 0 while True: x += X cnt += 1 if x % 360 == 0: print(cnt) exit()
1
13,170,944,398,656
null
125
125
N = int(input()) table = [[int(i) for i in input().split()] for N in range(N)] a = -1 b = 10**10 c = -10**10 d = 10**10 for i in range(N): p = table[i][0] q = table[i][1] if a < p+q: a = p+q if b > p+q: b = p+q if c < p-q: c = p-q if d > p-q: d = p-q print(max(a-b,c-d))
H, W = map(int, input().split()) total = H*W if H == 1 or W == 1: ans = 1 elif total % 2 == 0: ans = total//2 else: total += 1 ans = total//2 print(ans)
0
null
27,074,999,591,366
80
196
# ABC 147 D N=int(input()) A=list(map(int,input().split())) res=0 p=10**9+7 bits=[0]*71 for a in A: j=0 while a>>j: if (a>>j)&1: bits[j]+=1 j+=1 t=0 n=70 while n>=0: if bits[n]!=0: break n-=1 for a in A: j=0 while j<=n: if (a>>j)&1: res+=((2**j)*(N-bits[j]))%p else: res+=((2**j)*bits[j])%p j+=1 t=res print((res*500000004)%p)
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) ans = 0 MOD = 10**9+7 for i in range(63): one, zero = 0, 0 for Aj in A: if (Aj>>i)&1: one += 1 else: zero += 1 ans += 2**i*one*zero ans %= MOD print(ans)
1
122,843,645,788,150
null
263
263
# coding: utf-8 a = int(input()) b = int(input()) if a + b == 3: print("3") elif a + b == 4: print("2") else: print("1")
x = int(input()) h = x // 3600 m = (x -h*3600)//60 s = x - h*3600 - m*60 print(h, ':',m , ':', s, sep="")
0
null
55,491,684,715,898
254
37
# B Popular Vote N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse = True) border = sum(A) / (4 * M) cnt = 0 for a in A: if a >= border: cnt += 1 else: break if cnt >= M: print("Yes") else: print("No")
T=input() N=len(T) l=[] for i in range(N): if T[i]=="?": l.append("D") else: l.append(T[i]) ans="" for i in range(N): ans+=l[i] print(ans)
0
null
28,635,319,664,344
179
140
n = int(raw_input()) a = 1 b = 1 for i in range(n-1): tmp = a a = b b += tmp print b
def memolize(f): cache = {} def helper(x): if x not in cache: cache[x] = f(x) return cache[x] return helper @memolize def fib(n): if n == 0: return 1 elif n == 1: return 1 return fib(n - 1) + fib(n - 2) n = int(input()) print(fib(n))
1
1,821,756,060
null
7
7
def powmod(x, n,mod): if n == 0: return 1 K = 1 while n > 1: if n % 2 != 0: K = K * x%mod x = x ** 2%mod n = (n - 1) // 2 else: x = x ** 2%mod n = n // 2%mod return K * x # 指数を割り続け n が 1 に至ったら終了 N,K = map(int,input().split()) mod=10**9+7 ans=[0]*(K+1) for i in range(K): b=int(K/(K-i)) if b==1: ans[K-i]+=1 else: ans[K-i]+=powmod(b, N,mod) ans[K-i]%=mod for j in range(b-1): ans[K-i]-= ans[(K-i)*(j+2)] ans[K-i]%=mod c=0 for i in range(K+1): c+=ans[i]*i c%=mod print(c)
N, S = map(int, input().split()) A = list(map(int, input().split())) mod = 998244353 dp = [[0 for j in range(S+1)] for i in range(N+1)] dp[0][0] = 1 for i in range(N): for j in range(S+1): dp[i+1][j] += 2*dp[i][j] 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[N][S])
0
null
27,051,237,918,620
176
138
while True: [h,w] = map(int,input().split()) if h==0 and w ==0: break print(('#'*w + '\n')*h)
while True: hw = [int(x) for x in input().split()] h, w = hw[0], hw[1] if h == 0 and w == 0: break for hh in range(h): for ww in range(w): print('#', end = '') print('') print('')
1
775,588,276,760
null
49
49
n, m, k = map(int, input().split()) a_books = [int(i) for i in input().split()] b_books = [int(i) for i in input().split()] time = 0 count = 0 for i in range(n): time += a_books[i] if time > k: time -= a_books[i] i -= 1 break count += 1 for j in range(m): time += b_books[j] if time > k: time -= b_books[j] j -= 1 break count += 1 max_count = count #print(max_count, time) while j < m and i >= 0: time -= a_books[i] i -= 1 count -= 1 j += 1 while j < m: time += b_books[j] if time > k: time -= b_books[j] j -= 1 break count += 1 j += 1 if count > max_count: max_count = count #print(count, time) #print(max_count) print(max_count)
d,t,s=map(int,input().split()) print("YNeos"[s*t<d::2])
0
null
7,148,264,738,472
117
81
N,K = map(int,input().split()) h = [int(i) for i in input().split()] ans = 0 for i in range(N): if(h[i] >= K): ans += 1 print(ans)
#!/usr/bin/env python3 N, K = [int(s) for s in input().split()] h = [int(s) for s in input().split()] print(len(list(filter(lambda x: x >= K, h))))
1
178,509,447,838,880
null
298
298
def main(): n = int(input()) S = list(map(int,input().split())) q = int(input()) T = list(map(int,input().split())) cnt = 0 S.sort() for i in range(n): if i == 0: if S[i] in T: cnt += 1 continue if (S[i] in T) and (S[i] != S[i-1]): cnt += 1 return cnt print(main())
n=int(input()) S=input().split(' ') q=int(input()) T=input().split(' ') def equal_element(S,T): m=0 for i in range(len(T)): for j in range(len(S)): if S[j]==T[i]: m+=1 break return(m) print(equal_element(S,T))
1
67,070,938,998
null
22
22
def insertionSort(A, n, g, cnt): for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v return [cnt, A] def shellSort(A, n): cnt = 0 a = 1 G = [] while a <= n: G.append(a) a = 3*a + 1 m = len(G) G = G[::-1] for i in range(0, m): cnt, A = insertionSort(A, n, G[i], cnt) return [m, G, cnt, A] if __name__ == "__main__": n = int(input()) A = [int(input()) for _ in range(n)] m, G, cnt, A = shellSort(A, n) print(m) print(*G) print(cnt) for i in A: print(i)
def insertion_sort(a, g, cnt): for i in range(g, len(a)): v = a[i] j = i - g while j >= 0 and a[j] > v: a[j+g] = a[j] j = j - g cnt += 1 a[j+g] = v return cnt n = int(input()) g = [1] t = 1 cnt = 0 while 1: t = 3 * t + 1 if t < n and len(g) < 100: g += [t] else: g = g[::-1] break a = [int(input()) for _ in range(n)] for i in range(0, len(g)): cnt = insertion_sort(a, g[i], cnt) print(len(g)) print(*g) print(cnt) for i in a: print(i)
1
29,918,734,508
null
17
17
l = int(input()) print((l/3)**3)
N = int(input()) A = list(map(int, input().split())) m = 1000000007 result = 0 for i in range(60): j = 1 << i c = sum((a & j) >> i for a in A) result += (c * (N - c)) << i result %= m print(result)
0
null
85,297,032,150,428
191
263
#coding:utf-8 #1_3_B from collections import deque n, quantum = map(int, input().split()) q = deque() total_time = 0 for i in range(n): name, time = input().split() q.append([name, int(time)]) while q: ps_name, ps_time = q.popleft() if ps_time <= quantum: total_time += ps_time print(ps_name, total_time) else: total_time += quantum ps_time -= quantum q.append([ps_name, ps_time])
table = [[ 0 for i in range(13)] for j in range(4)] n = int(input()) i = 0 while i < n: s,num = input().split() num = int(num) if s == "S": table[0][num-1] = 1 elif s == "H": table[1][num-1] = 1 elif s == "C": table[2][num-1] = 1 else: # D table[3][num-1] = 1 i += 1 for i,elem_i in enumerate(table): for j,elem_j in enumerate(elem_i): if elem_j ==1: continue if i == 0: s_str='S' elif i == 1: s_str='H' elif i == 2: s_str='C' else: s_str='D' print (s_str + " " + str(j+1))
0
null
534,090,963,956
19
54
h,n=map(int,input().split()) INF=10**18 dp=[INF]*(h+1) dp[0]=0 for _ in range(n): a,b=map(int,input().split()) for i in range(h+1): dp[min(i+a,h)]=min(dp[min(i+a,h)],dp[i]+b) print(dp[h])
def main(): n, k = map(int, input().split()) MOD = 10**9 + 7 a = [0]*(k+1) for i in range(1, k+1): a[i] = pow(k//i, n, MOD) for i in reversed(range(1, k+1)): for j in range(2*i, k+1, i): a[i] -= a[j] a[i] %= MOD ans = 0 for i in range(1, k+1): ans += a[i]*i ans %= MOD print(ans) if __name__ == "__main__": main()
0
null
58,889,416,786,922
229
176
def main(): # import sys # readline = sys.stdin.readline # readlines = sys.stdin.readlines N = int(input()) A = [(a, i) for i, a in enumerate(map(int, input().split()))] A.sort(reverse=True) dp = [[-float('inf')] * (N + 1) for _ in range(N + 1)] dp[0][0] = 0 for k in range(N): for i in range(k + 1): j = k - i here = dp[i][j] a, idx = A[k] dp[i + 1][j] = max(dp[i + 1][j], here + a * ((N - 1 - i) - idx)) dp[i][j + 1] = max(dp[i][j + 1], here + a * (idx - j)) # print(k, i) ans = 0 for i in range(N + 1): j = N - i ans = max(ans, dp[i][j]) print(ans) if __name__ == "__main__": main()
n = int(input()) a = list(map(int, input().split())) a = list(enumerate(a)) a.sort(key = lambda x: x[1]) DP = [[0 for i in range(n+1)] for j in range(n+1)] DP[0][0] = 0 for i in range(1, n+1): pos, val = a.pop() pos = pos + 1 DP[0][i] = DP[0][i-1] + abs(val * (n - i + 1 - pos)) DP[i][0] = DP[i-1][0] + abs(val * (pos - i)) for x in range(1, i): y = i - x DP[x][y] = max(DP[x-1][y] + abs(val * (pos - x)), \ DP[x][y-1] + abs(val * (n - y + 1 - pos))) ans = 0 for i in range(n+1): ans = max(ans, DP[i][n-i]) print(ans)
1
33,848,471,668,568
null
171
171
N=input() n=N[-1] if n=='3': ans='bon' elif n=='0' or n=='1' or n=='6' or n=='8': ans='pon' else: ans='hon' print(ans)
def Qa(): n = input() if n[-1] in ['2', '4', '5', '7', '9']: print('hon') elif n[-1] in ['0', '1', '6', '8']: print('pon') else: print('bon') if __name__ == '__main__': Qa()
1
19,317,771,906,550
null
142
142
while True: a,b = list(map(int, input().split())) if (a == 0) and (b == 0): break elif (a < b): print(str(a) + " " + str(b)) else : print(str(b) + " " + str(a))
l=raw_input() k=l.split() k.sort() f=0 # while f==0: a=int(k[0]) b=int(k[1]) if a==b==0: break else: if a<b: print a,b else: print b,a l=raw_input() k=l.split() k.sort()
1
523,401,527,064
null
43
43
N,M,K = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) a_sum = [0 for i in range(N+1)] for i in range(N): a_sum[i+1] = a_sum[i] + A[i] b_sum = [0 for i in range(M+1)] for i in range(M): b_sum[i+1] = b_sum[i] + B[i] ans = 0 for i in range(N+1): t = a_sum[i] l = 0 r = len(b_sum) while(l+1<r): c = (l+r)//2 if t+b_sum[c]<=K: l = c else: r = c if a_sum[i]+b_sum[l]<=K: ans = max(ans,i+l) print(ans)
N, M, K = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) min = 0 cnt = 0 for k in b: min += k j = M for i in range(N+1): while(j > 0 and min > K): j -= 1 min -= b[j] if(min > K): break cnt = max(cnt, i + j) if(i == N): break min += a[i] print(cnt)
1
10,686,743,648,910
null
117
117
T=input() for i in range(len(T)): T=T.replace(T[i],'x') print(T)
s = list(input()) print("x"*len(s))
1
72,654,509,106,332
null
221
221
from itertools import accumulate def LS(): return list(input().split()) N = int(input()) title = [] time = [] for _ in range(N): s, t = LS() time.append(int(t)) title.append(s) time.append(0) Tsum = list(accumulate(time)) X = input() for i in range(N): if title[i] == X: break print(Tsum[N]-Tsum[i])
N=input() total=0 for i in N: total += int(i) print('Yes' if total % 9 == 0 else 'No')
0
null
50,852,741,813,060
243
87
R,G,B=map(int,input().split()) K=int(input()) M=0 while R>=G or G>=B: if R>=G: G*=2 M+=1 if G>=B: B*=2 M+=1 if M<=K: print('Yes') else: print('No')
from math import sqrt while True: input_data =[] # ????´?????????? alpha = 0 # ?????? num = int(input()) if num == 0: break input_data = [float(i) for i in input().split()] m = sum(input_data) / float(num) for i in range(num): alpha += (input_data[i] - m)**2 print(sqrt(alpha/num))
0
null
3,576,309,724,614
101
31
def main(): altitude_lis = [] for i in range(10): input_line = raw_input() altitude = int(input_line) altitude_lis.append(altitude) altitude_lis.sort() altitude_lis.reverse() for i in range(3): print(altitude_lis[i]) if __name__ == '__main__': main()
a=[] for i in range(10): a.append(input()) a.sort() a=a[::-1] a=a[:3] print(a[0]) print(a[1]) print(a[2])
1
34,179,520
null
2
2
K, X = input().split() K = int(K) X = int(X) if 500*K >= X: print("Yes") else: print("No")
S = input() L = len(S) INF = float('inf') dp = [[INF]*(L+1) for _ in range(2)] dp[0][0] = 0 for i in range(L): d = int(S[-1-i]) dp[0][i+1] = min(dp[0][i], dp[1][i]) + d dp[1][i+1] = min(dp[0][i] + 10-d+1, dp[1][i] + 10-d-1) print(min(dp[0][-1], dp[1][-1]))
0
null
84,781,975,527,500
244
219
import Queue n,q=map(int,raw_input().strip().split()) name=[] time=[] qu=Queue.Queue() class task: def __init__(self,name,time): self.name=name self.time=time self.total=0 for i in xrange(n): inp=raw_input().strip().split() qu.put(task(inp[0],int(inp[1]))) curtime=0 while not qu.empty(): tmp=qu.get() if tmp.time>q: tmp.time-=q curtime+=q qu.put(tmp) else: curtime+=tmp.time ed='' if qu.qsize()==0 else '\n' print tmp.name,curtime # print curtime
from collections import deque if __name__ == '__main__': n, q = map(int, input().split()) Q = deque() for i in range(n): name, time = input().split() Q.append([name, int(time)]) sum = 0 while Q: qt = Q.popleft() if qt[1] <= q: sum += qt[1] print(qt[0], sum) else: sum += q qt[1] -= q Q.append(qt)
1
39,981,692,672
null
19
19
def main(): s = input() ans="" for i in range(0,len(s)): ans+='x' print(ans) main()
S = input() result = '' for _ in S: result += 'x' print(result)
1
72,917,929,492,422
null
221
221
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**20 MOD = 1000000007 def I(): return int(input()) def F(): return float(input()) def S(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def resolve(): N = I() A = LI() # color_number[i][j]: [0, i)でj番目に多い色の人数 color_number = [[0, 0, 0] for _ in range(N)] for i in range(N-1): if A[i] in color_number[i]: idx = color_number[i].index(A[i]) else: idx = -1 for j in range(3): if j==idx: color_number[i+1][j] = color_number[i][j] + 1 else: color_number[i+1][j] = color_number[i][j] ans = 1 for i in range(N): ans *= color_number[i].count(A[i]) ans %= MOD print(ans) if __name__ == '__main__': resolve()
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) A = list(map(int, input().split())) res = 1 cnt = [3 if i == 0 else 0 for i in range(n + 1)] for a in A: res = res * cnt[a] % mod cnt[a] -= 1 cnt[a + 1] += 1 print(res) if __name__ == '__main__': resolve()
1
130,128,672,882,490
null
268
268
k=int(input()) s=list(input()) if len(s)<=k: print("".join(s)) else: s_short="" for i in range(k): s_short+=s[i] print((s_short+"..."))
K = int(input()) S = input() i = 0 string = "" if len(S) > K: while i < K: string += S[i] i += 1 print(string + "...") else: print(S)
1
19,771,594,717,980
null
143
143
k,x = [int(i) for i in input().split(' ')] print('Yes') if(500*k >= x) else print('No')
n=int(input()) arr=list(map(int,input().split())) if n<=3: print(max(arr)) exit() lim=n%2+2 dp=[[0]*lim for _ in range(n+1)] for i in range(n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) if lim==3: dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i]) print(max(dp[-1][:lim]))
0
null
68,009,412,867,068
244
177
import math a,b,c = map(float, input().split()) cc = math.radians(c) h = b * math.sin(cc) S = a * h / 2 L = a + b + math.sqrt(h**2 + (a-b*math.cos(cc))**2) print("{0:.10f}\n{1:.10f}\n{2:.10f}\n".format(S, L, h))
n = int(input()) A = [int(j) for j in input().split()] q = int(input()) m = [int(j) for j in input().split()] total = [] for i in range(2**n): bag = [] for j in range(n): if ((i>>j)&1): bag.append(A[j]) total.append(sum(bag)) for m1 in m: if m1 in set(total): print('yes') else: print('no')
0
null
140,960,890,266
30
25
import sys import math from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)] # Nの素因数分解を辞書で返す def prime_fact(n): root = int(math.sqrt(n)) prime_dict = {} for i in range(2, root+1): cnt = 0 while n % i == 0: cnt += 1 n = n // i if cnt: prime_dict[i] = cnt if n != 1: prime_dict[n] = 1 return prime_dict def main(): N = NI() A = NLI() L = {} primes_a = {} for a in A: prime_a = prime_fact(a) primes_a[a] = prime_a for p, n in prime_a.items(): L.setdefault(p, 0) L[p] = max(L[p], n) ans = 0 l = 1 for p, n in L.items(): l = l * pow(p, n, MOD) % MOD for i, a in enumerate(A): ans += l * pow(a, MOD-2, MOD) % MOD print(ans % MOD) if __name__ == "__main__": main()
from functools import reduce from fractions import gcd mod = 10**9 + 7 n, *A = map(int, open(0).read().split()) if len(A) == 1: print(1) else: l = reduce(lambda x, y: x*y // gcd(x, y), A) % mod s = 0 for a in A: s += l * pow(a, mod-2, mod) s %= mod print(s)
1
87,810,020,569,948
null
235
235
def main(): """"ここに今までのコード""" H = int(input()) Count, atk = 1,1 while H > atk * 2 - 1: atk = atk * 2 Count = Count * 2 + 1 print(Count) if __name__ == '__main__': main()
from collections import defaultdict class Tree: def __init__(self, n, edges, weight=False): self.n = n self.adj = [[] for _ in range(n)] self.parent = [-1] * self.n self.children = [[] for _ in range(self.n)] self.dist = [-1] * self.n # 根からの距離 self.depth = [-1] * self.n # 根からの深さ(cost=1での距離) self.weight = defaultdict(lambda: 10**18) if weight: for u, v, weight in edges: self.adj[u].append(v) self.adj[v].append(u) self.weight[(u, v)] = weight self.weight[(v, u)] = weight else: for u, v in edges: self.adj[u].append(v) self.adj[v].append(u) self.weight[(u, v)] = 1 self.weight[(v, u)] = 1 def set_root(self, root): # O(n) self.root = root self.order = [root] self.dist[root] = 0 self.depth[root] = 0 stack = [root] while stack: v = stack.pop() for child in self.adj[v]: if child == self.parent[v]: continue else: self.parent[child] = v self.children[v].append(child) self.dist[child] = self.dist[v] + self.weight[(v, child)] self.depth[child] = self.depth[v] + 1 self.order.append(child) stack.append(child) def get_root_path(self, target): path = [target] v = target while v != self.root: path.append(self.parent[v]) v = self.parent[v] path.reverse() return path def get_diameter(self, restore=False): # double-sweepで求める O(n) u = self.dist.index(max(self.dist)) # 根から一番遠いものを根とし、そこから一番遠いものを見つける dist_u = [-1] * self.n dist_u[u] = 0 stack = [u] parent_u = [None for _ in range(self.n)] while stack: v = stack.pop() for child in self.adj[v]: if dist_u[child] == -1: dist_u[child] = dist_u[v] + self.weight[(v, child)] parent_u[child] = v stack.append(child) diameter = max(dist_u) v = dist_u.index(diameter) if restore: path = [v] while v != u: v = parent_u[v] path.append(v) path.reverse() # [u,...,v] return diameter, path else: return diameter, u, v # --- Heavy Light Decomposition --- # def heavy_light_decompose(self): # O(n) self.subsize = [1] * self.n # 部分木の要素数(自分含む) self.head = [self.root] * self.n # 分割された各部分木の先頭 self.tree_order = [0] * self.n # 末端の方から各頂点の部分木の要素数(subsize)を計算していって、 # heavy-nodeがchildren[v][0]に来るようにする for v in reversed(self.order): v_kids = self.children[v] # 名前が長いのでalias for i, child in enumerate(v_kids): self.subsize[v] += self.subsize[child] if self.subsize[child] > self.subsize[v_kids[0]]: v_kids[i], v_kids[0] = v_kids[0], v_kids[i] # それぞれのnodeについて分割されたchianの先頭(head)を記録 # また、DFSの行きがけ順をtree_orderとする headの浅い順でchainが入る stack = [self.root] tree_label = 0 while stack: v = stack.pop() self.tree_order[v] = tree_label tree_label += 1 for child in reversed(self.children[v]): # スタックを使ったdfsのため逆にしておく if child == self.children[v][0]: self.head[child] = self.head[v] else: self.head[child] = child # light-nodeは切り離されたsub-treeのheadになる stack.append(child) def get_hld_chain_paths(self, u, v): # (u,v)間の経路をchainごとに返す [l,r) ret = [] while True: if self.tree_order[u] > self.tree_order[v]: u, v = v, u if self.head[u] == self.head[v]: ret.append((self.tree_order[u], self.tree_order[v] + 1)) return ret else: ret.append((self.tree_order[self.head[v]], self.tree_order[v] + 1)) v = self.parent[self.head[v]] def get_hld_lca(self, u, v): # Lowest Common Ancestor while True: # head[u] = head[v] になるまで遡る if self.tree_order[u] > self.tree_order[v]: u, v = v, u if self.head[u] == self.head[v]: return u v = self.parent[self.head[v]] def get_hld_distance(self, u, v): return self.dist[u] + self.dist[v] - (2 * self.dist[self.get_hld_lca(u, v)]) def exist_on_path_hld(self, u, v, x): # u,v間の最短経路上にxがあるかどうか return self.get_hld_distance(u, x) + self.get_hld_distance(x, v) == self.get_hld_distance(u, v) # ---------------------- # n, u, v = (int(x) for x in input().split()) u -= 1 v -= 1 edges = [tuple(int(x) - 1 for x in input().split()) for _ in range(n - 1)] tree = Tree(n, edges) tree.set_root(0) tree.heavy_light_decompose() ans = 0 for i in range(n): if tree.get_hld_distance(i, u) <= tree.get_hld_distance(i, v): ans = max(ans, tree.get_hld_distance(i, v) - 1) print(ans)
0
null
99,251,401,061,670
228
259
import math K = int(input()) S = 0 for a in range(1, K+1): for b in range(1, K+1): T = math.gcd(a, b) for c in range(1, K+1): S += math.gcd(T, c) print(S)
A=input();print(sum(i!=j for i,j in zip(A,A[::-1]))//2)
0
null
77,942,632,279,072
174
261
n ,q = map(int, input().split()) ntlist = [] for i in range(n): nt = list(map(str, input().split())) ntlist.append(nt) tp = 0 while (len(ntlist)): nt = ntlist.pop(0) if (int(nt[1])> q): nt[1] = int(nt[1]) - q tp += q ntlist.append(nt) else: tp += int(nt[1]) nt[1] = 0 print(nt[0], tp)
class queue(): def __init__(self): self.head = 0 self.tail = 0 self.MAX = 100000 self.Q = [[0] for i in range(self.MAX)] def is_empty(self): return self.head == self.tail def is_full(self): return self.head == (self.tail + 1) % self.MAX def enqueue(self, x): if self.is_full(): raise ValueError("エラー(オーバーフロー)") self.Q[self.tail] = x if self.tail + 1 == self.MAX: self.tail = 0 else: self.tail += 1 def dequeue(self): if self.is_empty(): raise ValueError("エラー(アンダーフロー)") x = self.Q[self.head] if self.head + 1 == self.MAX: self.head = 0 else: self.head += 1 return x n, q = input().split(" ") n = int(n) q = int(q) q_name = queue() q_val = queue() for i in range(n): name, t = input().split(" ") t = int(t) q_name.enqueue(name) q_val.enqueue(t) results = [] end_time = 0 while True: process_val = q_val.dequeue() process_name = q_name.dequeue() if process_val <= q: end_time += process_val results.append([process_name, end_time]) else: end_time += q rest_val = process_val - q q_name.enqueue(process_name) q_val.enqueue(rest_val) if q_val.head == q_val.tail: break for v in results: print("{} {}".format(v[0],v[1]))
1
41,913,248,388
null
19
19
import bisect n = int(input()) a = list(map(int,input().split())) # ni - nj = ai + aj (i>j) # ai - ni = - aj - nj a1 = sorted([a[i] - (i+1) for i in range(n)]) a2 = sorted([- a[i] - (i+1) for i in range(n)]) ans = 0 for i in range(n): left = bisect.bisect_left(a2, a1[i]) right = bisect.bisect_right(a2, a1[i]) ans += (right - left) print(ans)
S=input() l=len(S) X='x'*l X=str(X) print(X)
0
null
49,575,752,888,110
157
221
K=int(input()) S=input() l=[] if len(S)<=K: print(S) else: for i in range(K): l.append(S[i]) print("".join(l)+'...')
K=int(input()) S=input() if len(S) <= K : print(S) else: print(S[:K]+'...',end='')
1
19,571,910,040,342
null
143
143
N = int(input()) total = 0 for n in range(1, N+1): total += N//n * (n + N - N%n)//2 print(total)
n = int(input()) ans=0 for j in range(1,n+1): y = n//j ans += y*(y+1)*j//2 print(ans)
1
11,069,939,292,580
null
118
118
N = int(input()) S = [] for _ in range(N): S.append(input()) ans = set(S) print(len(ans))
def main(): N,M=map(int,input().split()) if N%2!=0: for i in range(1,M+1): print(i,N-i+1) else: for i in range(1,(M+1)//2+1): print(i,N-i+1) for i in range((M+1)//2+1,M+1): print(i,N-i) if __name__=='__main__': main()
0
null
29,225,822,191,148
165
162
def f():return map(int,raw_input().split()) n,m,l=f() A = [f() for _ in [0]*n] B = [f() for _ in [0]*m] C = [[0 for _ in [0]*l] for _ in [0]*n] for i in range(n): for j in range(l): print sum([A[i][k]*B[k][j] for k in range(m)]), print
from collections import deque D1 = {i:chr(i+96) for i in range(1,27)} D2 = {val:key for key,val in D1.items()} N = int(input()) heap = deque([(D1[1],1)]) A = [] while heap: a,n = heap.popleft() if n<N: imax = 0 for i in range(len(a)): imax = max(imax,D2[a[i]]) for i in range(1,min(imax+1,26)+1): heap.append((a+D1[i],n+1)) if n==N: A.append(a) A = sorted(list(set(A))) for i in range(len(A)): print(A[i])
0
null
26,825,733,604,640
60
198
from sys import stdin N = int(stdin.readline().rstrip()) if N % 2 == 0: print(N//2-1) else: print(N//2)
import collections n, m = map(int, input().split()) linked = collections.defaultdict(list) i2group = dict() gid = n + 1 def get_root(i): if i not in linked: return i j = get_root(linked[i]) linked[i] = j return j def get_groups(): return [get_root(i) for i in range(1, n + 1)] for i in range(m): a, b = map(int, input().split()) ra, rb = get_root(a), get_root(b) if ra == rb: continue linked[ra] = gid linked[rb] = gid gid += 1 g = get_groups() print(len(set(g)) - 1) exit() n_connected = 0 n_group = 0 for s in linked.values(): s = s[0] if s: n_group += 1 n_connected += len(s) s.clear() print((n - n_connected) + (n_group - 1))
0
null
77,990,888,467,608
283
70
import numpy as np N=int(input()) A=np.array(list(map(int,input().split()))) B=np.sum(A)-np.cumsum(np.append(0, A[:len(A)-1])) v=0 k=0 for i in range(N+1): if i==0: if N==0 and A[0]==1: k=1 elif A[0]==0: k=1 else: print(-1) break elif i==N: if B[i]<=2*(k-A[i-1]): k=B[i] else: k=0 print(-1) break else: k=min(2*(k-A[i-1]),B[i]) if k<=0: print(-1) break v+=k if k>0: print(v)
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) leaf = sum(A) ans = 0 node = 1 for i in range(N+1): if A[i] > node or leaf == 0: ans = -1 break ans += node leaf -= A[i] node = min(2*(node-A[i]), leaf) print(ans)
1
18,765,204,233,436
null
141
141
from math import sqrt import itertools N = int(input()) dis = [input().split() for i in range(N)] lst = [x for x in range(N)] p_lst = list(itertools.permutations(lst)) ans = 0 for i in p_lst: for j in range(N-1): ans += sqrt((int(dis[i[j]][0]) - int(dis[i[j+1]][0]))**2 + (int(dis[i[j]][1]) - int(dis[i[j+1]][1]))**2) print(ans/len(p_lst))
import math N = int(input()) x = [] y = [] for i in range(N): tmp = input().split(" ") x.append(int(tmp[0])) y.append(int(tmp[1])) d = 0 for i in range(N): for j in range(N): d += math.sqrt((x[j]-x[i]) ** 2 + (y[j]-y[i]) ** 2) print(d/N)
1
148,244,883,918,506
null
280
280
import sys import collections X = int(input()) Angle = 360 for i in range(1,10**9): if Angle < (X*i): Angle = Angle + 360 if (Angle / (X*i)) == 1: print(i) sys.exit()
X = int(input()) ret = 0 cur = 0 while True: ret += 1 cur += X if cur % 360 == 0: print(ret) break
1
13,013,507,754,492
null
125
125
n, m = map(int, input().split()) from collections import deque l = deque([i for i in range(1, n + 1)]) if n % 2 ==0: for i in range(1, m + 1): a, b = l.popleft(), l.pop() if (b - a) == n / 2 or (len(l) < n // 2 and (b-a) % 2 == 1): b = l.pop() print(a, b) else: for i in range(1, m + 1): print(i, n - i)
def prime_numbers(n): cnds = [True] * n for x in xrange(2, int(n**0.5 + 1)): if cnds[x]: for m in xrange(2*x, n, x): cnds[m] = False return [i for i in xrange(2, n) if cnds[i]] def is_prime(n): return all(n % m for m in primes if m < n) primes = prime_numbers(10**4) N = input() print sum(is_prime(input()) for i in range(N))
0
null
14,337,519,240,512
162
12
def main(): N, S = map(int, input().split()) A = list(map(int, input().split())) return solve(N, S, A) def solve(N, S, A): mod = 998244353 dp = [0] * (S + 1) dp[0] = pow(2, N, mod) div2 = pow(2, mod - 2, mod) m = 0 for a in A: m += a for i in reversed(range(a, min(S, m) + 1)): dp[i] = (dp[i] + dp[i - a] * div2) % mod return dp[S] print(main())
k = int(input()) x = 7 % k for i in range(1, k+1): if x == 0: print(i) exit() x = (x*10+7)%k print(-1)
0
null
11,794,104,645,888
138
97
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): N, R = map(int, input().split()) if N < 10: ans = R + 100 * (10 - N) else: ans = R print(ans) if __name__ == '__main__': solve()
import sys sys.setrecursionlimit(10**7) 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 LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N,R = MI() print(R if N >= 10 else R+100*(10-N))
1
63,541,396,373,440
null
211
211
def main(): n, k = map(int, input().split()) p_lst = list(map(int, input().split())) lst = [] for i in range(n): lst.append((p_lst[i] + 1) / 2) tmp_sum = sum(lst[:k]) maximum = tmp_sum for i in range(n - k): tmp_sum -= lst[i] tmp_sum += lst[i + k] maximum = max(maximum, tmp_sum) print(maximum) if __name__ == '__main__': main()
s = input() k = int(input()) ren = [] n = 1 p = s[0] for i in range(1,len(s)): if p == s[i]: n += 1 else: ren.append(n) p = s[i] n = 1 ren.append(n) ans = 0 if ren[0] == len(s): ans = (ren[0]*k)//2 elif s[0] == s[-1]: ans = ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2 ren[0] += ren[-1] ren[-1] = 0 for i in ren: ans += (i//2)*k else: for i in ren: ans += (i//2)*k print(ans)
0
null
125,558,484,728,630
223
296
import sys SUITS = ('S', 'H', 'C', 'D') cards = {suit:{i for i in range(1, 14)} for suit in SUITS} n = input() # 読み捨て for line in sys.stdin: suit, number = line.split() cards[suit].discard(int(number)) for suit in SUITS: for i in cards[suit]: print(suit, i)
# ABC149 # A Blackjack A = list(map(int, input().split())) a = sum(A) if a > 21: print("bust") else: print("win")
0
null
59,898,159,462,948
54
260
N = int(input()) a_list = list(map(int, input().split())) c = 0 for i in range(N-1): minj = i for j in range(i+1, N): if a_list[j] < a_list[minj]: minj = j if a_list[i] != a_list[minj]: a_list[i], a_list[minj] = a_list[minj], a_list[i] c += 1 print(' '.join(map(str, a_list))) print(c)
def selection(A,n): count = 0 for i in range(0,n-1): min = i for j in range(i,n): if(A[j] < A[min]): min = j if(min!=i): A[i], A[min] = A[min], A[i] count+=1 printList(A) print(count) def printList(A): print(" ".join(str(x) for x in A)) n = int(input()) A = [int(x) for x in input().split()] selection(A,n)
1
21,619,644,420
null
15
15
import itertools n = int(input()) tes = [[] for _ in range(n)] for i in range(n): a = int(input()) for _ in range(a): x, y = map(int, input().split()) tes[i].append([x - 1, y]) ans = 0 for tf_s in itertools.product(range(2), repeat = n): for i in range(n): if tf_s[i] == 0: continue for x, y in tes[i]: if tf_s[x] != y: break else: continue break else: ans = max(ans, tf_s.count(1)) print(ans)
import sys A, B, K = map(int, input().split()) if A >= K: A -= K print(A, B) sys.exit(0) else: K -= A if B >= K: B -= K print(0, B) sys.exit(0) else: print(0, 0)
0
null
112,990,531,367,652
262
249
def main(): import sys def input(): return sys.stdin.readline().rstrip() a,b,c = map(int, input().split()) import numpy as np if c-a-b >=0 and (c-a-b)**2-4*a*b > 0: print('Yes') else: print('No') if __name__ == '__main__': main()
# coding: utf-8 # Your code here! import math def main(): A, B = input().split() B = int(B.replace(".","")) ans = int(A) * B // 100 print(ans) main()
0
null
34,244,228,560,892
197
135
s = input() h = 'hi' if s == h or s == h * 2 or s == h * 3 or s == h * 4 or s == h * 5: print('Yes') else: print('No')
s = "hi" S = input() flag = False for i in range(5): if S==s: flag=True break s = s+"hi" if flag: print("Yes") else: print("No")
1
53,357,374,706,402
null
199
199
input_line = input() input_line_cubic = input_line ** 3 print input_line_cubic
print("win" if sum(map(int,input().split()))<=21 else "bust")
0
null
59,403,002,799,360
35
260
n = input() n = int(n) x = raw_input() x_list = x.split() x_list = map(int, x_list) max = x_list[0] min = x_list[0] sum = x_list[0] for i in range(1, n): if max < x_list[i]: max = x_list[i] elif min > x_list[i]: min = x_list[i] sum += x_list[i] print("%d %d %d" %(min, max, sum))
n = int(input()) l = list(map(int,input().split())) mini = min(l) maxi = max(l) sums = 0 for i in range(0,n): sums = sums + int(l[i]) print(f"{mini} {maxi} {sums}")
1
735,158,359,598
null
48
48
N,M = map(int,input().split()) num_AC,num_WA = 0,0 res = [list(input().split()) for i in range(M)] check = ['v']*N WA_check = [0]*N for i,j in res: i = int(i) if check[i-1] == 'v': if j == 'WA': WA_check[i-1] += 1 if j == 'AC': num_AC += 1 num_WA += WA_check[i-1] check[i-1] = '.' print(num_AC,num_WA)
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n,m = inpm() P = [] S = [] for i in range(m): tmp = input().split() P.append(int(tmp[0])) S.append(tmp[1]) AC = [0]*100001 WA = [0]*100001 for i in range(m): if S[i] == 'AC': AC[P[i]] = 1 elif S[i] == 'WA' and AC[P[i]] != 1: WA[P[i]] += 1 cnt_ac = 0 cnt_wa = 0 for i in range(1,n+1): if AC[i] == 1: cnt_ac += 1 cnt_wa += WA[i] print(cnt_ac,cnt_wa)
1
93,281,023,930,040
null
240
240
a,b,c = map(int,input().split()) ab= (a*b)*4 C= (c-a-b)**2 if c-a-b>=0: if ab<C: print("Yes") else : print("No") else : print("No")
line = input() data = line.split() import math a =int(data[0]) b =int(data[1]) c =int(data[2]) if c-a-b>0: if(-a-b+c)*(-a-b+c) >a*b*4: print("Yes") else: print("No") else: print("No")
1
51,771,546,560,292
null
197
197
#coding:UTF-8 import copy n = map(int,raw_input().split()) if n[0]<n[1]<n[2]: print "Yes" else: print "No"
x = input() split_x = x.split() a = int(split_x[0]) b = int(split_x[1]) c = int(split_x[2]) if a < b < c: print("Yes") else: print("No")
1
393,330,100,630
null
39
39
import numpy as np n=int(input()) d_i = list(map(int, input().split())) d=np.array(d_i) out=0 for i in range(1,n): a=d_i.pop(0) d_i.append(a) out+=np.dot(d,np.array(d_i)) print(int(out/2))
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) d = list(map(int, input().split())) ans = (sum(d)**2 - sum(item**2 for item in d))//2 print(ans)
1
168,095,779,689,890
null
292
292
import math while True: n = int(input()); if n == 0: break; A = list(map(int, input().split())); h = sum(A) / len(A); k = 0; for j in range(0,n): k += (A[j] - h)**2; print(math.sqrt(k/n));
a=1 while True: i = input() if i==0: break else : print "Case %d: %d"%(a,i) a+=1
0
null
335,456,970,770
31
42
from itertools import accumulate mod = 10**9 + 7 n, k = map(int, input().split()) arr = [] for i in range(n+1): arr.append(i) ls = [0] + list(accumulate(arr)) ans = 0 for i in range(k, n+2): ans += (((ls[-1] - ls[-1-i]) - ls[i]) + 1)%mod ans %= mod print(ans)
while True: t = input() if t.find("?") > 0: break print(int(eval(t)))
0
null
16,812,169,774,360
170
47
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): N=int(input()) A=[] for i in range(N): X,L=map(int,input().split()) A.append([X-L,X+L]) A=sorted(A, key=lambda x: x[1]) cur=-(10**10) cnt=0 for i in range(N): if A[i][0]<cur: continue else: cur=A[i][1] cnt+=1 print(cnt) resolve()
I = input() for i in range(len(I)): if 'a' <= I[i] <= 'z': print(I[i].upper(), end = '') continue if 'A' <= I[i] <= 'Z': print(I[i].lower(), end = '') continue print(I[i], end = '') print()
0
null
45,718,368,257,548
237
61
import itertools n = int(input()) tastes = list(map(int, input().split())) ans_lists = [] for v in itertools.combinations(tastes, 2): cure = v[0]*v[1] ans_lists.append(cure) ans = 0 for i in ans_lists: ans += i print(ans)
N,K=list(map(int,input().split())) A=sorted(list(map(int,input().split()))) F=sorted(list(map(int,input().split())),reverse=True) ok=10**12 ng=0 while abs(ok-ng)>0: center=(ok+ng)//2 cnt=0 for i in range(N): ap=center//F[i] cnt+=max(0,A[i]-ap) if K<cnt: ng=center+1 break else: ok=center print(ok)
0
null
167,008,785,422,688
292
290
import math k = int(input()) ab = [] ans = 0 for a in range(1,k+1): for b in range(1,k+1): if a % b == 0: ab.append(b) elif b % a == 0: ab.append(a) else: ab.append(math.gcd(a, b)) for i in ab: for c in range(1,k+1): if i % c == 0: ans += c elif c % i == 0: ans += i else: ans += math.gcd(i, c) print(ans)
# 10_* class Dice: def __init__(self, label: list): self.top, self.front, self.right, self.left, self.back, self.bottom = label def roll(self, direction: str): if direction == "N": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.front, self.bottom, self.right, self.left, self.top, self.back, ) elif direction == "W": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.right, self.front, self.bottom, self.top, self.back, self.left, ) elif direction == "S": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.back, self.top, self.right, self.left, self.bottom, self.front, ) elif direction == "E": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.left, self.front, self.top, self.bottom, self.back, self.right, ) def output_top(self): print(self.top) def get_top_front(self): return f"{self.top} {self.front}" def print_right(self): print(self.right) # 10_A # (*label,) = map(int, input().split()) # dice = Dice(label) # for i in input(): # dice.roll(i) # dice.output_top() # 10_B (*label,) = map(int, input().split()) dice = Dice(label) q = int(input()) for _ in range(q): t, f = map(int, input().split()) for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2: if f"{t} {f}" == dice.get_top_front(): dice.print_right() break dice.roll(i)
0
null
17,963,605,962,080
174
34
money = int(input()) while money > 1000 : money -= 1000 print(1000 - money)
def resolve(): N = int(input()) print(1000 * ((1000 + (N-1)) // 1000) - N) resolve()
1
8,358,234,840,320
null
108
108