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
values = input() a, b = [int(x) for x in values.split()] if a == b: print('a == b') elif a > b: print('a > b') else: print('a < b')
i=map(int,raw_input().split()) if i[0]>i[1]: print "a > b" if i[0]<i[1]: print "a < b" if i[0]==i[1]: print "a == b"
1
366,307,880,220
null
38
38
cnt = 0 n = int(input()) lst = list(map(int, input().split())) for i in range(n): for j in range(n-1,i,-1): if lst[j] < lst[j-1]: lst[j-1:j+1] = lst[j], lst[j-1] cnt += 1 print(*lst) print(cnt)
#coding: utf-8 def print_list(X): first_flag = True for val in X: if first_flag: print_line = str(val) first_flag = False else: print_line = print_line + ' ' + str(val) print(print_line) def bubble_sort(A, N): #print_list(A) #flag: ???????????????????????????True???????´? flag = True counter = 0 while flag: flag = False for j in range(1, N): if A[j] < A[j-1]: tmp_val = A[j] A[j] = A[j-1] A[j-1] = tmp_val flag = True counter += 1 #print_list(A) print_list(A) print(counter) N = int(input()) A = list(map(int, input().split())) bubble_sort(A, N)
1
18,024,810,410
null
14
14
import sys input = sys.stdin.readline print((input() + input()).count('ABC'))
from collections import defaultdict N, u, v = map(int, input().split()) d = defaultdict(list) for _ in range(N-1): A, B = map(int, input().split()) d[A].append(B) d[B].append(A) def get_dist(s): dist = [-1]*(N+1) dist[s] = 0 q = [s] while q: a = q.pop() for b in d[a]: if dist[b]!=-1: continue dist[b] = dist[a] + 1 q.append(b) return dist du, dv = get_dist(u), get_dist(v) ds = [(i,j[0], j[1]) for i,j in enumerate(zip(du, dv)) if j[0]<j[1]] ds.sort(key=lambda x:-x[2]) a, b, c = ds[0] print(c-1)
0
null
108,316,659,211,232
245
259
N = int(input()) a = map(int, input().split()) even = [i for i in a if i % 2 == 0] for check in even: if check % 3 != 0 and check % 5 != 0: print('DENIED') exit() print('APPROVED')
N, K = list(map(int, input().split())) P = list(map(int, input().split())) s = sum(P[:K]) ans = s for i in range(N-K): s = s - P[i] + P[i+K] ans = max(ans,s) print((ans + K) / 2)
0
null
72,059,758,517,884
217
223
def abc150c_count_order(): import bisect, itertools n = int(input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) pattern = list(itertools.permutations(range(1, n+1))) p_idx = bisect.bisect(pattern, p) q_idx = bisect.bisect(pattern, q) print(abs(p_idx-q_idx)) abc150c_count_order()
# similar to problem if n person are arranged in a row and have 3 different hats to wear # no of ways of wearing hats so that every adjacent person wears different hats # so ith person cannot wear more than 3 no of different ways mod = 10**9+7 def main(): ans =1 n = int(input()) arr = list(map(int , input().split())) col=[0 for i in range(0 , 6)] for i in range(0 , n): cnt , cur =0 , -1 if arr[i]==col[0]: cnt = cnt+1 cur = 0 if arr[i]==col[1]: cnt = cnt+1 cur = 1 if arr[i]==col[2]: cnt = cnt+1 cur = 2 if cur ==-1: print(0) exit() col[cur]=col[cur]+1 ans = (ans*cnt)%mod ans = ans%mod print(ans) if __name__ =="__main__": main()
0
null
115,148,832,052,142
246
268
import sys input = sys.stdin.buffer.readline import copy def main(): N,K = map(int,input().split()) MOD = 10**9+7 fac = [0 for _ in range(2*10**5+1)] fac[0],fac[1] = 1,1 inv = copy.deepcopy(fac) invfac = copy.deepcopy(fac) for i in range(2,2*10**5+1): fac[i] = (fac[i-1]*i)%MOD inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD invfac[i] = (invfac[i-1]*inv[i])%MOD def coef(x,y): num = (((fac[x]*invfac[y])%MOD)*invfac[x-y]%MOD) return num ans = 0 for i in range(min(N,K+1)): a = coef(N,i) b = coef(N-1,N-i-1) ans += ((a*b)%MOD) print(ans%MOD) if __name__ == "__main__": main()
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 = 2*(10**5)+1 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 ) a,b=map(int,input().split()) c=min(a,b) s=0 for i in range(0,c+1): s+=cmb(a,i,10**9+7)*cmb(a-1,i,10**9+7) print(s%(10**9+7))
1
67,321,464,461,120
null
215
215
N,K = map(int,input().split()) A = list(map(int,input().split())) A = [(a-1) % K for a in A] S = [0 for i in range(N+1)] for i in range(1, N+1): S[i] = (S[i-1] + A[i-1]) % K kinds = set(S) counts = {} ans = 0 for k in kinds: counts[k] = 0 for i in range(N+1): counts[S[i]] += 1 if i >= K: counts[S[i-K]] -= 1 ans += (counts[S[i]] - 1) print(ans)
s=input() for i in range(int(input())): sou_com=input().split() if sou_com[0]=='print': print(s[int(sou_com[1]):int(sou_com[2])+1]) elif sou_com[0]=='reverse': s=s[:int(sou_com[1])]\ +s[int(sou_com[1]):int(sou_com[2])+1][::-1]\ +s[int(sou_com[2])+1:] elif sou_com[0]=='replace': s=s[:int(sou_com[1])]\ +sou_com[3]\ +s[int(sou_com[2])+1:]
0
null
69,824,745,233,910
273
68
n, k =map(int,input().split()) MOD = 10**9 + 7 ans = 0 for i in range(k,n+2): L = (i-1)*i / 2 #初項0,末項l,項数iの等差数列の和 H = ((n-i)+(n+1))*i //2 #初項a,末項l,項数iの等差数列の和 ans += H - L + 1 ans %= MOD print(int(ans))
n,k=map(int,input().split()) mod=10**9+7 def f(i): return (1+i*(n-i+1))%mod ans=0 for i in range(k,n+2): ans=(ans+f(i))%mod print(ans)
1
33,055,698,605,830
null
170
170
def dfs(v): global t, d, f, visited d[v] = t visited[v] = True t += 1 for u in AL[v]: if not visited[u]: dfs(u) f[v] = t t += 1 # 入力 n = int(input()) AL = [[] for _ in range(n + 1)] for v in range(1, n + 1): AL[v] = [int(x) for x in input().split()][2:] # 計算 d = [0] * (n + 1) f = [0] * (n + 1) t = 1 visited = [False] * (n + 1) for v in range(1, n + 1): if not visited[v]: dfs(v) # 出力 for v in range(1, n + 1): print(v, d[v], f[v])
def search(l, m): #dp = [[None for _ in range(len(l) + 1)] for __ in range(m + 1)] dp = [[False for _ in range(m+1)] for __ in range(len(l) + 1)] dp[0][0]= True for i in range(len(l)): for mi in range(m + 1): if l[i] <= mi: dp[i+1][mi] = dp[i][mi - l[i]] or dp[i][mi] else: dp[i+1][mi] = dp[i][mi] return dp[len(l)][m] n = int(input()) l = list(map(int, input().split())) q = int(input()) ms = list(map(int, input().split())) for m in ms: if search(l, m): print('yes') else: print('no')
0
null
54,039,569,892
8
25
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(): r = int(readline()) print(r * r) return if __name__ == '__main__': main()
from collections import deque n=int(input()) l=[list(map(int,input().split())) for i in range(n-1)] tree=[[]for _ in range(n)] for a,b in l: a-=1 b-=1 tree[a].append(b) tree[b].append(b) ans_num=0 for i in tree: ans_num=max(ans_num,len(i)) dq=deque() dq.append((0,0)) seen=set() seen.add(0) ans_dict={} while dq: x,color=dq.popleft() i=0 for nx in tree[x]: if nx in seen: continue i+=1 if i==color: i+=1 seen.add(nx) dq.append((nx,i)), ans_dict[x+1,nx+1]=i ans_dict[nx+1,x+1]=i print(ans_num) for i in l: print(ans_dict[tuple(i)])
0
null
140,274,537,462,452
278
272
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n = int(input()) r = [] while n > 0: n -= 1 t1 = n % 26 r.append(chr(t1+97)) n = n // 26 r2 = "".join(r[::-1]) print(r2) if __name__ == '__main__': main()
S=input() Q=int(input()) rev = 0 front, back=[],[] for i in range(Q): q = input() if len(q)==1:rev = 1- rev else: n,f,c=q.split() if f=='1' and rev==0: front.append(c) elif f=='2' and rev==1: front.append(c) elif f=='1' and rev==1: back.append(c) elif f=='2' and rev == 0: back.append(c) if rev==0: S = ''.join(front[::-1]) + S + ''.join(back) else: S = ''.join(back[::-1]) + S[::-1] + ''.join(front) print(S)
0
null
34,436,269,054,912
121
204
x=int(input()) for a in range(-200,200,1): for b in range(-200,200,1): if a**5 - b**5 == x: print(a,b) exit()
x = int(input()) for i in range(1000): for j in range(i): if i ** 5 - j ** 5 == x: print(i, j) exit() if i ** 5 + j ** 5 == x: print(i, -j) exit()
1
25,625,895,796,800
null
156
156
import sys #import string #from collections import defaultdict, deque, Counter #import bisect #import heapq #import math #from itertools import accumulate #from itertools import permutations as perm #from itertools import combinations as comb #from itertools import combinations_with_replacement as combr #from fractions import gcd #import numpy as np stdin = sys.stdin sys.setrecursionlimit(10 ** 7) MIN = -10 ** 9 MOD = 10 ** 9 + 7 INF = float("inf") IINF = 10 ** 18 def solve(): #n = int(stdin.readline().rstrip()) n,k = map(int, stdin.readline().rstrip().split()) H = list(map(int, stdin.readline().rstrip().split())) #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin] #word = [stdin.readline().rstrip() for _ in range(n)] #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)] #zeros = [[0] * w for i in range(h)] H.sort() if n <= k: print(0) exit() for i in range(k): H.pop(-1) print(sum(H)) if __name__ == '__main__': solve()
n,m=input().split() if(n==m): print("Yes\n") else: print("No\n")
0
null
80,991,797,509,130
227
231
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) import math from itertools import combinations, product #import bisect# lower_bound etc #import numpy as np def run(): N,K = map(int, read().split()) k = int(math.log(N, 10)) s = N // (10 ** k) tmp1, tmp2, div = 1, 1, 1 for i in range(K-1): tmp1 *= k-i div *= i+1 tmp2 *= 9 ret = tmp1//div * tmp2 ret *= s-1 tmp1 *= k - (K-1) tmp2 *= 9 div *= K ret += tmp1 * tmp2 // div lis = range(k) nums = range(1,10) base = s * 10 ** k for A in combinations(lis, K-1): for X in product(nums, repeat = K-1): tmp = base for a,x in zip(A,X): tmp += 10 ** a * x if tmp <= N: ret += 1 print(ret) if __name__ == "__main__": run()
N,X,T = map(int,input().split()) Y = int(N/X) A = N%X print( Y*T if A == 0 else Y*T + T )
0
null
40,069,775,918,480
224
86
# coding: utf-8 # Your code here! class dice(object): def __init__(self, arr): self.top = arr[0] self.side_s = arr[1] self.side_e = arr[2] self.side_w = arr[3] self.side_n = arr[4] self.bottom = arr[5] def roll(self, s): if s=='S': tmp = self.bottom self.bottom = self.side_s self.side_s = self.top self.top = self.side_n self.side_n = tmp elif s=='E': tmp = self.bottom self.bottom = self.side_e self.side_e = self.top self.top = self.side_w self.side_w = tmp elif s=='W': tmp = self.bottom self.bottom = self.side_w self.side_w = self.top self.top = self.side_e self.side_e = tmp elif s=='N': tmp = self.bottom self.bottom = self.side_n self.side_n = self.top self.top = self.side_s self.side_s = tmp s = input().split() # s = '1 2 4 8 16 32'.split() dice = dice(s) arr = input() for a in arr: dice.roll(a) # print(type(dice)) print(dice.top)
class Dice: def __init__(self, label: list): self.top, self.front, self.right, self.left, self.back, self.bottom = label def roll(self, direction: str): if direction == "N": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.front, self.bottom, self.right, self.left, self.top, self.back, ) elif direction == "W": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.right, self.front, self.bottom, self.top, self.back, self.left, ) elif direction == "S": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.back, self.top, self.right, self.left, self.bottom, self.front, ) elif direction == "E": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.left, self.front, self.top, self.bottom, self.back, self.right, ) def output_top(self): print(self.top) (*label,) = map(int, input().split()) dice = Dice(label) for i in input(): dice.roll(i) dice.output_top()
1
229,734,797,410
null
33
33
n,k,s = map(int, input().split()) if s == 10**9: ansl = [] for i in range(n): if i < k: ansl.append(s) else: ansl.append(1) print(*ansl) else: ansl = [] for i in range(n): if i < k: ansl.append(s) else: ansl.append(10**9) print(*ansl)
n, k, s =map(int, input().split()) if s == 10 ** 9: for i in range(k): print(s, end=" ") for i in range(n-k): print(1, end=" ") else: for i in range(k): print(s, end=" ") for i in range(n-k): print(s+1, end=" ")
1
90,788,742,316,630
null
238
238
import sys input=lambda :sys.stdin.readline().rstrip() mod = 10**9+7 n, k = map(int, input().split()) d = [0] * (k+1) for i in range(1, k+1): d[i] = pow(k//i, n, mod) for i in range(k, 0, -1): for j in range(2*i, k+1, i): d[i] -= d[j] d[i] %= mod ans=0 for i in range(1, k+1): ans += d[i]*i ans %= mod print(ans)
n, k = map(int, input().split()) MOD = 1000000007 ans = 0 c = {} for i in range(k, 0, -1): t = pow(k // i, n, MOD) m = 2 while i * m <= k: t -= c[i * m] m += 1 c[i] = t % MOD print(sum([k * v for k, v in c.items()]) % MOD)
1
36,918,954,261,630
null
176
176
import sys from collections import deque def LS(): return list(input().split()) S = deque(input()) Q = int(input()) rev = 0 for i in range(Q): A = LS() if A[0] == "1": rev += 1 rev %= 2 else: if A[1] == "1": if rev == 0: S.appendleft(A[2]) else: S.append(A[2]) else: if rev == 0: S.append(A[2]) else: S.appendleft(A[2]) if rev == 0: print(''.join(S)) else: S.reverse() print(''.join(S))
R = int(input()) print(R * 6.28318530717958623200)
0
null
44,477,976,198,982
204
167
a,b,c = map(int, raw_input().split()) ans = 0 for i in range(c): num = c % (i + 1) if num == 0: if a <= i + 1 and i + 1 <= b: ans += 1 print ans
a,b,c=map(int,input().split(" ")) count=0 while(a<=b): if c%a==0: count+=1 a+=1 print(count)
1
565,027,299,980
null
44
44
N, D = map(int, input().split()) D = D*D count = 0 for i in range(N): P = list(map(int, input().split())) dis = P[0]*P[0] + P[1]*P[1] if dis <= D: count += 1 print(count)
n = input() n = n.split() d = int(n[1]) n = int(n[0]) c = 0 for a in range(n): b = input() b = b.split() x = int(b[0]) y = int(b[1]) if x * x + y * y <= d * d: c = c + 1 print(c)
1
5,868,684,505,112
null
96
96
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from numba import njit MOD = 10**9 + 7 N = int(readline()) S = np.array(list(read().rstrip()), np.int8) R = np.sum(S == ord('R')) B = np.sum(S == ord('B')) G = np.sum(S == ord('G')) @njit def f(S): N = len(S) ret = 0 for i in range(N): for j in range(i + 1, N): k = j + j - i if k >= N: break if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]: ret += 1 return ret answer = R * B * G - f(S) print(answer)
n = int(input()) al = list(map(int,input().split())) lst = [[] for _ in range(n)] for i in range(1,n+1): lst[al[i-1]-1] = i print(*lst)
0
null
108,475,656,399,558
175
299
N = int(input()) a = list(map(int, input().split())) mod = 10**9 + 7 s = 0 for i in a: s += i ans = 0 for i in range(N): s -= a[i] ans += a[i] * s % mod print(ans%mod)
n = int(input()) #n, m = map(int, input().split()) al = list(map(int, input().split())) #al=[list(input()) for i in range(n)] mod = 10**9+7 add = 0 ans = 0 for i in range(n-1, 0, -1): add = (add+al[i]) % mod ans = (ans+add*al[i-1]) % mod print(ans)
1
3,791,220,771,520
null
83
83
import sys sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline def popcount(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f def solve(): _ = int(rl()) X = list(map(int, rl().rstrip()))[::-1] ones = X.count(1) upmod = X[0] % (ones + 1) c = 1 for xi in X[1:]: c = c * 2 % (ones + 1) upmod = (upmod + c * xi) % (ones + 1) botmod = 0 if ones - 1 != 0: botmod = X[0] % (ones - 1) c = 1 for xi in X[1:]: c = c * 2 % (ones - 1) botmod = (botmod + c * xi) % (ones - 1) ans = [] for i, xi in enumerate(X): if ones == 1 and xi == 1: ans.append(0) continue if xi == 0: xmod = (upmod + pow(2, i, ones + 1)) % (ones + 1) else: xmod = (botmod - pow(2, i, ones - 1)) % (ones - 1) cnt = 1 while xmod != 0: xmod = xmod % popcount(xmod) cnt += 1 ans.append(cnt) print(*ans[::-1], sep='\n') if __name__ == '__main__': solve()
from collections import deque from sys import stdin n = int(input()) line = stdin.readlines() ddl = deque() for i in range(n): inp = line[i].split() if len(inp) == 2: op, data = inp data = int(data) else: op, data = inp[0], None if op == 'insert': ddl.appendleft(data,) elif op == 'delete': try: ddl.remove(data) except ValueError: pass elif op == 'deleteFirst': ddl.popleft() elif op == 'deleteLast': ddl.pop() print(' '.join([str(item) for item in ddl]))
0
null
4,108,903,823,310
107
20
import sys import math import collections def set_debug(debug_mode=False): if debug_mode: fin = open('input.txt', 'r') sys.stdin = fin def int_input(): return list(map(int, input().split())) def get(s): return str(s % 9) + '9' * (s // 9) if __name__ == '__main__': # set_debug(True) # t = int(input()) t = 1 for ti in range(1, t + 1): n = int(input()) A = int_input() cur = 0 for x in A: cur = x ^ cur res = [] for x in A: res.append(cur ^ x) print(*res)
x1,x2,x3,x4,x5 = map(int,input().split()) if x1==0: print('1') elif x2==0: print('2') elif x3==0: print('3') elif x4==0: print('4') elif x5==0: print('5')
0
null
12,835,956,849,794
123
126
time = int(input()) h = time // 3600 m = (time - h * 3600) // 60 s = time - h * 3600 - m * 60 print("{0}:{1}:{2}".format(h, m, s))
S = int(input()) print("%d:%d:%d" % (S / 3600, S % 3600 / 60, S % 60))
1
330,580,052,320
null
37
37
# -*- coding: utf-8 -*- """ Created on Wed Sep 9 02:04:12 2020 @author: liang """ import math N = int(input()) d = list() for i in range(N): x, y = map(int,input().split()) d.append((x,y)) #print(d) lis = list(range(N)) num = list() perm_list = list() def make_perm(): if len(num) == N: perm_list.append(num.copy()) for n in lis: a = lis.pop(0) num.append(a) make_perm() num.pop() lis.append(a) make_perm() #print(len(perm_list)) res = 0 for nums in perm_list: tmp = 0 for i in range(N-1): tmp += math.sqrt((d[nums[i]][0]-d[nums[i+1]][0])**2 + (d[nums[i]][1] - d[nums[i+1]][1])**2) res += tmp print(res/len(perm_list))
from decimal import * getcontext().prec=1000 a,b,c=map(int,input().split()) A=Decimal(a)**Decimal("0.5") B=Decimal(b)**Decimal("0.5") C=Decimal(c)**Decimal("0.5") D= Decimal(10) ** (-100) if A+B+D<C: print("Yes") else: print("No")
0
null
99,640,333,765,728
280
197
n,k = map(int,input().split()) mod = 10**9 + 7 fact = [1] finv = [1] for i in range(1, 2*n): fact.append((fact[i-1] * i) % mod) finv.append(pow(fact[i], mod-2, mod)) if n-1 <= k: print((fact[2*n-1] * finv[n] * finv[n-1]) % mod) exit() ans = 0 for i in range(k+1): ans += fact[n] * finv[n-i] * finv[i] * fact[n-1] * finv[n-1-i] * finv[i] ans %= mod print(ans)
#セグ木 from collections import deque def f(L, R): return L|R # merge def g(old, new): return old^new # update zero = 0 #零元 class segtree: def __init__(self, N, z): self.M = 1 while self.M<N: self.M *= 2 self.dat = [z] * (self.M*2-1) self.ZERO = z def update(self, x, idx, l=0, r=-1): if r==-1: r = self.M idx += self.M-1 self.dat[idx] = g(self.dat[idx], x) while idx > 0: idx = (idx-1)//2 self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2]) def query(self, a, b=-1, idx=0, l=0, r=-1): if r==-1: r = self.M if b==-1: b = self.M q = deque([]) q.append([l, r, 0]) ret = self.ZERO while len(q): tmp = q.popleft() L = tmp[0] R = tmp[1] if R<=a or b<=L: continue elif a<=L and R<=b: ret = f(ret, self.dat[tmp[2]]) else: q.append([L, (L+R)//2, tmp[2]*2+1]) q.append([(L+R)//2, R, tmp[2]*2+2]) return ret n = int(input()) s = list(input()) q = int(input()) seg = segtree(n+1, 0) for i in range(n): num = ord(s[i]) - ord("a") seg.update((1<<num), i) for _ in range(q): a, b, c = input().split() b = int(b) - 1 if a == "1": pre = ord(s[b]) - ord("a") now = ord(c) - ord("a") seg.update((1<<pre), b) seg.update((1<<now), b) s[b] = c else: q = seg.query(b, int(c)) bin(q).count("1") print(bin(q).count("1"))
0
null
64,679,901,715,088
215
210
arr = list([]) for i in range(10): arr.append(int(input())) arr.sort(reverse=True) for i in range(3): print arr[i]
mountains = [] for x in range(10): mountains.append(int(raw_input())) mountains.sort() print(mountains[-1]) print(mountains[-2]) print(mountains[-3])
1
8,202,128
null
2
2
from collections import deque def main(): n = int(input()) V = [None]*(n+1) ans = [None]*(n+1) for i in range(1, n+1): _, _, *v = map(int, input().split()) V[i] = v q = deque([1]) ans[1] = 0 while q: node = q.pop() d = ans[node]+1 for v in V[node]: if ans[v] is None: ans[v] = d q.appendleft(v) print(1, 0) for i, distance in enumerate(ans[2:], 2): print(i, distance or -1) if __name__ == "__main__": main()
from collections import deque def bfs(adj_mat, d): Q = deque() N = len(d) color = ["W" for n in range(N)] Q.append(0) d[0] = 0 while len(Q) != 0: u = Q.popleft() for i in range(N): if adj_mat[u][i] == 1 and color[i] == "W": color[i] = "G" d[i] = d[u] + 1 Q.append(i) color[u] = "B" for i in range(N): if color[i] != "B": d[i] = -1 def Main(): N = int(input()) adj_mat = [[0 for n in range(N)] for n in range(N)] d = [0] * N for n in range(N): u, k , *V = map(int, input().split()) if k > 0: for i in V: adj_mat[n][i - 1] = 1 bfs(adj_mat, d) for n in range(N): print("{} {}".format(n + 1, d[n])) Main()
1
4,823,796,924
null
9
9
N,M = map(int,input().split()) if M % 2 == 1: for i in range(M // 2): print(1 + i, M - i) for i in range(M - M // 2): print(M + 1 + i, 2 * M + 1 - i) else: for i in range(M // 2): print(1 + i, M + 1 - i) print(M + 2 + i, 2 * M + 1 - i)
n=int(input()) wl={} for i in range(n): w=input() if w not in wl: wl[w]=0 wl[w]+=1 wm=max(wl.values()) wl3=sorted(wl.items()) for i in range(len(wl3)): if wl3[i][1]==wm: print(wl3[i][0])
0
null
49,387,206,986,690
162
218
a = input('') S = [] num = 0 for i in a: S.append(i) for j in range(3): if S[j] == 'R': num += 1 if num == 2 and S[1] == 'S': print(1) else: print(num)
s = input().split('S') m = 0 for i in s: if len(i) > m: m = len(i) print(m)
1
4,865,212,600,260
null
90
90
a, b, c = map(int, input().split()) ans = 0 for i in range(a, b+1): if c % i == 0: ans += 1 print(ans)
r = input() r = int(r) result = r**2 print(result)
0
null
72,544,153,904,912
44
278
n,m=map(int,input().split()) a=list(map(int,input().split())) ans=0 for i in range(m) : ans = ans+a[i] day=n-ans #if day>=0 : # print(day) #else : # print(-1) print(day if day >= 0 else "-1")
import math def main(): a,b,x=map(int,input().split()) if a**2*b/2<x : theta=math.atan(2*(a**2*b-x)/a**3) else : theta=math.pi/2-math.atan(2*x/(a*b**2)) print(theta*180/math.pi) main()
0
null
97,157,624,418,690
168
289
h, w = map(int, input().split()) if h == 1 or w == 1: print(1) else: print(int((h*w+1)/2))
X, Y = map(int, input().split()) if X>=2*Y: print(X-2*Y) else: print(0)
0
null
108,599,861,252,298
196
291
import sys #import time compare_counter = 0 array = [0 for x in range(500000)] def merge(left, mid, right): n_fore = mid - left n_rear = right - mid l_fore = array[left:left + n_fore] l_fore.append(sys.maxsize) l_rear = array[mid:mid + n_rear] l_rear.append(sys.maxsize) #print(left, mid, right) i = j = 0 global compare_counter compare_counter += (right - left) for k in range(left, right): if l_fore[i] < l_rear[j]: array[k] = l_fore[i] i += 1 else: array[k] = l_rear[j] j += 1 def merge_sort(left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(left, mid) merge_sort(mid, right) merge(left, mid, right) return def main(): #start = time.time() n = int(input()) for idx, tmp in enumerate(input().split()): array[idx] = int(tmp) #print("time", time.time()-start) merge_sort(0, n) #print("time", time.time()-start) print(" ".join(map(str, array[:n]))) print(compare_counter) #print("time",time.time()-start) return main()
N = int(input()) C = input() W_total = C.count("W") R_total = N - W_total w_cur = 0 r_cur = R_total ans = R_total cur = 0 for i in range(N): if C[i] == "W": w_cur += 1 else: r_cur -= 1 ans = min(ans, min(w_cur, r_cur) + abs(w_cur - r_cur)) print(ans)
0
null
3,206,357,379,846
26
98
#coding:utf-8 n = int(input()) S = list(map(int, input().split())) q = int(input()) T = list(map(int, input().split())) def search_banpei(array, target, cnt): tmp = array[len(array)-1] array[len(array)-1] = target n = 0 while array[n] != target: n += 1 array[len(array)-1] = tmp if n < len(array) - 1 or target == tmp: cnt += 1 return cnt def linear_search(): cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break def linear_banpei_search(): cnt = 0 for target in T: cnt = search_banpei(S, target, cnt) return cnt cnt = linear_banpei_search() print(cnt)
def linear_search(num_list,target): for num in num_list: if num == target: return 1 return 0 n = input() num_list = list(map(int,input().split())) q = input() target_list = list(map(int,input().split())) ans = 0 for target in target_list: ans += linear_search(num_list,target) print(ans)
1
64,254,901,700
null
22
22
X,Y = map(int,input().split()) if Y%2 == 0 and 2*X<=Y<=4*X: print('Yes') else: print('No')
n=input() if n.count('7')>0: print('Yes') else: print('No')
0
null
24,084,837,024,510
127
172
import math import sys N = int(input()) x = math.ceil(math.sqrt(N)) for i in range(x, 0, -1): if N % i == 0: print(int(i+N/i-2)) sys.exit()
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)
1
161,860,013,276,260
null
288
288
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)
import collections def main(): n = int(input()) a = list(map(int, input().split())) q = int(input()) a_dict = collections.Counter(a) a_dict = {key: key*value for key, value in a_dict.items()} answer = sum(a_dict.values()) for _ in range(q): b, c = map(int, input().split()) diff = 0 if b in a_dict: b_sum = a_dict.pop(b) c_add = b_sum//b * c diff = c_add - b_sum if c in a_dict: a_dict[c] += c_add else: a_dict[c] = c_add answer += diff print(answer) if __name__ == '__main__': main()
1
12,297,215,764,640
null
122
122
import collections N = int(input()) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a cnt = collections.Counter(prime_factorize(N)) ans = 0 # print(cnt) for val in cnt.values(): # print(val)1 m = 1 while m*(m+1)//2 <= val: m += 1 ans += m-1 print(ans)
def division(n): if n < 2: return [] prime_fac = [] for i in range(2,int(n**0.5)+1): cnt = 0 while n % i == 0: n //= i cnt += 1 if cnt!=0:prime_fac.append((i,cnt)) if n > 1: prime_fac.append((n,1)) return prime_fac n = int(input()) div = division(n) ans = 0 for i,e in div: b = 1 while b <= e: e -= b b += 1 ans += 1 print(ans)
1
16,965,761,486,492
null
136
136
N = int(input()) cities = [] for n in range(N): cities.append(tuple(map(int, input().split()))) import math def distance(i, j): xi,yi = cities[i] xj,yj = cities[j] xd,yd = xi - xj, yi - yj return math.sqrt(xd * xd + yd * yd) # path: これまでに通過した街の番号 def search(path): total = 0 count = 0 for i in range(N): if i not in path: count += 1 path.append(i) total += (0 if len(path) == 1 else distance(i, path[-2])) + search(path) path.remove(i) if count == 0: return 0 else: return total / count print(search([]))
n,m = map(int,input().split(" ")) c = tuple(map(int,input().split(" "))) m = min(c) dp = [2**60 for _ in range(n+1)] dp[0] = 0 for i in range(1,n+1): for v in c: if i >= v: dp[i] = min(dp[i],dp[i-v]+1) print(dp[n])
0
null
74,210,156,670,132
280
28
ini = lambda : int(input()) inm = lambda : map(int,input().split()) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y n,k = inm() p = inl() p = sorted(p) print(sum(p[:k]))
N, K = map(int, input().split()) P = list(map(int, input().split())) assert len(P) == N # 1 <= K <= N <= 1000 P = sorted(P) print(sum(P[:K]))
1
11,695,133,421,760
null
120
120
L = raw_input().split() a = int(L[0]) b = int(L[1]) d = int(0) r = int(0) f = float(0) d = a / b r = a % b f = float(a) / float(b) print "{0} {1} {2:f}".format(d,r,f)
def ri(): return int(input()) def rii(): return [int(v) for v in input().split()] def solve(): X, N = rii() P = set(rii()) n = m = float("inf") if not P: print(X) return for i in range(min(P)-1, max(P)+2): if i not in P: d = abs(i - X) if d == m: n = min(n, i) elif d < m: m = d n = i print(n) if __name__ == "__main__": solve()
0
null
7,434,519,541,174
45
128
import decimal a,b = map(decimal.Decimal,input().split()) ans = a*b//1 print(ans)
from decimal import Decimal a, b = [Decimal(i) for i in input().split()] print(int(a * b))
1
16,524,243,192,128
null
135
135
a = int(input()) s = 100000 for i in range(a): s = s * 1.05 if s % 1000: s = s - (s % 1000) + 1000 print(int(s))
i = int(input()) x = 100000 for _ in range(i): x *= 1.05 x = int((x+999) / 1000) * 1000 print(x)
1
1,201,962,068
null
6
6
import copy def main(): N, M, Q = [int(n) for n in input().split(" ")] q = [[int(a) for a in input().split(" ")] for i in range(Q)] all_series = get_series(N, M) points = [0] for l in all_series: points.append(get_score(l, q)) print(max(points)) def get_score(l, q): return sum([q[i][3] if l[q[i][1] - 1] - l[q[i][0] - 1] == q[i][2] else 0 for i in range(len(q))]) def get_series(N, M): # N: number of elms # M: upper limit of val of elm all_series = [] checked = [[0] * M for i in range(N)] to_check = [[0, j + 1] for j in range(M)] series = [0 for k in range(N)] while len(to_check) > 0: checking = to_check.pop(-1) series[checking[0]] = checking[1] if checking[0] == N - 1: l = copy.deepcopy(series) all_series.append(l) else: to_check.extend([[checking[0] + 1, k] for k in range(checking[1], M + 1)]) return all_series main()
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)
0
null
45,957,140,680,010
160
212
import sys S = input() N = int(input()) for i in range(N): a = sys.stdin.readline().split() if a[0] == "replace": S = S[:int(a[1])] + a[3] + S[int(a[2])+1:] elif a[0] == "reverse": X = S[int(a[1]):int(a[2])+1] X = X[::-1] S = S[:int(a[1])] + X +S[int(a[2])+1:] elif a[0] == "print": print(S[int(a[1]):int(a[2])+1])
# https://atcoder.jp/contests/abc150/tasks/abc150_d import math def lcm(x, y): return (x * y) // math.gcd(x, y) n, m = list(map(int, input().split())) A = list(map(int, input().split())) for i in range(len(A)): A[i] //= 2 div_two_cnt = None for a in A: cnt = 0 while a % 2 == 0: a //= 2 cnt += 1 if div_two_cnt is None: div_two_cnt = cnt elif cnt != div_two_cnt: print(0) exit() tmp = A[0] for i in range(1, n): tmp = lcm(tmp, A[i]) # print(tmp) print(((m // tmp) + 1)//2)
0
null
52,109,253,639,382
68
247
n = int(input()) maximum_profit = -10**9 r0 = int(input()) r_min = r0 for i in range(1, n): r1 = int(input()) r_min = min(r0, r_min) maximum_profit = max(maximum_profit, r1 - r_min) r0 = r1 print(maximum_profit)
N = int(input()) a = [] for i in range(N): a.append(int(input())) mins = [a[0]] for i in range(1, N): mins.append(min(a[i], mins[i-1])) mx = -10**12 for j in range(1, N): mx = max(mx, a[j] - mins[j-1]) print(mx)
1
12,860,145,802
null
13
13
N=int(input()) ans=0 if ~N%2: for i in range(1,30): ans+=N//(2*5**i) print(ans)
def main(): n,s = map(int,input().split()) a = list(map(int,input().split())) mod = 998244353 dp = [[0]*(s+1) for i in range(n+1)] dp[0][0] = 1 for i in range(n): for j in range(s+1): if j >= a[i]: dp[i+1][j] += (dp[i][j]*2+dp[i][j-a[i]])%mod else: dp[i+1][j] += (dp[i][j]*2)%mod print(dp[-1][-1]) if __name__ =="__main__": main()
0
null
66,867,653,958,558
258
138
for i in sorted([int(input()) for _ in range(10)], reverse=True)[:3]: print(i)
n=int(input()) p=10**9+7 A=list(map(int,input().split())) binA=[] for i in range(n): binA.append(format(A[i],"060b")) lis=[0 for i in range(60)] for binAi in binA: for j in range(60): lis[j]+=int(binAi[j]) binary=[0 for i in range(60)] for i in range(n): for j in range(60): if binA[i][j]=="0": binary[j]+=lis[j] else: binary[j]+=n-lis[j] binary[58]+=binary[59]//2 binary[59]=0 explis=[1] for i in range(60): explis.append((explis[i]*2)%p) ans=0 for i in range(59): ans=(ans+binary[i]*explis[58-i])%p print(ans)
0
null
61,358,798,468,198
2
263
n = int(input()) A = list(map(int, input().split())) l = [] for a in A: if a % 2 == 0: l.append(a) if all([i % 3 ==0 or i % 5 ==0 for i in l]): print('APPROVED') else: print('DENIED')
N=int(input()) A=list(map(int,input().split())) a=[i for i in A if i%2==0] b=len([i for i in a if i%3==0 or i%5==0]) if len(a)==b: print('APPROVED') else: print('DENIED')
1
68,694,282,280,480
null
217
217
a=int(input()) b=100 i=0 while b<a: b+= b // 100 i+=1 print(i)
x = int(input()) i = 0 ganpon = 100 while True: if x > ganpon: ganpon += int(ganpon//100) i += 1 else: print(i) break
1
27,117,550,418,490
null
159
159
N=int(input()) S=input() ans=0 for i in range(N-2): if S[i]=='A': i+=1 if S[i]=='B': i+=1 if S[i]=='C': ans+=1 print(ans)
r, c = map(int, input().split()) sumOfCols = [0] * c for i in range(r): cols = list(map(int, input().split())) s = sum(cols) sumOfCols = [p + q for p,q in zip(sumOfCols, cols)] print(' '.join(map(str, cols)), end=' ') print(s) s = sum(sumOfCols) print(' '.join(map(str, sumOfCols)), end=' ') print(s)
0
null
50,520,591,343,430
245
59
N = [0] + list(map(int, input())) K = int(input()) n = len(N) DP = [ [[0] * (K+2) for _ in range(2)] for _ in range(n) ] # 0桁目(0)で最大値を取っていてk=0の要素は1個。 DP[0][0][0] = 1 for i in range(1, n): for k in range(K+1): if N[i] != 0: DP[i][0][k+1] += DP[i-1][0][k] DP[i][1][k] += DP[i-1][0][k] DP[i][1][k+1] += DP[i-1][0][k] * (N[i] - 1) else: DP[i][0][k] += DP[i-1][0][k] DP[i][1][k] += DP[i-1][1][k] DP[i][1][k+1] += DP[i-1][1][k] * 9 print(DP[n-1][1][K] + DP[n-1][0][K])
import sys read = sys.stdin.read def main(): N, K = map(int, read().split()) dp1 = [0] * (K + 1) dp2 = [0] * (K + 1) dp1[0] = 1 for x in map(int, str(N)): dp1, dp1_prev = [0] * (K + 1), dp1 dp2, dp2_prev = [0] * (K + 1), dp2 for j in range(K, -1, -1): if j > 0: dp2[j] = dp2_prev[j - 1] * 9 if x != 0: dp2[j] += dp1_prev[j - 1] * (x - 1) dp2[j] += dp2_prev[j] if x != 0: dp2[j] += dp1_prev[j] if x != 0: if j > 0: dp1[j] = dp1_prev[j - 1] else: dp1[j] = dp1_prev[j] print(dp1[K] + dp2[K]) return if __name__ == '__main__': main()
1
75,707,403,900,116
null
224
224
K = int(input()) A, B = map(int, input().split()) cnt = 0 while 1: cnt+=K if A <= cnt <= B: print("OK") break if B < cnt: print("NG") break
# -*- coding: utf-8 -*- import collections N = int(input()) all_str = [] for i in range(N): str_temp = input() all_str.append(str_temp) all_str.sort() coll_str = (collections.Counter(all_str)) count_max = 0 j = 0 max_str = coll_str.most_common() for i in max_str: num_of_str = i[1] if num_of_str == count_max or j == 0: print(i[0]) j = 1 count_max = num_of_str if num_of_str < count_max: break
0
null
48,072,572,927,850
158
218
n=int(input())#nはデータセットの数 for i in range(n):#n回繰り返す edge=input().split()#入力 edge=[int(j) for j in edge]#入力 edge.sort()#ここでedge[2]が最大になる if(edge[0]**2+edge[1]**2==edge[2]**2):#直角三角形かどうか print("YES") else:#そうでないなら print("NO")
n = int(input()) s, t = input().split() ans = '' for x,y in zip(s,t): ans += x + y print(ans)
0
null
56,001,761,862,068
4
255
from collections import deque import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def bfs(field, sx, sy, seen): queue = deque([(sx, sy)]) seen[sx][sy] += 1 while queue: x, y = queue.popleft() for dx, dy in [(-1, 0), (0, 1), (1, 0), (0, -1)]: nx = x + dx ny = y + dy if seen[nx][ny] == -1 and field[nx][ny] != "#": seen[nx][ny] = seen[x][y] + 1 queue.append((nx, ny)) return seen[x][y] def main(): H,W = map(int, readline().split()) c = ["#" * (W + 2)] for _ in range(H): c.append("#" + readline().strip() + "#") c.append("#" * (W + 2)) ans = 0 for sx in range(1,H+1): for sy in range(1,W+1): if c[sx][sy] == ".": seen = [[-1] * (W + 2) for i in range(H+2)] dist = bfs(c, sx, sy, seen) ans = max(ans, dist) print(ans) if __name__ == "__main__": main()
def main(): H, W = [int(x) for x in input().split(" ")] S = [] S.append(["X"] * (W + 2)) h = 0 w = 0 for i in range(H): row = list(input()) S.append(["X"] + row + ["X"]) if not h and not w and row.count(".") > 0: h = i + 1 w = row.index(".") + 1 S.append(["X"] * (W + 2)) ans = [] for i in range(H): for j in range(W): ans.append(BFS(S, i + 1, j + 1, H + 2, W + 2)) print(max(ans)) def BFS(M, i, j, H, W): if M[i][j] != ".": return 0 to_visit = [{"row": i, "col": j, "step": 0}] checked = [[0] * W for x in range(H)] checked[i][j] = 1 z = [[0] * W for x in range(H)] while len(to_visit): visiting = to_visit.pop(0) r0 = visiting["row"] c0 = visiting["col"] s0 = visiting["step"] z[r0][c0] = s0 for d in [[1, 0], [-1, 0], [0, 1], [0, -1]]: r = r0 + d[0] c = c0 + d[1] s = s0 + 1 if checked[r][c] == 0 and M[r][c] == ".": to_visit.append({"row": r, "col": c, "step": s}) checked[r][c] = 1 a = 0 for i in range(len(z)): for j in range(len(z[i])): if a < z[i][j]: a = z[i][j] return a main()
1
94,393,429,670,354
null
241
241
temp=int(input()) if(temp >= 30): print("Yes") else: print("No")
H,N=map(int,input().split()) attack = list(map(int,input().split())) total = sum(attack) if H - total <= 0: print("Yes") else: print("No")
0
null
41,664,059,737,312
95
226
# Queue class MyQueue: def __init__(self): self.queue = [] # list self.top = 0 def isEmpty(self): if self.top==0: return True return False def isFull(self): pass def enqueue(self, x): self.queue.append(x) self.top += 1 def dequeue(self): if self.top>0: self.top -= 1 return self.queue.pop(0) else: print("there aren't enough values in Queue") def main(): n, q = map(int, input().split()) A = [ list(map(lambda x: int(x) if x.isdigit() else x, input().split())) for i in range(n) ] A = [{'name': name, 'time': time} for name, time in A] queue = MyQueue() for a in A: queue.enqueue(a) elapsed = 0 while not queue.isEmpty(): job = queue.dequeue() if job['time']>q: elapsed += q job['time'] = job['time'] - q queue.enqueue(job) else: elapsed += job['time'] print(job['name']+ ' ' + str(elapsed)) main()
n, q = map(int, input().split()) process = [] for _ in range(n): name, time = input().split() process.append([name, int(time)]) process.append([]) def reduce(index): left_time = process[index][1] - q return [process[index][0], left_time] head = 0 tail = n quene_len = len(process) elapsed_time = 0 while head != tail: if process[head][1] > q: process[tail] = reduce(head) elapsed_time += q head = (head+1)%quene_len tail = (tail+1)%quene_len else: elapsed_time += process[head][1] print(process[head][0], elapsed_time) head = (head+1)%quene_len
1
43,042,994,244
null
19
19
N=int(input()) S={input() for _ in range(N)} print(len(S))
import copy def main(): h, o = map(int, input().split(' ')) if h <= o: print('unsafe') else: print('safe') main()
0
null
29,722,834,352,108
165
163
r,c=map(int,raw_input().split()) A=[] for i in range(r): A.append(map(int,raw_input().split())) A[i].append(sum(A[i])) A.append([sum([A[i][j] for i in range(r)]) for j in range(c+1)]) for i in range(r+1): print(' '.join(map(str,A[i])))
import sys r, c = map(int, raw_input().split()) table = {} for i in range(r): a = map(int, raw_input().split()) for j in range(c): table[(i,j)] = a[j] for i in range(r+1): for j in range(c+1): if(i != r and j != c): sys.stdout.write(str(table[(i,j)])) sys.stdout.write(' ') elif(i != r and j == c): print sum(table[(i,l)] for l in range(c)) elif(i == r and j != c): sys.stdout.write(str(sum(table[(k,j)] for k in range(r)))) sys.stdout.write(' ') elif(i == r and j == c): total = 0 for k in range(r): for l in range(c): total += table[(k,l)] print total
1
1,357,611,447,150
null
59
59
N= int(input()) stone_str = input() r_cnt = stone_str.count('R') print(stone_str.count('W', 0, r_cnt))
while True: n = list(map(int,input().split())) if(n[0] == n[1] == 0):break print(" ".join(map(str,sorted(n))))
0
null
3,459,287,423,098
98
43
N = int(input()) A = list(map(int, input().split())) flag = True swap = 0 while flag: flag = False for j in range(N - 1, 0, -1): if A[j] < A[j - 1]: A[j], A[j - 1] = A[j - 1], A[j] swap += 1 flag = True print(" ".join(list(map(str, A)))) print(swap)
def bubble_sort(A, N): cnt = 0 flag = True while flag: flag = False for j in range(N - 1, 0, -1): if A[j - 1] > A[j]: A[j - 1], A[j] = A[j], A[j - 1] flag = True cnt += 1 return cnt N = int(input()) A = list(map(int, input().split())) cnt = bubble_sort(A, N) print(*A) print(cnt)
1
17,259,786,400
null
14
14
import sys a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) if v==w or w>v: print('NO') sys.exit() else: tp=(b-a)/(v-w) tm=(a-b)/(v-w) if b>a: if t>=tp: print('YES') else: print('NO') else: if t>=tm: print('YES') else: print('NO')
import sys sys.setrecursionlimit(300000) def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 INF = float('inf') A, V = MI() B, W = MI() T = I() d = max(0, V - W) if abs(A - B) - d * T <= 0: print('YES') else: print('NO')
1
15,057,919,853,192
null
131
131
n=int(input()) if n%2==0:print(n//2) else:print(n//2+1)
while True: n = int(input()) if n == 0: break s = list(map(int, input().split())) m = sum(s)/n a2 = 0.0 for i in range(n): a2 += (s[i] - m)**2 a = (a2/n)**0.5 print(a)
0
null
29,629,184,637,048
206
31
n = int(input()) a = input() print(a.count("ABC"))
import sys N = input() for i in range ( len ( N )): if '7' == N[i] : print("Yes") sys.exit() print("No")
0
null
66,596,075,821,238
245
172
import sys import math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 998244353 def I(): return int(input()) def LI(): return list(map(int, input().split())) def LIR(row,col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return map(list, zip(*read_all)) ################# N,S = LI() A = LI() beki = [1]*(N+1) for i in range(1,N+1): beki[i] = beki[i-1]*2 beki[i] %= mod inv2 = pow(2,mod-2,mod) d = [0]*(S+1) d[0] = beki[N] ans = 0 for i in range(N): if 0 <= S-A[i] <= S: ans += d[S-A[i]]*inv2 ans %= mod diff = [0]*(S+1) for k in range(S-A[i]+1): diff[k+A[i]] = d[k]*inv2 for k in range(S+1): d[k] += diff[k] d[k] %= mod print(ans)
k = int(input()) a = [7 % k] if a[0] == 0: print(1) exit() for i in range(1, k): a.append((10*a[i - 1] + 7) % k) if a[i] % k == 0: print(i + 1) exit() print(-1)
0
null
11,984,805,559,100
138
97
n, k = map(int, input().split()) d = [0]*k a = [0]*k for i in range(k): d[i] = int(input()) a[i] = list(map(int, input().split())) ans = [0]*100 for i in range(k): for j in range(d[i]): ans[a[i][j]-1] = 1 print(n-sum(ans))
S=str(input()) def kinshi(S:str): len_count=len(S) return("x"*len_count) print(kinshi(S))
0
null
48,794,557,155,904
154
221
import sys from collections import deque def LS(): return list(input().split()) S = deque(input()) Q = int(input()) rev = 0 for i in range(Q): A = LS() if A[0] == "1": rev += 1 rev %= 2 else: if A[1] == "1": if rev == 0: S.appendleft(A[2]) else: S.append(A[2]) else: if rev == 0: S.append(A[2]) else: S.appendleft(A[2]) if rev == 0: print(''.join(S)) else: S.reverse() print(''.join(S))
import sys input = sys.stdin.readline N = int(input()) imo = [] xlmin = 0 xlmax = 0 for _ in range(N): x,l = map(int,input().split()) imo.append([x-l,x+l-1]) imo = sorted(imo,key = lambda x: x[1]) cnt = 1 ls = imo[0][1] for i in range(1,N): if imo[i][0]<=ls: continue else: cnt += 1 ls = imo[i][1] print(cnt)
0
null
73,877,804,474,140
204
237
#!/usr/bin/python3 cmdvar_numlist=input() cmdvar_spritd=cmdvar_numlist.split() D,T,S=list(map(int,cmdvar_spritd)) if D/S<=T: print("Yes") else: print("No")
def cal_puddle(puddle): depth = 0 score = 0 for s in puddle: if s == "\\": score += depth + 0.5 depth += 1 elif s == "/": depth -= 1 score += depth + 0.5 elif s == "_": score += depth if depth == 0: return int(score) return int(score) def get_puddles(diagram): hight = 0 top_list = [] in_puddle = True for index, s in enumerate(diagram + "\\"): if s == "/": in_puddle = True hight += 1 if s == "\\": if in_puddle: in_puddle = False top_list.append([hight, index]) hight -= 1 puddles = [] prev_hight = 0 hight_list = [h for h, i in top_list] i = 0 while i < len(top_list) - 1: cur_top = top_list[i] next_tops = list(filter(lambda top:cur_top[0] <= top[0], top_list[i + 1:])) #print(next_tops) if next_tops: next_top = next_tops[0] puddles.append((cur_top[1], next_top[1])) i = top_list.index(next_top) else: cur_top[0] -= 1 cur_top[1] += diagram[cur_top[1] + 1:].index("\\") + 1 #print(hight_list) #print(top_list) #print(puddles) return puddles def main(): diagram = input() result = [] for s,e in get_puddles(diagram): result.append(cal_puddle(diagram[s:e])) print(sum(result)) print(str(len(result)) + "".join([" " + str(i) for i in result])) if __name__ == "__main__": main()
0
null
1,781,239,309,628
81
21
# ALDS1_3_C: Doubly Linked List # collections.deque # https://docs.python.org/3.8/library/collections.html#collections.deque #n = 7 #A = [('insert', 5), ('insert', 2), ('insert', 3), ('insert', 1), # ('delete', 3), ('insert', 6), ('delete', 5),] from collections import deque n = int(input()) mylist = deque() for i in range(n): myinput = input().split() if len(myinput) == 1: order = myinput[0] x = 0 else: order, x = myinput #print(order, x) if order == 'insert': mylist.appendleft(x) elif order == 'delete': try: mylist.remove(x) except: pass elif order == 'deleteFirst': #mylist.remove(mylist[0]) mylist.popleft() elif order == 'deleteLast': mylist.pop() #print(mylist) print(" ".join(map(str, mylist)))
import sys def input(): return sys.stdin.readline().rstrip() def main(): N = list(map(int,input())) count = 0 S = len(N) flag = 0 for i in range(S): temp = flag + N[-1 - i] if temp > 5: count += 10 - temp flag = 1 elif temp ==5 and i !=S-1 and N[-1-i-1]>=5: count+=temp flag=1 else: count += temp flag = 0 print(count + flag) if __name__ == "__main__": main()
0
null
35,595,052,353,632
20
219
n = int(input().split()[0]) c = list(filter(lambda x:x <= n,map(int,input().split()))) m = len(c) minimum = [ i for i in range(n+1) ] for i in c: minimum[i] = 1 for i in range(1,n+1): if minimum[i] <= 2: continue for j in range(m): if c[j]<=i and minimum[i-c[j]] + 1 < minimum[i]: minimum[i] = minimum[i-c[j]]+1 print(minimum[n])
n, m = map(int, input().split()) coins = list(map(int, input().split())) memo = [0] + [10**7] * n for coin in coins: for i in range(coin, n+1): memo[i] = min(memo[i], memo[i-coin]+1) print(memo[-1])
1
137,978,423,868
null
28
28
# 貪欲法 + 山登り法 + スワップ操作 import time s__ = time.time() limit = 1.9 #limit = 10 from numba import njit import numpy as np d = int(input()) cs = list(map(int, input().split())) cs = np.array(cs, dtype=np.int64) sm = [list(map(int, input().split())) for _ in range(d)] sm = np.array(sm, dtype=np.int64) @njit('i8(i8[:], i8)', cache=True) def total_satisfaction(ts, d): ls = np.zeros(26, dtype=np.int64) s = 0 for i in range(d): t = ts[i] t -= 1 s += sm[i][t] ls[t] = i + 1 dv = cs * ((i+1) - ls) s -= dv.sum() return s @njit('i8[:]()', cache=True) def greedy(): ts = np.array([0] * d, dtype=np.int64) for i in range(d): mx = -1e10 mxt = None for t in range(1, 26+1): ts[i] = t s = total_satisfaction(ts, i + 1) if s > mx: mx = s mxt = t ts[i] = mxt return ts @njit('i8(i8, i8[:])', cache=True) def loop(mxsc, ts): it = 50 rds = np.random.randint(0, 4, (it,)) rdd = np.random.randint(1, d, (it,)) rdq = np.random.randint(1, 26, (it,)) rdx = np.random.randint(1, 12, (it,)) for i in range(it): bk1 = 0 bk2 = 0 if rds[0] == 0: # trailing di = rdd[i] qi = rdq[i] bk1 = ts[di] ts[di] = qi else: # swap di = rdd[i] xi = rdx[i] if di + xi >= d: xi = di - xi else: xi = di + xi bk1 = ts[di] bk2 = ts[xi] ts[di] = bk2 ts[xi] = bk1 sc = total_satisfaction(ts, d) if sc > mxsc: #print(mxsc, '->', sc) mxsc = sc else: # 最大値を更新しなかったら戻す if rds[0] == 0: ts[di] = bk1 else: ts[di] = bk1 ts[xi] = bk2 return mxsc ts = greedy() mxsc = total_satisfaction(ts, d) mxbk = mxsc s_ = time.time() mxsc = loop(mxsc, ts) e_ = time.time() consume = s_ - s__ elapsed = e_ - s_ #print('consume:', consume) #print('elapsed:', elapsed) if consume < limit: lp = int((limit - consume)/ elapsed) #print('loop', lp) for _ in range(lp): mxsc = loop(mxsc, ts) for t in ts: print(t) #print(mxbk, mxsc) #print(time.time() - s__)
''' ITP-1_5-D ?§???????????????°???????????° goto ?????????C/C++?¨????????????§???????????¨?????§???????????§????????????????????¨????????¶????????????????????????????????????????£?????????????????????° goto CHECK_NUM; ??¨?????????????????????????????¨???????????°??????????????§ CHECK_NUM: ??¨????????????????????????????§?????????????????????????????????£????????°?????????????????????????????????????????¨?????§???????????? ?????????goto ???????????±??????????????????????????°?????????????????§?????±??????????????????????????????????????????????????¨?????¨?\¨????????????????????? ?¬????C++?¨???????????????°????????¨?????????????????????????????°????????????????????????????????????????????????goto ????????????????????§????£????????????????????????? void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } ???Input ???????????´??° nn ????????????????????????????????? ???Output ????¨?????????°???????????\????????´??° nn ???????????????????????????????????????????????? ''' # import import sys inputData = int(input()) outputData = [] cntVal = 1 while True: # CHECK_NUM checkVal = cntVal if checkVal % 3 == 0: outputData.append(str(cntVal)) else: while True: # INCLUDE3 if checkVal % 10 == 3: outputData.append(str(cntVal)) break checkVal = int(checkVal / 10) # EndChek if checkVal != 0: continue else: break # increment cntVal += 1 # EndChek if cntVal <= inputData: continue else: break # Output print(" " + " ".join(outputData))
0
null
5,352,778,840,768
113
52
def print_residence(residence): for i in range(4): for j in range(3): print " " +" ".join(map(str, residence[i][j])) if i != 3: print "####################" n = int(raw_input()) residence = [[[0] * 10 for i in range(3)] for j in range(4)] #print_residence(residence) for i in range(n): info = map(int, raw_input().split()) #print info #print residence residence[info[0]-1][info[1]-1][info[2]-1] += info[3] #print residence print_residence(residence)
Adr = [[[0 for r in range(10)]for f in range(3)]for b in range(4)] n = input() for i in range(n): Inf = map(int, raw_input().split()) Adr[Inf[0]-1][Inf[1]-1][Inf[2]-1] += Inf[3] for b in range(4): for f in range(3): print "", for r in range(10): if r != 9: print Adr[b][f][r], if r == 9: if f == 3: print Adr[b][f][r], if f != 3: print Adr[b][f][r] if b < 3: print "####################"
1
1,089,741,402,090
null
55
55
n = int(input()) s = input() m = len(s.replace("ABC", "")) print((n - m) // 3)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- a,b,c = map(int, input().split()) print("{0} {1} {2}".format(c,a,b))
0
null
68,937,025,816,810
245
178
while True: inVal = input().split() if inVal[1] == "?": break if inVal[1] == "+": print(int(inVal[0]) + int(inVal[2])) elif inVal[1] == "-": print(int(inVal[0]) - int(inVal[2])) elif inVal[1] == "*": print(int(inVal[0]) * int(inVal[2])) elif inVal[1] == "/": print(int(inVal[0]) // int(inVal[2]))
while True: ins = input().split() a = int(ins[0]) b = int(ins[2]) op = ins[1] if op == "?": break elif op == "+": print(a+b) elif op == "-": print(a-b) elif op == "/": print(a//b) else: print(a*b)
1
681,559,970,348
null
47
47
import math h,w=map(int,input().split()) if h>2 and w>1: print(math.ceil(h*w/2)) if h==1 or w==1: print(1)
X = int(input()) print('Yes' if X >= 30 else 'No')
0
null
28,350,140,686,816
196
95
N = int(input()) for i in range(N): a = list(map(int, input().split())) a.sort() if (a[2] ** 2 == a[0] ** 2 + a[1] ** 2): print("YES") else: print("NO")
N = int(raw_input()) for i in range(N): a = range(3) a[0],a[1],a[2] = map(int, raw_input().split()) a.sort() if a[0]**2 + a[1]**2 == a[2]**2: print "YES" else: print "NO"
1
400,017,772
null
4
4
import sys W = input().lower() T = sys.stdin.read().lower() print(T.split().count(W))
w = raw_input() t = [] while 1: x = raw_input() if x =="END_OF_TEXT":break t+=x.lower().split() print t.count(w)
1
1,817,770,217,332
null
65
65
n=int(input()) A=[int(x) for x in input().split()] u=10**6+1 C=[0]*u D=[0]*2+[1]*(u-2) def gcd(a,b): while a%b: a,b=b,a%b return b n=4 while n<u: D[n]=0 n+=2 i=3 while i*i<u: if D[i]: n=i*2 while n<u: D[n]=0 n+=i i+=2 for a in A: C[a]+=1 for i in [x for x in range(2,u) if D[x]==1]: if sum(C[i::i])>1: break else: print('pairwise coprime') exit() c=A[0] for a in A: c=gcd(c,a) if c==1: break else: print('not coprime') exit() print('setwise coprime')
import math n = int(input()) print((n // 2) / n if n % 2 == 0 else math.ceil(n / 2) / n)
0
null
90,485,062,362,882
85
297
FAST_IO = 0 if FAST_IO: import io, sys, atexit rr = iter(sys.stdin.read().splitlines()).next sys.stdout = _OUTPUT_BUFFER = io.BytesIO() @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) else: rr = raw_input rri = lambda: int(rr()) rrm = lambda: map(int, rr().split()) rrmm = lambda n: [rrm() for _ in xrange(n)] #### from collections import defaultdict as ddic, Counter, deque import heapq, bisect, itertools MOD = 10 ** 9 + 7 def solve(N, A): from fractions import gcd g = A[0] for x in A: g= gcd(g,x) if g > 1: return "not coprime" seen = set() for x in A: saw = set() while x % 2 == 0: x //= 2 saw.add(2) d = 3 while d*d <= x: while x%d == 0: saw.add(d) x //= d d += 2 if x > 1: saw.add(x) for p in saw: if p in seen: return "setwise coprime" seen |= saw return "pairwise coprime" N= rri() A = rrm() print solve(N, A)
from math import gcd N=int(input()) A = list(map(int,input().split())) val = A[0] for i in range(1,N): val = gcd(val,A[i]) if val > 1: print("not coprime") exit() D = [i for i in range(max(A)+1)] p = 2 while(p*p<=max(A)): if D[p]==p: for i in range(2*p,len(D),p): if D[i]==i: D[i]=p p+=1 prime = set() for a in A: tmp=D[a] L=set() while(a>1): a=a//tmp L.add(tmp) tmp=D[a] #print(L) for l in L: if l in prime: #print(D) #print(prime) print("setwise coprime") exit() else: prime.add(l) #print(D) #print(prime) print("pairwise coprime")
1
4,148,318,412,810
null
85
85
s=input() ans=0 a=[0] for i in s: if i=='<': if a[-1]>=0:a[-1]+=1 else:a+=[1] else: if a[-1]<0:a[-1]-=1 else:a+=[-1] n=len(a) for i in range(n//2): i*=2 j=i+1 if a[i]<abs(a[j]): x=abs(a[j]) y=a[i]-1 else: x=abs(a[j])-1 y=a[i] ans+=x*(x+1)//2+y*(y+1)//2 ans+=n%2*a[-1]*(a[-1]+1)//2 print(ans)
def resolve(): s = input() print(s[:3]) if 'unittest' not in globals(): resolve()
0
null
85,849,259,600,028
285
130
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 N = int(input()) A = list(map(int, input().split())) def get_primenumber(number): # エラトステネスの篩 prime_list = [] search_list = list(range(2, number + 1)) # search_listの先頭の値が√nの値を超えたら終了 while search_list[0] <= math.sqrt(number): # search_listの先頭の値が√nの値を超えたら終了 # search_listの先頭をprime_listに入れて、先頭をリストに追加して削除 head_num = search_list.pop(0) prime_list.append(head_num) # head_numの倍数を除去 search_list = [num for num in search_list if num % head_num != 0] # prime_listにsearch_listを結合 prime_list.extend(search_list) return prime_list def prime_factor_table(n): table = [0] * (n + 1) for i in range(2, n + 1): if table[i] == 0: for j in range(i + i, n + 1, i): table[j] = i return table def prime_factor(n, prime_factor_table): prime_count = collections.Counter() while prime_factor_table[n] != 0: prime_count[prime_factor_table[n]] += 1 n //= prime_factor_table[n] prime_count[n] += 1 return prime_count table = prime_factor_table(10**6+10) numset = set() for i in A: thedic = prime_factor(i, table) for l in thedic.keys(): flag = True if l in numset and l != 1: flag = False break if flag: tmpset = set(thedic.keys()) numset |= tmpset else: break if flag: print('pairwise coprime') sys.exit() else: flag = True theset = set(prime_factor(A[0], table).keys()) for i in A[1:]: thedic = prime_factor(i, table) theset = theset & set(thedic.keys()) if len(theset) == 0: print('setwise coprime') flag = False break if flag: print('not coprime') if __name__ == '__main__': solve()
m = 100000 for i in range(int(raw_input())): m*=1.05 m=(int((m+999)/1000))*1000 print m
0
null
2,040,282,639,780
85
6
n,m,k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) a_c_sum = [0]*(n + 1) for i in range(n): a_c_sum[i + 1] = a_c_sum[i] + a[i] b_c_sum = [0]*(m + 1) for i in range(m): b_c_sum[i + 1] = b_c_sum[i] + b[i] ans, best_b = 0, m for i in range(n + 1): if a_c_sum[i] > k: break else: while 1: if b_c_sum[best_b] + a_c_sum[i] <= k: ans = max(ans, i + best_b) break else: best_b -= 1 if best_b == 0: break print(ans)
import bisect n, m, k = list(map(int, input().split())) book_a = list(map(int, input().split())) book_b = list(map(int, input().split())) a_time_sum = [0] b_time_sum = [] for i in range(n): if i == 0: a_time_sum.append(book_a[0]) else: a_time_sum.append(a_time_sum[i]+book_a[i]) for i in range(m): if i == 0: b_time_sum.append(book_b[0]) else: b_time_sum.append(b_time_sum[i-1]+book_b[i]) ans = 0 # Aから何冊か読む for i in range(n+1): read = i a_time = a_time_sum[i] time_remain = k - a_time if time_remain < 0: break # このときBから何冊よめる? b_read = bisect.bisect_right(b_time_sum, time_remain) read += b_read ans = max(ans, read) print(ans)
1
10,750,987,036,790
null
117
117
x=int(input('')) print(x*x*x)
n = input() print(n ** 3)
1
278,273,742,512
null
35
35
def resolve(): N = int(input()) XY = [] for i in range(N): A = int(input()) xy = [list(map(int, input().split())) for _ in range(A)] XY.append(xy) ans = 0 for _bits in range(1<<N): bits = list(map(int, bin(_bits)[2:].zfill(N))) unmatch = False for i in range(N): if bits[i] == 0: continue for x, y in XY[i]: if bits[x-1] != y: unmatch = True break if unmatch: break else: ans = max(ans, bin(_bits).count('1')) print(ans) if '__main__' == __name__: resolve()
from itertools import product n = int(input()) l1 = [] for _ in range(n): l2 = [] for _ in range(int(input())): l2.append(list(map(int, input().split()))) l1.append(l2) ans = 0 for k in product([1, 0], repeat=n): check = True for i, j in enumerate(l1): if k[i] == 0: continue for x in j: if k[x[0] - 1] != x[1]: check = False if check: ans = max(ans, sum(k)) print(ans)
1
121,410,828,283,416
null
262
262
import math N=int(input()) sum=0 for i in range(1,N+1): for j in range(1,N+1): x=math.gcd(i,j) for k in range(1,N+1): y=math.gcd(x,k) sum = sum+y print(sum)
n,m = map(int,input().split()) ans = ["num"]*n for i in range(m): s,c = map(int,input().split()) if ans[s-1] == "num" or ans[s-1] == c: ans[s-1] = c else: print("-1") exit() if ans[0] == 0 and n >= 2: print("-1") exit() elif ans[0] == 0 and n == 1: print("0") exit() elif ans[0] == "num" and n == 1: print("0") exit() elif ans[0] == "num": ans[0] = 1 for j in range(n): if ans[j] == "num": ans[j] = 0 [print(ans[k],end ="") for k in range(n)]
0
null
48,208,825,458,570
174
208
A,B,M=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) List=[list(map(int,input().split())) for i in range(M)] minn=min(a)+min(b) for i in range(M): minn=min(minn,a[List[i][0]-1]+b[List[i][1]-1]-List[i][2]) print(minn)
def sieve_of_eratosthenes(N): N += 1 sieve = [0] * N for p in range(2, N): if sieve[p]: continue for i in range(p, N, p): sieve[i] = p return sieve def lcm_with_sieve(numbers, N): sieve = sieve_of_eratosthenes(N) lcm = dict() for n in numbers: d = dict() while n > 1: factor = sieve[n] n //= factor d[factor] = d.get(factor, 0) + 1 for factor, power in d.items(): lcm[factor] = max(lcm.get(factor, 0), power) return lcm def main(): MOD = 10 ** 9 + 7 _, *A = map(int, open(0).read().split()) lcm = 1 for factor, power in lcm_with_sieve(A, 10 ** 6).items(): lcm = lcm * pow(factor, power, MOD) % MOD total = 0 for a in A: total = (total + lcm * pow(a, MOD - 2, MOD)) % MOD print(total) main()
0
null
70,675,695,666,400
200
235
n, d, a = map(int, input().split()) XH = [tuple(map(int, input().split())) for i in range(n)] XH.sort() X = [x for x, h in XH] H = [h for x, h in XH] X.append(10**10) H.append(0) j = 0 S = [0]*(n+1) ans = 0 for i in range(n): H[i] = max(0, H[i]-S[i]) c = -(-H[i]//a) while X[j] <= X[i] + 2*d: j += 1 S[i+1] += S[i] + a*c S[j] -= a*c ans += c print(ans)
import math from collections import deque N,D,A = map(int,input().split(' ')) XHn = [ list(map(int,input().split(' '))) for _ in range(N)] ans = 0 XHn.sort() attacks = deque([]) # (区間,攻撃回数) attack = 0 ans = 0 for i in range(N): x = XHn[i][0] h = XHn[i][1] while len(attacks) > 0 and x > attacks[0][0]: distance,attack_num = attacks.popleft() attack -= attack_num*A if h > attack: diff = h - attack distance_attack = x + D*2 need_attack = math.ceil(diff/A) attacks.append((distance_attack,need_attack)) attack += A*need_attack ans += need_attack print(ans)
1
81,760,012,853,284
null
230
230
n, m, x = map(int, input().split()) c = [0] * n a = [0] * n for i in range(n): xs = list(map(int, input().split())) c[i] = xs[0] a[i] = xs[1:] ans = 10 ** 9 for i in range(2 ** n): csum = 0 asum = [0] * m for j in range(n): if (i >> j) & 1: csum += c[j] for k in range(m): asum[k] += a[j][k] if len(list(filter(lambda v: v >= x, asum))) == m: ans = min(ans, csum) print(-1 if ans == 10 ** 9 else ans)
H, _ = map(int, input().split()) A = list(map(int, input().split())) if H <= sum(A): print('Yes') else: print('No')
0
null
50,137,255,032,810
149
226
# https://atcoder.jp/contests/abc164/tasks/abc164_d import sys input = sys.stdin.readline S = input().rstrip() res = 0 x = 0 p = 1 L = len(S) MOD = 2019 reminder = [0]*2019 reminder[0] = 1 for s in reversed(S): """ 累積和 """ x = (int(s)*p + x)%MOD p = p*10%MOD reminder[x] += 1 for c in reminder: res += c*(c-1)//2 print(res)
n, x, y = list(map(int, input().split())) x = x-1 y = y-1 ans = [0] * (n-1) for i in range(n): for j in range(i+1, n): shortest = min(abs(j-i), abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1) ans[shortest-1] += 1 for a in ans: print(a)
0
null
37,711,449,158,280
166
187
N = int(input()) A = list(map(int, input().split())) answer = 'DENIED' for i in range(0, N): if A[i] % 2 == 0: if A[i] % 3 == 0 or A[i] % 5 == 0: answer = 'APPROVED' else: answer = 'DENIED' break else: answer = 'APPROVED' print(answer)
import sys input() numbers = map(int, input().split()) evens = [number for number in numbers if number % 2 == 0] if len(evens) == 0: print('APPROVED') sys.exit() for even in evens: if even % 3 != 0 and even % 5 != 0: print('DENIED') sys.exit() print('APPROVED')
1
69,221,849,408,370
null
217
217
count=int(input()) for i in range(0, count): a = map(int, input().split(' ')) a = [j**2 for j in a] a.sort() if (a[0] + a[1] == a[2]): print('YES') else: print('NO')
count = int(input()) for i in range(count): a = map(int,raw_input().split()) a.sort() if a[0]**2+a[1]**2 == a[2]**2: print "YES" else: print "NO"
1
357,884,462
null
4
4
n, q = (int(x) for x in input().split()) process = [input().split() for _ in range(n)] time = 0 while process: p = process.pop(0) if int(p[1]) <= q: time += int(p[1]) print(p[0], time) else: time += q process.append([p[0], int(p[1]) - q])
def isok(arg): if arg < 0: return False count = 0 for i in range(n): count += max(0,-(-(a[i]*f[i]-arg)//f[i])) if count <= k: return True else: return False def bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if isok(mid): ok = mid else: ng = mid return ok n,k = map(int,input().split()) a = list(map(int,input().split())) f = list(map(int,input().split())) a.sort() f.sort(reverse = True) print(bisect(-1,10**12))
0
null
82,243,036,542,238
19
290
def gcd(a, b): return gcd(b, a%b) if b else a while True: try: a, b = map(int, raw_input().split()) ans = gcd(a, b) print ans, a*b//ans except EOFError: break
def gcd(a, b): if (a % b) == 0: return b return gcd(b, a%b) def lcd(a, b): return a * b // gcd(a, b) while True: try: nums = list(map(int, input().split())) print(gcd(nums[0], nums[1]), lcd(nums[0], nums[1])) except EOFError: break
1
644,890,980
null
5
5
""" 1 4 2 3 5 6 """ class Dice: def __init__(self, top, front, right, left, rear, bottom): self.top = top self.front = front self.right = right self.left = left self.rear = rear self.bottom = bottom def N(self): self.tmp = self.top self.top = self.front self.front = self.bottom self.bottom = self.rear self.rear = self.tmp def E(self): self.tmp = self.top self.top = self.left self.left = self.bottom self.bottom = self.right self.right = self.tmp def S(self): self.tmp = self.top self.top = self.rear self.rear = self.bottom self.bottom = self.front self.front = self.tmp def W(self): self.tmp = self.top self.top = self.right self.right = self.bottom self.bottom = self.left self.left = self.tmp def show_numbers(self): print("上:%d"% self.top) print("前:%d"% self.front) print("右:%d"% self.right) print("左:%d"% self.left) print("後:%d"% self.rear) print("底:%d"% self.bottom) def show_top(self): print("%d" % self.top) # ここからプログラム buf = input().split(" ") dice1 = Dice(int(buf[0]), int(buf[1]), int(buf[2]), int(buf[3]), int(buf[4]), int(buf[5])) buf = input() for ch in buf: if ch == "N": dice1.N() elif ch == "E": dice1.E() elif ch == "S": dice1.S() elif ch == "W": dice1.W() dice1.show_top()
from typing import List class Dice: def __init__(self, s: List[int]): self.s = s def get_s(self) -> int: return self.s[0] def invoke_method(self, mkey: str) -> None: if mkey == 'S': self.S() return None if mkey == 'N': self.N() return None if mkey == 'E': self.E() return None if mkey == 'W': self.W() return None raise ValueError(f'This method does not exist. : {mkey}') def set_s(self, s0, s1, s2, s3, s4, s5) -> None: self.s[0] = s0 self.s[1] = s1 self.s[2] = s2 self.s[3] = s3 self.s[4] = s4 self.s[5] = s5 def S(self) -> None: self.set_s(self.s[4], self.s[0], self.s[2], self.s[3], self.s[5], self.s[1]) def N(self) -> None: self.set_s(self.s[1], self.s[5], self.s[2], self.s[3], self.s[0], self.s[4]) def E(self) -> None: self.set_s(self.s[3], self.s[1], self.s[0], self.s[5], self.s[4], self.s[2]) def W(self) -> None: self.set_s(self.s[2], self.s[1], self.s[5], self.s[0], self.s[4], self.s[3]) # 提出用 data = [int(i) for i in input().split()] order = list(input()) # # 動作確認用 # data = [int(i) for i in '1 2 4 8 16 32'.split()] # order = list('SE') dice = Dice(data) for o in order: dice.invoke_method(o) print(dice.get_s())
1
230,729,813,000
null
33
33
n = int(input()) l = list(map(int,input().split())) h = 0 sum = 0 for i in range(n): if l[i] <= h: sum += h - l[i] else: h = l[i] print(sum)
N = int(input()) As = list(map(int,input().split())) Q = int(input()) count_array = [0]*(10**5+1) for i in range(N): count_array[As[i]] += 1 sum = 0 for i in range(len(As)): sum += As[i] for i in range(Q): x,y = map(int,input().split()) sum += count_array[x]*(y-x) print(sum) count_array[y] += count_array[x] count_array[x] = 0
0
null
8,281,295,685,338
88
122
from decimal import Decimal N = int(input()) M = int(N/Decimal(1.08)) + 1 if N == int(M*Decimal(1.08)) : print( int(M)) else : print(':(')
import math def solve(): N = int(input()) if math.floor(math.ceil(N / 1.08) * 1.08) == N: print(math.ceil(N / 1.08)) else: print(':(') if __name__ == "__main__": solve()
1
125,520,192,742,520
null
265
265
n = int(input()) m = list(map(int, input().split())) count = 0 for i in range(n-1): minj =i for j in range(i+1, n): if m[j] < m[minj]: minj = j if m[i] != m[minj]: m[i], m[minj] = m[minj], m[i] count += 1 print(" ".join(str(x) for x in m)) print(count)
# Selection Sort length = int(input()) array = [int(i) for i in input().rstrip().split()] count = 0 for i in range(length): minj = i for j in range(i, length): if array[j] < array[minj]: minj = j if minj != i: count += 1 array[i], array[minj] = array[minj], array[i] for i in range(length): if i < length - 1: print(array[i], end = " ") else: print(array[i]) print(count)
1
20,682,066,020
null
15
15
X = int(input()) i = 0 x = 0 while x<X: x = i*1000 i+=1 print (x-X)
import math def abc173a_payment(): n = int(input()) print(math.ceil(n/1000)*1000 - n) abc173a_payment()
1
8,466,280,957,916
null
108
108