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
import sys from collections import deque input = sys.stdin.readline def dfs(N): alphabet = "abcdefghij" stack = deque(["a"]) while stack: s = stack.pop() if len(s) == N: print(s) continue for suffix in reversed(alphabet[:len(set(s)) + 1]): stack.append("".join((s, suffix))) def main(): N = int(input()) dfs(N) if __name__ == "__main__": main()
import sys import math from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() # アルファベットと数字の対応 alp_to_num = {chr(i+97): i for i in range(26)} ALP_to_num = {chr(i+97).upper(): i for i in range(26)} num_to_alp = {i: chr(i+97) for i in range(26)} num_to_ALP = {i: chr(i+97).upper() for i in range(26)} def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)] def main(): N = NI() ans = [] def dfs(s, i, max_num): if i == N: ans.append(s) return for n in range(max_num+2): dfs(s + num_to_alp[n], i+1, max(max_num, n)) dfs("a", 1, 0) ans.sort() for a in ans: print(a) if __name__ == "__main__": main()
1
52,618,833,603,228
null
198
198
N,u,v = map(int, input().split()) G=[[] for i in range(N)] for i in range(N-1): s,t = map(int, input().split()) G[s-1].append(t-1) G[t-1].append(s-1) def expro(u): D=[0]*N D[u]=0 S=[] S.append(u) L=[] q=0 while(q<N): l=S[q] for i in range(len(G[l])): m=G[l][i] if(len(G[l])==1 and l!=u): L.append(l) if(D[m]==0 and m!=u): D[m]=D[l]+1 S.append(m) #S.remove(l) q+=1 return L,D L,D = expro(u-1) M,E = expro(v-1) k=0 ans=0 #print(G) #print(D) #print(L) for i in M: if D[i]<E[i]: if k<E[i]: k=E[i] ans=E[i]-1 print(ans)
while True: n, x = map(int, input().split()) if n == x == 0: break cnt = 0 upper_max_value = min(x - 3, n) lower_max_value = max(int(x / 3), 3) for i in range(upper_max_value, lower_max_value - 1, -1): for j in range(i - 1, 1, -1): for k in range(j - 1, 0, -1): if (i + j + k) == x: cnt += 1 print(cnt)
0
null
59,449,230,143,442
259
58
import numpy as np N = int(input()) data_list = [] for i in range(N): si = input() data_list.append(si) data_list = np.array(data_list) print(len(np.unique(data_list)))
import os import sys import numpy as np def solve(N, U, V, AB): G = [[0]*0 for _ in range(N+1)] for idx_ab in range(len(AB)): a, b = AB[idx_ab] G[a].append(b) G[b].append(a) P1 = np.zeros(N+1, dtype=np.int64) def dfs1(u): st = [u] while st: v = st.pop() p = P1[v] for u in G[v]: if p != u: st.append(u) P1[u] = v dfs1(U) path_u2v = [U] v = V while v != U: v = P1[v] path_u2v.append(v) path_u2v.reverse() l = len(path_u2v) half = (l-2) // 2 c = path_u2v[half] ng = path_u2v[half+1] Depth = np.zeros(N+1, dtype=np.int64) def dfs2(c): st = [c] P = np.zeros(N+1, dtype=np.int64) while st: v = st.pop() p = P[v] d = Depth[v] for u in G[v]: if p != u and u != ng: st.append(u) P[u] = v Depth[u] = d + 1 dfs2(c) c_ = path_u2v[l-1-half] v = c_ while v != c: Depth[v] = 0 v = P1[v] d = l%2 ans = max(Depth) + half + d return ans # >>> numba compile >>> numba_config = [ [solve, "i8(i8,i8,i8,i8[:,:])"], ] if sys.argv[-1] == "ONLINE_JUDGE": from numba import njit from numba.pycc import CC cc = CC("my_module") for func, signature in numba_config: vars()[func.__name__] = njit(signature)(func) cc.export(func.__name__, signature)(func) cc.compile() exit() elif os.name == "posix": exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}") else: from numba import njit for func, signature in numba_config: vars()[func.__name__] = njit(signature, cache=True)(func) print("compiled!", file=sys.stderr) # <<< numba compile <<< def main(): N, u, v = map(int, input().split()) if N==2: print(0) return AB = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N-1, 2) ans = solve(N, u, v, AB) print(ans) main()
0
null
74,078,559,442,856
165
259
from itertools import accumulate n = int(input()) A = list(map(int, input().split())) L = [0] R = [] min_L = float("inf") for i, a in enumerate(A): b = A[-(i+1)] if i%2 == 0: L.append(a) else: R.append(a) R.append(0) L = list(accumulate(L)) R = list(accumulate(R[::-1]))[::-1] ans = -float("inf") if n%2: def f(A): temp = 0 left = 0 right = 0 for i in range(2, n, 2): temp += A[i] res = max(ans, temp) for i in range(1, n//2): temp -= A[i*2] left, right = left+A[2*(i-1)], max(left, right)+A[2*(i-1)+1] res = max(res, temp+max(left, right)) return res ans = max(f(A), f(A[::-1])) temp = 0 for i in range(1, n, 2): temp += A[i] ans = max(ans, temp) else: for l, r in zip(L, R): ans = max(ans, l+r) print(ans)
n, q = list(map(int, input().split())) que = [] for _ in range(n): name, time = input().split() que.append([name, int(time)]) elapsed_time = 0 while que: name, time = que.pop(0) dt = min(q, time) time -= dt elapsed_time += dt if time > 0: que.append([name, time]) else: print (name, elapsed_time)
0
null
18,880,059,017,120
177
19
import bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys from cmath import pi, rect sys.setrecursionlimit(10**7) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) A,B,H,M = LI() H += M / 60 H = H/12 * 2*pi M = M/60 * 2*pi # 余弦定理 l = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(H-M) ) # 複素数座標 Aexp(iθ) zA = A * np.exp(H*1j) zB = B * np.exp(M*1j) l=abs(zA - zB) print(l)
import math a,b,H,M=map(int,input().split()) theta_a = math.pi/6 * (H+M/60) theta_b = math.pi*2*M/60 ans = math.sqrt((b*math.cos(theta_b) - a*math.cos(theta_a))**2 + (b*math.sin(theta_b) - a*math.sin(theta_a))**2) print(ans)
1
20,085,880,598,150
null
144
144
# -*-coding:utf-8 def main(): while True: n, x = map(int, input().split()) if ((n == 0) and (x == 0)): break count = 0 for i in range(1, n+1): for j in range(1, n+1): for k in range(1, n+1): if((i<j) and (j<k) and i+j+k == x): count += 1 print(count) if __name__ == '__main__': main()
n, x = map(int, input().split()) while n != 0 or x != 0: count = 0 for i in range(1, n+1): for j in range(i+1, n+1): for k in range(j+1, n+1): if i+j+k == x: count += 1 print(count) n, x = map(int, input().split())
1
1,282,203,482,060
null
58
58
from typing import List class Info: def __init__(self, arg_start, arg_end, arg_area): self.start = arg_start self.end = arg_end self.area = arg_area if __name__ == "__main__": LOC: List[int] = [] POOL: List[Info] = [] all_symbols = input() loc = 0 total_area = 0 for symbol in all_symbols: if symbol == '\\': LOC.append(loc) elif symbol == '/': if len(LOC) == 0: continue tmp_start = int(LOC.pop()) tmp_end = loc tmp_area = tmp_end - tmp_start total_area += tmp_area while len(POOL) > 0: # \ / : (tmp_start, tmp_end) # \/ : (POOL[-1].start, POOL[-1].end) if tmp_start < POOL[-1].start and POOL[-1].end < tmp_end: tmp_area += POOL[-1].area POOL.pop() else: break POOL.append(Info(tmp_start, tmp_end, tmp_area)) else: pass loc += 1 print(f"{total_area}") print(f"{len(POOL)}", end="") while len(POOL) > 0: print(f" {POOL[0].area}", end="") POOL.pop(0) print()
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): N = int(input()) A = [(i, v) for i, v in enumerate(map(int, input().split()))] values = [[0] * (N + 1) for _ in range(N + 1)] A.sort(key=lambda x:-x[1]) for i, (p, v) in enumerate(A): for j in range(i + 1): left = abs((p - j) * v) right = abs((N - 1 - (i - j) - p) * v) values[i + 1][j + 1] = max(values[i][j] + left, values[i + 1][j + 1]) values[i + 1][j] = max(values[i][j] + right, values[i + 1][j]) print(max(values[-1])) if __name__ == '__main__': main()
0
null
16,778,386,674,684
21
171
N = int(input()) 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 L1 = factorization(N - 1) s = 1 # print(L1) for [a, b] in L1: s *= (b + 1) # print(s) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] for i in set(make_divisors(N))-{1}: temp = N while temp % i == 0: temp //= i if (temp-1) % i == 0: s += 1 s -= 1 if N == 2: print(1) else: print(s)
import math N = int(input()) N_d = [] N1_d = [] answer = set() for i in range(1,math.ceil(N**0.5)+1): if N%i == 0: N_d.append(i) N_d.append(N//i) for i in range(len(N_d)): temp = N while temp % N_d[i] == 0: temp = temp//N_d[i] if N_d[i] == 1: break if temp % N_d[i] == 1: answer.add(N_d[i]) for i in range(1,math.ceil((N-1)**0.5)+1): if (N-1) %i == 0: answer.add(i) answer.add((N-1)//i) answer.remove(1) print(len(answer))
1
41,322,130,666,880
null
183
183
N=input() N=N[::-1]+"0" ans=0 up=0 for i,n in enumerate(N): d=int(n)+up if d>5 or (d==5 and i<len(N)-1 and int(N[i+1])>=5): ans+=(10-d) up=1 else: ans+=d up=0 print(ans)
N = [0] + list(map(int, list(input()))) L = len(N) ans = 0 for i in range(L-1, -1, -1): if N[i] == 10: if i == 0: ans += 1 else: N[i-1] += 1 N[i] = 0 if N[i] < 5: ans += N[i] elif N[i] > 5: ans += 10 - N[i] N[i-1] += 1 else: if i == 0: ans += N[i] else: if N[i-1] >= 5: N[i-1] += 1 ans += 5 else: ans += N[i] print(ans)
1
70,607,441,069,730
null
219
219
def Binary_Search_Count(A,x,sort=True,equal=False): """2分探索によって,x未満の要素の個数を調べる. A:リスト x:調べる要素 sort:ソートをする必要があるかどうか(Trueで必要) equal:Trueのときはx"未満"がx"以下"になる """ if sort: A.sort() N=len(A) if A[-1]<=x: return N elif x<A[0] or (not equal and x==A[0]): return 0 L,R=0,N while R-L>1: C=L+(R-L)//2 if x<A[C] or (not equal and x==A[C]): R=C else: L=C return R def Binary_Search_High_Value(A,x,sort=True,equal=False): """Aのxを超える要素の中で最小のものを出力する. A:リスト x:調べる要素 sort:ソートをする必要があるかどうか(Trueで必要) equal:Trueのときはx"を超える"がx"以上"になる ※全ての要素がx以下(未満)場合はNoneが返される. """ if sort: A.sort() K=Binary_Search_Count(A,x,sort=False,equal=not equal) if K==len(A): return None else: return A[K] N=int(input()) T={i:[] for i in range(10)} S=input() for i in range(N): T[int(S[i])].append(i) X=0 for k in range(10**3): a,b,c=(k//100),(k//10)%10,k%10 if T[a]: x=T[a][0] if T[b]: y=Binary_Search_High_Value(T[b],x,False,False) if y!=None and T[c]: z=Binary_Search_High_Value(T[c],y,False,False) if z!=None: X+=1 print(X)
import math import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) def main(): n = int(input()) mod = 10 ** 9 + 7 h = {} zero = 0 for i in range(n): a, b = map(int, input().split()) if a == 0 and b == 0: zero += 1 continue m = (0, 0) if b == 0: m = (1, 0) elif b > 0: g = math.gcd(a, b) m = (a // g, b // g) else: g = math.gcd(a, b) m = (-1 * (a // g), -1 * (b // g)) if m not in h: h[m] = set() h[m].add(i) h2 = {} for m in h: mi1 = (-1 * m[1], m[0]) if mi1 in h and mi1 not in h2: h2[m] = mi1 mi2 = (m[1], -1 * m[0]) if mi2 in h and mi2 not in h2: h2[m] = mi2 ans = 1 left = n - zero for k, v in h2.items(): s1 = len(h[k]) s2 = len(h[v]) # print(s1, s2) r = (pow(2, s1 + s2, mod) - (pow(2, s1, mod) - 1) * (pow(2, s2, mod) - 1)) % mod ans *= r ans %= mod left -= (s1 + s2) ans *= pow(2, left, mod) ans -= 1 ans += zero print(ans % mod) if __name__ == '__main__': main()
0
null
74,859,477,245,960
267
146
N = int(input()) As = [] Bs = [] for _ in range(N): c = 0 m = 0 for s in input(): if s == '(': c += 1 elif s == ')': c -= 1 m = min(m, c) if c >= 0: As.append((-m, c - m)) else: Bs.append((-m, c - m)) As.sort(key=lambda x: x[0]) Bs.sort(key=lambda x: x[1], reverse=True) f = True c = 0 for (l, r) in As: if c < l: f = False break c += r - l if f: for (l, r) in Bs: if c < l: f = False break c += r - l f = f and (c == 0) if f: print('Yes') else: print('No')
import sys from functools import reduce n=int(input()) s=[input() for i in range(n)] t=[2*(i.count("("))-len(i) for i in s] if sum(t)!=0: print("No") sys.exit() st=[[t[i]] for i in range(n)] for i in range(n): now,mi=0,0 for j in s[i]: if j=="(": now+=1 else: now-=1 mi=min(mi,now) st[i].append(mi) now2=sum(map(lambda x:x[0],filter(lambda x:x[1]>=0,st))) v,w=list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st)) v.sort(reverse=True,key=lambda z:z[1]) w.sort(key=lambda z:z[0]-z[1],reverse=True) #print(now2) for vsub in v: if now2+vsub[1]<0: print("No") sys.exit() now2+=vsub[0] for wsub in w: if now2+wsub[1]<0: print("No") sys.exit() now2+=wsub[0] print("Yes")
1
23,569,542,866,610
null
152
152
if __name__ == '__main__': N, A, B = map(int, input().split()) base = pow(10, 100) C = A+B mod = N%C n = N//C if mod>A: print(A*n+A) else: print(A*n+mod)
n, a, b = map(int, input().split()) d = n // (a + b) q = n % (a + b) if q <= a: count = d * a + q else: count = d * a + a print(count)
1
55,724,635,334,368
null
202
202
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy import bisect if __name__ == "__main__": n,x,y = map(int,input().split()) x-=1 y-=1 ans = [0]*(n) for i in range(n): for j in range(i+1,n): d = min(abs(i-j),abs(x-i) + abs(y-j) + 1) ans[d] += 1 for i in range(1,n): print(ans[i])
billdings = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)] def printstate(billdings): """ for billnum, billding in enumerate(billdings): for flooor in billding: for room in flooor: print(" {}".format(room), end="") print() print("#"*20 if billnum != len(billdings)-1 else "") """ for i in range(len(billdings)): for j in range(len(billdings[0])): for k in range(len(billdings[0][0])): print(" "+str(billdings[i][j][k]), end="") print() if i != len(billdings)-1: print("#"*20) n = int(input()) for _ in range(n): b, f, r, v = map(int, input().split()) b, f, r = b-1, f-1, r-1 billdings[b][f][r] += v printstate(billdings)
0
null
22,596,755,750,228
187
55
A1, A2, A3 = map(int, input().split()) print('win') if A1 + A2 + A3 <= 21 else print('bust')
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) a = LI() s = sum(a) if s >= 22: print('bust') else: print('win')
1
118,606,464,914,740
null
260
260
h, a = map(int, input().split()) ans = 0 while True: if h > 0: h = h - a ans += 1 else: print(ans) exit()
import sys import math from collections import deque from collections import defaultdict def main(): n, k = list(map(int,sys.stdin.readline().split())) ans = n//k if n%k != 0: ans += 1 print(ans) return 0 if __name__ == "__main__": main()
1
76,494,422,761,510
null
225
225
S = input() if str.islower(S): print('a') else: print('A') exit()
print(''.join(input().split()[::-1]))
0
null
57,129,888,916,640
119
248
in_value = int(input()) if in_value >= 30: print("Yes") else: print("No")
if(int(input())>=30): print("Yes") else: print("No")
1
5,701,884,134,688
null
95
95
import sys def get_maximum_profit(): element_number = int(input()) v0 = int(input()) v1 = int(input()) min_v = min(v0, v1) max_profit = v1-v0 for v in map(int, sys.stdin.readlines()): max_profit = max(max_profit, v-min_v) min_v = min(min_v, v) print(max_profit) if __name__ == '__main__': get_maximum_profit()
# -*- coding: utf-8 -*- import sys from collections import deque, defaultdict from math import sqrt, factorial, gcd, ceil, atan, pi # def input(): return sys.stdin.readline()[:-1] # warning not \n # def input(): return sys.stdin.buffer.readline().strip() # warning bytes # def input(): return sys.stdin.buffer.readline().decode('utf-8') import string # string.ascii_lowercase from bisect import bisect_left MOD = int(1e9)+7 INF = float('inf') def solve(): # n, m = [int(x) for x in input().split()] n, x, y = [int(x) for x in input().split()] ans = defaultdict(int) for i in range(1, n): for j in range(i + 1, n+1): d = min(j - i, min(abs(i - x) + 1 + abs(j - y), abs(i - y) + 1 + abs(j - x))) ans[d] += 1 for i in range(1, n): print(ans[i]) t = 1 # t = int(input()) for case in range(1,t+1): ans = solve() """ azyxwvutsrqponmlkjihgfedcb """
0
null
21,961,232,796,712
13
187
from collections import deque S = input() pool_q=deque() slope_q=deque() for i,s in enumerate(S): if s=="\\": slope_q.append(i) pool_q.append((i,0)) elif s=="/": if len(slope_q) > 0: pre_down=slope_q.pop() plus=i-pre_down while 1: pre_pool=pool_q.pop() if pre_pool[0] == pre_down: pool_q.append((pre_down,plus)) break else: plus+=pre_pool[1] SUM = 0 ans=[0] cnt=0 for i in range(len(pool_q)): pool=pool_q.popleft()[1] if pool > 0: ans.append(pool) SUM+=pool cnt+=1 ans[0]=cnt print(SUM) print(*ans)
s=[] p=[] a=i=0 for c in input(): if"\\"==c:s+=[i] elif"/"==c and s: j=s.pop() t=i-j a+=t while p and p[-1][0]>j:t+=p[-1][1];p.pop() p+=[(j,t)] i+=1 print(a) if p:print(len(p),*list(zip(*p))[1]) else:print(0)
1
57,849,135,302
null
21
21
n, k = map(int, input().split()) R, S, P = map(int, input().split()) t = input() prev = {} ans = 0 for i in range(k): if t[i] == 'r': ans += P prev[i] = 'p' elif t[i] == 's': ans += R prev[i] = 'r' elif t[i] == 'p': ans += S prev[i] = 's' for i in range(k, n): a = i % k if t[i] == 'r': if prev[a] != 'p': ans += P prev[a] = 'p' else: if i + k < n and t[i + k] != 's': prev[a] = 'r' else: prev[a] = 's' elif t[i] == 's': if prev[a] != 'r': ans += R prev[a] = 'r' else: if i + k < n and t[i + k] != 'p': prev[a] = 's' else: prev[a] = 'p' elif t[i] == 'p': if prev[a] != 's': prev[a] = 's' ans += S else: if i + k < n and t[i + k] != 'r': prev[a] = 'p' else: prev[a] = 'r' print(ans)
k, n = map(int,input().split()) a = list(map(int,input().split())) new_a = sorted(a) num = len(new_a) - 1 s_a = [] b = (k - new_a[num]) + new_a[0] s_a.append(b) cun = 0 for i in new_a[1::]: s = i - new_a[cun] s_a.append(s) cun += 1 max_num = max(s_a) print(sum(s_a) - max_num)
0
null
74,804,808,557,788
251
186
MOD = int(1e+9 + 7) N, K = map(int, input().split()) cnt = [0] * (K + 1) # 要素が全てXの倍数となるような数列の個数をXごとに求める for x in range(1, K + 1): cnt[x] = pow(K // x, N, MOD) for x in range(K, 0, -1): # 2X, 3Xの個数を求めてひく for i in range(2, K // x + 1): cnt[x] -= cnt[x * i] ans = 0 for k in range(K+1): ans += cnt[k] * k ans = ans % MOD print(ans)
import sys sys.setrecursionlimit(10**7) def main(): s=input() k=int(input()) n=len(s) def dp(i,j,smaller): # i桁目以降について、0以外の値を残りj個使用可能という状況を考える。i桁目までは決定している。残りn-i桁 # このときi桁目までの部分が「等しい」か「strict に小さくなっている」かを smaller フラグによって分岐する。 if n==i: # 0でない数字をk個つかえなかったパターン。 return 0 if j>0 else 1 if smaller:# 残りのn-i桁の中からj桁選び好きな数字にできる。j桁以外はすべて0 if j==0: return 1 elif j==1: return (n-i)*9 elif j==2: return ((n-i)*(n-i-1))//2*9**2 elif j==3: return ((n-i)*(n-i-1)*(n-i-2))//6*9**3 if j==0: # i桁目以降はすべて0で決まり return 1 ret=0 # i+1桁目が0なら0を使うしかない if s[i]=='0': ret+=dp(i+1,j,smaller) else: ret+=dp(i+1,j-1,smaller) # i+1桁目でsと同じ数字を使う ret+=(int(s[i])-1)*dp(i+1,j-1,True) # i+1桁目で0より大きくs未満の数字使う ret+=dp(i+1,j,True) # i+1桁目で0を使う。 return ret print(dp(0,k,False)) if __name__=='__main__': main()
0
null
56,093,708,231,378
176
224
import math X = int(input()) print(int(360 / math.gcd(360, X)))
X = int(input()) K = 0 while ((X * K) % 360 != 0) or (K == 0): K += 1 print(K)
1
13,156,398,788,858
null
125
125
import os, sys, re, math S = input() count = 0 for i in range(len(S) // 2): if S[i] != S[-i - 1]: count += 1 print(count)
import math S = input() ans = 0 l = int(math.floor(len(S)/2)) for i in range(l): if S[i] != S[len(S)-1-i]: ans += 1 print(ans)
1
119,571,303,751,788
null
261
261
# coding: utf-8 while True: strnum = input().rstrip() if strnum == "0": break answer = sum(map(int, strnum)) print(answer)
N,Q = map(int,input().split()) par = [-1]*(N+1) def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) #経路圧縮 return par[x] def same(x,y): return find(x) == find(y) def unite(x,y): x = find(x) y = find(y) if x == y: return 0 else: if par[x] > par[y]: x,y = y,x par[x] += par[y] par[y] = x def size(x): return -par[find(x)] for i in range(Q): a,b = map(int,input().split()) a-=1 b-=1 unite(a,b) M = 0 for i in range(N): M = max(size(i),M) print(M)
0
null
2,786,377,523,520
62
84
def print_frame(h, w): """ h: int(3 <= h <= 300) w: int(3 <= w <= 300) outputs a rectangle frame h x w >>> print_frame(3, 4) #### #..# #### >>> print_frame(5, 6) ###### #....# #....# #....# ###### >>> print_frame(3, 3) ### #.# ### """ print('#' * w) for i in range(h-2): print('#' + '.'*(w-2) + '#') print('#' * w) if __name__ == '__main__': while True: (h, w) = [int(i) for i in input().split(' ')] if h == 0 and w == 0: break print_frame(h, w) print()
while True: H, W = [int(i) for i in input().split()] if H == W == 0: break for h in range(H): for w in range(W): if h == 0 or h == H-1 or w == 0 or w == W - 1: print('#', end='') else: print('.', end='') print() print()
1
828,861,812,792
null
50
50
n,m=map(int,input().split()) C=list(map(int,input().split())) dp=[[float('inf')]*(n+1) for i in range(m+1)] for i in range(m+1): dp[i][0]=0 for i in range(1,m+1): c=C[i-1] for j in range(1,n+1): dp[i][j]=dp[i-1][j] if j>=c: dp[i][j]=min(dp[i][j],dp[i-1][j-c]+1,dp[i][j-c]+1) print(dp[m][n])
import numpy as np from functools import * import sys sys.setrecursionlimit(100000) input = sys.stdin.readline def acinput(): return list(map(int, input().split(" "))) def II(): return int(input()) directions=np.array([[1,0],[0,1],[-1,0],[0,-1]]) directions = list(map(np.array, directions)) mod = 10**9+7 def factorial(n): fact = 1 for integer in range(1, n + 1): fact *= integer return fact def serch(x, count): #print("top", x, count) for d in directions: nx = d+x #print(nx) if np.all(0 <= nx) and np.all(nx < (H, W)): if field[nx[0]][nx[1]] == "E": count += 1 field[nx[0]][nx[1]] = "V" count = serch(nx, count) continue if field[nx[0]][nx[1]] == "#": field[nx[0]][nx[1]] = "V" count = serch(nx, count) return count K=int(input()) s = [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] print(s[K-1])
0
null
25,167,707,226,960
28
195
w,c = map(int,input().split()) res = w - (2*c) if res < 0: res =0 print(res)
n=int(input()) def dfs(s,mx): if len(s)==n: print(s) return for c in range(ord('a'),mx+2): t=s t+=chr(c) dfs(t,max(mx,c)) dfs("",ord('a')-1)
0
null
109,456,522,378,560
291
198
n,k=map(int,input().split()) p=list(map(int,input().split())) dp=[0]*(n-k+1) dp[0]=sum(p[:k]) for i in range(n-k): dp[i+1]=dp[i]+p[k+i]-p[i] print((max(dp)+k)/2)
import math N = int(input()) ans = 0 ve = math.floor(math.sqrt(N)) for st in range(ve): tmp = math.floor(N/(st+1)-0.000001) score = 2*(tmp - st) if score > 0: score -= 1 ans += score print(ans)
0
null
38,748,235,660,420
223
73
s=input() count=0 list_s=list(s) if(list_s[2]==list_s[3] and list_s[4]==list_s[5]): print("Yes") else: print("No")
n=int(input()) mod=998244353 A=list(map(int,input().split())) import sys # mod=10**9+7 ; inf=float("inf") from math import sqrt, ceil from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化 input=lambda: sys.stdin.readline().strip() sys.setrecursionlimit(11451419) from decimal import ROUND_HALF_UP,Decimal #変換後の末尾桁を0や0.01で指定 #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)) from functools import lru_cache from bisect import bisect_left as bileft, bisect_right as biright from fractions import Fraction as frac #frac(a,b)で正確なa/b #メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10) #引数にlistはだめ #######ここまでテンプレ####### #ソート、"a"+"b"、再帰ならPython3の方がいい #######ここから天ぷら######## C=Counter(A) if A[0]!=0 or A.count(0)>1: print(0);exit() Q=[C[i] for i in range(max(A)+1)] #print(Q) ans=1 for i in range(len(Q)-1): ans*= pow(Q[i],Q[i+1],mod) ans%=mod print(ans)
0
null
98,168,106,882,432
184
284
x,y=map(int,input().split()) print(100000*(max(4-x,0)+max(4-y,0)+4*(x==y==1)))
x,y = map(int,input().split()) if(x+y==2): print(1000000) else: answer = 0 if(x==2): answer+=200000 elif(x==3): answer+=100000 elif(x==1): answer+=300000 if(y==2): answer+=200000 elif(y==3): answer+=100000 elif(y==1): answer+=300000 print(answer)
1
140,225,963,896,380
null
275
275
# Forbidden List X, N = [int(i) for i in input().split()] pi = [int(i) for i in input().split()] pl = [] pu = [] for i in pi: if i <= X: pl.append(i) if X <= X: pu.append(i) pl.sort(reverse=True) pu.sort() nl = X for i in pl: if i == nl: nl -= 1 nu = X for i in pu: if i == nu: nu += 1 if X - nl <= nu - X: print(nl) else: print(nu)
X, N = map(int, input().split()) if not N == 0: p_l = list(map(int, input().split())) if N == 0: print(X) exit() a = b = X if not a in p_l: if not b in p_l: if a > b: print(b) exit() else: print(a) exit() print(a) exit() elif not b in p_l: if not a in p_l: if a > b: print(b) exit() else: print(a) exit() print(b) while True: a += 1 if b > 0: b -= 1 if a in p_l and b in p_l: continue if not a in p_l: if not b in p_l: if a > b: print(b) # print("A") exit() else: # print("B") print(a) exit() # print("C") print(a) exit() elif not b in p_l: if not a in p_l: if a > b: print(b) # print("D") exit() else: print(a) # print("E") exit() # print("F") print(b) exit()
1
14,152,522,151,820
null
128
128
import sys def gcd(a,b): if b == 0: return a else: return gcd(b,a%b) for i in sys.stdin: a, b = map(int, i.split()) g = gcd(a,b) print g, a/g*b
#coding: utf-8 import sys def gojo(a,b): if b % a == 0: return a else: return gojo(b % a, a) for line in sys.stdin: l = map(int,line.split()) l.sort() a = l[0] b = l[1] print gojo(a,b),a*b/gojo(a,b)
1
701,077,380
null
5
5
K = int(input()) s = "" for i in range(K): s += 'ACL' print(s)
k = int(input()) i = 0 ans = "" for i in range(k): ans += "ACL" #print(ans) i += 1 print(ans)
1
2,196,010,919,542
null
69
69
n,m = map(int,input().split()) x = n*(n-1)//2 r = m*(m-1)//2 print(x+r)
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # ---------------------------------------------- aa = str(input()) #print(aa) tar = ord(aa) if (tar <= 91): print('A') else: print('a')
0
null
28,319,027,139,130
189
119
import math as mt def kock(n, p1, p2): if n == 0: return s =[(2 * p1[0] + p2[0]) / 3 , (2 * p1[1] + p2[1]) / 3] t = [(p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3] u = [(t[0]-s[0])*mt.cos(mt.radians(60)) -(t[1]-s[1])*mt.sin(mt.radians(60)) + s[0], (t[0]-s[0])*mt.sin(mt.radians(60)) +(t[1]-s[1])*mt.cos(mt.radians(60)) + s[1]] kock(n-1, p1, s) print("{0:.8f} {1:.8f}".format(s[0],s[1])) kock(n-1, s, u) print("{0:.8f} {1:.8f}".format(u[0],u[1])) kock(n-1, u, t) print("{0:.8f} {1:.8f}".format(t[0],t[1])) kock(n-1, t, p2) if __name__ == '__main__': n = int(input()) p1 = (0,0) p2 = (100,0) print("{0:.8f} {1:.8f}".format(p1[0],p1[1])) kock(n, p1, p2) print("{0:.8f} {1:.8f}".format(p2[0],p2[1]))
import math def koch(m, p1, p2): if m == 0: return s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3] t = [(p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3] u = [(t[0] - s[0]) * math.cos(math.pi / 3) - (t[1] - s[1]) * math.sin(math.pi / 3) + s[0], (t[0] - s[0]) * math.sin(math.pi / 3) + (t[1] - s[1]) * math.cos(math.pi / 3) + s[1]] koch(m-1, p1, s) print(s[0], s[1]) koch(m-1, s, u) print(u[0], u[1]) koch(m-1, u, t) print(t[0], t[1]) koch(m-1, t, p2) n = int(input()) print(0, 0) koch(n, [0, 0], [100, 0]) print(100, 0)
1
125,313,553,838
null
27
27
class Dice: def __init__(self, list1): self.f = list1 def move(self, direct): if direct == "N": self.f[0], self.f[1], self.f[4], self.f[5] = self.f[1], self.f[5], self.f[0], self.f[4] return self.f elif direct == "E": self.f[0], self.f[2], self.f[3], self.f[5] = self.f[3], self.f[0], self.f[5], self.f[2] return self.f elif direct == "S": self.f[0], self.f[1], self.f[4], self.f[5] = self.f[4], self.f[0], self.f[5], self.f[1] return self.f elif direct == "W": self.f[0], self.f[2], self.f[3], self.f[5] = self.f[2], self.f[5], self.f[0], self.f[3] return self.f data = list(map(int, input().split())) direction = input() dice = Dice(data) for i in direction: dice.move(i) print(dice.f[0])
def bubblesort(N, A): c, flag = 0, 1 while flag: flag = False for j in range(N-1, 0, -1): if A[j] < A[j-1]: A[j], A[j-1] = A[j- 1], A[j] c += 1 flag = True return (A, c) A, c = bubblesort(int(input()), list(map(int, input().split()))) print(' '.join([str(v) for v in A])) print(c)
0
null
128,985,438,130
33
14
c = input() a = ord(c) a += 1 print(chr(a))
C =input() L =[] for i in range(97, 123): L.append(chr(i)) print(L[ord(C)-96])
1
92,324,280,843,330
null
239
239
n = int(input()) count = [0 for i in range(n+1)] for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): f = x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x if f <= n: count[f] += 1 for i in count[1:]: print(i)
import math N = int(input()) #f(n) を以下の 2 つの条件の両方を満たすような 3 つの整数の組 (x,y,z)の個数とします。 # 1≤x,y,z # x**2 + y**2 + z**2 + xy + yz + zx = n # x,y,zの最大値を考える。 # x**2 + 1**2 + 1**2 + x + 1 + x = n # x**2 + 2x = n - 3 # x**2 + 2x -n + 3 = 0 # x = {-2 ± sqrt(2**2 - 4*1*(-n+3))}/2*1 # x = {-2 ± sqrt(4 + 4n -12)}/2 # 1 ≤ xより # x = {-2 + sqrt(4n - 8)}/2 = {-2 + 2 * sqrt(n - 2)}/2 = -1 + sqrt(n - 2) # ∴ 1 ≤ x ≤ math.floor(-1 + sqrt(n - 2)) # y,zも同様。 # N <= 10**4 より、x,y,xで全探索しても(10**2)**3 = 10**6 で間に合う ans_dict = {i:set() for i in range(1,N+1)} if N != 1: for i in range(1,1 + math.floor(-1 + math.sqrt(N - 2))): for j in range(1,1 + math.floor(-1 + math.sqrt(N - 2))): for k in range(1,1 + math.floor(-1 + math.sqrt(N - 2))): n = i**2 + j**2 + k**2 + i*j + j*k + k*i if 1 <= n <= N: ans_dict[n].add((i,j,k)) for i in range(1,N+1): print(len(ans_dict[i])) else: print(0)
1
7,955,480,669,850
null
106
106
#-*-coding:utf-8-*- import sys input=sys.stdin.readline def main(): numbers=[] a,b = map(int,input().split()) tmp1=int(a/0.08) tmp2=int(b/0.10) ans=[] for i in range(min(tmp1,tmp2),max(tmp1,tmp2)+2): if int(i*0.08) == a and int(i*0.10) == b: ans.append(i) if len(ans)>0: print(min(ans)) else: print("-1") if __name__=="__main__": main()
a,b = map(int,input().split()) if a%2 == 0: a_list = [int(a/0.08) + i for i in range(13)] else: a_list = [int(a/0.08) + i for i in range(1,13)] b_list = [int(b/0.1) + j for j in range(10)] com = set(a_list) & set(b_list) if len(com) == 0: print(-1) elif len(com) != 0: if int(min(com)*0.08) != a or int(min(com)*0.1) != b: print(-1) else: print(min(com))
1
56,380,689,642,772
null
203
203
from collections import deque N, M = map(int, input().split()) G = [[] for _ in range(N+1)] for _ in range(M): a, b = map(int, input().split()) G[a].append(b) G[b].append(a) q = deque([1]) closed = [False] * (N+1) closed[1] = True Ans = [0] * (N+1) while q: v = q.popleft() for u in G[v]: if not closed[u]: closed[u] = True q.append(u) Ans[u] = v print("Yes") print("\n".join(map(str, Ans[2:])))
from collections import deque n,m=map(int,input().split()) data=[[] for i in range(n+1)] for i in range(m): a,b=map(int,input().split()) data[a].append(b) data[b].append(a) que=deque() que.append(1) cnt=[0]*(n+1) while que: h=que.popleft() for u in data[h]: if cnt[u]!=0: continue cnt[u]=h que.append(u) print('Yes') for i in range(2,n+1): print(cnt[i])
1
20,628,104,330,890
null
145
145
s = input() s = s.replace("hi", "") if s: print("No") else: print("Yes")
n=int(input()) for i in range(n,10**6): for j in range(2,int(i**0.5)+1): if i%j==0: break else: print(i) break
0
null
79,359,216,773,312
199
250
S = input() flag = 0 for i in range(0, len(S), 1): if S[i] != S[len(S)-1-i]: flag = 1 for i in range(0, len(S)//2, 1): if S[i] != S[len(S)//2-1-i]: flag = 1 if flag == 0: print("Yes") else: print("No")
def main(): s = input() n = len(s) for i in range(n//2): if s[i] != s[n-1-i]: print("No") return s1 = s[:(n-1)//2] s2 = s[(n+3)//2-1:] n1 = len(s1) for i in range(n//4): if s1[i] != s[n1-1-i]: print("No") return if s2[i] != s[n1-1-i]: print("No") return print("Yes") if __name__ == "__main__": main()
1
45,987,046,631,048
null
190
190
S = input() l1 = [] l2 = [] total_area = 0 for i, j in enumerate(S): if j == '\\': l1.append(i) elif j == '/' and l1: i_p = l1.pop() v = i -i_p total_area += v while l2 and l2[-1][0] > i_p: v += l2.pop()[1] l2.append([i_p, v]) ans = [str(len(l2))] + [str(k[1]) for k in l2] print(total_area) print(' '.join(ans))
def main(): SS = 0 s1 = [] s2 = [] l = raw_input() for b in range(len(l)): c = l[b] if c == '\\': s1.append(b) elif c == "/": if not len(s1) == 0: a = s1.pop() s = b-a SS += s while not len(s2) == 0: sigma,alpha,beta = s2.pop() if alpha>a and beta<b: s = s + sigma else: s2.append([sigma,alpha,beta]) break s2.append([s,a,b]) print SS print len(s2), for item in s2[:-1]: print item[0], if not len(s2) == 0: print s2[-1][0] if __name__ == "__main__": main()
1
59,640,596,498
null
21
21
from math import log2 n,x,m = map(int, input().split()) logn = int(log2(n))+1 db = [[0]*m for _ in range(logn)] dbs = [[0]*m for _ in range(logn)] for i in range(m): db[0][i] = (i**2)%m dbs[0][i] = (i**2)%m for i in range(logn-1): for j in range(m): db[i+1][j] = db[i][db[i][j]] dbs[i+1][j] = dbs[i][db[i][j]] + dbs[i][j] ans = x now = x for i in range(logn): if (n-1)&(1<<i) > 0: ans += dbs[i][now] now = db[i][now] print(ans)
import sys import math def MI(): return map(int,sys.stdin.readline().rstrip().split()) N,X,M = MI() if M == 1: print(0) exit() flag = [-1]*M Z = [X] flag[X] = 1 r = X for i in range(2,M+2): r = r ** 2 r %= M if flag[r] != -1: a,b = flag[r],i # [a,b) = 循環節 break else: flag[r] = i Z.append(r) z = len(Z) ans = 0 for i in range(a-1): ans += Z[i] n = N-a+1 q = n//(b-a) r = n % (b-a) for i in range(a-1,a+r-1): ans += (q+1)*Z[i] for i in range(a+r-1,b-1): ans += q*Z[i] print(ans)
1
2,858,312,179,712
null
75
75
x,y,a,b,c = map(int,input().split()) p = list(map(int,input().split())) q = list(map(int,input().split())) r = list(map(int,input().split())) p.sort() q.sort() r.sort(reverse=True) ppick = p[-x:] qpick = q[-y:] pi = 0 qi = 0 for i in range(len(r)): if pi >= x: while True: if qi < y and i < c and r[i] > qpick[qi]: qpick[qi] = r[i] qi += 1 i += 1 else: break elif qi >= y: while True: if pi < x and i < c and r[i] > ppick[pi]: ppick[pi] = r[i] pi += 1 i += 1 else: break elif ppick[pi] >= qpick[qi] and qpick[qi] < r[i]: qpick[qi] = r[i] qi += 1 continue elif ppick[pi] < qpick[qi] and ppick[pi] < r[i]: ppick[pi] = r[i] pi += 1 continue break print(sum(ppick) + sum(qpick))
X, Y, A, B, C = [int(_) for _ in input().split()] P = [int(_) * 3 for _ in input().split()] Q = [int(_) * 3 + 1 for _ in input().split()] R = [int(_) * 3 + 2 for _ in input().split()] S = sorted(P + Q + R) cnt = [0, 0, 0] ans = [0, 0, 0] limit = [X, Y, 10**10] while S: s = S.pop() q, r = divmod(s, 3) if cnt[r] >= limit[r]: continue cnt[r] += 1 ans[r] += q if sum(cnt) == X + Y: print(sum(ans)) exit()
1
45,006,801,930,520
null
188
188
d=input().split() s={'N':"152304",'W':"215043",'E':"310542",'S':"402351"} for o in input(): d=[d[int(i)]for i in s[o]] print(d[0])
tmp=input().split() m=int(tmp[0]) n=int(tmp[1]) while(m!=n): if(m>n): m=m-n else: n=n-m print(m)
0
null
119,386,010,690
33
11
m=[] for i in range(10):m.append(int(input())) m.sort(reverse=True) for i in range(3):print(m[i])
mounts =[int(input()) for i in range(10)] mounts.sort(reverse = True) for i in range(3): print(mounts[i])
1
20,096,128
null
2
2
# 配るDP、もらうDP n, k = map(int, input().split()) mod = 998244353 kukan = [] for _ in range(k): # 区間の問題は扱いやすいように[ ) の形に直せるなら直す l, r = map(int, input().split()) l -= 1 kukan.append([l, r]) dp = [0 for i in range(n)] dp[0] = 1 # 区間のL, Rは数字が大きいため、その差一つ一つを考えると時間がない! # それゆえにL, Rの端を考えればいいようにするためにそこまでの累和を考える ruiseki = [0 for i in range(n + 1)] ruiseki[1] = 1 for i in range(1, n): for l, r in kukan: l = i - l r = i - r l, r = r, l # print(l, r) if r < 0: continue elif l >= 0: dp[i] += (ruiseki[r] - ruiseki[l]) % mod else: dp[i] += (ruiseki[r]) % mod ruiseki[i + 1] = (ruiseki[i] + dp[i]) # print(ruiseki, dp) print(dp[-1] % mod)
n, k = map(int, input().split()); m = 998244353; a = [] for i in range(k): a.append(list(map(int, input().split()))) b = [0]*n; b.append(1); c = [0]*n; c.append(1) for i in range(1, n): d = 0 for j in range(k): d = (d+c[n+i-a[j][0]]-c[n+i-a[j][1]-1])%m b.append(d); c.append(c[-1]+d) print(b[-1]%m)
1
2,684,981,054,300
null
74
74
while True: c = 0 n, x= map(int, input().split()) if n == 0 and x == 0: break for i in range(1, n + 1): for j in range(1, n + 1 ): if j <= i: continue for k in range(1, n + 1): if k <= j: continue if i != j and i != k and j != k and i + j + k == x: c += 1 print(c)
from itertools import combinations while True: n,m=map(int,input().split()) if n==m==0: break print(sum(1 for p in combinations(range(1,n+1),3) if sum(p)==m))
1
1,270,786,359,740
null
58
58
N = int(input()) A = list(map(int,input().split())) cums = [0] for a in A: cums.append(cums[-1] + a) MOD = 10**9+7 ans = 0 for i in range(N-1): ans += A[i] * (cums[-1] - cums[i+1]) ans %= MOD print(ans)
n = int(input()) num_list = input().split() mod_value = 10**9 + 7 sum_all = 0 sum_int = 0 for index in range(len(num_list) - 1): sum_int += int(num_list[index]) sum_all += sum_int * int(num_list[index + 1]) if sum_all > mod_value: sum_all %= mod_value print(sum_all)
1
3,874,476,306,340
null
83
83
while True: n = input() if n == "0": break ans = sum([int(x) for x in n]) print(ans)
N = int(input()) A = list(map(int, input().split())) cnt = [0] * (100001) ans = sum(A) for a in A: cnt[a] += 1 Q = int(input()) for _ in range(Q): B, C = map(int, input().split()) cnt[C] += cnt[B] ans += cnt[B] * (C-B) cnt[B] = 0 print(ans)
0
null
6,841,940,554,400
62
122
import math A, B = map(int, input().split()) arange = set(range(math.ceil(A*100/8), math.ceil((A+1)*100/8))) brange = set(range(math.ceil(B*100/10), math.ceil((B+1)*100/10))) ans_range = arange & brange if len(ans_range) == 0: print(-1) else: print(min(ans_range))
# coding: utf-8 # Your code here! n = int(input()) sum = 100000 for i in range(n): sum += sum * 0.05 if sum % 1000 > 0: sum -= sum % 1000 sum += 1000 print(int(sum))
0
null
28,247,814,958,140
203
6
from collections import deque n, m = map(int,input().split()) graph = [[] for _ in range(n+1)] for i in range(m): a,b = map(int, input().split()) graph[a].append(b) graph[b].append(a) # dist = [-1]*(n+1) # dist[0] = 0 # dist[1] = 0 mark = [-1]*(n+1) mark[0] - 0 mark[1] = 0 d = deque() d.append(1) while d: v = d.popleft() for i in graph[v]: if mark[i] != -1: # if dist[i] != -1: continue mark[i] = v # dist[i] = dist[v] + 1 d.append(i) if '-1' in mark: print('No') else: print('Yes') print(*mark[2:], sep='\n')
import math def kock(n,p1x,p1y,p2x,p2y): if(n==0): return sx = (2*p1x+p2x)/3.0 sy = (2*p1y+p2y)/3.0 tx = (p1x+2*p2x)/3.0 ty = (p1y+2*p2y)/3.0 ux = (tx-sx)*math.cos(math.radians(60)) - (ty-sy)*math.sin(math.radians(60)) + sx uy = (tx-sx)*math.sin(math.radians(60)) + (ty-sy)*math.cos(math.radians(60)) + sy kock(n-1,p1x,p1y,sx,sy) print(sx,sy) kock(n-1,sx,sy,ux,uy) print(ux,uy) kock(n-1,ux,uy,tx,ty) print(tx,ty) kock(n-1,tx,ty,p2x,p2y) n = int(input()) print(0,0) kock(n,0,0,100,0) print(100,0)
0
null
10,283,296,425,052
145
27
import itertools from collections import deque from sys import stdin input = stdin.readline def main(): H, W = list(map(int, input().split())) M = [input()[:-1] for _ in range(H)] def bfs(start): dist = [[float('inf')]*W for _ in range(H)] dist[start[0]][start[1]] = 0 q = deque([start]) max_ = 0 while len(q): now_h, now_w = q.popleft() if M[now_h][now_w] == '#': return for next_h, next_w in ((now_h+1, now_w), (now_h-1, now_w), (now_h, now_w-1), (now_h, now_w+1)): if not(0 <= next_h < H) or not(0 <= next_w < W) or \ (dist[next_h][next_w] != float('inf')) or \ M[next_h][next_w] == '#': continue # temp = dist[now_h][now_w] + 1 # dist[next_h][next_w] = temp # if max_ < temp: # max_ = temp dist[next_h][next_w] = dist[now_h][now_w] + 1 max_ = max(max_, dist[next_h][next_w]) q.append((next_h, next_w)) return max_ max_ = 0 for h in range(H): for w in range(W): if M[h][w] == '.': max_ = max(bfs((h, w)), max_) print(max_) if(__name__ == '__main__'): main()
n=int(input()) d=list(map(int,input().split())) if d[0] != 0: print(0) exit() d.sort() if d[1] == 0: print(0) exit() cnt = 1 pre = 1 ans =1 i = 1 mod = 998244353 while i < n: if d[i]-1 != d[i-1]: ans = 0 while i!=n-1 and d[i+1] == d[i]: i+=1 cnt+=1 ans *= pow(pre,cnt,mod) ans %= mod pre =cnt cnt = 1 i+=1 print(ans)
0
null
124,406,466,549,352
241
284
from collections import deque N = int(input()) A = [[] for i in range(N)] B = [] for i in range(N-1): a = list(map(int, input().split())) A[a[0]-1].append([a[1]-1, 0]) A[a[1]-1].append([a[0]-1, 1]) B.append(a) K = 0 D = {} C = [0 for i in range(N)] de = deque([[0, -1]]) while len(de): n = de.pop() C[n[0]] = 1 color = 1 for a in A[n[0]]: if C[a[0]] == 1: continue if color == n[1]: color += 1 if a[1] == 0: D[str(n[0])+","+str(a[0])] = color else: D[str(a[0])+","+str(n[0])] = color de.append([a[0], color]) K = max(K, color) color += 1 print(K) for b in B: print(D[str(b[0]-1)+","+str(b[1]-1)])
#グラフ構造DFSを使う import sys sys.setrecursionlimit(500000) N = int(input()) ans = [-1] * (N-1) g = [[] for _ in range(N)] for i in range(N-1): a, b = map(int, input().split()) g[a-1].append((b-1, i)) g[b-1].append((a-1, i)) def bfs(v, c, p): n_c = 1 for i in range(len(g[v])): to = g[v][i][0] ID = g[v][i][1] if to == p: continue if n_c == c: n_c += 1 ans[ID] = n_c bfs(to, n_c, v) n_c += 1 bfs(0, 0, -1) print(max(ans)) for i in range(N-1): print(ans[i])
1
136,074,497,768,496
null
272
272
m1,_ = input().split() m2,_ = input().split() ans = 0 if m1 != m2: ans = 1 print(ans)
m,d = map(int,input().split()) m2,d2 = map(int,input().split()) print(1 if m != m2 else 0)
1
124,457,550,633,020
null
264
264
n = int(input()) if n%2 ==0: cnt = n/2 - 1 elif n%2 !=0: cnt = n//2 print(int(cnt))
n=int(input()) if n%2==0: print(int((n/2)-1)) else: print(int((n-1)/2))
1
153,488,567,357,440
null
283
283
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def main(): N, K = map(int, input().split()) ans = N % K ans = min(ans, abs(ans - K)) print(ans) if __name__ == '__main__': main()
N,K = map(int,input().split()) if N % K >= abs(N % K - K): print(abs(N % K - K)) else: print(N % K)
1
39,054,098,180,810
null
180
180
score = list(map(int,input().split())) answer = 0 if score[3] - score[0] <= 0: answer += score[3] else: answer += score[0] if score[3] - score[0] - score[1] > 0: answer -= score[3] - score[0] - score[1] print(answer)
# B - Easy Linear Programming A,B,C,K = map(int,input().split()) while True: ans = 0 ans += min(A,K) K -= min(A,K) if K<=0: break K -= B if K<=0: break ans -= K break print(ans)
1
21,789,087,009,240
null
148
148
S = input() l_s = len(S) cnt = 0 for i in range(0,l_s//2): if S[i] != S[-i-1]: cnt += 1 print(cnt)
def func(S): T = S[::-1] ans = sum(1 for s, t in zip (S, T) if s != t) // 2 return ans if __name__ == "__main__": S = input() print(func(S))
1
119,800,808,767,222
null
261
261
n,k = map(int, input().split()) num = [] for i in range(k): d = int(input()) num += list(map(int, input().split())) Q = list(set(num)) print(n-len(Q))
#!usr/bin/env python3 def main(): while True: numbers = input() if int(numbers) == 0: break res = 0 for i in numbers: res += int(i) print(res) if __name__ == '__main__': main()
0
null
13,010,254,099,360
154
62
import math def kochCurve(d, p1, p2): if d <= 0: return s = [(2.0*p1[0]+1.0*p2[0])/3.0, (2.0*p1[1]+1.0*p2[1])/3.0] t = [(1.0*p1[0]+2.0*p2[0])/3.0, (1.0*p1[1]+2.0*p2[1])/3.0] u = [(t[0]-s[0])*math.cos(math.radians(60))-(t[1]-s[1])*math.sin(math.radians(60))+s[0], (t[0]-s[0])*math.sin(math.radians(60))+(t[1]-s[1])*math.cos(math.radians(60))+s[1]] kochCurve(d-1, p1, s) print(s[0], s[1]) kochCurve(d-1, s, u) print(u[0], u[1]) kochCurve(d-1, u, t) print(t[0], t[1]) kochCurve(d-1, t, p2) n = int(input()) s = [0.00000000, 0.00000000] e = [100.00000000, 0.00000000] print(s[0],s[1]) if n != 0: kochCurve(n,s,e) print(e[0],e[1])
import math a, b, x = map(int, input().split(' ')) x = x / a if x > a * b / 2: print(math.atan2((a * b - x) * 2, a ** 2) * 180 / math.pi) else: print(math.atan2(b ** 2, x * 2) * 180 / math.pi)
0
null
81,568,778,768,932
27
289
n = int(input()) a_list = list(map(int, input().split())) sum_l = sum(a_list) ans = 0 for i in range(n-1): sum_l -= a_list[i] ans += sum_l * a_list[i] print(ans % 1000000007)
def resolve(): x, y, z = list(map(int, input().split())) print(f'{z} {x} {y}') resolve()
0
null
20,860,210,822,288
83
178
a,b = (input().split()) print(int(a)*int(b))
A, B = input().split() A = int(A) B = round(float(B) * 100) ans = (A * B) // 100 print(int(ans))
1
15,920,936,518,358
null
133
133
N = int(input()) C=[[0]*10 for _ in range(10)] for n in range(1,N+1): n=str(n) n_s=int(n[0]) n_e=int(n[-1]) C[n_s][n_e]+=1 ans=0 for c_1 in range(10): for c_2 in range(10): ans += C[c_1][c_2]*C[c_2][c_1] print(ans)
def main(): N = int(input()) d = dict() for i in range(1, N+1): u = int(str(i)[0]) v = int(str(i)[-1]) d[(u, v)] = d.get((u, v), 0) + 1 ans = 0 for u, v in d: if (v, u) in d: ans += d[(u, v)] * d[(v, u)] return ans if __name__ == '__main__': print(main())
1
86,431,882,388,790
null
234
234
def main(): n = int(input()) a = list(map(int, input().split())) a.sort() ans = 0 sieve = [False for _ in range(1000001)] for i in range(n): if sieve[a[i]]: continue for j in range(a[i], 1000001, a[i]): sieve[j] = True if i > 0: if a[i] == a[i-1]: continue if i < n-1: if a[i] == a[i+1]: continue ans += 1 print(ans) if __name__ == '__main__': main()
from collections import defaultdict as d n=int(input()) a=list(map(int,input().split())) p=d(int) l=0 for i in a: p[i]+=1 l+=i for i in range(int(input())): b,c=map(int,input().split()) l+=p[b]*(c-b) p[c]+=p[b] p[b]=0 print(l)
0
null
13,272,614,309,280
129
122
[a, b, c] = [int(number) for number in input().split()]; count = 0; for i in range(a, b + 1): if (c % i == 0): count += 1; print(count);
#!/usr/bin/env python # coding: utf-8 # In[5]: H,N = map(int, input().split()) A = []; B = [] for _ in range(N): a,b = map(int, input().split()) A.append(a) B.append(b) # In[12]: a_max = max(A) dp = [0]*(H+a_max) for i in range(H+a_max): dp[i] = min(dp[i-a] + b for a,b in zip(A,B)) print(min(dp[H-1:])) # In[ ]:
0
null
40,793,858,740,430
44
229
d=list(map(int,input().split())) c=list(input()) class dice(object): def __init__(self, d): self.d = d def roll(self,com): a1,a2,a3,a4,a5,a6=self.d if com=="E": self.d = [a4,a2,a1,a6,a5,a3] elif com=="W": self.d = [a3,a2,a6,a1,a5,a4] elif com=="S": self.d = [a5,a1,a3,a4,a6,a2] elif com=="N": self.d = [a2,a6,a3,a4,a1,a5] dice1=dice(d) for com in c: dice1.roll(com) print(dice1.d[0])
d1=[0 for i in range(6)] d1[:]=(int(x) for x in input().split()) t1=[0 for i in range(6)] order=input() for i in range(len(order)): if order[i]=='N': t1[0]=d1[1] t1[1]=d1[5] t1[2]=d1[2] t1[3]=d1[3] t1[4]=d1[0] t1[5]=d1[4] if order[i]=='S': t1[0]=d1[4] t1[1]=d1[0] t1[2]=d1[2] t1[3]=d1[3] t1[4]=d1[5] t1[5]=d1[1] if order[i]=='E': t1[0]=d1[3] t1[1]=d1[1] t1[2]=d1[0] t1[3]=d1[5] t1[4]=d1[4] t1[5]=d1[2] if order[i]=='W': t1[0]=d1[2] t1[1]=d1[1] t1[2]=d1[5] t1[3]=d1[0] t1[4]=d1[4] t1[5]=d1[3] d1=list(t1) print(d1[0])
1
239,589,750,452
null
33
33
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: print('Yes' if b else 'No') YESNO=lambda b: print('YES' if b else 'NO') def main(): N,M=map(int,input().split()) c=list(map(int,input().split())) dp=[[INF]*10**6 for _ in range(M+1)] dp[0][0]=0 ans=INF for i in range(M): for money in range(N+1): dp[i+1][money]=min(dp[i+1][money],dp[i][money]) if money-c[i]>=0: dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1) print(dp[M][N]) if __name__ == '__main__': main()
h,n=map(int,input().split()) ab=[[] for i in range(n)] for i in range(n): ab[i]=list(map(int,input().split())) dp=[100000000 for i in range(h+1)] dp[0]=0 for hi in range(h): for i in range(n): damage=min(h,hi+ab[i][0]) dp[damage] = min(dp[damage],dp[hi]+ab[i][1]) #print(damage,dp[damage],dp[hi]+ab[i][1]) print(dp[h])
0
null
40,881,478,330,228
28
229
s = input() t = input() ans = 0 for i in range(len(s)-len(t)+1): tm = 0 for j in range(len(t)): if s[i+j] == t[j]: tm += 1 ans = max(tm,ans) print(len(t)-ans)
N,K=map(int,input().split()) A=[int(x)-1 for x in input().split()] seen={0} town=0 while K>0: town=A[town] K-=1 if town in seen: break seen.add(town) start=town i=0 while K>0: town=A[town] i+=1 K-=1 if town is start: break K=K%i if i>0 else 0 while K>0: town=A[town] i+=1 K-=1 print(town+1)
0
null
13,213,875,270,248
82
150
N,K = map(int,input().split()) A = [int(a) for a in input().split()] n = 0 for i in range(K,N): if A[i] > A[n] : print("Yes") else: print("No") n+=1
#!/usr/bin/env python3 #ABC146 F import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n,m = LI() s = input() i = 0 cnt = 0 M = 0 while i < n+1: if s[i] == '1': cnt += 1 M = max(M,cnt) else: cnt = 0 i += 1 if M >= m: print(-1) quit() lst = [] now = n while now > 0: if now - m <= 0: lst.append(now) now -= m else: for j in range(1,m+1)[::-1]: if s[now-j] == '0': lst.append(j) now -= j break print(*lst[::-1])
0
null
72,793,426,643,300
102
274
a = int(input()) res = 0 if a%2 ==0: res = int(a/2) else: a +=1 res = int(a/2) print(res)
num = map(int, raw_input().split()) flg=1 while flg==1: flg=0 for i in range(2): if num[i]>num[i+1]: box = num[i] num[i]=num[i+1] num[i+1]=box flg=1 print "%d %d %d" % (num[0],num[1],num[2])
0
null
29,675,467,120,432
206
40
#!/usr/bin python3 # -*- coding: utf-8 -*- def pc(x): return format(x, 'b').count('1') N = int(input()) X = input() Xn = int(X,2) p = pc(Xn) X = list(X) Xp = Xn%(p+1) if p==1: Xm = 0 else: Xm = Xn%(p-1) def f(i): if p==1 and X[i]=='1': #Xi == 0 > POPcount ==0 return 0 else: if X[i]=='1': # p->p-1 ret = Xm - pow(2, N-1-i, p-1) ret %= p-1 else: # p->p+1 ret = Xp + pow(2, N-1-i, p+1) ret %= p+1 cnt = 1 while ret > 0: ret %= pc(ret) cnt += 1 return cnt def main(): for i in range(N): ret = f(i) print(ret) if __name__ == '__main__': main()
h = int(input()) w = int(input()) n = int(input()) a = 0 b = 0 c = 0 d = 0 for i in range(h): a += w b += 1 if a >= n: break for i in range(w): c += h d += 1 if c >= n: break if b > d: print(d) else: print(b)
0
null
48,316,408,442,410
107
236
n = int(input()) s = input() if n%2==1: print("No") else: s1 = "" s2 = "" for i in range(0, n//2): s1+=s[i] s2+=s[n//2 + i] if(s1 == s2): print("Yes") else: print("No")
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") INF = 10**18 import bisect import statistics mod = 10**9+7 # mod = 998244353 N = int(input()) S = input() if N % 2 == 0: if S[:N//2] == S[N//2:]: print("Yes") else: print("No") else: print("No")
1
146,563,071,278,052
null
279
279
#!/usr/bin/env python # -*- coding: utf-8 -*- # # FileName: D_fix # CreatedDate: 2020-08-30 14:54:11 +0900 # LastModified: 2020-08-30 15:07:52 +0900 # import os import sys # import numpy as np # import pandas as pd def main(): H = int(input()) mul = 0 while H != 1: mul += 1 H //= 2 print(2**(mul+1)-1) if __name__ == "__main__": main()
h = [int(input())] a = 1 while(True): if h[0] < 1: break h = list(map(lambda x: x / 2, h)) a = a * 2 print(a - 1)
1
80,046,357,618,144
null
228
228
(h,n),*t=[list(map(int,o.split()))for o in open(0)] d=[0]*10**8 for i in range(h):d[i+1]=min(b+d[i-a+1]for a,b in t) print(d[h])
from collections import deque n,p=map(int ,input().split()) que=deque([]) for i in range(n): name,time=input().split() time=int(time) que.append([name,time]) t=0 while len(que)>0: atop=que.popleft() spend=min(atop[1],p) atop[1]-=spend t+=spend if(atop[1]==0): print(atop[0],t) else: que.append(atop)
0
null
40,389,561,173,438
229
19
while True: count=0 n,x = map(int,input().split()) if n==x==0: break for a in range(n): for b in range(n): for c in range(n): if a<b<c and a+b+c==x-3: count+=1 print(count)
n=int(input()) nums=list(map(int,input().split())) k=0 for i in range(len(nums)-1): for j in range(len(nums)-1,i,-1): if nums[j]<nums[j-1]: nums[j],nums[j-1]=nums[j-1],nums[j] k+=1 print(*nums) print(k)
0
null
659,393,114,980
58
14
from sys import stdin h, w = [int(x) for x in stdin.readline().strip().split()] if(h == 1 or w == 1): print(1) else: print((h//2)*(w//2)+((h+1)//2)*((w+1)//2))
N = input() n = int(N[-1]) if n in [2,4,5,7,9]: print('hon') elif n == 3: print('bon') else: print('pon')
0
null
34,995,417,099,130
196
142
import sys input = sys.stdin.readline n = int(input()) robots = [tuple(map(int, input().split())) for _ in range(n)] robots.sort(key=(lambda robo: robo[0] + robo[1])) z = -float('inf') ans = 0 for x, l in robots: if z <= x - l: ans += 1 z = x + l print(ans)
n = int(input()) a = list(map(int, input().split())) A = max(a) cnt = [0]*(A+1) uq = [] for i in a: cnt[i] += 1 for i in range(A+1): if cnt[i] == 1: uq.append(i) cnt = [0]*((10**6)+1) cnt1 = 0 a = list(set(a)) # for i in a: # for j in range(2,A+1): # if i*j<=A+1: # cnt[i*j] = 1 for elem in a: for m in range(elem * 2, (10 ** 6) + 1, elem): cnt[m] = 1 for i in uq: if cnt[i] == 0: cnt1 += 1 print(cnt1)
0
null
52,503,812,153,828
237
129
def main(): X = int(input()) c = 600 k = 8 while True: if X < c: print(k) break c += 200 k -= 1 if __name__ == '__main__': main()
N=int(input()) if N>=400 and 599>=N: print('8') if N>=600 and 799>=N: print('7') if N>=800 and 999>=N: print('6') if N>=1000 and 1199>=N: print('5') if N>=1200 and 1399>=N: print('4') if N>=1400 and 1599>=N: print('3') if N>=1600 and 1799>=N: print('2') if N>=1800 and 1999>=N: print('1')
1
6,657,375,421,998
null
100
100
from math import atan, sqrt, degrees a,b,x = map(int, input().split()) ans = 0 if x <= a*a*b/2: ans = degrees(atan(a*b*b/(2*x))) else: ans = degrees(atan((2*b-2*x/(a*a))/a)) print(ans)
n = input() list = [] list = map(str, raw_input().split()) list.reverse() print " ".join(list)
0
null
82,374,181,830,458
289
53
import sys input = sys.stdin.readline def main(): n = int(input()) stick = list(map(int, input().split())) total = sum(stick) mid = total // 2 cum = 0 midi = 0 for i, block in enumerate(stick): cum += block if cum >= mid: midi = i break l1 = cum r1 = total - l1 diff1 = abs(l1 - r1) l2 = l1 - stick[midi] r2 = r1 + stick[midi] diff2 = abs(l2 - r2) print(min(diff1, diff2)) main()
import sys nums = [] for line in sys.stdin: nums.append(line) for i in range(len(nums)): input_line = nums[i].split(" ") a = int(input_line[0]) b = int(input_line[1]) if a > b: num_bigger = a num_smaller = b else: num_bigger = b num_smaller = a r = 1 #????????? while r > 0: r = num_bigger % num_smaller num_bigger = num_smaller num_smaller = r max_common_div = num_bigger min_common_mpl = int((a * b)/max_common_div) print(str(max_common_div) + " " + str(min_common_mpl))
0
null
71,025,206,539,520
276
5
row = input().split() row = [ int(i) for i in row] print(row[0] * row[1], 2 * (row[0] + row[1]))
a,b = raw_input().split(" ") x = int(a)*2+int(b)*2 y = int(a)*int(b) print "%d %d"%(y,x)
1
299,361,524,518
null
36
36
N = int(input()) result = False count = 0 for i in range(N): D1,D2 = map(int,input().split()) if D1 == D2: count += 1 else: count = 0 if count > 2: result = True break if result: print('Yes') else: print('No')
n = int(input()) ans = 0 flag = 0 for i in range(0, n): x, y = input().split() if x == y: ans = ans + 1 else: ans = 0 if ans >= 3: flag = 1 if flag == 1: print("Yes") else : print("No")
1
2,478,037,032,842
null
72
72
input() numbers = input().split() numbers.reverse() print(" ".join(numbers))
N = int(input()) S = list(input()) R = [] G = [] B = [0 for _ in range(N)] b_cnt = 0 for i in range(N): if S[i] == 'R': R.append(i) elif S[i] == 'G': G.append(i) else: B[i] = 1 b_cnt += 1 answer = 0 for r in R: for g in G: answer += b_cnt if (g-r)%2 == 0 and B[(r+g)//2] == 1: answer -= 1 if 0 <= 2*g-r < N and B[2*g-r] == 1: answer -= 1 if 0 <= 2*r-g < N and B[2*r-g] == 1: answer -= 1 print(answer)
0
null
18,655,516,993,088
53
175
h, w, n = (int(input()) for i in range(3)) print(-(-n // max(h, w)))
l = [int(i) for i in input().split()] a = l[0] b = l[1] c = l[2] yaku = 0 for i in range(b-a+1): if c % (i+a) == 0: yaku = yaku + 1 print(yaku)
0
null
44,768,894,348,848
236
44
n,m = map(int,input().split()) a = list(map(int,input().split())) ans = 0 for i in range(m): ans += a[i] if n < ans: print(-1) else: print(n-ans)
n,m = map(int,input().split()) a = [int(i) for i in input().split()] ans = n - sum(a) if ans < 0: ans = -1 print(ans)
1
31,991,251,597,400
null
168
168
N = int(input()) A = list(map(int, input().split())) # <- note that this has (N - 1) elements #print(A) A_0 = [x - 1 for x in A] #print(A_0) ans = [0] * N # <- represents number of immediate subordinates of each person for i in range(0, N - 1): ans[A_0[i]] += 1 for i in range(0, N): print(ans[i])
#coding: utf-8 #ALDS1_2B def pnt(s): for i in xrange(len(s)): print s[i], print n=int(raw_input()) a=map(int,raw_input().split()) cnt=0 for i in xrange(n): mini = i for j in xrange(i + 1, n): if a[j] < a[mini]: mini = j if i != mini: a[i], a[mini] = a[mini], a[i] if i!=mini: cnt+=1 pnt(a) print cnt
0
null
16,250,512,955,238
169
15
a, b =map(int, input().split()) m = a*b lst = [] for i in range(1, b+1): if m < a*i: break lst.append(a*i) for j in lst: if j%b == 0: print(j) break
import math H = int(input()) W = int(input()) N = int(input()) print(math.ceil(N/max(H,W)))
0
null
100,758,440,686,120
256
236
import math N=int(input()) a=math.ceil(N/(1.08)) if math.floor(a*1.08)==N: print(a) else: print(':(')
n,a,b=list(map(int,input().split())) #2^n-nCa-nCbを求める #冪乗を求める関数を求める #2のn乗をmで割ったあまりを求める def pow(a,n,m): if n==0: return 1 else: k=pow(a*a%m,n//2,m) if n%2==1: k=k*a%m return k #次は組み合わせを計算する #まずは前処理をする inv=[0 for i in range(200001)] finv=[0 for i in range(200001)] inv[1]=1 finv[1]=1 for i in range(2,200001): #逆元の求め方p=(p//a)*a+p%a a^(-1)=-(p//a)*(p%a)^(-1) inv[i]=(-(1000000007//i)*inv[1000000007%i])%1000000007 finv[i]=finv[i-1]*inv[i]%1000000007 #nが10^7程度であればnCk=n!*(k!)*((n-k)!)を求めればいい #nがそれより大きい時は間に合わない。ここでkが小さいことに着目すると #nCk=n*(n-1).....*(n-k+1)*(k!)^(-1)で求められることがわかる a_num=1 b_num=1 for i in range(n-a+1,n+1): a_num=i*a_num%1000000007 for i in range(n-b+1,n+1): b_num=i*b_num%1000000007 print((pow(2,n,1000000007)-1-a_num*finv[a]-b_num*finv[b])%1000000007)
0
null
96,474,116,107,890
265
214
#! /usr/bin/python3 m=100 for _ in range(int(input())): m = int(m*1.05+0.999) print(m*1000)
import math x,y = int(input()),100 for i in range(x): y = math.ceil(y*1.05) print(y*1000)
1
1,259,381,440
null
6
6
x=int(input()) if 29>x>(-40): print('No') elif x>=30: print('Yes') elif x<-40: print('No') else: print('No')
import base64 import subprocess import gzip exe_bin = b'\x1f\x8b\x08\x00<0J_\x02\xff\xddZi\x93\xb2<\xb3\xfe-\x96K\xa9SV!\xe2V\xb8\x81\xa0(\n\x82\xb2\xc8\x07\x15\xdcw\x1d\xdcQ\x7f\xfb\xcb2\xf7\xc4\x9b\x919\xcfSu\xde\xf3\xe1\xe4\xc3L\x9b\x8bt:I\xa7\xbb\xd3\xc9\xb8XD`H\xf7\xf3\x08\x04\x8a\xf1\x98\x05!\x9e\xcf\xc6\x8f\x9bt\xabbW\xd1\xebn(`S:<\xbc\xb5\xc0\xb7\xf4Z\r*p\xa1X\xcbe\xf9f\xf2\x14\xef\x95\xf4T\x9ceT\x04\xb4xG\xf5\xafU\xa1\xef\xa2\xe0\xf5\x12\xcd|I`\xf0\t\x9bK\rJ\xa5\xcev\xd5;*\xf3\xec\xdd\xdb.\xca\x16\x1cP\xf1\xddv\x91\x84~-\x97\xb2!p.\n\x82\xe2\xb8\xf4\xc2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x00' exe_bin = base64.b85decode(gzip.decompress(exe_bin)) with open("./kyomu", 'wb') as f: f.write(exe_bin) subprocess.run(["chmod +x ./kyomu"], shell=True) subprocess.run(["./kyomu"], shell=True)
1
5,767,809,243,680
null
95
95
n = int(input()) a = list(map(int, input().split())) count = {} for i in range(len(a)):#番号と身長を引く minus = (i+1) - a[i] if minus in count: count[minus] += 1 else: count[minus] = 1 total = 0 for i in range(len(a)): plus = a[i] + (i+1) if plus in count: total += count[plus] print(total)
from collections import Counter n=int(input()) a=list(map(int,input().split())) jc=[0]*n for i in range(n): jc[i]+=i+1-a[i] jcc=Counter(jc) count=0 for j in range(n): count+=jcc[a[j]+j+1] print(count)
1
26,140,149,285,448
null
157
157
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return map(fn, readline().split()) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): a, b = geta(int) print(max(0, a - 2 * b)) if __name__ == "__main__": main()
x = list(map(int,input().split())) i = 0 while (x[i] != 0): i+=1 print(i+1)
0
null
90,211,860,850,238
291
126
from itertools import groupby N = int(input()) S = input() gr = list(groupby(S)) print(len(gr))
import sys sys.setrecursionlimit(10 ** 6) INF = float("inf") MOD = 10 ** 9 + 7 def input(): return sys.stdin.readline().strip() def main(): T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) A = A1 * T1 + A2 * T2 B = B1 * T1 + B2 * T2 if A1 < B1 and A < B: print(0) return if A1 > B1 and A > B: print(0) return if A == B: print("infinity") return # T1 + T2 分後にできる差 diff = abs(A - B) if T1 * abs(A1 - B1) % diff == 0: ans = T1 * abs(A1 - B1) // diff * 2 else: ans = T1 * abs(A1 - B1) // diff * 2 + 1 print(ans) if __name__ == "__main__": main()
0
null
150,051,383,789,492
293
269
R = int(input()) print(R * 6.28318530717958623200)
import heapq X,Y,A,B,C = map(int,input().split()) qa = list(map(int,input().split())) qb = list(map(int,input().split())) r = list(map(int,input().split())) qa.sort(reverse=True) qb.sort(reverse=True) r.sort(reverse=True) qa_ans = qa[:X] qb_ans = qb[:Y] heapq.heapify(qa_ans) heapq.heapify(qb_ans) for i in range(C): r_max = r[i] qa_min = heapq.heappop(qa_ans) qb_min = heapq.heappop(qb_ans) if (r_max>qa_min) or (r_max>qb_min): if qa_min >qb_min: heapq.heappush(qa_ans,qa_min) heapq.heappush(qb_ans,r_max) else: heapq.heappush(qa_ans,r_max) heapq.heappush(qb_ans,qb_min) else: heapq.heappush(qa_ans, qa_min) heapq.heappush(qb_ans, qb_min) break print(sum(qa_ans)+sum(qb_ans))
0
null
37,969,116,130,208
167
188
import itertools n = int(input()) twn = [list(map(int, input().split())) for _ in range(n)] twnst = list(itertools.permutations(twn)) dstttl = 0 for i in twnst: for j in range(0, len(i) - 1): dstttl += (abs(i[j][0] - i[j+1][0])**2 + abs(i[j][1] - i[j+1][1])**2)**0.5 print(dstttl / len(twnst))
def dist(x0, y0, x1, y1): from math import sqrt return sqrt((x1-x0)**2 + (y1-y0)**2) from itertools import permutations N = int(input()) points = [tuple(map(int, input().split())) for _ in range(N)] #; print(points) dsum = 0 for i, j in permutations(points, 2): dsum += dist(*i, *j) print(dsum/N)
1
148,949,984,857,948
null
280
280
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") INF = 10**18 import bisect import statistics mod = 10**9+7 # mod = 998244353 N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N): for j in range(i+1,N): p = L[i]+L[j] k = bisect.bisect_left(L[j+1:], p) ans += k print(ans)
from bisect import bisect_left n = int(input()) a = list(map(int,input().split())) a.sort() ans = 0 for i in range(n-2): for j in range(i+1,n-1): ind = bisect_left(a,a[i]+a[j]) ans += ind-j-1 print(ans)
1
171,929,825,512,576
null
294
294
from collections import deque k = int(input()) # 23から232(A),233(B),234(C)が作れる # 20からは200(B),201(C)しか作れない # 29からは298(A),299(B)しか作れない queue = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) for i in range(k): x = queue.popleft() #print(x) # (A)の場合 if x % 10 != 0: queue.append(10 * x + (x % 10) - 1) # (B)の場合 queue.append(10 * x + x % 10) # (C)の場合 if x % 10 != 9: queue.append(10 * x + x % 10 + 1) print(x)
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n, m, k = map(int, input().split()) uf = UnionFind(n) friend = [set([]) for i in range(n)] for i in range(m): ai, bi = map(int, input().split()) ai -= 1; bi -= 1 uf.union(ai, bi) friend[ai].add(bi) friend[bi].add(ai) block = [set([]) for i in range(n)] for i in range(k): ci, di = map(int, input().split()) ci -= 1; di -= 1 block[ci].add(di) block[di].add(ci) for i in range(n): uf.find(i) ans = [] for i in range(n): num = uf.size(i) - len(friend[i]) - 1 for j in block[i]: if uf.find(i) == uf.find(j): num -= 1 ans.append(num) print(' '.join(map(str, ans)))
0
null
50,766,197,437,242
181
209
s_l = list(input()) t_l = list(input()) count_difference = 0 for s, t in zip(s_l, t_l): if s != t: count_difference += 1 print(count_difference)
ans=0 for i,j in zip(input(),input()): if i!=j:ans+=1 print(ans)
1
10,485,537,267,872
null
116
116