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
D = int(input()) clist = list(map(int, input().split())) slist = [list(map(int, input().split())) for _ in range(D)] tlist = [int(input()) for _ in range(D)] zlist = [] dlist = [0] * 26 ans = 0 ''' print(sum(clist)) print('--------------') print(slist[0][0]) print(slist[1][16]) print(clist[16]) print('--------------') ''' for i in range(D): #print(slist[i],tlist[i]-1) zlist.append(clist[tlist[i]-1] * ((i+1) - dlist[tlist[i]-1])) dlist[tlist[i]-1] = i+1 ans += slist[i][tlist[i]-1] - ((i+1) * sum(clist)) + sum(zlist) print(ans)
n=int(input()) x=list(map(int,input().split())) ans=10**9 for i in range(1,101): tmp=0 for j in range(n): tmp+=(i-x[j])*(i-x[j]) ans=min(ans,tmp) print(ans)
0
null
37,585,960,554,888
114
213
from math import floor def main(): X=int(input()) tmp=100 for year in range(1,4000): tmp += tmp//100 if tmp >= X: print(year) exit() main()
a=int(input()) cnt=0 t=100 while t<a: t=(t*101)//100 cnt+=1 print(cnt)
1
27,240,505,192,656
null
159
159
def merge(a, l, m, r): global cnt ll = a[l:m] + [1e9 + 1] rl = a[m:r] + [1e9 + 1] i, j = 0, 0 for k in range(l, r): if ll[i] < rl[j]: a[k] = ll[i] i += 1 else: a[k] = rl[j] j += 1 cnt += 1 def merge_sort(a, l, r): if l + 1 < r: m = (l + r) // 2 merge_sort(a, l, m) merge_sort(a, m, r) merge(a, l, m, r) n, a, cnt = int(input()), list(map(int, input().split())), 0 merge_sort(a, 0, n) print(*a) print(cnt)
a,b,m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) xyc = [list(map(int,input().split())) for nesya in range(m)] cheap = min(a)+min(b) for hoge in xyc: ch = a[hoge[0]-1]+b[hoge[1]-1]-hoge[2] cheap = min(ch,cheap) print(cheap)
0
null
26,976,682,906,760
26
200
def main(): k = int(input()) s = input() if len(s) <= k: print(s) else: print(f"{s[:k]}...") if __name__ == "__main__": main()
import sys # \n def input(): return sys.stdin.readline().rstrip() def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort(reverse=True) # 0(NlogN) F.sort() # O(NlogN) def train(X, Y, T): # O(N) ans: 回数 ans = 0 for i in range(len(X)): ans += max(0, X[i] - T // Y[i]) return ans ok = 10**18+1 #時間 ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 #時間 ans = train(A,F,mid) #kaisuu if ans >K: ng =mid else: ok =mid print(ok) if __name__ == "__main__": main()
0
null
92,450,549,690,172
143
290
import sys [a, b, c] = [int(x) for x in sys.stdin.readline().split()] counter = 0 for value in range(a, b + 1): if c % value == 0: counter += 1 print(counter)
class MyClass(): def main(self): self.n = input() self.A = map(int,raw_input().split()) self.q = input() self.M = map(int,raw_input().split()) W = map(self.solve,self.M) for w in W: print w def solve(self,m): w = self.rec(m,self.A) if w: return "yes" else: return "no" def rec(self,m,A): if len(A) == 1: r1 = False else: r1 = self.rec(m,A[1:]) m_new = m - A[0] if m_new == 0: r2 = True elif len(A) > 1 and min(A[1:]) <= m_new <= sum(A[1:]): r2 = self.rec(m_new,A[1:]) else: r2 = False if r1 or r2: return True else: return False if __name__ == "__main__": MC = MyClass() MC.main()
0
null
325,857,653,022
44
25
def main(): n = int(input()) a = list(map(int,input().split())) flg=0 for i in range(0,n): if a[i]%2==0 : if a[i]%3!=0 and a[i]%5!=0 : flg=1 if flg==0: print("APPROVED") else: print("DENIED") main()
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() a = inpl() ans = 'APPROVED' for i in range(n): if a[i] % 2 == 0 and a[i] % 3 != 0 and a[i] % 5 != 0: ans = 'DENIED' print(ans)
1
68,748,301,920,848
null
217
217
S = input() K = int(input()) if len(S) == 1: print(K//2) exit() if len(set(S)) == 1: ans = len(S)*K//2 print(ans) exit() if S[0] != S[-1]: ans = 0 tmp = "" for s in S: if s == tmp: ans += 1 tmp = "" continue else: tmp = s ans *= K print(ans) exit() elif S[0] == S[-1]: A = 0 B = 0 for s in S: if s == S[0]: A+=1 else: break for s in S[::-1]: if s == S[0]: B+=1 else: break ans = 0 tmp = "" for s in S: if s == tmp: ans += 1 tmp = "" continue else: tmp = s ans *= K ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1) print(ans) exit()
S = list(input()) K = int(input()) def solve(S, K): T = S * K ans = 0 for i in range(len(T) - 1): if T[i] == T[i + 1]: ans += 1 T[i + 1] = "*" return ans A = [solve(S, i) for i in range(6)] if K <= 5: print(A[K]) else: if K % 2 == 1: d = A[5] - A[3] print(A[5] + (K - 5) // 2 * d) else: d = A[4] - A[2] print(A[4] + (K - 4) // 2 * d)
1
175,536,294,260,028
null
296
296
N = int(input()) L = list(map(int, input().split())) L.sort(reverse=True) total = 0 for i in range(N-2): a = L[i] for j in range(i+1, N-1): b = L[j] # j以降の項で、初めてL[k] < a-bとなるkを二分探索する if L[-1] > a - b: # 一番最後の項でもOKな場合(j+1以降全部OK) total += N - j - 1 elif L[j+1] <= a - b: # 一番最初の項からNGな場合 continue else: head = j+1 # head はL[head] > a - bを満たす(OK側) tail = N-1 # tail はL[tail] <= a - bを満たす(NG側) while head+1 != tail: if L[(head + tail)//2] > a - b: # 中間地点はOK側 head = (head + tail) // 2 else: # 中間地点はNG側 tail = (head + tail) // 2 total += head - j print(total)
inputs = [int(d) for d in input().split()] results = [] for i in (0, 1): for j in (2, 3): results.append(inputs[i] * inputs[j]) print(max(results))
0
null
87,647,435,214,592
294
77
while(1): str = raw_input() if str == "-": break else: m = int(raw_input()) for i in range(m): h = int(raw_input()) str = str[h:len(str)] + str[0:h] print str
while True: l = input() if l == '-': break deck = list(l) for i in range(int(input())): n = int(input()) deck = deck[n:] + deck[:n] print(''.join(deck))
1
1,935,367,321,230
null
66
66
XS = open(0).read().split() i = 0 while True: t = XS[i] i += 1 if t == "-": break n = int(XS[i]) i += 1 m = sum(map(int, XS[i:i+n])) % len(t) i += n print(t[m:] + t[:m])
while True: string = input() if string == "-": break else: s = 0 for i in range(int(input())): s += int(input()) s = s % len(string) print(string[s:len(string)] + string[0:s])
1
1,901,820,337,030
null
66
66
def solve(): a, b = map(int, input().split()) print(max(0, a-2*b)) if __name__ == '__main__': solve()
x = input() window = int(x.split()[0]) b = int(x.split()[1]) curtain = b * 2 if window > curtain: print(window - curtain) else: print('0')
1
166,867,004,082,126
null
291
291
h, w, k = map(int, input().split()) s = [input() for _ in range(h)] t = [[0] * w for _ in range(h)] n = 0 rows = [] for i in range(h): if s[i].count("#") == 0: rows.append(i) else: if s[i][0] == "#": for j in range(w): if s[i][j] == "#": n += 1 t[i][j] = n else: n += 1 f = 0 for j in range(w): if f and s[i][j] == "#": n += 1 elif s[i][j] == "#": f = 1 t[i][j] = n if rows != [] and rows[-1] == h-1: for k in range(h)[::-1]: if t[k][j] != 0: for j in range(w): t[rows[-1]][j] = t[k][j] break for i in rows: for k in range(i+1, h): if t[k][j] != 0: for j in range(w): t[i][j] = t[k][j] break for i in range(h): print(*t[i])
from collections import deque n = int(input()) d = deque() cmd = ['com', 0] for i in range(n): cmd = input().split() if cmd[0] == 'insert': d.appendleft(int(cmd[1])) elif cmd[0] == 'delete': try: d.remove(int(cmd[1])) except ValueError: pass elif cmd[0] == 'deleteFirst': d.popleft() elif cmd[0] == 'deleteLast': d.pop() print(*list(d))
0
null
71,999,140,331,012
277
20
s, t = [input() for _ in range(2)] print('Yes' if s == t[:len(s):] else 'No')
if int(input()) >= 30:print('Yes') else:print('No')
0
null
13,619,264,411,612
147
95
h,w,k = list(map(int, input().split())) s = [input() for _ in range(h)] strawberry = [] for i in s: if '#' in i: strawberry.append(True) else: strawberry.append(False) ans = [[0]*w for _ in range(h)] num = 0 for i in range(h): flag = 0 if strawberry[i]: num += 1 for j in range(w): if s[i][j]=='#': flag += 1 if flag==2: num += 1 flag = 1 ans[i][j] = num tmp = strawberry.index(True) for i in range(h): if strawberry[i]==False: ans[i] = ans[tmp] else: tmp = i for i in ans: print(' '.join(map(str,i)))
n = int(input()) p = list(map(int, input().split())) m = p[0] ans = 0 for i in p: if (m >= i): ans += 1 m = min(i,m) print(ans)
0
null
114,215,263,085,586
277
233
T = list(input()) ans = 0 for i in range(len(T)): if T[i]=="?": T[i]="D" print(*T, sep="")
N=int(input()) A=[int(i) for i in input().split()] S=0 for i in range(1,N): if A[i-1]>A[i]: S+=A[i-1]-A[i] A[i]=A[i-1] print(S)
0
null
11,571,033,386,318
140
88
k,s=int(input()),input();print([s[:k]+'...',s][len(s)<=k])
n = int(input()) s = input() print(s if len(s) <= n else s[:n] + '...')
1
19,849,038,385,120
null
143
143
n=list(map(int,input().split())) a=list(map(int,input().split())) count=0 for i in range(0,len(a)): if n[1]<=a[i]: count+=1 print(count)
N,M=map(int,input().split()) G=[[] for _ in range(N+1)] for i in range(M): a,b=map(int,input().split()) G[a].append(b) G[b].append(a) ans=[0]*(N+1) d=[1] while d: c=d.pop(0) for g in G[c]: if not ans[g]: d.append(g) ans[g]=c print('Yes') for i in range(2, N+1): print(ans[i])
0
null
99,713,415,013,148
298
145
n, m = list(map(int, input().split())) num = [0 for i in range(n)] flag = False for i in range(m): s, c = list(map(int, input().split())) if (s == 1) and (c == 0) and (n > 1): flag = True elif num[s-1] == 0: num[s-1] = c else: if num[s-1] != c: flag = True if flag: print(-1) else: if (n > 1) and (num[0] == 0): num[0] = 1 print("".join(list(map(str, num))))
import sys import itertools def resolve(in_): N, M = map(int, in_.readline().split()) sc = tuple(tuple(map(int, line.split())) for line in itertools.islice(in_, M)) if N == 1: values = range(10) else: values = range(10 ** (N - 1), 10 ** N) for value in values: if all(value // (10 ** (N - s)) % 10 == c for s, c in sc): return value return -1 def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
1
61,003,038,950,182
null
208
208
def main(S, T): N = len(S) ans = 0 for i in range(N//2): if S[i] != T[i]: ans += 1 if S[-1-i] != T[-1-i]: ans += 1 if N%2 == 1: if S[N//2] != T[N//2]: ans += 1 return ans if __name__ == '__main__': S = input() T = input() ans = main(S, T) print(ans)
N,K = map(int,input().split()) if N<=K : print(0) else : H = list(map(int,input().split())) H.sort() if 0<K : del H[-K:] print(sum(H))
0
null
44,530,591,242,458
116
227
build = [[[0]*10,[0]*10,[0]*10],[[0]*10,[0]*10,[0]*10],[[0]*10,[0]*10,[0]*10],[[0]*10,[0]*10,[0]*10]] n = int(input()) for i in range(n): b, f, r, v = [int(x) for x in input().split()] build[b-1][f-1][r-1] += v count = 0 for i1 in build: for i2 in i1: line = "" for i3 in i2: line += " " + str(i3) print(line) if count < 3: print("#"*20) count += 1
def main(): n = int(input()) n_b = 4 n_f = 3 n_r = 10 from collections import defaultdict state = defaultdict(int) for _ in range(n): # b?£?f??????r???????????¨?±? # v??????????????§??\?±????????????¨??????????????? # v?????????????????´??????v????????????????????¨?????????????????? b, f, r, v = map(int, input().split()) state[(b, f, r)] += v for b in range(1, n_b + 1): for f in range(1, n_f + 1): room_state = [] for r in range(1, n_r + 1): room_state.append(state[(b, f, r)]) print(" " + " ".join(map(str, room_state))) if b != n_b: print("#" * 20) if __name__ == "__main__": main()
1
1,097,608,117,278
null
55
55
S = input() ans = 'ARC' if S == 'ABC' else 'ABC' print(ans)
N = int(input()) A = list(map(int,input().split())) B = [[A[i],i+1]for i in range(N)] B.sort() ans = [B[i][1]for i in range(N)] print(" ".join(map(str,ans)))
0
null
102,612,813,566,560
153
299
N = int(input()) P = list(map(int,input().split())) P_min = [] a = 200000 ans = 0 for i in range(N): if a >= P[i]: ans += 1 a = P[i] print(ans)
n=int(input()) p=list(map(int,input().split())) sai = p[0] answer = 1 for i in range(1,n): if p[i-1]<=sai: sai=p[i-1] if sai >= p[i]: answer = answer + 1 print(answer)
1
85,361,282,054,532
null
233
233
S=list(str(input())) ans=0 sofar=0 j=1 nax=0 for i in range(len(S)-1): if S[i]==S[i+1]: ans+=j j+=1 elif S[i]=='<' and S[i+1]=='>': ans+=j nax=j j=1 else: ans+=j if nax!=0: ans-=j j=1 nax=0 if j>nax: ans-=nax nax=0 if j>nax: ans+=j ans-=nax print(ans)
H=int(input()) Q=[] import math for i in range(10000): if H>1: H=H//2 Q.append(H) elif H==1: break Q.sort() S=0 a=1 for i in range(len(Q)): a=2*a+1 print(a)
0
null
117,977,130,673,302
285
228
mod = 10**9 + 7 max_N = 2 * 10**5 def power(b, e): if e == 0: return 1 half = power(b, e // 2) if e % 2 == 0: return (half * half) % mod else: return (((half * half) % mod) * b) % mod def mod_inv(n): return power(n, mod - 2) fac = [1] * (max_N + 1) for i in range(1, max_N + 1): fac[i] = (i * fac[i - 1]) % mod fac_inv = [1] * (max_N + 1) fac_inv[max_N] = mod_inv(fac[max_N]) for i in range(max_N - 1, -1, -1): fac_inv[i] = (fac_inv[i + 1] * (i + 1)) % mod def choose(n, k): return (((fac[n] * fac_inv[k]) % mod) * fac_inv[n - k]) % mod if __name__ == "__main__": line = input().split(" ") N, K = int(line[0]), int(line[1]) K = min(K, N - 1) ans = 0 for i in range(K + 1): ans = (ans + (choose(N, i) * choose(N - i - 1 + i, i)) % mod) % mod print(ans)
turn = int(input()) tp, hp = 0, 0 for i in range(turn): t, h = input().split() if t == h: tp += 1 hp += 1 elif t > h: tp += 3 elif t < h: hp += 3 print(tp, hp)
0
null
34,337,260,285,130
215
67
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product, accumulate, combinations, product #import bisect #import numpy as np #from copy import deepcopy #from collections import deque #from decimal import Decimal #from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10 ** 9 + 7 def mapline(t = int): return map(t, sysread().split()) def mapread(t = int): return map(t, read().split()) def generate_inv(n,mod): """ 逆元行列 n >= 2 Note: mod must bwe a prime number """ ret = [0, 1] for i in range(2,n+1): next = -ret[mod%i] * (mod // i) next %= mod ret.append(next) return ret def run(): N, *A = mapread() maxA = max(A) L = maxA.bit_length() subs = [0] * L for k in range(L): sum = 0 for a in A: if (a >> k) & 1: sum += 1 << k sum %= mod subs[k] = sum sumA = 0 for a in A: sumA += a sumA %= mod ret = 0 ret += (sumA * N) % mod ret += (sumA * N) % mod sub_sum = 0 for a in A: sums = 0 for k in range(L): if (a >> k) & 1: sums += subs[k] * 2 sums %= mod sub_sum += sums sub_sum %= mod ret -= sub_sum ret %= mod inv = generate_inv(2, mod) ret *= inv[2] ret %= mod print(ret) if __name__ == "__main__": run()
N = int(input()) a = list(map(int, input().split())) MOD = 10**9+7 ans = 0 for j in range(60): count = 0 for i in range(len(a)): a[i], pre = divmod(a[i], 2) count += pre ans += count*(N-count)*2**j ans %= MOD print(ans)
1
122,918,905,212,054
null
263
263
from itertools import combinations_with_replacement CList = [] N, M, Q = map(int, input().split()) for i in range(1, M+1): CList.append(i) Qtotal = [] x = 0 ans = 0 CList=list(combinations_with_replacement(CList, N)) a, b, c, d = map(int, input().split()) for i in CList: if CList[x][b-1]-CList[x][a-1] == c: Qtotal.append(d) else: Qtotal.append(0) x = x+1 x=0 for i in range(Q-1): a, b, c, d = map(int, input().split()) for j in CList: if CList[x][b-1]-CList[x][a-1] == c: Qtotal[x] = Qtotal[x]+d x = x+1 x=0 ans=max(Qtotal) print(ans)
n, m, q = map(int, input().split()) abcd = [list(map(int, input().split())) for _ in range(q)] a = [1]*n def func(a): if a[-1] != m: a[-1] += 1 return a else: d = n - 1 while d > 0 and a[d] == m: d = d - 1 if d < 0: return a else: a[d] += 1 for x in range(d,n): a[x] = a[d] return a ans = 0 a[-1] = 0 while sum(a) != n*m: func(a) di = 0 for i in range(q): if a[abcd[i][1]-1] - a[abcd[i][0]-1] == abcd[i][2]: di += abcd[i][3] ans = max(ans, di) print(ans)
1
27,677,753,819,308
null
160
160
import math a, b, C = map(float, input().split()) h = b * math.sin(math.radians(C)) S = a * h / 2 a1 = b * math.cos(math.radians(C)) cc = math.sqrt(h * h + (a - a1) * (a - a1)) print("{a:5f}".format(a=S)) print("{a:5f}".format(a=a + b + cc)) print("{a:5f}".format(a=h))
N = int(input()) S = input() ans = ['' for _ in range(len(S))] a = ord('A') for i, c in enumerate(S): ans[i] = chr((ord(c) - a + N) % 26 + a) print(''.join(ans))
0
null
67,115,777,523,652
30
271
from collections import deque n = int(input()) d = deque() cmd = ['com', 0] for i in range(n): cmd = input().split() if cmd[0] == 'insert': d.appendleft(int(cmd[1])) elif cmd[0] == 'delete': try: d.remove(int(cmd[1])) except ValueError: pass elif cmd[0] == 'deleteFirst': d.popleft() elif cmd[0] == 'deleteLast': d.pop() print(*list(d))
n = int(input()) a = list(map(int, input().split())) for i in a: if i % 2 == 0: if i % 6 > 0 and i % 10 > 0: print('DENIED') exit() print('APPROVED')
0
null
34,742,776,427,232
20
217
#!/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())) n, k = LI() a = LI() check_num = [-1] * n idx = 0 cnt = 1 while 1: idx = a[idx] - 1 if check_num[idx] != -1: s = check_num[idx] - 1 cnt -= 1 break check_num[idx] = cnt cnt += 1 if cnt >= k: for i in range(n): if check_num[i] == k: print(i+1) quit() else: roop_num = cnt - s x = (k - (s + 1)) % roop_num for i in range(n): if check_num[i] - s - 1 == x: print(i+1) quit()
N, K = map(int, input().split()) A = list(map(int, input().split())) dic = {} for i, v in enumerate(A): dic[i+1] = v town = 1 s = set() l = [] for _ in range(K): l.append(town) s.add(town) town = dic[town] if town in s: stop_twon = town break if N <= K: list_first_split = l[:l.index(stop_twon)] list_second_split = l[l.index(stop_twon):] print(list_second_split[(K - (len(list_first_split))) % len(list_second_split)]) else: print(town)
1
22,723,625,248,298
null
150
150
ans = [0 for _ in range(10001)] for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): w = x*x + y*y + z*z + x*y + y*z + z*x if w <= 10000: ans[w] += 1 print(*ans[1:int(input())+1], sep="\n")
num_limit = int(input()) num_list = [0] * num_limit j_limit = int(num_limit ** 0.5) for j in range(1,j_limit+1): for k in range(1,j + 1): for l in range(1,k+1): if num_limit >= j**2 + k**2 + l**2 + j*k + k*l + l*j: if j > k: if k > l: num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 6 else: num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3 elif k > l: num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3 else: num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 1 for i in num_list: print(i)
1
7,986,403,368,220
null
106
106
import bisect n, d, a = map(int, input().split()) fox = [None]*n for i in range(n): x, h = map(int, input().split()) fox[i] = (x, h) fox.sort() x = [int(fox[i][0]) for i in range(n)] h = [int(fox[i][1]) for i in range(n)] ans = 0 bit = [0]*n for i in range(n): if i != 0: bit[i] += bit[i-1] if bit[i] >= h[i]: continue sub = (h[i]-bit[i]-1)//a+1 ans += sub bit[i] += sub*a index = bisect.bisect_right(x, x[i]+2*d) if index == n: continue bit[index] -= sub*a print(ans)
import sys from collections import deque sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, d, a = map(int, input().split()) XH = sorted([list(map(int, input().split())) for _ in range(n)]) res = 0 tt_dmg = 0 que = deque() for x, h in XH: while que and que[0][1] < x: dmg, rng = que.popleft() tt_dmg -= dmg if tt_dmg < h: h -= tt_dmg cnt = (h + a - 1) // a res += cnt dmg = cnt * a tt_dmg += dmg que.append((dmg, x + d * 2)) print(res) if __name__ == '__main__': resolve()
1
82,152,657,808,178
null
230
230
n,k,s=map(int,input().split()) sMax=10**9 if k==0: if s==sMax: print("1 "*n) else: print((str(sMax)+" ")*n) else: if s==sMax: print((str(s)+" ")*k+"1 "*(n-k)) else: print((str(s)+" ")*k+(str(sMax)+" ")*(n-k))
n, k, s = map(int,input().split()) t1 = [str(s)] * k if s != 10**9: t2 = [str(s+1)] * (n-k) else: t2 = [str(1)] * (n-k) print(*(t1+t2))
1
90,773,286,629,678
null
238
238
import sys import math import collections import heapq import queue import itertools import functools import operator import time readline = sys.stdin.readline IPS = lambda: readline().rstrip() IP = lambda: int(readline().rstrip()) MP = lambda: map(int, readline().split()) LS = lambda: list(map(int, readline().split())) def solve(): for _ in range(1): n = IP() print(n + n**2 + n**3) if __name__ == "__main__": solve()
a = int(input()) s = a*a c = a*a*a t = a+s+c print(int(t))
1
10,314,204,419,298
null
115
115
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**8) #mod = 10**9+7 #mod = 998244353 #INF = 10**18 #eps = 10**-7 def main(): N,K = map(int,readline().split()) A = list(map(int,readline().split())) F = list(map(int,readline().split())) A.sort() F.sort(reverse=True) ng = -1 ok = 10**12+100 while ok - ng > 1: mid = (ok + ng) // 2 if sum(max(0,a-mid//f) for a,f in zip(A,F)) <= K: ok = mid else: ng = mid print(ok) if __name__ == '__main__': main()
N, K = map(int, input().split()) A = sorted(list(map(int, input().split()))) F = sorted(list(map(int, input().split())), reverse=True) # にぶたん := N人のメンバーそれぞれが完食にかかる時間のうち最大値をxに以下にできるか? ok, ng = 10 ** 12 + 1, -1 while ok - ng > 1: x = (ok + ng) // 2 need_training = 0 for a, f in zip(A, F): need_training += max(0, a - x // f) if need_training > K: ng = x break else: ok = x print(ok)
1
165,137,207,457,210
null
290
290
MOD = 1000000007 n, k = map(int, input().split()) rsw = [0]*(n+2) for i in range(1,n+2): rsw[i] = (rsw[i-1]+i-1)%MOD rsw_e = [0]*(n+2) for i in range(1,n+2): rsw_e[i] = (rsw_e[i-1]+n-(i-1))%MOD res = 0 for i in range(k,n+2): start = rsw[i] end = rsw_e[i] res += (end-start+1)%MOD print(res%MOD)
a, b = map(int,input().split()) c, d = map(int,input().split()) if d == 1: print("1") else: print("0")
0
null
78,951,944,481,540
170
264
N, M = map(int, input().split()) totalN = 1/2*(N-1)*N totalM = 1/2*(M-1)*M import math print(math.floor(totalN + totalM))
N, M = [int(i) for i in input().split(' ')] print((N * (N - 1) + M * (M - 1)) // 2)
1
45,643,545,479,730
null
189
189
H, W = map(int, input().split(' ')) s = [] for _ in range(H): s.append(input()) dp = [[10 ** 9 for i in range(W)] for j in range(H)] dp[0][0] = 0 if s[0][0] == '.' else 1 for i in range(H): for j in range(W): if i + 1 < H: cost = int(s[i][j] == '.' and s[i + 1][j] == '#') dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cost) if j + 1 < W: cost = int(s[i][j] == '.' and s[i][j + 1] == '#') dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cost) print(dp[H - 1][W - 1])
m,n=map(int,raw_input().split()) if m>n:print'a > b' elif m<n:print'a < b' else:print'a == b'
0
null
24,828,627,290,568
194
38
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math from copy import copy, deepcopy from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意 from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする def input(): return sys.stdin.readline()[:-1] def printl(li): print(*li, sep="\n") def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def dfs(H,W,L): d=0 c=True if L[0][0]==False: d=1 c=False q=deque([(d*10000,c)]) dxs=((0,1),(1,0)) visited=[False]*10000 while len(q): #print(q) dxy,c=q.popleft()#ここをpopleftにすると幅優先探索BFSになる d,xy=divmod(dxy,10000) x,y=divmod(xy,100) if visited[xy]: continue visited[xy]=True if x==H-1 and y==W-1: return d for dx in dxs: nx=x+dx[0] ny=y+dx[1] if nx>=H or ny>=W: continue if visited[nx*100+ny]:continue if L[nx][ny] or c==False: q.appendleft((d*10000+nx*100+ny,L[nx][ny])) else: q.append(((d+1)*10000+nx*100+ny,False)) def main(): mod = 10**9+7 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え #N = int(input()) H,W = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル L = list(list(input()) for i in range(H)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 #Lt=[[True]*H for _ in range(W)] for i in range (H): for j in range(W): if L[i][j]=='#': L[i][j]=False else: L[i][j]=True ans=dfs(H,W,L) print(ans) if __name__ == "__main__": main()
h,w = map(int,input().split()) B = [input() for _ in range(h)] dp=[] def ch(x1,y1,x2,y2): if B[x1][y1]=='.' and B[x2][y2]=='#': return 1 else: return 0 dp = [[0 for j in range(w)] for i in range(h)] for i in range(h): for j in range(w): if i==0 and j==0 and B[i][j]=='#': dp[i][j]+=1 elif i==0: dp[i][j] = dp[i][j-1]+ch(i,j-1,i,j) elif j==0: dp[i][j] = dp[i-1][j]+ch(i-1,j,i,j) else: dp[i][j] = min(dp[i][j-1]+ch(i,j-1,i,j),dp[i-1][j]+ch(i-1,j,i,j)) print(dp[h-1][w-1])
1
49,622,993,055,086
null
194
194
import math A,B,H,M=map(int,input().split()) M_rad = math.radians(M*6) H_rad = math.radians(H*30+M*0.5) rad = M_rad - H_rad ans = math.sqrt(A**2+B**2-2*A*B*math.cos(rad)) print(ans)
a_1,a_2,a_3=map(int,input().split()) if a_1+a_2+a_3<=21: print('win') else: print('bust')
0
null
69,157,290,464,768
144
260
N=int(input()) S=input() cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B') ans=cntR*cntG*cntB for i in range(N-2): for j in range(i+1,N-1): if S[i]!=S[j]: k=2*j-i if k<N and S[k]!=S[i] and S[k]!=S[j]: ans-=1 print(ans)
N=int(input()) S=input() cnt=0 for i in range(N): left=i-1 right=i+1 while 0<=left and right<N: if S[i]!=S[left] and S[i]!=S[right] and S[left]!=S[right]: cnt+=1 left-=1 right+=1 x=S.count('R') y=S.count('G') z=S.count('B') print(x*y*z-cnt)
1
35,992,215,568,802
null
175
175
# -*- coding: utf-8 -*- str = raw_input() for _ in xrange(input()): ops = raw_input().split() a = int(ops[1]) b = int(ops[2]) + 1 op = ops[0] if op[0]=="p": print str[a:b] elif op[2]=="v": str = str[:a] + str[a:b][::-1] + str[b:] else: str = str[:a] + ops[3] + str[b:]
x,y,z = input().split() if x<y<z: print('Yes') else: print('No')
0
null
1,241,090,012,932
68
39
n = int(input()) x = list(map(int, input().split())) min_x = 100 * 100 * 100 + 1 for p in range(1, 100+1, 1): total = 0 for xi in x: total += (xi - p) ** 2 min_x = min([min_x, total]) print(min_x)
input() print(sum([int(x) % 2 for x in input().split()[::2]]))
0
null
36,253,117,266,150
213
105
x,y = map(str,input().split()) a = {'1':300000,'2':200000,'3':100000} if int(x) > 3 or int(y) > 3: if int(x) <= 3: print(a[x]) elif int(y) <= 3: print(a[y]) else: print(0) else: if x == y == '1': print(1000000) else: print(a[x]+a[y])
from math import gcd K = int(input()) result = 0 for a in range(1, K + 1): for b in range(1, K + 1): t = gcd(a, b) for c in range(1, K + 1): result += gcd(t, c) print(result)
0
null
88,237,963,694,726
275
174
x1,y1,x2,y2=map(float,input().split()) if x1<=x2: x=x2-x1 else: x=x1-x2 if y1<=y2: y=y2-y1 else: y=y1-y2 t=x**2+y**2 t1=t**(1/2) print(f'{t1:10.8f}')
n = int(input()) x = list(map(int,input().split())) ans = 10 ** 12 for i in range(1,101): p = 0 for j in x: p += (j - i) ** 2 ans = min(ans,p) print(ans)
0
null
32,494,390,867,290
29
213
num = list(map(int,input().split())) print("%d %d" % (num[0]*num[1],(num[0]+num[1])*2))
a,b = map(int, input().split()) c=a*b d=2*(a+b) print(c,d)
1
299,055,588,260
null
36
36
import math n=int(input()) print((n-math.floor(n/2))/n)
N = int(input()) num_odd = int(N/2+0.5) print(num_odd/N)
1
176,616,969,965,800
null
297
297
k,n = map(int,input().split()) a = list(map(int,input().split())) ans = 10 ** 8 for i in range(n-1): a.append(a[i]+k) for i in range(n): ans = min(ans,a[i+n-1] - a[i]) print(ans)
import sys def main(): read = sys.stdin.buffer.read k, n, *A = map(int, read().split()) far = k + A[0] - A[-1] y = A[0] for x in A[1:]: dis = x - y if far < dis: far = dis y = x print(k - far) if __name__ == "__main__": main()
1
43,344,403,600,398
null
186
186
def main(): n, a, b = map(int, input().split()) if (b - a) % 2 == 0: ans = (b - a) // 2 else: if b - 1 < n - a: g = (b - a + 1) // 2 ans = a + g - 1 else: g = (2 * n + a - b + 1) // 2 ans = 2 * n - b - g + 1 print(ans) if __name__ == "__main__": main()
n, k = (int(x) for x in input().split()) A = list(int(x) for x in input().split()) MOD = 10**9 + 7 A.sort() l = 0 r = n - 1 sign = 1 # 1 or -1 ans = 1 if k % 2 == 1: ans = A[r] r -= 1 k -= 1 if ans < 0: sign = -1 while k: x = A[l] * A[l + 1] y = A[r] * A[r - 1] if x * sign > y * sign: ans *= x % MOD ans %= MOD l += 2 else: ans *= y % MOD ans %= MOD r -= 2 k -= 2 print(ans)
0
null
59,235,412,918,340
253
112
from itertools import accumulate def LS(): return list(input().split()) N = int(input()) title = [] time = [] for _ in range(N): s, t = LS() time.append(int(t)) title.append(s) time.append(0) Tsum = list(accumulate(time)) X = input() for i in range(N): if title[i] == X: break print(Tsum[N]-Tsum[i])
M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) if M1 in [1, 3, 5, 7, 8, 10, 12]: if D1 == 31: print(1) else: print(0) elif M1 in [4, 6, 9, 11]: if D1 == 30: print(1) else: print(0) elif M1 == 2: if D1 == 28: print(1) else: print(0)
0
null
110,840,384,691,750
243
264
a, b, c = map(int, input().split()) if(a > b) : a, b = b, a if(b > c) : b, c = c, b if(a > b) : a, b = b, a else : pass else : pass print(a, b, c) else : if(b > c) : b, c = c, b if(a > b) : a, b = b, a else : pass else : pass print(a, b, c)
a = raw_input().split(" ") a.sort() print "%s %s %s" % (a[0],a[1],a[2])
1
424,506,394,930
null
40
40
#!/usr/bin/env python3 def main(): from scipy.special import comb N = int(input()) A = [int(x) for x in input().split()] num_lst = [0] * (N + 1) for a in A: num_lst[a] += 1 ans = 0 for num in num_lst: ans += comb(num, 2, exact=True) for a in A: print(ans - (num_lst[a] - 1)) if __name__ == '__main__': main()
while 1: n=raw_input() if '?' in n: break else: print eval(n.replace(' ',''))
0
null
24,199,034,472,100
192
47
# import math # import statistics a=int(input()) #b,c=int(input()),int(input()) # c=[] # for i in a: # c.append(i) # e1,e2 = map(int,input().split()) f = list(map(int,input().split())) #g = [input() for _ in range(a)] f.sort() count=1 ans=[0 for i in range(a)] for i in range(len(f)-1): if f[i]==f[i+1]: count+=1 else: ans[f[i]-1]=count count=1 if count>=1: ans[f[-1]-1]=count for i in ans: print(i)
N = int(input()) ls = list(map(int,input().split())) cnt = [0] * (N+1) for i in range(N-1): cnt[ls[i]] += 1 for i in range(1,N+1): print(cnt[i])
1
32,513,540,557,790
null
169
169
N = int(input()) print(sum([i for i in range(1, N+1) if i%3 if i%5]))
#12716015 n, m = map(int, input().split()) h = list(map(int, input().split())) ans = [1]*n for i in range(m): a, b= map(int, input().split()) a -= 1 b -= 1 if h[a] > h[b]: ans[b] = 0 elif h[a] < h[b]: ans[a] = 0 if h[a] == h[b]: ans[a] = 0 ans[b] = 0 print(ans.count(1))
0
null
30,143,227,081,550
173
155
S = list(input()) K = int(input()) #print(S) N=len(S) #if K==1: kosuu=[] cnt=1 for i in range(N-1): if S[i]==S[i+1]: cnt+=1 if i==N-2: kosuu.append(cnt) elif S[i]!=S[i+1]: kosuu.append(cnt) cnt=1 #print('kosuu', kosuu) dammy=0 for i in range(len(kosuu)): dammy+=kosuu[i]//2 #else: if K==1: out=dammy elif S[0]!=S[-1]: out = dammy * K elif len(S)==1: out=K//2 elif len(kosuu)==1: out=(kosuu[0]*K)//2 else: #kotei=kosuu[1:-1] #少ないとき kotei = dammy - kosuu[0]//2 - kosuu[-1]//2 aida = (kosuu[0] + kosuu[-1]) // 2 #print('aida',aida) out = kosuu[0]//2 + (kotei*K) + aida*(K-1) + kosuu[-1]//2 print(out)
s = input() k = int(input()) l=len(s) s+='?' ch = 1 ans=0 j=0 for i in range(l): if s[i]==s[i+1]: ch+=1 else: ans+=ch//2 if j==0: st=ch if s[i+1]=='?': gl=ch ch=1 j=1 ans*=k if st%2==1 and gl%2==1 and s[0]==s[l-1]: ans+=k-1 if st==l: ans=l*k//2 print(ans)
1
175,631,612,833,508
null
296
296
import sys sys.setrecursionlimit(4100000) import math INF = 10**9 def main(): s,t = input().split() print(t+s) if __name__ == '__main__': main()
print("".join(input().split()[::-1]))
1
103,087,085,946,068
null
248
248
from heapq import heappush, heappop import sys input = sys.stdin.readline N = int(input()) pos = [] zero = [] neg = [] for _ in range(N): S = input().rstrip() m = s = 0 for c in S: if c == '(': s += 1 else: s -= 1 m = min(m, s) if s > 0: heappush(pos, (-m, s)) # take larger mins first elif s == 0: heappush(zero, (m, s)) else: heappush(neg, (m - s, s)) # take smaller mins first num = 0 while pos: m, s = heappop(pos) if num - m < 0: print('No') exit() num += s while zero: m, s = heappop(zero) if num + m < 0: print('No') exit() while neg: m, s = heappop(neg) m += s if num + m < 0: print('No') exit() num += s if num == 0: print('Yes') else: print('No')
n = int(input()) s = [] for i in range(n): s.append(input()) ls = [] rs = [] tot = 0 for si in s: b = 0 h = 0 for c in si: if c == '(': h += 1 else: h -= 1 b = min(h,b) if h > 0: ls.append((b,h)) else: rs.append((b-h,-h)) tot += h ls.sort(reverse = True) rs.sort(reverse = True) def check(x): t = 0 for bx,hx in x: if t+bx < 0: return False t += hx return True if check(ls) and check(rs) and tot == 0: print('Yes') else: print('No')
1
23,598,825,812,000
null
152
152
s = input() partition = s.replace('><','>|<').split('|') ans=0 for sub in partition: left = sub.count('<') right = sub.count('>') ans += sum(range(1, max(left, right) + 1)) ans += sum(range(1, min(left, right))) print(ans)
s = input() n = len(s) + 1 t = [0]*n for i in range(n-1): if s[i] == '<': t[i+1] = t[i] + 1 for i in range(n-2,-1,-1): if s[i] == '>': t[i] = max(t[i],t[i+1]+1) print(sum(t))
1
156,959,660,179,516
null
285
285
x, y = map(int, input().split()) while y>0: x, y = y, x%y print(x)
#ABC162-E Sum of gcd of Tuples(Hard) """ 問題を「1~kまでの数字を用いた長さnの数列において、gcdがDになる数列はいくつあるか」 というふうに置き換える。(1<=D<=k) 更に制約を替えて、gcdが"Dの倍数"(但し,k以下)でも良いのでそれを全て求めよ、 というふうになった場合、全ての要素はD*n(nは整数,D*n<=k)となる。 この制約によって、そのような数列の数は(k/D)^nとして表せる。(これが大事) 例: n = 3,k = 4の場合で、D(gcd)=2について求める (4//2)**3 = 8※ そこで、大きい方からgcdがDになる数列の個数(これをメモ化)を求めていった場合、 Dの倍数がk以下であるならば、予めメモしておいたその値分を引いてやる。 これによって全ての通り数が求まる。 例の続き: D=2について、D*n <= k という制約のもとでn=2が存在する。 D = 2*2 = 4の時の通り数は、4,4,4の1通り※なので、 D(gcd)=2となるパターン数は、※より、 8-1=7 となる。 (この7通りは2と4からなる数列で、全ての値が4になる場合を引いている) """ import sys readline = sys.stdin.buffer.readline n,k = map(int,readline().split()) mod = 10**9+7 ans = 0 count = [0]*(k+1) for D in range(k,0,-1): mul = k//D #何倍まであり得るか(あり得るものをcountから引く) res = pow(mul,n,mod) for i in range(2,mul+1): res -= count[i*D] count[D] = res #個数 ans += res*D #個数*値(求めたいのはgcdの合計値のため) ans %= mod print(ans)
0
null
18,439,286,226,418
11
176
K = int(input()) s = len(input()) mod = 10 ** 9 + 7 N = 2 * 10**6 fac = [1, 1] finv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fac.append( ( fac[-1] * i ) % mod ) inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) ) finv.append( finv[-1] * inv[-1] % mod ) def cmb(n, r): return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod p25 = [1] p26 = [1] for i in range(K): p25.append(p25[i]*25%mod) p26.append(p26[i]*26%mod) ans = 0 for i in range(K+1): ans += ( cmb(s+K-i-1, s-1) * p25[K-i] % mod ) * p26[i] % mod ans %= mod print(ans)
import sys import math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(input()) def LI(): return list(map(int, input().split())) def LIR(row,col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return map(list, zip(*read_all)) ################# # nCk ## 0!~n!をmodしつつ求める def fact_all(n,M=mod): f = [1]*(n+1) ans = 1 for i in range(1,n+1): ans = (ans*i)%M f[i] = ans return f ## inv(0!)~inv(n!)をmodしつつ求める def fact_inv_all(fact_all,M=mod): N = len(fact_all) finv = [0]*N finv[-1] = pow(fact_all[-1],M-2,M) for i in range(N-1)[::-1]: finv[i] = finv[i+1]*(i+1)%M return finv ## nCkをmodしつつ返す def nCk(n,k,fact_list,inv_list,M=mod): return (((fact_list[n]*inv_list[k])%M)*inv_list[n-k])%M K = I() S = list(input()) N = len(S) fl = fact_all(N+K+1) il = fact_inv_all(fl) beki25 = [1]*(N+K+1) for i in range(1,N+K+1): beki25[i] = beki25[i-1]*25 beki25[i] %= mod beki26 = [1]*(N+K+1) for i in range(1,N+K+1): beki26[i] = beki26[i-1]*26 beki26[i] %= mod ans = 0 for i in range(N-1,N+K): ans += nCk(i,N-1,fl,il)*beki25[i-N+1]*beki26[N+K-1-i] ans %= mod print(ans)
1
12,785,155,128,022
null
124
124
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64) # Original source code : """ #include <stdio.h> int main() { int d, t, s; scanf("%d %d %d", &d, &t, &s); if (s * t >= d) { puts("Yes"); } else { puts("No"); } } """ import base64 import subprocess import zlib exe_bin = "c%1E7eQZ<L6~E6(hy#gZNC5M(VYSW_*2N?cAdIHu1t+{rNk}1KR0W<Ke<U7`o!QS_K;4FvGRdOuJZaKUyQ!5XO?2wC_K!_eleVCAU8hYNmA18Nsl=)>1y;0dtPx`(-nsAH^Zf4hdz4B0lcPB2o!>p@-0%C&J@1=+gZ(Z^B1l!_F+!!{3PbK;cyWWN0$3NRga4l)n+a8`w&;ocw#0L{S&w1Y<uYWEZzepKEWCy|(@Y)D3GthDw5=B!4D>>SpW~CP-f0(a=VEpjncYREk9?6eY*FZ6HT#V+e<BYNo>wzIa!rfU=T7EG<c|`bqut|Rw}RY1c^N;%>T?>GqpZEiaUQlM6XUx&w<V)($wVqQ(>Bw!t8G_jFq;l;*W2V}x(9~GbbUJCIJC69nPIfNe*TU;@}oZ<X?p7gY2C}GKUkNY`?19A%PaH#=&J;0j;D?ATVsQ7alrRE-~|W&s~q&d@1WlfzlUsa0^=H?!?=s6Y9gDC?AfDcBjHq>Oy{&LU|B63IjKe_Ppa{7A_+ibCalI2sc<rJItC)Or%D-3oeC#X<iOxS?|yZAaJTu?X+CWa?j-8K=#UzXWnvSFtQO0R4((5-Q?b$Tc#?XXm`bOZH`P$JRixyC`J^*ktv^d3(YeEQwmy+)pk<FUtXY?<$dgRYZA{cryBO2Q^@sbZSZnZC1$>0zZZD6c{BEPc>E5uerK=Xa+JY}waO*j<Xu)eO_-zaBw%~INr@Af+{+0!=vf!63xOE>Zvmd*ab2Z&7{X{uCr@2a(mDxAk^JaNz=Z!i)DYbkI{~NdTz!Q}xY0>qoC7_lMsZ6_m{jx5<M`hZi>vOvNPmtq9OMR_Mp}P(gqRP4ImR5@8LjhmMoKhGJG%JPCfLAGKf%=8l!1`P$(A@abP{6x46sZ6D!(e#@s#<soiooF9(*a*p+3~3ECD#NkZ=DB~pHY>=pz^o(7mfjo2OGCMqt_lUcHA7uzkNc<f2hoUv^X+4Sg835Xe)(=TeKmCZmM5e`#EUyzZ$oMbZ7vCF{Mx=16TIkR`S=h4KQSP+{TbK94}oh*KmBEj#62seWiAVoi5$Y)@86)E-hCn`9<Z@!ahZMQ+az?^MS)l%waus=;ZHA_v@fWa@&;I?(fm3G1{Jb<y`mkAT1P@OQi(`y6|SrcR-e?`59_=Yd)^`hpHdH9;c(C%kr1yBLn$&<S`k>qGhQ@?`j+6hvod;f&9|o)@%A2xpcQ`;SYC9CFSf*&EN4pwr4PZXE47M%Ku$1HD6I?=Oty&2e}(`4Lx~WJ|-WRPsr+gvE2S!^K8wrRVKmeZHfBzKk`H@ONP@#+Elf-i>=dVp-O7`d*H7CzXJRX;K!h&qrj8UlaDA4{0owC?o*OZA0pC>SK3rx>n=*QUW)7Qda!%Mvi|M$2??M+)Yn6~$J_7meW`KP*W72wzKwf7za#Jv+S7Ne5A>}2liD7GpBHeA0wGVk>)1+<TVAD?Q=6yhd_sHlGpX0({kE&u<9n{E&*Lvt_j+2Ntx-Jf-&&z~x@K#KJUtmtm+WbmJ*~YSKj?veug9&QZFD>?fFJ8Q@PHoB1A0LBOBnxPykor&QL1PBB^I=>aGo@?Ll3WS7*}m#GM<SW8OQi)vrzuYaw$#ud3K0lY*b`H48|-MS@}vP|D5qvjQbd0OL)Rq=mLv_@T^p@AB<z{wVv^#H9UU4ns4_U<9Hp!`aer}z5kSq{z(j4X7W+yuT(DAX_3kOto+|hw#Ib-Ps01ANPlMi|10B5_qrV4gD_q`uz&v-{jFo;xs;ak?+)$^wzuub=~BlxI=X`Gom&m`etgm!K$p!+kKPkTZSg9i+2Ymay5sR0bG`BS3UgiZc&#~KJnlB<naAtQ^~B>V&2`7)tIYk!<Mm|D7H{B#eG~T(uPxqa?q?qN62C3J+RPj9_!=^8i#M6)1CKYG=K_zfwOyB0WSzN>c^r1F*ADj)uPwfz0;Bt{n*5_A;%*1LiO{peL*|6>T+49oG6&Sk@DTxjOs~7#PCN&O^ykX)(U_m2;OC64UpdZB?SE0%UqiGyvBX~gC;I=UiuU|c_ft7vzhU}fd*0LkSFWF%x}VDVt&(W|1J*6m$8Fgp+2=pb>UiaP*e2QMQDlkc3D#GvlLlSCa$hJ8exeTeEb}k6r|8iB7Xe@GT5q14NUu=bvLEsI_yrrEm)Ls1Jjd&V*6Sla!B3v)V;&aoM8A^^eQ_M#!SQGM8pE$R^mmE1U-aX0+4py|%RXQAYu&%ixkr;v!3c?Dw5*nk$KkP@WKy*$HA1sTG@%tus}srecsQv>wR9${hI2C{lAfAQ#<W;8xO>;0E_)@K^h&7VOeTCvjit2ADH6|wr($X}H#Kz%Oe~TLni{97s{M!Lp+2>5I7Aa$yh4<yp(lprp@IE;iJk`o=)mxp+NUrNO6U+#4-6jcl?T;>{r!jgM%7Wdcd$>zTwElZ)0=wFOdCz^_4IIgxmYx;g)0(%Wu?x_WS`(cr5?;y^Qk;FnoX;d;Z&5S`34R`K{Sz4bJ<wb+HTr;kjJxG=0;B`@`=fErMsa7dWD1Pm@VXUmVBd0FnelB3y%ZWG6tW-r$h=oO_N|Mt;K?J??9Uto?y~MDi<8jC6dv$M3m^#WH>uXg3(hc@Mmx>W0X7<%VZPj6ep-qmWd_9RFOSRCpB6n3;=x$PNd;Mi_O4)eKv!cv_3(>*d$wOlhI6BGE9wyV_4ub)DWIZMBqU;hp{C=SnpG?Fm3kN|4KBjr|%{_f1SRoAc^_)hY6pv6u(>e1${9*>JaQPo<kn^6nmO?S%O#^?J@2<FSH+z8!?O-CdOR@?J+(?{w~8YAB^^RFE~Q@Zxt9vBFFm-k~n@Rh;dgydyF@c<5`UDcM1F?G438HV_b^7$D#d5rwL}@4Z`>p`J7O{*#BpkeJ|Eu!*jfkQE{D({d1)Jt&I}C7m(w<4N08;ykL)UGx8om-z)I%3ijp$<KlR^1^xrU9^a?PUBZ3C%ZucPf<4A1$i*;D?ElMz-@h0~Aa54*Mf=wTd#CS*PWHbN?D3v}+$}74aXfzuKZvT!_j&VsqP@O2{(pjBqs1QM*jMk<{x8HBd$ccquQg=+PP;;|!+AVUjQ)%HhzpH|eDqW5zaiM0@uZipN3=&;WEk3GeCGAq>x<{lCkzuW=xD#y!QRU4^3*-d-p2-xzGogGmHWTW(snByU1xAHA0W1WwS#?;Rj@4JqWymX{m5y7" open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod +x ./kyomu"], shell=True) subprocess.run(["./kyomu"], shell=True)
import sys r=sys.stdin.readline N,M=map(int,r().split()) city=[[] for _ in range(N+1)] for _ in range(M): a,b=map(int,r().split()) city[a].append(b) city[b].append(a) check=[True]+[False]*(N) def dfs(v): stack=[v] while stack: cur=stack.pop() check[cur]=True for v in city[cur]: if not check[v]: stack.append(v) cnt=0 for i in range(1,N+1): if not check[i]: dfs(i) cnt+=1 print(cnt-1)
0
null
2,937,815,845,932
81
70
list1=list(map(int,input().split())) A=list1[0] B=list1[1] C=list1[2] if list1.count(A)==2 or list1.count(B)==2 or list1.count(C)==2: print("Yes") else: print("No")
from collections import defaultdict d = defaultdict(int) N,M,L = map(int,input().split()) d[N] += 1 d[M] += 1 d[L] += 1 print(("No","Yes")[len(d)==2])
1
67,905,188,309,948
null
216
216
a=input() print(str.swapcase(a))
import sys n,k=map(int,input().split()) a=sorted(list(map(int,input().split()))) f=sorted(list(map(int,input().split())),reverse=True) h,l=max(a[i]*f[i] for i in range(n))+1,0 if sum(a)<=k: print(0);sys.exit() while h-l>1: m=(h+l)//2 practice=sum(max(0,a[i]-m//f[i]) for i in range(n)) if practice<=k: h=m else: l=m print(h)
0
null
83,590,398,981,530
61
290
N=int(input()) #N=5 n=N//2 print(1-n/N)
#!/usr/bin/env python3 import bisect def main(): N = int(input()) L = sorted(map(int, input().split())) ans = 0 for a in range(N - 2): for b in range(a + 1, N - 1): ans += bisect.bisect_right(L, L[a] + L[b] - 1) - b - 1 print(ans) if __name__ == "__main__": main()
0
null
174,184,575,491,608
297
294
import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] IN=lambda : map(int, input().split()) mod=1000000007 #+++++ def main(): ll=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] a = int(input()) print(ll[a-1]) #+++++ isTest=False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform =='ios': if input_method==input_methods[0]: ic=input_clipboard() input = lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else: pass isTest=True else: pass #input = sys.stdin.readline ret = main() if ret is not None: print(ret)
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] num = int(input()) - 1 print(list[num])
1
50,104,329,652,362
null
195
195
import numpy as np import sys input = sys.stdin.readline A,B,M = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) res = np.min(a) + np.min(b) for i in range(M): x,y,c = map(int,input().split()) x-=1 y-=1 res = min(res,(a[x]+b[y]-c)) print(res)
A,B,M=map(int,input().split()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] m=[[] for i in range(M)] for i in range(M): m[i]=[int(x) for x in input().split()] for i in range(M): m[i]=a[m[i][0]-1]+b[m[i][1]-1]-m[i][2] if(min(m)>min(a)+min(b)): print(min(a)+min(b)) else: print(min(m))
1
54,037,844,168,932
null
200
200
# -*- coding: utf-8 -*- import sys import os def input_to_list(): return list(map(int, input().split())) H, W = input_to_list() M = [] for i in range(H): M.append(input_to_list()) v = [] for i in range(W): v.append(int(input())) # M x v for i in range(H): all = 0 for j in range(W): all += M[i][j] * v[j] print(all)
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 ** 9) mod = 10**9+7 cnt = 0 ans = 0 inf = float("inf") n = k() ss = [v() for i in range(n)] c = Counter(ss) a = list(c.most_common()) maxc = a[0][1] Ans = [] for i in a: if i[1] == maxc: Ans.append(i) Ans.sort() for i in Ans: print(i[0])
0
null
35,734,754,339,228
56
218
x, y = input().split() x = int(x) z = round(float(y)*100) print(x*z//100)
import decimal def multply(a: str, b: str) -> int: return int(decimal.Decimal(a) * decimal.Decimal(b)) a, b = input().split() print(multply(a, b))
1
16,483,593,435,362
null
135
135
A,B = input().split() from decimal import Decimal A = Decimal(A) B = Decimal(B) ans = A*B ans = str(ans) n = len(ans) s = '' for i in range(n): if ans[i] == '.': break s += ans[i] print(s)
A,B = list(input().split()) A = int(A) B = int((float(B)+0.005)*100) print(A*B//100)
1
16,691,339,299,360
null
135
135
N = int(input()) A = list(map(int,input().split())) ans = 0 for i in range(N-1): next = i + 1 if A[i] > A[next]: a =A[i] - A[next] ans += a A[next] += a else: pass print(ans)
import sys from itertools import accumulate 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, *A = map(int, read().split()) A.sort(reverse=True) counter = [0] * (A[0] + 1) for a in A: counter[a] += 1 for i in range(A[0] - 1, -1, -1): counter[i] += counter[i + 1] def is_ok(x): c = 0 for a in A: if x - a <= A[0]: c += counter[max(x - a, 0)] pass return c <= M ok = 2 * A[0] + 1 ng = 2 * A[-1] - 1 while ok - ng > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid x = ok ans = 0 csum = [0] csum.extend(accumulate(A)) for a in A: if x - a <= A[0]: c = counter[max(x - a, 0)] ans += a * c + csum[c] M -= c ans += (x - 1) * M print(ans) return if __name__ == '__main__': main()
0
null
56,205,549,226,408
88
252
import sys import itertools N = int(input()) array = list(map(int,input().split())) sum = 0 for I in list(itertools.combinations(array,2)): sum += I[0]*I[1] print(sum)
n = int(input()) a = list(map(int, input().split())) ans = 0 tmp = a[0] for i in range(1,n): tmp = max(a[i], tmp) ans += tmp - a[i] print(ans)
0
null
86,871,039,864,160
292
88
import sys # import re import math import collections # import decimal import bisect import itertools import fractions # import functools import copy # import heapq import decimal # import statistics import queue # import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): from functools import reduce # 最小公倍数 def lcm_base(x, y): return (x * y) // math.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) n = ni() a = na() lcm = a[0] for i in a: lcm = lcm // math.gcd(lcm, i) * i lcm %= MOD ans = 0 for ai in a: ans += lcm * pow(ai, MOD - 2, MOD) % MOD ans %= MOD print(ans) if __name__ == '__main__': main()
import sys from collections import defaultdict, Counter 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()) N_MAX = 10 ** 6 min_factor = list(range(1, N_MAX + 1, 2)) for i in range(1, int((N_MAX ** 0.5 - 1) / 2) + 1): f = 2 * i + 1 if min_factor[i] != f: continue for j in range(2 * i * (i + 1), len(min_factor), f): if min_factor[j] > f: min_factor[j] = f def prime_factorize_fast(n): a = Counter() while not n & 1: a[2] += 1 n //= 2 while n != 1: a[min_factor[(n - 1) // 2]] += 1 n //= min_factor[(n - 1) // 2] return a lcm_prime = Counter() for a in A: for p, n in prime_factorize_fast(a).items(): if lcm_prime[p] < n: lcm_prime[p] = n l = 1 for p, n in lcm_prime.items(): l = l * pow(p, n, MOD) % MOD ans = 0 for a in A: ans = (ans + pow(a, MOD - 2, MOD)) % MOD ans = ans * l % MOD print(ans) return if __name__ == '__main__': main()
1
87,328,818,127,054
null
235
235
from math import gcd n = int(input()) ration = dict() used = dict() for _ in range(n): a, b = map(int, input().split()) if a == 0 or b == 0: if a == b == 0: r = '0' elif a == 0: r = '0a' else: r = '0b' else: s = '-' if (a < 0) ^ (b < 0) else '+' a = abs(a) b = abs(b) g = gcd(a, b) r = f'{s} {a//g} {b//g}' ration[r] = ration.get(r, 0) + 1 used[r] = 0 res = 1 mod = 10**9+7 add = 0 for k, v in ration.items(): if used[k]: continue if k == '0': add += v used[k] = 1 elif k == '0a' or k == '0b': res *= 2**ration.get('0a', 0) + 2**ration.get('0b', 0) - 1 used['0a'] = used['0b'] = 1 else: r = k.split() l = f'{"-" if r[0]=="+" else "+"} {r[2]} {r[1]}' res *= 2**v + 2**ration.get(l, 0) - 1 used[k] = used[l] = 1 res %= mod res += add res -= 1 if res < 0: res += mod print(res)
from math import gcd from collections import defaultdict def sign(x): if x < 0: return -1 if x > 0: return +1 return 0 def power(a, b, m): res = 1 base = a while b: if b & 1: res = res * base % m base = base * base % m b = b >> 1 return res N = int(input()) M = 1000000007 cnt = defaultdict(int) case00 = 0 for _ in range(N): a, b = map(int, input().split()) if a == 0 and b == 0: # (0, 0) cannot pair with anyone case00 += 1 continue s = sign(a) * sign(b) a, b = abs(a), abs(b) g = gcd(a, b) a, b = a // g, b // g cnt[s, a, b] += 1 ans = 1 # empty set vis = set() for (s, a, b) in cnt.keys(): if (s, a, b) in vis: continue if (-s, b, a) in cnt: mul = 1 # empty set from (s, a, b) and (-s, b, a) mul += power(2, cnt[s, a, b], M) - 1 # non-empty subsets from (s, a, b) mul += power(2, cnt[-s, b, a], M) - 1 # non-empty subsets from (-s, b, a) ans = ans * (mul % M) % M vis.add((-s, b, a)) else: ans = ans * power(2, cnt[s, a, b], M) % M ans = (ans - 1 + M) % M # Remove empty set ans = (ans + case00) % M # Special case print(ans)
1
21,125,126,416,274
null
146
146
def main(): A = [list(map(int, input().split())) for _ in range(3)] n = int(input()) for _ in range(n): b = int(input()) for i in range(3): for j in range(3): if A[i][j] == b: A[i][j] = 0 ans = 'No' for i in range(3): if any(A[i]) == 0: ans = 'Yes' for i in range(3): if any([A[0][i], A[1][i], A[2][i]]) == 0: ans = 'Yes' if any([A[0][0], A[1][1], A[2][2]]) == 0: ans = 'Yes' if any([A[0][2], A[1][1], A[2][0]]) == 0: ans = 'Yes' print(ans) if __name__ == '__main__': main()
a = str(input()) if a.islower(): print('a') else: print('A')
0
null
35,651,087,288,900
207
119
if(int(input())>=30): print("Yes") else: print("No")
from fractions 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 def main(): X = int(input()) print('Yes') if X >= 30 else print('No') if __name__ == '__main__': main()
1
5,763,594,930,798
null
95
95
def a172(a): return a + a**2 + a**3 def main(): a = int(input()) print(a172(a)) if __name__ == '__main__': main()
a=int(input()) ans=a+a**2+a**3 print(ans)
1
10,167,175,665,108
null
115
115
import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N = I() a = LI() xor = 0 for x in a: xor ^= x for x in a: print(xor^x,end=' ') print()
N = int(input()) a = list(map(int,input().split())) S = 0 for i in range(N): S ^= a[i] Ans = "" for i in range(N): print(S^a[i])
1
12,586,402,018,400
null
123
123
N,K=map(int,input().split()) H=sorted(list(map(int,input().split()))) if N<=K: print(0) else: if K==0: print(sum(H)) else: print(sum(H[:-K]))
n = int(input()) a = list(map(int, input().split())) m, s = 0, 0 for i in range(n): m = max(m, a[i]) s += m - a[i] print(s)
0
null
41,552,820,832,380
227
88
num = int(input()) K = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51" l = K.split(',') print(l[num-1])
def main(): a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print(a[int(input())-1]) main()
1
50,194,341,860,608
null
195
195
a,b,c=map(int,input().split()) import math d=math.radians(c) S=a*b*math.sin(d)*(1/2) e=math.cos(d) x=a**2+b**2-2*a*b*e L=a+b+math.sqrt(x) h=2*S/a print('{:.6f}'.format(S)) print('{:.6f}'.format(L)) print('{:.6f}'.format(h))
a, b = map(int, input().split()) print(a//b) print(a%b) print('{:.5f}'.format(a/b))
0
null
384,445,252,972
30
45
from sys import stdin for l in stdin: l = l.rstrip() if 0 == int(l): break print(sum([int(ch) for ch in l]))
table = [] i = 0 while True: table.append(int(input())) if table[i] == 0: break i += 1 for num in table: if num == 0: break sum = 0 i = 0 while num != 0: sum += num % 10 num //= 10 if num == 0: break print(sum)
1
1,602,249,371,350
null
62
62
n = int(input()) l = list(map(int, input().split())) l.sort(reverse=True) ans = 0 c = n - 1 for a in range(n - 2): c = n - 1 for b in range(a + 1, n - 1): # 各a,bに対してのcを尺取法で探索 while l[a] >= l[b] + l[c]: c -= 1 if c <= b: break else: # print(l[a], l[b], l[c]) ans += c - b continue break print(ans)
from bisect import bisect_left N=int(input()) A=sorted(list(map(int,input().split()))) cnt=0 for i in range(N-1): for j in range(i+1,N): a=bisect_left(A,A[i]+A[j]) if j<a: cnt+=a-j-1 print(cnt)
1
171,293,156,515,910
null
294
294
class Dice: def __init__(self,num): self.num = num.copy() def east(self): temp = self.num.copy() self.num[1-1] = temp[4-1] self.num[4-1] = temp[6-1] self.num[6-1] = temp[3-1] self.num[3-1] = temp[1-1] def north(self): temp = self.num.copy() self.num[1-1] = temp[2-1] self.num[2-1] = temp[6-1] self.num[6-1] = temp[5-1] self.num[5-1] = temp[1-1] def south(self): temp = self.num.copy() self.num[1-1] = temp[5-1] self.num[5-1] = temp[6-1] self.num[6-1] = temp[2-1] self.num[2-1] = temp[1-1] def west(self): temp = self.num.copy() self.num[1-1] = temp[3-1] self.num[3-1] = temp[6-1] self.num[6-1] = temp[4-1] self.num[4-1] = temp[1-1] def right(self): temp = self.num.copy() self.num[2-1] = temp[4-1] self.num[4-1] = temp[5-1] self.num[5-1] = temp[3-1] self.num[3-1] = temp[2-1] num = list(map(int,input().split())) dice = Dice(num) q = int(input()) for _ in range(q): top,front = map(int,input().split()) while not (top == dice.num[0] or front == dice.num[1]): dice.north() while top != dice.num[0]: dice.east() while front != dice.num[1]: dice.right() print(dice.num[2])
import math A,B,H,M = map(int,input().split()) arg_H = (360*H)/12+(30*M)/60 if M ==0: arg_M = 360 else: arg_M = (360*M)/60 HM = abs(arg_H-arg_M) arg_HM = min(HM, 360-HM) CM2 = A**2+B**2-2*A*B*math.cos(math.radians(arg_HM)) CM = math.sqrt(CM2) print(CM)
0
null
10,129,620,612,868
34
144
def gcd(a,b): if b == 0: return a else: return gcd(b, a%b) k = int(input()) ans = 0 for a in range(1,k+1): for b in range(1,k+1): for c in range(1,k+1): ans += gcd(gcd(a,b),c) print(ans)
import math import sys def main(): n = int(sys.stdin.readline()) total = 0 for i in range(1,n+1): for j in range(1,n+1): for k in range(1,n+1): total += math.gcd(i, math.gcd(j,k)) print(total) main()
1
35,690,145,527,432
null
174
174
n = int(input()) for i in range(n): l = [int(j) for j in input().split()] l.sort() print("YES" if l[0]**2 + l[1]**2 == l[2]**2 else "NO")
n = list(input()) ans = 0 for i in n: ans += int(i) ans = ans%9 print('Yes' if ans == 0 else 'No')
0
null
2,192,565,923,264
4
87
# -*- coding: utf-8 -*- import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines R, C, K = map(int, readline().split()) V = [[0]*(C+1) for _ in range(R+1)] for i in range(K): r,c,v = map(int,readline().split()) V[r][c] = v dp = [0] * (C+1) dp[0] = 0 for i in range(1,R+1): ndp = [0] * (C+1) row = V[i] ldp = [0] * 4 for j in range(1,C+1): # ldp[0] = max(ldp[0], dp[j]) ldp[0] = dp[j] for k in range(2,-1,-1): ldp[k+1] = max(ldp[k+1], ldp[k] + row[j]) # 取る場合と取らない場合 ndp[j] = max(ldp) dp = ndp print(dp[C])
n,m = map(int,input().split()) sub = [] for i in range(m): tmp= [x for x in input().split()] sub.append(tmp) ac = [0]*n wa = [0]*n for i in range(m): res = sub[i][1] que = int(sub[i][0]) - 1 if res == "AC" and ac[que] == 0: ac[que] += 1 elif res == "WA" and ac[que] == 0: wa[que] += 1 for i in range(n): if ac[i] != 1: wa[i] = 0 print(sum(ac),sum(wa))
0
null
49,426,272,988,352
94
240
import sys import heapq import re from heapq import heapify, heappop, heappush from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from fractions import gcd from math import factorial, sqrt, ceil from functools import lru_cache, reduce INF = 1 << 60 MOD = 1000000007 sys.setrecursionlimit(10 ** 7) # UnionFind class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) # ダイクストラ def dijkstra_heap(s, edge, n): #始点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 # 素因数分解 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 # 2数の最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) # リストの要素の最小公倍数 def lcm_list(numbers): return reduce(lcm, numbers, 1) # リストの要素の最大公約数 def gcd_list(numbers): return reduce(gcd, numbers) # 素数判定 def is_prime(n): if n <= 1: return False p = 2 while True: if p ** 2 > n: break if n % p == 0: return False p += 1 return True # limit以下の素数を列挙 def eratosthenes(limit): A = [i for i in range(2, limit+1)] P = [] while True: prime = min(A) if prime > sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P # 同じものを含む順列 def permutation_with_duplicates(L): if L == []: return [[]] else: ret = [] # set(集合)型で重複を削除、ソート S = sorted(set(L)) for i in S: data = L[:] data.remove(i) for j in permutation_with_duplicates(data): ret.append([i] + j) return ret # ここから書き始める k = int(input()) queue = deque([str(i) for i in range(1, 10)]) ans = "" for i in range(k): ans = queue.popleft() if ans[-1] != "0": queue.append(ans + str(int(ans[-1]) - 1)) queue.append(ans + ans[-1]) if ans[-1] != "9": queue.append(ans + str(int(ans[-1]) + 1)) print(ans)
N = int(input()) a_list = list(map(int, input().split())) MOD = 10**9 + 7 cnts = [0,0,0] sames = 0 ind = -1 res = 1 for a in a_list: for i, cnt in enumerate(cnts): if cnt == a: sames += 1 ind = i res *= sames res %= MOD cnts[ind] += 1 sames = 0 print(res)
0
null
85,415,902,857,728
181
268
N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) LB = A[-1] * 2 # 一回の握手で上がる幸福度の下限は、左手も右手もパワーが一番低い人を握った場合 UB = A[0] * 2 # 一回の握手で上がる幸福度の上限は、左手も右手もパワーが一番高い人を握った場合 # cgs[i] は パワーがi以上のゲストの数 cgs = [0] * (UB + 1) for a in A: cgs[a] += 1 for i in range(UB, 0, -1): cgs[i - 1] += cgs[i] # 組み合わせの数がM以上になる一回で発生する幸福度の閾値を二分探索する def is_ok(n): m = 0 for a in A: m += cgs[max(n - a, 0)] return m >= M ok = LB ng = UB + 1 while ng - ok > 1: m = (ok + ng) // 2 if is_ok(m): ok = m else: ng = m # cps[i] は A[0]~A[i] の累積和 cps = A[:] for i in range(1, N): cps[i] += cps[i - 1] result = 0 for a in A: # 左手固定 t = cgs[max(ok - a, 0)] # 握手すると閾値を超えるひとたち if t != 0: result += a * t + cps[t - 1] # 1人目pとu回握手 + 右手はu人までと握手 M -= t result += ok * M # 閾値上の人の処理 print(result)
n,m=map(int,input().split()) a=list(map(int,input().split())) for i in range(n):a[i]*=-1 a.sort() from bisect import bisect_left,bisect_right def check(mid): mm=0 for i in range(n): if -(a[i]+a[0])<mid:break mm+=bisect_right(a,-(mid+a[i])) return mm ok=0 ng=10**10+7 while ng!=ok+1: mid=(ok+ng)//2 if check(mid)>=m:ok=mid else:ng=mid b=[0] for i in a:b.append(b[-1]+i) ans=0 for i in range(n): if -(a[i]+a[0])<ok:break ind=bisect_right(a,-(ok+a[i])) ans+=a[i]*ind ans+=b[ind] print(-(ans+(check(ok)-m)*ok))
1
108,020,893,982,400
null
252
252
K = int(input()) S = input() m = 1000000007 def make_factorial_table(n): result = [0] * (n + 1) result[0] = 1 for i in range(1, n + 1): result[i] = result[i - 1] * i % m return result def mcomb(n, k): if n == 0 and k == 0: return 1 if n < k or k < 0: return 0 return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m fac = make_factorial_table(len(S) - 1 + K) result = 0 for i in range(K + 1): t = pow(26, i, m) * mcomb(len(S) - 1 + K - i, len(S) - 1) t %= m t *= pow(25, K - i, m) t %= m result += t result %= m print(result)
#import sys #input = sys.stdin.readline #input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): 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() #import numpy as np from collections import defaultdict def main(): mod=10**9+7 n=II() s=input() s=len(s) pp=[1] for i in range(n+10): pp.append(pp[-1]*25%mod) nn=n+s comb=[1] for i in range(1,n+10): comb.append(comb[-1]*(nn-i+1)*pow(i,mod-2,mod)%mod) #print(comb) ans=0 for i in range(n+1): ans+=(pp[i]*comb[i])%mod ans%=mod print(ans) if __name__ == "__main__": main()
1
12,788,144,780,530
null
124
124
W = input().lower() T = '' while True: txt = input() if txt == 'END_OF_TEXT': break T += txt.lower() + ' ' print(tuple(T.split(' ')).count(W))
# coding: utf-8 # Here your code ! def func(): try: word=input().rstrip().lower() words=[] while(True): line=input().rstrip() if(line == "END_OF_TEXT"): break else: words.extend(line.lower().split(" ")) except: return inputError() print(words.count(word)) def inputError(): print("input Error") return -1 func()
1
1,790,855,507,104
null
65
65
import sys def main(): dp = [[0] * W for _ in range(H)] for y in range(H): for x in range(W): if x == 0 and y == 0: if s[0][0] == "#": dp[0][0] = 1 elif x == 0: if s[y][x] == "#" and s[y - 1][x] == ".": dp[y][x] = dp[y - 1][x] + 1 else: dp[y][x] = dp[y - 1][x] elif y == 0: if s[y][x] == "#" and s[y][x - 1] == ".": dp[y][x] = dp[y][x - 1] + 1 else: dp[y][x] = dp[y][x - 1] else: if s[y][x] == "#" and s[y][x - 1] == "." and s[y - 1][x] == ".": dp[y][x] = min(dp[y][x - 1], dp[y - 1][x]) + 1 elif s[y][x] == "#" and s[y][x - 1] == ".": dp[y][x] = min(dp[y][x - 1] + 1, dp[y - 1][x]) elif s[y][x] == "#" and s[y - 1][x] == ".": dp[y][x] = min(dp[y][x - 1], dp[y - 1][x] + 1) else: dp[y][x] = min(dp[y][x - 1], dp[y - 1][x]) print(dp[-1][-1]) if __name__ == "__main__": H, W = map(int, sys.stdin.readline().split()) s = [list(sys.stdin.readline().rstrip()) for _ in range(H)] main()
import sys readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines read = sys.stdin.buffer.read sys.setrecursionlimit(10 ** 7) INF = float('inf') H, W = map(int, readline().split()) masu = [] for _ in range(H): masu.append(readline().rstrip().decode('utf-8')) # print(masu) dp = [[INF]*W for _ in range(H)] dp[0][0] = int(masu[0][0] == "#") dd = [(1, 0), (0, 1)] # 配るDP for i in range(H): for j in range(W): for dx, dy in dd: ni = i + dy nj = j + dx # はみ出す場合 if (ni >= H or nj >= W): continue add = 0 if masu[ni][nj] == "#" and masu[i][j] == ".": add = 1 dp[ni][nj] = min(dp[ni][nj], dp[i][j] + add) # print(dp) ans = dp[H-1][W-1] print(ans)
1
49,404,184,747,918
null
194
194
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 998244353 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) SI = lambda : sys.stdin.readline().rstrip() N,S = LI() A = [0] + LI() dp = [[0] * (S+1) for _ in range(N+1)] dp[0][0] = pow(2,N,MOD) d2 = pow(2,MOD-2,MOD) for i in range(1,N+1): for j in range(0,S+1): if j >= A[i]: dp[i][j] = (dp[i-1][j] + dp[i-1][j-A[i]] * d2) % MOD else: dp[i][j] = dp[i-1][j] print(dp[-1][-1]) if __name__ == '__main__': main()
h,n = map(int,input().split()) a = list(map(int,input().split())) suma = sum(a) print('Yes' if h - suma <= 0 else 'No')
0
null
47,740,072,595,712
138
226
import sys k = int(input()) a = dict() cnt = 0 base = 0 while True: cnt += 1 base = (base*10+7)%k if base == 0: break if base in a: cnt = -1 break else: a[base] = 1 print(cnt)
k = int(input()) a = [None for i in range(10**7) ] ans = -1 a[1] = 7%k for i in range(2,k+1): a[i] = (a[i-1]*10 + 7)%k for i in range(1,k+1): if a[i] == 0: ans = i break print(ans)
1
6,185,986,298,720
null
97
97
n = int(input()) graph = {} ans = [] np = set(range(1,n+1)) for i in range(n): t = list(map(int, input().split())) v = t[0] k = t[1] graph[v] = [t[i+2] for i in range(k)] np=np - set(graph[v]) ans.append([v,None,None]) class Time: def __init__(self): self.time = 0 def getTime(self): self.time += 1 return self.time t = Time() visited = set() def dfs(graph, target): visited.add(target) # ???????????????????¨???? if ans[target - 1][1] is None: ans[target - 1][1] = t.getTime() if graph[target] == []: if ans[target - 1][2] is None: ans[target - 1][2] = t.getTime() return for v in sorted(graph[target]): # # ???????????????????¨???? if v not in visited: if ans[v - 1][1] is None: ans[v - 1][1] = t.getTime() visited.add(target) dfs(graph,v) if ans[target - 1][2] is None: ans[target - 1][2] = t.getTime() if np == set(): np = [1] for v in sorted(list(np)): dfs(graph,v) for row in ans: print(*row)
import math def plot(x,y): print(f"{x:.8f} {y:.8f}") def koch(n,x1,y1,x2,y2): if n==0: plot(x1,y1) return ax=(2*x1+x2)/3 ay=(2*y1+y2)/3 bx=(x1+2*x2)/3 by=(y1+2*y2)/3 cx=(bx-ax)*(1/2)-(by-ay)*(math.sqrt(3)/2)+ax cy=(bx-ax)*(math.sqrt(3)/2)+(by-ay)*(1/2)+ay koch(n-1,x1,y1,ax,ay) koch(n-1,ax,ay,cx,cy) koch(n-1,cx,cy,bx,by) koch(n-1,bx,by,x2,y2) n=int(input()) koch(n,0,0,100,0) plot(100,0)
0
null
61,574,305,422
8
27
def insersionSort(A, N, count=0, g=1): # 間隔 g で挿入ソートを行う 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 count += 1 A[j+g] = v return A, count def shellSort(): N, *A = map(int, open(0).read().split()) G = [1] cursor = 2 while True: g = (3 ** cursor - 1) // 2 if g < N: G.append(g) cursor += 1 else: break G = G[::-1] print(len(G)) print(' '.join([str(g) for g in G])) count = 0 for g in G: A, count = insersionSort(A, N, count, g) print(count) for a in A: print(a) if __name__=="__main__": shellSort()
a,b = map(int,input().split()) for i in range(1,1100): if int(i*0.08) == a: if int(i*0.1) == b: print(i) exit() print("-1")
0
null
28,158,605,882,920
17
203
import math A,B,H,M= map(int,input().split()) kd_a=0.5*(M+60*H) kd_b=6*M rad=math.radians(kd_a-kd_b) X=A**2+B**2-2*A*B*math.cos(rad) print(X**0.5)
W, H, x, y, r = [int(temp) for temp in input().split()] if r <= x <= (W - r) and r <= y <= (H - r) : print('Yes') else : print('No')
0
null
10,227,011,964,700
144
41
S = input() count = 0 ans = 0 for i in range(3): if S[i] == "R": count += 1 ans = max(ans, count) else: ans = max(ans, count) count = 0 print(ans)
s = input() res = 0 cur = 0 for i in s: if i =='S': cur = 0 else: cur += 1 res = max(cur, res) print(res)
1
4,899,610,613,238
null
90
90
S=list(input()) s=0 f=0 g=0 h=0 for i in range(len(S)): if S[i]==">": g=0 f+=1 if h>=f: s+=f-1 else: s+=f else: f=0 g+=1 s+=g h=g print(s)
s=input() sl=len(s) a=[] count=1 for i in range(sl-1): if s[i+1]==s[i]: count+=1 else: a.append(count) count=1 a.append(count) ans=0 al=len(a) if s[0]=="<": for i in range(0,al-1,2): m,n=max(a[i],a[i+1]),min(a[i],a[i+1]) ans+=(m*(m+1)+n*(n-1))/2 if al%2==1: ans+=a[-1]*(a[-1]+1)/2 elif s[0]==">": ans+=a[0]*(a[0]+1)/2 for i in range(1,al-1,2): m,n=max(a[i],a[i+1]),min(a[i],a[i+1]) ans+=(m*(m+1)+n*(n-1))/2 if al%2==0: ans+=a[-1]*(a[-1]+1)/2 print(int(ans))
1
156,284,014,070,590
null
285
285
n =int(input()) S = list(map(int, input().split(' '))) q = int(input()) T = list(map(int, input().split(' '))) count = 0 for t in T: if t in S: count += 1 print(count)
str=input() l=len(str) n=0 while l>0: n=n+int(str[l-1]) l=l-1 if n%9 == 0: print("Yes") else : print("No")
0
null
2,234,689,396,482
22
87
# Tsundoku import numpy as np N, M, K = map(int,input().split()) A = np.array([0] + list(map(int, input().split()))) B = np.array([0] + list(map(int, input().split()))) a = np.cumsum(A) b = np.cumsum(B) ans = 0 j = M for i in range(N+1): if a[i] > K: break while b[j] > K - a[i]: j -= 1 ans = max(ans, i+j) print(ans)
# -*- coding: utf-8 -*- N = int(input()) g = N // 2 k = ( N + 1 ) // 2 if N % 2 == 0: print(g) else: print(k)
0
null
35,132,697,409,680
117
206
n = int(input()) d = list(map(int, input().split())) a = [0] * n for i in range(n): a[d[i]] += 1 if a[0] == 1 and d[0] == 0: ans = 1 for i in range(1, n): ans *= a[i-1]**a[i] ans %= 998244353 print(ans) else: print(0)
D=int(input()) C=list(map(int, input().split())) S=[list(map(int,input().split())) for i in range(D)] T=[] for i in range(D): T.append(int(input())) def dissat(day): dissat = 0 for i in range(26): if T[day-1]-1 == i: continue dissat += C[i]*(day-lastdays[i]) return dissat def last(day): lastdays[T[day-1]-1] = day sat = 0 lastdays = [0]*26 # main for i in range(D): # dayi last(i) sat += S[i][T[i]-1] - dissat(i+1) print(sat)
0
null
82,567,757,495,168
284
114