code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
n = int(raw_input()) dp = {} def fib(n): if n in dp: return dp[n] if n == 0: dp[n] = 1 return 1 elif n == 1: dp[n] = 1 return 1 else: dp[n] = fib(n-1)+fib(n-2) return dp[n] print fib(n)
cnt = 0 def insert_sort(g): global cnt i = g for _ in range(n): v = nums[i] j = i - g while j >= 0 and nums[j] > v: nums[j + g] = nums[j] j -= g cnt += 1 nums[j + g] = v i += 1 if i >= n: break def shell_sort(): i = 0 for _ in range(m): insert_sort(g[i]) i += 1 n = int(input()) nums = [] for _ in range(n): nums.append(int(input())) g = [] g_val = n for _ in range(n): g_val = g_val // 2 g.append(g_val) if g_val == 1: break m = len(g) shell_sort() print(m) g_cnt = 0 s = '' for _ in range(m): s += str(g[g_cnt]) + ' ' g_cnt += 1 print(s.rstrip()) print(cnt) nums_cnt = 0 for _ in range(n): print(nums[nums_cnt]) nums_cnt += 1
0
null
15,731,791,160
7
17
A, B, C, K = list(map(lambda x : int(x), input().split(" "))) if A >= K: print(K) elif A + B >= K: print(A) else: print(2 * A + B - K)
N=int(input()) if N%1000==0: print("0") else: n=((N-(N%1000))/1000)+1 print(int((1000*n)-N))
0
null
15,178,688,742,288
148
108
class Queue: def __init__(self): self.queue = [] def enqueue(self, value): self.queue.append(value) def dequeue(self): return self.queue.pop(0) class Task: def __init__(self, name, time): self.name = name self.time = int(time) self.endtime = 0 def __repr__(self): return '{} {}'.format(self.name, self.endtime) def rr(queue, q): time = 0 while len(queue.queue) > 0: task = queue.dequeue() if task.time > q: task.time -= q time += q queue.enqueue(task) else: time += task.time task.time = 0 task.endtime = time print(task) if __name__ == '__main__': nq = [int(s) for s in input().split()] N = nq[0] q = nq[1] queue = Queue() task_arr = [Task(*input().split()) for i in range(N)] for t in task_arr: queue.enqueue(t) rr(queue, q)
from collections import namedtuple Task = namedtuple('Task', 'name time') class Queue: def __init__(self, n): self.n = n self._l = [None for _ in range(self.n + 1)] self._head = 0 self._tail = 0 def enqueue(self, x): self._l[self._tail] = x self._tail += 1 if self._tail > self.n: self._tail -= self.n def dequeue(self): if self.isEmpty(): raise IndexError("pop from empty queue") else: e = self._l[self._head] self._l[self._head] = None self._head += 1 if self._head > self.n: self._head -= self.n return e def isEmpty(self): return self._head == self._tail def isFull(self): return self._tail == self.n if __name__ == '__main__': n, q = map(int, input().split()) queue = Queue(n+1) for _ in range(n): name, time = input().split() time = int(time) queue.enqueue(Task(name=name, time=time)) now = 0 while not queue.isEmpty(): task = queue.dequeue() t = task.time if t <= q: now += t print(task.name, now) else: now += q queue.enqueue(Task(task.name, t - q))
1
41,649,463,254
null
19
19
N, X, T = list(map(int, input().split())) if N%X == 0: print((N//X)*T) else: print(((N//X)+1)*T)
N,X,T = map(int,input().split()) a = N % X if a == 0: ans = (N//X)*T else: ans = ((N//X)+1)*T print(ans)
1
4,243,898,773,600
null
86
86
import sys import numpy as np sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def IS(): return sys.stdin.readline()[:-1] def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LII(rows_number): return [II() for _ in range(rows_number)] def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def main(): N,T = MI() max_T = -1 dish = [] for i in range(N): A,B = MI() dish.append([A,B]) dish.sort(key=lambda x : x[0]) max_T = max(max_T, A) dp=np.array([-1 for _ in range(T+max_T)]) dp[0] = 0 upper = 1 for i in range(N): ch = (dp>=0) ch[T:] = False ch2 = np.roll(ch, dish[i][0]) ch2[:dish[i][0]]=False dp[ch2] = np.maximum(dp[ch2] , dp[ch] + dish[i][1]) print(max(dp)) main()
A,V = map(int,input().split()) B,W = map(int,input().split()) T = int(input()) if W >= V: print('NO') else: if (V-W)*T >= abs(A-B): print('YES') else: print('NO')
0
null
83,267,500,508,992
282
131
def choose_hand(last,next): for j in ['r','s','p']: if j!=last and j!=next: return j n,k = map(int,input().split()) r,s,p = map(int,input().split()) points = {'r':r, 's':s, 'p':p} hands = {'r':'p', 's':'r', 'p':'s'} t = list(input()) rpsList = ['']*n ans = 0 for i,hand in enumerate(t): rpsList[i] += hands[hand] if i>=k and rpsList[i]==rpsList[i-k]: lastHand = rpsList[i-k] nextHand = hands[t[i+k]] if i+k<n else '' rpsList[i] = choose_hand(lastHand,nextHand) else: ans += points[hands[hand]] print(ans)
N,K = map(int,input().split()) R,S,P = map(int,input().split()) T = list(input()) graph = {"r":P,"s":R,"p":S,"*":0} for i,t in enumerate(T): if len(T)-i-K > 0: if t == T[i+K]: T[i+K] = "*" ans = 0 for t in T: ans += graph[t] print(ans)
1
106,471,758,070,194
null
251
251
import sys input = sys.stdin.readline from operator import itemgetter sys.setrecursionlimit(10000000) INF = 10**30 def main(): t = input().strip() s = [] # A = 0 ans = [] prevA = 0 for i in range(len(t)): if t[i] == '\\': s.append(i) elif len(s) > 0 and t[i] == '/': p = s.pop() k = i - p ans.append((p, k)) q = 0 while len(ans) > 0: # print(ans) g, h = ans[-1] if g >= p: q += h ans.pop() else: break # for j in range(len(ans) - len(s)): # print('i: ', i) # print('j: ', j) # print('ans: ', ans) # q += ans.pop() # print('q: ', q) if q != 0: ans.append((p, q)) # elif len(s) > 0 and t[i] == '_': # A += 1 v = 0 for i in range(len(ans)): v += ans[i][1] print(v) print(len(ans), end='') for i in range(len(ans)): print(' {}'.format(ans[i][1]), end='') print('') if __name__ == '__main__': main()
S = raw_input() S1, S2 = [], [] ans = pool = 0 for i in xrange(len(S)): if S[i] == "/" and len(S1) > 0: j = S1.pop() ans += i - j a = i - j while (len(S2) > 0 and S2[-1][0] > j): a += S2.pop()[1] S2.append([j, a]) if S[i] == "\\": S1.append(i) print ans if len(S2) > 0: print len(S2), " ".join(map(str, [a for j, a in S2])) else: print 0
1
57,651,101,760
null
21
21
x = input().split() W, H, x, y, r = int(x[0]), int(x[1]), int(x[2]), int(x[3]), int(x[4]) if r <= x and r <= y and x + r <= W and y + r <= H: print('Yes') else: print('No')
x = int(input());print((x//500)*1000 + ((x%500)//5)*5)
0
null
21,745,975,072,616
41
185
f=input n,s,q=int(f()),list(f()),int(f()) d={chr(97+i):[] for i in range(26)} for i in range(n): d[s[i]]+=[i] from bisect import * for i in range(q): a,b,c=f().split() b=int(b)-1 if a=='1': if s[b]==c: continue d[s[b]].pop(bisect(d[s[b]],b)-1) s[b]=c insort(d[c],b) else: t=0 for l in d.values(): m=bisect(l,b-1) if m<len(l) and l[m]<int(c): t+=1 print(t)
# https://atcoder.jp/contests/abc157/tasks/abc157_e import sys input = sys.stdin.readline class SegmentTree: def __init__(self, n, op, e): """ :param n: 要素数 :param op: 二項演算 :param e: 単位減 例) 区間最小値 SegmentTree(n, lambda a, b : a if a < b else b, 10 ** 18) 区間和 SegmentTree(n, lambda a, b : a + b, 0) """ self.n = n self.op = op self.e = e self.size = 1 << (self.n - 1).bit_length() # st[self.size + i] = array[i] self.tree = [self.e] * (self.size << 1) def built(self, array): """arrayを初期値とするセグメント木を構築""" for i in range(self.n): self.tree[self.size + i] = array[i] for i in range(self.size - 1, 0, -1): self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1]) def update(self, i, x): """i 番目の要素を x に更新""" i += self.size self.tree[i] = x while i > 1: i >>= 1 self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1]) def get_val(self, l, r): """[l, r)の畳み込みの結果を返す""" l, r = l + self.size, r + self.size res = self.e while l < r: if l & 1: res = self.op(self.tree[l], res) l += 1 if r & 1: r -= 1 res = self.op(self.tree[r], res) l, r = l >> 1, r >> 1 return res ################################################################################################################## def popcount(x): return bin(x).count("1") N = int(input()) st = SegmentTree(N, lambda a, b: a | b, 0) S = input().strip() data = [] for s in S: data.append(1 << (ord(s) - ord("a"))) st.built(data) Q = int(input()) for _ in range(Q): q, a, b = input().split() if q == "1": st.update(int(a)-1, 1 << (ord(b) - ord("a"))) if q == "2": a = int(a) - 1 b = int(b) print(popcount(st.get_val(a, b)))
1
62,720,524,462,820
null
210
210
n = int(input()) result = '' for x in range(3, n+1): if x % 3 == 0 or '3' in str(x): result += (' '+str(x)) print(result)
n = int(input()) result = "" for i in (range(1,n+1)): if i % 3 == 0: result += " " + str(i) continue j = i while j > 0: if j % 10 == 3: result += " " + str(i) break else: j //= 10 print (result)
1
915,743,890,790
null
52
52
x, y = map(int, input().split()) for i in range(x + 1): if 2 * (x - i) + 4 * i == y: print("Yes") break else: print("No")
x, y = list(map(int, input().split())) if y % 2 == 0 and 2 * x <= y and y <= 4 * x: print("Yes") else: print("No")
1
13,782,076,478,702
null
127
127
def main(): n = int(input()) points = [0, 0] for i in range(n): t, h = input().split(' ') points = map(lambda x, y: x+y, points, judge(t, h)) print("{0[0]} {0[1]}".format(list(points))) def judge(t, h): if t < h: return (0, 3) elif t > h: return (3, 0) return (1, 1) if __name__ == '__main__': main()
def main(): N = int(input()) S = input() cnt = 0 for i in range(N): for j in range(i + 1, N): k = 2 * j - i if k >= N: continue if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]: cnt += 1 print(S.count("R") * S.count("B") * S.count("G") - cnt) if __name__ == "__main__": main()
0
null
18,987,577,810,600
67
175
from sys import stdin import sys, math n = int(stdin.readline().rstrip()) a = [0 for i in range(n)] d = [int(x) for x in stdin.readline().rstrip().split()] for i in range(n-1): k = d[i] a[k-1] = a[k-1] + 1 for i in range(n): print(a[i])
N = int(input()) A = list(map(int, input().split())) B = [0 for i in range(N)] for i in range(N): B[A[i]-1] = i for b in B: print(b+1)
0
null
106,429,211,111,090
169
299
N = int(input()) P = [p for p in map(int,input().split())] ans = 0 min_p = P[0] for p in P: if min_p >= p: min_p = p ans += 1 print(ans)
N = int(input()) P = list(map(int,input().split())) num = float("inf") ans = 0 for i in range(N): if num >= P[i]: ans += 1 num = P[i] print(ans)
1
85,028,083,718,302
null
233
233
n, t = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort(key=lambda x: x[0]) dp = [[0] * (n+1) for i in range(t)] ans = 0 for time in range(1, t): for i in range(n): if ab[i][0] <= time: if dp[time][i] < (ab[i][1] + dp[time - ab[i][0]][i]): dp[time][i+1] = (ab[i][1] + dp[ time - ab[i][0] ][i]) else: dp[time][i+1] = dp[time][i] else: dp[time][i+1] = dp[time][i] if i < n-1: ans = max(ans, dp[time][i+1] + ab[i+1][1]) print(ans)
N, T = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort() dp = [0] * T #print("AB:", AB) answer = 0 for a, b in AB: for t in range(T-1, -1, -1): if dp[t]: if a + t < T: dp[a + t] = max(dp[a + t], dp[t] + b) answer = max(answer, dp[a + t]) else: answer = max(answer, dp[t] + b) if a < T: dp[a] = max(dp[a], b) answer = max(answer, b) #print("dp:", dp) print(answer)
1
151,707,157,680,580
null
282
282
N,M,Q = map(int, input().split()) a = [0]*Q b = [0]*Q c = [0]*Q d = [0]*Q for i in range(Q): a[i], b[i], c[i], d[i] = map(int, input().split()) def dfs(n_list, o, l, L): if o+l==0: num = 1 pos = 0 L_child = [0]*N for i in range(N+M-1): if n_list[i]==1: num += 1 else: L_child[pos] = num pos += 1 L.append(L_child) if o>=1: n_list[N+M-o-l-1] = 0 dfs(n_list, o-1,l, L) if l>=1: n_list[N+M-o-l-1] = 1 dfs(n_list, o, l-1, L) A = [0]*(N+M-1) L =[] dfs(A,N,M-1,L) ans = 0 for i in L: score = 0 for j in range(Q): if i[b[j]-1]-i[a[j]-1]==c[j]: score += d[j] if score > ans: ans = score print(ans)
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g import sys sys.setrecursionlimit(10000000) #mod = 10**9 + 7 #mod = 9982443453 mod = 998244353 def readInts(): return list(map(int,input().split())) def I(): return int(input()) x = I() xgcd = gcd(x,360) xlcm = 360 * x // xgcd print(xlcm//x)
0
null
20,429,901,961,888
160
125
import math H,W=map(int,input().split()) if W==1: print(1) elif H==1: print(1) else: A=math.ceil(H*W/2) print(A)
#65 import math while True: n=int(input()) if n==0: break s=list(map(int,input().split())) m=sum(s)/n a=0 for i in range(n): a+=(s[i]-m)**2 b=math.sqrt(a/n) print(b)
0
null
25,375,426,949,860
196
31
N, X, M = map(int, input().split()) visited = [False] * M tmp = X total_sum = X visited[tmp] = True total_len = 1 while True: tmp = (tmp ** 2) % M if visited[tmp]: loop_start_num = tmp break total_sum += tmp visited[tmp] = True total_len += 1 path_len = 0 tmp = X path_sum = 0 while True: if tmp == loop_start_num: break path_len += 1 path_sum += tmp tmp = (tmp ** 2) % M loop_len = total_len - path_len loop_sum = total_sum - path_sum result = 0 if N <= path_len: tmp = X for i in range(N): result += X tmp = (tmp ** 2) % M print(result) else: result = path_sum N -= path_len loops_count = N // loop_len loop_rem = N % loop_len result += loop_sum * loops_count tmp = loop_start_num for i in range(loop_rem): result += tmp tmp = (tmp ** 2) % M print(result) # print("loop_start_num", loop_start_num) # print("path_sum", path_sum) # print("loop_sum", loop_sum)
N, X, M = map(int, input().split()) if X <= 1: print(X*N) exit() check = [0]*(M+1) check[X] += 1 A = X last_count = 0 while True: A = (A**2)%M if check[A] != 0: last_count = sum(check) target_value = A break check[A] += 1 A2 = X first_count = 0 while A2 != target_value: first_count += 1 A2 = (A2**2)%M roop_count = last_count-first_count A3 = target_value mass = A3 for i in range(roop_count-1): A3 = (A3**2)%M mass += A3 if roop_count == 0: print(N*X) exit() if first_count != 0: ans = X A = X for i in range(min(N,first_count)-1): A = (A**2)%M ans += A else: ans = 0 if N > first_count: ans += ((N-first_count)//roop_count)*mass A4 = target_value if (N-first_count)%roop_count >= 1: ans += A4 for i in range(((N-first_count)%roop_count)-1): A4 = (A4**2)%M ans += A4 print(ans)
1
2,822,672,015,610
null
75
75
a=int(input()) x = 0 i = 0 while(1): x += a i += 1 x %= 360 if x: continue else: print(i) quit()
N_str=list(reversed(input())) N=int(N_str[0]) if N==2 or N==4 or N==5 or N==7 or N==9: print("hon") elif N==0 or N==1 or N==6 or N==8: print("pon") elif N==3: print("bon")
0
null
16,113,367,720,550
125
142
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 s = int(input()) mod = 10 **9 + 7 N = s 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 ) l = s//3 ans = 0 if s <= 2: print(0) else: for i in range(l): ans += cmb(s%3 + 3 * i +(l-i)-1, (l-i)-1,mod) print(ans%mod)
s = int(input()) mod = 10**9+7 import numpy as np if s == 1 or s == 2: print(0) elif s == 3: print(1) else: array = np.zeros(s+1) array[0] = 1 for i in range(3, s+1): array[i] = np.sum(array[:i-2]) % mod print(int(array[s]))
1
3,264,922,186,828
null
79
79
s=input() l=len(s) x=0 for i in range(l): x=x+int(s[i]) if x%9==0: print("Yes") else: print("No")
# -*- coding: utf-8 s = list(map(str,input().split())) sum = 0 for i in range(len(s)): sum += (int) (s[i]) if sum %9 == 0: print("Yes") else: print("No")
1
4,376,859,418,118
null
87
87
N= int(input()) ans = 0 for j in range(1,N+1): N_j = N//j ans += j*(1+N_j)*N_j//2 print(ans)
def main(): N = int(input()) A = list(map(int,input().split())) list_a = [0]*N for i in range(len(A)): list_a[A[i]-1] += 1 for i in range(N): print(list_a[i]) main()
0
null
21,920,419,992,968
118
169
#coding:utf-8 m = 0 f = 0 r = 0 while m + f + r >-3: m , f, r =[int(i) for i in input().rstrip().split(" ")] if m+f+r == -3: break if m == -1: print("F") elif f == -1: print("F") elif m+f <30: print("F") elif m+f <50: if r>=50: print("C") else: print("D") elif m+f <65: print("C") elif m+f <80: print("B") else: print("A")
# -*- coding: utf-8 -*- def bubbleSort(num_list): flag = True length = len(num_list) count = 0 while flag: flag = False for j in range(length-1, 0, -1): if num_list[j] < num_list[j-1]: num_list[j], num_list[j-1] = num_list[j-1], num_list[j] flag = True count += 1 return num_list, count input_num = int(input()) num_list = [int(i) for i in input().split()] bubble_list, swap_num = bubbleSort(num_list) for i in range(len(num_list)): if i > 0: print(" ", end="") print(num_list[i], end="") print() print(swap_num)
0
null
627,956,837,398
57
14
num= n = int(input()) price = [] max_pro = -999999999 while(n>0): x = int(input()) price.append(x) n -= 1 min = price[0] for i in range(1,num): pro = price[i]-min if(max_pro < pro): max_pro = pro if(min > price[i]): min = price[i] print ("{0}".format(max_pro))
i = raw_input().strip().split() W = int(i[0]) H = int(i[1]) x = int(i[2]) y = int(i[3]) r = int(i[4]) flag = True if x-r < 0 or x+r > W: flag = False elif y-r < 0 or y+r > H: flag = False if flag: print "Yes" else: print "No"
0
null
224,749,934,412
13
41
n = input() print '', for i in range(1, n+1): if i%3 == 0 or str(i).count('3'): print i,
n = int(input()) x = 1 y = "" z = 1 while True: z = 1 x += 1 if x % 3 == 0: y += " " y += str(x) else: while True: b = int(x % 10 ** (z - 1)) a = int((x - b) / 10 ** z) c = a % 10 ** z d = a % 10 ** (z - 1) if a == 3 or b == 3 or c == 3 or d == 3: y += " " y += str(x) break z += 1 if a < 3 and z > 3: break if x >= n: break print(y)
1
930,798,876,420
null
52
52
#!/usr/bin/env python3 a=sorted(input().split()) print(a[0]*int(a[1]))
# ABC152 a, b = map(int, input().split()) print(min(str(a)*b, str(b)*a))
1
84,078,094,228,414
null
232
232
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()) mod = 10 ** 9 + 7 N, K = MI() def num(self): return (-2 * pow(self, 3) + 3 * N * pow(self, 2) + (3 * N + 8) * self) // 6 ans = num(N + 1) - num(K - 1) print(ans % mod)
N, K = map(int, input().split()) mod = 10 ** 9 + 7 print(((N+1)*(N*N+2*N+6)//6+(K-1)*(2*K*K-(3*N+4)*K-6)//6) % mod)
1
33,158,874,559,982
null
170
170
while True: table = input().split() a = int(table[0]) op = table[1] b = int(table[2]) if op == "?": break if op == "+": print("%d"%(a+b)) elif op == "-": print("%d"%(a-b)) elif op == "*": print("%d"%(a*b)) else: print("%d"%(a/b))
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10 ** 9 + 7 N, K = lr() answer = 0 for i in range(K, N+2): low = i * (i-1) // 2 high = i * (N+N-i+1) // 2 answer += high - low + 1 answer %= MOD print(answer%MOD)
0
null
16,776,073,605,060
47
170
if(int(input()) %2 == 1): print("No") exit() t = input() if(t[:len(t)//2] == t[len(t)//2:]): print("Yes") else: print("No")
N = int(input()) S = input() if N%2!=0: print("No") elif N%2 == 0: if S[0:N//2]==S[N//2:N+1]: print("Yes") else: print("No")
1
147,077,999,783,488
null
279
279
import sys N, M = [int(x) for x in input().split()] s = 1 e = 2 * -(-M // 2) for _ in range(M): if s >= e: s = N - 2 * (M // 2) e = N print(s, e) s += 1 e -= 1
import math n, m = map(int, input().split()) c = 0 f = [math.floor(n/2), math.floor(n/2) + 1] if n % 2 == 0: while c < m: c += 1 if c == math.floor(n/4) + 1: if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n print(str(f[0]) + ' ' + str(f[1])) if (f[0] - 1) % n == 0: f[0] = n else: f[0] = (f[0] - 1) % n if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n else: while c < m: c += 1 print(str(f[0]) + ' ' + str(f[1])) if (f[0] - 1) % n == 0: f[0] = n else: f[0] = (f[0] - 1) % n if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n
1
28,639,928,525,718
null
162
162
n = int(input()) s = input() ans = n if n == 1: print("1") else: for i in range(n-1): if s[i] == s[i+1]: ans -= 1 print(ans)
N, K = [int(_) for _ in input().split()] P = [int(_) - 1 for _ in input().split()] C = [int(_) for _ in input().split()] def f(v, K): if K == 0: return 0 if max(v) < 0: return max(v) n = len(v) X = [0] for i in range(n): X.append(X[-1] + v[i]) ans = -(10 ** 10) for i in range(n + 1): for j in range(i): if i - j > K: continue ans = max(ans, X[i] - X[j]) return(ans) X = [False for _ in range(N)] ans = -(10 ** 10) for i in range(N): if X[i]: continue t = i v = [] while X[t] is False: X[t] = True v.append(C[t]) t = P[t] n = len(v) if K > n: s = sum(v) x = f(v * 2, n) if s > 0: a = s * (K // n - 1) + max(s + f(v * 2, K % n), x) else: a = x else: a = f(v * 2, K) ans = max(a, ans) print(ans)
0
null
87,975,352,907,482
293
93
from decimal import Decimal p=3.141592653589 r=float(raw_input()) print Decimal(r*r*p),Decimal(r*2*p)
import math x = float(input()) print("%.6f %.6f"%(x*x*math.pi, x*2*math.pi))
1
648,135,177,744
null
46
46
def main1(): s = input() s1 = s[0:len(s)//2] s2 = s[::-1] s2 = s2[0:len(s)//2] ans = 0 for i in range(len(s)//2): if s1[i]==s2[i]: continue else: ans+=1 print(ans) if __name__ == '__main__': main1()
def solve(): X = [int(i) for i in input().split()] for i in range(len(X)): if X[i] == 0: print(i+1) break if __name__ == "__main__": solve()
0
null
66,702,652,868,930
261
126
# A - DDCC Finals def main(): X, Y = map(int, input().split()) prize = 0 for i in (X, Y): if i == 1: prize += 300000 elif i == 2: prize += 200000 elif i == 3: prize += 100000 if X == Y and X == 1: prize += 400000 print(prize) if __name__ == "__main__": main()
a, b = map(int,input().split()) def main(x,y): print(x*y) main(a,b)
0
null
78,271,110,938,978
275
133
import sys INF = 1 << 32 - 1 S = sys.stdin.readlines() N, M, L = map(int, S[0].split()) dp = [[INF] * N for _ in range(N)] for i in range(1, M + 1): A, B, C = map(int, S[i].split()) dp[A - 1][B - 1] = C dp[B - 1][A - 1] = C for i in range(N): dp[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) dp2 = [[INF] * N for _ in range(N)] for i in range(N): for j in range(N): if dp[i][j] <= L: dp2[i][j] = 1 # for i in range(N): # dp2[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) Q = int(S[M + 1]) for i in range(M + 2, M + 2 + Q): s, t = map(int, S[i].split()) refuel = dp2[s - 1][t - 1] if refuel >= INF: print(-1) else: print(refuel - 1)
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M, L = lr() INF = 10 ** 19 dis = [[INF for _ in range(N+1)] for _ in range(N+1)] for _ in range(M): a, b, c = lr() if c > L: continue dis[a][b] = c dis[b][a] = c for k in range(N+1): # kが中継地点 for i in range(N+1): for j in range(i+1, N+1): x = dis[i][k] + dis[k][j] if x < dis[i][j]: dis[i][j] = dis[j][i] = x supply = [[INF] * (N+1) for _ in range(N+1)] for i in range(N+1): for j in range(i+1, N+1): if dis[i][j] <= L: supply[i][j] = supply[j][i] = 1 for k in range(N+1): # kが中継地点 for i in range(N+1): for j in range(i+1, N+1): y = supply[i][k] + supply[k][j] if y < supply[i][j]: supply[i][j] = supply[j][i] = y Q = ir() for _ in range(Q): s, t = lr() if supply[s][t] == INF: print(-1) else: print(supply[s][t] - 1) # 59
1
174,141,766,265,270
null
295
295
S,W=map(int,input().split()) if S<=W: print("unsafe") elif S>W: print("safe")
n = int(input()) xy = [list(map(int, input().split())) for i in range(n)] def distance(i, j): xi, yi = xy[i] xj, yj = xy[j] return (xi-xj)**2 + (yi-yj)**2 visited = [False] * n ans = 0 def dfs(route, length): global ans if len(route)==n: ans += length return else: for i in range(n): if visited[i]: continue next_distance = distance(route[-1], i)**0.5 visited[i] = True dfs(route+[i], length+next_distance) visited[i] = False cnt = 1 for i in range(n): cnt*=i+1 visited[i] = True dfs([i], 0) visited[i] = False print(ans/cnt)
0
null
89,177,572,055,680
163
280
n, t = map(int, input().split()) lst = [0 for _ in range(t)] ab = [list(map(int, input().split())) for _ in range(n)] ab.sort() ans = 0 for a, b in ab: ans = max(ans, lst[-1] + b) for i in range(t - 1, a - 1, -1): lst[i] = max(lst[i], lst[i - a] + b) print(ans)
# -*- coding: utf-8 -*- num = int(raw_input()) a = int(raw_input()) b = int(raw_input()) diff = b - a pre_min = min(a,b) counter = 2 while counter < num: current_num = int(raw_input()) if diff < current_num - pre_min: diff = current_num - pre_min if pre_min > current_num: pre_min = current_num counter += 1 print diff
0
null
75,510,724,566,980
282
13
N=int(input()) A=list(map(int,input().split())) A1=set(A) ans="NO" if len(A)==len(A1): ans="YES" print(ans)
N = int(input()) A = list(map(int, input().split())) A_set = set(A) if len(A) == len(A_set): print('YES') else: print('NO')
1
73,692,528,929,304
null
222
222
A = int(input()) print(A//2+A%2)
word = input() if word == 'AAA' or word == 'BBB': print('No') else: print('Yes')
0
null
56,642,070,061,372
206
201
def main(): K = int(input()) work = 7 answer = -1 for i in range(1, K+1): i_mod = work % K if i_mod == 0 : answer = i break work = i_mod * 10 + 7 print(answer) main()
K=int(input()) num=7 ans=-1 for n in range(pow(10,7)): if num%K==0: ans=n+1 break shou=num//K num-=K*shou num=int(str(num)+'7') print(ans)
1
6,125,048,295,092
null
97
97
r,c,k = map(int,input().split()) v = [[0]*(c+1) for i in range(r+1)] for i in range(k): x,y,z = map(int,input().split()) v[x][y] = z dp = [[0]*4 for i in range(r+1)] for i in range(1,c+1): for j in range(1,r+1): if v[j][i]>0: dp[j][3] = max(dp[j][2]+v[j][i],dp[j][3]) dp[j][2] = max(dp[j][1]+v[j][i],dp[j][2]) dp[j][1] = max(dp[j][0]+v[j][i],dp[j][1],max(dp[j-1])+v[j][i]) dp[j][0] = max(dp[j][0],max(dp[j-1])) print(max(dp[r]))
from copy import deepcopy def getval(): r,c,k = map(int,input().split()) item = [[0 for i in range(c)] for i in range(r)] for i in range(k): ri,ci,vi = map(int,input().split()) item[ri-1][ci-1] = vi return r,c,k,item def main(r,c,k,item): #DP containing the information of max value given k items picked in i,j prev = [[0 for i in range(4)]] inititem = item[0][0] prev[0] = [0,inititem,inititem,inititem] for i in range(1,r): initval = prev[i-1][3] temp = [] cur = item[i][0] for j in range(4): temp.append(initval) for j in range(1,4): temp[j] += cur prev.append(temp) for j in range(1,c): init = deepcopy(prev[0]) for i in range(1,4): init[i] = max(prev[0][i],prev[0][i-1]+item[0][j]) curcol = [init] for i in range(1,r): cur = item[i][j] left = curcol[-1] down = prev[i] temp = [max(left[3],down[0])] for k in range(1,4): temp.append(max(max(left[3],down[k-1])+cur,down[k])) curcol.append(temp) prev = curcol print(max(prev[-1])) if __name__=="__main__": r,c,k,item = getval() main(r,c,k,item)
1
5,540,077,457,056
null
94
94
r = int(input()) a = (44/7)*r print(a)
R = int(input()) print(R * 6.28318530717958623200)
1
31,282,132,009,898
null
167
167
m,n=map(long,raw_input().split()) print m/n, print m%n, print '%.5f' % (float(m)/n)
a, b = map(int, input().split()) print('{0} {1} {2:f}'.format(a // b, a % b, a / b))
1
610,730,163,680
null
45
45
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) mod = 10**9+7 dir = [(-1,0),(0,-1),(1,0),(0,1)] alp = "abcdefghijklmnopqrstuvwxyz" def main(): n,m,k = map(int,ipt().split()) fl = [[] for i in range(n)] bl = [set() for i in range(n)] for i in range(m): a,b = map(int,ipt().split()) fl[a-1].append(b-1) fl[b-1].append(a-1) for i in range(k): c,d = map(int,ipt().split()) bl[c-1].add(d-1) bl[d-1].add(c-1) ans = [-1]*n al = [True]*n for i in range(n): if al[i]: q = [i] al[i] = False st = set([i]) while q: qi = q.pop() for j in fl[qi]: if al[j]: st.add(j) al[j] = False q.append(j) lst = len(st) for j in st: tmp = lst-len(fl[j])-1 for k in bl[j]: if k in st: tmp -= 1 ans[j] = tmp print(" ".join(map(str,ans))) return None if __name__ == '__main__': main()
a = input().split() d = int(a[0]) // int(a[1]) r = int(a[0]) % int(a[1]) f = float(a[0]) / float(a[1]) print('{0} {1} {2:.5f}'.format(d,r,f))
0
null
31,193,534,569,220
209
45
N=input().split() X=N[0] Y=N[1] Z=N[2] print(Z + ' ' + X + ' ' + Y)
# 問題:https://atcoder.jp/contests/abc142/tasks/abc142_b n, k = map(int, input().strip().split()) h = list(map(int, input().strip().split())) res = 0 for i in range(n): if h[i] < k: continue res += 1 print(res)
0
null
108,167,135,569,792
178
298
r=int(input()) print(int(pow(r,2)))
r = int(input()) s = r**2 print(s)
1
145,488,212,924,908
null
278
278
N = int(input()) S = [s for s in input()] ans = S.count("R") * S.count("G") * S.count("B") for i in range(N - 2): for j in range(i + 1, N - 1): k = j + (j - i) if N - 1 < k: continue if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]: ans -= 1 print(ans)
n = int(input()) s = input() num = len(s) ans = s.count('R')*s.count('G')*s.count('B') for i in range(num): for j in range(i+1, num): if 0 <= 2*j-i < num: if s[i] != s[j] and s[j] != s[2*j-i] and s[2*j-i] != s[i]: ans -= 1 print(ans)
1
36,304,259,815,108
null
175
175
def main(): a,b,c,k = list(map(int,input().split())) if k<=a: print(k) elif k<=a+b: print(a) elif k < a+b+c: print(a-(k-(a+b))) else: print(a-c) main()
small = [] large = [] while True: input_a, input_b = map(int, raw_input().split()) if input_a == 0 and input_b == 0: break else: if input_a < input_b: small.append(input_a) large.append(input_b) else: small.append(input_b) large.append(input_a) for (n, m) in zip(small, large): print n, m
0
null
11,138,048,758,668
148
43
def show2dlist(nlist,r,c): for x in xrange(0,r): nlist[x] = map(str,nlist[x]) ans = " ".join(nlist[x]) print ans # input n,m,l = map(int,raw_input().split()) a_matrix = [[0 for x in xrange(m)] for y in xrange(n)] b_matrix = [[0 for x in xrange(l)] for y in xrange(m)] for x in xrange(n): a_matrix[x] = map(int,raw_input().split()) for x in xrange(m): b_matrix[x] = map(int,raw_input().split()) c_matrix = [[0 for x in xrange(l)] for y in xrange(n)] # calc for ni in xrange(n): for li in xrange(l): for mi in xrange(m): c_matrix[ni][li] += a_matrix[ni][mi] * b_matrix[mi][li] # show result show2dlist(c_matrix,n,l)
f = open(0) N, M, L = map(int, f.readline().split()) A = [list(map(int, f.readline().split())) for i in range(N)] B = [list(map(int, f.readline().split())) for i in range(M)] C = [[0]*L for i in range(N)] for i in range(N): for j in range(L): C[i][j] = str(sum(A[i][k]*B[k][j] for k in range(M))) for line in C: print(*line)
1
1,410,658,091,300
null
60
60
N=int(input()) A=map(int, input().split()) P=1000000007 ans = 1 cnt = [3 if i == 0 else 0 for i in range(N + 1)] for a in A: ans=ans*cnt[a]%P if ans==0: break cnt[a]-=1 cnt[a+1]+=1 print(ans)
from bisect import bisect_left n = int(input()) l = list(map(int, input().split())) l.sort() ans = 0 for i in range(n): for j in range(i + 1, n): k = l[i] + l[j] pos = bisect_left(l, k) ans += max(0, pos - j - 1) print(ans)
0
null
151,099,023,523,110
268
294
import math import itertools n = int(input()) al = [0] * n bl = [0] * n for i in range(n): al[i], bl[i] = map(int, input().split()) bunbo = math.factorial(n) ans = 0 for p in itertools.permutations(list(range(n))): for i in range(n-1): ans += ((al[p[i+1]]-al[p[i]])**2+(bl[p[i+1]]-bl[p[i]])**2)**0.5 print(ans/bunbo)
import itertools N = int(input()) c = [] d = 0 for i in range(N): x1, y1 = map(int, input().split()) c.append((x1,y1)) cp = list(itertools.permutations(c)) x = len(cp) for i in range(x): for j in range(N-1): d += ((cp[i][j][0]-cp[i][j+1][0])**2 + (cp[i][j][1] - cp[i][j+1][1])**2)**0.5 print(d/x)
1
148,452,010,328,960
null
280
280
if 22 > sum(map(int, input().split())): print('win') else: print('bust')
print('bust' if sum(list(map(int, input().split()))) >= 22 else 'win')
1
119,022,098,779,872
null
260
260
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline().rstrip() def main(): n=int(input()) A=list(map(int, input().split())) counts=[0]*(10**6+5) for AA in A: counts[AA]+=1 ans=0 for i in range(1,10**6+5): if counts[i]>0: for j in range(i+i,10**6+5,i): counts[j]=-1 if counts[i]==1: ans+=1 print(ans) if __name__ == '__main__': main()
N = int(input()) tree = [[] for _ in range(N)] for _ in range(N): u, k, *v = map(int, input().split()) tree[u-1] = v ans = [float('inf') for _ in range(N)] ans[0] = 0 from collections import deque q = deque([(0, 0)]) while q: p, d = q.popleft() for c in tree[p]: if ans[c-1] > d+1: ans[c-1] = d+1 q.append((c-1, d+1)) for i in range(N): if ans[i] == float('inf'): print(i+1, -1) else: print(i+1, ans[i])
0
null
7,189,869,389,568
129
9
n,k = map(int,input().split()) mod = 10**9 +7 sum1 = 0 for i in range(k,n+2): sum1 +=(-i*(i-1)//2 + i*(2*n-i+1)//2+1)%mod print(sum1%mod)
N, K = map(int,input().split()) MOD = 10**9 + 7 ans = 0 for k in range(K,N+2): m = (k*(k-1))//2 M = (k*(N+N-k+1))//2 ans += M-m+1 print(ans%MOD)
1
32,925,361,752,566
null
170
170
from collections import defaultdict MOD = 10**9+7 n = int(input()) A = list(map(int, input().split())) def sieve(n): n += 1 res = [i for i in range(n)] for i in range(2, int(n**.5)+1): if res[i] < i: continue for j in range(i**2, n, i): if res[j] == j: res[j] = i return res U = max(A)+1 min_factor = sieve(U) def prime_factor(n): res = defaultdict(lambda: 0) while 1 < n: res[min_factor[n]] += 1 n //= min_factor[n] return res pf = defaultdict(lambda: 0) for a in A: for p, q in prime_factor(a).items(): if pf[p] < q: pf[p] = q x = 1 for p, q in pf.items(): x *= pow(p, q, MOD) x %= MOD print(sum(x*pow(a, MOD-2, MOD) for a in A) % MOD)
from math import gcd from functools import reduce N = int(input()) A = [int(i) for i in input().split()] mod = 10**9 + 7 def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) num = lcm_list(A)%mod ans = 0 for a in A: ans += (num * pow(a, mod-2, mod))%mod ans %= mod print(ans)
1
87,377,226,785,160
null
235
235
count = 1 while True: x = int(input()) if x == 0: break print('Case %d: %d' % (count, x)) count += 1
from collections import Counter S = input() L = len(list(S)) dp = [0] * L dp[0] = 1 T = [0] * L T[0] = int(S[-1]) for i in range(1, L): dp[i] = dp[i - 1] * 10 dp[i] %= 2019 T[i] = int(S[-(i+1)]) * dp[i] + T[i - 1] T[i] %= 2019 ans = 0 for k, v in Counter(T).items(): if k == 0: ans += v ans += v * (v - 1) // 2 else: ans += v * (v - 1) // 2 print(ans)
0
null
15,717,445,990,048
42
166
n = int(input()) l = 0 r = 0 cntl = 0 cntr = 0 fl = 0 fr = 0 exl = 0 exr = 0 only_r = 0 only_l = 0 maxl = 0 maxr = 0 exlr = [] for i in range(n): s = input() templ = 0 tempr = 0 temp_exl = 0 temp_exr = 0 fl = 0 fr = 0 for i in s: if i == "(": tempr += 1 elif i == ")": tempr -= 1 if tempr < 0: tempr = 0 templ += 1 fl = 1 temp_exl += templ if tempr > 0: temp_exr += tempr fr = 1 if fl == 1 and fr == 0: only_l += temp_exl elif fr == 1 and fl == 0: only_r += temp_exr elif temp_exl + temp_exr > 0: exl += temp_exl exr += temp_exr exlr.append([temp_exl-temp_exr, temp_exl,temp_exr]) # maxl = max(maxl,temp_exl) # maxr = max(maxr,temp_exr) # print (exr,exl,only_r,only_l) a = only_r b = only_l # print(exlr) exlr.sort() # exlr.sort(key=lambda x: x[1]) # print(exlr) # for i in range(len(exlr)): # if exlr[i][1] <= a and exlr[i][0] <= 0: # a -= exlr[i][0] # exlr[i] = [0,0,0] # print(exlr) for i in exlr: a -= i[1] if a<0: print("No") exit() a += i[2] if a-b == 0: print("Yes") else: print("No") # if exl+only_l == exr+only_r and exl-exr == only_r-only_l and only_l > 0 and only_r > 0: # print("Yes") # elif exr+exl+only_l+only_r == 0: # print("Yes") # else: # print("No")
# 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 #import queue# queue,get(), queue.put() def run(): N = int(input()) current = 0 ways = [] dic = {'(': 1, ')': -1} SS = read().split() for S in SS: path = [0] for s in S: path.append(path[-1]+ dic[s]) ways.append((path[-1], min(path))) ways_pos = sorted([(a,b) for a,b in ways if a >= 0], key = lambda x:(x[1], x[0]), reverse=True) ways_neg = sorted([(a,b) for a,b in ways if a < 0], key = lambda x:(x[1] - x[0], -x[0])) for i in range(len(ways_pos)): go, max_depth = ways_pos[i] if current + max_depth >= 0: current += go else: print("No") return None for i in range(len(ways_neg)): go, max_depth = ways_neg[i] if current + max_depth >= 0: current += go else: print("No") return None if current == 0: print('Yes') else: print('No') if __name__ == "__main__": run()
1
23,700,388,597,320
null
152
152
N,K = map(int, input().split()) tmp=N count=0 while tmp!=0: tmp = tmp//K count += 1 print(count)
from sys import stdin rs = stdin.readline ri = lambda : int(rs()) ril = lambda : list(map(int, rs().split())) from functools import reduce def main(): N, K = ril() A = ril() l = 1 r = 1000000000 while l < r: m = (l + r) // 2 f = lambda i, j : i + (j - 1) // m k = reduce(f, A, 0) if k <= K: r = m else: l = m + 1 print(r) if __name__ == '__main__': main()
0
null
35,444,716,599,512
212
99
a,b=map(int,input().split()) if a<=9: if b<=9: print(a*b) else: print("-1") else: print("-1")
input() a=1 d=1000000000000000000 for i in input().split(): a=min(a*int(i),d+1) print([a,-1][a>d])
0
null
87,634,538,593,680
286
134
import sys from collections import deque import copy def main(): S = input() print(S[0:3]) if __name__ == '__main__': main()
K = str(input()) print(K[0:3])
1
14,776,212,259,952
null
130
130
(X,N) = map(int,input().split()) if N == 0: print(X) else: p = list(map(int,input().split())) for i in range(N+1): if (X - i) not in p: print(X-i) break elif(X+i) not in p: print(X+i) break
size = [int(i) for i in input().split()] matrix = [[0 for i in range(size[1])] for j in range(size[0])] vector = [0 for i in range(size[1])] for gyou in range(size[0]): x = [int(i) for i in input().split()] matrix[gyou] = x for retsu in range(size[1]): x = int(input()) vector[retsu] = x for gyou in range(size[0]): print(sum(map(lambda val1, val2: val1 * val2, matrix[gyou], vector)))
0
null
7,583,725,123,456
128
56
a=[] a=input() print('%s%s%s'%(a[0],a[1],a[2]))
a = input() b = a[:3] print(b)
1
14,663,842,952,798
null
130
130
a, b, c, k = map(int, input().split()) ans = 0 for i, j in zip([1, 0, -1], [a, b, c]): x = min(k, j) ans += i*x k -= x print(ans)
A,B,C,K = map(int,input().split()) koa = 0 if A<K: koa = A else : koa = K kob = 0 if B<K-koa: kob = B else : kob = K-koa #print (koa) #print (kob) sum = koa+0*kob+(K-(koa+kob))*-1 print (sum)
1
21,641,983,636,648
null
148
148
h, n = map( int, input().split() ) a = [] b = [] for _ in range( n ): a_i, b_i = map( int, input().split() ) a.append( a_i ) b.append( b_i ) dp = [ float( "Inf" ) ] * ( h + 1 ) # dp[ d ] = dを与える最小マナ dp[ 0 ] = 0 for i in range( h ): for j in range( n ): update_index = min( i + a[ j ], h ) dp[ update_index ] = min( dp[ update_index ], dp[ i ] + b[ j ] ) print( dp[ h ] )
# ABC153 E Crested Ibis vs Monster f=lambda:map(int,input().split()) H,N=f() # dp[n][h]:=nthまでで体力をh削るときの最小魔力 INF=10**9 dp=[[INF]*(H+1) for _ in [0]*(N+1)] for i in range(N+1): if i!=0: a,b=f() else: a,b=0,0 for j in range(H+1): if i==0: if j==0: dp[i][j]=0 else: dp[i][j]=INF else: dp[i][j]=min(dp[i-1][j],dp[i][max(j-a,0)]+b) print(dp[N][H])
1
80,997,051,078,930
null
229
229
from collections import deque def round_robin_scheduling(n, q, A): sum = 0 while A: head = A.popleft() if head[1] <= q: sum += head[1] print(head[0], sum) else: sum += q head[1] -= q A.append(head) if __name__ == '__main__': n, q = map(int, input().split()) A = deque() for i in range(n): name, time = input().split() A.append([name, int(time)]) round_robin_scheduling(n, q, A)
n, quantum = list(map(int, input().split())) queue = [] sumOfTime = 0 for _ in range(n): name, time = input().split() queue.append([name, int(time)]) while len(queue) > 0: name, time = queue.pop(0) if time > quantum: sumOfTime += quantum queue.append([name, time - quantum]) else: sumOfTime += time print(name, sumOfTime)
1
42,070,619,280
null
19
19
def resolve(): S = list(input()) ans = [0 for _ in range(len(S) + 1)] cnt = 0 for i in range(len(S)): if S[i] == "<": cnt += 1 ans[i + 1] = max(cnt, ans[i + 1]) else: cnt = 0 cnt = 0 for i in range(len(S), 0, -1): if S[i - 1] == ">": cnt += 1 ans[i - 1] = max(cnt, ans[i - 1]) else: cnt = 0 print(sum(ans)) resolve()
S=input() N=len(S) count=[0]*(N+1) i=0 while i<N: if S[i]=='<': count[i+1]=count[i]+1 i+=1 S=S[::-1] count=count[::-1] i=0 while i<N: if S[i]=='>': count[i+1]=max(count[i+1],count[i]+1) i+=1 print(sum(count))
1
156,570,519,775,980
null
285
285
n = int(input()[-1]) if n in [2,4,5,7,9]: print("hon") elif n in [0,1,6,8]: print("pon") else: print("bon")
mylist1 = [2,4,5,7,9] mylist2 = [0,1,6,8] N = int(input()) X = N % 10 if X in mylist1: print('hon') elif X in mylist2: print('pon') else: print('bon')
1
19,264,652,915,068
null
142
142
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) def solve(N: int, K: int): NL = list(map(int, N)) useMaxDigits = [[0 for i in range(K+1)] for j in range((len(N)+1))] noUseMaxDigits = [[0 for i in range(K+1)] for j in range((len(N)+1))] useMaxDigits[0][0] = 1 for digit in range(1, len(N)+1): D = NL[digit-1] # Use Max continueingly if D != 0: for i in range(1, K+1): useMaxDigits[digit][i] = useMaxDigits[digit-1][i-1] for i in range(0, K+1): noUseMaxDigits[digit][i] = useMaxDigits[digit-1][i] else: for i in range(0, K+1): useMaxDigits[digit][i] = useMaxDigits[digit-1][i] # Use non max for i in range(0, K+1): # if use zero noUseMaxDigits[digit][i] += noUseMaxDigits[digit-1][i] for i in range(1, K+1): noUseMaxDigits[digit][i] += noUseMaxDigits[digit-1][i-1]*9 for i in range(1, K+1): noUseMaxDigits[digit][i] += useMaxDigits[digit - 1][i-1]*max(0, D-1) print(useMaxDigits[-1][-1]+noUseMaxDigits[-1][-1]) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = next(tokens) # type: int K = int(next(tokens)) # type: int solve(N, K) if __name__ == '__main__': main()
H, W = map(int,input().split()) S = [list(input()) for i in range(H)] N = [[10**9]*W]*H l = 0 u = 0 if S[0][0] == '#' : N[0][0] = 1 else : N[0][0] = 0 for i in range(H) : for j in range(W) : if i == 0 and j == 0 : continue #横移動 l = N[i][j-1] #縦移動 u = N[i-1][j] if S[i][j-1] == '.' and S[i][j] == '#' : l += 1 if S[i-1][j] == '.' and S[i][j] == '#' : u += 1 N[i][j] = min(l,u) print(N[-1][-1])
0
null
62,620,687,569,622
224
194
import math def main(): n=int(input()) print(math.ceil(n/2)/n) if __name__ == '__main__': main()
def disc(s,d): ans[d][0] = s s += 1 if main[d][0] != 0: for l in range(1,int(main[d][0])+1): if ans[int(main[d][l])-1][0] == 0: s = disc(int(s),int(main[d][l])-1) ans[d][1] = s return s+1 n = int(input()) main = [] for i in range(n): a = input().split() if int(a[1]) > 0: main.append(a[1:]) else: main.append([0]) del a ans = [[0] * 2 for i in range(n)] ls = disc(1,0) for i in range(n): if ans[i][0] == 0: ls = disc(int(ls),i) for i in range(n): print(str(i+1) + " " + str(ans[i][0]) + " " + str(ans[i][1]))
0
null
88,181,862,429,342
297
8
x=int(input()) print('ACL'*x)
k = int(input()) text = "ACL" * k print(text)
1
2,176,679,542,784
null
69
69
l = int(input()) ans = l * l * l / 27 print(ans)
#coding: UTF-8 def Sort(a,b,c): box = 0 if a > b: box = b b = a a = box if b > c: box = c c = b b = box if a > b: box = b b = a a = box return a,b,c if __name__=="__main__": a = input().split(" ") a,b,c = Sort(int(a[0]),int(a[1]),int(a[2])) print(str(a)+" "+str(b)+" "+str(c))
0
null
23,888,306,701,582
191
40
n,k = map(int,input().split()) h = list(map(int,input().split())) ans = 0 if(n <= k): print(0) else: h.sort() a = [] a = h[:n-k] print(sum(a))
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)
0
null
72,951,602,244,590
227
215
import sys dic = set() L = sys.stdin.readlines() for Ins in L[1:]: ins, op = Ins.split() if ins == 'insert': dic.add(op) if ins == 'find': print('yes' if op in dic else 'no')
M = 1046527 POW = [pow(4, i) for i in range(13)] def insert(dic, string): # i = 0 # while dic[(hash1(string) + i*hash2(string)) % M]: # i += 1 # dic[(hash1(string) + i*hash2(string)) % M] = string dic[get_key(string)] = string def find(dic, string): # i = 0 # while dic[(hash1(string) + i*hash2(string)) % M] and dic[(hash1(string) + i*hash2(string)) % M] != string: # i += 1 # return True if dic[(hash1(string) + i*hash2(string)) % M] == string else False # print(dic[get_key(string)], string) return True if dic[get_key(string)] == string else False def get_num(char): if char == "A": return 1 elif char == "C": return 2 elif char == "G": return 3 else: return 4 def get_key(string): num = 0 for i in range(len(string)): num += POW[i] * get_num(string[i]) return num def main(): n = int(input()) dic = [None] * POW[12] # print(dic) for i in range(n): order, string = input().split() if order == "insert": insert(dic, string) else: if find(dic, string): print('yes') else: print('no') if __name__ == "__main__": main()
1
77,487,996,688
null
23
23
class Main: S = input() if S[-1] == 's': print(S+'es') else : print(S+'s')
N = int(input()) S = input() from collections import Counter d = Counter(list(S)) allr = d["R"] leftd = Counter(list(S[:allr])) leftr = leftd["R"] print(allr-leftr)
0
null
4,379,066,938,890
71
98
N,M,K=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a_s=[0] b_s=[0] for i in range(N): if a_s[i]+a[i]>K: break a_s.append(a[i]+a_s[i]) for i in range(M): if b_s[i]+b[i]>K: break b_s.append(b[i]+b_s[i]) bn=len(b_s)-1 ans=0 for i in range(len(a_s)): while a_s[i]+b_s[bn]>K: bn-=1 ans=max(ans,i+bn) print(ans)
import bisect n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a2 = [0] * (n + 1) b2 = [0] * (m + 1) for i in range(0, n): a2[i+1] = a[i] + a2[i] for i in range(0, m): b2[i+1] = b[i] + b2[i] ans = 0 for i in range(n+1): tmp = bisect.bisect_right(b2, k-a2[i]) - 1 if a2[i] + b2[tmp] <= k and tmp >= 0: ans = max(ans, i+tmp) print(ans)
1
10,718,750,455,000
null
117
117
for i in range(1,10): for j in range(1,10): print('%sx%s=%s'%(i,j,i*j))
for i in range(1, 10): for j in range(1, 10): print(i,'x',j,'=',i*j,sep='')
1
1,009,462
null
1
1
n, W = map(int, input().split()) ab = [tuple(map(int, input().split()))for _ in range(n)] ab.sort() ans = 0 dp = [0]*W for a, b in ab: if ans < dp[-1]+b: ans = dp[-1]+b for j in reversed(range(W)): if j-a < 0: break if dp[j] < dp[j-a]+b: dp[j] = dp[j-a]+b print(ans)
def main(): N, T = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N)] dp = [-1] * (T + 3000) dp[0] = 0 c = 0 for a, b in sorted(AB): for j in range(c, -1, -1): if dp[j] == -1: continue t = dp[j] + b if dp[j + a] < t: dp[j + a] = t c = min(c + a, T - 1) print(max(dp)) main()
1
151,304,500,570,180
null
282
282
a, b, m = list(map(int, input().split())) fridges = list(map(int, input().split())) microwaves = list(map(int, input().split())) price_min = min(fridges) + min(microwaves) for _ in range(m): x, y, c = list(map(int, input().split())) price = fridges[x-1] + microwaves[y-1] - c if price < price_min: price_min = price print(price_min)
(A, B, M), aa, bb, *xyc = [list(map(int, s.split())) for s in open(0)] ans = min(aa)+min(bb) for x, y, c in xyc: ans = min(ans, aa[x-1]+bb[y-1]-c) print(ans)
1
54,092,036,514,308
null
200
200
d = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for i in range(d)] lastd = [0] * 26 for i in range(1, d + 1): ans = 0 tmp = 0 for j in range(26): if tmp < s[i - 1][j] + (i - lastd[j]) * c[j]: tmp = s[i - 1][j] + (i - lastd[j]) * c[j] ans = j + 1 lastd[ans - 1] = i print(ans)
import random D=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split())) for i in [0]*D] for i in range(D): print(random.randint(1,26))
1
9,792,225,830,102
null
113
113
n,m = map(int,input().split()) memo2 = [False for i in range(n)] memo = [0 for i in range(n)] count1,count2 = 0,0 for i in range(m): p,l = input().split() p = int(p)-1 if memo2[p]: continue else: if l == 'WA': memo[p]+=1 else: memo2[p] = True count2 += 1 count1+=memo[p] print(count2,count1)
K=int(input());S="" for i in range(K): S=S+"ACL" print(S)
0
null
48,067,194,330,708
240
69
n,m = map(int, input().split()) #a = list(map(int, input().split())) class UnionFind: def __init__(self,n): self.par=[i for i in range(n)] self.siz=[1]*n def root(self,x): while self.par[x]!=x: self.par[x]=self.par[self.par[x]] x=self.par[x] return x def unite(self,x,y): x=self.root(x) y=self.root(y) if x==y: return False if self.siz[x]<self.siz[y]: x,y=y,x self.siz[x]+=self.siz[y] self.par[y]=x return True def is_same(self,x,y): return self.root(x)==self.root(y) def size(self,x): return self.siz[self.root(x)] uni = UnionFind(n) for i in range(m): a,b = map(int, input().split()) uni.unite(a-1, b-1) cnt = [0]*(n) for i in range(n): cnt[uni.root(i)] = 1 print(sum(cnt)-1)
#0926 class UnionFind(): # 0インデックス def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def test(self): return self.parents def test2(self): return sum(z <0 for z in self.parents) N, M = map(int, input().split()) # N人、M個の関係 uf = UnionFind(N) for _ in range(M): A, B = map(int, input().split()) A -= 1 B -= 1 uf.union(A, B) print(uf.test2()-1)
1
2,314,951,178,980
null
70
70
d,t,s=map(int,input().split()) print("Yes" if t>=d/s else "No")
d,t,s = [int(x) for x in input().split()] if d/s <= t: print("Yes") else: print("No")
1
3,551,483,556,972
null
81
81
n = int(input()) A = list(map(int, input().split())) a=0 result=0 for i in range(n-1): if A[i] > A[i+1]: a = A[i] - A[i+1] A[i+1] += a result += a print(result)
n = input() list_height = list(map(int, input().split())) pre = 0 max_chair = 0 list_chair = list() for i in list_height: if i < pre: max_chair = pre - i pre = i + max_chair list_chair.append(max_chair) else: pre = i print(sum(list_chair))
1
4,602,065,561,828
null
88
88
h, w = [int(i) for i in input().split()] if h == 1 or w == 1: print(1) exit(0) s = h * w if s % 2 == 0: print(s // 2) exit(0) print(s // 2 + 1)
INF=10**30 H,N=map(int,input().split()) A,B=[],[] for i in range(N): a,b=map(int,input().split()) A.append(a);B.append(b) dp=[INF]*(H+10) dp[0]=0 for i in range(N): for j in range(H+1): if(j<A[i]): dp[j]=min(dp[j],dp[0]+B[i]) else: dp[j]=min(dp[j],dp[j-A[i]]+B[i]) print(dp[H])
0
null
65,850,514,572,856
196
229
import sys N = int(input()) p = list(map(int, input().split())) for i in range(N): if p[i] == 0: print(0) sys.exit() product = 1 for i in range(N): product = product * p[i] if product > 10 ** 18: print(-1) sys.exit() break print(product)
N = int(input()) arr = list(map(int, input().split())) result = 1 if 0 in arr: result = 0 else: for i in arr: result *= i if result > 10**18: result = -1 break print(result)
1
16,018,013,543,390
null
134
134
n, k = map(int,input().split()) if n == 1: print(1) else: a=1 ans = 0 while a<=n: a *=k ans += 1 print(ans)
n = int(input()) cnt = 0 for a in range(1, n): cnt += ~-n//a print(cnt)
0
null
33,535,758,737,130
212
73
import sys,math,copy,queue,itertools,bisect LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() data = [[a,i] for i,a in enumerate(LI())] data.sort(reverse=True) dp = [[0 for _ in range(N+1)] for _ in range(N+1)] for i in range(N): a, p = data[i] for j in range(i+1): dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + abs(N-1-j-p)*a) dp[i+1][j] = max(dp[i+1][j], dp[i][j] + abs(i-j-p)*a) print(max(dp[-1]))
n = int(input()) lis = list(map(int, input().split())) ans = 0 for i in range(0, n-1): for t in range(i+1, n): con = lis[i] * lis[t] ans += con print(ans)
0
null
101,111,663,591,778
171
292
N = int(input()) res = 0 for j in range(1, N+1): div_num = N//j res += (div_num +1) * div_num * j // 2 print(res)
# Problem D - Sum of Divisors # input N = int(input()) # initialization count = 0 # count for j in range(1, N+1): M = N // j count += j * ((M * (M+1)) // 2) # output print(count)
1
11,024,351,917,670
null
118
118
s = input() for _ in range(int(input())): c = input().split() a = int(c[1]) b = int(c[2]) if c[0] == "replace": s = s[:a] + c[3] + s[b+1:] elif c[0] == "reverse": s = s[:a] + s[a:b+1][::-1] + s[b+1:] else: print(s[a:b+1])
n,k = map(int,input().split()) person = [0]*n for i in range(k): d = int(input()) A = list(map(int,input().split())) for j in range(len(A)): person[A[j]-1] = 1 print(person.count(0))
0
null
13,345,562,463,560
68
154
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) ans = 0 for i in range(1,N+1): if i % 3 == 0 or i % 5 == 0: continue ans += i print(ans)
k = int(input()) s = input() if len(s) <= k: print(s) else: print("{}...".format(s[0:k]))
0
null
27,303,644,683,932
173
143
n, k = map(int, input().split()) R, S, P = map(int, input().split()) t = input() prev = {} ans = 0 for i in range(k): if t[i] == 'r': ans += P prev[i] = 'p' elif t[i] == 's': ans += R prev[i] = 'r' elif t[i] == 'p': ans += S prev[i] = 's' for i in range(k, n): a = i % k if t[i] == 'r': if prev[a] != 'p': ans += P prev[a] = 'p' else: if i + k < n and t[i + k] != 's': prev[a] = 'r' else: prev[a] = 's' elif t[i] == 's': if prev[a] != 'r': ans += R prev[a] = 'r' else: if i + k < n and t[i + k] != 'p': prev[a] = 's' else: prev[a] = 'p' elif t[i] == 'p': if prev[a] != 's': prev[a] = 's' ans += S else: if i + k < n and t[i + k] != 'r': prev[a] = 'p' else: prev[a] = 'r' print(ans)
N, K = [int(x) for x in input().split()] r, s, p = [int(x) for x in input().split()] win_point = { 'r': r, 's': s, 'p': p, } next_hands = { 'r': ['s', 'p'], 's': ['r', 'p'], 'p': ['r', 's'], } enemy_hands = input() def can_win(enemy_hand, my_hands): # 勝てる場合にはTrueと勝てる手を教えてくれる if enemy_hand == 'r' and 'p' in my_hands: return True, 'p' if enemy_hand == 's' and 'r' in my_hands: return True, 'r' if enemy_hand == 'p' and 's' in my_hands: return True, 's' # 勝てる手がない場合 return False, None point = 0 for index in range(K): now_hands = ['r', 'p', 's'] for i in range(index, N, K): win, hand = can_win(enemy_hands[i], now_hands) if win: point += win_point[hand] now_hands = next_hands[hand] else: # 勝てない場合次似邪魔しない手を選ぶ # 勝てない回の次は必ず勝てるため全手出せる前提とする now_hands = ['r', 'p', 's'] print(point)
1
106,859,636,407,040
null
251
251
import sys n,k = map(int, sys.stdin.readline().rstrip("\n").split()) ans = 0 while n != 0: n = n // k ans += 1 print(ans)
from collections import deque N = int(input()) que = deque(['a']) while len(que) > 0: s = que.popleft() if len(s) == N: print(s) else: for i in range(ord(sorted(s)[-1]) - 95): que.append(s + chr(97 + i))
0
null
58,234,856,710,888
212
198
apple = [1, 2, 3] apple.remove(int(input())) apple.remove(int(input())) print(apple[0])
A = int(input()) B = int(input()) AB = [A,B] Ans = [x for x in range(1,4) if x not in AB] print(Ans[0])
1
110,312,518,834,782
null
254
254
n = int(input()) mod = 10**18 li = list(map(int, input().split())) li.sort() ans = 1 for i in range(n): ans *= li[i] if ans > mod: ans = -1 break print(ans)
N = int(input()) A = list(map(int, input().split())) X = 10**18 ans = 1 if 0 in A: ans = 0 else: for i in range(N): ans = ans * A[i] if ans > X: ans = -1 break print(ans)
1
16,264,274,344,952
null
134
134
import math r=float(input()) print('%f %f' %(math.pi*r*r, 2*math.pi*r))
import sys from collections import Counter c = Counter() for line in sys.stdin.readlines(): c.update(line.lower()) for a in 'abcdefghijklmnopqrstuvwxyz': print a + ' :', c.get(a, 0)
0
null
1,162,851,187,930
46
63
x = int(input()) print(x * x * x)
card_dk = int(input()) block = ['S','H','C','D'] no = [1,2,3,4,5,6,7,8,9,10,11,12,13] card_st =[] not_card =[] for i in range(card_dk): card = input().split() card[1] = int(card[1]) card_st.append(card) for ch_block in block: for ch_no in no: flag = 0 for card in card_st: if card == [ch_block,ch_no]: flag = 1 if flag == 0: card = [ch_block,ch_no] not_card.append(card) for fud_card in not_card: print('{} {}'.format(fud_card[0],fud_card[1]))
0
null
644,124,389,768
35
54
import math a=int(input()) b=100000 for i in range(a): b=b*1.05 b=b/1000 b=math.ceil(b) b=b*1000 print(b)
n = int(input()) xy = [list(map(int,input().split())) for i in range(n)] cheby = [] for i in range(n): l = [xy[i][0]-xy[i][1],xy[i][0]+xy[i][1]] cheby.append(l) xmax = -10**10 xmin = 10**10 ymax = -10**10 ymin = 10**10 for i in range(n): if cheby[i][0] > xmax : xmax = cheby[i][0] xa = i if cheby[i][0] < xmin : xmin = cheby[i][0] xi = i if cheby[i][1] > ymax : ymax = cheby[i][1] ya = i if cheby[i][1] < ymin : ymin = cheby[i][1] yi = i if abs(xmax-xmin) > abs(ymax-ymin): print(abs(xy[xa][0]-xy[xi][0])+abs(xy[xa][1]-xy[xi][1])) else : print(abs(xy[ya][0]-xy[yi][0])+abs(xy[ya][1]-xy[yi][1]))
0
null
1,716,174,485,834
6
80
#!/usr/bin/env python3 import sys # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import gcd # for Python 3.4 (previous contest @AtCoder) def main(): mod = 998244353 # 10^9+7 inf = float('inf') # sys.float_info.max = 1.79...e+308 # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) # def my_update(seq, L): # n = len(seq) # for i in range(n-1): # seq[i+1] += L[i] # n, s = mi() # L = lmi() # dp = [[0] * (n + 1) for j in range(s + 1)] # chain の長さ、場合のかず # # print(dp) # for i in range(n): # for j in range(s, -1, -1): # if j == 0 and L[i] <= s: # dp[L[i]][1] += 1 # elif j + L[i] <= s and dp[j]: # my_update(dp[j + L[i]], dp[j]) # counter # # print(dp) # ans = 0 # for chain_len, num in enumerate(dp[s]): # ans = (ans + pow(2, n - chain_len, mod) * num) % mod # print(ans) # write-up solution """ Ai それぞれ選ぶ or 選ばないと選択して行った時、足して S にできる組み合わせは何パターンできるか? -> まさに二項定理の発想 fi = 1+x^Ai として T = {1, 2, 3} に対する答えは [x^S]f1*f2*f3 T = {1, 2} に対する答えは [x^S]f1*f2 のように計算していく 全パターン f1*f2*f3 + f1*f2 + f1*f3 + f2*f3 + f1 + f2 + f3 の [x^S] の値が答え -> (1+f1)*...*(1+fi)*...*(1+fn) の x^S の係数と一致 [x^S] Π{i=1...n} (2 + x^Ai) を計算せよ、という問である """ n, s = mi() A = lmi() power_memo = [0] * (s + 1) power_memo[0] = 2 if A[0] <= s: power_memo[A[0]] = 1 for i in range(1, n): # print(power_memo) for j in range(s, -1, -1): tmp = (power_memo[j] * 2) % mod if j - A[i] >= 0 and power_memo[j - A[i]]: tmp += power_memo[j - A[i]] power_memo[j] = tmp % mod # print(power_memo) print(power_memo[s]) if __name__ == "__main__": main()
d,t,s = map(int,input().split()) print("Yes" if d <= t*s else "No")
0
null
10,607,169,770,418
138
81
i = list(map(int, input().split())) N = i[0] R = i[1] if N <= 10: print(R + (100*(10 - N))) else: print(R)
n = int(input()) furui = [i for i in range(10**6+2)] ans = 9999999999999 yakusuu = [] for i in range(1,int(n**0.5)+1+1): if n%i == 0: yakusuu.append(i) for i in yakusuu: ans = min(i+n//i,ans) # print(i,ans) print(ans-2)
0
null
112,368,502,253,828
211
288
health, attack = map(int, input().split()) damage = list(map(int, input().split())) if health <= sum(damage): print('Yes') else: print('No')
import math a,b,c,d = map(int,input().split()) def death_time(hp,atack): if hp%atack == 0: return hp/atack else: return hp//atack + 1 takahashi_death = death_time(a,d) aoki_death = death_time(c,b) if aoki_death<=takahashi_death: print("Yes") else: print("No")
0
null
54,126,228,449,078
226
164