code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
from sys import exit n, m = map(int, input().split()) s = input() one_sequence = 0 for i in range(1, n): if s[i] == "1": one_sequence += 1 if one_sequence == m: print(-1) exit() else: one_sequence = 0 pos = n ans = "" while pos != 0: for i in range(1, m+1)[::-1]: if pos-i < 0: continue if s[pos-i] != "1": ans = str(i) + " " + ans pos -= i break print(ans)
N = int(input()) MOD = 10**9+7 ans = ((10**N%MOD - 9**N%MOD*2%MOD)%MOD + 8**N%MOD)%MOD print(ans)
0
null
71,404,551,833,690
274
78
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")
# 0がX個、1がY個ある(ただしX+Y=N)とき、Xorの組み合わせ自体は N*(N-1)//2 通りある。 # しかし、それらの和をとることを考えてみた時 # (0,0)と(1,1)を選んだ場合はそのXORは0になることに注意すると、(0,1)の組み合わせの個数だけ数えれば良い。 # これは、たとえば 〇〇〇●●●●(X=3,Y=4)から〇と●を選ぶ組み合わせは何個あるか、という問いと同じことなので # Nの値には依存することはなく、単純にX*Y通りとなる。 # よって # ΣΣ A_i Xor A_j = X*Y # この処理によって、O(N^2)が、O(N)(=Aの各数字を一通り調べる)に減らせる。 # これを各ケタについて計算し、合計すれば良い。 # ケタ数が60まで定まっているので 計算量は O(Nlog(max(A)))≦ O(N*60) # あるケタのbitを取り出すには ビットシフト「>>」でずらして下1ケタだけを見ると便利。 N=int(input()) A=list(map(int,input().split())) p=10**9+7 ans=0 for k in range(60): cnt_z=0 cnt_o=0 #print(A) for i in range(N): s=A[i]%2 if s==0: cnt_z +=1 else: cnt_o +=1 A[i] >>= 1 ans += ((2**k)*cnt_z*cnt_o)%p print(ans%p)
0
null
64,614,149,939,440
101
263
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n = I() span = [None for _ in range(n)] for i in range(n): x, l = LI() span[i] = [x-l, x+l] span.sort(key=lambda x: x[1]) choice = [[-float("inf"),-float("inf")]] for each_span in span: if choice[-1][1] <= each_span[0]: choice.append(each_span) ans = len(choice)-1 print(ans) main()
s = input() t = s[::-1] cnt = 0 for i, j in zip(s, t): if i != j: cnt += 1 print(cnt // 2)
0
null
104,909,073,381,972
237
261
from collections import deque def bfs(y,x): q=deque([(y,x)]) visited[y][x]=0 while q: cy,cx=q.popleft() for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]: ny,nx=cy+dy,cx+dx if 0<=ny<h and 0<=nx<w and visited[ny][nx]==-1: if s[ny][nx]=="#":continue visited[ny][nx]=visited[cy][cx]+1 q.append((ny,nx)) res=0 for i in range(h): for j in range(w): if s[i][j]!="#": res=max(res,visited[i][j]) return res h,w=map(int,input().split()) s=[input() for _ in range(h)] ans=0 for i in range(h): for j in range(w): if s[i][j]=="#":continue sh=i sw=j visited=[[-1]*w for _ in range(h)] ans=max(ans,bfs(sh,sw)) print(ans)
#!/usr/bin/env python # -*- coding: utf-8 -*- t = input().rstrip() list_t = [] for s in t: list_t.append(s) ans_str = "" for i, s in enumerate(list_t): if s == "?": list_t[i] = "D" print("".join(list_t))
0
null
56,391,368,161,398
241
140
n = int(input()) s_l = [ input() for _ in range(n) ] d = {} for s in s_l: try: d[s] += 1 except: d[s] = 1 max_c = max([ v for _,v in d.items() ]) ans = [ i for i, v in d.items() if v == max_c ] for i in sorted(ans): print(i)
# coding: utf-8 from collections import defaultdict def main(): N = int(input()) dic = defaultdict(int) max_p = 0 for i in range(N): dic[input()] += 1 d = dict(dic) l = [] for key, value in d.items(): l.append([key, value]) if max_p < value: max_p = value l.sort(key=lambda x: (-x[1], x[0]), reverse=False) for i, j in l: if j == max_p: print(i) else: break if __name__ == "__main__": main()
1
69,835,477,845,810
null
218
218
from operator import mul from functools import reduce def cmb(n,r): r = min(n-r,r) if r == 0: return 1 over = reduce(mul, range(n, n - r, -1)) under = reduce(mul, range(1,r + 1)) return over // under s= int(input()) box_max =s//3 ans =0 if box_max ==0: print(ans) else: for i in range(1, box_max +1): ball_and_bar =(s-3*i)+i-1 bar =i-1 ans += cmb(ball_and_bar, bar)%(10**9 +7) print(ans%(10**9 + 7))
S = int(input()) f = 10**9 + 7 dp = [0]*(S+1) dp[0] = 1 for i in range(1,S+1): if i==1 or i==2: dp[i] = 0 else: for j in range(0,i-2): dp[i] += dp[j] dp[i] %= f print(dp[-1]%f)
1
3,285,745,879,580
null
79
79
import bisect N = int(input()) Ls = list(map(int, input().split(" "))) Ls.sort() ans = 0 for i in range(0,N-2): for j in range(i+1,N-1): k = bisect.bisect_left(Ls,Ls[i]+Ls[j]) ans += k - (j + 1) print(ans)
import bisect n=int(input()) l=[int(x) for x in input().rstrip().split()] l.sort() ans=0 comb=[] ans=0 for i in range(n): for j in range(i+1,n): now=l[i]+l[j] ind=bisect.bisect_left(l,now) ans+=max(0,ind-j-1) print(ans)
1
171,573,176,906,180
null
294
294
def main(): K = int(input()) work = 7 answer = -1 for i in range(1, K+1): i_mod = work % K if i_mod == 0 : answer = i break work = i_mod * 10 + 7 print(answer) main()
n = int(input()) print(n**3/27)
0
null
26,538,375,131,122
97
191
def solve(d,p,t): if d - p * t <= 0: return "YES" else: return "NO" A,V = map(int,input().split()) B,W = map(int,input().split()) T = int(input()) d = abs(B-A) p = V - W print(solve(d,p,T))
N = int(input()) says = [] for _ in range(N): A = int(input()) say = [list(map(int, input().split())) for _ in range(A)] says.append(say) # print(says) max_upright_count = 0 for i in range(1 << N): integrate = True upright_count = 0 declares = [-1 for _ in range(N)] for j in range(N): if not integrate: continue # もし真偽不明の場合は正しいことを言う場合もあるから無視する if (i >> j & 1) == 1: upright_count += 1 for x, y in says[j]: # print(i, j, x, y, declares) if declares[x - 1] == -1: declares[x - 1] = y else: if declares[x - 1] == y: continue else: integrate = False break # print(bin(i), integrate, declares, upright_count) for j in range(N): # print((i >> j) & 1, declares[j]) if ((i >> j) & 1) != declares[j] and declares[j] != -1: # print(False) integrate = False # print(integrate) if integrate: max_upright_count = max(max_upright_count, upright_count) print(max_upright_count)
0
null
68,603,064,729,078
131
262
def main(n,m,s): #i初期化 i = n tmp = [] while i > 0 : for j in range(m,-1,-1): if j == 0 : i = -1 break if i-j >= 0 : if s[i-j] == '0': i -= j tmp.append(j) break if i == 0: for l in reversed(tmp): print(l,end=' ') else: print(-1) n,m = map(int,input().split()) s = input() main(n,m,s)
N,M = map(int,input().split()) S = input() c = 0 flag = 0 for i in S: if i == '0': if c >= M: flag = 1 break c = 0 else: c += 1 if flag == 1: print(-1) else: T = S[::-1] now = 0 ans = [] while now != N: delta = 0 for i in range(1,M+1): if now + i == N: delta = i break if T[now+i] == '0': delta = i ans.append(delta) now += delta Answer = ans[::-1] print(*Answer)
1
138,828,090,974,030
null
274
274
l = int(input()) squre = (l/3)**3 print(squre)
n = int(input()) str1 = "" while n > 0: n -= 1 m = n % 26 n = n // 26 str1 += chr(m+ord("a")) ans = str1[::-1] print(ans)
0
null
29,404,517,357,788
191
121
''' ITP-1_8-A ??§????????¨?°????????????\????????? ????????????????????????????°?????????¨??§???????????\????????????????????°???????????????????????????????????? ???Input ????????????1??????????????????????????? ???Output ????????????????????????????°?????????¨??§???????????\???????????????????????????????????????????????? ??¢????????????????????\??????????????????????????????????????????????????? ''' # inputData inputData = input() for i in range(len(inputData)): if "a"<=inputData[i]<="z": # ??§???????????? print(inputData[i].upper(),end='') elif "A"<=inputData[i]<="Z": # ?°????????????? print(inputData[i].lower(),end='') else: # ??¢????????????????????\????????????????????? print(inputData[i],end='') # ???????????? print('')
import collections N = int(input()) A = sorted(list(map(int,input().split()))) cA = collections.Counter(A) li = [1]*(max(A)+1) for j in range(N): for i in range(A[j]*2,A[-1]+1,A[j]): li[i] = 0 for key,val in cA.items(): if val >1: li[key]=0 sA = sum([li[i] for i in A]) print(sA)
0
null
8,002,132,010,182
61
129
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 LI(): return list(map(int, input().split())) def LIR(row,col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return map(list, zip(*read_all)) ################# T1,T2 = LI() A1,A2 = LI() B1,B2 = LI() if A1 > B1 and A2 > B2: print(0) exit() if A1 < B1 and A2 < B2: print(0) exit() if A1 > B1: t = (A1-B1)*T1 / (B2-A2) delta = (A1-B1)*T1+(A2-B2)*T2 if t == T2: print('infinity') exit() elif t > T2: print(0) exit() else: if delta > 0: print(math.floor((T2-t)*(B2-A2)/delta) + 1) exit() else: x = (A1-B1)*T1 / (-delta) if int(x) == x: print(2*int(x)) else: print(2*math.floor(x)+1) else: t = (B1-A1)*T1 / (A2-B2) delta = (B1-A1)*T1+(B2-A2)*T2 if t == T2: print('infinity') exit() elif t > T2: print(0) exit() else: if delta > 0: print(math.floor((T2-t)*(A2-B2)/delta) + 1) exit() else: x = (B1-A1)*T1 / (-delta) if int(x) == x: print(2*int(x)) else: print(2*math.floor(x)+1)
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) Ax = A1 * T1 + A2 * T2 Bx = B1 * T1 + B2 * T2 diff = abs(Ax - Bx) if diff == 0: print('infinity') exit() if not ((A1 * T1 > B1 * T1 and Ax < Bx) or (A1 * T1 < B1 * T1 and Ax > Bx)): print(0) exit() ans = 2 * ((abs(B1 - A1) * T1) // diff) if (abs(B1 - A1) * T1) % diff != 0: ans += 1 print(ans)
1
131,028,408,799,652
null
269
269
def backtrack(nums, N, cur_state, result): if len(cur_state) == N: result.append(cur_state[:]) else: for i in range(len(nums)): cur_state.append(nums[i]) backtrack(nums[i:], N, cur_state, result) cur_state.pop() def solve(): N,M,Q = [int(i) for i in input().split()] quads = [] for i in range(Q): quads.append([int(i) for i in input().split()]) candidates = [] backtrack(list(range(1, M+1)), N, [], candidates) ans = 0 for candidate in candidates: score = 0 for a,b,c,d in quads: if candidate[b-1] - candidate[a-1] == c: score += d ans = max(score, ans) print(ans) if __name__ == "__main__": solve()
import bisect,collections,copy,heapq,itertools,math,string,decimal import numpy as np import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) # N = I() _A,_B = LS() A = decimal.Decimal(_A) B = decimal.Decimal(_B) print((A*B).quantize(decimal.Decimal('0'), rounding=decimal.ROUND_DOWN)) #AB = [LI() for _ in range(N)] #A,B = zip(*AB) #Ap = np.array(A) #C = np.zeros(N + 1) # if ans: # print('Yes') # else: # print('No')
0
null
22,016,746,739,130
160
135
class Unionfind(): def __init__(self, n): self.n = n self.parents = [-1] * n def root (self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.root(self.parents[x]) return self.parents[x] def connect(self, x, y): x = self.root(x) y = self.root(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def isConnect(self, x): return self.root(x) == self.root(y) def size(self, x): return -self.parents[self.root(x)] N, M = map(int, input().split()) uf = Unionfind(N) for i in range(M): a, b = map(lambda x: int(x) - 1, input().split()) uf.connect(a, b) ans = 0 for i in range(N): ans = max(ans, uf.size(i)) print(ans)
count = int(input()) array = [int(i) for i in input().split(" ")] for n in range( count - 1, 0, -1): print(array[n], end = " ") print(array[0])
0
null
2,425,683,303,218
84
53
n = int(input()) lst = [] for i in range(n): tmp = input().split() lst.append(tmp) d = {} for i in range(n): if lst[i][0] == 'insert': d[lst[i][1]] = d.get(lst[i][1], 0) + 1 elif lst[i][0] == 'find': print('yes') if lst[i][1] in d else print('no')
class Dic: def __init__(self): self.end = False self.a = self.c = self.g = self.t = 0 def insert(self, s): node = self index = 0 while index < len(s): c = s[index] child = 0 if c == 'A': if not node.a: node.a = Dic() child = node.a elif c == 'C': if not node.c: node.c = Dic() child = node.c elif c == 'G': if not node.g: node.g = Dic() child = node.g elif c == 'T': if not node.t: node.t = Dic() child = node.t else: return node = child index += 1 node.end = True def find(self, s): node = self index = 0 while index < len(s): c = s[index] child = 0 if c == 'A': child = node.a elif c == 'C': child = node.c elif c == 'G': child = node.g elif c == 'T': child = node.t if child == 0: return False node = child index += 1 return node.end dic = Dic() n = int(input()) for _ in range(n): cmd = list(input().split()) if cmd[0] == 'insert': dic.insert(cmd[1]) elif cmd[0] == 'find': print('yes' if dic.find(cmd[1]) else 'no')
1
77,121,206,052
null
23
23
t = input() ans = [] for i in t: if i == "?": i = "D" ans.append(i) print("".join(ans))
def main(): n, m = map(int, input().split(" ")) a =list(map(int, input().split(" "))) if n - sum(a) <0: print(-1) else: print(n-sum(a)) if __name__ == "__main__": main()
0
null
25,197,545,892,580
140
168
n = int(input()) first = 1 second = 1 for i in range(n-1): second, first = first + second, second print(second)
#!/usr/bin/env python3 #coding: utf-8 # Volume0 - 0001 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0001) li = [] for x in range(10): s = input() s = int(s) li.append(s) li.sort() li.reverse() for y in range(3): print(li[y])
0
null
864,344,012
7
2
N, M = map(int, input().split()) A = list(map(int, input().split())) A1 = sum(A) if N - A1 >= 0: print(N - A1) else: print("-1")
n,m = map(int,input().split()) # 受け取った文字をスペースで分けてリスト化 a = list(input().split()) # 文字列のリストの値を整数化 a_int = [int(i) for i in a] # 夏休みの日数がリスト内の日数の合計より多ければ残日数を表示 if n >= sum(a_int): print(n - sum(a_int)) # リスト内の日数の合計が夏休みの日数より多ければ-1を表示 else: print("-1")
1
31,848,398,948,948
null
168
168
N=int(input()) MOD=10**9+7 in_9=10**N-9**N in_0=10**N-9**N nine_and_zero=10**N-8**N ans=int(int(in_0+in_9-nine_and_zero)%MOD) print(ans)
x = int(input()) y = 0 z = 100 while z<x: y+=1 z *= 101 z //= 100 print(y)
0
null
15,081,381,759,200
78
159
n=int(input()) ans=10**n ans-=2*9**n ans+=8**n ans%=10**9+7 print(ans)
mod = 1000000007 def fexp(x, y): ans = 1 while y > 0: if y % 2 == 1: ans = ans * x % mod x = x * x % mod y //= 2 return ans n = int(input()) ans = fexp(10, n) - 2 * fexp(9, n) + fexp(8, n) ans %= mod if ans < 0: ans += mod print(ans)
1
3,168,078,330,692
null
78
78
a = raw_input().split() while a[1] != '?': print eval(a[0]+a[1]+a[2]) a = raw_input().split()
n=input() a=int(n[-1]) if a==2 or a==4 or a==5 or a ==7 or a==9: print('hon') elif a==0 or a==1 or a==6 or a==8: print('pon') else: print('bon')
0
null
9,952,598,573,830
47
142
import copy import random D = list(map(int, input().split())) q = int(input()) for x in range(q): y, z = map(int, input().split()) while True: r = random.randint(0,3) if r == 0: Dt = copy.copy(D) temp = Dt[0] Dt[0] = Dt[4] Dt[4] = Dt[5] Dt[5] = Dt[1] Dt[1] = temp elif r== 1: Dt = copy.copy(D) temp = Dt[0] Dt[0] = Dt[2] Dt[2] = Dt[5] Dt[5] = Dt[3] Dt[3] = temp elif r== 2: Dt = copy.copy(D) temp = Dt[0] Dt[0] = Dt[3] Dt[3] = Dt[5] Dt[5] = Dt[2] Dt[2] = temp elif r == 3: Dt = copy.copy(D) temp = Dt[0] Dt[0] = Dt[1] Dt[1] = Dt[5] Dt[5] = Dt[4] Dt[4] = temp D = copy.copy(Dt) if Dt[0] == y and Dt[1] == z: print(Dt[2]) break
class dise: def __init__(self, label): self.label1 = label[0] self.label2 = label[1] self.label3 = label[2] self.label4 = label[3] self.label5 = label[4] self.label6 = label[5] def N_rotation(self): reg = self.label1 self.label1 = self.label2 self.label2 = self.label6 self.label6 = self.label5 self.label5 = reg def E_rotation(self): reg = self.label1 self.label1 = self.label4 self.label4 = self.label6 self.label6 = self.label3 self.label3 = reg def S_rotation(self): reg = self.label1 self.label1 = self.label5 self.label5 = self.label6 self.label6 = self.label2 self.label2 = reg def W_rotation(self): reg = self.label1 self.label1 = self.label3 self.label3 = self.label6 self.label6 = self.label4 self.label4 = reg def right_rotation(self): reg = self.label2 self.label2 = self.label3 self.label3 = self.label5 self.label5 = self.label4 self.label4 = reg def search(self, value): while True : self.N_rotation() if value[0] == self.label1: break self.E_rotation() if value[0] == self.label1: break while True : self.right_rotation() if value[1] == self.label2: break init_dise = input().split() times = int(input()) for i in range(times): dise1 = dise(init_dise) order = input().split() dise1.search(order) print(dise1.label3)
1
249,778,383,998
null
34
34
import math r = input() print '%.10f %.10f' %(r*r*math.pi , r*2*math.pi)
import math class Circle: def output(self, r): print "%.6f %.6f" % (math.pi * r * r, 2.0 * math.pi * r) if __name__ == "__main__": cir = Circle() r = float(raw_input()) cir.output(r)
1
634,074,461,488
null
46
46
N = int(input()) print('Yes' if N >= 30 else 'No')
a = int(input()) print("Yes") if a >= 30 else print("No")
1
5,751,648,742,490
null
95
95
n=int(input()) p=10**9+7 A=list(map(int,input().split())) binA=[] for i in range(n): binA.append(format(A[i],"060b")) exp=[1] for i in range(60): exp.append((exp[i]*2)%p) ans=0 for i in range(60): num0=0 num1=0 for j in range(n): if binA[j][i]=="0": num0+=1 else: num1+=1 ans=(ans+num0*num1*exp[59-i])%p print(ans)
# coding: utf-8 import sys from collections import deque output_str = deque() data_cnt = int(input()) for i in range(data_cnt): line = input().rstrip() if line.find(" ") > 0: in_command, in_str = line.split(" ") else: in_command = line if in_command == "insert": output_str.appendleft(in_str) elif in_command == "delete": if output_str.count(in_str) > 0: output_str.remove(in_str) elif in_command == "deleteFirst": output_str.popleft() elif in_command == "deleteLast": output_str.pop() print(" ".join(output_str))
0
null
61,546,243,066,080
263
20
n = int(input()) S = list(map(int, input().split())) q = int(input()) T = map(int, input().split()) count = 0 for key in T: U = S + [key] i = 0 while U[i] != key: i = i+1 if i != n: count = count + 1 print(count)
n = int(input()) S = [int(i) for i in input().split()] q = int(input()) T = [int(i) for i in input().split()] cnt = 0 for T in T: if T in S: cnt += 1 print(cnt)
1
68,016,101,428
null
22
22
a, b, k = map(int, input().split()) a = a-k if a < 0: b += a print(max(a, 0), max(b, 0))
n, m = (int(x) for x in input().split()) list_a = sorted([int(x) for x in input().split()], reverse=True) for i in range(0, m): if list_a[i] < sum(list_a) / (4 * m): print('No') exit() print('Yes')
0
null
71,527,840,381,412
249
179
A = int(input()) if A >= 30: print('Yes') else: print('No')
from fractions import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations def main(): X = int(input()) print('Yes') if X >= 30 else print('No') if __name__ == '__main__': main()
1
5,731,011,973,290
null
95
95
N=int(input()) K=int(input()) import sys sys.setrecursionlimit(10**6) def solve(N, K): if K==1: l=len(str(N)) ans=0 for i in range(l): if i!=l-1: ans+=9 else: ans+=int(str(N)[0]) #print(ans) return ans else: nextK=K-1 l=len(str(N)) ini=int(str(N)[0]) res=ini*(10**(l-1))-1 #print(res) if l>=K: ans=solve(res, K) nextN=int(str(N)[1:]) ans+=solve(nextN, nextK) return ans else: return 0 ans=solve(N,K) print(ans)
taro_score = 0 hanako_socore = 0 game_times = int(input()) for _ in range(game_times): cards = input().split() if cards[0] > cards[1]: taro_score += 3 elif cards[0] == cards[1]: taro_score += 1 hanako_socore += 1 else: hanako_socore += 3 print(taro_score, hanako_socore)
0
null
39,090,144,175,622
224
67
class Tree(): def __init__(self, n, edge, indexed=1): self.n = n self.tree = [[] for _ in range(n)] for e in edge: self.tree[e[0] - indexed].append(e[1] - indexed) self.tree[e[1] - indexed].append(e[0] - indexed) def setroot(self, root): self.root = root self.parent = [None for _ in range(self.n)] self.parent[root] = -1 self.depth = [None for _ in range(self.n)] self.depth[root] = 0 self.order = [] self.order.append(root) self.size = [1 for _ in range(self.n)] stack = [root] while stack: node = stack.pop() for adj in self.tree[node]: if self.parent[adj] is None: self.parent[adj] = node self.depth[adj] = self.depth[node] + 1 self.order.append(adj) stack.append(adj) for node in self.order[::-1]: for adj in self.tree[node]: if self.parent[node] == adj: continue self.size[node] += self.size[adj] import sys input = sys.stdin.readline N, u, v = map(int, input().split()) u -= 1; v -= 1 E = [tuple(map(int, input().split())) for _ in range(N - 1)] t = Tree(N, E) t.setroot(u); dist1 = t.depth t.setroot(v); dist2 = t.depth tmp = 0 for i in range(N): if dist1[i] < dist2[i]: tmp = max(tmp, dist2[i]) print(tmp - 1)
import sys input = sys.stdin.readline from collections import deque def bfs(s): dist = [-1]*N dist[s] = 0 q = deque([s]) while q: v = q.popleft() for nv in adj_list[v]: if dist[nv]==-1: dist[nv] = dist[v]+1 q.append(nv) return dist N, u, v = map(int, input().split()) adj_list = [[] for _ in range(N)] for _ in range(N-1): Ai, Bi = map(int, input().split()) adj_list[Ai-1].append(Bi-1) adj_list[Bi-1].append(Ai-1) d1 = bfs(u-1) d2 = bfs(v-1) ans = 0 for i in range(N): if d1[i]<d2[i]: ans = max(ans, d2[i]-1) print(ans)
1
117,202,179,558,688
null
259
259
a,b,c = map(int,input().split()) print("%s"%("Yes" if a<b<c else "No"))
n,a=int(input()),sorted(list(map(int,input().split()))) m=a[-1]+1 s=[0]*m for i in a: s[i]+=1 for i in set(a): if s[i]: for j in range(i*2,m,i): s[j]=0 print(s.count(1))
0
null
7,419,785,617,090
39
129
n, W = map(int, input().split()) ab = [tuple(map(int, input().split()))for _ in range(n)] ab.sort() dp = [[0]*W for _ in range(n+1)] for i in range(1, n+1): w, v = ab[i-1] for j in range(W): if dp[i][j] < dp[i-1][j]: dp[i][j] = dp[i-1][j] if 0 <= j-w and dp[i][j] < dp[i-1][j-w]+v: dp[i][j] = dp[i-1][j-w]+v ans = 0 for i in range(n): a, b = ab[i] if ans < dp[i][W-1]+b: ans = dp[i][W-1]+b print(ans)
import sys read = sys.stdin.buffer.read def main(): N, T, *AB = map(int, read().split()) D = [(a, b) for a, b in zip(*[iter(AB)] * 2)] D.sort() dp = [[0] * T for _ in range(N + 1)] for i, (a, b) in enumerate(D): for t in range(T): if 0 <= t - a: dp[i + 1][t] = dp[i][t - a] + b if dp[i + 1][t] < dp[i][t]: dp[i + 1][t] = dp[i][t] ans = 0 for i in range(N - 1): if ans < dp[i + 1][T - 1] + D[i + 1][1]: ans = dp[i + 1][T - 1] + D[i + 1][1] print(ans) return if __name__ == '__main__': main()
1
151,245,326,716,032
null
282
282
i = 1 while(1): x = int(input()) if(x == 0):break print("Case %d: %d" % (i, x)) i += 1
i = 0 while True : x = int(input()) if(x == 0) : break else : i += 1 print("Case ", i, ": ", x, sep = "")
1
500,574,225,020
null
42
42
def gcd (a,b): if a%b==0: return b if b%a==0: return a if a>b: return gcd(b,a%b) return gcd(a,b%a) def lcm (a,b): return ((a*b)//gcd(a,b)) inp=list(map(int,input().split())) a=inp[0] b=inp[1] print (lcm(a,b))
from sys import exit import math import collections ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) a,b = mi() print((a*b)//math.gcd(a,b))
1
113,613,795,895,282
null
256
256
X = int(input()) for a in range(-119, 120): for b in range(-119, 120): if X == a**5 - b**5: la = a lb = b print(la, lb)
ma = lambda: map(int, input().split()) t,u = ma(); a,c = ma(); b,d = ma() p = (a-b)*t; q = (c-d)*u if p < 0: p *= -1; q *= -1 if p+q > 0: print(0) elif p+q == 0: print('infinity') else: t = -p-q print(1+(p//t)*2 if p%t else (p//t)*2)
0
null
78,289,909,908,320
156
269
import math r = float(raw_input()) print '%.5f %.5f' % (r*r*math.pi, 2*r*math.pi)
A = input() B = input() candidate = set(('1', '2', '3')) exclude = set((A, B)) print((candidate - exclude).pop())
0
null
55,356,664,564,278
46
254
x, y, z = map(int, input().split()) y, x = x, y z, x = x, z print(x, y, z)
xyz=list(map(int,input().split())) xyz[0],xyz[1]=xyz[1],xyz[0] xyz[0],xyz[2]=xyz[2],xyz[0] print(xyz[0],xyz[1],xyz[2])
1
37,908,364,105,800
null
178
178
x,y,xx,yy=map(float, input().split()) print('%5f'%((x-xx)**2+(y-yy)**2)**0.5)
import sys for line in sys.stdin: n = [int(i) for i in line.replace("\n", "").split(" ")] n.sort() low = n[0] hi = n[1] while hi % low: hi, low = low, hi % low print("%d %d" % (low, n[0] / low * n[1]))
0
null
82,241,080,698
29
5
a, b, c = [int(x) for x in input().split(" ")] if a < b and b < c: ans ="Yes" else: ans ="No" print(ans)
a,b,c = map(int,input().split()) print("%s"%("Yes" if a<b<c else "No"))
1
389,417,347,368
null
39
39
n,k = map(int,input().split()); kk = n-k+2 a = [0]*kk for i in range(kk): ii = i + k p = ii*(ii-1); q = ii*(2*n+1-ii); a[i] = (q//2)-(p//2)+1; con = 0; for v in range(kk): con = (con+a[v]) % 1000000007; print(con);
import math K = int(input()) result = 0 # 全て等しい場合はそれ自身が最大公約数 for i in range(1, K+1): result += i # 二つが等しい場合は二つある方を選ぶので2倍、二数の公約数の三倍で6倍 d = {} for i in range(1, K+1): for j in range(i+1, K+1): d[(i, j)] = math.gcd(i, j) result += 6 * d[(i, j)] # 三つバラバラなら6倍 for i in range(1, K+1): for j in range(i+1, K+1): for k in range(j+1, K+1): tmp = 0 if i < j: tmp = d[(i, j)] else: tmp = d[(j, i)] if tmp < k: result += 6 * d[(tmp, k)] else: result += 6 * d[(k, tmp)] print(result)
0
null
34,230,842,519,394
170
174
num = map(int, raw_input().split()) if num[0] > num[1]: x = num[0] y = num[1] else: y = num[0] x = num[1] while y > 0: z = x % y x = y y = z print x
def DICE(dice,dir): if dir == "N": dice[0],dice[1],dice[4],dice[5] = dice[1],dice[5],dice[0],dice[4] elif dir == "S": dice[0],dice[1],dice[4],dice[5] = dice[4],dice[0],dice[5],dice[1] elif dir == "E": dice[0],dice[2],dice[3],dice[5] = dice[3],dice[0],dice[5],dice[2] elif dir == "W": dice[0],dice[2],dice[3],dice[5] = dice[2],dice[5],dice[0],dice[3] return dice tmp = raw_input().split() s = raw_input() for i in s: tmp = DICE(tmp, i) print tmp[0]
0
null
118,007,080,000
11
33
N = int(input()) d_lst= [int(x) for x in input().split(' ')] sum = 0 for i in range(len(d_lst)): for j in range(1+i,len(d_lst)): sum = sum + d_lst[i]*d_lst[j] print(sum)
sec_input = int(input()) hour = sec_input // (60 * 60) remain = sec_input % (60 * 60) min = remain // 60 sec = remain % 60 print('%d:%d:%d' % (hour, min, sec))
0
null
84,532,784,318,268
292
37
#セグ木 from collections import deque def f(L, R): return L|R # merge def g(old, new): return old^new # update zero = 0 #零元 class segtree: def __init__(self, N, z): self.M = 1 while self.M<N: self.M *= 2 self.dat = [z] * (self.M*2-1) self.ZERO = z def update(self, x, idx, l=0, r=-1): if r==-1: r = self.M idx += self.M-1 self.dat[idx] = g(self.dat[idx], x) while idx > 0: idx = (idx-1)//2 self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2]) def query(self, a, b=-1, idx=0, l=0, r=-1): if r==-1: r = self.M if b==-1: b = self.M q = deque([]) q.append([l, r, 0]) ret = self.ZERO while len(q): tmp = q.popleft() L = tmp[0] R = tmp[1] if R<=a or b<=L: continue elif a<=L and R<=b: ret = f(ret, self.dat[tmp[2]]) else: q.append([L, (L+R)//2, tmp[2]*2+1]) q.append([(L+R)//2, R, tmp[2]*2+2]) return ret n = int(input()) s = list(input()) q = int(input()) seg = segtree(n+1, 0) for i in range(n): num = ord(s[i]) - ord("a") seg.update((1<<num), i) for _ in range(q): a, b, c = input().split() b = int(b) - 1 if a == "1": pre = ord(s[b]) - ord("a") now = ord(c) - ord("a") seg.update((1<<pre), b) seg.update((1<<now), b) s[b] = c else: q = seg.query(b, int(c)) bin(q).count("1") print(bin(q).count("1"))
#1indexed class BIT(): def __init__(self, n): self.size = n self.bit = [0] * (n+1) def sum(self, i): s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.bit[i] += x i += i & -i n = int(input()) s = input() q = int(input()) bit = [BIT(n+1) for i in range(26)] for i in range(n): bit[ord(s[i])-97].add(i+1, 1) s = list(s) for _ in range(q): query, a, b = input().split() if query == "1": i = int(a) c = ord(b)-97 bit[c].add(i, 1) bit[ord(s[i-1])-97].add(i, -1) s[i-1] = b else: ans = 0 for k in range(26): if bit[k].sum(int(b))-bit[k].sum(int(a)-1) >= 1: ans += 1 print(ans)
1
62,238,364,281,836
null
210
210
#!/usr/bin/env python3 def main(): n = int(input()) S, T = input().split() print(*[s + t for s, t in zip(S, T)], sep="") if __name__ == "__main__": main()
a,b,c=[int(x) for x in input().split()] print('Yes' if a<b<c else 'No')
0
null
56,210,920,296,572
255
39
import sys inlist = list(map(int, sys.stdin.readline().split(" "))) a = inlist[0] b = inlist[1] print("{0} {1} {2:f}".format(a // b, a % b, a / b))
A,B = map(int,input().split()) ans=int(A-B*2) print(ans if ans >= 0 else 0)
0
null
83,618,007,528,990
45
291
N = int(input()) ans = -(-N // 2) print(ans)
n,k=map(int,input().split()) p=list(map(int,input().split())) dp=[0]*(n-k+1) dp[0]=sum(p[:k]) for i in range(n-k): dp[i+1]=dp[i]+p[k+i]-p[i] print((max(dp)+k)/2)
0
null
66,976,447,739,872
206
223
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))
n=int(input()) a=list(map(int,input().split())) res=0 for i in range(n): res^=a[i] ans=[] for i in range(n): ans.append(res^a[i]) print(*ans)
1
12,458,018,907,278
null
123
123
N,K,C = map(int,input().split()) S = list(input()) F = [] maru = 0 last = -10**9 span = C for i in range(N): if S[i]=="o" and span >= C: maru += 1 last = i F.append([maru,last]) span = 0 else: span += 1 F.append([maru,last]) #print(F) s = S[::-1] maru = 0 last = 10**9 span = C E = [] for i in range(N): if s[i] == "o" and span >= C: maru += 1 last = N-1-i E.append([maru,last]) span = 0 else: E.append([maru,last]) span += 1 E = E[::-1] #print(E) F = [[0,-10**9]] + F + [[0,10**9]] E = [[0,-10**9]] + E + [[0,10**9]] #print(F) #print(E) ans = [] for i in range(1,N+1): cnt = F[i-1][0] + E[i+1][0] if S[i-1] == "o": if E[i+1][1] - F[i-1][1] < C: cnt -= 1 if cnt == K-1: ans.append(i) #print(F[i-1],E[i+1],cnt) for i in range(len(ans)): print(ans[i])
import sys _ = sys.stdin.readline() x=sys.stdin.readline() arr=x.split() arrInt=list() #print(arr, type(arr)) for i in arr: # print(i) arrInt.append(int(i)) #print(arrInt,type(arrInt)) print(min(arrInt),max(arrInt),sum(arrInt))
0
null
20,568,520,985,028
182
48
N = int(input()) Alist = list(map(int, input().split())) Alist = [[idx+1, a] for (idx, a) in enumerate(Alist)] Alist.sort(key=lambda x:x[1]) ans = [str(a) for a, _ in Alist] print(" ".join(ans))
l, r, d = [int(x) for x in input().rstrip().split(" ")] print(r//d-l//d + (l%d==0))
0
null
93,671,527,315,890
299
104
def resolve(): N = int(input()) ans = N % 1000 if ans == 0: print(0) else: print(1000 - ans) resolve()
n=int(input()) change=1000-n%1000 if change==1000: print(0) else: print(change)
1
8,424,828,799,900
null
108
108
n=int(input()) s=100000 for i in range(n): s*=1.05 p=s%1000 if p!=0: s+=1000-p print(int(s))
N = int(input()) A=list(map(int,input().split())) A.sort(reverse=True) sum=0 for i in range(1,N): sum+=A[i//2] print(sum)
0
null
4,600,522,353,042
6
111
def root(x): if F[x] < 0: return x else: F[x] = root(F[x]) return F[x] def unite(x, y): x = root(x) y = root(y) if x == y: return if x > y: x, y = y, x F[x] += F[y] F[y] = x N, M = map(int, input().split()) F = [-1] * N for m in range(M): a, b = map(int, input().split()) unite(a - 1, b - 1) ans = 0 for f in F: ans = min(ans, f) print(-ans)
import sys import math from collections import defaultdict 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 main(): R, C, K = NMI() item = [[0] * (C + 1) for i in range(R + 1)] for i in range(K): r_, c_, v_, = NMI() item[r_ - 1][c_ - 1] = v_ dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)] for i in range(R + 1): for j in range(C + 1): for k in range(4): a = dp[k][i][j] v = item[i][j] if k == 3: dp[0][i + 1][j] = max(a, dp[0][i + 1][j]) continue dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j]) dp[k][i][j + 1] = max(a, dp[k][i][j + 1]) dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1]) print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) if __name__ == "__main__": main()
0
null
4,736,849,830,658
84
94
import math print(2*float(input())*math.pi)
print(2*3.14159*int(input()))
1
31,466,235,066,240
null
167
167
h, w = map(int, input().split()) from math import ceil odd = ceil(h/2) * ceil(w/2) even = int(h/2) * int(w/2) if h==1 or w==1: print(1) else: print(odd + even)
import math h,w = map(int,input().split()) if h == 1 or w == 1: print(1) else: print(math.ceil(h/2*w))
1
50,782,894,476,160
null
196
196
def merge(a, left, mid, right): L = a[left:mid] + [INF] R = a[mid:right] + [INF] i = 0 j = 0 for k in range(left, right): global idx idx += 1 if( L[i] <= R[j] ): a[k] = L[i] i += 1 else: a[k] = R[j] j += 1 def merge_sort(a, left, right): if( left + 1 < right ): mid = (left + right) // 2 merge_sort(a, left, mid) merge_sort(a, mid, right) merge(a, left, mid, right) INF = 1000000000 idx = 0 n = int(input()) a = [int(i) for i in input().split()] merge_sort(a,0,len(a)) print(*a) print(idx)
f=[1,1] for _ in[0]*43:f+=[f[-2]+f[-1]] print(f[int(input())])
0
null
60,144,182,420
26
7
h, w = map(int, input().split()) s = [input() for _i in range(h)] visit = [[float("inf") for _ in range(w)] for _j in range(h)] visit[0][0] = 0 for i in range(h): for j in range(w): if i-1 >= 0: visit[i][j] = visit[i-1][j]+(s[i][j]!=s[i-1][j]) if j-1 >= 0: visit[i][j] = min(visit[i][j], visit[i][j-1]+(s[i][j]!=s[i][j-1])) if s[0][0]==s[h-1][w-1]==".": print(visit[h-1][w-1]//2) elif s[0][0]==s[h-1][w-1]=="#": print(visit[h-1][w-1]//2 +1) else: print(visit[h-1][w-1]//2 +1)
def main(): import sys input=sys.stdin.buffer.readline h,w=map(int,input().split()) b,q=b'.'*w,range(w) for i in range(h): s=input() a=[] a_add=a.append for x,y,z,c in zip(b,b'.'+s,s,q): if x==46>z:c+=1 if y==46>z:i+=1 if i>c:i=c a_add(i) b,q=s,a print(i) main()
1
49,353,343,197,990
null
194
194
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)
# coding: utf-8 a, b = map(int, input().split()) ans = -1 if a < 10 and b < 10: ans = a * b print(ans)
1
158,664,903,368,998
null
286
286
from sys import stdin from collections import deque # 入力 n = int(input()) # command = [stdin.readline()[:-1] for a in range(n)] command = stdin # process output = deque([]) for a in command: if a[0] == 'i': output.appendleft(int(a[7:])) elif a[0:7] == 'delete ': try: output.remove(int(a[7:])) except ValueError: pass elif a[6] == 'F': output.popleft() else: output.pop() # 出力 print(*list(output))
from collections import deque n = int(input()) dll = deque() for i in range(n): input_line = input().split() if input_line[0] == "insert": dll.appendleft(input_line[1]) elif len(dll) == 0: continue elif input_line[0] == "delete": try: dll.remove(input_line[1]) except: pass elif input_line[0] == "deleteFirst": dll.popleft() else: dll.pop() print(*dll)
1
50,130,195,816
null
20
20
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline INF = 10**9 # 個数制限なしナップザック問題 h,n = map(int, input().split()) dp = [INF]*(h+1) dp[0] = 0 for i in range(n): a,b = map(int, input().split()) for j in range(h): nj = min(a+j, h) dp[nj] = min(dp[nj], dp[j]+b) print(dp[-1])
import sys def gcd(m, n): if n > m: m, n = n, m if n == 0: return m else: return gcd(n, m % n) for line in sys.stdin: try: a, b = [int(i) for i in line.split()] g = gcd(a, b) l = a * b / g print("%d %d" % (g, l)) except: break
0
null
40,481,168,421,804
229
5
W = input() T = "" while True: x = input() if x == "END_OF_TEXT": break T += x + " " num = 0 for t in T.split(): if t.lower() == W.lower(): num += 1 print(num)
n=input() a=map(int,raw_input().split()) INF=10**18 pr=[0]*(n+2) pr[0]=1 for i in xrange(n+1): pr[i+1]=min(INF,(pr[i]-a[i])*2) if pr[n+1]<0: print "-1" exit(0) s=0 ans=0 for i in xrange(n,-1,-1): s=min(s+a[i],pr[i]) ans+=s print ans
0
null
10,359,081,804,600
65
141
s=input() if len(s)%2!=0: print("No") exit() for i,c in enumerate(s): if (i%2==0 and c=="h") or (i%2==1 and c=="i"): continue else: print("No") exit() print("Yes")
s = input() ans = [0 for i in range(len(s)+1)] for i in range(len(s)): if s[i] == '<': ans[i+1] = max(ans[i+1],ans[i]+1) for i in range(len(s)-1,-1,-1): if s[i] == '>': ans[i] = max(ans[i],ans[i+1]+1) print(sum(ans))
0
null
104,594,990,659,808
199
285
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d N = int(input()) alphabet = "abcdefghijklmnopqrstuvwxyz" curr_str = [] def print_str(curr_str): string = "" for i in curr_str: string += alphabet[i] print(string) def dfs(index, curr_str, curr_char): if curr_char > index: return None if curr_char > max(curr_str) + 1: return None if index == N-1: print_str(curr_str + [curr_char]) return None for i in range(N): dfs(index+1, curr_str+[curr_char], i) if N == 1: print("a") else: for i in range(N): dfs(1, [0], i)
def main(): from string import ascii_lowercase dic = {i: s for i, s in enumerate(ascii_lowercase)} N = int(input()) ans = [] def dfs(s, mx): if len(s) == N: print(s) return else: for i in range(mx+2): v = s + dic[i] mx = max(mx, i) dfs(v, mx) dfs("a", 0) if __name__ == '__main__': main()
1
52,042,349,662,490
null
198
198
ans = ["1","2","3"] a,b = input(),input() ans.remove(a) ans.remove(b) print(ans[0])
A = int(input()) B = int(input()) for x in range(1, 4): if x not in [A, B]: print(x) break
1
110,486,852,814,830
null
254
254
n,x,y=map(int,input().split()) ans=[0]*n tree=[[] for _ in range(n)] for i in range(1,n): tree[i-1].append(i) tree[i].append(i-1) tree[x-1].append(y-1) tree[y-1].append(x-1) from collections import deque ans=[0]*n for i in range(n): checked=[-1]*n stack=deque([i]) checked[i]=0 while len(stack)>0: tmp=stack.popleft() for item in tree[tmp]: if checked[item]==-1: checked[item]=checked[tmp]+1 stack.append(item) for item in checked: ans[item]+=1 for item in ans[1:]: print(item//2)
import sys read = sys.stdin.read readlines = sys.stdin.readlines from collections import defaultdict def main(): n, x, y = map(int, input().split()) x -= 1 y -= 1 dis = defaultdict(int) for i1 in range(n): for i2 in range(i1+1, n): d = min(abs(i2-i1), abs(x-i1)+abs(y-i2)+1, abs(x-i2)+abs(y-i1)+1) dis[d] += 1 for k1 in range(1, n): print(dis[k1]) if __name__ == '__main__': main()
1
44,331,167,409,618
null
187
187
def main(): x, y, z = map(int, input().split(" ")) print(f"{z} {x} {y}") if __name__ == "__main__": main()
#!/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(N: int, M: int, p: "List[int]", S: "List[str]"): ac = [0 for _ in range(N)] for i in set(x[0] for x in zip(p, S) if x[1] == "AC"): ac[i - 1] = 1 wa = 0 for x in zip(p, S): ac[x[0] - 1] &= x[1] == "WA" wa += ac[x[0] - 1] return f'{len(set(x[0] for x in zip(p,S) if x[1] == "AC"))} {wa}' def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int p = [int()] * (M) # type: "List[int]" S = [str()] * (M) # type: "List[str]" for i in range(M): p[i] = int(next(tokens)) S[i] = next(tokens) print(f"{solve(N, M, p, S)}") if __name__ == "__main__": main()
0
null
65,610,878,472,468
178
240
# coding: UTF-8 #共通関数と演算 def pprint(numlist): print(" ".join(map(str,numlist))) def greater(s,t): if s[1] > t[1]: return True else: return False def equal(s,t): if s[1] == t[1]: return True else: return False def wasStable(Ans,Initial,N): I = Initial.copy() for i in range(N-1): if equal(Ans[i],Ans[i+1]): for x in I: if equal(Ans[i],x): if(Ans[i][0] != x[0]): return False else: I.remove(x) break return True #input N = int(input()) A = input().split() Initial = A.copy() B = A.copy() #バブルソート count = 0 flag = True while flag: flag = False j = N - 1 while j >= 1: if greater(A[j-1],A[j]): v = A[j] A[j] = A[j-1] A[j-1] = v flag = True count += 1 j -= 1 pprint(A) print("Stable") #選択ソート count = 0 for i in range(N): j=i minj=i while j<= N-1: if greater(B[minj],B[j]): minj = j j += 1 if i != minj: v=B[i] B[i]=B[minj] B[minj]=v count += 1 print(" ".join(map(str,B))) if wasStable(B,Initial,N): ans = "Stable" else: ans = "Not stable" print(ans)
def bblsrt(cards): cards1 = cards.copy() for i in range(len(cards1)): for j in range(len(cards1) - 1, i, -1): if cards1[j][1] < cards1[j - 1][1]: cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j] return cards1 def slcsrt(cards): cards2 = cards.copy() for i in range(len(cards2)): minj = i for j in range(i, len(cards2)): if cards2[j][1] < cards2[minj][1]: minj = j cards2[i], cards2[minj] = cards2[minj], cards2[i] return cards2 n = int(input()) C = list(input().split()) print(' '.join(bblsrt(C))) print('Stable') print(' '.join(slcsrt(C))) print('Stable' if slcsrt(C) == bblsrt(C) else 'Not stable')
1
23,503,779,478
null
16
16
k = int(input()) s = input() l = len(s) if l > k: print(s[0:k] + '...') else: print(s)
import math import collections K = int(input()) S = input() L = list(S) if len(L) <= K: print(S) else: M = L[:K] print(''.join(M)+'...')
1
19,630,930,997,340
null
143
143
if __name__ == '__main__': n = int(input()) dic = set() for i in range(n): Cmd, Key = input().split() if Cmd == "insert": dic.add(Key) else: if Key in dic: print("yes") else: print("no")
n = int(input()) pair = [1, 1] for i in range(n - 1): pair[i % 2] = sum(pair) print(pair[n % 2])
0
null
39,128,973,868
23
7
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): A, B = map(int, readline().split()) if A < 10 and B < 10: print(A * B) else: print(-1) return if __name__ == '__main__': main()
D = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(D)] out = [int(input()) for _ in range(D)] sat = 0 last = [0] * 26 for d in range(D): assert(1 <= out[d] and out[d] <= 26) j = out[d] - 1 last[j] = d + 1 for i in range(26): sat -= (d + 1 - last[i]) * c[i] sat += s[d][j] print(sat)
0
null
84,465,477,325,680
286
114
from collections import defaultdict from collections import deque from collections import Counter import math def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() n,k = readInts() a = readInts() a.sort(reverse=True) if n==1: print(math.ceil(a[0]/(k+1))) exit() def get(left, right): l = (right-left)//2+left ans = 0 for i in a: ans+=math.ceil(i/l)-1 #print(l, ans, left, right) return ans,l def nibu(left,right): ans,l = get(left, right) if left<right: if ans<=k: return nibu(left,l) else: return nibu(l+1, right) else: return right print(nibu(1,a[0]))
def solve(): N, K = map(int,input().split()) A = list(map(int,input().split())) left = 0 right = 10 ** 9 while right - left > 1: mid = (right+left) // 2 cnt = 0 for a in A: cnt += (a-1) // mid if cnt <= K: right = mid else: left = mid print(right) if __name__ == '__main__': solve()
1
6,529,751,466,180
null
99
99
S = list(input()) if S[-1] != "s": S.append("s") else: S.append("es") print(*S, sep="")
s=input() if s[len(s)-1]=='s':print(s+'es') else:print(s+'s')
1
2,417,941,515,378
null
71
71
s=0 j=0 a=[] k=[] l=[] for i,x in enumerate(input()): if x=='\\': a+=[i] elif x=='/' and a: j=a.pop() y=i-j;s+=y while k and k[-1]>j: y+=l.pop() k.pop() k+=[j] l+=[y] print(s) print(len(k),*(l))
# -*- coding: utf-8 -*- l = input() S1, S2 = [], [] sum = 0 n = len(l) for i in range(n): if l[i] == "\\": S1.append(i) elif l[i] == "/" and S1: j = S1.pop() a = i - j sum += a while S2 and S2[-1][0] > j: a += S2.pop()[1] S2.append([j, a]) print(sum) print(len(S2), *(a for j, a in S2))
1
57,987,045,076
null
21
21
import sys n = int(input()) for i in range(int(n / 1.08), int(n / 1.08) + 2): if int(i * 1.08) == n: print(i) sys.exit() else: print(":(")
import math n=int(input()) num=math.ceil(n/1.08) if math.floor(num*1.08)==n: print(num) else: print(":(")
1
125,853,074,500,150
null
265
265
k = int(input()) s = str(input()) if len(s) <= k: print(s) elif len(s) > k: print(s[:k] + '...')
K = int(input()) N = list(input()) #print(K,N) ans = [] if len(N) > K: for i in range(len(N)-K): #print(i,len(N)) N.pop(-1) N.append("...") print("".join(N))
1
19,517,012,321,678
null
143
143
import math a,b,c=map(float,input().split()) if c<90: e=c*math.pi/180 S=a*b*1/2*math.sin(e) t=a**2+b**2-2*a*b*math.cos(e) r=math.sqrt(t) L=a+b+r h=b*math.sin(e) print('{:.08f}'.format(S)) print('{:.08f}'.format(L)) print('{:.08f}'.format(h)) if c==90: e=c*math.pi/180 S=a*b*1/2*math.sin(e) t=a**2+b**2-2*a*b*math.cos(e) r=math.sqrt(t) L=a+b+r h=b print('{:.08f}'.format(S)) print('{:.08f}'.format(L)) print('{:.08f}'.format(h)) if c>90: e=c*math.pi/180 d=180*math.pi/180 f=d-e S=a*b*1/2*math.sin(e) t=a**2+b**2-2*a*b*math.cos(e) r=math.sqrt(t) L=a+b+r h=b*math.sin(f) print('{:.08f}'.format(S)) print('{:.08f}'.format(L)) print('{:.08f}'.format(h))
import math a, b, C = map(int, input().split()) C = math.radians(C) c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C)) S = a * b * math.sin(C) / 2 print(f"{S:0.9f}") print(f"{a+b+c:0.9f}") print(f"{S*2/a:0.9f}")
1
173,438,159,618
null
30
30
from fractions import gcd import sys n, m = map(int, input().split()) a = [int(i) for i in input().split()] b = [i // 2 for i in a] def div2check(i): count = 0 while i % 2 == 0: count += 1 i //= 2 return count c = [div2check(i) for i in b] if c.count(c[0]) != n: print(0) sys.exit() lcm = b[0] for i in b[1:]: lcm = lcm * i // gcd(lcm, i) print((m // lcm + 1) // 2)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): from fractions import gcd n, m = list(map(int, readline().split())) a = list(map(int, readline().split())) cnt = [0] * n for i, elem in enumerate(a): x = elem c = 0 while x % 2 == 0: x //= 2 c += 1 cnt[i] = c ans = 0 if len(set(cnt)) == 1: lcm = a[0] for elem in a[1:]: lcm = (lcm * elem) // gcd(lcm, elem) ans = (m + (lcm // 2)) // lcm print(ans) if __name__ == '__main__': main()
1
101,820,625,735,250
null
247
247
from collections import defaultdict n, k = map(int, input().split()) m = defaultdict(int) for _ in range(k): input() for x in input().split(): m[int(x)] += 1 result = 0 for i in range(1, n+1): if m[i] == 0: result += 1 print(result)
n,k=map(int,input().split()) lst_ans=[] for i in range(k): s=int(input()) lst_n=list(map(int,input().split())) for j in lst_n: lst_ans.append(j) print(n-len(set(lst_ans)))
1
24,689,835,827,422
null
154
154
n = input() ans = 0 for nn in n: ans += int(nn) print('Yes') if ans%9 == 0 else print('No')
r, c = list(map(int,input().split())) S = [map(int,input().split()) for i in range(r)] col_sum = [0 for i in range(c)]; for row in S: row = list(row) print(' '.join(map(str,row)) + ' {}'.format(sum(row))) col_sum = [x + y for (x,y) in zip(col_sum,row)] print(' '.join(map(str,col_sum)) + ' {}'.format(sum(col_sum)))
0
null
2,894,899,208,902
87
59
import sys import math r, c = map(int, raw_input().split()) b = [0 for i in xrange(c+1)] for i in xrange(r): a = map(int, raw_input().split()) for j in xrange(c): b[j] += a[j] sys.stdout.write(str(a[j]) + " ") print sum(a) b[c] += sum(a) for j in xrange(c+1): sys.stdout.write(str(b[j])) if j < c: sys.stdout.write(" ") print
while True: a = input() b = a.split(' ') b.sort(key=int) if int(b[0]) == 0 and int(b[1]) == 0: break print('%s %s' % (b[0],b[1]))
0
null
935,535,517,070
59
43
h,w,m=map(int,input().split()) item=[list(map(int,input().split())) for i in range(m)] row=[0]*h col=[0]*w for i in range(m): x,y=item[i] row[x-1]+=1 col[y-1]+=1 mr,mc=max(row),max(col) xr=set([i for i in range(h) if row[i]==mr]) xc=set([i for i in range(w) if col[i]==mc]) check=len(xr)*len(xc) for i in range(m): r,c=item[i] if r-1 in xr and c-1 in xc: check-=1 print(mr+mc if check>0 else mr+mc-1)
H, W, M = map(int, input().split()) h = [0 for _ in range(H+1)] w = [0 for _ in range(W+1)] hmax = 0 wmax = 0 Q = [] for _ in range(M): a, b = map(int, input().split()) Q.append((a, b)) h[a] += 1 hmax = max(hmax, h[a]) w[b] += 1 wmax = max(wmax, w[b]) h_ok = False w_ok = False hm = [False for _ in range(H+1)] wm = [False for _ in range(W+1)] h_cnt = 0 w_cnt = 0 hw_cnt = 0 for a, b in Q: if not hm[a] and h[a] == hmax: hm[a] = True h_cnt += 1 if not wm[b] and w[b] == wmax: wm[b] = True w_cnt += 1 if h[a] == hmax and w[b] == wmax: hw_cnt += 1 if h_cnt*w_cnt - hw_cnt > 0: print(hmax+wmax) else: print(hmax+wmax-1)
1
4,775,165,214,092
null
89
89
N = int(input()) A = sorted([int(i) for i in input().split()], reverse=True) print(sum([A[(i+1)//2] for i in range(N-1)]))
n = int(input()) arr = list(map(int, input().split())) arr.sort(reverse=True) ans = arr[0] i = 1 j = 1 while i < n-1: ans += arr[j] #print (arr[j]) if i % 2 == 0: j += 1 i += 1 print (ans)
1
9,176,857,161,252
null
111
111
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() num = 0 for i in range(N): a, b = MI() if a == b: num += 1 if num == 3: print("Yes") return else: num = 0 print("No") main()
N,X,M = map(int,input().split()) ls = [X] for i in range(M): Ai = ls[-1]**2 % M if Ai in ls: loop = ls[ls.index(Ai):] lenloop = len(loop) sumloop = sum(loop) startls = ls[:ls.index(Ai)] break ls.append(Ai) if N <= len(startls): ans = sum(startls[:N]) else: ans = sum(startls) + ((N-len(startls))//lenloop)*sumloop + sum(loop[:(N-len(startls))%lenloop]) print(ans)
0
null
2,643,571,705,148
72
75
import sys sys.setrecursionlimit(10**6) h, w, m = map(int, input().split()) # 各行各列に何個ずつあるか hs = [0] * h ws = [0] * w # 座標を記録 s = set() readline = sys.stdin.readline for _ in range(m): r, c = [int(i) for i in readline().split()] r -= 1 c -= 1 hs[r] += 1 ws[c] += 1 s.add((r, c)) # 最大値 mh = 0 mw = 0 for i in range(h): mh = max(mh, hs[i]) for j in range(w): mw = max(mw, ws[j]) # 最大値をとっている行・列 si = [] sj = [] for i in range(h): if mh == hs[i]: si.append(i) for j in range(w): if mw == ws[j]: sj.append(j) # 爆破対象がないマスに爆弾を設置できれば尚良し。そこでmh+mwをansに仮に記録して、1個でも見つかればその座標を出力。見つからなければ、爆破対象があるマスに爆弾を設置するのが最大となるので、ans=mh+mw-1となる ans = mh + mw for i in si: for j in sj: if (i, j) in s: continue print(ans) exit() print(ans-1)
from collections import defaultdict h, w, m = map(int, input().split()) target = [] point = defaultdict(int) count_target_of_y = defaultdict(int) count_target_of_x = defaultdict(int) for i in range(m): x, y = map(int, input().split()) count_target_of_y[y] += 1 count_target_of_x[x] += 1 point[(x,y)] += 1 max_x_count = max(list(count_target_of_x.items()), key=lambda x:x[1])[1] max_y_count = max(list(count_target_of_y.items()), key=lambda x:x[1])[1] max_x_count_list = [i for i in count_target_of_x.items() if i[1] == max_x_count] max_y_count_list = [i for i in count_target_of_y.items() if i[1] == max_y_count] for x in max_x_count_list: for y in max_y_count_list: if point[(x[0], y[0])] == 0: print(max_x_count + max_y_count) exit() print(max_x_count + max_y_count - 1)
1
4,785,861,439,020
null
89
89
x,y=map(int,input().split()) print(100000*(max(4-x,0)+max(4-y,0)+4*(x==y==1)))
x, y = map(int, input().split()) def shokin(z): if z == 1: return 300000 elif z == 2: return 200000 elif z == 3: return 100000 else: return 0 v = 0 if x == 1 and y == 1: v = 400000 print(shokin(x)+shokin(y)+v)
1
140,404,857,599,620
null
275
275
# Take both input K & S, then compare the length of S with K and assign it to length # If the length is <= K print all # And if length is >K print some of the character K = int(input()) S = input() x = 0 length = len(S) if length <= K: print(S) else: while x < K: print(S[x], end=("")) x += 1 print("...")
A, B, C, K = map(int, input().split()) # 1:A枚, 0:B枚, -1:C枚, K枚を選ぶ A = min(A, K) B = min(K - A, B) C = min(K - A - B, C) assert A + B + C >= K #print(A, B, C) print(A - C)
0
null
20,756,643,408,874
143
148
import sys N, D = map(int, input().split()) ans = 0 for _ in range(N): x, y = map(int, sys.stdin.readline().split()) if x **2 + y**2 <= D**2: ans += 1 print(ans)
def dfs(v): global t, d, f, visited d[v] = t visited[v] = True t += 1 for u in AL[v]: if not visited[u]: dfs(u) f[v] = t t += 1 # 入力 n = int(input()) AL = [[] for _ in range(n + 1)] for v in range(1, n + 1): AL[v] = [int(x) for x in input().split()][2:] # 計算 d = [0] * (n + 1) f = [0] * (n + 1) t = 1 visited = [False] * (n + 1) for v in range(1, n + 1): if not visited[v]: dfs(v) # 出力 for v in range(1, n + 1): print(v, d[v], f[v])
0
null
2,999,292,897,688
96
8
a,b,c=input().split() print(c,a,b)
A, B, C = map(str, input().split()) print(C+' '+A+' '+B)
1
37,923,300,640,448
null
178
178
n = int(input()) li_a = list(map(int, input().split())) dic_a = {} for a in li_a: dic_a[a] = dic_a.get(a, 0) + 1 q = int(input()) li_bc = list() for i in range(q): li_bc.append(tuple(map(int, input().split()))) answer = sum(li_a) for l in li_bc: b = l[0] c = l[1] diff = (c - b) * dic_a.get(b, 0) if b in dic_a.keys(): dic_a[c] = dic_a.get(c, 0) + dic_a.get(b, 0) dic_a[b] = 0 answer += diff else: pass print(answer)
import sys n = int(input()) for i in range(1, n + 1): x = i if x % 3 == 0: sys.stdout.write(" %d" % i) else: while x > 1: if x % 10 == 3: sys.stdout.write(" %d" % i) break x //= 10 print()
0
null
6,631,953,336,932
122
52
def main(): S = input() Q = int(input()) order = [list(input().split()) for _ in range(Q)] left_flag = 0 right_flag = 0 cnt = 0 for i in range(Q): if order[i][0] == '1': cnt += 1 else: if cnt%2 == 0: if order[i][1] == '1': if left_flag == 1: left = order[i][2] + left else: left = order[i][2] left_flag = 1 else: if right_flag == 1: right = right + order[i][2] else: right = order[i][2] right_flag = 1 else: if order[i][1] == '2': if left_flag == 1: left = order[i][2] + left else: left = order[i][2] left_flag = 1 else: if right_flag == 1: right = right + order[i][2] else: right = order[i][2] right_flag = 1 if left_flag == 1 and right_flag == 1: S = left + S + right elif left_flag == 1 and right_flag == 0: S = left + S elif left_flag == 0 and right_flag == 1: S = S + right else: S = S if cnt%2 == 0: return(S) else: S2 = S[-1] for i in range(len(S)-2,-1,-1): S2 = S2 + S[i] return S2 print(main())
S = input() for i in range(1,6): if S == "hi" * i: print("Yes") exit(0) print("No")
0
null
55,471,353,052,362
204
199
def min_dist(x_b,y_b): s=0 for x,y in zip(x_b,y_b): s+=abs(x-y) return s def man_dist(x_b,y_b): s=0 for x, y in zip(x_b,y_b): s+=(abs(x-y))**2 return s**0.5 def che_dist(x_b,y_b): s=0 for x,y in zip(x_b,y_b): s+=(abs(x-y))**3 return s**(1/3) def anf_dist(x_b,y_b): s=[abs(x-y) for x,y in zip(x_b,y_b)] return max(s) n=int(input()) x_b=list(map(int,input().split())) y_b=list(map(int,input().split())) print(min_dist(x_b,y_b)) print(man_dist(x_b,y_b)) print(che_dist(x_b,y_b)) print(anf_dist(x_b,y_b))
n = int(input()) x = list(map(int,input().split())) y = list(map(int,input().split())) i = 0 p1 = 0 p2 = 0 p3 = 0 p4 = 0 for _ in range(n): if x[i] > y[i]: p1 = (x[i] - y[i]) + p1 else: p1 = (y[i] - x[i]) + p1 i = i + 1 print('{:.8f}'.format(p1)) i = 0 for _ in range(n): p2 = ((x[i] - y[i]))**2 + p2 i = i + 1 print('{:.8f}'.format(p2**(1/2))) i = 0 for _ in range(n): if x[i] > y[i]: p3 = ((x[i] - y[i]))**3 + p3 else: p3 = ((y[i] - x[i]))**3 + p3 i = i + 1 print('{:.8f}'.format(p3**(1/3))) i = 0 M = 0 for _ in range(n): if x[i] > y[i]: p4 = x[i] - y[i] if M < p4: M = p4 else: p4 = y[i] - x[i] if M < p4: M = p4 i = i + 1 print('{:.8f}'.format(M))
1
206,853,586,652
null
32
32
while True: m,f,r=map(int, input().split()) s=m+f if m==-1 and f==-1 and r==-1: break elif m==-1 or f==-1 or s <30: print('F') elif s <50 and r <50: print('D') elif s <65: print('C') elif s <80: print('B') else: print('A')
if __name__ == '__main__': from sys import stdin while True: m, f, r = (int(n) for n in stdin.readline().rstrip().split()) if m == f == r == -1: break s = m + f result = "F" if m == -1 or f == -1 \ else "A" if 80 <= s \ else "B" if 65 <= s \ else "C" if 50 <= s or 50 <= r \ else "D" if 30 <= s \ else "F" print(result)
1
1,232,195,675,812
null
57
57
def solve(n,s): if "ABC" not in s: return 0 cnt = 0 for i in range(len(s)-2): if "ABC" == s[i:i+3]: cnt+=1 return cnt n = int(input()) s = input() ans = solve(n,s) print(ans)
n = int(input()) a = list(map(int,input().split())) mod = 1000000007 ans = 1 l = [] for i in range(n): if a[i] == 0: l.append(0) ans = ans*(4-len(l))%mod else: id = -1 count = 0 for j in range(len(l)): if l[j] == a[i] - 1: count += 1 id = j if id == -1: ans = 0 break ans = (ans*count)%mod l[id] = a[i] if ans == 0: break print(ans%mod)
0
null
114,730,665,676,438
245
268
S, W =map(int, input().split()) print('unsafe') if W >= S else print('safe')
#!/usr/bin/env python3 import sys def solve(S: int, W: int): print("safe" if S > W else "unsafe") return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = int(next(tokens)) # type: int W = int(next(tokens)) # type: int solve(S, W) if __name__ == '__main__': main()
1
29,193,204,206,500
null
163
163
def main(): """ ????????? """ num = int(input().strip()) F = [] for n in range(num+1): if n < 2: F.append(1) else: F.append(F[n-1] + F[n-2]) print (F[num]) if __name__ == '__main__': main()
n = int(input()) a = int(0) b = int(1) if n==1: A = b elif n==2: A = 2 else: for i in range(n): a,b = b,a+b A = b print(A)
1
1,722,093,088
null
7
7
s=input() l=input().split() m=[int(i) for i in l] print("{} {} {}".format(min(m),max(m),sum(m)))
input() xs = list(map(int, input().split())) print(' '.join(map(str,[f(xs) for f in [min,max,sum]])))
1
727,684,409,540
null
48
48
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K, *H = map(int, read().split()) H.sort(reverse=True) print(sum(H[K:])) return if __name__ == '__main__': main()
N,K = map(int,input().split()) H = list(map(int,input().split())) H = sorted(H)[::-1] H = H[K:N] print(str(sum(H)))
1
79,349,008,949,110
null
227
227
#!/usr/bin python3 # -*- coding: utf-8 -*- x = int(input()) print(10-x//200)
#!usr/bin/env python3 from collections import defaultdict, deque, Counter from heapq import heappush, heappop from itertools import permutations import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): x = I() if 599 >= x >= 400: print(8) elif 799 >= x >= 600: print(7) elif 999 >= x >= 800: print(6) elif 1199 >= x >= 1000: print(5) elif 1399 >= x >= 1200: print(4) elif 1599 >= x >= 1400: print(3) elif 1799 >= x >= 1600: print(2) elif 1999 >= x >= 1800: print(1) return # Solve if __name__ == "__main__": solve()
1
6,720,466,597,952
null
100
100
n=int(input()) p=2 from itertools import product iterator=product(range(p),repeat=n) #for idxs in iterator: # print(idxs) L=[[] for i in range(n)] for i in range(n): a=int(input()) for _ in range(a): L[i].append(list(map(int,input().split()))) ans=0 for idxs in iterator: cnt_honest=0 for i in range(n): cnt=0 if idxs[i]==1: for j in L[i]: if idxs[j[0]-1]==j[1]: cnt+=1 if cnt==len(L[i]): cnt_honest+=1 if cnt_honest==sum(idxs): ans=max(sum(idxs),ans) print(ans)
n=int(input()) A=[{} for _ in range(n)] for i in range(n): for _ in range(int(input())): x,y=map(int,input().split()) A[i][x]=y a=0 for i in range(2**n): t=0 for j in range(n): if i>>j&1: if A[j] and any(i>>~-k&1!=A[j][k] for k in A[j]): break else: t+=1 else: a=max(a,t) print(a)
1
122,014,265,690,252
null
262
262
x = int(input()) for i in range(1,1500): for j in range(-1000,1000): y = i**5 - j**5 if x == y: print(i,j) exit()
S = input() N=len(S) h=0 for i in range(0,N//2): if S[i]!=S[N-1-i]: h+=1 print(h)
0
null
73,127,506,395,358
156
261