code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
C = input() n = chr(ord(C)+1) print(n)
alp_list = list('abcdefghijklmnopqrstuvwxyz') C = str(input()) z = alp_list.index(C) z += 1 print(alp_list[z])
1
92,189,036,887,460
null
239
239
S = int(input()) s = S % 60 m1 = S // 60 m = m1 % 60 h = m1 // 60 print(str(h)+':'+str(m)+':'+str(s))
minute = int(input()) print('{}:{}:{}'.format(minute // 3600, (minute % 3600) // 60, (minute % 3600) % 60))
1
335,909,143,332
null
37
37
X = input() l = len(X) m = l//2 if (X == 'hi'*m): print("Yes") else: print("No")
n = int(input()) slimes = input() fusion = [slimes[0]] cnt = 0 for i in range(1,n): if fusion[cnt] != slimes[i]: fusion.append(slimes[i]) cnt += 1 print(cnt+1)
0
null
111,519,065,167,200
199
293
import numpy as np N,K = map(int,input().split()) import math A = list(map(int,input().split())) flag = 0 if 0 in A: flag = 1 A.sort() plus = list(filter(lambda x:x>0, A))[::-1] plus = list(map(lambda x:np.longdouble(math.log(x,10000000)),plus)) from itertools import accumulate acc_plu = [0] + list(accumulate(plus)) minu = filter(lambda x:x<0, A) minu = list(map(lambda x:np.longdouble(math.log(-x,10000000)),minu)) acc_min = [0] + list(accumulate(minu)) if K % 2 == 0 : num = K // 2 + 1 else: num = (K + 1) // 2 cand = [] x = K y = 0 MOD = 10**9 +7 for i in range(num): try: cand.append((acc_plu[x] + acc_min[y],x ,y )) except: pass x -= 2 y += 2 ans = 1 if cand == []: if flag: print(0) exit() cnt = 0 #マイナス確定 abss = sorted(list(map(lambda x :abs(x),A))) for x in abss: if cnt == K:break ans *= x ans %= MOD cnt += 1 ans *= -1 ans %= MOD print(ans) else: cand = sorted(cand)[::-1] plus = list(filter(lambda x:x>0, A))[::-1] minu = list(filter(lambda x:x<0, A)) c = cand[0] ans = 1 for i in range(c[1]): ans *= plus[i] ans %= MOD for i in range(c[2]): ans *= minu[i] ans %= MOD print(ans)
N = int(input()) A = [] for i in range(N): x,y = map(int, input().split()) A.append([x+y,x-y]) A.sort() now = -float('inf') ans = 0 for a,b in A: if b>=now: ans += 1 now = a print(ans)
0
null
49,585,554,301,832
112
237
integer = int(input()) for i in range(9): for j in range(9): if (i + 1) * (j + 1) == integer: print('Yes') exit() print('No')
n = int(input()) playList = [] sumTerm = 0 for i in range(n) : song = input().split() song[1] = int(song[1]) playList.append(song) sumTerm += song[1] x = input() tmpSumTerm = 0 for i in range(n) : tmpSumTerm += playList[i][1] if playList[i][0] == x : print(sumTerm - tmpSumTerm) break
0
null
128,704,808,379,936
287
243
n = int(input()) s, t = map(str, input().split()) ans = '' for a, b in zip(s, t): ans += a+b print(ans)
while True: data=map(int,list(raw_input())) if data==[0]: break print sum(data)
0
null
56,583,365,413,728
255
62
import sys input = sys.stdin.readline n,a,b=map(int,input().split()) val = n//(a+b) pos = n%(a+b) if pos>a: pos = a print(val*a + pos)
class Dice: def __init__(self,u,s,e,w,n,d): self.n = n self.e = e self.s = s self.w = w self.u = u self.d = d def roll(self,dir): if (dir == "N"): tmp = self.n self.n = self.u self.u = self.s self.s = self.d self.d = tmp elif (dir == "E"): tmp = self.e self.e = self.u self.u = self.w self.w = self.d self.d = tmp elif (dir == "S"): tmp = self.s self.s = self.u self.u = self.n self.n = self.d self.d = tmp elif (dir == "W"): tmp = self.w self.w = self.u self.u = self.e self.e = self.d self.d = tmp spots = raw_input().split() operations = raw_input() dice = Dice(*spots) for i in operations: dice.roll(i) print dice.u
0
null
27,936,807,305,558
202
33
print(-1*(-1*int(input()) // 2))
n=int(input()) if n%2==0:print(n//2) else:print(n//2+1)
1
58,907,189,903,210
null
206
206
#!/usr/bin/env python # -*- coding: utf-8 -*- s = input() print("ARC") if s == "ABC" else print("ABC")
I=input r=range a=[[[0 for i in r(10)]for j in r(3)]for k in r(4)] for i in r(int(I())):b,f,r,v=map(int,I().split());a[b-1][f-1][r-1]+=v f=0 for i in a: if f:print('#'*20) else:f=1 for j in i:print('',*j)
0
null
12,595,841,325,280
153
55
k,n=map(int,input().split()) l =list(map(int, input().split())) a = [] a.append(l[n-1]- l[0]) for i in range(n-1): a.append(k-l[i+1]+l[i]) print(min(a))
N,K=map(int,input().split()) A=list(map(int,input().split())) B=[N-A[K-1]+A[0]] for i in range(K-1): b=A[i+1]-A[i] B.append(b) B.sort() print(sum(B)-B[K-1])
1
43,507,866,221,492
null
186
186
S = input() ans = {'ABC': 'ARC', 'ARC': 'ABC'} print(ans[S])
S = input() if S[1:2] == "R": print("ABC") else: print("ARC")
1
24,000,676,980,882
null
153
153
#https://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html # N: 処理する区間の長さ #bit管理 #演算はor N = int(input()) s = input() N0 = 1 while N0<=N: N0*=2 INF = 0 data = [0]*(2*N0) # a_k の値を x に更新 def update(k, x): k += N0-1 data[k] = 1<<x while k >= 0: k = (k - 1) // 2 data[k] =data[2*k+1]|data[2*k+2] # 区間[l, r)の最小値 def query(l, r): L = l + N0; R = r + N0 s = INF while L < R: if R & 1: R -= 1 s = s|data[R-1] if L & 1: s = s|data[L-1] L += 1 L >>= 1; R >>= 1 return s for i in range(N): update(i,ord(s[i])-ord("a")) q = int(input()) for j in range(q): t,l,r = input().split( ) if t=="1": update(int(l)-1,ord(r)-ord("a")) else: bit = bin(query(int(l)-1,int(r)))[2:] ans = 0 for i in bit: ans += int(i) print(ans)
import sys, bisect, math, itertools, heapq, collections from operator import itemgetter # a.sort(key=itemgetter(i)) # i番目要素でsort from functools import lru_cache # @lru_cache(maxsize=None) sys.setrecursionlimit(10**8) input = sys.stdin.readline INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): ''' 一つの整数 ''' return int(input()) def inpl(): ''' 一行に複数の整数 ''' return list(map(int, input().split())) class SegmentTree(): def __init__(self, init_val, N): """ Parameters ---------- init_val:int identity element N:int the number of nodes """ self.init_val=init_val # Range Minimum Query self.N0 = 2**(N-1).bit_length() # 0-indexedで管理 self.data = [self.init_val] * (2 * self.N0) def _segfunc(self, left, right): res= left | right return res def update(self,k, x): """ Parameters ---------- k:int target index(0-index) x:any target value """ k += self.N0-1 self.data[k] = x while k > 0: k = (k - 1) // 2 self.data[k] = self._segfunc(self.data[2*k+1], self.data[2*k+2]) def query(self, l, r): """ Parameters ---------- l,r:int target range [l,r) Return ---------- res:any val """ L = l + self.N0 R = r + self.N0 s = self.init_val while L < R: if R & 1: R -= 1 s = self._segfunc(s, self.data[R-1]) if L & 1: s = self._segfunc(s,self.data[L-1]) L += 1 L >>= 1; R >>= 1 return s n=inp() s=input() st = SegmentTree(0,n) for i in range(n): st.update(i,1<<(int.from_bytes(s[i].encode(),'little')-int.from_bytes('a'.encode(),'little'))) q = inp() ans = [] for i in range(q): mode, first, second = input().split() if mode == "1": st.update(int(first)-1,1<<(int.from_bytes(second.encode(),'little')-int.from_bytes('a'.encode(),'little'))) else: ans.append(bin(st.query(int(first) - 1, int(second))).count("1")) for i in ans: print(i)
1
62,619,016,860,000
null
210
210
import sys from collections import Counter as cc def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) def main(): mod = 10**9 + 7 n = ii() a = li() t = [0]*(n) ans = 1 for i in range(n): if a[i] == 0: tmp = 3 else: tmp = t[a[i]-1] ans *= tmp-t[a[i]] ans %= mod t[a[i]] += 1 print(ans) if __name__ == '__main__': main()
n,k = (int(x) for x in input().split()) lr = [] for _ in range(k): l,r = (int(x) for x in input().split()) lr.append((l,r)) lr.sort() mod = 998244353 dp= [0]*(n+1) dp[1] = 1 for i in range(2,n+1): cnt = 0 for l,r in lr: if l >= i: break else: cnt += dp[i-l] - dp[max(0,i-r-1)] dp[i] = (dp[i-1] + cnt) % mod print(cnt%mod)
0
null
66,515,812,530,444
268
74
import sys, heapq from collections import defaultdict from itertools import product, permutations, combinations sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] N, u, v = map(int, input().split()) def dijkstra_heap(s,edge): #始点sから各頂点への最短距離 d = [10**20] * N used = [True] * N #True:未確定 d[s] = 0 used[s] = False edgelist = [] for a,b in edge[s]: heapq.heappush(edgelist,a*(10**6)+b) while len(edgelist): minedge = heapq.heappop(edgelist) #まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge%(10**6)]: continue v = minedge%(10**6) d[v] = minedge//(10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1]) return d AB = [list(map(int, input().split())) for _ in range(N-1)] adjl = [[] for _ in range(N)] for ab in AB: a, b = ab[0]-1, ab[1]-1 adjl[a].append([1, b]) adjl[b].append([1, a]) du = dijkstra_heap(u-1, adjl) dv = dijkstra_heap(v-1, adjl) dOK = [j for i, j in zip(du, dv) if i < j] print(int(max(dOK)-1))
def II(): return int(input()) def LII(): return list(map(int, input().split())) n=II() town=[LII() for _ in range(n)] distance=0 for i in range(n-1): for j in range(i+1,n): [xi,yi]=town[i] [xj,yj]=town[j] distance += ((xi-xj)**2+(yi-yj)**2)**0.5 print(distance*2/n)
0
null
132,321,593,224,548
259
280
from sys import stdin readline = stdin.readline def i_input(): return int(readline().rstrip()) def i_map(): return map(int, readline().rstrip().split()) def i_list(): return list(i_map()) def main(): X, Y = i_map() ans = False z = Y - (X * 2) if z < 0: pass elif z == 0 or (z % 2 == 0 and (z // 2) <= X): ans = True print("Yes" if ans else "No") if __name__ == "__main__": main()
n = int(input()) i = 10 ans = 0 while i <= n: ans += (n // i) i *= 5 print(ans if n & 1 == 0 else 0)
0
null
65,172,758,313,432
127
258
n=int(input()) a=[] from collections import deque as dq for i in range(n): aaa=list(map(int,input().split())) aa=aaa[2:] a.append(aa) dis=[-1]*n dis[0]=0 queue=dq([0]) while queue: p=queue.popleft() for i in range(len(a[p])): if dis[a[p][i]-1]==-1: queue.append(a[p][i]-1) dis[a[p][i]-1]=dis[p]+1 for i in range(n): print(i+1,dis[i])
import collections N = int(input()) P = [[0 for _ in range(N)] for _ in range(N)] for i in range(N): u,k,*varray = map(int,input().split()) # u,k は数, varray は配列 for v in varray: P[u-1][v-1] = 1 D = [-1 for _ in range(N)] D[0] = 0 # 始点への距離は 0, 他の距離は-1 Q = collections.deque() Q.append(0) while len(Q) > 0: c = Q.popleft() for i in range(N): if P[c][i]==1 and D[i]==-1: D[i] = D[c]+1 Q.append(i) for v in range(N): print(v+1, D[v])
1
4,191,390,436
null
9
9
A = int(input()) B = int(input()) for x in range(1, 4): if x not in [A, B]: print(x) break
x, y, z = map(int, raw_input().split()) cnt = 0 for i in range(x, y+1): if z%i == 0: cnt += 1 print cnt
0
null
55,699,331,542,862
254
44
N=int(input()) lis=[chr(i) for i in range(97, 97+26)] ans='' while N>0: N-=1 ans+=lis[N%26] N=N//26 print(ans[::-1])
N = int(input()) ans = "" letter = "abcdefghijklmnopqrstuvwxyz" while N != 0: N -= 1 ans = letter[N % 26] + ans N = N // 26 print(ans)
1
11,864,673,860,390
null
121
121
def main(): n, k = map(int, input().split()) a_list = list(map(int, input().split())) visited_list = [-1] * n # 何ワープ目で訪れたか visited_list[0] = 0 city, loop, non_loop = 1, 0, 0 # 今いる街、何ワープでループするか、最初にループするまでのワープ数 for i in range(1, n + 1): city = a_list[city - 1] if visited_list[city - 1] != -1: loop = i - visited_list[city - 1] non_loop = visited_list[city - 1] - 1 break else: visited_list[city - 1] = i city = 1 if k <= non_loop: for _ in range(k): city = a_list[city - 1] else: for _ in range(non_loop + (k - non_loop) % loop + loop): city = a_list[city - 1] print(city) if __name__ == "__main__": main()
N, K = [int(n) for n in input().split()] A = [int(n) for n in input().split()] count = 0 for i in range(1,N+1): A[i-1] = A[i-1]-1 check = {0: [0,1,[0]]} s = 0 for i in range(1,N+1): s = (s + A[i-1]) % K if s in check: j = check[s][0] l = check[s][1] while j < l and i - check[s][2][j] >= K: j += 1 check[s][0] = j count += l - j check[s][2].append(i) check[s][1] = l + 1 else: check[s] = [0,1,[i]] print(count)
0
null
79,944,510,993,212
150
273
import heapq from collections import deque must_red, must_green, a,b,c = map(int,input().split()) delicious_red_ls = list(map(int, input().split())) delicious_green_ls = list(map(int, input().split())) delicious_free_ls = list(map(int, input().split())) delicious_red_ls.sort(reverse=True) delicious_green_ls.sort(reverse=True) first_red = delicious_red_ls[:must_red] first_green = delicious_green_ls[:must_green] first_set = first_green + first_red first_set.sort() delicious_free_ls.sort() while delicious_free_ls: to_be_erased = heapq.heappop(first_set) erase = delicious_free_ls[-1] if to_be_erased < erase: new = delicious_free_ls.pop() heapq.heappush(first_set, new) else: heapq.heappush(first_set, to_be_erased) break print(sum(first_set))
#!/usr/bin/env python3 import sys import collections as cl 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 main(): x, y, a, b, c = MI() p = LI() q = LI() r = LI() p.sort(reverse=True) q.sort(reverse=True) r.sort(reverse=True) p_selected = p[:x] q_selected = q[:y] ans = [*p_selected, *q_selected] ans.sort() i = 0 while i < x + y and i < c and ans[i] < r[i]: ans[i] = r[i] i += 1 print(sum(ans)) main()
1
44,699,165,307,328
null
188
188
def north(d): d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0] def west(d): d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0] def east(d): d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0] def south(d): d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0] F = {'N': north, 'W': west, 'E': east, 'S': south} d, os = list(map(int, input().split())), input() for o in os: F[o](d) print(d[0])
class Dice: def __init__(self, hoge): self.num = hoge self.face = {'U': 0, 'W': 3, 'E': 2, 'N': 4, 'S': 1, 'B': 5} def move(self, direct): previouse = {k: v for k, v in self.face.items()} if direct == 'E': self.face['U'] = previouse['W'] self.face['W'] = previouse['B'] self.face['E'] = previouse['U'] self.face['B'] = previouse['E'] elif direct == 'W': self.face['U'] = previouse['E'] self.face['W'] = previouse['U'] self.face['E'] = previouse['B'] self.face['B'] = previouse['W'] elif direct == 'N': self.face['U'] = previouse['S'] self.face['N'] = previouse['U'] self.face['S'] = previouse['B'] self.face['B'] = previouse['N'] elif direct == 'S': self.face['U'] = previouse['N'] self.face['N'] = previouse['B'] self.face['S'] = previouse['U'] self.face['B'] = previouse['S'] def get_upper(self): return self.num[self.face['U']] if __name__ == '__main__': dice = Dice([int(x) for x in input().split()]) for d in input(): dice.move(d) print (dice.get_upper())
1
231,572,676,438
null
33
33
x = int(input()) x_ = divmod(x, 100) if 5*x_[0] >= x_[1]: print(1) else: print(0)
H,W,K = map(int, input().split()) S = [input() for _ in range(H)] L = [[0]*(W) for _ in range(H)] for i in range(H): for j in range(W): if S[i][j] == "1": L[i][j] = 1 ans = H*W for i in range(2**(H-1)): cnt = 0 used = [0]*W memo = [] for j in range(H-1): if i & (1<<j): cnt += 1 memo.append(j+1) memo.append(H) num = [0]*(cnt+1) for j in range(W): idx = 0 for k in range(H): if memo[idx] == k: idx += 1 num[idx] += L[k][j] f = False for k in range(len(num)): if num[k] > K: f = True break if f: if j == 0 or used[j-1] == 1: cnt = H*W break used[j-1] = 1 cnt += 1 num = [0]*len(num) idx = 0 for k in range(H): if memo[idx] == k: idx += 1 num[idx] += L[k][j] ans = min(ans, cnt) print(ans)
0
null
87,677,915,171,560
266
193
a,b,c=map(int,input().split()) d=[i for i in range(a,b+1)] count=0 for i in d: if c%i==0: count+=1 print(count)
ins = input().split() a = int(ins[0]) b = int(ins[1]) c = int(ins[2]) print(len([x for x in list(range(a, b + 1)) if c % x == 0]))
1
564,055,926,670
null
44
44
a = [list(map(int,input().split())) for i in range(3)] n = int(input()) b = [int(input()) for i in range(n)] for i in range(3): for j in range(3): if a[i][j] in b: a[i][j] = "o" for i in range(3): if a[i][0] == a[i][1] == a[i][2]: print("Yes") exit() elif a[0][i] == a[1][i] == a[2][i]: print("Yes") exit() elif a[0][0] == a[1][1] == a[2][2]: print("Yes") exit() elif a[0][2] == a[1][1] == a[2][0]: print("Yes") exit() elif i == 2: print("No")
# coding: utf-8 # Your code here! N=int(input()) A=list(map(int,input().split())) if A[0]==1: if N==0: pass else: print(-1) exit() elif A[0]>1: print(-1) exit() limit=[1] for a in A[1:]: limit.append(limit[-1]*2-a) A=A[::-1] limit=limit[::-1] ans=A[0] temp=A[0] for i in range(len(limit)-1): a=limit[i+1] b=temp x=b-a y=a-x if x<0: x=0 y=temp elif y<0: print(-1) exit() temp=x+y+A[i+1] ans+=temp print(ans)
0
null
39,540,248,039,242
207
141
# 146A # 日曜日が何日後なのか # 入力 s = str(input()) # 処理 if s == "SUN": print(7) elif s == "MON": print(6) elif s == "TUE": print(5) elif s == "WED": print(4) elif s == "THU": print(3) elif s == "FRI": print(2) elif s == "SAT": print(1)
s = input() x = 7 if s == "SUN": pass elif s == "SAT": x = x - 6 elif s == "FRI": x = x - 5 elif s == "THU": x = x - 4 elif s == "WED": x = x - 3 elif s == "TUE": x = x - 2 elif s == "MON": x = x - 1 print(x)
1
132,909,761,368,010
null
270
270
while 1: x, y = map(int, raw_input().split()) if x == 0 and y == 0: break if x > y: print "%d %d" % (y, x) else: print "%d %d" % (x, y)
a,b = input().split() if int(a * int(b))>= int(b *int(b)): print(b*int(a)) else: print(a*int(b))
0
null
42,310,906,845,572
43
232
x,y,a,b,c=[int(i) for i in input().split()] p=[int(i) for i in input().split()] q=[int(i) for i in input().split()] r=[int(i) for i in input().split()] p.sort() q.sort() r.sort() p=p[-x:] q=q[-y:] ans=p+q+r ans.sort() ans=ans[-x-y:] print(sum(ans))
X, Y, A, B, C = map(int, input().split()) P = list(map(int, input().split())) Q = list(map(int, input().split())) R = list(map(int, input().split())) P = sorted(P, reverse=True)[:X] Q = sorted(Q, reverse=True)[:Y] R = sorted(R, reverse=True) L = sorted(P + Q + R, reverse=True) print(sum(L[:X+Y]))
1
44,933,027,213,732
null
188
188
c= '123' a= str(input()) b= str(input()) c= c.replace(a, '') c= c.replace(b, '') print(c)
class Comb(): def __init__(self, n, p): # O(n) fct, inv = [1, 1], [1, 1] a, b = 1, 1 for i in range(2, n + 1): a = (a * i) % p b = (b * pow(i, p - 2, p)) % p fct.append(a) inv.append(b) self.fct = fct self.inv = inv self.n = n self.p = p def calc(self, n, r): fct, inv = self.fct, self.inv if (r < 0 or n < r): return 0 else: return fct[n] * inv[r] * inv[n - r] % p N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() B = A[::-1] p = 10 ** 9 + 7 cmb = Comb(N, p) ans = 0 for n in range(N - K + 1): c = cmb.calc(N - n - 1, K-1) ans -= A[n] * c % p ans += B[n] * c % p print(ans % p)
0
null
103,361,134,224,740
254
242
ABC = input().split() a = int(ABC[0]) b = int(ABC[1]) c = int(ABC[2]) i = 0 while a<=b: if c%a==0: i = i+1 a = a+1 print(i)
num = [int(x) for x in input().split() if x.isdigit()] count = 0 for i in range(num[0], num[1]+1): if num[2] % i == 0: count += 1 print(count)
1
557,642,211,360
null
44
44
from collections import defaultdict n = int(input()) dic = defaultdict(lambda: 0) for _ in range(n): com = input().split(' ') if com[0]=='insert': dic[com[1]] = 1 else: if com[1] in dic: print('yes') else: print('no')
# 初期入力 from copy import copy K = int(input()) # lunlun_start =["1","2","3","4","5","6","7","8","9"] lunlun_roop =copy(lunlun_start) lunlun =[] ans =copy(lunlun_start) x="" while len(ans) <K: #for i in range(1,10): lunlun =[] for i in lunlun_roop: if i[-1] =="0": lunlun.append(i+"0") lunlun.append(i+"1") elif i[-1] =="9": lunlun.append(i+"8") lunlun.append(i+"9") else: x =int(i+i[-1])-1 lunlun.append((str(x) )) x +=1 lunlun.append((str(x) )) x +=1 lunlun.append((str(x) )) if len(lunlun) >K: break lunlun_roop =copy(lunlun) ans.extend(lunlun) print(ans[K-1])
0
null
20,112,825,009,172
23
181
n=int(input()) a=list(map(int,input().split())) ans = [] for i in range(n): ans.append(0) for i in range(n): ans[a[i]-1] = i +1 for i in range(len(ans)): print(ans[i], end=" ")
n,m = map(int, input().split()) class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if(x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める elif(self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): print(self.root) return -self.root[self.Find_Root(x)] def Output(self): return [i for i in self.root if i < 0] uf = UnionFind(n) for i in range(m): ab = list(map(int, input().split())) uf.Unite(ab[0],ab[1]) #print(uf.Output()) print(len(uf.Output())-2)
0
null
91,151,645,112,612
299
70
n = int(input()) R = [] for _ in range(n): R.append(int(input())) maxv = R[1] - R[0] minv = R[0] for j in range(1, n): maxv = max(R[j] - minv, maxv) minv = min(R[j],minv) print(maxv)
n = input() R = [] for i in range(n): R.append(input()) min_v = R[0] max_v = -1000000000000 for i in range(1, n): temp = R[i] - min_v if (temp >= max_v): max_v = temp temp = R[i] if (min_v >= temp): min_v = temp print max_v
1
11,919,249,412
null
13
13
import itertools def main(): N = int(input()) n_x_y = {} for n in range(N): A = int(input()) x_y = {} for _ in range(A): x, y = map(int, input().split()) x_y[x-1] = y n_x_y[n] = x_y ans = 0 for flags in itertools.product([1, 0], repeat=N): sat = True for n, flag in enumerate(flags): if flag == 0: continue for x, y in n_x_y[n].items(): if (y == 1 and flags[x] == 0) or (y == 0 and flags[x] == 1): sat = False break if sat is False: break if sat is True and sum(flags) > ans: ans = sum(flags) print(ans) if __name__ == '__main__': main()
# -*- coding:utf-8 -*- import math n = int(input()) ret_just = math.floor(n/1.08) ret_minus1 = ret_just - 1 ret_plus1 = ret_just + 1 if math.floor(ret_just*1.08) == n: print(ret_just) elif math.floor(ret_minus1*1.08) == n: print(ret_minus1) elif math.floor(ret_plus1*1.08) == n: print(ret_plus1) else: print(":(")
0
null
123,258,740,556,578
262
265
for i in range(1,10): for j in range(1,10): print("{i}x{j}={k}".format(i=i, j=j, k=i*j))
import sys write=sys.stdout.write for i in range(1,10): for j in range(1,10): write(str(i)) write('x') write(str(j)) write('=') write(str(i*j)) print()
1
2,028,348
null
1
1
N,K = map(int,input().split()) m = N%K print(min(m,K-m))
N,K=map(int,input().split()) if N%K != 0: if abs(K-N%K)<N: print(K-N%K) else: print(N) else: print(0)
1
39,130,286,478,228
null
180
180
a,b=input().split() A=a*int(b) B=b*int(a) if A[0] > B[0]: print(B) else: print(A)
def main(): N = int(input()) dp = [[0] * 10 for _ in range(10)] for i in range(1,N+1): tmp = str(i) left = int(tmp[0]) right = int(tmp[-1]) if left == 0 or right == 0: continue dp[left][right] += 1 ans = 0 for i in range(10): for j in range(10): ans += dp[i][j] * dp[j][i] print(ans) if __name__ == "__main__": main()
0
null
85,471,482,935,018
232
234
n, m = list(map(int, input().split())) h = list(map(int, input().split())) routes = [[] for _ in range(len(h) + 1)] for _ in range(m): a, b = list(map(int, input().split())) routes[a].append(b) routes[b].append(a) good = 0 for i in range(1, len(routes)): if len(routes[i]) == 0: good += 1 continue if h[i - 1] > max([h[j - 1] for j in routes[i]]): good += 1 print(good)
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,M=map(int,input().split()) h=list(map(int,input().split())) edge=[[] for _ in range(N)] for _ in range(M): a,b=map(int1,input().split()) edge[a].append(b) edge[b].append(a) ans=0 for i in range(N): for nv in edge[i]: if h[nv]>=h[i]: break else: ans+=1 print(ans)
1
25,171,867,191,170
null
155
155
H=int(input()) if H==1: print(1) else: i=1 count=1 while H//2!=1: i*=2 count+=i H=H//2 i*=2 count+=i print(count)
import numpy as np from collections import Counter from math import sqrt from time import time def main(): N = int(input()) np_a_o = list([int(x) for x in input().split()]) np_a = Counter(np_a_o) np_a_keys = set(np_a.keys()) div_list = set() key_max = max(np_a_keys) c = 0 for key in np_a_keys: for div in range(key*2, key_max+1, key): div_list.add(div) r = np_a_keys - div_list u, count = np.unique(np.array(np_a_o), return_counts=True) r -= set(u[count > 1]) print(len(r)) if __name__ == '__main__': main()
0
null
47,248,308,686,660
228
129
n = int(input()) dna = set() for i in range(n): command = input().split() if command[0] == 'insert': dna.add(command[1]) else: print('yes' if command[1] in dna else 'no')
#!/usr/bin/env python # coding: utf-8 # In[21]: N,K = map(int, input().split()) R,S,P = map(int,input().split()) T = input() # In[22]: points = {} points["r"] = P points["s"] = R points["p"] = S ans = 0 mylist = [] for i in range(N): mylist.append(T[i]) if i >= K: if T[i] == mylist[-K-1]: mylist[-1] = "x" else: ans += points[T[i]] else: ans += points[T[i]] print(ans) # In[ ]:
0
null
53,393,295,947,310
23
251
from math import ceil def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) def check(Min): kill = 0 for a in A: kill += (ceil(a/Min)-1) return kill <= K l = 0 r = 1000000000 while r-l > 1: mid = (l+r)//2 if check(mid): r = mid else: l = mid print(r) if __name__ == '__main__': main()
n, k = map(int, input().split()) p = list(map(int, input().split())) e = [] for i in range(n): e.append(p[i] + 1) sum_e = [0] for i in range(1,n+1): sum_e.append(sum_e[i-1]+e[i-1]) ans = [] for i in range(n-k+1): ans.append(sum_e[i+k]-sum_e[i]) print(max(ans)/2)
0
null
40,565,326,997,958
99
223
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()) dct = {} A = list(map(int, input().split())) for a in A: if a in dct.keys(): dct[a] += 1 else: dct[a] = 1 for n in range(1, N+1): print(dct.get(n, 0))
1
32,525,226,026,192
null
169
169
def count(word, text): """Count the word in text. Counting is done case-insensitively. >>> count('a', 'A b c a') 2 >>> count('computer', 'Nurtures computer scientists' \ + ' and highly-skilled computer engineers' \ + ' who will create and exploit "knowledge"' \ + ' for the new era. Provides an outstanding' \ + ' computer environment.') 3 """ return (text .lower() .split() .count(word.lower())) def run(): word = input() text = "" line = input() while line != "END_OF_TEXT": text += line + "\n" line = input() print(count(word, text)) if __name__ == "__main__": run()
alp=list("abcdefghijklmnopqrstuvwxyz") print(alp[alp.index(input())+1])
0
null
46,868,661,819,210
65
239
a,b,c=map(int, input().split(" ")) if a>c : k=c c=a a=k if c<b : k=b b=c c=k if b<a : k=b b=a a=k a,b,c=map(str,(a,b,c)) print(a+' '+b+' '+c)
n,k=map(int,(input().split())) ans=0 max=sum(range(n-k+1,n+1))*(n-k+2) min=sum(range(k))*(n-k+2) for i in range(1,n-k+2): min+=(k-1+i)*(n-k+2-i) for i in range(1,n-k+2): max+=(n-k+1-i)*(n-k+2-i) ans=(max-min+n-k+2)%(10**9+7) print(ans)
0
null
16,671,869,695,990
40
170
import sys def input(): return sys.stdin.readline().rstrip() import math X = int(input()) ans = False money = 100 year = 0 while money < X: money += money // 100 year += 1 print(year)
n = int(input()) c0 = 0 c1 = 0 c2 = 0 c3 = 0 for i in range(n): c = input() if c == 'AC': c0 += 1 elif c == 'WA': c1 += 1 elif c == 'TLE': c2 += 1 else: c3 += 1 print(f'AC x {c0}') print(f'WA x {c1}') print(f'TLE x {c2}') print(f'RE x {c3}')
0
null
17,959,524,744,792
159
109
from collections import Counter n = int(input()) s = [input() for _ in range(n)] c = Counter(s) csort = sorted(c.items(), key=lambda x:x[1],reverse=True) maxc = csort[0][1] ans = [] for s,v in csort: if v == maxc: ans.append(s) anssort = sorted(ans) for s in anssort: print(s)
n = int(input()) d = {} for i in range(n): s = str(input()) if s in d.keys(): d[s] += 1 else: d[s] = 1 max_count = max(d.values()) for i in sorted(d.keys()): if d[i] == max_count: print(i)
1
69,700,860,662,640
null
218
218
import math m=10**2 for i in range(input()): m*=1.05 m=math.ceil(m) print int(m*(10**3))
import bisect import copy import heapq import math import sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) sys.setrecursionlimit(5000000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] s=input() lns=len(s) lst=[0]*(lns+1) start=[] if s[0]=="<": start.append(0) for i in range(lns-1): if s[i]==">" and s[i+1]=="<": start.append(i+1) if s[lns-1]==">": start.append(lns) for i in start: d=deque([[i,0],[i,1]]) while d: now,lr=d.popleft() # print(now) if now-1>=0 and lr==0 and s[now-1]==">": lst[now-1]=max(lst[now-1],lst[now]+1) d.append([now-1,0]) if now+1<=lns and lr==1 and s[now]=="<": lst[now+1]=max(lst[now+1],lst[now]+1) d.append([now+1,1]) # print(lst) # print(start) # print(lst) print(sum(lst))
0
null
78,079,465,578,432
6
285
while True: result = set() n, x = map(int, raw_input().split()) if n == 0 and x == 0: break else: for i in range(1, n + 1): for j in range(i, n + 1): for k in range(j, n + 1): if i + j + k == x and i != j and j != k and k != i: temp = [i, j, k] sorted(temp) temp = tuple(temp) result.add(temp) print(len(result))
def solve(n,x): count = 0 for i in range(1,n+1): for j in range(i+1,n+1): k = x - i - j if j < k and k <= n: count += 1 return count while True: n,x = map(int,input().split()) if n == x == 0: break; print(solve(n,x))
1
1,271,457,340,298
null
58
58
from sys import stdin import numpy as np n, k = map(int, stdin.buffer.readline().split()) a = np.fromstring(stdin.buffer.read(), dtype=np.int, sep=' ') ng = 0 ok = 10 ** 9 + 1 while ok - ng > 1: mid = (ok + ng) >> 1 if np.sum(np.ceil(a / mid) - 1) <= k: ok = mid else: ng = mid print(ok)
import sys readline = sys.stdin.readline from bisect import bisect_left, insort_left def main(): n = int(readline()) s = list(readline().rstrip()) q = int(readline()) chk_abc = [[] for i in range(26)] for i, si in enumerate(s): ci = ord(si) - 97 chk_abc[ci].append(i) ans = [] for _ in range(q): cmd, i, j = readline().rstrip().split() i = int(i) - 1 if cmd == "1": if s[i] == j: continue c1 = ord(s[i]) - 97 prev = chk_abc[c1] c2 = ord(j) - 97 prev.pop(bisect_left(prev, i)) s[i] = j insort_left(chk_abc[c2], i) else: j = int(j) - 1 num = 0 for chk in chk_abc: le = len(chk) k = bisect_left(chk, i, 0, le) if k == le: continue if i <= chk[k] <= j: num += 1 ans.append(num) print(*ans, sep="\n") if __name__ == "__main__": main()
0
null
34,696,083,041,970
99
210
import sys readline = sys.stdin.readline N,X,M = map(int,readline().split()) MAXD = 55 # nex[t][v] = v (mod M)から2 ** tステップ進んだ先の値 # まずnex[0][v] は、v (mod M)から1ステップ進んだ先の値を入れておく # sums[t][v] = v (mod M)から2 ** tステップ進んだ総和 # まずsums[0][v]は、各項がvそのものになる(1ステップだから) nex = [[-1] * M for i in range(MAXD + 1)] sums = [[0] * M for i in range(MAXD + 1)] # まず、1ステップ進んだ先の値を入れる for r in range(M): nex[0][r] = r * r % M sums[0][r] = r for p in range(MAXD): for r in range(M): nex[p + 1][r] = nex[p][nex[p][r]] sums[p + 1][r] = sums[p][r] + sums[p][nex[p][r]] # 最初は、1ステップ(今いる場所)の場合の総和が入っている。次の進み先の総和と足すことで、 # 今いる場所と次の場所の総和となり、2つ進んだ場合の総和が求められる # これで2つ進んだ場合の総和を求めるリストになるため、 # ここで同じことをやることで、「2つ分の総和とその次の2つ分の総和」->「4つ分の総和」となる res = 0 cur = X for p in range(MAXD, -1, -1): if N & (1 << p): res += sums[p][cur] cur = nex[p][cur] print(res)
N,X,M=map(int,input().split()) a=[0]*(M) A=X%M a[A]=1 ans=A Ans=[A] flag=0 for i in range(N-1): A=A*A%M if A==0: break if a[A]==1: flag=1 break a[A]=1 ans+=A Ans.append(A) if flag==1: for num in range(len(Ans)): if A==Ans[num]: break n=len(Ans)-num b=sum(Ans[:num]) x=(N-num)//n y=(N-num)%n Sum=b+(ans-b)*(x)+sum(Ans[num:y+num]) else: Sum=sum(Ans) print(Sum)
1
2,811,170,378,416
null
75
75
N=input() N=list(N) N=map(lambda x: int(x),N) if sum(N)%9==0: print("Yes") else: print("No")
m = input("") s = m.split(".") sum = 0 if len(s) == 1 and int(m)>=0 and int(m)<10**200000: for i in m : sum = sum+int(i) if sum % 9 == 0: print("Yes") else: print("No")
1
4,369,236,533,762
null
87
87
import string from itertools import zip_longest turn = int(input()) dic = {s: i for i, s in enumerate(string.ascii_lowercase)} t_s, h_s = 0, 0 for _ in range(turn): t, h = input().split() if t == h: t_s += 1 h_s += 1 for t_c, h_c in zip_longest(t, h, fillvalue='a'): if dic[t_c] > dic[h_c]: t_s += 3 break elif dic[t_c] < dic[h_c]: h_s += 3 break print(t_s, h_s)
import sys n = int(sys.stdin.readline()) points = [0, 0] for i in range(n): (taro, hanako) = sys.stdin.readline().split() if taro < hanako: points[1] += 3 elif taro > hanako: points[0] += 3 else: points[0] += 1 points[1] += 1 print(points[0], points[1])
1
2,010,946,660,228
null
67
67
n=int(input()) s=list(map(int,input().split())) p=[0]*n for i in range(n): p[s[i]-1]=i+1 print(*p)
a,b,c,d=map(int,input().split()) for i in range(1001): if i%2==0: c-=b if c<=0: print("Yes") exit(0) else: a-=d if a<=0: print("No") exit(0)
0
null
105,143,180,957,240
299
164
""" タグ:区間 """ import sys input = sys.stdin.readline N, P = map(int, input().split()) S = input().strip() if P == 5: res = 0 i = 0 for s in reversed(S): if int(s)%5==0: res += N-i i += 1 print(res) elif P == 2: res = 0 i = 0 for s in reversed(S): if int(s)%2==0: res += N-i i += 1 print(res) else: T = [0] p = 1 for s in reversed(S): T.append(int(s)*p + T[-1]) p = p*10%P cnt = [0]*P for i in range(N+1): cnt[T[i]%P] += 1 res = 0 for c in cnt: res += c*(c-1)//2 print(res)
import math a,b,deg = map(float,input().split(" ")) sindeg = math.sin(math.radians(deg)) S = (a*b*sindeg)/2 cosdeg = math.cos(math.radians(deg)) z = a*a + b*b - 2*a*b*cosdeg L = a + b + math.sqrt(z) h = b*sindeg print("{:.5f}".format(S)) print("{:.5f}".format(L)) print("{:.5f}".format(h))
0
null
29,046,869,777,060
205
30
s1, s2 = input().split() n1, n2 = map(int, input().split()) u = input() if u == s1: n1 -= 1 else: n2 -= 1 print(n1, n2)
import sys import time import math def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ A, B = map(int, input().split()) print(A*B // math.gcd(A,B)) # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
0
null
92,583,546,892,390
220
256
n = int(input().split()[0]) c = list(filter(lambda x:x <= n,map(int,input().split()))) m = len(c) minimum = [ i for i in range(n+1) ] for i in c: minimum[i] = 1 for i in range(1,n+1): if minimum[i] <= 2: continue for j in range(m): if c[j]<=i and minimum[i-c[j]] + 1 < minimum[i]: minimum[i] = minimum[i-c[j]]+1 print(minimum[n])
n,m=map(int,input().split()) c=list(map(int,input().split())) c.sort() # print(c) #DB dp=[[0 for j in range(n+1)] for i in range(m)] # i番目(0<=i<=m-1)までのコインを使用してj円(0<=j<=n)を支払う際の最少の枚数 for j in range(n+1): dp[0][j]=j for i in range(1,m): for j in range(n+1): if j<c[i]: dp[i][j]=dp[i-1][j] else: dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1) # print(c[i],dp[i]) #DB print(dp[m-1][n])
1
135,741,043,580
null
28
28
N,A,B = map(int,input().split()) mod = 10**9 + 7 def cmb(n,r,mod): a=1 b=1 r = min(r,n-r) for i in range(r): a = a*(n-i)%mod b = b*(i+1)%mod return a*pow(b,mod-2,mod)%mod all = pow(2,N,mod) + mod nCa = cmb(N,A,mod) nCb = cmb(N,B,mod) ans = all - nCa - nCb print((ans-1)%mod)
# D - Bouquet n,a,b = map(int,input().split()) MOD = 10**9+7 ans = pow(2,n,MOD)-1 a,b = min(a,b),max(a,b) tmp = 1 for i in range(1,a+1): tmp = tmp*(n+1-i)*pow(i,-1,MOD) tmp %= MOD ans = (ans-tmp)%MOD for i in range(a+1,b+1): tmp = tmp*(n+1-i)*pow(i,-1,MOD) tmp %= MOD ans = (ans-tmp)%MOD print(ans)
1
65,998,103,380,100
null
214
214
#import numpy as np import sys, math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial#, gcd from bisect import bisect_left, bisect_right #bisect_left(list, value) sys.setrecursionlimit(10**7) enu = enumerate MOD = 2019 def input(): return sys.stdin.readline()[:-1] pl = lambda x: print(*x, sep='\n') S = input() N = len(S) d = defaultdict(int) d[0] += 1 # nums = [0]*(N+1) m = 0 last = 0 dd = 1 for i in range(N): m += int(S[N-i-1])*dd m %= MOD # val = (int(S[i])*m + nums[i])%MOD # cnt += d[val] dd = (dd*10)%MOD d[m] += 1 cnt = 0 for i, v in d.items(): cnt += v*(v-1)//2 print(cnt)
#!/usr/bin/python3 # main n = int(input()) - 1 fib = [1, 2] for i in range(2, n + 1): fib.append(fib[i - 1] + fib[i - 2]) print(fib[n])
0
null
15,489,331,266,332
166
7
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS()) def main(): a, b = GIS() print(a * b) main()
INPUT = list(map(int, input().split())) print(INPUT[0]*INPUT[1])
1
15,756,584,409,908
null
133
133
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n,t = inpl() wv = [None] * n for i in range(n): a,b = inpl() wv[i] = (a,b) rwv = wv[::-1] udp = [[0] * t for _ in range(n)] ddp = [[0] * t for _ in range(n)] for i in range(n-1): w,v = wv[i] for j in range(t): if j < w: udp[i+1][j] = udp[i][j] else: udp[i+1][j] = max(udp[i][j], udp[i][j-w] + v) res = udp[n-1][t-1] + wv[n-1][1] for i in range(n-1): w,v = rwv[i] for j in range(t): if j < w: ddp[i+1][j] = ddp[i][j] else: ddp[i+1][j] = max(ddp[i][j], ddp[i][j-w] + v) res = max(res,ddp[n-1][t-1] + wv[0][1]) # print(res) for i in range(1,n-1): u = i; d = n-i-1 mx = 0 for j in range(t): tmp = udp[u][j] + ddp[d][t-1-j] mx = max(mx, tmp) res = max(res, mx + wv[i][1]) print(res)
A, B, H, M = map(int, input().split()) import math theta = (30 * H) - (5.5 * M) d2 = A * A + B * B - 2 * A * B * math.cos(math.radians(theta)) d = math.sqrt(d2) print(d)
0
null
85,507,269,822,492
282
144
m1,d1 = map(int,input().split()) m2,d2 = map(int,input().split()) print(1 if m1!=m2 else 0)
print(0-input().find(input()[:2]))
1
124,566,130,997,052
null
264
264
n,a,b = map(int,input().split()) A=n//(a+b) B=n%(a+b) ans = a * A if B>=a: ans += a else: ans += B print(ans)
n,a,b=map(int,input().split()) i=n%(a+b) if i>a: print(a*(n//(a+b))+a) else: print(a*(n//(a+b))+i)
1
55,620,050,740,188
null
202
202
n, k = map(int, input().split()); m = 998244353; a = [] for i in range(k): a.append(list(map(int, input().split()))) b = [0]*n; b.append(1); c = [0]*n; c.append(1) for i in range(1, n): d = 0 for j in range(k): d = (d+c[n+i-a[j][0]]-c[n+i-a[j][1]-1])%m b.append(d); c.append(c[-1]+d) print(b[-1]%m)
S = input() T = input() print("Yes") if S == T[:-1] else print("No")
0
null
11,934,958,799,000
74
147
n,m = map(int,input().split()) a = [int(s) for s in input().split()] daycount = 0 for i in range(m): daycount += a[i] if n - daycount >= 0: print(n - daycount) else: print(-1)
N, M = map(int, input().split()) A = list(map(int, input().split())) day = N - sum(A) if N - sum(A) >= 0: print(day) elif N - sum(A) < 0: print(-1)
1
31,960,500,071,520
null
168
168
n,m=map(int, input().split()) a=[int(x) for x in input().split()] kaisuu=0 for i in a: zantei=0 while True: if i%2==0: zantei+=1 i//=2 else: break if kaisuu==0: kaisuu=zantei else: if kaisuu!=zantei: print(0) exit() sks=a[0]//2 import math for i in range(1,len(a)): sks=sks*(a[i]//2)//(math.gcd(sks,a[i]//2)) ans=int(m/(2*sks)+(1/2)) print(ans)
n,m=map(int,input().split()) c=list(map(int,input().split())) dp=[10**5 for i in range(50001)] dp[0]=0 dp[1]=1 for i in range(1,n+1): for j in range(m): if i>=c[j]: dp[i]=min(dp[i-c[j]]+1,dp[i]) print(dp[n])
0
null
51,206,642,098,132
247
28
MOD = 10 ** 9 + 7 INF = 10 ** 20 import sys input = sys.stdin.readline sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) def main(): n = int(input()) a = list(map(int,input().split())) if n%2 == 0: ans1 = 0 ans2 = 0 for i in range(n): if i%2 == 0: ans1 += a[i] else: ans2 += a[i] ans = max(ans1,ans2) cuml = [0] * (n + 1) cumr = [0] * (n + 1) for i in range(n): if i == 0: cuml[i + 1] = a[i] else: cuml[i + 1] = cuml[i - 1] + a[i] for i in range(n - 1,-1,-1): if i == n - 1: cumr[i] = a[i] else: cumr[i] = cumr[i + 2] + a[i] for i in range(1,n - 2,2): ans = max(ans,cuml[i] + cumr[i + 2]) else: cuml = [0] * (n + 1) cumr = [0] * (n + 1) cumr2 = [0] * (n + 1) for i in range(n): if i == 0: cuml[i + 1] = a[i] else: cuml[i + 1] = cuml[i - 1] + a[i] for i in range(n - 1,-1,-1): if i == n - 1: cumr[i] = a[i] cumr2[i] = a[i] else: cumr[i] = cumr[i + 2] + a[i] if i%2 == 1: if i == n - 2: continue if i == n - 4: cumr2[i] = cumr2[i + 3] + a[i] else: cumr2[i] = max(cumr2[i + 2],cumr[i + 3]) + a[i] cumr.append(0) ans = -INF for i in range(n): ans = max(ans,cuml[i] + cumr[i + 2]) if i <= n - 6 and i%2 == 1: ans = max(ans,cuml[i] + cumr2[i + 2]) if i <= n - 4 and i%2 == 1: ans = max(ans,cuml[i] + cumr[i + 3]) print(ans) if __name__ =='__main__': main()
from collections import Counter def main(): n = int(input()) S = [input() for _ in range(n)] S_c = Counter(S) num = list(S_c.values()).count(max(list(S_c.values()))) anss = S_c.most_common()[:num] for ans in sorted(anss): print(ans[0]) if __name__ == '__main__': main()
0
null
53,484,740,843,420
177
218
import sys input = sys.stdin.readline n = int(input()) S = list(map(int, input().split())) SENTINEL = 1000000005 merge_count = 0 def main(): mergeSort(S, 0, len(S)) print(' '.join(map(str, S))) print(merge_count) def merge(A, left, mid, right): # print("---merge start---") # print("A is {}".format(A)) # print("left:{0}, mid:{1}, right{2}".format(left, mid, right)) global merge_count L = A[left:mid] + [SENTINEL] R = A[mid:right] + [SENTINEL] # print("L:{}".format(L)) # print("R:{}".format(R)) i, j = 0, 0 for k in range(left, right, 1): merge_count += 1 # print("k:{0}".format(k)) if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 # print("A is {}".format(A)) # print("----merge end----".format(A)) def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) // 2 # print("------mergeSort start--------") # print("left:{0}, mid:{1}, right:{2}".format(left, mid, right)) mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) if __name__ == '__main__': main()
SENTINEL = 10**9 + 1 def merge_sort(alist): """Sort alist using mergesort. Returns a tuple of the number of comparisons and sorted list. >>> merge_sort([8, 5, 9, 2, 6, 3, 7, 1, 10, 4]) (34, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) """ def _sort(left, right): count = 0 if left + 1 < right: mid = (left + right) // 2 count += _sort(left, mid) count += _sort(mid, right) count += merge(left, mid, right) return count def merge(left, mid, right): count = 0 ll = alist[left:mid] + [SENTINEL] rl = alist[mid:right] + [SENTINEL] i = j = 0 for k in range(left, right): count += 1 if ll[i] <= rl[j]: alist[k] = ll[i] i += 1 else: alist[k] = rl[j] j += 1 return count comp = _sort(0, len(alist)) return (comp, alist) def run(): _ = int(input()) # flake8: noqa li = [int(i) for i in input().split()] (c, s) = merge_sort(li) print(" ".join([str(i) for i in s])) print(c) if __name__ == '__main__': run()
1
111,867,938,432
null
26
26
n,k=map(int,input().split()) r,s,p = map(int,input().split()) T=list(input()) a=[[] for i in range(k)] for i in range(n): a[i%k].append(T[i]) score=0 for j in range(k): b=a[j] flg=0 for l in range(len(b)): if l==0: if b[l]=='r': score+=p elif b[l]=='s': score+=r elif b[l]=='p': score+=s else: if b[l-1]==b[l] and flg==0: flg=1 continue elif b[l-1]==b[l] and flg==1: if b[l]=='r': score+=p elif b[l]=='s': score+=r elif b[l]=='p': score+=s flg=0 elif b[l-1]!=b[l]: if b[l]=='r': score+=p elif b[l]=='s': score+=r elif b[l]=='p': score+=s flg=0 print(score)
N, K = [int(x) for x in input().split()] R, S, P = [int(x) for x in input().split()] T = input() point = {'r':P, 's':R, 'p':S} win = [False] * N total = 0 for i in range(N): if i < K or T[i] != T[i - K] or win[i - K] == False: total += point[T[i]] win[i] = True print(total)
1
106,595,031,591,772
null
251
251
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(): a, b = map(int, readline().split()) s1 = str(a) * b s2 = str(b) * a if s1 < s2: print(s1) else: print(s2) return if __name__ == '__main__': main()
import queue N = int(input()) G = [] for _ in range(N): u, n, *K = map(int, input().split()) G.append((u - 1, [k - 1 for k in K])) Q = queue.Queue() Q.put(G[0]) dist = [-1] * N dist[0] = 0 while not Q.empty(): U = Q.get() for u in U[1]: if dist[u] == -1: Q.put(G[u]) dist[u] = dist[U[0]] + 1 for i, time in enumerate(dist): print(i + 1, time)
0
null
41,986,339,274,502
232
9
x = input() ans = 'A' if x in ('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') else 'a' print(ans)
from collections import defaultdict # ---------- INF = float("inf") MOD = 10 ** 9 + 7 # ---------- def combination(a, b): if b > a - b: return combination(a, a - b) return fact[a] * ifact[b] * ifact[a-b] K = int(input()) S = input().strip() N = len(S) # 階乗を前処理 fact = defaultdict(int) fact[0] = 1 for i in range(1, N+K+1): fact[i] = fact[i-1] * i fact[i] %= MOD # 階乗の逆元を前処理 ifact = defaultdict(int) ifact[N+K] = pow(fact[N+K], MOD-2, MOD) for i in reversed(range(1, N+K+1)): ifact[i-1] = ifact[i] * i ifact[i-1] %= MOD ans = 0 for i in range(K+1): now = pow(26, K-i, MOD) now *= pow(25, i, MOD) now %= MOD now *= combination(i+N-1, N-1) now %= MOD ans += now ans %= MOD print(ans)
0
null
12,003,580,664,128
119
124
N,M = map(int,input().split()) from collections import deque g = [[] for _ in range(N)] for _ in range(M): a,b = map(int,input().split()) g[a-1].append(b-1) g[b-1].append(a-1) dist = [float('inf')]*(N) ans = [0]*N dist[0] = 0 q = deque([]) q.append((0,0)) while q: idx,d = q.popleft() for nxt in g[idx]: if d + 1 < dist[nxt]: ans[nxt] = idx+1 dist[nxt] = d+1 q.append((nxt,d+1)) for i in range(N): if dist[i]==float('inf'): print('No');exit() print('Yes') for i in range(1,N): print(ans[i])
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) a = LI() s = sum(a) if s >= 22: print('bust') else: print('win')
0
null
69,784,511,074,670
145
260
while(True): h,w = [int(i) for i in input().split()] if h == 0 and w == 0: break for i in range(h): out = '' for j in range(w): if j == 0 or j == (w-1) or i == 0 or i == (h-1): out += '#' else : out += '.' print(out) print('')
p, q = 0, 1 for x in map(int, input()): p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x) print(p)
0
null
35,838,991,063,592
50
219
a, b, c, k = map(int, input().split()) if k <= a: print(k) if a < k <= a+b: print(a) if a+b < k <= a+b+c: print(a+(-1)*(k-a-b))
a,b=map(int,input().split()) x=a-(b+b) print(x if x>=0 else 0)
0
null
93,803,019,434,758
148
291
S = input() s = S[::-1] cnt = [0]*2019 cnt[0] = 1 number = 0 d = 1 for i in s: number += int(i)*d cnt[number % 2019] += 1 d *= 10 d = d % 2019 ans = 0 for i in cnt: ans += i*(i-1) // 2 print(ans)
import sys input = sys.stdin.readline N = int(input()) op = [] ed = [] mid = [0] dg = 10**7 for _ in range(N): s = list(input()) n = len(s)-1 a,b,st = 0,0,0 for e in s: if e == '(': st += 1 elif e == ')': if st > 0: st -= 1 else: a += 1 st = 0 for i in range(n-1,-1,-1): if s[i] == ')': st += 1 else: if st > 0: st -= 1 else: b += 1 if a > b: ed.append(b*dg + a) elif a == b: mid.append(a) else: op.append(a*dg + b) op.sort() ed.sort() p = 0 for e in op: a,b = divmod(e,dg) if p < a: print('No') exit() p += b-a q = 0 for e in ed: b,a = divmod(e,dg) if q < b: print('No') exit() q += a-b if p == q and p >= max(mid): print('Yes') else: print('No')
0
null
27,094,250,610,560
166
152
t1,t2=map(int,input().split()) a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) d1=t1*a1+t2*a2 d2=t1*b1+t2*b2 import sys if d1>d2: dif=d1-d2 gap=(b1-a1)*t1 elif d1<d2: dif=d2-d1 gap=(a1-b1)*t1 else: print('infinity') sys.exit() if (b1-a1)*(b2-a2)>0 or (b1-a1)*(d2-d1)>0: print(0) sys.exit() if gap%dif!=0: print(gap//dif*2+1) else: print(gap//dif*2)
from math import atan,pi a,b,x=map(int,input().split()) if b-x/a**2 <= x/a**2:print(atan((b-x/a**2)/(a/2))*(180/pi)) else: y = x/a*2/b print(atan(b/y)*(180/pi))
0
null
147,639,180,296,660
269
289
#from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 #R = 998244353 def ddprint(x): if DBG: print(x) n = inn() ls = [] rs = [] z = 0 for i in range(n): ss = ins() l = r = 0 for c in ss: if c=='(': l += 1 else: if l>0: l -= 1 else: r += 1 rr = r l = r = 0 for j in range(len(ss)-1,-1,-1): c = ss[j] if c==')': r += 1 else: if r>0: r -= 1 else: l += 1 r = rr if l>r: ls.append((r,l-r)) elif l<r: rs.append((l,r-l)) else: z = max(z,r) ls.sort() rs.sort() #ddprint(ls) #ddprint(rs) #ddprint(z) l = r = 0 for rr,ll in ls: if l<rr: print('No') exit() l = l+ll for ll,rr in rs: if r<ll: print('No') exit() r = r+rr print('Yes' if l==r>=z else 'No')
import sys input = sys.stdin.readline def main(): N = int( input()) S = [input().strip() for _ in range(N)] Up = [] Down = [] for s in S: now = 0 m = 0 for t in s: if t == "(": now += 1 else: now -= 1 if now < m: m = now # print(t, now) if now >= 0: Up.append((m,now)) else: Down.append((m-now,-now)) up = 0 Up.sort(reverse=True) for m, inc in Up: if up+m < 0: print("No") return up += inc down = 0 Down.sort(reverse=True) # print(Up, Down) for m, dec in Down: if down+m < 0: print("No") return down += dec if up != down: print("No") return print("Yes") if __name__ == '__main__': main()
1
23,732,909,656,476
null
152
152
import itertools N = int(input()) z = [] for i in range(N): x,y = map(int,input().split()) z.append((x,y)) ALL = 1 for i in range(N): ALL *= (i+1) base = [i for i in range(N)] A = list(itertools.permutations(base,N)) SUM = 0 def distance(a,b): ax = a[0]; ay = a[1] bx = b[0]; by = b[1] dis = ((ax-bx)**2 + (ay-by)**2)**(0.5) return dis for X in A: now = z[X[0]] for i in range(1,N): nxt = z[X[i]] dif = distance(now,nxt) #print(dif) SUM += dif #print(SUM,ALL) ans = SUM/ALL print(ans)
n = int(input()) a = list(map(int, input().split())) d = dict() for i in range(n): d[i] = 0 for e in a: d[e-1] += 1 for i in range(n): print(d[i])
0
null
90,753,531,286,600
280
169
S = input() arr = [0]*(len(S) + 1) cn = 0 for i in range(len(S)): if S[i] == "<": cn += 1 else: cn = 0 arr[i+1] = cn cn = 0 for i in range(len(S)-1, -1, -1): if S[i] == ">": cn += 1 else: cn = 0 arr[i] = max(arr[i], cn) # print(arr) print(sum(arr))
if __name__ == '__main__': M=998244353 n,m,k=map(int,input().split()) p,c=[m],[1] for i in range(1,n): p+=[p[-1]*(m-1)%M] c+=[c[-1]*(n-i)*pow(i,-1,M)%M] print(sum(p[n-i-1]*c[i] for i in range(k+1))%M)
0
null
89,982,416,665,910
285
151
N , M = map(int,input().split()) ans = 0 ans += N * (N - 1) // 2 ans += M * (M - 1) // 2 print( ans )
N,M = map(int,input().split()) ki = (N*(N-1))//2 gu = (M*(M-1))//2 print (ki+gu)
1
45,448,208,920,362
null
189
189
N = int(input()) *A ,=map(int,input().split()) count =0 for i in range(N): mini = i for j in range(i+1,N): if A[j] <A[mini]: mini = j A[mini],A[i] = A[i],A[mini] if (mini != i):count +=1 print(' '.join(list(map(str,A)))) print(count)
import itertools n = int(input()) p = tuple(map(int,input().split())) q = tuple(map(int,input().split())) r = list(itertools.permutations([i for i in range(1,n+1)])) P , Q = (r.index(p)), (r.index(q)) print(abs(P-Q))
0
null
50,428,897,894,030
15
246
n=int(input()) s=input() a=[s[0]] for i in range(1,n): if s[i]!=s[i-1]: a.append(s[i]) "".join(a) print(len(a))
a, b, c, d = map(int, input().split()) T = 0 A = 0 while a > 0: a -= d A += 1 while c > 0: c -= b T += 1 if A >= T: print("Yes") else: print("No")
0
null
99,905,540,672,448
293
164
n = int(input()) data = list(map(int, input().split())) for i in range(n): v = data[i] j = i - 1 while j >= 0 and data[j] > v: data[j+1] = data[j] j -= 1 data[j+1] = v print(" ".join(map(str, data)))
import sys def print_arr(arr): ln = '' for v in arr: ln += str(v) + ' ' ln = ln.strip() print(ln) def insertion_sort(arr): for i in range(1, len(arr)): print_arr(arr) v = arr[i] j = i-1 while j >= 0 and arr[j] > v: arr[j+1] = arr[j] j -= 1 arr[j+1] = v print_arr(arr) input0 = sys.stdin.readline() input_sample = sys.stdin.readline() # input_sample = "5 2 4 6 1 3" input = input_sample.split(" ") input = [int(i) for i in input] insertion_sort(input)
1
6,104,569,600
null
10
10
def modinv(a,m): return pow(a,m-2,m) n,k = map(int,input().split()) P = 10**9+7 ans = 1 nCl = 1 n1Cl = 1 for l in range(1,min(k+1,n)): nCl = nCl*(n+1-l)*modinv(l,P)%P n1Cl = n1Cl*(n-l)*modinv(l,P)%P ans = (ans+nCl*n1Cl)%P print(ans)
def readInt(): return list(map(int, input().split())) h, w = readInt() if h == 1 or w == 1: print(1) elif h*w%2 == 0: print(h*w//2) else: print(h*w//2+1)
0
null
58,856,234,343,492
215
196
a,b=input().split() A=int(a) B=int(b) aa=a bb=b for i in range(B-1): aa+=a for j in range(A-1): bb+=b if aa >= bb: print(bb) else: print(aa)
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(input()) XY = [[int(x) for x in input().split()] for _ in range(N)] arr1 = [] arr2 = [] for x, y in XY: arr1.append(x - y) arr2.append(x + y) print(max(abs(max(arr1) - min(arr1)), abs(max(arr2) - min(arr2)))) if __name__ == '__main__': main()
0
null
44,101,021,869,640
232
80
A, B, N = [int(x) for x in input().split()] Q = A // B R = A % B if R == 0: ans = Q * (B - 1) elif B <= N: ans = R - 1 + Q * (B - 1) else: ans = int(A * N / B) - A * int(N / B) print(ans)
import sys import math from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN from collections import deque from bisect import bisect_left from itertools import product def I(): 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 LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)] #文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる def LSI(): return list(map(int, list(sys.stdin.readline().rstrip()))) def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)] #文字列として取得 def ST(): return sys.stdin.readline().rstrip() def LST(): return sys.stdin.readline().rstrip().split() def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)] def FILL(i,h): return [i for j in range(h)] def FILL2(i,h,w): return [FILL(i,w) for j in range(h)] def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)] def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)] def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP) #'0.01'や'1E1'などで指定、整数に戻すならintをかます MOD = 1000000007 INF = float("inf") sys.setrecursionlimit(10**6+10) N = LSI() dp = [[INF]*2 for _ in range(len(N)+1)] #dp[i][0]が下からi桁めをぴったり払う最低枚数 dp[0][0] = 0 for i in range(len(N)): d = N[-(i+1)] dp[i+1][0] = min(dp[i][0] + d, dp[i][1] + d + 1) dp[i+1][1] = min(dp[i][0] + (10-d), dp[i][1] + (10-d) - 1) print(min(dp[-1][0], dp[-1][1]+1))
0
null
49,686,150,466,304
161
219
s = list(input()) for i in range(int(input())): cmd, a, b, *c = input().split() a = int(a); b = int(b) if cmd == "print": print(*s[a:b+1], sep='') elif cmd == "reverse": s[a:b+1] = reversed(s[a:b+1]) else: s[a:b+1] = c[0]
#coding: utf-8 s = input() q = int(input()) for i in range(q): order = input().split(" ") if order[0] == "print": print(s[int(order[1]) : int(order[2])+1]) elif order[0] == "reverse": r = s[int(order[1]) : int(order[2])+1] r = r[::-1] s = s[:int(order[1])] + r + s[int(order[2])+1:] elif order[0] == "replace": s = s[:int(order[1])] + order[3] + s[int(order[2])+1:]
1
2,077,176,778,742
null
68
68
#!/usr/bin/env python3 import sys from itertools import chain # floor(A x / B) - A * floor(x / B) # # x = B * x1 + x2 : (x2 < B) とする # # = floor(A (B*x1+x2) / B) - A floor((B*x1+x2) / B) # = A x1 + floor(A x2 / B) - A x1 # = floor(A x2 / B) def solve(A: int, B: int, N: int): if N >= B: x2 = B - 1 else: x2 = N return (A * x2) // B def main(): tokens = chain(*(line.split() for line in sys.stdin)) A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int N = int(next(tokens)) # type: int answer = solve(A, B, N) print(answer) if __name__ == "__main__": main()
N=int(input()) A=list(map(int,input().split())) M=1000 S=0 for i in range(N-1): if A[i+1]>A[i]: S+=M//A[i] M-=A[i]*(M//A[i]) else: M+=S*A[i] S=0 print(M+S*A[N-1])
0
null
17,593,704,583,612
161
103
N, K = map(int, input().split()) vec = [0] * N for _ in range(K): d = int(input()) A = list(map(int, input().split())) for i in range(d): vec[A[i]-1] += 1 print(vec.count(0))
n,k=map(int,input().split()) l=[0]*n for i in range(k): x=int(input()) d=list(map(int,input().split())) for i in d: l[i-1]+=1 c=0 for i in l: if(i==0): c=c+1 print(c)
1
24,510,809,363,222
null
154
154
H, W, K = map(int, input().split()) sl = [] for _ in range(H): sl.append(list(input())) ans = 10**8 for i in range(2 ** (H-1)): fail_flag = False comb = [] for j in range(H-1): if ((i >> j) & 1): comb.append(j) comb.append(H-1) # print(comb) sections = [] for k in range(0,len(comb)): if k == 0: sections.append( sl[0:comb[0]+1] ) else: sections.append( sl[comb[k-1]+1:comb[k]+1] ) # print(sections) partition_cnt = 0 sections_w_cnts = [0]*len(sections) for w in range(W): sections_curr_w_cnts = [0]*len(sections) partition_flag = False for i, sec in enumerate(sections): for row in sec: if row[w] == '1': sections_curr_w_cnts[i] += 1 sections_w_cnts[i] += 1 if sections_curr_w_cnts[i] > K: fail_flag = True break if sections_w_cnts[i] > K: partition_flag = True if fail_flag: break if fail_flag: break if partition_flag: sections_w_cnts = [v for v in sections_curr_w_cnts] # sections_w_cnts[:] = sections_curr_w_cnts[:] partition_cnt += 1 if not fail_flag: ans = min(len(comb)-1+partition_cnt, ans) print(ans)
h, w, k = map(int, input().split()) s = [list(map(int, list(input()))) for _ in range(h)] result = [] if h*w<=k: result.append(0) else: for i in range(2**(h-1)): checker, num, p = 0, i ,[0] for _ in range(h): p.append(p[-1]+num%2) checker += num%2 num >>= 1 x = 0 c = [0 for _ in range(checker+1)] for j in range(w): num = i nex = [0 for _ in range(checker+1)] for m in range(h): nex[p[m]] += s[m][j] if max(nex) > k: x = float('inf') break if all(nex[m]+c[m] <= k for m in range(checker+1)): c = [c[I]+nex[I] for I in range(checker+1)] else: x += 1 c = nex result.append(checker+x) print(min(result))
1
48,370,414,782,470
null
193
193
N, T = map(int, input().split()) ls = [] for i in range(N): a, b = map(int, input().split()) ls += [(a,b)] ls.sort(key=lambda x:x[0]) t = [[0]*T for i in range(N+1)] for i in range(1,N+1): a, b = ls[i-1] for j in range(T): if j-a>=0: t[i][j] = max(t[i-1][j-a]+b,t[i-1][j]) last = [0] for i in range(N-1,-1,-1): last += [max(last[-1], ls[i][-1])] ans = 0 for i in range(1,N+1): j = N-i ans = max(ans, last[j]+t[i][-1]) print(ans)
from collections import deque n = int(input()) G = [[] for _ in range(n)] for i in range(n): u, k, *vs = map(int, input().split()) u -= 1 vs = list(map(lambda x: x - 1, vs)) for v in vs: G[u].append(v) dist = [-1] * n dist[0] = 0 que = deque([0]) while len(que) > 0: now_v = que.popleft() now_dist = dist[now_v] next_vs = G[now_v] for next_v in next_vs: if dist[next_v] == -1: dist[next_v] = now_dist + 1 que.append(next_v) for i, x in enumerate(dist): print(i + 1, x)
0
null
76,103,192,569,300
282
9
n = input() l = map(int, raw_input().split()) k = 0 a = [] while n > 0: a.append(l[n - 1]) n -= 1 print ' '.join(map(str, a))
# -*- coding: utf-8 -*- n = input() l = map(int, raw_input().split()) for i in range(n-1): print l[n-i-1], print l[0]
1
996,263,029,462
null
53
53
n = int(input()) a = list(map(int,input().split())) ans = [0]*(n-1) for i in range(n-1): ans[a[i]-1] += 1 for i in range(n-1): print(ans[i]) print(0)
n = int(input()) a = list(map(int, input().split())) number_buka = [0]*n for i in a: number_buka[i-1] += 1 for j in number_buka: print(j)
1
32,700,689,788,690
null
169
169
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] def union(x,y): x = root(x) y = root(y) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 n, m = LI() par = [i for i in range(n)] rank = [0] * n for _ in range(m): a, b = LI() if root(a-1) != root(b-1): union(a-1, b-1) s = set() for i in range(n): s.add(root(i)) ans = len(s)-1 print(ans)
class UnionFind: def __init__(self, n): self.nodes = n self.parents = [i for i in range(n)] self.sizes = [1] * n self.rank = [0] * n def find(self, i): # どの集合に属しているか(根ノードの番号) if self.parents[i] == i: return i else: self.parents[i] = self.find(self.parents[i]) # 経路圧縮 return self.parents[i] def unite(self, i, j): # 二つの集合を併合 pi = self.find(i) pj = self.find(j) if pi != pj: if self.rank[pi] < self.rank[pj]: self.sizes[pj] += self.sizes[pi] self.parents[pi] = pj else: self.sizes[pi] += self.sizes[pj] self.parents[pj] = pi if self.rank[pi] == self.rank[pj]: self.rank[pi] += 1 def same(self, i, j): # 同じ集合に属するかを判定 return self.find(i)==self.find(j) def get_parents(self): # 根ノードの一覧を取得 for n in range(self.nodes): # findで経路圧縮する self.find(n) return self.parents adj = [] N, M = map(int,input().split()) for m in range(M): a,b = map(int,input().split()) adj.append([a-1,b-1]) uf = UnionFind(N) for i in range(M): # 取り除く辺番号 uf.unite(*adj[i]) ans=len(set(uf.get_parents())) # 複数の集合にわかれているか確認 print (ans-1)
1
2,299,432,972,320
null
70
70
import random s = input() len_s = len(s) if len_s==3: num = 0 else: num = random.randint(0,len_s-4) name = s[num]+s[num+1]+s[num+2] print(name)
line=input() print(line[:3])
1
14,768,268,558,762
null
130
130
l = [1,2,3] A = int(input()) B = int(input()) for i in range(3): if l[i]!=A and l[i]!=B: print(l[i])
def main(): N = int(input()) A,B = [],[] for _ in range(N): a,b = [int(x) for x in input().split()] A.append(a) B.append(b) A.sort() B.sort() if N % 2 == 1: minMed = A[N//2] maxMed = B[N//2] print(int(maxMed-minMed)+1) else: minMed = A[N//2-1] + A[N//2] maxMed = B[N//2-1] + B[N//2] print(int(maxMed-minMed)+1) if __name__ == '__main__': main()
0
null
63,814,484,273,540
254
137
a=100000 for i in range(int(input())): a *=1.05 if a%1000 !=0: a=a-(a%1000)+1000 print(int(a))
#162B #FizzBuzz Sum n=int(input()) print(sum(x for x in range(1,n+1) if x%3!=0 and x%5!=0))
0
null
17,558,177,908,764
6
173
x = list(map(int, input().split())) if 0 in x: ans = x.index(0) + 1 print(ans)
n = int(input()) g = n // 2 print((n-g) / n)
0
null
95,665,049,539,460
126
297
import math a, b, x = map(int, input().split()) x = x / a if x >= a*b/2: K = (a*b - x)/a*2 L = K/math.sqrt(K**2+a**2) ans = math.degrees(math.asin(L)) print(ans) else: K = 2*x/b L = b/math.sqrt(K**2+b**2) ans = math.degrees(math.asin(L)) print(ans)
import math a, b, t = map(int, input().strip().split()) t = math.radians(t) h = b * math.sin(t) l = a + b + math.sqrt(a*a + b*b - 2*a*b*math.cos(t)) s = a * h / 2 print(s) print(l) print(h)
0
null
81,678,966,405,482
289
30
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)
N, K = [int(i) for i in input().split(" ")] N = N % K if (K - N) < N: N = K - N print(N)
0
null
40,055,748,951,208
182
180
n = int(input()) x = list(map(int, input().split())) p = [0] * 100 for i in range(1, 101): for j in x: p[i-1] += (i - j)**2 print(min(p))
n, m = map(int, input().split()) c = [int(i) for i in input().split()] dp = [[-1 for _ in range(m + 1)] for _ in range(n + 1)] for i in range(1, n + 1): dp[i][1] = i for j in range(1, m + 1): dp[0][j] = 0 # dp[1][j] = 1 for i in range(n + 1): for j in range(1, m): if c[j] > i: dp[i][j + 1] = dp[i][j] else: dp[i][j + 1] = min(dp[i][j], dp[i - c[j]][j + 1] + 1) print(dp[n][m])
0
null
32,596,287,427,870
213
28
N, K = map(int, input().split()) MOD = 998244353 S = [] for _ in range(K): S.append(tuple(map(int, input().split()))) dp = [0] * (N + 1) dp[1] = 1 sum_list = [0] * (N + 1) sum_list[1] = 1 for i in range(2, N+1): for L, R in S: RR = i - L if RR <= 0: continue LL = max(1, i-R) if LL <= RR: t = sum_list[RR] - sum_list[LL-1] dp[i] += t dp[i] %= MOD sum_list[i] = (sum_list[i-1] + dp[i]) % MOD print(dp[N])
#! /usr/bin/env python3 import sys sys.setrecursionlimit(10**9) YES = "Yes" # type: str NO = "No" # type: str INF=10**20 def solve(A: int, B: int, C: int, D: int): while True: C-=B if C <= 0: print(YES) break A-=D if A <= 0: print(NO) break return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int D = int(next(tokens)) # type: int solve(A, B, C, D) if __name__ == "__main__": main()
0
null
16,305,612,254,442
74
164