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 bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) N,K = LI() H = LI() Hs = np.array(sorted(H, reverse=True)) ans = np.sum(Hs[K:]) print(ans)
A = int(input()) B = int(input()) abc = {1, 2, 3} ab = {A, B} print(list(abc-ab)[0])
0
null
94,575,235,349,530
227
254
# -*- coding: utf-8 -*- import math a, b, C = map(float, input().split()) c = math.sqrt((a * a) + (b * b) - 2 * a * b * math.cos(math.radians(C))) s = (a * b * math.sin(math.radians(C))) / 2 l = a + b + c h = (2 * s) / a print(s) print(l) print(h)
def main(): s = input() cnt = 0 cnt2 = 0 for i in s: if i == "R": cnt2 += 1 else: cnt = max(cnt, cnt2) cnt2 = 0 print(max(cnt, cnt2)) main()
0
null
2,570,810,963,842
30
90
n=int(input()) s=list(input()) # z=90=>65 for i in s: x=ord(i) y=x+n if y>90: z=chr(y-26) else: z=chr(y) print(z,end='')
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 # # 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() s = input() ans = '' for t in s: st = ord(t) + n if(st > ord('Z')): st = ord('A') + st - ord('Z') - 1 ans = ''.join([ans, chr(st)]) print(ans)
1
134,689,276,692,530
null
271
271
N, M = list(map(int, input().split())) A = list(map(lambda x: int(x),input().split())) cnt = [0 for _ in range(N)] for i in range(N): a = A[i] while a%2 == 0: a = a // 2 cnt[i] += 1 if max(cnt) > min(cnt): print(0) exit(0) C = max(cnt) A = list(map(lambda x: x // pow(2,C), A)) def gcd(a,b): if a<b: a,b = b,a while a%b > 0: a,b = b,a%b return b def lcm(a,b): return a*b//gcd(a,b) x = A[0] for a in A[1:]: x = lcm(x,a) x = x * pow(2,C-1) print((M // x + 1) // 2)
def gcd(x, y): if x == 0: return y return gcd(y % x, x) def lcm(x, y): return x // gcd(x, y) * y n, m = map(int, input().split()) a = list(map(int, input().split())) aa = [e // 2 for e in a] for i, e in enumerate(aa): if i == 0: base = 0 while e % 2 == 0: e //= 2 base += 1 else: cnt = 0 while e % 2 == 0: e //= 2 cnt += 1 if cnt != base: print(0) exit() c = 1 for e in aa: c = lcm(c, e) if c > m: print(0) exit() ans = (m - c) // (2 * c) + 1 print(ans)
1
101,610,329,648,828
null
247
247
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)
# listじゃなくてdict使いたい n = int(input()) j = [0] * 4 moji = ["AC", "WA", "TLE", "RE"] for i in range(n): s=input() if s == "AC": j[0] += 1 elif s=="WA": j[1] += 1 elif s=="TLE": j[2] += 1 elif s == "RE": j[3] += 1 for k in range(4): print(f"{moji[k]} x {j[k]}")
1
8,733,570,173,020
null
109
109
#!usr/bin/env python3 import sys def generate_default_spreadsheet(): r, c = [int(row_col) for row_col in sys.stdin.readline().split()] sheet = [ [int(row_num) for row_num in sys.stdin.readline().split()] for row in range(r) ] return c, sheet def generate_spreadsheet_with_sums(): orig_total_col, sheet_with_sums = generate_default_spreadsheet() sheet_with_sums.append([0 for col in range(orig_total_col)]) for row in range(len(sheet_with_sums)-1): for col in range(len(sheet_with_sums[0])): sheet_with_sums[-1][col] += sheet_with_sums[row][col] for row in sheet_with_sums: row.append(sum(row)) return sheet_with_sums def print_summed_spreadsheet(): sheet_with_sums = generate_spreadsheet_with_sums() [print(*row) for row in sheet_with_sums] def main(): print_summed_spreadsheet() if __name__ == '__main__': main()
r, c = map(int, input().split()) table = [] for i in range(r): table.append(list(map(int, input().split()))) for i in table: i.append(sum(i)) b = [] for i in range(c): x = 0 for k in range(r): x += table[k][i] b.append(x) b.append(sum(b)) for i in table: print(" ".join(map(str, i))) print(" ".join(map(str, b)))
1
1,374,913,560,172
null
59
59
n=int(input()) a=[] b=[] for i in range(n): x,y=map(int,input().split()) a.append(x+y) b.append(x-y) a=sorted(a) b=sorted(b) ans=max(a[-1]-a[0],b[-1]-b[0]) print(ans)
n=int(input()) x=[0]*n y=[0]*n z=[] w=[] for i in range(n): x[i],y[i]= list(map(int, input().strip().split())) z.append(x[i]+y[i]) w.append(x[i]-y[i]) a=max(z)-min(z) b=max(w)-min(w) print(max(a,b))
1
3,410,474,487,940
null
80
80
A = [[]]*3 for row in range(3): A[row] = list(map(int, input().split())) n = int(input()) B = [0]*n for i in range(n): B[i] = int(input()) flag = False def check_bingo(A, B): for row in range(3): if A[row][0] and A[row][1] and A[row][2]: return True for col in range(3): if A[0][col] and A[1][col] and A[2][col]: return True if A[0][0] and A[1][1] and A[2][2]: return True if A[0][2] and A[1][1] and A[2][0]: return True return False for row in range(3): for col in range(3): if A[row][col] in B: A[row][col] = True else: A[row][col] = False print("Yes" if check_bingo(A, B) else "No")
K,X=map(int,input().split()) ans=500*K-X if (ans>=0): print ('Yes') else: print ('No')
0
null
79,099,032,259,950
207
244
n = int(input()) a = [] cnt = 0 for i in range(n): a.append(int(input())) 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 = cnt + 1 a[j+g] = v g = [] g.append(1) m = 0 while g[m] < n: if n > 3 * g[m] + 1: m = m + 1 g.append(3 * g[m-1] + 1) else: break m = m + 1 g.reverse() for i in range(m): insertionSort(a,n,g[i]) print(m) print(*g) print(cnt) for i in range(n): print(a[i])
def a(): x :int = int(input()) if x == 1: return 0 else: return 1 if __name__ == '__main__': print(a())
0
null
1,481,654,937,620
17
76
n = int(input()) a = list(map(int,input().split())) tmp = [0] * (n+1) ans = 0 for i in range(n): tmp[a[i]] += 1 for i in range(1,len(tmp)): if tmp[i] > 1: ans += int(tmp[i] * (tmp[i] - 1) / 2) for i in range(n): if tmp[a[i]] > 1: print(ans - int(tmp[a[i]] * (tmp[a[i]] - 1) / 2) + int((tmp[a[i]] - 1) * (tmp[a[i]] - 2) / 2)) else: print(ans)
inl=map(int, raw_input().split()) if inl[0]>=inl[2]+inl[4] and inl[2]-inl[4]>=0 and inl[1]>=inl[3]+inl[4] and inl[3]-inl[4]>=0: print "Yes" else: print "No"
0
null
23,984,451,802,400
192
41
s=input() i=s[-1] if i=='2' or i=='4' or i=='5' or i=='7' or i=='9': print('hon') elif i=='0' or i=='1' or i=='6' or i=='8': print('pon') else: print('bon')
N = int(input()) N1 = N % 10 if N1 == 3: print("bon") elif (N1 == 0) or (N1 == 1) or (N1 == 6) or (N1 == 8): print("pon") else: print("hon")
1
19,312,634,002,412
null
142
142
while 1: n, x = map(int, raw_input().split()) if n == 0 and x == 0: break count = 0 for i in xrange(1, n-1): for j in xrange(i+1, n): for k in xrange(j+1, n+1): if i+j+k > x: break if i+j+k == x: count += 1 print count
N,K=map(int,input().split()) mod=10**9+7 def cmb(n,r): global mod if r<0 or r>n: return 0 return (g1[n]*g2[r]*g2[n-r])%mod g1=[1,1] g2=[1,1] inv=[0,1] for i in range(2,1000003): g1.append((g1[-1]*i)%mod) inv.append((-inv[mod%i]*(mod//i))%mod) g2.append((g2[-1]*inv[-1])%mod) P=0 for i in range(min(N,K+1)): P=(P+cmb(N,i)*cmb(N-1,i))%mod print(P)
0
null
34,320,950,061,970
58
215
a,b,c = map(int,input().split()) print("%d %d %d" %(c,a,b))
x = input().split() x[0], x[1], x[2] = x[2], x[0], x[1] print(x[0]+' '+x[1]+' '+x[2])
1
38,019,371,161,310
null
178
178
# C - Next Prime N = 110000 p = [0]*N x = int(input()) for i in range(2,N): if p[i]: continue if i>=x: print(i) break tmp = i while tmp<N: p[tmp] = 1 tmp += i
N,K=map(int,input().split()) a=N%K b=abs(N%K-K) print(min(a,b))
0
null
72,771,993,834,720
250
180
while True: [a,b,c]=[x for x in input().split()] [a,c]=[int(a),int(c)] op=b if op=="?": break elif op=="+": print(a+c) elif op=="-": print(a-c) elif op=="*": print(a*c) else: print(a//c)
#------------------------------------------------------------------------------- #関数定義 def f(a,d,T): try: return T[d+1:].index(a)+(d+1) except ValueError: return len(T) def g(a,d,T): try: return (d-1)-T[d-1::-1].index(a) except ValueError: return 0 #------------------------------------------------------------------------------- #インポート from math import inf,exp from random import random,randint import time from copy import copy #------------------------------------------------------------------------------- #定数 TIME_LIMIT=1.864 #ループの時間制限 A=26 #アルファベットの数 START=time.time() ALPHA=15 ep=10**(-6) #アニーリングの微小温度 #------------------------------------------------------------------------------- #読み込み部 D=int(input()) C=[True]+list(map(int,input().split())) #減る満足度のベース S=[True]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度 for i in range(1,D+1): S[i]=[0]+list(map(int,input().split())) #------------------------------------------------------------------------------- #貪欲部 L=[0]*(A+1) T=[0] for d in range(1,D+1): Y=-inf E=0 for a in range(1,A+1): X=S[d][a] for s in range(1,A+1): if a!=s: X-=C[s]*(d-L[s]) if X>Y: Y=X E=a L[E]=d T.append(E) #------------------------------------------------------------------------------- #調節部 t=time.time()-START while t<TIME_LIMIT: d=randint(1,D) p=T[d] q=randint(1,A) Delta=(S[d][q]-S[d][p])+(d-g(q,d,T))*(f(q,d,T)-d)*C[q]-(d-g(p,d,T))*(f(p,d,T)-d)*C[p] if (Delta>=0) or (Delta<0 and random()<exp(Delta/(ALPHA*(TIME_LIMIT-t)+ep))): T[d]=q t=time.time()-START for i in range(1,D+1): print(T[i])
0
null
5,215,119,309,410
47
113
n=int(input());s=[*input()];count=0 count=s.count('R')*s.count('G')*s.count('B') for i in range(n+1): for j in range(i,n+1): k=2*j-i if k<n: if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]: count-=1 print(count)
X = int(input()) m = 100 y = 0 while m < X : m = m*101//100 y += 1 print(y)
0
null
31,705,041,272,736
175
159
n=int(input()) if n%2==0: print(int((n/2)-1)) else: print(int((n-1)/2))
a,b=map(int,raw_input().split()) print'%d %d' %(a*b,2*(a+b))
0
null
77,168,623,938,160
283
36
# coding: utf-8 # Here your code ! count=0 def merge(A, left, mid, right): global count n1 = mid - left n2 = right - mid L = [0 for i in xrange(n1 + 1)] R = [0 for i in xrange(n2 + 1)] for i in xrange(n1): L[i] = A[left + i] for i in xrange(n2): R[i] = A[mid + i] L[n1] = 1<<32 - 1 R[n2] = 1<<32 - 1 i = 0 j = 0 for k in xrange(left, right): count += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) / 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) if __name__ == "__main__": n = int(raw_input()) refA = map(int, raw_input().split()) A = list(refA) mergeSort(A, 0, n) print " ".join(map(str,A)) print count
cnt=0 def mer(l,r): global cnt ll=len(l) rr=len(r) md=[] i,j=0,0 l.append(float('inf')) r.append(float('inf')) for k in range(ll+rr): cnt+=1 if l[i]<=r[j]: md.append(l[i]) i+=1 else: md.append(r[j]) j+=1 return md def mergesort(a): m=len(a) if m<=1: return a m=m//2 l=mergesort(a[:m]) r=mergesort(a[m:]) return mer(l,r) n=int(input()) a=list(map(int, input().split())) b=mergesort(a) for i in range(n-1): print(b[i],end=" ") print(b[n-1]) print(cnt)
1
111,886,650,082
null
26
26
n=int(input()) a=list(map(int,input().split())) if n==1: print(1) else: min1=a[0] ans=1 for x in range(1,n): if min1>=a[x]: ans+=1 min1=min(min1,a[x]) print(ans)
import sys input = sys.stdin.buffer.readline r, c, k = map(int, input().split()) graph = [[0] * (c) for _ in range(r)] for _ in range(k): d, e, f = map(int, input().split()) graph[d - 1][e - 1] = f infi = 10 ** 10 money = [[[-infi] * (c) for _ in range(r)] for _ in range(4)] money[0][0][0] = 0 for i in range(r): for j in range(c): for t in range(4): m = money[t][i][j] delta = graph[i][j] if i < r - 1: ni = i + 1 nj = j nt = 0 money[nt][ni][nj] = max(money[nt][ni][nj], m) if t < 3: money[nt][ni][nj] = max(money[nt][ni][nj], m + delta) if j < c - 1: ni = i nj = j + 1 nt = t money[nt][ni][nj] = max(money[nt][ni][nj], m) if t < 3: nt = t + 1 money[nt][ni][nj] = max(money[nt][ni][nj], m + delta) ans = 0 if graph[r - 1][c - 1] > 0: for t in range(3): money[t][r - 1][c - 1] += graph[r - 1][c - 1] for i in range(4): ans = max(money[i][r - 1][c - 1], ans) print(ans)
0
null
45,608,029,945,660
233
94
n = int(input()) total = 0 for i in range(n): a,b = map(int, input().split()) if a == b: total += 1 if total == 3: break else: total = 0 if total == 3: print('Yes') else: print('No')
n = int(input()) tmp = 0 import sys for i in range(n): d = list(map(int,input().split())) if d[0] == d[1]: tmp += 1 #check if tmp == 3: print('Yes') sys.exit() else: tmp = 0 print('No')
1
2,489,380,323,132
null
72
72
N,M=map(int, input().split()) if N in [0,1]:n=0 else: n=N*(N-1)/2 if M in [0,1]:m=0 else: m=M*(M-1)/2 print(int(n+m))
n=int(input())-1;print(sum(n//-~i for i in range(n)))
0
null
24,252,497,925,810
189
73
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)
n=input() s='' for i in range(1,int(n)+1): s += (' '+str(i)) if i%3==0 or '3' in str(i) else '' print(s)
0
null
83,243,080,589,408
290
52
from collections import defaultdict import sys N = int(input()) A = list(map(int, input().split())) C = defaultdict(int) for a in A: C[a] += 1 if C[a] >= 2: print('NO') sys.exit() print('YES')
s = input() d = {'ABC': 'ARC', 'ARC': 'ABC'} print(d[s])
0
null
48,939,080,460,110
222
153
n,k=map(int,input().split()) A=sorted(list(map(int,input().split()))) F=sorted(list(map(int,input().split())),reverse=True) ng=-1 ok=10**12+10 while ok-ng>1: mid=(ok+ng)//2 a=0 for i in range(n): a=a+max(0,A[i]-mid//F[i]) if a>k: ng=mid else: ok=mid print(ok)
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)
1
165,160,279,965,212
null
290
290
import sys input = sys.stdin.readline D,T,S = map(int,input().split()) if(D/S <= T): print('Yes') else: print('No')
a=list(map(int,input().split())) if a[0]>a[1]*2: print(a[0]-a[1]*2) else: print('0')
0
null
85,094,719,805,888
81
291
n = int(input()) s = set() for i in range(n): s |= {input()} print(len(s))
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) seen = set() t = ini() for _ in range(t): s = ins() seen.add(s) print(len(seen))
1
30,360,638,837,982
null
165
165
from collections import deque N,M=map(int,input().split()) C=[[] for i in range(N+1)] for i in range(M): A,B=sorted(list(map(int,input().split()))) C[A].append(B) C[B].append(A) d=[-1]*(N+1) d[0]=0 d[1]=0 queue=deque([1]) while queue: now = queue.popleft() for i in C[now]: if d[i]!=-1:continue d[i]=now queue.append(i) if d.count(0)>2:print('No');exit print('Yes') for i in range(2,N+1): print(d[i])
N = int(input()) # 26進数に変換する問題 ans = "" alphabet = "Xabcdefghijklmnopqrstuvwxyz" while N > 0: mod = N % 26 if mod == 0: mod = 26 ans = alphabet[mod] + ans N -= mod N //= 26 print(ans)
0
null
16,163,291,755,588
145
121
A, B = map(int, input().split()) if A == B: print('Yes') else: print('No')
from collections import defaultdict d=defaultdict(int) N,K=map(int,input().split()) A=[0]+list(map(int,input().split())) S=[None]*(N+1) S[0]=0 cnt=0 d[0]=1 for i in range(1,N+1): S[i]=(S[i-1]+A[i]-1)%K for i in range(1,N+1): if i-K>=0: d[S[i-K]]-=1 cnt+=d[S[i]] d[S[i]]+=1 print(cnt)
0
null
110,237,109,048,348
231
273
N = int(input()) purchase_price = int(input()) profit = -2000000000 for _ in range(N-1): price = int(input()) profit = max(profit, (price-purchase_price)) purchase_price = min(price, purchase_price) print(profit)
import sys n = int(input()) minv = int(input()) maxv = -1000000000 for r in map(int,sys.stdin.readlines()): m = r-minv if maxv < m: maxv = m if m < 0: minv = r elif m < 0: minv = r print(maxv)
1
13,939,882,880
null
13
13
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N = readline().strip() if N.count('7') > 0: print('Yes') else: print('No') return if __name__ == '__main__': main()
N = input() ans = "No" for s in N: if s == "7": ans = "Yes" break print(ans)
1
34,203,453,913,632
null
172
172
r=int(input()) print(int(pow(r,2)))
n, k = list(map(int, input().split())) while n > abs(n - k): if n >= k: n = min(n, n % k) elif k > n: n = min(n, k % n) print(n)
0
null
92,424,609,200,898
278
180
import sys input = sys.stdin.readline import numpy as np N, M = map(int, input().split()) L = list(map(int, input().split())) A = np.zeros(1<<18) for i in L: A[i] += 1 C = (np.fft.irfft(np.fft.rfft(A) * np.fft.rfft(A)) + .5).astype(np.int64) G = C.cumsum() count = np.searchsorted(G, N*N-M) rest = N*N-M - G[count-1] temp = (C[:count]*np.arange(count, dtype=np.int64)).sum() + count*rest ans = sum(L)*2*N - temp print(ans)
n,m=map(int,input().split()) A=[int(i) for i in input().split()] A.sort() s=sum(A) SA=[0] for a in A: SA.append(SA[-1]+a) for i in range(n+1): SA[i]=s-SA[i] l,r=0,2*max(A)+1 import bisect def chk(x): ct=0 for a in A: ct+=n-bisect.bisect_left(A,max(x-a,0)) if ct>=m: return True else: return False def count(x): ct=0 for a in A: ct+=n-bisect.bisect_left(A,max(x-a,0)) return ct while r-l>1: mid=(l+r)//2 if chk(mid): l=mid else: r=mid ans=0 for a in A: aa=bisect.bisect_left(A,max(l-a,0)) ans+=SA[aa]+a*(n-aa) print(ans-l*(count(l)-m))
1
107,669,263,951,972
null
252
252
import sys input = sys.stdin.readline P = [list(map(int,input().split())) for i in range(2)] T = int(input()) if(P[0][1]<P[1][1]): print('NO') else: if(abs(P[0][0]-P[1][0])<=abs(P[0][1]-P[1][1])*T): print('YES') else: print('NO')
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) firstDis = abs(A - B) steps = (V - W)*T print("YES" if firstDis <= steps else "NO")
1
15,079,939,271,770
null
131
131
import sys import numpy as np import numba from numba import njit, b1, i4, i8, f8 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines uf_t = numba.types.UniTuple(i8[:], 2) @njit((uf_t, i8), cache=True) def find_root(uf, x): root = uf[0] while root[x] != x: root[x] = root[root[x]] x = root[x] return x @njit((uf_t, i8, i8), cache=True) def merge(uf, x, y): root, size = uf x, y = find_root(uf, x), find_root(uf, y) if x == y: return False if size[x] < size[y]: x, y = y, x size[x] += size[y] root[y] = root[x] return True @njit((i8, i8, i8[:]), cache=True) def main(N, M, AB): ans = N - 1 root = np.arange(N + 1, dtype=np.int64) size = np.ones_like(root) uf = (root, size) for i in range(0, len(AB), 2): a, b = AB[i:i + 2] if merge(uf, a, b): ans -= 1 return ans N, M = map(int, readline().split()) AB = np.array(read().split(), np.int64) print(main(N, M, AB))
import queue N, M = map(int, input().split()) e = [[] for _ in range(N)] for i in range(M): A, B = map(int, input().split()) A -= 1 B -= 1 e[A].append(B) e[B].append(A) # print(e) seen = [-1] * N k = -1 for i in range(N): if seen[i] == -1: k += 1 seen[i] = k que = queue.Queue() que.put(i) while not que.empty(): v = que.get() for nv in e[v]: if seen[nv] != -1: continue seen[nv] = k que.put(nv) # print(seen) print(k)
1
2,307,653,003,348
null
70
70
N = int(input()) S = input() total = 0 for i in range(N-2): if S[i] == "R": num_G = S[i+1:].count('G') num_B = S[i+1:].count('B') total += num_G * num_B elif S[i] == "G": num_B = S[i+1:].count('B') num_R = S[i+1:].count('R') total += num_B * num_R elif S[i] == "B": num_G = S[i+1:].count('G') num_R = S[i+1:].count('R') total += num_G * num_R for i in range(N-2): for j in range(i+1, N-1): if 2*j-i >= N: continue if S[j] != S[i] and S[2*j-i] != S[j] and S[2*j-i] != S[i]: total -= 1 print(total)
N = int(input()) S = [""]*N Dict={} ac=0 wa =0 tle =0 re=0 for i in range(N): S[i] = str(input()) for j in S: if j in Dict: temp = Dict[j] Dict[j] = temp + 1 else: Dict[j] = 1 if "AC" in Dict: ac = Dict["AC"] if "WA" in Dict: wa = Dict["WA"] if "TLE" in Dict: tle = Dict["TLE"] if "RE" in Dict: re = Dict["RE"] print("AC x " , ac) print("WA x " , wa) print("TLE x " , tle) print("RE x " , re)
0
null
22,355,954,414,230
175
109
S = input() N = int(input()) line = [''] * (N+1) * 2 rev = False pos = N line[pos] = S leftPos = pos - 1 rightPos = pos + 1 for i in range(N): A = input().split() if len(A) == 1: rev = not rev else: if A[1] == '1': if rev == False: pos = leftPos leftPos -= 1 else: pos = rightPos rightPos += 1 else: if rev == False: pos = rightPos rightPos += 1 else: pos = leftPos leftPos -= 1 line[pos] = A[2] ans = line[leftPos+1:rightPos] ans = "".join(ans) if rev == False: print(ans) else: print(ans[::-1])
if __name__ == '__main__': key_in = input() data = key_in.split(' ') a = int(data[0]) b = int(data[1]) c = int(data[2]) if a < b < c: print('Yes') else: print('No')
0
null
29,039,336,642,612
204
39
#coding: utf-8 while True: m, f, r = (int(i) for i in input().split()) if m == f == r == -1: break if m == -1 or f == -1: print("F") elif m + f >= 80: print("A") elif m + f >= 65 and m + f < 80: print("B") elif (m + f >= 50 and m + f < 65) or r >= 50: print("C") elif m + f >= 30 and m + f < 50: print("D") elif m + f < 30: print("F")
N = input() if N.count('7') > 0: print("Yes") else: print('No')
0
null
17,772,572,542,880
57
172
from copy import copy import random import math import sys input = sys.stdin.readline D = int(input()) c = list(map(int,input().split())) s = [list(map(int,input().split())) for _ in range(D)] last = [0]*26 ans = [0]*D score = 0 for i in range(D): ps = [0]*26 for j in range(26): pl = copy(last) pl[j] = i+1 ps[j] += s[i][j] for k in range(26): ps[j] -= c[k]*(i+1-pl[k]) idx = ps.index(max(ps)) last[idx] = i+1 ans[i] = idx+1 score += max(ps) for k in range(1,35001): na = copy(ans) x = random.randint(1,365) y = random.randint(1,365) z = random.randint(min(x,y),max(x,y)) na[y-1] = na[x-1] na[y-1] = na[z-1] last = [0]*26 ns = 0 for i in range(D): last[na[i]-1] = i+1 ns += s[i][na[i]-1] for j in range(26): ns -= c[j]*(i+1-last[j]) if k%100 == 1: T = 300-(298*k/40000) p = pow(math.e,-abs(ns-score)/T) if ns > score or random.random() < p: ans = na score = ns for a in ans: print(a)
d = int(input()) *C, = map(int, input().split()) S = [list(map(int, input().split())) for i in range(d)] X = [] L = [-1 for j in range(26)] for i in range(d): max_diff = -10**10 best_j = 0 for j in range(26): memo = L[j] L[j] = i diff = S[i][j] - sum([C[jj] * (i - L[jj]) for jj in range(26)]) if diff > max_diff: max_diff = diff best_j = j L[j] = memo L[best_j] = i X.append(best_j) for x in X: print(x + 1)
1
9,717,207,187,082
null
113
113
n=int(input()) S=[int(i) for i in input().split()] q=int(input()) T=[int(i) for i in input().split()] s=0 for i in range(q): if T[i] in S: s+=1 print(s)
#---------------for input-------------------- numberN=int(input()) arrayS=list(map(int,input().split())) numberQ=int(input()) arrayT=list(map(int,input().split())) #---------------for input---------------------- def linearSearch(arrayS,arrayT,numberQ): machedNumber=0 index=0 while index<numberQ: if arrayT[index] in arrayS: machedNumber+=1 index+=1 print(machedNumber) #----------------for main------------------------ linearSearch(arrayS,arrayT,numberQ) #----------------for main------------------------
1
67,012,181,040
null
22
22
D = int(input()) for i in range(D): print(i%26+1)
from collections import namedtuple Card = namedtuple('Card', 'suit value') def BubbleSort(C): for i in range(len(C)): for j in range(len(C)-1,i,-1): if C[j].value < C[j-1].value: C[j],C[j-1] = C[j-1],C[j] def SelectionSort(C): for i in range(len(C)): mini = i for j in range(i,len(C)): if C[j].value < C[mini].value: mini = j C[i],C[mini] = C[mini],C[i] def checkStable(C0, C1): result = True for i in range(1,10): f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))] f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))] if f0!=f1: result = False return result if __name__=='__main__': N = int(input()) Co = list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split()))) Cb,Cs = [Co[:] for _ in range(2)] for C, Sort in zip([Cb,Cs], [BubbleSort, SelectionSort]): Sort(C) print(*["".join([X.suit,str(X.value)]) for X in C]) print("Stable" if checkStable(Co,C) else "Not stable")
0
null
4,850,807,842,716
113
16
def main(): n = input() if n[0] == '7': print("Yes") return if n[1] == '7': print("Yes") return if n[2] == '7': print("Yes") return print("No") if __name__ == "__main__": main()
n=int(input()) if n%10==7: print("Yes") exit() n//=10 if n%10==7: print("Yes") exit() n//=10 if n%10==7: print("Yes") exit() print("No")
1
34,415,187,757,148
null
172
172
N=int(input()) S=input() l=len(S) a='' for i in range(l): if ord(S[i])+N>90: a+=chr(ord(S[i])+N-26) else: a+=chr(ord(S[i])+N) print(a)
def main(): N = int(input()) S = str(input()) ans = '' alphabet = ['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'] for i in range(len(S)): c = alphabet.index(S[i]) + N if c > 25: c = c - 26 ans = ans + alphabet[c] print(ans) main()
1
134,932,760,355,172
null
271
271
import sys input = sys.stdin.buffer.readline import math n = int(input()) mod = 1000000007 AB = [] for i in range(n): a, b = map(int, input().split()) AB.append((a, b)) def power(a, n, mod): bi=str(format(n,"b")) #2進数 res=1 for i in range(len(bi)): res=(res*res) %mod if bi[i]=="1": res=(res*a) %mod return res def toid(a, b): flag = False if a == 0 and b == 0: return (0, 0) elif a == 0: return (0, 1) elif b == 0: return (1, 0) else: if a > 0 and b > 0: g = math.gcd(a, b) a //= g b //= g elif a > 0 and b < 0: b = -b g = math.gcd(a, b) a //= g b //= g b = -b elif a < 0 and b > 0: a = -a g = math.gcd(a, b) a //= g b //= g b = -b else: a = -a b = -b g = math.gcd(a, b) a //= g b //= g return (a, b) def totg(a, b): if a == 0 and b == 0: return (0, 0) elif a == 0: return (1, 0) elif b == 0: return (0, 1) else: if a > 0 and b > 0: g = math.gcd(a, b) a //= g b //= g t = (b, -a) elif a > 0 and b < 0: b = -b g = math.gcd(a, b) a //= g b //= g b = -b t = (-b, a) elif a < 0 and b > 0: a = -a g = math.gcd(a, b) a //= g b //= g a = -a t = (b, -a) else: a = -a b = -b g = math.gcd(a, b) a //= g b //= g a = -a b = -b t = (-b, a) return t d = {} ans = 0 for i in range(n): a, b = AB[i] s = toid(a, b) if s not in d: d[s] = 1 else: d[s] += 1 ans = 1 used = set() for k1, v1 in d.items(): if k1 in used: continue if k1 == (0, 0): continue a, b = k1 k2 = totg(a, b) if k2 in d: v2 = d[k2] else: v2 = 0 temp = power(2, v1, mod)-1+power(2, v2, mod)-1+1 ans *= temp ans %= mod used.add(k1) used.add(k2) ans -= 1 if (0, 0) in d: ans += d[(0, 0)] print(ans%mod)
import math from collections import defaultdict n = int(input()) p = defaultdict(int) mod = 10 ** 9 + 7 ori = 0 for _ in range(n): a,b = map(int,input().split()) if a == b == 0: ori += 1 continue elif b < 0: a *= -1 b *= -1 elif b == 0 and a < 0: a *= -1 if a == 0: p[(0,1)] += 1 elif b == 0: p[(1,0)] += 1 else: g = math.gcd(a,b) p[(a//g, b//g)] += 1 k = n - ori ans = ori-1 tmp = 1 l = k for q,num in sorted(p.items(), reverse=True): x,y = q if x <= 0: break if p[(-y, x)] >= 1: a,b = p[(x,y)], p[(-y, x)] tmp *= pow(2,a,mod) + pow(2,b,mod) - 1 l -= a+b tmp *= pow(2,l,mod) print((ans+tmp) % mod)
1
20,968,121,186,322
null
146
146
#AIsing2020 d def f(n): cnt = 0 while n: cnt+= 1 n = n%bin(n).count('1') return cnt def main(): N = int(input()) X = input() X10 = int(X,2) X10_num1 = X.count('1') X10_pulse = X10%(X10_num1+1) X10_ninus = X10%(X10_num1-1) if X10_num1 >1 else 0 for i in range(N,0,-1): if (X10>>(i-1) & 1) and X10_num1 >1: mod = X10_num1-1 amari = (X10_ninus - pow(2,i-1,mod))%(mod) elif (X10>>(i-1) & 1) and X10_num1 ==1: print(0) continue else: mod = X10_num1+1 amari = (X10_pulse + pow(2,i-1,mod))%(mod) print(1+f(amari)) main()
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list(map(lambda x: int(x)-1, input().split())) def II(): return int(input()) def IF(): return float(input()) def S(): return input().rstrip() def LS(): return S().split() def IR(n): res = [None] * n for i in range(n): res[i] = II() return res def LIR(n): res = [None] * n for i in range(n): res[i] = LI() return res def FR(n): res = [None] * n for i in range(n): res[i] = IF() return res def LIR(n): res = [None] * n for i in range(n): res[i] = IF() return res def LIR_(n): res = [None] * n for i in range(n): res[i] = LI_() return res def SR(n): res = [None] * n for i in range(n): res[i] = S() return res def LSR(n): res = [None] * n for i in range(n): res[i] = LS() return res mod = 1000000007 inf = float('INF') #solve def solve(): def f(n, c): tmp = n % c t = tmp b = 0 while tmp: if tmp & 1: b += 1 tmp //= 2 if t: return f(t, b) + 1 else: return 1 n = II() a = S() b = 0 for ai in a: if ai == "1": b += 1 a = a[::-1] bp = 0 bm = 0 if b != 1: for i, ai in enumerate(a): if ai == "1": bp += pow(2, i, b + 1) bm += pow(2, i, b - 1) bp %= b + 1 bm %= b - 1 ans = [] for i, ai in enumerate(a): if ai == "1": tmpbm = bm - pow(2, i, b - 1) tmpbm %= b - 1 ans.append(f(tmpbm, b - 1)) else: tmpbp = bp + pow(2, i, b + 1) tmpbp %= b + 1 ans.append(f(tmpbp, b + 1)) for ai in ans[::-1]: print(ai) return else: for i, ai in enumerate(a): if ai == "1": bp += pow(2, i, b + 1) bp %= b + 1 ans = [] for i, ai in enumerate(a): if ai == "1": ans.append(0) else: tmpbp = bp + pow(2, i, b + 1) tmpbp %= b + 1 ans.append(f(tmpbp, b + 1)) for ai in ans[::-1]: print(ai) return #main if __name__ == '__main__': solve()
1
8,186,692,609,160
null
107
107
N = int(input()) A = list(map(int, input().split())) flag = True A = sorted(A) for i in range(N-1): if A[i] == A[i+1]: flag = False if flag: print("YES") else: print("NO")
N = int(input()) A_ls = input().split(' ') A_set = { i for i in A_ls } if len(A_set) == N: print('YES') else: print('NO')
1
73,832,125,634,058
null
222
222
import numpy as np from numba import jit R, C, K = map(int, input().split()) G = np.zeros((R+1, C+1), np.int64) for i in range(K): [r, c, v] = list(map(int, input().split())) G[r-1][c-1] = v @jit def main(G, R, C): dp = np.full((R+1, C+1, 4), -1) dp[0][0][0] = 0 if G[0][0] != None: dp[0][0][1] = G[0][0] for r in range(R): for c in range(C): for k in range(4): if dp[r][c][k] == -1: continue if k < 3: # can go right and pick up if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]: dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1] if dp[r][c+1][k] < dp[r][c][k]: dp[r][c+1][k] = dp[r][c][k] if dp[r+1][c][0] < dp[r][c][k]: dp[r+1][c][0] = dp[r][c][k] if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]: dp[r+1][c][1] = dp[r][c][k] + G[r+1][c] return(max(dp[r][c])) ret = main(G, R, C) print(ret)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from heapq import heappush, heappop from functools import reduce from decimal import Decimal, ROUND_CEILING def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 R, C, K = MAP() dp1 = [[0]*4 for _ in range(C+1)] dp2 = [[0]*4 for _ in range(C+1)] field = [[0]*(C+1)] + [[0]*(C+1) for _ in range(R)] for _ in range(K): r, c, v = MAP() field[r][c] = v for i in range(1, R+1): for j in range(1, C+1): if i%2 == 0: up_max = max(dp1[j]) p = field[i][j] dp2[j][0] = max(up_max, dp1[j-1][0]) dp2[j][1] = max(up_max+p, dp2[j-1][1], dp2[j-1][0]+p) dp2[j][2] = max(dp2[j-1][2], dp2[j-1][1]+p) dp2[j][3] = max(dp2[j-1][3], dp2[j-1][2]+p) else: up_max = max(dp2[j]) p = field[i][j] dp1[j][0] = max(up_max, dp2[j-1][0]) dp1[j][1] = max(up_max+p, dp1[j-1][1], dp1[j-1][0]+p) dp1[j][2] = max(dp1[j-1][2], dp1[j-1][1]+p) dp1[j][3] = max(dp1[j-1][3], dp1[j-1][2]+p) a = max(dp1[-1]) b = max(dp2[-1]) print(max(a, b))
1
5,601,188,543,538
null
94
94
R, C, K, *RCV = [int(_) for _ in open(0).read().split()] RCV = sorted([(r, -c, v) for r, c, v in zip(RCV[::3], RCV[1::3], RCV[2::3])]) class SegmentTree(): def __init__(self, array, f, ti): """ Parameters ---------- array : list to construct segment tree from f : func binary operation of the monoid ti : identity element of the monoid """ self.f = f self.ti = ti self.n = n = 2**(len(array).bit_length()) self.dat = dat = [ti] * n + array + [ti] * (n - len(array)) for i in range(n - 1, 0, -1): # build dat[i] = f(dat[i << 1], dat[i << 1 | 1]) def update(self, p, v): # set value at position p (0-indexed) f, n, dat = self.f, self.n, self.dat p += n dat[p] = v while p > 1: p >>= 1 dat[p] = f(dat[p << 1], dat[p << 1 | 1]) def operate_right(self, p, v): # apply operator from the right side f, n, dat = self.f, self.n, self.dat p += n dat[p] = f(dat[p], v) while p > 1: p >>= 1 dat[p] = f(dat[p << 1], dat[p << 1 | 1]) def operate_left(self, p, v): # apply operator from the left side f, n, dat = self.f, self.n, self.dat p += n dat[p] = f(v, dat[p]) while p > 1: p >>= 1 dat[p] = f(dat[p << 1], dat[p << 1 | 1]) def query(self, l, r): # result on interval [l, r) (0-indexed) f, ti, n, dat = self.f, self.ti, self.n, self.dat vl = vr = ti l += n r += n while l < r: if l & 1: vl = f(vl, dat[l]) l += 1 if r & 1: r -= 1 vr = f(dat[r], vr) l >>= 1 r >>= 1 return f(vl, vr) dp1 = SegmentTree([0] * (C + 1), max, -1) dp2 = SegmentTree([0] * (C + 1), max, -1) dp3 = SegmentTree([0] * (C + 1), max, -1) rnow = 0 rcv = {} for r, c, v in RCV: if rnow != r: rnow = r rcv[r] = [] rcv[r] += [(-c, v)] for r in sorted(rcv.keys()): cv = rcv[r] for c, v in cv: dp1.update(c, dp3.query(0, c + 1) + v) for c, v in cv: dp2.update(c, max(dp1.query(c, c + 1), dp1.query(0, c) + v)) for c, v in cv: dp3.update(c, max(dp2.query(c, c + 1), dp2.query(0, c) + v)) ans = dp3.query(0, C + 1) print(ans)
n, d = map(int, input().split()) A = [] for i in range(n): A_i = list(map(int, input().split())) A.append(A_i) ans = 0 for j in A: if (j[0] ** 2 + j[1] ** 2) <= d **2 : ans += 1 print(ans)
0
null
5,693,300,969,438
94
96
N = int(input()) cnt = [0]*4 judge = ["AC","WA","TLE","RE"] for i in range(N): s = input() if s=="AC": cnt[0]+=1 elif s=="WA": cnt[1]+=1 elif s=="TLE": cnt[2]+=1 else: cnt[3]+=1 for i in range(4): print(judge[i],"x",cnt[i])
N = int(input()) lst = input().split() count = 0 for i in range(N): if (i + 1) % 2 == 1 and int(lst[i]) % 2 == 1: count += 1 print(count)
0
null
8,215,705,084,832
109
105
input() print(*reversed([int(e) for e in input().split()]))
n = input() a = map(int, raw_input(). split()) while n != 0: print(a[n-1]), n-=1
1
994,601,551,360
null
53
53
N, M = list(map(int, input().split())) H = list(map(int, input().split())) good = [True]*N for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 if H[a] >= H[b]: good[b] = False if H[a] <= H[b]: good[a] = False print(good.count(True))
import sys def input(): return sys.stdin.readline()[:-1] def main(): N = int(input()) A = list(map(int,input().split())) zougen = [-1 if A[i] > A[i + 1] else 1 for i in range(N - 1)] money = 1000 kabu = 0 for i in range(N-1): if zougen[i] == 1: kabu += money // A[i] money = money % A[i] else: money += kabu * A[i] kabu = 0 print(A[-1] * kabu + money) if __name__ == "__main__": main()
0
null
16,205,624,180,200
155
103
kuku = [] for i in range(1,10): for j in range(1,10): if i * j not in kuku: kuku.append(i*j) n = int(input()) if n in kuku: print('Yes') else: print('No')
import math N=int(input()) ARR=[0]*(N+1) for x in range(1,101): for y in range(1,101): for z in range(1,101): res=x**2+y**2+z**2+x*y+y*z+z*x if res<=N: ARR[res]+=1 for i in ARR[1:]: print(i)
0
null
83,998,829,589,312
287
106
a,s=0,input().lower() while(True): t = input().split() if t[0] == "END_OF_TEXT": print(a) quit() for i in t: if i.lower() == s: a += 1
import sys BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 P = str(input()).upper() line = [] while True: tmp_line = str(input()) if tmp_line == 'END_OF_TEXT': break line += tmp_line.upper().split() ans = 0 for tmp_word in line: if tmp_word == P: ans += 1 print("%d"%(ans))
1
1,833,863,652,430
null
65
65
L = int(input()) a = float(L/3) b = float(L/3) c = float(L / 3) print(a * b * c)
n = int(input())/3 print(n*n*n)
1
46,696,586,860,856
null
191
191
#! /usr/bin/env python3 noOfInputs = int(input()) for i in range(noOfInputs): numsInStr = input().split() nums = [] for n in numsInStr: nums.append(int(n)) largest = max(nums) nums.remove(max(nums)) #print(nums) if (largest**2 == sum([i**2 for i in nums])): print('YES') else: print('NO')
n = input() for i in xrange(n): li = map(int, raw_input().split()) li.sort() if li[0]**2 + li[1]**2 == li[2]**2: print "YES" else: print "NO"
1
281,361,200
null
4
4
n, k = map(int, input().split(' ')) h = list(map(int, input().split(' '))) ans = 0 for i in h: if i >= k: ans += 1 print(ans)
n, k = map(int, input().split()) list01 = input().split() list02 = [int(a) for a in list01] x = 0 for i in list02: if i >= k: x += 1 else: pass print(x)
1
179,187,335,265,876
null
298
298
s = input().strip() buf = s[0] count = 0 popa = [] suma = 0 for i in s: if i=="<": count+=1 suma += count elif i==">" and buf=="<": popa.append(count) suma -= count count = 0 buf = i buf = s[-1] count = 0 dupa = [] for i in s[::-1]: if i==">": count+=1 suma += count elif i=="<" and buf==">": dupa.append(count) suma -= count count = 0 buf = i for i,j in zip(dupa[::-1],popa): suma+=max(i,j) print(suma) # print(sum(map(int,"0 3 2 1 0 1 2 0 1 2 3 4 5 2 1 0 1".split())))
s = list(input()) al = [0]*(len(s)+1) for i in range(len(s)): if s[i] == '<': al[i+1] = max(al[i]+1, al[i+1]) for i in range(len(s)-1, -1, -1): if s[i] == '>': al[i] = max(al[i+1]+1, al[i]) print(sum(al))
1
156,844,170,092,374
null
285
285
n=int(input()) ans="No" for i in range(10): for j in range(10): if n==i*j: ans="Yes" print(ans)
import sys def solve(): input = sys.stdin.readline N = int(input()) P = [input().strip("\n").split() for _ in range(N)] X = input().strip("\n") sec = 0 lastId = 0 for i in range(N): if P[i][0] == X: lastId = i break for i in range(lastId + 1, N): sec += int(P[i][1]) print(sec) return 0 if __name__ == "__main__": solve()
0
null
128,434,327,860,670
287
243
L = int(input()) a = L/3 m = a*a*a print(m)
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline import itertools def main(): n = int(input()) k = n / 3 print(k**3) if __name__=="__main__": main()
1
46,863,627,929,172
null
191
191
N = int(input()) l = list(map(int,input().split())) ans = [i for i in range(len(l))] for i in range(N): ans[l[i] - 1] = i + 1 print(*ans)
N=int(input()) L=list(map(int,input().split())) S=[0]*N c=1 for i in L: S[i-1]=c c+=1 for i in range(N): print(S[i],end=' ')
1
181,061,893,712,128
null
299
299
import math a = float(input()) b = math.acos(-1) print "%f %f" % (a * a * b , 2 * a * b)
import math r = float(input()) print('%.6f %.6f' %(math.pi*r**2, math.pi*2*r))
1
638,374,691,068
null
46
46
input_line = input().split() a = int(input_line[0]) b = int(input_line[1]) if a > b: symbol = ">" elif a < b: symbol = "<" else: symbol = "==" print("a",symbol,"b")
#coding: UTF-8 def SLE(a,b): if a > b: return "a > b" elif a < b: return "a < b" else: return "a == b" if __name__=="__main__": a = input().split(" ") ans = SLE(int(a[0]),int(a[1])) print(ans)
1
369,510,507,492
null
38
38
#! /usr/bin/env python3 import sys sys.setrecursionlimit(10**9) INF=10**20 def solve(N: int, K: int, P: "List[int]", C: "List[int]"): ans = -INF for i in range(N): start = i + 1 stack = [start] score_his = [0] scores = 0 depth = 1 seen = {} while stack: if depth > K: break current = stack.pop() if current in seen: loop_start_depth = seen[current] loop_end_depth = depth - 1 loop_scores = score_his[-1] - score_his[loop_start_depth-1] loop_len = loop_end_depth - loop_start_depth + 1 if loop_scores < 0: break # print(start,score_his) # print(loop_start_depth,loop_end_depth,loop_scores,loop_len) rest_count = K - depth + 1 available_loop_count = rest_count // loop_len res1 = (available_loop_count-1) * loop_scores + scores # print("a",rest_count,available_loop_count,res1) res2 = res1 rest_loop_len = rest_count % loop_len + loop_len # print("b",rest_loop_len) ress = [res1,res2] for j in range(rest_loop_len): score = C[P[current-1]-1] res2 += score ress.append(res2) current = P[current-1] # print("ress",ress) score_his.append(max(ress)) break score = C[P[current-1]-1] scores += score score_his.append(scores) seen[current] = depth stack.append(P[current-1]) depth += 1 ans = max(ans,max(score_his[1:])) print(ans) 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 K = int(next(tokens)) # type: int P = [int(next(tokens)) for _ in range(N)] # type: "List[int]" C = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, K, P, C) if __name__ == "__main__": main()
import sys import resource sys.setrecursionlimit(10000) n,k=map(int,input().rstrip().split()) p=list(map(int,input().rstrip().split())) c=list(map(int,input().rstrip().split())) def find(start,now,up,max,sum,count,flag): if start==now: flag+=1 if start==now and flag==2: return [max,sum,count] elif count==up: return [max,sum,count] else: count+=1 sum+=c[p[now-1]-1] if max<sum: max=sum return find(start,p[now-1],up,max,sum,count,flag) kara=[-10000000000] for i in range(1,n+1): m=find(i,i,n,c[p[i-1]-1],0,0,0) if m[2]>=k: m=find(i,i,k,c[p[i-1]-1],0,0,0) if m[0]>kara[0]: kara[0]=m[0] result=kara[0] elif m[1]<=0: if m[0]>kara[0]: kara[0]=m[0] result=kara[0] else: w=k%m[2] if w==0: w=m[2] spe=find(i,i,w,c[p[i-1]-1],0,0,0)[0] if m[1]+spe>m[0] and m[1]*(k-w)//m[2]+spe>kara[0]: kara[0]=m[1]*(k-w)//m[2]+spe elif m[1]+spe<=m[0] and m[1]*((k-w)//m[2]-1)+m[0]>kara[0]: kara[0]=m[1]*((k-w)//m[2]-1)+m[0] result=kara[0] print(result)
1
5,424,158,899,512
null
93
93
n=int(input()) s=[n-1] for i in range(2,n): s.append((n-1)//i) t=0 for j in s: t+=j print(t)
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print('\n'.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) n = readint() ans = 0 for a in range(1,n): b = n//a if a*b==n: ans += b-1 else: ans += b print(ans)
1
2,546,112,207,872
null
73
73
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")
from itertools import tee print( ' '.join( map(str, map(lambda f, ns: f(ns), (min, max, sum), (lambda m: tee(m, 3))( map(int, (lambda _, line: line.split())( input(), input())))))))
0
null
23,424,148,249,980
190
48
a,b,c = map(int, input().split()) print("Yes") if b * c >= a else print("No")
def main(): d, t, s = map(int, input().split()) if d <= (t*s): ans = 'Yes' else: ans = 'No' print(ans) if __name__ == "__main__": main()
1
3,592,990,214,060
null
81
81
def input_int(): return map(int, input().split()) def one_int(): return int(input()) def one_str(): return input() def many_int(): return list(map(int, input().split())) import math from decimal import Decimal A, B = input().split() # A=int(A) # B=float(B) temp = Decimal(A)*Decimal(B) print(int(math.floor(temp)))
from decimal import * import math a, b = map(str, input().split()) print(math.floor(Decimal(a)*Decimal(b)))
1
16,665,419,690,608
null
135
135
x, y = [int(x) for x in input().split()] def gcd(a, b): m = a%b return gcd(b, m) if m else b print(gcd(x, y))
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import itertools import math import sys INF = float('inf') YES = "Yes" # type: str NO = "No" # type: str def solve(N: int, M: int, A: "List[int]"): t = sum(A)/4/M return [YES, NO][len([a for a in A if a >= t]) < M] def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" print(f'{solve(N, M, A)}') if __name__ == '__main__': main()
0
null
19,343,923,579,300
11
179
N = int(input()) if(N > 81): print("No") else: state='No' for i in range(1,10): for j in range(1,10): if(i*j == N): state='Yes' break if(i*j > N): break print(state)
n = int(input()) def binary_search(l, target): left = 0 right = len(l) while left<right: mid = (left+right)//2 if target == l[mid]: return True elif target < l[mid]: right = mid else: left = mid+1 return False seki = [i*j for i in range(1, 10) for j in range(1, 10)] seki.sort() if binary_search(seki, n): print('Yes') else: print('No')
1
159,914,878,882,618
null
287
287
n = int(input()) songs = [] for _ in range(n): s, t = input().split() t = int(t) songs.append((s, t)) x = input() ans = 0 flag = False for s, t in songs: if flag: ans += t if s == x: flag = True print(ans)
N=int(input()) music=[] T=[] ans=0 for i in range(N): s, t=input().split() t=int(t) music.append(s) T.append(t) X=input() num=music.index(X) for j in range(num+1, N): ans+=T[j] print(ans)
1
96,967,503,792,992
null
243
243
a = [] for i in range(10000): a.append(int(input())) if a[i] == 0: break print("Case {}: {}".format(i+1,a[i]))
N,K = map(int,input().split()) import numpy as np A = np.array(input().split(),np.int64) B = np.array(input().split(),np.int64) A.sort() ; B.sort() B=B[::-1] right = max(A*B) #時間の可能集合の端点 left = -1 #時間の不可能集合の端点 def test(t): C = A-t//B D= np.where(C<0,0,C) return D.sum()<=K while left+1<right: mid = (left+right)//2 if test(mid): right=mid else: left = mid print(right)
0
null
82,645,773,781,012
42
290
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()) P = list(map(int,input().split())) S={} ans="YES" for p in P: if p in S: ans = "NO" break else: S[p]=1 print(ans)
1
73,586,332,059,680
null
222
222
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float("inf") def solve(N: int, M: int, p: "List[int]", S: "List[str]"): ac = [0 for _ in range(N)] for i in set(x[0] for x in zip(p, S) if x[1] == "AC"): ac[i - 1] = 1 wa = 0 for x in zip(p, S): ac[x[0] - 1] &= x[1] == "WA" wa += ac[x[0] - 1] return f'{len(set(x[0] for x in zip(p,S) if x[1] == "AC"))} {wa}' def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int p = [int()] * (M) # type: "List[int]" S = [str()] * (M) # type: "List[str]" for i in range(M): p[i] = int(next(tokens)) S[i] = next(tokens) print(f"{solve(N, M, p, S)}") if __name__ == "__main__": main()
def get_sieve_of_eratosthenes(n): import math if not isinstance(n, int): raise TypeError('n is int type.') if n < 2: raise ValueError('n is more than 2') prime = [] limit = math.sqrt(n) data = [i + 1 for i in range(1, n)] while True: p = data[0] if limit <= p: return prime + data prime.append(p) data = [e for e in data if e % p != 0] def abc149c_next_prime(): import bisect x = int(input()) list = get_sieve_of_eratosthenes(100003) idx = bisect.bisect_left(list, x) print(list[idx]) abc149c_next_prime()
0
null
99,429,509,531,236
240
250
def power_set(A, s): if len(A) == 0: return {s} else: return power_set(A[1:], s) | power_set(A[1:], s+A[0]) def main(): n = int(input()) A = input() #print(n) A = list(map(int, A.split())) q = int(input()) m = input() ms = list(map(int, m.split())) powerset = power_set(A, 0) for m in ms: if m in powerset: print('yes') else: print('no') if __name__ == '__main__': main()
class MyClass(): def main(self): self.n = input() self.A = map(int,raw_input().split()) self.q = input() self.M = map(int,raw_input().split()) W = map(self.solve,self.M) for w in W: print w def solve(self,m): w = self.rec(m,self.A) if w: return "yes" else: return "no" def rec(self,m,A): if len(A) == 1: r1 = False else: r1 = self.rec(m,A[1:]) m_new = m - A[0] if m_new == 0: r2 = True elif len(A) > 1 and min(A[1:]) <= m_new <= sum(A[1:]): r2 = self.rec(m_new,A[1:]) else: r2 = False if r1 or r2: return True else: return False if __name__ == "__main__": MC = MyClass() MC.main()
1
99,550,289,090
null
25
25
N = int(input()) X_list = list(map(int, input().split())) X_list_min = sorted(X_list) ans = 10**8+1 for i in range(X_list_min[0], X_list_min[-1]+1): ans_temp = 0 for j in range(N): ans_temp += (X_list_min[j] - i)**2 ans = min(ans, ans_temp) print(ans)
suits = ['S', 'H', 'C', 'D'] table = [[False] * 14 for i in range(4)] N = int(input()) for _i in range(N): mark, num = input().split() num = int(num) if mark == 'S': table[0][num] = True if mark == 'H': table[1][num] = True if mark == 'C': table[2][num] = True if mark == 'D': table[3][num] = True for i in range(4): for j in range(1, 14): if not table[i][j]: print(f'{suits[i]} {j}')
0
null
32,943,604,097,150
213
54
a = list(map(int, input().split())) s = a[0] + a[1] + a[2] if s >= 22: print('bust') else: print('win')
#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,permutations,accumulate # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入 import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(input()) n,m = readInts() base = [] if n == 1 and m == 0: print(0) exit() elif n == 2 and m == 0: print(10) exit() elif n == 3 and m == 0: print(100) exit() if n >= 1: base.append('1') if n >= 2: base.append('0') if n == 3: base.append('0') dic = defaultdict(int) for i in range(m): s,c = readInts() s -= 1 if dic[s] != 0: if int(base[s]) == c: pass else: print(-1) exit() else: dic[s] = 1 base[s] = str(c) if s == 0 and c == 0 and n >= 2: print(-1) exit() print(*base,sep='')
0
null
89,779,246,225,340
260
208
def resolve(): n, m = list(map(int, input().split())) print('Yes' if n == m else 'No') resolve()
a,b,c = list(map(int,input().split())) k = int(input()) cnt = 0 while not a < b: b*=2 cnt+=1 while not b < c: c*=2 cnt+=1 #print('cnt:',cnt,'k:',k) print('Yes' if cnt <=k else 'No')
0
null
45,253,488,310,768
231
101
N = int(input()) S = list(input()) print("".join(chr(65+(ord(s)-65+N)%26) for s in S))
n = int(input()) s = input() for i in s: i = ord(i) + n if (i > 90): d = i - 90 print(chr(64+d),end = '') else: print(chr(i),end = '')
1
134,580,167,784,672
null
271
271
#! python3 # greatest_common_divisor.py def greatest_common_divisor(x, y): r = None if x >= y: r = x%y if r == 0: return y else: r = y%x if r == 0: return x return greatest_common_divisor(y, r) x, y = [int(n) for n in input().split(' ')] print(greatest_common_divisor(x, y))
a=map(int,raw_input().split()) a.sort() while a[1]%a[0]!=0: a[0],a[1]=a[1]%a[0],a[0] print(a[0])
1
8,090,458,308
null
11
11
a,b,c=map(int,input().split());print('YNeos'[a/b>c::2])
def chess(h,w): o = "" for i in range(h): if i%2: if w%2: o+= ".#"*(w/2)+".\n" else: o+= ".#"*(w/2)+"\n" else: if w%2: o+= "#."*(w/2)+"#\n" else: o+= "#."*(w/2)+"\n" print o while 1: h,w=map(int,raw_input().split()) if h==w==0:break chess(h,w)
0
null
2,236,726,159,886
81
51
# -*- coding: utf-8 -*- # A import sys from collections import defaultdict, deque from heapq import heappush, heappop import math import bisect input = sys.stdin.readline # 再起回数上限変更 # sys.setrecursionlimit(1000000) N = int(input()) if N % 2 == 0: print(0.5) else: a = N//2 b = N - a print(b/N)
s = input().split('S') m = 0 for i in s: if len(i) > m: m = len(i) print(m)
0
null
91,283,200,472,772
297
90
n = int(input()) a = list(map(int, input().split())) ans = 0 for x in a[::2]: ans += x % 2 print(ans)
N = int(input()) S, T = input().split() answer = [] for s, t in zip(S, T): answer.append(s) answer.append(t) print(*answer, sep='')
0
null
60,280,948,806,948
105
255
""" 9 5 -4 -3 -2 -1 0 1 2 3 """ N,K = map(int,input().split()) A = list(map(int,input().split())) A.sort() Am = [] Ap = [] for a in A: if a < 0: Am.append(a) else: Ap.append(a) mod = 10**9 + 7 ans = 1 if N == K: for a in A: ans *= a ans %= mod elif A[-1] < 0: if K % 2 == 1: for i in range(K): ans *= Am[-1-i] ans %= mod else: for i in range(K): ans *= Am[i] ans %= mod else: if K%2 == 1: ans *= Ap[-1] ans %= mod K -= 1 del Ap[-1] Amd = [] Apd = [] for i in range(len(Ap)//2): Apd.append(Ap[-1-(2*i)]*Ap[-1-(2*i+1)]) for i in range(len(Am)//2): Amd.append(Am[2*i]*Am[2*i+1]) Apd.append(-1) Amd.append(-1) ip = 0 im = 0 while K > 0: if Apd[ip] >= Amd[im]: ans *= Apd[ip] ip += 1 else: ans *= Amd[im] im += 1 ans %= mod K -= 2 ans %= mod print(ans)
from collections import deque n , k = map(int,input().split()) a = list(map(int,input().split())) mod = 10**9 + 7 ans = 1 plus = [] minus = [] if n == k: for i in range(n): ans *= a[i] ans %= mod print(ans) exit() for i in range(n): if a[i] >= 0: plus.append(a[i]) elif a[i] < 0: minus.append(a[i]) if not plus and k % 2 == 1: minus.sort(reverse=True) for i in range(k): ans *= minus[i] ans %= mod print(ans) exit() plus.sort(reverse=True) minus.sort() plus = deque(plus) minus = deque(minus) cou = [] while True: if len(cou) == k: break elif len(cou) == k-1: cou.append(plus.popleft()) break else: if len(plus)>=2 and len(minus)>=2: p1 = plus.popleft() p2 = plus.popleft() m1 = minus.popleft() m2 = minus.popleft() if p1*p2 > m1*m2: cou.append(p1) plus.appendleft(p2) minus.appendleft(m2) minus.appendleft(m1) else: cou.append(m1) cou.append(m2) plus.appendleft(p2) plus.appendleft(p1) elif len(plus) < 2: m1 = minus.popleft() m2 = minus.popleft() cou.append(m1) cou.append(m2) elif len(minus) < 2: p1 = plus.popleft() cou.append(p1) for i in cou: ans *= i ans %= mod print(ans)
1
9,444,491,523,370
null
112
112
n = int(input()) a = list(map(int,input().split())) if len(set(a)) == n: print('YES') else: print('NO')
#154_C def has_duplicates(seq): return len(seq) != len(set(seq)) n = int(input()) a = list(map(int, input().split())) if has_duplicates(a): print('NO') else: print('YES')
1
73,892,605,803,744
null
222
222
def main(): n = int(input()) a = list(map(int, input().split())) a.append(-1) num_kabu = 0 money = 1000 for i in range(0, n): if a[i+1] >= a[i]: num_kabu += money//a[i] money %= a[i] if a[i+1] <a[i]: money += num_kabu*a[i] num_kabu = 0 print(money) if __name__ =="__main__": main()
N = int(input()) A = list(map(int,input().split())) # for i in range(N): # A[i] = int(i) cMoney = 1000 stock = 0 A.append(0) for i in range(N): stock = 0 if A[i] < A[i+1]: stock = cMoney // A[i] cMoney -= stock * A[i] cMoney += A[i+1] * stock print(cMoney) # for i in range(N): # stock = 0 # if A[i] < A[i+1]: # stock = cMoney // A[i] # cMoney += (A[i+1] - A[i]) * stock # print(cMoney)
1
7,279,659,709,140
null
103
103
import sys input=sys.stdin.readline N,M,L=map(int,input().split()) def warshall_floyd(d): #d[i][j]: iからjへの最短距離 for k in range(size_v): for i in range(size_v): for j in range(size_v): d[i][j]=min(d[i][j],d[i][k]+d[k][j]) return d # vlistに点のリスト、dist[vi][vj]に辺(vi,vj)のコストを入れて呼び出す size_v=N+1 dist=[[float("inf")]*size_v for i in range(size_v)] for _ in range(M): A,B,C=map(int,input().split()) dist[A][B]=C dist[B][A]=C for i in range(size_v): dist[i][i]=0 #自身のところに行くコストは0 dist=warshall_floyd(dist) #print(dist) dist2=[[float("inf")]*size_v for i in range(size_v)] for i in range(size_v): for j in range(size_v): if dist[i][j]<=L: dist2[i][j]=1 for i in range(size_v): dist2[i][i]=0 #自身のところに行くコストは0 dist2=warshall_floyd(dist2) #print(dist2) Q=int(input()) for _ in range(Q): s,t=map(int,input().split()) answer=dist2[s][t]-1 if answer==float("inf"): print(-1) else: print(answer)
from math import gcd k=int(input()) cnt=0 for i in range(1,k+1): for p in range(1,k+1): for q in range(1,k+1): gcd1=gcd(i,p) cnt+=gcd(gcd1,q) print(cnt)
0
null
104,600,980,559,478
295
174
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): 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) def gcd(*numbers): reduce(math.gcd, numbers) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 count = 0 ans = 0 inf = float("inf") import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): 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) def gcd(*numbers): reduce(math.gcd, numbers) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 count = 0 ans = 0 import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): 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) def gcd(*numbers): reduce(math.gcd, numbers) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 count = 0 ans = 0 inf = float("inf") n,m = I() g = [[] for _ in range(n)] for i in range(m): a,b = I() g[a-1].append(b-1) g[b-1].append(a-1) q = deque([0]) d = [-1]*n d[0] = 0 while q: v = q.popleft() for i in g[v]: if d[i] != -1: continue d[i] = v q.append(i) if -1 in d: print("No") else: print("Yes") for i in d[1:]: print(i+1)
print("Yes" if int(input()) >= 30 else "No")
0
null
13,211,172,788,844
145
95
#!/usr/bin/env python3 import sys import math import decimal import itertools from itertools import product from functools import reduce def input(): return sys.stdin.readline()[:-1] def sort_zip(a:list, b:list): z = zip(a, b) z = sorted(z) a, b = zip(*z) a = list(a) b = list(b) return a, b def main(): H, W, K = map(int, input().split()) c = [] for i in range(H): c.append(input()) ans = 0 for i in product([0, 1], repeat=H): for j in product([0, 1], repeat=W): black = 0 for h in range(H): for w in range(W): if i[h] == 1 and j[w] == 1 and c[h][w] == '#': black += 1 if black == K: ans += 1 print(ans) if __name__ == '__main__': main()
N, K = map(int,input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort(reverse=True) F.sort() U = 10**12 L = -1 while U - L > 1: x = (U+L)//2 cnt = 0 for i in range(N): if x//F[i] < A[i]: cnt += A[i] - x//F[i] if cnt > K: L = x else: U = x print(U)
0
null
86,612,529,688,090
110
290
S = input() length =len(S) S = list(S) count = 0 for i in range(length): if S[i] == '?': S[i] = 'D' answer = "".join(S) print(answer)
import sys X=int(input()) X5=X**0.2 #print('X5=',X5,int(X5)) if X5-int(X5)==0: a=int(X5) b=0 print(a,b) #print(1) sys.exit() for a in range(1,int(X5)+1): for mb in range(a): if a**5+mb**5==X: print(a,-mb) #print(2) sys.exit() for a in range(1,2*int(X5)): for b in range(a): if a**5-b**5==X: print(a,b) #print(3) sys.exit() #print(4)
0
null
21,950,418,210,080
140
156
A,B = map(str,input().split()) out = B+A print(out)
s,t=input().split();print(t+s)
1
103,123,883,911,520
null
248
248
n, k = map(int, input().split()) w = [int(input()) for _ in range(n)] # k台以内のトラックで運べる荷物の個数 # P: ひとつのトラックに積載できる最大量 def check(P): i = 0 for j in range(k): s = 0 while s + w[i] <= P: s += w[i] i += 1 if i == n: return n return i # 二部探索 left = 0 right = 100000 * 10000 while right - left > 1: mid = (left + right) // 2 v = check(mid) if v >= n: right = mid else: left = mid print(right)
C = input() alpha = ["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"] j = 0 for i in alpha: if i == C: print(alpha[j+1]) j += 1
0
null
46,237,571,794,670
24
239
X=int(input()) n=X%100 m=X//100 if 0<=n<=m*5: print(1) else: print(0)
import itertools N = int(input()) x = [] y = [] for i in range(N): xy = list(map(int, input().split())) x.append(xy[0]) y.append(xy[1]) l = [i for i in range(N)] ans = 0 cnt = 0 for i in itertools.permutations(l, N): cnt += 1 for j in range(1, N): x1 = x[i[j]] x2 = x[i[j-1]] y1 = y[i[j]] y2 = y[i[j-1]] ans += pow((x1 - x2)**2 + (y1 - y2)**2, 0.5) # print(i, j, x1, y1, x2, y2) ans /= cnt print(ans)
0
null
138,059,424,632,672
266
280
pi = 3.141592653589 r = float(input()) c = pi*r**2 s = 2*pi*r print('%.5f %.5f' % (c,s))
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
4,631,887,512,100
46
109
import queue n,u,v = map(int, input().split()) u -= 1 v -= 1 path = [[] for i in range(n)] for i in range(n-1): a,b = map(int, input().split()) a -= 1 b -= 1 path[a].append(b) path[b].append(a) t = [10**9]*n t[u]=0 q = queue.Queue() q.put(u) while not q.empty(): p = q.get() for x in path[p]: if t[x]>t[p]+1: q.put(x) t[x]=t[p]+1 a = [10**9]*n a[v]=0 q = queue.Queue() q.put(v) while not q.empty(): p = q.get() for x in path[p]: if a[x]>a[p]+1: q.put(x) a[x]=a[p]+1 c = [a[i] for i in range(n) if a[i]>t[i]] print(max(c)-1)
import sys printf = sys.stdout.write abc = [] ans = [0 for i in range(26)] for i in range(26): abc.append(str(chr(i + 97))) word = [] for line in sys.stdin: word.append(line) for i in range(len(word)): for j in range(len(word[i])): for k in range(29): if (k + 65) == ord(word[i][j]) or (k + 97) == ord(word[i][j]): ans[k] += 1 for i in range(26): printf(abc[i] + " : " + str(ans[i]) + "\n")
0
null
59,401,813,905,372
259
63
n = int(input()) Tp = 0 Hp = 0 tmp = "abcdefghijklmnopqrstuvwxyz" alph = list(tmp) for i in range(n): Ta,Ha = input().split() lTa = list(Ta) lHa = list(Ha) num = 0 if (len(Ta) <= len(Ha)): #definition of num num = len(Ta) else: num = len(Ha) if (Ta in Ha and lTa[0] == lHa[0]): #drow a if (Ta == Ha): Tp += 1 Hp += 1 else: Hp += 3 elif (Ha in Ta and Ha != Ta and lTa[0] == lHa[0]): Tp += 3 else: for i in range(len(lTa)): # convert alphabet to number for j in range(26): if (lTa[i] == alph[j]): lTa[i] = int(j) else : continue for i in range(len(lHa)): # convert alphabet to number for j in range(26): if (lHa[i] == alph[j]): lHa[i] = int(j) else : continue for i in range(num): if (lTa[i] < lHa[i]): Hp +=3 break elif (lHa[i] < lTa[i]): Tp +=3 break elif (lHa[i] == lTa[i]): continue print(Tp,Hp)
n = int(input()) p1 = p2 = 0 for _ in range(n): taro,hanako = map(str,input().split(" ")) if taro>hanako: p1 += 3 elif taro<hanako: p2 += 3 else: p1 += 1 p2 += 1 print(p1,p2)
1
2,005,120,705,130
null
67
67
n,a,b = map(int,input().split()) if abs(a-b)%2 == 0: print(abs(a-b)//2) else: if a - 1 > n - b: print((n-b+n-a+1)//2) else: print((a-1+b-1+1)//2)
# ALDS1_4_A. # リニアサーチ。 def intinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def main(): n = int(input()) S = intinput() q = int(input()) T = intinput() count = 0 for k in T: if k in S: count += 1 print(count) if __name__ == "__main__": main()
0
null
54,827,665,429,460
253
22
s = input() S = list(s) if S[2] == S[3] and S[4] == S[5]: print('Yes') else: print('No')
S = input() if (S[2] == S[3]) and (S[4] == S[5]): print('Yes') else: print('No')
1
42,195,831,784,832
null
184
184
word=input() last_letter=word[int(len(word))-1] if last_letter=="s": print(word+"es") else: print(word+"s")
N = int(input()) A = [-1] + list(map(int, input().split())) lis = [0]*(N+1) for a in A[1:]: lis[a] += 1 sum_combinations = 0 for x in lis[1:]: if x >= 2: sum_combinations += x*(x-1)//2 for i in range(1,N+1): ans = sum_combinations num = lis[A[i]] if num >= 2: ans += (num-1)*(num-2)//2 - num*(num-1)//2 print(ans)
0
null
25,204,794,692,868
71
192
#!/usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys sys.setrecursionlimit(10**6) input = sys.stdin.buffer.readline INF = 10 ** 9 + 1 # sys.maxsize # float("inf") def debug(*x): print(*x, file=sys.stderr) def solve(N, K, AS): for _i in range(K): d = [0] * (N + 1) for i in range(N): x = AS[i] d[max(i - x, 0)] += 1 d[min(i + x + 1, N)] -= 1 cur = 0 ret = [0] * N for i in range(N): cur += d[i] ret[i] = cur AS = ret if all(x == N for x in ret): return ret return ret def main(): N, K = map(int, input().split()) AS = list(map(int, input().split())) print(*solve(N, K, AS)) T1 = """ 5 1 1 0 0 1 0 """ def test_T1(): """ >>> as_input(T1) >>> main() 1 2 2 1 2 """ T2 = """ 5 2 1 0 0 1 0 """ def test_T2(): """ >>> as_input(T2) >>> main() 3 3 4 4 3 """ def _test(): import doctest doctest.testmod() def as_input(s): "use in test, use given string as input file" import io global read, input f = io.StringIO(s.strip()) def input(): return bytes(f.readline(), "ascii") def read(): return bytes(f.read(), "ascii") USE_NUMBA = False if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c': print("compiling") from numba.pycc import CC cc = CC('my_module') cc.export('solve', solve.__doc__.strip().split()[0])(solve) cc.compile() exit() else: input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba": # -p: pure python mode # if not -p, import compiled module from my_module import solve # pylint: disable=all elif sys.argv[-1] == "-t": print("testing") _test() sys.exit() elif sys.argv[-1] != '-p' and len(sys.argv) == 2: # input given as file input_as_file = open(sys.argv[1]) input = input_as_file.buffer.readline read = input_as_file.buffer.read main()
n,x,m=map(int,input().split()) logn = (10**10).bit_length() doubling = [] sumd = [] for _ in range(logn): tmpd = [-1] * m doubling.append(tmpd) tmps = [0] * m sumd.append(tmps) for i in range(m): doubling[0][i] = i * i % m sumd[0][i] = i for i in range(1,logn): for j in range(m): doubling[i][j] = doubling[i-1][doubling[i-1][j]] sumd[i][j] = sumd[i-1][j] + sumd[i-1][doubling[i-1][j]] now = x pos = 0 result = 0 while n: if n & 1: result += sumd[pos][now] now = doubling[pos][now] n = n >> 1 pos += 1 print(result)
0
null
9,118,055,602,078
132
75
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)
n, k = map(int, input().split()) MOD = 10 ** 9 + 7 ans = 0 for i in range(k, n + 2): mini = i * (i - 1) / 2 maxx = i * (2 * n - i + 1) / 2 ans += maxx - mini + 1 ans %= MOD print(int(ans))
1
33,313,255,530,490
null
170
170
def magic(a,b,c,k): for i in range(k): if(a>=b): b*=2 elif(b>=c): c*=2 if(a < b and b < c): print("Yes") else: print("No") d,e,f = map(int,input().split()) j = int(input()) magic(d,e,f,j)
import itertools A,B,C = list(map(int, input().split())) K = int(input()) ans = False for p in itertools.product(['a','b','c'], repeat=K): A0,B0,C0 = A,B,C for e in p: if e == 'a': A0 = 2*A0 elif e == 'b': B0 = 2*B0 else: C0 = 2*C0 if A0 < B0 < C0 : ans = True break print('Yes' if ans else 'No')
1
6,866,084,225,352
null
101
101