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
import math pi=math.pi r = int(input().strip()) print(2*r*pi)
import math def main(): R = input_int() print(R * 2 * math.pi) def input_int(): return int(input()) def input_ints(): return map(int, input().split()) def input_int_list_in_line(): return list(map(int, input().split())) def input_int_tuple_list(n: int, q: int): return [tuple(map(int, input().split())) for _ in range(n)] main()
1
31,263,257,443,368
null
167
167
import itertools N = int(input()) l = list(itertools.permutations(range(1,N+1))) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) print(abs(l.index(A) - l.index(B)))
import itertools N = int(input()) l = [] for i in itertools.permutations(list(range(1,N+1))): l.append(i) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) a = 1 b = 1 for i in l: if i < P: a += 1 for i in l: if i < Q: b += 1 print(abs(a-b))
1
100,854,904,837,860
null
246
246
from random import * D=int(input()) C=list(map(int,input().split())) S=[list(map(int,input().split())) for i in range(D)] X=[0]*26 XX=[0]*26 P=[] Y,Z=0,0 V,W=0,0 T,U=0,0 for i in range(D): for j in range(26): X[j]+=C[j] XX[j]+=X[j] Y,Z=-1,-10**20 V,W=Y,Z T,U=V,W for j in range(26): if Y==-1: Y,Z=0,X[0]+S[i][0] continue if Z<X[j]+S[i][j]: T,U=V,W V,W=Y,Z Y,Z=j,X[j]+S[i][j] elif W<X[j]+S[i][j]: T,U=V,W V,W=j,X[j]+S[i][j] elif U<X[j]+S[i][j]: T,U=j,X[j]+S[i][j] XX[Y]-=X[Y] X[Y]=0 P.append([Y,V,T]) if randrange(0,50)==0: P[i][1]=randrange(0,26) if randrange(0,5)==0: P[i][2]=randrange(0,26) P[i]=tuple(P[i]) SCORE=0 X=[0]*26 for i in range(D): SCORE+=S[i][P[i][0]] for j in range(26): X[j]+=C[j] X[P[i][0]]=0 SCORE-=sum(X) SCORE2=0 YY=[] for i in range(D): for k in range(2): d,q=i,P[i][k+1] SCORE2=SCORE YY=XX[:] SCORE2-=S[d][P[d][0]] SCORE2+=S[d][q] for j in range(26): X[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] X[P[d][0]]+=C[P[d][0]] X[q]+=C[q] X[Z]=0 YY[P[d][0]]+=X[P[d][0]] YY[q]+=X[q] if SCORE2-sum(YY)>SCORE-sum(XX): z=[P[i][k+1]] for l in range(3): if l!=k: z.append(P[i][l]) P[i]=tuple(z) XX=YY[:] SCORE=SCORE2 for i in range(D): print(P[i][0]+1)
a = int(input()) l = [] c,f =0, 0 for i in range(a): ta,tb = map(int,input().split()) if ta==tb : c+=1 else: c = 0 if c>=3 : f = 1 if f: print("Yes") else: print("No")
0
null
6,058,804,464,098
113
72
a=int(input()) b=list(map(int,input().split())) b.sort() c=0 for i in range(a-1): if b[i]==b[i+1]: c=c+1 if c==0: print("YES") else: print("NO")
n = int(input()) s = sorted([int(i) for i in input().split()]) for i, v in enumerate(s[0:-1]): if v == s[i+1]: print('NO') exit() print('YES')
1
73,576,365,531,614
null
222
222
# 公式解説を見てからやった # 複数サイクルでき、1-K回移動可能 # N < 5000?多分、O(N * 2N)くらいで行けそうに見えるが。。。 def main(N,K,P,C): # 一度計算したサイクル情報を一応キャッシュしておく。。。 # あんまり意味なさそう cycleIDs = [ -1 for _ in range(N) ] cycleInfs = [] # print(P) ans = -1e10 cycleID = 0 for n in range(N): v = n currentCycleItemCnt = 0 currentCycleTotal = 0 if cycleIDs[v] != -1: currentCycleItemCnt, currentCycleTotal = cycleInfs[ cycleIDs[v] ] # print(currentCycleItemCnt, currentCycleTotal) else: while True: # 全頂点について、属するサイクルを計算する currentCycleItemCnt += 1 currentCycleTotal += C[v] v = P[v] if v == n: # サイクル発見 cycleInfs.append( (currentCycleItemCnt, currentCycleTotal) ) cycleID += 1 break # 一応、一度サイクルを計算した頂点については、 # その頂点の属するサイクルの情報をメモっておく。。。 cycleIDs[v] = cycleID procCnt = 0 currentCycleSumTmp = 0 while True: # 頂点vにコマが置かれた時の最高スコアを計算し、 # これまでの最高スコアを上回ったら、これまでの最高スコアを更新する procCnt += 1 currentCycleSumTmp += C[v] if K < procCnt: break cycleLoopCnt = 0 if procCnt < K and 0 < currentCycleTotal: cycleLoopCnt = ( K - procCnt ) // currentCycleItemCnt # print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, procCnt) tmp = currentCycleSumTmp + cycleLoopCnt * currentCycleTotal ans = max( ans, tmp ) v = P[v] if v == n: # サイクル終了 break return ans # print(ans) if __name__ == "__main__": N,K = map(int,input().split()) P = [ int(p)-1 for p in input().split() ] C = list(map(int,input().split())) ans=main(N,K,P,C) print(ans)
n = int(input()) cnt_ac = 0 cnt_wa = 0 cnt_tle = 0 cnt_re = 0 for i in range(n): s = input() if s == 'AC': cnt_ac += 1 elif s == 'WA': cnt_wa += 1 elif s == 'TLE': cnt_tle += 1 elif s == "RE": cnt_re += 1 print('AC x ', cnt_ac) print('WA x ', cnt_wa) print('TLE x ', cnt_tle) print('RE x ', cnt_re)
0
null
7,009,130,280,308
93
109
n=int(input()) s=input().split() a=s[0] b=s[1] ans='' for i in range(len(a)): ans+=a[i] ans+=b[i] print (ans)
N=int(input()) S,T=input().split() list=[] i=0 while i<N: list.append(S[i]) list.append(T[i]) i=i+1 print(*list, sep='')
1
112,275,835,346,080
null
255
255
from sys import stdin a, b = (int(n) for n in stdin.readline().rstrip().split()) sign = "==" if a == b else ">" if a > b else "<" print("a {} b".format(sign))
x = list(map(int, input().split())) top_count = 0 ans = 0 for i in x: if i == 1: ans += 300000 top_count += 1 elif i == 2: ans += 200000 elif i == 3: ans += 100000 if top_count == 2: print(ans + 400000) else: print(ans)
0
null
70,521,825,208,770
38
275
inputted = input().split() S = inputted[0] T = inputted[1] answer = T + S print(answer)
s,t = map(str,input().split()) print(t+s)
1
103,307,193,250,272
null
248
248
n, k = map(int, input().split()) x = n % k y = abs(x - k) if x >= y: print(y) else: print(x)
from collections import deque def run(): n = int(input()) dq = deque() for _ in range(n): order = input() if order[0] == 'i': dq.appendleft(order[7:]) elif order[6] == ' ': key = order.split()[1] if not key in dq: continue for i in range(len(dq)): if dq[i] == key: dq.remove(key) break elif order[6] == 'F': dq.popleft() elif order[6] == 'L': dq.pop() print(' '.join(dq)) if __name__ == '__main__': run()
0
null
19,689,797,432,512
180
20
n = int(input()) for i in range(0, n): a, b, c = sorted(map(int, input().split())) print("YES" if c*c == a*a+b*b else "NO")
def ifTriangle(a, b, c): if (a**2) + (b**2) == c**2: print("YES") else: print("NO") n=int(input()) for i in range(n): lines=list(map(int, input().split())) lines.sort() ifTriangle(lines[0], lines[1], lines[2])
1
217,089,378
null
4
4
X, Y, A, B, C = map(int, input().split()) P = sorted(list(map(int, input().split())), reverse=True) Q = sorted(list(map(int, input().split())), reverse=True) R = sorted(list(map(int, input().split())), reverse=True) pq = sorted(P[:X] + Q[:Y]) cnt = 0 for i in range(min(C, X+Y)): if R[i] <= pq[i]: break cnt += 1 ans = sum(pq[cnt:]) + sum(R[:cnt]) print(ans)
X, Y, A, B, C = map(int, input().split()) P = sorted(list(map(int, input().split())), reverse=True) Q = sorted(list(map(int, input().split())), reverse=True) R = sorted(list(map(int, input().split())), reverse=True) red = sorted(P[:X]) gre = sorted(Q[:Y]) m = min((X+Y),C) n = R[:m] red.extend(gre) red.extend(n) red = sorted(red, reverse=True) print(sum(red[:X+Y]))
1
44,830,235,864,418
null
188
188
import math score = list(map(int,input().split())) minut = score[2]*60 + score[3] jisin = math.radians(minut/2) hunsin = math.radians(score[3]*6) jixy = [math.cos(jisin)*score[0] , math.sin(jisin)*score[0]] huxy = [math.cos(hunsin)*score[1] , math.sin(hunsin)*score[1]] delx = abs(jixy[0] - huxy[0]) dely = abs(jixy[1] - huxy[1]) answer = (delx**2 + dely**2)**0.5 print(answer)
from math import cos, radians def main(): a, b, h, m = map(int, input().split()) h_angle = (h * 60 + m) / 2 # 時針の角度 m_angle = m * 6 # 分針の角度 theta = abs(h_angle - m_angle) x_2 = a**2 + b**2 - 2*a*b*cos(radians(theta)) print(x_2 ** 0.5) main()
1
20,019,971,962,540
null
144
144
import math n,m=map(int,input().split()) a=list(map(int,input().split())) half_a=[ai//2 for ai in a] # print(half_a) lcm=half_a[0] for i in range(n-1): a,b=lcm,half_a[i+1] lcm=a*b//math.gcd(a,b) # print(lcm) pow_cnt=0 tmp=half_a[0] while tmp%2==0: pow_cnt+=1 tmp=tmp//2 flag=True for ai in half_a[1:]: if ai%(2**pow_cnt)!=0: flag=False break elif ai%(2**(pow_cnt+1))==0: flag=False break if flag: print(math.ceil(m//lcm/2)) else: print(0)
def resolve(): K, N = list(map(int, input().split())) A = list(map(int, input().split())) maxdiff = 0 idx = None for i in range(N): if i == N-1: diff = (K+A[0]) - A[i] else: diff = A[i+1] - A[i] if maxdiff < diff: idx = i maxdiff = max(maxdiff, diff) print(K - maxdiff) if '__main__' == __name__: resolve()
0
null
72,867,607,340,626
247
186
H,W,K = map(int, input().split()) ans = 0 board =[list(input()) for _ in range(H)] for paint_H in range(2 ** H): #行の塗りつぶし方の全列挙 for paint_W in range(2 ** W): #列の塗りつぶし方の全列挙 cnt = 0 for i in range(H): for j in range(W): if (paint_H>>i)&1==0 and (paint_W>>j)&1==0: if board[i][j] == '#': cnt += 1 if cnt == K: ans += 1 print(ans)
h, w, k, = map(int, input().split()) c = [0] * h for i in range(h): c[i] = input() y = 0 for i in range(2 ** (h + w)): x = 0 a = [0] * (h + w) for j in range(h + w): if (i // (2 ** j)) % 2 == 1: a[j] = 1 for j in range(h): if a[j] == 0: for l in range(w): if a[h+l] == 0: if c[j][l] == '#': x += 1 if x == k: y += 1 print(y)
1
8,946,732,275,068
null
110
110
n = int(input()) d = list(map(int, input().split())) m = 1 num = 0 for s in range(0,n-1): for t in range(m,n): num += (d[s]*d[t]) m += 1 print(num)
import itertools n = int(input()) tastes = list(map(int, input().split())) ans_lists = [] for v in itertools.combinations(tastes, 2): cure = v[0]*v[1] ans_lists.append(cure) ans = 0 for i in ans_lists: ans += i print(ans)
1
168,072,980,214,066
null
292
292
s = list(input()) n = len(s) flag = 0 for i in range(n//2): if s[i] != s[n-i-1]: flag = 1 if flag == 0: s2 = s[:(n-1)//2] n2 = len(s2) for i in range(n2//2): if s2[i] != s2[n2-i-1]: flag = 1 #print(n, n2, s, s2) if flag == 0: if flag == 0: s2 = s[(n+3)//2-1:] n2 = len(s2) for i in range(n2//2): if s2[i] != s2[n2-i-1]: flag = 1 #print(s2) if flag == 0: print("Yes") else: print("No")
N = int(input()) print(((N+2-1)//2)/N)
0
null
111,853,218,176,320
190
297
import math N = int(input()) ans = math.inf for i in range(1, math.ceil(math.sqrt(N)) + 1): if N%i == 0: ans = i+N//i-2 print(ans)
# import itertools # import math # import sys # sys.setrecursionlimit(500*500) # import numpy as np N = int(input()) S = input() # n, *a = map(int, open(0)) # N, M = map(int, input().split()) # A = list(map(int, input().split())) # B = list(map(int, input().split())) # tree = [[] for _ in range(N + 1)] # B_C = [list(map(int,input().split())) for _ in range(M)] # S = input() # B_C = sorted(B_C, reverse=True, key=lambda x:x[1]) # all_cases = list(itertools.permutations(P)) # a = list(itertools.combinations_with_replacement(range(1, M + 1), N)) # itertools.product((0,1), repeat=n) # A = np.array(A) # cum_A = np.cumsum(A) # cum_A = np.insert(cum_A, 0, 0) # def dfs(tree, s): # for l in tree[s]: # if depth[l[0]] == -1: # depth[l[0]] = depth[s] + l[1] # dfs(tree, l[0]) # dfs(tree, 1) all = S.count("R") * S.count("G") * S.count("B") cnt = 0 for i in range(N): for j in range(i, N): k = 2 * j - i if k >= N: continue if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]: cnt += 1 print(all - cnt)
0
null
98,408,440,345,088
288
175
import math A, B, N = map(int, input().split()) ans = [] if B-1<N: sahen = math.floor(A*(B-1)//B) uhen = math.floor((B-1)//B) uhen = uhen*A ans.append(sahen-uhen) sahen = math.floor(A*N//B) uhen = math.floor(N//B) uhen = uhen*A ans.append(sahen-uhen) print(max(ans))
n = int(input()) ans = int(n/2) + n%2 print(ans)
0
null
43,580,394,924,728
161
206
#import numpy as np #def area--------------------------# #ryouno syokiti class ryou: def flinit(self): room=list() for i in range(10): room+=[0] return room #def kaijo([a_1,a_2,a_3,a_4,a_5,a_6,a_7,a_8,a_9,a_10]): #def kaijo(x): # y=[] # for i in x: # y=y+ " "+x[i] # return y def kaijo(x): print "", for i in range(len(x)-1): print str(x[i]), print str(x[len(x)-1]) #----------------------------------# floor_11=ryou().flinit() floor_12=ryou().flinit() floor_13=ryou().flinit() floor_21=ryou().flinit() floor_22=ryou().flinit() floor_23=ryou().flinit() floor_31=ryou().flinit() floor_32=ryou().flinit() floor_33=ryou().flinit() floor_41=ryou().flinit() floor_42=ryou().flinit() floor_43=ryou().flinit() fldic={"11":floor_11, "12":floor_12, "13":floor_13, "21":floor_21, "22":floor_22, "23":floor_23, "31":floor_31, "32":floor_32, "33":floor_33, "41":floor_41, "42":floor_42, "43":floor_43 } #----------------------------------# #1kaime yomikomi n=int(raw_input()) #nkaime syusyori for l in range(n): list_mojiretsu=raw_input().split(" ") henka=map(int,list_mojiretsu) fldic[str(henka[0])+str(henka[1])][henka[2]-1]+=henka[3] kaijo(floor_11) kaijo(floor_12) kaijo(floor_13) print "####################" kaijo(floor_21) kaijo(floor_22) kaijo(floor_23) print "####################" kaijo(floor_31) kaijo(floor_32) kaijo(floor_33) print "####################" kaijo(floor_41) kaijo(floor_42) kaijo(floor_43)
bldgs = [] for k in range(4): bldgs.append([[0 for i in range(10)] for j in range(3)]) n = int(input()) for i in range(n): b,f,r,v = map(int, input().split(' ')) bldgs[b-1][f-1][r-1] += v for i, bldg in enumerate(bldgs): if i > 0: print('#'*20) for floor in bldg: print(' '+' '.join([str(f) for f in floor]))
1
1,094,133,469,880
null
55
55
from sys import stdin n = int(stdin.readline().rstrip()) A = [int(x) for x in stdin.readline().rstrip().split()] ans = [0] * n for i, a in enumerate(A): ans[a-1] = i+1 print(' '.join(map(str, ans)))
n,k=map(int,input().split()) W=[int(input()) for _ in range(n)] def Wcheck(W,P,k): i=0 for j in range(k): temp_w=0 while temp_w+W[i]<=P: temp_w=temp_w+W[i] i=i+1 if i==len(W): return len(W) return i def PSearch(W,start,end,k): if start==end: return start mid=(start+end)//2 v=Wcheck(W,mid,k) if v>=n: return PSearch(W,start,mid,k) else: return PSearch(W,mid+1,end,k) print(PSearch(W,0,1000000000,k))
0
null
90,506,173,499,040
299
24
N = int(input()) slist = [] for i in range(N): slist.append(input()) print (len(set(slist)))
import collections N, M = map(int, input().split()) ways = collections.defaultdict(set) for _ in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 ways[a].add(b) ways[b].add(a) dist = [-1] * N q = collections.deque() dist[0] = True q.append(0) while q: n = q.popleft() for adjacent in ways[n]: if dist[adjacent] != -1: continue dist[adjacent] = dist[n] + 1 q.append(adjacent) if -1 in dist: print('No') else: print('Yes') for n, d in enumerate(dist): if n == 0: continue for adjacent in ways[n]: if d - 1 == dist[adjacent]: print(adjacent + 1) break
0
null
25,509,154,585,618
165
145
N = int(input()) testimony = [[] for _ in range(N)] for i in range(N): num = int(input()) for j in range(num): person, state = map(int, input().split()) testimony[i].append([person-1, state]) honest = 0 for i in range(2**N): flag = 0 for j in range(N): if (i>>j)&1 == 1: # j番目は正直と仮定 for x,y in testimony[j]: if (i>>x)&1 != y: # j番目は正直だが矛盾を発見 flag = 1 break if flag == 0: # 矛盾がある場合はflag == 1になる honest = max(honest, bin(i)[2:].count('1')) # 1の数をカウントし最大となるものを選択 print(honest)
import bisect n = int(input()) lines = list(int(i) for i in input().split()) lines.sort() counter = 0 for i in range(n-2): for j in range(i+1, n-1): counter += bisect.bisect_left(lines, lines[i] + lines[j]) - (j + 1) print(counter)
0
null
146,374,293,921,312
262
294
import math a,b,C = map(float,input().split()) S = 1/2*a*b*math.sin(C*math.pi/180) c = math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180)) L = a+b+c h = 2*S/a print(format(S,'.8f')) print(format(L,'.8f')) print(format(h,'.8f'))
n = int(input()) a = list(map(int,input().split())) b = [None] *n for idx,person in enumerate(a): b[person-1] = idx+1 for j in b: print(j,end=' ')
0
null
90,180,866,840,510
30
299
import sys from fractions import gcd sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10 ** 9 + 7 N = ir() A = lr() lcm = 1 answer = 0 for a in A: coef = a // gcd(lcm, a) answer *= coef lcm *= coef answer += lcm // a print(answer%MOD)
s = int(input()) if(s<3): print(0) exit() l = s//3 cnt = 0 mod = 10**9+7 for i in range(l): if(i==0): cnt += 1 continue remain = s-3*(i+1) bar_remain = remain+i n = 1 for j in range(i): n*=(bar_remain-j) k = 1 for j in range(1,i+1): k*=j cnt += (n//k)%mod cnt %= mod print(cnt)
0
null
45,324,925,255,232
235
79
N,M,X=map(int,input().split()) B=[list(map(int,input().split())) for _ in range(N)] inf=(10**5)*12+1 ans=inf for i in range(1,2**N): tmp=[0]*M c=0 for j in range(N): if i>>j&1: for k in range(M): tmp[k]+=B[j][k+1] c+=B[j][0] if len([i for i in tmp if i>=X])==M: ans=min(c,ans) print(ans if ans<inf else -1)
N, M, X = map(int, input().split()) CA = [list(map(int, input().split())) for _ in range(N)] min_num = 10**18 for i in range(1<<N): cost = 0 l = [0]*M for j in range(N): if (i>>j)&1: c, *a = CA[j] cost += c for k, ak in enumerate(a): l[k] += ak if all(lj >= X for lj in l): min_num = min(min_num, cost) # print(l) print(-1 if min_num == 10**18 else min_num)
1
22,315,192,351,440
null
149
149
import math a, b, c = map(int, input().split()) d = math.ceil(a / b) print(d * c)
def func(N,X,T): result = -(-N // X) * T return result if __name__ == "__main__": N,X,T = map(int,input().split()) print(func(N,X,T))
1
4,238,700,304,370
null
86
86
import sys readline = sys.stdin.readline def main(): A, V = map(int, readline().rstrip().split()) B, W = map(int, readline().rstrip().split()) T = int(readline()) v = V - W if v <= 0: print('NO') return if abs(A - B) / v > T: print('NO') else: print('YES') if __name__ == '__main__': main()
S, T = input().split() print(T, S, sep='')
0
null
59,146,464,536,082
131
248
n = int(input()) output = 0 for i in range(n): if (i + 1) % 3 != 0 and (i + 1) % 5 != 0:output += i + 1 print(output)
# 入力 a = int(input()) # 定義 answer = 0 # 処理 for i in range(1, a + 1): if i % 3 == 0 and i % 5 == 0: continue elif i % 3 == 0: continue elif i % 5 == 0: continue else: answer += i # 出力 print(answer)
1
34,990,189,582,480
null
173
173
class Battle: def __init__(self, A, B, C, D): self.A = A self.B = B self.C = C self.D = D def result(self): while self.A > 0 or self.C > 0: self.C -= self.B if self.C <= 0: return "Yes" self.A -= self.D if self.A <= 0: return "No" def atc_164b(ABCD: str) -> str: A, B, C, D = map(int, ABCD.split(" ")) battle = Battle(A, B, C, D) return battle.result() ABCD_input = input() print(atc_164b(ABCD_input))
import math A, B, C, D = map(int, input().split()) #on which turn do they die takahashi = math.ceil(A / D) aoki = math.ceil(C / B) #print(takahashi) #print(aoki) if takahashi >= aoki: print("Yes") else: print("No")
1
29,939,399,832,122
null
164
164
import collections N = int(input()) S = [input() for i in range(N)] C = collections.Counter(S) L = C.most_common() ans = [] flag = 0 for n in range(len(C)): if L[n][1] < flag: break else: ans.append(L[n][0]) flag = (L[n][1]) ans.sort() for i in range(len(ans)): print(ans[i])
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() d = [] s = set() dd = {} ind = 0 for i in range(n): x = input() if x in s: d[dd[x]][1] += 1 else: dd[x] = ind d.append([x,1]) ind += 1 s.add(x) d.sort(key = lambda x:x[1], reverse = True) # print(d) res = [] for key,va in d: if va < d[0][1]: break res.append(key) res.sort() for x in res: print(x)
1
70,204,589,604,380
null
218
218
n = int(input()) s = input() cnt = 0 for p in range(len(s)): if p <= n - 3: if s[p] == 'A': if s[p + 1] == 'B' and s[p + 2] == 'C': cnt += 1 print(cnt)
N=int(input()) S=input()+' ' count = 0 for i in range(len(S)-2): if S[i:i+3] == 'ABC':count += 1 print(count)
1
99,384,233,298,118
null
245
245
import math N = int(input()) Ans = math.ceil(N/2) print(Ans)
N = int(input()) A = N / 2 A = int(A) B = (N + 1) / 2 B = int(B) if N % 2 == 0: print(A) else: print(B)
1
58,970,641,154,194
null
206
206
n=str(input()) a=len(n) N=list(n) m=str(input()) A=len(m) x=0 for i in range(a): C=[] for i in range(A): C.append(N[i]) B=''.join(C) c=N[0] if B==m: x=x+1 N.remove(c) N.append(c) if x>0: print('Yes') else: print('No')
import math a, b, c = map(float, input().split()) s = a*b*math.sin(math.radians(c))/2 h = 2*s/a l = a + b + (a**2+b**2 - 2*a*b*math.cos(math.radians(c)))**0.5 print("{0:.5f} {1:.5f} {2:.5f}".format(s,l,h))
0
null
974,180,247,172
64
30
def main(): input_line = raw_input() N = int(input_line) for i in range(N): input_line = raw_input() num_lis = [] for num in input_line.split(' '): num_lis.append(int(num)) num_lis.sort(reverse=True) if num_lis[0]**2 == num_lis[1]**2 + num_lis[2]**2: print('YES') else: print('NO') if __name__ == '__main__': main()
for i in range ( int ( input ( ) ) ): ( a, b, c ) = sorted ( list ( map ( int, input ( ).split ( ) ) ) ) if ( a ** 2 ) + ( b ** 2 ) == ( c ** 2 ): print ( "YES" ) else: print ( "NO" )
1
242,456,550
null
4
4
n,k=map(int,input().split(' ')) l=list(map(int, input().split(' '))) l=sorted(l) print(sum(l[:max(n-k,0)]))
target = raw_input() count = 0 while True: line = raw_input() if line == 'END_OF_TEXT': break if line[-1] == '.': line = line[:-1] for word in line.lower().split(): if target == word: count += 1 print count
0
null
40,612,653,633,376
227
65
case_num = 1 while True: tmp_num = int(input()) if tmp_num == 0: break else: print("Case %d: %d" % (case_num,tmp_num)) case_num += 1
N,M=map(int,input().split()) if(N==M): print("Yes") else: print("No")
0
null
41,614,497,032,992
42
231
from collections import deque h, w = map(int, input().split()) s = [] for i in range(h): s.append(list(input())) def bfs(x, y): if s[y][x] == '#': return 0 queue = deque() queue.appendleft([x, y]) visited = dict() visited[(x, y)] = 0 while queue: nx, ny = queue.pop() cur = visited[(nx, ny)] if nx - 1 >= 0 and (nx - 1, ny) not in visited: if s[ny][nx - 1] == '.': visited[(nx - 1, ny)] = cur + 1 queue.appendleft((nx - 1, ny)) if nx + 1 < w and (nx + 1, ny) not in visited: if s[ny][nx + 1] == '.': visited[(nx + 1, ny)] = cur + 1 queue.appendleft((nx + 1, ny)) if ny - 1 >= 0 and (nx, ny - 1) not in visited: if s[ny - 1][nx] == '.': visited[(nx, ny - 1)] = cur + 1 queue.appendleft((nx, ny - 1)) if ny + 1 < h and (nx, ny + 1) not in visited: if s[ny + 1][nx] == '.': visited[(nx, ny + 1)] = cur + 1 queue.appendleft((nx, ny + 1)) return max(visited.values()) result = 0 for i in range(h): for j in range(w): r = bfs(j, i) result = max(result, r) print(result)
import sys stdin = sys.stdin inf = 1 << 60 mod = 1000000007 ni = lambda: int(ns()) nin = lambda y: [ni() for _ in range(y)] na = lambda: list(map(int, stdin.readline().split())) nan = lambda y: [na() for _ in range(y)] nf = lambda: float(ns()) nfn = lambda y: [nf() for _ in range(y)] nfa = lambda: list(map(float, stdin.readline().split())) nfan = lambda y: [nfa() for _ in range(y)] ns = lambda: stdin.readline().rstrip() nsn = lambda y: [ns() for _ in range(y)] ncl = lambda y: [list(ns()) for _ in range(y)] nas = lambda: stdin.readline().split() n, k = na() def modpow(n, p, m): if p == 0: return 1 if p % 2 == 0: t = modpow(n, p // 2, m) return t * t % m return n * modpow(n, p - 1, m) % m d = [0] * (k + 1) ans = 0 for i in range(k, 0, -1): d[i] = modpow(k // i, n, mod) j = 2 while j * i <= k: d[i] -= d[j * i] j += 1 ans += d[i] * i % mod print(ans % mod)
0
null
65,642,477,628,220
241
176
n, k = list(map(int, input().split())) h = list(map(int, input().split())) h.sort() if k > 0: h = h[:-k] print(sum(h))
x = int(input()) prlist = [] n = 2 sosuu = 0 answer = 0 while n**2 < x: for i in prlist: if n % i == 0: sosuu = 1 break if sosuu == 0: prlist.append(n) sosuu = 0 n += 1 sosuu = 1 while answer == 0: for j in prlist: if x % j == 0: sosuu = 2 break if sosuu == 1: answer = x sosuu = 1 x += 1 print(answer)
0
null
92,117,233,512,230
227
250
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import defaultdict def f(x): return (int(str(x)[0]), int(str(x)[-1])) def main(): N = int(readline()) df = defaultdict(int) for i in range(1, N+1): df[f(i)] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): ans += df[(i, j)]*df[(j, i)] print(ans) if __name__ == '__main__': main()
n = int(input()) dic = {} for i in range(1,n+1): if str(i)[-1] == 0: continue key = str(i)[0] key += "+" + str(i)[-1] if key in dic: dic[key] += 1 else: dic[key] = 1 res = 0 for i in range(1,n+1): if str(i)[-1] == 0: continue key = str(i)[-1] key += "+" + str(i)[0] if key in dic: res += dic[key] print(res)
1
86,457,550,676,528
null
234
234
K=int(input()) s =input() x = len(s) if x<=K: print(s) else: print(s[:K]+'...')
a = '' n = int(input()) while n> 0: n -= 1 a += chr(ord('a') + n%26) n //=26 print(a[::-1])
0
null
15,742,463,113,618
143
121
from collections import deque def bfs(start, g, visited): q = deque([start]) visited[start] = 0 while q: curr_node = q.popleft() for next_node in g[curr_node]: if visited[next_node] >= 0: continue visited[next_node] = visited[curr_node] + 1 q.append(next_node) def main(): n,u,v = map(int, input().split()) gl = [ [] for _ in range(n+1)] visited_u = [-1] * (n+1) visited_v = [-1] * (n+1) for i in range(n-1): a, b = map(int, input().split()) gl[a].append(b) gl[b].append(a) bfs(u, gl, visited_u) bfs(v, gl, visited_v) # print(visited_u) # print(visited_v) # target_i = 0 # max_diff_v = 0 ans = 0 for i in range(1,n+1): if visited_u[i] < visited_v[i] and visited_v[i]: # if (visited_v[i]-visited_u[i])%2 == 0: val = visited_v[i]-1 ans = max(ans,val) # else: # val = visited_v[i] # ans = max(ans,val) print(ans) if __name__ == "__main__": main()
n, u, v = map(int, input().split()) V = [ [] for _ in range(n + 1) ] for _ in range(n - 1): a, b = map(int, input().split()) V[a].append(b) V[b].append(a) import collections def bfs(x): X = [ -1 ] * (n + 1) q = collections.deque([ (x, 0) ]) X[x] = 0 while q: node, dist = q.popleft() for dst in V[node]: if X[dst] == -1: X[dst] = dist + 1 q.append((dst, dist + 1)) return X T = bfs(u) A = bfs(v) ans = 0 for i in range(1, len(T)): if T[i] < A[i]: ans = max(ans, A[i] - 1) print(ans)
1
117,405,767,428,168
null
259
259
import sys N, M = map(int, input().split()) S = [] C = [] for m in range(M): s, c = map(int, input().split()) S.append(s) C.append(c) for i in range(10**N): tes = str(i) if len(tes) != N: continue flag = True for s, c in zip(S, C): if tes[s-1] != str(c): flag = False if flag: print(tes) sys.exit() print(-1)
# -*- coding: utf-8 -*- """ Created on Mon Sep 7 17:11:27 2020 @author: liang """ N, M = map(int, input().split()) ans = [-1]*N res = 0 for i in range(M): s, c = map(int, input().split()) if s == 1 and c == 0 and N != 1: print(-1) break if ans[s-1] == -1 or ans[s-1] == c: ans[s-1] = c else: print(-1) break else: if ans[0] == -1: ans[0] = 1 if M == 0 and N == 1: ans[0] = 0 ans = [0 if a == -1 else a for a in ans] #print(ans) for i in range(N): res += ans[-(i+1)]*10**i print(res)
1
60,436,595,376,420
null
208
208
def resolve(): import numpy as np d = int(input()) C = list(map(int, input().split())) S = [] for _ in range(d): _S = list(map(int, input().split())) S.append(_S) S = np.array(S) T = [] for _ in range(d): T.append(int(input())) last = [-1 for i in range(26)] score = 0 for i in range(d): # max_idx = np.argmax(S[i]) # print(max_idx + 1) score += S[i][T[i] - 1] last[T[i] - 1] = i for j in range(26): score -= C[j] * (i - last[j]) print(score) resolve()
n,m=map(int,input().split()) a=list(map(int,input().split())) c=0 for i in a: if i>=sum(a)*(1/(4*m)): c+=1 if c>=m: print('Yes') else: print('No')
0
null
24,197,243,435,482
114
179
Nsum = 0 while True: I = input() if int(I) == 0: break for i in I: Nsum += int(i) print(Nsum) Nsum = 0
numbers = [int(i) for i in input().split()] D, S, T = numbers[0], numbers[1], numbers[2] if D <= S*T: print("Yes") else: print("No")
0
null
2,518,635,034,372
62
81
N = int(input()) S = [input() for _ in range(N)] C0 = 0 C1 = 0 C2 = 0 C3 = 0 for i in range(N): if S[i] == "AC": C0 += 1 elif S[i] == "WA": C1 += 1 elif S[i] == "TLE": C2 += 1 else: C3 += 1 print("AC x "+ str(C0)) print("WA x "+ str(C1)) print("TLE x "+ str(C2)) print("RE x "+ str(C3))
n=list(input()) n=n[::-1] k=int(n[0]) if k==3: print("bon") elif k==2 or k==4 or k==5 or k==7 or k==9: print("hon") else: print("pon")
0
null
13,981,854,507,872
109
142
#!/usr/bin/env python3 c = [[0] * 10 for _ in [0] * 10] for i in range(1, int(input()) + 1): c[int(str(i)[0])][int(str(i)[-1])] += 1 print(sum(c[i][j] * c[j][i] for i in range(10) for j in range(10)))
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,450,855,392,420
null
234
234
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))
n= int(input()) s = input() ans = 1 for i in range(n-1): if s[i]==s[i+1]: pass else: ans += 1 print(ans)
0
null
162,852,169,694,708
285
293
N = int(input()) a_num = 97 def dfs(s, n): #s: 現在の文字列, n: 残りの文字数, cnt: 現在の文字列の最大の値 if n == 0: print(s) return for i in range(ord("a"), ord(max(s))+2): dfs(s+chr(i), n-1) dfs("a", N-1)
import math N = int(input()) Alist = list(map(int,input().split())) box = [0]*(10**6+1) sign = math.gcd(Alist[0],Alist[1]) Amax = max(Alist[0],Alist[1]) for i in range(0,len(Alist)): A = Alist[i] sign = math.gcd(sign, A) Amax = max(Amax, A) box[A] += 1 setwise = (sign == 1) pairwise = (sign == 1) Amax = math.sqrt(Amax)+1 for i in range(2,10**6+1): if sum(box[i::i]) >1: pairwise = False break if setwise: if pairwise: print('pairwise coprime') else: print('setwise coprime') else: print('not coprime')
0
null
28,414,303,926,488
198
85
l = [] a,b,c = map(int,input().split()) for i in range(a,b+1): if c % i == 0: l.append(i) ll = len(l) print(str(ll))
s=input() if s[len(s)-1]=='s':print(s+'es') else:print(s+'s')
0
null
1,497,592,016,540
44
71
def solve(string): s, t = string.split() return str(len(s) - sum(_s == _t for _s, _t in zip(s, t))) if __name__ == '__main__': import sys print(solve(sys.stdin.read().strip()))
import numpy as np N = int(input()) A = list(map(int, input().split())) A = np.argsort(A) for a in A: print(a+1, end=" ")
0
null
95,697,731,424,060
116
299
import sys INF = 10**60 inint = lambda: int(sys.stdin.readline()) inintm = lambda: map(int, sys.stdin.readline().split()) inintl = lambda: list(inm()) instr = lambda: sys.stdin.readline() instrm = lambda: map(str, sys.stdin.readline().split()) instrl = lambda: list(instrm()) n = inint() min_sum = INF i = 0 j = 0 for k in range(1,n): if k > n**0.5: break if n/k % 1 != 0: continue i = k j = n/k if i+j < min_sum: min_sum = i+j print(int(min_sum - 2))
N = int(input()) ans = 10**100 for i in range(1,int(N**(0.5))+1): if N % i == 0: tmp = (i-1) + (N//i -1) ans = min(ans,tmp) print(ans)
1
161,523,284,950,300
null
288
288
n=int(input()) suit = ["S","H","C","D"] card = {i:[] for i in suit} for i in range(n): tmp = ([c for c in input().split()]) card[tmp[0]].append(tmp[1]) for i in suit: for j in range(1,14): if not (str(j) in card[i]): print("%s %s" % (i,j))
import sys n = input() a = [] flag = {} for j in range(1, 14): flag[('S',j)] = 0 flag[('H',j)] = 0 flag[('C',j)] = 0 flag[('D',j)] = 0 for i in range(n): temp = map(str, raw_input().split()) a.append((temp[0],temp[1])) #print a[i][0] #print a[i][1] card = ['S', 'H', 'C', 'D'] #print card for egara in card: for i in range(n): if(a[i][0] == egara): for j in range(1,14): if(int(a[i][1]) == j): flag[(egara, j)] = 1 for egara in card: for j in range(1,14): if(flag[(egara, j)] == 0): sys.stdout.write(egara) sys.stdout.write(' ') sys.stdout.write(str(j)) print exit(0)
1
1,035,253,511,236
null
54
54
A, B, C, D=map(int,input().split()) if (A+D-1)//D<(C+B-1)//B: print("No") else: print("Yes")
t_HP, t_A, a_HP, a_A = map(int,input().split()) ans = False while True: a_HP -= t_A if a_HP <= 0: ans = True break t_HP -= a_A if t_HP <= 0: break if ans == True: print("Yes") else: print("No")
1
29,968,551,220,648
null
164
164
def bubble_sort(data): for i in range(len(data) - 1): for j in range(len(data) - 1, i, -1): if int(data[j][1]) < int(data[j - 1][1]): data[j], data[j - 1] = data[j - 1], data[j] def selection_sort(data): for i in range(len(data)): min_j = i for j in range(i, len(data)): if int(data[j][1]) < int(data[min_j][1]): min_j = j if min_j != i: data[i], data[min_j] = data[min_j], data[i] input() cards = [x for x in input().split()] cards_b = cards.copy() cards_s = cards.copy() bubble_sort(cards_b) selection_sort(cards_s) for data in [cards_b, cards_s]: print(' '.join(data)) if data == cards_b: print("Stable") else: print("Not stable")
def is_stable(oline, line): for i in range(N): for j in range(i+1, N): for a in range(N): for b in range(a+1, N): if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]): return False return True N = int(input()) line = input().split() oline = line.copy() #BubbleSort for i in range(N): for j in range(N-1, i, -1): if int(line[j][1]) < int(line[j-1][1]): tmp = line[j] line[j] = line[j-1] line[j-1] = tmp print(' '.join(line)) print(('Not stable', 'Stable')[is_stable(oline, line)]) #SelectionSort line = oline.copy() for i in range(N): minj = i for j in range(i+1, N): if int(line[minj][1]) > int(line[j][1]): minj = j tmp = line[i] line[i] = line[minj] line[minj] = tmp print(' '.join(line)) print(('Not stable', 'Stable')[is_stable(oline, line)])
1
23,441,807,312
null
16
16
A,B = map(int, input().split()) print(int((A*(A-1)+B*(B-1))/2))
s,t = map(str,input().split()) print(t ,end='') print(s)
0
null
74,294,926,384,228
189
248
r, c = map(int, input().split()) table = [cc + [sum(cc)] for cc in (list(map(int, input().split())) for _ in range(r))] table.append(list(map(sum, zip(*table)))) for line in table: print(*line)
import sys r, c = map(int, raw_input().split()) table = {} for i in range(r): a = map(int, raw_input().split()) for j in range(c): table[(i,j)] = a[j] for i in range(r+1): for j in range(c+1): if(i != r and j != c): sys.stdout.write(str(table[(i,j)])) sys.stdout.write(' ') elif(i != r and j == c): print sum(table[(i,l)] for l in range(c)) elif(i == r and j != c): sys.stdout.write(str(sum(table[(k,j)] for k in range(r)))) sys.stdout.write(' ') elif(i == r and j == c): total = 0 for k in range(r): for l in range(c): total += table[(k,l)] print total
1
1,345,656,739,450
null
59
59
n = int(input()) p = list(map(int,input().split())) minp =[p[0]] for i in range(1,n): minp.append(min(minp[i-1],p[i])) cnt = 0 for i in range(n): if minp[i] == p[i]: cnt += 1 print(cnt)
m,n,o=map(int,raw_input().split()) print'Yes'if m<n<o else'No'
0
null
43,081,731,868,540
233
39
while True: h, w = map(int, input().split()) if h == w == 0: break for c in ['\n' if y == w else '#' if (x+y) % 2 == 0 else '.' for x in range(0,h) for y in range(0, w + 1)]: print(c, end='') print('')
def main(): import sys input=sys.stdin.readline h,w,k=map(int,input().split()) H=range(h) W=range(w) dp=[[[0]*w for j in H] for i in range(4)] for _ in range(k): r,c,v=map(int,input().split()) dp[0][r-1][c-1]=v if dp[0][0][0]!=0: dp[1][0][0]=dp[0][0][0] dp[0][0][0]=0 for y in H: for x in W: v=dp[0][y][x] dp[0][y][x]=0 for i in range(4): if 0<x: if dp[i][y][x]<dp[i][y][x-1]: dp[i][y][x]=dp[i][y][x-1] if 0<i and v!=0 and dp[i][y][x]<dp[i-1][y][x-1]+v: dp[i][y][x]=dp[i-1][y][x-1]+v if 0<y: if dp[0][y][x]<dp[i][y-1][x]: dp[0][y][x]=dp[i][y-1][x] if v!=0 and dp[1][y][x]<dp[i][y-1][x]+v: dp[1][y][x]=dp[i][y-1][x]+v print(max([dp[i][h-1][w-1] for i in range(4)])) main()
0
null
3,243,112,536,110
51
94
def insertionSort(A, n, g): global cnt for i in range(g,n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt+=1 A[j+g] = v def shellSort(A, n): global cnt cnt = 0 g = 1 G = [1] m = 1 for i in range(1,101): tmp = G[i-1]+(3)**i if tmp <= n: m = i+1 G.append(tmp) g += 1 else: break G.reverse() print(m) # 1行目 print(" ".join(list(map(str,G)))) # 2行目 for i in range(0,m): insertionSort(A, n, G[i]) print(cnt) # 3行目 for i in range(0,len(A)): print(A[i]) # 4行目以降 cnt = 0 n = int(input()) A = [] for i in range(n): A.append(int(input())) shellSort(A,n)
def insertion_sort(A): for i in range(1, len(A)): print(A) v = A[i] j = i - 1 while (j >= 0) and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v return A def bubble_sort(A): cnt = 0 flag = True while flag: flag = False for i in sorted(range(1, len(A)), reverse=True): if A[i] < A[i - 1]: cnt += 1 tmp = A[i] A[i] = A[i - 1] A[i - 1] = tmp flag = True return A, cnt def selection_sort(A): for i in range(len(A)): minj = i for j in range(i, len(A)): if A[j] < A[minj]: minj = j tmp = A[i] A[i] = A[minj] A[minj] = tmp return A def insertion_sort_for_shell(A, g): cnt = 0 for i in range(g, len(A)): v = A[i] j = i - g while (j >= 0) and (A[j] > v): A[j + g] = A[j] j -= g cnt += 1 A[j + g] = v return A, cnt def shell_sort(A): cnt = 0 G = [] g = 1 while True: G.append(g) g = g *3 + 1 if g > len(A): break G = sorted(G, reverse=True) for g in G: A, c = insertion_sort_for_shell(A, g) cnt += c return A, G, cnt def print_shell_sort_result(A, G, cnt): print(len(G)) print(' '.join(map(str, G))) print(cnt) [print(a) for a in A] if __name__ == '__main__': N = int(input()) A = [0] * N for i in range(N): A[i] = int(input()) print_shell_sort_result(*shell_sort(A))
1
30,333,337,952
null
17
17
# encoding:utf-8 input = map(int, raw_input().split()) a, b = input if a == b: print("a == b") elif a > b: print("a > b") else: print("a < b")
a,b=list(map(int,input().split())) if a==b: print("a == b") elif a<b: print("a < b") else: print("a > b")
1
367,002,284,990
null
38
38
#input K = int(input()) S = str(input()) #output # (o以外) o (o以外) o (f以外) f (何でも) #こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。 mod = pow(10, 9) + 7 n_ = 5 * pow(10, 6) fun = [1] * (n_+1) for i in range(1, n_+1): fun[i] = fun[i-1] * i % mod rev = [1] * (n_+1) rev[n_] = pow(fun[n_], mod-2, mod) for i in range(n_-1, 0, -1): rev[i] = rev[i+1] * (i+1) % mod def cmb(n,r): if n < 0 or r < 0 or r > n: return 0 return fun[n] * rev[r] % mod * rev[n-r] % mod #重複組み合わせはH(n, r) = cmb(n+r-1, r) L = len(S) answer = 0 for i in range(K+1): answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(L-1+i, i) answer %= mod print(answer)
import sys sys.setrecursionlimit(10000000) MOD = 10 ** 9 + 7 INF = 10 ** 15 def main(): K = int(input()) S = input() M = len(S) N = M + K MAXN = N + 2 fact = [1] for i in range(1,MAXN + 1): fact.append(fact[-1]*i%MOD) inv_fact = [-1] * (MAXN + 1) inv_fact[-1] = pow(fact[-1],MOD - 2,MOD) for i in range(MAXN - 1,-1,-1): inv_fact[i] = inv_fact[i + 1]*(i + 1)%MOD nck = lambda N,K: 0 if K > N or K < 0 else fact[N]*inv_fact[N - K]*inv_fact[K]%MOD power25 = [1] power26 = [1] for i in range(N): power25.append(power25[-1]*25%MOD) power26.append(power26[-1]*26%MOD) ans = 0 for i in range(M,N + 1): ans += nck(i - 1,M - 1) * power25[i - M] * power26[N - i] % MOD ans %= MOD print(ans) if __name__ == '__main__': main()
1
12,808,836,280,448
null
124
124
# -*- codinf: utf-8 -*- import math N = int(input()) # 素因数分解 n = N i = 2 f = {} # keyが素因数、valueが素因数の数 while i * i <= n: count = 0 while n % i == 0: count += 1 f[i] = count n /= i i += 1 if 1 < n: f[n] = 1 if len(f) == 0: print(0) exit() count = 0 for v in f.values(): d = 1 while v > 0: v -= d if v >= 0: count += 1 d += 1 print(count)
N = int(input()) def factors(n): i = 2 factors = [] while i * i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return factors p = list(set(factors(N))) ans = 0 e = 0 i = 0 for i in range(len(p)): e = 1 while 1 < N: z = p[i] ** e if N % z == 0: N //= z ans += 1 else: break e += 1 print(ans)
1
16,999,527,553,712
null
136
136
import sys sys.setrecursionlimit(10**9) def main(): N,M,K = map(int,input().split()) MOD = 998244353 def get_fact(maxim,mod): maxim += 1 fact = [0]*maxim fact[0] = 1 for i in range(1,maxim): fact[i] = fact[i-1] * i % mod invfact = [0]*maxim invfact[maxim-1] = pow(fact[maxim-1],mod-2,mod) for i in reversed(range(maxim-1)): invfact[i] = invfact[i+1] * (i+1) % mod return fact, invfact def powerful_comb(n,r,mod,fact,invfact): return fact[n] * invfact[r] * invfact[n-r] % mod ans = 0 fact, invfact = get_fact(N+1,MOD) for i in range(K+1): ans += (M*pow(M-1,N-i-1,MOD) * powerful_comb(N-1,i,MOD,fact,invfact)) % MOD print(ans % MOD) if __name__ == "__main__": main()
from functools import reduce def cin(): return list(map(int,input().split())) N, M, K = cin() MOD = 998244353 fac = [1] * (N + 1) inv = [1] * (N + 1) for j in range(1, N + 1): fac[j] = fac[j - 1] * j % MOD inv[N] = pow(fac[N], MOD - 2, MOD) for j in range(N - 1, -1, -1): inv[j] = inv[j + 1] * (j + 1) % MOD def cmb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % MOD ans = 0 for i in range(K + 1): ans += M * cmb(N - 1, i) * pow(M - 1, N - 1 - i, MOD) ans %= MOD print(ans)
1
23,120,132,881,884
null
151
151
import sys chash = {} for i in range( ord( 'a' ), ord( 'z' )+1 ): chash[ chr( i ) ] = 0 while True: line = sys.stdin.readline().rstrip() if not line: break for i in range( len( line ) ): if line[i].isalpha(): chash[ line[i].lower() ] += 1 for i in range( ord( 'a' ), ord( 'z' )+1 ): print( "{:s} : {:d}".format( chr( i ), chash[ chr( i ) ] ) )
s = "" while True: try: s += input().lower() except: break dic = {} orda = ord("a") ordz = ord("z") for c in s: if orda <= ord(c) <= ordz: try: dic[c] += 1 except: dic[c] = 1 for i in range(orda,ordz + 1): c = chr(i) try: print("%s : %d" % (c, dic[c])) except: print("%s : %d" % (c, 0))
1
1,665,775,677,680
null
63
63
S = input() Q = int(input()) d = 0 X = [[], []] for i in range(Q): q = input() if q[0] == "1": d = (d + 1) % 2 else: a, f, c = q.split() x = (int(f) + d) % 2 X[x].append(c) if d == 0: v = "".join(X[1])[::-1] + S + "".join(X[0]) else: v = "".join(X[0])[::-1] + S[::-1] + "".join(X[1]) print(v)
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): N = int(input()) P = list(map(int, input().split())) Q = list(map(int, input().split())) p = 0 q = 0 for i, v in enumerate(permutations(range(1, N + 1)), start=1): p_ok = True q_ok = True for j in range(N): p_ok &= v[j] == P[j] q_ok &= v[j] == Q[j] if p_ok: p = i if q_ok: q = i print(abs(p - q)) def main(): solve() if __name__ == '__main__': main()
0
null
79,244,350,142,440
204
246
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict import bisect con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) def Binary_Search(A, N, M): #初期化 left = 0 right = 10 ** 7 ans = 0 #累積和 Asum = [0] for i in range(N): Asum.append(Asum[i] + A[-1 - i]) leftj = [INF, INF] rightj = [0, 0] #二分探索 while left <= right: mid = (left + right) // 2 var = 0 happiness = 0 for i in range(N): ind = bisect.bisect_left(A, mid - A[i]) ind = N - ind var += ind happiness += ind * A[i] + Asum[ind] # print(var, happiness) if var == M: return happiness elif var > M: leftj = min(leftj, [var, -mid]) left = mid + 1 else: ans = max(ans, happiness) rightj = max(rightj, [var, -mid]) right = mid - 1 # print(ans) # print(leftj) # print(rightj) ans = ans + (M - rightj[0]) * (-leftj[1]) return ans #処理内容 def main(): N, M = getlist() A = getlist() A.sort() ans = Binary_Search(A, N, M) print(ans) if __name__ == '__main__': main()
import sys from bisect import bisect_right, bisect_left from itertools import accumulate sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): def meguru_bisect(ok, ng): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok def is_ok(x): cnt = 0 for a in A: t = x - a idx = bisect_right(A, t) cnt += n - idx return cnt < m n, m = map(int, input().split()) A = list(map(int, input().split())) A.sort() ng, ok = 0, 10 ** 15 + 1 mth = meguru_bisect(ok, ng) R = [0] + list(accumulate(A)) res = 0 cnt = 0 for a in A: s = mth - a left = bisect_left(A, s) res += (n - left) * a + R[-1] - R[left] cnt += n - left print(res - mth * (cnt - m)) if __name__ == '__main__': resolve()
1
107,917,525,775,712
null
252
252
K = int(input()) S = input() MAX = 2 * 10 ** 6 + 1 MOD = 10 ** 9 + 7 # Factorial fac = [0] * (MAX + 1) fac[0] = 1 fac[1] = 1 for i in range(2, MAX + 1): fac[i] = fac[i - 1] * i % MOD # Inverse factorial finv = [0] * (MAX + 1) finv[MAX] = pow(fac[MAX], MOD - 2, MOD) for i in reversed(range(1, MAX + 1)): finv[i - 1] = finv[i] * i % MOD def comb(n, k): if n < k or k < 0: return 0 return (fac[n] * finv[k] * finv[n - k]) % MOD N = len(S) ans = 0 for i in range(K + 1): tmp = (pow(25, K - i, MOD) * pow(26, i, MOD)) % MOD ans += comb(N + K - i - 1, N - 1) * tmp 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,833,545,529,210
null
124
124
a,b=map(int,raw_input().split()) print'%d %d' %(a*b,2*(a+b))
# A - A?C # 'ABC'には'ARC'を、'ARC'には'ABC'を返す S = str(input()) if S == 'ABC': print('ARC') elif S == 'ARC': print('ABC')
0
null
12,133,441,921,300
36
153
import sys input = sys.stdin.readline n,m = map(int,input().split()) a = [int(i) for i in input().split()] a = sorted(list(set(a))) from fractions import gcd lc = a[0] if n != 1: for num,i in enumerate(a[1:]): if lc == 0: break lc = lc * i // gcd(lc, i) if gcd(lc, i) == min(i,lc): for j in a[:num+1]: if (i/j)%2 == 0: lc = 0 break if lc == 0: print(0) else: print((m+lc//2)//lc)
import math import sys n,m = map(int, input().split()) a = list(map(int, input().split())) def gcd(x,y): if x < y: x,y = y,x while x%y != 0: x,y = y,x%y return y def lcm(x,y): return x/gcd(x,y)*y def f(x): count = 0 while x%2 == 0: x /= 2 count += 1 return count for i in range(n): if a[i]%2 == 1: print(0) sys.exit() a[i] /= 2 count = f(a[0]) for i in range(n): if f(a[i]) != count: print(0) sys.exit() a[i] /= 2**count m /= 2**count l = 1 for i in range(n): l = lcm(l,a[i]) if l > m: print(0) sys.exit() m /= l ans = (m+1)/2 print(int(ans))
1
101,812,384,173,850
null
247
247
rs = [(x - l, x + l) for x, l in (map(int, input().split()) for _ in range(int(input())))] rs.sort(key=lambda x: x[1]) last = - 10 ** 9 ans = 0 for l, r in rs: if last <= l: ans += 1 last = r print(ans)
import sys W,H,x,y,r = map(int,sys.stdin.readline().split()) if x+r > W or x-r < 0 or y+r > H or y-r < 0: print('No') else: print('Yes')
0
null
44,987,858,497,010
237
41
L=int(input()) anssub=L/3 ans=anssub**3 print(ans)
L = int(input()) A = L/3 B = (L-A)/2 C = L - A - B print(A * B * C)
1
46,910,348,464,250
null
191
191
import re import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def v(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 6) mod = 10**9+7 cnt = 0 ans = 0 inf = float("inf") al = "abcdefghijklmnopqrstuvwxyz" AL = al.upper() n = k() a = l() sum = 1000 for i in range(n-1): if a[i] > a[i+1]: xx = a[cnt:i+1] b = sum//min(xx) sum += (max(xx)-min(xx))*b cnt = i+1 xx = a[cnt:] b = sum//min(xx) sum += (max(xx)-min(xx))*b print(sum)
n = int(input()) a = list(map(int, input().split())) okane = 1000 kabu = 0 for i in range(n-1): if a[i] > a[i+1]: okane += kabu * a[i] kabu = 0 elif a[i] < a[i+1]: kabu += okane // a[i] okane = okane % a[i] r = okane + kabu * a[n-1] print(r)
1
7,416,807,460,260
null
103
103
def Li(): return list(map(int, input().split())) N = int(input()) A = Li() ans = 1 if 0 in A: ans = 0 else: for i in A: ans *= i if ans > pow(10, 18): ans = -1 break print(ans)
n=int(input()) an=[int(i) for i in input().split()] ans=1 for a in an: ans*=a if ans>10**18: ans=-1 break if 0 in an: ans=0 print(ans)
1
16,230,357,252,240
null
134
134
N = int(input()) A = [int(s) for s in input().split(' ')] print('YES' if N == len(set(A)) else 'NO')
N=int(input()) ListIN = list(map(int, input().split())) s_l=set(ListIN) if len(ListIN) == len(s_l): print("YES") else: print("NO")
1
73,739,170,598,782
null
222
222
n = int(input()) a = list(map(int,input().split())) j = 1 ans = 0 for i in a: if i == j: j += 1 else: ans += 1 if j == 1: print('-1') else: print(ans)
W = input() T = input() count = 0 while T != 'END_OF_TEXT': T = T.lower().split() count += T.count(W.lower()) T = input() print(count)
0
null
58,331,506,209,680
257
65
#!/usr/bin/env python # -*- coding: utf-8 -*- h = [int(input()) for i in range(10)] h.sort() h.reverse() print(h[0]) print(h[1]) print(h[2])
a = []; for i in range(0, 10): a.append(int(input())); a.sort(reverse = True); for i in range(0, 3): print(a[i]);
1
28,555,788
null
2
2
n = int(input()) # cs = ['W' for i in range(200000)] cs = input() w_count = 0 for c in cs: if c == 'W': w_count += 1 if w_count == 0: print(0) exit() rest = cs[-w_count:] answer = 0 for c in rest: if c == 'R': answer += 1 print(answer)
a = input().split() print(' '.join(sorted(a)))
0
null
3,375,268,828,740
98
40
while 1: n,m=map(int,input().split()) if n==0 and m==0: break if n<m: print(n,m) else: print(m,n)
import sys input = sys.stdin.readline n, m, l = map(int, input().split()) INF = float("INF") d = [[INF] * n for _ in range(n)] for i in range(n): d[i][i] = 0 for i in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 d[a][b] = c d[b][a] = c for k in range(n): for i in range(n): for j in range(n): if d[i][j] > d[i][k] + d[k][j]: d[i][j] = d[i][k] + d[k][j] # print() # print(*d, sep='\n') for i in range(n): for j in range(n): if i == j: continue if d[i][j] <= l: d[i][j] = 1 else: d[i][j] = INF for k in range(n): for i in range(n): for j in range(n): if d[i][j] > d[i][k] + d[k][j]: d[i][j] = d[i][k] + d[k][j] # print() # print(*d, sep='\n') q = int(input()) for i in range(q): s, t = map(int, input().split()) s -= 1 t -= 1 if d[s][t] == INF: print(-1) else: print(d[s][t]-1)
0
null
86,998,628,345,060
43
295
a, b, c = map(int, input().split()) k = int(input()) if a >= b: while a >= b: if k == 0: print("No") exit() b *= 2 k -= 1 if b >= c: while b >= c: if k == 0: print("No") exit() c *= 2 k -= 1 print("Yes")
a,b,c = map(int,input().split()) K = int(input()) judge = False for i in range(K+1): for j in range(K+1): for k in range(K+1): x = a*2**i y = b*2**j z = c*2**k if i+j+k <= K and x < y and y < z: judge = True if judge: print("Yes") else: print("No")
1
6,911,310,760,944
null
101
101
from collections import defaultdict n, k = map(int, input().split()) A = list(map(int, input().split())) accm = [0] * (n + 1) for i in range(n): accm[i + 1] = accm[i] + A[i] li = [(val - itr) % k for itr, val in enumerate(accm)] ans = 0 box = defaultdict(int) for i in range(n + 1): if i >= k: box[li[i - k]] -= 1 ans += box[li[i]] box[li[i]] += 1 print(ans)
a,b=map(int,input().split()) if a<b: print(str(a)*b) elif a>b: print(str(b)*a) elif a==b: print(str(a)*b)
0
null
110,970,876,201,420
273
232
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): a,b = readInts() print(a - b*2 if a - b*2 >= 0 else 0) if __name__ == '__main__': main()
import sys sys.setrecursionlimit(10**6) a,b = map(int, input().split()) if 2*b > a: print(0) else: print(a-2*b)
1
166,495,461,169,952
null
291
291
N = int(input()) dict = {} strings = [] for i in range(N): x = input() if x in dict.keys(): dict[x] += 1 else: dict[x] = 1 maximum = 1 for i in dict: maximum = max(maximum,dict[i]) for word in dict: if dict[word] == maximum: strings.append(word) strings.sort() for word in strings: print(word)
n = int(input()) d = dict() for i in range(n): s = input() if(s not in d.keys()): d[s] = 1 else: d[s] +=1 max = max(d.values()) ans = [] for i in d.keys(): if(d[i] == max): ans.append(i) for i in sorted(ans): print(i)
1
70,388,101,679,708
null
218
218
n=int(input()) s=input() S=[] for i in s: if ord(i)+n > 90: S.append(chr(ord(i)+n-26)) else: S.append(chr(ord(i)+n)) print(''.join(S))
import sys class alphabet: #Trueなら大文字 def __init__(self, capitalize): self.num = dict() #アルファベットを数字に変換 self.abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"\ ,"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] if capitalize: for i in range(26): self.abc[i] = self.abc[i].upper() for i, a in enumerate(self.abc): self.num[a] = i def solve(): input = sys.stdin.readline N = int(input()) S = input().strip("\n") Ans = "" Alphabet = alphabet(True) for i in range(len(S)): sNum = Alphabet.num[S[i]] rotateNum = (sNum + N) % 26 Ans += Alphabet.abc[rotateNum] print(Ans) return 0 if __name__ == "__main__": solve()
1
134,510,567,167,262
null
271
271
# D N = int(input()) A = list(map(int,input().split())) next_number = 1 cnt = 0 for a in A: if a == next_number: next_number += 1 else: cnt += 1 if cnt == len(A): print('-1') else: print(cnt)
class Dice: def __init__(self, x): self.top = x[0] self.front = x[1] self.right = x[2] self.left = x[3] self.back = x[4] self.bottom = x[5] def N(self): self.top, self.front, self.bottom, self.back = self.front, self.bottom, self.back, self.top def E(self): self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom def S(self): self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom def W(self): self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.top def up_front_to_right(self, top, front): if (top, front) in [(self.top, self.front), (self.front, self.bottom), (self.bottom, self.back), (self.back, self.top)]: return self.right if (top, front) in [(self.front, self.top), (self.bottom, self.front), (self.back, self.bottom), (self.top, self.back)]: return self.left if (top, front) in [(self.left, self.front), (self.front, self.right), (self.right, self.back), (self.back, self.left)]: return self.top if (top, front) in [(self.front, self.left), (self.right, self.front), (self.back, self.right), (self.left, self.back)]: return self.bottom if (top, front) in [(self.top, self.left), (self.left, self.bottom), (self.bottom, self.right), (self.right, self.top)]: return self.front if (top, front) in [(self.left, self.top), (self.bottom, self.left), (self.right, self.bottom), (self.top, self.right)]: return self.back *x,=map(int,input().split()) dice=Dice(x) q=int(input()) for _ in range(q): a,b=map(int,input().split()) print(dice.up_front_to_right(a,b))
0
null
57,405,260,281,138
257
34
from decimal import Decimal A, B = input().split() A = Decimal(A) B = Decimal(B) ans = int(A * B) print(ans)
def sell(rate, kabu): return rate * kabu def buy(rate, money): kabu = money//rate otsuri = money % rate return kabu, otsuri N,*A = map(int, open(0).read().split()) money = 1000 have_kabu = 0 for i in range(N): #売る money += sell(A[i], have_kabu) have_kabu = 0 #買う if i != N-1 and A[i] < A[i+1]: have_kabu, money = buy(A[i], money) print(money)
0
null
11,922,302,354,502
135
103
import math #A , B = map(float,input().split()) a , b = input().split() a = int(a) b = round(100*float(b)) #ans = int (A *(B*100)/100) print(a*b//100)
x = int(input()) k = 1 while(True): if k * x % 360 == 0: print(k) break else: k += 1
0
null
14,822,136,095,952
135
125
import heapq n,k = map(int,input().split()) a = [int(i) for i in input().split()] low = 0 high = 10**9 if k == 0: print(max(a)) exit() while low+1 < high: tmp = 0 mid = (low + high) //2 for i in range(n): tmp += ((a[i]+mid-1) // mid)-1 if tmp <= k: high = mid else: low = mid print(high)
import sys import math import time sys.setrecursionlimit(int(1e6)) if False: dprint = print else: def dprint(*args): pass n, k = list(map(int, input().split())) A = list(map(int, input().split())) dprint("n, k = ", n, k) lx = int(0) # NG rx = int(1e9) # OK #ans = 0 while ((rx-lx)>1): x = (rx + lx) // 2 dprint("lx, x, rx = ", lx, x, rx) n = 0 for i in range(len(A)): #n += math.ceil(A[i] / x) - 1 n += (A[i]-1) // x if n > k: break dprint("n = ", n) if n <= k: dprint(" smaller x") rx = x else: dprint(" cut less, bigger x") lx = x #ans = math.ceil(rx) print(rx)
1
6,429,851,538,326
null
99
99
import math a,b = map(int,input().split()) print((a*b)//math.gcd(a,b))
s = input() for c in s: if c.islower(): print(c.upper(), end="") else: print(c.lower(), end="") print()
0
null
57,731,844,751,838
256
61
a=input() list1=a.split() list2=list(map(int,list1)) K=list2[0] X=list2[1] if 500*K>=X: print("Yes") else: print("No")
k, m = list(map(int, input().split())) if 500 * k >= m: print('Yes') elif 500 * k < m: print('No') else: print('No')
1
98,285,432,211,024
null
244
244
a, b = map(int, input().split()) c = list(map(int, input().split()[:b])) d = sum(c) if d >= a: print("Yes") else: print("No")
from itertools import combinations import math N = int(input()) x = [] y = [] for i in range(N): _x, _y = map(int, input().split()) x.append(_x) y.append(_y) s = 0 for c in combinations(zip(x, y), 2): s += math.sqrt((c[0][0] - c[1][0]) ** 2 + (c[0][1] - c[1][1]) ** 2) print(s * 2 / N)
0
null
113,413,052,329,382
226
280
while input()!='0': n=list(map(int,input().split())) b=len(n) a=sum(n)/b print((sum((x-a)**2 for x in n)/b)**0.5)
import math while True: s = int(input()) if s == 0: break r = list(map(float, input().split())) x = sum(r) / s sigtwo = sum(list(map(lambda y: (y-x)**2, r))) / s sig = math.sqrt(sigtwo) print("{:.8f}".format(sig))
1
199,797,481,280
null
31
31
MOD = 10 ** 9 + 7 def main(): n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort(key=lambda x: abs(x), reverse=True) res = 1 if k == n: for e in a: res *= e res %= MOD elif max(a) < 0: if k % 2 == 1: for i in range(n - k, n): res *= a[i] res %= MOD else: for i in range(k): res *= a[i] res %= MOD else: plus_a = [e for e in a if e >= 0] minus_a = [e for e in a if e < 0] minus_cnt = min(k, len(minus_a)) minus_cnt -= minus_cnt % 2 plus_cnt = k - minus_cnt minus_a = minus_a[:minus_cnt] minus_a.reverse() max_change_cnt = min(minus_cnt, len(plus_a) - plus_cnt) max_change_cnt -= max_change_cnt % 2 change_cnt = 0 while change_cnt < max_change_cnt: if plus_a[plus_cnt + change_cnt] * plus_a[plus_cnt + change_cnt + 1]\ <= minus_a[change_cnt] * minus_a[change_cnt + 1]: break change_cnt += 2 for i in range(change_cnt, minus_cnt): res *= minus_a[i] res %= MOD for i in range(plus_cnt + change_cnt): res *= plus_a[i] res %= MOD print(res) main()
def solve(): MOD = 10**9 + 7 N, K = map(int, input().split()) As = list(map(int, input().split())) if K == N: ans = 1 for A in As: ans *= A ans %= MOD print(ans) return As.sort(key=lambda x: abs(x)) if max(As) < 0 and K%2 != 0: ans = 1 for A in As[:K]: ans *= A ans %= MOD print(ans) return pos0As, negAs = [], [] for A in As: if A >= 0: pos0As.append(A) elif A < 0: negAs.append(A) pos0As.sort() negAs.sort(reverse=True) ans = 1 rest = K while rest > 0: if rest == 1: ans *= pos0As.pop() rest -= 1 else: if len(pos0As) < 2: ans *= negAs.pop() ans *= negAs.pop() rest -= 2 elif len(negAs) < 2: ans *= pos0As.pop() rest -= 1 else: pPos0 = pos0As[-1] * pos0As[-2] pNeg = negAs[-1] * negAs[-2] if pPos0 >= pNeg: ans *= pos0As.pop() rest -= 1 else: ans *= negAs.pop() ans *= negAs.pop() rest -= 2 ans %= MOD print(ans) solve()
1
9,402,212,543,712
null
112
112
n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a_sums, b_sums = [0], [0] for i in range(n): a_sums.append(a_sums[i] + a[i]) for i in range(m): b_sums.append(b_sums[i] + b[i]) ans = 0 j = m for i in range(n + 1): if a_sums[i] > k: break while a_sums[i] + b_sums[j] > k: j -= 1 ans = max(ans, i + j) print(ans)
from bisect import bisect N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) SA = [0] * (N + 1) SB = [0] * (M + 1) for i in range(N): SA[i+1] = SA[i] + A[i] for i in range(M): SB[i+1] = SB[i] + B[i] result = 0 for x in range(N+1): if SA[x] > K: break y = bisect(SB, K - SA[x]) - 1 result = max(result, x + y) print(result)
1
10,668,300,272,510
null
117
117
# import sys input=sys.stdin.readline def main(): N,K=map(int,input().split()) A=list(map(lambda x: int(x)-1,input().split())) latest=[-1]*N latest[0]=0 now=0 while(K>0): K-=1 to=A[now] if latest[A[now]]!=-1: K%=latest[now]-latest[A[now]]+1 latest[A[now]]=latest[now]+1 now=to print(now+1) if __name__=="__main__": main()
n,k=map(int,input().split()) A = list(map(int,input().split())) C=[0]*n C[0]=1 c=0 loopc=0 i=0 io=0 while c<k : newi = A[i]-1 C[newi]+=1 if C[newi]>=3 : rs=newi break elif C[newi]==2 : loopc+=1 io=i i=newi c+=1 if (k-c)<0 or loopc==0 : print(i+1) exit() mod = (k-c)%(loopc) # print( k, c, loopc, i, mod) # i=rs while mod>0 : newi = A[i]-1 i=newi mod-=1 print( i+1 )
1
22,776,904,718,448
null
150
150
n = int(input()) s = input() ans=[] for i in s: a = chr(ord('A')+(ord(i)-ord('A')+n)%26) ans.append(a) print(('').join(ans))
N = int(input()) S = input() list = [] for i in range(len(S)): a = ord(S[i]) + N if a > 90: a -= 26 list.append(chr(a)) print("".join(list))
1
133,901,236,853,150
null
271
271
n, k = map(int, input().split()) mod = 1000000007 def pow(x, n): ret = 1 while n > 0: if (n & 1) == 1: ret = (ret * x) % mod x = (x * x) % mod n //= 2 return ret fac = [1] inv = [1] for i in range(n * 2): fac.append(fac[-1] * (i + 1) % mod) inv.append(pow(fac[-1], mod - 2)) def cmb(n, k): if k < 0 or k > n: return 0 return (fac[n] * inv[k] * inv[n - k]) % mod x = max(0, n - k - 1) ret = cmb(n * 2 - 1, n - 1) for i in range(x): ret = (ret - cmb(n, i + 1) * cmb(n - 1, i)) % mod print(ret)
data = [ [[0 for k in range(10)] for j in range(3)] for i in range(4) ] count = int(input()) for x in range(count): (b,f,r,v) = [int(i) for i in input().split()] data[b - 1][f - 1][r - 1] += v for b in range(4): for f in range(3): print(' ',end='') for r in range(10): if r == 9: print(data[b][f][r], end='') else: print(data[b][f][r], '', end='') print() if b == 3: break for x in range(20): print('#',end='') print()
0
null
34,102,757,312,608
215
55
r,c,k = map(int,input().split()) v = [[0]*(c+1) for i in range(r+1)] for i in range(k): x,y,z = map(int,input().split()) v[x][y] = z dp = [[0]*4 for i in range(r+1)] for i in range(1,c+1): for j in range(1,r+1): if v[j][i]>0: dp[j][3] = max(dp[j][2]+v[j][i],dp[j][3]) dp[j][2] = max(dp[j][1]+v[j][i],dp[j][2]) dp[j][1] = max(dp[j][0]+v[j][i],dp[j][1],max(dp[j-1])+v[j][i]) dp[j][0] = max(dp[j][0],max(dp[j-1])) print(max(dp[r]))
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9+7 INF = float('inf') AZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int,input().split())) def SL(): return list(map(str,input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD-2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if(len(kaijo_memo) > n): return kaijo_memo[n] if(len(kaijo_memo) == 0): kaijo_memo.append(1) while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n] if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1) while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD) return gyaku_kaijo_memo[n] def nCr(n,r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n-r) % MOD return ret ######Factorization###### 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 #####MakeDivisors###### 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) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2,N+1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd (a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n-1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X//n: return base_10_to_n(X//n, n)+[X%n] return [X%n] def base_n_to_10(X, n): return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X)))) def base_10_to_n_without_0(X, n): X -= 1 if X//n: return base_10_to_n_without_0(X//n, n)+[X%n] return [X%n] #####IntLog##### def int_log(n, a): count = 0 while n>=a: n //= a count += 1 return count ############# # Main Code # ############# R,C,K = IL() data = [[0 for i in range(C)] for j in range(R)] for _ in range(K): j,i,v = IL() data[j-1][i-1] = v dp = [[0,0,0,0] for i in range(C+1)] for j in range(R): dpprev = dp[:] for i in range(C): v = data[j][i] m = max(dpprev[i+1]) if v == 0: dp[i+1][0] = max(dp[i][0],m) dp[i+1][1] = max(dp[i][1],m) dp[i+1][2] = max(dp[i][2],m) dp[i+1][3] = max(dp[i][3],m) else: dp[i+1][0] = max(dp[i][0],m) dp[i+1][1] = max(dp[i][1],dp[i][0]+v,m+v) dp[i+1][2] = max(dp[i][2],dp[i][1]+v) dp[i+1][3] = max(dp[i][3],dp[i][2]+v) print(max(dp[-1]))
1
5,563,366,295,278
null
94
94
def i1(): return int(input()) def i2(): return [int(i) for i in input().split()] [n,p]=i2() s=input() if p==2 or p==5: x1=0 for i in range(n): if int(s[i])%p==0: x1+=i+1 print(x1) else: t=0 x2=0 d={0:1} a=1 for i in range(n)[::-1]: t+=int(s[i])*a t%=p a*=10 a%=p if t in d: x2+=d[t] d[t]+=1 else: d[t]=1 print(x2)
from sys import stdin input = stdin.readline def main(): N, K = map(int, input().rstrip().split()) A = list(map(int, input().rstrip().split())) F = list(map(int, input().rstrip().split())) A.sort() F.sort(reverse=True) l = -1 r = 10 ** 12 while(r - l > 1): c = (l + r) // 2 s = 0 for i in range(N): d = A[i] - (c // F[i]) s += max(0, d) if s <= K: r = c else: l = c print(r) if __name__ == "__main__": main()
0
null
111,255,957,808,058
205
290
input() a = input().split() a.reverse() print(' '.join(a))
# -*- coding: utf-8 -*- n = int(raw_input()) num = map(int, raw_input().split()) for e in num[::-1]: if e == num[0]: print e break print e,
1
993,983,556,730
null
53
53
import numpy as np from numba import njit @njit('i8(i8)', cache=True) def solve(x): count = np.zeros(x + 1, dtype=np.int64) for i in range(1, x + 1): for j in range(i, x + 1, i): count[j] += j return count.sum() if __name__ == "__main__": x = int(input()) print(solve(x))
n = int(input()) t = [0]*(n+1) for i in range(1,n+1): for j in range(i,n+1,i): t[j] += j print(sum(t))
1
11,051,983,642,742
null
118
118