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
import numpy as np import sys N,K = map(int, input().split()) A = np.array(sys.stdin.readline().split(), np.int64) maxa = np.max(A) mina = maxa // (K+1) while maxa > mina + 1: mid = (maxa + mina)// 2 div = np.sum(np.ceil(A/mid-1)) if div > K: mina = mid else: maxa = mid print(maxa)
N = int(input()) R = [int(input()) for _ in range(N)] p_buy = R[0] p_sale = R[1] buy = R[1] sale = None for i in range(2, N): if p_sale < R[i]: p_sale = R[i] if buy > R[i]: if sale is None: sale = R[i] if p_sale - p_buy < sale - buy: p_sale, p_buy = sale, buy sale, buy = None, R[i] else: if sale is None or sale < R[i]: sale = R[i] p_gain = p_sale - p_buy print(p_gain if sale is None else max(p_gain, sale - buy))
0
null
3,285,237,932,102
99
13
x = [1,2,3,4,5,6,7,8,9] y = [1,2,3,4,5,6,7,8,9] for w in x : for c in y : print(w,"x",c,"=",w*c,sep="")
[[print("{}x{}={}".format(i,j,i*j))for j in range(1,10)]for i in range(1,10)]
1
628,904
null
1
1
import sys def input(): return sys.stdin.readline().rstrip() from collections import Counter def main(): n=int(input()) D=[int(_) for _ in input().split()] dc=Counter(D) mod,ans=998244353,1 if D[0]!=0 or dc[0]!=1: print(0) sys.exit() for i,_ in enumerate(list(dc.items())): if i>1: ans*=dc[i-1]**dc[i]%mod print(ans%mod) if __name__=='__main__': main()
N = int(input()) D = list(map(int, input().split())) M = 998244353 from collections import Counter if D[0] != 0: print(0) exit(0) cd = Counter(D) if cd[0] != 1: print(0) exit(0) tmp = sorted(cd.items(), key=lambda x: x[0]) ans = 1 for kx in range(2, max(D)+1): # print(tmp) # for kx in range(2, len(tmp)): # print(kx) # __, p = tmp[kx-1] # _, v = tmp[kx] p = cd[kx-1] v = cd[kx] # print("{}^{}".format(p, v)) while v > 0: ans *= p ans %= M v -= 1 # print(cd) # for kx in range(1, max(D)+1): # ans *= pow(cd[kx-1], cd[kx],M) # ans %= M print(ans)
1
154,955,794,342,948
null
284
284
a, b, m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) li = [list(map(int,input().split())) for i in range(m)] kouho = [min(a)+min(b)] for l in li: kouho.append(a[l[0]-1] + b[l[1]-1] -l[2]) print(min(kouho))
# forใ—ใชใŒใ‚‰ifใ€ifใงใชใ„ใจใใฏforใ—ใชใ„ใฎใงใ€่จˆ็ฎ—้‡ๆธ› # ๅˆๆœŸๅ…ฅๅŠ›ใ€€ใ€€๏ผ’๏ผ๏ผ’๏ผ๏ผ๏ผ๏ผ—๏ผ’๏ผ—ใ€€21๏ผš50 from collections import Counter import sys input = sys.stdin.readline #ๆ–‡ๅญ—ๅˆ—ใงใฏไฝฟใ‚ใชใ„ N = int(input()) *S, =input().strip() """ c =Counter(S) ans =combinations_count(N, 3) -len(c) """ count =0 x100=0 x10=0 x1=0 for i in range(10): if str(i) in S: x100 =S.index(str(i)) +1 for j in range(10): if str(j) in S[x100:]: x10 =S[x100:].index(str(j)) +1 for k in range(10): if str(k) in S[x100 +x10:]: x1 =S[x100+x10:].index(str(k)) +1 count +=1 #print("aa",i,j,k,"bb",x100,x100+x10,x100+x10+x1) print(count)
0
null
90,993,763,296,900
200
267
#!/usr/bin/env python3 import sys from itertools import chain YES = "Yes" # type: str NO = "No" # type: str def solve(H: int, N: int, A: "List[int]"): if H <= sum(A): return YES else: return NO def main(): tokens = chain(*(line.split() for line in sys.stdin)) H = int(next(tokens)) # type: int N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" answer = solve(H, N, A) print(answer) if __name__ == "__main__": main()
HP, N = map(int, input().split()) ATK = list(map(int, input().split())) print('Yes' if sum(ATK) >= HP else 'No')
1
78,130,763,085,358
null
226
226
n = int(input()) ans = 0 t = 0 J = 0 for i in range(1,n): for j in range(i,n): if i*j >= n:break if i == j : t+=1 ans +=1 J = j print(2*ans -t)
import sys def input(): return sys.stdin.readline().rstrip() def main(): n,a,b=map(int,input().split()) if (b-a)%2==0:print((b-a)//2) else:print(min((b+a-1)//2,(2*n-b+1-a)//2)) if __name__=='__main__': main()
0
null
55,880,946,810,652
73
253
A = [] for _ in range(3): a = [int(a) for a in input().split()] A.append(a) N = int(input()) for _ in range(N): num = int(input()) for i in range(3): for j in range(3): if A[i][j]==num: A[i][j] = -1 # Rows for row in range(3): bingo_row = True for col in range(3): if A[row][col]!=-1: bingo_row = False if bingo_row: print('Yes') exit() # Columns for col in range(3): bingo_col = True for row in range(3): if A[row][col]!=-1: bingo_col = False if bingo_col: print('Yes') exit() # Naname bingo_naname = True for i in range(3): col, row = i, i if A[row][col] != -1: bingo_naname = False if bingo_naname: print('Yes') exit() bingo_naname = True for i in range(3): col, row = 2-i, i if A[row][col] != -1: bingo_naname = False if bingo_naname: print('Yes') exit() print('No')
n=int(input()) import heapq q=[] for i in range(n): x,l=map(int,input().split()) heapq.heappush(q,(x+l,l)) largest=-float('inf') c=0 while q: a,l=heapq.heappop(q) if largest<=a-2*l: largest=a c+=1 print(c)
0
null
75,109,388,837,600
207
237
h1, m1, h2, m2, k = map(int, input().split()) d = (h2 - h1) * 60 + (m2 - m1) print(max(d - k, 0))
import collections N=int(input()) D=list(map(int,input().split())) mod=998244353 if D[0]!=0: print(0);exit() D=collections.Counter(D) if D[0]!=1: print(0);exit() ans=1 for i in range(1,len(D)): ans*=pow(D[i-1],D[i],mod) ans%=mod print(ans)
0
null
86,363,622,166,910
139
284
import math n = int(input()) x = n * (n + 1) / 2 f = math.floor(n / 3) fizzsum = f * (f + 1) / 2 * 3 b = math.floor(n / 5) buzzsum = b * (b + 1) / 2 * 5 fb = math.floor(n / 15) fizzbuzzsum = fb * (fb + 1) / 2 * 15 print(int(x - fizzsum - buzzsum + fizzbuzzsum))
N = int(input()) SUM = 0 for i in range(1, N + 1): if i % 3 != 0: if i % 5 != 0: SUM += i print(SUM)
1
34,933,432,034,048
null
173
173
from math import ceil H=int(input()) W=int(input()) N=int(input()) print(min(ceil(N/H),ceil(N/W)))
a=int(input()) b=int(input()) c=int(input()) if a<b: a,b=b,a if c%a==0: print(c//a) else: print(c//a+1)
1
88,893,280,068,360
null
236
236
#! /usr/bin/python3 m=[int(input()) for i in range(10)] m.sort() m.reverse() print("{0}\n{1}\n{2}".format(m[0], m[1], m[2]))
mountains = [] for i in range(10): m = int(input()) mountains.append(m) mountains.sort(reverse=True) for i in range(3): print(mountains[i])
1
15,259,486
null
2
2
n = int(input()) ls = list(map(int,input().split())) mon = 1000 beet = 0 p = [] m = [] if ls[1]-ls[0] > 0: beet += int(mon//ls[0]) mon -= ls[0]*int(mon//ls[0]) be = True else: be = False for i in range(n-1): if ls[i] < ls[i+1]: if be == False: beet += int(mon//ls[i]) mon -= ls[i]*int(mon//ls[i]) be = True if ls[i] > ls[i+1]: if be == True: mon += ls[i] * beet beet = 0 be = False if beet > 0: mon += beet*ls[-1] print(mon)
import bisect n = int(input()) a = list(map(int,input().split())) # ni - nj = ai + aj (i>j) # ai - ni = - aj - nj a1 = sorted([a[i] - (i+1) for i in range(n)]) a2 = sorted([- a[i] - (i+1) for i in range(n)]) ans = 0 for i in range(n): left = bisect.bisect_left(a2, a1[i]) right = bisect.bisect_right(a2, a1[i]) ans += (right - left) print(ans)
0
null
16,683,227,263,700
103
157
string1 = input() string2 = input() n, m = len(string1), len(string2) best = float("inf") for i in range(n - m + 1): current = string1[i:i+m] differences = 0 for i in range(m): if current[i] != string2[i]: differences += 1 best = min(differences, best) if best == float("inf"): print(0) else: print(best)
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() ans = 0 n_ketasuu = len(str(n)) sta_max = int(str(n)[0]) end_max = int(str(n)[n_ketasuu-1]) for i in range(1,n+1): sta = int(str(i)[len(str(i))-1]) end = int(str(i)[0]) if sta == 0: continue #1ๆก if sta == end: ans +=1 #2ๆก if n_ketasuu >= 2 and sta*10 + end <= n: ans += 1 #3ๆก if n_ketasuu > 3 or (n_ketasuu == 3 and sta < sta_max): ans += 10 elif n_ketasuu == 3 and sta == sta_max: ans += int(str(n)[1:n_ketasuu-1]) if end <= end_max: ans += 1 #4ๆก if n_ketasuu > 4 or (n_ketasuu == 4 and sta < sta_max): ans += 100 elif n_ketasuu == 4 and sta == sta_max: ans += int(str(n)[1:n_ketasuu-1]) if end <= end_max: ans += 1 #5ๆก if n_ketasuu > 5 or (n_ketasuu == 5 and sta < sta_max): ans += 1000 elif n_ketasuu == 5 and sta == sta_max: ans += int(str(n)[1:n_ketasuu-1]) if end <= end_max: ans += 1 #6ๆก if n_ketasuu > 6 or (n_ketasuu == 6 and sta < sta_max): ans += 10000 elif n_ketasuu == 6 and sta == sta_max: ans += int(str(n)[1:n_ketasuu-1]) if end <= end_max: ans += 1 print(ans)
0
null
45,233,622,505,786
82
234
# coding: utf-8 N = int(input()) x_ = N//1.08 ans = ':(' for i in range(1,100000): x = x_+i if int(1.08*x) == N: ans = int(x) break print(ans)
N=int(input()) for i in range(N+1): if int(i*1.08)==N: print(i) break if all(int(i*1.08)!=N for i in range(N+1))==True: print(":(")
1
125,217,260,341,848
null
265
265
def input_one(): #no endline S1 = input() return S1 def x_cubic(num): return num**3 def output_line(): print("") def output(stdoutput): print(stdoutput, end = "") output(x_cubic(int(input_one()))) output_line()
x = int(input('')) print("{0}".format(x*x*x))
1
289,158,339,720
null
35
35
def f(): n=int(input()) l=[0,0,0] ans=1 mod=10**9+7 for i in list(map(int,input().split())): if i not in l:print(0);exit() ans=ans*l.count(i)%mod l[l.index(i)]+=1 print(ans) if __name__ == "__main__":f()
a=int(input()) b=list(map(int,input().split())) c=[0,0,0] ans=1 mod=1000000007 for i in b: d=0 for j in c: if i==j: d+=1 if d==0: ans = 0 break else: ans=ans*d%mod for j in range(3): if i==c[j]: c[j]+=1 break print(ans)
1
130,032,336,277,932
null
268
268
n = int(input()) s = input() i = 0 while i < len(s)-1: if s[i] == s[i+1]: s = s[:i] + s[i+1:] i -= 1 i += 1 print(len(s))
n = int(input()) s = input() sl = list(s) k = 0 cur = '0' for i in range(n): if sl[i] == cur: continue else: k += 1 cur = sl[i] print(k)
1
170,275,394,111,472
null
293
293
x,y = map(int,input().split()) ans = 0 for i in [x,y]: if i==3:ans+=100000 elif i==2:ans+=200000 elif i==1:ans+=300000 if x==y==1: ans += 400000 print(ans)
import sys import math a = [] for line in sys.stdin: a.append(line) for n in a: inl=n.split() num1=int(inl[0]) check=1 list=[] while check<=math.sqrt(num1): if num1%check==0: list.append(check) list.append(num1/check) check+=1 list.sort() list.reverse() num2=int(inl[1]) for i in list: if num2%i==0: gud=i break lcm=num1*num2/gud print gud,lcm
0
null
70,067,347,635,472
275
5
N, A, B = map(int, input().split()) temp = N // (A+B) temp2 = N % (A + B) temp2 = min(temp2, A) print(temp*A + temp2)
# -*- coding: utf-8 -*- num = int(raw_input()) a = int(raw_input()) b = int(raw_input()) diff = b - a pre_min = min(a,b) counter = 2 while counter < num: current_num = int(raw_input()) if diff < current_num - pre_min: diff = current_num - pre_min if pre_min > current_num: pre_min = current_num counter += 1 print diff
0
null
27,849,041,271,556
202
13
while True: (n, x) = [int(i) for i in input().split()] if n == x == 0: break count = 0 for a in range(1, n+1): for b in range(a+1, n+1): for c in range(b+1, n+1): if (a + b + c) == x: count += 1 elif (a + b + c) > x: break print(count)
while True: try: n,x = map(int,raw_input().split()) if n == x == 0: break except EOFError: break total = 0 for k in range(1,n+1): for j in range(1,n+1): for l in range(1,n+1): if k!=j!=l and k + j + l == x and k<j<l: total +=1 print total
1
1,291,310,007,900
null
58
58
x,n=map(int,input().split()) p=set(map(int,input().split())) low=x high=x while True: if low not in p: print(low) break elif high not in p: print(high) break low-=1 high+=1
from sys import exit x, n = map(int, input().split()) p = list(map(int, input().split())) for d in range(x+1): #0ใซ้”ใ—ใŸๆ™‚็‚นใง0ใ‚’ๅ‡บๅŠ›ใ—ใฆ็ต‚ไบ†ใ™ใ‚‹ใฎใงใ€ๅคงใใ„ๅดใฏๆฐ—ใซใ—ใชใใฆใ‚ˆใ„ for s in [-1, 1]: a = x + d*s if p.count(a) == 0: print(a) exit()
1
14,080,713,930,668
null
128
128
N=int(input()) S=list(input()) if N%2==1: print("No") else: n=int(N/2) if S[0:n]==S[n:N]: print("Yes") else: print("No")
while True: m,f,r= map(int,input().split()) if m+f+r==-3:break if m==-1 or f==-1:s="F" elif m+f>=80:s="A" elif m+f>=65:s="B" elif m+f>=50:s="C" elif m+f>=30 and r>=50:s="C" elif m+f>=30:s="D" else:s="F" print(str(s))
0
null
74,152,633,895,440
279
57
X,Y=map(int,input().split()) b=0 for i in range(X+1): if 4*(i)+2*(X-i)==Y: b+=1 if not b==0: print("Yes") else: print("No")
x,y=map(int,input().split()) print(('No','Yes')[2*x<=y<=4*x and -~y%2])
1
13,757,032,288,612
null
127
127
import math a, b, n = list(map(int, input().split())) output = 0 if n < b: output = math.floor(a * n / b) else: output = math.floor(a * (b-1) / b) print(output)
A,B,N=map(int,input().split()) # A,B,N=11, 10, 5 ans=0 if N>=B: ans=(A*(B-1))//B - A*((B-1)//B) else: ans=(A*N)//B - A*(N//B) print(ans)
1
28,202,938,385,678
null
161
161
def gcd( x, y ): if 1 < y < x: return gcd( y, x%y ) else: if y == 1: return 1 return x a, b = [ int( val ) for val in raw_input( ).split( " " ) ] if a < b: a, b = b, a print( gcd( a, b ) )
N, K = map(int, input().split()) ans = 0 for height in map(int, input().split()): if height >= K: ans += 1 print(ans)
0
null
89,792,937,140,048
11
298
a=int(input()) b=int(input()) print(6//(a*b))
N, K = map(int, input().split()) p = list(map(int, input().split())) import numpy as np data = np.array(p) + 1 Pcum = np.zeros(N + 1, np.int32) Pcum[1:] = data.cumsum() length_K_sums = Pcum[K:] - Pcum[0:-K] print(np.max(length_K_sums)/2)
0
null
92,806,696,771,642
254
223
N, K = map(int,input().split()) MOD = 10**9 + 7 ans = 0 for k in range(K,N+2): m = (k*(k-1))//2 M = (k*(N+N-k+1))//2 ans += M-m+1 print(ans%MOD)
N, K = map(int, input().split()) sum_pattern_num = 0 for num_cnt in range(K, N+2): if num_cnt == K: min_sum_frac = sum([i for i in range(0, K)]) max_sum_frac = sum([i for i in range(N - K + 1, N + 1)]) else: min_sum_frac = min_sum_frac + (num_cnt - 1) max_sum_frac = max_sum_frac + (N - num_cnt + 1) sum_pattern_num = \ (sum_pattern_num + (max_sum_frac - min_sum_frac + 1)) % 1000000007 print(sum_pattern_num)
1
33,106,362,191,048
null
170
170
from sys import stdin from collections import defaultdict, Counter N, P = map(int, stdin.readline().split()) S, = stdin.readline().split() ans = 0 # 2 cases if P == 2 or P == 5: digitdiv = [] for i in range(N): if int(S[i]) % P == 0: ans += i + 1 else: # count = Counter() prefix = [] ten = 1 mod = 0 for i in range(N): x = (int(S[N - i - 1])*ten + mod) % P prefix.append(x) count[x] += 1 ten = (ten * 10) % P mod = x prefix.append(0) count[0] += 1 for val in count.values(): ans += val*(val - 1)//2 print (ans)
n, k = map(int,input().split()) a = list(map(int,input().split())) f = list(map(int,input().split())) a.sort() f.sort(reverse = True) af = [a[i]*f[i] for i in range(n)] def check(x): r = 0 for i in range(n): r += (max(0,(af[i]-x))+f[i]-1)//f[i] #print(r, x) if r<=k: return True else: return False ok = 10**12+1 ng = -1 while ok-ng>1: mid = (ok + ng)//2 if check(mid): ok = mid else: ng = mid print(ok)
0
null
112,034,373,212,412
205
290
S=input() h=S/3600 r=S%3600/60 s=S-h*3600-r*60 print str(h)+':'+str(r)+':'+str(s)
S = int(input()) S = S % (24 * 3600) hour = S // 3600 S %= 3600 minutes = S // 60 S %= 60 seconds = S print("%d:%d:%d" % (hour, minutes, seconds))
1
339,419,030,196
null
37
37
k=int(input()) if k==4 or k==6 or k==9 or k==10 or k==14 or k==21 or k==22 or k==25 or k==26: print(2) elif k==8 or k==12 or k==18 or k==20 or k==27: print(5) elif k==16: print(14) elif k==24: print(15) elif k==32: print(51) elif k==28 or k==30: print(4) else: print(1)
N = list(map(int, "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".split(", "))) n = int(input()) print(N[n-1])
1
50,011,928,543,640
null
195
195
import sys input = sys.stdin.readline def main(): H, A = map(int, input().split()) answer = 0 while H > 0: H -= A answer += 1 print(answer) if __name__ == '__main__': main()
import math n = float(input()) a = math.floor(n/1.08) x = [] if math.floor((a)*1.08) == n: print(a) elif math.floor((a+1)*1.08) == n: print(a+1) elif math.floor((a+2)*1.08) == n: print(a+2) elif math.floor((a+3)*1.08) == n: print(a+3) elif math.floor((a-1)*1.08) == n: print(a-1) else: print(":(")
0
null
101,599,462,344,480
225
265
from math import sqrt N = int(input()) def f(x): n = N while n % x == 0: n //= x return n % x == 1 ans = 1 for k in range(2, int(sqrt(N)) + 1): res = N % k if res == 0: k1, k2 = k, N // k ans += 1 if f(k1) else 0 ans += 1 if k1 != k2 and f(k2) else 0 elif res == 1: ans += 1 if k == (N - 1) // k else 2 if N >= 3: ans += 1 print(ans)
N = int(input()) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors ans = len(make_divisors(N-1)) - 1 #print(ans) divisors = make_divisors(N) def dfs(x,N): while N % x == 0: N //= x # print(N) N %= x # print(N) return N == 1 counta = 0 for i in range(1,len(divisors)): if dfs(divisors[i],N): counta += 1 #print(counta) ans += counta print(ans)
1
41,347,610,075,088
null
183
183
H =int(input()) #h= 1 #while 2**(h+1) <= H: # h += 1 # #n=2**(h+1) - 1 #print(n) # import math def helper(h): if h ==1: return 1 return 1 + 2 * helper(math.floor(h/2)) print(helper(H))
n,k=[int(x) for x in input().split()] ans=0 l=[0]*(k+1) i=k mod=1000000007 while i>0: l[i]=pow(k//i,n,mod) j=2*i while j<=k: l[i]=(l[i]-l[j]+mod)%mod j+=i i-=1 for i in range(1,k+1): ans+=(l[i]*i)%mod print(ans%mod)
0
null
58,581,793,253,508
228
176
l = [int(i) for i in input().split()] a = l[0] b = l[1] c = l[2] yaku = 0 for i in range(b-a+1): if c % (i+a) == 0: yaku = yaku + 1 print(yaku)
def table_composition(N): table = [] i = 1 while i <= N/2: if N%i == 0: table.append(i) i += 1 table.append(N) return table a, b, c = map(int, input().split()) table = table_composition(c) count = 0 for ele in table: if ele >= a and ele <= b: count += 1 print(count)
1
561,256,528,348
null
44
44
#n = int(input()) from collections import deque n, m = map(int, input().split()) # n=200000 # m=200000 #al = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] adjl = [[] for _ in range(n+1)] NIL = -1 appear = {} isalone = {} for i in range(m): a, b = map(int, input().split()) if appear.get((a, b), False) or appear.get((a, b), False): continue appear[(a, b)] = True appear[(b, a)] = True isalone[a] = False isalone[b] = False adjl[a].append(b) adjl[b].append(a) NIL = -1 # ๆœช็™บ่ฆ‹ใ‚’็คบใ™ๅ€ค d = [-1 for i in range(n+1)] # ้ ‚็‚น1ใ‹ใ‚‰ใฎ่ท้›ขใ‚’ๆ ผ็ดใ™ใ‚‹ใƒชใ‚นใƒˆ color = [NIL for i in range(n+1)] # ๆœชๅˆฐ้”ใ‹ใ‚’็คบใ™ใƒชใ‚นใƒˆ def bfs(start_node, color_id): # uใฏๆŽข็ดขใฎ้–‹ๅง‹็‚น global color, d q = deque([start_node]) d[start_node] = 0 color[start_node] = color_id while len(q) != 0: u = q.popleft() for v in adjl[u]: if color[v] == NIL: d[v] = d[u]+1 color[v] = color_id q.append(v) color_id = 0 for u in range(1, n+1): if color[u] == NIL: color_id += 1 bfs(u, color_id) group = {} for i in range(1, n+1): if isalone.get(i, True): continue group[color[i]] = group.get(color[i], 0)+1 mx = 1 for k, v in group.items(): mx = max(mx, v) print(mx)
N,M=map(int,input().split()) par=[i for i in range(N)] size=[1 for i in range(N)] def find(x): if par[x]==x: return x else: par[x]=find(par[x]) return par[x] def union(a,b): x=find(a) y=find(b) if x!=y: if size[x]<size[y]: par[x]=par[y] size[y]+=size[x] else: par[y]=par[x] size[x]+=size[y] else: return for i in range(M): a,b=map(int,input().split()) union(a-1,b-1) print(max(size))
1
3,943,059,431,492
null
84
84
class Dice: def __init__(self, faces): self.faces = tuple(faces) def roll_north(self): self.faces = (self.faces[1], self.faces[5], self.faces[2], self.faces[3], self.faces[0], self.faces[4]) def roll_south(self): self.faces = (self.faces[4], self.faces[0], self.faces[2], self.faces[3], self.faces[5], self.faces[1]) def roll_west(self): self.faces = (self.faces[2], self.faces[1], self.faces[5], self.faces[0], self.faces[4], self.faces[3]) def roll_east(self): self.faces = (self.faces[3], self.faces[1], self.faces[0], self.faces[5], self.faces[4], self.faces[2]) def number(self, face_id): return self.faces[face_id - 1] dice = Dice(list(map(int, input().split()))) commands = input() for c in commands: if c == "N": dice.roll_north() elif c == "S": dice.roll_south() elif c == "W": dice.roll_west() elif c == "E": dice.roll_east() print(dice.number(1))
a = map(int, raw_input().split()) for i in range(len(a)): point = a[i:].index(min(a[i:])) + i temp = a[i]; a[i] = a[point] a[point] = temp print '%s %s %s' % (str(a[0]), str(a[1]), str(a[2]))
0
null
322,365,031,392
33
40
#!/usr/bin/env python3 import sys import numpy as np input = sys.stdin.readline def S(): return input().rstrip() def I(): return int(input()) def MI(): return map(int, input().split()) H, W, M = MI() R = np.zeros(H + 1) C = np.zeros(W + 1) bombs = [] for _ in range(M): h, w = MI() bombs.append((h, w)) R[h] += 1 C[w] += 1 R_max = [R == max(R)] ans = max(R) + max(C) C_max = [C == max(C)] cnt = 0 for h, w in bombs: if R_max[0][h] and C_max[0][w]: cnt += 1 if cnt == np.count_nonzero(R_max) * np.count_nonzero(C_max): print(int(ans - 1)) else: print(int(ans))
import sys h,w,m = map(int,input().split()) h_lst = [[0,i] for i in range(h)] w_lst = [[0,i] for i in range(w)] memo = [] for i in range(m): x,y = map(int,input().split()) h_lst[x-1][0] += 1 w_lst[y-1][0] += 1 memo.append((x-1,y-1)) h_lst.sort(reverse = True) w_lst.sort(reverse = True) Max_h = h_lst[0][0] Max_w = w_lst[0][0] h_ans = [h_lst[0][1]] w_ans = [w_lst[0][1]] if h != 1: s = 1 while s < h and h_lst[s][0] == Max_h: h_ans.append(h_lst[s][1]) s+= 1 if w!= 1: t=1 while t < w and w_lst[t][0] == Max_w: w_ans.append(w_lst[t][1]) t += 1 memo = set(memo) #ๆŽข็ดขใ™ใ‚‹ใƒชใ‚นใƒˆใฏใ€ๆœ€ๅคงใ‚’ๅ–ใ‚‹ใ‚‚ใฎใฎ้›†ๅˆใงใชใ‘ใ‚Œใฐ่จˆ็ฎ—้‡ใฏO(m)ใซใฏใชใ‚‰ใชใ„๏ผ for j in h_ans: for k in w_ans: if (j,k) not in memo: print(Max_h+Max_w) sys.exit() print((Max_h+Max_w)-1)
1
4,693,624,567,580
null
89
89
x = int(input()) n = x//100 if x%100 <= 5*n: print(1) else: print(0)
X=int(input()) N=X%100 if N%5==0: if N//5<=X//100: print('1') else: print('0') else: if N//5+1<=X//100: print('1') else: print('0')
1
127,487,219,076,360
null
266
266
A, B, C = [int(x) for x in input().split()] if len({A, B, C}) == 2: print('Yes') else: print('No')
# Aizu Problem ALDS_1_4_D: Allocation import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input2.txt", "rt") def check(n, k, W, p): idx = 0 for i in range(k): S = 0 while W[idx] + S <= p: S += W[idx] idx += 1 if idx == n: return True return False n, k = [int(_) for _ in input().split()] W = [int(input()) for _ in range(n)] left, right = 0, 10**16 while right - left > 1: mid = (left + right) // 2 if check(n, k, W, mid): right = mid else: left = mid print(right)
0
null
34,227,294,193,638
216
24
z = [] w = [] for _ in range(int(input())): x, y = map(int, input().split()) z.append(x + y) w.append(x - y) z_max = max(z) z_min = min(z) w_max = max(w) w_min = min(w) print(max([abs(z_max - z_min), abs(w_max - w_min)]))
N = int(input()) #https://img.atcoder.jp/abc178/editorial-E-phcdiydzyqa.pdf z_list = list() w_list = list() for i in range(N): x,y = map(int, input().split()) z_list.append(x + y) w_list.append(x - y) print(max(max(z_list)-min(z_list),max(w_list)-min(w_list)))
1
3,405,813,815,832
null
80
80
N = int(input()) C = {} for _ in range(N): s = input().strip() if s not in C: C[s] = 0 C[s] += 1 print(len(C))
scnum = int(input()) word = [0]*scnum for i in range(scnum): word[i] = input() word.sort() answer = 1 for j in range(scnum-1): if word[j] != word[j+1]: answer += 1 print(answer)
1
30,323,701,163,648
null
165
165
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) result = min(a) + min(b) for _ in range(M): x, y, c = map(int, input().split()) discount = a[x-1] + b[y-1] - c result = min(result, discount) print(result)
from sys import stdin input = lambda: stdin.readline().rstrip() na, nb, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = min(a) + min(b) for i in range(m): x, y, c = map(int, input().split()) x -= 1 y -= 1 ans = min(ans, a[x] + b[y] - c) print(ans)
1
54,194,691,823,368
null
200
200
s = input() w = {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1} print(w[s])
ls = ["SUN","MON","TUE","WED","THU","FRI","SAT"] print(7 - ls.index(str(input())))
1
132,846,036,626,184
null
270
270
N=int(input()) S=str(N) A=len(S) M=0 for i in range(A): M=M+int(S[i]) if M%9==0: print("Yes") else: print("No")
print('YNeos'[input().replace('hi','')!=''::2])
0
null
28,908,334,197,600
87
199
import sys input = sys.stdin.buffer.readline def main(): N = int(input()) d = list(map(int,input().split())) if d[0] != 0: print(0) else: MOD = 998244353 use = [0 for _ in range(max(d)+1)] for num in d: use[num] += 1 if use[0] != 1: print(0) else: ans,pa = 1,1 for num in use: ans *= pow(pa,num,MOD) ans %= MOD pa = num print(ans) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- def main(): A = int(input()) B = int(input()) for i in range(1, 4): if i != A and i != B: ans = i print(ans) if __name__ == "__main__": main()
0
null
132,697,964,126,306
284
254
import math def is_prime(x): if x == 2: return True if (x == 1) or (x % 2 == 0): return False for i in range(3, math.ceil(math.sqrt(x))+1, 2): if x % i == 0: return False return True if __name__ == '__main__': element_number = int(input()) input_array = [int(input()) for i in range(element_number)] output = 0 for x in input_array: if(is_prime(x)): output += 1 print(output)
import base64 import subprocess exe_bin = "e??420s#R400000000000{}h%0RR91&<Owl00000KmY&$00000s2czP0000000000Kma%Z2>?I<9RM5v1^@s61ONa4KmY&$00000KmY&$00000KmY&$00000_yGU_00000_yGU_000002mk;8000000{{R31ONa4I066w00000I066w00000I066w000008~^|S000008~^|S000000RR91000000RR911poj5000000000000000000000000000000*bD#w00000*bD#w00000001BW000000RR911^@s6Xbk`W00000Xbm6$00000Xbm6$00000r~&{0000007zF?T00000001BW000000ssI21^@s6fDHfu00000fDIr300000fDIr30000000IC20000000IC2000002mk;8000001ONa41ONa4R004100000R004100000R004100000L;wH)00000L;wH)000001ONa400000P~~)F1ONa4YzqJY00000YzqJY00000YzqJY00000L;wH)00000L;wH)000001ONa400000QRQ@G1^@s6000000000000000000000000000000000000000000000000005C8xG00000Qss1H1ONa4Xbk`W00000Xbm6$00000Xbm6$00000m;wL*00000m;wL*000000RR9100000FKlUIHZ(76WG!rIZgqGqcsMpKHZ(4CZ!R(b1ONa45C8xG0RR91M^04$000000{{R30ssI2000001ONa46aWAK0{{R3M^04$66o;Pv0SFPAbMN%YxTqg6IY|L0ssI24gdfE0RR911^@s6000mI0RRL54gdfE000006qpP{bCw4J000000000000000000000000000000fdBvi5&!@I00000000000000000000LID5(A^-pY00000000000000000000E&%`l5&!@I00000000000000000000RR9105&!@I00000000000000000000H30ws5&!@I000000000000000000009RUCU5&!@I00000000000000000000qW}N^5&!@I00000000000000000000@c;k-5&!@I000000000000000000009{>OVAOHXW00000000000000000000Q2_t|5&!@I000000000000000000005C8xGAOHXW00000000000000000000I{*LxAOHXW00000000000000000000X#fBK5&!@I000000000000000000002>}2A5datfKoB4R000005CH%H00000U;qFB5datfU=bhy000007y$qP000000BmVub97{5D=RK@Z!R_fUtec!Z*E_6bYXIIUta)UNmNZ=WMy(?XK8bEWpY$aLu_wuWmI8eY-IpnNmNZ=a%E>}b97~LR82!{Z*FB&VPb4$0AE^8Q)zN@MN(-1Us_XiGh=CP0AE^8Q*=0KZ*yN_VRL0PNp5L$L@`Bn0AE^8Q*=0KZ*yN_VRL0MHFJ4xV_$b^bZB35bYy97MPdM7T2pi}HeX+Fb98cLVQpV&ZgXXFbV*}VbTKhwXkl_+baG*7baP2#MMY9mbTKnxVRLC?UvG1Ca%Ev{NmO4{FkeMeHeXOnQ!`&|0AE^8Q*=0KZ*yN_VRL0PNp5L$Lor2m0AE^DbTngcb#wr1X<}n8b8jv-0AF8obYWv_Ut?%%UuI!xYyfj~a%^R80AF8Ycwt{*bY*yHbO2vpV|Za-W@&C=Y-xIB0AF8hX<}nvb97;HbYE>@X>I^VOi4mRUotK<07pzoLPK9NE;24P07pzoLPJ<sUo$Q=E;#^4Oi4mRSXf^(E;IlD000620{{a60ssR51ONp90ssI20{{R3000620ssO4000000RRF369E7K5C8xGFaQ7m6lrM<000C4V*vmF5C8xGbsA|200093Z2<rP000000RRF30RR915C8xG00000iGL{q000F5c>w?b5C8xGbSaVu00062hXDWp00000Xbm6$000002mk;800000&<X$m00000a19^;000002mk;800000pa}o~00000cnu%`000002mk;800000kO}|*000002oN9u000002mk;8000002oN9u00000&<`L0000001^@s60ssI20000000000*bg88000001^@s62><{90000000000;13`G000001^@s63IG5A0000000000=no(O000001^@s63jhEB0000000000@DCsW000001^@s63;+NC0000000000_zxfe000001^@s64FCWD0000000000KoB4R000001poj54gdfE0000000000U=bhy000001poj54*&oF0000000000m=7QT000002LJ#70RR910000000000pbsDb000002LJ#70{{R30000000000s1G0j000002LJ#71ONa40000000000un!;r000002LJ#71poj50000000000xDOxz000002LJ#71^@s60000000000zz-k*000002LJ#72LJ#70000000000$PXX@000002LJ#72mk;80000000000NQ3MMNQ(u%2Ot1Qg}`(I|IkQ-#0bLx0000000000|20AfAOQa*L<b-M4<A4P|0O~PAOL6p0002#;Q#;s|0OyHAOL6q0002#(EtDc|0Oa9AOL6r0002#!2kdM|0OC1AOL6s0002#u>b%6|0N;^AOL6t0002#p#T5>|0Nm+AOL6u0002#kpKVx|0NO!AOL6v0002#fdBvh|0N0sAOL2N0000000000Q!)QYjU9~w002mX>>y-Fiv%So0000;i9{qAF~I0u|Ns9;jdUaoNR2&V2p|AR#|1tKAOHXW008J=|Ns9;jdUasNQuYjRR90~NR4zP6iA83=tuwm|BFN<6iAIVFaiJo53fWd5IaO93`h@5-bjhx=okP0|45BJ@CG0NNQuHoiQec%|Ns9;jdUanNR2(&1|R^s0RR91#zZ6w3g{~T|NlsfOe7d&NHYv2C;$KebqGj<#2_)iTf^x6{{R0E9{^@94<Cd800000NR2(x2p|ARgX{?C0RR90NQ*r|1|R@PjTK4;AOJ{>HM9sI07!$x2<fu^|Nmx?G3`l-(OyW2;z)z!@K97tjRk4}002mh4f6m107#8J-2VUn{}tv1AOQ3aA4C8ENR2%S1|R@cNR0&n1|R@PIrvD4<#ZWHiv_v`AOJ{(z;q2=|KMgW4<Cd800000UBeF_KmcYg4<Cd800000NR2(o1t0)OjWxmrAOKZJDgH=_<w(K)14xPRNWthoNCC!3(f)K8NQ(u51t0)Og}`(SUH{-_4<Cd800000UBeF_KmcYg4<Cd800000fIZ;{AOHY$FGzzuF9jd~098nd<#Y^4i#=KeAOPqM{{R2zNdN!;#s#?tAOHbf!w(;T00000^TTEjA4C8ERY-~DUFl~3|NmwWA4C8EL03UmNr~4%RY6otjU{#hAOKZJjV*oxAOKTAiTz25_Dm_|NQ3MMNWuLB=nwt>|44=HbRaR?4<Cd800000Oo{qTiS|T^??L|*+(?7N0Z2LBb?Qii#0XnmL0myyL0&;$!;oe!4<Cd800000^TPlDNQ3MMNQ1-(!vFvP0RRF3PHzBNWpe-k0UHB5KmY&$2LJ#7)cpVdi~s-tRQ><|v;Y7AWc~mD%m4rYH2(kp@Bjb+Wd8sETmS$7bpQYV3;_TD<p2NwQ~>}06aWAK000000eVsZ0eBDr8w>{skO2n}6aWAK8~^|S0RI2~D*ylh00000000006aWAK000000eVsZ0eBDr8w>{skO2SyBme*a8~^|SK>YvzfB*mh01gmF4j4)g3wH>B06!W#Dl;S^000006aWAKL;wH)nEe0$2mk;80000000000AOHXWTmS$7ko^Du!vFvP06`8Ag91$sFaoR!4iG~Q2tf+~7ytkOfB*mhJpKRwE&u=k080)KUJeKV00000L;wH)oB#j-VE+IAWdHyG074EBj{-st7>)x)4j_#LLJla51xOAsh6YFuID-dG4nT4aI6)3DK@KQF4j@7f7(xyZLJkN35C8xG<NyEwi2nco0ssI20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000&<X$m00000pa}o~00000kO}|*000000RR91000000RR91000000RR910000069E7K000003;+NC00000AP4{e000004FCWD00000R0{wA0000082|tP00000Xbm6$000008vp<R000005C8xG000008UO$Q00000cnu%`000008~^|S000002mk;800000_5S~F00000m;wL*000001poj500000Km-5)000001^@s600000zybgO000003IG5A00000lK}t#000003jhEB000007ytkO000006#xJL0000000000000000{{R300000fDa%5000000ssI200000r~m)}000006aWAK000002LJ#7000007XSbN00000cn1Ig000002LJ#700000SOx$9000002mk;800000AOQdX000002><{9000007ytkO000009smFU000002mk;800000`~UxM000000RR9900000{{R1P00000_yqs}00000|NsAQ000000ssI200000@c;jB00000)CB+l00000`TzfK000001ONa4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fDIr30000000000000000000000000RtNw900000W(WWP00000b_f6f00000h6n%v00000mIwd<00000rU(E400000wg><K0000000000000000000000000000000000000000000000000000000000000000000000000002oN9u00000M?*t8AShL0b#8QZAU7^GE-)=Kbz*gHbagR)F*q(TG$|lAE;TMN0000000000000000000000000000000000000000000000{{U4I066w000000000000000000000{{X5R0041000000000000000000000{{a6bOHbX000000000000000000000{{d7m;wL*000000000000000000000{{g8zybgO000000000000000000000{{j9Km-5)000000000000000000000{{mA)CB+l000000000000000000000{{pB_yqs}000000000000000000000{{sCSOx$9000000000000000000000{{vDcn1Ig000000000000000000000{{yEAP4{e000000000000000000000{{#FKnMT;000000000000000000000{{&Gzz6^U000000000000000000000{{*H&<Fqk000000000000000000000{{;IR0{wA000000000000000000000{{>JU<&{M000000000000000000000{{^KYzqJY000000000000000000000{{{LunPbH000000000000000000000{{~MXbm6$000000000000000000000{|2Ncnu%`000000000000000000000{|5OfDIr3000000000000000000000{|8PfDa%5000000000000000000000{|BQ01zMm000000000000000000000{|ERKoB4R000000000000000000000{|HS000000000000000000000RR911OV~>000000000000000000002><{90ssyGpa}o~00000E&u=k000009RL6T0RR{Pc@iK1000000RR9100000EC2ui1OV~>00000000000000000000Hvj+t0ssyG015yA000000000000000IRF3v0ssyGKnef=000000000000000OaK4?0ssyGkO}|*000000000000000VgLXD0RR{PcoHB0000000RR9100000aR2}S0RR*Lcnu%`000000000000000m;e9(0ssyG&<X$m000000000000000qyPW_0RR&KXbm6$000000000000000EC2ui1OV~>00000000000000000000!vFvP0RR#J)C>Rs000000000000000000001OV~>00000000000000000000(EtDd000pHYzqJY000000000000000<NyEw0RR;MfDIr3000000000000000?EnA(000vJcnu%`000000000000000{r~^~000vJXbm6$0000000000000005di=I0RR>NfDa%5000000000000000CjkHe5C9hd5D*{$000000000000000c>(|cAOIHt01zMm000000000000000E&%`l5daVXU<&{M000001ONa400000Jplj!5&!@I00000000000000000000YykiOA^-pY00000000000000000000hyefq5&!@I000000000000000000007ytkO5&#YW&<Fqk00000!vFvP00000oB;p;5ds$g2oN9u000000000000000sQ~~05&!@I00000000000000000000>jD4(5&#bXR0{wA000000000000000!2tjO5&!@I00000000000000000000eF6Xg5&#YW&<Owl00000D*ylh00000+W`Oo5&!@I00000000000000000000zXAXN5&#PTAP4{e000000000000000_W=L^5ds$g5D*{$0000000000000000|Ed55&!@I00000000000000000000U;+RD5datfKoB4R000005CH%H00000cLD$a5C9hd01zMm000000000000000`2YX_5C9kefD#}8000000000000000gaQBn5C9ke5D*{$000000000000000kOBYz5&!@I00000000000000000000wE_SD5&#YW;0gc$00000WdHyG00000#R32TAOHXW00000000000000000000;Q{~v5&#YWPzwM6000000ssI200000@d5w<5datfU=bhy000007y$qP000002Lk{A5&!@I00000000000000000000CIbKfAOHXW00000000000000000000H3I+uAOHXW00000000000000000000PXhn|5&!@I000000000000000000000BvDuZZ2bE0AEK;PeMUVUte=|VqZyLZDDC{0AE^DbWAv3Uukb?ZfSG?V{&wJbaiHCE@J>>WpZU_X>)XCa$j_9Ut?@<Ze?=-UteTzUuSG@Vqt7wWOQ$Gb6;U~cmQK>ZE$R5bY)~NH#Rvq0AF8ZZ(nC@Z(?C=Uu1M|a&uo{b$DN9X>Ms>VRCX|d0%C2baHtBW^!R|WnW}<ZEbk~UteZ&VQpn!WOZ$Ad0%O6X>?y<a&lpLUuAA|a(Mt>Uq(_vO+{ZtPDEc{0AF86PE}t;NMA-$K}|(pNJLTqUqo3>K}|_R0AF8eZfSI1VRCX|d0%C2WB^}ZX>MtBUtw}`VR>J3bYXII0AEK;PeMUVUr$CxQ$<u?R6#;aMPC44Wn^J=VE|uAPhWF%WNB_+b#rB80AE^8Q*=0KZ*yN_VRL0MHFJ4xV_$b^bZB35bYy97MPfieM@&gVLs(c}GcGg$UteQ*VP9rxZeeU`dSyUBM@&gVLtip3GA=a$b98cSWo|$~M@&gVLtip3GA=a$UteT%Z(nF(Ze(m_0AE^8Q)zN@MN(-%Ku1hTLPJ<sUo$Q=0AF8Ycwt{*bY*yHbU;8yOi4mRUotK-E;RsOUvqR}V{2byXlq|)VQFkYKu1hTLPK9NE;ImNUsO#)UqwztUta)UT2pi}HeX+Fb98cLVQpV&ZgXXFbV*}VbTKhwXkl_+baG*7baP2#MMY9mbTKnxVRLC?UvG1Ca%Ev{NmO4{FkeMeHeXOnQ!`&|KtM-KNkT(dSYI<PG%h&+Us_XiG-GddbU;8yOi4mRSXf^(E;ImNUu0o)VPA7}VRCc;UteN#b6<0GVRCc;Us_I6bU0~mb6;X%b7eG1ZfSHwF-3MjKu1hTLPJ<sUo$Q=0AF8hX<}nvV{>(1X>MtB0AEQ|O<!bXa%E>}b97~LR82!{Z*FB&VPb4$0AF8hX<}nvV{>(1W@&C|0AE^DbTeaVZa_dsOi4mRSXf^(E;ImNUu<b&V_$Q0VRCd|ZDDC{KtM-KNkT(kGA=SMH2_~<XKin8UvqR}a&%u`0AEQ|O<!_lXK8bEWpY$aLu_wuWmI8eY-IpnT251RIB9QlUt(c%Wi&}{X>>#}MRq_yM@&gVLs(c}GcGg$04{TRZFFH`04{TMa&%#004{TAb98caVPXI-X>N37a&Q1HZf|sDE<r*`Ep%aL04{ECbY(7QZgnnVb!lv5Eoo!`E@y6aE@)wMXaFu`d2VxgZ2&H0d2VxbasV!8ZgnnpWpZ<AZ*BlCXKr;ac4cyNX>V>{asV!JWo%(CWO;4?E^=jTVJ>iNbO0`CZfSG?E^usgE@y9a04{W8cys_RW@&C|04{QGWMOn+04`-{UuJS)ZDn6*WO4v5WoTb!a$#*{04`~6X>?y<a&lpL04`=}ZfRd(a&lpL04`*CZeeX{V*oB>VRT^tE@E?Y04`&1ZEa<4bN~PV00000000000000000000000000000000000000000000000000000000000000000000000000000000000008vp<R0RR910ssI200000I066w00000I066w000008~^|S0000000000000000RR91000000000000000BLDyZ2LJ#70ssI200000R004100000R004100000AOHXW0000000000000001ONa4000000000000000F#rGn2LJ#70ssI200000bOHbX00000bOHbX00000Bme*a0000000000000001ONa4000000000000000L;wH)_W%EH0ssI200000m;wL*00000m;wL*00000C;$Ke000001poj5000002mk;8000000000000000P5=M^3jhEB0ssI200000zybgO00000zybgO00000fB^si000001^@s60RR912mk;8000007ytkO00000RsaA10{{R30ssI200000Km-5)00000Km-5)00000lK}t#0000000000000000RR91000000000000000UH||9|NsAQ0ssI200000)CB+l00000)CB+l00000AOHXW000001poj5000000ssI2000000ssI200000YXATM{{R1P0ssI200000_yqs}00000_yqs}00000U;qFB000001^@s60ssI22mk;8000000000000000dH?_b1ONa40ssI200000SOx$900000SOx$900000AOQdX000001poj5000002mk;8000007ytkO00000ga7~l1ONa4LI3~&00000cn1Ig00000cn1Ig00000r~m)}000001poj5761SM2mk;8000007ytkO00000jsO4v0RR911^@s600000AP4{e00000AP4{e000007XSbN0000000000000001ONa4000000000000000i2wiq0RR911^@s600000KnMT;00000KnMT;00000fB*mh0000000000000005C8xG000005C8xG00000lmGw#0RR911^@s600000zz6^U00000zz6^U000002mk;80000000000000002mk;8000002mk;800000od5s;0RR911^@s600000&<Fqk00000&<Fqk00000f&u^l0000000000000005C8xG000000000000000qW}N^0RR911^@s600000R0{wA00000R0{wA000002><{90000000000000001ONa4000000000000000sQ>@~0RR910ssI200000U<&{M00000U<&{M000003jhEB0000000000000001ONa4000000000000000u>b%70RR910ssI200000YzqJY00000YzqJY00000L;wH)0000000000000001ONa4000000000000000zW@LL0RR910ssI200000unPbH00000unPbH00000C;<Qf0000000000000002mk;8000000000000000$p8QV4gdfE0{{R300000Xbm6$00000Xbk`W000005C8xG0000000000000002mk;8000002mk;800000)c^nh4*&oF0{{R300000cnu%`00000cntsm000002mk;80000000000000002mk;8000002mk;800000;Q#;t1^@s60{{R300000fDIr300000fDHfu0000000IC2000001^@s6000002mk;8000005C8xG00000m;e9(0RR910{{R300000fDa%500000fDZrw00000fB*mh0000000000000002mk;8000002mk;800000>Hq)$0RR910{{R30000001zMm0000001yBG000005C8xG0000000000000002mk;8000000000000000@Bjb+2mk;80{{R300000KoB4R000005D)+W00000Kmq^&000000000000000KmY&$000000000000000^#A|>0RR91FaQ7m0000000000000005D)+W00000DF6Tf0000000000000000RR91000000RR91000000RR910ssI200000000000000000000Ko9@`00000@CE<?000008vp<REdT%j2mk;8000007ytkO000002><{90{{R300000000000000000000Fc$y-00000bOQhY0000000000000000RR910000000000000005dZ)H0{{R300000000000000000000q#6JK00000{r~^~0000000000000000RR91000000000000000" open("./kyomu", 'wb').write(base64.b85decode(exe_bin)) subprocess.run(["chmod +x ./kyomu"], shell=True) subprocess.run(["./kyomu"], shell=True)
0
null
1,799,109,322,514
12
81
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): X = int(input()) print(X ^ 1) if __name__ == "__main__": main()
print('1' if int(input()) == 0 else '0')
1
2,925,045,478,454
null
76
76
array_str = '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' array = array_str.split(', ') k = int(input()) print(array[k - 1])
N = int(input()) get = set() for _ in range(N): s = str(input()) get.add(s) print(len(get))
0
null
40,106,642,039,428
195
165
def cubic(x): return x ** 3 def main(): x = int(input()) y = cubic(x) return y print(main())
import math A, B, H, M = map(int, input().split()) X, Y = A*math.cos(math.pi*(60*H+M)/360), -A*math.sin(math.pi*(60*H+M)/360) x, y = B*math.cos(math.pi*M/30), -B*math.sin(math.pi*M/30) print(math.sqrt((X-x)**2+(Y-y)**2))
0
null
10,145,111,738,192
35
144
n = int(input()) #lis = list(map(int,input().split())) for i in range(1,10): q = n // i r = n % i if r == 0 and q < 10: print("Yes") exit() print("No")
N = int(input()) if N > 81: print('No') ans_list = [] if N <= 81: for i in range(1,10): for j in range(1,10): ans_list.append(i * j) if N in ans_list: print('Yes') if N not in ans_list: print('No')
1
159,781,387,215,970
null
287
287
N, K, C = map(int, input().split()) S = input() S_reverse = S[::-1] left_justified = [-1 for _ in range(N)] right_justified = [-2 for _ in range(N)] for i_justified in (left_justified, right_justified): if i_justified == left_justified: i_S = S nearest_position = 1 positioning = 1 else: i_S = S_reverse nearest_position = K positioning = -1 i_K = 0 while i_K <= N-1: if i_S[i_K] == 'o': i_justified[i_K] = nearest_position i_K += C nearest_position += positioning i_K += 1 for i_N in range(N): if left_justified[i_N] == right_justified[N - i_N - 1]: print(i_N + 1)
import sys N = int(input()) X = [int(c) for c in input().split()] l = [10**10] for i in range(1,101): l.append(0) for j in range(len(X)): l[i] += (X[j]-i)**2 if l[i-1] < l[i]: print(l[i-1]) sys.exit(0)
0
null
53,127,626,071,140
182
213
from collections import deque n, q = map(int, input().split()) queue = deque([]) for i in range(n): a = input().split() queue.append([a[0], int(a[1])]) time = 0 while queue: b = queue.popleft() if b[1] <= q: time += b[1] print(b[0] + ' ' + str(time)) else: b[1] -= q time += q queue.append(b)
N = int(input()) hash = {} end = int(N ** (1/2)) for i in range(2, end + 1): while N % i == 0: hash[i] = hash.get(i, 0) + 1 N = N // i if N != 1: hash[i] = hash.get(i, 0) + 1 count = 1 res = 0 for i in hash.values(): count = 1 while i >= count: res += 1 i -= count count += 1 print(res)
0
null
8,405,556,395,350
19
136
from sys import exit x, n = map(int, input().split()) p = list(map(int, input().split())) for d in range(x+1): #0ใซ้”ใ—ใŸๆ™‚็‚นใง0ใ‚’ๅ‡บๅŠ›ใ—ใฆ็ต‚ไบ†ใ™ใ‚‹ใฎใงใ€ๅคงใใ„ๅดใฏๆฐ—ใซใ—ใชใใฆใ‚ˆใ„ for s in [-1, 1]: a = x + d*s if not a in p: print(a) exit()
x, n = map(int, input().split()) p = list(map(int, input().split())) n = list(i for i in range(-1, 110) if i not in p) diff = 110 ans = 0 for i in n: if diff > abs(x-i): diff = abs(x-i) ans = i print(ans)
1
14,010,307,314,876
null
128
128
x = list(input().split(" ")) a = int(x[0]) b = int(x[1]) c = int(x[2]) divisors = 0 for i in range(a, b+1): if c % i == 0: divisors += 1 print(divisors)
l = input().split() a = int(l[0]) b = int(l[1]) c = int(l[2]) d = [] for i in range(a,b+1): if c % i == 0: d.append(i) print(len(d))
1
561,896,904,632
null
44
44
while True: c = input().split() x, y = int(c[0]), int(c[1]) if x == y == 0: break if y < x: x, y = y, x print("%d %d" % (x, y))
# coding: utf-8 import sys i = sys.stdin for line in i: a,b = map(int,line.split()) if a == 0 and b == 0: break if a < b: print(a,b) else: print(b,a)
1
521,126,929,846
null
43
43
H1,M1,H2,M2,K = map(int,input().split()) A1 = H1*60+M1 A2 = H2*60+M2 print(max(0,A2-A1-K))
import sys from collections import Counter from collections import deque import heapq import math import fractions import bisect import itertools def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) a,b,c,d,k=mp() print(c*60+d-a*60-b-k)
1
18,030,597,520,500
null
139
139
x = input().split() a,b,c=[int(x) for x in x] ans=0 for x in range(a,b+1): if c%x==0:ans+=1 print(ans)
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(input()) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=' '): print(k.join(list(map(str, lst)))) INF = float('inf') # from math import ceil, floor, log2 # from collections import deque # from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush # import numpy as np # cumsum # from bisect import bisect_left, bisect_right def solve(): N = II() A = LI() memo = {} ans = 0 for i, a in enumerate(A): i = i + 1 # print(i, a - i, i - a) ans = ans + memo.get(i - a, 0) memo[a + i] = memo.get(a + i, 0) + 1 print(ans) if __name__ == '__main__': solve()
0
null
13,290,503,832,932
44
157
input();print " ".join(raw_input().split()[::-1])
import math def koch_kurve(n, p1=[0, 0], p2=[100, 0]): if n == 0: return s, t, u = make_edge_list(p1, p2) koch_kurve(n-1, p1, s) # print(s) # print(s) print(" ".join([ str(i) for i in s ])) koch_kurve(n-1, s, u) print(" ".join([ str(i) for i in u ])) koch_kurve(n-1, u, t) print(" ".join([ str(i) for i in t ])) koch_kurve(n-1, t, p2) def make_edge_list(p1, p2): sx = 2 / 3 * p1[0] + 1 / 3 * p2[0] sy = 2 / 3 * p1[1] + 1 / 3 * p2[1] # s = (sx, sy) s = [sx, sy] tx = 1 / 3 * p1[0] + 2 / 3 * p2[0] ty = 1 / 3 * p1[1] + 2 / 3 * p2[1] t = [tx, ty] theta = math.radians(60) ux = math.cos(theta) * (tx - sx) - math.sin(theta) * (ty - sy) + sx uy = math.sin(theta) * (tx - sx) + math.cos(theta) * (ty - sy) + sy u = [ux, uy] return s, t, u n = int(input()) print("0 0") koch_kurve(n) print("100 0")
0
null
552,344,584,062
53
27
n,k=map(int,input().split()) #้šŽไน— F = 200005 mod = 10**9+7 fact = [1]*F inv = [1]*F for i in range(2,F): fact[i]=(fact[i-1]*i)%mod inv[F-1]=pow(fact[F-1],mod-2,mod) for i in range(F-2,1,-1): inv[i] = (inv[i+1]*(i+1))%mod ans=1 for i in range(1,min(n,k+1)): comb=(fact[n]*inv[i]*inv[n-i])%mod h=(fact[n-1]*inv[i]*inv[n-1-i])%mod ans=(ans+comb*h)%mod print(ans)
A,B = map(int, input().split()) tmp_A, tmp_B = max(A,B), min(A,B) while 1: if tmp_A % tmp_B != 0: tmp = tmp_B tmp_B = tmp_A%tmp_B tmp_A = tmp else: if tmp_B == 1: result = A*B break else: result = int(A*B/tmp_B) break print(result)
0
null
90,418,800,608,344
215
256
p,r=input,range A=sum([list(map(int,p().split()))for _ in r(3)],[]) b=[int(p())for _ in r(int(p()))] print('Yes'if[v for v in[7,56,73,84,146,273,292,448]if sum(1<<i for i in r(9)if A[i]in b)&v==v]else'No')
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)]) a = inpll(3) n = inp() B = inplm(n) tmp = np.zeros((3,3),dtype=np.int) for b in B: for i in range(3): for j in range(3): if a[i][j] == b: tmp[i][j] = 1 ans = 'No' if np.any(np.all(tmp == 1,axis=0) == True) or np.any(np.all(tmp == 1,axis=1) == True) or (tmp[0][0] == 1 and tmp[1][1] == 1 and tmp[2][2] == 1) or (tmp[0][2] == 1 and tmp[1][1] == 1 and tmp[2][0] == 1): ans = 'Yes' print(ans)
1
60,027,090,430,770
null
207
207
N = int(input()) A = list(map(int,input().split())) D = [0] * (10**6 + 1) A.sort() for i in range(N): D[A[i]] += 1 ans = 0 for i in range(1, 10**6+1): if D[i]: if D[i]==1: ans += 1 for j in range(i,A[-1]+1,i): D[j] = 0 print(ans)
n, k = map(int, input().split()) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort(reverse = True) cost = max([a[i] * f[i] for i in range(n)]) cost2 = 0 while True: cost3 = (cost + cost2) // 2 count = 0 for i in range(n): count += max((a[i] * f[i] - cost3 - 1) // f[i] + 1, 0) if count <= k: cost = cost3 else: cost2 = cost3 + 1 if cost == cost2: break print(cost)
0
null
89,620,491,045,568
129
290
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) X = int(input()) big_coin, amari = divmod(X, 500) print(big_coin*1000+(amari//5)*5)
a,b,x = map(int,input().split()) import math d = x/(a**2) c = b-d e = c*2 if e<=b: f = (e**2+a**2)**(1/2) g = (f**2+a**2-e**2)/(2*f*a) print(math.degrees(math.acos(g))) else: e = 2*x/(a*b) #print(e) a = b f = (e**2+a**2)**(1/2) g = (f**2+a**2-e**2)/(2*f*a) print(90-(math.degrees(math.acos(g))))
0
null
102,706,970,354,858
185
289
s=input() t=input() for i in range(len(s)): if s[i]!=t[i]: print("No") exit() if len(t)==len(s)+1: print("Yes")
import sys import bisect as bi import math from collections import defaultdict as dd import heapq input=sys.stdin.readline ##import numpy as np #sys.setrecursionlimit(10**7) mo=10**9+7 def cin(): return map(int,sin().split()) def ain(): return list(map(int,sin().split())) def sin(): return input() def inin(): return int(input()) ##def power(x, y): ## if(y == 0):return 1 ## temp = power(x, int(y / 2))%mo ## if (y % 2 == 0):return (temp * temp)%mo ## else: ## if(y > 0):return (x * temp * temp)%mo ## else:return ((temp * temp)//x )%mo ## ##for _ in range(inin()): n=inin() d=dd(int) for i in range(n): s=sin().strip() d[s]+=1 print("AC x",d["AC"]) print("WA x",d["WA"]) print("TLE x",d["TLE"]) print("RE x",d["RE"]) ## ##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power ##def pref(a,n,f): ## pre=[0]*n ## if(f==0): ##from beginning ## pre[0]=a[0] ## for i in range(1,n): ## pre[i]=a[i]+pre[i-1] ## else: ##from end ## pre[-1]=a[-1] ## for i in range(n-2,-1,-1): ## pre[i]=pre[i+1]+a[i] ## return pre ##maxint=10**24 ##def kadane(a,size): ## max_so_far = -maxint - 1 ## max_ending_here = 0 ## ## for i in range(0, size): ## max_ending_here = max_ending_here + a[i] ## if (max_so_far < max_ending_here): ## max_so_far = max_ending_here ## ## if max_ending_here < 0: ## max_ending_here = 0 ## return max_so_far
0
null
15,000,156,432,452
147
109
# Function for calc def match(n, a, b): if (b - a)% 2 == 0: print((b-a)/2) else: if (n - b) >= a: print((a)+((b-(a+1))/2)) else: x=(n-b+1) print(x+((n-(a+x))/2)) # Run match in_string = raw_input() [N, A, B] = [int(v) for v in in_string.split()] match(N, A, B)
print("pphbhhphph"[int(input())%10]+"on")
0
null
64,505,172,749,578
253
142
from collections import deque infty = 10 ** 9 def BFS(graph, parent, u): queue = deque() queue.append(u) visited = [False for k in range(len(parent))] #ๆŽข็ดขใŒๅง‹ใพใฃใŸใ‹ๅฆใ‹ visited[u] = True while queue: v = queue.popleft() for j in graph[v]: if not visited[j]: queue.append(j) visited[j] = True parent[j] = v n, m = map(int, input().split()) graph = [[] for i in range(n)] for i in range(m): a, b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) parent = [-1 for i in range(n)] BFS(graph, parent, 0) if -1 in parent[1:]: print("No") else: print("Yes") for p in parent[1:]: print(p+1)
import sys A, B = map(int,input().split()) def solve(): ret = A*B return ret print(solve())
0
null
18,140,990,904,708
145
133
import sys 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".split(", ") N = int(sys.stdin.readline().rstrip()) print(A[N-1])
L = "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 = L.split(", ") k = int(input()) print(L[k-1])
1
49,845,377,217,860
null
195
195
n, W = map(int, input().split()) ab = [tuple(map(int, input().split()))for _ in range(n)] ab.sort() dp = [[0]*W for _ in range(n+1)] for i in range(1, n+1): w, v = ab[i-1] for j in range(W): if dp[i][j] < dp[i-1][j]: dp[i][j] = dp[i-1][j] if 0 <= j-w and dp[i][j] < dp[i-1][j-w]+v: dp[i][j] = dp[i-1][j-w]+v ans = 0 for i in range(n): a, b = ab[i] if ans < dp[i][W-1]+b: ans = dp[i][W-1]+b print(ans)
n,t = map(int,input().split()) l = [] for i in range(n): a,b = map(int,input().split()) l.append([a,b]) l.sort(key=lambda x:x[0]) dp = [[0 for i in range(t)] for i in range(n+1)] al = [] for i in range(n): a,b = l[i] for j in range(t): if dp[i][j] == 0: if j == 0: if j + a < t: dp[i+1][j+a] = max(dp[i][j+a],b) else: al.append(b) else: if j + a < t: dp[i+1][j+a] = max(dp[i][j+a],dp[i][j]+b) else: al.append(dp[i][j]+b) dp[i+1][j] = max(dp[i+1][j],dp[i][j]) if len(al) > 0: print(max(max(dp[n]),max(al))) else: print(max(dp[n]))
1
151,116,479,558,304
null
282
282
import fractions lst = [] for i in range(200): try: lst.append(input()) except EOFError: break nums = [list(map(int, elem.split(' '))) for elem in lst] # gcd res_gcd = [fractions.gcd(num[0], num[1]) for num in nums] # lcm res_lcm = [nums[i][0] * nums[i][1] // res_gcd[i] for i in range(len(nums))] for (a, b) in zip(res_gcd, res_lcm): print('{} {}'.format(a, b))
import sys a = int(input()) print (a+a**2+a**3)
0
null
5,148,498,686,050
5
115
import math PI = math.pi r = input() men = r*r * PI sen = r*2 * PI print('%.6f %.6f' % (men, sen))
import math r=input() p=math.pi print "{0:.6f} {1:.6f}".format(r*r*p,2*r*p)
1
640,624,294,902
null
46
46
l=[list(map(int,input().split())) for _ in range(int(input()))] f=sorted([x+y for x,y in l]) g=sorted([x-y for x,y in l]) print(max(f[-1]-f[0],g[-1]-g[0]))
n=int(input()) a=[] b=[] c=[] d=[] for i in range(n): k,l=map(int,input().split()) a.append((k-l,i)) b.append((k+l,i)) c.append((-k-l,i)) d.append((-k+l,i)) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) d.sort(reverse=True) print(max(a[0][0]+d[0][0],b[0][0]+c[0][0]))
1
3,429,301,314,506
null
80
80
def main(): H, W, K = (int(i) for i in input().split()) A = [input() for i in range(H)] ans = [[-1]*W for _ in range(H)] p = 1 for h in range(H): flag = False cnt = 0 for w in range(W): if A[h][w] == "#": flag = True cnt += 1 upper = p + cnt if not(flag): continue for w in range(W): ans[h][w] = p if A[h][w] == "#": if p + 1 < upper: p += 1 p = upper for h in range(H): for w in range(W): if ans[h][w] != -1: continue if h != 0: ans[h][w] = ans[h-1][w] for h in range(H)[::-1]: for w in range(W): if ans[h][w] != -1: continue if h != H-1: ans[h][w] = ans[h+1][w] for a in ans: print(*a) if __name__ == '__main__': main()
import copy h, w = map(int,input().split()) maze = [[9]*(w+2)] for i in range(h): s = input() tmp = [9] for j in s: if j == "#": tmp.append(9) else: tmp.append(0) tmp.append(9) maze.append(tmp) maze.append([9]*(w+2)) #print(maze) def bfs(start): maze2 = copy.deepcopy(maze) #print(maze2) pos = [start] max_depth = 0 maze2[start[0]][start[1]] = 2 while len(pos): x, y, depth = pos.pop(0) max_depth = max(depth, max_depth) if maze2[x-1][y] < 2: pos.append([x-1,y,depth + 1]) maze2[x-1][y] = 2 if maze2[x+1][y] < 2: pos.append([x+1,y,depth + 1]) maze2[x+1][y] = 2 if maze2[x][y-1] < 2: pos.append([x,y-1,depth +1]) maze2[x][y-1] = 2 if maze2[x][y+1] < 2: pos.append([x,y+1,depth +1]) maze2[x][y+1] = 2 return max_depth ans = 0 for i in range(h): for j in range(w): start = [i+1,j+1,0] maze2 = maze if maze[i+1][j+1] != 9: #print(bfs(start)) ans = max(ans,bfs(start)) print(ans)
0
null
119,072,240,167,480
277
241
n = int(input()) a_ls = list(map(int, input().split())) def isOK(a,b,c): return abs(a-b) < c < a+b a_ls.sort() ans = 0 for i in range(n): short = a_ls[i] r = i+1 num = 0 for l in range(i+1,n-1): while r+1 < n and isOK(short, a_ls[l], a_ls[r+1]): r += 1 num += r - l if l == r: r += 1 ans += num print(ans)
a,b,c = map(int,input().split()) if a == b and b == c and c == a: print('No') elif a != b and b != c and c != a: print('No') else: print('Yes')
0
null
119,823,395,284,340
294
216
n = int(input()) v = [input() for i in range(n)] for i in ["AC", "WA", "TLE", "RE"]: print("{} x {}".format(i, v.count(i)))
n = int(input()) c0 = 0 c1 = 0 c2 = 0 c3 = 0 for _ in range(n): s = input() if s == 'AC': c0 += 1 elif s == 'WA': c1 += 1 elif s == 'TLE': c2 += 1 elif s == 'RE': c3 += 1 print('AC x', c0) print('WA x', c1) print('TLE x', c2) print('RE x', c3)
1
8,634,478,180,988
null
109
109
import math n, k = map(int,input().split()) list = [int(x) for x in input().split()] list.sort() l = 0 r = max(list) while r - l > 1: count = 0 x = (r + l)//2 for i in range(len(list)): if x >= list[i]: continue count += math.ceil(list[i]/x) - 1 if count <= k: r = x else: l = x print(r)
a,b=list(map(int ,input().split())) print(a*b)
0
null
11,065,328,770,258
99
133
for x in range(1, 10): for y in range(1, 10): print "{}x{}={}".format(x, y, x*y)
for a in range(1,10): for b in range(1,10): i = a * b print(a,"x",b,"=",i,sep="")
1
125,060
null
1
1
n, m, k = map(int, input().split()) MOD = 998244353 ans = 0 c = 1 for i in range(k + 1): ans = (ans + m * pow(m - 1, n - i - 1, MOD) * c) % MOD c = (c * (n - 1 - i) * pow(i + 1, MOD - 2, MOD)) % MOD # print(f"{ans = }, {c = }") print(ans)
import sys, math, itertools input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**20 MOD = 998244353 def I(): return int(input()) def F(): return float(input()) def S(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def factorialMod(n, p): fact = [0] * (n+1) fact[0] = fact[1] = 1 factinv = [0] * (n+1) factinv[0] = factinv[1] = 1 inv = [0] * (n+1) inv[1] = 1 for i in range(2, n + 1): fact[i] = (fact[i-1] * i) % p inv[i] = (-inv[p % i] * (p // i)) % p factinv[i] = (factinv[i-1] * inv[i]) % p return fact, factinv def combMod(n, r, fact, factinv, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p def resolve(): N, M, K = LI() ans = 0 fact, factinv = factorialMod(N, MOD) for i in range(K + 1): ans += combMod(N - 1, i, fact, factinv, MOD) * M * pow(M - 1, N - 1 - i, MOD) ans %= MOD print(ans) if __name__ == '__main__': resolve()
1
22,982,315,846,460
null
151
151
mod = 10**9+7 N, K = map(int,input().split()) A = sorted(list(map(int,input().split()))) pi = 1 ni = 0 ans = 1 i = 0 while i < K-1: if A[ni]*A[ni+1] > A[-pi]*A[-pi-1]: ans = ans*A[ni]*A[ni+1]%mod ni += 2 i += 2 else: ans = ans*A[-pi]%mod pi += 1 i += 1 if i == K-1: ans = ans*A[-pi]%mod if A[-1]<0 and K%2==1: ans = 1 for i in A[N-K:]: ans = ans*i%mod print(ans)
N, K = map(int, input().split()) A = [-1] * (N+1) for i in range(K): d_list = int(input()) B = input().split() B = [int(x) for x in B] for i in range(1, N+1): if i in B: A[i] = 1 count = 0 for i in range(1, N+1): if A[i] == -1: count += 1 print(count)
0
null
17,064,068,914,850
112
154
k, n = map(int, input().split()) a = [int(i) for i in input().split()] a += [a[0] + k] sum = 0 max = 0 # ๆœ€ใ‚‚้•ทใ„่พบใ‚’ๆฑ‚ใ‚ใ‚‹ for i in range(n): d = abs(a[i] - a[i + 1]) sum += d if max < d: max = d # ๆœ€ใ‚‚้•ทใ„่พบใ‚’้€šใ‚‰ใšใซ1ๅ‘จๅ›žใ‚‹ใฎใŒๆœ€ๅฐ print(sum - max)
from collections import deque K = int(input()) q = deque([1,2,3,4,5,6,7,8,9]) for i in range(K): num = q.popleft() if num%10 != 0: q.append(num*10+num%10-1) q.append(num*10+num%10) if num%10 != 9: q.append(num*10+num%10+1) print(num)
0
null
41,920,143,758,108
186
181
#!/usr/bin/env python3 import sys from math import gcd from collections import defaultdict sys.setrecursionlimit(10**8) MOD = 1000000007 # type: int def solve(N: int, A: "List[int]", B: "List[int]"): def quadrant(a, b): if a > 0 and b >= 0: return 0 elif a <= 0 and b > 0: return 1 elif a < 0 and b <= 0: return 2 elif a >= 0 and b < 0: return 3 else: return None def norm(a, b): g = gcd(a, b) a //= g b //= g while quadrant(a, b) != 0: a, b = -b, a return a, b d = defaultdict(lambda: [0, 0, 0, 0]) kodoku = 0 for i, (a, b) in enumerate(zip(A, B)): if (a, b) == (0, 0): kodoku += 1 else: d[norm(a, b)][quadrant(a, b)] += 1 ans = 1 for v in d.values(): buf = pow(2, v[0]+v[2], MOD) buf += pow(2, v[1]+v[3], MOD) buf = (buf-1) % MOD ans *= buf ans %= MOD print((ans-1+kodoku) % MOD) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int()] * (N) # type: "List[int]" B = [int()] * (N) # type: "List[int]" for i in range(N): A[i] = int(next(tokens)) B[i] = int(next(tokens)) solve(N, A, B) if __name__ == '__main__': main()
N=int(input()) a=[int(x) for x in input().split()] cnt=0 for i in range(N): if i%2==0 and a[i]%2==1: cnt+=1 print(cnt)
0
null
14,312,730,076,032
146
105
MOD = pow(10, 9)+7 def combi(n, k, MOD): numer = 1 for i in range(n, n-k, -1): numer *= i numer %= MOD denom = 1 for j in range(k, 0, -1): denom *= j denom %= MOD return (numer*(pow(denom, MOD-2, MOD)))%MOD def main(): n, a, b = map(int, input().split()) allsum = pow(2, n, MOD) s1 = combi(n, a, MOD) s2 = combi(n, b, MOD) ans = (allsum - s1 - s2 - 1)%MOD print(ans) if __name__ == "__main__": main()
import math import sys import collections import bisect readline = sys.stdin.readline def main(): n, a, b = map(int, readline().rstrip().split()) mod = 10 ** 9 + 7 ans = pow(2, n, mod) - 1 nca, ncb = 1, 1 for i in range(b): ncb = ncb * (n - i) % mod ncb *= pow(i + 1, mod - 2, mod) if i + 1 == a: nca = ncb print((ans - (nca + ncb)) % mod) if __name__ == '__main__': main()
1
66,282,412,132,764
null
214
214
import math def at(x): return math.degrees(math.atan(x)) a, b, x = map(int, input().split()) print(at(a*b*b/(2*x)) if 2*x < a*a*b else at(2*(a*a*b-x)/(a**3)))
import math a, b, x = map(int, input().split()) if x < a ** 2 * b / 2: theta = math.atan2(b, 2 * x / b / a) else: theta = math.atan2(2 * b - 2 * x / a / a, a) deg = math.degrees(theta) print(deg)
1
163,408,394,338,160
null
289
289
n, a, b = map(int, input().split(' ')) q, r = divmod(n, a + b) s = q * a if r > a: s += a else: s += r print(s)
N, A, B = map(int, input().split()) r = (N//(A+B))*A N = N%(A+B) print(r+N if N<=A else r+A)
1
55,512,607,797,570
null
202
202
n=int(input()) a=list(map(int,input().split())) thing={} ans=0 for i in range(n): if i-a[i] in thing: ans+=thing[i-a[i]] if i+a[i] in thing: thing[i+a[i]]+=1 else: thing[i+a[i]]=1 print(ans)
n=int(input()) flag = False for i in range(100*n,100*(n+1)): if i%108 == 0: x = int(i//108) print(x) flag = True break if flag == False: print(':(')
0
null
75,942,478,130,402
157
265
N,M,K=map(int,input().split()) mod=998244353 fact=[1 for i in range(N+1)] for i in range(1,N): fact[i+1]=(fact[i]*(i+1))%mod def nCk(n,k): return fact[n]*pow(fact[n-k]*fact[k],mod-2,mod) result=0 for k in range(K+1): result+=nCk(N-1,k)*M*pow(M-1,N-k-1,mod) result=int(result)%mod print(result)
n, m, k = map(int, input().split()) mod = 998244353 def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod N = 10**6 g1 = [1, 1] # ๅ…ƒใƒ†ใƒผใƒ–ใƒซ g2 = [1, 1] #้€†ๅ…ƒใƒ†ใƒผใƒ–ใƒซ inverse = [0, 1] #้€†ๅ…ƒใƒ†ใƒผใƒ–ใƒซ่จˆ็ฎ—็”จใƒ†ใƒผใƒ–ใƒซ for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) ans = 0 for i in range(k+1): col = m * pow(m-1,n-i-1,mod) match = cmb(n-1,i,mod) ans += col * match print(ans % mod)
1
23,253,884,061,672
null
151
151
# C - Marks def marks(n, k, a): results = [] for i in range(n - k): if a[i] < a[i + k]: results.append("Yes") else: results.append("No") return results if __name__ == "__main__": n, k = map(int, input().split()) a = list(map(int, input().split())) results = marks(n, k, a) for i in results: print(i)
# coding: utf-8 import sys def merge(A, left, mid, right): global count L = A[left:mid] R = A[mid:right] L.append(sys.maxsize) R.append(sys.maxsize) i = 0 j = 0 for k in range(left,right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 count += 1 def mergeSort(A, left, right): if left+1 < right: mid = int((left + right)/2); mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) n = int(input().rstrip()) A = list(map(int,input().rstrip().split())) count = 0 mergeSort(A, 0, n) print(" ".join(map(str,A))) print(count)
0
null
3,590,569,262,710
102
26
import math t1,t2 = map(int, input().split()) c1,c2 = map(int, input().split()) d1,d2 = map(int, input().split()) x = [(c1*t1, c2*t2),(d1*t1, d2*t2)] x.sort(reverse=True) if x[0][0]+x[0][1] == x[1][0]+x[1][1]: print("infinity") elif x[0][0]+x[0][1] > x[1][0]+x[1][1]: print(0) else: n = (x[0][0]-x[1][0]+0.0)/(x[1][0]+x[1][1]-x[0][0]-x[0][1]) m = math.ceil(n) if math.floor(n) == m: print(2*m) else: print(2*m-1)
T1,T2 = map(int,input().split()) A1,A2 = map(int,input().split()) B1,B2 = map(int,input().split()) ans = 0 if T1*A1+T2*A2 == T1*B1+T2*B2: print("infinity") exit() if A1>B1: jtA = True else: jtA = False if jtA: if T1*A1+T2*A2 > T1*B1+T2*B2: print(0) exit() else: jA = False x = abs(T1*B1+T2*B2 - T1*A1-T2*A2) else: if T1*A1+T2*A2 < T1*B1+T2*B2: print(0) exit() else: jA = True x = abs(T1*A1+T2*A2 - T1*B1-T2*B2) if (abs(A1-B1)*T1)%x == 0: ans += ((abs(A1-B1)*T1)//x)*2 else: ans += ((abs(A1-B1)*T1)//x)*2+1 print(ans)
1
131,888,428,184,250
null
269
269
import math a,b,c,d = map(int,input().split(" ")) taka = math.ceil(c/b) aoki = math.ceil(a/d) if taka <= aoki: print("Yes") else: print("No")
a,b,c,d = map(int, input().split()) for i in range(100): # ็นฐใ‚Š่ฟ”ใ—ๅ‡ฆ็†ใ—ใŸใ„ใ€ใจใ‚Šใ‚ใˆใš100ๅ›žไปฅไธŠใฎ็นฐใ‚Š่ฟ”ใ—ใฏใชใ„ใ‹ใ‚‰100ๅ›ž็นฐใ‚Š่ฟ”ใ™ c -= b # ้’ๆœจใใ‚“ใฎไฝ“ๅŠ›cใ‹ใ‚‰้ซ˜ๆฉ‹ใใ‚“ใฎๆ”ปๆ’ƒๅŠ›bใถใ‚“ๅผ•ใ # print('้’ๆœจไฝ“ๅŠ›', c) # ๆฎ‹ใ‚Šไฝ“ๅŠ›ใ‚’็ขบ่ชใ™ใ‚‹ๆ™‚ใฏๅ…ˆ้ ญใฎ#ใ‚’ๅค–ใ™ if c <= 0: # ้’ๆœจใใ‚“ไฝ“ๅŠ›ใŒ0ไปฅไธ‹ใซใชใฃใŸใ‚‰ print('Yes') # ้ซ˜ๆฉ‹ใใ‚“ใฎๅ‹ใกใชใฎใงYes break # ไฝ“ๅŠ›ใŒ0ใซใชใฃใŸใ‚‰็นฐใ‚Š่ฟ”ใ—ใ‚‚็ต‚ไบ† a -= d # ๆฌกใซ้ซ˜ๆฉ‹ใใ‚“ใฎไฝ“ๅŠ›aใ‹ใ‚‰้’ๆœจใใ‚“ใฎๆ”ปๆ’ƒๅŠ›dใ‚’ๅผ•ใ # print('้ซ˜ๆฉ‹ไฝ“ๅŠ›',a) # ๆฎ‹ใ‚Šไฝ“ๅŠ›ใ‚’็ขบ่ชใ™ใ‚‹ๆ™‚ใฏๅ…ˆ้ ญใฎ#ใ‚’ๅค–ใ™ if a <= 0: # ้ซ˜ๆฉ‹ใใ‚“ไฝ“ๅŠ›ใŒ0ไปฅไธ‹ใซใชใฃใŸใ‚‰ print('No') # ้’ๆœจใใ‚“ๅ‹ๅˆฉใงNo break # ไฝ“ๅŠ›ใŒ0ใซใชใฃใŸใ‚‰็นฐใ‚Š่ฟ”ใ—ใ‚‚็ต‚ไบ† # ใฉใกใ‚‰ใฎไฝ“ๅŠ›ใ‚‚ๆฎ‹ใฃใฆใŸใ‚‰ๆฌกใฎ็นฐใ‚Š่ฟ”ใ—
1
29,621,709,894,432
null
164
164
N = int(input()) dp = [[0]*10 for _ in range(10)] for i in range(1, N+1): if i%10==0: continue strI = str(i) f,l = strI[-1], strI[0] dp[int(f)][int(l)] += 1 res = 0 for i in range(1,10): for j in range(1,10): res += dp[i][j] * dp[j][i] print(res)
N = int(input()) matrix = [[0,0,0,0,0,0,0,0,0,0] for _ in range(10)] for i in range(1,N+1): first = int(str(i)[0]) last = int(str(i)[-1]) matrix[first][last] += 1 ans = 0 for i in range(10): for l in range(10): ans += matrix[i][l]*matrix[l][i] print(ans)
1
86,749,850,259,880
null
234
234
m1, d1 = map(int, input().split()) m2, d2 = map(int, input().split()) print(1 if m2 == m1 % 12 + 1 and d2 == 1 else 0)
a = [] b = [] a = input().split() b = input().split() if a[0] == b[0]: print("0") else: print("1")
1
124,330,463,368,892
null
264
264
def main(): x, y, z = map(int, input().split(" ")) print(f"{z} {x} {y}") if __name__ == "__main__": main()
argList = list(map(int, input().split())) print(str(argList[2])+" "+str(argList[0])+" "+str(argList[1]))
1
38,141,187,329,810
null
178
178
S = input() ans = 0 for i in range(int(len(S) / 2)): if S[i] != S[-1-i]: ans += 1 print(ans)
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 h, w, k = list(map(int, readline().split())) a = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)] no = 0 is_f = True for i in range(h): if a[i].count("#") != 0: row_f = True no += 1 for j in range(w): if a[i][j] == "#": if not row_f: no += 1 else: row_f = False a[i][j] = no if is_f: is_f = False if i != 0: for j in range(i - 1, -1, -1): for k in range(w): a[j][k] = a[i][k] else: for j in range(w): a[i][j] = a[i-1][j] for i in range(h): print(*a[i]) if __name__ == '__main__': solve()
0
null
132,382,166,186,842
261
277
import bisect n, k = map(int, input().split()) h = sorted(list(map(int, input().split()))) print(n - bisect.bisect_left(h, k))
import sys input = sys.stdin.readline N = int(input()) S = input().rstrip() Q = int(input()) qs = [input().split() for i in range(Q)] def ctoi(c): return ord(c) - ord('a') class BinaryIndexedTree: def __init__(self,size): self.N = size self.bit = [0]*(size+1) def add(self,x,w): while x <= self.N: self.bit[x] += w x += (x & -x) def sum(self,x): ret = 0 while x > 0: ret += self.bit[x] x -= (x & -x) return ret bits = [BinaryIndexedTree(N) for _ in range(26)] for i,c in enumerate(S): bits[ctoi(c)].add(i+1,1) s = list(S) ans = [] for a,b,c in qs: if a=='1': x = int(b) bits[ctoi(c)].add(x,1) bits[ctoi(s[x-1])].add(x,-1) s[x-1] = c else: tmp = 0 for i in range(26): if bits[i].sum(int(c)) - bits[i].sum(int(b)-1) > 0: tmp += 1 ans.append(tmp) print(*ans, sep='\n')
0
null
121,230,099,574,582
298
210
N = int(input()) syo = N//1000 if N%1000 == 0: print(0) else: amari = (syo+1)*1000 - N print(amari)
s=input() t=input() i=len(s)-1 counter=0 while i>=0: if s[i]!=t[i]: counter+=1 i=i-1 print(counter)
0
null
9,551,405,821,510
108
116
n,k=map(int,input().split()) r,s,p=map(int,input().split()) t=input() t2 = [[] for _ in range(k)] score = [0]*n for i,c in enumerate(t): t2[i%k].append(c) score = {'r':p,'s':r,'p':s} total = 0 for t3 in t2: if len(t3)==0: continue if len(t3)==1: total += score[t3[0]] continue for i in range(len(t3)-1): if t3[i] == 'e': continue total += score[t3[i]] if t3[i] == t3[i+1]: t3[i+1]='e' if t3[-1] != 'e': total += score[t3[-1]] print(total)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) check = list(map(int, readline().split())) prize = [3 * 10 ** 5, 2 * 10 ** 5, 10 ** 5] ans = 0 if check.count(1) == 2: ans = 10 ** 6 else: if check[0] <= 3: ans += prize[check[0] - 1] if check[1] <= 3: ans += prize[check[1] - 1] print(ans)
0
null
124,133,721,403,048
251
275
import sys def input(): return sys.stdin.readline().rstrip() def main(): n=int(input()) A=list(map(int, input().split())) ans = 0 mod = 10**9 + 7 for i in range(60): q = sum(map(lambda x:((x >> i) & 0b1),A)) ans += q*(n-q)*pow(2, i, mod) ans = ans % mod print(ans) if __name__=='__main__': main()
D,T,S = map(int,input().split()) if D <= T*S: print("Yes") else:print("No")
0
null
62,951,418,923,500
263
81
N,M = map(int,input().split()) if N>=2: gyu = N*(N-1)//2 else: gyu = 0 if M>=2: ki = M*(M-1)//2 else: ki = 0 print(gyu+ki)
import sys def dump(x): print(x, file=sys.stderr) n = int(input()) print(1-n)
0
null
24,263,467,661,860
189
76
import math H, N = 9, 3 ARR = [ [8, 3], [4, 2], [2, 1] ] H, N = 100, 6 ARR = [ [1, 1], [2, 3], [3, 9], [4, 27], [5, 81], [6, 243], ] H,N = map(int,input().split()) ARR = [list(map(int,input().split())) for i in range(N)] def calculate(h, n, arr): brr = [math.inf] * (h + 1) brr[0] = 0 for i in range(h + 1): for j in range(n): damage = arr[j][0] cost = arr[j][1] nextDamage = min(i + damage, h) nextCost = min(brr[nextDamage], brr[i] + cost) brr[nextDamage] = nextCost print(brr[-1]) calculate(H, N, ARR)
n = int(input()) s = input() cnt = 0 for i in range(n-1): if s[i] == s[i+1]: cnt += 1 print(n-cnt)
0
null
125,577,401,023,558
229
293
#!/usr/bin/env python def GCD(x,y): while y!=0: tmp=y y=x%y x=tmp return x if __name__ == "__main__": x,y=list(map(int,input().split())) if x<y: tmp=x x=y y=tmp print(GCD(x,y))
a, b = map(int, input().split()) def gcd(a, b): big = max(a, b) small = min(a, b) while not big % small == 0: big, small = small, big%small return small print(gcd(a, b))
1
8,176,739,142
null
11
11
#ABC 171 E - Red Scarf n = int(input()) A = list(map(int, input().split())) S = 0 for i in A: S ^= i B = [S^i for i in A] print(*B)
S,T=input().split() num1,num2=map(int,input().split()) throw=input() if throw==S: num1-=1 else: num2-=1 print(num1,num2)
0
null
42,025,909,901,088
123
220
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ใ‚ณใƒณใƒ†ใ‚นใƒˆๅพŒใซ่งฃ่ชฌ่จ˜ไบ‹ใ‚’่ฆ‹ใฆAC Python 3ใ ใจTLE """ import array from bisect import * from collections import * import fractions import heapq from itertools import * import math import random import re import string import sys def solve(N_str): """ https://betrue12.hateblo.jp/ ใฎ้€šใ‚ŠๅฎŸ่ฃ… ไธŠใฎๆกใ‹ใ‚‰้ †็•ชใซ่ฆ‹ใฆใ„ใ dp[i][j] = ไธŠใ‹ใ‚‰ i ๆก็›ฎใพใงใฎ็กฌ่ฒจใฎๆ”ฏๆ‰•ใ„ใจใŠ้‡ฃใ‚Šใ‚’ๅ‡ฆ็†ใ—็ต‚ใ‚ใฃใฆใ€ N ใฎ i ๆก็›ฎใพใงใฎ้‡‘้กใ‚ˆใ‚Šใ‚‚ j ๆžšๅˆ†ๅคšใๆ”ฏๆ‰•ใฃใฆใ„ใ‚‹ใจใใฎใ€ ใ“ใ‚Œใพใงใฎๆ”ฏๆ‰•ใ„ใƒปใŠ้‡ฃใ‚Š็กฌ่ฒจใฎๆœ€ๅฐๅˆ่จˆๆžšๆ•ฐ """ N_str = '0' + N_str dp = [[0] * 2 for _ in range(len(N_str))] # 0376ๅ††ใฎใจใ # dp[1][0] = 0 0ๅ††ๆ‰•ใ†(0) # dp[1][1] = 1 1000ๅ††ๆ‰•ใ†(1) # # dp[2][0] = 3 0ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰300ๅ††ๆ‰•ใ†(3) vs 1000ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰700ๅ††ใŠ้‡ฃใ‚Šใ‚’ใ‚‚ใ‚‰ใ†(8) # dp[2][1] = 4 0ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰400ๅ††ๆ‰•ใ†(4) vs 1000ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰600ๅ††ใŠ้‡ฃใ‚Šใ‚’ใ‚‚ใ‚‰ใ†(7) # # dp[3][0] = 7 300ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰่ฟฝๅŠ ใง70ๅ††ๆ‰•ใ†(3+7) vs 400ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰30ๅ††ใ‚‚ใ‚‰ใ†(4+3) # dp[3][1] = 6 300ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰่ฟฝๅŠ ใง80ๅ††ๆ‰•ใ†(3+8) vs 400ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰20ๅ††ใ‚‚ใ‚‰ใ†(4+2) # # dp[4][0] = 10 370ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰่ฟฝๅŠ ใง6ๅ††ๆ‰•ใ†(7+6) vs 380ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰4ๅ††ใ‚‚ใ‚‰ใ†(6+4) # dp[4][1] = 9 370ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰่ฟฝๅŠ ใง7ๅ††ๆ‰•ใ†(7+7) vs 380ๅ††ใฎ็Šถๆ…‹ใ‹ใ‚‰3ๅ††ใ‚‚ใ‚‰ใ†(6+3) for i, ch in enumerate(N_str): if i == 0: dp[0][0] = 0 dp[0][1] = 1 else: dp[i][0] = min(dp[i - 1][0] + int(ch), dp[i - 1][1] + 10 - int(ch)) dp[i][1] = min(dp[i - 1][0] + int(ch) + 1, dp[i - 1][1] + 9 - int(ch)) return dp[len(N_str) - 1][0] def wrong(N_str): """ๆœ€ๅˆใซ้–“้•ใฃใฆๆ›ธใ„ใŸ่ฒชๆฌฒ 1ใฎไฝใ‹ใ‚‰่ฆ‹ใฆใ„ใใ€0~4ใชใ‚‰ๆ”ฏๆ‰•ใ„ใ€5~9ใชใ‚‰10ๆ‰•ใฃใฆใŠ้‡ฃใ‚Šใ‚’ใ‚‚ใ‚‰ใ† N = 65ใฎใจใใ€ ใ“ใฎ้–ขๆ•ฐใ ใจ70ๆ‰•ใฃใฆ5ใŠ้‡ฃใ‚Šใ‚’ใ‚‚ใ‚‰ใ†ใ“ใจใซใชใ‚‹ใŒ ๅฎŸ้š›ใฏ100ๆ‰•ใฃใฆ35ใŠ้‡ฃใ‚Šใ‚’ใ‚‚ใ‚‰ใ†ในใใชใฎใง่ชคใ‚Š """ N_str = N_str[::-1] ans = 0 prev = 0 for ch in N_str: n = int(ch) n += prev if n <= 5: ans += n prev = 0 else: ans += 10 - n prev = 1 ans += prev return ans # for n in range(1, 101): # print() # n_str = str(n) # w = wrong(n_str) # gt = solve(n_str) # if w != gt: # print("n, gt, wrong = ", n, gt, w) N_str = input() print(solve(N_str))
import sys import functools # sys.setrecursionlimit(100000000) n = input() # import random # n = ''.join(str(random.randint(1,9)) for _ in range(10**6)) # # @functools.lru_cache(None) # def doit(index: int, carry: int) -> int: # if index >= len(n): # return 0 if carry == 0 else 2 # d = int(n[index]) # if carry > 0: # return min(10 - d + doit(index + 1, 0), 9 - d + doit(index + 1, 1)) # else: # return min(d + doit(index + 1, 0), d + 1 + doit(index + 1, 1)) # # # print(min(doit(0, 0), 1 + doit(0, 1))) dp = [0, 2] for d in reversed(n): d = int(d) dp = [min(d + dp[0], d + 1 + dp[1]), min(10 - d + dp[0], 9 - d + dp[1])] print(min(dp[0], 1 + dp[1]))
1
70,655,848,856,250
null
219
219