code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
import sys tscore = hscore = 0 n = int( sys.stdin.readline() ) for i in range( n ): tcard, hcard = sys.stdin.readline().rstrip().split( " " ) if tcard < hcard: hscore += 3 elif hcard < tcard: tscore += 3 else: hscore += 1 tscore += 1 print( "{:d} {:d}".format( tscore, hscore ) )
num = int(input()) tscore, hscore = 0, 0 for i in range(num): ts, hs = input().split() if ts > hs: tscore += 3 elif ts < hs: hscore += 3 else: tscore += 1 hscore += 1 print(tscore, hscore)
1
2,030,758,516,420
null
67
67
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)
from collections import defaultdict N,K=map(int,input().split()) alist=list(map(int,input().split())) #print(alist) slist=[0] for i in range(N): slist.append(slist[-1]+alist[i]) #print(slist) sslist=[] for i in range(N+1): sslist.append((slist[i]-i)%K) #print(sslist) answer=0 si_dic=defaultdict(int) for i in range(N+1): if i-K>=0: si_dic[sslist[i-K]]-=1 answer+=si_dic[sslist[i]] si_dic[sslist[i]]+=1 print(answer)
1
137,555,094,546,176
null
273
273
def bubbleSort(c, n): flag = 1 while(flag) : flag = 0 for i in reversed(range(1,n)): if(c[i][1] < c[i-1][1]): c[i], c[i-1] = c[i-1], c[i] flag = 1 return c def selectionSort(c,n): for i in range(n): minj = i for j in range(i, n): if(c[j][1] < c[minj][1]): minj = j c[i], c[minj] = c[minj], c[i] return c def isStable(c1, c2, n): for i in range(n): if(c1[i] != c2[i]): return False return True n = int(input()) c = input().split(' ') trump = [list(i) for i in c] bubble = ["".join(s) for s in bubbleSort(trump, n)] trump = [list(i) for i in c] selection = ["".join(s) for s in selectionSort(trump, n)] str_bubble = " ".join(bubble) str_selection = " ".join(selection) print(str_bubble) print('Stable') print(str_selection) if isStable(bubble, selection, n): print('Stable') else: print('Not stable')
import sys class Card: def __init__(self, card): self.card = card self.mark = card[0] self.value = card[1] def equals(self, other): if self.mark != other.mark: return False if self.value != other.value: return False return True def __str__(self): return self.card def print_cards(cards, cards_): n = len(cards) same = True for i in range(n): if cards_ != None and cards[i].equals(cards_[i]) == False: same = False sys.stdout.write(str(cards[i])) if i != n - 1: sys.stdout.write(' ') print() return same def swap(cards, i, j): temp = cards[i] cards[i] = cards[j] cards[j] = temp def bubble_sort(cards): n = len(cards) for i in range(n): for j in range(n - 1, i, -1): if cards[j].value < cards[j - 1].value: swap(cards, j, j - 1) def selection_sort(cards): n = len(cards) for i in range(n): mini = i for j in range(i, n): if cards[j].value < cards[mini].value: mini = j if mini != i: swap(cards, i, mini) n = int(input()) input_list = list(map(str, input().split())) cards1 = [None] * n cards2 = [None] * n for i in range(n): cards1[i] = Card(input_list[i]) cards2[i] = Card(input_list[i]) bubble_sort(cards1) selection_sort(cards2) print_cards(cards1, None) print('Stable') stable = print_cards(cards2, cards1) if stable == True: print('Stable') else: print('Not stable')
1
24,948,008,010
null
16
16
N = int(input()) A = list(map(int, input().split())) A.sort() res = 1 for i in A: res*=i; if res>10**18: res = -1 break print(res)
s = input() l = [0,'SAT','FRI','THU','WED','TUE','MON','SUN'] print(l.index(s))
0
null
74,672,099,839,010
134
270
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)
import itertools N, K = map(int, input().split()) p = list(map(int, input().split())) pos = [(p[i]+1)/2 for i in range(N)] pos_acum = list(itertools.accumulate(pos)) ans = pos_acum[K-1] for i in range(N-K): ans = max(ans, pos_acum[K+i]-pos_acum[i]) print(ans)
0
null
124,149,654,778,818
295
223
def bubbleSort(c, n): flag = 1 while(flag) : flag = 0 for i in reversed(range(1,n)): if(c[i][1] < c[i-1][1]): c[i], c[i-1] = c[i-1], c[i] flag = 1 return c def selectionSort(c,n): for i in range(n): minj = i for j in range(i, n): if(c[j][1] < c[minj][1]): minj = j c[i], c[minj] = c[minj], c[i] return c def isStable(c1, c2, n): for i in range(n): if(c1[i] != c2[i]): return False return True n = int(input()) c = input().split(' ') trump = [list(i) for i in c] bubble = ["".join(s) for s in bubbleSort(trump, n)] trump = [list(i) for i in c] selection = ["".join(s) for s in selectionSort(trump, n)] str_bubble = " ".join(bubble) str_selection = " ".join(selection) print(str_bubble) print('Stable') print(str_selection) if isStable(bubble, selection, n): print('Stable') else: print('Not stable')
N = int(input()) B = input().split() S = B[:] for i in range(N): for j in range(N-1, i, -1): if B[j][1] < B[j-1][1]: B[j], B[j-1] = B[j-1], B[j] m = i for j in range(i, N): if S[m][1] > S[j][1]: m = j S[m], S[i] = S[i], S[m] print(*B) print('Stable') print(*S) print(['Not s', 'S'][B==S] + 'table')
1
24,394,971,900
null
16
16
N = int(input()) A = sorted(list(map(int,input().split()))) ans = "YES" for i in range(1,N,2): boollist = [ A[i-1] == A[i] ] if i < N-1 : boollist.append(A[i] == A[i+1]) if any(boollist): ans = "NO" break print(ans)
from collections import deque N=int(input()) G=[{} for i in range(N+1)] colors = [] for i in range(N-1): a,b=map(int,input().split()) G[a][b]=[i,-1] G[b][a]=[i,-1] def bfs(s): seen = [0 for i in range(N+1)] prev = [0 for i in range(N+1)] todo = deque([]) cmax = 0 now = s seen[now]=1 todo.append(now) while 1: if len(todo)==0:break a = todo.popleft() if len(G[a])<50: if prev[a] == 0: a_color=set([]) else: a_color=set([G[a][prev[a]][1]]) for b in G[a]: if seen[b] == 0: seen[b] = 1 todo.append(b) prev[b] = a for c in range(1,N+1): if c not in a_color: a_color.add(c) colors.append((G[a][b][0],c)) G[a][b][1]=G[b][a][1]=c if c > cmax: cmax = c break else: temp = list(range(1,N)) if prev[a] != 0: del temp[G[a][prev[a]][1]-1] temp = deque(temp) for i,b in enumerate(G[a]): if seen[b] == 0: seen[b] = 1 todo.append(b) prev[b] = a c = temp.popleft() colors.append((G[a][b][0],c)) G[a][b][1]=G[b][a][1]=c if c > cmax: cmax = c return colors, cmax colors,cmax = bfs(1) colors=sorted(colors) print(cmax) for i in range(N-1): print(colors[i][1])
0
null
104,539,201,981,188
222
272
a, b = [int(n) for n in input().split()] print(a*b if 1 <= a <= 9 and 1 <= b <= 9 else '-1')
x = int(input()) Level = [i for i in range(400, 2000, 200)] ans = 9 for level in Level: if x >= level: ans -= 1 print(ans)
0
null
82,362,895,563,650
286
100
from sys import stdin s = list(stdin.readline()) for i in range(len(s)): if s[i].islower(): s[i] = s[i].upper() elif s[i].isupper(): s[i] = s[i].lower() print(*s, sep="", end="")
N = int(input()) L = [1]*(N+1) for k in range(2,N+1): t = 1 while k*t <= N: L[k*t] += 1 t += 1 ans = 0 for k in range(1,N+1): ans += k*L[k] print(ans)
0
null
6,330,992,522,052
61
118
def N(): return int(input()) def L(): return list(map(int,input().split())) def NL(n): return [list(map(int,input().split())) for i in range(n)] mod = pow(10,9)+7 #import numpy a,b,c,d = L() ta = -(-c // b) ao = -(-a//d) #print(ta,ao) if ta <= ao : print("Yes") else: print("No")
A,B,C,D = list(map(int,input().split())) Takahashi = C//B if C%B != 0 : Takahashi += 1 Aoki = A//D if A%D != 0 : Aoki += 1 # print(Takahashi,Aoki) ans='No' if Takahashi <= Aoki: ans = 'Yes' print(ans)
1
29,632,560,315,228
null
164
164
H,N = (int(x) for x in input().split()) A = [int(x) for x in input().split()] if sum(A)>=H: print('Yes') else: print('No')
H, N = map(int, input().split()) N = list(map(int, input().split())) print("Yes") if(sum(N) >= H) else print("No")
1
78,237,530,116,242
null
226
226
while 1: n=int(input()) if n==0:break s=list(map(int,input().split())) print((sum([(m-sum(s)/n)**2 for m in s])/n)**.5)
import statistics while True: n=int(input()) if n==0: break stdnt=list(map(int,input().split())) std=statistics.pstdev(stdnt) print(std)
1
195,381,631,892
null
31
31
N, M = list(map(int, input().split())) A = [0] * M B = [0] * M R = [0] * N for i in range(N): R[i] = set() for i in range(M): A[i], B[i] = list(map(int, input().split())) R[A[i]-1].add(B[i]-1) R[B[i]-1].add(A[i]-1) stack = set() visited = set() max_groups = 0 for i in range(N): if not i in visited: stack.add(i) groups = 0 while True: current = stack.pop() visited.add(current) groups += 1 stack |= (R[current] - visited) if not stack: break max_groups = max(max_groups,groups) print(max_groups)
class UnionFind: def __init__(self,n): self.par = [-1] * n # 負数は友達の数(自分を含む)初期値は自分-1、0と正数は根を示す def root(self,x): # xの根を返す if self.par[x] < 0: # xが根の時は、xを返す return x self.par[x] = self.root(self.par[x]) # 根でないときは、par[x]に根の根を代入 return self.par[x] # 根の根を返す def union(self,x,y): x = self.root(x) y = self.root(y) if x == y: return if self.par[x] > self.par[y]: # par[x]が小さく(友達が多く)なるように交換 x, y = y, x self.par[x] += self.par[y] # 友達が多い方に少ない方を加える self.par[y] = x # yの根をxにする def size(self): return -1 * min(self.par) n, m = map(int, input().split()) uf = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) uf.union(a-1,b-1) # 1が0番目、2が1番目・・・ print(uf.size())
1
3,935,414,734,044
null
84
84
N=int(input()) H=list(map(int,input().split())) depth=[0]*(N+1) depth[0]=1 if N==0: if H[0]!=1: print(-1) exit() else: print(1) exit() else: if H[0]!=0: print(-1) exit() for i in range(1,N+1): depth[i]=(depth[i-1]-H[i-1])*2 if depth[i]<0: print(-1) exit() if depth[N-1]*2<H[N]: print(-1) exit() else: depth[N]=min(depth[N],H[N]) for i in range(N - 1, -1, -1): if depth[i + 1] == 0: if H[i] != 0: depth[i] = H[i] else: depth[i] = 0 if i == 0: depth[i] = 1 else: depth[i] = min(depth[i + 1] + H[i], depth[i]) print(sum(depth))
from itertools import accumulate n, *A = map(int, open(0).read().split()) if A[0] != 0: if A[0] == 1 and n == 0: print(1) else: print(-1) else: B = list(accumulate(A[::-1]))[::-1] C = [1] * (n+1) D = [1] * (n+1) for i in range(1, n+1): C[i] = min(B[i], 2*D[i-1]) D[i] = C[i] - A[i] if D[i] < 0: print(-1) break else: print(sum(C))
1
18,733,212,862,572
null
141
141
N=int(input()) S=[] T=[] for i in range(N): x,y=map(str,input().split()) S.append(x) T.append(int(y)) X=str(input()) p=S.index(X) print(sum(T[p+1:]))
# coding: utf-8 # Your code here! def multiple_3(num): if num % 3 == 0: print(" {}".format(num), end="") else: included_3(num) def included_3(num): if "3" in str(num): print(" {}".format(num), end="") n = int(input()) for num in range(3, n+1): multiple_3(num) print()
0
null
49,222,883,315,788
243
52
import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) L = I() len_edge = L/3 print(len_edge**3)
def main(): l = int(input()) num = l / 3 print(num**3) if __name__ == "__main__": main()
1
47,173,665,804,858
null
191
191
import bisect n=int(input()) l=sorted(list(map(int,input().split()))) ans=0 for i in range(n): for j in range(i+1,n): index=bisect.bisect_left(l,l[i]+l[j]) ans+=index-j-1 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() A = sorted(A, reverse=True) # 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) tot = 0 for i in range(N - 1): if i % 2 == 0: tot += A[i // 2] else: tot += A[i // 2 + 1] print(tot)
0
null
90,707,308,054,608
294
111
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(N - 1): if A[i] > A[i + 1]: ans += A[i] - A[i + 1] A[i + 1] = max(A[i], A[i + 1]) print(ans)
def factorization(n): arr = [] tmp = n for i in range(2, int(-(-n**0.5//1))+1): if tmp % i == 0: cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i arr.append([i, cnt]) if tmp != 1: arr.append([tmp, 1]) if arr == [] and n != 1: arr.append([n, 1]) return arr n = int(input()) c = factorization(n) ans = 0 for k, v in c: cnt = 1 while v >= cnt: v -= cnt cnt += 1 ans += (cnt - 1) print(ans)
0
null
10,679,905,580,708
88
136
n = int(input()) ans = "" while n: n -= 1 ans += chr(ord('a') + (n % 26)) n //= 26 print(ans[::-1])
nn, kk = list(map(int,input().split())) pp = list(map(int,input().split())) expectation = [0]*(nn-kk+1) expectation[0] = sum(pp[0:kk]) for i in range(1,nn-kk+1): expectation[i] = expectation[i-1] - pp[i-1] + pp[i+kk-1] print((max(expectation)+kk)/2)
0
null
43,318,396,295,890
121
223
n,k=list(map(int,input().split())) prices=list(map(int , input().split())) prices.sort() amount=0 for i in range(0,k): amount+=prices[i] print(amount)
r,cr,c = map(int,input().split()) matrix_a = [list(map(int,input().split())) for i in range(r)] matrix_b = [list(map(int,input().split())) for i in range(cr)] matrix_c = [ [0 for a in range(c)] for b in range(r)] for j in range(r): for k in range(c): for l in range(cr): matrix_c[j][k] += matrix_a[j][l]*matrix_b[l][k] for x in matrix_c: print(" ".join(list(map(str,x))))
0
null
6,448,963,447,238
120
60
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) n,x,y=nii() x-=1 y-=1 ans=[0 for i in range(n)] for i in range(n-1): for j in range(i+1,n): dist1=j-i dist2=abs(i-x)+1+abs(j-y) dist=min(dist1,dist2) ans[dist]+=1 for i in ans[1:]: print(i)
n,x,y=map(int,input().split()) a=[0]*n for i in range(1,n+1): for j in range(i,n+1): b=min(abs(i-j),abs(i-x)+1+abs(y-j),abs(x-j)+1+abs(y-i)) a[b]+=1 print(*a[1:],sep="\n")
1
44,024,096,685,382
null
187
187
HP, n = map(int,input().split()) a = list(map(int,input().split())) count = 0 for i in a: count += i if count >= HP: print("Yes") else: print("No")
x, y = input().split() x = int(x) y = int(y) if y % 2 == 0 and 2 * x <= y <= 4 * x: print('Yes') else: print('No')
0
null
45,900,183,080,052
226
127
n = [int(i) for i in input().split()] print(max(n[0] - 2*n[1], 0))
[A,B] = list(map(int,input().split())) nokori = A - B*2 if nokori>=0: print(nokori) else: print(0)
1
166,644,547,670,898
null
291
291
#!/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(X: int): return X//500*1000 + X % 500//5*5 def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int print(f'{solve(X)}') if __name__ == '__main__': main()
def solve(): X = int(input()) a,b = divmod(X, 500) print(1000*a + 5*(b//5)) if __name__ == "__main__": solve()
1
42,972,229,664,728
null
185
185
n=int(input()) 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 ans=0 l=len(factorization(n)) s=factorization(n) for i in range(l): for j in range(1,1000): if s[i][1]>=j: ans+=1 s[i][1]-=j else: break if n==1: print(0) else: print(ans)
import math def solve(): N = int(input()) ans = 0 for i in range(2, int(math.sqrt(N)) + 2): n = 1 cnt = 0 while N % i == 0: N //= i cnt += 1 if cnt == n: cnt = 0 n += 1 ans += 1 if N != 1: ans += 1 return ans print(solve())
1
16,858,754,974,282
null
136
136
import itertools N = int(input()) P = list(map(int, input().split())) Q = list(map(int, input().split())) a = [i for i in range(1,N+1)] cnt = 0 ans_a, ans_b = 0, 0 for target in itertools.permutations(a): cnt += 1 if list(target) == P: ans_a = cnt if list(target) == Q: ans_b = cnt print(abs(ans_a-ans_b))
# -*- coding: utf-8 -*- buf = str(raw_input()) char_list = list(buf) res = "" for i in char_list: if i.isupper(): res += i.lower() elif i.islower(): res += i.upper() else: res += i print res
0
null
51,145,973,218,578
246
61
n,k,c = map(int,input().split()) s = list(input()) L = [] R = [] i = -1 j = n for ki in range(k): while i < n: i += 1 if s[i] == 'o': L += [i] i += c break for ki in range(k): while 0 <= j: j -= 1 if s[j] == 'o': R += [j] j -= c break for i in range(k): if L[i] == R[-i-1] : print(L[i]+1)
def warshal(data): for k in range(n): for i in range(n): for j in range(n): data[i][j]=min(data[i][j],data[i][k]+data[k][j]) return data n,m,l=map(int,input().split()) inf=float("inf") data=[[inf]*n for i in range(n)] for i in range(m): a,b,c=map(int,input().split()) data[a-1][b-1]=c data[b-1][a-1]=c for i in range(n): data[i][i]=0 data=warshal(data) for i in range(n): for j in range(n): if data[i][j]<=l: data[i][j]=1 else: data[i][j]=inf for i in range(n): data[i][i]=0 data=warshal(data) q=int(input()) st=[] for i in range(q): s,t=map(int,input().split()) st.append([s-1,t-1]) for s,t in st: if data[s][t]==inf: print(-1) else: print(data[s][t]-1)
0
null
106,804,018,744,608
182
295
#!/usr/bin/env python # coding: utf-8 # In[21]: N,K = map(int, input().split()) R,S,P = map(int,input().split()) T = input() # In[22]: points = {} points["r"] = P points["s"] = R points["p"] = S ans = 0 mylist = [] for i in range(N): mylist.append(T[i]) if i >= K: if T[i] == mylist[-K-1]: mylist[-1] = "x" else: ans += points[T[i]] else: ans += points[T[i]] print(ans) # In[ ]:
W = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] S = input() print(len(W) - W.index(S))
0
null
119,669,062,487,322
251
270
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) def isok(bs, RT): return True if bs <= RT else False def search(B, RT): left = -1 right = M+1 while right-left>1: mid = left+(right-left)//2 if isok(B[mid], RT): left = mid else: right = mid return left def solve(): asum = [0]*(N+1) bsum = [0]*(M+1) for i in range(N): asum[i+1]=asum[i]+A[i] for i in range(M): bsum[i+1]=bsum[i]+B[i] ans = 0 for i in range(N+1): RT = K-asum[i] if RT < 0: break ans = max(ans, i+search(bsum, RT)) print(ans) if __name__ == '__main__': solve()
import typing def binary_serch(x:int, b_sum:list): l = 0 r = len(b_sum) - 1 mid = (l + r + 1) // 2 res = mid while True: if x == b_sum[mid]: return mid elif x < b_sum[mid]: res = mid - 1 r = mid mid = (l + r + 1) // 2 elif b_sum[mid] < x: res = mid l = mid mid = (l + r + 1) // 2 if l + 1 == r: return res n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) b_sum = [0] * (m + 2) for i in range(m): b_sum[i + 1] = b[i] + b_sum[i] b_sum[-1] = 10 ** 9 + 1 a = [0] + a pass_k = 0 ans = 0 for i in range(n + 1): if pass_k + a[i] <= k: pass_k += a[i] book = i book += binary_serch(k - pass_k, b_sum) ans = max(ans, book) else: break print(ans)
1
10,760,146,990,360
null
117
117
def main(): import sys K=int(sys.stdin.readline()) print('ACL'*K) main()
a=int(input()) b='' for i in range(a): b=b+'ACL' print(b)
1
2,151,579,169,476
null
69
69
H,N = map(int,input().split()) A = list(map(int,input().split())) sum =0 for i in range(len(A)): sum = sum + A[i] if sum >= H: print("Yes") else: print("No")
H, N = map(int,input().split()) A = list(map(int,input().split())) if H > sum(A): print('No') else: print('Yes')
1
77,958,080,603,700
null
226
226
n,m = map(int,input().split()) mat=[] v=[] for i in range(n): a=list(map(int,input().split())) mat.append(a) for j in range(m): v.append(int(input())) for i in range(n): w = 0 for j in range(m): w += mat[i][j]*v[j] print(w)
n,m = map(int,input().split()) A = [] B = [] for i in range(n): tmp = list(map(int,input().split())) A.append(tmp) tmp=[] for i in range(m): num = int(input()) B.append(num) for i in range(n): c = 0 for j in range(m): c += A[i][j]*B[j] print(c)
1
1,163,755,520,560
null
56
56
N,K = map(int,input().split()) S = [] d = {} A = list(map(int,input().split())) ans = 0 sum =0 for i in range(1,N+1): sum += A[i-1] % K s = (sum - i) % K if i > K: x = S.pop(0) d[x] -= 1 elif i < K: if s == 0: ans += 1 if s not in d: d[s] = 0 ans += d[s] d[s] += 1 S.append(s) print(ans)
from itertools import accumulate from collections import defaultdict n, k = map(int, input().split()) a = list(map(int, input().split())) acc = [0] + list(accumulate(a)) sm = [(e - i) % k for i, e in enumerate(acc)] d = defaultdict(int) ans = 0 for r in range(1, n + 1): if r - k >= 0: e = sm[r - k] d[e] -= 1 e = sm[r - 1] d[e] += 1 e = sm[r] ans += d[e] print(ans)
1
137,464,905,489,200
null
273
273
import math # 提出用 n = int(input()) x = [int(i) for i in input().split()] y = [int(i) for i in input().split()] # # 動作確認用 # with open('input_itp1_10_d_1.txt', mode='r')as fin: # n = int(next(fin)) # x = [int(i) for i in next(fin).split()] # y = [int(i) for i in next(fin).split()] tmp = 0 for i in range(n): tmp += abs(x[i] - y[i]) print('%f' % (tmp)) tmp = 0 for i in range(n): tmp += (abs(x[i] - y[i]))**2 print('%f' % (math.sqrt(tmp))) tmp = 0 for i in range(n): tmp += (abs(x[i] - y[i]))**3 print('%f' % (pow(tmp, 1 / 3))) tmp = 0 for i in range(n): tmp = abs(x[i] - y[i]) if tmp < abs(x[i] - y[i]) else tmp print('%f' % (tmp))
n = int(input()) xs = list(map(int, input().split())) ys = list(map(int, input().split())) ds = [abs(x - y) for x, y in zip(xs, ys)] for i in range(1, 4): ans = 0 for d in ds: ans += d**i print(ans**(1/i)) print(max(ds))
1
208,802,670,150
null
32
32
N = int(input()) S = input() assert len(S) == N if N % 2 == 0: print('Yes' if S[:N//2] == S[N//2:] else 'No') else: print('No')
import sys A, B, C, D = map(int, input().split()) while A > 0 or B > 0: C = C - B if C <= 0: print("Yes") sys.exit() A = A - D if A <= 0: print("No") sys.exit()
0
null
87,949,029,028,848
279
164
# ????????? n ?¬?????????????????????????p ??????????????? 1???2???3????????? ?????????????????????????????¢????±???????????????°?????? import math # ?¬??????°n????¨??????\??????????????? n = int(input()) # ????????????x????¨??????\??????????????? x = list(input()) x = "".join(x).split() # ????????????y????¨??????\??????????????? y = list(input()) y = "".join(y).split() # p=1,2,????????§???????????????????????????????????¢???????´????????????? # ????????????????????? dxy = [0 for i in range(4)] # p=1???????????????????????????????????¢????¨???? for i in range(0, n): dxy[0] += math.fabs(int(x[i]) - int(y[i])) # p=2 for i in range(0, n): dxy[1] += (math.fabs(int(x[i]) - int(y[i]))) ** 2 dxy[1] = math.sqrt(dxy[1]) # p=3 for i in range(0, n): dxy[2] += (math.fabs(int(x[i]) - int(y[i]))) ** 3 dxy[2] = math.pow(dxy[2], 1.0 / 3.0) # p=????????§ dxy[3] = math.fabs(int(x[0]) - int(y[0])) for i in range(1, n): if dxy[3] < math.fabs(int(x[i]) - int(y[i])): dxy[3] = math.fabs(int(x[i]) - int(y[i])) # ?????? for i in range(0, 4): print("{0}".format(dxy[i]))
import math n = int(input()) x = list(map(int,input().split())) y = list(map(int,input().split())) p1 = p2 = p3 = p = 0 for x,y in zip(x,y): d = abs(x-y) p1 += d p2 += d**2 p3 += d**3 if d>p: p = d print('{0:.5f}\n{1:.5f}\n{2:.5f}\n{3:.5f}'.format(p1,math.sqrt(p2),math.pow(p3,1/3),p))
1
207,605,976,708
null
32
32
from decimal import * getcontext().prec = 1000 a, b, c = map(lambda x: Decimal(x), input().split()) if a.sqrt() + b.sqrt() + Decimal('0.00000000000000000000000000000000000000000000000000000000000000000001') < c.sqrt(): print('Yes') else: print('No')
a, b, c = raw_input().split() print "Yes" if a < b < c else "No"
0
null
26,049,532,320,812
197
39
import copy def main(): A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if V <= W: print('NO') elif (abs(A-B) / (V-W)) <= T: print('YES') else: print('NO') main()
# first line > /dev/null input() items = sorted([int(i) for i in input().split(' ')]) print(items[0], items[-1], sum(items))
0
null
7,982,698,656,032
131
48
s = [] n = int(input()) for i in range(n): s.append(input()) print("AC x " + str(s.count("AC"))) print("WA x " + str(s.count("WA"))) print("TLE x " + str(s.count("TLE"))) print("RE x " + str(s.count("RE")))
N=int(input()) d={"AC":0,"WA":0,"TLE":0,"RE":0} for _ in range(N): d[input()]+=1 print("AC x",d["AC"]) print("WA x",d["WA"]) print("TLE x",d["TLE"]) print("RE x",d["RE"])
1
8,734,304,229,240
null
109
109
class Dice: def __init__(self): self.up = 1 self.under = 6 self.N = 5 self.W = 4 self.E = 3 self.S = 2 def roll(self, d):#d => direction if d == "N": tmp = self.up self.up = self.S self.S = self.under self.under = self.N self.N = tmp elif d == "W": tmp = self.up self.up = self.E self.E = self.under self.under = self.W self.W = tmp elif d == "E": tmp = self.up self.up = self.W self.W = self.under self.under = self.E self.E = tmp elif d == "S": tmp = self.up self.up = self.N self.N = self.under self.under = self.S self.S = tmp def getUpward(self): return self.up def setRoll(self,up,under,N,W,E,S): self.up = up self.under = under self.N = N self.W = W self.E = E self.S = S def rotate(self):#crockwise tmp = self.S self.S = self.E self.E = self.N self.N = self.W self.W = tmp def getE(self, up, S): ''' :param up:num :param S: num :return: num ''' count = 0 while True: if self.up == up: break if count != 3: self.roll("N") count += 1 else: self.roll("E") while True: if self.S == S: break self.rotate() return self.E myd = Dice() myd.up, myd.S, myd.E, myd.W, myd.N, myd.under = map(int,input().split()) n = int(input()) for i in range(n): up, S = map(int,input().split()) print(myd.getE(up,S))
#coding:UTF-8 def GCD(x,y): d=0 if x < y: d=y y=x x=d if y==0: print(x) else: GCD(y,x%y) if __name__=="__main__": a=input() x=int(a.split(" ")[0]) y=int(a.split(" ")[1]) GCD(x,y)
0
null
130,262,017,692
34
11
word = input().lower() cnt = 0 while True: eot = input() if eot == 'END_OF_TEXT': break sent = eot.lower().split() if word in sent: cnt += sent.count(word) print(cnt)
x=int(input()) if x>=400 and x<=599: print(8) exit() if x>=600 and x<=799: print(7) exit() if x>=800 and x<=999: print(6) exit() if x>=1000 and x<=1199: print(5) exit() if x>=1200 and x<=1399: print(4) exit() if x>=1400 and x<=1599: print(3) exit() if x>=1600 and x<=1799: print(2) exit() if x>=1800 and x<=1999: print(1) exit()
0
null
4,283,888,889,962
65
100
n = int(input()) alpha = "abcdefghij" lst = [] def f(s,k): if len(s) == n: print(s) return for i in range(k+1): if i == k: f(s+alpha[i],k+1) else: f(s+alpha[i],k) f("",0)
import math def merge(S, left, mid, right) -> int: # n1 = mid - left # n2 = right - mid L = S[left: mid] R = S[mid: right] # for i in range(n1): # L.append(S[left + i]) L.append(math.inf) # for i in range(n2): # R.append(S[mid + i]) R.append(math.inf) i = 0 j = 0 for k in range(left, right): if L[i] <= R[j]: S[k] = L[i] i += 1 else: S[k] = R[j] j += 1 return right - left def merge_sort(S, left, right): count = 0 if left + 1 < right: mid = int((left + right) / 2) count += merge_sort(S, left, mid) count += merge_sort(S, mid, right) count += merge(S, left, mid, right) return count def main(): n = int(input()) S = list(map(int, input().split())) count = 0 count = merge_sort(S, 0, n) print(*S) print(count) if __name__ == "__main__": main()
0
null
26,205,427,721,660
198
26
A,B=input().split() A=int(A) B=int(100*float(B)+0.5) print(int(A*B/100))
A, B = input().split() A = int(A) B = round(float(B) * 100) ans = (A * B) // 100 print(int(ans))
1
15,805,564,150,908
null
133
133
n = int(input()) ans = ['a'] for i in range(n-1): buf = [] for j in ans: l = len(set(j)) for c in range(l+1): buf.append(j+chr(ord('a')+c)) ans = buf for i in ans: print(i)
n = int(input()) def calc(x_list): tmp = [] for x in x_list: m = max(x) for alpha in range(ord('a'), ord(m) + 2): tmp.append(x + chr(alpha)) if len(tmp[-1]) < n: tmp = calc(tmp) return tmp ans = calc(['a']) ans.sort() if n >= 2: print(*ans, sep="\n") else: print('a')
1
52,237,632,724,860
null
198
198
from sys import stdin import math import re import queue input = stdin.readline MOD = 1000000007 INF = 122337203685477580 def solve(): A,B,M = map(int, input().split()) v1 =list(map(int, input().split())) v2 =list(map(int, input().split())) res = INF for i in range(M): X,Y,C = map(int, input().split()) res = min(res,v1[X-1] + v2[Y-1] - C) res = min(res,min(v1) + min(v2)) res = max(0,res) print(res) if __name__ == '__main__': solve()
n,m=map(int,input().split());print('YNeos'[n!=m::2])
0
null
68,545,243,602,268
200
231
s = list(str(input())) q = int(input()) flag = 1 from collections import deque s = deque(s) for i in range(q): query = list(map(str, input().split())) if len(query) == 1: flag = 1-flag else: t, f, c = query if f == '1': if flag: s.appendleft(c) else: s.append(c) else: if flag: s.append(c) else: s.appendleft(c) s = list(s) if not flag: s.reverse() print(''.join(s))
def main(): S = list(input()) T = [] reverse = False n_q = int(input()) for i in range(n_q): q = input().split(" ") if q[0] == "1": reverse = not reverse elif q[0] == "2": f = q[1] c = q[2] if (f == "1" and not reverse) or (f == "2" and reverse): T.append(c) elif (f == "1" and reverse) or (f == "2" and not reverse): S.append(c) if reverse: S.reverse() ans = S + T elif not reverse: T.reverse() ans = T + S print("".join(ans)) main()
1
57,120,283,726,998
null
204
204
t = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [t[0]*a[0],t[1]*a[1]] d = [t[0]*b[0],t[1]*b[1]] if sum(c)==sum(d): print('infinity') exit() elif c[0]==d[0]: print('infinity') exit() if sum(d)>sum(c) and d[0]>c[0]: print(0) exit() elif sum(c)>sum(d) and c[0]>d[0]: print(0) exit() else: n = (c[0]-d[0])/(sum(d)-sum(c)) if n==int(n): print(2*int(n)) else: print(2*int(n)+1)
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) def main(): t1,t2 = map(int,ipt().split()) a1,a2 = map(int,ipt().split()) b1,b2 = map(int,ipt().split()) d1 = t1*(a1-b1) d2 = t2*(a2-b2) if d1*(d1+d2) > 0: print(0) elif d1+d2 == 0: print("infinity") else: dt = d1+d2 if abs(d1)%abs(dt): print(abs(d1)//abs(dt)*2+1) else: print(abs(d1)//abs(dt)*2) return None if __name__ == '__main__': main()
1
131,712,335,872,740
null
269
269
N = int(input()) A = list(map(int,input().split())) D = [0] * (10**6 + 1) A.sort() for i in range(N): D[A[i]] += 1 ans = 0 for i in range(1, 10**6+1): if D[i]: if D[i]==1: ans += 1 for j in range(i,A[-1]+1,i): D[j] = 0 print(ans)
def resolve(): x, y, z = list(map(int, input().split())) print(f'{z} {x} {y}') resolve()
0
null
26,122,890,343,526
129
178
from sys import stdin input = stdin.readline def rec(H): if H == 1: return 1 # print(H) return 1 + 2*rec(int(H/2)) def main(): H = int(input()) print(rec(H)) if(__name__ == '__main__'): main()
import math def pow(x, n): ans = 1 while n: if n % 2: ans *= x x *= x n >>= 1 return ans H = int(input()) #print(int(math.log2(H))) print(pow(2,int(math.log2(H))+1)-1)
1
80,463,974,903,572
null
228
228
import math x = int(input()) def lcm(x, y): return (x * y) // math.gcd(x, y) print(lcm(x, 360)//x)
a,b=map(int,input().split());print('a == b'if a==b else'a > b'if a>b else'a < b')
0
null
6,751,677,914,510
125
38
n = int(input()) debt = 100000 for i in range(n): debt *= 1.05 if debt % 1000 > 0: tmp = debt % 1000 debt -= tmp debt += 1000 print(int(debt))
s = input() l = ['SUN','MON','TUE','WED','THU','FRI','SAT'] i = 7-l.index(s) print(i)
0
null
66,297,929,275,490
6
270
def dfs(s): global ans if len(s) == n: cnt = 0 for i in range(q): if s[abcd[i][1]-1]-s[abcd[i][0]-1] == abcd[i][2]: cnt += abcd[i][3] ans = max(ans, cnt) return last = 1 if len(s) > 0: last = s[-1] for i in range(last, m+1): dfs(s+[i]) return n, m, q = map(int, input().split()) abcd = [list(map(int, input().split())) for i in range(q)] ans = 0 dfs([]) print(ans)
while True: n = list(map(int,input().split())) if(n[0] == n[1] == 0):break print(" ".join(map(str,sorted(n))))
0
null
13,998,452,108,410
160
43
import math a, b = map(int, input().split()) print(int((a*b)/math.gcd(a, b)))
def gcd(a, b): return b if a % b == 0 else gcd(b, a % b) def lcm(a, b): return a // gcd(a, b) * b a, b = map(int, input().split()) print(lcm(a, b))
1
113,684,814,127,488
null
256
256
import decimal def main(): A, B = map(decimal.Decimal,input().split()) if A == 0: return 0 else: AB = A*B return int(AB) print(main())
def main(istr, ostr): x, y = istr.readline().strip().split() a = int(x) b0, _, b1, b2 = y b0, b1, b2 = list(map(int, [b0, b1, b2])) c = a * (100 * b0 + 10 * b1 + b2) res = c // 100 print(res, file=ostr) if __name__ == "__main__": import sys main(sys.stdin, sys.stdout)
1
16,510,965,226,372
null
135
135
K = int(input()) [A,B] = list(map(int,input().split())) flag=0 for i in range(A,B+1): if i%K==0: flag=1 if flag==1: print('OK') else: print('NG')
def main(): K = int(input()) A,B = map(int,input().split()) for i in range(A,B+1): if i%K == 0: return('OK') return('NG') print(main())
1
26,417,380,127,130
null
158
158
N = int(input()) D = [] for i in range(N): s, t = input().split() D.append([s, int(t)]) m = input() n = 0 for i in range(N): if m in D[i]: n = i break print(sum([d[1] for d in D[n + 1:]]))
n = int(input()) s, t = [], [] for i in range(n): si, ti = input().split() ti = int(ti) s.append(si) t.append(ti) x = input() bit = 0 ans = 0 for i in range(n): if s[i] == x: bit = 1 else: if bit == 1: ans += t[i] print(ans)
1
97,094,471,159,040
null
243
243
sute = map(int,raw_input().split()) num = map(int,raw_input().split()) for i in range(len(num) - 1): print "%d" % num[len(num) - i - 1], print num[0]
if __name__ == '__main__': data_num = int(input()) data = [x for x in input().split(' ')] assert data_num == len(data), "invalid input" data.reverse() output = ' '.join(data) print(output)
1
972,704,136,640
null
53
53
import sys n = int(input()) SENTINEL = 10000000000 COMPAR = 0 A = list(map(int, sys.stdin.readline().split())) def merge(A, left, mid, right): global COMPAR n1 = mid - left n2 = right - mid L = A[left:mid] R = A[mid:right] L.append(SENTINEL) R.append(SENTINEL) j = 0 i = 0 for k in range(left, right): COMPAR += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) merge_sort(A, 0, n) print(' '.join(map(str, A))) print(COMPAR)
n = int(input()) S = list(map(int, input().split())) SENTINEL = 10 ** 9 + 1 count = 0 def merge(S, left, mid, right): L = S[left:mid] + [SENTINEL] R = S[mid:right] + [SENTINEL] i = j = 0 global count for k in range(left, right): if (L[i] <= R[j]): S[k] = L[i] i += 1 else: S[k] = R[j] j += 1 count += right - left def mergeSort(S, left, right): if(left + 1 < right): mid = (left + right) // 2 mergeSort(S, left, mid) mergeSort(S, mid, right) merge(S, left, mid, right) mergeSort(S, 0, n) print(*S) print(count)
1
117,230,403,190
null
26
26
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline import itertools from collections import Counter def main(): n,k = map(int, input().split()) h = list(map(int, input().split())) h.sort() if k == 0: print(sum(h)) else: h = h[:-k] print(sum(h)) if __name__=="__main__": main()
n, k = map(int, input().split()) h = list(map(int,input().split())) ans = 0 h = sorted(h,reverse=True) for i in range(k,n): ans += h[i] print(ans)
1
79,035,722,829,580
null
227
227
from collections import deque s = list(input()) q = int(input()) d = deque() for i in s: d.append(i) c = 1 for _ in range(q): t = list(input().split()) if t[0] == '1': c *= -1 else: if t[1] == '1': if c == 1: d.appendleft(t[2]) else: d.append(t[2]) else: if c == 1: d.append(t[2]) else: d.appendleft(t[2]) print(''.join(list(d)[::c]))
s = input() n = int(input()) hanten=0 s1="" s2="" for i in range(n): Q = input() if int(Q[0])==1: hanten+=1 elif int(Q[0])==2 : if hanten%2 == int(Q[2])-1 : s1= s1+Q[4] else: s2= s2+Q[4] s1 = s1[::-1] s = s1+s+s2 if hanten%2 : s = s[::-1] print(s)
1
57,468,386,667,236
null
204
204
import sys for line in sys.stdin: a,op,b=line.split() if op == '?': break print eval(line)
while 1: x = raw_input().split() a,op,b = int(x[0]),x[1],int(x[2]) if op == "+": print a+b elif op == "-": print a-b elif op == "/": print a/b elif op == "*": print a*b else: break
1
682,058,605,088
null
47
47
import math n = int(input()) x_buf = input().split() y_buf = input().split() x = [] y = [] for i in range(n): x.append(int(x_buf[i])) y.append(int(y_buf[i])) sum1 = 0 sum2 = 0 sum3 = 0 sum_inf = 0 max_inf = 0 for i in range(n): sum1 += abs(x[i] - y[i]) sum2 += abs(x[i] - y[i]) ** 2 sum3 += abs(x[i] - y[i]) ** 3 sum_inf = abs(x[i] - y[i]) if max_inf < sum_inf: max_inf = sum_inf d1 = sum1 d2 = math.sqrt(sum2) d3 = sum3 ** (1/3) d4 = max_inf print(d1) print(d2) print(d3) print(d4)
# coding: utf-8 # Here your code ! N=int(input()) dict={} for i in range(N): a,b=input().split() if a=="insert": dict[b]=i else: if b in dict: print("yes") else: print("no")
0
null
146,695,206,968
32
23
A = int(input()) B = int(input()) if A == 1 and B == 2: print('3') elif A == 1 and B == 3: print('2') elif A == 2 and B == 1: print('3') elif A == 2 and B == 3: print('1') elif A == 3 and B == 1: print('2') elif A == 3 and B == 2: print('1')
base_txt = input() base_txt_to_P = base_txt.replace("?","P") base_txt_to_D = base_txt.replace("?","D") index_count_base_txt_to_P = base_txt_to_P.count("D") + base_txt_to_P.count("PD") index_count_base_txt_to_D = base_txt_to_D.count("D") + base_txt_to_D.count("PD") if index_count_base_txt_to_P >index_count_base_txt_to_D: print(base_txt_to_P) else: print(base_txt_to_D)
0
null
64,800,164,980,740
254
140
N = int(input()) ans = 0 for n in range(1, N+1): if n % 3 == 0 and n % 5 == 0: pass elif n % 3 == 0: pass elif n % 5 == 0: pass else: ans += n % (10**9+7) print(ans)
N = int(input()) def S(x): return(x*(x+1)//2) print(S(N) - 3*S(N//3) - 5*S(N//5) + 15*S(N//15))
1
34,790,240,919,742
null
173
173
a = int ( input ( ) ) h = a // 3600 m = ( a // 60 ) % 60 d = a % 60 print ( "%s:%s:%s" % ( h, m, d ) )
from sys import stdin, stdout n, m = map(int, stdin.readline().strip().split()) if m>=n: print('unsafe') else: print('safe')
0
null
14,805,066,999,800
37
163
k,x = [int(x) for x in input().split()] if k * 500 >= x: print("Yes") else: print("No")
mod = 10**9 + 7 from collections import deque def main(): N = iip(False) K = iip(False) ret = solve(N, K) print(ret) def solve(N, K): strn = str(N) A = [] B = [] for i in range(len(strn), 0, -1): if strn[len(strn)-i] != "0": A.append(int(strn[len(strn)-i])) B.append(i) if K == 1: return 9*(B[0]-1) + A[0] if K == 2: if len(strn) < 2: return 0 ret = 0 ret += (B[0]-1) * (B[0]-2) // 2 * (9**2) #桁数がmaxじゃない場合 ret += (A[0]-1) * 9 * (B[0]-1) #桁数がmaxで先頭桁がmax以外の場合 if len(B) >= 2 and len(A) >= 2: ret += (B[1]-1) * 9 + A[1] #先頭桁がmaxの場合 return ret ret = 0 ret += (B[0] - 1) * (B[0] - 2) * (B[0] - 3) // 6 * 9**3 #桁数がmaxじゃない場合 ret += (A[0] - 1) * (B[0] - 1) * (B[0] - 2) // 2 * 9**2 #桁数がmaxで先頭桁がmaxじゃない場合 #以下、桁数はmaxで先頭桁はmaxとする if len(strn) < 3: return 0 if len(B) >= 2: ret += (B[1]-1) * (B[1]-2) // 2 * 9**2 #有効2桁目の桁数がmaxじゃない場合 if len(B) >= 2 and len(A) >= 2: ret += (A[1] - 1) * (B[1]-1) * 9 #有効2桁目の桁数がmaxで数字がmaxじゃない場合 if len(B) >= 3 and len(A) >= 3: ret += (B[2] - 1) * 9 + A[2] #有効2桁目,3桁目がmaxの場合 return ret #####################################################ライブラリ集ここから def split_print_space(s): print(" ".join([str(i) for i in s])) def split_print_enter(s): print("\n".join([str(i) for i in s])) def searchsorted(sorted_list, n, side): if side not in ["right", "left"]: raise Exception("sideはrightかleftで指定してください") l = 0 r = len(sorted_list) if n > sorted_list[-1]: #print(sorted_list) return len(sorted_list) if n < sorted_list[0]: return 0 while r-l > 1: x = (l+r)//2 if sorted_list[x] > n: r = x elif sorted_list[x] < n: l = x else: if side == "left": r = x elif side == "right": l = x if side == "left": if sorted_list[l] == n: return r - 1 else: return r if side == "right": if sorted_list[l] == n: return l + 1 else: return l def iip(listed): ret = [int(i) for i in input().split()] if len(ret) == 1 and not listed: return ret[0] return ret def soinsuu_bunkai(n): ret = [] for i in range(2, int(n**0.5)+1): while n % i == 0: n //= i ret.append(i) if i > n: break if n != 1: ret.append(n) return ret def conbination(n, r, mod, test=False): if n <=0: return 0 if r == 0: return 1 if r < 0: return 0 if r == 1: return n ret = 1 for i in range(n-r+1, n+1): ret *= i ret = ret % mod bunbo = 1 for i in range(1, r+1): bunbo *= i bunbo = bunbo % mod ret = (ret * inv(bunbo, mod)) % mod if test: #print(f"{n}C{r} = {ret}") pass return ret def inv(n, mod): return power(n, mod-2) def power(n, p): if p == 0: return 1 if p % 2 == 0: return (power(n, p//2) ** 2) % mod if p % 2 == 1: return (n * power(n, p-1)) % mod if __name__ == "__main__": main()
0
null
86,578,155,111,210
244
224
n,m = map(int,input().split()) if n % 2 == 1:ans = [[1+i,n-i] for i in range(n//2)] else:ans = [[1+i,n-i] for i in range(n//4)]+[[n//2+1+i,n//2-1-i] for i in range(n//2-n//4-1)] for i in range(m):print(ans[i][0],ans[i][1])
n = input() s = input().split() q = input() t = input().split() ans = 0 for c1 in t: for c2 in s: if c1 == c2: ans += 1 break print(ans)
0
null
14,261,490,440,990
162
22
N, K = map(int, input().split()) snuke = [False] * (N + 1) for _ in range(K): d = int(input()) A = list(map(int, input().split())) for a in A: snuke[a] = True ans = 0 for i in range(1, N + 1): if snuke[i] == False: ans += 1 print(ans)
#a=int(input()) #b,c=int(input()),int(input()) # c=[] # for i in b: # c.append(i) H,N = map(int,input().split()) f = list(map(int,input().split())) #j = [input() for _ in range(a)] # h = [] # for i in range(e1): # h.append(list(map(int,input().split()))) if sum(f)>=H: print("Yes") else: print("No")
0
null
51,297,109,329,620
154
226
# -*- coding:utf-8 def main(): N = int(input()) A = list(map(int, input().split())) insertionSort(A, N) print(' '.join(map(str, A))) def insertionSort(A, N): for i in range(1, N): print(' '.join(map(str, 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 if __name__ == '__main__': main()
h= int(input()) w = int(input()) n = int(input()) a = max(h,w) print((n+a-1)//a)
0
null
44,383,224,199,930
10
236
while True: s = raw_input().split() a = int(s[0]) b = int(s[2]) if s[1] == "?": break elif s[1] == '+': print a + b elif s[1] == '-': print a - b elif s[1] == '*': print a * b elif s[1] == '/': print a / b
import math while True: ins = input().split() x = int(ins[0]) op = ins[1] y = int(ins[2]) if op == "+": print(x + y) elif op == "-": print(x - y) elif op == "/": print(math.floor(x / y)) elif op == "*": print(x * y) elif op == "?": break else: break
1
697,095,677,800
null
47
47
def main(): import sys def input(): return sys.stdin.readline().rstrip() a,b,c = map(int, input().split()) import numpy as np if c-a-b >=0 and (c-a-b)**2-4*a*b > 0: print('Yes') else: print('No') if __name__ == '__main__': main()
m, d = input().split(' ') M, D = input().split(' ') if D == '1': print(1) else: print(0)
0
null
88,418,605,382,352
197
264
import sys from functools import reduce import math read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def gcd(*numbers): return reduce(math.gcd, numbers) K = int(readline()) ans = 0 for i in range(1,K+1): for j in range(1,K+1): for k in range(1,K+1): ans += gcd(i,j,k) print(ans)
from collections import defaultdict as dd from collections import deque import bisect import heapq def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): x = ri() steps = 0 bal = 100 while bal < x: steps += 1 bal += bal // 100 print (steps) mode = 's' if mode == 'T': t = ri() for i in range(t): solve() else: solve()
0
null
31,359,274,000,988
174
159
n = int(input()) ans = '' while n > 0: n -= 1 ans += chr(n % 26 + ord('a')) n = n // 26 print(ans[::-1])
n = int(input()) al = 26 alf='abcdefghijklmnopqrstuvwxyz' na = '' while n >26: na = alf[(n-1)%al]+na n = (n-1)//al na = alf[(n-1)%al]+na print(na)
1
11,901,848,990,526
null
121
121
# F - Bracket Sequencing N = int(input()) L = [] R = [] for _ in range(N): S = list(str(input())) len_S = len(S) L_d = 0 L_min_d = 0 R_d = 0 R_min_d = 0 for i in range(len_S): if S[i] == '(': L_d += 1 else: L_d -= 1 L_min_d = min(L_min_d, L_d) if S[len_S-i-1] == ')': R_d += 1 else: R_d -= 1 R_min_d = min(R_min_d, R_d) if L_d >= 0: L.append((L_d, L_min_d)) else: R.append((R_d, R_min_d)) L.sort(key=lambda x: x[1], reverse=True) R.sort(key=lambda x: x[1], reverse=True) ans = 'Yes' l_now = 0 for d, min_d in L: if l_now + min_d < 0: ans = 'No' break else: l_now += d r_now = 0 for d, min_d in R: if r_now + min_d < 0: ans = 'No' break else: r_now += d if l_now != r_now: ans = 'No' print(ans)
# -*- coding: utf-8 -*- """ Created on Tue Sep 8 20:45:37 2020 @author: liang """ def gcc(a,b): if b == 0: return a return gcc(b, a%b) A, B = map(int, input().split()) if A < B: A ,B = B, A print(A*B//gcc(A,B))
0
null
68,560,158,410,052
152
256
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N, M = map(int, readline().split()) AC = [False] * N cnt = [0] * N for _ in range(M): p, s = input().split() p = int(p) p -= 1 if s == "AC": AC[p] = True else: if not AC[p]: cnt[p] += 1 ans_a = 0 ans_p = 0 for i in range(N): if AC[i]: ans_a += 1 ans_p += cnt[i] print(ans_a, ans_p) if __name__ == '__main__': main()
k = int(input()) a, b=map(int, input().split()) c=0 for i in range(a, b+1): if i%k == 0: c += 1 else: pass if c == 0: print("NG") else: print("OK")
0
null
59,888,678,014,330
240
158
N = int(input()) x = [] for i in range(N): s, t = input().split() x.append([s, int(t)]) X = input() count = False ans = 0 for i in range(N): if count: ans += x[i][1] if x[i][0] == X: count = True print(ans)
def resolve(): a,b = map(int,input().split()) A = str(a)*b B = str(b)*a print(A if A<B else B) resolve()
0
null
90,905,659,389,420
243
232
import math r = float(raw_input()) l = 2 * math.pi * r S = math.pi * r ** 2 print "%f %f" %(S, l)
MOD = 1000000007 def fast_power(base, power): """ Returns the result of a^b i.e. a**b We assume that a >= 1 and b >= 0 Remember two things! - Divide power by 2 and multiply base to itself (if the power is even) - Decrement power by 1 to make it even and then follow the first step """ result = 1 while power > 0: # If power is odd if power % 2 == 1: result = (result * base) % MOD # Divide the power by 2 power = power // 2 # Multiply base to itself base = (base * base) % MOD return result n,k = [int(j) for j in input().split()] d = dict() ans = k d[k] = 1 sum_so_far = 1 for i in range(k-1, 0, -1): d[i] = fast_power(k//(i),n) for mul in range(i*2, k+1, i): d[i]-=d[mul] # d[i] = max(1, d[i]) ans+=(i*d[i])%MOD # if d[i]>1: # sum_so_far += d[i] print(ans%MOD)
0
null
18,696,614,660,800
46
176
n = int(input()) a = list(map(int, input().split())) b = set(a) a.sort() if len(a) != len(b): print("NO") else: print("YES")
from collections import Counter n=int(input()) a=list(map(int, input().split())) cnt=Counter(a) for k in cnt.values(): if k != 1: print('NO') break else: print('YES')
1
74,035,390,472,270
null
222
222
N, M, X = map(int, input().split()) Ca = [list(map(int, input().split())) for _ in range(N)] pattern = [] for i in range(2**N): lis = [] for j in range(N): if ((i>>j)&1): lis.append(Ca[j]) pattern.append(lis) cnt = [] for i in range(2**N): g = [0] * (M+1) for j in range(len(pattern[i])): for k in range(M+1): g[k] += pattern[i][j][k] if M==1 and g[1]< X: continue elif M>1 and min(g[1:M+1]) < X: continue else: cnt.append(g[0]) if len(cnt) ==0: print(-1) else: print(min(cnt))
n = int(input()) a = list(map(int, input().split())) INF = 10 ** 18 if n % 2: dp = [[[-INF,-INF,-INF] for i in range(2)] for i in range(n+1)] dp[0][0][0] = 0 # 初期化条件考える for i,v in enumerate(a): for j in range(2): if j: dp[i+1][0][0] = max(dp[i+1][0][0],dp[i][1][0]) dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][1][1]) dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][1][2]) else: dp[i+1][1][0] = max(dp[i+1][1][0],dp[i][0][0] + v) dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][0][0]) dp[i+1][1][1] = max(dp[i+1][1][1],dp[i][0][1] + v) dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][0][1]) dp[i+1][1][2] = max(dp[i+1][1][2],dp[i][0][2] + v) print(max(max(dp[n][0]),max(dp[n][1][1:]))) else: odd_sum,even_sum = 0,0 cumsum = [] for k,v in enumerate(a): if k % 2: odd_sum += v cumsum.append(odd_sum) else: even_sum += v cumsum.append(even_sum) ans = max(cumsum[n-2],cumsum[n-1]) for i in range(2,n,2): ans = max(ans, cumsum[i-2]+cumsum[n-1]-cumsum[i-1]) print(ans)
0
null
29,778,378,060,042
149
177
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline read = sys.stdin.read n,*a = [int(i) for i in read().split()] from itertools import accumulate if n%2==0: a1 = list(accumulate([0]+a[::2])) a2 = list(accumulate([0]+a[n-1::-2]))[::-1] #print(a1,a2) print(max(x+y for x,y in zip(a1,a2))) #elif n==3: print(max(a)) else: dp0 = [0]*(n+9) dp1 = [0]*(n+9) dp2 = [0]*(n+9) for i in range(n): if i%2==0: dp0[i] = dp0[i-2]+a[i] if i >= 2: dp2[i] = max(dp2[i-2],dp1[i-3],dp0[i-4]) + a[i] else: dp1[i] = max(dp1[i-2],dp0[i-3]) + a[i] #print(dp0) #print(dp1) #print(dp2) print(max(dp2[n-1],dp1[n-2],dp0[n-3]))
import sys n = int(input()) a = list(map(int, input().split())) if n%2 == 0: dp = [[-10**20 for _ in range(2)] for _ in range(n)] dp[0][0] = a[0] dp[0][1] = 0 dp[1][1] = a[1] for i in range(1, n): if i%2 == 0: dp[i][0] = dp[i-2][0] + a[i] dp[i][1] = max(dp[i-1][0], dp[i-1][1]) else: dp[i][0] = dp[i-1][0] if i > 1: dp[i][1] = max(dp[i-2][1] + a[i], dp[i-3][0] + a[i]) else: dp = [[-10**20 for _ in range(3)] for _ in range(n)] dp[0][0] = a[0] dp[0][1] = 0 dp[1][1] = a[1] dp[0][2] = 0 dp[1][2] = 0 dp[2][2] = a[2] for i in range(1, n): if i%2 == 0: if i < n-1: dp[i][0] = dp[i-2][0] + a[i] else: dp[i][0] = dp[i-1][0] dp[i][1] = max(dp[i-1][1], dp[i-2][0]) if i > 2: dp[i][2] = max(dp[i-2][2] + a[i], dp[i-4][0] + a[i], dp[i-3][1] + a[i]) else: dp[i][0] = dp[i-1][0] if i > 1: dp[i][1] = max(dp[i-2][0] + a[i], dp[i-2][1] + a[i]) dp[i][2] = max(dp[i-1][2], dp[i-2][1], dp[i-3][0]) print(max(dp[n-1]))
1
37,487,473,846,254
null
177
177
from sys import stdin, setrecursionlimit def main(): input = stdin.readline n = int(input()) s_arr = [] t_arr = [] for _ in range(n): s, t = list(map(str, input().split())) t = int(t) s_arr.append(s) t_arr.append(t) x = input()[:-1] print(sum(t_arr[s_arr.index(x) + 1:])) if __name__ == "__main__": setrecursionlimit(10000) main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): A, B = map(int, readline().split()) if A < 10 and B < 10: print(A * B) else: print(-1) return if __name__ == '__main__': main()
0
null
127,831,851,981,900
243
286
def main(): N = int(input()) S = input() ans = 0 for i in range(len(S) - 1): if S[i:i + 3] == 'ABC': ans += 1 print(ans) main()
n=int(input()) s=list(input()) flg=0 ans=0 for i in range(n): if s[i]=="A": flg=1 elif s[i]=="B" and flg==1: flg=2 elif s[i]=="C" and flg==2: ans=ans+1 flg=0 else: flg=0 print(ans)
1
99,696,456,513,212
null
245
245
#!/usr/bin/env python3 # N:全日数 K:働く日数 C:働いた日からその後働かない日数 N, K, C = map(int, input().split()) S = input() # num回目に働く日はl[num-1]日目以降 l = [] num = 0 i = 0 while num < K: if S[i] == "o": l.append(i) num += 1 i += C + 1 else: i += 1 # num回目に働く日はl[num-1]日目以前 r = [] num = 0 i = N - 1 while num < K: if S[i] == "o": r.append(i) num += 1 i -= C + 1 else: i -= 1 r.reverse() for i in range(K): if l[i] == r[i]: print(l[i] + 1)
N = int(input()) l = input().split() p = [] for i in range(N): p.append((int(l[i]),i)) p.sort() s = N ans = 0 for i in range(N): (a,b) = p[i] if b < s: ans += 1 s = b print(ans)
0
null
63,030,471,877,216
182
233
import copy import random import sys import time from collections import deque t1 = time.time() readline = sys.stdin.buffer.readline global NN NN = 26 def evaluate(D, C, S, out, k): score = 0 last = [0 for _ in range(NN)] for d in range(len(out)): last[out[d]] = d + 1 for i in range(NN): score -= (d + 1 - last[i]) * C[i] score += S[d][out[d]] for d in range(len(out), min(D, len(out) + k)): for i in range(NN): score -= (d + 1 - last[i]) * C[i] return score def compute_score(D, C, S, out): score = 0 last = [0 for _ in range(NN)] for d in range(len(out)): p = out[d] last[p] = d + 1 last[out[d]] = d + 1 for i in range(NN): score -= (d + 1 - last[i]) * C[i] score += S[d][out[d]] return score def solve(D, C, S, k): out = deque() for _ in range(D): max_score = -10 ** 8 best_i = 0 for i in range(NN): out.append(i) score = evaluate(D, C, S, out, k) if max_score < score: max_score = score best_i = i out.pop() out.append(best_i) return out # 1箇所ランダムに変える def random_change(D, C, S, out, score): new_out = copy.deepcopy(out) d = random.randrange(0, D) new_out[d] = random.randrange(0, NN) new_score = compute_score(D, C, S, new_out) if new_score > score: score = new_score out = new_out return out, score # N箇所ランダムに変える def random_changeN(D, C, S, out, score): N = 2 new_out = copy.deepcopy(out) for _ in range(N): d = random.randrange(0, D) new_out[d] = random.randrange(0, NN) new_score = compute_score(D, C, S, new_out) if new_score > score: score = new_score out = new_out return out, score # 2つswap def random_swap2(D, C, S, out, score): d1 = random.randrange(0, D - 1) d2 = random.randrange(d1 + 1, min(d1 + 16, D)) new_out = copy.deepcopy(out) new_out[d1], new_out[d2] = out[d2], out[d1] new_score = compute_score(D, C, S, out) if new_score > score: score = new_score out = new_out return out, score # 3つswap def random_swap3(D, C, S, out, score): d1 = random.randrange(0, D - 1) d2 = random.randrange(d1 + 1, min(d1 + 8, D)) d3 = random.randrange(max(d1 - 8, 0), d1 + 1) new_out = copy.deepcopy(out) new_out[d1], new_out[d2], new_out[d3] = out[d2], out[d3], out[d1] new_score = compute_score(D, C, S, out) if new_score > score: score = new_score out = new_out return out, score def main(): D = int(readline()) C = list(map(int, readline().split())) S = [list(map(int, readline().split())) for _ in range(D)] # ランダムな初期値 # out = [random.randrange(0, NN) for _ in range(D)] # 貪欲法で初期値を決める # k = 18 # kを大きくして,局所解から遠いものを得る k = 26 # kを大きくして,局所解から遠いものを得る out = solve(D, C, S, k) # 初期値を数カ所変える # np = 0.2 # 変えすぎ? # np = 0.1 np = 0.05 n = int(D * np) queue = [random.randrange(0, D) for _ in range(n)] for q in queue: out[q] = random.randrange(0, NN) score = compute_score(D, C, S, out) for cnt in range(10 ** 10): bl = [random.randint(0, 1) for _ in range(5)] for b in bl: if b: out, score = random_change(D, C, S, out, score) # out, score = random_changeN(D, C, S, out, score) else: # out, score = random_swap2(D, C, S, out, score) out, score = random_swap3(D, C, S, out, score) t2 = time.time() if t2 - t1 > 1.85: break ans = [str(i + 1) for i in out] print("\n".join(ans)) main()
n = int(input()) for i in range(n): a = list(map(int, input().split())) m = max(a) b = sum([i**2 for i in a if i != m]) if (m**2 == b): print("YES") else: print("NO")
0
null
4,780,788,425,672
113
4
a, b, c, d = map(int, input().split()) flg = False while True: if c - b <= 0: flg = True break if a - d <= 0: flg = False break a -= d c -= b print('Yes' if flg else 'No')
a, b, c, d = list(map(int, input().split())) turn = True while True: if turn: c -= b if c <= 0: print("Yes") import sys sys.exit() else: a -= d if a <= 0: print("No") import sys sys.exit() turn ^= True
1
29,772,072,878,668
null
164
164
import sys MOD = 10**9+7 s = int(input()) dp = [0, 0, 0, 1] ruisekiwa = [0, 0, 0, 0] if s < 3: print(0) sys.exit() for i in range(4, s+1): dp.append(1 + ruisekiwa[i-1]) ruisekiwa.append(dp[i-2] + ruisekiwa[i-1]) # print(dp) # print(ruisekiwa) print(dp[-1] % MOD)
S=int(input()) a = [0]*(2000+1) a[3]=1 for i in range(4, S+1): a[i] = a[i-3] + a[i-1] mod=10**9+7 print(a[S]%mod)
1
3,290,710,828,118
null
79
79
n = int(input()) graph = [[] for _ in range(n)] for i in range(n - 1): a, b = map(int, input().split()) graph[a - 1].append((b - 1, i)) graph[b - 1].append((a - 1, i)) ans = [0] * (n - 1) from collections import deque d = deque() d.append([0, -1]) while d: point, prev = d.popleft() color = 1 if prev != 1 else 2 for a, index in graph[point]: if ans[index] == 0: ans[index] = color d.append([a, color]) color += 1 if prev != color + 1 else 2 print(max(ans)) print(*ans, sep='\n')
N = int(input()) edges = [[] for _ in range(N)] for i in range(N - 1): fr, to = map(lambda a: int(a) - 1, input().split()) edges[fr].append((i, to)) edges[to].append((i, fr)) ans = [-1] * (N - 1) A = [set() for _ in range(N)] st = [0] while st: now = st.pop() s = 1 for i, to in edges[now]: if ans[i] != -1: continue while s in A[now]: s += 1 ans[i] = s A[to].add(s) A[now].add(s) st.append(to) print(max(ans)) print(*ans, sep="\n")
1
136,394,726,854,448
null
272
272
n, d = map(int, input().split(" ")) p = [] ans = 0 for i in range(n): p.append(list(map(int, input().split(" ")))) for i, [x, y] in enumerate(p): if(x > d or y > d): continue if(x**2 + y**2 <= d**2): ans += 1 print(ans)
import fractions from sys import stdin def main(): n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) sa = set(a) lcm = 1 for ai in sa: lcm = (ai * lcm) // fractions.gcd(ai, lcm) ans = 0 for ai in a: ans += lcm // ai ans %= 10 ** 9 + 7 print(ans) if __name__ == "__main__": main()
0
null
46,850,961,656,082
96
235
while True: a, b, c = map(int, raw_input().split()) if (a == -1) and (b == -1) and (c == -1): break if (a == -1) or (b == -1): print "F" elif (a + b) >= 80: print "A" elif (a + b) >= 65: print "B" elif (a + b) >= 50: print "C" elif (a + b) < 30: print "F" elif c >= 50: print "C" else: print "D"
ans = '' while True: m, f, r = map(int, input().split(' ')) if (m == -1 and f == -1) and r == -1: break else: x = m + f if (m == -1) or (f == -1): ans += 'F\n' elif x >= 80: ans += 'A\n' elif x >= 65: ans += 'B\n' elif x >= 50: ans += 'C\n' elif x >= 30: if r >= 50: ans += 'C\n' else: ans += 'D\n' else: ans += 'F\n' if ans != '': print(ans[:-1])
1
1,228,034,312,438
null
57
57
r, c = map(int, input().split()) sum_row = [] for i in range(c + 1): sum_row.append(0) for i in range(r): tmp_row = tuple(map(int, input().split())) tmp_row_sum = sum(tmp_row) tmp_row += tmp_row_sum, print(" ".join(map(str, tmp_row))) for j in range(c + 1): sum_row[j] += tmp_row[j] print(" ".join(map(str, sum_row)))
def main(): nums = list(map(int, input().split(' '))) directs = input() d = Dice(nums) for c in directs: if 'N' == c: d.toN() if 'S' == c: d.toS() if 'E' == c: d.toE() if 'W' == c: d.toW() print(d.top) class Dice: def __init__(self, labels): self.labels = labels self._top = 0 self._front = 1 self._right = 2 self._left = 3 self._back = 4 self._bottom = 5 def toN(self): self._back, self._top, self._front, self._bottom = self._top, self._front, self._bottom, self._back return self def toS(self): self._back, self._top, self._front, self._bottom = self._bottom, self._back, self._top, self._front return self def toW(self): self._left, self._top, self._right, self._bottom = self._top, self._right, self._bottom, self._left return self def toE(self): self._left, self._top, self._right, self._bottom = self._bottom, self._left, self._top, self._right return self def get_top(self): return self.labels[self._top] top = property(get_top) if __name__ == '__main__': main()
0
null
795,173,202,912
59
33
x = int(input()) def answer(x: int) -> int: ans = 1000 * (x // 500) x %= 500 ans += 5 * ((x - 500 * (x // 500)) // 5) return ans print(answer(x))
A, B=input().split() a=int(A) R,E=B.split('.') while len(E)<2: E=E+0 c=int(R+E) p=str(a*c) if len(p)<=2: print(0) else: print(p[0:len(p)-2])
0
null
29,604,536,236,160
185
135
a = int(input()) b = input().split() c = "APPROVED" for i in range(a): if int(b[i]) % 2 == 0: if int(b[i]) % 3 == 0 or int(b[i]) % 5 == 0: c = "APPROVED" else: c = "DENIED" break print(c)
N = int(input()) A = list(map(int, input().split())) flag = True for i in range(N): if A[i]%2 == 0: if A[i]%3!=0 and A[i]%5!=0: flag = False if flag: print("APPROVED") else: print("DENIED")
1
68,967,312,435,362
null
217
217
X, N = map(int,input().split()) p = list(map(int,input().split())) i = 0 while True: if not X - i in p: print(X - i) break if not X + i in p: print(X + i) break i += 1
N, M = map(int, input().split()) x = list(map(int, input().split())) #print(N) #print(M) #print(x) def hantei(number_1, list_1): for a in range(101): a_plus = number_1 + a a_minus = number_1 - a if a_minus not in list_1: return a_minus break elif a_plus not in list_1: return a_plus break print(hantei(N,x))
1
14,129,561,849,832
null
128
128
n = int(input()) ren = 0 for i in range(n): a, b = (int(x) for x in input().split()) if a == b: ren += 1 elif ren >= 3: continue else: ren = 0 if ren >= 3: print("Yes") else: print("No")
counter = int(input()) result_flg = False fir_fir, fir_sec = map(int, input().split()) sec_fir, sec_sec = map(int, input().split()) for i in range(2, counter): thi_fir, thi_sec = map(int, input().split()) if fir_fir == fir_sec: if sec_fir == sec_sec: if thi_fir == thi_sec: result_flg = True break # reset content fir_fir = sec_fir fir_sec = sec_sec sec_fir = thi_fir sec_sec = thi_sec if result_flg == True: print('Yes') else: print('No')
1
2,527,144,699,934
null
72
72
import sys ERROR_INPUT = 'input is invalid' ERROR_INPUT_NOT_UNIQUE = 'input is not unique' def main(): S = get_input1() T = get_input2() count = 0 for t in T: for s in S: if t == s: count += 1 break print(count) def get_input1(): n = int(input()) if n > 10000: print(ERROR_INPUT) sys.exit(1) li = [] for x in input().split(' '): if int(x) < 0 or int(x) > 10 ** 9: print(ERROR_INPUT) sys.exit(1) li.append(x) return li def get_input2(): n = int(input()) if n > 500: print(ERROR_INPUT) sys.exit(1) li = [] for x in input().split(' '): if int(x) < 0 or int(x) > 10 ** 9: print(ERROR_INPUT) sys.exit(1) elif int(x) in li: print(ERROR_INPUT_NOT_UNIQUE) sys.exit(1) li.append(x) return li main()
a, b, c, k = map(int,input().split()) ans = 0 if k - a > 0: ans = ans + a k = k - a if k - b > 0: k = k -b ans = ans - k else: ans = ans + k print(ans)
0
null
11,002,924,006,908
22
148
def main(): N, R = map(int, input().split()) X = R + max(0, 100 * (10 - N)) print(X) if __name__ == '__main__': main()
import sys sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline def solve(): n, r = map(int,input().split()) if 10 > n: print(r + (100 * (10 - n))) else: print(r) if __name__ == '__main__': solve()
1
63,577,679,602,912
null
211
211
import numpy as np N, K = map(int, input().split()) A = sorted(list(map(int, input().split()))) F = sorted(list(map(int, input().split())), reverse=True) A = np.array(A, np.int64) F = np.array(F, np.int64) Asum = sum(A) def test(X): return (Asum - np.minimum(A, X//F).sum() <= K) l = -1 r = 10**12 while (l + 1 < r): mid = (l + r) // 2 if test(mid): r = mid else: l = mid ans = r print(ans)
N,K=list(map(int,input().split())) A=sorted(list(map(int,input().split()))) F=sorted(list(map(int,input().split())),reverse=True) ok=10**12 ng=0 while abs(ok-ng)>0: center=(ok+ng)//2 cnt=0 for i in range(N): ap=center//F[i] cnt+=max(0,A[i]-ap) if K<cnt: ng=center+1 break else: ok=center print(ok)
1
164,921,823,724,028
null
290
290
a,b,c,d=map(float,input().split()) import math x=math.sqrt((c-a)**2+(d-b)**2) print("{:.5f}".format(x))
import math x1, y1, x2, y2 = map(float, input().split()) dx = x1 - x2 dy = y1 - y2 d = math.hypot(dx, dy) print(d)
1
156,092,955,018
null
29
29
# https://atcoder.jp/contests/abc150/tasks/abc150_d import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() # GCD -- START -- def gcd(x,y): while y: x,y=y,x%y return x # GCD --- END --- # LCM -- START -- def lcm(x,y): return x*y//gcd(x,y) # LCM --- END --- def f(x): a=0 while x%2==0: x//=2 a+=1 return a def main(): n,m=LI() _l=LI() l=[x//2 for x in _l] t=f(l[0]) for i in range(n): b=l[i] if t!=f(b): return 0 l[i]>>=t m>>=t _lcm=1 for x in l: _lcm=lcm(_lcm,x) if _lcm>m: return 0 # print(m,_lcm) m//=_lcm return (m+1)//2 # main() print(main())
N=int(input()) S=input() ans="" for i in range(len(S)): ans+=chr(ord("A")+(ord(S[i])-ord("A")+N)%26) print(ans)
0
null
118,011,282,197,332
247
271
# ??\????????? N = int(input()) r = [int(input()) for i in range(N)] # ?????§????¨???? max_profit = (-1) * (10 ** 9) min_value = r[0] for j in range(1, len(r)): max_profit = max(max_profit, r[j] - min_value) min_value = min(min_value, r[j]) print(max_profit)
line = int(input()) nums = [] for n in range(line): nums.append(int(input())) # res = nums[1] - nums[0] # for i in range(line): # for j in range(i+1, line): # dif = nums[j] - nums[i] # res = dif if dif > res else res maxd = nums[1] - nums[0] minv = nums[0] for j in range(1, line): maxd = max(maxd, nums[j] - minv) minv = min(minv, nums[j]) print(maxd)
1
11,997,625,562
null
13
13