code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
n = 6 a = int(input()) b = int(input()) print(n - a - b)
N, T = map(int, input().split()) p = [] for i in range(N): A, B = map(int, input().split()) p.append([A, B]) p.sort() dp = [[0]*3005 for _ in range(3005)] ans = 0 for i in range(N): for j in range(T): dp[i+1][j] = max(dp[i+1][j], dp[i][j]) nextj = j + p[i][0] if nextj < T: dp[i+1][nextj] = max(dp[i+1][nextj], dp[i][j] + p[i][1]) now = dp[i][T-1] + p[i][1] ans = max(ans, now) print(ans)
0
null
131,437,000,016,080
254
282
N = int(input()) n = N % 10 if n == 3: ans = 'bon' elif n == 0 or n == 1 or n == 6 or n == 8: ans = 'pon' else: ans = 'hon' print(ans)
import sys N = input() array_hon = [2,4,5,7,9] array_pon = [0,1,6,8] array_bon = [3] if not ( int(N) <= 999 ): sys.exit() if int(N[-1]) in array_hon: print('hon') if int(N[-1]) in array_pon: print('pon') if int(N[-1]) in array_bon: print('bon')
1
19,255,258,122,458
null
142
142
import sys values = [] for line in sys.stdin: values.append([int(x) for x in line.split()]) digit = 0 for x, y in values: sum = x + y; digit = 0 while sum >= 1: sum //= 10 digit += 1 print(digit)
s = '' while True: try: s += input().lower() except EOFError: break for i in range(97, 123): print(chr(i)+' : '+str(s.count(chr(i))))
0
null
811,686,940,230
3
63
import math a,b,x=map(int,input().split()) if (a*a*b/2<=x): if (a*a*b==x): print(0) else: theta=math.atan((a*a*a)/(2*(a*a*b-x))) print(90.0-theta*180.0/math.pi) else: theta=math.atan(2*x/(a*b*b)) print((math.pi/2-theta)*180.0/math.pi)
# 問題: https://atcoder.jp/contests/abc144/tasks/abc144_d import math a, b, x = map(int, input().strip().split()) if a * a * b / 2 < x: res = b res -= x/(a*a) res *= 2 res /= a else: res = a * b * b res /= 2 * x res = math.atan(res) res = math.degrees(res) print(res)
1
163,233,610,392,522
null
289
289
n = int(input()) S = list(map(int,input().split(' '))) q = int(input()) T = list(map(int,input().split(' '))) C = 0 for i in S: if i in T: C += 1 T.remove(i) print(C)
n = input() S = [int(x) for x in raw_input().split()] q = input() T = [int(x) for x in raw_input().split()] C = 0 for i in T: for j in S: if i==j: C += 1 break print C
1
66,026,413,160
null
22
22
import sys input = sys.stdin.readline def main(): n, k = input_list() # R = グー, S = チョキ, P = パー R, S, P = input_list() t = input() tt = list(t) for i in range(n - k): if tt[i] == t[i+k]: tt[i+k] = "x" r = tt.count("r") * P s = tt.count("s") * R p = tt.count("p") * S print(r + s + p) def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
W,H,x,y,r = map(int, input().split()) if(x+r <= W and y+r <= H): if(x-r >= 0 and y-r >= 0) : print("Yes") else : print("No") else : print("No")
0
null
53,542,781,074,530
251
41
S = list(input()) #print(set(S)) setS = set(S) if len(setS) == 2: print("Yes") else: print("No")
t=str(input()) print(t.replace("?","D"))
0
null
36,705,434,307,860
201
140
n=int(input()) s=str(input()) print(s.count("ABC"))
X = input() S = input() print(S.count("ABC"))
1
99,335,417,585,920
null
245
245
n = int(input()) a = list(map(int,input().split())) m = max(a) + 1 li = [0]*m for x in a: li[x] += 1 ans = 0 for i in range(1,m): if li[i]: if li[i]==1: ans += 1 for j in range(i,m,i): li[j] = 0 print(ans)
n=int(input("")) aa=input("").split(" ") lista=[] for i in range(n): lista+=[int(aa[i])] lista.sort() listtf=[] s=0 for i in range(lista[n-1]): listtf+=[True] for i in range(n): if(listtf[lista[i]-1]): if(i<n-1 and lista[i]==lista[i+1]): s-=1 s+=1 t=1 while(t*lista[i]<=lista[n-1]): listtf[lista[i]*t-1]=False t+=1 print(s)
1
14,457,659,166,680
null
129
129
# -*- coding: utf-8 -*- # A import sys from collections import defaultdict, deque from heapq import heappush, heappop import math import bisect input = sys.stdin.readline # 再起回数上限変更 # sys.setrecursionlimit(1000000) N = int(input()) if N % 2 == 0: print(0.5) else: a = N//2 b = N - a print(b/N)
N = int(input()) max = 10**6 sum = 0 for i in range(1,N+1): if i % 3 != 0 and i % 5 != 0: sum = sum + i print(sum)
0
null
106,310,647,118,752
297
173
N,K=input().split() N=int(N) K=int(K) a=[] a=[int(a) for a in input().split()] a.sort() print(sum(a[0:K]))
S,T=map(str,input().split()) A,B=map(int,input().split()) U=str(input()) if S==U: print(str(A-1)+" "+str(B)) else: print(str(A)+" "+str(B-1))
0
null
42,012,505,098,212
120
220
from collections import deque n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a_stack=deque([]) now=0 mn=0 j=0 for i in a: mn+=i if mn>k: mn-=i break else: now+=1 a_stack.append(i) for i in b: mn+=i if mn>k: mn-=i break else: now+=1 j+=1 if j==m: print(now) exit() ans=now while a_stack: if j>=m: break else: q=a_stack.pop() mn-=q now-=1 while k-mn>0: mn+=b[j] now+=1 if k-mn<0: now-=1 mn-=b[j] break j+=1 if j==m: break ans=max(now,ans) print(ans)
S=int(input()) ans=[0]*(S+1) MOD=10**9+7 if S<=2: print(0) exit(0) elif S==3: print(1) exit(0) ans[3]=1 for i in range(4,S+1): ans[i]=ans[i-1]+ans[i-3] print(ans[i]%MOD)
0
null
7,045,182,203,360
117
79
import sys from collections import deque n = int(input()) q = deque() for i in range(n): c = sys.stdin.readline()[:-1] if c[0] == 'i': q.appendleft(c[7:]) elif c[6] == ' ': try: q.remove(c[7:]) except: pass elif c[6] == 'F': q.popleft() else: q.pop() print(*q)
from collections import deque def process_command(dll, commands): for cmd in commands: # print(cmd) if cmd.startswith('insert') or cmd.startswith('delete '): t = cmd.split(' ') cmd = t[0] num_str = t[1] if cmd == 'insert': dll.appendleft(int(num_str)) elif cmd == 'delete': if int(num_str) in dll: temp = [] result = dll.popleft() while result != int(num_str): temp.append(result) result = dll.popleft() temp = temp[::-1] dll.extendleft(temp) elif cmd == 'deleteFirst': dll.popleft() elif cmd == 'deleteLast': dll.pop() # print(dll) # print('=' * 64) if __name__ == '__main__': # ??????????????\??? commands = [] num = int(input()) for i in range(num): commands.append(input()) # ?????? dll = deque() process_command(dll, commands) # ??????????????? # dll.reverse() print('{0}'.format(' '.join(map(str, dll))))
1
50,948,573,372
null
20
20
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, T = map(str, input().split()) ans = "" for i in range(N): ans += S[i] + T[i] print(ans)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s,t = input().split() print(''.join([s[i] + t[i] for i in range(n)]))
1
112,161,465,026,082
null
255
255
n = int(input()) li = list(map(int, input().split())) cnt = 0 flag = True while flag: flag = False for i in range(n-1,0,-1): if li[i] < li[i-1]: li[i], li[i-1] = li[i-1], li[i] flag = True cnt +=1 print(*li) print(cnt)
a=int(input()) print(a*6.283185307178)
0
null
15,845,032,304,630
14
167
n = int(input()) cnt = 0 for i in range(1, n//2+1): if i != n - i and n - i > 0: cnt += 1 print(cnt)
import sys def main(): _ = int(input()) imps = sys.stdin.readlines() db = {} for imp in imps: c, k = imp.split(' ') if c == 'insert': db[k] = 0 elif k in db: print('yes') else: print('no') main()
0
null
76,384,126,693,292
283
23
def main(): n, k = map(int, input().split()) a = 1 b = 0 while True: a *= k if a > n: break b += 1 ans = b + 1 print(ans) if __name__ == "__main__": main()
def main(): N, K = map(int, input().split()) ans = 0 while N > 0: N //= K ans += 1 print(ans) if __name__ == '__main__': main()
1
64,466,761,764,700
null
212
212
import sys # input = sys.stdin.readline def main(): A,B = map(int,input().split()) if A//10 +B//10 >0: print(-1) else: print(A*B) if __name__ == "__main__": main()
def judge99(x): if x <= 9: return True else: return False a, b = map(int,input().split()) if judge99(a) and judge99(b): print(a*b) else: print(-1)
1
158,753,456,812,272
null
286
286
data = [] for i in range(10): data.append(int(raw_input())) data.sort(reverse = True) print data[0] print data[1] print data[2]
n, k = map(int, input().split()) a = list(map(int, input().split())) b = 0 for i in (a): if i >= k: b += 1 else: b += 0 print(b)
0
null
89,897,334,146,060
2
298
INPUT = list(map(int, input().split())) print(INPUT[0]*INPUT[1])
print(eval(input().replace(' ','*')))
1
15,903,087,303,290
null
133
133
print(int(input().strip('\n'))**2)
r = float(input()) re1 = 1 * 1 re = r * r print(int(re/re1))
1
145,425,519,776,404
null
278
278
import sys input = sys.stdin.readline N = int(input()) A = list(zip(list(map(int, input().split())), range(N))) A.sort(reverse=True) dp = [[0] * (N+1) for _ in range(N+1)] for i in range(1, N+1): a, k = A[i-1] dp[i][0] = dp[i-1][0] + a * abs(N-i-k) for j in range(1, i): dp[i][j] = max(dp[i-1][j] + a * abs(N-(i-j)-k), dp[i-1][j-1] + a * abs(j-1-k)) dp[i][i] = dp[i-1][i-1] + a * abs(i-1-k) print(max(dp[N]))
X, Y = map(int, input().split()) n = (2 * X - Y) // 3 m = (-X + 2 * Y) // 3 if n < 0 or m < 0 or (2 * X - Y) % 3 != 0 or (-X + 2 * Y) % 3 != 0: print(0) else: # (n+m)Cn 通り fac = [1, 1] finv = [1, 1] inv = [1, 1] MOD = 10 ** 9 + 7 for i in range(2, n + m + 1): fac.append(fac[i - 1] * i % MOD) inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD) finv.append(finv[i - 1] * inv[i] % MOD) print(fac[n+m] * (finv[n] * finv[m] % MOD) % MOD)
0
null
91,819,801,447,850
171
281
import sys def main(): for line in sys.stdin: print(int(line.strip())**3) if __name__ == "__main__": main()
import array K = int(input()) s = 0 cache = [1] * K def gcd(a, b): while b != 0: a, b = b, a % b return a for i in range(1, K+1): cache[i-1] = [1] * K for j in range(i, K+1): cache[i-1][j-1] = array.array('i', [1] * K) for k in range(j, K+1): cache[i-1][j-1][k-1] = gcd(k, gcd(j, i)) for i in range(1, K+1): for j in range(1, K+1): for k in range(1, K+1): a, b, c = sorted([i, j, k]) s += cache[a-1][b-1][c-1] print(s)
0
null
17,791,861,452,412
35
174
strN = input().rstrip() K = int(input()) maxD = len(strN) dp = [[[0]*(K+1) for j in range(2)] for i in range(maxD+1)] dp[0][0][0] = 1 for d, Nd in enumerate(strN): Nd = int(Nd) for isLtN in range(2): for numNot0 in range(K+1): for x in range(10): if not isLtN and x > Nd: continue isLtN2 = isLtN or x < Nd numNot02 = numNot0 + (x != 0) if numNot02 > K: continue dp[d+1][isLtN2][numNot02] += dp[d][isLtN][numNot0] ans = dp[-1][0][K] + dp[-1][1][K] print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from functools import lru_cache n, k = map(int, read().split()) @lru_cache() def check(n, k): if n < 10: if k == 0: return 1 if k == 1: return n return 0 a, b = divmod(n, 10) cnt = 0 if k >= 1: cnt += check(a, k - 1) * b cnt += check(a - 1, k - 1) * (9 - b) cnt += check(a, k) return cnt print(check(n, k))
1
76,045,772,895,160
null
224
224
N,X,Y =map(int,input().split()) count = [0] * (N-1) for i in range(1,N): for j in range(i+1,N+1): dist = min(j-i, abs(X-i)+1+abs(Y-j)) count[dist-1] +=1 print("\n".join(map(str,count)))
import sys # sys.setrecursionlimit(100000) from collections import deque from collections import defaultdict def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return [int(i) for i in input().split()] def main(): # 各ノードで幅優先探索を行う # 計算量(O(n^2)) n, x, y = input_int_list() g = defaultdict(list) g[x].append(y) g[y].append(x) for i in range(1, n): g[i].append(i + 1) g[i + 1].append(i) ans = [0] * (n + 1) for i in range(1, n + 1): # 幅優先探索 seen = set() dq = deque() dq.append((i, 0)) # node,depth while dq: p, d = dq.popleft() if p > i: # 整数の組(i,j) (1 <= i <= j <= N) ans[d] += 1 for q in g[p]: if q not in seen: dq.append((q, d + 1)) seen.add(q) for i in range(1, n): print(ans[i]) return if __name__ == "__main__": main()
1
44,170,405,680,050
null
187
187
N = int(input()) % 10 if N in {2,4,5,7,9}: print("hon") elif N in {0,1,6,8}: print("pon") else: print("bon")
n = int(input()) tp = 0 hp = 0 for i in range(n): tarou, hanako = map(str,input().split()) if(tarou > hanako): tp += 3 elif(tarou < hanako): hp += 3 else: tp += 1 hp += 1 print("%d %d" %(tp,hp))
0
null
10,553,248,989,348
142
67
import collections N = int(input()) UKV = [list(map(int,input().split())) for _ in range(N)] dist = [-1]*N que = collections.deque() G = [[]]*N for ukv in UKV: G[ukv[0]-1] = sorted(ukv[2:]) dist[0] = 0 que.append(1) while len(que) != 0: v = que.popleft() for nv in G[v-1]: if dist[nv-1] != -1: continue dist[nv-1] = dist[v-1] + 1 que.append(nv) for i,d in enumerate(dist): print(i+1, d)
N = int(input()) sum = 0 for i in range(1, N + 1): if not i % 3 == 0 and not i % 5 == 0: sum += i print(sum)
0
null
17,422,679,960,428
9
173
def main(): N = int(input()) def enum_divisors(n): # 約数列挙 divs = [] for i in range(1, n+1): if i*i > n: break if n % i == 0: divs.append(i) if n//i != i: # i が平方数でない divs.append(n//i) return divs ans = 0 for k in enum_divisors(N-1): if 2 <= k: ans += 1 for k in enum_divisors(N): if 2 <= k: n = N while n > 1 and n % k == 0: n //= k if n % k == 1: ans += 1 print(ans) if __name__ == '__main__': main()
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors N = int(input()) ans = len(make_divisors(N-1))-1 for i in make_divisors(N): if i == 1: continue Ni = int(N/i) while Ni % i == 0: Ni = int(Ni/i) if Ni % i == 1: ans+=1 print(ans)
1
41,234,292,001,640
null
183
183
counter=0 while True: counter+=1 x=int(input()) if x==0: break print("Case "+str(counter)+": "+str(x))
count = 1 while True: x = input().strip() if x == '0': break else: print('Case %s: %s' %(count, x)) count = count + 1
1
469,656,272,250
null
42
42
input() S = input() j = "" A ="" for i in S: if i !=j: A += i j = i print(len(A))
from decimal import Decimal X=int(input()) c =Decimal(100) C=0 while c<X: c=Decimal(c)*(Decimal(101))//Decimal(100) C+=1 print(C)
0
null
98,821,479,186,980
293
159
n = int(input()) S = [int(i) for i in input().split()] q = int(input()) T = [int(i) for i in input().split()] cnt = 0 for T in T: if T in S: cnt += 1 print(cnt)
import types _atcoder_code = """ # Python port of AtCoder Library. __version__ = '0.0.1' """ atcoder = types.ModuleType('atcoder') exec(_atcoder_code, atcoder.__dict__) _atcoder_dsu_code = """ import typing class DSU: ''' Implement (union by size) + (path compression) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0): self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a < self._n assert 0 <= b < self._n x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n if self.parent_or_size[a] < 0: return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self, a: int) -> int: assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> typing.List[typing.List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return list(filter(lambda r: r, result)) """ atcoder.dsu = types.ModuleType('atcoder.dsu') exec(_atcoder_dsu_code, atcoder.dsu.__dict__) dsu = atcoder.dsu #c # from atcoder import dsu n,m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] ds = dsu.DSU(n) for i in ab: ds.merge(i[0]-1,i[1]-1) s = ds.groups() print(len(s)-1)
0
null
1,188,424,839,888
22
70
n = int(input()) A = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) max = max(m) dp = [[0 for _ in range(max + 1)] for __ in range(n + 1)] dp[0][0] = 1#[1 for _ in range(max + 1)] for j in range(n): for k in range(max + 1): if k >= A[j] and dp[j][k - A[j]]: dp[j + 1][k] = 1 elif dp[j][k]: dp[j + 1][k] = 1 for i in range(q): if dp[n][m[i]]: print("yes") else: print("no")
n = int(input()) a = list(map(int,input().split())) m = int(input()) q = list(map(int,input().split())) cand = [] for i in range(2**n): tmp = 0 for j in range(n): if(i>>j)&1: tmp += a[j] if tmp not in cand: cand.append(tmp) for i in q: print('yes' if i in cand else 'no')
1
101,160,476,288
null
25
25
N, M, K = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) sumA = [0] sumB = [0] tmp = 0 answer = 0 st = 0 for i in range(N): tmp = tmp + A[i] sumA.append(tmp) tmp = 0 for i in range(M): tmp = tmp + B[i] sumB.append(tmp) for i in range(N, -1, -1): booktmp = 0 for j in range(st, M + 1): if sumA[i] + sumB[j] <= K: booktmp = i + j else: st = j break answer = max(answer, booktmp) if j == M: break print(answer)
import bisect N,M,K = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) time = 0 cnt = 0 C = [] SA =[0] SB =[0] for a in A: SA.append(SA[-1] + a) for b in B: SB.append(SB[-1] + b) for x in range(N+1): L = K - SA[x] if L < 0: break y_max = bisect.bisect_right(SB, L) - 1 C.append(y_max + x) print(max(C))
1
10,831,305,505,898
null
117
117
number = input().split(" ") print(int(number[0]) * int(number[1]))
m,k=input().split(" ") result=int(m)*int(k) print("%d"%result)
1
15,809,968,251,872
null
133
133
""" 桁DPで解ける dp[i][j][k][l] => i桁目まで見る。i桁目がjであるような数字の数。kは0でない数の個数のメモ。lは未満フラグ。 """ N = input() K = int(input()) dp = [[[[0]*(2) for _ in range(5)]for _ in range(10)]for _ in range(len(N))] #初期化 x = int(N[0]) for i in range(x+1): if i == 0: dp[0][i][0][1] += 1 else: if i<x: flag = 1 else: flag = 0 dp[0][i][1][flag] += 1 for i in range(len(N)-1): x = int(N[i+1]) for j in range(10): for k in range(4): for l in range(2): if l: r = 10 else: r = x+1 for m in range(r): if l==0 and m==x: flag = 0 else: flag = 1 if m == 0: cnt = k else: cnt = k+1 dp[i+1][m][cnt][flag] += dp[i][j][k][l] ans = 0 for j in range(10): ans += sum(dp[-1][j][K]) print(ans)
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K = map(int, read().split()) X = list(map(int, str(N))) L = len(X) dp1 = [[0] * (K + 1) for _ in range(L + 1)] dp2 = [[0] * (K + 1) for _ in range(L + 1)] dp1[0][0] = 1 for i, x in enumerate(X): for j in range(K + 1): if x != 0: if j > 0: dp1[i + 1][j] = dp1[i][j - 1] else: dp1[i + 1][j] = dp1[i][j] if j > 0: dp2[i + 1][j] = dp2[i][j - 1] * 9 if x != 0: dp2[i + 1][j] += dp1[i][j - 1] * (x - 1) dp2[i + 1][j] += dp2[i][j] if x != 0: dp2[i + 1][j] += dp1[i][j] print(dp1[L][K] + dp2[L][K]) return if __name__ == '__main__': main()
1
76,252,978,583,418
null
224
224
import math a,b,C=map(float,input().split()) S=a*b*math.sin(math.pi*C/180)/2 c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.pi*C/180)) L=a+b+c h=2*S/a print(f'{S:.5f}') print(f'{L:.5f}') print(f'{h:.5f}')
import math def main(): a, b, ang_ab = [float(x) for x in input().split()] rad_ab = (ang_ab/180)*math.pi c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad_ab)) h = b*math.sin(rad_ab) s = (a*h)/2 l = a+b+c print("{:f} {:f} {:f}".format(s, l, h)) if __name__ == '__main__': main()
1
168,524,721,472
null
30
30
n, m = map(int, input().split()) c = list(map(int, input().split())) dp = [float("inf")] * (n+1) dp[0] = 0 for i in range(1, n + 1): for j in range(m): if i >= c[j]: dp[i] = min(dp[i], dp[i-c[j]]+1) print(dp[n])
D=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split())) for i in range(D)] test=[int(input()) for i in range(D)] lastday=[0 for j in range(26)] points=[0 for i in range(D)] lastday=[lastday[i]+1 for i in range(26)] lastday[test[0]-1]=0 minus=sum([x*y for (x,y) in zip(c,lastday)]) points[0]=s[0][test[0]-1]-minus for i in range(1,D): lastday=[lastday[i]+1 for i in range(26)] lastday[test[i]-1]=0 minus=sum([x*y for (x,y) in zip(c,lastday)]) points[i]=points[i-1]+s[i][test[i]-1]-minus for ps in points: print(ps)
0
null
5,033,500,402,952
28
114
n, m, k = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] aa = [0] bb = [0] for s in range(n): aa.append(aa[s] + a[s]) for s in range(m): bb.append(bb[s] + b[s]) ans = 0 j = m for i in range(n+1): if aa[i] > k: break while bb[j] > k - aa[i]: j -= 1 ans = max(ans, i+j) print(ans)
N,M,K = map(int,input().split()) a=list(map(int, input().split())) b=list(map(int, input().split())) a.insert(0,0) b.insert(0,0) b_num = sum(b) b_best = M j = M a_num = 0 maxmize = 0 num = 0 for i in range(N+1): a_num +=a[i] flag = 1 while flag == 1: num = b_num+a_num if num<=K: maxmize = max(M+i,maxmize) break else: if not b: break else: j = b.pop() M-=1 b_num = b_num-j print(maxmize)
1
10,733,616,534,048
null
117
117
a = list(map(int, input().split())) b = a[0] while b % a[1] != 0: b += a[0] print(b)
weather = list(input()) i = 0 j = 0 days = 0 consecutive = [] while i <= 2: while i + j <= 2: if weather[i+j] == "R": days += 1 j += 1 else: break i += 1 j = 0 consecutive.append(days) days = 0 print(max(consecutive))
0
null
58,867,453,130,190
256
90
N = int(input()) mod = int(1e9) + 7 def doubling(n, m): y = 1 bas = n tmp = m while tmp: if tmp % 2: y *= bas y %= mod bas *= bas bas %= mod tmp >>= 1 return y d10 = doubling(10, N) d9 = doubling(9, N) d8 = doubling(8, N) print((d10 - 2*d9 + d8) % mod)
v=input() v=int(v) print(v**3)
0
null
1,743,102,713,828
78
35
n = int(input()) C = list(input()) if "R" not in C: print(0) exit() W = C.count("W") R = C.count("R") w = 0 r = R ans = float('inf') for c in C: if c == "W": w += 1 else: r -= 1 ans = min(ans, max(w, r)) print(ans)
n = int(input()) l = [[] for _ in range(n)] d = [[] for _ in range(n)] for i in range(n): l[i] = list(map(int,input().split())) d[i] = [l[i][0]-l[i][1],l[i][0]+l[i][1]] d.sort(key=lambda x:x[1]) ma = -9999999 c = 0 for i in range(n): if(d[i][0] >= ma): ma = d[i][1] c += 1 print(c)
0
null
48,282,884,472,850
98
237
n,d = map(int, input().split()) x = [] y = [] for i in range(n): a,b = map(int, input().split()) x.append(a) y.append(b) count = 0 for i in range(n): if (x[i]**2 + y[i]**2)**(1/ 2) <= d: count += 1 print(count)
N = int(input()) A = [int(x) for x in input().split()] M = max(A) count = [0] * (M + 1) for i in range(N): count[A[i]] += 1 check = [True] * (M + 1) for a in range(1, M + 1): if count[a] > 0 and check[a] == True: for k in range(2, M // a + 1): check[a * k] = False ans = 0 for i in range(N): if count[A[i]] == 1 and check[A[i]] == True: ans += 1 print(ans)
0
null
10,215,037,200,574
96
129
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n, m = list(map(int, readline().split())) print("Yes" if n == m else "No") if __name__ == '__main__': solve()
n,t = map(int,input().split()) l = [] for i in range(n): a,b = map(int,input().split()) l.append([a,b]) l.sort(key=lambda x:x[0]) dp = [[0 for i in range(t)] for i in range(n+1)] al = [] for i in range(n): a,b = l[i] for j in range(t): if dp[i][j] == 0: if j == 0: if j + a < t: dp[i+1][j+a] = max(dp[i][j+a],b) else: al.append(b) else: if j + a < t: dp[i+1][j+a] = max(dp[i][j+a],dp[i][j]+b) else: al.append(dp[i][j]+b) dp[i+1][j] = max(dp[i+1][j],dp[i][j]) if len(al) > 0: print(max(max(dp[n]),max(al))) else: print(max(dp[n]))
0
null
117,442,266,892,984
231
282
#!/usr/bin/env python3 import sys from math import gcd read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) A, B = map(int, input().split()) gc = gcd(A, B) LCM = A * B // gc print(LCM)
def gcd(a, b): while b: a, b = b, a % b return a import math A,B=map(int,input().split()) print(A*B//gcd(A,B))
1
113,737,972,026,732
null
256
256
X = int(input()) ans="No" if X>=30: ans='Yes' print(ans)
temp = input() temp = int(temp) if temp<-40 or temp>40: print('Out') elif temp >=30: print('Yes') else: print('No')
1
5,703,641,593,860
null
95
95
import math inf = math.inf def merge(A, left, mid, right): global cnt L = [] R = [] for i in A[left:mid]: L.append(i) for i in A[mid:right]: R.append(i) L.append(inf) R.append(inf) i = 0 j = 0 for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if right - left > 1: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) _ =input() A = list(map(int, input().rstrip().split(" "))) cnt = 0 mergeSort(A, 0, len(A)) print(" ".join(list(map(str, A)))) print(cnt)
# def merge(arr, l, mid, r): # L = [arr[i] for i in range(l, mid)] # R = [arr[i] for i in range(mid, r)] # L.append(int(1e9 + 10)) # R.append(int(1e9 + 10)) # i, j = 0, 0 # cnt = 0 # for k in range(l, r): # if L[i] <= R[j]: # arr[k] = L[i] # i += 1 # else: # arr[k] = R[j] # j += 1 # cnt += 1 # return cnt # def mergeSort(arr, l, r): # cnt = 0 # if l + 1 < r: # mid = (l + r) >> 1 # cnt += mergeSort(arr, l, mid) # cnt += mergeSort(arr, mid, r) # cnt += merge(arr, l, mid, r) # return cnt # triky def count(l, r): cnt = 0 if l + 1 < r: mid = (l + r) >> 1 cnt += count(l, mid) cnt += count(mid, r) cnt += r - l return cnt cnt = count(0, int(input())) arr = list(map(int, input().split())) arr.sort() print(*arr) print(cnt)
1
113,658,138,856
null
26
26
import sys for e in sys.stdin:print(len(str(sum(map(int,e.split())))))
n = int(input()) A_l = [(A,i) for i, A in enumerate(map(int,input().split()))] A_l.sort(reverse=True) dp = [] for _ in range(n+1): dp.append([0] * (n+1)) for j in range(1,n+1): # all go bigger a, i = A_l[j-1] dp[j][0] = dp[j-1][0] + a*(n-(j-1) - (i+1)) for k in range(1,n+1): # all go smaller a, i = A_l[k-1] dp[0][k] = dp[0][k-1] + a*((i+1) - (1+(k-1))) for j in range(1,n+1): for k in range(1,n-j+1): a, i = A_l[j+k-1] j_plus = a*(n-(j-1) - (i+1)) k_plus = a*((i+1) - (1+(k-1))) dp[j][k] = max(dp[j-1][k]+j_plus, dp[j][k-1]+k_plus) result = 0 for j in range(0,n+1): k = n-j result = max(result, dp[j][k]) print(result) #for l in range(n+1): # print(dp[l])
0
null
16,867,865,358,024
3
171
from fractions import gcd import sys sys.setrecursionlimit(10**7) a,b = map(int,input().split()) def lcm(x, y): return (x * y) // gcd(x, y) if b != 0: print(lcm(a, b)) else: print(a)
a, b, c = map(int, input().split()) if a < b and b < c: ans = 'Yes' else: ans = 'No' print(ans)
0
null
56,550,797,676,692
256
39
H=int(input()) b=0 while 2**b <= H: b+=1 print(2**(b)-1)
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) mod = 10**9+7 # mod = 998244353 dir = [(-1,0),(0,-1),(1,0),(0,1)] alp = "abcdefghijklmnopqrstuvwxyz" INF = 1<<32-1 # INF = 10**18 def main(): s = input() if s[-1] == "s": print(s+"es") else: print(s+"s") return None if __name__ == '__main__': main()
0
null
41,478,657,795,166
228
71
import math x1,y1,x2,y2 =map(float, input().split()) length = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) print("{0:04f}".format(length))
N = int(input()) r = N while r >= 1000: r = r-1000 if r == 0: print(0) else: print(1000-r)
0
null
4,305,503,560,006
29
108
import sys input = sys.stdin.readline N, M, L = map(int, input().split()) INF = float('inf') VD = [[INF] * N for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 VD[a][b] = c VD[b][a] = c for i in range(N): VD[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): if VD[i][j] > VD[i][k] + VD[k][j]: VD[i][j] = VD[i][k] + VD[k][j] WD = [[INF] * N for _ in range(N)] for i in range(N): WD[i][i] = 0 for j in range(i+1,N): d = VD[i][j] if d <= L: WD[i][j] = 1 WD[j][i] = 1 for k in range(N): for i in range(N): for j in range(N): if WD[i][j] > WD[i][k] + WD[k][j]: WD[i][j] = WD[i][k] + WD[k][j] Q = int(input()) for _ in range(Q): s, t = map(int, input().split()) print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1)
x = input() count = int(x.split()[0]) num = int(x.split()[1]) if count < 10: num = num + (100 * (10 - count)) else: num print(num)
0
null
118,464,353,898,098
295
211
import itertools n = int(input()) d = list(map(int, input().split())) lst = list(itertools.combinations(d, 2)) ans = 0 for i in lst: a = i[0] * i[1] ans += a print(ans)
n=int(input()) d=list(map(int,input().split())) sum=0 for i in range(n): for j in range(n): if j<=i: continue else: sum+=d[i]*d[j] print(sum)
1
167,566,619,632,660
null
292
292
s=input() for i in range(1,6): if s=='hi'*i: print('Yes') quit() print('No')
n = input().split() a = [] for i in range(len(n)): a.append(int(n[i])) a = sorted(a) print('{0} {1} {2}'.format(a[0],a[1],a[2]))
0
null
26,829,477,450,368
199
40
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N = int(readline()) def enum_divisors(n): # 約数列挙 divisors = [] for i in range(1, int(n ** 0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors divs = enum_divisors(N) ans = INF for div1 in divs: div2 = N // div1 score = (div1 + div2 - 2) ans = min(score, ans) print(ans) if __name__ == '__main__': main()
import math n = int(input()) sq = int(math.sqrt(n)) i=sq for i in range(sq,0,-1): if n%i==0: j=n//i break print(i+j-2)
1
161,753,164,252,742
null
288
288
import sys input = sys.stdin.buffer.readline r, c, k = map(int, input().split()) v = [[0]*(c+1) for i in range(r+1)] for i in range(k): cr, cc, cv = map(int, input().split()) v[cr][cc] = cv dp = [[0]*4 for _ in range(c+1)] last = [[0]*4 for _ in range(c+1)] for cr in range(1, r+1): for cc in range(1, c+1): upper = max(last[cc][0], last[cc][1], last[cc][2], last[cc][3]) dp[cc][0] = max(upper, dp[cc-1][0], dp[cc][0]) dp[cc][1] = max(dp[cc-1][1], dp[cc-1][0]+v[cr][cc], upper+v[cr][cc]) dp[cc][2] = max(dp[cc-1][2], dp[cc-1][1]+v[cr][cc]) dp[cc][3] = max(dp[cc-1][3], dp[cc-1][2]+v[cr][cc]) last = dp print(max(dp[c]))
import sys import math lines = sys.stdin.readlines() # print(lines) n = int(lines[0].rstrip()) heights = [int(x) for x in lines[1].rstrip().split()] # print(heights) tot = 0 for i in range(n-1): if heights[i] <= heights[i+1]: continue else: diff = heights[i] - heights[i+1] heights[i+1] += diff tot += diff print(tot)
0
null
5,044,037,279,160
94
88
n,m = map(int,input().split()) coins = list(map(int,input().split())) inf = float("inf") dp = [inf]*(n+2) dp[0]= 0 for i in range(1,n+1): for coin in coins: if i-coin>=0: dp[i]= min(dp[i-coin]+1,dp[i]) print(dp[n])
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N, M = map(int, readline().split()) C = list(map(int, readline().split())) # dp[i] := i円払うのに必要な枚数 dp = [INF] * (N+1) dp[0] = 0 for c in C: if c<=N: for i in range(N-c+1): dp[i+c] = min(dp[i]+1, dp[i+c]) print(dp[N]) if __name__ == '__main__': main()
1
141,107,899,168
null
28
28
MOD=10**9+7 N=int(input()) ans=pow(10,N,MOD) ans-=2*pow(9,N,MOD) ans+=pow(8,N,MOD) ans%=MOD print(ans)
import math n = int(input()) mod = 1000000007 all = pow(10, n, mod) s1 = 2 * pow(9, n, mod) % mod s2 = pow(8, n, mod) % mod ans = int(all - s1 + s2)%mod if ans < 0: ans += mod print(ans%mod)
1
3,170,221,594,488
null
78
78
palavra= input() tam= len(palavra) if palavra[tam-1]=='s': print(palavra+'es') else: print(palavra+'s')
x = raw_input() a, b, c = x.split() a = int(a) b = int(b) c = int(c) kai = 0 d = b + 1 for i in range(a, d): if c % i == 0: kai += 1 print kai
0
null
1,474,789,244,320
71
44
S = int(input()) p = 10**9 +7 def pow_mod(p,a,n): res = 1 while n > 0: if n % 2 == 1: res = (res * a) % p n = n // 2 a = (a*a)%p return res n = 2000 fac = [1] foo = 1 for i in range(1,n+1): foo = (foo*i)%p fac.append(foo) #コンビネーションのmod def comb_mod(n,k): res = (fac[n] * pow_mod(p,fac[k],p-2) * pow_mod(p,fac[n-k],p-2)) % p return res ans = 0 for i in range(1,1+S//3): t = S - 3*i ans = (ans + comb_mod(t+i-1,t)) %p print(ans)
import math N = int(input()) A = list(map(int,input().split())) A.sort(reverse=True) comfortPoint = A[0] for i in range(N-1)[1::]: comfortPoint += A[math.ceil(i/2)] print(comfortPoint)
0
null
6,216,243,296,320
79
111
n = int(raw_input()) elems = map(int, raw_input().split(' ')) cumul = 0 res = 0 for j in range(len(elems)): res += elems[j] * cumul cumul += elems[j] print res
N = int(input()) if N % 1000 == 0: print(0) else: payment = N // 1000 + 1 change = payment*1000 - N print(change)
0
null
87,998,763,229,920
292
108
from math import floor from decimal import Decimal x = int(input()) amount = 100 count = 0 while amount < x: amount += floor(Decimal(amount) / Decimal(100)) count += 1 print(count)
from operator import itemgetter from bisect import bisect_right n, d, a = map(int, input().split()) monster = [tuple(map(int, input().split())) for _ in range(n)] monster.sort(key=itemgetter(0)) xx = [xi for xi, hi in monster] ans = 0 imos = [0] * (n + 1) for i, (xi, hi) in enumerate(monster): hi -= imos[i] if hi > 0: c = (hi + a - 1) // a ans += c idx = bisect_right(xx, xi + 2 * d) imos[i] += c * a imos[idx] -= c * a # update imos imos[i + 1] += imos[i] print(ans)
0
null
54,946,524,447,232
159
230
a,b,k = map(int, input().split()) m = k if a > k else a a -= m b -= min(k-m, b) print(f'{a} {b}')
a, b, k = map(int,input().split()) if k >= a + b: print("0 0") elif k>a: print ("0 "+str(a+b-k)) else: print(str(a-k)+" "+str(b))
1
104,371,968,499,302
null
249
249
l = int(input()) print(l/3 * l/3 * (l - 2*l/3))
import math import sys def main(): n = int(sys.stdin.readline()) total = 0 for i in range(1,n+1): for j in range(1,n+1): for k in range(1,n+1): total += math.gcd(i, math.gcd(j,k)) print(total) main()
0
null
41,523,542,472,650
191
174
n, k = map(int, input().split()) mod = 10 ** 9 + 7 ans = 0 coma = 1 comb = 1 for i in range(min(k+1, n)): ans += coma * comb ans %= mod coma *= (n-i) * pow(i+1, mod-2, mod) coma %= mod comb *= (n-i-1) * pow(i+1, mod-2, mod) comb %= mod print(ans)
h, hoge = list(map(int, input().split(' '))) l = list(map(int, input().split(' '))) print('Yes' if h <= sum(l) else 'No')
0
null
72,812,873,028,882
215
226
N = int(input()) P = list(map(int,input().split())) P_min = [] a = 200000 ans = 0 for i in range(N): if a >= P[i]: ans += 1 a = P[i] print(ans)
N = int(input()) P = list(map(int, input().split())) S = sorted(P, reverse = True) cn = 0 L = [] for i in range(N): if i == 0: cn = cn + 1 L.append(P[i]) else: if P[i] > L[0]: continue else: cn = cn + 1 L.append(P[i]) L.pop(0) print(cn)
1
85,537,732,485,828
null
233
233
# -*- coding: utf-8 -*- n, k = map(int,input().split()) p = [int(i) for i in input().split()] p.sort() print(sum(p[:k]))
#B問題 ans = 0 n, k = map(int, input().split()) P = list(map(int, input().split())) for i in range(k): ans += min(P) P.remove(min(P)) print(ans)
1
11,566,120,032,980
null
120
120
import sys k = int(input()) a = dict() cnt = 0 base = 0 while True: cnt += 1 base = (base*10+7)%k if base == 0: break if base in a: cnt = -1 break else: a[base] = 1 print(cnt)
def bubble_sort(r, n): flag = True # ??£??\????´?????????¨????????° while flag: flag = False for i in range(n - 1, 0, -1): if r[i - 1][1] > r[i][1]: r[i - 1], r[i] = r[i], r[i - 1] flag = True return r def select_sort(r, n): for i in range(0, n): minj = i for j in range(i, n): if r[j][1] < r[minj][1]: minj = j if i != minj: r[i], r[minj] = r[minj], r[i] return r def stable_sort(r, sort_r): for i in range(len(r)): for j in range(i + 1, len(r)): for a in range(len(sort_r)): for b in range(a + 1, len(sort_r)): if r[i][1] == r[j][1] and r[i] == sort_r[b] and r[j] == sort_r[a]: return "Not stable" return "Stable" N = int(input()) R = list(input().split()) C = R[:] BS_R = bubble_sort(R, N) SS_R = select_sort(C, N) print(*BS_R) print(stable_sort(R, BS_R)) print(*SS_R) print(stable_sort(R, SS_R))
0
null
3,101,746,373,018
97
16
N = int(input()) XL = [list(map(int, input().split())) for i in range(N)] LR = [[x - l, x + l] for x, l in XL] LR.sort(key=lambda x: x[1]) ans = 0 prev = -float("INF") for l, r in LR: if prev <= l: ans += 1 prev = r print(ans)
from math import atan, degrees a,b,x = map(int,input().split()) o = 2 * x / (a*a) - b if o < 0: h = 2 * (x / a) / b print(degrees(atan(b/h))) else: print(degrees(atan((b-o)/a)))
0
null
126,613,813,153,568
237
289
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap class UnionFind(): def __init__(self): self.__table = {} self.__size = defaultdict(lambda: 1) self.__rank = defaultdict(lambda: 1) def __root(self, x): if x not in self.__table: self.__table[x] = x elif x != self.__table[x]: self.__table[x] = self.__root(self.__table[x]) return self.__table[x] def same(self, x, y): return self.__root(x) == self.__root(y) def union(self, x, y): x = self.__root(x) y = self.__root(y) if x == y: return False if self.__rank[x] < self.__rank[y]: self.__table[x] = y self.__size[y] += self.__size[x] else: self.__table[y] = x self.__size[x] += self.__size[y] if self.__rank[x] == self.__rank[y]: self.__rank[x] += 1 return True def size(self, x): return self.__size[self.__root(x)] def num_of_group(self): g = 0 for k, v in self.__table.items(): if k == v: g += 1 return g @mt def slv(N, M, AB): uf = UnionFind() p = set() for a, b in AB: uf.union(a, b) p.add(a) p.add(b) ans = 1 for c in p: ans = max(ans, uf.size(c)) return ans def main(): N, M = read_int_n() AB = [read_int_n() for _ in range(M)] print(slv(N, M, AB)) if __name__ == '__main__': main()
H,N = map(int,input().split()) A = list(map(int,input().split())) sum =0 for i in range(len(A)): sum = sum + A[i] if sum >= H: print("Yes") else: print("No")
0
null
40,823,045,082,170
84
226
n,k =map(int, input().split()) h = list(map(int, input().split())) # n = int(input()) # s = [map(int, input()) for i in range(3)] count = 0 for i in range (0,n): if h[i] < k: count+=1 print(n-count)
if __name__ == '__main__': data_num = int(input()) data = [x for x in input().split(' ')] assert data_num == len(data), "invalid input" data.reverse() output = ' '.join(data) print(output)
0
null
90,287,126,847,050
298
53
import itertools a=int(input()) b=list(map(int,input().split())) c=list(map(int,input().split())) n=sorted(b) m=list(itertools.permutations(n)) m=[list(i) for i in m] print(abs(m.index(b)-m.index(c)))
import itertools n = int(input()) s = list(map(int, input().split(' '))) t = list(map(int, input().split(' '))) hoge = list(itertools.permutations(range(1, n+1))) p = 0 q = 0 for i in range(len(hoge)): if list(hoge[i]) == s: p = i if list(hoge[i]) == t: q = i print(abs(p - q))
1
100,463,108,061,540
null
246
246
N = input() a=0 for i in range(len(N)): a+=int(N[i])%9 if a%9==0: print('Yes') if a%9!=0: print('No')
a = 0 for c in map(int, input()): a += c print("Yes" if a % 9 == 0 else "No")
1
4,385,949,843,968
null
87
87
n,*a=map(int,open(0).read().split()) mod=10**9+7 ans=0 for j in range(60): cnt=0 for i in range(n): cnt+=a[i]&1 a[i]=(a[i]>>1) ans+=(cnt*(n-cnt)%mod)*pow(2,j,mod) ans%=mod print(ans)
h, w, k = map(int, input().split()) choco = [[0] * w for _ in range(h)] for i in range(h): s = input() for j in range(w): choco[i][j] = int(s[j]) ans = float("inf") for bit in range(1 << (h - 1)): idx = [0] * h group = 0 for i in range(h): idx[i] = group if (bit >> i) & 1: group += 1 group += 1 array = [[0] * w for _ in range(group)] for j in range(w): for i in range(h): array[idx[i]][j] += choco[i][j] cnt = group - 1 cum = [0] * group canAdd = True for i in range(w): for j in range(group): if cum[j] > k: canAdd = False if ans <= cnt: canAdd = False if canAdd is False: break for j in range(group): tmp = cum[j] + array[j][i] if tmp > k: cnt += 1 for l in range(group): cum[l] = array[l][i] break cum[j] += array[j][i] if canAdd: ans = min(ans, cnt) print(ans)
0
null
85,304,911,417,348
263
193
n,m = map(int, input().split()) d = list(map(int, input().split())) inf = float('inf') dp = [inf for i in range(n+1)] dp[0] = 0 for i in range(m): for j in range(d[i], n+1): dp[j] = min(dp[j], dp[j-d[i]]+1) print(dp[-1])
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])
1
140,857,275,802
null
28
28
N=int(input()) c=-(-N//2)-1 print(c)
# -*- coding: utf-8 -*- N = int(input()) if N % 2 == 1: N += 1 print(N // 2 - 1)
1
153,201,619,330,332
null
283
283
x = int(input()) c1 = x//500 x -= 500*c1 c2 = x//5 print(1000*c1 + 5*c2)
# ABC160 B x = int(input()) a,moda = divmod(x,500) b,modb = divmod(moda,5) print(a*1000+b*5)
1
42,588,768,833,690
null
185
185
def resolve(): N, M = map(int, input().split()) if N%2==1: for i in range(1, M+1): a, b = i, N-i print(a, b) else: for i in range(1, M+1): a, b = i, N - i # 円として配置したとき、b-aが半分以上になったら片方だけ進める if b-a <= N//2: a += 1 print(a, b) if __name__ == "__main__": resolve()
def e_rotation_matching(): N, M = [int(i) for i in input().split()] if N % 2 == 1: ans = [(left, N - left) for left in range(1, (N // 2) + 1)] else: ans = [] flag = False left, right = 1, N - 1 while left < right: if not flag and right - left <= N // 2: right -= 1 flag = True ans.append((left, right)) left += 1 right -= 1 return '\n'.join([f'{a} {b}' for a, b in ans[:M]]) print(e_rotation_matching())
1
28,673,032,418,498
null
162
162
N=int(input()) arr=list(map(int,input().split())) print(' '.join(map(str,arr))) for key in range(1,len(arr)): temp=arr[key] i=key-1 while i>=0 and arr[i]>temp: arr[i+1]=arr[i] i-=1 arr[i+1]=temp print(' '.join(map(str,arr)))
import sys lines = sys.stdin.readlines() N = lines[0] A = lines[1].strip().split(" ") print " ".join(A) for i in range(1, len(A)): key = A[i] j = i - 1 while j >= 0 and int(A[j]) > int(key): A[j+1] = A[j] j -= 1 A[j+1] = key print " ".join(A)
1
6,425,123,770
null
10
10
n,k = map(int,input().split()) ans = 0 while n >= k: ans += 1 n = n//k print(ans+1)
n,k = map(int,input().split()) i = 0 while True : s = k **i if n < s : ans = i break i += 1 print(ans)
1
64,296,813,033,828
null
212
212
n,q=map(int,input().split()) Q=[] sum=0 for i in range(n): tmp=input().split() tmp[1]=int(tmp[1]) Q.append(tmp[0]) Q.append(tmp[1]) loop=0 while loop==0: for i in range(len(Q)//2): tmp=[Q[0],Q[1]] if tmp[1]>q: sum+=q Q.append(tmp[0]) Q.append(tmp[1]-q) else: sum+=tmp[1] print(tmp[0],sum) Q.pop(0) Q.pop(0) if len(Q)==0: break
# -*- coding: utf-8 -*- def round_robin_scheduling(process_name, process_time, q): result = [] elapsed_time = 0 while len(process_name) > 0: # print process_name # print process_time if process_time[0] <= q: elapsed_time += process_time[0] process_time.pop(0) result.append(process_name.pop(0) + ' ' + str(elapsed_time)) else: elapsed_time += q process_name.append(process_name.pop(0)) process_time.append(process_time.pop(0) - q) return result if __name__ == '__main__': N, q = map(int, raw_input().split()) process_name, process_time = [], [] for i in xrange(N): process = raw_input().split() process_name.append(process[0]) process_time.append(int(process[1])) # N, q = 5, 100 # process_name = ['p1', 'p2', 'p3', 'p4', 'p5'] # process_time = [150, 80, 200, 350, 20] result = round_robin_scheduling(process_name, process_time, q) for i in xrange(len(result)): print result[i]
1
43,068,125,308
null
19
19
def main3(): N = int(input()) ans = 0 for a in range(1, N): ans += (N-1)//a print(ans) if __name__ == "__main__": main3()
n=int(input()) def f(i): if n%i==0: return n//i-1 else: return n//i sum=0 for i in range(1,n): sum+=f(i) print(sum)
1
2,575,122,071,830
null
73
73
N, *A = map(int, open(0).read().split()) mod = 10**9 + 7 batch = 8 rg = tuple(range((63//batch)+1)) mask = (1<<batch) - 1 B = [[0]*(1<<batch) for _ in rg] for a in A: for i in rg: B[i][a & mask] += 1 a >>= batch xr = [[] for _ in [0]*(1<<batch)] for i in range(1<<batch): for j in range(i+1, 1<<batch): xr[i].append(i^j) ans = 0 shift = 1 for b in B: x = sum(xr[i][j]*bi*bj for i, bi in enumerate(b) for j, bj in enumerate(b[i+1:])) x %= mod x *= shift x %= mod shift <<= batch shift %= mod ans += x ans %= mod print(ans)
#Union Find #xの根を求める def find(x): if par[x] < 0: return x else: tank = [] while par[x] >= 0: tank.append(x) x = par[x] for elt in tank: par[elt] = x return x #xとyの属する集合の併合 def unite(x,y): x = find(x) y = find(y) if x == y: return False else: #sizeの大きいほうがx if par[x] > par[y]: x,y = y,x par[x] += par[y] par[y] = x return True n,m = map(int, input().split()) par = [-1] * n for i in range(m): a,b = map(int,input().split()) unite(a-1,b-1) ans = set([]) for i in range(n): ans.add(find(i)) print(len(ans)-1)
0
null
62,715,825,742,372
263
70
import sys sys.setrecursionlimit(10 ** 7) def resolve(): N, M,K = map(int, input().split()) frind = [[] for _ in range(N)] for _ in range(M): a, b = map(lambda x:int(x)-1, input().split()) frind[a].append(b) frind[b].append(a) block = [[] for _ in range(N)] for _ in range(K): a, b = map(lambda x: int(x) - 1, input().split()) block[a].append(b) block[b].append(a) D = {} parent = [-1]*N visited = [False]*N for root in range(N): if visited[root]: continue D[root] = set([root]) stack = [root] while stack: n = stack.pop() visited[n] = True parent[n] = root for to in frind[n]: if visited[to]: continue D[root].add(to) stack.append(to) ans = [0]*N for i in range(N): gr = D[parent[i]] tmp = len(gr)-len(frind[i]) - 1 for bl in block[i]: if bl in gr: tmp -= 1 ans[i] = tmp print(*ans) if __name__ == "__main__": resolve()
#!/usr/bin/env python3 def main(): from collections import deque N, M, K = map(int, input().split()) friends = [set() for _ in range(N + 1)] for _ in range(M): a, b = map(int, input().split()) friends[a].add(b) friends[b].add(a) blocks = [set() for _ in range(N + 1)] for _ in range(K): c, d = map(int, input().split()) blocks[c].add(d) blocks[d].add(c) friends_chain = [] seen = [-1] * (N + 1) cnt = 0 for person in range(1, N + 1): if seen[person] != -1: continue q = deque([person]) friends_chain.append(set(q)) while q: now = q.pop() seen[now] = cnt for next in friends[now]: if seen[next] != -1: continue friends_chain[-1].add(next) q.append(next) cnt += 1 for person in range(1, N + 1): res = friends_chain[seen[person]] tmp_ans = len(res) - len(friends[person]) - 1 for block in blocks[person]: tmp_ans -= 1 if block in res else 0 print(tmp_ans, end=' ') if __name__ == '__main__': main()
1
61,293,374,229,856
null
209
209
f = lambda: int(input()) d = -float('inf') n = f() l = f() for _ in range(n-1): r = f() d = max(d, r-l) l = min(l, r) print(d)
N = int(input()) X = N / 1.08 X_down = int(X) X_up = int(X) + 1 bool_down = int(X_down * 1.08) == N bool_up = int(X_up * 1.08) == N if bool_down: print(X_down) elif bool_up: print(X_up) else: print(":(")
0
null
62,913,351,172,210
13
265
import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush, heappop BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 global current_time global visited,go_time,back_time global G def dfs(node_id): global current_time #書かないとローカル変数扱いされる go_time[node_id] = current_time current_time += 1 for next_node in G[node_id]: if visited[next_node] == True: continue visited[next_node] = True dfs(next_node) back_time[node_id] = current_time current_time += 1 V = int(input()) G = [[] for i in range(V)] visited = [False]*V go_time = [0]*V back_time = [0]*V for loop in range(V): node_id,num,*tmp_adj = list(map(int,input().split())) node_id -= 1 for i in range(num): G[node_id].append(tmp_adj[i]-1) current_time = 1; for i in range(V): if visited[i] == True: continue visited[i] = True dfs(i) for i in range(V): print("%d %d %d"%(i+1,go_time[i],back_time[i]))
N = int(input()) D1, D2 = [], [] for i in range(N): li = list(map(int,input().split())) D1.append(li[0]) D2.append(li[1]) for i in range(N-2): if D1[i]==D2[i] and D1[i+1]==D2[i+1] and D1[i+2]==D2[i+2]: print('Yes') break else: print('No')
0
null
1,242,537,938,612
8
72
import sys import re import math import collections import decimal import bisect # import copy # import heapq # from collections import deque # import decimal # sys.setrecursionlimit(100001) INF = sys.maxsize # MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): a, b, c = ns() tmp = decimal.Decimal(a).sqrt() + decimal.Decimal(b).sqrt() - decimal.Decimal(c).sqrt() print("Yes" if tmp < 0 else "No") if __name__ == '__main__': main()
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) a, b, c = mapint() if c-(a+b)>=0: if 4*a*b<(c-a-b)**2: print('Yes') else: print('No') else: print('No')
1
51,881,815,613,640
null
197
197
class Dice: def __init__(self,t,f,r,l,b,u): self.t = t self.f = f self.r = r self.l = l self.b = b self.u = u self.a=[t,f,r,l,b,u] self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)} def roll(self,d): self.a=[self.a[i] for i in self.direction[d]] self.t = self.a[0] self.f = self.a[1] self.r = self.a[2] self.l = self.a[3] self.b = self.a[4] self.u = self.a[5] t,f,r,l,b,u=map(int,input().split()) dice=Dice(t,f,r,l,b,u) n=int(input()) s='SSSEWW' yw='YYY' for j in range(n): t,f=map(int,input().split()) for d in s: if dice.t==t: break dice.roll(d) for t in yw: if dice.f==f: break dice.roll(t) print(dice.r)
import random class Dise: def __init__(self,top,flont,right,left,back,bottom): self.top,self.flont,self.right,self.left,self.back,self.bottom=top,flont,right,left,back,bottom def rot(self,d): if d=='N': self.top,self.flont,self.bottom,self.back=self.flont,self.bottom,self.back,self.top elif d=='E': self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom elif d=='S': self.top,self.flont,self.bottom,self.back=self.back,self.top,self.flont,self.bottom elif d=='W': self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top def gettop(self): return self.top def getfront(self): return self.flont def getright(self): return self.right n=list(map(int,input().split())) m=int(input()) dise=Dise(n[0],n[1],n[2],n[3],n[4],n[5]) for i in range(m): a,b=(int(x) for x in input().split()) for j in range(1000): dise.rot(random.choice('NESW')) if a==dise.gettop() and b==dise.getfront(): print(dise.getright()) break
1
254,173,384,388
null
34
34
import math print(2*float(input())*math.pi)
import math R = int(input()) circum = R * 2 * math.pi print(circum)
1
31,468,122,913,172
null
167
167
from math import gcd n=int(input()) l=list(map(int,input().split())) mal=max(l) e=[i for i in range(mal+1)] x=2 while x*x <= mal: if x == e[x]: for m in range(x, len(e), x): if e[m] == m: e[m] = x x+=1 #print(e) s=set() f=0 for i in l: st = set() while i > 1: st.add(e[i]) i//=e[i] if not s.isdisjoint(st): f=1 break s |= st if f==0: print('pairwise coprime') exit() p=l[0] for i in range(1,n): p=gcd(p,l[i]) if p==1: print('setwise coprime') else: print('not coprime')
n = int(input()) ans=0 for j in range(1,n+1): y = n//j ans += y*(y+1)*j//2 print(ans)
0
null
7,615,211,113,082
85
118
L = float(input()) print((L/3.)**3.)
import sys l = int(input()) print((l / 3)**3)
1
47,070,726,329,010
null
191
191
n = int(input()) array = [input().split() for i in range(n)] S = [] H = [] C = [] D = [] for i in range(1,14): S.append(i) H.append(i) C.append(i) D.append(i) for i in range(n): if array[i][0] == "S": S[int(array[i][1])-1]=" " elif array[i][0] == "H": H[int(array[i][1])-1]=" " elif array[i][0] == "C": C[int(array[i][1])-1]=" " else: D[int(array[i][1])-1]=" " for i in range(13): if S[i] != " ": print("S "+str(S[i])) for i in range(13): if H[i] != " ": print("H "+str(H[i])) for i in range(13): if C[i] != " ": print("C "+str(C[i])) for i in range(13): if D[i] != " ": print("D "+str(D[i]))
s = range(1,14) h = range(1,14) c = range(1,14) d = range(1,14) n = input() for i in range(n): mark, number = raw_input().split() if mark == 'S': s[int(number)-1] = 0 elif mark == 'H': h[int(number)-1] = 0 elif mark == 'C': c[int(number)-1] = 0 elif mark == 'D': d[int(number)-1] = 0 for i in range(13): if s[i] != 0: print "S %d" %s[i] for i in range(13): if h[i] != 0: print "H %d" %h[i] for i in range(13): if c[i] != 0: print "C %d" %c[i] for i in range(13): if d[i] != 0: print "D %d" %d[i]
1
1,024,971,851,640
null
54
54
def swap(m, n, items): x = items[n] items[n] = items[m] items[m] = x ABC = input().split() if ABC[0] > ABC[1]: swap(0, 1, ABC) if ABC[1] > ABC[2]: swap(1, 2, ABC) if ABC[0] > ABC[1]: swap(0, 1, ABC) elif ABC[1] > ABC[2]: swap(1, 2, ABC) if ABC[0] > ABC[1]: swap(0, 1, ABC) print(ABC[0], ABC[1], ABC[2])
N = int(input()) print(input().count("ABC")) """ 3文字ずつスライスし判定 S = input() count = 0 # スライスでi+2文字目まで行くのでfor文範囲はN-2でとどめる for i in range(N-2): if S[i:i+3] == "ABC": count += 1 print(count) """
0
null
49,723,135,975,548
40
245
n = int( input() ) x = input() x_pop = x.count( "1" ) x_pls = x_pop + 1 x_mns = x_pop - 1 # 2の冪乗のリスト.ただし後々に備えてpopcountで割った余りにしてある rp = [ pow( 2, i, x_pls ) for i in range( n + 1 ) ] if x_mns > 0: rm = [ pow( 2, i, x_mns ) for i in range( n + 1 ) ] else: rm = [ 0 ] * ( n + 1 ) x = x[ : : -1 ] rem_p = 0 rem_m = 0 for i in range( n ): if x[ i ] == "1": rem_p += rp[ i ] rem_m += rm[ i ] for i in range( n - 1, -1, -1 ): if x[ i ] == "0": tmp = ( rem_p + rp[ i ] ) % x_pls elif x_mns > 0: tmp = ( rem_m - rm[ i ] ) % x_mns else: # popcount( X_i ) == 0 print( 0 ) continue ans = 1 while tmp > 0: tmp = tmp % bin( tmp ).count( "1" ) ans += 1 print( ans )
n = int(input()) x = list(input()) def popcount(n): bin_n = bin(n)[2:] count = 0 for i in bin_n: count += int(i) return count cnt = 0 for i in range(n): if x[i] == '1': cnt += 1 plus = [0 for i in range(n)] # 2^index を cnt+1 で割った時のあまり minus = [0 for i in range(n)] # 2^index を cnt-1 で割った時のあまり if cnt == 0: plus[0] = 0 else: plus[0] = 1 if cnt != 1: minus[0] = 1 for i in range(1, n): plus[i] = (plus[i-1]*2) % (cnt+1) if cnt != 1: minus[i] = (minus[i-1]*2) % (cnt-1) origin = int(''.join(x), base=2) amariplus = origin % (cnt+1) if cnt != 1: amariminus = origin % (cnt-1) for i in range(n): if x[i] == '0': amari = (amariplus + plus[n-i-1]) % (cnt+1) else: if cnt != 1: amari = (amariminus - minus[n-i-1]) % (cnt-1) else: print(0) continue ans = 1 while amari != 0: ans += 1 amari = amari % popcount(amari) print(ans)
1
8,256,689,320,672
null
107
107
#https://atcoder.jp/contests/abc164/tasks/abc164_b A,B,C,D = map(int,input().split()) Senkou_N,Senkou_Amari = divmod(C,B) if Senkou_Amari != 0: Senkou_N += 1 Koukou_N,Koukou_Amari = divmod(A,D) if Koukou_Amari != 0: Koukou_N += 1 if Senkou_N <= Koukou_N: print("Yes") else: print("No")
class monster: def __init__(self, hp: int, ap: int): self.hit_point = hp self.attack_point = ap self.status = 'healthy' def attack(self, enemy: 'monster'): enemy.defend(self.attack_point) def defend(self, enemy_ap: int): self.hit_point -= enemy_ap if self.hit_point <= 0: self.status = 'dead' def is_alive(self) -> bool: return not self.is_dead() def is_dead(self) -> bool: return self.status == 'dead' def answer(t_hp: int, t_ap: int, a_hp: int, a_ap: int) -> str: taka_monster = monster(t_hp, t_ap) aoki_monster = monster(a_hp, a_ap) while taka_monster.is_alive() and aoki_monster.is_alive(): taka_monster.attack(aoki_monster) if aoki_monster.is_dead(): return 'Yes' aoki_monster.attack(taka_monster) if taka_monster.is_dead(): return 'No' def main(): a, b, c, d = map(int, input().split()) print(answer(a, b, c, d)) if __name__ == '__main__': main()
1
29,658,045,263,152
null
164
164
x = int(input()) def f(a,b): return a**5-b**5 for a in range(-120,120): for b in range(-120,120): if f(a,b)==x: print(a,b) exit()
def main(): x = int(input()) a_lst = [] b_lst = [] for i in range(400): a_lst.append(-200 + i) for i in range(400): b_lst.append(-200 + i) flag = False for i in range(len(a_lst)): for j in range(len(b_lst)): a = a_lst[i] b = b_lst[j] if a ** 5 - b ** 5 == x: print(a, b) flag = True break if flag: break if __name__ == '__main__': main()
1
25,586,663,407,392
null
156
156
x,y=map(int,input().split()) for i in range(0,x+1): if(2*i+4*(x-i)==y): print("Yes") exit() print("No")
import numpy as np import numpy.linalg as linalg X, Y = map(int, input().split()) if Y%2 == 1: print('No') else: A = np.array([[1, 1], [2, 4]]) A_inv = linalg.inv(A) B = np.array([X , Y]) C = np.dot(A_inv, B) if C[0] >= 0 and C[1] >= 0 : print('Yes') else: print('No')
1
13,736,645,125,238
null
127
127
from decimal import* l=Decimal(input()) ans=(l/3)**3 print(ans)
s = input() s = '0' + s[::-1] dp = [[0, 0] for _ in range(len(s) + 1)] for i in range(len(s)): for j in range(2): if j == 0: #ぴったり dp[i + 1][j] = min(dp[i]) + int(s[i]) else: #1枚多めに払う dp[i + 1][j] = min(dp[i][1] + 9 - int(s[i]), dp[i][0] + 11 - int(s[i])) print(min(dp[-1]))
0
null
59,137,912,771,296
191
219
def int_to_str(n): if n == 0: return "a" elif n == 1: return "b" elif n == 2: return "c" elif n == 2: return "c" elif n == 2: return "c" elif n == 2: return "c" elif n == 2: return "c" elif n == 2: return "c" elif n == 2: return "c" def Base_10_to_n(X, n): if (int(X/n)): if X%n != 0: return Base_10_to_n(int(X/n), n)+chr((X%n)+96) else: return Base_10_to_n(int(X/n)-1, n)+chr(26+96) if(X%n != 0): return str(chr(X%n+96)) else: return "" N = int(input()) s = Base_10_to_n(N,26) print(s)
N = int(input()) ans = '' while(N > 0): N -= 1 _i = N % 26 ans = chr(ord('a') + _i) + ans N //= 26 print(ans)
1
12,009,535,682,048
null
121
121
N = int(input()) % 10 print('hon' if N in [2, 4, 5, 7, 9] else 'pon' if N in [0, 1, 6, 8] else 'bon')
s =int(list(input())[-1]) if s in [2,4,5,7,9]:print('hon') elif s in [0,1,6,8]:print('pon') else:print('bon')
1
19,157,589,636,800
null
142
142
# -*- coding:utf-8 -*- import sys data = [] count = 0 for i in sys.stdin: data.append(int(i)) count = count+1 if count == 10: break N = len(data) m = 100 for i in range(m): for n in range(N-1): a = data[n] b = data[n+1] if a <= b: data[n] = b data[n+1] = a else: pass for i in range(3): print(data[i])
moutain = [0 for i in range(10)] for i in range(10): moutain[i] = int(raw_input()) moutain.sort(reverse=True) for i in range(3): print moutain[i]
1
24,535,028
null
2
2