code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
from decimal import Decimal a, b = map(str, input().split()) a = int(a) b = Decimal(b) print(int(a * b))
a, b = input().split() a = int(a) b = str(b).replace(".", "") x = a * int(b) if x < 100: print(0) else: print(str(x)[:-2])
1
16,635,927,046,270
null
135
135
s = input() if s.endswith('s'): s += 'es' else: s += 's' print(s)
s=input() if(s[-1]=='s'): s=s+"es" print(s) else: s=s+"s" print(s)
1
2,390,686,874,400
null
71
71
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) a,b,c = inpm() k = inp() for i in range(k): if b <= a: b *= 2 elif c <= b: c *= 2 if a < b < c: ans = 'Yes' else: ans = 'No' print(ans)
A,B,C=map(int,input().split()) K=int(input()) count=0 if B<=A: while B<=A: B*=2 count+=1 if count>K: print('No') else: C*=2**(K-count) if C>B: print('Yes') else: print('No')
1
6,970,397,436,490
null
101
101
import sys N, M, K = map(int, input().split()) friends = [set() for _ in range(N)] for _ in range(M): a, b = map(int, sys.stdin.readline().split()) friends[a-1].add(b-1) friends[b-1].add(a-1) blocks = [set() for _ in range(N)] for _ in range(K): c, d = map(int, sys.stdin.readline().split()) blocks[c-1].add(d-1) blocks[d-1].add(c-1) done = set() chains = [] todo = [] for s in range(N): if s in done: continue chain = set() todo.append(s) while todo: i = todo.pop() for ni in friends[i]: if ni in done: continue done.add(ni) chain.add(ni) todo.append(ni) chains.append(chain) ans = [0] * N for chain in chains: for i in chain: blocks[i].intersection_update(chain) ans[i] = len(chain) - len(blocks[i]) - len(friends[i]) - 1 print(" ".join(map(str, ans)))
import sys sys.setrecursionlimit(10 ** 6) # from decorator import stop_watch # # # @stop_watch def solve(N, M, K, ABs, CDs): friend_map = [[] for _ in range(N + 1)] for a, b in ABs: friend_map[a].append(b) friend_map[b].append(a) block_map = [[] for _ in range(N + 1)] for c, d in CDs: block_map[c].append(d) block_map[d].append(c) def dfs(group_num, members, now_n): belongs[now_n] = group_num members.append(now_n) for f in friend_map[now_n]: if belongs[f] == -1: members = dfs(group_num, members, f) return members friend_groups = [] belongs = [-1] * (N + 1) for i in range(1, N + 1): if belongs[i] == -1: m = dfs(len(friend_groups), [], i) m.sort() friend_groups.append(m) ans = '' for n in range(1, N + 1): block = 0 group = friend_groups[belongs[n]] for b in block_map[n]: if belongs[n] == belongs[b]: block += 1 ans += ' ' + str(len(group) - len(friend_map[n]) - block - 1) print(ans[1:]) if __name__ == '__main__': # # handmade test # N, M, K = 2 * 10 ** 5, 10 ** 5, 10 ** 5 # ABs = [[1, i] for i in range(2, 10 ** 5 + 2)] # CDs = [[i, i + 1] for i in range(2, 10 ** 5 + 2)] # # handmade random # import random # N, M, K = 20, 10, 10 # ABs = [] # while True: # if len(ABs) == M: # break # a = random.randint(1, N - 1) # b = random.randint(a + 1, N) # if not [a, b] in ABs: # ABs.append([a, b]) # CDs = [] # while True: # if len(CDs) == K: # break # c = random.randint(1, N - 1) # d = random.randint(c + 1, N) # if not [c, d] in ABs and not [c, d] in CDs: # CDs.append([c, d]) # print(N, M, K) # print(ABs) # print(CDs) N, M, K = map(int, input().split()) ABs = [[int(i) for i in input().split()] for _ in range(M)] CDs = [[int(i) for i in input().split()] for _ in range(K)] solve(N, M, K, ABs, CDs)
1
61,800,349,454,760
null
209
209
def main(): n = int(input()) ans = n for i in range(1, int(n ** 0.5) + 1): if n % i != 0: continue j = n // i ans = min(ans, i + j - 2) print(ans) if __name__ == "__main__": main()
import math N = int(input()) start_digit = math.ceil(math.sqrt(N)) for i in range(start_digit, 0, -1): q, r = divmod(N, i) if r == 0: output = i+q-2 break print(output)
1
161,389,420,997,698
null
288
288
import bisect import copy import heapq import math import sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) sys.setrecursionlimit(500000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n=int(input()) a=list(map(int,input().split())) dic=defaultdict(int) ans=0 for i in range(n): ans+=dic[i-a[i]] dic[a[i]+i]+=1 print(ans)
def main(): n = int(input()) a = list(map(int,input().split())) f,s = {},{} for i in range(n): if i+1-a[i] not in f.keys(): f[i+1-a[i]] = 1 else: f[i+1-a[i]]+=1 if i+1+a[i] not in s.keys(): s[i+1+a[i]] = 1 else: s[i+1+a[i]] += 1 ans = 0 for k in f.keys(): if k in s.keys(): ans += f[k] * s[k] print(ans) if __name__ == "__main__": main()
1
26,070,311,686,012
null
157
157
N = int(input()) a = 0 for i in range(1,int(N**0.5)+1): if N%i == 0: a = max(a,i) b = N//a print((a-1)+(b-1))
# -*- coding: utf-8 -*- """ Created on Wed Sep 9 01:55:56 2020 @author: liang """ import math N = int(input()) key = int(math.sqrt(N)) ans = 10**12 for i in reversed(range(1,key+1)): if N%i == 0: ans = i-1 + N//i -1 break print(ans)
1
161,607,936,897,010
null
288
288
T = input() r = T.replace("?", "D") print(r)
n = int(input()) a = list(map(int, input().split())) min_a = min(a) max_a = max(a) sum_a = sum(a) print(min_a, max_a, sum_a)
0
null
9,651,210,940,320
140
48
a = int(input()) if a>=400 and a<600:print(8) elif a>=600 and a<800:print(7) elif a>=800 and a<1000:print(6) elif a>=1000 and a<1200:print(5) elif a>=1200 and a<1400:print(4) elif a>=1400 and a<1600:print(3) elif a>=1600 and a<1800:print(2) elif a>=1800 and a<2000:print(1)
import numpy as np a = int(input()) print(int( np.ceil((2000-a)/200)))
1
6,643,933,652,420
null
100
100
def calc_matrix(A, B, size): n, m, l = size # print(n, m, l) results = [] for i in range(n): row_data = [] for j in range(l): products = [] for k in range(m): products.append(A[i][k] * B[k][j]) # print('C[{0}][{1}] = {2}'.format(i, j, sum(products))) row_data.append(sum(products)) results.append(row_data) return results if __name__ == '__main__': # ??????????????\??? A = [] B = [] # A.append([1, 2]) # A.append([0, 3]) # A.append([4, 5]) # B.append([1, 2, 1]) # B.append([0, 3, 2]) n, m, l = [int(x) for x in input().split(' ')] for i in range(n): A.append([int(x) for x in input().split(' ')]) for i in range(m): B.append([int(x) for x in input().split(' ')]) # ??????????????? results = calc_matrix(A, B, (n, m, l)) # ??????????????? for row in results: print(' '.join(map(str, row)))
n_max, m_max, l_max = (int(x) for x in input().split()) a = [] b = [] c = [] for n in range(n_max): a.append([int(x) for x in input().split()]) for m in range(m_max): b.append([int(x) for x in input().split()]) for n in range(n_max): c.append( [sum(a[n][m] * b[m][l] for m in range(m_max)) for l in range(l_max)]) for n in range(n_max): print(" ".join(str(c[n][l]) for l in range(l_max)))
1
1,438,694,673,920
null
60
60
import math r = float(raw_input()) print ('%.6f' % (r*r*math.pi)), print ('%.6f' % (r*2*math.pi))
import math r = float(input()) S = math.pi * r * r L = 2 * math.pi * r print("{0:.10f}".format(S),end=" ") print("{0:.10f}".format(L))
1
649,345,891,908
null
46
46
l,r,d = [int(x) for x in input().split(' ')] st = (l+d-1)//d en = r//d print(en-st+1)
n, m = map(int, input().split()) a = [int(x) for x in input().split()] s = sum(a) print('Yes' if len(list(filter(lambda x : x >= s * (1/(4*m)), a))) >= m else 'No')
0
null
23,037,418,824,992
104
179
import itertools import math n = int(input()) #座標のリスト xy_list = [] for i in range(n) : xy_list.append(list(map(int, input().split()))) #順列を生成 per_list = [] for j in itertools.permutations([x for x in range(n)]) : per_list.append(j) #順列に従って距離を加算 d = 0 for k in per_list : for l in range(n - 1) : d += math.sqrt((xy_list[k[l + 1]][0] - xy_list[k[l]][0]) ** 2 + (xy_list[k[l + 1]][1] - xy_list[k[l]][1]) ** 2) print(d/(len(per_list)))
n,m = map(int,input().split()) li = [list(map(int,input().split())) for _ in range(m)] if n==1 and all([i[1]==0 for i in li]): print(0) exit() for i in range(10**(n-1),10**n): p = list(map(int,list(str(i)))) for s,c in li: if p[s-1] != c:break else: print(i) exit() print(-1)
0
null
104,385,845,577,728
280
208
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 = int(readline()) print((N+1) // 2) return if __name__ == '__main__': main()
# ??\????????? N = int(input()) r = [int(input()) for i in range(N)] # ?????§????¨???? max_profit = (-1) * (10 ** 9) min_value = r[0] for j in range(1, len(r)): max_profit = max(max_profit, r[j] - min_value) min_value = min(min_value, r[j]) print(max_profit)
0
null
29,429,486,554,032
206
13
li=["SUN","MON","TUE","WED","THU","FRI","SAT"] day=input() for i in range(7): if(li[i]==day): print(7-i)
#template def inputlist(): return [int(j) for j in input().split()] #template N,K = inputlist() p = inputlist() p.sort() ans = 0 for i in range(K): ans +=p[i] print(ans)
0
null
72,138,995,538,070
270
120
deglist = raw_input().split(" ") a = int(deglist[0]) b = int(deglist[1]) c = int(deglist[2]) cnt = 0 for x in range(a, b+1): if c % x == 0: cnt += 1 print cnt
n=int(input()) a=[int(i) for i in input().split()] a.sort() prod=1 for i in a: prod*=i if prod>10**18: break if prod>10**18: print(-1) else: print(prod)
0
null
8,304,477,097,308
44
134
from functools import lru_cache @lru_cache(maxsize=None) def solve(i, count): global ans global a if count >= N: return if ans[i][0] == -1: ans[i][0] = count elif ans[i][0] > count: ans[i][0] = count for x in range(a[i][1]): solve(a[i][2 + x] - 1, count + 1) N = int(input()) a = [] for _ in range(N): a.append([int(x) for x in input().split()]) ans = [[-1 for i in range(1)] for j in range(N)] solve(0, 0) for i, x in enumerate(ans): print(i + 1, *x)
from sys import stdin from collections import deque n = int(stdin.readline()) g = [None] * n for _ in range(n): u, _, *cs = [int(s) for s in stdin.readline().split()] g[u-1] = [c - 1 for c in cs] ds = [-1] * n v = [False] * n v[0] = True q = deque([(0, 0)]) while len(q): u, d = q.popleft() ds[u] = d for c in g[u]: if not v[c]: v[c] = True q.append((c, d + 1)) for u, d in enumerate(ds): print(u + 1, d)
1
3,991,928,720
null
9
9
def choose_hand(last,next): for j in ['r','s','p']: if j!=last and j!=next: return j n,k = map(int,input().split()) r,s,p = map(int,input().split()) points = {'r':r, 's':s, 'p':p} hands = {'r':'p', 's':'r', 'p':'s'} t = list(input()) rpsList = ['']*n ans = 0 for i,hand in enumerate(t): rpsList[i] += hands[hand] if i>=k and rpsList[i]==rpsList[i-k]: lastHand = rpsList[i-k] nextHand = hands[t[i+k]] if i+k<n else '' rpsList[i] = choose_hand(lastHand,nextHand) else: ans += points[hands[hand]] print(ans)
import sys,itertools,collections,bisect from collections import deque,Counter,defaultdict from heapq import heappush,heappop,heapify read=sys.stdin.readline sys.setrecursionlimit(10**6) MOD=10**9+7 N=int(input()) A=list(map(int,input().split())) cum=[0]*(N+1) for i in range(N): cum[i+1]=(cum[i]+A[i])%MOD ans=0 for i in range(N): res=(cum[N]-cum[i+1]+MOD)%MOD*A[i]%MOD ans=(ans+res)%MOD print(ans)
0
null
55,112,581,197,582
251
83
import math # one = 1000000000000001 dict={1:"a",2:"b",3:"c",4:"d",5:"e",6:"f",7:"g",8:"h",9:"i",10:"j", 11:"k",12:"l",13:"m",14:"n",15:"o",16:"p",17:"q",18:"r",19:"s",20:"t", 21:"u",22:"v",23:"w",24:"x",25:"y",26:"z"} n=int(input()) ans = "" while n: ans = str(dict[(n-1)%26+1]) + ans n=(n-1)//26 print(ans)
def check_weather(weathers: str) -> int: count = weathers.count('R') return 1 if weathers[1] == 'S' and count == 2 else count if __name__=='__main__': print(check_weather(input()))
0
null
8,313,561,668,120
121
90
n = int(input()) s = input() count = 1 for h in range(len(s)-1): if s[h] != s[h+1]: count += 1 print(count)
import sys L = int(input()) print((L / 3) ** 3)
0
null
108,788,709,617,992
293
191
from collections import deque h,w = map(int, input().split()) hw = [input() for _ in range(h)] def bfs(s): que = deque([s]) m = [[-1]*w for _ in range(h)] sh, sw = s m[sh][sw] = 0 ret = 0 while que: now_h, now_w = que.popleft() for dh, dw in [(1,0), (-1,0), (0,-1), (0,1)]: nh = now_h + dh nw = now_w + dw if not (0<=nh<h and 0<=nw<w) or m[nh][nw] != -1 or hw[nh][nw] == '#': continue m[nh][nw] = m[now_h][now_w] + 1 que.append((nh,nw)) ret = max(ret, m[now_h][now_w] + 1) return ret ans = 0 for y in range(h): for x in range(w): if hw[y][x] == '#': continue s = (y, x) ans = max(bfs(s), ans) print(ans)
H,W=map(int,input().split()) S=[list(input())for _ in range(H)] from collections import deque def bfs(h,w,sy,sx,S): maze=[[10**9]*(W)for _ in range(H)] maze[sy-1][sx-1]=0 que=deque([[sy-1,sx-1]]) count=0 while que: y,x=que.popleft() for i,j in [(1,0),(0,1),(-1,0),(0,-1)]: nexty,nextx=y+i,x+j if 0<=nexty<h and 0<=nextx<w: dist1=S[nexty][nextx] dist2=maze[nexty][nextx] else: continue if dist1!='#': if dist2>maze[y][x]+1: maze[nexty][nextx]=maze[y][x]+1 count=max(count,maze[nexty][nextx]) que.append([nexty,nextx]) return count ans=0 for sy in range(H): for sx in range(W): if S[sy][sx]=='.': now=bfs(H,W,sy+1,sx+1,S) ans=max(ans,now) print(ans)
1
94,613,443,934,670
null
241
241
import math def insertionsort(A, n, g): cnt = 0 for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j + g] = A[j] j = j - g cnt += 1 A[j + g] = v return cnt def shellsort(A, n): G = [] gap = 1 while gap <= math.ceil(n / 3): G.append(gap) gap = gap * 3 + 1 G = G[::-1] m = len(G) print(m) print(*G) cnt = 0 for i in range(m): cnt += insertionsort(A, n, G[i]) print(cnt) n = int(input()) A = [] for i in range(n): A.append(int(input())) shellsort(A, n) for i in range(n): print(A[i])
import sys def print_arr(arr): for i in range(len(arr)): sys.stdout.write(str(arr[i])) if i != len(arr) - 1: sys.stdout.write(' ') print() def insertion_sort(arr, g): n = len(arr) cnt = 0 for i in range(n): key = arr[i] j = i - g while j >= 0 and arr[j] > key: arr[j + g] = arr[j] j -= g cnt += 1 arr[j + g] = key return cnt def shell_sort(arr, G): cnt = 0 for i in range(len(G)): cnt += insertion_sort(arr, G[i]) return cnt def get_gaps(n): lst = [] v = 1 cnt = 1 while v <= n: lst.append(v) v += 3**cnt cnt += 1 if len(lst) == 0: lst.append(1) return list(reversed(lst)) n = int(input()) arr = [None] * n for i in range(n): arr[i] = int(input()) G = get_gaps(n) cnt = shell_sort(arr, G) print(len(G)) print_arr(G) print(cnt) for i in range(n): print(arr[i])
1
30,978,384,162
null
17
17
n=int(input()) a=list(map(int,input().split())) if a[0]!=0: print(0) exit() r=1 b=0 g=0 pos=3 for i in range(1,n): pre=0 de=0 if a[i]==r: pre += 1 r += 1 de=1 if a[i]==b: pre += 1 if de==0: b += 1 de=1 if a[i]==g: pre += 1 if de==0: g += 1 pos *= pre print(pos%(10**9+7))
import itertools as it n, A = int(input()), [*map(int, input().split())] yes_nums = set() for bools in it.product([True, False], repeat=n): yes_nums.add(sum(A[i] for i in range(n) if bools[i])) _ = input() for m in map(int, input().split()): print("yes" if m in yes_nums else "no")
0
null
65,431,586,523,912
268
25
# coding:utf-8 array = map(int, raw_input().split()) n = array[0] m = array[1] a = [[0 for i in range(m)] for j in range(n)] b = [0 for i in range(m)] answer = [0 for i in range(n)] for i in range(n): a[i] = map(int, raw_input().split()) for j in range(m): b[j] = input() for i in range(n): for j in range(m): answer[i] += a[i][j] * b[j] for i in range(n): print answer[i]
k = int(input()) a = [7%k] for i in range(1, k): a.append((a[i-1]*10+7)%k) for i in range(k): if a[i] == 0: print(i+1) exit() print(-1)
0
null
3,690,362,235,532
56
97
n = int(input()) mod = 10**9+7 ans = pow(10,n) ans -= pow(9,n)*2 ans += pow(8,n) print(ans%mod)
import itertools n = int(input()) p = [[0 for i in range(2)] for j in range(n)] for i in range(n): p[i][0],p[i][1] = map(int,input().split()) #print(p) def dis(a,b): dis = (a[0]-b[0]) ** 2 + (a[1]-b[1]) **2 return dis ** (1/2) perm = [i for i in range(n)] total = 0 num = 0 for v in itertools.permutations(perm,n): path = 0 for i in range(n-1): path += dis(p[v[i]],p[v[i+1]]) num += 1 total += path print(total/num)
0
null
75,481,670,313,358
78
280
#import numpy as np import sys, math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial#, gcd from bisect import bisect_left, bisect_right #bisect_left(list, value) sys.setrecursionlimit(10**7) enu = enumerate MOD = 2019 def input(): return sys.stdin.readline()[:-1] pl = lambda x: print(*x, sep='\n') S = input() N = len(S) d = defaultdict(int) d[0] += 1 # nums = [0]*(N+1) m = 0 last = 0 dd = 1 for i in range(N): m += int(S[N-i-1])*dd m %= MOD # val = (int(S[i])*m + nums[i])%MOD # cnt += d[val] dd = (dd*10)%MOD d[m] += 1 cnt = 0 for i, v in d.items(): cnt += v*(v-1)//2 print(cnt)
total, max, time=map(int, input().split()) print (time*int(total/max) if total%max==0 else time*(int(total/max)+1))
0
null
17,630,224,892,800
166
86
n = int(input()) li = list(map(int, input().split())) print(min(li), max(li), sum(li))
n = input() l = [int(i) for i in input().split()] print(' '.join([str(min(l)),str(max(l)),str(sum(l))]))
1
726,881,651,648
null
48
48
def sep(): return map(int,input().strip().split(" ")) def lis(): return list(sep()) import sys sys.setrecursionlimit(10**6) n=int(input()) k=(n//500)*1000 t=((n%(500))//5)*5 print(k+t)
# coding: utf-8 import math import numpy as np #N = int(input()) #A = list(map(int,input().split())) x = int(input()) #x, y = map(int,input().split()) for i in range(1,10**5): if (i*x)%360==0: print(i) break
0
null
27,972,995,750,084
185
125
x = int(input()) import math print(360*x//math.gcd(360,x)//x)
def a(): x = int(input()) k = 1 while (k * x) % 360 != 0: k += 1 print(k) a()
1
13,080,752,152,658
null
125
125
def mult(num): print(int(num[0])*int(num[1])) num = input().split() mult(num)
number = list(map(int, input().split())) print(number[0]*number[1])
1
15,925,715,779,612
null
133
133
N = int(input()) s = input() ans = min(s.count('R'), s.count('W'), s[N-s.count('W'):].count('R')) print(ans)
import sys input = sys.stdin.readline N = int(input()) S = input()[:-1] R = S.count('R') accR = [0] for Si in S: accR.append(accR[-1]+(1 if Si=='R' else 0)) ans = 10**18 for i in range(N+1): ans = min(ans, abs(i-R)+abs(i-accR[i])) print(ans)
1
6,314,546,027,340
null
98
98
def ST(A,k): #標準形の文字列を与えたときに #長さが1大きい標準形の文字列の集合を出力 OP = [] for a in A: max_cord = 0 for i in range(len(a)): max_cord = max(ord(a[i]),max_cord) for i in range(97,max_cord+2): OP.append(a+chr(i)) return OP N = int(input()) n,A = 1,["a"] while n < N: A = ST(A,n) n += 1 A.sort() for i in range(len(A)): print(A[i])
n=int(input()) def make(floor,kind,name): #floor=何階層目か,kind=何種類使ってるか if floor==n+1: print(name) return num=min(floor,kind+1) for i in range(num): use=0 #新しい文字使ってるか if kind-1<i: use=1 make(floor+1,kind+use,name+chr(i+97)) make(1,0,"")
1
52,534,091,083,904
null
198
198
def atc_160b(X: int) -> int: return X // 500 * 1000 + X % 500 // 5 * 5 X_input = int(input()) print(atc_160b(X_input))
import math r = float(raw_input()) print '%.5f %.5f' % (r*r*math.pi, 2*r*math.pi)
0
null
21,585,593,262,870
185
46
# -*- coding: utf-8 -*- import sys from collections import deque N,D,A=map(int, sys.stdin.readline().split()) XH=[ map(int, sys.stdin.readline().split()) for _ in range(N) ] XH.sort() q=deque() #(攻撃が無効となる座標、攻撃によるポイント) ans=0 cnt=0 attack_point=0 for x,h in XH: while q: if x<q[0][0]:break #無効となる攻撃がない場合はwhileを終了 end_x,end_point=q.popleft() attack_point-=end_point #攻撃が無効となる座標<=現在の座標があれば、その攻撃のポイントを引く if h<=attack_point: #モンスターの体力よりも攻撃で減らせるポイントの方が大きければ新規攻撃は不要 pass else: #新規攻撃が必要な場合 if h%A==0: cnt=(h-attack_point)/A #モンスターの大量をゼロ以下にするために何回攻撃が必要か else: cnt=(h-attack_point)/A+1 attack_point+=cnt*A q.append((x+2*D+1,cnt*A)) #(攻撃が無効となる座標、攻撃によるポイント)をキューに入れる ans+=cnt print ans
N, K = map(int, input().split()) expectation = list(map(lambda x: (x+1) / 2, map(int, input().split()))) cur_expectation = sum(expectation[:K]) max_expectation = cur_expectation for i in range(N - K): cur_expectation -= expectation[i] cur_expectation += expectation[i + K] if cur_expectation > max_expectation: max_expectation = cur_expectation print(max_expectation)
0
null
78,472,213,761,380
230
223
N,K = map(int,input().split()) P = list(map(lambda x:int(x)-1,input().split())) C = list(map(int,input().split())) ans = -float('inf') for i in range(N): visited = set() tmp = 0 for k in range(K): if P[i] in visited: break tmp += C[P[i]] i = P[i] visited.add(i) ans = max(ans, tmp) if tmp < 0: continue l = len(visited) rem = K-l d,m = divmod(rem,l) if m==0 and d > 0: m = l d -= 1 tmp *= (d+1) for k in range(m): tmp += C[P[i]] i = P[i] ans = max(ans, tmp) print(ans)
import sys for line in sys.stdin: if line.find("?") != -1: break print(int(eval(line)))
0
null
2,991,907,587,348
93
47
n = int(input()) arr = [int(x) for x in input().split()] q = int(input()) dictA = {} for i in arr: if dictA.get(i): dictA[i] += 1 else: dictA[i] = 1 summ = sum(arr) for i in range(q): b, c = list(map(int, input().split())) if dictA.get(b): summ = summ - (dictA[b]*b) + (dictA[b]*c) if dictA.get(c): dictA[c] += dictA[b] else: dictA[c] = dictA[b] del dictA[b] print(summ)
n = int(input()) al = list(map(int, input().split())) num_cnt = {} c_sum = 0 for a in al: num_cnt.setdefault(a,0) num_cnt[a] += 1 c_sum += a ans = [] q = int(input()) for _ in range(q): b,c = map(int, input().split()) num_cnt.setdefault(b,0) num_cnt.setdefault(c,0) diff = num_cnt[b]*c - num_cnt[b]*b num_cnt[c] += num_cnt[b] num_cnt[b] = 0 c_sum += diff ans.append(c_sum) for a in ans: print(a)
1
12,214,931,696,550
null
122
122
import sys from functools import reduce def gcd(a, b): return gcd(b, a % b) if b else abs(a) def lcm(a, b): return abs(a // gcd(a, b) * b) n, m, *a = map(int, sys.stdin.read().split()) def main(): for i in range(n): a[i] //= 2 b = set() for x in a: cnt = 0 while x % 2 == 0: x //= 2 cnt += 1 b.add(cnt) if len(b) == 2: print(0); return l = reduce(lcm, a, 1) res = (m // l + 1) // 2 print(res) if __name__ == '__main__': main()
str = list(input()) for _ in range(int(input())): cmd = input().split() a, b = map(int, cmd[1:3]) if cmd[0] == 'print': for i in range(a, b + 1): print(str[i], end='') print('') if cmd[0] == 'reverse': str = str[:a] + list(reversed(str[a:b + 1])) + str[b + 1:] if cmd[0] == 'replace': p = cmd[3] str = str[:a] + list(p) + str[b + 1:]
0
null
51,828,389,383,300
247
68
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): K, X = map(int, readline().split()) if 500 * K >= X: print('Yes') else: print('No') if __name__ == '__main__': main()
from collections import Counter n = int(input()) x = list(map(int, input().split())) a = [] b = [] for i in range(n): a.append(i+1+x[i]) b.append(i+1-x[i]) ans = 0 a, b = Counter(a), Counter(b) for i in range(min(a), max(b)+1): ans += a[i]*b[i] print(ans)
0
null
62,129,311,763,722
244
157
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) from collections import Counter def resolve(): N, K, C = lr() S = [i+1 for i, s in enumerate(sr()) if s == 'o'] l = [S[0]] for i in S[1:]: if l[-1]+C >= i or len(l) > K: continue l.append(i) S = S[::-1] r = [S[0]] for i in S[1:]: if r[-1]-C <= i or len(r) > K: continue r.append(i) r = r[::-1] for i in range(K): if l[i] == r[i]: print(l[i]) resolve()
n = int(raw_input()) _min, dif = 10**10, -10**10 for x in xrange(n): a = int(raw_input()) if a -_min > dif: dif = a - _min if a < _min: _min = a print dif
0
null
20,206,306,107,508
182
13
N = int(input()) ans = N - 1 for i in range(2, int((N ** 0.5) + 1)): if N % i == 0: j = N // i m = i + j - 2 ans = min(ans, m) print(ans)
N = int(input()) res = 0 for i in range(int(N**0.5)): if(N % (i+1) == 0): res = max(res, i+1) print((res-1) + (N//res-1))
1
162,213,655,924,570
null
288
288
#!/usr/bin/python3 #coding: utf-8 N = int(input()) p = 10**9 + 7 ret = pow(10, N) ret -= pow(9, N) ret -= pow(9, N) ret += pow(8, N) ret %= p print(ret)
def popcount(x): return bin(x).count("1") n=int(input()) x=input() num=int(x,2) cnt=popcount(num) A=[] for i in range(n): number=num if x[i]=="1" and cnt==1:A.append(-1) elif x[i]=="1": number %=cnt-1 A.append((number-pow(2,n-i-1,cnt-1))%(cnt-1)) else: number %=cnt+1 A.append((number+pow(2,n-i-1,cnt+1))%(cnt+1)) for i in A: ans=i if ans==-1:print(0) else: point=1 while ans!=0: ans %=popcount(ans) point +=1 print(point)
0
null
5,668,303,399,808
78
107
N, M, X = map(int, input().split()) CA = [list(map(int, input().split())) for _ in range(N)] sum_money = float("inf") for i in range(2 ** N): money = 0 algorithm = [0]*M for j in range(N): if (i >> j) & 1 == 1: money += CA[j][0] for k in range(M): algorithm[k] += CA[j][k+1] check = True for l in algorithm: if l < X: check = False if check: sum_money = min(sum_money, money) print(sum_money if sum_money != float("inf") else -1)
def main(): n, kk = map(int, input().split()) mod = 10**9+7 fact = [1, 1] for i in range(2, 2*10**5+1): fact.append(fact[-1]*i % mod) def nCr(n, r, mod=10**9+7): return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod ans = [1] for k in range(1, n): ans.append(nCr(n-1, k)*nCr(n, k) % mod) print(sum(ans[:min(kk+1, n)]) % mod) main()
0
null
44,697,731,831,340
149
215
k=int(input()) s=input() n=len(s) if(n<=k): print(s) else: print(s[:k]+'...')
N=int(input()) A=list(map(int,input().split())) t=[0]*N for idx,i in enumerate(A): t[i-1]=idx+1 print(*t)
0
null
99,998,255,446,570
143
299
import sys input = lambda: sys.stdin.readline().rstrip() def main(): D = int(input()) c = [0] + list(map(int, input().split())) s = [[0]*27] t = [0] satisfy = 0 last = [0] * 27 for _ in range(D): s.append([0] + list(map(int, input().split()))) for _ in range(D): t += [int(input())] for i in range(1, D+1): decrease = 0 last[t[i]] = i for j in range(1, 27): decrease += (c[j] * (i - last[j])) satisfy += (s[i][t[i]] - decrease) print(satisfy) if __name__ == '__main__': main()
import numpy as np D = int(input()) c = np.array( list(map(int, input().split())) ) s = [[] for i in range(365+1)] for i in range(D): s[i] = np.array( list(map(int, input().split())) ) # last = np.array( [-1]*26 ) av = np.array( [0]*26 ) id = np.identity(4,dtype=int) v = 0 for d in range(D): av = s[d] - sum( c*(d-last) ) + c*(d-last) t = int(input()) t -= 1 last[t] = d v += av[t] print( v ) #
1
9,962,242,436,060
null
114
114
num=int(input()) num2=[10, 9 ,8] def multi(x): y=x**num return y a, b, c=map(multi, num2) print((a-2*b+c)%(int(1e9+7)))
n=int(input()) num=10**n-9**n-9**n+8**n ans=num%(10**9+7) print(ans)
1
3,183,617,321,304
null
78
78
a,b=input().split() a=int(a) b=int(b) if a==b: print("Yes") else: print("No")
#Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque import threading threading.stack_size(10**8) sys.setrecursionlimit(300000) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- n=int(input()) ans=0 d=defaultdict(int) d1=defaultdict(int) m=-10**13 m1=-10**13 mi=10**13 mi1=10**13 for i in range(n): a,b=map(int,input().split()) m=max(m,a+b) mi=min(mi,a+b) m1=max(m1,a-b) mi1=min(mi1,a-b) #print(mi,mi1,m,m1) print(max(m-mi,m1-mi1))
0
null
43,498,382,522,080
231
80
N = int(input()) A = list(map(int, input().split())) count = 0 for item in A: if item % 2 == 0: if item % 3 == 0 or item % 5 == 0: count += 1 else: count += 1 if count == N: print("APPROVED") else: print("DENIED")
from collections import defaultdict, deque import sys, heapq, bisect, math, itertools, string, queue, copy, time from fractions import gcd import numpy as np sys.setrecursionlimit(10**8) INF = float('inf') MOD = 10**9+7 EPS = 10**-7 s = input() if s == 'AAA' or s == 'BBB': ans = 'No' else: ans = 'Yes' print(ans)
0
null
61,834,152,579,456
217
201
from collections import defaultdict n, k = map(int, input().split()) A = list(map(int, input().split())) accm = [0] * (n + 1) for i in range(n): accm[i + 1] = accm[i] + A[i] li = [(val - itr) % k for itr, val in enumerate(accm)] ans = 0 box = defaultdict(int) for i in range(n + 1): if i >= k: box[li[i - k]] -= 1 ans += box[li[i]] box[li[i]] += 1 print(ans)
import math p = map(float, raw_input().split()) print("%.10f" %(math.sqrt((p[2] - p[0]) * (p[2] - p[0]) + (p[3] - p[1]) * (p[3] - p[1]))))
0
null
69,112,098,772,640
273
29
n = int(input()) print(" ".join(reversed(input().split())))
s = input() if s.count('A') == 0 or s.count('B') == 0: print('No') else: print('Yes')
0
null
27,757,972,914,000
53
201
n = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for i, a in enumerate(L[2:]): k = i + 1 for j, b in enumerate(L[:i + 2]): while j < k and a - b < L[k]: k -= 1 ans += i - max(k, j) + 1 print(ans)
import bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) N = I() L = LI() # L = np.array(_L) #C = np.zeros(N + 1) # def test(a,b,c): # if a<b+c and b<c+a and c<a+b: # return True # return False # count = 0 # for pair in itertools.combinations(L, 3): # # print(pair) # if test(*pair): # count += 1 # print(count) # for i in range(N): # for j in range(i+1,N): from numba import njit @njit def f(A): count = 0 for i in range(N): for j in range(i + 1, N): for k in range(j + 1, N): count += (A[k] < A[i] + A[j]) return count A = np.array(L) A.sort() print(f(A))
1
171,743,168,052,000
null
294
294
def bubble_sort(a,n): m=0 flag=True while(flag): flag=False for i in range(n-1,0,-1): if(a[i-1] > a[i]): tmp=a[i-1] a[i-1]=a[i] m+=1 a[i]=tmp flag=True b=list(map(str,a)) print(" ".join(b)) print(m) a=[] n=int(input()) s=input() a=list(map(int,s.split())) bubble_sort(a,n)
n = int(input()) numbers = [int(i) for i in input().split(" ")] flag = 1 cnt = 0 while flag: flag = 0 for j in range(n - 1, 0, -1): if numbers[j] < numbers[j - 1]: numbers[j], numbers[j - 1] = numbers[j - 1], numbers[j] flag = 1 cnt += 1 numbers = map(str, numbers) print(" ".join(numbers)) print(cnt)
1
17,553,632,250
null
14
14
n = list(map(int, input().split())) result = "Yes" if sum(n) % 9 == 0 else "No" print(result)
number = list(input()) sum = 0 for i in number: sum += int(i) if (sum % 9) == 0 : print("Yes") else: print("No")
1
4,415,845,715,142
null
87
87
s = input() l = len(s) ss = "" for x in range(l): ss = ss+'x' print(ss)
def resolve(): s = input() print('x'*len(s)) resolve()
1
72,684,056,299,958
null
221
221
k = int(input()) a, b = map(int, input().split()) x = 0 while True: x += k if a <= x <= b: print('OK') break if x > b: print('NG') break
K=int(input()) A,B=map(int,input().split()) for i in range(A,B+1): if i%K==0: print('OK') exit() print('NG')
1
26,604,001,782,732
null
158
158
#176-B N = input() sum = 0 for i in range(1,len(N)+1): sum += int(N[-i]) if int(sum) % 9 == 0: print('Yes') else: print('No')
A, B, C = map(int, input().split()) print(C, A, B)
0
null
21,290,063,607,022
87
178
from math import pi print(2 * pi * int(input()), end='\n')
n = int(input()) s = input() print(len(s.split('ABC')) - 1)
0
null
65,671,471,861,340
167
245
a,b = map(float, raw_input().split()) if b > 10**6: f = 0.0 else: f = a/b d = int(a/b) r = int(a%b) print d, r, f
a,b = map(int,input().split()) print('%d %d %.10f'%(a/b,a%b,a/b))
1
612,910,001,692
null
45
45
N = input() if '7' in N: print('Yes') exit() else: print('No')
N = str(input()) for i in range(3): if N[i] == '7': print('Yes') quit() print('No')
1
34,233,442,239,726
null
172
172
if __name__ == '__main__': N = int(input()) l = input().split() num = [int(i) for i in l] print(min(num), max(num), sum(num))
t=list(input()) if t[0]=='?': t[0]=t[0].replace('?','D') for i in range(1,len(t)-1): if t[i]=='?' and t[i+1]=='D' and t[i-1]=='P': t[i]=t[i].replace('?','D') elif t[i]=='?' and t[i+1]=='P' and t[i-1]=='P': t[i]=t[i].replace('?','D') elif t[i]=='?' and t[i+1]=='D' and t[i-1]=='D': t[i]=t[i].replace('?','P') elif t[i]=='?' and t[i+1]=='P' and t[i-1]=='D': t[i]=t[i].replace('?','D') elif t[i]=='?' and t[i+1]=='?' and t[i-1]=='D': t[i]=t[i].replace('?','P') elif t[i]=='?' and t[i+1]=='?' and t[i-1]=='P': t[i]=t[i].replace('?','D') if t[-1]=='?': t[-1]=t[-1].replace('?','D') for i in t: print(i,end='')
0
null
9,693,096,898,618
48
140
import math n = int(input()) X = list(map(int, input().split())) Y = list(map(int, input().split())) D = [abs(X[i]-Y[i]) for i in range(n)] for p in [1, 2, 3, -1]: if p == -1: print(max(D)) else: print(math.pow(sum([math.pow(D[i],p) for i in range(n)]),1/p))
cards = { 'S':[r for r in range(1,13+1)], 'H':[r for r in range(1,13+1)], 'C':[r for r in range(1,13+1)], 'D':[r for r in range(1,13+1)] } n = int(input()) for nc in range(n): (s,r) = input().split() index = cards[s].index(int(r)) del cards[s][index] for s in ['S','H','C','D']: for r in cards[s]: print(s,r)
0
null
643,747,506,230
32
54
A, B, K = [int(x) for x in input().split()] if A >= K: print("{} {}".format(A-K, B)) exit() K -= A A = 0 if B >= K: print("{} {}".format(A, B-K)) exit() print("{} {}".format(0, 0))
# ABC149 # B Greesy Takahashi # takはA枚、aokiはB枚、TAKはK回 a, b, k = map(int, input().split()) if k > a: if k - a > b: print(0,0) else: print(0,b - (k - a)) else: print(a-k,b)
1
104,288,621,191,022
null
249
249
import sys n = int(input()) for i in range(int(n / 1.08), int(n / 1.08) + 2): if int(i * 1.08) == n: print(i) sys.exit() else: print(":(")
n = int(input()) r = n % 27 if r == 13 or r == 26: print(':(') elif r ==0: x = int(100*n/108) print(x) else: for i in range(1, 25): if 1.08*(i-1) < r <= 1.08*i: break x = int(100*(n - i)/108) + i print(x)
1
125,586,821,991,390
null
265
265
def draw(h,w): s = "#" * w for i in range(0,h): print s print if __name__ == "__main__": while True: h,w = map(int, raw_input().split()) if h==0 and w==0: break else: draw(h,w)
while True: h,w = map(int,input().split()) if h == w == 0: break for x in range(int(h)): for y in range(int(w)): print("#",end="") print("") print("")
1
779,532,120,262
null
49
49
while 1: r=0 S=0 n=int(input()) if n==0:break s=list(map(int,input().split())) a=(sum(s)/n) for i in s: S=((a-i)**2)/n r+=S print(r**0.5)
from statistics import pstdev, variance, mean while 1: num = int(input()) if num == 0: break else: data = list(map(int, input().split())) st = float(pstdev(data)) print(st)
1
198,397,356,882
null
31
31
import sys input = sys.stdin.readline m = [1, 1] + [None]*50 def fibonacci(n): if m[n-2]: pass else: fibonacci(n-2) if m[n-1]: pass else: fibonacci(n-1) m[n] = m[n-1] + m[n-2] N = int(input()) fibonacci(44) print(m[N])
n=int(input()) x=0 y=1 if n==0 or n==1: print(1) else: for i in range(n): x,y=y,x+y i+=1 print(y)
1
1,698,836,558
null
7
7
s=input() for _ in range(int(input())): a=input().split() i,j=map(int, a[1:3]) if a[0] == "print": print(s[i:j+1]) elif a[0] == "reverse": t1=s[0:i] t2=list(s[i:j+1]) t2.reverse() t3=s[j+1:] s=t1+"".join(t2)+t3 else: s=s[0:i]+a[3]+s[j+1:]
in_str = raw_input() q = input() for i in xrange(q): order = raw_input().split() a = int(order[1]) b = int(order[2])+1 if order[0] == "print": print in_str[a:b] if order[0] == "reverse": temp_str = in_str[a:b] in_str = in_str[:a] + temp_str[::-1] + in_str[b:] if order[0] == "replace": in_str = in_str[:a] + order[3] + in_str[b:]
1
2,117,505,269,152
null
68
68
def main(): S = input().rstrip() if S[-1] == "s": S = S + "es" else: S = S + "s" print(S) main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) n = I() def yaku(m): ans = [] i = 1 while i*i <= m: if m % i == 0: j = m // i ans.append(i) i += 1 ans = sorted(ans) return ans a = yaku(n) #print(a) ans = float('inf') for v in a: ans = min(ans, (v-1)+(n//v)-1) print(ans)
0
null
82,067,603,143,420
71
288
import fractions A,B=map(int,input().split()) def lcm(x,y): return int((x*y)/fractions.gcd(x,y)) print(lcm(A,B))
from fractions import gcd n, m = map(int, input().split()) print(n * m // gcd(n, m))
1
113,357,447,358,050
null
256
256
import sys r,g,b=map(int,input().split()) k=int(input()) for i in range(k+1): if r<g<b: print("Yes") sys.exit() else: if r<=b<=g: b*=2 elif b<=r<=g: b*=2 elif b<=g<=r: b*=2 elif g<=r<=b: g*=2 elif g<=b<=r: b*=2 print("No")
N,K = [int(i) for i in input().split()] H = [int(i) for i in input().split()] ans = 0 for i in range(N): if K <= H[i]: ans += 1 print(ans)
0
null
92,571,415,508,420
101
298
a = input() b = a[:3] print(b)
s=list(input()) print(s[0]+s[1]+s[2])
1
14,748,974,250,098
null
130
130
N = int(input()) An = list(map(int, input().split())) An.sort(reverse=True) answer = 0 t = N-1 for i, Ai in enumerate(An): lim = 2 if i==0: lim = 1 for j in range(lim): if t > 0: answer += Ai t -= 1 print(answer)
import itertools import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) # x1+x2+x3+...xN = X (x>=0) def nHk_list(N,X): if N == 0: return [] elif N == 1: return [[X]] border = [i for i in range(X+1)] res = [] for S in itertools.combinations_with_replacement(border, N-1): # print(S) pre = 0 sub = [] for s in S: sub.append(s-pre) pre = s sub.append(X-pre) res.append(sub) return res INF=10**20 def main(): N=ii() alphabet = ["a","b","c","d","e","f","g","h","i","j"] ans = [] for c in range(1,N+1): # print("___\nc",c) for X in nHk_list(c,N-c): # print("X:",X,"c:",c,"N-c:",N-c) V = [] for i in range(len(X)): x = X[i] V.append(list(itertools.product(alphabet[:i+1],repeat=x))) # print("V",V) U = itertools.product(*V) base = alphabet[:c] for u in U: char = "" for i in range(c): char += alphabet[i] + "".join(list(u[i])) ans.append(char) ans.sort() # ans.append("".join(alphabet[:N])) print(*ans,sep='\n') if __name__ == "__main__": main()
0
null
30,857,901,378,720
111
198
import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(input()) def II(): return map(int, input().split()) def III(): return list(map(int, input().split())) def Line(N,num): if N<=0: return [[]]*num elif num==1: return [I() for _ in range(N)] else: read_all = [tuple(II()) for _ in range(N)] return map(list, zip(*read_all)) ################# from bisect import bisect_left #Binary Indexed Tree(区間加算) #1-indexed class Range_BIT(): def __init__(self, N): self.size = N self.data0 = [0]*(N+1) self.data1 = [0]*(N+1) def _add(self, data, k, x): while k <= self.size: data[k] += x k += k & -k # 区間[l,r)にxを加算 def add(self, l, r, x): self._add(self.data0, l, -x*(l-1)) self._add(self.data0, r, x*(r-1)) self._add(self.data1, l, x) self._add(self.data1, r, -x) def _get(self, data, k): s = 0 while k: s += data[k] k -= k & -k return s # 区間[l,r)の和を求める def query(self, l, r): return self._get(self.data1, r-1)*(r-1)+self._get(self.data0, r-1)\ -self._get(self.data1, l-1)*(l-1)-self._get(self.data0, l-1) N,M = II() A = III() A.sort() def is_ok(x): num = 0 for a in A: p = bisect_left(A,x-a) num += N-p if num>=M: return True else: return False #l:その値以上の幸福度の握手がM通り以上ある最大値 l = 0 r = 2*10**5 + 1 while abs(r-l)>1: mid = (l+r)//2 if is_ok(mid): l = mid else: r = mid #値l以上の握手で用いるA[i]の個数を調べる bit = Range_BIT(N) for i in range(1,N+1): p = bisect_left(A,l-A[i-1]) if p!=N: bit.add(p+1,N+1,1) bit.add(i,i+1,N-p) x = [0]*N for i in range(N): x[i] = bit.query(i+1,i+2) ans = 0 for i in range(N): ans += A[i]*x[i] #握手の回数がM回になるように調整 ans -= l*((sum(x)-2*M)//2) print(ans)
n = int(input()) dp = [0]*(n+1) def fibo(n): if n <2: return 1 if dp[n] > 0: return dp[n] dp[n] = fibo(n-1) + fibo(n -2) return dp[n] print(fibo(n))
0
null
54,311,705,633,850
252
7
count =[[[0]*10 for j in range(3)] for k in range(4)] n = int(input()) for x in range(n): b,f,r,v = map(int,input().split()) # 1 <= b <=4 # 1 <= f <= 3 # 1 <= r <= 10 # 1 <= v <= 9 count[b-1][f-1][r-1] += v for i in range(4): if i != 0: print("#"*20) for j in range(3): for k in range(10): print(f' {count[i][j][k]}',end="") print()
a, b = input().split() print('Yes') if a==b else print('No')
0
null
42,218,598,111,532
55
231
a, b, k = map(int, input().split()) if a>=k: print(a-k,b) elif a<k and a+b>k: print(0,b-(k-a)) else: print(0,0)
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,309,308,404,132
null
249
249
from collections import deque que = deque() l = input() S = 0 S2 = [] for j in range(len(l)): i = l[j] if i == '\\': que.append(j) continue elif i == '/': if len(que) == 0: continue k = que.pop() pond_sum = j-k S += pond_sum while S2 and S2[-1][0] > k: pond_sum += S2[-1][1] S2.pop() S2.append([k,pond_sum]) elif i == '_': continue data = [i for j,i in S2] print(S) print(len(S2),*data)
inp = input().split() A = int(inp[0]) B = int(inp[1].replace('.','')) print(A*B//100)
0
null
8,230,896,571,470
21
135
N, M = map(int, input().split()) A = list(map(int, input().split())) k = sum(A) / (4*M) print('Yes' if [a >= k for a in A].count(True) >= M else 'No')
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def solve(A: int, B: int): return A * B if A <= 9 and B <= 9 else -1 def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int print(f'{solve(A, B)}') if __name__ == '__main__': main()
0
null
98,644,739,922,472
179
286
n = int(input()) if n % 2 == 0: ans = n / 2 - 1 else: ans = n / 2 print(int(ans))
#!/usr/bin/env python3 def main(): N = int(input()) X = [None] * N for i in range(N): x, l = map(int, input().split()) X[i] = (x+l,x-l) X.sort() ans = 0 maxT = - 10**18 for i in range(N): if maxT <= X[i][1]: ans += 1 maxT = X[i][0] print(ans) if __name__ == "__main__": main()
0
null
121,896,540,767,990
283
237
def main(): N,R = map(int, input().split()) if N>=10: print(R) else: print(R+100*(10-N)) main()
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: map(int, stdin.readline().split()) rlf = lambda: map(float, stdin.readline().split()) INF, NINF = float('inf'), float('-inf') def main(): L, R, d = rli() ans = 0 for x in range(L, R+1): if x % d == 0: ans += 1 print(ans) stdout.close() if __name__ == "__main__": main()
0
null
35,582,833,464,920
211
104
#!/usr/bin/env python from __future__ import division, print_function from sys import stdin from Queue import Queue def main(): num = int(stdin.readline()) L = [] for _ in xrange(num): L.append([int(s) for s in stdin.readline().split()[2:]]) d = [-1] * num d[0] = 0 q = Queue(100) q.put(0) while not q.empty(): u = q.get() for v in L[u]: if d[v-1] < 0: d[v-1] = d[u] + 1 q.put(v-1) for i, v in enumerate(d): print(i+1, v) main()
from heapq import heappush, heappop N, K, C = map(int, input().split()) S = input() if C == 0 : if K == S.count('o') : for i, s in enumerate(S) : if s == 'o' : print(i + 1) else : N += 2 S = 'x' + S + 'x' dpL = [0] * N dpR = [0] * N for l in range(1, N) : r = N - 1 - l dpL[l] = max(dpL[l - 1], int(S[l] == 'o')) dpR[r] = max(dpR[r + 1], int(S[r] == 'o')) if l - C - 1 >= 0 and S[l] == 'o' : dpL[l] = max(dpL[l], dpL[l - C - 1] + 1) if r + C + 1 < N and S[r] == 'o' : dpR[r] = max(dpR[r], dpR[r + C + 1] + 1) h = [] for r in range(C + 1) : heappush(h, (-dpR[r], r)) for l in range(1, N) : r = l - 1 + C + 1 if r < N : cost = dpL[l - 1] + dpR[r] else : cost = dpL[l - 1] heappush(h, (-cost, r)) while h[0][1] <= l : heappop(h) if -h[0][0] < K and S[l] == 'o' : print(l)
0
null
20,286,272,202,730
9
182
def main(): N = int(input()) S = input() fusion = [S[0]] prev = S[0] for s in S[1:]: if s == prev: continue fusion.append(s) prev = s print(len(fusion)) main()
#!/usr/bin/env python import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**6) INF = float("inf") def main(): N = int(input()) S = input() ans = 1 for i in range(N-1): if S[i+1] != S[i]: ans += 1 print(ans) if __name__ == "__main__": main()
1
170,159,284,990,688
null
293
293
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush import math #inf = 10**17 #mod = 10**9 + 7 n,t = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort(key=lambda x: x[1]) ab.sort(key=lambda x: x[0]) dp = [-1]*(t+1) dp[0] = 0 for a, b in ab: for j in range(t-1, -1, -1): if dp[j] >= 0: if j+a<=t: dp[j+a] = max(dp[j+a], dp[j]+b) else: dp[-1] = max(dp[-1], dp[j]+b) print(max(dp)) if __name__ == '__main__': main()
N = int(input()) def solve(N): fib = [1]*(N+1) for i in range(2,N+1): fib[i] = fib[i-1] + fib[i-2] ans = fib[N] return ans print(solve(N))
0
null
75,596,569,948,262
282
7
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy import bisect import functools @functools.lru_cache(None) def dfs(i,sum_v,val): if i == n: return sum_v == val if dfs(i+1,sum_v,val): return True if dfs(i+1,sum_v + A[i],val): return True return False n = int(input()) A = list(map(int,input().split())) q = int(input()) m = list(map(int,input().split())) for i in range(q): if dfs(0,0,m[i]): print("yes") else: print("no")
input() A = [int(x) for x in input().split()] input() ms = [int(x) for x in input().split()] enable_create = [False]*2000 for bit in range(1 << len(A)): n = 0 for i in range(len(A)): if 1 & (bit >> i) == 1: n += A[i] enable_create[n] = True for m in ms: print("yes" if enable_create[m] else "no")
1
97,917,614,692
null
25
25
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) min_price = min(a) + min(b) for _ in range(M): x, y, c = map(int, input().split()) discount_price = a[x-1] + b[y-1] - c if min_price > discount_price: min_price = discount_price print(min_price)
A, B, M = map(int, input().split()) an = list(map(int, input().split())) bn = list(map(int, input().split())) ans = min(an)+min(bn) for i in range(M): x, y, c = map(int, input().split()) ans = min(ans, an[x-1] + bn[y-1] - c) print(ans)
1
54,078,399,545,902
null
200
200
def main(): S = input() if "RRR" in S: print(3) elif "RR" in S: print(2) elif "R" in S: print(1) else: print(0) if __name__ == '__main__': main()
s = input() count = 0 for i in range(len(s)): if s[i] == "R": count += 1 if i + 1 >= 3: break elif s[i+1] == "S": break print(count)
1
4,854,916,912,252
null
90
90
n = int(input()) d = {} for i in range(n): s = input() if s in d: d[s] += 1 else: d[s] = 1 mx = max(d.values()) ans = [''] for k, v in d.items(): if v == mx: ans.append(k) ans.sort() print(*ans, sep='\n')
from collections import defaultdict N = int(input()) S = defaultdict(int) for i in range(N): S[input()] += 1 m = max(S.values()) for s in sorted(filter(lambda x: S[x] == m, S)): print(s)
1
69,989,607,009,852
null
218
218
N, M, X = map(int, input().split()) CA = [list(map(int, input().split())) for _ in range(N)] min_num = 10**18 for i in range(1<<N): cost = 0 l = [0]*M for j in range(N): if (i>>j)&1: c, *a = CA[j] cost += c for k, ak in enumerate(a): l[k] += ak if all(lj >= X for lj in l): min_num = min(min_num, cost) # print(l) print(-1 if min_num == 10**18 else min_num)
# coding: utf-8 # Your code here! import itertools import numpy as np def main(): N, M, X = map(int, input().split()) for i in range(N): row = np.array(list(map(int, input().split()))) # print(row) if i == 0: c_array = row[0].reshape(1, 1) a_matrix = row[1:].reshape(1, len(row[1:])) else: c_array = np.append(c_array, row[0]) a_matrix = np.vstack([a_matrix, row[1:].reshape(1, len(row[1:]))]) # print(c_array) # print(a_matrix) min_cost = float("inf") for i in range(1, N+1): for v in itertools.combinations(np.arange(N), i): tmp = a_matrix[v, :].sum(axis=0) cost = c_array[list(v)].sum() # print(tmp) if tmp.min() >= X and cost <= min_cost: min_cost = cost if min_cost == float("inf"): print("-1") else: print(min_cost) main()
1
22,424,778,850,892
null
149
149
# -*- coding:utf-8 -*- import copy def bubble_sort(num_list): for i in range(len(num_list)): for j in range(len(num_list)-1, i , -1): if num_list[j][1] < num_list[j-1][1]: num_list[j], num_list[j-1] = num_list[j-1], num_list[j] return num_list def selection_sort(num_list): for i in range(len(num_list)): mini = i for j in range(i, len(num_list)): if num_list[j][1] < num_list[mini][1]: mini = j num_list[i], num_list[mini] = num_list[mini], num_list[i] return num_list def is_stable(before_sort, after_sort): current_num = 0 same_number_card = list() for num in after_sort: if current_num == int(num[1]): for same_card in same_number_card: if before_sort.index(same_card) > before_sort.index(num): return False same_number_card.append(num) else: current_num = int(num[1]) same_number_card = [num,] return True def show_list(list): i = 0; while(i < len(list)-1): print(list[i], end=" ") i = i + 1 print(list[i]) def show_stable(flag): if flag: print('Stable') else: print('Not stable') num = int(input()) input_card = [x for i, x in enumerate(input().split()) if i < num] bubble_sort_card = bubble_sort(copy.deepcopy(input_card)) show_list(bubble_sort_card) show_stable(is_stable(input_card, bubble_sort_card)) selection_sort_card = selection_sort(copy.deepcopy(input_card)) show_list(selection_sort_card) show_stable(is_stable(input_card, selection_sort_card))
# coding: utf-8 # Stable Sort 2018/3/12 class Card(object): def __init__(self, card): self.value = int(card[1]) self.card = card def __repr__(self): return self.card def BubbleSort(C, N): for i in range(N): for j in reversed(range(i+1, N)): if C[j].value < C[j-1].value: C[j], C[j-1] = C[j-1], C[j] return C def SelectionSort(C, N): for i in range(N): minj = i for j in range(i, N): if C[j].value < C[minj].value: minj = j C[i], C[minj] = C[minj], C[i] return C def isStable(inl, out): n = len(inl) for i in range(n): for j in range(i+1, n): for a in range(n): for b in range(a+1, n): if inl[i].value == inl[j].value and inl[i] == out[b] and inl[j] == out[a]: return False return True def print_stable(inl, out): if isStable(inl, out): print "Stable" else: print "Not stable" if __name__ == "__main__": N = int(raw_input()) inputs = raw_input().split() C = [] for i in inputs: C.append(Card(i)) Cb = BubbleSort(list(C), N) print " ".join([i.card for i in Cb]) print_stable(C, Cb) Cs = SelectionSort(list(C), N) print " ".join([i.card for i in Cs]) print_stable(C, Cs)
1
24,979,908,640
null
16
16
S = input() Q = int(input()) q = [] for i in range(Q): a = input().split(" ") if len(a) == 1: q.append([int(a[0])]) else: q.append([int(a[0]), int(a[1]), a[2]]) #print(S) #print(q) def switch(s): d = "" for i in range(len(s)): d += s[len(s) - i - 1] return d H = "" B = "" direction = 1 #通常の向き -1:反対方向 for t in range(len(q)): T = q[t] if T[0] == 1: direction *= -1 else: F = T[1] C = T[2] if F == 1: if direction == 1: H += C else: B += C else: if direction == 1: B += C else: H += C if direction == 1: print(switch(H) + S + B) else: print(switch(B) + switch(S) + H)
import sys read = sys.stdin.read INF = 1 << 60 def main(): H, N, *AB = map(int, read().split()) dp = [INF] * (H + 1) dp[0] = 0 for a, b in zip(*[iter(AB)] * 2): for i in range(H + 1): if i >= a: if dp[i] > dp[i - a] + b: dp[i] = dp[i - a] + b else: if dp[i] > dp[0] + b: dp[i] = dp[0] + b print(dp[H]) return if __name__ == '__main__': main()
0
null
68,996,469,447,732
204
229
MON = list(map(int,input().split())) while 1: MON[2] = MON[2] - MON[1] if(MON[2] <= 0): print("Yes") break MON[0] = MON[0] - MON[3] if (MON[0] <= 0 ): print("No") break
# coding=utf-8 inputs = raw_input().rstrip().split() nums = [int(x) for x in inputs] print ' '.join([str(x) for x in sorted(nums)])
0
null
14,983,547,282,138
164
40
L,R,d=map(int,input().split()) ans=0 for i in range(L,R+1): if i%d==0: ans+=1 print(ans)
N = int(input()) A = list(map(int, input().split())) count = 0 for i in A: count ^= i for i in range(len(A)): A[i] ^= count print(*A)
0
null
9,944,491,833,252
104
123
count=0 def mg(S,left,right,mid): global count L=[] L=S[left:mid] L.append(9999999999) R=[] R=S[mid:right] R.append(9999999999) r=0 l=0 for i in range(left,right): count=count+1 if L[l]<=R[r]: S[i]=L[l] l=l+1 else: S[i]=R[r] r=r+1 def ms(S,left,right): if right>left+1: mid=(right+left)//2 ms(S,left,mid) ms(S,mid,right) mg(S,left,right,mid) n=int(input()) S=[] S=input().split() S=[int(u) for u in S] ms(S,0,n) for i in range(0,n-1): print(S[i],end=" ") print(S[n-1]) print(count)
S=input(); if(S=="hi" or S=="hihi" or S=="hihihi" or S=="hihihihi" or S=="hihihihihi"): print("Yes"); else: print("No");
0
null
26,853,820,879,798
26
199
def ifTriangle(v): largest = max(v) smallers_sum = 0 for x in v: if not x == largest: smallers_sum += x if smallers_sum > largest: return True return False N = int(input()) L = [int(x) for x in input().split()] L.sort() L.reverse() count = 0 before_i = -1 before_j = -1 before_k = -1 for i in range(N-2): for j in range(i+1, N-1): if L[j] == L[i]: continue if L[i]/2 >= L[j]: break for k in range(j+1, N): if L[k] == L[j]: continue if ifTriangle([L[i], L[j], L[k]]): count += 1 print(count)
def solve(): N, K = map(int,input().split()) A = list(map(int,input().split())) left = 0 right = 10 ** 9 while right - left > 1: mid = (right+left) // 2 cnt = 0 for a in A: cnt += (a-1) // mid if cnt <= K: right = mid else: left = mid print(right) if __name__ == '__main__': solve()
0
null
5,833,737,642,532
91
99
n = int(input()) a = set(input().split()) print('YES' if (len(a) == n) else 'NO')
from collections import* n,u,v=map(int,input().split()) e=[[]for _ in range(n+1)] INF=10**18 d=[INF]*(n+1) for _ in range(n-1): a,b=map(int,input().split()) e[a]+=[b] e[b]+=[a] q=deque([(v,0)]) while q: now,c=q.popleft() d[now]=c for to in e[now]: if d[to]!=INF:continue q.append((to,c+1)) q=[(u,0)] ans=0 vis=[1]*(n+1) while q: now,c=q.pop() vis[now]=0 f=1 for to in e[now]: if vis[to]: f=0 if d[to]>c+1:q+=[(to,c+1)] if d[to]==c+1:ans=max(c+1,ans) else:ans=max(c,ans) if len(e[now])==1:ans=max(d[to],ans) print(ans)
0
null
95,469,609,643,012
222
259
class Dice: """Dice class""" def __init__(self): # ????????????????????? self.eyeIndex = 1 #center self.eyeIndex_E = 3 #east self.eyeIndex_W = 4 #west self.eyeIndex_N = 5 #north self.eyeIndex_S = 2 #south self.eye = 0 self.eye_S = 0 self.eye_E = 0 self.eyes = [] def convEyesIndexToEyes(self): self.eye = self.eyes[self.eyeIndex] self.eye_S = self.eyes[self.eyeIndex_S] self.eye_E = self.eyes[self.eyeIndex_E] def shakeDice(self, in_command): pre_eyeIndex = self.eyeIndex if in_command == "E": self.eyeIndex = self.eyeIndex_W self.eyeIndex_E = pre_eyeIndex self.eyeIndex_W = 7 - self.eyeIndex_E elif in_command == "W": self.eyeIndex = self.eyeIndex_E self.eyeIndex_W = pre_eyeIndex self.eyeIndex_E = 7 - self.eyeIndex_W elif in_command == "N": self.eyeIndex = self.eyeIndex_S self.eyeIndex_N = pre_eyeIndex self.eyeIndex_S = 7 - self.eyeIndex_N elif in_command == "S": self.eyeIndex = self.eyeIndex_N self.eyeIndex_S = pre_eyeIndex self.eyeIndex_N = 7 - self.eyeIndex_S self.convEyesIndexToEyes() def rotateDice(self): #rotate clockwise pre_E = self.eyeIndex_E pre_S = self.eyeIndex_S pre_W = self.eyeIndex_W pre_N = self.eyeIndex_N self.eyeIndex_E = pre_N self.eyeIndex_S = pre_E self.eyeIndex_W = pre_S self.eyeIndex_N = pre_W self.convEyesIndexToEyes() def getEye(self): return self.eye def getEye_S(self): return self.eye_S def getEye_E(self): return self.eye_E def setEyes(self, eyes): # setEyes()???????????? ??????????????? eyes = "0 " + eyes self.eyes = list(map(int, eyes.split(" "))) self.convEyesIndexToEyes() dice_1 = Dice() dice_1.setEyes(input().rstrip()) command_time = int(input().rstrip()) for i in range(command_time): in_eye, in_eye_S = map(int, input().rstrip().split(" ")) shake_direction = "E" def_eye = dice_1.getEye() while True: dice_1.shakeDice(shake_direction) if dice_1.getEye() == in_eye: break if dice_1.getEye() == def_eye: shake_direction = "N" while True: if dice_1.getEye_S() == in_eye_S: break dice_1.rotateDice() print(dice_1.getEye_E())
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict from fractions import gcd import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): a,b,m = readInts() A = readInts() B = readInts() ans = float('inf') for i in range(m): x,y,c = readInts() x -=1 y -=1 ans = min(ans,A[x] + B[y] - c) # Aの商品の中で1番最小のやつを買うだけでもいいかもしれない # Bの商品の中で1番最小のやつを買うだけでもいいかもしれない ans = min(ans,min(A) + min(B)) print(ans) if __name__ == '__main__': main()
0
null
27,272,055,374,240
34
200
from functools import lru_cache @lru_cache(None) def f(n,k): if k<1: return 1 if n<10: if k<2: return n return 0 d,m=n//10,n%10 return f(d,k-1)*m+f(d-1,k-1)*(9-m)+f(d,k) print(f(int(input()),int(input())))
N = input() K = int(input()) L = len(N) dp =[[[ 0 for _ in range(2)] for _ in range(5)] for _ in range(len(N)+1)] # dp[i][j][flg] i+1桁目までで0以外の個数がj個 # flg = 1 -> N 以下が確定している dp[0][1][1] = int(N[0])-1 dp[0][1][0] = 1 dp[0][0][1]=1 for i in range(1,L): for j in range(4): b = i-1 # hitotumae now = int(N[i]) ## N上限に張り付いてる方 if now == 0: dp[i][j][0] += dp[b][j][0] else: dp[i][j][1] += dp[b][j][0] dp[i][j+1][1] += dp[b][j][0] * (now-1) dp[i][j+1][0] += dp[b][j][0] ## 張り付いてない方 dp[i][j][1] += dp[b][j][1] dp[i][j+1][1] += dp[b][j][1] * 9 print(dp[L-1][K][0] + dp[L-1][K][1])
1
75,805,668,420,324
null
224
224
s=int(input()) p=10**9+7 if s<=2: print(0) exit() n=s//3 ans=0 x=[0]*(s+1) x[0]=1 x[1]=1 y=[0]*(s+1) for i in range(2,s+1): x[i]=x[i-1]*i%p y[s]=pow(x[s],p-2,p) for i in range(s): y[s-1-i]=y[s-i]*(s-i)%p for k in range(1,n+1): ans+=x[s-2*k-1]*y[k-1]*y[s-3*k]%p print(ans%p)
s = int(input()) mod = 10**9 + 7 a = [0] * (2001) a[3] = a[4] = a[5] = 1 for i in range(6, s + 1): a[i] = a[i - 1] + a[i - 3] a[i] %= mod print(a[s])
1
3,252,346,834,708
null
79
79
INFTY = 1000000001 def merge(A, left, mid, right): global cnt L = A[left:mid] R = A[mid:right] L.append(INFTY) R.append(INFTY) i = 0 j = 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 cnt += 1 def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) n = int(input()) S = list(map(int, input().split())) cnt = 0 merge_sort(S, 0, len(S)) print(*S) print(cnt)
def merge(a, left, mid, right): x = 0 l = a[left:mid] + [float("inf")] r = a[mid:right] + [float("inf")] i = 0 j = 0 for k in range(left,right): if l[i] <= r[j]: a[k] = l[i] i += 1 else : a[k] = r[j] j += 1 x += 1 return x def mergeSort(a, left, right,x): if left+1 < right: mid = int((left + right)/2) mergeSort(a, left, mid,x) mergeSort(a, mid, right,x) x[0] += merge(a, left, mid, right) n = int(input()) s = list(map(int,input().split())) x = [0] mergeSort(s,0,n,x) print(*s) print(x[0])
1
115,926,438,240
null
26
26
def gcd(x, y): while y != 0: x,y = y, x % y return x A = list(map(int,input().split())) print(gcd(A[0], A[1]))
def insertion_sort(a, n, g, cnt): for i in range(g,n,1): v = a[i] j = i - g #initial value while j>=0 and a[j]>v: a[j+g]=a[j] j -= g cnt += 1 a[j+g] = v return a, cnt def shell_sort(a,n,m,g): cnt = 0 for i in range(m): sorted_list, cnt = insertion_sort(a,n,g[i],cnt) return sorted_list, cnt def seqforshell(n): seq = [1] next_num = 3*seq[0] + 1 while next_num<n: seq.insert(0, next_num) next_num = 3*next_num + 1 return seq if __name__ == "__main__": a = [] n = int(input()) for i in range(n): a.append(int(input())) g = seqforshell(n) m = len(g) res, cnt = shell_sort(a,n,m,g) print(m) print(*g) print(cnt) for i in range(n): print(res[i])
0
null
19,958,130,248
11
17
taka, aoki, num = map(int, input().split()) if taka <= num: num -= taka taka = 0 if aoki <= num: aoki = 0 print(taka, aoki) elif aoki > num: aoki -= num print(taka, aoki) if taka > num: taka -= num print(taka, aoki)
a,b,k = map(int,input().split()) if a < k: k -= a a = 0 else : a -= k k = 0 if b < k: b = 0 k = 0 else : b -= k k = 0 print(str(a)+ " " + str(b))
1
104,639,951,026,766
null
249
249
import math ni = int(input()) xi = map(int, raw_input().split()) yi = map(int, raw_input().split()) p1 = [] p2 = [] p3 = [] p4 = [] for x, y in zip(xi, yi): p1.append(abs(x - y)) p2.append(abs(x - y)**2) p3.append(abs(x - y)**3) p4.append(abs(x - y)) print '%.8f' % reduce(lambda x, y: x + y, p1) print '%.8f' % reduce(lambda x, y: x + y, p2) ** (1.0/2.0) print '%.8f' % reduce(lambda x, y: x + y, p3) ** (1.0/3.0) print '%.8f' % max(p4)
#!/usr/bin/env python3 n=int(input()) print((n-n//2)/n)
0
null
88,520,017,203,840
32
297