code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
print(str((lambda x:x**3)(int(input()))))
print((lambda x : x**3)(int(input())))
1
276,218,594,950
null
35
35
N, K = map(int, input().split()) A = list(map(int, input().split())) A = [0] + A #print(A) machi = 1 road = [0,1] Keiyu = [0]*(N+1) for n in range(1, N+1): if Keiyu[machi] == 0: Keiyu[machi] = n road.append(A[machi]) machi = A[machi] else: S = Keiyu[machi] - 1 E = n - 1 break #print(road) #print(Keiyu) #print(S) #print(E) if K <= S: print(road[K+1]) else: K = K - S K = S + K % (E-S) print(road[K+1])
n,a,b = map(int,input().split()) A=n//(a+b) B=n%(a+b) ans = a * A if B>=a: ans += a else: ans += B print(ans)
0
null
39,012,249,293,490
150
202
h,n=map(int, input().split()) a_list=[int(i) for i in input().split()] if sum(a_list)>=h: print("Yes") else: print("No")
H,N=map(int,input().split()) A=sorted(list(map(int,input().split()))) for i in range(1,N+1): H-=A[-i] if H<=0: print('Yes') exit() print('No')
1
77,720,110,729,092
null
226
226
N = int(input()) As = list(map(int,input().split())) if(N == 0): if(As[0] == 1): print(1) else: print(-1) else: flag = True if(As[0] != 0): flag = False if(flag): D = [[0]*3 for i in range(N+1)] D[0] = [1,1,0] # mind maxD Ed for i in range(1,N+1): if(As[i] > 2*D[i-1][1]): flag = False break else: D[i][0] = max(0,D[i-1][0] - As[i]) D[i][1] = min(2*D[i-1][1] - As[i],1 << i) D[i][2] = As[i] if(flag): D[N][1] = 0 maxcnt = 0 for i in range(N,-1,-1): depthmax = D[i][1] + D[i][2] maxcnt += depthmax if(i > 0): D[i-1][1] = min(D[i-1][1],depthmax) print(maxcnt) else: print(-1)
n=int(input()) s=input() ans=0 for i in range(10): if str(i) in s[:-2]: s1=s.index(str(i)) for j in range(10): if str(j) in s[s1+1:-1]: s2=s[s1+1:].index(str(j))+s1+1 for k in range(10): if str(k) in s[s2+1:]: ans+=1 print(ans)
0
null
73,771,922,738,122
141
267
n = int(input()) print(((10 ** n) % (10 ** 9 + 7) - (9 ** n) % (10 ** 9 + 7) - (9 ** n) % (10 ** 9 + 7) + (8 ** n) % (10 ** 9 + 7)) % (10 ** 9 + 7))
N,M=map(int,input().split()) ans=0 if N>1: ans += N*(N-1)//2 else: pass if M>1: ans += M*(M-1)//2 else: pass print(ans)
0
null
24,253,907,604,212
78
189
MAXN = 45 fibs = [-1] * MAXN def fib(n): """Returns n-th fibonacci number >>> fib(3) 3 >>> fib(10) 89 >>> fib(20) 10946 """ if n == 0: return 1 elif n == 1: return 1 elif fibs[n] == -1: fibs[n] = fib(n-1) + fib(n-2) return fibs[n] def run(): n = int(input()) print(fib(n)) if __name__ == '__main__': run()
N = int(input()) def memorize(f) : cache = {} def helper(*args) : if args not in cache : cache[args] = f(*args) return cache[args] return helper @memorize def fibonacci(n): if n == 0 or n == 1: return 1 res = fibonacci(n - 2) + fibonacci(n - 1) return res print(fibonacci(N))
1
1,942,415,780
null
7
7
x, y = map(int, input().split()) if x > y: x, y = y, x while x: x, y = y % x, x print(y)
def gcd(x,y): a=max(x,y) b=min(x,y) if a%b==0: return b else: return gcd(a%b,b) A,B=map(int,input().split()) print(gcd(A,B))
1
7,094,705,650
null
11
11
s=input() s_list=list(s) x=len(s_list) if s_list[x-1]=="s": s_list.append("es") else: s_list.append("s") print("".join(s_list))
s=input() a=len(s) if s[a-1]=='s': print(s+'es') else : print(s+'s')
1
2,384,307,573,502
null
71
71
n,k = map(int,input().split()) a = list(map(int,input().split())) si = [0 for i in range(n+1)] p = [1 for i in range(n)] import copy for q in range(min(k,50)): v = 0 s = copy.deepcopy(si) for i in range(n): if a[i] != 0: s[max(i-a[i],0)] += 1 s[min(i+a[i]+1,n)] -= 1 a[i] = 0 else: a[i] = 1 for i in range(n): v += s[i] a[i] += v for i in range(n): print(a[i], end = ' ')
import numpy as np from numba import njit import math n,k = map(int,input().split()) a = np.array(input().split(),np.int64) @njit def solve(n,k,a): for i in range(k): new = np.zeros_like(a) for j in range(n): distance = j - a[j] if distance < 0: distance = 0 last = j + a[j] if last > n-1: last = n-1 new[distance]+=1 if last+1 < n: new[last+1]-=1 a = np.cumsum(new) if np.all(a==n): break return a a = solve(n,k,a) print(" ".join(a.astype(str)))
1
15,536,693,776,610
null
132
132
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) for i in range(1,10): if n%i==0 and n//i<10: ans = "Yes" break else: ans = "No" print(ans)
N, K = map(int, input().split()) cad = N // K n = N - K * cad m = K * (cad + 1) - N print(min(n, m))
0
null
100,006,012,888,668
287
180
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()
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) a = list(map(int, input().split())) c = 0 ans = -1 for num in a: if num==c+1: c = num else: pass # print(ans) if c>0: ans = max(ans, c) if ans>=0: print(n-ans) else: print(-1)
0
null
59,358,031,046,950
84
257
while True: n, x = [int(a) for a in input().split()] if n == x == 0: break cnt = 0 for i in range(1, n): for j in range(i + 1, n): flag = False for k in range(j + 1, n + 1): if flag: break if (i + j + k) == x: cnt += 1 flag = True print(cnt)
from itertools import combinations def main(): while True: n, x = map(int, input().split()) if (n, x) == (0, 0): break ans = 0 for nums in combinations(range(1, n + 1), 3): if x == sum(nums): ans += 1 print(ans) if __name__ == "__main__": main()
1
1,290,230,773,172
null
58
58
def main(): n = int(input()) A = [int(x) for x in input().split()] if 0 in A: print(0) return mul = 1 for a in A: mul *= a if mul > 1e18: print(-1) return print(mul) main()
time = int(input()) s = time % 60 h = time // 3600 m = (time - h * 3600) // 60 print(str(h) + ":" + str(m) + ":" + str(s))
0
null
8,232,175,901,768
134
37
n = int(input()) a = list(map(int, input().split())) mod = 10**9 + 7 ans = 1 cnt = [0] * 3 for i in range(n): t = 0 first = True for j in range(3): if cnt[j] == a[i]: t += 1 if first: first = False cnt[j] += 1 ans = (ans * t) % mod print(ans)
N, M = list(map(int, input().split())) ans = (N * (N-1)) // 2 + (M * (M-1)) // 2 print(ans)
0
null
88,025,475,915,288
268
189
from collections import deque n=int(input()) l=[list(map(int,input().split())) for i in range(n-1)] tree=[[]for _ in range(n)] for a,b in l: a-=1 b-=1 tree[a].append(b) tree[b].append(b) ans_num=0 for i in tree: ans_num=max(ans_num,len(i)) dq=deque() dq.append((0,0)) seen=set() seen.add(0) ans_dict={} while dq: x,color=dq.popleft() i=0 for nx in tree[x]: if nx in seen: continue i+=1 if i==color: i+=1 seen.add(nx) dq.append((nx,i)), ans_dict[x+1,nx+1]=i ans_dict[nx+1,x+1]=i print(ans_num) for i in l: print(ans_dict[tuple(i)])
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) INF = float("inf") import bisect N = int(input()) ad = [[] for i in range(N+1)] edges = [] for i in range(N-1): a, b = list(map(int, input().split())) edges.append((a,b)) ad[a].append(b) ad[b].append(a) ans_max = 0 for i in range(1,N+1): ans_max = max(ans_max, len(ad[i])) print(ans_max) visited = [0 for i in range(N+1)] seen = [0 for i in range(N+1)] edge_color = defaultdict(int) node_color = [0 for i in range(N+1)] def bfs(u): stack = deque([u]) seen[u] = 1 node_color[u] = 0 while len(stack) > 0: v = stack.popleft() c = 1 for w in ad[v]: if seen[w] == 0: stack.append(w) if c != node_color[v]: edge_color[(v, w)] = c node_color[w] = c else: c += 1 edge_color[(v, w)] = c node_color[w] = c c += 1 seen[w] = 1 if stack == []: break bfs(1) for edge in edges: if edge_color[edge] != 0: print(edge_color[edge]) else: print(edge_color[edge.reverse()])
1
135,570,303,204,884
null
272
272
N = int(input()) # x の y 乗を d で割った余りを求める def powmod(x, y, d): ret = 1 for _ in range(1, y+1): ret = ret * x % d return ret ans = powmod(10, N, 10**9+7) - powmod(9, N, 10**9+7)*2 + powmod(8, N, 10**9+7) print(ans % (10**9+7))
if __name__ == "__main__": t0 = int(raw_input()) h = t0 / 60 / 60 t1 = t0 - ( h * 60 * 60 ) m = t1 / 60 s = t1 - ( m * 60 ) print "{0}:{1}:{2}".format(h,m,s)
0
null
1,734,516,591,200
78
37
import itertools n = int(input()) l = list(map(int, input().split())) count = 0 c_list = list(itertools.combinations(l, 3)) for c in c_list: if (c[0]+c[1])>c[2] and (c[1]+c[2])>c[0] and (c[2]+c[0])>c[1]: if len(set(c)) == 3: count += 1 print(count)
n, m = list(map(int, input().split())) num = [0 for i in range(n)] flag = False for i in range(m): s, c = list(map(int, input().split())) if (s == 1) and (c == 0) and (n > 1): flag = True elif num[s-1] == 0: num[s-1] = c else: if num[s-1] != c: flag = True if flag: print(-1) else: if (n > 1) and (num[0] == 0): num[0] = 1 print("".join(list(map(str, num))))
0
null
32,947,597,212,480
91
208
X=int(input()) div=X//100 mod=X%100 print(1 if 5*div>=mod else 0)
x=int(input()) syo=x//100 amari=int(str(x)[-2:]) if amari/5<=syo: print(1) exit() print(0)
1
126,999,755,275,740
null
266
266
n = int(input()) for i in range(9, 0, -1): if n % i == 0 and n // i <= 9: print('Yes') exit() print('No')
n= int(input()) list=input() strlist=list.split(' ') output='' for i in range(n): output=output+strlist[0][i]+strlist[1][i] print(output)
0
null
136,308,905,902,610
287
255
n,s = map(int,input().split()) A = list(map(int,input().split())) mod = 998244353 dp = [[0 for i in range(s+1)] for j in range(n+1)] dp[0][0] = 1 for i in range(n): for j in range(s+1): if j - A[i] >= 0: dp[i+1][j]=(dp[i][j]*2+dp[i][j-A[i]])%mod else: dp[i+1][j]=(dp[i][j]*2)%mod print(dp[n][s])
N, S = map(int, input().split()) MOD = 998244353 A = list(map(int, input().split())) dp = [0]*(S+1) dp[0] = 1 for a in A: for s in reversed(range(S+1)): if s+a<=S: dp[s+a] += dp[s] dp[s] *= 2 dp[s] %= MOD print(dp[S]%MOD)
1
17,705,333,483,442
null
138
138
r = int(input()) ans = int(r ** 2) print(ans)
import math a,b,c=map(int,input().split()) if b>c: print(math.floor((a*c)/b)-a*(math.floor(c/b))) else: print(math.floor((a*(b-1))/b)-a*(math.floor((b-1)/b)))
0
null
87,137,344,651,208
278
161
def main(): n = input() x = "abcdefghijklmnopqrstuvwxyz" print(x[x.index(n)+1]) if __name__ == '__main__': main()
def resolve(): N = int(input()) print(1000 * ((1000 + (N-1)) // 1000) - N) resolve()
0
null
50,370,529,863,328
239
108
N = int(input()) d = list(map(int,input().split())) amount = 0 b = [0] * N for i in range(N): b[i] = amount amount += d[N-1-i] ans = 0 for i in range(N): ans += d[i]*b[N-1-i] print(ans)
while True: h, w = [int(i) for i in input().split(' ')] if h ==0 and w ==0: break for i in range(h): row = '' for j in range(w): if i == 0 or i == h - 1: row = row + '#' else: if j == 0 or j == w -1: row = row + '#' else: row = row + '.' print(row) print('')
0
null
84,422,294,309,408
292
50
from __future__ import division, print_function from sys import stdin word = stdin.readline().rstrip().lower() cnt = 0 for line in stdin: if line.startswith('END_OF_TEXT'): break cnt += line.lower().split().count(word) print(cnt)
W = input().rstrip() lst = [] while True: line = input().rstrip() if line == "END_OF_TEXT": break lst += line.lower().split() print(lst.count(W))
1
1,813,527,709,540
null
65
65
from decimal import Decimal N = int(input()) M = int(N/Decimal(1.08)) + 1 if N == int(M*Decimal(1.08)) : print( int(M)) else : print(':(')
a,b = map(int,input().split()) print(a-b*2 if b*2 <= a else '0')
0
null
145,799,916,212,214
265
291
x, y, z = map(int,input().split()) a = x + y + z if (a >= 22): print("bust") else: print("win")
from sys import stdin n = int(input()) A = list(map(int, stdin.readline().split())) q = int(input()) m = list(map(int, stdin.readline().split())) def solve(i,m): ''' i番目以降の要素を使用してmを作れる場合、trueを返す ''' if m == 0: return True if sum(A[i:]) < m: return False if i >= n: return False res = solve(i+1,m) or solve(i+1,m-A[i]) return res for a in m: if solve(0,a): print("yes") else: print("no")
0
null
59,453,025,346,068
260
25
def backoutput(y): if y.isupper(): return y.lower() elif y.islower(): return y.upper() else: return y first_input = list(map(backoutput, input())) print(*first_input, sep='')
N = int(input()) A = sorted(list(map(int,input().split()))) ans = "YES" for i in range(1,N,2): boollist = [ A[i-1] == A[i] ] if i < N-1 : boollist.append(A[i] == A[i+1]) if any(boollist): ans = "NO" break print(ans)
0
null
37,514,937,611,776
61
222
import sys input = sys.stdin.readline N = int(input()) imo = [] xlmin = 0 xlmax = 0 for _ in range(N): x,l = map(int,input().split()) imo.append([x-l,x+l-1]) imo = sorted(imo,key = lambda x: x[1]) cnt = 1 ls = imo[0][1] for i in range(1,N): if imo[i][0]<=ls: continue else: cnt += 1 ls = imo[i][1] print(cnt)
n=int(input()) ans =0 for i in range(2,int(n**0.5)+5): cnt = 0 while n%i==0: n//=i cnt += 1 s=1 while cnt-s>=0: cnt -= s s +=1 ans += 1 if n!=1:ans+=1 print(ans)
0
null
53,728,937,999,900
237
136
# coding: utf-8 # 二分探索(応用) def loading(pack_list, k, q): truck = 0 idx = 0 for pack in pack_list: if pack > q: return False if truck + pack > q: idx += 1 truck = 0 truck += pack if truck > 0: idx += 1 return False if idx > k else True if __name__ == "__main__": n, k = [int(i) for i in input().split()] pack = [] for _ in range(n): pack.append(int(input())) min = 0 max = int(1E20) # min = sum(pack) // n # max = sum(pack) q = (max + min) // 2 res = loading(pack, k, q) while min + 1 != max: min, max = [min, q] if res else [q, max] q = (max + min) // 2 res = loading(pack, k, q) print(max)
# -*- coding: utf-8 -*- """ Created on Mon Apr 30 15:18:29 2018 ALDS1-4c @author: maezawa """ def can_load(w, k, p): n = len(w) m = 0 tk = 0 i = 0 while tk < k: if m + w[i] <= p: m += w[i] i += 1 if i >= n: return n+1 else: m = 0 tk += 1 return i n, k = list(map(int, input().split())) w = [] tr = [0 for _ in range(k)] for i in range(n): w.append(int(input())) maxw = max(w) # ============================================================================= # for p in range(maxw, maxw*n): # if can_load(w, k, p) == n: # print(p) # break # ============================================================================= right = maxw*n left = maxw while left<right: mid = (right+left)//2 cl = can_load(w, k, mid) # if cl == n: # print(mid) # break # elif cl < n: if cl < n: left = mid + 1 else: right = mid print(right)
1
90,173,365,126
null
24
24
N = int(input()) A = map(int, input().split()) curr = 0 ans = 0 for a in A: if curr > a: ans += curr - a else: curr = a print(ans)
def main(): N = int(input()) A = [int(i) for i in input().split()] ma = A[0] ans = 0 for a in A: ma = max(ma, a) ans += ma - a print(ans) if __name__ == '__main__': main()
1
4,599,956,301,600
null
88
88
from math import log2, ceil H = int(input()) print(2**(ceil(log2(H))+1 if log2(H).is_integer() else ceil(log2(H))) - 1)
h = int(input()) for i in range(100): if 2**i > h: print(2**i - 1) exit()
1
79,968,557,898,460
null
228
228
def main(): h,w,k=map(int,input().split()) grid=[input() for _ in [0]*h] ans=[[0]*w for _ in [0]*h] berry=0 for i in range(h): if "#" in grid[i]: cnt=0 berry+=1 for j in range(w): if grid[i][j]=="#": cnt+=1 if cnt>1: berry+=1 ans[i][j]=berry for i in range(1,h): if ans[i][0]==0: for j in range(w): ans[i][j]=ans[i-1][j] for i in range(h-2,-1,-1): if ans[i][0]==0: for j in range(w): ans[i][j]=ans[i+1][j] for i in ans: print(*i) main()
a, b, c = map(int, input().split()) if c - (a+b) < 0: print("No") exit() if 4*a*b < c**2 - 2*c*(a+b) + (a+b)**2: print("Yes") else: print("No")
0
null
98,078,292,731,972
277
197
import sys import math 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()) H,W= LI() if H == 1 or W == 1: print(1) else: ans = (H*W+1)/2 print(int(ans))
print('Yes'if input().count('7')else'No')
0
null
42,784,231,942,332
196
172
a, b, c, d = list(map(int, input().split())) turn = True while True: if turn: c -= b if c <= 0: print("Yes") import sys sys.exit() else: a -= d if a <= 0: print("No") import sys sys.exit() turn ^= True
n = int(input()) lst = [] for i in range(n): x, l = map(int, input().split()) left = x - l right = x + l lst.append([left, right]) lst = sorted(lst, key=lambda x: x[1]) ans = 1 limit = lst[0][1] for i in range(n): if lst[i][0] >= limit: ans += 1 limit = lst[i][1] print(ans)
0
null
59,874,995,504,652
164
237
#!/usr/bin/env python3 import sys import numpy as np import numba from numba import njit, b1, i4, i8, f8 input = sys.stdin.readline def I(): return int(input()) @njit((i8,), cache=True) def main(n): table = np.zeros(n, np.int64) for i in range(1, n): table[::i] += 1 ans = 0 for n in table[1:]: q, r = divmod(n, 2) ans += q * 2 + 1 * r return ans N = I() print(int(main(N)))
from collections import defaultdict def main(): n = int(input()) a = list(map(int, input().split(" "))) d = defaultdict(lambda:0) for i in range(n): d[a[i]] += 1 if max(d.values()) >1: print("NO") else: print("YES") if __name__ == "__main__": main()
0
null
38,489,968,858,448
73
222
L,R,d = [int(i) for i in input().split()] ans = 0 for i in range(L,R+1): if i%d == 0: ans += 1 print(ans)
import sys,math,collections from collections import defaultdict #from itertools import permutations,combinations def file(): sys.stdin = open('input.py', 'r') sys.stdout = open('output.py', 'w') def get_array(): l=list(map(int, input().split())) return l def get_2_ints(): a,b=map(int, input().split()) return a,b def get_3_ints(): a,b,c=map(int, input().split()) return a,b,c def sod(n): n,c=str(n),0 for i in n: c+=int(i) return c def getFloor(A, x): (left, right) = (0, len(A) - 1) floor = -1 while left <= right: mid = (left + right) // 2 if A[mid] == x: return A[mid] elif x < A[mid]: right = mid - 1 else: floor = A[mid] left = mid + 1 return floor #file() def main(): l,r,n=get_3_ints() c=0 for i in range(min(l,r),max(l,r)+1): #print(i) if(i%n==0): c+=1 print(c) if __name__ == '__main__': main()
1
7,465,102,471,232
null
104
104
num = map(int,input().split()) s=sum(num) print(15-s)
x = map(int, input().replace(' ','')) x = list(x) for idx in range(len(x)): if x[idx] == 0: print(idx + 1) break
1
13,461,288,539,028
null
126
126
# coding: utf-8 while True: valueA, operation, valueB = input().split(" ") if operation == "?": break elif operation == "+": result = int(valueA) + int(valueB) elif operation == "-": result = int(valueA) - int(valueB) elif operation == "*": result = int(valueA) * int(valueB) elif operation == "/": result = int(valueA) / int(valueB) print("{0}".format(int(result)))
while True: a,b,c = input().split() if b=='?': break elif b =='+': d = int(a) + int(c) elif b=='-': d = int(a) - int(c) elif b=='*': d = int(a)*int(c) else : d = int(a)/int(c) print(int(d))
1
683,090,424,480
null
47
47
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))
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict, deque import copy sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def calc_water(u, l, h): return ((u + l) * h) // 2 def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") S = iss() stack = [] water = [] sum = 0 for i in range(len(S)): s = S[i] if s == '\\': stack.append(i) elif s == '/' and len(stack) > 0: j = stack.pop() sum += i - j area = i - j while len(water) > 0 and water[-1][0] > j: w = water.pop() area += w[1] water.append([j, area]) ret = [] for i, w in water: ret.append(w) print(sum) print(len(ret), *ret) if __name__ == '__main__': main()
1
58,957,257,088
null
21
21
n,k = map(int,input().split()) mod = 10**9 +7 sum1 = 0 for i in range(k,n+2): sum1 +=(-i*(i-1)//2 + i*(2*n-i+1)//2+1)%mod print(sum1%mod)
N, K = map(int,input().split()) ans = 0 while K <= N+1: ans += ((N+1)*(N+2) - (N-K+1)*(N-K+2) - K*(K+1)) // 2 + 1 K += 1 print(ans % (10 ** 9 + 7))
1
33,050,072,767,798
null
170
170
def main(): X = int(input()) v = 100 ans = 0 while v < X: ans += 1 v = int(v * 101 // 100) print(ans) if __name__ == '__main__': main()
X = int(input().split()[0]) x = 100 count = 0 while x < X: x += x // 100 count += 1 ans = count print(ans)
1
26,906,508,245,578
null
159
159
n,m,q=map(int,input().split()) e=[list(map(int,input().split())) for _ in range(q)] ans=0 for i in range(1<<(m+n)): a=[1] for j in range(m+n): if (i>>j)&1:a[-1]+=1 else:a+=[a[-1]] if a[-1]>m: flag=0 break if len(a)>n: flag=1 break else:flag=1 if flag==0 or len(a)<n:continue cnt=0 for s,t,u,v in e: if a[t-1]-a[s-1]==u:cnt+=v ans=max(ans,cnt) print(ans)
def dfs(lst): global ans if len(lst) > n: return lowest = 1 if lst != []: lowest = lst[-1] for i in range(lowest, m+1): lst.append(i) dfs(lst) lst.pop() if len(lst) == n: cnt = 0 for i in range(q): a, b, c, d = ab[i] if lst[b-1] - lst[a-1] == c: cnt += d ans = max(cnt, ans) n,m,q = map(int, input().split()) ab = [tuple(map(int, input().split())) for _ in range(q)] ans = 0 dfs([]) print(ans)
1
27,693,206,542,012
null
160
160
import string import sys input_str = "" for i in sys.stdin: input_str += i for i in range(26): char = string.ascii_lowercase[i] CHAR = string.ascii_uppercase[i] cnt = input_str.count(char) + input_str.count(CHAR) print("{0} : {1}".format(char, cnt))
N = int(input()) S, T = map(str,input().split()) for s, t in zip(S, T): print(s+t, end='')
0
null
56,991,869,918,590
63
255
while True: H, W = map(int, input().split()) if H == W == 0: break print('#' * W + '\n' + ('#' + '.' * (W - 2) + '#' + '\n') * (H - 2) + '#' * W + '\n')
#!/usr/bin/env pypy3 def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): N,M=MI() st=pow(10,N-1) en=pow(10,N) if N==1: st=0 s=[0]*M c=[0]*M for i in range(M): s[i],c[i]=MI() s[i]-=1 ans=-1 for i in range(st,en): flag=1 i2=str(i) for j in range(M): aaa=int(i2[s[j]]) if aaa!=c[j]: flag=0 break if flag: ans=i break print(ans) main()
0
null
30,880,536,159,710
50
208
import math def is_prime(n): if n in [2, 3, 5, 7]: return True elif 0 in [n%2, n%3, n%5, n%7]: return False else: check_max = math.ceil(math.sqrt(n)) for i in range(2, check_max + 1): if n % i == 0: return False else: return True def main(): primes = set([]) length = int(input()) for _ in range(0, length): n = int(input()) if is_prime(n): primes.add(n) print(len(primes)) return 0 if __name__ == '__main__': main()
import sys import math count = 0 judge = 0 for line in sys.stdin.readlines(): num = int(line.strip()) if judge == 0: judge = 1 else: flag = 0 for i in range(2, int(math.sqrt(num)) + 1): if num % i == 0: flag = 1 break if flag == 0: count += 1 print count
1
9,788,830,660
null
12
12
from itertools import product n = int(input()) l1 = [] for _ in range(n): l2 = [] for _ in range(int(input())): l2.append(list(map(int, input().split()))) l1.append(l2) ans = 0 for k in product([1, 0], repeat=n): check = True for i, j in enumerate(l1): if k[i] == 0: continue for x in j: if k[x[0] - 1] != x[1]: check = False if check: ans = max(ans, sum(k)) print(ans)
n, m, q = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(q)] def combinations_with_replacement(iterable, r): pool = tuple(iterable) n = len(pool) if not n and r: return indices = [0] * r yield tuple(pool[i] for i in indices) while True: for i in reversed(range(r)): if indices[i] != n - 1: break else: return indices[i:] = [indices[i] + 1] * (r - i) yield tuple(pool[i] for i in indices) ans, tempAns = 0, 0 for tempA in combinations_with_replacement(range(1, m + 1), n): tempAns = 0 for a in A: if tempA[a[1] - 1] - tempA[a[0] - 1] == a[2]: tempAns += a[3] ans = max(ans, tempAns) print(ans)
0
null
74,479,668,598,240
262
160
m = 100000 rate = 0.05 n = int(input()) for i in range(n): m += m*rate x = m%1000 m -= x while(x % 1000 != 0): x += 1 m += x print(str(int(m)))
# 降順にしたものを考え、最大のやつは1回、あとのやつは2回ずつ使える n = int(input()) a = sorted(list(map(int, input().split())), reverse=True) ans = a[0] count = n - 2 idx = 1 while count > 0: count_of_count = 2 while count_of_count > 0 and count > 0: count -= 1 count_of_count -= 1 ans += a[idx] idx += 1 print(ans)
0
null
4,571,470,142,802
6
111
# -*- codinf: utf-8 -*- from collections import deque N, M = map(int, input().split()) route = [[] for _ in range(N + 1)] for _ in range(M): a, b = map(int, input().split()) route[a].append(b) route[b].append(a) q = deque([1]) # 頂点を設定して初期化 pre = [None] * (N+1) # 頂点までの最短に進む時の次の頂点のリスト pre[1] = 0 # 頂点は0 depth = [None] * (N+1) # 頂点からの深さ(最短距離)のリスト depth[1] = 0 # 頂点の距離は0 while len(q) > 0: x = q.popleft() for r in route[x]: if pre[r] is None: depth[r] = depth[x] + 1 pre[r] = x q.append(r) print("Yes") for i in range(2, len(pre)): print(pre[i])
N,M = map(int,input().split()) t = [[i+1] for i in range(N)] for i in range(M): A,B = map(int,input().split()) t[A-1].append(B) t[B-1].append(A) from collections import deque d = deque() ans = [-1]*(N) d.append(t[0]) while len(d) > 0: z = d.popleft() x = z[0] for i in range(1,len(z)): if ans[z[i]-1] == -1: ans[z[i]-1] = x d.append(t[z[i]-1]) print("Yes") for i in range(1,len(ans)): print(ans[i])
1
20,586,894,977,610
null
145
145
S = input() print('{}s'.format(S)) if S[-1] != 's' else print('{}es'.format(S))
S = input() if S[-1] == "s": S = S + "es" print(S) else: S = S + "s" print(S)
1
2,386,144,434,508
null
71
71
a,b=(int(x) for x in input().split()) if(a-2*b<0): print(0) else: print(a-2*b)
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): A, B = map(int, input().split()) ans = max(0, A - 2 * B) print(ans) if __name__ == '__main__': solve()
1
166,437,701,541,342
null
291
291
N,K=map(int,input().split()) P=list(map(int,input().split())) P.sort() b=0 for i in range(K): b+=P[i] print(b)
n,k = map(int,input().split()) count = 0 p = map(int,input().split()) P = sorted(p) for k in range(k): count = count + int(P[k]) print(count)
1
11,544,965,738,904
null
120
120
N = int(input()) ST = [] for i in range(N): x, l = list(map(int, input().split())) ST.append([x-l, x+l]) ST.sort(key = lambda x :x[1]) startT = ST[0][1] ans = 1 if N != 1: for i in range(1,N): if startT <= ST[i][0]: startT = ST[i][1] ans += 1 print(ans)
N = int(input()) alist = list(map(int, input().split())) k = 1 if 0 in alist: print(0) else: for i in range(0,N): k = k*alist[i] if k > 1000000000000000000: k= -1 break print(k)
0
null
53,323,362,040,230
237
134
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9+7 def lcm(x,y): return x*y//gcd(x,y) def lgcd(l): return reduce(gcd,l) def llcm(l): return reduce(lcm,l) def powmod(n,i,mod): return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod) def div2(x): return x.bit_length() def div10(x): return len(str(x))-(x==0) def intput(): return int(input()) def mint(): return map(int,input().split()) def lint(): return list(map(int,input().split())) def ilint(): return int(input()), list(map(int,input().split())) def judge(x, l=['Yes', 'No']): print(l[0] if x else l[1]) def lprint(l, sep='\n'): for x in l: print(x, end=sep) def ston(c, c0='a'): return ord(c)-ord(c0) def ntos(x, c0='a'): return chr(x+ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self,x,d=1): self.setdefault(x,0) self[x] += d def list(self): l = [] for k in self: l.extend([k]*self[k]) return l class comb(): def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self,k): l,n,mod = self.l, self.n, self.mod k = n-k if k>n//2 else k while len(l)<=k: i = len(l) l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod) return l[k] def pf(x): C = counter() p = 2 while x>1: k = 0 while x%p==0: x //= p k += 1 if k>0: C.add(p,k) p = p+2-(p==2) if p*p<x else x return C H,W,K=mint() s=[input() for _ in range(H)] res=[[0]*W for _ in range(H)] ans=1 index=[] for k in range(H): index.append(k) if s[k].count('#')==0: continue tmp=True for j in range(W): if s[k][j]=='#': K-=1 if tmp: tmp=False else: ans+=1 for i in index: res[i][j]=ans ans+=1 index=[] if K==0: for i in range(k+1,H): for j in range(W): res[i][j]=res[k][j] break for r in res: lprint(r,' ') print('')
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 h, w, k = list(map(int, readline().split())) s = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)] cnt = 0 ls = [] lsd = -1 for i in range(h): if s[i].count("#") != 0: lsd = i is_f = True cnt += 1 for j in range(w): if s[i][j] == "#": if is_f: is_f = False else: cnt += 1 s[i][j] = cnt while ls: ti = ls.pop() for j in range(w): s[ti][j] = s[i][j] else: ls.append(i) if i == h - 1: while ls: ti = ls.pop() for j in range(w): s[ti][j] = s[lsd][j] for i in range(len(s)): print(*s[i]) if __name__ == '__main__': solve()
1
143,153,619,347,040
null
277
277
times = int(input()) for i in range(0, times): edge = [] for e in input().split(" "): edge.append(int(e)) edge.sort() if pow(int(edge[0]), 2) + pow(int(edge[1]), 2) == pow(int(edge[2]), 2): print("YES") else: print("NO")
import sys count = int(raw_input()) #print count while 0 < count: count -=1 #print count a = map(int,raw_input().split()) #print a[0],a[1],a[2] if a[1]< a[2]: tmp = a[1] a[1] = a[2] a[2] = tmp if a[0] < a[1]: tmp = a[0] a[0] = a[1] a[1] = tmp n = a[1]*a[1] + a[2]*a[2] if a[0]*a[0] == n: print "YES" else: print "NO"
1
368,187,888
null
4
4
N,K = map(int,input().split()) S = set() for i in range(K) : D=int(input()) L=list(map(int, input().split())) for A in L : S.add(A) print (N-len(S))
n,k = map(int,input().split()) treat = [1]*n for i in range(k): d = int(input()) c = list(map(int,input().split())) for j in c: treat[j-1] = 0 print(sum(treat))
1
24,669,198,056,540
null
154
154
import sys argvs = sys.argv for x in sys.stdin: print str(int(x)**3)
print(str(int(input())**3))
1
275,735,962,908
null
35
35
import sys input = sys.stdin.readline H,W,K =list(map(int,input().split())) s = [input().rstrip() for _ in range(H)] cut = [[0]*W for _ in range(H)] cnt =0 for ih in range(H): if s[ih].count('#')==0: continue else: for iw in range(W): if s[ih][iw] == '#': cnt +=1 cut[ih][iw]= cnt for ih in range(H): for iw in range(W-1): if cut[ih][iw+1] ==0: cut[ih][iw+1]= cut[ih][iw] for iw in range(W-1,0,-1): if cut[ih][iw-1] ==0: cut[ih][iw-1]= cut[ih][iw] for ih in range(H-1): if cut[ih+1][0]==0: for iw in range(W): cut[ih+1][iw] = cut[ih][iw] for ih in range(H-1,0,-1): if cut[ih-1][0]==0: for iw in range(W): cut[ih-1][iw] = cut[ih][iw] for i in range(H): print(*cut[i])
s = input() k = int(input()) ans = 0 soui = 0 moji = s[0] for i in range(1,len(s)): if s[i] == s[i-1] and soui == 0: ans += 1 soui = 1 elif soui == 1: soui = 0 flag = 0 a = 0 b = 0 while s[0] == s[a] and a != len(s)-1: a += 1 while s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1: b += 1 if s[0] == s[len(s)-1]: flag = 1 for i in range(len(s)): if moji != s[i]: break elif i == len(s)-1: flag = 2 if flag == 1: print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2)))) elif flag == 2: print((k*len(s))//2) else: print(k*ans)
0
null
159,148,818,589,048
277
296
while True: n, goal = [int(x) for x in input().split(" ")] res =[] if n == goal == 0: break for first in range(1, n+1): for second in range(first+1, n+1): rem = goal - (first + second) if rem > second and n >= rem: res.append([first, second, rem]) print(len(res))
while(True): i=0 a=list(map(int,input().split())) if(a[0]==0 and a[1]==0): break for x in range(2,a[0]): sum=a[1]-x for y in range(1,x): if (sum-y<a[0]+1 and sum-y>x): i+=1 print(i)
1
1,300,762,431,552
null
58
58
from decimal import * import math a, b, c = list(map(int, input().split())) print('Yes' if c - a - b> 0 and 4*a*b < (c - a - b)**2 else 'No')
A, B, C = map(int, input().split()) x = A * B * 4 y = (C - A - B) ** 2 if x < y and C - A - B > 0: print("Yes") else: print("No")
1
51,459,754,094,132
null
197
197
h, a = map(int,input().split()) print(h//a + min(h%a,1))
H, A = map(int, input().split()) print(H//A + (H%A != 0))
1
76,828,641,309,992
null
225
225
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
N = int(input()) A = list(map(int, input().split())) b = [0] * (N+1) b[0] = 1 flag = True for i in range(N): if A[i] > b[i]: flag = False b[i+1] = (b[i] - A[i]) * 2 if A[N] > b[N]: flag = False ans = 0 l = 0 for i in range(N, -1, -1): l += A[i] ans += min(l, b[i]) if flag: print(ans) else: print(-1)
1
18,939,215,866,520
null
141
141
n,k=map(int,input().split()) count=1 subk=k while subk<=n: subk*=k count+=1 print(count)
n, k = map(int, input().split()) listn = list() for i in range(k): d = int(input()) a = list(map(int, input().split())) listn.extend(a) print(n - len(set(listn)))
0
null
44,667,413,373,542
212
154
#!usr/bin/env python3 def string_three_numbers_spliter(): a, b, c = [int(i) for i in input().split()] return a, b, c def main(): a, b, c = string_three_numbers_spliter() if a < b and a < c: print('Yes') else: print('No') if __name__ == '__main__': main()
# coding=utf-8 inputs = raw_input().rstrip().split() a, b, c = [int(x) for x in inputs] if a < b < c: print 'Yes' else: print 'No'
1
385,801,601,508
null
39
39
import sys numbers = [] for line in sys.stdin: numbers.append(int(line)) k = [] k.append(1) k.append(1) def getFib(i, n): if i == n : print(k[-1]) return k.append(int(k[i - 1]) + int(k[i - 2])) getFib(i + 1, n) getFib(2, int(numbers[0])+1)
n=int(input()) x=0 y=1 if n==0 or n==1: print(1) else: for i in range(n): x,y=y,x+y i+=1 print(y)
1
1,712,161,188
null
7
7
N,K=map(int,input().split()) R,S,P=map(int,input().split()) T=input() cnt=[0 for _ in range(N)] score={'r':P,'s':R,'p':S} for i in range(N): if i<K: cnt[i]=score[T[i]] else: if T[i-K]!=T[i]: cnt[i]=score[T[i]] else: if cnt[i-K]==0: cnt[i]=score[T[i]] print(sum(cnt))
N, K = map(int, input().split()) R, S, P = map(int, input().split()) T = input() dp = [[0]*3 for _ in range(N+1)] for i in range(1, N+1): if i <= K: dp[i][0] = int(T[i-1]=='s') * R dp[i][1] = int(T[i-1]=='p') * S dp[i][2] = int(T[i-1]=='r') * P else: dp[i][0] = max(dp[i-K][1], dp[i-K][2]) + int(T[i-1]=='s') * R dp[i][1] = max(dp[i-K][0], dp[i-K][2]) + int(T[i-1]=='p') * S dp[i][2] = max(dp[i-K][0], dp[i-K][1]) + int(T[i-1]=='r') * P ans = 0 for d in dp[-K:]: ans += max(d) print(ans)
1
107,259,099,493,348
null
251
251
# 解法1 # def main(): # N, M = map(int, input().split()) # num = [-1] * N # for _ in range(M): # s, c = map(int, input().split()) # s -= 1 # if s == 0 and c == 0: # if N != 1: # print(-1) # return # if num[s] == -1: # num[s] = c # elif num[s] != c: # print(-1) # return # ans = "" # for i in range(len(num)): # c = num[i] # if c == -1: # if i != 0 or N == 1: # ans += "0" # else: # ans += "1" # else: # ans += str(c) # print(ans) # 解法2 def main(): N, M = map(int, input().split()) S = [0] * M C = [0] * M for i in range(M): s, c = map(int, input().split()) S[i] = s-1 C[i] = c if N == 1: start = 0 else: start = 10 ** (N - 1) for n in range(start, 10 ** (N)): n = str(n) ok = True for i in range(M): s = S[i] c = C[i] if n[s] != str(c): ok = False break if ok: print(n) return print(-1) main()
n, m = map(int, input().split()) sc = [tuple(map(int, input().split())) for j in range(m)] for i in range(10**n): if len(str(i)) == n and all(str(i)[s - 1] == str(c) for s, c in sc): print(i) break else: print(-1)
1
60,561,902,483,420
null
208
208
put = ['#','.'] while(True): h,w = [int(i) for i in input().split()] if h==0 and w==0: break for i in range(h): out = '' if i % 2 == 0: count = 0 else : count = 1 for j in range(w): out += put[count%2] count += 1 print(out) print("")
h= [] w= [] while True: a,b= map(int,input().split()) if(not (a==0 or b==0)): h.append(a) w.append(b) elif(a==b==0): break n= 0 for e in h: c= 0 for f in range(e): if(w[n]%2==0): if(c== 0): print('#.'*(w[n]//2)) c= 1 else: print('.#'*(w[n]//2)) c= 0 else: if(c== 0): print('#.'*(w[n]//2)+'#') c= 1 else: print('.#'*(w[n]//2)+'.') c= 0 print() n+= 1
1
883,730,948,386
null
51
51
a = list(map(int, input().split(' '))) a = set(a) l = len(a) if l == 2: print('Yes') else: print('No')
X = list(map(int,input().split())) for i in [0,1]: if X.count(X[i]) == 2: print('Yes') exit() print('No')
1
67,920,994,868,520
null
216
216
cnt = 0 def insert_sort(g): global cnt i = g for _ in range(n): v = nums[i] j = i - g while j >= 0 and nums[j] > v: nums[j + g] = nums[j] j -= g cnt += 1 nums[j + g] = v i += 1 if i >= n: break def shell_sort(): i = 0 for _ in range(m): insert_sort(g[i]) i += 1 n = int(input()) nums = [] for _ in range(n): nums.append(int(input())) g = [] g_val = n for _ in range(n): g_val = g_val // 2 g.append(g_val) if g_val == 1: break m = len(g) shell_sort() print(m) g_cnt = 0 s = '' for _ in range(m): s += str(g[g_cnt]) + ' ' g_cnt += 1 print(s.rstrip()) print(cnt) nums_cnt = 0 for _ in range(n): print(nums[nums_cnt]) nums_cnt += 1
x=input() i=1 while (x!='0'): print("Case {0}: {1}".format(i,x)); i+=1; x=input()
0
null
260,699,014,720
17
42
n = int(input()) Taro = 0 Hanako = 0 for i in range(n): t,h = input().split() if t == h: Hanako += 1 Taro += 1 elif t> h: Taro += 3 else: Hanako += 3 print("{} {}".format(Taro,Hanako))
def cardgame(animal1, animal2, taro, hanako): if animal1==animal2: return [taro+1, hanako+1] anim_list = sorted([animal1, animal2]) if anim_list[0]==animal1: return [taro, hanako+3] else: return [taro+3, hanako] n = int(input()) taro, hanako = 0, 0 for i in range(n): data = input().split() result = cardgame(data[0], data[1], taro, hanako) taro, hanako = result[0], result[1] print(taro, end=" ") print(hanako)
1
1,996,523,606,656
null
67
67
#coding:utf-8 #1_8_D 2015.4.9 import re s = input() p = input() if re.search(p , s * 2): print('Yes') else: print('No')
import math def koch(d,p1x,p1y,p2x,p2y): if d == 0: return 0 sin = math.sin(math.radians(60)) cos = math.cos(math.radians(60)) ax = (2 * p1x + 1 * p2x)/3 ay = (2 * p1y + 1 * p2y)/3 bx = (1 * p1x + 2 * p2x)/3 by = (1 * p1y + 2 * p2y)/3 ux = (bx - ax)* cos - (by - ay)*sin + ax uy = (bx - ax)* sin + (by - ay)*cos + ay koch(d-1,p1x,p1y,ax,ay) print(ax,ay) koch(d-1,ax,ay,ux,uy) print(ux,uy) koch(d-1,ux,uy,bx,by) print(bx,by) koch(d-1,bx,by,p2x,p2y) d = int(input()) print(0,0) koch(d,0,0,100,0) print(100,0)
0
null
944,194,134,316
64
27
N = int(input()) S = input() ans = 0 for x in range(10): for y in range(10): for z in range(10): for i in range(N): if x != int(S[i]): continue for j in range(i+1, N): if y != int(S[j]): continue for k in range(j+1, N): if z != int(S[k]): continue ans += z == int(S[k]) break break break print(ans)
N = int(input()) S = list(input()) ans = 0 for x in range(1000) : X = list(str(x).zfill(3)) i = 0 j = 0 if X[0] in S[:N-2] : i = S.index(X[0]) else : continue if X[1] in S[i+1:N-1] : j = S[i+1:N-1].index(X[1])+i+1 else : continue if X[2] in S[j+1:N] : ans += 1 print(ans)
1
128,856,308,543,466
null
267
267
import sys input = sys.stdin.readline read = sys.stdin.read n, t = map(int, input().split()) m = map(int, read().split()) AB = sorted(zip(m, m)) A, B = zip(*AB) dp = [[0]*t for _ in range(n+1)] for i, a in enumerate(A[:-1]): for j in range(t): if j < a: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = max(dp[i][j-a]+B[i], dp[i][j]) ans = 0 maxB = [B[-1]]*n for i in range(n-2, 0, -1): maxB[i] = max(B[i], maxB[i+1]) for i in range(n-1): ans = max(ans, dp[i+1][-1] + maxB[i+1]) print(ans)
N = int(input()) from functools import reduce import math sum=0 for i in range(1,N+1): for j in range(1,N+1): a = math.gcd(i,j) for k in range(1,N+1): sum+=math.gcd(a,k) print(sum)
0
null
93,610,763,777,152
282
174
x1,y1,x2,y2=map(float,input().split()) print(f'{((x2-x1)**2+(y2-y1)**2)**0.5:.6f}')
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys x1, y1, x2, y2 = map(float, sys.stdin.readline().split()) print(round(((x2-x1)**2 + (y2-y1)**2) ** 0.5, 6))
1
156,155,006,238
null
29
29
a, b, c = [int(i) for i in input().split()] if a < b: if b < c: print('Yes') else: print('No') else: print('No')
a, b, c = map(int, input().split()) if (a < b) and (b < c): print('Yes') else: print('No')
1
388,244,663,340
null
39
39
# -*- coding: utf-8 -*- import sys for s in sys.stdin: print len(str(int(s.rstrip().split()[0])+int(s.rstrip().split()[1])))
while True: try: a, b = map(int, input().split()) except EOFError: break count=1 k=a+b while k>=10: k//=10 count+=1 print(count)
1
129,969,012
null
3
3
n = int(input()) x = [] for i in range(n): a, b = map(int, input().split()) x.append([a, b]) ans = 0 for i in range(len(x) - 1): for j in range(i+1, len(x)): ans += ((x[i][0]-x[j][0])**2 + (x[i][1]-x[j][1])**2)**0.5 print((2*ans)/n)
from collections import deque H, W = map(int, input().split()) S_raw = [list(input()) for _ in range(H)] m = 0 def calc(h,w): S = [list(S_raw[i][j] for j in range(W)) for i in range(H)] S[h][w]=0 queue = deque([(h,w)]) while queue: q = queue.popleft() for x in ((q[0]-1, q[1]),(q[0]+1, q[1]), (q[0], q[1]-1), (q[0], q[1]+1)): if 0<=x[0]<=H-1 and 0<=x[1]<=W-1: if S[x[0]][x[1]]==".": S[x[0]][x[1]] = S[q[0]][q[1]]+1 queue.append(x) return max(S[h][w] for w in range(W) for h in range(H) \ if str(S[h][w]).isdigit()) for h in range(H): for w in range(W): if S_raw[h][w]==".": m = max(m, calc(h,w)) print(m)
0
null
121,131,187,010,372
280
241
A ,V= map(int, input().split()) B ,W= map(int, input().split()) T = int(input()) if V <= W: print("NO") elif abs(A - B) / (V - W) <= T: print("YES") else: print("NO")
def gcd(a, b): # ?????§??¬?´???° while b > 0: a, b = b, a % b return a a, b = map(int, input().split()) print(gcd(a, b))
0
null
7,570,735,031,282
131
11
import sys from functools import lru_cache from collections import defaultdict inf = float('inf') readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def read(): return int(readline()) def reads(): return map(int, readline().split()) a,b,n=reads() x=min(b-1,n) print(int((a*x)/b))
alphabet = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") N = int(input()) S = input() for i in S: print(alphabet[(alphabet.index(i)+N) % 26], end='')
0
null
81,128,149,125,880
161
271
# -*- coding: utf-8 -*- ## Library import sys from fractions import gcd import math from math import ceil,floor import collections from collections import Counter import itertools import copy ## input # N=int(input()) # A,B,C,D=map(int, input().split()) # S = input() # yoko = list(map(int, input().split())) # tate = [int(input()) for _ in range(N)] # N, M = map(int,input().split()) # P = [list(map(int,input().split())) for i in range(M)] # S = [] # for _ in range(N): # S.append(list(input())) N=int(input()) print(N+N**2+N**3)
x=int(input()) x=x+(x**2)+(x**3) print(x)
1
10,143,212,567,058
null
115
115
n = int(input()) S = [int(x) for x in input().split()] q = int(input()) T = [int(x) for x in input().split()] res = 0 for num in T: if num in S: res += 1 print(res)
def main(): n = int(input()) S = list(map(int, input().split())) q = int(input()) T = list(map(int, input().split())) res = 0 for i in T: if i in S: res += 1 print(res) if __name__ == '__main__': main()
1
66,772,811,560
null
22
22
from collections import Counter N=int(input()) list1=list(map(int,input().split())) dic1=Counter(list1) def choose2(n): return n*(n-1)/2 sum=0 for key in dic1: sum+=choose2(dic1[key]) for i in list1: print(int(sum-dic1[i]+1))
import collections import itertools N = int(input()) A = list(map(int, input().split())) ac = collections.Counter(A) dp = [0] * (N+1) dp2 = [0] * (N+1) total = 0 for no, num in ac.items(): dp[no] = int(num*(num-1)/2) dp2[no] = dp[no] - (num-1) total += dp[no] for k in range(1,N+1): no = A[k-1] print(int(total - dp[no] + dp2[no]))
1
47,673,837,025,178
null
192
192
values = input() W, H, x, y, r = [int(x) for x in values.split()] flag = True if x - r < 0 or x + r > W: flag = False if y - r < 0 or y + r > H: flag = False if flag: print('Yes') else: print('No')
w,h,x,y,r = map(int,raw_input().split()) if w-r >= x and h-r >= y and x-r >= 0 and y-r >= 0: print "Yes" else: print "No"
1
454,606,518,620
null
41
41
#!/usr/bin python3 # -*- coding: utf-8 -*- n = int(input()) print(int(not n))
a = int(input()) if a == 0: print("1") else: print("0")
1
2,943,757,134,500
null
76
76
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import copy import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f def solve(): N = Scanner.int() cnt = [[0 for _ in range(10)] for _ in range(10)] for i in range(1, N + 1): front = int(str(i)[0]) back = int(str(i)[-1]) cnt[front][back] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): ans += cnt[i][j] * cnt[j][i] print(ans) def main(): # sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
x=[] z=[] A,b=map(int,input().split()) for i in range(0,A): a=list(map(int,input().split())) x.append(a) for s in range(0,b): q=int(input()) z.append(q) for i in range(A): l=0 for s in range(b): l += x[i][s]*z[s] print(l)
0
null
43,742,871,101,232
234
56
import sys #input = sys.stdin.buffer.readline def main(): S = input() print(S[:3]) if __name__ == "__main__": main()
X=int(input()) count=8 for i in range(600,2001,200): if X<i: print(count) exit() count-=1
0
null
10,688,021,813,810
130
100
import string x = '' allcase = string.ascii_lowercase while True: try: x+=input().lower() except:break for letter in allcase: print(letter + " : " + repr(x.count(letter)))
s = '' while True: try: s += input().lower() except EOFError: break for c in 'abcdefghijklmnopqrstuvwxyz': print('{} : {}'.format(c, s.count(c)))
1
1,646,179,134,430
null
63
63
import sys num = int(sys.stdin.readline()) ans = num ** 3 print ans
X,Y = map(int, input().split()) if X * 2 > Y: print('No') elif X * 4 < Y: print('No') else: for i in range(0,X+1): if Y == (X * 2) + (i * 2): print('Yes') break else: print('No')
0
null
7,092,040,007,598
35
127
x=int(input()) a=x//3600 b=(x-a*3600)//60 c=x-(a*3600+b*60) print(a, ':', b, ':', c, sep='')
S=int(input()) a,s=divmod(S,60) h,m=divmod(a,60) print(str(h)+':'+str(m)+':'+str(s))
1
333,853,413,844
null
37
37
import heapq s = [] h, w = map(int, input().split()) for _ in range(h): s.append(list(input().strip())) ans = 0 for i in range(h): for j in range(w): if s[i][j] == '#': continue q = [(0, (i, j))] mins = [[h * w for _ in range(w)] for _ in range(h)] visited = [[0 for _ in range(w)] for _ in range(h)] while len(q) > 0: c, (x, y) = heapq.heappop(q) ans = max(ans, c) if visited[x][y]: continue visited[x][y] = True for nx, ny in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]: if nx < 0 or nx >= h or ny < 0 or ny >= w or s[nx][ny] == '#': continue if visited[nx][ny]: continue if mins[nx][ny] > c + 1: mins[nx][ny] = c + 1 heapq.heappush(q, (c + 1, (nx, ny))) print(ans)
# D - Maze Master # https://atcoder.jp/contests/abc151/tasks/abc151_d from collections import deque def main(): height, width = [int(num) for num in input().split()] maze = [input() for _ in range(height)] ans = 0 next_to = ((0, 1), (1, 0), (0, -1), (-1, 0)) for start_x in range(height): for start_y in range(width): if maze[start_x][start_y] == '#': continue queue = deque() queue.append((start_x, start_y)) reached = [[-1] * width for _ in range(height)] reached[start_x][start_y] = 0 while queue: now_x, now_y = queue.popleft() for move_x, move_y in next_to: adj_x, adj_y = now_x + move_x, now_y + move_y # Python は index = -1 が通ってしまうことに注意。 # except IndexError では回避できない。 if (not 0 <= adj_x < height or not 0 <= adj_y < width or maze[adj_x][adj_y] == '#' or reached[adj_x][adj_y] != -1): continue queue.append((adj_x, adj_y)) reached[adj_x][adj_y] = reached[now_x][now_y] + 1 most_distant = max(max(row) for row in reached) ans = max(most_distant, ans) print(ans) if __name__ == '__main__': main()
1
94,491,490,596,388
null
241
241
n = int(input()) ab = [tuple(map(int, input().split())) for _ in range(n)] a, b = map(list, zip(*ab)) a.sort() b.sort(reverse=True) a1, b1 = a[n//2], b[n//2] a2, b2 = a[n//2-1], b[n//2-1] if n % 2: print(b1 - a1 + 1) else: print((b1+b2) - (a1+a2) + 1)
N = int(input()) left = [] right = [] for _ in range(N): l, r = map(int, input().split()) left.append(l) right.append(r) left.sort() right.sort() if N%2==0: for i, (l, r) in enumerate(zip(left, right), 1): if i==N//2: L = l R = r if i==N//2+1: R +=r L += l print((R-L)+1) else: for i, (l, r) in enumerate(zip(left, right), 1): if i==N//2+1: print(r-l+1)
1
17,382,073,202,560
null
137
137
n = int(input()) lst = list(map(int, input().split())) count = 0 for x in range(1,n+1,2): if lst[x-1]%2 != 0: count +=1 print(count)
ABC = input().split() print("Yes" if len(set(ABC)) == 2 else "No")
0
null
37,789,141,137,290
105
216
print(1-int(input()))
n, *a = map(int, open(0).read().split()) a.sort() if a[0] == 0: print(0) exit() b = 1 for c in a: b *= c if b > 10 ** 18: print(-1) exit() print(b)
0
null
9,561,862,813,032
76
134
data = { 'S': [int(x) for x in range(1,14)], 'H': [int(x) for x in range(1,14)], 'C': [int(x) for x in range(1,14)], 'D': [int(x) for x in range(1,14)] } count = int(input()) for c in range(count): (s, r) = input().split() r = int(r) del data[s][data[s].index(r)] for i in ('S', 'H', 'C', 'D'): for v in data[i]: print(i, v)
def havec(x_list, y): x_list[y-1] = 1 def printc(x_list, s): for i in range(13): if x_list[i] == 0: print("%s %d" %(s, i+1)) n = input() Sp = [0,0,0,0,0,0,0,0,0,0,0,0,0] Ha = [0,0,0,0,0,0,0,0,0,0,0,0,0] Cl = [0,0,0,0,0,0,0,0,0,0,0,0,0] Di = [0,0,0,0,0,0,0,0,0,0,0,0,0] for i in range(n): incard = raw_input() a, b = incard.split(" ") b = int(b) if a == "S": havec(Sp, b) elif a == "H": havec(Ha, b) elif a == "C": havec(Cl, b) else: havec(Di, b) printc(Sp, "S") printc(Ha, "H") printc(Cl, "C") printc(Di, "D")
1
1,052,707,578,340
null
54
54
n=int(input()) if n%2==0: r=0 i=1 while 2*5**i<=n: r+=n//(2*5**i) i+=1 print(r) else: print(0)
def main(): n = int(input()) if n%2==1: print(0) return md = 10 cnt = 0 while n>=md: cnt += n//md md = md*5 print(cnt) if __name__ == "__main__": main()
1
115,921,858,327,200
null
258
258
import math def koch(d, p1, p2): if d == 0: return v = [p2[0] - p1[0], p2[1] - p1[1]] s = [p1[0] + v[0] / 3, p1[1] + v[1] / 3] t = [p1[0] + 2 * v[0] / 3, p1[1] + 2 * v[1] / 3] u = [p1[0] + v[0] / 2 - v[1] * math.sqrt(3) / 6, p1[1] + v[1] / 2 + v[0] * math.sqrt(3) / 6] koch(d - 1, p1, s) print(" ".join(map(str, s))) koch(d - 1, s, u) print(" ".join(map(str, u))) koch(d - 1, u, t) print(" ".join(map(str, t))) koch(d - 1, t, p2) n = int(input()) print("0 0") koch(n, [0, 0], [100, 0]) print("100 0")
n=int(input()) abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] ans = '' while n: ans += abc[(n-1)%len(abc)] n = (n-1)//len(abc) print(ans[::-1])
0
null
6,021,022,191,680
27
121
def bubbleSort(A, N): flag = 1 cnt = 0 while flag: flag = 0 for j in range(N - 1, 0, -1): if A[j] < A[j - 1]: cnt += 1 A[j], A[j - 1] = A[j - 1], A[j] flag = 1 print(*A) print(cnt) N = int(input()) A = list(map(int, input().split())) bubbleSort(A, N)
A = input() if(A.isupper()): print("A") else: print("a")
0
null
5,717,259,496,928
14
119
import sys from collections import deque import bisect import copy import heapq import itertools import math input = sys.stdin.readline sys.setrecursionlimit(1000000) mod = 10 ** 9 + 7 def read_values(): return map(int, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_list(): return list(read_values()) def read_lists(N): return [read_list() for n in range(N)] def f(N): res = 0 while N != 0: b = format(N, "b").count("1") N %= b res += 1 return res def main(): N = int(input()) X = input().strip() K = X.count("1") A = [(1, 1)] for i in range(N): a, b = A[-1] A.append(((a * 2) % (K - 1) if K != 1 else 0, (b * 2) % (K + 1))) B = [0, 0] for i, b in enumerate(X[::-1]): if b == "0": continue if K != 1: B[0] += A[i][0] B[0] %= K - 1 B[1] += A[i][1] B[1] %= K + 1 res = [0] * N for i, b in enumerate(X[::-1]): if b == "0": res[i] = (B[1] + A[i][1]) % (K + 1) else: if K == 1: res[i] = 0 continue res[i] = (B[0] - A[i][0]) % (K - 1) res[i] = f(res[i]) + 1 for r in res[::-1]: print(r) if __name__ == "__main__": main()
def solve(x): cnt = 1 while x > 0: x %= bin(x).count('1') cnt += 1 return cnt n = int(input()) x = input() one = sum(map(int, list(x))) num = int(x, 2) up = num%(one+1) if one == 1: down = 0 else: down = num%(one-1) for i in range(n): if x[i] == '1': if one == 1: print(0) continue s = (down - pow(2, n-i-1, one-1))%(one-1) else: s = (up + pow(2, n-i-1, one+1))%(one+1) print(solve(s))
1
8,234,520,606,420
null
107
107
#coding:utf-8 n = int(input()) A = list(map(int, input().split())) times = 0 for i in range(n): minj = i for j in range(i,n): if A[j] < A[minj]: minj = j if i != minj: A[i], A[minj] = A[minj], A[i] times += 1 B = " ".join([str(num) for num in A]) print(B) print(times)
N = int(input()) A = [int(x) for x in input().split()] num_c = 0 for i in range(0, N): minj = i for j in range(i, N): if A[j] < A[minj]: minj = j if(i != minj): A[i], A[minj] = A[minj], A[i] num_c += 1 print((" ").join(str(x) for x in A)) print(num_c)
1
19,409,182,308
null
15
15
K, N = map(int, input().split()) nums = list(map(int, input().split())) before = 0 max_n = 0 for num in nums: dist = num - before max_n = max(max_n, dist) before = num max_n = max(max_n, K-nums[-1]+nums[0]) print(K-max_n)
def main(): x = list(map(int, input().split())) k = x[0] n = x[1] a = list(map(int, input().split())) max_distance = 0 for i in range(n): distance = a[i]-a[i-1] if distance < 0: distance = k+distance if max_distance < distance: max_distance = distance answer = k - max_distance print(answer) if __name__ == "__main__": main()
1
43,500,697,981,652
null
186
186