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
l = [1,2,3] A = int(input()) B = int(input()) for i in range(3): if l[i]!=A and l[i]!=B: print(l[i])
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) a = int(input()) b = int(input()) if (a == 1 and b == 2): print(3) elif(a == 1 and b == 3): print(2) elif (a == 2 and b == 1): print(3) elif (a == 2 and b == 3): print(1) elif (a == 3 and b == 1): print(2) elif (a == 3 and b == 2): print(1)
1
110,770,496,325,600
null
254
254
n = int(input()) l = list(map(int,input().split())) p=l[0] s=0 for i in l[1:]: s+= max(0,p-i) p=max(p,i) print(s)
n = int(input()) a = list(map(int,input().split())) max_num = a[0] ans = 0 for i in range(1,n): max_num = max(max_num, a[i]) if max_num != a[i]: ans += (max_num - a[i]) print(ans)
1
4,535,575,325,428
null
88
88
x=input() ret = '' for a in x: if a.islower() : a = a.upper() elif a.isupper(): a = a.lower() ret += a print(ret)
inputa = input() print(inputa.swapcase())
1
1,474,348,862,840
null
61
61
from decimal import Decimal from math import sqrt a, b, c = map(int, input().split()) print('Yes' if Decimal(a).sqrt()+Decimal(b).sqrt() < Decimal(c).sqrt() else 'No')
a,b,c = map(int, raw_input().split(' ')) print 'Yes' if a+b < c and 4*a*b < (c - a - b) **2 else 'No'
1
51,847,672,631,608
null
197
197
a = int(input()) b = int(input()) d = {} d[a] = True d[b] = True for i in range(1, 4): if i not in d: print(i)
ls = [1,2,3] ls.remove(int(input())) ls.remove(int(input())) print(ls[0])
1
110,273,353,146,450
null
254
254
i=0 while True: i+=1 a=input() if a==0: break else: print("Case "+str(i)+": "+str(a))
c = 0 while True: x = int(input()) if x == 0: break; c += 1 print('Case', str(c) + ':', x)
1
482,767,526,560
null
42
42
n,k,s = map(int,input().split()) if s == 10**9: t = 1 else: t = s+1 ls = [t]*n for i in range(k): ls[i] = s print(*ls)
N, K, S = map(int, input().split()) ans = [] n = N-K for i in range(K): ans.append(S) for i in range(n): if S == 10**9: ans.append(S-1) else: ans.append(S+1) ans=[str(a) for a in ans] ans=" ".join(ans) print(ans)
1
90,819,213,647,390
null
238
238
a=input() print(a+"e"*(a[-1]=='s')+'s')
import os,sys s=input() n=len(s) if s[n-1]=='s': s=s+'es' else: s=s+'s' print(s)
1
2,403,446,449,756
null
71
71
N = int(input()) def numalpha(num): if num <= 26: return chr(64+num) elif num % 26 == 0: return numalpha(num//26-1)+chr(90) else: return numalpha(num//26)+chr(64+num%26) print(numalpha(N).lower())
def dp_solver(tmp): l=len(tmp) rev=tmp[::-1]+"0" dp=[[float("inf") for _ in range(2)] for _ in range(l+2)] dp[0][0]=0 for i in range(l+1): for j in range(2): num=int(rev[i]) num+=j if num<10: dp[i+1][0]=min(dp[i+1][0],dp[i][j]+num) if num>0: dp[i+1][1]=min(dp[i+1][1],dp[i][j]+(10-num)) #import numpy as np #dp=np.array(dp) return(dp[l+1]) s=input() ans=dp_solver(s) print(ans[0])
0
null
41,359,532,414,112
121
219
S = int(input()) h = str(S // 3600) m = str((S % 3600) // 60) s = str(((S % 3600) % 60)) print(h + ":" + m + ":" + s)
i = raw_input().strip().split() a = int(i[0]) b = int(i[1]) c = int(i[2]) if a < b and b < c: print "Yes" else: print "No"
0
null
356,989,398,970
37
39
print(float(input()) * 2.0 * 3.141592653589)
n,k = map(int,input().split()) a = list(map(int,input().split())) temp,i = sum(a[:k]),k for _ in range(n-k): score = temp+a[i]-a[i-k] print("Yes" if score>temp else "No") temp = score i+=1
0
null
19,154,097,077,372
167
102
import sys, bisect N = int(input()) L = list(map(int, sys.stdin.readline().rsplit())) L.sort() res = 0 for i in reversed(range(1, N)): for j in reversed(range(i)): l = bisect.bisect_left(L, L[i] + L[j]) # r = bisect.bisect_right(L, abs(L[i] - L[j])) res += l - 1 - i print(res)
import itertools n = int(input()) A = list(map(int,input().split())) A.sort() def binary_search(l,r,v): while r >= l: h = (l+r) // 2 if A[h] < v: l = h+1 else: r = h-1 return r ans = 0 for i in range(n-2): for j in range(i+1,n-1): a = binary_search(j,n-1,A[i]+A[j]) ans += a-j print(ans)
1
172,105,034,275,132
null
294
294
def resolve(): x = int(input()) t = 0 pos = 100 while True: pos += pos // 100 # print(t, pos) t += 1 if pos >= x: break print(t) resolve()
X=int(input()) x=100 ans=0 while x<X: x=101*x//100 ans+=1 print(ans)
1
27,201,177,324,860
null
159
159
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 N = int(readline()) A = list(map(int, readline().split())) lcmnum = 1 def gcd(a, b): if (a == 0): return b return gcd(b%a, a) def lcm(x, y): return (x * y) // gcd(x, y) for a in A: lcmnum = lcm(lcmnum, a) ans = 0 for a in A: a = lcmnum // a ans += a ans %= mod print(ans) if __name__ == '__main__': solve()
from collections import Counter S = input() C = Counter() MOD = 2019 n = 0 for i, s in enumerate(S[::-1]): s = int(s) n += pow(10, i, MOD) * s % MOD C[n % MOD] += 1 C[0] += 1 ans = 0 for v in C.values(): ans += v * (v - 1) // 2 print(ans)
0
null
59,513,390,721,092
235
166
N,K=map(int,input().split()) P=list(map(int,input().split())) from itertools import accumulate acc=[0]+list(accumulate(P)) print((max(b-a for a,b in zip(acc,acc[K:]))+K)/2)
N,K=map(int,input().split()) P=list(map(int,input().split())) X=[] for a in P: X.append(a/2+0.5) gou=sum(X[0:K]) han=-32 saigou=sum(X[N-K:N]) han=saigou for a in range(N-K-1): if gou>han: han=gou gou=gou-X[a]+X[a+K] print(han)
1
74,673,490,260,252
null
223
223
l=[[[0 for i in range(10)]for j in range(3)]for k in range(4)] s='#'*20 n=input() for i in range(n):b,f,r,v=map(int,raw_input().split());l[b-1][f-1][r-1]+=v for i in range(4): for j in range(-3,0):print ' '+' '.join(map(str,l[i][j])) if i<3:print s
from sys import stdin input = stdin.readline from time import time from random import randint from copy import deepcopy start_time = time() def calcScore(t, s, c): scores = [0]*26 lasts = [0]*26 for i in range(1, len(t)): scores[t[i]] += s[i][t[i]] dif = i - lasts[t[i]] scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2 lasts[t[i]] = i for i in range(26): dif = len(t) - lasts[i] scores[i] -= c[i] * dif * (dif-1) // 2 return scores def greedy(c, s): day_lim = len(s) socres = [0]*26 t = [0]*day_lim lasts = [0]*26 for i in range(1, day_lim): pls = [v for v in socres] mns = [v for v in socres] for j in range(26): pls[j] += s[i][j] mns[j] -= c[j] * (i - lasts[j]) sum_mns = sum(mns) pt = sum_mns - mns[0] + pls[0] idx = 0 for j in range(1, 26): tmp = sum_mns - mns[j] + pls[j] if pt < tmp: pt = tmp idx = j t[i] = idx lasts[idx] = i for j in range(26): if j == idx: socres[j] = pls[j] else: socres[j] = mns[j] return socres, t def subGreedy(c, s, t, day): day_lim = len(s) socres = [0]*26 t = [0]*day_lim lasts = [0]*26 for i in range(1, day_lim): if day <= i: pls = [v for v in socres] mns = [v for v in socres] for j in range(26): pls[j] += s[i][j] mns[j] -= c[j] * (i - lasts[j]) sum_mns = sum(mns) pt = sum_mns - mns[0] + pls[0] idx = 0 for j in range(1, 26): tmp = sum_mns - mns[j] + pls[j] if pt < tmp: pt = tmp idx = j t[i] = idx lasts[idx] = i for j in range(26): if j == idx: socres[j] = pls[j] else: socres[j] = mns[j] else: scores[t[i]] += s[i][t[i]] lasts[t[i]] = i for j in range(26): dif = i - lasts[j] scores[j] -= c[j] * dif return socres, t D = int(input()) c = list(map(int, input().split())) s = [[0]*26 for _ in range(D+1)] for i in range(1, D+1): s[i] = list(map(int, input().split())) scores, t = greedy(c, s) sum_score = sum(scores) while time() - start_time < 1.86: typ = randint(1, 100) if typ <= 70: for _ in range(300): tmp_t = deepcopy(t) tmp_t[randint(1, D)] = randint(0, 25) tmp_scores = calcScore(tmp_t, s, c) sum_tmp_score = sum(tmp_scores) if sum_score < sum_tmp_score: sum_score = sum_tmp_score t = deepcopy(tmp_t) scores = deepcopy(tmp_scores) elif typ <= 98: for _ in range(100): tmp_t = deepcopy(t) dist = randint(1, 15) p = randint(1, D-dist) q = p + dist tmp_t[p], tmp_t[q] = tmp_t[q], tmp_t[p] tmp_scores = calcScore(tmp_t, s, c) sum_tmp_score = sum(tmp_scores) if sum_score < sum_tmp_score or randint(1, 100) <= 3: sum_score = sum_tmp_score t = deepcopy(tmp_t) scores = deepcopy(tmp_scores) elif typ <= 100: tmp_t = deepcopy(t) day = randint(D//4*3, D) tmp_scores, tmp_t = subGreedy(c, s, tmp_t, day) sum_tmp_score = sum(tmp_scores) if sum_score < sum_tmp_score: sum_score = sum_tmp_score t = deepcopy(tmp_t) scores = deepcopy(tmp_scores) for v in t[1:]: print(v+1)
0
null
5,367,344,046,010
55
113
x,n=[int(x) for x in input().split()] if n!=0: p=[int(x) for x in input().split()] l=list(range(110)) for i in p: l.remove(i) L=[] for i in l: L.append(abs(i-x)) m=min(L) print(l[L.index(m)]) else: print(x)
n = int(input()) cnt = 0 for i in range(1, n//2+1): if i != n - i and n - i > 0: cnt += 1 print(cnt)
0
null
83,430,476,843,990
128
283
import sys input = sys.stdin.readline def print_ans(X): """Test Case >>> print_ans(30) Yes >>> print_ans(25) No >>> print_ans(35) Yes >>> print_ans(-10) No """ if X >= 30: print('Yes') else: print('No') if __name__ == '__main__': X = int(input().rstrip()) print_ans(X)
temp=int(input()) if temp<30: print('No') else: print('Yes')
1
5,695,276,059,260
null
95
95
import sys def input(): return sys.stdin.readline()[:-1] N,D,A=map(int,input().split()) s=[tuple(map(int, input().split())) for i in range(N)] s.sort() d=2*D+1 t=0 p=0 l=[0]*N a=0 for n,i in enumerate(s): while 1: if t<N and s[t][0]<i[0]+d: t+=1 else: break h=i[1]-p*A if h>0: k=-(-h//A) a+=k p+=k l[t-1]+=k p-=l[n] print(a)
from collections import deque n , d , a = map(int,input().split()) mon = [tuple(map(int,input().split())) for i in range(n)] mon.sort() p = deque(mon) baku = deque() cou = 0 ans = 0 while p: nowx , nowh = p.popleft() while baku: bx , bh = baku.popleft() if bx >= nowx: baku.appendleft((bx,bh)) break elif bx < nowx: cou -= bh if nowh <= cou: continue elif nowh > cou: k = -((-nowh+cou)//a) ans += k cou += a*k baku.append((nowx+2*d,a*k)) print(ans)
1
82,474,170,908,360
null
230
230
#!/usr/bin/env python3 print("x"*len(input()))
import sys N = int(sys.stdin.readline().strip()) X = sys.stdin.readline().strip() def popcount(n): cnt = 0 while n > 0: cnt += n & 1 n //= 2 return cnt def f(n): cnt = 0 while n != 0: n = n % popcount(n) cnt += 1 return cnt #nX = int(X, 2) pcnt = X.count('1') MOD1 = pcnt + 1 MOD2 = pcnt - 1 nXp = 0 nXm = 0 pow1 = [1] * N pow2 = [0] * N for i in range(1, N): pow1[i] = (pow1[i-1] * 2) % MOD1 if MOD2 != 0: pow2[0] = 1 for i in range(1, N): pow2[i] = (pow2[i-1] * 2) % MOD2 for i in range(N): if X[i] == '1': nXp += pow1[N-1-i] nXp %= MOD1 if MOD2 != 0: for i in range(N): if X[i] == '1': nXm += pow2[N-1-i] nXm %= MOD2 for i in range(0, N): if X[i] == '0': k = (nXp + pow1[N-1-i]) % MOD1 print(f(k) + 1) else: if MOD2 == 0: print(0) else: k = (nXm - pow2[N-1-i]) % MOD2 print(f(k) + 1)
0
null
40,466,193,380,702
221
107
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): t1, t2 = map(int, readline().split()) a1, a2 = map(int, readline().split()) b1, b2 = map(int, readline().split()) if a1 < b1: a1, b1 = b1, a1 a2, b2 = b2, a2 if a2 > b2: return print(0) else: d1 = t1 * a1 + t2 * a2 d2 = t1 * b1 + t2 * b2 if d1 == d2: return print("infinity") elif d2 > d1: ans = 1 diff = d2 - d1 x = t1 * (a1 - b1) cnt = x // diff ans += cnt * 2 if x % diff == 0: ans -= 1 return print(ans) else: return print(0) if __name__ == '__main__': main()
import math t1,t2 = map(int, input().split()) c1,c2 = map(int, input().split()) d1,d2 = map(int, input().split()) x = [(c1*t1, c2*t2),(d1*t1, d2*t2)] x.sort(reverse=True) if x[0][0]+x[0][1] == x[1][0]+x[1][1]: print("infinity") elif x[0][0]+x[0][1] > x[1][0]+x[1][1]: print(0) else: n = (x[0][0]-x[1][0]+0.0)/(x[1][0]+x[1][1]-x[0][0]-x[0][1]) m = math.ceil(n) if math.floor(n) == m: print(2*m) else: print(2*m-1)
1
131,677,874,312,698
null
269
269
N = int(input()) S = input() r = S.count("R") g = S.count("G") b = S.count("B") ans = r * g * b for i in range(N): for j in range(i + 1, N): k = 2 * j - i if k < N: if sorted(S[i] + S[j] + S[k]) == ['B', 'G', 'R']: ans -= 1 print(ans)
n = int(input()) ans = 0 for i in range(1,n): for j in range(1,n): if n <= i*j: break else: ans += 1 print(ans)
0
null
19,481,071,709,138
175
73
#!/usr/bin/env python # -*- coding: utf-8 -*- var = int(raw_input()) sum = var*var*var print sum
import sys from collections import Counter def main(): input = sys.stdin.buffer.readline n, x, y = map(int, input().split()) k_cnt = Counter() for i in range(1, n): for j in range(i + 1, n + 1): if i <= x: if j < y: dist = min(j - i, (x - i) + 1 + (y - j)) elif y <= j: dist = (x - i) + 1 + (j - y) elif x < i < y: dist = min(j - i, (i - x) + 1 + abs(j - y)) else: dist = j - i k_cnt[dist] += 1 for i in range(1, n): print(k_cnt[i]) if __name__ == "__main__": main()
0
null
22,318,941,998,500
35
187
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines D = int(readline()) C = list(map(int,readline().split())) score = [] for i in range(D): s = list(map(int,readline().split())) score.append(s) t = list(map(int,read().split())) last = [0] * 26 S = 0 for d in range(D): select = t[d]-1 S += score[d][select] last[select] = d+1 for i in range(26): S -= C[i] * (d+1-last[i]) print(S)
# -*- coding: utf-8 -*- D = int(input()) c = list(map(int, input().split())) s = [] t = [] for i in range(D): s.append(list(map(int, input().split()))) for i in range(D): t.append(int(input()) - 1) last = [0] * 26 ans = 0 for i in range(D): ans = ans + s[i][t[i]] for j in range(26): if t[i] != j: last[j] += 1 ans = ans - (c[j] * last[j]) elif t[i] == j: last[j] = 0 print(ans)
1
9,979,385,848,320
null
114
114
import sys def input(): return sys.stdin.readline()[:-1] def main(): X = int(input()) if X >= 1800: print(1) elif X >= 1600: print(2) elif X >= 1400: print(3) elif X >= 1200: print(4) elif X >= 1000: print(5) elif X >= 800: print(6) elif X >= 600: print(7) else: print(8) if __name__ == "__main__": main()
N = int(input()) L = list(map(int, input().split())) mi = L[0] co = 1 for i in range(1, N): mi = min(L[i], mi) if L[i] == 1: co += 1 break elif mi == L[i]: co += 1 print(co)
0
null
45,857,449,804,032
100
233
n=int(input()) s=input() ans="" for i in range(len(s)): a=(ord(s[i])+n-65)%26 ans=ans+chr(a+65) print(ans)
from sys import stdin A, B = [int(x) for x in stdin.readline().rstrip().split()] if A > 2*B: print(A - 2*B) else: print(0)
0
null
151,246,269,716,838
271
291
import itertools n = int(input()) a = [list(map(int, input().split(" "))) for i in range(n)] ans = 0 for [ix,iy], [jx, jy] in itertools.combinations(a, 2): ans += ((jx-ix)**2+(jy-iy)**2)**0.5*2 print(ans/n)
import math import itertools n = int(input()) l = list(range(n)) pos_list =[list(map(int, input().split())) for _ in range(n)] ans = 0 def clc_distandce(a,b): [x1, y1] = a [x2, y2] = b dist = math.sqrt((a[0] - b[0])**2 + (a[1]-b[1])**2) return dist for i in itertools.permutations(l,n): #print(i) #print(list(i)[0]) for k in range(1,n): dist = clc_distandce(pos_list[list(i)[k]],pos_list[list(i)[k-1]]) ans += dist #print(ans) #print() print(ans/math.factorial(n))
1
148,345,410,873,088
null
280
280
import math k = int(input()) sum_gcd = 0 for a in range(1,k+1): for b in range(1,k+1): for c in range(1,k+1): sum_gcd += math.gcd(math.gcd(a,b) , c) print(sum_gcd)
import sys readline = sys.stdin.readline N,X,Y = map(int,readline().split()) X -= 1 Y -= 1 ans = [0] * N for i in range(N - 1): for j in range(i + 1, N): val = min(abs(i - j),abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X)) ans[val] += 1 for i in range(1, len(ans)): print(ans[i])
0
null
39,993,170,157,010
174
187
A, B, K = map(int, input().split()) Taka = max(A-K, 0) if K <= A: Aoki = B else: Aoki = max(0, B-(K-A)) print(Taka, Aoki)
a, b, k = map(int, input().split()) if a==0 and b==0: print(0, 0) elif k>a: if b-(k-a)>0: print(0, b-(k-a)) else: print(0, 0) elif k<a: print(a-k, b) elif a==k: print(0, b)
1
104,141,342,527,228
null
249
249
N = int(input()) A = [int(i) for i in input().split()] S = [] e = 0 for i in A: e += i S.append(e) ans = 0 for i in range(N-1): ans += A[i]%(10**9+7)*((S[N-1] - S[i])%(10**9+7)) print(ans%(10**9+7))
N = int(input()) print(-(N%-1000))
0
null
6,177,695,681,030
83
108
def func(N): strN = str(N) sum = 0 for s in strN: sum += int(s) return "Yes" if sum % 9 == 0 else "No" if __name__ == "__main__": N = str(input()) print(func(N))
import math n = sum([int(x) for x in str(input()).split()]) a, b = divmod(n, 9) print("No" if b else "Yes")
1
4,354,613,683,498
null
87
87
def main(): n, s = map(int, input().split()) a = list(map(int, input().split())) mod = 998244353 dp = [[0]*(3001) for _ in range(n+1)] dp[0][0] = 1 for i in range(1, n+1): ai = a[i-1] for j in range(ai): dp[i][j] += dp[i-1][j]*2 dp[i][j] %= mod for j in range(ai, 3001): dp[i][j] += dp[i-1][j]*2 + dp[i-1][j-ai] dp[i][j] %= mod print(dp[n][s]) if __name__ == "__main__": main()
import sys readline = sys.stdin.readline S = readline().rstrip() from collections import deque S = deque(S) Q = int(readline()) turn = False for i in range(Q): query = readline().split() if query[0] == "1": turn ^= True elif query[0] == "2": if query[1] == "1": if turn: S.append(query[2]) else: S.appendleft(query[2]) elif query[1] == "2": if turn: S.appendleft(query[2]) else: S.append(query[2]) S = "".join(S) if turn: S = S[::-1] print(S)
0
null
37,481,287,568,900
138
204
inp = int(input()) print(inp**3)
print ((int(raw_input()))**3)
1
287,604,806,710
null
35
35
class UnionFind: par = None def __init__(self, n): self.par = [0] * n def root(self, x): if(self.par[x] == 0): return x else: self.par[x] = self.root(self.par[x]) return self.root(self.par[x]) def unite(self, x, y): if(self.root(x) != self.root(y)): self.par[self.root(x)] = self.root(y) def same(self, x, y): return self.root(x) == self.root(y) N, M = list(map(int, input().split())) UF = UnionFind(N) for i in range(M): A, B = list(map(int, input().split())) UF.unite(A - 1, B - 1) ans = 0 for i in range(N): if(UF.par[i] == 0): ans += 1 print(ans - 1)
import sys sys.setrecursionlimit(10**9) input = sys.stdin.buffer.readline N, M = map(int, input().split()) nextcity = [[] for _ in range(N)] sgn = [0 for _ in range(N)] while M: M -= 1 A, B = map(int, input().split()) A -= 1 B -= 1 nextcity[A].append(B) nextcity[B].append(A) def dfs(cnt, city): for item in nextcity[city]: if sgn[item] == 0: sgn[item] = cnt dfs(cnt, item) return None cnt = 0 for k in range(N): if sgn[k] == 0: cnt += 1 sgn[k] = cnt dfs(cnt, k) print(cnt -1)
1
2,305,410,198,210
null
70
70
n, m = map(int, input().split()) class UnionFind: def __init__(self, n): self.pare = [-1] * n self.size = [1] * n def root(self, x): if self.pare[x] < 0: return x r = self.root(self.pare[x]) self.pare[x] = r return r def unite(self, x, y): rx = self.root(x) ry = self.root(y) if rx == ry: return self.pare[rx] = ry self.size[ry] += self.size[rx] return uf = UnionFind(n) for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 uf.unite(a, b) print(max(uf.size))
s=input() ans='Yes' a=s[0] b=s[1] c=s[2] if a==b and b==c and a==c: ans='No' print(ans)
0
null
29,425,411,275,702
84
201
#!/usr/bin/env python n, m = list(map(int, input().split())) c = list(map(int, input().split())) DP = [n for i in range(n + 1)] DP[0] = 0 for cost in c: for i in range(cost, n + 1): DP[i] = min(DP[i], DP[i - cost] + 1) print(DP[n])
n = int(input().split()[0]) c = list(filter(lambda x:x <= n,map(int,input().split()))) minimum = [ i for i in range(n+1) ] for i in c: minimum[i] = 1 for i in range(2,n+1): for j in c: if j<=i and minimum[i-j] + 1 < minimum[i]: minimum[i] = minimum[i-j]+1 print(minimum[n])
1
139,888,893,452
null
28
28
import math def getDistance(n, x, y, p): temp = 0.0 for i in xrange(n): temp += math.fabs(x[i] - y[i]) ** p # print "temp = " + str(temp) temp2 = 1.0 / p # print temp2 return math.pow(temp, temp2) n = int(raw_input()) x = map(float, raw_input().split(" ")) y = map(float, raw_input().split(" ")) for i in xrange(1, 4): print "{0:.6f}".format(getDistance(n, x, y, i)) max = 0.0 for i in xrange(n): d = math.fabs(x[i] - y[i]) if d > max: max = d print "{0:.6f}".format(max)
n = input() sum_of_digits = 0 for d in n: sum_of_digits += int(d) print('Yes' if sum_of_digits%9 == 0 else 'No')
0
null
2,337,189,459,528
32
87
import sys import math n = input() s = [set(), set(), set(), set()] ch = {0:"S", 1:"H", 2:"C", 3:"D"} for i in xrange(n) : kind, num = raw_input().split() num = int(num) for j in xrange(4) : if (kind == ch[j]) : s[j].add(num) break for i in xrange(4) : for j in xrange(1, 14) : if not(j in s[i]) : print ch[i], j
z = input() d = {} c = 0 L = ['S','H','C','D'] for i in L: for j in range(1,14): d[i] = d.get(i,[]) + [j] while c < z: x = raw_input().split() d[x[0]].remove(int(x[1])) c += 1 for i in L: for j in sorted(d[i]): print i + " " + str(j)
1
1,029,008,257,602
null
54
54
a, b = map(str, input().split()) ans = [a] * int(b) if int(a)<=int(b) else [b] * int(a) print(''.join(ans))
x, y = map(int, input().split()) if y % 2 != 0: print('No') exit() if x*2 <= y <= x*4: print('Yes') else: print('No')
0
null
49,076,739,733,180
232
127
(a, b) = [int(x) for x in input().split()] di = a // b m = a % b df = a / b print('{0} {1} {2:.8f}'.format(di, m, df))
def insert_sort(): n = int(input()) A = [int(x) for x in input().split()] print(*A) for i in range(1,n): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(*A) if __name__ == "__main__": insert_sort()
0
null
294,070,520,292
45
10
M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) print(1 if M1 != M2 else 0)
def g(A,l,m,r): global c L=A[l:m]+[1e10] R=A[m:r]+[1e10] i=j=0 for k in range(l,r): if L[i]<R[j]:A[k]=L[i];i+=1 else:A[k]=R[j];j+=1 c+=1 def s(A,l,r): if l+1<r: m=(l+r)//2 s(A,l,m) s(A,m,r) g(A,l,m,r) c=0 n=int(input()) A=list(map(int,input().split())) s(A,0,n) print(*A) print(c)
0
null
62,495,275,071,548
264
26
n, d = map(int, input().split()) A = [] for i in range(n): A_i = list(map(int, input().split())) A.append(A_i) ans = 0 for j in A: if (j[0] ** 2 + j[1] ** 2) <= d **2 : ans += 1 print(ans)
import math N, D = [int(x) for x in input().split()] Z = [] for i in range(N): Z.append([int(x) for x in input().split()]) ans = 0 for i in range(N): if math.sqrt(Z[i][0]**2 + Z[i][1]**2) <= D: ans += 1 print(ans)
1
5,874,837,753,076
null
96
96
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list(map(lambda x: int(x)-1, input().split())) def II(): return int(input()) def IF(): return float(input()) def LS(): return list(map(list, input().split())) def S(): return list(input().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float('INF') #A def A(): return #B def B(): return #C def C(): return #D def D(): return #E def E(): n, m, l = LI() dist = [[inf] * n for i in range(n)] for _ in range(m): a, b, c = LI_() c += 1 if c > l: continue dist[a][b] = c dist[b][a] = c supply = [[n] * n for i in range(n)] for k in range(n): distk = dist[k] for i in range(n): if i == k: continue disti = dist[i] distik = dist[i][k] for j in range(i + 1, n): if distik + distk[j] < disti[j]: disti[j] = distik + distk[j] dist[j][i] = disti[j] lis = [[] for i in range(n)] for i in range(n): for j in range(i + 1, n): if dist[i][j] <= l: supply[i][j] = 0 supply[j][i] = 0 lis[i].append(j) lis[j].append(i) for i in range(n): q = [] for k in lis[i]: heappush(q, (0, k)) supplyi = supply[i] while q: time, p = heappop(q) for k in lis[p]: if supplyi[k] > time + 1: supplyi[k] = time + 1 heappush(q, (time + 1, k)) q = II() for _ in range(q): s, t = LI_() if dist[s][t] == inf: print(-1) continue else: print(supply[s][t]) return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == '__main__': E()
from scipy.sparse.csgraph import floyd_warshall # ダイクストラを二回行う N, M, L = map(int, input().split()) graph = [[float('inf')]*N for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 graph[a][b] = c graph[b][a] = c graph = floyd_warshall(graph) another = [[float('inf')]*N for _ in range(N)] for i in range(N): for j in range(N): if graph[i][j] <= L: another[i][j] = 1 another = floyd_warshall(another) Q = int(input()) for _ in range(Q): s, t = map(lambda x: int(x)-1, input().split()) if another[s][t] == float('inf'): print(-1) else: print(int(another[s][t])-1)
1
173,182,869,494,940
null
295
295
n = input() x = list(map(int,raw_input().split())) y = list(map(int,raw_input().split())) gap = [] gap1 = 0.0 gap2 = 0.0 gap3 = 0.0 a = 0.0 for i in range(n): gap.append(abs(x[i]-y[i])) for i in range(n): gap1 += gap[i] print gap1 for i in range(n): gap2 += gap[i] ** 2 print pow(gap2,0.5) for i in range(n): gap3 += gap[i] ** 3 print pow(gap3,0.3333333333) print max(gap)
input() X_vec = map(float, input().split()) Y_vec = map(float, input().split()) pair = list(zip(X_vec, Y_vec)) D1 = sum(abs(x-y) for x,y in pair) D2 = (sum((x-y)**2 for x,y in pair)) ** .5 D3 = (sum(abs(x-y)**3 for x,y in pair)) ** (1/3) Dinf = max(abs(x-y) for x,y in pair) print("{0:.6f}\n{1:.6f}\n{2:.6f}\n{3:.6f}\n".format(D1,D2,D3,Dinf))
1
209,006,899,980
null
32
32
a=input() b=a.split() c=list() for d in b: c.append(int(d)) d=sorted(c) print(d[0],d[1],d[2])
list = [] a, b, c = map(list.append, raw_input().split()) list = sorted(list) for i in range(3): print list[i],
1
419,085,796,316
null
40
40
MM = input().split() N = int(MM[0]) K = int(MM[1]) HH = input().split() total = 0 for i in HH: if int(i) >= K: total +=1 print(total)
N, K = map(int, input().split()) l = list(map(int, input().split())) cnt = 0 for i in l: if i >= K: cnt = cnt + 1 print(cnt)
1
179,121,394,990,274
null
298
298
x, k, d = map(int, input().split()) t = min(abs(x)//d, k) u = abs(x)-d*t print(abs(u-d*((k-t)%2)))
a, b = map(int, input().split(" ")) tmp_str = "" if a==b: tmp_str = " == " elif a > b: tmp_str = " > " else: tmp_str = " < " print("a" + tmp_str + "b")
0
null
2,770,580,194,670
92
38
#!/usr/bin/env python3 val1 = input() if int(val1) >= 30: print("Yes") else: print("No")
x = int(input()) if 30 <= x: print("Yes") else: print("No")
1
5,740,082,932,878
null
95
95
n = int(input()) a_list = [int(x) for x in input().split()] a_sum = sum(a_list) m = 10 ** 9 + 7 ans = 0 for i in range(n - 1): a_sum -= a_list[i] ans = (ans + a_list[i] * a_sum) % m print(ans)
N = int(input()) X = list(map(int, input().split())) p = 0 s = sum(X) for n in range(N): s -= X[n] s = s % (10**9 + 7) p += s * X[n] p = p % (10**9 + 7) print(p)
1
3,821,108,730,140
null
83
83
import numpy as np n = int(input()) mod = 10**9 + 7 a = np.array(list(map(int, input().split()))) ans = 0 for i in range(len(bin(max(a)))): num_1 = np.count_nonzero((a>>i)&1) num_0 = n - num_1 ans += (2**i)*(num_1*num_0) % mod ans %= mod print(ans)
def main(): N=int(input()) A=list(map(int,input().split())) mod=10**9+7 ans=0 for i in range(60): c=0 for j in A: if j>>i&1: c+=1 ans+=pow(2,i,mod)*c*(N-c) ans%=mod print(ans) if __name__=='__main__': main()
1
123,040,513,895,530
null
263
263
# coding: utf-8 def getint(): return int(input().rstrip()) def main(): ls = [] num_of_mount = 10 num_of_top = 3 for i in range(num_of_mount): ls.append(getint()) ls.sort(reverse=True) for i in range(num_of_top): print(ls[i]) if __name__ == '__main__': main()
height_list = [] for i in range(10): height_list.append(input()) height_list.sort() height_list.reverse() for height in height_list[:3]: print height
1
15,396,420
null
2
2
s=list(input()) n=len(s) k=int(input()) count=[] i=0 while i<=n-1: j=0 while i+j+1<=n-1 and s[i+j]==s[i+j+1]: j+=1 count.append(j+1) i+=(j+1) length=len(count) if length==1: print((n*k)//2) else: if s[0]==s[-1]: ans=0 for l in range(length): if l!=0 and l!=length-1: ans+=(count[l]//2)*k ans+=(count[0]//2+count[-1]//2) ans+=((count[0]+count[-1])//2)*(k-1) print(ans) else: ans=0 for m in count: ans+=(m//2)*k print(ans)
n = int(input()) dat = [] for _ in range(n): x, l =map(int, input().split()) dat.append([x-l, x+l]) dat.sort(key=lambda x: x[1]) #print(dat) prevr = -99999999999999999 res = 0 for i in range(n): if dat[i][0] >= prevr: prevr = dat[i][1] res += 1 print(res)
0
null
132,625,927,698,508
296
237
from collections import defaultdict h,w,m = map(int,input().split()) dh = defaultdict(int) dw = defaultdict(int) l=defaultdict(tuple) for _ in range(m): x,y = map(int,input().split()) dh[x]+=1 dw[y]+=1 l[(x,y)]=1 m = 0 for i in range(1,h+1): if dh[i]>m: m = dh[i] hi=i c=m m = 0 for i in range(1,w+1): d = dw[i] if l[(hi,i)]==1: d-=1 m = max(m,d) c+=m m = 0 wi=0 for i in range(1,w+1): if dw[i]>m: m = dw[i] wi=i c2=m m = 0 for i in range(1,h+1): d = dh[i] if l[(i,wi)]==1: d-=1 m = max(m,d) c2+=m print(max(c,c2))
from collections import Counter def main(): H, W, M = list(map(int, input().split())) bombs = [list(map(int, input().split())) for _ in range(M)] counter_row = Counter([h for h, _ in bombs]) val_max_row, max_rows = 0, [] for h, v in counter_row.items(): if val_max_row < v: val_max_row = v max_rows = [h] elif val_max_row == v: max_rows.append(h) counter_col = Counter([w for _, w in bombs]) val_max_col, max_cols = 0, [] for w, v in counter_col.items(): if val_max_col < v: val_max_col = v max_cols = [w] elif val_max_col == v: max_cols.append(w) # 基本的には val_max_row + val_max_col が答え。 # 行・列で重複カウントになるケースだった場合はここから1引かないといけない。 max_rows = Counter(max_rows) max_cols = Counter(max_cols) n_max_cells = len(max_rows.keys()) * len(max_cols.keys()) n_cells = 0 for h, w in bombs: if max_rows[h] > 0 and max_cols[w] > 0: n_cells += 1 ans = val_max_row + val_max_col if n_cells >= n_max_cells: ans -= 1 print(ans) if __name__ == '__main__': main()
1
4,754,843,308,960
null
89
89
from itertools import accumulate MAX = 2 * 10 ** 5 + 5 N, M, *A = map(int, open(0).read().split()) B = [0] * MAX for a in A: B[a] += 1 C = list(accumulate(reversed(B)))[::-1] ng, ok = 1, MAX while abs(ok - ng) > 1: m = (ok + ng) // 2 if sum(C[max(0, m - a)] for a in A) >= M: ng = m else: ok = m D = list(accumulate(reversed(list(i * b for i, b in enumerate(B)))))[::-1] print(sum(D[max(0, ng - a)] - (ng - a) * C[max(0, ng - a)] for a in A) + ng * M)
import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(input()) def II(): return map(int, input().split()) def III(): return list(map(int, input().split())) def Line(N,num): if N<=0: return [[] for _ in range(num)] elif num==1: return [I() for _ in range(N)] else: read_all = [tuple(II()) for _ in range(N)] return map(list, zip(*read_all)) ################# import cmath pi = cmath.pi exp = cmath.exp def convolution(a,b): def fft(a,sz,inv=False): tmp = [0]*sz mask = sz-1 p = 0 i = sz>>1 sign = 1 if inv else -1 while i: if p&1: cur,nex = tmp,a else: cur,nex = a,tmp ei = exp(2j*pi*i*sign/sz) w = 1 for j in range(0,sz,i): for k in range(i): nex[j+k] = cur[((j<<1)&mask)+k] + w*cur[(((j<<1)+i)&mask)+k] w *= ei p += 1 i >>= 1 if p&1: a,tmp = tmp,a if inv: a = list(map(lambda x: x/sz, a)) return a sz = 1<<(len(a)+len(b)-2).bit_length() a = a + [0]*(sz-len(a)) b = b + [0]*(sz-len(b)) fa = fft(a,sz) fb = fft(b,sz) fafb = [fai*fbi for fai,fbi in zip(fa,fb)] ab = fft(fafb,sz,inv=True) return [round(x.real) for x in ab[:len(a)+len(b)-1]] N,M = II() A = III() h = [0]*(max(A)) for a in A: h[a-1] += 1 conv = [0,0] + convolution(h,h) ans = 0 for k in range(2,2*max(A)+1)[::-1]: if conv[k]<M: ans += k*conv[k] M -= conv[k] else: ans += k*M break print(ans)
1
108,029,124,334,138
null
252
252
n,k=map(int,input().split()) a=list(map(int,input().split())) dp=[0] mp={0:1} ans=0 for t in range(n): i=a[t] if t>=k-1: mp[dp[-k]]-=1 num=(dp[-1]+i-1)%k if num in mp.keys(): ans += mp[num] mp[num] += 1 else: mp[num] = 1 dp.append(num) print(ans)
import sys, os import collections MOD = 10 ** 9 + 7 def solve(input_stream): N, K = read_ints(input_stream) numbers = [int(i) - 1 for i in input_stream.readline().strip().split()] cumulative_sum = [0 for i in range(N + 1)] mods = {} ans = 0 for index, number in enumerate(numbers): cumulative_sum[index + 1] = (cumulative_sum[index] + number) % K queue = [] for index in range(N+1): if cumulative_sum[index] not in mods: mods[cumulative_sum[index]] = 0 ans += mods[cumulative_sum[index]] mods[cumulative_sum[index]] += 1 queue.append(cumulative_sum[index]) if len(queue) == K: target = queue.pop(0) mods[target] -= 1 return [str(ans)] def read_ints(input_stream): return [i for i in map(int, input_stream.readline().strip().split())] def read_int(input_stream): return int(input_stream.readline().strip()) if __name__ == "__main__": outputs = solve(sys.stdin) for line in outputs: print(line)
1
137,766,379,310,240
null
273
273
N, R = (int(x) for x in input().split()) if N > 9: print(R) else: print(R + (100 * (10 - N)))
N=int(input()) S=[int(s) for s in input().split()] for i in range(N): if S[i]%2==0 and S[i]%5!=0 and S[i]%3!=0: print("DENIED") break elif i==N-1: print("APPROVED")
0
null
66,521,581,315,480
211
217
a, op, b = input().split() a = int(a) b = int(b) L = [] while op != "?": L.append([a, b, op]) a, op, b = input().split() a = int(a) b = int(b) for (a, b, op) in L: if op == "+": print(str(a + b)) elif op == "-": print(str(a - b)) elif op == "*": print(str(a * b)) else: print(str(a // b))
count = -1 a = [] while True: count += 1 n = input() a.append(n.split()) boy = a[count][0] fuck = a[count][1] girl = a[count][2] if fuck == "+": print(int(boy)+int(girl)) elif fuck == "-": print(int(boy)-int(girl)) elif fuck == "*": print(int(boy)*int(girl)) elif fuck == "/": print(int(int(boy)/int(girl))) if a[count][1] == "?": break
1
672,131,908,530
null
47
47
a,b=input().split() print(-1 if len(a)>1 or len(b)>1 else int(a)*int(b))
a,b=map(int,input().split()) if a<0 or a>9: print(-1) elif b<0 or b>9: print(-1) else: print(a*b)
1
157,979,408,325,830
null
286
286
from collections import Counter N = int(input()) A = list(map(int, input().split())) p = [i+Ai for i, Ai in zip(range(1, N+1), A)] q = [j-Aj for j, Aj in zip(range(1, N+1), A)] pc = Counter(p) qc = Counter(q) r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys()) print(r)
while True: try: a,b = map(int, input().split()) d = 0 s = sum([a,b]) while (s): s //= 10 d += 1 print(d) except EOFError: break
0
null
12,991,197,057,618
157
3
def f(num): mn = 20000 for y in c: if y > num/2: break mn = min(mn, yen[y]+yen[num-y]) return mn n, m = map(int, input().split()) c = list(map(int, input().split())) c = sorted(c) yen = [0 for i in range(n+1)] yen[1] = 1 for num in range(2, n+1): if num in c: yen[num] = 1 else: yen[num] = min(yen[num-1]+1,f(num)) print(yen[n])
from collections import defaultdict def solve(): N, M = map(int, input().split()) d = defaultdict(lambda: -1) for i in range(M): x,y = map(int, input().split()) if d[x]>=0 and d[x]!=y: return -1 if N>1 and x==1 and y==0: return -1 d[x] = y if N==1 and d[1]==-1: return 0 if d[1]==-1: d[1] = 1 for i in range(2,N+1): if d[i]==-1: d[i] = 0 ans = '' for i in range(1,N+1): ans += str(d[i]) return ans print(solve())
0
null
30,373,493,418,060
28
208
x = input() a, b = [int(z) for z in x.split()] x = a // b y = a % b z = ('{:.5f}'.format(a / b)) print('{} {} {}'.format(x, y, z))
def main(): N = int(input()) a = [] for _ in range(N): a.append(list(map(int, input().split()))) for x in range(N): a[x].sort(reverse = True) if a[x][0] ** 2 == a[x][1] ** 2 + a[x][2] ** 2: print("YES") else: print("NO") if __name__ == "__main__": main()
0
null
305,243,631,200
45
4
h,w = list(map(int,input().split())) h += 2 w += 2 grid = '#'*w for _ in range(h-2): grid += '#' + input() + '#' grid += '#'*w from collections import deque ans = 0 for i in range(len(grid)): INF = 10**9 dist = [INF]*(h*w) if grid[i]=='#': continue dist[i] = 0 q = deque([i]) while q: v = q.popleft() dv = dist[v] for m in (-1,1,w,-w): move = v + m if grid[move]=='#': continue dmove = dv + 1 if dmove >= dist[move]: continue dist[move] = dmove q.append(move) # print([dist[i] if dist[i]!=INF else 0 for i in range(len(dist))]) ans = max(ans, max([dist[i] if dist[i]!=INF else 0 for i in range(len(dist))])) # print(ans) print(ans)
from collections import deque import _pickle as cPickle import cProfile H, W =map(int,input().split()) grid = [input() for i in range(H)] dist = [[-1]*W for _ in range(H)] cells = deque() for h in range(H): for w in range(W): if grid[h][w] == '.': dist[h][w] = 0 cells.append((h,w)) distG = cPickle.loads(cPickle.dumps(dist, -1)) pcells = deque() def bfs(h,w): pcells.append((h,w)) d = 1 distG[h][w] = 1 while pcells: oh,ow = pcells.popleft() d = distG[oh][ow] for dx, dy in ((0,1),(0,-1),(1,0),(-1,0)): nw = ow + dx nh = oh + dy if nw < 0 or W <= nw or nh <0 or H <= nh: continue if distG[nh][nw] == 0: distG[nh][nw] = d+1 pcells.append((nh,nw)) return d-1 a = 0 for i in range(len(cells)): distG = cPickle.loads(cPickle.dumps(dist, -1)) h,w = cells.popleft() a = max(a,bfs(h,w)) print(a)
1
94,197,491,625,268
null
241
241
import sys n, k = map(int, input().split()) mod = 998244353 dp = [0] * (n+1) dp[1] = 1 r = [tuple(map(int, input().split())) for _ in range(k)] s = [0 for _ in range(k)] for i in range(2, n + 1): sums = 0 for j in range(k): s[j] += dp[max(0, i - r[j][0])] - dp[max(0, i - r[j][1] - 1)] s[j] %= mod sums = (sums + s[j]) % mod dp[i] = sums print(dp[n])
N, K = [int(v) for v in input().split()] links = [] for k in range(K): L, R = [int(v) for v in input().split()] links.append((L, R)) links = sorted(links, key=lambda x: x[1]) count = [1] sub = [0, 1] subtotal = 1 for i in range(1, N): v = 0 for l, r in links: r2 = i - l + 1 l2 = i - r if l2 < 0: l2 = 0 if r2 >= 0: v += sub[r2] - sub[l2] count.append(v % 998244353) subtotal = (subtotal + v) % 998244353 sub.append(subtotal ) print(count[-1])
1
2,698,187,305,352
null
74
74
n = int(input()) S = 0 for i in range(1,n+1): a = n//i j = i * a s = (i+j)*a//2 S += s print(S)
N = int(input()) ans = 0 for x in range(1, N + 1): n = N // x #ans += n * (2 * x + (n - 1) * x) // 2 ans += n * ( x + n * x) // 2 print(ans)
1
11,024,832,278,020
null
118
118
if __name__ == '__main__': data_num = int(input()) data = [int(x) for x in input().split(' ')] assert data_num == len(data), "invalid input" print('{0} {1} {2}'.format(min(data), max(data), sum(data)))
N = int(input()) A = input().split(" ") def bubble_sort(A): N = len(A) for i in range(N): for j in range(N - 1, i, -1): if int(A[j][1]) < int(A[j - 1][1]): A[j - 1], A[j] = A[j], A[j - 1] return A def selection_sort(A): N = len(A) for i in range(N): mini = i for j in range(i + 1, N): if int(A[j][1]) < int(A[mini][1]): mini = j if mini != i: A[mini], A[i] = A[i], A[mini] return A def is_stable(A, B): map_a = {} map_b = {} for i in range(len(A)): s_a = A[i][0] s_b = B[i][0] v_a = A[i][1] v_b = B[i][1] if v_a in map_a: map_a[v_a].append(s_a) else: map_a[v_a] = [s_a] if v_b in map_b: map_b[v_b].append(s_b) else: map_b[v_b] = [s_b] result = True for k in map_a: if len(map_a[k]) > 1: result = result and (map_a[k] == map_b[k]) return result A_sorted = bubble_sort(A[:]) print(" ".join(A_sorted)) print("Stable") if is_stable(A, A_sorted) else print("Not stable") A_sorted = selection_sort(A[:]) print(" ".join(A_sorted)) print("Stable") if is_stable(A, A_sorted) else print("Not stable")
0
null
385,304,257,250
48
16
import numpy as np h,w,m=map(int, input().split()) hw=[tuple(map(int,input().split())) for i in range(m)] H=np.zeros(h) W=np.zeros(w) for i in range(m): hi,wi=hw[i] H[hi-1]+=1 W[wi-1]+=1 mh=max(H) mw=max(W) hmax=[i for i, x in enumerate(H) if x == mh] wmax=[i for i, x in enumerate(W) if x == mw] f=0 for i in range(m): hi,wi=hw[i] if H[hi-1]==mh and W[wi-1]==mw: f+=1 if len(hmax)*len(wmax)-f<1: print(int(mh+mw-1)) else: print(int(mh+mw))
n = int(input()) if n%2 == 1: print(0) exit() point = 0 now = 10 while now <= n: point += n//now now *= 5 print(point)
0
null
60,097,909,602,980
89
258
N= int(input()) S = input() abc = "ABC" ans = 0 j = 0 for i in range(N): if S[i] == abc[j]: j += 1 if S[i] == "C": j = 0 ans += 1 elif S[i] == "A": j = 1 else: j = 0 print(ans)
import time start = time.time() n = int(input()) a = list(map(int,input().split())) b = [] m = 0 for i in range(1,n): m = m ^ a[i] b.append(m) for j in range(1,n): m = m ^ a[j-1] m = m ^ a[j] b.append(m) b = map(str,b) print(' '.join(b))
0
null
55,603,734,611,178
245
123
N, M = map(int, input().split()) A = list(map(int, input().split())) D = sum(A) cnt = 0 for i in range(N): if A[i] * 4 * M >= D: cnt += 1 if cnt >= M: print('Yes') else: print('No')
N, M = map(int, input().split()) A = list(map(int, input().split())) cnt = 0 sumA = sum(A) for a in A: if a >= sumA / 4 / M: cnt += 1 if cnt >= M: print('Yes') else: print('No')
1
38,670,303,087,680
null
179
179
A,B=map(int,input().split()) N = list(map(int,input().split())) c=0 for i in range(A): if N[i] >= B: c+=1 else: pass i+=1 print(c)
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 count = 0 N,K = I() h = l() for i in range(N): if h[i] >= K: count += 1 print(count)
1
178,078,341,637,532
null
298
298
n = int(input()) a = list(map(int,input().split())) M = max(a)+1 if M == 2: print("pairwise coprime") exit() count = [0]*(M) prime = [2,3,5,7,11,13] for i in range(14,int(M**0.5)+2): check = True for j in prime: if i%j == 0: check = False break if check: prime.append(i) for i in a: for j in prime: if i < j: break if i%j==0: while i%j == 0: i //= j count[j] += 1 if i > 1: count[i] += 1 ans = max(count) if ans == 1: print("pairwise coprime") elif ans == n: print("not coprime") else: print("setwise coprime")
import sys, io, os, re from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right from pprint import pprint from math import sin, cos, pi, radians, sqrt, floor, ceil from copy import copy, deepcopy from collections import deque, defaultdict from fractions import gcd from functools import reduce from itertools import groupby, combinations from heapq import heapify, heappush, heappop # sys.setrecursionlimit(5000) n1 = lambda: int(sys.stdin.readline().strip()) nn = lambda: list(map(int, sys.stdin.readline().strip().split())) f1 = lambda: float(sys.stdin.readline().strip()) fn = lambda: list(map(float, sys.stdin.readline().strip().split())) s1 = lambda: sys.stdin.readline().strip() sn = lambda: list(sys.stdin.readline().strip().split()) nl = lambda n: [n1() for _ in range(n)] fl = lambda n: [f1() for _ in range(n)] sl = lambda n: [s1() for _ in range(n)] nm = lambda n: [nn() for _ in range(n)] fm = lambda n: [fn() for _ in range(n)] sm = lambda n: [sn() for _ in range(n)] def array1(n, d=0): return [d] * n def array2(n, m, d=0): return [[d] * m for x in range(n)] def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)] def linc(A, d=1): return list(map(lambda x: x + d, A)) def ldec(A, d=1): return list(map(lambda x: x - d, A)) N = n1() A = nn() #MAX = 10**6 MAX = max(A) dp = defaultdict(list) p = 2 while p <= MAX: i = p while i <= MAX: dp[i].append(p) i += p p += 1 while len(dp[p]) >= 1: p += 1 if max(A) == 1: print("pairwise coprime") exit(0) dic = defaultdict(list) for ai in A: fact = dp[ai] for x in fact: dic[x].append(ai) maxlen = 0 for k, v in dic.items(): maxlen = max(len(v), maxlen) if maxlen == 1: print("pairwise coprime") elif maxlen == N: print("not coprime") else: print("setwise coprime")
1
4,111,816,372,062
null
85
85
a,b = 1,1 n = int(input()) for i in range(n): a,b = b,a+b print(a)
# coding: utf-8 # Your code here! n = int(input()) m = [1,1] if n == 0: print(1) elif n == 1: print(1) else: for i in range(2, n+1): m.append( m[i-1] + m[i-2] ) print(m.pop())
1
1,943,555,138
null
7
7
n=int(input()) a=input() if n%2!=0: print('No') exit() t1=a[0:int(n/2)] t2=a[int(n/2):n] if t1==t2: print('Yes') else: print('No')
N = int(input()) S = input() if N%2 == 1: print("No") else: print("Yes") if S[:len(S)//2] == S[len(S)//2:] else print("No")
1
146,999,511,936,598
null
279
279
def main(): today = input().split() tomo = input().split() if today[0] == tomo[0]: print(0) else: print(1) if __name__ == '__main__': main()
def main(): from collections import deque N, M = (int(i) for i in input().split()) if N % 2 == 0: A = deque([i+1 for i in range(N)]) for i in range(1, M+1): if (N-i)-i > N//2: print(A[i], A[N-i]) else: print(A[i], A[N-i-1]) else: A = deque([i for i in range(N)]) for i in range(1, M+1): print(A[i], A[N-i]) if __name__ == '__main__': main()
0
null
76,234,471,694,260
264
162
# 与えられた数値の桁数と桁値の総和を計算する. def calc_digit_sum(num): digits = sums = 0 while num > 0: digits += 1 sums += num % 10 num //= 10 return digits, sums length = len(input()) print("x" * length)
S = str(input()) t = len(S) print('x'*t)
1
73,036,811,923,620
null
221
221
_, vs, c = input(), list(map(int, input().split())), 0 for i in range(len(vs)): for j in range(len(vs)-1, i, -1): if vs[j] < vs[j-1]: vs[j], vs[j-1] = vs[j-1], vs[j] c += 1 print(' '.join(map(str, vs))) print(c)
def bubble_sort(alist): """Sort alist by bubble sort. Returns (number of swap operations, sorted list) >>> bubble_sort([5, 3, 2, 4, 1]) ([1, 2, 3, 4, 5], 8) """ size = len(alist) count = 0 for i in range(size-1): for j in reversed(range(i+1, size)): if alist[j] < alist[j-1]: count += 1 alist[j-1], alist[j] = alist[j], alist[j-1] return (alist, count) def run(): _ = int(input()) # flake8: noqa nums = [int(i) for i in input().split()] (sorted_list, num_swap) = bubble_sort(nums) print(" ".join([str(i) for i in sorted_list])) print(num_swap) if __name__ == '__main__': run()
1
16,916,987,600
null
14
14
import numpy as np import math import collections if __name__ == '__main__': n = int(input()) print(int(np.lcm(360,n)/n))
icase=0 if icase==0: a,b=map(int,input().split()) print(max(a-2*b,0))
0
null
90,160,627,968,960
125
291
n = int(input()) sum = 0 for _ in range(n): a = int(input()) if a == 2: continue for i in range(a): x = i + 2 if a%x == 0: sum += 1 break if x > a ** 0.5: break print(n - sum)
def p(x): i=2 while i<=x**.5: if x%i==0:return 0 i+=1 return 1 n=int(input()) print(sum([p(int(input()))for _ in range(n)]))
1
10,684,563,050
null
12
12
n = int(input()) C = list(input()) W = C.count("W") R = C.count("R") # 仕切りより左側にある白石の数 w = 0 # 仕切りより右側にある赤石の数 r = R ans = r for i in range(n): if C[i] == "W": w += 1 else: r -= 1 ans = min(ans, max(w, r)) print(ans)
N = int(input()) A = list(map(int, input().split())) if 0 in A: print(0) exit() else: flag = True prd = 1 A.sort(reverse=True) for i in range(N): prd *= A[i] if prd > 10**18: flag = False break if flag: print(prd) else: print(-1)
0
null
11,209,370,737,760
98
134
n,m = map(int,input().split()) if m != 0: l = [list(input().split()) for i in range(m)] p,s = [list(i) for i in zip(*l)] t = [0] * n ac = 0 wa = 0 for i in range(m): if s[i] == 'WA' and t[int(p[i])-1] != 'AC': t[int(p[i])-1] += 1 elif s[i] == 'AC' and t[int(p[i])-1] != 'AC': ac += 1 wa += t[int(p[i])-1] t[int(p[i])-1] = 'AC' else: pass print(ac,wa)
# input here _INPUT = """\ 2 5 1 WA 1 AC 2 WA 2 AC 2 WA 2 AC """ def main(): n, m= map(int, input().split()) ps = [list(map(str,input().split())) for _ in range(m)] str_l = ["WA"]*n int_l = [0]*n num = 0 ac = 0 for pp, s in ps: p = int(pp)-1 if s == "AC": str_l[p] = "AC" else: if str_l[p] != "AC": int_l[p] += 1 for i in range(n): if str_l[i] == "AC": num += int_l[i] ac += 1 print(ac,num) # n, m = map(int, input().split()) # seikai = [False] * n # matigai = [0] * n # for i in range(m): # p,q = map(str, input().split()) # p = int(p)-1 # if q == "AC": # seikai[p] = True # else: # if seikai[p] != True: # matigai[p] += 1 # correct = seikai.count(True) # mistake = sum(matigai) # print(correct, mistake) if __name__ == '__main__': import io import sys import math import itertools from collections import deque # sys.stdin = io.StringIO(_INPUT) main()
1
93,627,446,032,710
null
240
240
import math r=int(input()) L=2*math.pi*r print('{0}'.format(L))
s = input() k = int(input()) l=len(s) s+='?' ch = 1 ans=0 j=0 for i in range(l): if s[i]==s[i+1]: ch+=1 else: ans+=ch//2 if j==0: st=ch if s[i+1]=='?': gl=ch ch=1 j=1 ans*=k if st%2==1 and gl%2==1 and s[0]==s[l-1]: ans+=k-1 if st==l: ans=l*k//2 print(ans)
0
null
103,781,843,730,188
167
296
#!/usr/bin/env python3 m1, d1 = list(map(int, input().split())) m2, d2 = list(map(int, input().split())) ans = 1 if d2 == 1 else 0 print(ans)
m1, d1 = map(int, input().split()) m2, d2 = map(int, input().split()) if m1 == m2: print('0') else:print('1')
1
124,038,434,965,348
null
264
264
import sys import math MAX_INT = int(10e15) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return input() T1, T2 = IL() a1, a2 = IL() b1, b2 = IL() if a1*T1 + a2*T2 > b1*T1 + b2*T2: pass else: a1,a2,b1,b2 = b1,b2,a1,a2 if a1*T1 + a2*T2 == b1*T1 + b2*T2: print("infinity") elif a1*T1 >= b1*T1: print(0) else: half = b1*T1 - a1*T1 x = (a1*T1 + a2*T2 - (b1*T1 + b2*T2)) # half/x >= n loop = half//x + 1 if (loop - 1)*x == half: print(loop*2 -2) else: print(loop*2 -1)
i = 1 while i < 10 : j = 1 while j < 10 : print(str(i) + "x" + str(j) + "=" + str(i*j)) j += 1 i += 1
0
null
65,665,441,225,446
269
1
days = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] current_day = input() i = 0 while True: if days[i] == current_day: break i += 1 print(7 - i)
s = int(input()) h = s // 3600 m = s % 3600 // 60 s = s % 60 print(f'{h}:{m}:{s}')
0
null
66,757,929,174,930
270
37
mod = 1000000007 N = int(input()) A = list(map(int, input().split())) S = [0] # 累積和のリスト ans = 0 for i in range(N): S.append(A[i] + S[i] % mod) for i in range(N): sum = S[N] - S[i + 1] if sum < 0: sum += mod ans += A[i] * sum print(ans % mod)
from sys import stdin from itertools import accumulate input = stdin.readline n = int(input()) a = list(map(int,input().split())) p = [0] + list(accumulate(a)) res = 0 for i in range(n-1,-1,-1): res += (a[i] * p[i])%(10**9 + 7) print(res % (10**9 + 7))
1
3,876,335,811,168
null
83
83
import math r = float(input()) s = r*r*math.pi l = 2*r*math.pi print(s,l)
import math r = input() print "%.6f %.6f" % (math.pi * r * r, math.pi * 2 * r)
1
645,013,076,110
null
46
46
#K = input() NR = list(map(int, input().split())) #s = input().split() #N = int(input()) if (NR[0] >= 10): print(NR[1]) else: print(NR[1] + 100 * (10 - NR[0]))
def main(): N,R = map(int, input().split()) if N>=10: print(R) else: print(R+100*(10-N)) main()
1
63,553,492,296,672
null
211
211
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def solve(H: int): return 1 if H == 1 else solve(H//2) * 2 + 1 def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int print(f'{solve(H)}') if __name__ == '__main__': main()
pi = 3.141 r = int(input()) print(2*pi*r)
0
null
55,598,922,037,058
228
167
def main(): N = int(input()) m = float("inf") ans = 0 for i in [int(j) for j in input().split()]: if i < m: m = i ans += 1 print(ans) if __name__ == '__main__': main()
s = input() n = len(s) kotae = "x"*n print(kotae)
0
null
79,014,101,158,618
233
221
x = [int(x) for x in input().split()] if (x[1]<x[0]): print("safe") else: print("unsafe")
N, M = map(int, input().split()) A = list(map(int, input().split())) s = sum(A) ans = 0 for a in A: if a * 4 * M >= s: ans += 1 print("Yes" if ans >= M else "No")
0
null
34,162,358,908,980
163
179
import numpy as np count = 0 n, d = map(int, input().split()) for _ in range(n): x, y = map(int, input().split()) if np.sqrt(x**2 + y**2) <= d: count +=1 print(count)
s = input().rstrip().split(' ') a = int(s[0]) b = int(s[1]) c = int(s[2]) if a < b and b < c: print("Yes") else: print("No")
0
null
3,135,522,374,670
96
39
n = int(input()) tbl = [[0 for i in range(n)] for j in range(5)] for i in range(2): a = list(map(int,input().split())) for j in range(n): tbl[i][j] = a[j] D_1 = 0 d_2 = 0 d_3 = 0 for k in range(n): tbl[2][k] = abs(tbl[0][k]-tbl[1][k]) tbl[3][k] = (abs(tbl[0][k]-tbl[1][k]))**2 tbl[4][k] = (abs(tbl[0][k]-tbl[1][k]))**3 D_1 += tbl[2][k] d_2 += tbl[3][k] d_3 += tbl[4][k] M = max(tbl[2]) print(f'{D_1:.6f}') print(f'{(d_2)**(1/2):.6f}') print(f'{(d_3)**(1/3):.6f}') print(f'{M:.6f}')
import math n=int(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) a=[1,2,3,4] for i in a: num=0 if i==1: for j in range(len(x)): num+=abs(x[j]-y[j]) print(num) elif i==2 or i==3: for j in range(len(x)): num+=(abs(x[j]-y[j]))**i num=math.pow(num,1/i) print(num) else: b=[] for j in range(len(x)): b.append(abs(x[j]-y[j])) print(float(max(b)))
1
213,276,353,228
null
32
32
N = int(input()) ans = set() for i in range(N): ans.add(input()) print(len(ans))
lis = [int(x) for x in input().split()] if lis[0] < lis[1]and lis[1] < lis[2]: print("Yes") else: print("No")
0
null
15,207,582,387,992
165
39
N = int(input()) A = list(map(int, input().split())) A.reverse() min_max = [[] for _ in range(N+1)] def main(): min_max[0] = [A[0], A[0]] for i in range(1, N+1): a = A[i] pre_min, pre_max = min_max[i-1] min_max[i] = [(1+pre_min)//2 +a, pre_max +a] min_max.reverse() if min_max[0][0] != 1: print(-1) return A.reverse() ans = 1 pre = 1 for i in range(1, N+1): a = A[i-1] pre = min(2*(pre -a), min_max[i][1]) ans += pre print(ans) main()
N = int(input()) A = list(map(int, input().split())) B = [0] *(N+1) B[0] = 1 ans = 0 for i in range(1, N+1): B[i] = (B[i-1] - A[i-1])*2 if B[i] <= 0: ans = -1 break if B[N] < A[N]: ans = -1 if ans == 0: check = 0 for j in range(N, 0, -1): check += A[j] if check < B[j]: ans += check else: last = j for k in range(1, last+1): ans += B[k] break ans += 1 if N == 0 and A[0] == 1: ans = 1 print(ans)
1
18,805,235,932,110
null
141
141
n = list(map(int,input().split())) a = list(map(int,input().split())) for i in range(n[1],n[0]): if a[i-n[1]] < a[i]: print("Yes") else: print("No")
N, K = map(int, input().split()) A = list(map(int, input().split())) result = [] for i in range(K, N): if A[i] > A[i - K]: result.append('Yes') else: result.append('No') print(*result, sep='\n')
1
7,089,218,346,268
null
102
102
n,k = map(int,input().split()) A = [int(i) for i in input().split()] A.sort() F = [int(i) for i in input().split()] F.sort(reverse=True) left = -1 right = 10**12 def f(x): return sum(max(A[i]-x//F[i],0) for i in range(n)) <= k while right - left > 1: mid = (left+right)//2 if f(mid): right = mid else: left = mid print(right)
N = int(input()) A = list(map(int, input().split())) print('YES' if len(set(A)) == N else 'NO')
0
null
119,021,311,923,390
290
222
import sys input = sys.stdin.readline N, D = map(int, input().split()) count = 0 for i in range(N): a, b = map(int, input().split()) if (a*a + b*b) <= D*D: count += 1 print(count)
H = int(input()) W = int(input()) N = int(input()) for i in range(min(H,W)): N -= max(H, W) if N <= 0: print(i+1) exit()
0
null
47,639,516,253,332
96
236
n=int(input()) s=input() r=s.count('R') g=s.count('G') b=s.count('B') cnt=0 for i in range(n-1): for j in range(1, min(i+1, n-i)): if (s[i] != s[i-j]) and (s[i] != s[i+j]) and (s[i-j] != s[i+j]): cnt += 1 print(r*g*b-cnt)
from collections import Counter as coun from itertools import combinations as comb import sys input = sys.stdin.readline N = int(input()) S = input() C = coun(S) ans = C["R"] * C["G"] * C["B"] for i, j in comb(range(N), 2): k = 2 * j - i if k < N: A, B, C = S[i], S[j], S[k] if A != B and B != C and C != A: ans -= 1 print(ans)
1
36,235,766,051,638
null
175
175
n,s = map(int, input().split()) a = list(map(int, input().split())) a.sort() mod = 998244353 dp = [[0 for i in range(s+1)] for j in range(n+1)] dp[0][0] = 1 for i in range(n): for x in range(s+1): dp[i+1][x] = 2*dp[i][x] if x-a[i] >= 0: dp[i+1][x] += dp[i][x-a[i]] dp[i+1][x] %= mod print(dp[n][s])
from sys import stdin from collections import defaultdict, Counter N, P = map(int, stdin.readline().split()) S, = stdin.readline().split() ans = 0 # 2 cases if P == 2 or P == 5: digitdiv = [] for i in range(N): if int(S[i]) % P == 0: ans += i + 1 else: # count = Counter() prefix = [] ten = 1 mod = 0 for i in range(N): x = (int(S[N - i - 1])*ten + mod) % P prefix.append(x) count[x] += 1 ten = (ten * 10) % P mod = x prefix.append(0) count[0] += 1 for val in count.values(): ans += val*(val - 1)//2 print (ans)
0
null
38,165,528,801,534
138
205
i = raw_input().strip().split() a = int(i[0]) b = int(i[1]) c = int(i[2]) if a < b and b < c: 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
391,935,188,832
null
39
39
class Dise(): def __init__(self, aLabelList): self.LabelList = aLabelList self.LabelsRelationship = [[0 for i in range(5)] for j in range(6)] for i in range(6): if i == 0: self.LabelsRelationship[i][0] = self.LabelList[2 -1] #下1 self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2 self.LabelsRelationship[i][2] = self.LabelList[5 -1] #下3 self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4 self.LabelsRelationship[i][4] = self.LabelList[6 -1] #対面 elif i == 1: self.LabelsRelationship[i][0] = self.LabelList[6 -1] #下1 self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2 self.LabelsRelationship[i][2] = self.LabelList[1 -1] #下3 self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4 self.LabelsRelationship[i][4] = self.LabelList[5 -1] #対面 elif i == 2: self.LabelsRelationship[i][0] = self.LabelList[6 -1] #下1 self.LabelsRelationship[i][1] = self.LabelList[5 -1] #下2 self.LabelsRelationship[i][2] = self.LabelList[1 -1] #下3 self.LabelsRelationship[i][3] = self.LabelList[2 -1] #下4 self.LabelsRelationship[i][4] = self.LabelList[4 -1] #対面 elif i == 3: self.LabelsRelationship[i][0] = self.LabelList[2 -1] #下1 self.LabelsRelationship[i][1] = self.LabelList[1 -1] #下2 self.LabelsRelationship[i][2] = self.LabelList[5 -1] #下3 self.LabelsRelationship[i][3] = self.LabelList[6 -1] #下4 self.LabelsRelationship[i][4] = self.LabelList[3 -1] #対面 elif i == 4: self.LabelsRelationship[i][0] = self.LabelList[1 -1] #下1 self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2 self.LabelsRelationship[i][2] = self.LabelList[6 -1] #下3 self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4 self.LabelsRelationship[i][4] = self.LabelList[2 -1] #対面 elif i == 5: self.LabelsRelationship[i][0] = self.LabelList[5 -1] #下1 self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2 self.LabelsRelationship[i][2] = self.LabelList[2 -1] #下3 self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4 self.LabelsRelationship[i][4] = self.LabelList[1 -1] #対面 def DisePrintRight(self,aTopItem,aFront): xTopIndex = self.LabelList.index(str(aTopItem)) for i in range(4): if int(self.LabelsRelationship[xTopIndex][i]) == aFront: if i + 1 == 4: idxR = int(self.LabelsRelationship[xTopIndex][0]) else: idxR = int(self.LabelsRelationship[xTopIndex][i+1]) print(idxR) break myInstance = Dise(input().split()) x = int(input()) for i in range(x): a,b = map(int, input().split()) myInstance.DisePrintRight(a,b)
dice_init = input().split() dicry = {'search':"152304",'hittop':'024135', 'hitfront':'310542'} num = int(input()) def dicing(x): global dice dice = [dice[int(c)] for c in dicry[x]] for _ in range(num): dice = dice_init top, front = map(int, input().split()) while True: if int(dice[0]) == top and int(dice[1]) == front: break elif int(dice[0]) == top: dicing('hittop') elif int(dice[1]) == front: dicing('hitfront') else: dicing('search') print(dice[2])
1
251,057,368,932
null
34
34