code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
N = int(input()) A = {} for i in range(N): s = input() if s in A: A[s] += 1 else: A[s] = 1 s_max = max(A.values()) for j in sorted(k for k in A if A[k] == s_max): print(j)
N=int(input()) A=list(map(int,input().split())) D={} for i in range(N): if not(A[i] in D): D[A[i]]=0 D[A[i]]+=1 ans=0 for i in D: ans+=(D[i]*(D[i]-1))//2 for k in range(N): print(ans-D[A[k]]+1)
0
null
58,853,929,118,348
218
192
import sys def main(): input = sys.stdin.buffer.readline a, b, c = map(int, input().split()) if len(set([a, b, c])) == 2: print("Yes") else: print("No") if __name__ == "__main__": main()
arr = list(map(int, input().split())) arr.sort() if (arr[0] == arr[1]) and (arr[2] != arr[1]): print("Yes") elif (arr[1] == arr[2]) and (arr[0] != arr[1]): print("Yes") else: print("No")
1
68,283,282,419,498
null
216
216
import itertools as it N=int(input()) W=list(range(1,N+1)) c1=-1 c2=-1 c=0 L=tuple(map(int,input().split())) M=tuple(map(int,input().split())) if L==M: print(0) exit() for i in it.permutations(W,N): c+=1 if i==L: c1=c elif i==M: c2=c print(abs(c1-c2))
import itertools n = int(input()) a = list() for i in range(1,n+1): a.append(i) b = list(input().split()) c = list(input().split()) for i in range(0,n): b[i]=int(b[i]) c[i]=int(c[i]) cnt = 1 for i in itertools.permutations(a): #print(i) if(tuple(b)==i): cnta = cnt #print('p is '+str(cnta)) if(tuple(c)==i): cntb = cnt #print('q is '+str(cntb)) cnt +=1 print(abs(cnta-cntb))
1
100,372,488,214,528
null
246
246
# coding:UTF-8 import sys from math import factorial MOD = 10 ** 9 + 7 INF = 10000000000 def main(): # ------ 入力 ------# n = int(input()) # 数字 # 定数行入力 x = n dList = [list(map(int, input().split())) for _ in range(x)] # スペース区切り連続数字(行列) # ------ 処理 ------# flg = 1 for i in range(n-2): if dList[i][0] == dList[i][1]: if dList[i+1][0] == dList[i+1][1]: if dList[i+2][0] == dList[i+2][1]: flg = 0 # ------ 出力 ------# if flg == 0: print("Yes") else: print("No") if __name__ == '__main__': main()
if __name__ == '__main__': n = input() ans = int(n[-1]) if ans in [2,4,5,7,9]: print("hon") elif ans in [0,1,6,8]: print("pon") else: print("bon")
0
null
10,829,977,903,252
72
142
n = int(input()) a = list(map(int,input().split())) s = sum(a) aa = [a[i]*a[i] for i in range(n)] s2 = sum(aa) print((s**2 - s2) //2%(10**9+7))
n = int(input()) a = list(map(int, input().split())) b = [x*x for x in a] #print(a) #print(b) s = sum(a) s = s * s - sum(b) s = s // 2 s = s % 1000000007 print(s) # (a+b+c)^2 = a^2 + b^2 + c^2 + 2ab + 2ac + 2bc
1
3,815,722,788,680
null
83
83
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): h, n = map(int, input().split()) A = list(map(int, input().split())) print("Yes" if h <= sum(A) else "No") if __name__ == '__main__': resolve()
H, N = map(int, input().split()) A = [int(x) for x in input().split()] AA = sum(A) if AA >= H: print("Yes") else: print("No")
1
78,327,520,732,732
null
226
226
hp, count_skills = map(int, input().split()) a = map(int, input().split()) skills_list = list(a) for skill in skills_list: hp -= skill if hp <= 0: print('Yes') break if hp >= 1: print('No')
H, N = [int(v) for v in input().rstrip().split()] A = [int(v) for v in input().rstrip().split()] total = sum(A) r = 'Yes' if H <= total else 'No' print(r)
1
77,850,951,503,752
null
226
226
a, b = input().split() if a < b: print(a * int(b)) elif a > b: print(b * int(a)) else: print(a * int(a))
print(1&~int(input()))
0
null
43,449,221,796,838
232
76
from sys import stdin input = stdin.readline K = int(input()) print("ACL" * K)
import sys input = sys.stdin.readline H, W = map(int, input().split()) s = [input().rstrip() for _ in range(H)] dp = [[1000]*W for _ in range(H)] if s[0][0] == '#': dp[0][0] = 1 else: dp[0][0] = 0 for j in range(W): for i in range(H): if i <= H - 2: if s[i][j] == '.' and s[i+1][j] == '#': dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1) else: dp[i+1][j] = min(dp[i+1][j], dp[i][j]) if j <= W - 2: if s[i][j] == '.' and s[i][j+1] == '#': dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1) else: dp[i][j+1] = min(dp[i][j+1], dp[i][j]) print(dp[H-1][W-1])
0
null
25,923,741,009,280
69
194
import math a=float(input()) print("{0:.9f} {1:.9f}".format(a*a*math.pi,a*2*math.pi))
r = float(input()) l = 2*r*3.14159265358979 are = r*r*3.14159265358979 print("{0:.8f} {1:.8f}".format(are, l))
1
647,929,771,048
null
46
46
a,b,c,d=map(int,input().split()) prd=[a*c,a*d,b*c,b*d] if (a<0<b or c<0<d) and max(prd)<0: print(0) else: print(max(prd))
arr = [int(x) for x in input().split()] print( max( max(arr[0]*arr[2], arr[0]*arr[3]), max(arr[1]*arr[2], arr[1]*arr[3]) ))
1
3,045,646,062,382
null
77
77
N = int(input()) A = list(map(int,input().split())) x = True for i in range(N): if A[i] % 2 != 0: continue if not (A[i]%3==0 or A[i]%5==0): x = False if x: print("APPROVED") else: print("DENIED")
n = list(map(int,input().split())) a = list(map(int,input().split())) ans = 'APPROVED' for i in a: if i % 2 == 0: if i % 3 != 0 and i % 5 != 0: ans = 'DENIED' break print(ans)
1
69,180,901,168,570
null
217
217
A,B,M=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) m=10**6 for i in range(M): x,y,z=map(int,input().split()) m=min(a[x-1]+b[y-1]-z,m) print(min(m,min(a)+min(b)))
input_line = int(input()) if input_line > 1 : count = 10**input_line - 8**input_line - (9**input_line - 8**input_line) * 2 print(count % (10**9 + 7)) else : print(0)
0
null
28,689,661,596,098
200
78
n, m, l = map(int, input().split()) A, B = [], [] C = [[0 for i in range(l)] for j in range(n)] for i in range(n): A.append([int(i) for i in input().split()]) for i in range(m): B.append([int(i) for i in input().split()]) B = list(zip(*B)) for i, line_A in enumerate(A): for j, line_B in enumerate(B): for x, y in zip(line_A, line_B): C[i][j] += x * y for line in C: for i, x in enumerate(line): if i == l - 1: print(x) else: print(x, end=" ")
n, m, ll = map(int, input().split()) a = [] b = [] for i in range(n): a.append(list(map(int, input().split()))) for i in range(m): b.append(list(map(int, input().split()))) for i in range(n): prt = [] for j in range(ll): s = 0 for k in range(m): s += a[i][k] * b[k][j] prt.append(s) print(*prt)
1
1,430,260,338,010
null
60
60
print((1000 - (int(input()) % 1000)) % 1000)
# encoding:utf-8 while True: input = map(int, raw_input().split()) x, y = input if x == y == 0: break input.sort() print(" ".join(map(str, input)))
0
null
4,450,713,041,158
108
43
how_many = int(input()) results = [] index = 0 numbers = {index+1:int(item) for index,item in zip(range(how_many),input().split())} for key_value in numbers.items(): if key_value[0] % 2 == 1 and key_value[1] % 2 == 1: results.append(True) print(len(results))
N = int(input()) A = map(int, input().split()) cnt = 0 for i, a in enumerate(A): if ((i + 1) * a) % 2: cnt += 1 print(cnt)
1
7,816,980,028,352
null
105
105
def my_eval(ar,str): res = True n = len(str) # print(n) # print("start") for i in range(n): # print(i) if(ar[str[i][0]] == 1): # print(str[i][0]) # print(str[i][1]) # print(str[i][2]) # print(ar[str[i][1]-1]) # print(ar[str[i][1]-1] == str[i][2]) # print(ar) # print() if(ar[str[i][1]] != str[i][2]): res = False # print("end") # print() return res if __name__ == "__main__": # 全探索 n = int(input()) str = [] for i in range(n): a = int(input()) for j in range(a): x = list(map(int,input().split())) x.insert(0,i+1) str.append(x) ar = [0] * (n+1) res = 0 # print(str) count = 0 for i in range(2**n): count = 0 for j in range(n): if(i >> j & 1 == 1): ar[j+1] = 1 count += 1 else: ar[j+1] = 0 # print(ar) if(my_eval(ar,str)): res = max(res,count) print(res)
n = int(input()) memo = {} for i in range(n): man_idx = i count = int(input()) comment = [ list(map(int,input().split())) for _ in range(count) ] memo[man_idx] = comment ans = 0 for i in range(2**n): sub_ans = 0 is_true = True for j in range(n): if i >> j & 1: sub_ans += 1 for x, y in memo[j]: if (i >> (x-1) & 1) != int(y): is_true = False break if is_true: ans = max(sub_ans, ans) print(ans)
1
121,884,159,452,220
null
262
262
H,W,K = map(int,input().split()) S = [input() for _ in range(H)] ans = 10**10 for i in range(2**(H-1)): # iはbit rel = [0 for h in range(H)] a,b = 0,0 for h in range(H-1): if i>>h&1: b += 1 rel[h+1] = b a += b cnt = [0 for j in range(b+1)] for w in range(W): for h in range(H): if S[h][w] == '1': cnt[rel[h]] += 1 OK = True for j in range(b+1): if cnt[j] > K: OK = False break if OK: continue a += 1 cnt = [0 for j in range(b+1)] for h in range(H): if S[h][w] == '1': cnt[rel[h]] += 1 OK2 = True for j in range(b+1): if cnt[j] > K: OK2 = False break if OK2: continue a = 10**10 break ans = min(ans,a) print(ans)
import sys readline = sys.stdin.readline N,X,Y = map(int,readline().split()) X -= 1 Y -= 1 ans = [0] * N for i in range(N - 1): for j in range(i + 1, N): val = min(abs(i - j),abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X)) ans[val] += 1 for i in range(1, len(ans)): print(ans[i])
0
null
46,365,488,232,210
193
187
n = int(input()) a = [] for i in range(1, n+1): if i%3 == 0 or i%5 == 0: continue else: a.append(i) print(sum(a))
N=int(input()) ans=0 for i in range(N+1): if i%3!=0 and i%5!=0: ans+=i print(ans)
1
34,673,551,353,572
null
173
173
m=input().split() M=input().split() if int(M[0]) - int(m[0]) == 1: print('1') else: print('0')
h = -1 w = -1 while (h != 0) and (w != 0): input = map(int, raw_input().split(" ")) h = input[0] w = input[1] if (h == 0 and w == 0): break i = 0 j = 0 line = "" while j < w: line += "#" j += 1 while i < h: print line i += 1 print ""
0
null
62,440,539,670,570
264
49
x, y, z = [int(i) for i in input().split(" ")] print(z, x, y)
def ABC_swap(): # 入力 X, Y, Z = map(int, input().split()) A = X B = Y C = Z # 入れ替え処理 A, B = B, A A, C = C, A # 表示 print(A, B, C) ABC_swap()
1
38,002,315,570,918
null
178
178
N = int(input()) A = list(map(int,input().split())) R, B, G = 0, 0, 0 ans = 1 for a in A: if R == a: if B == a and G == a: ans *= 3 elif B == a or G == a: ans *= 2 else: ans *= 1 R += 1 elif B == a: if G == a: ans *= 2 else: ans *= 1 B += 1 elif G == a: ans *= 1 G += 1 else: print(0) exit() ans %= 10**9+7 print(ans)
MOD = 10**9+7 n = int(input()) a = list(map(int, input().split())) cnt = [0 for _ in range(n)] ans = 1 for x in a: if x > 0: ans *= cnt[x-1] - cnt[x] else: ans *= 3 - cnt[0] cnt[x] += 1 ans %= MOD print(ans)
1
130,454,067,647,136
null
268
268
while True: a, b = map(int, input().split()) if a == 0 and b == 0: break; for i in range(0, a): if i % 2 == 0: print(("#." * int((b + 1) / 2))[:b]) else: print((".#" * int((b + 1) / 2))[:b]) print("")
while True: h, w = map(int, input().split()) if h == w == 0: break for c in ['\n' if y == w else '#' if (x+y) % 2 == 0 else '.' for x in range(0,h) for y in range(0, w + 1)]: print(c, end='') print('')
1
873,329,840,296
null
51
51
x=input() lst=x.split(" ") print(int(lst[0])*int(lst[1]))
while True: s = input() if s == "-": exit() m = int(input()) for i in range(m): h = int(input()) s = s[h:] + s[:h] print(s)
0
null
8,843,584,202,784
133
66
s=[input() for _ in range(int(input()))] def c(b):return str(s.count(b)) x=' x ' n='\n' a='AC' w='WA' t='TLE' r='RE' print(a+x+c(a)+n+w+x+c(w)+n+t+x+c(t)+n+r+x+c(r))
n = int(input()) cnt = [] for i in range(n): s = input() cnt.append(s) print("AC x ", cnt.count('AC')) print("WA x ", cnt.count("WA")) print("TLE x ", cnt.count("TLE")) print("RE x ", cnt.count("RE"))
1
8,735,204,618,228
null
109
109
N =int(input()) S, T = input().split() for i in range(N): print(S[i], end="") print(T[i], end="") print()
def answer(n: int, s: str, t: str) -> str: new_str = '' for i in range(n): new_str += f'{s[i]}{t[i]}' return new_str def main(): n = int(input()) s, t = input().split() print(answer(n, s, t)) if __name__ == '__main__': main()
1
112,311,019,342,700
null
255
255
N=int(input()) S=input() cnt=0 for i in range(N): left=i-1 right=i+1 while 0<=left and right<N: if S[i]!=S[left] and S[i]!=S[right] and S[left]!=S[right]: cnt+=1 left-=1 right+=1 x=S.count('R') y=S.count('G') z=S.count('B') print(x*y*z-cnt)
N = int(input()) S = input() R = [] G = [] B = [] for i in range(N): if S[i] == 'R': R.append(i+1) elif S[i] == 'G': G.append(i+1) elif S[i] == 'B': B.append(i+1) lenb = len(B) cnt = 0 for r in R: for g in G: up = max(r, g) down = min(r, g) diff = up - down chk = 0 if up + diff <= N: if S[up+diff-1] == 'B': chk += 1 if down-diff >= 1: if S[down-diff-1] == 'B': chk += 1 if diff%2 == 0: if S[int(up-diff/2-1)] == 'B': chk += 1 cnt += lenb - chk print(cnt)
1
36,196,547,852,540
null
175
175
n,k = map(int,input().split()) # Function of Combination mod M # set n >= max p expected M = 10**9+7 if k >= n-1: fac = [1]+[0]*(2*n-1) for i in range(1,2*n): fac[i] = fac[i-1]*i %M comb = lambda p,q:(fac[p]*pow(fac[q],M-2,M)*pow(fac[p-q],M-2,M))%M y = comb(2*n-1,n-1) else: y = 1 c1,c2=1,1 for i in range(1,k+1): p = pow(i,M-2,M) c1 = c1*(n+1-i)*p%M c2 = c2*(n-i)*p%M y += c1*c2%M # y = (y+c1*c2)%M print(y%M)
import sys sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python import math from copy import copy, deepcopy from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意 from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする from functools import lru_cache#pypyでもうごく #@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率 def input(): return sys.stdin.readline()[:-1] def printl(li): print(*li, sep="\n") def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def matmat(A,B): K,N,M=len(B),len(A),len(B[0]) return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] def matvec(M,v): N,size=len(v),len(M) return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] def T(M): n,m=len(M),len(M[0]) return [[M[j][i] for j in range(n)] for i in range(m)] def main(): mod = 10**9+7 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え #N = int(input()) N, K = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル #L = tuple(int(input()) for i in range(N)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 #2n-1Cn fac1=1 fac2=1 facs=[1,1] for i in range(2,2*N): facs.append(facs[-1]*i%mod) # fac1=pow(facs[N],mod-2,mod) # fac2=pow(facs[N-1],mod-2,mod) # tot=facs[2*N-1]*fac1%mod # tot*=fac2 # tot%=mod def comb(N,r): fac1=pow(facs[r],mod-2,mod) fac2=pow(facs[N-r],mod-2,mod) tot=(facs[N]*fac1%mod)*fac2%mod return tot tot=comb(2*N-1,N) if N-1<=K: print(tot) else:#0のへやがk+1より多くあるとボツ r=0 for i in range(1,N-(K+1)+1): n=N-i r+=comb(N,i)*comb(n+i-1,i-1)%mod r%=mod print((tot-r)%mod) if __name__ == "__main__": main()
1
67,071,830,735,152
null
215
215
import sys sys.setrecursionlimit(10**8) def find(x): if par[x]==x: return x else: par[x]=find(par[x]) return par[x] def union(a,b): a=find(a) b=find(b) if a==b: return if rank[a]<rank[b]: par[a]=b rank[b]+=rank[a] rank[a]=rank[b] else: par[b]=a rank[a]+=rank[b] rank[b]=rank[a] return def chk(a,b): if par[a]==par[b]: print('Yes') else: print('No') return N,M=map(int, input().split()) par=(list(range(N+1))) rank=[1]*(N+1) for _ in range(M): A,B=map(int, input().split()) union(A,B) print(max(rank))
import sys from sys import stdin input = stdin.readline class UnionFind(): def __init__(self, n): self.n = n self.d = [-1] * n def find(self, x): if (self.d[x] < 0): return x else: self.d[x] = self.find(self.d[x]) return self.d[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if (x == y): return if (self.d[x] > self.d[y]): x, y = y, x self.d[x] += self.d[y] self.d[y] = x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.d[self.find(x)] n, m = map(int, input().split()) uf = UnionFind(n) for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 uf.unite(a,b) ans = 0 for i in range(n): ans = max(ans, uf.size(i)) print(ans)
1
3,913,771,711,840
null
84
84
a=int(input()) b=a+a**2+a**3 c=round(b) print(c)
def gcd(x, y): if x < y: x, y = y, x while y > 0: r = x % y x = y y = r return x x, y = map(int, input().split(' ')) n = min(x, y) print(gcd(x, y))
0
null
5,131,954,512,580
115
11
x, y = map(int, input().split()) msg = 'No' for a in range(1, x+1): if 2*a + 4*(x-a) == y or 4*a + 2*(x-a) == y: msg = 'Yes' print(msg)
x, y = map(int, input().split()) a = [] for i in range(0, x+1): a.append(2 * i + 4 * (x - i)) print("Yes" if y in a else "No")
1
13,687,769,573,984
null
127
127
import sys c = 0 while True: x = int(sys.stdin.readline()) if x == 0: break c+=1 print ('Case ' + str(c)+':', x)
def examA(): N = I() ans = (N-1)//2 print(ans) return def examB(): N = I() D = LI() d = Counter(D) loop = max(d.keys()) if D[0]!=0 or d[0]!=1: print(0) return # print(d,loop) ans = 1; cur = 1 for i in range(loop+1): if d[i]==0: print(0) return for _ in range(d[i]): ans *= cur ans %= mod2 cur = d[i] print(ans) return def examC(): ans = 0 print(ans) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LFI(): return list(map(float,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 alphabet = [chr(ord('a') + i) for i in range(26)] if __name__ == '__main__': examB() """ """
0
null
77,630,646,892,902
42
284
N = int(input()) a_list = list(map(int, input().split())) #print(a_list) myans = 0 for a, b in enumerate(a_list): #print(a,b) if (a+1)%2 != 0 and b%2 != 0: myans += 1 print(myans)
import sys sys.setrecursionlimit(300000) def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 INF = float('inf') N = I() A = LMI() ans = 0 for i, a in enumerate(A): if i % 2 == 0 and a % 2 != 0: ans += 1 print(ans)
1
7,768,205,211,206
null
105
105
# -*- coding: utf-8 -*- """ Created on Thu May 3 19:22:34 2018 ALDS-1-5-C @author: maezawa """ cnt = 0 n = int(input()) a = list(map(int, input().split())) def merge_sort(a, left, right): #global cnt #cnt += 1 if left+1 < right: mid = (left+right)//2 merge_sort(a, left, mid) merge_sort(a, mid, right) merge(a, left, mid, right) def merge(a, left, mid, right): global cnt n1 = mid - left n2 = right - mid l = a[left:mid].copy() r = a[mid:right].copy() l.append(10**10) r.append(10**10) i = 0 j = 0 for k in range(left, right): cnt += 1 if l[i] <= r[j]: a[k] = l[i] i += 1 else: a[k] = r[j] j += 1 merge_sort(a, 0, len(a)) print(a[0], end='') for i in range(1,len(a)): print(' {}'.format(a[i]), end='') print() print(cnt)
import bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys from cmath import pi, rect sys.setrecursionlimit(10**7) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) A,B,H,M = LI() H += M / 60 H = H/12 * 2*pi M = M/60 * 2*pi # 余弦定理 l = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(H-M) ) # 複素数座標 Aexp(iθ) zA = A * np.exp(H*1j) zB = B * np.exp(M*1j) l=abs(zA - zB) print(l)
0
null
10,019,675,838,898
26
144
import sys from copy import copy, deepcopy input = sys.stdin.readline ''' n, m = map(int, input().split()) n = int(input()) A = list(map(int, input().split())) S = input().strip() for CASES in range(int(input())): ''' inf = 100000000000000000 # 1e17 mod = 998244353 ''' # example input ''' def replace(pos, char): x = pos old_char = A[x] while x <= n: tr[x][old_char] -= 1 x += x & (-x) x = pos while x <= n: tr[x][char] += 1 x += x & (-x) A[pos] = char def query(pos, char): x = pos sum = 0 while x != 0: sum += tr[x][char] x -= x & (-x) return sum n = int(input()) S = input().strip() A = [27] * (n + 1) ''' for i in range(len(S)): A.append(ord(S[i])-ord('a')) ''' tr = [[0] * 30 for i in range(len(S) + 10)] for i in range(len(S)): replace(i + 1, ord(S[i]) - ord('a')) q = int(input()) for i in range(q): QUERY = list((input().split())) if int(QUERY[0]) == 1: replace(int(QUERY[1]), ord(QUERY[2]) - ord('a')) else: sum = 0 for char in range(ord('a'), ord('z') + 1): num = query(int(QUERY[2]), char - ord('a')) - \ query(int(QUERY[1]) - 1, char - ord('a')) if num >= 1: sum += 1 print(sum)
s = list(input()) n = len(s) ans = 0 for i in range(n//2): if s[i] != s[-1-i]: ans += 1 print(ans)
0
null
91,331,791,171,644
210
261
string = input() if string[-1] == 's': out = string + "es" else: out = string + "s" print(out)
a=str(input()) if a[-1]=="s": print(a+"es") else: print(a+"s")
1
2,399,715,675,588
null
71
71
n = int(input()) ls = [0]*n ls1 = list(map(int, input().split())) for i in ls1: ls[i-1] += 1 for j in ls: print(j)
S = input() N = len(S) print("x" * N)
0
null
52,749,260,371,328
169
221
N = int(input()) a = b = 1 while N: a, b = b, a+b N -= 1 print(a)
# -*- coding: utf_8 -*- n = int(input()) + 1 arr = [-1] * n arr[0] = 1 arr[1] = 1 for i in range(2, len(arr)): arr[i] = arr[i - 1] + arr[i - 2] print(arr[n - 1])
1
1,952,099,820
null
7
7
u = str(input()) len_ =len(u) tmp = str() for i in range(len_): tmp = tmp + 'x' print(tmp)
# coding: utf-8 s = input() print("x" * len(s))
1
72,826,001,825,290
null
221
221
''' @sksshivam007 - Template 1.0 ''' import sys, re, math from collections import deque, defaultdict, Counter, OrderedDict from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from heapq import heappush, heappop, heapify, nlargest, nsmallest def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def sortListWithIndex(listOfTuples, idx): return (sorted(listOfTuples, key=lambda x: x[idx])) def sortDictWithVal(passedDic): temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1] toret = {} for tup in temp: toret[tup[0]] = tup[1] return toret def sortDictWithKey(passedDic): return dict(OrderedDict(sorted(passedDic.items()))) INF = float('inf') mod = 10 ** 9 + 7 n, k = MAP() a = [0]*(k+1) for i in range(k, 0, -1): temp = pow((k//i), n, mod) ans = temp%mod for j in range(2, k//i + 1): ans -= a[j*i]%mod a[i] = ans%mod final = 0 for i in range(len(a)): final+=(a[i]*i)%mod print(final%mod)
m, n = map(int, input().split()) print((m + n - 1)//n)
0
null
57,130,999,646,428
176
225
a = int(input()) if a == 1: print(0) else: print(1)
n = int(input()) D = set() for _ in range(n): q, s = map(str, input().split()) if q == 'insert': D.add(s) elif q == 'find': if s in D: print('yes') else: print('no')
0
null
1,512,994,767,570
76
23
def main(): N = int(input()) user_remarks = {} for i in range(1, N+1): A = int(input()) user_remarks[i] = [] for _ in range(A): user_id, is_honest = [int(x) for x in input().split()] user_remarks[i].append((user_id, is_honest == 1)) max_count = 0 for i in range(2**N): honest = {} is_ok = True for x in range(N): # フラグが経っている時 = 正直もの if ((i >> x) & 1): honest[x+1] = True if is_ok: # 正直者の証言チェック for user_remark in user_remarks[x+1]: target_user = user_remark[0] target_is_honest = user_remark[1] # ターゲットは正直者である場合 if target_is_honest: # 正直者ではなかったら矛盾している if not ((i >> (target_user-1)) & 1): is_ok = False # ターゲットが不親切な人である場合 if not target_is_honest: # 正直者だったら矛盾している if ((i >> (target_user-1)) & 1): is_ok = False if is_ok: max_count = max(max_count, len(honest)) print(max_count) if __name__ == '__main__': main()
import math N = int(input()) A = [] for i in range(2,int(math.sqrt(N))+1): if N%i == 0: A.append(i + (N//i) - 2) if not A: print(N-1) else: print(min(A))
0
null
141,582,002,048,102
262
288
H1,M1,H2,M2,K=map(int, input().split()) M1 += H1*60 M2 += H2*60 print(M2-M1-K)
import sys def input(): return sys.stdin.readline().rstrip() def main(): h1, m1, h2, m2, k = map(int,input().split()) print(h2*60+m2-h1*60-m1-k) if __name__=='__main__': main()
1
18,074,513,760,758
null
139
139
H, W, K = map(int,input().split()) S = [] ans = [["" for _ in range(W)] for __ in range(H)] checkBerry = [] cake = 1 for i in range(H): s = input() S.append(s) flag = False for ss in s: if ss == "#": flag = True checkBerry.append(flag) LS = [] n = 0 lss = [] while(n < H): lss.append(n) if (checkBerry[n] == True): LS.append(lss.copy()) lss = [] n += 1 if lss != []: LS[-1].extend(lss) for ls in LS: i = 0 for l in ls: if checkBerry[l] == True: i = l firstBerry = False for j in range(W): if(S[i][j] == "#" and firstBerry == False): firstBerry = True elif(S[i][j] == "#" and firstBerry == True): cake += 1 for l in ls: ans[l][j] = str(cake) cake += 1 for a in ans: print(" ".join(a))
N, K, C = map(int, input().split()) S = input() must = set() i = len(S)+C for j in range(K): i = S.rindex("o", 0, i-C) must.add(i) if i<=C or "o" not in S[:i-C]: i = -C-1 for j in range(K): i = S.index("o", i+C+1) if i in must: print(i+1)
0
null
91,866,069,513,632
277
182
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): from collections import Counter n = int(readline()) count = Counter() for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): a = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x count[a] += 1 for i in range(1, n + 1): print(count[i]) if __name__ == '__main__': main()
while True: _=input() if _ == '-': break for i in range(int(input())): l=int(input()) _=_[l:]+_[:l] print(_)
0
null
4,966,489,446,214
106
66
import copy H, W, K = map(int, input().split()) tiles = [list(input()) for _ in range(H)] answer = 0 for h in range(2**H): for w in range(2**W): b_cnt = 0 for i in range(H): for j in range(W): if not (h>>i&1 or w>>j&1) and tiles[i][j] == '#': b_cnt += 1 if b_cnt == K: answer += 1 print(answer)
import itertools def LI(): return tuple(map(int, input().split())) N = int(input()) P = LI() Q = LI() Nlist = list(range(1, N+1)) count = 1 for v in itertools.permutations(Nlist, N): if P == v: p = count if Q == v: q = count count += 1 print(abs(p-q))
0
null
54,901,519,627,812
110
246
n = input() str_n = list(n) if str_n[-1] == "3": print("bon") elif str_n[-1] == "0" or str_n[-1] == "1" or str_n[-1] == "6" or str_n[-1] == "8": print("pon") else: print("hon")
n = int(input()) a = list(map(int,input().split())) ok = True for i in range(n): if a[i] % 2 == 0 and a[i] % 3 != 0 and a[i] % 5 != 0: ok = False if ok: print("APPROVED") else: print("DENIED")
0
null
44,314,269,786,890
142
217
A, B, M = list(map(int, input().split())) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) ans = min(a_list) + min(b_list) for i in range(M): x, y, c = list(map(int, input().split())) cost = a_list[x - 1] + b_list[y - 1] - c if cost < ans: ans = cost print(ans)
A, B, M = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) ans = [] for i in range(M): x, y, c = map(int,input().split()) z = a[x - 1] + b[y - 1] - c ans.append(z) z = min(a) + min(b) ans.append(z) ans = sorted(ans) print(ans[0])
1
53,838,187,900,020
null
200
200
n,m=map(int,input().split()) a=[i for i in range(n+1)] for i in list(map(int,input().split())): for j in range(i,n+1): a[j]=min(a[j-i]+1,a[j]) print(a[-1])
n = int(input().split()[0]) c = list(filter(lambda x:x <= n,map(int,input().split()))) minimum = [ i for i in range(n+1) ] for i in c: minimum[i] = 1 for i in range(2,n+1): for j in c: if j<=i and minimum[i-j] + 1 < minimum[i]: minimum[i] = minimum[i-j]+1 print(minimum[n])
1
140,885,722,032
null
28
28
k=int(input()) s=len(input()) def cmb(n,r,mod): if r<0 or n<r: return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]%mod mod=10**9+7 g1=[1,1]#元table g2=[1,1]#逆元table inv=[0,1]#逆元table計算用 for i in range(2,k+s+1): g1.append(g1[-1]*i%mod) inv.append(-inv[mod%i]*(mod//i)%mod) g2.append(g2[-1]*inv[-1]%mod) ans=1 for i in range(1,k+1): ans=(ans*26+cmb(i+s-1,s-1,mod)*pow(25,i,mod))%mod print(ans)
n = int(input()) if n%2 == 1: print(0) exit() num = 5 i = 1 ans = 0 while num**i < n: ans += n//num**i//2 i += 1 print(ans)
0
null
64,636,813,508,842
124
258
int = int(input()) dev = int % 10 if dev==3: print("bon") elif dev==0 or dev==1 or dev==6 or dev==8: print("pon") else: print("hon")
while True : a, b, c = [int(temp) for temp in input().split()] if a == b == c == -1 : break if (a == -1) or (b == -1) or (a + b < 30) : print('F') elif (80 <= a + b) : print('A') elif (65 <= a + b) : print('B') elif (50 <= a + b) or ((30 <= a + b) and (50 <= c)) : print('C') else : print('D')
0
null
10,350,657,015,378
142
57
hei = int(input()) wei = int(input()) n = int(input()) kuro =0 count = 0 if hei > wei: data = hei else: data = wei while kuro<n: kuro +=data count +=1 print(count)
def dist(A_lst, B_lst, p): s = 0 for a, b in zip(A_lst, B_lst): s += abs(a - b) ** p return s ** (1 / p) N = int(input()) *A, = map(int, input().split()) *B, = map(int, input().split()) print("{:.6f}".format(dist(A, B, 1))) print("{:.6f}".format(dist(A, B, 2))) print("{:.6f}".format(dist(A, B, 3))) chebyshev = max(abs(a - b) for a, b in zip(A, B)) print("{:.6f}".format(chebyshev))
0
null
44,614,872,389,950
236
32
N,X,Y=map(int,input().split()) d=[0]*N for i in range(N): for j in range(i+1,N):d[min(j-i,abs(X-1-i)+abs(Y-1-j)+1)]+=1 for i in d[1:]:print(i)
from collections import deque N, X, Y = map(int, input().split()) ans = [0 for i in range(N)] dqs = [-1, 1] for i in range(N-1): vis = [-1 for _ in range(N)] Q = deque([i]) vis[i] = 0 while Q: q = Q.popleft() for dq in dqs: if 0 <= q + dq < N: if vis[q + dq] == -1: vis[q + dq] = vis[q] + 1 Q.append(q + dq) if q + dq > i: ans[vis[q + dq]] += 1 if q==X-1: if vis[Y-1] == -1: vis[Y-1] = vis[q] + 1 Q.append(Y-1) if Y-1 > i: ans[vis[Y-1]] += 1 if q==Y-1: if vis[X-1] == -1: vis[X-1] = vis[q] + 1 Q.append(X-1) if X-1 > i: ans[vis[X-1]] += 1 for a in ans[1:]: print(a)
1
44,158,689,563,872
null
187
187
def mitsui2019d_lucky_pin(): import itertools n = int(input()) s = input() cnt = 0 for t in itertools.product(range(0, 10), repeat=2): si = ''.join(map(str,t)) for i in range(n - 2): if si[0] != s[i]: continue for j in range(i + 1, n - 1): if si[1] != s[j]: continue ss = set(list(s[j+1:])) cnt += len(ss) break break print(cnt) mitsui2019d_lucky_pin()
import collections N = int(input()) S = input() S_list = [S[i] for i in range(N)] S_c = collections.Counter(S_list) list12 = [] list1 = [] ans = 0 for i in range(N-2): s1 = S_list[i] S_c[s1] = S_c[s1]-1 if s1 in list1: continue S_c23 = S_c.copy() list1.append(s1) for j in range(i+1,N-1): s2 = S_list[j] S_c23[s2] = S_c23[s2] - 1 if (s1+s2) in list12: continue else: list12.append(s1+s2) for key in S_c23.keys(): if S_c23[key] != 0: ans+=1 print(ans)
1
128,534,362,161,628
null
267
267
#akash mandal: jalpaiguri government engineering college import sys,math def ii(): return int(input()) def mii(): return map(int,input().split()) def lmii(): return list(mii()) def main(): A,B,C=mii() print("Yes" if B*C>=A else "No") if __name__=="__main__": main()
while True: H, W = map(int, input().split()) if not(H or W): break for i in range(H): print('#', end='') for j in range(W-2): if i > 0 and i < H - 1: print('.', end='') else: print('#', end='') print('#') print()
0
null
2,151,040,437,248
81
50
from collections import Counter N = int(input()) A = list(map(int, input().split())) l =[] r =[] for id,h in enumerate(A,start=1): r.append(id -h) l.append(id +h) r_cou =Counter(r) l_cou =Counter(l) ans =[] for i in l_cou.keys(): ans.append(l_cou[i] *r_cou.get(i,0)) print(sum(ans))
from collections import defaultdict N = int(input()) A = list(map(int, input().split())) dAl = defaultdict(int) dAr = defaultdict(int) for i in range(N): L = (i + 1) + A[i] R = (i + 1) - A[i] dAl[L] += 1 dAr[R] += 1 # dictの中を見る ans = 0 for k, v in dAl.items(): ans += v * dAr[k] print(ans)
1
25,919,330,020,970
null
157
157
import sys from itertools import product sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) def dfs(s, num): if len(s) == n: print(s) return for i in range(num + 1): t = s + chr(97 + i) dfs(t, max(num, i + 1)) dfs("", 0) if __name__ == '__main__': resolve()
import sys import math input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import defaultdict MOD = 10**9+7 N = int(input()) dic = defaultdict(int) zero = 0 left_zero = 0 right_zero = 0 for i in range(N): a, b = map(int, input().split()) if b < 0: a = -a b = -b if a == 0 and b == 0: zero += 1 elif a == 0: left_zero += 1 elif b == 0: right_zero += 1 else: g = math.gcd(a, b) a //= g b //= g dic[a,b] += 1 done = set() ans = 1 for a,b in dic: k = (a, b) if k in done: continue rk = (-b, a) rk2 = (b, -a) done.add(k) done.add(rk) done.add(rk2) c = pow(2, dic[k], MOD)-1 if rk in dic: c += pow(2, dic[rk], MOD)-1 if rk2 in dic: c += pow(2, dic[rk2], MOD)-1 c += 1 ans *= c ans %= MOD c1 = pow(2, left_zero, MOD)-1 c2 = pow(2, right_zero, MOD)-1 c = c1+c2+1 ans *= c ans += zero print((ans-1)%MOD)
0
null
36,806,839,264,198
198
146
n=int(input()) a=1 b=1 i=0 while i<n: a,b=b,a+b i+=1 print(a)
n = int(input()) toko = [int(i) for i in input().split()] ans = [int(0) for i in range(n)] for j in range(n): ##01234 ans[toko[j]-1] = j + 1 print(' '.join(map(str, ans)))
0
null
89,934,565,333,340
7
299
K,N=map(int,input().split()) A=[int(i) for i in input().split()] dlist=[] for i in range(1,N): d=A[i]-A[i-1] dlist.append(d) dlist.append(A[0]+K-A[N-1]) print(K-max(dlist))
k,n=map(int,input().split()) l=list(map(int,input().split())) diff=[] l.append(l[0]+k) for i in range(n): diff.append(l[i+1]-l[i]) print(sum(diff)-max(diff))
1
43,468,303,646,812
null
186
186
n = int(input()) A = list(map(int,input().split())) data = [0]*3 ans = 1 mod = pow(10,9)+7 for i in A: ans *= data.count(i) ans %= mod if ans == 0: break data[data.index(i)] += 1 print(ans)
from collections import * from heapq import * import sys input=lambda :sys.stdin.readline().rstrip() N=int(input()) A=list(map(int,input().split())) mod=10**9+7 count=1 lst=[0,0,0] for a in A: data=[i for i in range(3) if lst[i] == a] if not data: count=0 break count*=len(data) count%=mod i=data[0] lst[i]+=1 print(count)
1
130,614,451,326,882
null
268
268
import sys input = sys.stdin.readline N, D, a = [int(x) for x in input().split()] XH = [] for _ in range(N): XH.append([int(x) for x in input().split()]) XH.sort() #####segfunc###### def segfunc(x,y): return x + y def init(init_val): #set_val for i in range(n): seg[i+num-1]=init_val[i] #built for i in range(num-2,-1,-1) : seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) def update(k,x): k += num-1 seg[k] = x while k: k = (k-1)//2 seg[k] = segfunc(seg[k*2+1],seg[k*2+2]) def query(p,q): if q<=p: return ide_ele p += num-1 q += num-2 res=ide_ele while q-p>1: if p&1 == 0: res = segfunc(res,seg[p]) if q&1 == 1: res = segfunc(res,seg[q]) q -= 1 p = p//2 q = (q-1)//2 if p == q: res = segfunc(res,seg[p]) else: res = segfunc(segfunc(res,seg[p]),seg[q]) return res #入力 n = N A = [0] * N #####単位元###### ide_ele = 0 #num:n以上の最小の2のべき乗 num =2**(n-1).bit_length() seg=[ide_ele]*2*num #init init(A) import bisect X = [] H = [] for i in XH: X.append(i[0]) H.append(i[1]) ans = 0 for i in range(N): x, h = X[i], H[i] idx_left = bisect.bisect_left(X, x - 2 * D) idx_right = i tmp = query(idx_left, idx_right) if tmp < h: h -= tmp cnt = h // a + int(h % a != 0) ans += cnt update(i, a * cnt) print(ans)
import sys readline=sys.stdin.readline N,D,A=map(int,readline().split()) D*=2 # 爆発の長さ X=[None]*N for i in range(N): X[i]=list(map(int,readline().split())) X=sorted(X,key=lambda x:x[0]) # lastX=X[-1][0] # 最後のモンスターの場所 damage=0 # 現在の爆発が与えられるダメージ from collections import deque bombs=deque() # 爆弾が切れるタイミング # [位置、効力] ans=0 for i in range(len(X)): x=X[i][0] h=X[i][1] # モンスターの体力 # 爆発が途切れていないかを確認 while bombs: b=bombs.popleft() if b[0]<x: damage-=b[1] else: bombs.appendleft(b) break h-=damage if h>0: turn=((h+A-1)//A) damage+=turn*A ans+=turn bombs.append([x+D,turn*A]) print(ans)
1
82,123,679,422,498
null
230
230
N = int(input()) A = list(map(int, input().split())) if N == 0: if A[0] == 1: print (1) exit() else: print (-1) exit() MAX = 10 ** 18 lst = [1] * (10 ** 5 + 10) #純粋な2分木としたときの最大値 for i in range(N + 1): lst[i + 1] = min(MAX, lst[i] * 2) # print (lst[:10]) for i in range(N + 1): tmp = lst[i] - A[i] if tmp < 0: print (-1) exit() lst[i + 1] = min(lst[i + 1], tmp * 2) # print (lst[:10]) if lst[N] >= A[N]: lst[N] = A[N] else: print (-1) exit() # print (lst[:10]) ans = 1 tmp = 0 for i in range(N, 0, -1): ans += lst[i] lst[i - 1] = min(lst[i] + A[i - 1], lst[i - 1]) # print (lst[:10]) print (ans)
import sys input = sys.stdin.readline n = int(input()) a = [int(x) for x in input().split()] max_a = [0]*(n + 1) """ if n == 0 and a[0] == 0: print(-1) sys.exit() """ for i in range(n + 1): if i == 0: max_a[i] = 1 else: max_a[i] = (max_a[i - 1] - a[i - 1])*2 if max_a[i] < 0: print(-1) sys.exit() # print(max_a) for i in range(n, -1, -1): if i == n: if max_a[i] < a[i]: print(-1) sys.exit() max_a[i] = a[i] else: min_p = max_a[i + 1] // 2 + int(max_a[i + 1] % 2 == 1) max_p = max_a[i + 1] if max_a[i] < min_p: print(-1) sys.exit() max_a[i] = min(max_p + a[i], max_a[i]) print(sum(max_a)) # print(max_a)
1
18,735,840,359,950
null
141
141
n = int(input()) a = list(map(int, input().split())) x = [] flag = True for i in reversed(range(n)): if i == 0: if not flag: x.append(a[i]) break flag2 = flag if flag: if a[i - 1] < a[i]: x.append(a[i]) flag2 = not flag2 else: if a[i - 1] > a[i]: x.append(a[i]) flag2 = not flag2 flag = flag2 x = x[::-1] m = len(x) if m % 2 == 1: x = x[1:] # print("x =", x) cur_money = 1000 cur_stock = 0 for i in range(m): if i % 2 == 0: cur_stock += cur_money // x[i] cur_money %= x[i] else: cur_money += x[i] * cur_stock cur_stock = 0 print(cur_money)
import sys a=[] for i in sys.stdin: a.append(map(int,i.split())) for i in a: print(str(len(str(i[0]+i[1]))))
0
null
3,669,401,448,328
103
3
x, y = map(int, input().split()) cnt = 0 for i in range(x+1): for j in range(x+1): if i + j == x and i*2+j*4 == y: cnt += 1 print("Yes") if cnt > 0 else print("No")
X,Y = map(int,input().split()) if Y%2 == 0 and 2*X<=Y<=4*X: print('Yes') else: print('No')
1
13,839,683,163,360
null
127
127
# -*- coding:utf-8 -*- h,w = map(int,input().split()) if h == 1 or w == 1: print(1) elif w %2 == 0: print(h * w //2) elif h % 2 == 0: print(h * w //2) else: print(h*w//2+1)
S=str(input()) print('x'*len(S))
0
null
61,872,653,555,040
196
221
def main(): a,b= list(map(int,input().split())) a_str="" b_str="" for i in range(0,b): a_str+=str(a) for i in range(0,a): b_str+=str(b) if a_str<b_str: print(a_str) else: print(b_str) main()
al =["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"] C = input() kk = al.index(C) print(al[kk+1])
0
null
88,374,351,417,800
232
239
N=int(input()) K=int(input()) string = str(N) digits = len(string) #dp[i][j][k]=と同じ桁数の整数で上からi桁目までで0でない数字がj個あるものの個数 #k=0: i桁目まで見てN未満が確定, k=1: 未確定 dp = [[[0]*2 for _ in range(K+1)] for __ in range(digits+1)] #初期状態 dp[0][0][1] = 1 for i in range(digits): d = int(string[i]) ni = i+1 for j in range(K+1): for k in range(2): for nd in range(10): nk = 1 if k == 1 and nd == d else 0 if k == 1 and nd > d: break nj = j + (1 if nd != 0 else 0) if nj > K: continue dp[ni][nj][nk] += dp[i][j][k] print(dp[digits][K][0] + dp[digits][K][1])
# https://atcoder.jp/contests/abc154/tasks/abc154_e # 桁DPっぽいよなぁ => O """ memo dp0[i][j] 上からi桁目まで決めて,0でない桁がj個あり Nより小さいことが確定している (less) dp1[i][j] 上からi桁目まで決めて,0でない桁がj個あり Nより小さいことが確定していない (i桁目まで同じ) 通常の再帰 rec """ S = input() K = int(input()) N = len(S) def com(N, R): if R < 0 or R > N: return 0 if R == 1: return N elif R == 2: return N * (N - 1) // 2 elif R == 3: return N * (N - 1) * (N - 2) // 6 else: raise NotImplementedError("NIE") # 再帰呼出し def rec(i, k, smaller): if i == N: return 1 if k == 0 else 0 if k == 0: return 1 if smaller: # 残っている桁数からk個を選び,それぞれ9^kのパターンがある return com(N - i, k) * pow(9, k) else: if S[i] == '0': return rec(i + 1, k , False) else: zero = rec(i + 1, k, True) aida = rec(i + 1, k - 1, True) * (int(S[i]) - 1) ichi = rec(i + 1, k - 1, False) return zero + aida + ichi ans = rec(0, K, False) print(ans)
1
76,123,851,578,720
null
224
224
import sys N, P = map(int, input().split()) A = input() ans = 0 if 10 % P == 0: for r in range(len(A)): if int(A[r]) % P == 0: ans += r + 1 print(ans) sys.exit() A = "0" + A[::-1] S = [0] * len(A) cnt = [0] * P cnt[0] = 1 for i in range(len(A) - 1): S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i, P)) % P cnt[S[i + 1] % P] += 1 # print(S, cnt) # ans = cnt[0] * (cnt[0] - 1) // 2 for c in cnt: ans += c * (c - 1) // 2 print(ans)
#!/usr/bin/env python3 n,p = map(int,input().split()) s=input() ans = 0 l = [0 for i in range(p)] l[0] = 1 z = 0 ten = 1 tmp = 0 if p == 2 or p == 5: if p == 2: for i in range(n): if int(s[i])%2 == 0: ans+=i+1 if p == 5: for i in range(n): if int(s[i])%5 == 0: ans+= i+1 else: for i in s[::-1]: i = int(i) tmp=(tmp+i*ten)%p ten = (ten*10)%p l[tmp]+=1 for i in l: ans+= i*(i-1)//2 print(ans)
1
58,164,451,687,232
null
205
205
import sys for line in sys.stdin: a,b = [int(i) for i in line.split()] print(len(str(a+b)))
import math import sys while True: try: a,b = map(int, input().split()) print(len(str(a+b))) except EOFError: break
1
104,683,360
null
3
3
n,k = map(int,input().split()) m = n%k a = abs(k - m) l = [m,a] print(min(l))
n,a,b = map(int,input().split()) mod = 10**9 + 7 all = pow(2, n, mod) if all == 0: all = 10**9 + 6 else: all -= 1 a = min(n-a,a) b = min(n-b,b) a_fact = 1 a_inv = 1 for i in range(1,a+1): a_fact *= (n-i+1)%mod a_inv *= pow(i,mod-2,mod) a_fact %= mod a_inv %= mod nca = a_fact * a_inv nca %= mod b_fact = 1 b_inv = 1 for i in range(1,b+1): b_fact *= (n-i+1)%mod b_inv *= pow(i,mod-2,mod) b_fact %= mod b_inv %= mod ncb = b_fact * b_inv ncb %= mod ans = all - nca - ncb while ans < 0: ans += mod if ans >= mod: ans -= mod print(ans)
0
null
52,376,230,674,192
180
214
n = int(input()) a = list(map(int, input().split())) ans = 0 for num in range(1, n+1, 2): if a[num-1] % 2 != 0: ans += 1 print(ans)
import sys readline = sys.stdin.readline N = int(readline()) ans = 0 for a in list(map(int,readline().split()))[::2]: ans += (a & 1) print(ans)
1
7,780,589,522,640
null
105
105
def num(): from sys import stdin h, n = map(int, input().split()) magic = [list(map(int, stdin.readline().split())) for _ in range(n)] INF = float('inf') ans = [INF]*(h+1) ans[-1] = 0 for i in range(h, 0, -1): if ans[i] != INF: for j, k in magic: if i-j < 0: num = ans[i]+k if ans[0] > num: ans[0] = num else: num = ans[i]+k if ans[i-j] > num: ans[i-j] = num return ans[0] print(num())
a = list(map(int, input().split())) HP = a[0] x = [] for i in range(a[1]): x1, y1 = [int(i) for i in input().split()] x.append((x1, y1)) max_tup = max(x, key=lambda x: x[0]) #最高攻撃力の呪文を記憶 max_a = max_tup[0] #その攻撃力を記録 #1次元 横:与えるダメージ 中身:最小魔力 dp = [10**10] * (HP + max_a) #DP表はHP+最高攻撃力 dp[0] = 0 for i in range(1, len(dp)): for a, b in x: if i >= a: dp[i] = min(dp[i],dp[i - a] + b ) print(min(dp[HP:]))
1
81,068,037,718,918
null
229
229
def countPakages(P, k, W): i, n = 0, len(W) for j in range(k): s = 0 while s + W[i] <=P: s += W[i] i += 1 if i == n: return n return i def ALDS1_4D(): n_limit, k_limit, wi_limit = 100000, 100000, 10000 n, k= map(int, input().split()) W = [int(input()) for i in range(n)] Pleft, Pright = 0, n_limit * wi_limit while Pright - Pleft > 1: Pmid = (Pleft+Pright)//2 v = countPakages(Pmid, k, W) if v < n: Pleft = Pmid else: Pright = Pmid return Pright if __name__ == '__main__': print(ALDS1_4D())
# coding: utf-8 # Your code here! x = input() lst = list(x) pt = [] rst = [] k = 0 # point get cnt = 0 tmp = "" for s in lst: if s == "/": if tmp == "_" or tmp == "/": cnt += 1 elif s == "\\": if tmp == "\\": cnt -= 1 else: if tmp == "\\": cnt -= 1 pt += [cnt] tmp = s #メンセキ i,xs,m2 = 0,0,0 for s in lst: if s == "/": if i == xs and xs > 0: rst += [m2] k += 1 xs,m2 = 0,0 elif s == "_": pass else: try: x = pt[i+1:].index(pt[i])+i+1 m2 += x-i if xs < x: xs = x except: pass i += 1 print(sum(rst)) print(k,*rst)
0
null
75,347,513,462
24
21
import sys input = sys.stdin.readline from collections import * def bfs(): q = deque([0]) pre = [-1]*N pre[0] = 0 while q: v = q.popleft() for nv in G[v]: if pre[nv]==-1: pre[nv] = v q.append(nv) return pre N, M = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(M): A, B = map(int, input().split()) G[A-1].append(B-1) G[B-1].append(A-1) pre = bfs() print('Yes') for pre_i in pre[1:]: print(pre_i+1)
from collections import deque def bfs(graph, n, s): visited = [0]*n # 移動回数を保持 visited[s] = 1 # 部屋1の探索は完了としている q = deque([s]) # 探索用にdequeを設定し、初期位置としてs(0)を設定する while q: node = q.popleft() # 先頭から順番に実行 for i in graph[node]: # 各部屋から行ける別の部屋を確認 if not visited[i]: # 値が"0"の場合に処理を実行 visited[i] = node + 1 # 部屋1からの移動回数を保持する q.append(i) # 移動先の部屋をqに格納し、探索を継続する return visited n,m = map(int, input().split()) graph = [[] for _ in range(n)] for _ in range(m): a,b = map(lambda x: int(x)-1, input().split()) graph[a].append(b) graph[b].append(a) visited = bfs(graph, n, 0)[1:] # 幅優先探索を行い、部屋1以外の結果を取得する if all(visited): print("Yes") print(*visited, sep="\n") else: print("No")
1
20,510,740,764,540
null
145
145
H, W, M = list(map(int, input().split())) h = [0] * H w = [0] * W hw = {} for _ in range(M): a, b = list(map(int, input().split())) h[a - 1] += 1 w[b - 1] += 1 temp = "x" + str(a - 1) + "y" + str(b - 1) hw[temp] = 1 hm = max(h) wm = max(w) hp = [i for i, v in enumerate(h) if v == hm] wp = [i for i, v in enumerate(w) if v == wm] for x in hp: for y in wp: temp = "x" + str(x) + "y" + str(y) if temp not in hw: print(hm + wm) exit() else: print(hm + wm - 1)
def A(): n, x, t = map(int, input().split()) print(t * ((n+x-1)//x)) def B(): n = list(input()) s = 0 for e in n: s += int(e) print("Yes" if s % 9 == 0 else "No") def C(): int(input()) a = list(map(int, input().split())) l = 0 ans = 0 for e in a: if e < l: ans += l - e l = max(l, e) print(ans) def E(): h, w, m = map(int, input().split()) row = [0] * h col = [0] * w exist = set([]) th = 1000000000 for i in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 row[x] += 1 col[y] += 1 exist.add(x*th + y) max_row = max(row) max_col = max(col) candi_row = [] candi_col = [] for i in range(h): if row[i] == max_row: candi_row.append(i) for i in range(w): if col[i] == max_col: candi_col.append(i) ans = max_row + max_col for x in candi_row: for y in candi_col: if x*th + y in exist: continue print(ans) return print(ans - 1) E()
1
4,740,955,527,870
null
89
89
N = int(input()) if N%2 == 1 : print(0) exit() n = 0 i = 0 for i in range(1,26) : n += N//((5**i)*2) print(n)
n=int(input()) ans=0 if n%2==0: for i in range(1,26): ans+=(n//(2*5**i)) print(ans)
1
115,746,182,118,600
null
258
258
import sys import math input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import defaultdict MOD = 10**9+7 N = int(input()) dic = defaultdict(int) zero = 0 for i in range(N): a, b = map(int, input().split()) if b < 0: a = -a b = -b if a == 0 and b == 0: zero += 1 continue elif a == 0: b = 1 elif b == 0: a = 1 g = math.gcd(a, b) a //= g b //= g dic[a,b] += 1 done = set() ans = 1 for a,b in dic: k = (a, b) if k in done: continue c, d = -b, a if d <= 0: c = -c d = -d rk = (c, d) done.add(k) done.add(rk) c = pow(2, dic[k], MOD)-1 if rk in dic: c += pow(2, dic[rk], MOD)-1 c += 1 ans *= c ans %= MOD print((ans+zero-1)%MOD)
s=list(input()) k=0 bef="x" n=[] ans=0 def kai(n): if n==0: return 0 ret=0 for i in range(1,n+1): ret+=i return ret for i in s: if bef!=i: if bef=="x": st=i bef=i k+=1 continue bef=i n.append(k) k=0 k+=1 n.append(k) n.reverse() if st==">": ans+=kai(n.pop()) while len(n)!=0: if len(n)==1: ans+=kai(n.pop()) else: f=n.pop() s=n.pop() if f>s: ans+=kai(f)+kai(s-1) else: ans+=kai(f-1)+kai(s) #print("{} {}".format(f,s)) print(ans)
0
null
88,938,873,992,100
146
285
#ALDS_3_B 16D8103010K Ko Okasaki from collections import deque n,q=map(int,input().split()) que=deque() for i in range(n): name,time=input().split() time=int(time) que.append([name,time]) t=0 while len(que)>0: que_t=que.popleft() if que_t[1]>q: que_t[1]-=q t+=q que.append(que_t) else: t+=que_t[1] print(que_t[0],t)
n = int(input()) a = list( map(int, input().split())) p =10**9+7 cnt= [0]*n cnt[0]=1 ans = 3 if a[0]!=0: print(0) exit() for i in range(1,n): if a[i]==0: ans *= (3-cnt[a[i]]) else: ans *= (cnt[a[i]-1] - cnt[a[i]]) if cnt[a[i]-1]==0: print(0) exit() ans%=p cnt[a[i]] += 1 if cnt[a[i]]>3: print(0) exit() print(ans%p)
0
null
65,264,449,201,690
19
268
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): S = readline().rstrip().decode() print('x' * len(S)) if __name__ == '__main__': main()
M = int(input()) A = [int(_) for _ in input().split()] N = 1000 kabu = 0 if A[0] < A[1]: kabu, N = divmod(N, A[0]) for a, b, c in zip(A, A[1:], A[2:]): if a <= b >= c: N += kabu * b kabu = 0 elif a >= b <= c: dkabu, N = divmod(N, b) kabu += dkabu N += kabu * A[-1] print(N)
0
null
40,047,765,354,464
221
103
n,a,b=map(int,input().split()) if a%2==b%2: print((b-a)//2) exit() if a-1<n-b: print(a+(b-a-1)//2) else: print(n-b+1+(b-a-1)//2)
import sys n = int(input()) A=[[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)] #0??§????????? #[[[0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0]], # [[0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0]], # [[0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0]], # [[0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0]]] #?£? Building = b #??? Floor = f #??? Room = r #??° Number = num for i in range(n): b,f,r,num = input().strip().split() A[int(b)-1][int(f)-1][int(r)-1]+=int(num) for i in range(4): for j in range(3): print('',' '.join(map(str,A[i][j]))) if i!=3: print('#'*20)
0
null
55,574,039,310,582
253
55
s, w = map(int, input().split()) ans = "safe" if s > w else 'unsafe' print(ans)
def bubble(A, N): c = 0 flag = True while flag: flag = False for j in range(N-1, 0, -1): if A[j] < A[j-1]: A[j], A[j-1] = A[j-1], A[j] c += 1 flag = True return A, c if __name__ == "__main__": N = int(input()) A = [int(i) for i in input().split()] A, c = bubble(A, N) print (*A) print (c)
0
null
14,520,262,462,660
163
14
N = int(input()) S = list(input()) ans = 'No' if N%2 == 0: num = int(N/2) pre = S[:num] suf = S[num:] if pre == suf: ans = "Yes" print(ans)
a=list(input()) count=1 ans = 0 temp = 0 for i in range(len(a)-1): if a[i] ==a[i+1]: count+=1 else: if a[i]=='<': ans += count*(count+1)//2 temp = count #print('<', count, ans) count = 1 else: ans += count*(count+1)//2 ans -= min(count, temp) #print('>', count, ans) count =1 else: if a[-1]=='<': ans += count*(count+1)//2 else: ans += count*(count+1)//2 ans -= min(count, temp) print(ans)
0
null
152,305,876,969,408
279
285
import bisect N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 1, 1, -1): for j in range(i - 1, 0, -1): x = bisect.bisect(L, L[i] - L[j]) ans += max((j - x), 0) print(ans)
from sys import exit import math import collections ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) s = input() cnt = 0 for i in range(len(s)//2): if s[i] != s[-1-i]: cnt += 1 print(cnt)
0
null
146,136,998,452,420
294
261
import sys #UnionFindTreeクラスの定義 class UnionFind(): #クラスコンストラクタ #selfはインスタンス自身 def __init__(self, n): #親ノードを-1に初期化する self.parents = [-1] * n #根を探す(再帰関数) def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] #xとyの木を併合する def union(self, x, y): #x,yの根をX,Yとする X = self.find(x) Y = self.find(y) #根が同じなら結合済み if X == Y: return #ノード数が多い方をXとする if self.parents[X] > self.parents[Y]: X, Y = Y, X #XにYのノード数を足す self.parents[X] += self.parents[Y] #Yの根を X>0 とする self.parents[Y] = X N, M = map(int, input().split()) info = [tuple(map(int, s.split())) for s in sys.stdin.readlines()] #UnionFindインスタンスの生成 uf = UnionFind(N) for a, b in info: #インデックスを調整し、a,bの木を結合 a -= 1; b -= 1 uf.union(a, b) c = 0 for i in range(N): if uf.parents[i] < 0: c += 1 print(c-1)
import sys sys.setrecursionlimit(10**9) input = sys.stdin.buffer.readline N, M = map(int, input().split()) nextcity = [[] for _ in range(N)] sgn = [0 for _ in range(N)] while M: M -= 1 A, B = map(int, input().split()) A -= 1 B -= 1 nextcity[A].append(B) nextcity[B].append(A) def bfs(cnt, lis): nextvisit = [] for j in lis: for item in nextcity[j]: if sgn[item] == 0: nextvisit.append(item) sgn[item] = cnt if nextvisit: bfs(cnt, nextvisit) return None else: return None cnt = 0 for k in range(N): if sgn[k] == 0: cnt += 1 sgn[k] = cnt bfs(cnt, [k]) print(cnt -1)
1
2,274,331,124,750
null
70
70
#coding:utf-8 def seki(a, b): c = [] gou = 0 d = [] for i in range(len(a)): for j in range(len(b[0])): for k in range(len(b)): gou += a[i][k] * b[k][j] d.append(gou) gou = 0 c.append(d) d=[] return c n, m, l = [int(i) for i in input().rstrip().split()] a = [list(map(int , input().rstrip().split())) for i in range(n)] b = [list(map(int , input().rstrip().split())) for i in range(m)] c = seki(a,b) for i in c: print(" ".join(list(map(str,i))))
if __name__ == '__main__': n, m, l = [int(i) for i in input().split()] A = [[int(i) for i in input().split()] for j in range(n)] B = [[int(i) for i in input().split()] for j in range(m)] B = list(map(list, zip(*B))) # trace C = [[sum(map(lambda x,y: x*y, A[i], B[j])) for j in range(l)] for i in range(n)] for i in C: print(' '.join([str(x) for x in i]))
1
1,424,520,808,618
null
60
60
n = int(input()) a = [n] if n != 2: a.append(n - 1) def div_(N, k): while N % k == 0: N /= k if N % k == 1: a.append(k) for k in range(2, int(n ** 0.5) + 1): if n % k == 0: div_(n,k) if k != n / k: div_(n, n // k) if (n - 1) % k == 0: a.append(k) if k != (n - 1) / k: a.append((n - 1) // k) print(len(a))
import math N=int(input()) if N==2: print(1) exit() def yaku(n): a=set() s=int(math.sqrt(n)) for i in range(2,s+1): if n%i==0: a.add(i) a.add(n//i) return a ans=len(yaku(N-1))+1 a=yaku(N) for i in a: n=N while n%i==0: n=n//i if n%i==1: ans+=1 print(ans+1)
1
41,279,211,890,808
null
183
183
while True: n = str(input()) if n == "-": break m = int(input()) for i in range(m): h=int(input()) n = n[h:len(n)] + n[0:h] print(n)
# coding: utf-8 # Here your code ! def shuffle_chars(): chars = "chars" shuffle_num = "shuffle_num" #load data inputdata=[] i = -1 while(True): try: line = input().rstrip() if line == "-" : break elif line.isalpha() : inputdata.append({chars: line, shuffle_num: []}) tmp = input() i += 1 else: inputdata[i][shuffle_num].append(int(line)) except EOFError: break except : return inputError() #shuffle for item in inputdata: for num in item[shuffle_num] : item[chars] = item[chars][num:] + item[chars][:num] print(item[chars]) def inputError(): print("input Error") return -1 if __name__ == "__main__" : shuffle_chars()
1
1,930,675,141,918
null
66
66
a, b, c = list(map(int, input().split())) k = int(input()) for i in range(k): if a >= b: b *= 2 else: c *= 2 if a < b and b < c: print('Yes') else: print('No')
while True: h,w = map(int,input().split()) if h == 0 and w == 0: break for x in range(h): if x == range(h)[0] or x == range(h)[-1]: print(w*"#",end="") else: for y in range(w): if y == range(w)[0] or y == range(w)[-1]: print("#",end="") else: print(".",end="") print() print()
0
null
3,859,087,401,390
101
50
N = int(input()) A = list(map(int,input().split())) for i in range(N): A[i] = (A[i],i+1) A.sort() ans = '' for tup in A: v, i = tup ans+=str(i)+' ' print(ans)
N=int(input()) A=list(map(int,input().split())) res=[0]*N for i in range(N): res[A[i]-1]=i+1 for j in res: print(j,end=" ")
1
179,981,357,387,250
null
299
299
from math import ceil H,W=map(int,input().split()) print(ceil(H*W/2) if H!=1 and W!=1 else 1)
H,W = map(int, input().split()) if H == 1 or W == 1: print(1) else: t = H * W print(t // 2) if t % 2 == 0 else print((t // 2) + 1)
1
50,648,470,808,540
null
196
196
#!/usr/bin/env python3 def next_line(): return input() def next_int(): return int(input()) def next_int_array_one_line(): return list(map(int, input().split())) def next_int_array_multi_lines(size): return [int(input()) for _ in range(size)] def next_str_array(size): return [input() for _ in range(size)] def main(): h, w, k = map(int, input().split()) ch = [] for _ in range(h): ch.append(next_line()) # print(ch) res = 0 for i in range(1 << h): for j in range(1 << w): count = 0 for l in range(h): for m in range(w): if ch[l][m] == "#" and (i & (1 << l) == 0) and (j & (1 << m) == 0): count += 1 if count == k: res += 1 print(res) if __name__ == '__main__': main()
import itertools H, W, K = list(map(int,input().split())) board = [] for i in range(H): row = input() board.append(row) result = [] for n in range(len(board)+1): for conb in itertools.combinations(board, n): result.append(list(conb)) rotate_result = [] for i in range(len(result)): rotate_result.append([list(x) for x in zip(*result[i])]) ans = 0 result2 = [] for i in range(len(rotate_result)): for j in range(len(rotate_result[i])+1): for conb in itertools.combinations(rotate_result[i], j): result2.append(list(conb)) l = list(itertools.chain.from_iterable(list(conb))) if l != []: count = 0 for k in range(len(l)): if l[k] == "#": count += 1 if k == len(l)-1 and count == K: ans += 1 print(ans)
1
8,867,152,966,560
null
110
110
N = int(input()) A = [[0]*10 for _ in range(10)] for i in range(1,N+1): a = i%10 #1の位 b = i // (10**(len(str(i))-1)) if a!= 0: A[a][b] += 1 t = 0 for i in range(1,10): s = A[i][i] if s != 0: t += int(s + (s*(s-1))) for i in range(1,9): for j in range(i+1,10): t += A[i][j] * A[j][i]*2 print(t)
N = int(input()) a = [0] i = 0 L = 26 while True: if a[i] < N <= a[i] + L**(i + 1): break a.append(a[i] + L**(i + 1)) i += 1 N -= a[i] + 1 for j in range(i, -1, -1): if j > 0: print(chr(N // L**(j) + ord('a')), end="") else: print(chr(N + ord('a')), end="") N = N % L**(j)
0
null
49,266,182,203,200
234
121
s = input() a = input() print("Yes" if a[:-1]==s else "No")
N = int(input()) l0 = [[int(i) for i in input().split()] for _ in range(N)] l1 = [0] * N l2 = [0] * N for cnt, val in enumerate(l0): l1[cnt] = val[0] + val[1] l2[cnt] = val[0] - val[1] l1.sort() l2.sort() print(max(l1[-1] - l1[0], l2[-1] - l2[0]))
0
null
12,440,898,083,120
147
80
n, m = map(int,input().split()) a = list(map(int,input().split())) if n - sum(a) >= 0: print(n - sum(a)) else: print('-1')
N, M = map(int, input().split(' ')) A_ls = list(map(int, input().split(' '))) if sum(A_ls) > N: print(-1) else: print(N - sum(A_ls))
1
31,855,927,040,572
null
168
168
n, W = map(int, input().split()) ab = [tuple(map(int, input().split()))for _ in range(n)] ab.sort() dp = [[0]*W for _ in range(n+1)] for i in range(1, n+1): w, v = ab[i-1] for j in range(W): if dp[i][j] < dp[i-1][j]: dp[i][j] = dp[i-1][j] if 0 <= j-w and dp[i][j] < dp[i-1][j-w]+v: dp[i][j] = dp[i-1][j-w]+v ans = 0 for i in range(n): a, b = ab[i] if ans < dp[i][W-1]+b: ans = dp[i][W-1]+b print(ans)
H, A = map(int,input().split()) a = int(H/A) b = H/A if a==b: print(a) else: c = a+1 print(c)
0
null
114,157,440,793,920
282
225
h = int(input()) w = int(input()) n = int(input()) x = max(h, w) ans = (n + x - 1) // x print(ans)
h = int(input()) w = int(input()) n = int(input()) x = max(h, w) cnt = 0 cur = 0 while cur < n: cur += x cnt+=1 print(cnt)
1
88,584,733,162,156
null
236
236
def cube(x): return x**3 n = int(input()) print(cube(n))
def sample(n): return n * n * n n = input() x = sample(n) print x
1
276,935,830,780
null
35
35
n=int(input()) x=n%100 y=n//100 if(y*5>=x): print("1") else: print(0)
n = int(input()) a = [] b = [] for i in range(n): a_1, b_1 = input().split() a.append(int(a_1)) b.append(int(b_1)) a.sort() b.sort() is_odds = n % 2 == 0 if n % 2 == 0: print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1) else: print(b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1)
0
null
72,405,191,540,920
266
137
if __name__ == '__main__': s = input() q = int(input()) for i in range(q): code = input().split() op, a, b = code[0], int(code[1]), int(code[2]) if op == 'print': print(s[a:b+1]) elif op == 'reverse': s = s[:a] + s[a:b+1][::-1] + s[b+1:] elif op == 'replace': s = s[:a] + code[3] + s[b+1:]
s = input() n = int(input()) for _ in range(n): li = input().split() op = li[0] a, b = map(int, li[1:3]) if op == "replace": p = li[3] s = s[:a] + p + s[b+1:] elif op == "reverse": s = s[:a] + s[a:b+1][::-1] + s[b+1:] elif op == "print": print(s[a:b+1])
1
2,100,960,567,828
null
68
68
n = int(input()) fives = [0] if n % 2 == 1: print(0) else: i = 0 while 1: temp5 = (n // (5** (i +1))) //2 if temp5 != 0: fives.append(temp5) i += 1 else: break print(sum(fives))
N = input() def f(x): p = 1 i = 1 cnt = 0 while p > 0: p = x // (5**i) // 2 cnt += p i += 1 return cnt if int(N[-1])%2 == 1: print(0) else: print(f(int(N)))
1
115,647,533,210,452
null
258
258