code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
N = int(input()) A = list(map(int, input().split())) ans = 'APPROVED' for i in range(0,N): if (A[i]%2)==0: if not ((A[i] % 3) == 0 or (A[i] % 5) == 0): ans = 'DENIED' break print(ans)
n = int(input()) list01 = input().split() x = 0 for i in list01: if int(i) % 2 != 0: pass elif int(i) % 3 == 0: pass elif int(i) % 5 == 0: pass else: x += 1 break if x == 1: print('DENIED') else: print('APPROVED')
1
68,999,326,047,892
null
217
217
m={"S":[], "D":[], "H":[], "C":[]} for i in range(int(input())): mark, num=input().split() m[mark].append(int(num)) for j in ["S", "H", "C", "D"]: nai=set(range(1,14))-set(m[j]) for k in nai: print(j, k)
Suits = ['S', 'H', 'C', 'D'] Taro = [] Missing = [] n = int(input()) for i in range(n): Taro.append(input()) for j in range(52): card = Suits[j//13] + ' ' + str(j % 13 + 1) if card not in Taro: Missing.append(card) if Missing != []: print('\n'.join(Missing))
1
1,052,875,267,248
null
54
54
x, y = map(int, input().split()) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) def knight(x, y): s = (0, 0) if x == y == 0: return 0 if (x + y) % 3: return 0 if (2*y-x)%3 or (2*x-y)%3: return 0 a, b = (2*y-x)//3, (2*x-y)//3 n = (x+y)//3 r = min(a, b) if a<0 or b<0: return 0 return cmb(n, r, mod) print(knight(x,y))
S = int(input()) h = int(S / 3600) m = int((S % 3600) / 60) s = S % 60 print(h,m,s,sep=':')
0
null
75,071,338,661,076
281
37
from itertools import product H, W, K = map(int, input().split()) choco = [list(input()) for _ in range(H)] def cnt(array): count = [0] * H split_cnt = 0 for w in range(W): for h in range(H): if choco[h][w] == "1": count[array[h]] += 1 if any(i > K for i in count): split_cnt += 1 count = [0] * H for h in range(H): if choco[h][w] == "1": count[array[h]] += 1 if any(i > K for i in count): return 10 ** 20 return split_cnt def get_array(array): l = len(array) ret = [0] * l for i in range(1, l): ret[i] = ret[i-1] + array[i] return ret ans = 10 ** 20 for p in product(range(2), repeat=H-1): p = get_array([0]+list(p)) ans = min(ans, cnt(p)+max(p)) print(ans)
def insection_sort(lst): lens=len(lst) ans=0 for i in xrange(lens): mn=i for j in xrange(i+1,lens): if(lst[j]<lst[mn]): mn=j if(mn!=i): tmp=lst[i] lst[i]=lst[mn] lst[mn]=tmp ans+=1 return ans num=int(raw_input().strip()) arr=map(int,raw_input().strip().split()) ans=insection_sort(arr) print " ".join(str(pp) for pp in arr) print ans
0
null
24,290,267,517,700
193
15
s = input() s = s[::-1] L = [0] cnt = 1 for i in range(len(s)): L.append((L[-1]+(int(s[i])*cnt))%2019) cnt *= 10 cnt %= 2019 D = dict() for j in L: if j in D: D[j] += 1 else: D[j] = 1 ans = 0 for k in D.values(): ans += k * (k-1) //2 print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n = list(map(int, list(readline().rstrip().decode())[::-1])) a = 0 b = 10000 for x in n: memo = min(a + x, b + x) b = min(a + 11 - x, b + 9 - x) a = memo print(min(a, b))
0
null
50,866,412,980,120
166
219
def study_time(h1, m1, h2, m2, k): result = (h2 - h1) * 60 + m2 - m1 - k return result h1, m1, h2, m2, k = tuple(map(int, input().split())) if __name__ == '__main__': print(study_time(h1, m1, h2, m2, k))
N,M=map(int,input().split()) #brr=[list(map(int,input().split())) for i in range(M)] arr=[[] for i in range(N)] check=[0]*N ans=[] for i in range(M): a,b=map(int,input().split()) arr[a-1].append(b-1) arr[b-1].append(a-1) q=[] cnt=0 for i in range(N): if check[i]==0: cnt+=1 q.append(i) #print(cnt,q) while q: x=q.pop() if check[x]==0: check[x]=1 for j in arr[x]: q.append(j) print(cnt-1)
0
null
10,087,295,900,540
139
70
while True: str_shuffled = input() if str_shuffled == '-': break shuffle_time = int(input()) for _ in range(shuffle_time): num_to_shuffle = int(input()) str_shuffled = str_shuffled[num_to_shuffle:] + str_shuffled[:num_to_shuffle] print(str_shuffled)
origin_cards = raw_input() while origin_cards != '-': shuffle_number = int(raw_input()) for x in xrange(shuffle_number): h = int(raw_input()) temp = origin_cards[h:len(origin_cards)+1] + origin_cards[0:h] origin_cards = temp print origin_cards origin_cards = raw_input()
1
1,922,779,937,800
null
66
66
X = int(input()) if X >= 400 and X < 600: print('8') elif X >= 600 and X < 800: print('7') elif X >= 800 and X < 1000: print('6') elif X >= 1000 and X < 1200: print('5') elif X >= 1200 and X < 1400: print('4') elif X >= 1400 and X < 1600: print('3') elif X >= 1600 and X < 1800: print('2') elif X >= 1800 and X < 2000: print('1')
# 問題: https://atcoder.jp/contests/abc144/tasks/abc144_b n = int(input()) has_multiple = False for a in range(1, 10): if n % a > 0: continue b = n / a if 0 < b < 10: has_multiple = True break if has_multiple: print('Yes') else: print('No')
0
null
83,444,922,918,148
100
287
#!python3 import sys input = sys.stdin.readline def resolve(): N = int(input()) S = list(input()) Q = int(input()) c0 = ord('a') smap = [1<<(i-c0) for i in range(c0, ord('z')+1)] T = [0]*N + [smap[ord(S[i])-c0] for i in range(N)] for i in range(N-1, 0, -1): i2 = i << 1 T[i] = T[i2] | T[i2|1] ans = [] #print(T) for cmd, i, j in zip(*[iter(sys.stdin.read().split())]*3): i = int(i) - 1 if cmd == "1": if S[i] == j: continue S[i] = j i0 = N + i T[i0] = smap[ord(j)-c0] while i0 > 1: i0 = i0 >> 1 T[i0] = T[i0+i0] | T[i0-~i0] elif cmd == "2": i += N j = int(j) + N d1 = 0 while i < j: if i & 1: d1 |= T[i] i += 1 if j & 1: j -= 1 d1 |= T[j] i >>= 1; j >>=1 ans.append(bin(d1).count('1')) print(*ans, sep="\n") if __name__ == "__main__": resolve()
# coding=UTF-8 from collections import deque from operator import itemgetter from bisect import bisect_left, bisect import itertools import sys import math import numpy as np import time sys.setrecursionlimit(10**6) input = sys.stdin.readline def ev(n): return 0.5*(n+1) def main(): n, k = map(int, input().split()) p = list(map(int, input().split())) p_ev = list(map(ev, p)) s = np.cumsum(p_ev) s = np.insert(s, 0, 0) ans = [] for i in range(n - k+1): ans.append(s[i + k] - s[i]) print(max(ans)) if __name__ == '__main__': main()
0
null
68,913,665,740,810
210
223
N = int(input()) music_list = [input().split(' ') for i in range(N)] X = input() sleep_switch = False total_time = 0 for music in music_list: if not sleep_switch: if music[0] == X: sleep_switch = True else: total_time += int(music[1]) print(total_time)
def main(): n = int(input()) S, T = [], [] for _ in range(n): s, t = input().split() S.append(s) T.append(int(t)) x = input() print(sum(T[S.index(x) + 1:])) if __name__ == '__main__': main()
1
97,102,895,862,394
null
243
243
import math import copy from copy import deepcopy import sys import fractions # import numpy as np from functools import reduce # import statistics import heapq import collections import itertools sys.setrecursionlimit(100001) # input = sys.stdin.readline # sys.setrecursionlimit(10**6) # ===FUNCTION=== def getInputInt(): inputNum = int(input()) return inputNum def getInputListInt(): outputData = [] inputData = input().split() outputData = [int(n) for n in inputData] return outputData def getSomeInputInt(n): outputDataList = [] for i in range(n): inputData = int(input()) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList = [] outputDataList = [] for i in range(n): inputData = input().split() inputDataList = [int(n) for n in inputData] outputDataList.append(inputDataList) return outputDataList # ===CODE=== # n, m = map(int, input().split()) n = int(input()) list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print(list[n-1])
mlist = list([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]) b = int(input()) print(mlist[b-1])
1
50,181,444,753,198
null
195
195
X = int(input()) n = 10**6 is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False for i, p in enumerate(is_prime): if i >= X and p is True: print(i) break
import math def resolve(): import sys input = sys.stdin.readline # row = [int(x) for x in input().rstrip().split(" ")] # n = int(input().rstrip()) x = int(input().rstrip()) def get_sieve_of_eratosthenes(n: int): candidate = [i for i in range(2, n + 1)] primes = [] while len(candidate) > 0: prime = candidate[0] candidate = [num for num in candidate if num % prime != 0] primes.append(prime) return primes # xまでの素数 primes = get_sieve_of_eratosthenes(x) ans = x if not x in primes: while True: if any([ans % prime == 0 for prime in primes]): ans += 1 continue break print(ans) if __name__ == "__main__": resolve()
1
105,870,153,246,220
null
250
250
c = str(input()) a = 'abcdefghijklmnopqrstuvwxyz' for i, letter in enumerate(a): if c == letter: ans = a[i+1] print(ans)
input_line = set([]) input_line.add(int(input())) input_line.add(int(input())) for i in range(1,4): if i not in input_line: print(i)
0
null
101,513,675,718,968
239
254
import sys input = sys.stdin.readline INF = 10**18 sys.setrecursionlimit(10**6) def li(): return [int(x) for x in input().split()] N = int(input()) xs, ys = [], [] for i in range(N): x, y = li() xs.append(x) ys.append(y) def get_max_manhattan_distanse(xs, ys): X = [xs[i] + ys[i] for i in range(len(xs))] Y = [xs[i] - ys[i] for i in range(len(xs))] # return max(max(X) - min(X), max(Y) - min(Y)) X.sort() Y.sort() return max(X[-1] - X[0], Y[-1] - Y[0]) ans = get_max_manhattan_distanse(xs, ys) print(ans)
#!/usr/bin/env python n = int(input()) x_plus_y = [0 for _ in range(n)] x_minus_y = [0 for _ in range(n)] for i in range(n): x, y = map(int, input().split()) x_plus_y[i] = x+y x_minus_y[i] = x-y ans = max(max(x_plus_y)-min(x_plus_y), max(x_minus_y)-min(x_minus_y)) print(ans)
1
3,468,118,863,680
null
80
80
x = input() window = int(x.split()[0]) b = int(x.split()[1]) curtain = b * 2 if window > curtain: print(window - curtain) else: print('0')
a, b = list(map(int, input().split())) remain = a - (b * 2) print(remain if remain >= 0 else 0)
1
167,227,943,814,048
null
291
291
import sys sys.setrecursionlimit(10**7) import fileinput def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) for line in sys.stdin: x, y = map(int, line.split()) print(gcd(x,y),lcm(x,y))
import sys import math a = [] for line in sys.stdin: a.append(line) for n in a: inl=n.split() num1=int(inl[0]) check=1 list=[] while check<=math.sqrt(num1): if num1%check==0: list.append(check) list.append(num1/check) check+=1 list.sort() list.reverse() num2=int(inl[1]) for i in list: if num2%i==0: gud=i break lcm=num1*num2/gud print gud,lcm
1
595,397,780
null
5
5
import itertools for x, y in itertools.product(range(1, 10), range(1, 10)): print("%dx%d=%d" % (x, y, x * y))
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 mans = inf ;ans = 0 ;count = 0 ;pro = 1 n,m=map(int,input().split()) A=sorted(map(int,input().split())) B=[0]+A[:] for i in range(n): B[i+1]+=B[i] def solve_binary(mid): tmp=0 for i,ai in enumerate(A): tmp+=n-bisect.bisect_left(A,mid-ai) return tmp>=m def binary_search(n): ok=0 ng=n while abs(ok-ng)>1: mid=(ok+ng)//2 if solve_binary(mid): ok=mid else: ng=mid return ok binresult=binary_search(2*10**5+1) for i ,ai in enumerate(A): ans+=ai*(n-bisect.bisect_left(A,binresult-ai))+B[n]-B[bisect.bisect_left(A,binresult-ai)] count+=n-bisect.bisect_left(A,binresult-ai) # print(ans,count) ans-=binresult*(count-m) print(ans) # print(binresult)
0
null
53,920,185,258,578
1
252
A,B,C,D= map(int, input().split()) while (True): C = C - B if ( C <= 0 ): result = "Yes" break A = A - D if ( A <= 0 ) : result = "No" break print ( result )
import sys N, M = map(int, input().split()) S = input() tmp = 0 for i in range(N+1): if S[i] == '1': tmp += 1 if tmp == M: print(-1) sys.exit() else: tmp = 0 ans = [] i = N while i > M: ind = S[i-M:i].find('0') ans.append(M-ind) i -= M - ind ans.append(i) print(*ans[::-1])
0
null
84,857,950,758,000
164
274
INF = 10**18 def solve(n, a): # 現在の位置 x 選んだ個数 x 直前を選んだかどうか dp = [{j: [-INF, -INF] for j in range(i//2-1, (i+1)//2 + 1)} for i in range(n+1)] dp[0][0][False] = 0 for i in range(n): for j in dp[i].keys(): if (j+1) in dp[i+1]: dp[i+1][j+1][True] = max(dp[i+1][j+1][True], dp[i][j][False] + a[i]) if j in dp[i+1]: dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][False]) dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][True]) return max(dp[n][n//2]) n = int(input()) a = list(map(int, input().split())) print(solve(n, a))
a, b = input().split() print(a * int(b) if a < b else b * int(a))
0
null
60,671,832,269,728
177
232
import sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = LI() from itertools import accumulate for _ in range(min(K,41)): B = [0]*(N+1) for i in range(N): a = A[i] B[max(i-a,0)] += 1 B[min(N,i+a+1)] -= 1 C = list(accumulate(B)) A = C print(*[A[i] for i in range(N)])
a,b = list(map(int, input().split())) c,d = list(map(int, input().split())) if (a != c): print(1) else: print(0)
0
null
70,066,403,259,018
132
264
#!/usr/bin/env python3 def main(): import sys from collections import deque input = sys.stdin.readline N, M = map(int, input().split()) G = [[] for _ in [0] * (N + 1)] for _ in [0] * M: a, b = map(int, input().split()) G[a].append(b) G[b].append(a) q = deque([1]) depth = [0 for _ in [0] * (N + 1)] while q: v = q.popleft() for nv in G[v]: if depth[nv] == 0: # depth[nv] = depth[v] + 1 depth[nv] = v q.append(nv) if 0 in depth[2:]: print('No') return else: print('Yes') for guide in depth[2:]: print(guide) if __name__ == '__main__': main()
from collections import deque N,M =map(int,input().split()) graph=[[] for _ in range(N)] for _ in range(M): a,b=map(int,input().split()) a,b=a-1,b-1 graph[a].append(b) graph[b].append(a) dist=[-1]*N pre=[-1]*N dist[0]=0 q=deque() q.append(0) while q: v=q.popleft() for i in graph[v]: if dist[i] != -1: continue else: dist[i]=dist[v]+1 pre[i]=v q.append(i) print("Yes") for i in range(1,N): print(pre[i]+1)
1
20,489,103,631,488
null
145
145
import math n = int(input()) A = list(map(int,input().split())) count = 0 def merge(A, left, mid, right): global count L = A[left:mid] L.append(math.inf) R = A[mid:right] R.append(math.inf) i = 0 j = 0 for k in range(left,right): count += 1 if L[i] <= R[j]: A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 def mergeSort(A,left,right): if left +1 < right: mid = (left+right) // 2 mergeSort(A,left,mid) mergeSort(A,mid,right) merge(A,left,mid,right) mergeSort(A,0,n) x = list(map(str,A)) print(" ".join(x)) print(count)
ct=0 def merge(A,left,mid,right): global ct n1=mid-left n2=right-mid l=[A[left+i] for i in xrange(n1)] r=[A[mid+i] for i in xrange(n2)] l.append(float('inf')) r.append(float('inf')) i=0 j=0 for k in xrange(left,right): ct+=1 if l[i]<=r[j]: A[k]=l[i] i=i+1 else: A[k]=r[j] j=j+1 def mergesort(A,left,right): if left+1<right: mid=(left+right)/2 mergesort(A,left,mid) mergesort(A,mid,right) merge(A,left,mid,right) n=input() s=map(int,raw_input().split()) mergesort(s,0,n) i=0 s=map(str,s) print(" ".join(s)) print(ct)
1
112,599,702,592
null
26
26
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): a, b, m =[int(i) for i in input().split(" ")] res = 0 for i in range(a, b + 1): if m % i == 0: res += 1 print(res) if __name__ == '__main__': main()
a, b, c = map(int, raw_input().split()) print sum(1 for i in xrange(a, b + 1) if c % i == 0)
1
559,845,825,882
null
44
44
import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] IN=lambda : map(int, input().split()) mod=1000000007 #+++++ def main(): ll=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] a = int(input()) print(ll[a-1]) #+++++ isTest=False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform =='ios': if input_method==input_methods[0]: ic=input_clipboard() input = lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else: pass isTest=True else: pass #input = sys.stdin.readline ret = main() if ret is not None: print(ret)
a, b, n = map(int, input().split()) print(a * ((b - 1, n)[n <= b - 1] % b) // b)
0
null
39,067,769,672,202
195
161
import math A, B, N = map(int,input().split()) if N < B: temp1 = math.floor(A*1/B) - A*math.floor(1/B) temp2 = math.floor(A*N/B) - A*math.floor(N/B) ans = max(temp1, temp2) if N >= B: temp1 = math.floor(A*1/B) - A*math.floor(1/B) temp2 = math.floor(A*(B-1)/B) - A*math.floor((B-1)/B) ans = max(temp1, temp2) print(ans)
A,B,N=map(int,input().split()) max = 0 if B - 1 >= N: i = N else: i = B - 1 ans = A*i//B - A*(i//B) print(ans)
1
28,316,921,649,408
null
161
161
card = [] check = [[0, 0, 0] for i in range(3)] for i in range(3): card.append(list(map(int, input().split()))) n = int(input()) for i in range(n): b = int(input()) for j in range(3): for k in range(3): if b == card[j][k]: check[j][k] = 1 flag = 0 for i in range(3): if check[i][0] == check[i][1] == check[i][2] == 1: flag = 1 break elif check[0][i] == check[1][i] == check[2][i] == 1: flag = 1 break elif check[0][0] == check[1][1] == check[2][2] == 1: flag = 1 break elif check[0][2] == check[1][1] == check[2][0] == 1: flag = 1 break if flag: print('Yes') else: print('No')
n = int(input()) x = int(input(),2) def popcount(l): return bin(l).count("1") def count(l): res = 0 while l != 0: p = popcount(l) l %= p res += 1 return res m = popcount(x) x_plus = x%(m+1) if m != 1: x_minus = x%(m-1) else: x_minus = 1 lis_plus = [0]*n lis_minus = [0]*n for i in range(n): if i == 0: lis_plus[i] = 1%(m+1) if m != 1: lis_minus[i] = 1%(m-1) else: lis_plus[i] = lis_plus[i-1]*2%(m+1) if m != 1: lis_minus[i] = lis_minus[i-1]*2%(m-1) for i in range(n): if (x >> (n-i-1)) & 1: if m == 1: print(0) else: print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1) else: print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)
0
null
33,979,569,289,058
207
107
N = int(input()) S = input() r = S.count('R') g = S.count('G') b = S.count('B') ans = r*g*b for i in range(0,N): for j in range(i,N): k = 2*j - i if j < k <= N-1: if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]: ans -= 1 print(ans)
n = int(input()) s = input() rs = [0]*n gs = [0]*n bs = [0]*n for i in reversed(range(n)): if s[i] == 'R': rs[i] += 1 elif s[i] == 'G': gs[i] += 1 else: bs[i] += 1 for i in reversed(range(n-1)): rs[i] += rs[i+1] gs[i] += gs[i+1] bs[i] += bs[i+1] res = 0 for i in range(n): for j in range(i+1,n-1): if s[i] == s[j]: continue if s[i]!='B' and s[j]!='B': res += bs[j+1] if j-i+j < n: if s[j-i+j] == 'B': res -=1 elif s[i]!='G' and s[j]!='G': res += gs[j+1] if j - i + j < n: if s[j-i+j] == 'G': res -=1 else: res += rs[j+1] if j - i + j < n: if s[j-i+j] == 'R': res -= 1 print(res)
1
36,215,100,795,872
null
175
175
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() from collections import defaultdict def resolve(): n,k=map(int,input().split()) A=list(map(int,input().split())) S=[0]*(n+1) for i in range(n): S[i+1]=S[i]+A[i] for i in range(n+1): S[i]-=i S[i]%=k ans=0 D=defaultdict(int) for i in range(n+1): s=S[i] ans+=D[s] D[s]+=1 if(i>=k-1): D[S[i-k+1]]-=1 print(ans) resolve()
import sys input = sys.stdin.readline N, K = map(int, input().strip().split(" ")) A = list(map(int, input().strip().split(" "))) A = [0] + A for i in range(1, N + 1): A[i] += A[i - 1] A[i - 1] -= i - 1 A[N] -= N rem_count = {} rem_count[0] = 1 ans = 0 for i in range(1, N + 1): if i - K >= 0: rem_count[A[i - K] % K] -= 1 if A[i] % K in rem_count: ans += rem_count[A[i] % K] rem_count[A[i] % K] += 1 else: rem_count[A[i] % K] = 1 print(ans)
1
137,278,121,255,520
null
273
273
if int(input())%9==0: print('Yes') else: print('No')
N = input() nums = [] for num in N: nums.append(int(num)) s = sum(nums) if s % 9 == 0: print("Yes") else: print("No")
1
4,362,143,381,368
null
87
87
N = int(input()) X = list(map(int, input().split())) ans = 50 ** 2 * 100 for P in range(1,101): sum = 0 for i in range(N): sum += (X[i] - P) ** 2 if sum < ans: ans = sum print(ans)
N=int(input()) #people li = list(map(int, input().split())) Ave1=sum(li)//N Ave2=sum(li)//N+1 S1=0 S2=0 for i in range(N): S1=S1+(Ave1-li[i])**2 for i in range(N): S2=S2+(Ave2-li[i])**2 if S1>S2: print(S2) else: print(S1)
1
65,272,172,308,258
null
213
213
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n = I() a = LI() dic = collections.Counter(a) als = 0 exl = [0 for _ in range(n+1)] for key, value in dic.items(): if value >= 3: choice = (value)*(value-1)//2 choice1 = (value-1)*(value-2)//2 als += choice exl[key] = choice1 - choice elif value == 2: choice = (value)*(value-1)//2 als += choice exl[key] = -choice for ball in a: choices = als + exl[ball] print(choices) main()
S = list(input()) if S[-1] == S[-2] and S[-3] == S[-4]: print("Yes") else: print("No")
0
null
44,812,653,293,578
192
184
N = int(input()) A_list = [int(i) for i in input().split()] monney = 1000 stock = 0 def max_day(index): if index == N-1 or (A_list[index] > A_list[index+1]): return index return max_day(index+1) def min_day(index): if index == N-1: return -1 if A_list[index] < A_list[index+1]: return index return min_day(index+1) def main(day=0, flag="buy"): global monney, stock if flag == "buy": buy_day = min_day(day) if buy_day == -1: return monney stock, monney = divmod(monney, A_list[buy_day]) return main(buy_day+1, "sell") elif flag == "sell": sell_day = max_day(day) monney += stock * A_list[sell_day] stock = 0 if sell_day == N-1: return monney return main(sell_day+1, "buy") print(main())
N = int(input()) A = list(map(int,input().split())) money=1000 best = money pos = 1 kabu = 0 #初動 買うか買わないか if A[0]<=A[1]: kabu = money//A[0] money -= kabu*A[0] pos=0 else: pos=1 #二回目以降 買うか売るか保留か for i in range(1,N): if pos==0:#売り if A[i-1]>=A[i]: money+=kabu*A[i-1] kabu=0 pos=1 elif pos==1:#買い if A[i-1]<A[i]: kabu = money//A[i-1] money -= kabu*A[i-1] pos=0 best = max(best,money+kabu*A[i]) print(best)
1
7,286,763,796,700
null
103
103
from collections import defaultdict d = defaultdict(int) N = int(input()) arr = list(map(int, input().split())) ans = 0 for i in range(N): ans += d[i-arr[i]] d[i+arr[i]] += 1 print(ans)
# https://atcoder.jp/contests/abc166/tasks/abc166_e """ 変数分離すれば互いに独立なので、 連想配列でO(N)になる。 """ import sys input = sys.stdin.readline from collections import Counter N = int(input()) A = list(map(int, input().split())) P = (j+1-A[j] for j in range(N)) M = (i+1+A[i] for i in range(N)) dic = Counter(P) res = 0 for m in M: res += dic.get(m,0) print(res)
1
26,040,941,597,122
null
157
157
import math a, b, c = map(int, input().split()) PI = 3.1415926535897932384 c = math.radians(c) print('{:.5f}'.format(a * b * math.sin(c) / 2)) A = a - b * math.cos(c) B = b * math.sin(c) print('{:.5f}'.format(math.sqrt(A * A + B * B) + a + b)) print('{:.5f}'.format(B))
import math a,b,c=map(float,input().split()) C=math.radians(c) D=math.sin(C)*a*b S=D/2 E=a**2+b**2-2*a*b*math.cos(C) F=math.sqrt(E) L=a+b+F if C<90: h=b*math.sin(C) elif C==90: h=b else: h=b*math.sin(180-C) print(S,L,h)
1
169,641,927,444
null
30
30
s = input() ans = 0 if s[0] == "R": ans += 1 if s[1] == "R": ans += 1 if s[2] == "R": ans += 1 elif s[1] == "R": ans += 1 if s[2] == "R": ans += 1 elif s[2] == "R": ans += 1 print(ans)
#A問題 S = input() if S == "RRR": print(3) if S == "RRS"or S == "SRR" : print(2) if S == "RSR"or S == "RSS" or S == "SRS" or S == "SSR": print(1) if S == "SSS": print(0)
1
4,867,924,971,322
null
90
90
from collections import deque n,x,y = map(int,input().split()) adj = [[] for i in range(n)] adj[x-1].append(y-1) adj[y-1].append(x-1) for i in range(n-1): adj[i].append(i+1) adj[i+1].append(i) ans = [0]*(n-1) for i in range(n): q = deque([]) q.append(i) dist = [-1]*n dist[i] = 0 while len(q) > 0: v = q.popleft() for nv in adj[v]: if dist[nv] != -1: continue dist[nv] = dist[v] + 1 q.append(nv) for i in dist: if i != 0: ans[i-1] += 1 for i in ans: print(i//2)
N ,X, Y = map(int, input().split()) rlt = [0]*N for i in range(1,N+1): for j in range(i+1,N+1): if (i < X and j < X) or (i > Y and j > Y): rlt[j-i] += 1 elif i < X and j > Y: rlt[X-i+j-Y+1] += 1 elif i < X and j <= Y: rlt[min(j-i,X-i+1+Y-j)] += 1 elif i >= X and j > Y: rlt[min(j-i,i-X+1+j-Y)] += 1 elif i >= X and j <= Y: rlt[min(j-i,i-X+Y-j+1)] += 1 for i in rlt[1:]: print(i)
1
44,201,073,902,692
null
187
187
n=int(input()) a=list(map(int,input().split())) for i in a: if i%2==0: if i%3!=0 and i%5!=0: print('DENIED') exit() print('APPROVED')
a=int(input()) b=int(input()) c=int(input()) if a<b: a,b=b,a if c%a==0: print(c//a) else: print(c//a+1)
0
null
79,089,332,072,620
217
236
N = int(input()) S = [input() for i in range(N)] dict = {} for s in S : dict.setdefault(s, 0) dict[s] += 1 max_value = max(dict.values()) ans = sorted([ k for k,v in dict.items() if v == max_value]) for a in ans : print(a)
import sys from collections import Counter read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) l = read().decode().split() c = Counter(l) max = c.most_common()[0][1] ans = [i[0] for i in c.items() if i[1] >= max] print('\n'.join(sorted(ans)))
1
69,877,121,035,262
null
218
218
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) x=int(input()) a,b=divmod(x,100) if a*5>=b: print(1) else: print(0)
x = int(input()) dp = [True] + [False] * (x+110) for i in range(len(dp)): if not dp[i]: continue for food in range(100, 106): if i+food >= len(dp): continue dp[i+food] = True if dp[x]: print(1) else: print(0)
1
127,894,430,077,052
null
266
266
class Combination: def __init__(self, mod, max_n): self.MOD = mod self.MAX_N = max_n self.f = self.factorial(self.MAX_N) self.f_inv = [self.inv(x) for x in self.f] def inv(self,x): return pow(x, self.MOD-2, self.MOD) def factorial(self, n): res = [1] for i in range(1,n+1): res.append(res[-1] * i % self.MOD) return res def comb(self, n, r): return (self.f[n] * self.f_inv[r] % self.MOD) * self.f_inv[n-r] % self.MOD X, Y = map(int,input().split()) k, l = (2*Y-X)//3, (2*X-Y)//3 if (X + Y) % 3 != 0 or k < 0 or l < 0: print(0) exit() CB = Combination(10**9+7, k+l) print(CB.comb(k+l,k))
def main(): mod = 1000000007 n = int(input()) cnt = [0] * (n + 2) cnt[0] = 3 res = 1 for x in input().split(): v = int(x) res *= cnt[v] - cnt[v + 1] res %= mod cnt[v + 1] += 1 print(res) main()
0
null
140,445,463,439,358
281
268
n = input() sum = 0; for i in n: sum += int(i) if sum % 9 == 0: print('Yes') else: print('No')
round=int(input()) T_pt=0 H_pt=0 for i in range(round): pair=raw_input().split(" ") T_card=pair[0].lower() H_card=pair[1].lower() if T_card<H_card: H_pt+=3 elif T_card>H_card: T_pt+=3 else: T_pt+=1 H_pt+=1 print T_pt,H_pt
0
null
3,249,427,335,968
87
67
N,M = map(int,input().split()) ans = [] s = 1 e = M+1 while e>s: ans.append([s,e]) s += 1 e -= 1 s = M+2 e = 2*M+1 while e>s: ans.append([s,e]) s += 1 e -= 1 for s,e in ans: print(s,e)
import sys from collections import Counter inint = lambda: int(sys.stdin.readline()) inintm = lambda: map(int, sys.stdin.readline().split()) inintl = lambda: list(inintm()) instrm = lambda: map(str, sys.stdin.readline().split()) instrl = lambda: list(instrm()) class UnionFind(): def __init__(self, n): self.n = n # 要素数(初期頂点数) self.root = [i for i in range(n)] # 根 self.rank = [0] * n # 深さ self.sizes = [1] * n # 要素数(木) def find(self, x): # 根を返す if self.root[x] == x: return x self.root[x] = self.find(self.root[x]) # 経路圧縮 return self.root[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: # 浅い方を深い方につなげる self.root[x] = y self.sizes[y] += self.sizes[x] else: self.root[y] = x self.sizes[x] += self.sizes[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): # 同じ集合かどうかの真偽を返す return self.find(x) == self.find(y) def roots(self): return {i for i, num in enumerate(self.root) if i == num} def size(self, x): return self.sizes[self.find(x)] n, m = inintm() uf = UnionFind(n) for i in range(m): a, b = inintm() uf.unite(a-1, b-1) ans = 0 r = uf.roots() for i in r: if uf.size(i) > ans: ans = uf.size(i) print(ans)
0
null
16,385,211,605,120
162
84
def cmb(a,b,c): b = min(b,a-b) num = 1 for i in range(b): num = num*(a-i) % c den = 1 for i in range(b): den = den*(i+1) % c return num * pow(den,c-2,c) % c mod = 10**9+7 n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() ans = 0 c = cmb(n-1,k-1,mod) if k == 1: print(0) exit() for i in range(n-k+1): ans -= a[i] * c ans += a[-i-1] * c ans %= mod c = (c * (n-k-i) * pow(n-i-1,mod-2,mod)) % mod if ans < 0: ans += mod print(ans)
class Combination: """ O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms) 使用例: comb = Combination(1000000) print(comb(5, 3)) # 10 """ def __init__(self, n_max, mod=10**9+7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): if n < r: return 0 return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n+1): fac.append(fac[i-1] * i % self.mod) facinv.append(facinv[i-1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n+1) modinv[1] = 1 for i in range(2, n+1): modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod return modinv def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 A.sort() ans = 0 comb = Combination(1000000) cnt = [] for i in range(N-K+1): cnt.append(comb(N-i-1,K-1)) ans -= comb(N-i-1,K-1) * A[i] for i in range(N,N-len(cnt),-1): ans += A[i-1] * (cnt[N-i]) ans %= MOD print(ans) if __name__ == "__main__": main()
1
95,798,798,232,098
null
242
242
import array N = int(input()) A = array.array('L', list(map(int, input().split()))) MAX = 10**5+1 X = array.array('L', [0]) * MAX Y = array.array('L', range(MAX)) for i in range(len(A)): X[A[i]] += 1 Q = int(input()) cur = sum(array.array('L', (X[i]*Y[i] for i in range(len(X))))) for i in range(Q): [b, c] = list(map(int, input().split())) cur = cur - X[b]*b + X[b]*c print(cur) X[c] += X[b] X[b] = 0
s = input() t = input() if (s == t[0:len(s)]) and (len(s)+1 == len(t)): print("Yes") else: print("No")
0
null
16,761,548,528,398
122
147
n=int(raw_input().strip()) lst=[] minval=0x3f3f3f3f ans=-0x3f3f3f3f for i in xrange(n): val=int(raw_input().strip()) if(i>=1): #print val,minval ans=max(ans,val-minval) minval = min(minval, val) print ans
a,b = -1e11,1e11 for _ in range(int(input())): c = int(input()) a,b = max(a,c-b),min(b,c) print(a)
1
13,131,211,392
null
13
13
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)
import collections n=int(input()) A=list(map(int,input().split())) if A[0]!=0: print(0) exit() mod=998244353 C=[0]*n for i in range(n): C[A[i]]+=1 ans=1 if C[0]!=1: print(0) exit() for i in range(n-1): ans=ans*pow(C[i],C[i+1],mod)%mod print(ans)
0
null
158,031,258,205,564
288
284
import sys stdin = sys.stdin inf = 1 << 60 mod = 1000000007 sys.setrecursionlimit(10**7) ni = lambda: int(ns()) nin = lambda y: [ni() for _ in range(y)] na = lambda: list(map(int, stdin.readline().split())) nan = lambda y: [na() for _ in range(y)] nf = lambda: float(ns()) nfn = lambda y: [nf() for _ in range(y)] nfa = lambda: list(map(float, stdin.readline().split())) nfan = lambda y: [nfa() for _ in range(y)] ns = lambda: stdin.readline().rstrip() nsn = lambda y: [ns() for _ in range(y)] ncl = lambda y: [list(ns()) for _ in range(y)] nas = lambda: stdin.readline().split() def modpow(n, p, m): if p == 0: return 1 if p % 2 == 0: t = modpow(n, p // 2, m) return t * t % m return n * modpow(n, p - 1, m) % m n = ni() A = modpow(9, n, mod) B = A C = modpow(8, n, mod) D = modpow(10, n, mod) ans = (D - A - B + C) % mod print(ans)
def main(): line1 = input() line2 = input() line3 = input() n, m, k = list(map(int, line1.split())) a = [0] + list(map(int, line2.split())) b = [0] + list(map(int, line3.split())) mark1, mark2 = 0, 0 for i in range(1, len(a)): a[i] += a[i-1] if a[i] > k: mark1 = i break for i in range(1, len(b)): b[i] += b[i-1] if b[i] > k: mark2 = i break if mark1: a = a[:mark1] if mark2: b = b[:mark2] ans = 0 for i in range(len(a)): target = k - a[i] tmp = 0 low, high = 0, len(b) while low < high: mid = (low + high) // 2 if b[mid] <= target: tmp = mid low = mid + 1 else: high = mid - 1 ans = max(ans, i + tmp) print(ans) return if __name__ == "__main__": main()
0
null
6,939,217,273,242
78
117
def fib(n): def iter(a, b, cnt): if cnt == 0: return a return iter(b, a+b, cnt-1) return iter(1, 1, n) if __name__ == '__main__': n = int(input()) print(fib(n))
A=[0 for i in range(45)] A[0]=1 A[1]=1 for i in range(2,45): A[i]=A[i-1]+A[i-2] B=int(input()) print(A[B])
1
1,854,158,530
null
7
7
X, Y, Z = map(str, input().split()) print(Z+" "+X+" "+Y)
a, b, c = map(int, input().split()) a, b = b, a a, c = c, a print(a, b, c, sep = " ")
1
38,203,288,687,902
null
178
178
#!/usr/bin/env python3 def next_line(): return input() def next_int(): return int(input()) def next_int_array_one_line(): return list(map(int, input().split())) def next_int_array_multi_lines(size): return [int(input()) for _ in range(size)] def next_str_array(size): return [input() for _ in range(size)] def main(): a = next_line() if 'A' <= a[0] and a[0] <= 'Z': print("A") else: print("a") if __name__ == '__main__': main()
import numpy as np from scipy.sparse.csgraph import floyd_warshall def main(): N, M, L = map(int, input().split()) graph = [[0] * N for _ in range(N)] for _ in range(M): s, t, w = map(int, input().split()) if w <= L: graph[s-1][t-1] = graph[t-1][s-1] = w graph = floyd_warshall(graph, directed=False) graph = floyd_warshall(graph <= L, directed=False) graph[np.isinf(graph)] = 0 Q = int(input()) ans = [] for _ in range(Q): s, t = map(int, input().split()) ans.append(int(graph[s-1][t-1]) - 1) print(*ans, sep='\n') if __name__ == '__main__': main()
0
null
92,524,726,902,998
119
295
from collections import defaultdict def main(): n = int(input()) s =defaultdict(lambda:0) for i in range(n): s[input()] += 1 max_s = max(s.values()) for key, value in sorted(s.items()): if value == max_s: print(key) if __name__ == "__main__": main()
class Acc2D: def __init__(self, a): h, w = len(a), len(a[0]) self.acc2D = self._build(h, w, a) def _build(self, h, w, a): ret = [[0] * (w + 1) for _ in range(h + 1)] for r in range(h): for c in range(w): ret[r + 1][c + 1] = ret[r][c + 1] + ret[r + 1][c] - ret[r][c] + (1 if a[r][c] == '#' else 0) # 末項は必要に応じて改変すること return ret def get(self, r1, r2, c1, c2): # [r1,r2), [c1,c2) : 0-indexed acc2D = self.acc2D return acc2D[r2][c2] - acc2D[r1][c2] - acc2D[r2][c1] + acc2D[r1][c1] def main(): import sys sys.setrecursionlimit(10 ** 7) def fill_cake(r1, r2, c1, c2) -> None: """ケーキに番号を振る""" nonlocal piece_number for r in range(r1, r2): for c in range(c1, c2): ret[r][c] = piece_number piece_number += 1 def cut_cake(r1, r2, c1, c2, rest) -> None: """[r1,r2),[c1,c2)の範囲にrest個ケーキがある状態からのカット""" if rest == 1: fill_cake(r1=r1, r2=r2, c1=c1, c2=c2) return # これ以上カットする必要がないので、番号を振る for r in range(r1 + 1, r2): piece_count = acc2D.get(r1=r1, r2=r, c1=c1, c2=c2) if 0 < piece_count < rest: # restが減ることを保証する cut_cake(r1=r1, r2=r, c1=c1, c2=c2, rest=piece_count) cut_cake(r1=r, r2=r2, c1=c1, c2=c2, rest=rest - piece_count) return # ケーキを一つ以上含むように水平カットする for c in range(c1 + 1, c2): piece_count = acc2D.get(r1=r1, r2=r2, c1=c1, c2=c) if 0 < piece_count < rest: # restが減ることを保証する cut_cake(r1=r1, r2=r2, c1=c1, c2=c, rest=piece_count) cut_cake(r1=r1, r2=r2, c1=c, c2=c2, rest=rest - piece_count) return # ケーキを一つ以上含むように垂直カットする h, w, k = map(int, input().split()) s = [input() for _ in range(h)] acc2D = Acc2D(s) # usage: acc2D.get(r1,r2,c1,c2) # ケーキ個数の二次元累積和 ret = [[-1] * w for _ in range(h)] piece_number = 1 cut_cake(r1=0, r2=h, c1=0, c2=w, rest=k) for row in ret: print(*row) if __name__ == '__main__': main()
0
null
106,494,675,525,060
218
277
#coding:utf-8 n = int(input()) numbers = list(map(int, input().split())) def selectionSort(ary): count = 0 for i in range(len(ary)): minj = i for j in range(i, len(ary)): if ary[minj] > ary[j]: minj = j if minj != i: ary[minj], ary[i] = ary[i], ary[minj] count += 1 return (ary, count) result = selectionSort(numbers) print(*result[0]) print(result[1])
num = int(input()) A=list(map(int,input().split(" "))) chg = 0 for i in range(num-1): minv = i+1 for j in range(i+2,num): if A[minv] > A[j]: minv = j if A[i] > A[minv]: A[i],A[minv] = A[minv],A[i] chg += 1 print(*A) print(chg)
1
19,642,865,920
null
15
15
N = int(input()) a = N // 100 if 0 <= N - 100 * a <= 5 * a: print(1) else: print(0)
X=int(input()) DP=[0 for i in range(X+1)] DP[0]=1 L=[100,101,102,103,104,105] for s in range(6): for x in range(X+1): if DP[x]==1 and x+L[s]<=X: DP[x+L[s]]=1 print(DP[X])
1
126,980,572,628,944
null
266
266
N = int(input()) A = list(map(int,input().split())) c = 0 if N%2 == 0: for i in range(N//2): c += A[2*i+1] cm = c # print(c) for i in range(N//2): # print(2*i,2*i+1) c += A[2*i]-A[2*i+1] cm = max(c,cm) print(cm) else: dp = [[0]*(3) for _ in range(N//2)] # print(dp) # 初期化 dp[0][0] = A[0] dp[0][1] = A[1] dp[0][2] = A[2] for i in range(0,N//2-1): dp[i+1][0] = dp[i][0] + A[2*i+2] dp[i+1][1] = max(dp[i][0] + A[2*i+3], dp[i][1] + A[2*i+3]) dp[i+1][2] = max(dp[i][0] + A[2*i+4], dp[i][1] + A[2*i+4], dp[i][2] + A[2*i+4]) # print(dp) print(max(dp[N//2-1][0],dp[N//2-1][1],dp[N//2-1][2]))
a = list(map(int,input().split())) p = a[0] q = a[1] for i in range(2000): if int(i*0.08) == p and int(i*0.1) == q: print(i) break if i == 1999: print(-1)
0
null
46,739,686,811,660
177
203
x = int(input()) a = x // 200 print((8 - a) + 2)
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)
1
6,616,565,892,562
null
100
100
x, y = map(int,input().split()) min = 2 * x gap = y - min if gap < 0 or gap > min: print("No") else: if gap % 2 == 0: print("Yes") else: print("No")
n = int(input()) a, b = map(int, input().split()) ans = 0 for i in range(a, b + 1): if i % n == 0: ans += 1 break print("OK" if ans == 1 else "NG")
0
null
20,070,606,931,448
127
158
from sys import stdin from collections import deque n = int(input()) d = [-1] * (n + 1) G = [0] + [list(map(int, input().split()[2:])) for _ in range(n)] d[1] = 0 dq = deque([1]) while len(dq) != 0: v = dq.popleft() for c in G[v]: if d[c] == -1 : d[c] = d[v] + 1 dq.append(c) for i, x in enumerate(d[1:], start=1): print(i, x)
from collections import deque N = int(input()) nodes = [] G ={} is_visited = {} q = deque() for _ in range(N): lst = list(map(int, input().split())) idx = lst[0] nodes.append(idx) is_visited[idx] = False degree = lst[1] if degree > 0: G[idx] = lst[2:] else: G[idx] = [] INF = 10**12 costs = [INF]*N # bfs # 初期queue que = deque() # 必要なものはnodeidと原点からの距離 que.append(1) costs[0] = 0 while que: node_id = que.popleft() # 先入れ先出し cost = costs[node_id-1] for next_id in G[node_id]: if (costs[next_id-1] == INF): que.append(next_id) costs[next_id-1] = cost + 1 for i in range(N): if costs[i] != INF: print(i+1, costs[i]) else: print(i+1, -1)
1
3,912,519,382
null
9
9
S = input() A = '' P = 0 for s in range(len(S)): if P < 3: A += S[s] P += 1 print(A)
x1, y1, x2, y2 = map(float, raw_input().split()) num = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) if num == 0: print 0 else: xi = num for _ in range(100): xi = (xi + (num / xi)) / 2.0 print xi
0
null
7,498,653,719,228
130
29
n, m = map(int, input().split()) s = input() if "1" * m in s: print(-1) exit() pos = n ans = [] while pos > 0: prev = max(pos - m, 0) while s[prev] == "1": prev += 1 ans.append(pos - prev) pos = prev ans = ans[::-1] print(*ans)
A, B = [int(x) for x in input().split(" ")] if A > B*2: print(A-B*2) else: print(0)
0
null
152,729,079,888,700
274
291
N, K = map(int, input().split()) ls1 = list(map(int, input().split())) d = dict() ls2 = ['r', 's', 'p'] for x, y in zip(ls1, ls2): d[y] = x T = input() S = T.translate(str.maketrans({'r': 'p', 's': 'r', 'p': 's'})) ans = 0 for i in range(K): cur = '' for j in range(i, N, K): if cur != S[j]: ans += d[S[j]] cur = S[j] else: cur = '' print(ans)
s=input() if s=='SUN': print(7) if s=='MON': print(6) if s=='TUE': print(5) if s=='WED': print(4) if s=='THU': print(3) if s=='FRI': print(2) if s=='SAT': print(1)
0
null
119,923,220,262,018
251
270
x,y = map(int,input().split()) if y % 2 != 0: print('No') elif x * 2 <= y <= x * 4: print('Yes') else: print('No')
x, y = map(int, input().split()) ans = any(2 * i + 4 * (x - i) == y for i in range(x + 1)) print('Yes' if ans else 'No')
1
13,703,054,331,642
null
127
127
data = input() data = data.split() print("Yes") if int(data[0]) / int(data[2]) <= int(data[1]) else print("No")
import math import collections n, k = map(int, input().split()) W = collections.deque() for i in range(n): W.append(int(input())) left = max(math.ceil(sum(W) / k), max(W)) right = sum(W) center = (left + right) // 2 # print('------') while left < right: i = 1 track = 0 # print(center) for w in W: # if center == 26: # print('track: ' + str(track)) track += w if track > center: track = w i += 1 if i > k: left = center + 1 break else: right = center center = (left + right) // 2 print(center)
0
null
1,786,741,205,788
81
24
n=int(input()) if 30<=n : print('Yes') else: print('No')
N=int(input()) x=[0]*N for i in range(N): x[i]=list(map(int,input().split())) #print(x) z=[0]*N w=[0]*N for i in range(N): z[i]=x[i][0]+x[i][1] w[i]=x[i][0]-x[i][1] print(max(max(z)-min(z),max(w)-min(w)))
0
null
4,531,931,946,850
95
80
s, S = divmod(input(), 60) H, M = divmod(s, 60) print '%d:%d:%d' %(H,M,S)
S = int(input()) print(S // 3600, S // 60 % 60, S % 60, sep = ':')
1
335,331,362,532
null
37
37
ln = input().split() print(ln[1]+ln[0])
def resolve(): a, b = input().split() print(b+a) resolve()
1
103,123,910,709,920
null
248
248
# https://atcoder.jp/contests/abc161/tasks/abc161_d import sys # sys.setrecursionlimit(100000) import heapq 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(): n = int(input()) if n < 10: print(n) return cnt = 0 hq = [1, 2, 3, 4, 5, 6, 7, 8, 9] while cnt < n: i = heapq.heappop(hq) cnt += 1 if cnt == n: print(i) return r = int(str(i)[::-1][0]) heapq.heappush(hq, int(str(i) + str(r))) if r != 9: heapq.heappush(hq, int(str(i) + str(r + 1))) if r != 0: heapq.heappush(hq, int(str(i) + str(r - 1))) return if __name__ == "__main__": main()
N = int(input()) #U:0~9の整数でN桁の数列 = 10**N #A:0を含まないN桁の数列 = 9**N #B:9を含まないN桁の数列 = 9**N #ans = |U-(A∪B)| = |U|-|A|-|B|+|A∩B| MOD = 10**9 + 7 ans = pow(10, N, MOD) - pow(9, N, MOD) - pow(9, N, MOD) + pow(8, N, MOD) ans %= MOD print(ans)
0
null
21,536,230,019,964
181
78
import sys input = sys.stdin.readline MOD = pow(10, 9) + 7 n = int(input()) a = list(map(int, input().split())) m = max(a) num = [0] * 61 for x in a: for j in range(61): if (x >> j) & 1: num[j] += 1 s = 0 #print(num) for i in range(61): s += (n - num[i]) * num[i] * pow(2, i, MOD) % MOD print(s % MOD)
from copy import deepcopy N, M = map(int, input().split()) pairs = [0] * M for i in range(M): pairs[i] = list(map(int, input().split())) # N = 5 # pairs = [[1,2], [3,4], [5,1]] class UnionFind: def __init__(self, N): self.r = [-1] * N def root(self, x): if self.r[x] < 0: return x self.r[x] = self.root(self.r[x]) return self.r[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False if self.r[x] > self.r[y]: x, y = y, x self.r[x] += self.r[y] self.r[y] = x return True def size(self, x): return -self.r[self.root(x)] uf = UnionFind(N) for pair in pairs: a = pair[0] - 1 b = pair[1] - 1 uf.unite(a, b) ans = 0 for i in range(N): ans = max(ans, uf.size(i)) print(ans)
0
null
63,555,479,124,680
263
84
#ABC156B n,k = map(int,input().split()) ans = 0 while n > 0 : n = n // k ans = ans + 1 print(ans)
N,K=list(map(int, input().split())) ct=0 while N>0: N=N//K ct+=1 print(ct)
1
64,270,138,167,090
null
212
212
n = int(input()) A = list(map(int,input().split())) if not 1 in A: print(-1) exit() num = 1 cnt = 0 for a in A: if a == num: num += 1 else: cnt += 1 print(cnt)
K = int(input()) S = input() s = len(S) L = [] mod = 10 ** 9 + 7 N = 2 * 10**6 fac = [1, 1] finv = [1, 1] inv = [0, 1] def cmb(n, r): return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod for i in range(2, N + 1): fac.append( ( fac[-1] * i ) % mod ) inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) ) finv.append( finv[-1] * inv[-1] % mod ) for i in range(K+1): L.append( cmb(i+s-1, s-1) * pow(25, i, mod) % mod ) ans = [] for i, x in enumerate(L): if i == 0: ans.append(x) else: ans.append( ( ans[i-1]*26%mod + x ) % mod ) print(ans[K])
0
null
63,544,435,865,762
257
124
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()
h,w = map(int,input().split()) f = [] for i in range(h): s = list(map(lambda x:0 if x== "." else 1,list(input()))) f.append(s) from collections import deque def dfs_field(field,st,go): """ :param field: #が1,.が0になったfield st: [i,j] go: [i,j] :return: 色々今は回数returnしている。 """ h = len(field) w = len(field[0]) around = [[-1,0],[1,0],[0,1],[0,-1]] que = deque() visited = set() visited.add(str(st[0])+","+str(st[1])) que.append([st[0],st[1],0]) max_cos = 0 while True: if len(que) == 0: return max_cos top = que.popleft() nowi = top[0] nowj = top[1] cost = top[2] for a in around: ni = nowi+a[0] nj = nowj+a[1] if ni < 0 or ni > h-1 or nj < 0 or nj > w-1: continue if field[ni][nj] == 1: continue if ni == go[0] and nj == go[1]: return cost+1 else: key = str(ni)+","+str(nj) if key not in visited: que.append([ni,nj,cost+1]) visited.add(key) if cost+1 > max_cos: max_cos = cost+1 # print(que) ans = 0 for i in range(h): for j in range(w): if f[i][j] == 0: ct = dfs_field(f,[i,j],[-2,-2]) if ans < ct: ans = ct print(ans)
0
null
73,633,511,101,062
198
241
n,m=map(int,raw_input().split()) a,b=[],[] for i in range(n):a.append(map(int,raw_input().split())) for i in range(m):b.append(input()) for i in range(n): ans=0 for j in range(m): ans+=a[i][j]*b[j] print ans
# -*- coding: utf-8 -*- list = map(int, raw_input().split()) a = list[0] b = list[1] print a*b , print 2*(a+b)
0
null
745,690,782,332
56
36
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) mod = 10 ** 9 + 7 b = 1 ans = 0 for i in range(k - 1, n): ans += b * (a[i] - a[n - i - 1]) ans %= mod b = (i+1)*pow(i-k+2, mod - 2, mod) * b % mod print(ans)
def pre_c(n, mod): f = [0] * (n + 1) g = [0] * (n + 1) for i in range(n + 1): if i == 0: f[i] = 1 g[i] = 1 else: f[i] = (f[i - 1] * i) % mod g[i] = pow(f[i], mod - 2, mod) return f, g n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() mod = 10 ** 9 + 7 f, g = pre_c(n, mod) ans = 0 for i in range(n - k + 1): min_temp = a[i] * f[n - i - 1] * g[k - 1] * g[n - i - 1 - k + 1] % mod max_temp = a[n - i - 1] * f[n - i - 1] * g[k - 1] * g[n - i - 1 - k + 1] % mod ans = (ans + (max_temp - min_temp) % mod ) %mod print(ans)
1
95,553,917,497,984
null
242
242
# https://atcoder.jp/contests/abc163/tasks/abc163_d def main(): n, k = map(int, input().split(" ")) # このやり方だと当然TLE # total = 0 # for i in range(k, n + 2): # a = 0 # b = 0 # for j in range(i): # a += j # b += n - j # total += b - a + 1 # print(total) max_num = sum(range(n - k + 1, n + 1)) min_num = sum(range(k)) c = max_num - min_num + 1 total = c for i in range(k, n + 1): max_num += n - i min_num += i c = max_num - min_num + 1 total += c print(total % 1000000007) if __name__ == '__main__': main()
N = int(input()) ans = 0 if N % 2 == 1: pass else: two = 0 five = 0 tmp = 2 while tmp <= N: two += N // tmp tmp *= 2 tmp = 10 while tmp <= N: five += N // tmp tmp *= 5 ans = min(two, five) print(ans)
0
null
74,779,154,533,230
170
258
N = int(input()) x = input().strip() cnt = 0 for i in range(N): if x[i]=="R": cnt += 1 if cnt==0 or cnt==N: print(0) else: ans = 0 for i in range(cnt): if x[i]=="W": ans += 1 print(ans)
n=int(input()) s=input() r=0 for i in s: if(i=="R"): r+=1 ans=0 for j in range(r): if(s[j]=="W"): ans+=1 print(ans)
1
6,267,858,101,280
null
98
98
i = 1 while True : x = input() if (x == 0) : exit() print "Case %d: %d" % (i, x) i += 1
N = int(input()) X = (N%100)%10 if X == 3: print('bon') elif X == 0 or X == 1 or X == 6 or X == 8: print('pon') else: print('hon')
0
null
9,796,349,702,980
42
142
a=int(input()) b,c=input().split() b=int(b) c=int(c) if b%a==0 or c%a==0: print("OK") else: if int(b/a)==int(c/a): print("NG") else: print("OK")
k=int(input()) a,b=map(int,input().split()) c=1 for i in range(a,b+1): if i%k==0: print("OK") c=0 break if c==1: print("NG")
1
26,567,238,986,332
null
158
158
x=input().split() n=int(x[0]) k=int(x[1]) def fact_inverse(n,p): fact=[1]*(n+1) inv=[1]*(n+1) inv_fact=[1]*(n+1) inv[0]=0 inv_fact[0]=0 for i in range(2,n+1): fact[i]=(fact[i-1]*i)%p #compute the inverse of i mod p inv[i]=(-inv[p%i]*(p//i))%p inv_fact[i]=(inv_fact[i-1]*inv[i])%p return fact,inv_fact def combi2(n,p): f,inv=fact_inverse(n,p) combis=[1]*(n+1) for k in range(1,n+1): if k >=n//2+1: combis[k]=combis[n-k] else: combis[k]=(((f[n]*inv[n-k])%p)*inv[k])%p return combis p=10**9+7 combis1=combi2(n,p) combis2=combi2(n-1,p) s=0 L=min(n,k+1) for i in range(L): s=(s+(combis1[i]*combis2[i])%p)%p print(s)
n,k =list(map(int,input().split())) mod = 10**9+7 ans = 1%mod left_combination = 1 right_combination = 1 for i in range(1,min(k,n-1)+1): left_combination = (left_combination*(n+1-i)*pow(i,mod-2,mod))%mod right_combination = (right_combination*(n-i)*pow(i,mod-2,mod))%mod ans = (ans + (left_combination*right_combination)%mod)%mod print(ans)
1
67,171,862,123,072
null
215
215
X = int(input()) if X == 2: print(2) exit() for i in range(X,2*X): for j in range(2,i): if i % j == 0: break if j == i-1: print(i) exit()
x=int(input()) for i in range(x,10**6+1): now=i-1 flag=0 while(2<=now): if i%now==0: flag=1 break now-=1 if flag==0: print(i) break
1
105,705,177,419,632
null
250
250
h,w = map(int,input().split()) s = [list(str(input())) for i in range(h)] dp = [[10 ** 10] * w for i in range(h)] if s[0][0] == "#":dp[0][0] = 1 else:dp[0][0] = 0 for i in range(w): for j in range(h): if s[j][i] == "#": s[j][i] = 1 else: s[j][i] = 0 for i in range(1,h+w-1): for j in range(i+1): if 0 < j < h and 0 <= i-j < w: dp[j][i-j] = min(dp[j-1][i-j]+(s[j][i-j]&~s[j-1][i-j]),dp[j][i-j]) if 0 < i-j < w and 0 <= j < h: dp[j][i-j] = min(dp[j][i-j-1]+(s[j][i-j]&~s[j][i-j-1]),dp[j][i-j]) print(dp[h-1][w-1])
from sys import stdin X = int(stdin.readline().rstrip()) print(10-X//200)
0
null
27,841,580,503,142
194
100
k =int(input()) seq = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51' li = list(map(int,seq.split(', '))) print(li[k-1])
A,B,C,D=map(int,input().split()) while 1: C=C-B if C<=0: print("Yes") break A=A-D if A<=0: print("No") break
0
null
39,746,889,281,660
195
164
if __name__ == '__main__': from sys import stdin while True: m, f, r = (int(n) for n in stdin.readline().rstrip().split()) if m == f == r == -1: break s = m + f result = "F" if m == -1 or f == -1 \ else "A" if 80 <= s \ else "B" if 65 <= s \ else "C" if 50 <= s or 50 <= r \ else "D" if 30 <= s \ else "F" print(result)
result = [] while True: (m, f, r) = [int(i) for i in input().split()] sum = m + f if m == f == r == -1: break if m == -1 or f == -1: result.append('F') elif sum >= 80: result.append('A') elif sum >= 65: result.append('B') elif sum >= 50: result.append('C') elif sum >= 30: if r >= 50: result.append('C') else: result.append('D') else: result.append('F') [print(result[i]) for i in range(len(result))]
1
1,248,962,204,360
null
57
57
x, y = map(int,input().split()) if (y%2 == 1): print("No") else: if (y < x*2): print("No") elif (y > x*4): print("No") else: print("Yes")
from collections import defaultdict n = int(input()) d = list(map(int,input().split())) dic = defaultdict(int) ans = 1 mod = 998244353 for i in range(n): dic[d[i]] += 1 if dic[0] == 1 and d[0] == 0: for i in range(n): if not (dic[i] == 0 and dic[i+1] == 0): ans *= dic[i]**dic[i+1] % mod ans %= mod print(ans) else: print(0)
0
null
84,505,485,706,510
127
284
h,w,k = map(int, input().split()) s = [] st = 0 zero = [0 for i in range(h)] z = 0 for i in range(h): t = input() st += t.count('#') zero[i] = t.count('#') s.append(t) cake = 0 ans = [[0 for j in range(w)] for i in range(h)] for i in range(h): if zero[i] == 0: continue cake += 1 t = 0 for j in range(w): if s[i][j] == '#': t += 1 if t >= 2: cake += 1 ans[i][j] = cake for i in range(h-1): if zero[i+1] != 0: continue if ans[i][0] == 0: continue for j in range(w): ans[i+1][j] = ans[i][j] for i in range(h-1,0,-1): if zero[i-1] != 0: continue for j in range(w): ans[i-1][j] = ans[i][j] for i in range(h): print (*ans[i])
h,w,k = map(int, input().split()) cake = [input() for i in range(h)] ans = [[0]*w for i in range(h)] now = 1 for i in range(h): for j in range(w): if cake[i][j] == '#': ans[i][j] = now now+=1 for i in range(h): for j in range(1,w): if ans[i][j] == 0: ans[i][j] = ans[i][j-1] for i in range(h): for j in reversed(range(w-1)): if ans[i][j] == 0: ans[i][j] = ans[i][j+1] for i in range(1,h): for j in range(w): if ans[i][j] == 0: ans[i][j] = ans[i-1][j] for i in reversed(range(h-1)): for j in range(w): if ans[i][j] == 0: ans[i][j] = ans[i+1][j] for i in range(h): for j in range(w): print(ans[i][j], end=' ') print()
1
143,832,969,173,872
null
277
277
dict = {} def insert(word): global dict dict[word] = 0 def find(word): global dict if word in dict: print('yes') else: print('no') def main(): N = int(input()) order = [list(input().split()) for _ in range(N)] for i in range(N): if order[i][0] == 'insert': insert(order[i][1]) elif order[i][0] == 'find': find(order[i][1]) main()
from sys import stdin readline = stdin.readline payment, _ = map(int, readline().split()) coin = list(map(int, readline().split())) dp = [float('inf')] * (payment + 1) dp[0] = 0 for ci in coin: for pi in range(ci, len(dp)): if dp[pi] > dp[pi - ci] + 1: dp[pi] = dp[pi - ci] + 1 print(dp[-1])
0
null
108,753,308,882
23
28
def combination(n, r, m): res = 1 r = min(r, n - r) for i in range(r): res = res * (n - i) % m res = res * pow(i + 1, m - 2, m) % m return res mod = 10**9 + 7 n, a, b = map(int, input().split()) total = pow(2, n, mod) - 1 total -= (combination(n, a, mod) + combination(n, b, mod)) % mod print(total % mod)
N = int(input()) An = list(map(int, input().split())) money = 1000 stock = 0 for i in range(N-1): if An[i+1] > An[i]: stock = money // An[i] money += (An[i+1] - An[i]) * stock print(money)
0
null
36,705,159,191,284
214
103
n = int(input()) cnt=0 for _ in range(n): a,b=map(int,input().split()) if a==b: cnt+=1 if cnt>=3: break else: cnt=0 if cnt>=3: print("Yes") else: print("No")
n = int(input()) s = 0 b = False for _ in range(n): w = input().split() if w[0] == w[1]: s += 1 if s == 3: b = True break else: s = 0 print('Yes' if b else 'No')
1
2,506,922,669,052
null
72
72
import math a,b=[int(i) for i in input().split()] c=a//b e=abs(a-(b*c)) f=abs(a-(b*(c+1))) print(min(e,f))
# -*- coding: utf-8 -*- N, K = map(int, input().split()) remainder = N % K if remainder > K / 2: print(abs(remainder - K)) else: print(remainder)
1
39,396,697,453,222
null
180
180
A, B = map(int, input().split()) ans1 = 0 ans2 = 0 for i in range(10000): ans1 = int(i * 0.08) ans2 = int(i * 0.10) if (ans1) == A and int(ans2) == B: print(i) exit() print(-1)
import math a,b = map(int,input().split()) c = math.ceil min8, max8 = c(a*12.5), c((a+1)*12.5) min10, max10 = c(b*10), c((b+1)*10) l8, l10 = list(range(min8, max8)), list(range(min10, max10)) s8, s10 = set(l8), set(l10) ss = s8 & s10 #print(min8, max8, min10, max10) print(min(ss) if len(ss) >0 else -1) #print(238*0.08)
1
56,463,999,144,712
null
203
203
N = int(input()) num_even = N//2 num_odd = N - num_even print(num_odd/N)
def main(): n = int(input()) even = n // 2 print(1 - even / n) if __name__ == "__main__": main()
1
177,337,696,221,408
null
297
297
n = int(input()) i,j=1,1 count=0 x = i*j cc = n-x while cc>=1: cnt=0 while 1: p = i*j c = n - p if c>=1: #print(i,":",j,":",c) j=j+1 cnt+=1 else: j=i break count=count+((cnt*2)-1) i=i+1 j=j+1 x = i*j cc = n-x print(count)
#coding: UTF-8 while True: N, X = map(int, input().split()) if N == 0 and X == 0: break ans = 0 for i in range(1, N+1): for j in range(1, N+1): if i >= j: continue c = X - (i + j) if c > j and c <= N: ans += 1 print("%d"%(ans))
0
null
1,924,503,399,320
73
58
s = input() if 4 < len(s) < 6: print('No') exit() if s[::-1] != s: print('No') exit() s = s[:len(s)//2] if s[::-1] != s: print('No') exit() print('Yes')
# ABC159 # String Palindrome S = input() n = len(S) n m = int(((n - 1)/2)-1) l = int(((n + 3)/2)-1) if S[::1] == S[::-1]: if S[:m+1:] == S[m::-1]: if S[l::] == S[:l-1:-1]: print('Yes') exit() print('No')
1
46,128,174,044,170
null
190
190
n = int(input()) X = list(map(int, input().split())) Y = list(map(int, input().split())) C = [abs(X[i] - Y[i]) for i in range(n)] D = [] def distance(X, Y): for k in range(1, 4): d = 0 for j in range(len(X)): d += C[j] ** k d = d ** (1 / k) D.append(d) D.append(max(C)) return D distance(X, Y) for i in range(4): print('{:.08f}'.format(D[i]))
n=int(input()) cnt=0 ans=0 while(n>=1): ans+=2**cnt n//=2 cnt+=1 print(ans)
0
null
40,398,982,897,200
32
228
import sys import math import itertools import numpy import collections rl = sys.stdin.readline n = int(rl()) se = [] for _ in range(n): x, r = map(int, rl().split()) start, end = x-r, x+r se.append([start, end]) se.sort(key=lambda x: x[1]) cur = se[0][0] cnt = 0 for i in se: if cur <= i[0] <= i[1]: cur = i[1] cnt += 1 print(cnt)
n,m=map(int,raw_input().split()) c=map(int,raw_input().split()) dp=[[0]+[float('inf')]*n]+[[0]+[float('inf')]*n for i in xrange(m)] for i in xrange(m): for j in xrange(n+1): if c[i]>j: dp[i+1][j]=dp[i][j] else: dp[i+1][j]=min(dp[i][j],dp[i+1][j-c[i]]+1) print(dp[m][n])
0
null
44,986,485,872,860
237
28
c= int(input()) ans =0 s = 0 while c >1: c = c//2 ans += 1 for i in range(1,ans+1): s += 2**i print(s+1)
import sys def main(): orders = sys.stdin.readlines()[1:] dna_set = set() for order in orders: command, dna = order.split(" ") if command == "insert": dna_set.add(dna) elif command == "find": if dna in dna_set: print("yes") else: print("no") if __name__ == "__main__": main()
0
null
40,217,570,495,072
228
23
import math , sys, bisect N , M , K = list( map( int , input().split() )) A = list( map( int , input().split() )) B = list( map( int , input().split() )) if N > M: N , M = M , N A, B = B , A Asum=[0] Bsum=[] if A[0] > K and B[0] > K: print(0) sys.exit() for i in range(N): if i ==0: tot = A[i] else: tot += A[i] Asum.append(tot) for i in range(M): if i ==0: tot = B[i] else: tot += B[i] Bsum.append(tot) #ans=bisect.bisect(Bsum,K) ans=0 for i in range(N+1): tot = Asum[i] if tot > K: print(ans) sys.exit() num = bisect.bisect(Bsum,K-tot) if i + num >ans: ans=i+num print(ans)
n = int(input()) dic = {} for i in range(1,50000): dic[int(i * 1.08)] = i if n in dic: print(dic[n]) else: print(':(')
0
null
68,177,438,799,328
117
265
n = int(input()) a = list(map(int, input().split())) b = [] for i, v in enumerate(a): b.append([v, i]) b.sort(reverse = True) dp = [[0] * (n+1) for _ in range(n+1)] ans = 0 for i in range(n+1): for j in range(n+1-i): if i > 0: dp[i][j] = max(dp[i][j], dp[i-1][j] + b[i+j-1][0] * (b[i+j-1][1] - (i - 1))) if j > 0: dp[i][j] = max(dp[i][j], dp[i][j-1] + b[i+j-1][0] * ((n - j) - b[i+j-1][1])) for i in range(n+1): ans = max(ans, dp[i][n-i]) print(ans)
def solve(): n = int(input()) s, t = input().split() ans = "" for x, y in zip(s, t): ans = ans + x + y print(ans) solve()
0
null
73,098,280,270,780
171
255
l = list(map(int, input().split())) for i in range(5): if l[i] == 0: print(i + 1)
n = int(input()) S,T = input().split() result = '' for s,t in zip(S,T): result += s result += t print(result)
0
null
62,840,200,246,528
126
255
def base10toK_base(num, K): if num // K: return base10toK_base(num//K, K) + str(num % K) return str(num % K) N, K = map(int, input().split()) ans = len(base10toK_base(N, K)) print(ans)
# E - Payment S = input() N = len(S) # 先頭からi桁目までの金額のやり取りに必要な紙幣の枚数 dp = [0] dp_plus1 = [1] for i in range(N): x = int(S[i]) dp.append(min(dp[i] + x, dp_plus1[i] + (10 - x))) dp_plus1.append(min(dp[i] + (x + 1), dp_plus1[i] + (10 - (x + 1)))) print(dp[-1])
0
null
67,781,060,821,450
212
219
# ABC169 D N=int(input()) def factorization(N): res=[] for i in range(2,int(N**(1/2))+2): if not N%i: r=0 while not N%i: N//=i r+=1 res.append((i,r)) if N>1: res.append((N,1)) return res fact=factorization(N) res=0 for p,r in fact: i=1 while 1: if i*(i+1)//2<= r < (i+1)*(i+2)//2: break else: i+=1 res+=i print(res)
#active infants n=int(input()) lists=list(map(int,input().split())) data=[] for i in range(n): data.append((lists[i],i+1)) data=sorted(data,key=lambda x:-x[0]) #dp[K][i]=始めのKつまで考えてそのうちプラスの個数がiこの方法で最大のあたい(0<=i<=K) #求める値はmax(dp[N][i] for i in range(N+1))で与えられる #dp[N][N]まで考えればいい #計算量0(N**2) dp=[[0 for i in range(n+1)] for j in range(n+1)] dp[1][1]=n*(data[0][0])-data[0][0]*data[0][1] dp[1][0]=data[0][0]*data[0][1]-data[0][0] for i in range(2,n+1): #dp[i]について考える for j in range(i+1): x=data[i-1][0] y=data[i-1][1] #j=0,1,,,,,iまで #dp[i][j]-> 直前は i-1,j-1, or i-1 j のどちらか if i>j>=1: dp[i][j]=max(dp[i-1][j-1]+x*(n+1-j)-x*y,dp[i-1][j]-(i-j)*x+x*y) elif j==0: dp[i][j]=dp[i-1][0]-i*x+x*y elif j==i: dp[i][j]=dp[i-1][i-1]+x*(n+1-j)-x*y K=0 for i in range(n+1): K=max(K,dp[n][i]) print(K)
0
null
25,271,322,892,840
136
171
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) X = I() print((X // 500) * 1000 + ((X - ((X // 500) * 500)) // 5) * 5)
x = int(input()) print(x//500*1000 + x%500//5*5)
1
42,528,656,108,038
null
185
185