code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
h = int(input()) ans = 1 while h > 0: h //= 2 ans *= 2 print(ans-1)
H=int(input()) x=0 while True: x+=1 if 2**x>H: x-=1 break ans=0 for i in range(x+1): ans+=2**i print(ans)
1
79,912,490,813,342
null
228
228
#!/usr/bin/env python3 def main(): A, B = map(int, input().split()) if A>9 or B>9: ans=-1 else: ans=A*B print(ans) if __name__ == "__main__": main()
#144-A A,B = map(int,input().split()) if 1 <= A <= 9 and 1 <= B <= 9: print(A*B) else: print(-1)
1
158,106,833,320,188
null
286
286
def solve(m, f, r): if (m == -1 or f == -1) or m + f < 30: return "F" for a, b in ((80, "A"), (65, "B"), (50, "C")): if m + f >= a: return b if r >= 50: return "C" return "D" while True: m, f, r = map(int, input().split()) if m == f == r == -1: break print(solve(m, f, r))
n = int(input()) s = list(map(int, input().split())) c = 0 a = 'a' def merge(A, left, mid, right): global c L = A[left:mid] R = A[mid:right] L.append(10 ** 9) R.append(10 ** 9) i = 0 j = 0 for k in range(left, right): c += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergesort(A, left, right): if left+1 < right: mid = (left+right)//2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) mergesort(s, 0, n) for i in range(n-1): print(s[i], end=' ') print(s[n-1]) print(c)
0
null
682,231,090,940
57
26
import sys x, y = map(int, input().split()) ans = 0 for i in range(x+1): if y == i*2 + (x - i)* 4: ans = 1 break if ans == 1: print("Yes") else: print("No")
X,Y = map(int,input().split()) turtle_leg = 4 crane_leg = 2 for i in range(X+1): if Y == turtle_leg*i+crane_leg*(X-i): print ("Yes") break if i==X: print ("No") break
1
13,705,085,181,220
null
127
127
a,b = map(int,input().split()) if(a-(2*b)<0): print(0) else: print(a-(2*b))
a,b=map(int, input().split()) c=a-2*b print(c if c>=0 else 0 )
1
166,661,399,592,624
null
291
291
# author: kagemeka # created: 2019-11-09 21:20:16(JST) ### modules ## from standard library import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics # import functools # import operator ## from external libraries # import scipy.special # import scipy.misc # import numpy as np def main(): n = int(sys.stdin.readline().rstrip()) if n % 2 == 0: ans = n // 2 - 1 else: ans = n // 2 print(ans) if __name__ == "__main__": # execute only if run as a script main()
H, W, K = map(int, input().split()) a = [input() for _ in range(H)] ans = [[-1 for _ in range(W)] for _ in range(H)] i_cut_time = 0 j_cut_time = 0 for i in range(H): if '#' in a[i]: i_cut_time += 1 i_cut = [] start = 0 goal = -1 for i in range(H): if len(i_cut) == i_cut_time-1: break if '#' in a[i]: goal = i i_cut.append([start, goal, i]) start = goal+1 for i in range(start, H): if '#' in a[i]: i_cut.append([start, H-1, i]) # print(i_cut) cnt = 1 for s, g, p in i_cut: j_cut = [] jstart = 0 jgoal = -1 for i in range(W): if len(j_cut) == a[p].count('#')-1: break if a[p][i] == '#': jgoal = i j_cut.append([jstart, jgoal]) jstart = jgoal+1 j_cut.append([jstart, W-1]) # print(s, g, p, j_cut) # for i in range(s, g+1): for js, jg in j_cut: for j in range(js, jg+1): for i in range(s, g+1): # print(i, j, cnt) ans[i][j] = cnt cnt += 1 # print(*ans, sep='\n') for i in range(H): print(*ans[i])
0
null
148,818,727,570,630
283
277
from sys import stdin import sys a = stdin.readline().rstrip() b = stdin.readline().rstrip() count = 0 for i in range(len(a)): if a[i] != b[i]: count = count + 1 print (count)
S = list(input()) T = list(input()) L = len(S) i = 0 cn = 0 N = 200000 while i < L: if S[i] != T[i]: i = i + 1 cn = cn + 1 else: i = i + 1 print(cn)
1
10,463,590,148,480
null
116
116
n=int(input()) result = [0] * (n+1) for x in range(1,99): for y in range(1,99): for z in range(1,99): fn = x*x + y*y + z*z + x*y + y*z + z*x if fn > n: break result[fn] += 1 for i in range(1,n+1): print(result[i])
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) ans = [0]*N for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): val = x**2+y**2+z**2+x*y+y*z+z*x if val<=N: ans[val-1] += 1 for v in ans: print(v)
1
8,023,446,880,020
null
106
106
N = int(input()) MAX = 10**6 table = [0]*(MAX+1) for x in map(int,input().split()): table[x] += 1 for i in range(MAX+1): if table[i]: for j in range(2*i if table[i] == 1 else i, MAX+1, i): table[j] = 0 print(sum(table))
n = int(input()) def dfs(s): if len(s) == n: print(s) return for i in range(ord("a"), ord(max(s))+2): dfs(s+chr(i)) dfs("a")
0
null
33,550,365,344,078
129
198
A, B = map(int,input().split()) mult = A * B print(mult)
n,m=map(int,input().split());print(n*m)
1
15,714,931,996,108
null
133
133
def main(): x = int(input()) a = x // 500 b = (x - 500 * a) // 5 ans = int(a * 1000 + b * 5) print(ans) if __name__ == '__main__': main()
n = int(input()) if n%2 == 0: t=(n//2)/n else: t=(n//2+1)/n print('{:.10f}'.format(t))
0
null
109,873,681,250,970
185
297
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) else: ans=0 if l-1>=nextK: nextN=int(str(N)[1:]) ans+=solve(nextN, nextK) return ans return ans ans=solve(N,K) print(ans)
import math N = int(input()) X = N/1.08 Y = math.ceil(X) Z = math.floor(Y*1.08) if N == Z: print(Y) else: print(':(')
0
null
100,734,457,173,860
224
265
import io import sys import math def solve(): A, B, H, M = list(map(int, input().split())) C_sq = A**2 + B**2 - 2*A*B*math.cos((H - 11/60 * M)*math.pi/6) C = math.sqrt(C_sq) print(C) if __name__ == "__main__": solve()
import math rad = math.pi/180 A, B, H, M = map(int, input().split()) x = 6*M*rad y = (60*H + M) * 0.5 * rad print(math.sqrt(A**2 + B**2 -2*A*B*math.cos(x-y)))
1
20,093,171,432,670
null
144
144
import numpy as np n, *a = map(int, open(0).read().split()) s = np.cumsum(np.array(a)) print(min([abs(s[n - 1] - s[i] - s[i]) for i in range(n - 1)]))
from collections import deque n, x, y = map(int, input().split()) graph = [[i-1,i+1] for i in range(n+1)] graph[1]=[2] graph[n]=[n-1] graph[0]=[0] graph[x].append(y) graph[y].append(x) def bfs(start,graph2): dist = [-1] * (n+1) dist[0] = 0 dist[start] = 0 d = deque() d.append(start) while d: v = d.popleft() for i in graph2[v]: if dist[i] != -1: continue dist[i] = dist[v] + 1 d.append(i) dist = dist[start+1:] return dist ans=[0 for _ in range(n-1)] for i in range(1,n+1): for j in bfs(i,graph): ans[j-1] +=1 for i in ans: print(i)
0
null
93,126,835,007,190
276
187
v = int(input()) n = list(map(int, input().split(' '))) c = 0 for i in range(0, v, 2): if n[i] %2 == 1: #print(n[i]) c += 1 print(c)
N=int(input()) A = list(map(int, input().split())) ans = 0 for i in range(0, N, 2): ans += A[i] % 2 != 0 print(ans)
1
7,751,962,874,040
null
105
105
import sys read = sys.stdin.readline import time import math import itertools as it def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ N, K = inpl() A = inpl() for i in range(K, N): if A[i] > A[i-K]: print('Yes') else: print('No') # ----------------------------- ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
N, K = map(int, input().split()) A = list(map(int, input().split())) for idx, a in enumerate(A): if idx < K: continue else: if a <= A[idx - K]: print('No') else: print('Yes')
1
7,065,987,848,428
null
102
102
N,X,M = map(int,input().split()) ans = X A = X TF = True srt = 1000000 retu = [X] d = dict() d[X] = 0 loop = X flag = False for i in range(N-1): if TF: A = A**2 % M if d.get(A) != None: srt = d[A] goal = i TF = False if TF: retu.append(A) d[A] = i + 1 loop += A else: flag = True break if flag: n = (N-srt)//(goal-srt+1) saisyo = sum(retu[:srt]) loop -= saisyo print(saisyo + loop*n + sum(retu[srt:N-n*(goal-srt+1)])) else: print(sum(retu[:N]))
n = int(input()) if n == 1: print(1) elif n % 2 == 0: print(0.5) else: import math print(math.ceil(n/2)/n)
0
null
89,576,044,753,180
75
297
S=input() t=len(S) print("YNeos"[sum(1for i in range(t) if S[i]!=S[~i] )!=0 or S[(t+2)//2:]!=S[:(t-1)//2]::2])
s = input() def check(): if s != s[::-1]: return("No") n = len(s) s1 = s[:int((n-1)/2)] #print(s1) if s1 != s1[::-1]: return("No") s2 = s[int((n+3)/2-1):] if s2 != s2[::-1]: return("No") #print(s2) return("Yes") print(check())
1
46,513,122,323,456
null
190
190
import sys from collections import deque mapin = lambda: map(int, sys.stdin.readline().split()) listin = lambda: list(map(int, sys.stdin.readline().split())) inp = lambda: sys.stdin.readline() class UnionFind(): def __init__(self,n): self.N = n self.par = [-1] * n def find(self,n): if self.par[n] < 0: return n else: self.par[n] = self.find(self.par[n]) return self.par[n] def unite(self,x,y): x = self.find(x) y = self.find(y) if x == y: return False else: if -self.par[x] < -self.par[y]: x,y = y,x self.par[x] += self.par[y] self.par[y] = x def size(self,x): return -self.par[self.find(x)] def tree_num(self): res = 0 for i in self.par: res += i < 0 return res def same(self,x,y): return self.find(x) == self.find(y) def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) N,M = mapin() UF = UnionFind(N) for i in range(M): a,b = mapin() a,b = a - 1,b - 1 UF.unite(a,b) ans = 0 for i in UF.par: if i < 0: if ans < -i: ans = -i print(ans)
S = input() N = len(S)+1 x = [0 for _ in range(N)] l = 0 while(l<N-1): r = l+1 while(r<N-1 and S[r]==S[l]): r += 1 if S[l]=='<': x[l] = 0 for i in range(l+1, r+1): x[i] = max(x[i], x[i-1]+1) else: x[r] = 0 for i in range(r-1, l-1, -1): x[i] = max(x[i], x[i+1]+1) l = r print(sum(x))
0
null
80,561,845,619,530
84
285
def f(num,N,S): alphabet = ["a","b","c","d","e","f","g","h","i","j"] if N == num: for i in range(len(S)): print(S[i]) return else: tmp = [] length = len(S) for i in S: ttmp = sorted(list(i)) for j in range(alphabet.index(ttmp[-1])+2): tmp.append(i+alphabet[j]) f(num+1,N,tmp) N = int(input()) f(1,N,["a"])
i = 0 while 1: x = raw_input() i += 1 if x == '0': break print 'Case %s: %s' % (i,x)
0
null
26,573,764,813,408
198
42
import math import numpy as np pi = math.pi a, b, x = map(int, input().split()) if x >= a**2*b/2: print(180/pi*np.arctan(2*(a**2*b-x)/a**3)) else: print(180/pi*np.arctan(a*b**2/(2*x)))
import numpy as np a, b, x = map(int, input().split()) ans = 0 if (a*a*b/2) <= x: ans = np.rad2deg(np.arctan((2*(a*a*b-x))/(a*a*a))) else: ans = np.rad2deg(np.arctan((a*b*b)/(2*x))) print('{:.10f}'.format(ans))
1
162,438,608,956,740
null
289
289
n = int(input()) flag = False for x in (range(1,10)): for y in (range(1,10)): if x * y == n: flag = True else: continue break if flag: print("Yes") else: print("No")
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import time,random,resource sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def JA(a, sep): return sep.join(map(str, a)) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def main(): n,k = LI() a = LI() for kk in range(k): r = [0] * (n+1) for i in range(n): c = a[i] r[max(0, i - c)] += 1 r[min(n, i + c + 1)] -= 1 if r[0] == n and r[n] == -n: a = [n] * n break t = 0 for i in range(n): t += r[i] a[i] = t return JA(a, " ") print(main())
0
null
87,586,339,216,762
287
132
W, H ,x, y, r = map(int, input().split()) if ((x-r)<0) or ((y-r)<0) or ((x+r)>W) or ((y+r)>H): print("No") else: print("Yes")
W, H, x, y, r = [int(i) for i in input().rstrip().split(" ")] hidari, migi = x-r, x + r shita, ue = y-r, y+r if (0 <= hidari) and (migi <= W) and (0 <= shita) and (ue <= H): print("Yes") else: print("No")
1
452,521,151,768
null
41
41
n = int( raw_input( ) ) dic = {} output = [] for i in range( n ): cmd, word = raw_input( ).split( " " ) if "insert" == cmd: dic[ word ] = True elif "find" == cmd: try: dic[ word ] output.append( "yes" ) except KeyError: output.append( "no" ) print( "\n".join( output ) )
x=int(input()) if x<100: print(0) else: n=x//100 y=x%100 if y==0: print(1) else: if int((y+4)//5)<=n: print(1) else: print(0)
0
null
63,775,840,532,100
23
266
a,b=map(int,raw_input().split()) print'%d %d' %(a*b,2*(a+b))
tmp = raw_input().split() a = int(tmp[0]) b = int(tmp[1]) s = a * b l = 2 * (a+b) print "%d %d" % (s, l)
1
305,237,605,460
null
36
36
while True: H, W = [int(i) for i in input().split()] if H == 0 and W == 0: break for i in range(H): for j in range(W): if (i + j) % 2 == 0: print('#', end='') else: print('.', end='') print('') print('')
l='#.'*999 while 1: h,w=map(int,raw_input().split());s="" if h==0:break for i in range(h):s+=l[i%2:w+i%2]+"\n" print s
1
859,031,719,620
null
51
51
n, k = list(map(int, input().split())) list = list(map(int, input().split())) ans = [l for l in list if l >= k] print(len(ans))
N, K = map(int, input().split()) H = list(map(int, input().split())) print(len(list(filter(lambda x: x >= K, H))))
1
179,092,029,367,648
null
298
298
N, M = map(int, input().split()) A = list(map(int, input().split())) w = sum(A) ans = N - w if ans >= 0: print(ans) else: print(-1)
n,m = map(int,input().split()) a = list(map(int,input().split())) ans = 0 if sum(a) >n: ans = -1 else: ans = n-sum(a) print(ans)
1
32,014,163,504,192
null
168
168
from sys import stdin def main(): readline = stdin.readline n = int(readline()) s = tuple(readline().strip() for _ in range(n)) plus, minus = [], [] for c in s: if 2 * c.count('(') - len(c) > 0: plus.append(c) else: minus.append(c) plus.sort(key = lambda x: x.count(')')) minus.sort(key = lambda x: x.count('('), reverse = True) plus.extend(minus) sum = 0 for v in plus: for vv in v: sum = sum + (1 if vv == '(' else -1) if sum < 0 : return print('No') if sum != 0: return print('No') return print('Yes') if __name__ == '__main__': main()
#!/usr/bin/python3 #coding: utf-8 N = int(input()) p = 10**9 + 7 ret = pow(10, N) ret -= pow(9, N) ret -= pow(9, N) ret += pow(8, N) ret %= p print(ret)
0
null
13,379,977,177,788
152
78
f = lambda: int(input()) d = -float('inf') n = f() l = f() for _ in range(n-1): r = f() d = max(d, r-l) l = min(l, r) print(d)
import sys lines = [line.split() for line in sys.stdin] T = H = 0 n = int(lines[0][0]) for w1,w2 in lines[1:]: if w1 > w2: T += 3 elif w1 < w2: H += 3 else: T += 1 H += 1 print (str(T) + " " + str(H))
0
null
1,026,809,265,928
13
67
#!/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() ans = 1 for a in range(1, N-1): num_b = (N-1) // a ans += num_b print(ans) main()
n = int(input()) print(sum([(n-1)//a for a in range(1, n)]))
1
2,589,737,723,642
null
73
73
h,w,k= map(int, input().split()) s = [[int(i) for i in input()] for i in range(h)] for i in range(h): for j in range(1,w): s[i][j]+=s[i][j-1] for i in range(w): for j in range(1,h): s[j][i]+=s[j-1][i] # 1行目、一列目をゼロにする。 s=[[0]*w]+s for i in range(h+1): s[i]=[0]+s[i] ans=float('inf') #bit 全探索 for i in range(2**(h-1)): line=[] for j in range(h-1): if (i>>j)&1: line.append(j+1) cnt=len(line) line=[0]+line+[h] x=0 flag=True for k1 in range(1,w+1): v=0 for l in range(len(line)-1): # どう分割してもダメな奴に✖︎のフラグ立てる if s[line[l+1]][k1]-s[line[l+1]][k1-1]-s[line[l]][k1]>k: flag=False v=max(s[line[l+1]][k1]-s[line[l+1]][x]-s[line[l]][k1]+s[line[l]][x],v) if v>k: cnt+=1 x=k1-1 if flag: ans=min(cnt,ans) print(ans)
N = int(input()) h = [2,4,5,7,9] p = [0,1,6,8] b = [3] if h.count(N%10)==1: print('hon') if p.count(N%10)==1: print('pon') if b.count(N%10)==1: print('bon')
0
null
33,669,042,832,408
193
142
while True: m, f, r = map(int, raw_input().split()) if m + f + r == -3: break if m == -1 or f == -1: grade = 'F' elif m + f >= 80: grade = 'A' elif m + f >= 65: grade = 'B' elif m + f >= 50: grade = 'C' elif m + f >= 30: grade = 'C' if r >= 50 else 'D' elif m + f < 30: grade = 'F' print grade
scores = [] while True: score = list(map(int, input().split())) if score[0] == -1 and score[1] == -1 and score[2] == -1: break else: scores.append(score) for i in scores: mid_exam = i[0] final_exam = i[1] re_exam = i[2] total = i[0] + i[1] if mid_exam == -1 or final_exam == -1: print("F") elif total >= 80: print("A") elif total in range(65, 80): print("B") elif total in range(50, 65): print("C") elif 30 <= total < 50: if re_exam >= 50: print("C") else: print("D") elif total < 30: print("F")
1
1,236,733,421,968
null
57
57
s = input() t = input() ss = len(s) tt = len(t) min = tt for i in range(ss - tt + 1): count = 0 for j in range(tt): if s[i+j] != t[j]: count += 1 if min > count: min = count print(min)
s = input() t = input() numlist = [] for i in range(len(s)-len(t)+1): a = s[i:i+len(t)] count = 0 for j in range(len(t)): if a[j] != t[j]: count += 1 numlist.append(count) print(min(numlist))
1
3,672,253,483,490
null
82
82
from collections import deque N,u,v=map(int,input().split()) G=[[] for _ in range(N)] for _ in range(N-1): a,b = map(int,input().split()) G[a-1].append(b-1) G[b-1].append(a-1) def bfs(s): seen = [0]*N d = [0]*N todo = deque() seen[s]=1 todo.append(s) while len(todo): a = todo.popleft() for b in G[a]: if seen[b] == 0: seen[b] = 1 todo.append(b) d[b] += d[a] + 1 return d d1 = bfs(u-1) d2 = bfs(v-1) print(max([d2[i] for i in range(N) if d1[i]<=d2[i]])-1)
import sys input = sys.stdin.readline N,u,v=map(int,input().split()) E=[tuple(map(int,input().split())) for i in range(N-1)] EDGE=[[] for i in range(N+1)] for x,y in E: EDGE[x].append(y) EDGE[y].append(x) from collections import deque T=[-1]*(N+1) Q=deque() Q.append(u) T[u]=0 while Q: x=Q.pop() for to in EDGE[x]: if T[to]==-1: T[to]=T[x]+1 Q.append(to) A=[-1]*(N+1) Q=deque() Q.append(v) A[v]=0 while Q: x=Q.pop() for to in EDGE[x]: if A[to]==-1: A[to]=A[x]+1 Q.append(to) OK=[0]*(N+1) for i in range(N+1): if T[i]<A[i]: OK[i]=1 ANS=0 for i in range(N+1): if OK[i]==1: ANS=max(ANS,A[i]) print(max(0,ANS-1))
1
117,460,319,928,442
null
259
259
abcd = list(map(int, input().split())) max_pro = -float("inf") for i in range(2): for j in range(1,3): product = abcd[i] * abcd[-j] if max_pro < product: max_pro = product print(max_pro)
while True: H, W = map(int, input().split()) if H == 0 and W == 0: break for i in range(H): if i == 0 or i == H-1: print("#" * W) else: print("#" + "." * (W-2) + "#") print()
0
null
1,941,491,732,102
77
50
a, b, c, d, e = map(int, input().split()) f = (c - a) * 60 f += (d - b) print(f - e)
import sys import time import math def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ A, B = map(int, input().split()) print(A*B // math.gcd(A,B)) # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
0
null
65,552,866,101,750
139
256
# Problem B - Common Raccoon vs Monster # input H, N = map(int, input().split()) a_nums = list(map(int, input().split())) # initialization a_sum = sum(a_nums) # output if a_sum>=H: print("Yes") else: print("No")
N = int(input()) A = N / 2 A = int(A) B = (N + 1) / 2 B = int(B) if N % 2 == 0: print(A) else: print(B)
0
null
68,815,399,376,262
226
206
A,B=list(input().split()) A=int(A) b=B.replace(".","") print(A*int(b)//100)
# -*- coding: utf-8 -*- """ D - Xor Sum 4 https://atcoder.jp/contests/abc147/tasks/abc147_d """ import sys def solve(N, A): MOD = 10**9 + 7 bit_len = max(map(int.bit_length, A)) ans = 0 for i in range(bit_len): zeros, ones = 0, 0 for a in A: if (a & 1<<i): ones += 1 else: zeros += 1 ans = (ans + (ones * zeros * 2**i)) % MOD return ans % MOD def main(args): N = int(input()) A = list(map(int, input().split())) ans = solve(N, A) print(ans) if __name__ == '__main__': main(sys.argv[1:])
0
null
69,784,615,761,924
135
263
N = int(input()) A = list(map(int, input().split())) """ indexのi,jについて、 j - i = A[i] + A[j] になる組の数を数え上げる。 愚直にやると、i,jを全ペアためす。N(O^2)で間に合わない 二つの変数が出てきて、ある式で関係性が表せる場合は、iの式 = jの式 みたいにしてやるとうまくいきことが多い j - i = A[i] + A[j] -> A[i] + i = j - A[j] なので、各参加者について、iとして使う時とjとして使うときで分けて数えていって、最後に組の数を数え上げる A[i], i >=1 なので、2以上 1 <= j <= N, A[j] >= 1 なので、N未満 の範囲を調べればよい """ from collections import defaultdict I = defaultdict(int) J = defaultdict(int) for i in range(N): I[A[i] + i+1] += 1 J[i+1 - A[i]] += 1 ans = 0 for i in range(2, N): ans += I[i] * J[i] print(ans)
import sys array = list(map(int,input().split())) print(array.index(0)+1)
0
null
19,927,976,282,080
157
126
import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(20000000) MOD = 10 ** 9 + 7 INF = float("inf") def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) for _ in range(K): B = [0 for _ in range(N)] count = 0 for i in range(N): if A[i] == N: count += 1 l = max(0, i - A[i]) r = min(N - 1, i + A[i]) B[l] += 1 if r + 1 < N: B[r + 1] -= 1 B = list(accumulate(B)) if count == N: break else: A = B print(*B, sep=" ") if __name__ == "__main__": main()
n, k = map(int, input().split()) aa = list(map(int, input().split())) from itertools import accumulate aa for _ in range(k): d = [0] * n for i, a in enumerate(aa): d[max(i-a, 0)] += 1 end = i+1+a if end < n: d[end] -= 1 d = list(accumulate(d)) if aa == d: break aa = d print(' '.join(str(a) for a in aa))
1
15,533,059,001,480
null
132
132
n,k=map(int,input().split()) a=list(map(int,input().split())) l,r=10**9,0 while l-r>1: t=(l+r)//2 if sum((i-1)//t for i in a)>k: r=t else: l=t print(l)
def check(k, p, w_list): i_w = 0 for i_k in range(k): sum_w = 0 while True: if i_w >= len(w_list): return len(w_list) if sum_w + w_list[i_w] > p: break sum_w += w_list[i_w] i_w += 1 return i_w n, k = list(map(int, input().split())) w_list = list() for _ in range(n): w = int(input()) w_list.append(w) left = 0 right = 100000 * 10000 mid = None while left < right: mid = (left + right) // 2 v = check(k, mid, w_list) if v >= n: right = mid else: left = mid + 1 print(right)
0
null
3,261,790,909,250
99
24
n = int(raw_input()) tp = 0; hp = 0 for i in range(n): tw,hw = raw_input().split() if tw == hw: tp += 1 hp += 1 elif tw > hw: tp += 3 elif tw < hw: hp += 3 print '%s %s' % (tp,hp)
num = int(input()) tscore, hscore = 0, 0 for i in range(num): ts, hs = input().split() if ts > hs: tscore += 3 elif ts < hs: hscore += 3 else: tscore += 1 hscore += 1 print(tscore, hscore)
1
2,031,364,049,120
null
67
67
import numpy as np N = int(input()) ans = 0 for i in range(1, N + 1): if ((i % 3) != 0) & ((i % 5) != 0): ans += i print(ans)
N,K = map(int,input().split()) i = N // K N = N - K * i ans = N while True: N = abs(N - K) if ans > N: ans = N else: break print(ans)
0
null
37,176,977,979,350
173
180
N = int(input()) dic = {} ans = 0 A = list(map(int, input().split())) for i in range(N): dic[i] = 0 for i in range(N): b = A[i]+N-i-1 if A[i] < N-i: a = N-i-A[i]-1 dic[a] += 1 if b < N: ans += dic[b] print(ans)
from collections import Counter n = int(input()) a = list(map(int, input().split())) xc = Counter() yc = Counter() for i, v in enumerate(a): xc[i + v] += 1 yc[i - v] += 1 ans = 0 for v in xc: ans += xc[v] * yc[v] print(ans)
1
25,997,234,036,400
null
157
157
rate = int(input()) print(10 - rate // 200)
def I(): return int(input()) N = I() S = input() ans = 0 for i in range(1000): num = str(i).zfill(3) if S.find(num[0])==-1: continue S1 = S[S.find(num[0])+1:] if S1.find(num[1])==-1: continue S2 = S1[S1.find(num[1])+1:] if S2.find(num[2])==-1: continue ans += 1 print(ans)
0
null
67,289,153,885,568
100
267
import sys def gcd(x, y): if y == 1: return 1 elif y == 0: return x else: return gcd(y, x % y) line = sys.stdin.readline() (a, b) = line.split() a = int(a) b = int(b) if a > b: b, a = a, b print gcd(a, b)
""" N = list(map(int,input().split())) S = [str(input()) for _ in range(N)] S = [list(map(int,list(input()))) for _ in range(h)] print(*S,sep="") """ import sys sys.setrecursionlimit(10**6) input = lambda: sys.stdin.readline().rstrip() inf = float("inf") # 無限 a,b = map(int,input().split()) if 0<a<10 and 0<b<10: print(a*b) else: print(-1)
0
null
79,388,980,275,852
11
286
import sys input=lambda: sys.stdin.readline().rstrip() n,m,k=map(int,input().split()) mod=998244353 n_max=2*(10**5+1) F,FI=[0]*(n_max+1),[0]*(n_max+1) F[0],FI[0]=1,1 for i in range(n_max): F[i+1]=(F[i]*(i+1))%mod FI[n_max-1]=pow(F[n_max-1],mod-2,mod) for i in reversed(range(n_max-1)): FI[i]=(FI[i+1]*(i+1))%mod def comb(x,y): return (F[x]*FI[x-y]*FI[y])%mod P=[1] for i in range(n): P.append((P[-1]*(m-1))%mod) ans=0 for i in range(k+1): ans+=m*P[n-1-i]*comb(n-1,i) if ans>mod: ans%=mod print(ans)
''' https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e ''' def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate #from itertools import product from bisect import bisect_left,bisect_right import heapq from math import floor, ceil #from operator import itemgetter #inf = 10**17 mod = 10**9 + 7 n = int(input()) a = list(map(int, input().split())) cnt = [3] + [0]*n res = 1 for i in a: res *= cnt[i] % mod cnt[i] -= 1 cnt[i+1] += 1 res %= mod print(res) if __name__ == '__main__': main()
0
null
76,364,280,721,728
151
268
s = input() if s == 'hi': print('Yes') elif s == 'hihi': print('Yes') elif s == 'hihihi': print('Yes') elif s == 'hihihihi': print('Yes') elif s == 'hihihihihi': print('Yes') else: print('No')
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() ans = 0 if n % 2 == 1: ans = 0 else: div = 10 while div <= n: ans += n // div div *= 5 print(ans)
0
null
84,639,298,963,008
199
258
r = input() print(r[0:3])
''' Created on 2020/08/29 @author: harurun ''' def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write A,B,N=map(int,pin().split()) x=min(B-1,N) ans=int(A*x/B)-A*int(x/B) print(ans) return main() #解説AC
0
null
21,474,835,022,342
130
161
import sys num = [] for i in sys.stdin: H, W = i.split() if H == W == '0': break num.append((int(H), int(W))) for cnt in range(len(num)): for h in range(num[cnt][0]): for w in range(num[cnt][1]): if w == 0 or w == num[cnt][1] - 1 or h == 0 or h == num[cnt][0] - 1: print('#',end='') else: print('.',end='') print() print()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() from collections import Counter def resolve(): n, m = map(int, input().split()) E = [[] for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1; v -= 1 E[u].append(v) E[v].append(u) cnt = 0 color = [-1] * n def dfs(v): if color[v] != -1: return False color[v] = cnt queue = [v] for v in queue: for nv in E[v]: if color[nv] == -1: color[nv] = cnt queue.append(nv) return True for v in range(n): cnt += dfs(v) print(Counter(color).most_common()[0][1]) resolve()
0
null
2,400,157,374,908
50
84
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## from collections import Counter # c=sorted((i,int(val))for i,val in enumerate(input().split())) import heapq # c=sorted((i,int(val))for i,val in enumerate(input().split())) # n = int(input()) # ls = list(map(int, input().split())) #n=int(input()) #arr = list(map(int, input().split())) #for _ in range(int(input())): def find(x,root): if root[x]==x: return x else: return find(root[x],root) def unioin(x,y): uroot=find(u,root) vroot=find(v,root) if uroot!=vroot: if rank[uroot]>rank[vroot]: root[vroot]=root[uroot] rank[uroot]+=rank[vroot] elif rank[vroot]>rank[uroot]: root[uroot]=root[vroot] rank[vroot]+=rank[uroot] else: rank[uroot]+=rank[vroot] root[vroot]=root[uroot] n,m= map(int, input().split()) rank=[1]*(n+1) root=[i for i in range(n+1)] for i in range(m): u,v = map(int, input().split()) unioin(u,v) ans=0 print(max(rank))
import sys input = lambda: sys.stdin.readline().rstrip() n, m = map(int, input().split()) s = input() ans = [] s = s[::-1] now = 0 while True: for i in range(m, -1, -1): if i == 0: print(-1) sys.exit() if now + i <= n and s[now + i] == "0": now += i ans.append(i) if now == n: print(*ans[::-1]) sys.exit() else: break
0
null
71,636,715,740,448
84
274
s = list(input()) if len(s) % 2 != 0: print("No") exit() while s: if s[0]=="h" and s[1] == "i": s.pop(0) s.pop(0) else: print("No") exit() print("Yes")
# 問題:https://atcoder.jp/contests/abc142/tasks/abc142_b n, k = map(int, input().strip().split()) h = list(map(int, input().strip().split())) res = 0 for i in range(n): if h[i] < k: continue res += 1 print(res)
0
null
115,562,062,553,850
199
298
a,b = map(int,input().split()) print(a-2*b if a > 2*b else 0)
a,b = map(int,input().split()) if a > b * 2: print(a - b * 2) elif a <= b * 2: print(0)
1
166,952,827,803,312
null
291
291
inputs = input().split(" ") a = int(inputs[0]) b = int(inputs[1]) c = int(inputs[2]) d = int(inputs[3]) values = [a*c, a*d, b*c, b*d] print(max(values))
arr = [int(x) for x in input().split()] print( max( max(arr[0]*arr[2], arr[0]*arr[3]), max(arr[1]*arr[2], arr[1]*arr[3]) ))
1
3,053,113,033,920
null
77
77
n = int(input()) a = input().split() print(" ".join(reversed(a)))
n,p = map(int,input().split()) s = list(map(int, list(input()))) def solve(): total = 0 if 10%p == 0: for i in range(n): if s[i] % p == 0: total += i + 1 return total cnt = [0]*p r = 0 ten = 1 for i in range(n-1, 0-1, -1): cnt[r] += 1 r = (r + s[i]*ten) % p total += cnt[r] ten = ten * 10 % p return total print(solve())
0
null
29,749,799,166,428
53
205
def abc154d_dice_in_line(): n, k = map(int, input().split()) p = list(map(lambda x: (int(x)+1)*(int(x)/2)/int(x), input().split())) ans = sum(p[0:k]) val = ans for i in range(k, len(p)): val = val - p[i-k] + p[i] ans = max(ans, val) print(ans) abc154d_dice_in_line()
a, b, c = map(int,raw_input().split()) count = 0 for x in xrange(a,b+1): if c%x == 0: count+=1 print count
0
null
37,917,407,818,768
223
44
N, M = [int(i) for i in input().split(' ')] print((N * (N - 1) + M * (M - 1)) // 2)
from math import floor n,m = map(int,input().split()) a =(n*(n-1))/2 b =(m*(m-1))/2 print(floor(a+b))
1
45,824,734,149,180
null
189
189
n = int(input()) a = list(map(int, input().split())) ma = max(a) dp = [0]*(ma+1) for i in sorted(a): if 1 <= dp[i]: dp[i] += 1 continue for j in range(1, ma//i + 1): dp[j * i] += 1 ans=0 for i in a: if dp[i] == 1: ans += 1 print(ans)
def prime_factor(n): ass=[] for i in range(2,int(n**0.5)+1): while n%i==0:ass.append(i);n//=i if n!=1:ass.append(n) return ass n = int(input()) ans = 0 pf = prime_factor(n) from collections import Counter c = Counter(pf) for i in c.keys(): v = c[i] for j in range(1, 10**20): if j>v: break ans += 1 v -= j print(ans)
0
null
15,655,632,335,060
129
136
sentence = input().lower() ans = input().lower() doublesentence = sentence + sentence print("Yes" if ans in doublesentence else "No")
charge, n_coin = map(int,input().split()) coin_ls = list(map(int, input().split())) coin_ls = [0] + coin_ls dp = [[float('inf')] * (charge+1) for _ in range(n_coin+1)] dp[0][0] = 0 for coin_i in range(1,n_coin+1): for now_charge in range(0,charge+1): if now_charge - coin_ls[coin_i] >= 0: dp[coin_i][now_charge] = min(dp[coin_i][now_charge], dp[coin_i][now_charge-coin_ls[coin_i]]+1) dp[coin_i][now_charge] = min(dp[coin_i-1][now_charge], dp[coin_i][now_charge]) print(dp[n_coin][charge])
0
null
944,372,707,798
64
28
import sys sys.setrecursionlimit(10**8) 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 li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini]*i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value #from itertools import accumulate #list(accumulate(A)) N, M = mi() C = li() ''' # 二次元DP dp = dp2(float('inf'), N+1, M+1) dp[0][0] = 0 for i in range(1, M+1): for j in range(N+1): #if j == 0: #dp[i][j] = 0 dp[i][j] = min(dp[i-1][j], dp[i][j]) c = C[i-1] if j+c <= N: dp[i][j+c] = min(dp[i][j]+1, dp[i-1][j+c]) #print(dp) print(dp[M][N]) ''' # 1次元DP dp = [float('inf') for i in range(N+1)] dp[0] = 0 for i in range(M): for j in range(N+1): c = C[i] if j+c <= N: dp[j+c] = min(dp[j]+1, dp[j+c]) print(dp[N])
N,M = map(int, input().split()) C = list(map(int, input().split())) C.sort() dp = [[float("inf") for _ in range(N+1)] for _ in range(M+1)] dp[0][0] = 0 #i番目までのコインを使えるときに、j円を作る場合の、コインの最小枚数を求める for i in range(M): for j in range(N+1): # i番目を使えない場合 if C[i] > j: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = min(dp[i][j], dp[i+1][j - C[i]] + 1) print(dp[-1][-1])
1
138,096,533,490
null
28
28
N = int(input()) for i in range(10): pay = (i + 1) * 1000 if(pay >= N): break if(pay < N): print("たりません") else: print(pay - N)
a = list(map(int, input().split())) print(max((a[0] * a[2]),(a[0] * a[3]),(a[1] * a[3]),(a[1] * a[2])))
0
null
5,806,810,993,636
108
77
from fractions import gcd def lcm(x, y): return (x * y) // gcd(x, y) A, B = map(int, input().split()) print(lcm(A, B))
a,b = map(int, input().split()) child = a*b if a < b: a,b = b,a r = a%b while r > 0: a = b b = r r = a%b print(child//b)
1
113,383,397,575,502
null
256
256
d,e=0,0 for x in list("0"+input()): d,e=int(x)+min(e,d),9-int(x)+min(e,d+2) print(min(d,e))
class UnionFind: def __init__ (self,n): self.parent = [i for i in range (n)] self.height = [0 for _ in range (n)] def get_root(self,i): if self.parent[i] == i: return i else: self.parent[i] = self.get_root(self.parent[i]) return self.parent[i] def unite(self,i,j): root_i = self.get_root(i) root_j = self.get_root(j) if root_i != root_j: if self.height[root_i] < self.height[root_j]: self.parent[root_i] = root_j else: self.parent[root_j] = root_i if self.height[root_i] == self.height[root_j]: self.height[root_i] += 1 def is_in_group(self,i,j): if self.get_root(i) == self.get_root(j): return True else: return False def main(): N,M = map(int, input().split()) uf = UnionFind(N) for _ in range (M): A,B = map(lambda x: int(x)-1,input().split()) uf.unite(A,B) check = [0]*N for i in range(N): check[uf.get_root(i)] += 1 print(max(check)) main()
0
null
37,429,471,984,788
219
84
lst = [] num = int(input()) while num != 0: lst.append(num) num = int(input()) it = zip(range(len(lst)), lst) for (c, v) in it: print("Case " + str(c+1) + ": " + str(v))
from itertools import permutations n = int(input()) xy = [list(map(int, input().split())) for _ in range(n)] sum = 0 cnt = 0 for i in permutations(xy): for j in range(n - 1): sum += ((i[j][0] - i[j + 1][0]) ** 2 + (i[j][1] - i[j + 1][1]) ** 2) ** 0.5 cnt += 1 print(sum / cnt)
0
null
74,407,818,193,840
42
280
N = int(input()) if N == 1: print(0) else: print(1)
print(1 if input()=="0" else 0)
1
2,929,299,107,802
null
76
76
list = input().split(" ") a = int(list[0]) b = int(list[1]) print(a * b)
k=int(input()) if k%2==0 or k%5==0: print(-1) exit() ans=1 num=7 while num%k!=0: num=10*num+7 num%=k ans+=1 print(ans)
0
null
10,979,260,448,770
133
97
def gcd(x, y): if y == 0: return x else: return gcd(y, x%y) def lcm(x,y): return x/gcd(x, y)*y while True: try: x, y = map(int, raw_input().split()) except EOFError: break print "%d %d" % (gcd(x, y), lcm(x, y))
import sys import fractions import re def lcm(a, b): return a / fractions.gcd(a, b) * b #input_file = open(sys.argv[1], "r") #for line in input_file: for line in sys.stdin: ab = map(int, re.split(" +", line)) a, b = tuple(ab) gcd_ab = fractions.gcd(a, b) lcm_ab = lcm(a, b) print gcd_ab, lcm_ab
1
560,817,488
null
5
5
print('a' if input().islower() else 'A')
n = int(input()) taro = 0 hanako = 0 for i in range(n): columns = input().rstrip().split() tcard = columns[0] hcard = columns[1] if tcard > hcard: taro += 3 elif hcard > tcard: hanako += 3 else: taro += 1 hanako += 1 print(taro,hanako)
0
null
6,722,203,711,652
119
67
def matprod(A,B): C = [] for i in range(len(A)): tmpList = [] for k in range(len(B[0])): tmpVal = 0 for j in range(len(A[0])): tmpVal += A[i][j] * B[j][k] tmpList.append(tmpVal) C.append(tmpList) return C n,m,l = map(int, input().split()) A = [] for i in range(n): A.append(list(map(int, input().split()))) B = [] for i in range(m): B.append(list(map(int, input().split()))) for cr in matprod(A,B): print(' '.join(map(str, cr)))
n_max, m_max, l_max = (int(x) for x in input().split()) a = [] b = [] c = [] for n in range(n_max): a.append([int(x) for x in input().split()]) for m in range(m_max): b.append([int(x) for x in input().split()]) for n in range(n_max): c.append( [sum(a[n][m] * b[m][l] for m in range(m_max)) for l in range(l_max)]) for n in range(n_max): print(" ".join(str(c[n][l]) for l in range(l_max)))
1
1,428,220,127,332
null
60
60
d,t,s=map(int,input().split()) print("Yes" if t>=d/s else "No")
from itertools import combinations n = int(input()) def dfs(s): if len(s) == n: print(s) return 0 for i in range(ord('a'), ord(max(s))+2): t = s t += chr(i) dfs(t) dfs('a')
0
null
27,863,047,422,950
81
198
x = input() print pow(x, 3)
import sys # input = sys.stdin.readline input = lambda: sys.stdin.readline().rstrip() n = int(input()) s = [input() for _ in range(n)] def bracket(x): # f: final sum of brackets '(':+1, ')': -1 # m: min value of f f = m = 0 for i in range(len(x)): if x[i] == '(': f += 1 else: f -= 1 m = min(m, f) # m <= 0 return f, m def func(l): # l = [(f, m)] l.sort(key=lambda x: -x[1]) v = 0 for fi, mi in l: if v + mi >= 0: v += fi else: return -1 return v l1 = [] l2 = [] for i in range(n): fi, mi = bracket(s[i]) if fi >= 0: l1.append((fi, mi)) else: l2.append((-fi, mi - fi)) v1 = func(l1) v2 = func(l2) if v1 == -1 or v2 == -1: ans = 'No' else: ans = 'Yes' if v1 == v2 else 'No' print(ans)
0
null
11,940,505,474,536
35
152
import math H = int(input()) cnt = 0 monster = 1 while(H >= 1): cnt += monster H = math.floor(H/2) monster *= 2 print(cnt)
# coding: utf-8 # Your code here! H=int(input()) count=0 ans=0 while H>1: H=H//2 count+=1 for i in range(count+1): ans+=2**i print(ans)
1
79,922,753,889,950
null
228
228
def roundone(a, b): abc = "123" return abc.replace(a, "").replace(b, "") def main(): a = str(input()) b = str(input()) print(roundone(a, b)) if __name__ == '__main__': main()
import sys from collections import deque input = sys.stdin.readline H, W = map(int, input().split()) grid = [] for _ in range(H): grid.append(list(input().strip())) q = deque() # x, y, count, pre color q.append((0, 0, 1 if grid[0][0] == "#" else 0, grid[0][0])) visited = [[-1 for _ in range(W)] for _ in range(H)] ans = float("inf") while q: x, y, count, pre = q.popleft() # print(x, y, count, pre) v_score = visited[y][x] if v_score != -1 and v_score <= count: continue visited[y][x] = count for dx, dy in ((1, 0), (0, 1)): nx = x + dx ny = y + dy nc = count if nx < 0 or W <= nx or ny < 0 or H <= ny: continue n_color = grid[ny][nx] if n_color != pre and n_color == "#": nc += 1 if nx == W-1 and ny == H-1: ans = min(ans, nc) print(ans) sys.exit() else: if visited[ny][nx] != -1 and visited[ny][nx] <= nc: continue if count == nc: q.appendleft((nx, ny, nc, n_color)) else: q.append((nx, ny, nc, n_color)) # print(visited) print(ans)
0
null
80,283,959,476,978
254
194
A, B, M = map(int, input().split()) price_A = list(map(int, input().split())) price_B = list(map(int, input().split())) min_A = min(price_A) min_B = min(price_B) ans = min_A + min_B for i in range(M): x, y, c = map(int, input().split()) ans = min(price_A[x-1]+price_B[y-1]-c,ans) print(ans)
#!/usr/bin/env python # coding: utf-8 # In[9]: A,B,M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) mylist = [] for _ in range(M): mylist.append(list(map(int, input().split()))) # In[11]: ans = min(a)+min(b) for i in range(M): cost = a[mylist[i][0]-1] + b[mylist[i][1]-1] - mylist[i][2] if cost < ans: ans = cost print(ans) # In[ ]:
1
54,024,386,922,672
null
200
200
import math x1,y1,x2,y2=input().split() x1=float(x1) y1=float(y1) x2=float(x2) y2=float(y2) r=math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) print(r)
#distance import math x1,y1,x2,y2=map(float,input().split()) distance = math.sqrt((x2-x1)**2+(y2-y1)**2) print(distance)
1
158,083,702,422
null
29
29
while 1: H, W=map(int, raw_input().split()) if H==0 and W==0: break for i in range(H): L=list("#"*W) if i%2==0: for j in range(W): if j%2!=0: L[j]="." s="".join(L) print s else: for j in range(W): if j%2==0: L[j]="." s="".join(L) print s print ""
while True: h, w = map(int, input().split()) if h==w==0: break for y in range(h): for x in range(w): print('#.'[(x+y)%2], end='') print() print()
1
863,651,443,380
null
51
51
s = input() d = {'ABC': 'ARC', 'ARC': 'ABC'} print(d[s])
n = int(input()) pair = [1, 1] for i in range(n - 1): pair[i % 2] = sum(pair) print(pair[n % 2])
0
null
11,997,297,857,270
153
7
N ,*S = open(0).read().split() s = list(set(S)) print(len(s))
import sys input = sys.stdin.readline n,m=map(int,input().split()) M=set(tuple(map(int,input().split())) for _ in range(m)) d={i:set() for i in range(1,n+1)} for i,j in M: d[i].add(j) d[j].add(i) vis=set() res = 0 for i in range(1,n+1): if i not in vis: stack = [i] ans = 1 vis.add(i) while stack: curr = stack.pop() for j in d[curr]: if j not in vis: stack.append(j) ans+=1 vis.add(j) res = max(ans,res) print(res)
0
null
17,149,360,271,078
165
84
# coding: utf-8 # Your code here! x1, y1, x2, y2 = map(float,input().split()) x = (x2 - x1) y = (y2 - y1) s = (x*x + y*y)**(1/2) print(s)
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)
0
null
66,662,544,845,858
29
270
N=input() print("ABC" if N=="ARC" else "ARC")
import math n=int(input()) num=math.ceil(n/1.08) if math.floor(num*1.08)==n: print(num) else: print(":(")
0
null
75,365,586,027,380
153
265
W, H, x, y, r = [int(i) for i in input().split()] if r <= y <= H - r and r <= x <= W - r: print('Yes') else: print('No')
A,B,M=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) xyc=[] for i in range(M): tmp=list(map(int,input().split())) xyc.append(tmp) ans=min(a)+min(b) judge=[a[v[0]-1]+b[v[1]-1]-v[2] for v in xyc] print(min(ans,min(judge)))
0
null
27,299,098,164,480
41
200
import numpy as np N = int(input()) A = [] B = [] for i in range(N): a,b=map(int, input().split()) A.append(a) B.append(b) Aarray = np.array(A) Barray = np.array(B) medA = np.median(Aarray) medB = np.median(Barray) if N%2 == 1: ans = medB-medA+1 else: ans = 2*(medB-medA)+1 print(str(int(ans)))
from statistics import median n=int(input()) A,B=[],[] for _ in range(n): a,b=map(int,input().split()) A.append(a*2) B.append(b*2) ma,mb = int(median(A)),int(median(B)) #print(ma,mb) if n%2 == 0: print(mb-ma+1) else: print((mb-ma)//2+1)
1
17,171,109,408,882
null
137
137
x,y,a,b,c=map(int,input().split()) p=sorted(list(map(int,input().split())),reverse=1)[:x] q=sorted(list(map(int,input().split())),reverse=1)[:y] r=sorted(list(map(int,input().split())),reverse=1) pq=sorted(p+q,reverse=1) ans=sum(pq) n=len(r) count=-1 for i in range(n): if r[i]>pq[count]: ans+=(r[i]-pq[count]) count-=1 print(ans)
X,Y,A,B,C = map(int,input().split()) AList = sorted(list(map(int,input().split())),reverse=True) BList = sorted(list(map(int,input().split())),reverse=True) CList = sorted(list(map(int,input().split())),reverse=True) FullList = sorted(AList[:X] + BList[:Y]) counter = 0 for i in range(min(C,X+Y)): if CList[i] <= FullList[i]: break else: counter += 1 ans = sum(CList[:counter])+sum(FullList[counter:]) print(ans)
1
44,592,025,595,938
null
188
188
from bisect import bisect_left N = int(input()) S = input() d = {"R": [], "G": [], "B": []} for i in range(N): d[S[i]].append(i) def find(x, y, z): total = len(z) res = 0 for i in x: for j in y: if i > j: continue # Find k > j k = bisect_left(z, j) # Find k == 2 * j - i k0 = bisect_left(z, 2 * j - i) flag = int(k0 >= k and k0 < total and z[k0] == 2 * j - i) res += total - k - flag return res ans = 0 ans += find(d["R"], d["G"], d["B"]) ans += find(d["R"], d["B"], d["G"]) ans += find(d["G"], d["R"], d["B"]) ans += find(d["G"], d["B"], d["R"]) ans += find(d["B"], d["R"], d["G"]) ans += find(d["B"], d["G"], d["R"]) print(ans)
import math SIN_T = math.sin(math.pi / 3) COS_T = math.cos(math.pi / 3) def koch(p0, p4): p1 = ((p0[0]*2 + p4[0])/3, (p0[1]*2 + p4[1])/3) p3 = ((p0[0] + p4[0]*2)/3, (p0[1] + p4[1]*2)/3) p2 = (COS_T*(p3[0]-p1[0]) + -SIN_T*(p3[1]-p1[1]) + p1[0], SIN_T*(p3[0]-p1[0]) + COS_T*(p3[1]-p1[1]) + p1[1]) return [p1, p2, p3, p4] if __name__ == "__main__": n = int(input()) points = [(0, 0), (100, 0)] for _ in [0]*n: _points = [points[0]] for origin, dest in zip(points, points[1:]): _points += koch(origin, dest) points = _points for p in points: print(*p)
0
null
18,180,228,230,740
175
27
S = ['S', 'H', 'C', 'D'] D = map(str, range(1, 14)) n = input() T = [tuple(raw_input().split()) for _ in xrange(n)] for t in [(s, d) for s in S for d in D]: if t not in T: print ' '.join(t)
from sys import stdin cards = {} n = int(input()) for line in stdin: m, num = line.rstrip().split(' ') cards[(m, int(num))] = True for s in ['S','H','C','D']: for i in range(1, 14): if not (s, i) in cards: print("{} {}".format(s, i))
1
1,051,321,469,882
null
54
54
str1 = str(input()) if str1[2] == str1[3] and str1[4] == str1[5]: print('Yes') else: print('No')
s=str(input()) j="No" if s[2]==s[3] and s[4]==s[5]: j="Yes" print(j)
1
42,175,142,821,130
null
184
184
N,M,K=map(int,input().split()) par=[0]*(N+1) num=[0]*(N+1) group = [1]*(N+1) for i in range(1,N+1): par[i]=i def root(x): if par[x]==x: return x return root(par[x]) def union(x,y): rx = root(x) ry = root(y) if rx==ry: return par[max(rx,ry)] = min(rx,ry) group[min(rx,ry)] += group[max(rx,ry)] def same(x,y): return root(x)==root(y) for _ in range(M): a,b=map(int,input().split()) union(a,b) num[a]+=1 num[b]+=1 for _ in range(K): c,d=map(int,input().split()) if same(c,d): num[c]+=1 num[d]+=1 for i in range(1,N+1): print(group[root(i)]-num[i]-1,end=" ")
import sys input = lambda: sys.stdin.readline().rstrip() A,B,N = map(int, input().split()) def f(x): return int(A*x/B) - A*int(x/B) if N >= B-1: print(f(B-1)) else: print(f(N))
0
null
45,089,767,791,640
209
161
N,K=map(int,input().split()) h=input() def ans142(N:int, K:int, h:list): N=int(N) K=int(K) count=0 if N==1: h=int(h) if h>=K: return(1) elif h<K: return(0) else: h=h.split() for i in range(0,N): if int(h[i])>=K: count+=1 return(count) print(ans142(N,K,h))
import sys S = input() T = input() if not ( 1 <= len(S) <= 2*10**5 ): sys.exit() if not ( len(S) == len(T) ): sys.exit() if not ( S.islower() and T.islower() ): sys.exit() count = 0 for I in range(len(S)): if S[I] != T[I]: count += 1 print(count)
0
null
94,297,589,251,480
298
116
n = int(raw_input()) a = map(int, raw_input().split()) for i in range(n): print a[n-i-1],
import math import sys readline = sys.stdin.readline def main(): n = int(readline().rstrip()) A = list(map(int, readline().rstrip().split())) cnt = 0 for a in range(n): if ((a + 1) * A[a]) % 2 == 1: cnt += 1 print(cnt) if __name__ == '__main__': main()
0
null
4,365,772,111,480
53
105
s = input() ans = 0 for i in range(0, 3): if s[i] == 'R': ans += 1 if ans == 2 and s[1] == 'S': ans -= 1 print(ans)
days = input() consecutive_days = 0 max_days = 0 if 'R' in days: max_days = 1 consecutive_days = 1 for weather in range(len(days) - 1): if days[weather] == days[weather + 1] and days[weather] == 'R': consecutive_days += 1 if consecutive_days > max_days: max_days = consecutive_days print(max_days)
1
4,934,435,997,650
null
90
90
import math import numpy as np pi = math.pi a, b, x = map(int, input().split()) if x >= a**2*b/2: print(180/pi*np.arctan(2*(a**2*b-x)/a**3)) else: print(180/pi*np.arctan(a*b**2/(2*x)))
s = input() s = s[::-1] n = len(s) # stmp = s[::-1] # for i in range(len(s)): # for j in range(i,len(s)): # sint = int(stmp[i:j+1]) # if sint % 2019 == 0: # print(n-j,n-i) # print(sint) # print() rem2019_cnts = [0]*2019 rem2019_cnts[0] = 1 curr_rem = int(s[0]) rem2019_cnts[curr_rem] = 1 curr_10_rem = 1 ans = 0 for i,si in enumerate(s[1:]): sint = int(si) next_10_rem = (curr_10_rem*10)%2019 next_rem = (next_10_rem*sint + curr_rem)%2019 ans += rem2019_cnts[next_rem] rem2019_cnts[next_rem] += 1 curr_10_rem = next_10_rem curr_rem = next_rem # print(i+2, curr_rem) print(ans)
0
null
96,747,863,253,468
289
166
s = input() n = len(s) end = s[n-1] if end=='s': print(s+'es') else: print(s+'s')
word = input() if word[-1] == 's': word += 'es' else: word += 's' print(word)
1
2,362,303,627,272
null
71
71
n=int(input()) d={"AC":0,"WA":0,"TLE":0,"RE":0} for _ in range(n): d[input()]+=1 for d1, d2 in d.items(): print(d1,'x',d2)
from collections import Counter N = int(input()) A = list(map(int, input().split())) Q = int(input()) BC = [list(map(int, input().split())) for _ in range(Q)] counter = Counter(A) counter_sum = sum(k*v for k, v in counter.items()) for b, c in BC: counter[c] += counter[b] counter_sum -= b * counter[b] counter_sum += c * counter[b] counter[b] = 0 print(counter_sum)
0
null
10,541,615,951,678
109
122
import bisect import math import sys jd = [] for i in range(1,50) : jd.append((1+i)*i//2) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr n = int(input()) if n == 1 : print(0) sys.exit() p = factorization(n) ans = 0 for i in p : c = i[1] ans += bisect.bisect_right(jd, c) print(ans)
H,W=map(int,input().split()) s=[] dp=[[10**9]*W for _ in range(H)] dp[0][0]=0 for _ in range(H): s.append(list(input())) for i in range(H): for j in range(W): if j!=W-1: if s[i][j]=="." and s[i][j+1]=="#": dp[i][j+1]=min(dp[i][j]+1,dp[i][j+1]) else: dp[i][j+1]=min(dp[i][j],dp[i][j+1]) if i!=H-1: if s[i][j]=="." and s[i+1][j]=="#": dp[i+1][j]=min(dp[i][j]+1,dp[i+1][j]) else: dp[i+1][j]=min(dp[i][j],dp[i+1][j]) ans=dp[H-1][W-1] if s[0][0]=="#": ans+=1 print(ans)
0
null
33,273,481,191,600
136
194
MOD = 1000000007 def mod_pow(x , y): if y == 0: return 1 if y == 1: return x r = mod_pow(x , y // 2) r2 = (r * r) % MOD if y % 2 == 0: return r2 % MOD else: return (r2 * x) % MOD N , K = map(int , input().split()) result = 0 memo = {} for g in range(K , 0 , -1): comb = mod_pow(K // g , N) for j in range(2 , K // g + 1): comb = (comb - memo[j * g] + MOD) % MOD memo[g] = comb result = (result + comb * g) % MOD print(result)
def f_strivore(MOD=10**9 + 7): K = int(input()) S = input() length = len(S) class Combination(object): """素数 mod に対する二項係数の計算""" __slots__ = ['mod', 'fact', 'factinv'] def __init__(self, max_val_arg: int = 10**6, mod: int = 10**9 + 7): fac, inv = [1], [] fac_append, inv_append = fac.append, inv.append for i in range(1, max_val_arg + 1): fac_append(fac[-1] * i % mod) inv_append(pow(fac[-1], -1, mod)) for i in range(max_val_arg, 0, -1): inv_append((inv[-1] * i) % mod) self.mod, self.fact, self.factinv = mod, fac, inv[::-1] def combination(self, n, r): return (0 if n < 0 or r < 0 or n < r else self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.mod) comb = Combination(length + K).combination f = [1] * (K + 1) tmp = 1 for n in range(K + 1): f[n] = (comb(length + n - 1, length - 1) * tmp) % MOD tmp = (tmp * 25) % MOD g = [1] * (K + 1) for n in range(1, K + 1): g[n] = (f[n] + 26 * g[n - 1]) % MOD return g[K] print(f_strivore())
0
null
24,672,050,823,280
176
124
l = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51" li = [int(x.strip()) for x in l.split(',')] print(li[int(input())-1])
import sys lst=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] pos = input() print(lst[int(pos)-1])
1
49,976,021,937,338
null
195
195
while 1: n,m=map(int,input().split()) if n==0 and m==0: break if n<m: print(n,m) else: print(m,n)
i=0 xArray=[] yArray=[] while True: x,y=(int(num) for num in input().split()) if x==0 and y==0: break else: xArray.append(x) yArray.append(y) i+=1 for count in range(i): if xArray[count] < yArray[count]: print(xArray[count],yArray[count]) else: print(yArray[count],xArray[count])
1
534,556,122,620
null
43
43
X = list(map(int,input().split())) for i in [0,1]: if X.count(X[i]) == 2: print('Yes') exit() print('No')
n = int(input()) s = ['a']*(n) #print(''.join(s)) def dfs(x,alp): if x == n: print(''.join(s)) return for i in range(alp+1): #print(x,alp,i) s[x] = chr(i+ord("a")) dfs(x+1,max(i+1,alp)) #print(alp) dfs(0,0)
0
null
60,360,473,941,512
216
198
import sys N = input() array_hon = [2,4,5,7,9] array_pon = [0,1,6,8] array_bon = [3] if not ( int(N) <= 999 ): sys.exit() if int(N[-1]) in array_hon: print('hon') if int(N[-1]) in array_pon: print('pon') if int(N[-1]) in array_bon: print('bon')
from math import * H = int(input()) print(2**(int(log2(H))+1)-1)
0
null
49,581,709,949,980
142
228