code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
N, K = map(int, input().split()) moves = [0] + list(map(int, input().split())) points = [0] + list(map(int, input().split())) INF = 10**10 answer = -INF for start in range(1, N+1): circle = [start] next = moves[start] c_score = points[start] while(next != start): circle.append(next) c_score += points[next] next = moves[next] m_score = 0 for i in range(min(len(circle), K)): m_score += points[circle[i]] loop_cnt = (K-i-1)//len(circle) answer = max(answer, m_score + max(0, loop_cnt * c_score)) print(answer)
import sys import resource sys.setrecursionlimit(10000) n,k=map(int,input().rstrip().split()) p=list(map(int,input().rstrip().split())) c=list(map(int,input().rstrip().split())) def find(start,now,up,max,sum,count,flag): if start==now: flag+=1 if start==now and flag==2: return [max,sum,count] elif count==up: return [max,sum,count] else: count+=1 sum+=c[p[now-1]-1] if max<sum: max=sum return find(start,p[now-1],up,max,sum,count,flag) kara=[-10000000000] for i in range(1,n+1): m=find(i,i,n,c[p[i-1]-1],0,0,0) if m[2]>=k: m=find(i,i,k,c[p[i-1]-1],0,0,0) if m[0]>kara[0]: kara[0]=m[0] result=kara[0] elif m[1]<=0: if m[0]>kara[0]: kara[0]=m[0] result=kara[0] else: w=k%m[2] if w==0: w=m[2] spe=find(i,i,w,c[p[i-1]-1],0,0,0)[0] if m[1]+spe>m[0] and m[1]*(k-w)//m[2]+spe>kara[0]: kara[0]=m[1]*(k-w)//m[2]+spe elif m[1]+spe<=m[0] and m[1]*((k-w)//m[2]-1)+m[0]>kara[0]: kara[0]=m[1]*((k-w)//m[2]-1)+m[0] result=kara[0] print(result)
1
5,381,241,488,180
null
93
93
N=int(input()) A=list(map(int,input().split())) ans=1 if A.count(0)>0: ans=0 for i in range(N): ans*=A[i] if ans>10**18: ans=-1 break print(ans)
input() a=1 d=1000000000000000000 for i in input().split(): a*=[int(i),1][(a>d)*(i!='0')] print([a,-1][a>d])
1
16,130,152,539,680
null
134
134
k=int(input()) s=list(input()) if len(s)<=k: print("".join(s)) else: s_short="" for i in range(k): s_short+=s[i] print((s_short+"..."))
def main(): k = int(input()) s = input() if len(s) > k: print(s[:k]+"...") else: print(s) if __name__ == '__main__': main()
1
19,727,358,950,780
null
143
143
n=int(input()) a=list(map(int,input().split())) cnt=0 if 1 not in a: print(-1) exit() else: num=1 for i in range(n): if a[i]==num: num+=1 else: cnt+=1 print(cnt)
import sys readline = sys.stdin.buffer.readline a,b,c,k =list(map(int,readline().rstrip().split())) if k <= a: print(k) elif k > a and k <= a + b: print(a) else: print(a -(k-(a+b)))
0
null
68,204,266,754,848
257
148
n = int(input()) p = [int(x) for x in input().split()] q = [int(x) for x in input().split()] pos = [None, None] def fn(digits, maxlen, index, pos): for x in range(1, maxlen + 1): if x in digits: continue ndigits = digits + [x] if len(ndigits) < maxlen: index = fn(digits + [x], maxlen, index, pos) else: if ndigits == p: pos[0] = index if ndigits == q: pos[1] = index index = index + 1 # print(f"{index}:" + " ".join(str(x) for x in ndigits)) return index fn([], n, 0, pos) print(abs(pos[0] - pos[1]))
from collections import defaultdict it = lambda: list(map(int, input().strip().split())) def solve(): N, X, M = it() if N == 1: return X % M cur = 0 cnt = 0 value = defaultdict(int) history = defaultdict(int) for i in range(N): if X in history: break value[X] = cur history[X] = i cnt += 1 cur += X X = X * X % M loop = cur - value[X] period = i - history[X] freq, rem = divmod(N - cnt, period) cur += freq * loop for i in range(rem): cur += X X = X * X % M return cur if __name__ == '__main__': print(solve())
0
null
51,835,651,711,292
246
75
X, Y, A, B, C = map(int, input().split()) Ps = list(map(int, input().split())) Qs = list(map(int, input().split())) Rs = list(map(int, input().split())) Ps.sort(reverse=True) Qs.sort(reverse=True) Al = Ps[:X] + Qs[:Y] +Rs Al.sort(reverse=True) print(sum(Al[:X+Y]))
x,y,a,b,c = map(int,input().split()) R=list(map(int,input().split()) ) G=list(map(int,input().split()) ) W=list(map(int,input().split()) ) R.sort(reverse=True) G.sort(reverse=True) Z = W+R[0:x] + G[0:y] Z.sort(reverse=True) print(sum(Z[0:x+y]))
1
44,968,545,083,072
null
188
188
n = int(input()) A = list(map(int, input().split())) cnt = 0 money = 1000 b = 0 for i in range(n-1): if cnt == 0 and A[i] < A[i+1]: cnt += money//A[i] money %= A[i] b = A[i] else: money += cnt * A[i] cnt = 0 if A[i] < A[i+1]: cnt += money//A[i] money %= A[i] b = A[i] if cnt > 0: money += cnt * max(b, A[-1]) print(money)
import re import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def v(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 6) mod = 10**9+7 cnt = 0 ans = 0 inf = float("inf") al = "abcdefghijklmnopqrstuvwxyz" AL = al.upper() n = k() a = l() sum = 1000 for i in range(n-1): if a[i] > a[i+1]: xx = a[cnt:i+1] b = sum//min(xx) sum += (max(xx)-min(xx))*b cnt = i+1 xx = a[cnt:] b = sum//min(xx) sum += (max(xx)-min(xx))*b print(sum)
1
7,398,847,945,060
null
103
103
from bisect import bisect N = int(input()) S = [input() for _ in range(N)] def count(s): n = len(s) n1 = 0 n2 = 0 for i in range(n): if s[i]=='(': n2 += 1 else: if n2 > 0: n2 -= 1 else: n1 += 1 return n1,n2 l1 = [] l2 = [] m1 = 0 m2 = 0 for i in range(N): n1,n2 = count(S[i]) if n1+n2==0: continue if n1 == 0: m1 += n2 continue if n2 == 0: m2 += n1 continue if n2-n1>=0: l1.append([n1,n2]) else: l2.append([n1,n2]) ans = 'Yes' l1.sort() for i in range(len(l1)): n1,n2 = l1[i] if m1 < n1: ans = 'No' break m1 += n2-n1 l2.sort(key=lambda x:x[1]) for i in range(len(l2)): n1,n2 = l2[i] if m2 < n2: ans = 'No' break m2 += n1-n2 if m1!=m2: ans = 'No' print(ans)
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) INF = float("inf") import bisect def count(s): a = 0 aa = 0 b = 0 bb = 0 for i in range(len(s)): if s[i] == ")": if aa == 0: a = a + 1 else: aa = aa - 1 if s[i] == "(": aa = aa + 1 if s[len(s)-1-i] == "(": if bb == 0: b = b + 1 else: bb = bb - 1 if s[len(s)-1-i] == ")": bb = bb + 1 return [a, b] N = int(input()) c = [] d = [] for i in range(N): s = input() e = count(s) if e[1] - e[0] >= 0: c.append(e) if e[0] - e[1] > 0: d.append(e) c.sort(key=lambda x: x[0]) d.sort(key=lambda x: x[1], reverse=True) c = c + d # print(c) f = 0 for cc in c: f = f - cc[0] if f < 0: print("No") sys.exit() f = f + cc[1] if f == 0: print("Yes") else: print("No")
1
23,606,594,095,308
null
152
152
N, S = map(int,input().split()) A = [int(s) for s in input().split()] DP = [[0 for j in range(S + 1)] for i in range(N + 1)] mod = 998244353 DP[0][0] = 1 for i in range(N): for j in range(S + 1): DP[i + 1][j] += 2 * DP[i][j] DP[i + 1][j] %= mod if j + A[i] <= S: DP[i + 1][j + A[i]] += DP[i][j] DP[i + 1][j + A[i]] %= mod print(DP[N][S])
n,s=map(int,input().split()) a=list(map(int,input().split())) #dp[n][s] #nこめまで選んだ時の和がsの組 dp=[[0]*(s+1) for _ in range(n)] a.sort() #for i in range(s+1): # dp[0][i]=2 if a[0]>s: print(0) exit() mod=998244353 dp[0][0]=2 dp[0][a[0]]+=1 for i in range(1,n): for j in range(s+1): #i番目を入れて選択するパターン dp[i][j]=dp[i-1][j]*2%mod if j>=a[i]: dp[i][j]+=dp[i-1][j-a[i]]%mod print(dp[-1][s]%mod)
1
17,733,111,656,360
null
138
138
n = int(input()) #a, b = map(int, input().split()) #l = list(map(int, input().split())) s = input() ans = 1 last = s[0] for i in range(1,n): if last != s[i]: last = s[i] ans = ans + 1 print(ans)
N=int(input()) S=input() while True: x='' ans='' for i in S: if (x==''): x=i continue if x!=i: #print("p:",x,i,ans) ans+=x x=i #print("a:",x,i,ans) ans+=x #print('ans:',ans) if ans==S: break else: S=ans print(len(ans))
1
169,428,848,041,142
null
293
293
class My_Queue: def __init__(self, S): self.S = S self.q = [0 for i in range(S)] self.head = 0 self.tail = 0 def enqueue(self, x): if self.isFull(): print('overflow') raise else: self.q[self.tail] = x if self.tail + 1 == self.S: self.tail = 0 else: self.tail += 1 def dequeue(self): if self.isEmpty(): print('underflow') raise else: x = self.q[self.head] self.q[self.head] = 0 if self.head + 1 == self.S: self.head = 0 else: self.head += 1 return x def isEmpty(self): return self.head == self.tail def isFull(self): return self.head == (self.tail + 1) % self.S def main(): n, qms = map(int, input().split()) elapsed_time = 0 q = My_Queue(n + 1) for i in range(n): name, time = input().split() time = int(time) q.enqueue([name, time]) while(q.head != q.tail): a = q.dequeue() if a[1] <= qms: elapsed_time += a[1] print(a[0], elapsed_time) else: a[1] -= qms elapsed_time += qms q.enqueue(a) if __name__ == "__main__": main()
a = int(input("")) print(int(a*a))
0
null
72,978,269,907,550
19
278
import math def shell(l): N = len(l) cnt = 0 m = int(math.log(2 * N + 1, 3)) G = [(3 ** i - 1) // 2 for i in range(m, 0, -1)] for i in range(m): l, cnt = insert(l, G[i], cnt) return l, m, G, cnt def insert(l, g, cnt): N = len(l) for i in range(g, N): v = l[i] j = i - g while j >= 0 and l[j] > v: l[j + g] = l[j] j -= g cnt += 1 l[j + g] = v return l, cnt def output(l): count = 0 leng = len(l) for i in l: count += 1 if count < leng: print(i, end =' ') else: print(i) if __name__ == '__main__': n = int(input()) lists = list() for i in range(n): lists.append(int(input())) lists, m, g, cnt = shell(lists) print(m) output(g) print(cnt) for i in lists: print(i)
import math s, t = input().split(" ") print(t + s)
0
null
51,714,298,091,050
17
248
N = int(input()) print(int(N / 2)) if N % 2 == 0 else print(N // 2 + 1)
def main(): log_no, cut_max = [int(x) for x in input().split()] logs = [int(x) for x in input().split()] bin_l, bin_r = 0, 10 ** 9 while bin_r - bin_l > 1: bin_mid = (bin_l + bin_r) // 2 cut_count = sum((log - 1) // bin_mid for log in logs) if cut_count <= cut_max: bin_r = bin_mid else: bin_l = bin_mid print(bin_r) if __name__ == '__main__': main()
0
null
32,797,152,444,480
206
99
# -*- coding:utf-8 -*- x = int(input()) if x == False: print("1") else: print("0")
mod = 10**9 + 7 def C(): N = int(input()) ans = 10**N - 2*9**N + 8**N print(ans%mod) def A(): N = int(input()) if( N == 0): print(1) else: print(0) A()
1
2,910,384,346,888
null
76
76
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, M = map(int, readline().split()) if N == M: print('Yes') else: print('No') return if __name__ == '__main__': main()
x,y,z = map(int,input().split()) temp = x x = y y = temp temp = x x = z z = temp print(x,y,z)
0
null
60,704,733,271,048
231
178
a,b = map(int,input().split()) k = str(a) l = str(b) X = k*b Y = l*a if (X < Y): print(X) else: print(Y)
A, B = map(str, input().split()) A_ans='' B_ans='' if min(A,B) == A: for a in range(int(B)): A_ans += A print(A_ans) else: for b in range(int(A)): B_ans += B print(B_ans)
1
84,597,919,470,680
null
232
232
while True: N=input() if N=="0": break else: print(sum([int(x) for x in list(N)]))
while True: x = input() if x == '0': quit() print(sum([int(_) for _ in x]))
1
1,584,724,872,828
null
62
62
A, B, C, K = map(int, input().split()) if K<=A: print(1*K) elif A<K<=A+B: print(1*A) else: print(1*A-1*(K-A-B))
X, Y = map(int, input().split(" ")) print(100000 * max(4 - X, 0) + 100000 * max(4 - Y, 0) + (400000 if X == 1 and Y == 1 else 0))
0
null
81,209,173,180,068
148
275
import sys input = sys.stdin.readline import numpy as np def main(): n, k = map(int, input().split()) A = np.array(sorted(list(map(int, input().split())))) F = np.array(sorted(list(map(int, input().split())), reverse=True)) def is_time(x): c = np.maximum(A - x//F, 0).sum() if c <= k: return True return False ng = -1 ok = max(A*F) while ok - ng > 1: m = (ng + ok)//2 if is_time(m): ok = m else: ng = m print(ok) if __name__ == "__main__": main()
deta_set_count = int(input()) for _ in range(deta_set_count): k = list(map(int, input().split())) k= sorted(k) if k[0]**2 + k[1]**2 == k[2]**2: print('YES') else: print('NO')
0
null
82,745,238,809,594
290
4
N, P = map(int, input().split()) S = input() if P == 2 or P == 5: cnt = 0 cnt_a = 0 for s in S[::-1]: if int(s) % P == 0: cnt_a += 1 cnt += cnt_a else: r_lst = [0] * P r_lst[0] = 1 cnt = 0 num = 0 for i, s in enumerate(S[::-1]): num = (num + int(s) * pow(10, i, P)) % P cnt += r_lst[num] r_lst[num] += 1 print(cnt)
N, P = map(int, input().split()) S = input() now = 0 hyou = [0] * P hyou[0] = 1 cnt = 1 ans = 0 if P == 2 or P == 5: for i, t in enumerate(S[::-1]): temp = int(t) if temp % P == 0: ans += N - i print(ans) exit() for i, t in enumerate(S[::-1]): now = (now + int(t) * pow(10, i, P)) % P ans += hyou[now] hyou[now] += 1 print(ans)
1
58,067,514,342,630
null
205
205
def rle(t): tmp2, count_, ans_ = t[0], 1, [] for i_ in range(1, len(t)): if tmp2 == t[i_]: count_ += 1 else: ans_.append([tmp2, count_]) tmp2 = t[i_] count_ = 1 ans_.append([tmp2, count_]) return ans_ S = list(input()) l = rle(S) ans = [0] * (len(S) + 1) count = 0 for i in range(len(l)): if l[i][0] == '<': for j in range(l[i][1] + 1): ans[count + j] = max(ans[count + j], j) elif l[i][0] == '>': for k in range(l[i][1] + 1): ans[count + k] = max(ans[count + k], l[i][1] - k) count += l[i][1] print(sum(ans))
n = int(raw_input()) num = map(int, raw_input().split()) num.reverse() print " ".join(map(str, num))
0
null
78,627,918,051,060
285
53
N=int(input()) count=0 for i in range(1,N): for j in range(1,(N-1)//i+1): count+=1 print(count)
primeornot=[True]*(10**5*2) for i in range(2,10**5): if primeornot[i]==True: j=2*i while j<10**5*2: primeornot[j]=False j+=i x=int(input()) for i in range(x,10**5*2): if primeornot[i]==True: print(i) break
0
null
54,363,302,472,930
73
250
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read sys.setrecursionlimit(10 ** 7) from heapq import heappop, heappush #from collections import defaultdict # import math # from itertools import product, accumulate, combinations, product # import bisect# lower_bound etc #import numpy as np # from copy import deepcopy #from collections import deque #import numba def run(): H, N = map(int, sysread().split()) AB = list(map(int, read().split())) A = AB[::2] B = AB[1::2] Amax = max(A) INF = float('inf') dp = [[INF] * (H+Amax+1) for _ in range(N+1)] dp[0][0] = 0 for i in range(N): for j in range(H+Amax+1): tmp = j - A[i] if tmp >= 0: dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]]) elif j == H and tmp < 0: dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i]) else: dp[i+1][j] = dp[i][j] ret = min(dp[N][H:]) print(ret) if __name__ == "__main__": run()
x,y=map(int,input().split()) a=x*(x-1)//2 b=y*(y-1)//2 print(a+b)
0
null
63,179,098,788,220
229
189
# coding=utf-8 inputs = raw_input().rstrip().split() W, H, x, y, r = [int(x) for x in inputs] if 0 <= x - r and x + r <= W and 0 <= y - r and y + r <= H: print 'Yes' else: print 'No'
W,H,x,y,r = list(map(int,input().split())) if( (W - r >= x >= 0 + r) and (H - r >= y >= 0 + r)): print("Yes") else: print("No")
1
455,526,956,078
null
41
41
N = int(input()) A = list(map(int,input().split())) S = sum(A) T = 0 ans = float("inf") for e in A: T += e ans = min(ans,abs(T-(S-T))) print(ans)
import numpy as np import numba from numba import njit, b1, i4, i8, f8 @njit((i8, i8, i8, i8[:,:]), cache=True) def solve(R,C,K,item): dp = np.zeros((C+1,5), dtype=np.int64) for i in range(1,R+1): new_dp = np.zeros((C+1,5), dtype=np.int64) #上からアイテムを取らずに移動 new_dp[:,0] = dp[:,-1] #上からアイテムを取って移動 new_dp[1:,1] = np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1]) for j in range(1,C+1): #横からアイテムを取らずに移動 new_dp[j] = np.maximum(new_dp[j],new_dp[j-1]) #横からアイテムを取って移動 for k in range(1,4): new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1]) for k in range(4): new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k]) dp = new_dp ans = dp[-1,-1] return ans R, C, K = map(int, input().split()) item = np.zeros((R,C), dtype=np.int64) for i in range(K): r,c,v = map(int, input().split()) item[r-1,c-1] = v print(solve(R,C,K,item))
0
null
73,522,881,492,918
276
94
class Queue: queue_list = [] start = 0 def enqueue(self, a): self.queue_list.append(a) def dequeue(self): assert self.start != len(self.queue_list), "オーバーフローが発生しました。" self.start += 1 return self.queue_list[self.start - 1] def isEmpty(self): return self.start == len(self.queue_list) n, q = list(map(lambda x: int(x), input().strip().split())) queue = Queue() for i in range(n): queue.enqueue(input().strip().split()) sum_time = 0 while not queue.isEmpty(): name, time = queue.dequeue() if int(time) <= q: sum_time += int(time) print(name + ' ' + str(sum_time)) else: queue.enqueue([name, str(int(time) - q)]) sum_time += q
n, q = map(int, input().split(' ')) p = [] time = 0 counter = 0 for i in range(n): tmp_n, tmp_p = input().split(' ') tmp_p = int(tmp_p) p.append((tmp_n, tmp_p)) while len(p) > 0: task = p.pop(0) tmp_p = task[1] - q if( tmp_p > 0): time += q p.append((task[0], tmp_p)) elif( tmp_p <= 0): time += task[1] print('{} {}'.format(task[0], time))
1
42,566,045,918
null
19
19
N, M = map(int, input().split(' ')) rst_ls = [ '' for i in range(N) ] rst = '' if M == 0: if N == 1: print(0) else: rst = '1' + '0' * (N - 1) print(rst) else: is_end = False for i in range(M): ls = list(input().split(' ')) idx = int(ls[0]) - 1 if idx == 0 and ls[1] == '0' and N > 1: is_end = True print(-1) break elif rst_ls[idx] == '': rst_ls[idx] = ls[1] elif rst_ls[idx] != ls[1]: is_end = True print(-1) break if not is_end: if rst_ls[0] == '' and N > 1: rst_ls[0] = 1 for i in rst_ls: if i == '': i = 0 print(i, end='')
l=map(str,raw_input().split()) chk=[] op='-+*' while len(l): k=l.pop(0) if k in op: b=chk.pop() a=chk.pop() chk.append(str(eval(a+k+b))) else: chk.append(k) print chk[0]
0
null
30,500,358,426,240
208
18
x=input().split() a,b =int(x[0]),int(x[1]) if a<b: print("a < b") if a==b: print("a == b") if a>b: print("a > b")
# Aizu Problem ITP_1_2_A: Small, Large or Equal # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") a, b = [int(_) for _ in input().split()] if a < b: print("a < b") elif a > b: print("a > b") else: print("a == b")
1
361,387,392,178
null
38
38
a = int(input()) b = 'Yes' if a > 29 else 'No' print(b)
T=input() list=[] for j in range(len(T)): if T[j]=="?": list.append(j) tt=[] for TT in range(len(T)): tt.append(T[TT]) for i in list: tt[i]="D" answer="" for p in range(len(T)): answer+=tt[p] print(answer)
0
null
12,058,535,714,212
95
140
# Begin Header {{{ from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations, combinations_with_replacement # }}} End Header # _________コーディングはここから!!___________ n = int(input()) l = list(map(int, input().split())) l.sort() ans = 0 for x in combinations(l, 3): if x[0]!=x[1] and x[0]!=x[2] and x[1]!=x[2]: if x[0] + x[1] > x[2]: ans+=1 print(ans)
N=int(input()) L = list(map(int,input().split())) ans = 0 if N<=2: print(0) exit() for i1 in range(N-2): l1 = L[i1] for i2 in range(i1+1,N-1): l2 = L[i2] for i3 in range(i2+1,N): l3 = L[i3] if l1==l2 or l2==l3 or l3==l1: continue tmp = sorted([l1,l2,l3]) if tmp[0]+tmp[1]>tmp[2]: ans += 1 print(ans)
1
5,037,049,216,892
null
91
91
import sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = LI() from itertools import accumulate for _ in range(min(K,41)): B = [0]*(N+1) for i in range(N): a = A[i] B[max(i-a,0)] += 1 B[min(N,i+a+1)] -= 1 C = list(accumulate(B)) A = C print(*[A[i] for i in range(N)])
def main(): n,m = map(int,input().split()) if n == m: print('Yes') else: print('No') main()
0
null
49,412,056,198,998
132
231
# -*- coding: utf-8 -*- S1 = 1 r = input() R = int(r) S2 = R ** 2 result = S2 / S1 print(int(result))
s = int(input()) print(s**2)
1
144,507,589,125,558
null
278
278
S = input() mx = 0 c = 0 for si in S: if si == 'R': c += 1 mx = max(mx, c) else: c = 0 print(mx)
S = input() if S == "RRR": print(3) elif S == "SSS": print(0) elif S == "RRS" or S == "SRR": print(2) else: print(1)
1
4,933,337,633,962
null
90
90
a, b = list(map(int, input().split(' '))) print('Yes' if a * 500 >= b else 'No')
import math x = int(input()) ans = 0 y = 100 while y < x: y += y//100 ans += 1 print(ans)
0
null
62,233,401,347,172
244
159
N, K, C = map(int, input().split()) S = input() L = [] R = [] count_L = C count_R = C for i in range(N): if S[i] == "o" and count_L >= C: count_L = 0 L.append(i) else: count_L += 1 if S[N-i-1] == "o" and count_R >= C: count_R = 0 R.append(N-i-1) else: count_R += 1 if len(L) >= K and len(R) >= K: break for l, r in zip(L, R[::-1]): if l == r: print(l+1)
from heapq import heappush, heappop from bisect import bisect_left, bisect_right from collections import deque, defaultdict from itertools import combinations, permutations, combinations_with_replacement from itertools import accumulate from math import ceil, sqrt, pi MOD = 10 ** 9 + 7 INF = 10 ** 18 N, K, C = map(int, input().split()) S = input() left = [0] * N right = [0] * N i = 0 cnt = 0 while i < N: if cnt == K: break if S[i] == "o": cnt += 1 left[i] = 1 i += C + 1 else: i += 1 #print(left) S = S[::-1] i = 0 cnt = 0 while i < N: if cnt == K: break if S[i] == "o": cnt += 1 right[i] = 1 i += C + 1 else: i += 1 right = right[::-1] #print(right) left_ls, right_ls = [], [] for i in range(N): if left[i]: left_ls.append(i + 1) if right[i]: right_ls.append(i + 1) for l, r in zip(left_ls, right_ls): if l == r: print(l)
1
40,728,807,867,128
null
182
182
def main(): X = int(input()) if X < 100: print(0) elif 2000 <= X: print(1) else: a = X // 100 b = a * 5 if X % 100 <= b: print(1) else: print(0) if __name__ == '__main__': main()
X=int(input()) han=0 for a in range(1001): if a * 100 > X: break for b in range(1001-a): if a * 100 + b * 101 > X: break for c in range(1001-a-b): if a * 100 + b * 101 + c * 102 > X: break for d in range(1001-a-b-c): if a * 100 + b * 101 + c * 102 + 103 * d> X: break for e in range(1001-a-b-c-d): if a * 100 + b * 101 + c * 102 + 103 * d + 104 * e>X: break for f in range(1001-a-b-c-d-e): if a * 100 + b * 101 + c * 102 + 103 * d + 104 * e + 105 * f>X: break if a*100+b*101+c*102+103*d+104*e+105*f==X: print("1") han=1 exit() if han==0: print(0)
1
126,875,518,581,770
null
266
266
n=int(input()) nyukyo=[list(map(int, input().split())) for i in range(n)] bld=[[[0 for i in range(10)] for j in range(3)] for k in range(4)] for ny in nyukyo: bld[ny[0]-1][ny[1]-1][ny[2]-1]+=ny[3] for i,b in enumerate(bld): for f in b: print("",*f) if i != 3: print("####################")
N = int(input()) GACHA=set() for n in range(N): GACHA.add(input()) print(len(GACHA))
0
null
15,747,855,455,090
55
165
Row = int(input()) List = [] for i in range (Row): List.append(input()) s_l = set(List) print(len(s_l))
n=int(input()) ls=[] for i in range(n): s=input() ls.append(s) setl=set(ls) print(len(setl))
1
30,439,686,587,168
null
165
165
n,k = input().split() k = int(k) #print(n,k) p = [int(s) for s in input().split()] p.sort() #print(p) #print(k) p2 = p[0:k] #print(p2) s = sum(p) #print(s) print(sum(p2))
n = int(input()) m = n primes = {} for i in range(2, int(n**0.5+2)): while m % i == 0: m //= i if i not in primes: primes[i] = 1 else: primes[i] += 1 if i > m: break if m != 1: primes[m] = 1 cnt = 0 num = 0 flag = True while flag == True: num += 1 flag = False for i in primes: if 0 < primes[i] <= num*2: cnt += 1 primes[i] = 0 elif primes[i] > num*2: cnt += 1 flag = True primes[i] -= num print(cnt)
0
null
14,281,180,730,268
120
136
def bingo(): # 初期処理 A = list() b = list() comb_list = list() is_bingo = False # 入力 for _ in range(3): dummy = list(map(int, input().split())) A.append(dummy) N = int(input()) for _ in range(N): dummy = int(input()) b.append(dummy) # ビンゴになる組み合わせ for i in range(3): # 横 comb_list.append([A[i][0], A[i][1], A[i][2]]) # 縦 comb_list.append([A[0][i], A[1][i], A[2][i]]) # 斜め comb_list.append([A[0][0], A[1][1], A[2][2]]) comb_list.append([A[0][2], A[1][1], A[2][0]]) # 集計(出現した数字をnullに置き換え) for i in b: for j in range(8): for k in range(3): if i == comb_list[j][k]: comb_list[j][k] = 'null' # すべてnullのリストの存否 for i in comb_list: for j in i: if 'null' != j: is_bingo = False break else: is_bingo = True # 一組でもbingoがあれば即座に関数を抜ける if is_bingo == True: return 'Yes' # すべてのリストを確認後 if is_bingo == False: return 'No' result = bingo() print(result)
A11, A12, A13 = map(int, input().split()) A21, A22, A23 = map(int, input().split()) A31, A32, A33 = map(int, input().split()) N = int(input()) B = {int(input()) for _ in range(N)} h1 = {A11, A12, A13} h2 = {A21, A22, A23} h3 = {A31, A32, A33} v1 = {A11, A21, A31} v2 = {A12, A22, A32} v3 = {A13, A23, A33} c1 = {A11, A22, A33} c2 = {A13, A22, A31} if len(h1 & B)==3 or len(h2 & B)==3 or len(h3 & B)==3 or len(v1 & B)==3 or len(v2 & B)==3 or len(v3 & B)==3 or len(c1 & B)==3 or len(c2 & B)==3: print("Yes") else: print("No")
1
59,668,546,992,070
null
207
207
A = int(input()) B = int(input()) if A*B==2: print(3) elif A*B==3: print(2) else: print(1)
input = raw_input() s = int(input.split()[0]) l = int(input.split()[1]) ans_1 = s*l ans_2 = 2*(s+l) print str(ans_1)+" "+str(ans_2)
0
null
55,687,523,413,450
254
36
N=int(input()) A=list(map(int,input().split())) A1=set(A) ans="NO" if len(A)==len(A1): ans="YES" print(ans)
input() (*a,) = map(int, input().split()) print(["NO", "YES"][len(a) == len(set(a))])
1
73,898,993,171,902
null
222
222
n = int(input()) s = n*n print(s)
import sys r=int(input()) print(r*r)
1
145,384,105,459,602
null
278
278
import sys input=sys.stdin.readline R,C,k=map(int,input().split()) A=[[0]*C for i in range(R)] for i in range(k): r,c,v=map(int,input().split()) A[r-1][c-1]=v dp0=[[0]*(C+1) for i in range(R+1)] dp1=[[0]*(C+1) for i in range(R+1)] dp2=[[0]*(C+1) for i in range(R+1)] dp3=[[0]*(C+1) for i in range(R+1)] for i in range(1,R+1): for j in range(1,C+1): V=A[i-1][j-1] dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1]) dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1]) dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1]) dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1]) print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))
import sys input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return input().rstrip().decode() def II(): return int(input()) def FI(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode() def main(): r,c,k=MI() G=[[0]*(c+1) for _ in range(r+1)] dp=[[0]*(c+1) for j in range(4)] for _ in range(k): rrr,ccc,v=MI() G[rrr][ccc]=v #print(G) #print(dp) for rr in range(1,r+1): for cc in range(1,c+1): if G[rr][cc]==0: for i in range(4): dp[i][cc]=max(dp[i][cc-1],dp[3][cc]) else: dp[0][cc]=max(dp[3][cc],dp[0][cc-1]) dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1]) dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc]) dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc]) #print(dp) print(dp[-1][-1]) if __name__ == "__main__": main()
1
5,621,408,867,600
null
94
94
S = input() l = [0] * (len(S)+1) r = [0] * (len(S)+1) for i in range(len(S)): if S[i] == '<': l[i+1] = l[i] + 1 for i in range(len(S)-1,-1,-1): if S[i] == '>': r[i] = r[i+1] + 1 print(sum([max(l[i],r[i]) for i in range(len(S)+1)]))
import sys input = sys.stdin.readline from collections import deque class Graph: def __init__(self, n, directed=False, decrement=True, destroy=False, edges=[]): self.n = n self.directed = directed self.decrement = decrement self.destroy = destroy self.edges = [set() for _ in range(self.n)] self.parent = [-1]*self.n self.info = [-1]*self.n for x, y in edges: self.add_edge(x,y) def add_edge(self, x, y): if self.decrement: x -= 1 y -= 1 self.edges[x].add(y) if self.directed == False: self.edges[y].add(x) def add_adjacent_list(self, i, adjacent_list): if self.decrement: self.edges[i] = set(map(lambda x: x - 1, adjacent_list)) else: self.edges[i] = set(adjacent_list) def bfs(self, start=1, goal=-1, time=0, save=False): """ :param start: スタート地点 :param goal: ゴール地点 :param save: True = 前回の探索結果を保持する :return: (ループがあっても)最短距離。存在しなければ -1 """ if self.decrement: start -= 1 goal -= 1 if not save: self.parent = [-1] * self.n p, t = start, time self.parent[p] = -2 next_set = deque([(p, t)]) while next_set: p, t = next_set.popleft() for q in self.edges[p]: if self.parent[q] != -1: continue if q == goal: return t + 1 self.parent[q] = p next_set.append((q, t + 1)) return -1 def connection_counter(self): """ :return: 連結成分の個数。有効グラフではあまり意味がない。 """ cnt = 0 self.parent = [-1] * self.n for start in range(self.n): if self.parent[start] == -1: cnt += 1 self.bfs(start + self.decrement, save=True) return cnt def distance_list(self, start=1, save=False): """ :param start: スタート地点 :return: スタート地点から各点への距離のリスト """ dist = [-1]*self.n if self.decrement: start -= 1 if not save: self.parent = [-1] * self.n p, t = start, 0 self.parent[p] = -2 dist[p] = 0 next_set = deque([(p, t)]) while next_set: p, t = next_set.popleft() for q in self.edges[p]: if self.parent[q] != -1: continue dist[q] = t + 1 self.parent[q] = p next_set.append((q, t + 1)) return dist def path_list(self, start=1): """ :return: スタート地点から最短経路で進んだ時の、各頂点の一個前に訪問する頂点番号 訪問しない場合は -1 を返す """ self.distance_list(start) if self.decrement: start -= 1 return list(p + self.decrement for p in self.parent[1:]) ################################################################################################## N, M = map(int, input().split()) graph = Graph(N, directed=False, decrement=True, destroy=False) for _ in range(M): x, y = map(int, input().split()) graph.add_edge(x, y) res = graph.path_list() if -1 in res: print("No") else: print("Yes") print(*res, sep="\n")
0
null
88,213,937,567,690
285
145
import sys input=sys.stdin.readline def main(): r,c,k=map(int,input().split()) item=[[0]*c for i in range(r)] for i in range(k): R,C,v=map(int,input().split()) item[R-1][C-1]=v dp0=[[-10**10]*c for i in range(r)] dp1 = [[-10 ** 10] * c for i in range(r)] dp2 = [[-10 ** 10] * c for i in range(r)] dp3 = [[-10 ** 10] * c for i in range(r)] if item[0][0]==0: dp0[0][0]=0 else: dp0[0][0]=0 dp1[0][0]=item[0][0] for i in range(r): for j in range(c): if j!=c-1: v=item[i][j+1] if v==0: dp0[i][j+1]=max(dp0[i][j],dp0[i][j+1]) dp1[i][j + 1] = max(dp1[i][j], dp1[i][j + 1]) dp2[i][j + 1] = max(dp2[i][j], dp2[i][j + 1]) dp3[i][j + 1] = max(dp3[i][j], dp3[i][j + 1]) else: dp0[i][j+1]=max(dp0[i][j],dp0[i][j+1]) dp1[i][j+1]=max(dp0[i][j]+v,dp1[i][j],dp1[i][j+1]) dp2[i][j + 1] = max(dp1[i][j] + v, dp2[i][j], dp2[i][j + 1]) dp3[i][j + 1] = max(dp2[i][j] + v, dp3[i][j], dp3[i][j + 1]) if i!=r-1: v=item[i+1][j] if v==0: dp0[i+1][j]=max(dp0[i][j],dp1[i][j],dp2[i][j],dp3[i][j],dp0[i+1][j]) else: dp0[i+1][j]=max(dp0[i][j],dp1[i][j],dp2[i][j],dp3[i][j],dp0[i+1][j]) dp1[i + 1][j] = max(dp0[i][j]+v, dp1[i][j]+v, dp2[i][j]+v, dp3[i][j]+v, dp1[i + 1][j]) ans=max(dp0[r-1][c-1],dp1[r-1][c-1],dp2[r-1][c-1],dp3[r-1][c-1]) print(ans) if __name__=='__main__': main()
N=int(input()) A = list(map(int, input().split())) c=0 for i in range(0,len(A),2): if A[i]%2==1: c+=1 print(c)
0
null
6,648,607,757,132
94
105
import sys N = int(input()) S,T = input().split() if not ( 1 <= N <= 100 ): sys.exit() if not ( len(S) == len(T) and len(S) == N ): sys.exit() if not ( S.islower() and T.islower() ): sys.exit() for I in range(N): print(S[I],end='') print(T[I],end='')
n = int(input()) ans = 0 for i in range(1, n + 1): t = n//i ans += 0.5 * i * t * ( t + 1) print(int(ans))
0
null
61,415,899,940,864
255
118
N = int(input()) if N == 1: print(0) else: print(1)
n=int(input()) num=list(map(int,input().split())) num2=[] for i in num: if i%2==0: num2.append(i) num3=[] for j in num2: if j%3==0 or j%5==0: num3.append(0) elif j%3!=0 or j%5!=0: num3.append(1) a=sum(num3) if a==0: print("APPROVED") elif a!=0: print("DENIED")
0
null
35,927,470,097,110
76
217
cnt = int(input()) string = input() if len(string) <= cnt: print(string) else: print(string[:cnt] + "...")
[a,b,c] = list(map(int,input().split())) if c-a-b<0: print('No') else: left = 4*a*b right = (c-a-b)**2 if left<right: print('Yes') else: print('No')
0
null
35,491,409,058,390
143
197
N = int(input()) X = (N%100)%10 if X == 3: print('bon') elif X == 0 or X == 1 or X == 6 or X == 8: print('pon') else: print('hon')
from itertools import permutations n=int(input()) p=tuple(map(int,input().split())) q=tuple(map(int,input().split())) P=sorted(list(permutations(range(1,n+1),n))) print(abs(P.index(p)-P.index(q)))
0
null
59,737,253,129,778
142
246
import sys,bisect read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): # 区間加算、上書き、一点取得 class SegmentTree: def __init__(self, n, ele, segfun): #####単位元######要設定0or1orinf self.ide_ele = ele self.segfun = segfun #################### self.n = n self.N0 = 1 << n.bit_length() self.data = [self.ide_ele] * (self.N0 * 2) def update_add(self, l, r, val): l += self.N0 r += self.N0 while l < r: if l & 1: self.data[l] += val l += 1 if r & 1: self.data[r - 1] += val r -= 1 l //= 2 r //= 2 def update(self, l, r, val): l += self.N0 r += self.N0 while l < r: if l & 1: self.data[l] = self.segfun(self.data[l], val) l += 1 if r & 1: self.data[r - 1] = self.segfun(self.data[r - 1], val) r -= 1 l //= 2 r //= 2 def query(self, i): i += len(self.data) // 2 ret = self.data[i] while i > 0: i //= 2 ret = self.segfun(ret, self.data[i]) return ret N, D, A = map(int,readline().split()) X = [list(map(int,readline().split())) for _ in range(N)] X.sort() L = [0]*N for i in range(N): L[i] = X[i][0] S = SegmentTree(N,0,lambda a, b: a+b) ans = 0 for i,[x,h] in enumerate(X): H = h - S.query(i) if H<=0: continue ind = bisect.bisect(L,x+2*D) need = (H-1)//A + 1 S.update(i,ind,need*A) ans += need print(ans) return if __name__ == '__main__': main()
import bisect import sys input=sys.stdin.readline n,d,a=map(int,input().split()) l=[list(map(int,input().split())) for i in range(n)] l.sort() data0=[0]*(n+1) data1=[0]*(n+1) def _add(data,k,x): while k<=n: data[k]+=x k+=k&-k def add(l,r,x): _add(data0,l,-x*(l-1)) _add(data0,r,x*(r-1)) _add(data1,l,x) _add(data1,r,-x) def _get(data,k): s=0 while k: s+=data[k] k-=k&-k return s def query(l,r): return _get(data1,r-1)*(r-1)+_get(data0,r-1)-_get(data1,l-1)*(l-1)-_get(data0,l-1) x=[] for i in range(n): x.append(l[i][0]) add(i+1,i+2,l[i][1]) Right=[] for i in range(n): Right.append(bisect.bisect_right(x,x[i]+2*d)) p=0 ans=0 while p<n: Q=query(p+1,p+2) add(p+1,Right[p]+1,-((Q+a-1)//a)*a) ans+=(Q+a-1)//a p=min(p+1,n-1) while query(p+1,p+2)<=0: p+=1 if p==n: break print(ans)
1
81,966,673,624,020
null
230
230
import sys input = sys.stdin.readline def main(): H, A = map(int, input().split()) answer = 0 while H > 0: H -= A answer += 1 print(answer) if __name__ == '__main__': main()
from decimal import Decimal import math def main(): x = Decimal(input()) y = 0 p = Decimal(100) gr = Decimal('1.01') while p < x: p *= gr p = math.floor(p) y += 1 print(y) main()
0
null
51,941,562,994,190
225
159
def right(a,b,a1,a2,a3,a4,a5,a6): b1=a6 b2=a5 b3=a4 b4=a3 b5=a2 b6=a1 if a>b: tmp_a=a a=b b=tmp_a if [a,b]==[a1,a2]: right_side=[a3,b3] elif [a,b]==[a1,a3]: right_side=[a5,b5] elif [a,b]==[a1,a4]: right_side=[a2,b2] elif [a,b]==[a1, a5]: right_side=[a4,b4] elif [a,b]==[a2, a3]: right_side=[a1,b1] elif [a, b]==[a2, a4]: right_side=[a6,b6] elif [a,b]==[a2,a6]: right_side=[a3,b3] elif [a,b]==[a3, a5]: right_side=[a1,b1] elif [a,b]==[a3, a6]: right_side=[a5,b5] elif [a, b]==[a4, a5]: right_side=[a6,b6] elif [a,b]==[a4,a6]: right_side=[a2,b2] elif [a,b]==[a5,a6]: right_side=[a4,b4] return right_side initial=list( map(int,input().split())) num_of_q=int(input()) for i in range(0, num_of_q): a=list(map(int, input().split())) flag=0 if a[0]>a[1]: flag=1 answer=right(*a,*initial) print(answer[flag])
x, y = [int(_) for _ in input().split()] ans = 0 ans += (x-1 == 0)*300000 + (x-2 == 0)*200000 + (x-3 == 0)*100000 ans += (y-1 == 0)*300000 + (y-2 == 0)*200000 + (y-3 == 0)*100000 if x == 1 and y == 1: ans += 400000 print(ans)
0
null
70,278,177,806,790
34
275
nMonsters, nSpecial = [int(x) for x in input().split()] monst = [int(x) for x in input().split()] monst.sort() nMonsters -= nSpecial if nMonsters < 0: print(0) else: print(sum(monst[0:nMonsters]))
N,K=map(int,input().split()) H=list(map(int, input().split())) #Nモンスターの数、K必殺回数(モンスターは体力ゼロになる)、Hモンスターの数と各々の体力 H=sorted(H) if K>=len(H): print(0) else: for i in range(0,K): del H[-1] result=sum(H) print(result)
1
78,653,092,738,572
null
227
227
n = list(input()) print("Yes") if any([i == "7" for i in n]) else print("No")
a=int(input()) str_a=str(a) list_a=list(str_a) count=0 for i in range(0,len(list_a)): if(list_a[i]=='7'): count+=1 else: count+=0 if(count>1 or count==1): print('Yes') else: print('No')
1
34,481,069,960,414
null
172
172
#!/usr/bin/env python3 def main(): import sys input = sys.stdin.readline N, M = map(int, input().split()) H = [0] + [int(x) for x in input().split()] graph = [[] for _ in [0] * (N + 1)] for i in range(M): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) res = N for i in range(1, N + 1): if graph[i]: for j in graph[i]: if H[j] >= H[i]: res -= 1 break print(res) if __name__ == '__main__': main()
def solve(h, w): odd_line = '#.' * (w // 2) even_line = '.#' * (w // 2) if w%2: odd_line = odd_line + '#' even_line = even_line + '.' two_lines = odd_line + '\n' + even_line + '\n' print(two_lines * (h // 2), end='') if h%2: print(odd_line) print() if __name__ == '__main__': while True: h, w = [int(i) for i in input().split()] if h == w == 0: break solve(h, w)
0
null
13,009,992,284,100
155
51
# -*- coding: utf-8 -*- N = int(input().strip()) AB_list = [list(map(int, input().rstrip().split())) for i in range(N)] #----- def gcd(a,b): if b == 0: return a return gcd(b, a % b) #----- fish = {} cnt_A0_B0 = 0 cnt_A0_Bj = 0 cnt_Ai_B0 = 0 mod = 10**9 + 7 for a,b in AB_list: if a == b == 0: cnt_A0_B0 += 1 elif (a == 0): cnt_A0_Bj += 1 elif (b == 0): cnt_Ai_B0 += 1 else: g = gcd( abs(a) , abs(b) ) a //= g b //= g if a < 0: a *= (-1) b *= (-1) fish.setdefault( (a,b) , 0 ) fish[ (a,b) ] += 1 ans = 1 used = set() # multiple the number of pattern, where fish (A != 0) and (B != 0) for key_a, key_b in fish: if (key_a, key_b) not in used: if key_b >= 0: key_reverse = (key_b, -key_a) else: key_reverse = (-key_b, key_a) if key_reverse in fish: ans *= ( (pow(2, fish[(key_a, key_b)], mod) - 1) + (pow(2, fish[key_reverse], mod) - 1) + 1 ) % mod ans %= mod used.add( key_reverse ) else: ans *= ( pow(2, fish[(key_a, key_b)], mod) ) ans %= mod # multiple the number of pattern, where fish A=0 or B=0 ans *= ( (2**cnt_A0_Bj - 1) + (2**cnt_Ai_B0 - 1) + 1 ) % mod ans %= mod # Add the number of pattern, where fish (A,B)=(0,0) ans += cnt_A0_B0 ans %= mod # Minus the number of pattern, where no fish selected ans -= 1 ans = (ans + mod) % mod print(ans)
n = int(input()) a = list(map(int,input().split())) mod = 10**9+7 ans = 0 for i in range(60): x = 1<< i l = len([1 for j in a if j & x]) ans += x * l * (n-l) % mod ans %= mod print(ans)
0
null
71,568,214,584,660
146
263
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): N, M = map(int, input().split()) if N == M: print('Yes') else: print('No') if __name__ == '__main__': solve()
def main(): N,M = map(int,input().split()) if M == N: return 'Yes' else: return 'No' print(main())
1
83,383,525,774,300
null
231
231
n = list(input()) i = len(n) - 1 if n[i] == '3': print('bon') elif n[i] == '0' or n[i] == '1' or n[i] == '6' or n[i] == '8': print('pon') else: print('hon')
days_summer_vacation, amount_homework = map(int, input().split()) a = map(int, input().split()) schedule_hw = list(a) need_days_hw = 0 for i in schedule_hw: need_days_hw += i if days_summer_vacation > need_days_hw: print(days_summer_vacation - need_days_hw) elif days_summer_vacation == need_days_hw: print(0) else: print(-1)
0
null
25,637,486,442,600
142
168
import bisect,collections,copy,heapq,itertools,math,numpy,string import sys sys.setrecursionlimit(10**7) def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): H,A = LI() print(int(H/A) if H%A==0 else int(H/A+1)) main()
print('a' if input().islower()==True else 'A')
0
null
44,236,183,442,122
225
119
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)
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n, k = LI() N = 10**9+7 ans = 0 start = sum([i for i in range(0,k-1)]) goal = sum([i for i in range(n,n-k+1,-1)]) for i, j in zip(range(k-1,n+1), range(n-k+1,-1,-1)): start += i goal += j cnt = (goal-start+1)%N ans += cnt ans %= N print(ans) main()
1
33,250,815,294,180
null
170
170
import numpy as np # N: 会社員の人数 # 自分より番号が小さい人が直属の上司 N = int(input()) # A_i は社員番号iの直属の上司の社員番号 A = list(map(int, input().split())) ans = np.zeros(N) for i in range(N-1): ans[A[i]-1] += 1 for i in range(len(ans)): ans_str = int(ans[i]) print(ans_str)
N = int(input()) A = list(input().split()) boss = [0] for i in range(N-1): boss.append(0) boss[int(A[i])-1] += 1 for i in range(N): print(str(boss[i]))
1
32,610,306,719,340
null
169
169
s=input();print(('No','Yes')[s==input()[:len(s)]])
a = {} for s in ["S", "H", "C", "D"]: a.update({f'{s} {i}': 0 for i in range(1, 14)}) n = int(input()) for _ in range(n): s = input() del a[s] a = list(a) for i in range(len(a)): print(a[i])
0
null
11,139,556,583,324
147
54
N=int(input()) A=list(map(int,input().split())) for i in range(N): A[i] = [i+1, A[i]] A.sort(key=lambda x:x[1]) ans=[] for i in range(N): ans.append(A[i][0]) ans = map(str, ans) print(' '.join(ans))
n = int(input()) a = list(map(int,input().split())) l = [0] * n for i in range(n): l[a[i]-1] = i+1 for i in range(n): print(l[i],end = ' ')
1
180,850,289,024,190
null
299
299
while True: H,W = [int(i) for i in input().split()] if H == 0 and W == 0: break else: for line in list(range(1,H+1,1)): for column in list(range(1,W+1,1)): if line == 1 or line == H: if column == W: print("#") else: print("#", end = "") else: if column == 1: print("#", end = "") elif column == W: print("#") else: print(".", end = "") print("")
while True: H,W = map(int,input().split()) if 3 <= H and W <= 300: print(W * ('#') +'\n' + (H - 2) * (('#' + (('.') * (W - 2)) + '#') + '\n') + W * ('#')) if H == W == 0: break print()
1
809,480,487,140
null
50
50
# ABC153 # B Common Raccoon VS Monster h, n = map(int, input().split()) a = list(map(int, input().split())) s = sum(a) if h <= s: print("Yes") else: print("No")
from fractions import gcd n, m = map(int, input().split()) a = list(map(int, input().split())) def lcm(a, b): return a*b // gcd(a, b) """ akが偶数だから、bk=2akとして、 bk × (2p + 1)を満たすpが存在すれば良い 2p+1は奇数のため、Xとbkの2の素因数は一致しなければならない akに含まれる最大の2^kを探す。 """ if len(a) == 1: lcm_all = a[0]//2 else: lcm_all = lcm(a[0]//2, a[1]//2) amax = 0 for i in range(1, n): lcm_all = lcm(lcm_all, a[i]//2) amax = max(amax, a[i]//2) f = True if lcm_all > m: f = False for i in range(n): if n == 1: break if (lcm_all//(a[i]//2))%2 == 0: # akの2の約数の数がそろわないので、どんな奇数を掛けても共通のXを作れない f = False if f: # amaxの奇数倍でmを超えないもの ans = (m // lcm_all + 1)//2 print(ans) else: print(0)
0
null
89,948,885,074,760
226
247
a=input() b=a.capitalize() if a==b: print("A") else: print("a")
a = str(input()) if a.isupper(): print("A") else: print("a")
1
11,378,836,129,688
null
119
119
n = int(input()) dic = {} total = 0 for _ in range(n): s, t = input().split() total += int(t) dic[s] = total x = input() total -= dic[x] print(total)
def insertion_sort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j + g] = A[j] j -= g cnt += 1 A[j + g] = v def shell_sort(A, n): G = [] i = 1 while i <= n: G.append(i) i = i * 3 + 1 G_inv = G[::-1] for g in G_inv: insertion_sort(A, n, g) return len(G), G_inv, A N = int(input()) a = [int(input()) for i in range(N)] cnt = 0 m, Gl, A = shell_sort(a, N) print(m) print(' '.join(str(g) for g in Gl)) print(cnt) print('\n'.join(str(e) for e in A))
0
null
48,271,571,255,360
243
17
N = int(input()) D = list(map(int, input().split())) mod = 998244353 counter = [0] * N for d in D: counter[d] += 1 if counter[0] != 1: print(0) exit() ans = 1 for d in D[1:]: ans = ans * counter[d-1] % mod print(ans)
def solve(m, f, r): if (m == -1 or f == -1) or m + f < 30: return "F" for a, b in ((80, "A"), (65, "B"), (50, "C")): if m + f >= a: return b if r >= 50: return "C" return "D" while True: m, f, r = map(int, input().split()) if m == f == r == -1: break print(solve(m, f, r))
0
null
77,680,838,857,820
284
57
import math a, b, C=map(int, input().split()) print("{0:.5f}".format((1/2)*a*b*math.sin(C*math.pi/180.0))) print("{0:.5f}".format(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180)))) print("{0:.5f}".format(b*math.sin(C*math.pi/180.0)))
# coding:utf-8 import math a,b,C=list(map(float,input().split())) h=b*math.sin(math.radians(C)) S=a*h/2 c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C))) L=a+b+c print('%.6f'%S) print('%.6f'%L) print('%.6f'%h)
1
173,876,729,180
null
30
30
import math a, b, n = map(int, input().split()) if n < b: c = math.floor(a * n / b) print(c) else: c = math.floor(a * (b-1)/ b) print(c)
S=input() Q=int(input()) A=[list(input().split()) for i in range(Q)] c=0 R="" L="" for i in range(Q): if A[i][0]=="1": c+=1 continue if c%2==1 and A[i][0]=="2": if A[i][1]=="1": R=R+A[i][2] elif A[i][1]=="2": L=A[i][2]+L elif c%2==0 and A[i][0]=="2": if A[i][1]=="1": L=A[i][2]+L elif A[i][1]=="2": R=R+A[i][2] S=L+S+R if c%2==1: S=S[::-1] print(S)
0
null
42,872,924,018,198
161
204
N, M = map(int,input().split()) ans = 'No' if M == N: ans = 'Yes' print(ans)
ABC = list(map(int, input().split())) if len(set(ABC)) == 2: print('Yes') else: print('No')
0
null
75,288,844,525,790
231
216
import math X, N = map(int, input().split()) if N == 0: print(X) else: p = list(map(int, input().split())) q = [int(i)-10 for i in range(121)] #print(q) for i in p: q.remove(i) ans = 0 r0 = 100000 for j in q: r = abs(j-X) if r0 > r: r0 = r ans = j print(ans)
import sys def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr n=int(input()) if n==1: print(0) sys.exit() l=factorization(n) ans =0 for x in l: a=x[0] #素数 b=x[1] #素数の個数 k=0 t=0 while(True): t += 1 k += t if k==b: ans += t break elif k > b: ans += t-1 break print(ans)
0
null
15,560,269,510,742
128
136
a=list(input()) count=1 ans = 0 temp = 0 for i in range(len(a)-1): if a[i] ==a[i+1]: count+=1 else: if a[i]=='<': ans += count*(count+1)//2 temp = count #print('<', count, ans) count = 1 else: ans += count*(count+1)//2 ans -= min(count, temp) #print('>', count, ans) count =1 else: if a[-1]=='<': ans += count*(count+1)//2 else: ans += count*(count+1)//2 ans -= min(count, temp) print(ans)
S = input() N=len(S)+1 SS = '>'+S+'<' a = [-1]*(N+2) for i in range(N+1): if SS[i] == '>' and SS[i+1]=='<': a[i+1]=0 b = a[1:-1] c = a[1:-1] for i in range(N-1): if S[i] == '<' and b[i]>=0 : b[i+1] = b[i] +1 for i in range(N-2,-1,-1): if S[i] == '>' and c[i+1]>=0: c[i] = c[i+1] +1 ans = 0 for bb,cc in zip(b,c): ans += max(bb,cc) print(ans)
1
157,096,947,598,830
null
285
285
n = int(input()) a = n % 10 if a == 2 or a == 4 or a == 5 or a == 7 or a == 9: print("hon") elif a == 3: print("bon") else: print("pon")
# 5 import sys def input(): return sys.stdin.readline().strip() def I(): return int(input()) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return input() def LS(): return input().split() INF = float('inf') n = I() s = S() ciphers = [f'{i:03}' for i in range(1000)] ans = 0 for v in ciphers: j = 0 for i in range(n): if s[i] == v[j]: j += 1 if j == 3: ans += 1 break print(ans)
0
null
73,990,661,045,120
142
267
import math import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") D,T,S = LI() if T < D/S: ans = 'No' else: ans = 'Yes' print(ans)
d,t,s = map(int,input().split()) T = d/s if(t>=T): print("Yes") else: print("No")
1
3,520,770,660,658
null
81
81
n = int(input()) a = [0] + list(map(int,input().split())) l = [0]*n for i in a: l[i-1] += i for j in range(n): l[j] = int(l[j]/(j+1)) for k in l: print(k,end="\n")
a,b,n = list(map(int,input().split())) if n < b : x = n else : x = b-1 print(a*x//b-a*(x//b))
0
null
30,404,702,992,960
169
161
import math def comb(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) N = int(input()) Comlist = [] Ans = dict() Answer = 0 for i in range(1,10): for j in range(1,10): M = i*10 + j Comlist.append(str(M)) Ans[str(M)] = 0 for k in range(1,N+1): strk = str(k) if k < 10: Tar = strk + strk Ans[Tar] += 1 else: Tar = strk[0] + strk[-1] if Tar in Ans: Ans[Tar] += 1 Answer = 0 for q in range(len(Comlist)): p = Comlist[q] pin = p[1] + p[0] Answer += Ans[p] * Ans[pin] print(Answer)
import sys from collections import defaultdict time = 1 def dfs(g, visited, start, ans): global time visited[start - 1] = True ans[start - 1][0] = time for e in g[start]: if not visited[e - 1]: time += 1 dfs(g, visited, e, ans) time += 1 ans[start - 1][1] = time def main(): input = sys.stdin.buffer.readline n = int(input()) g = defaultdict(list) for i in range(n): line = list(map(int, input().split())) if line[1] > 0: g[line[0]] = line[2:] visited = [False] * n ans = [[1, 1] for _ in range(n)] global time while False in visited: start = visited.index(False) + 1 dfs(g, visited, start, ans) time += 1 for i in range(1, n + 1): print(i, *ans[i - 1]) if __name__ == "__main__": main()
0
null
43,215,546,397,618
234
8
# coding: utf-8 N,S=map(int,input().split()) A=list(map(int,input().split())) MOD=998244353 dp=[[0 for j in range(S+1)] for i in range(N+1)] dp[0][0]=1 for i in range(1,N+1): a=A[i-1] for j in range(0,S+1): dp[i][j]+=dp[i-1][j]*2 if j-a>=0: dp[i][j]+=dp[i-1][j-a] dp[i][j]=dp[i][j]%MOD print(dp[N][S])
n,s=map(int,input().split()) a=list(map(int,input().split())) #dp[n][s] #nこめまで選んだ時の和がsの組 dp=[[0]*(s+1) for _ in range(n)] a.sort() #for i in range(s+1): # dp[0][i]=2 if a[0]>s: print(0) exit() mod=998244353 dp[0][0]=2 dp[0][a[0]]+=1 for i in range(1,n): for j in range(s+1): #i番目を入れて選択するパターン dp[i][j]=dp[i-1][j]*2%mod if j>=a[i]: dp[i][j]+=dp[i-1][j-a[i]]%mod print(dp[-1][s]%mod)
1
17,756,218,830,020
null
138
138
N, M = map(int, input().split()) A = list(map(int, input().split())) total = sum(A) base = total / (4 * M) filtered = list(filter(lambda x: x >= base, A)) if (len(filtered) >= M): print('Yes') else: print('No')
#!/usr/bin/env python # coding: utf-8 # In[22]: X = int(input()) # In[23]: if -(-(X%100)//5) <= X//100: print(1) else: print(0) # In[ ]:
0
null
83,200,801,947,942
179
266
import sys if __name__ == "__main__": n = int(sys.stdin.readline()) inp = sys.stdin.readlines() lis = set() for i in range(n): com = inp[i].split() if com[0] == "insert": lis.add(com[1]) elif com[1] in lis: print("yes") else: print("no")
s = input()[::-1] counts = [0] * 2019 counts[0] = 1 digit = 1 sum = 0 for c in s: sum = (sum + int(c) * digit) % 2019 digit = digit * 10 % 2019 counts[sum] += 1 result = 0 for c in counts: result += c * (c - 1) // 2 print(result)
0
null
15,575,834,667,948
23
166
from itertools import accumulate N, *A = map(int, open(0).read().split()) A_acc = list(accumulate(A, initial=0)) min_diff = float("inf") for i in range(1, N): left, right = A_acc[i], A_acc[N] - A_acc[i] min_diff = min(min_diff, abs(right - left)) print(min_diff)
n = int(input()) arr = list(map(int,input().split())) tot = sum(arr) temp = 0 ans = 1e18 for i in range(n): temp += arr[i] rest = tot-temp cost = abs(rest-temp) if cost < ans: ans = cost print(ans)
1
142,183,469,588,468
null
276
276
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush import math #from math import gcd #inf = 10**17 #mod = 10**9 + 7 n,a,b = map(int, input().split()) if (b-a) % 2 == 0: print((b-a)//2) else: if b-a == 1: print(min(b-1, n-a)) else: print(min(a-1+(b-a+1)//2, n-b+(b-a+1)//2)) if __name__ == '__main__': main()
n,a,b = map(int,input().split()) if (a-b)%2 == 0: print(abs(a-b)//2) else: if abs(a-1) <= abs(n-b): # b -= abs(a-1) if (a-b)%2 == 1: b -= 1 print(abs(a-1)+abs(a-b)//2+1) else: print(abs(a-1)+abs(a-b)//2) else: # a += abs(n-b) if (a-b)%2 == 1: # b += 1 a += 1 print(abs(n-b)+abs(a-b)//2+1) else: print(abs(n-b)+abs(a-b)//2)
1
109,553,943,559,108
null
253
253
A = [] P = ['o']*9 for i in range(3): a = [int(i) for i in input().split()] for j in range(3): A.append(a[j]) N = int(input()) for i in range(N): b = int(input()) for j in range(9): if A[j] == b: P[j] = 'x' t = 0 for i in range(3): if (P[i] == P[i+3] == P[i+6] == 'x') or (P[3*i] == P[3*i+1] == P[3*i+2] == 'x'): t += 1 break if (P[0] == P[4] == P[8] == 'x') or (P[2] == P[4] == P[6] == 'x'): t += 1 if t == 0: print('No') else: print('Yes')
def Judge(a): col=[] diag1=0 diag2=0 for i in range(3): if(a[i].count(0)==3): return 1 break if(a[i][0]==0): col.append(0) if(a[i][1]==0): col.append(1) if(a[i][2]==0): col.append(2) if(a[i][i]==0): diag1+=1 if(a[i][-(i+1)]==0): diag2+=1 if(diag1==3 or diag2==3): return 1 if(col.count(0)==3 or col.count(1)==3 or col.count(2)==3): return 1 return 0 a=[] for i in range(3): a.append(list(map(int,input().split()))) n=int(input()) for i in range(n): b=int(input()) for j in range(3): for k in range(3): if(b==a[j][k]): a[j][k]=0 judge=Judge(a) if(judge==1): print("Yes") else: print("No")
1
59,639,745,831,680
null
207
207
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = map(int, read().split()) ans = 0 p = 1 for _ in range(60): n = 0 for i in range(N): A[i], d = A[i] // 2, A[i] % 2 n += d ans = (ans + n * (N - n) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == '__main__': main()
n=int(input()) b=list(map(int,input().split())) b.sort() for i in range(n-1): if b[i]==b[i+1]: print("NO") break if i==n-2: print("YES")
0
null
98,677,041,728,160
263
222
while True: a,b=map(int,input().split()) if not(a) and not(b):break if a>b:a,b=b,a print(a,b)
N = str(input()) a = [] for n in range(len(N)): a.append(int(N[n])) if sum(a) % 9 == 0: print('Yes') else: print('No')
0
null
2,493,514,162,384
43
87
import sys from collections import defaultdict def input(): return sys.stdin.readline().rstrip() def main(): H, W, K = map(int, input().split()) S = [input() for _ in range(H)] ans = 10 ** 9 for bit in range(1 << (H-1)): canSolve = True ord = defaultdict(int) N = 0 for i in range(H): if bit & 1 << i: ord[i+1] = ord[i] + 1 N += 1 else: ord[i+1] = ord[i] add = 0 nums = defaultdict(int) for w in range(W): one = defaultdict(int) ok = True for h in range(H): one[ord[h]] += int(S[h][w]) nums[ord[h]] += int(S[h][w]) if one[ord[h]] > K: canSolve = False if nums[ord[h]] > K: ok = False if not ok: add += 1 nums = one if canSolve and ans > N + add: ans = N + add print(ans) if __name__ == '__main__': main()
from itertools import product H, W, K = map(int, input().split()) S = [input() for _ in range(H)] S_T = [[int(s[w]) for s in S] for w in range(W)] sumS = sum(map(sum, S_T)) ans = (H - 1) * (W - 1) if sumS <= K: print(0) else: for i in product([True, False], repeat=H-1): cnt = sum(i) if cnt >= ans: continue M = [[0]] for j, k in enumerate(i): if k: M.append([]) M[-1].append(j+1) A = [0] * len(M) for s_t in S_T: for l, m in enumerate(M): A[l] += sum(s_t[i] for i in m) if any(a > K for a in A): cnt += 1 if cnt >= ans: break A = [sum(s_t[i] for i in m) for m in M] if any(a > K for a in A): cnt = ans + 1 break ans = min(cnt, ans) print(ans)
1
48,147,463,691,248
null
193
193
inList = input().split() stack = [] for i in inList: if i in ['+', '-', '*']: b, a = stack.pop(), stack.pop() if i == '+': stack.append(b + a) if i == '-': stack.append(a - b) if i == '*': stack.append(b * a) else: stack.append(int(i)) print(stack.pop())
n, xs = int(input()), map(int,raw_input().split()) print min(xs), max(xs), sum(xs)
0
null
380,857,072,848
18
48
W, H, x, y, r = [int(i) for i in input().split()] if r <= y <= H - r and r <= x <= W - r: print('Yes') else: print('No')
def main(): x = int(input()) if x >= 30: print('Yes') else: print("No") if __name__ == main(): main()
0
null
3,130,491,018,420
41
95
l=map(str,raw_input().split()) chk=[] op='-+*' while len(l): k=l.pop(0) if k in op: b=chk.pop() a=chk.pop() chk.append(str(eval(a+k+b))) else: chk.append(k) print chk[0]
# 09-Computation-Min_Max_and_Sum.py # ????°????????????§??????????¨???? # n ????????´??° ai(i=1,2,...n)?????\?????????????????????????°????????????§??????????¨????????±???????????????°???????????????????????????????????? # Input # ??????????????´??°?????° n ???????????????????????????????????? n ????????´??° ai ????????????????????§????????????????????? # Output # ????°????????????§??????????¨????????????????????????§???????????????????????????????????? # Constraints # 0<n???10000 # ???1000000???ai???1000000 # Sample Input # 5 # 10 1 5 4 17 # Sample Output # 1 17 37 num_min = 1000001 num_max = -1000001 num_sum = 0 num = int(input()) # a = [] # a = [ *map(int,input().split() ) ] a = input().split() for i in range(num): a[i]=int(a[i]) for i in range(num): if a[i]<num_min: num_min = a[i] if a[i]>num_max: num_max = a[i] num_sum+=a[i] print("{0} {1} {2}".format(num_min,num_max,num_sum) );
0
null
390,083,446,980
18
48
import math X = int(input()) year = 0 money = 100 while(money < X): money = money * 101//100 year += 1 print(year)
X = int(input()) ASSET = 100 cnt = 0 while ASSET < X: ASSET += ASSET // 100 cnt += 1 print(cnt)
1
27,225,224,576,802
null
159
159
import math N, K=map(int,input().split()) A=list(map(int,input().split())) def judge(ans,K,A): cut=0 for i in range(len(A)): cut+=(A[i]-1)//ans if cut>K: return False else: return True ansp=max(A) ansm=0 ans=(ansp+ansm)//2 d=1 while ansp-ansm>d: if judge(ans,K,A): ansp=ans else: ansm=ans ans=(ansp+ansm)//2 print(ansp)
from sys import stdin, setrecursionlimit def main(): input = stdin.buffer.readline a = map(int, input().split()) if sum(a) >= 22: print('bust') else: print('win') if __name__ == "__main__": setrecursionlimit(10000) main()
0
null
62,540,580,132,100
99
260
N = int(input()) A = list(map(int,input().split())) MOD = 1000000007 def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr lcma={} for ai in A: f=factorization(ai) for fi in f: if fi[0] in lcma: lcma[fi[0]]=max(lcma[fi[0]],fi[1]) else: lcma[fi[0]]=fi[1] l=1 for k,v in lcma.items(): l*=pow(k,v,MOD) l%=MOD ans=0 for ai in A: ans+=l*pow(ai,MOD-2,MOD) ans%=MOD print(ans)
import math def main(): MOD = 10 ** 9 + 7 N = int(input()) A = list(map(int, input().split(' '))) # 答えは sum(lcm(A) / A) L = 1 for a in A: L = L * a // math.gcd(L, a) ans = 0 for a in A: ans += L * pow(a, MOD - 2, MOD) ans %= MOD print(ans) if __name__ == '__main__': main()
1
87,653,565,936,988
null
235
235
l = input().split() print(l[2], l[0], l[1])
a=input() a=a.split() a=(a[2],a[0],a[1]) print(*a)
1
38,051,854,995,008
null
178
178
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') YES = "Yes" # type: str NO = "No" # type: str def solve(N: int, M: int): return [NO, YES][N == M] def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int print(f'{solve(N, M)}') if __name__ == '__main__': main()
h,a=map(int,input().split()) if h%a!=0: n=int(h/a)+1 print(n) else: n=int(h/a) print(n)
0
null
79,962,596,618,520
231
225
import bisect N=int(input()) rllist=[] for _ in range(N): X,L=map(int,input().split()) rllist.append((X+L,X-L)) rllist.sort() #print(rllist) dp=[0]*N dp[0]=1 for i in range(1,N): r,l=rllist[i] pos=bisect.bisect(rllist,(l,float("inf"))) #print(i,pos) if pos==0: dp[i]=dp[i-1] else: dp[i]=max(dp[i-1],dp[pos-1]+1) #print(dp) print(dp[-1])
N, K = map(int, input().split()) A = list(map(int, input().split())) left, right = 0, max(A) while right - left != 1: mid = (left + right) // 2 tmp = 0 for i in A: tmp += i // mid - 1 if i % mid == 0 else i // mid if tmp > K: left = mid else: right = mid print(right)
0
null
48,020,956,628,832
237
99
s = input() t = input() ans = 0 for cs, ct in zip(s, t): if cs != ct: ans += 1 print(ans)
n=int(input()) abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] ans = '' while n: ans += abc[(n-1)%len(abc)] n = (n-1)//len(abc) print(ans[::-1])
0
null
11,219,645,368,420
116
121
l = [] while True: s = [int(i) for i in input().split()] if s == [0,0]: break else: s.sort() l.append(str(s[0])+' '+str(s[1])) for i in l: print(i)
n,k=map(int,input().split()) tmp=[int(input()) for i in range(n)] left=max(tmp)-1 right=sum(tmp) while left+1 < right: mid=(left+right)//2 count=1 now=0 for i in tmp: if mid<now+i: now=i count+=1 else: now+=i if count<=k: right=mid else: left=mid print(right)
0
null
307,144,183,360
43
24
from collections import defaultdict, deque N, K = map(int, input().split()) A = list(map(int, input().split())) cumA = [0] * (N + 1) for i in range(1, N + 1): cumA[i] = cumA[i - 1] + A[i - 1] cnt = defaultdict(int) que = deque([]) ans = 0 for i, c in enumerate(cumA): while que and que[0][0] <= i - K: cnt[que.popleft()[1]] -= 1 diff = (i - c) % K ans += cnt[diff] cnt[diff] += 1 que.append((i, diff)) print(ans)
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def SL(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [SL() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def LR(n): return [L() for _ in range(n)] def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)] alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" sys.setrecursionlimit(1000000) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 INF = float("inf") def main(): N, K = LI() A = LI() S = list(itertools.accumulate(A)) keep = defaultdict(int) keep[0] += 1 ans = 0 for i in range(1, N+1): v = (S[i-1] - i) % K if i == K: keep[0] -= 1 if i - K > 0: w = (S[i-K-1] - (i - K)) % K keep[w] -= 1 ans += keep[v] keep[v] += 1 print(ans) if __name__ == '__main__': main()
1
138,064,040,949,312
null
273
273
# -*- coding: utf-8 -*- def linearSearch(l, key): m = len(l) l.append(key) i = 0 while l[i] != key: i += 1 l.pop() if i == m: return "NOT_FOUND" return i if __name__ == '__main__': n = int(input()) S = [int(s) for s in input().split(" ")] q = int(input()) T = [int(t) for t in input().split(" ")] count = 0 for t in T: if linearSearch(S, t) != "NOT_FOUND": count += 1 print(count)
def liner_search(r,key): for x in r: if x == key: return True return False N = int(input()) S = list(map(int, input().split())) q = int(input()) Key = list(map(int, input().split())) cnt = 0 for i in range(q): if liner_search(S, Key[i]): cnt += 1 print(cnt)
1
65,969,798,748
null
22
22