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
from math import pi r=input() print"%.8f %.8f"%(pi*r*r,2*pi*r)
N=int(input()) K=int(input()) import sys sys.setrecursionlimit(10**6) def solve(N, K): if K==1: l=len(str(N)) ans=0 for i in range(l): if i!=l-1: ans+=9 else: ans+=int(str(N)[0]) #print(ans) return ans else: nextK=K-1 l=len(str(N)) ini=int(str(N)[0]) res=ini*(10**(l-1))-1 #print(res) if l>=K: ans=solve(res, K) else: ans=0 if l-1>=nextK: nextN=int(str(N)[1:]) ans+=solve(nextN, nextK) return ans return ans ans=solve(N,K) print(ans)
0
null
38,213,427,947,772
46
224
l=int(input()) print(str(l*l*l/27)+"\n")
from collections import defaultdict N, K, *A = map(int, open(0).read().split()) x = [0] * (N + 1) for i in range(N): x[i + 1] = x[i] + A[i] y = [(x[i] - i) % K for i in range(N + 1)] ctr = defaultdict(int) ans = 0 for j in range(N + 1): ans += ctr[y[j]] ctr[y[j]] += 1 if j - K + 1 >= 0: ctr[y[j - K + 1]] -= 1 print(ans)
0
null
92,241,561,370,624
191
273
X, Y = list(map(int, input().split())) pX = [0 for _ in range(206)] pX[1] = 300000 pX[2] = 200000 pX[3] = 100000 point = pX[X] + pX[Y] if X == 1 and Y == 1: point += 400000 print(point)
N = list(input()) for i in N: if i == "7": print("Yes") exit() print("No")
0
null
87,500,406,119,236
275
172
a, b =map(int, input().split()) m = a*b lst = [] for i in range(1, b+1): if m < a*i: break lst.append(a*i) for j in lst: if j%b == 0: print(j) break
import itertools for x, y in itertools.product(range(1, 10), range(1, 10)): print("%dx%d=%d" % (x, y, x * y))
0
null
56,490,497,432,030
256
1
def check(mlist, s): if len(mlist) == 13: return 0 else: lack = [] for i in range(1, 14): if not i in mlist: lack.append(i) #print(lack) for j in lack: print("{} {}".format(s, j)) return 0 n = int(input()) Slist = [] Hlist = [] Clist = [] Dlist = [] for i in range(n): mark, num = input().split() num = int(num) if mark == 'S': Slist.append(num) elif mark == 'H': Hlist.append(num) elif mark == 'C': Clist.append(num) else: Dlist.append(num) Slist.sort() Hlist.sort() Clist.sort() Dlist.sort() check(Slist, 'S') check(Hlist, 'H') check(Clist, 'C') check(Dlist, 'D')
n = int(input()) s = input() prev = "" ans = "" for i in range(n): if s[i] == prev: continue prev = s[i] ans += s[i] print(len(ans))
0
null
85,304,564,866,592
54
293
n = int(input()) A = list(map(int, input().split())) total = 0 min_ = A[0] for i in range(n): if A[i] > min_: min_ = A[i] else: total += (min_ - A[i]) print(total)
# -*- coding: utf-8 -*- memo = ['' for i in xrange(45)] def recursion(n): if n == 0 or n == 1: return 1 return recursion(n - 1) + recursion(n - 2) def memo_search(n): if memo[n] != '': return memo[n] else: if n == 0 or n == 1: memo[n] = 1 return 1 memo[n] = memo_search(n - 1) + memo_search(n - 2) return memo[n] if __name__ == '__main__': n = input() # print recursion(n) print memo_search(n)
0
null
2,299,186,540,960
88
7
x = list(map(int,input().split())) a = x[0] b = x[1] if(2*b < a): print(a-2*b) else: print(0)
n,m,l=map(int,input().split()) abc=[list(map(int,input().split())) for _ in [0]*m] q=int(input()) st=[list(map(int,input().split())) for _ in [0]*q] inf=10**12 dist=[[inf]*n for _ in [0]*n] for i in range(n): dist[i][i]=0 for a,b,c in abc: dist[a-1][b-1]=c dist[b-1][a-1]=c for k in range(n): for i in range(n): for j in range(n): dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]) inf=10**3 dist2=[[inf]*n for _ in [0]*n] for i in range(n): for j in range(n): if dist[i][j]<=l: dist2[i][j]=1 for k in range(n): for i in range(n): for j in range(n): dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j]) for i in range(n): for j in range(n): if dist2[i][j]==inf: dist2[i][j]=-1 else: dist2[i][j]-=1 for s,t in st: print(dist2[s-1][t-1])
0
null
170,775,235,221,338
291
295
def main(): d, t, s = map(int, input().split()) print("Yes" if d / s <= t else "No") if __name__ == "__main__": main()
import math import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") D,T,S = LI() if T < D/S: ans = 'No' else: ans = 'Yes' print(ans)
1
3,510,720,897,828
null
81
81
a,b,k = map(int,input().split()) if a >= k: print(str(a - k) + " " + str(b)) elif a < k and b - k + a >= 0: print("0" + " " + str(b - k + a)) else: print("0" + " " + "0")
a = [int(i) for i in input().split()] if a[0]+a[1]<=a[2]: print(0,0) elif a[0]>=a[2]: print(a[0]-a[2],a[1]) elif a[0]<a[2]: b = a[2]-a[0] print(0,a[1]-b)
1
104,350,581,838,052
null
249
249
import numpy as np n = int(input()) a = list(map(int,input().split())) a = np.array(a,dtype=np.int64) point = 0 mod = 10**9+7 b = [((a>>i)&1).sum() for i in range(61)] c = [n-b[i] for i in range(61)] d = [c[i]*b[i]%mod for i in range(61)] point = 0 now = 1 for i in range(61): point += now*d[i] point %= mod now *= 2 now %= mod print(point)
import sys rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) flag = False s = rr() q = ri() front = '' end = '' for _ in range(q): query = list(rs()) if query[0] == '1': flag = not flag continue else: f = int(query[1]) c = query[-1] if flag == True: if f == 1: end += c else: front = c+front else: if f == 1: front = c+front else: end += c if flag: print((front+s+end)[::-1]) else: print(front+s+end)
0
null
90,015,972,435,070
263
204
a,b,c=map(int,input().split()) if 4*a*b<(c-a-b)*(c-a-b) and c-a-b>=0: print("Yes") else: print("No")
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 def main(): N=int(input()) A=list(map(int,input().split())) B=[(A[i],i) for i in range(N)] B.sort(key=lambda t: -t[0]) dp=[[0]*(N+1) for _ in range(N+1)] ans=0 for i in range(N): for x in range(i+1): y=i-x dp[x+1][y]=max(dp[x+1][y],dp[x][y]+B[i][0]*abs(B[i][1]-x)) dp[x][y+1]=max(dp[x][y+1],dp[x][y]+B[i][0]*abs(N-1-y-B[i][1])) ans=max(ans,dp[x+1][y],dp[x][y+1]) print(ans) if __name__ == '__main__': main()
0
null
42,646,072,877,478
197
171
def minkovsky(A,B,n = 0): C = [abs(a - b) for a , b in zip(A,B)] if n == 0: return max(C) else: d = 0 for c in C: d += c ** n d = d ** (1 / n) return d N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) print(minkovsky(A,B,1)) print(minkovsky(A,B,2)) print(minkovsky(A,B,3)) print(minkovsky(A,B))
N = int(input()) memo = [] memo = [1,1] + [0] * (N - 1) def f(n): if memo[n] == 0: memo[n] = f(n-1) + f(n-2) return(memo[n]) if memo[n] != 0: return(memo[n]) print(f(N))
0
null
103,068,084,940
32
7
c = input() if c == "RRR": print(3) elif "RR" in c: print(2) elif "R" in c: print(1) else: print(0)
total, max, time=map(int, input().split()) print (time*int(total/max) if total%max==0 else time*(int(total/max)+1))
0
null
4,586,253,881,472
90
86
import sys a = [] for line in sys.stdin: a.append(int(line)) b = [0, 0, 0] for i in a: j = 0 while j < 3: if i > b[j]: b.insert(j, i) break j += 1 for i in b[:3]: print i
a = [] for i in range(10) : a.append(int(input())) a.sort() a.reverse() print("%d\n%d\n%d" % (a[0], a[1], a[2]))
1
29,036,888
null
2
2
H, N = map(int, input().split()) dp = [10 ** 9] * (H + 1) dp[0] = 0 for _ in range(N): a, b = map(int, input().split()) for i in range(H): idx = min(H, i + a) dp[idx] = min(dp[idx], dp[i] + b) print(dp[H])
x = list(map(int, input().split())) print(x[2], x[0], x[1])
0
null
59,572,577,307,298
229
178
n,m=map(int,input().split()) if n%2==1: [print(i+1,n-i) for i in range(m)] else: [print(i+1,n-i) if i<m/2 else print(i+1,n-i-1) for i in range(m)]
import sys N,M = map(int,input().split()) if N%2 == 1: for i in range(1,M+1): print(i,N-i+1) elif N%4 == 0: total = 0 count = 1 for i in range(N//4,0,-1): print(i,i+count) count += 2 total += 1 if total >= M: sys.exit() count = 2 for i in range(3*(N//4)-1,N//2,-1): print(i,i+count) count += 2 total += 1 if total >= M: sys.exit() else: total = 0 count = 1 for i in range(N//4,0,-1): print(i,i+count) count += 2 total += 1 if total >= M: sys.exit() count = 2 for i in range(3*(N//4),N//2-1,-1): print(i,i+count) count += 2 total += 1 if total >= M: sys.exit()
1
28,536,942,529,618
null
162
162
a = raw_input().split(" ") W = int(a[0]) H = int(a[1]) x = int(a[2]) y = int(a[3]) r = int(a[4]) if (x - r) >= 0 and (x + r) <= W and (y - r) >= 0 and (y + r) <= H: print "Yes" else: print "No"
def main(): n, k = map(int, input().split()) lr = [list(map(int, input().split())) for _ in range(k)] dp = [0] * (n + 1) dp[1] = 1 dpsum = [0] * (n + 1) dpsum[1] = 1 mod = 998244353 for i in range(2, n + 1): for j in range(k): li = max(i - lr[j][1], 1) ri = i - lr[j][0] if ri < 0: continue dp[i] = (dp[i] + dpsum[ri] - dpsum[li - 1]) % mod dpsum[i] = dpsum[i - 1] + dp[i] print(dp[-1] % mod) if __name__ == "__main__": main()
0
null
1,603,650,859,840
41
74
cards = { 'S': [0 for _ in range(13)], 'H': [0 for _ in range(13)], 'C': [0 for _ in range(13)], 'D': [0 for _ in range(13)], } n = int(input()) for _ in range(n): (s, r) = input().split() cards[s][int(r) - 1] = 1 for s in ('S', 'H', 'C', 'D'): for r in range(13): if cards[s][r] == 0: print(s, r + 1)
n = int(input()) full_set=set([x for x in range(1,14)]) cards={"S":[],"H":[],"C":[],"D":[]} for i in range(n): suit,num = input().split() cards[suit].append(int(num)) for suit in ["S","H","C","D"]: suit_set = set(cards[suit]) for num in sorted(list(full_set - suit_set)): print(suit,num)
1
1,059,153,050,428
null
54
54
x,k,d = list(map(int, input().split())) amari = abs(x) % d shou = abs(x) // d amari_ = abs(amari - d) if k < shou: print(abs(x) - d * k) else: if (k - shou) % 2 == 0: print(amari) else: print(amari_)
X,K,D=list(map(int,input().split())) X=abs(X) import sys if X > 0 and X-K*D>=0: print(X-K*D) sys.exit() M=X//D Q=X%D if M%2 == K%2: print(Q) else: print(D-Q)
1
5,264,151,867,388
null
92
92
s=int(input()) A=[0,0,1] for i in range(3,s): A+=[A[i-1]+A[i-3]] print(A[s-1]%(10**9+7))
def main(): s = int(input()) mod = 10**9 + 7 dp = [0] * (s+1) dp[0] = 1 for i in range(1, s+1): for j in range(0, (i-3)+1): dp[i] += dp[j] dp[i] %= mod print(dp[-1]) if __name__ == "__main__": main()
1
3,324,224,745,012
null
79
79
nums = input().split() print(int(nums[0]) * int(nums[1]))
import math from math import gcd,pi,sqrt INF = float("inf") import sys sys.setrecursionlimit(10**6) import itertools from collections import Counter,deque def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def main(): n = i_input() if n%2==1: print(0) exit() ans = 0 cnt = 10 while True: ans += n//cnt cnt *= 5 if cnt > n: break print(ans) if __name__=="__main__": main()
0
null
66,134,206,871,858
133
258
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'] ans = [] def dfs(idx, cnt, lis): if idx==N: ans.append(''.join(lis)) return for i in range(cnt): dfs(idx+1, cnt, lis+[alpha[i]]) dfs(idx+1, cnt+1, lis+[alpha[cnt]]) return dfs(0, 0, []) ans.sort() for a in ans: print(a)
class dice: top = 1 flont = 2 right = 3 def do_N(self): temp = self.flont self.flont = 7-self.top self.top = temp def do_S(self): temp = 7-self.flont self.flont = self.top self.top = temp def do_E(self): temp = self.top self.top = 7-self.right self.right = temp def do_W(self): temp = 7-self.top self.top = self.right self.right = temp num1 = list(map(int, input().split())) order1 = input() dice1 = dice() for i in range(len(order1)): if order1[i] == "N": dice1.do_N() elif order1[i] == "S": dice1.do_S() elif order1[i] == "E": dice1.do_E() elif order1[i] == "W": dice1.do_W() print(str(num1[dice1.top-1]))
0
null
26,492,792,648,542
198
33
class Dice: def __init__(self, U, S, E, W, N, D): self.u, self.d = U, D self.e, self.w = E, W self.s, self.n = S, N def roll(self, commmand): if command == 'E': self.e, self.u, self.w, self.d = self.u, self.w, self.d, self.e elif command == 'W': self.e, self.u, self.w, self.d = self.d, self.e, self.u, self.w elif command == 'S': self.s, self.u, self.n, self.d = self.u, self.n, self.d, self.s else: self.s, self.u, self.n, self.d = self.d, self.s, self.u, self.n def rightside(self, upside, forward): self.structure = {self.u:{self.w: self.s, self.s: self.e, self.e: self.n, self.n: self.w}, self.d:{self.n: self.e, self.e: self.s, self.s: self.w, self.w: self.n}, self.e:{self.u: self.s, self.s: self.d, self.d: self.n, self.n: self.u}, self.s:{self.u: self.w, self.w: self.d, self.d: self.e, self.e: self.u}, self.w:{self.u: self.n, self.n: self.d, self.d: self.s, self.s: self.u}, self.n:{self.u: self.e, self.e: self.d, self.d: self.w, self.w: self.u}} print(self.structure[upside][forward]) U, S, E, W, N, D = [int(i) for i in input().split()] turns = int(input()) dice1 = Dice(U, S, E, W, N, D) for i in range(turns): upside, forward = [int(k) for k in input().split()] dice1.rightside(upside, forward)
d = { (1,2): 3, (1,3): 5, (1,4): 2, (1,5): 4, (2,1): 4, (2,3): 1, (2,4): 6, (2,6): 3, (3,1): 2, (3,2): 6, (3,5): 1, (3,6): 5, (4,1): 5, (4,2): 1, (4,5): 6, (4,6): 2, (5,1): 3, (5,3): 6, (5,4): 1, (5,6): 4, (6,2): 4, (6,3): 2, (6,4): 5, (6,5): 3 } v = list(map(int, input().split())) q = int(input()) questions = [] for _ in range(q): x, y = map(int, input().split()) questions.append((x,y)) vTod = dict(zip(v,list(range(1,7)))) dTov = {v:k for k, v in vTod.items()} for top, face in questions: top = vTod[top] face = vTod[face] right = d[(top,face)] right = dTov[right] print(right)
1
261,576,117,288
null
34
34
import sys def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s); sys.stdout.write('\n') def wi(n): sys.stdout.write(str(n)); sys.stdout.write('\n') def wia(a, sep=' '): sys.stdout.write(sep.join([str(x) for x in a])); sys.stdout.write('\n') def main(): n = ri() x = rs() k = int(x, 2) d = x.count('1') if d > 1: k0 = k % (d-1) k1 = k % (d+1) f = [0] * (n + 1) for i in range(1, n+1): f[i] = f[i % bin(i).count('1')] + 1 for i in range(n): cnt = 0 if x[i] == '1' and d - 1 > 0: cnt += f[(k0 - pow(2, n - i - 1, d - 1)) % (d - 1)] + 1 elif x[i] == '0': cnt += f[(k1 + pow(2, n - i - 1, d + 1)) % (d + 1)] + 1 wi(cnt) if __name__ == '__main__': main()
ans = 100000 n = int(raw_input()) for i in xrange(n): ans *= 1.05 ans = int((ans+999)/1000)*1000; print ans
0
null
4,062,828,373,692
107
6
S = input() ans = 0 l, r = 0, 0 i = 0 while i < len(S): while i < len(S) and S[i] == "<": l += 1 i += 1 while i < len(S) and S[i] == ">": r += 1 i += 1 ans += l * (l + 1) // 2 ans += r * (r + 1) // 2 ans -= min(l, r) l, r = 0, 0 print(ans)
def main(): from operator import itemgetter N = int(input()) a = map(int, input().split()) *ea, = enumerate(a, 1) ea.sort(key=itemgetter(1), reverse=True) dp = [[0] * (N + 1) for _ in range(N + 1)] # dp[left][right]:=活発な幼児から順に左端からleft,右端からright並べた際の最大うれしさ for i, (p, x) in enumerate(ea, 1): for left in range(i + 1): right = i - left if left > 0: dp[left][right] = max( dp[left][right], dp[left - 1][right] + x * (p - left) ) if right > 0: dp[left][right] = max( dp[left][right], dp[left][right - 1] + x * (N - right + 1 - p) ) ans = max(dp[i][N - i] for i in range(N + 1)) print(ans) if __name__ == '__main__': main()
0
null
95,219,849,720,468
285
171
FAST_IO = 0 if FAST_IO: import io, sys, atexit rr = iter(sys.stdin.read().splitlines()).next sys.stdout = _OUTPUT_BUFFER = io.BytesIO() @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) else: rr = raw_input rri = lambda: int(rr()) rrm = lambda: map(int, rr().split()) rrmm = lambda n: [rrm() for _ in xrange(n)] #### from collections import defaultdict as ddic, Counter, deque import heapq, bisect, itertools MOD = 10 ** 9 + 7 def solve(N, A): from fractions import gcd g = A[0] for x in A: g= gcd(g,x) if g > 1: return "not coprime" seen = set() for x in A: saw = set() while x % 2 == 0: x //= 2 saw.add(2) d = 3 while d*d <= x: while x%d == 0: saw.add(d) x //= d d += 2 if x > 1: saw.add(x) for p in saw: if p in seen: return "setwise coprime" seen |= saw return "pairwise coprime" N= rri() A = rrm() print solve(N, A)
import math N = int(input()) a = list(map(int,input().split())) m = max(a) c = [0] * (m+1) for i in a: c[i] += 1 pairwise = True for i in range(2, m+1, 1): cnt = 0 for j in range(i, m+1, i): cnt += c[j] if cnt > 1: pairwise = False break if pairwise: print("pairwise coprime") exit() g = 0 for i in range(N): g = math.gcd(g, a[i]) if g == 1: print("setwise coprime") exit() print("not coprime")
1
4,146,359,698,678
null
85
85
input_lists = list(input().split(' ')) result = [input_lists[-1]] result += input_lists[0:-1] result = ' '.join(result) print(result)
x,y,z = map(int, input().split()) a = x b = y c = z a = y b = x a = z c = y print(a,b,c)
1
38,113,368,332,478
null
178
178
import sys sys.setrecursionlimit(10**9) def main(): n, x, t = map(int, input().split()) if n % x == 0: print((n//x)*t) else: print((n//x+1)*t) return if __name__ == "__main__": main()
N, X, T = map(int,input().split()) n = 0 if N % X == 0: n = N / X else: n = N // X + 1 print(int(n * T))
1
4,241,784,364,928
null
86
86
import bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) N =I() _P= LI() #AB = [LI() for _ in range(N)] #A,B = zip(*AB) P = np.array(_P) #C = np.zeros(N + 1) def main(): # count = 1 # # if (len(P)==1): # # return count # min_array =[P[0]] # for i in range(1,N): # if (P[i]<=min_array[i-1]): # count += 1 # if P[i-1]>P[i]: # min_array.append(P[i]) # else: # min_array.append(P[i-1]) # return count # print(min_array) Q = np.minimum.accumulate(P) count = np.count_nonzero(P <= Q) return count print(main()) # if ans: # print('Yes') # else: # print('No')
N = int(input()) P = list(map(int, input().split())) mini = 10 ** 9 count = 0 for i in range(N): if P[i] <= mini: mini = P[i] count += 1 print(count)
1
85,141,405,881,858
null
233
233
x=int(input()) for a in range(-200,200,1): for b in range(-200,200,1): if a**5 - b**5 == x: print(a,b) exit()
N=int(input()) X=input() popcount=X.count('1') mod = [popcount+1, popcount-1] bi = [[0] * N for _ in range(2)] Xnum = [0] * 2 add_diff = [1, -1] for j in range(2): if mod[j] != 0: for i in range(N): if i==0: bi[j][0]=1%mod[j] else: bi[j][i]=bi[j][i-1]*2%mod[j] Xnum[j] = (Xnum[j] + int(X[N-i-1])*bi[j][i])%mod[j] for i in range(N): if popcount==1 and X[i]=='1': print(0) continue Xi = ( Xnum[int(X[i])] + add_diff[int(X[i])] * bi[int(X[i])][N-i-1] ) % mod[int(X[i])] ans = 1 while Xi!=0: Xi = Xi % bin(Xi).count('1') ans += 1 print(ans)
0
null
16,897,905,966,108
156
107
import numpy as np a,b,c = map(int,input().split()) print(int(np.ceil(a/b)*c))
n=int(input()) a= [list(map(int, input().split())) for i in range(n)] a1=float('inf') a2=-float('inf') a3=float('inf') a4=-float('inf') for i in range(n): cnt=a[i][0]+a[i][1] cnt1=a[i][0]-a[i][1] a1=min(a1,cnt) a2=max(a2,cnt) a3=min(cnt1,a3) a4=max(cnt1,a4) print(max(a2-a1,a4-a3))
0
null
3,854,147,750,860
86
80
# -*- coding: utf-8 -*- """ Created on Thu May 7 23:19:34 2020 @author: Kanaru Sato """ def dfs(v): global t d[v] = t t += 1 if conlist[v]: for connectedv in conlist[v]: if d[connectedv] == -1: dfs(connectedv) f[v] = t t += 1 n = int(input()) conlist = [[] for i in range(n)] for i in range(n): _ = list(map(int,input().split())) [conlist[i].append(_[k]-1) for k in range(2,_[1]+2)] d = [-1 for i in range(n)] f = [-1 for i in range(n)] t = 1 for i in range(n): if d[i] == -1: dfs(i) for i in range(n): print(i+1,d[i],f[i])
n = int(input()) graph = [-1] + [list(map(int, input().split())) for _ in range(n)] seen = [False]*(n+1) seen[0] = True d = [-1]*(n+1) f = [-1]*(n+1) time = 0 def dfs(v): global time time += 1 d[v] = time seen[v] = True k = graph[v][1] if k > 0: for i in range(k): w = graph[v][i+2] if seen[w] is False: dfs(w) time += 1 f[v] = time v = 0 while v <= n: if seen[v] is False: dfs(v) v += 1 for i in range(1, n+1): print(i, d[i], f[i])
1
2,944,130,980
null
8
8
for _ in[0]*int(input()):a,b,c=sorted(map(int,input().split()));print(['NO','YES'][a*a+b*b==c*c])
import itertools def check(a,b,c): for p in itertools.permutations([a,b,c]): (x,y,z)=p if x*x+y*y==z*z: return True return False n=input() for i in range(n): (a,b,c)=map(eval,raw_input().split()) if check(a,b,c): print "YES" else: print "NO"
1
300,848,670
null
4
4
def main2(): K = int(input()) rem = set() n = ans = 0 while True: n = n * 10 + 7 ans += 1 if n % K == 0: print(ans) break else: n = n % K if n in rem: print(-1) break else: rem.add(n) if __name__ == "__main__": main2()
K = int(input()) if K%2==0: print(-1) elif K==1: print(1) elif K==7: print(1) else: if K%7==0: K = K//7 a = 1 cnt = 1 ind = -1 for i in range(K): a = (a*10)%K cnt += a if cnt%K==0: ind = i break if ind<0: print(-1) else: print(ind+2)
1
6,132,903,964,160
null
97
97
n = int(input()) s = input() t = '' for c in s: t += chr((ord(c) + n - 65) % 26 + 65 ) print(t)
N = int(input()) S = input() base = ord("A") ans = "" for i in range(len(S)): p = (ord(S[i])-base) s = (p+N) % 26 ans += chr(s+base) print(ans)
1
134,367,010,926,820
null
271
271
N = int(input()) A, B = [], [] for i in range(N): a, b = map(int, input().split()) A += [a] B += [b] A.sort() B.sort() if N%2 == 1: med_minimum = A[(N-1)//2] med_maximum = B[(N-1)//2] else: med_minimum = (A[(N-2)//2] + A[(N-2)//2+1]) med_maximum = (B[(N-2)//2] + B[(N-2)//2+1]) print(med_maximum - med_minimum + 1)
print(str((lambda x:x**3)(int(input()))))
0
null
8,773,083,420,608
137
35
import sys def gcd(a,b): if a%b==0: return b return gcd(b,a%b) r=[list(map(int,line.split())) for line in sys.stdin] for i in r: o=gcd(i[0],i[1]) p=i[0]*i[1]/o print(o,int(p))
a,b,c,k=map(int,input().split()) if k < a: print(k) elif k <= a+b: print(a) else: print(2*a+b-k)
0
null
10,845,473,006,290
5
148
from itertools import permutations as p N = int(input()) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) j = 0 for i in p(range(1, N + 1)): j += 1 if i == P: a = j if i == Q: b = j if a - b >= 0: print(a - b) else: print(b - a)
n=int(input()) p=list(map(int,input().split())) res=p[0] cnt=0 for i in p: if res>=i: cnt+=1 res=min(res,i) print(cnt)
0
null
93,021,761,346,352
246
233
t = input() n = len(t) t += "a" ans = "" for i in range(n): if t[i] == "?": ans += "D" else: ans += t[i] print(ans)
T = list(input()) tlen = len(T) for i in range(0, tlen): if T[i] == '?': T[i] = 'D' print(*T,sep='')
1
18,641,327,394,660
null
140
140
X = int(input()) answer = (X // 500) * 1000 X %= 500 answer += (X // 5) * 5 print(answer)
s = input() t = input() c = 0 ctemp = 0 for i in range((len(s)-len(t))+1): for j in range(len(t)): if s[j+i] == t[j]: ctemp += 1 c = max(c,ctemp) ctemp = 0 ans = len(t) - c print(ans)
0
null
23,295,760,376,900
185
82
n,m = (int(i) for i in input().split()) array = [[int(i) for i in input().split()] for i in range(n)] b = [int(input()) for i in range(m)] for i in range(n): ans = 0 for i2 in range(m): ans += array[i][i2]*b[i2] print(ans)
from operator import itemgetter import bisect N, D, A = map(int, input().split()) enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0)) d_enemy = [enemy[0] for enemy in enemies] b_left = bisect.bisect_left logs = [] logs_S = [0, ] ans = 0 for i, enemy in enumerate(enemies): X, hp = enemy start_i = b_left(logs, X-2*D) count = logs_S[-1] - logs_S[start_i] hp -= count * A if hp > 0: attack_num = (hp + A-1) // A logs.append(X) logs_S.append(logs_S[-1]+attack_num) ans += attack_num print(ans)
0
null
41,928,323,750,080
56
230
n_1 = list(map(int, input().split())) n_2 = list(map(int, input().split())) if n_1[0] != n_2[0]: print(1) else: print(0)
a,b = map(int, input().split()) c,d = map(int, input().split()) if d == 1: print('1') else: print('0')
1
124,061,913,544,022
null
264
264
import fractions a, b = map(int, input().split()) print(int(a*b / fractions.gcd(a,b)))
a,b=map(int,input().split()) 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==[]: arr.append([n,1]) return arr a_arr = factorization(a) b_arr = factorization(b) a_map = {str(arr[0]):arr[1] for arr in a_arr} b_map = {str(arr[0]):arr[1] for arr in b_arr} factor = set(list(a_map.keys())+list(b_map.keys())) ans = 1 for i in factor: if str(i) in a_map.keys(): a_num = a_map[str(i)] else: a_num = 0 if str(i) in b_map.keys(): b_num = b_map[str(i)] else: b_num = 0 ans *= int(i)**(max(a_num,b_num)) print(ans)
1
113,751,258,613,578
null
256
256
n, k = map(int, input().split()) d = [0] * k a = [] for i in range(k): d[i] = int(input()) a_in = list(map(int, input().split())) a.extend(a_in) num = len(set(a)) print(n-num)
div = 0 mod = 0 h = int(input()) w = int(input()) n = int(input()) if h > w: div = n // h mod = n % h else: div = n // w mod = n % w if mod > 0: print(div+1) else: print(div)
0
null
56,833,454,970,802
154
236
import sys n, k = map(int, input().split()) hn = sorted(list(map(int, sys.stdin.readline().split())), reverse=True) ans = sum(hn[k:]) print(ans)
n,k=map(int,input().split()) l=list(map(int,input().split())) l.sort(reverse=True) s=sum(l[k:]) print(s)
1
79,160,729,446,162
null
227
227
# -*- coding: utf-8 -*- """ Created on Wed May 2 21:28:06 2018 ALDS1_5a @author: maezawa """ import itertools as itr n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) sum_array = [] for r in range(1,n+1): for comb in itr.combinations(a, r): sum_array.append(sum(comb)) for i in m: yesorno = 'no' for j in sum_array: #print(i, j) if i == j: yesorno = 'yes' break print(yesorno)
#!/usr/bin/env python # -*- coding:utf-8 -*- from __future__ import print_function,division import time import sys import io import re import math start = time.clock() i = 0 sys.stdin.readline() a=[int(s) for s in sys.stdin.readline().split()] sys.stdin.readline() ms=[int(s) for s in sys.stdin.readline().split()] ans=set([0]) for i in a: ans|=set(j+i for j in ans) ans=list(ans) for jk in ms: if jk in ans: print('yes') else: print('no')
1
95,114,568,278
null
25
25
h,w = map(int,input().split()) t = w//2+(w%2!=0) ans = (t+w//2)*(h//2)+t*(h%2!=0) if h == 1 or w == 1: print(1) exit() print(ans)
import sys, os.path import math from collections import Counter if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") MAX = 1000001 factor = [0]*(MAX + 1) def generatePrimeFactors(): factor[1] = 1 for i in range(2,MAX): factor[i] = i for i in range(4,MAX,2): factor[i] = 2 i = 3 while(i * i < MAX): if (factor[i] == i): j = i * i while(j < MAX): if (factor[j] == j): factor[j] = i j += i i+=1 def calculateNoOFactors(n): if (n == 1): return 1 ans = 1 dup = factor[n] c = 1 j = int(n / factor[n]) while (j > 1): if (factor[j] == dup): c += 1 else: dup = factor[j] ans = ans * (c + 1) c = 1 j = int(j / factor[j]) ans = ans * (c + 1) return ans generatePrimeFactors() n = int(input()) temp = n c = 1 count = 0 while(temp-c > 0): w = temp-c count += calculateNoOFactors(w) c += 1 print(count)
0
null
26,866,680,593,060
196
73
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools, bisect import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def S(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def LR(n): return [L() for _ in range(n)] def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" sys.setrecursionlimit(1000000) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 INF = float("inf") class Eratosthenes: # https://cp-algorithms.com/algebra/prime-sieve-linear.html def __init__(self, n): primes = [] lp = [0] * (n + 1) for i in range(2, n + 1): if lp[i] == 0: primes.append(i) lp[i] = i for pj in primes: if pj > lp[i] or i * pj > n: break lp[i * pj] = pj self.primes = primes self.lp = lp def is_prime(self, x): return self.lp[x] == x def factrization(self, x): ret = [] while x > 1: ret.append(self.lp[x]) x //= self.lp[x] return ret def main(): N, K = LI() era = Eratosthenes(K) count = [0] * (K + 1) for i in range(1, K + 1): count[i] = pow((K // i), N, MOD) for i in range(1, K + 1)[::-1]: divs = era.factrization(i) candedates = [l for l in set(reduce(lambda x, y:x * y, ll, 1) for r in range(1, len(divs) + 1) for ll in itertools.combinations(divs, r))] for v in candedates: count[i // v] -= count[i] ans = 0 for i in range(1, K + 1): ans = (ans + i * count[i]) % MOD print(ans % MOD) if __name__ == '__main__': main()
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) def my_pow(base, n, mod): if n == 0: return 1 x = base y = 1 while n > 1: if n % 2 == 0: x *= x n //= 2 else: y *= x n -= 1 x %= mod y %= mod return x * y % mod N, K = map(int, input().split()) cnt = [0] * (K + 1) ans = 0 total = 0 for i in range(K, 0, -1): t = K // i now = my_pow(t, N, MOD) for j in range(i*2, K + 1, i): now -= cnt[j] cnt[i] = now ans += (now * i) % MOD print(ans % MOD)
1
36,906,473,347,932
null
176
176
''' def main(): N, D = map(int, input().split(" ")) xy = [] for i in range(N): xy.append(list(map(int, input().split(" ")))) D2 = D **2 cnt = 0 for i in range(N): if xy[i][0] **2 + xy[i][1] **2 > D2: continue cnt += 1 print(cnt) ''' #if,contiueの使い方による実行時間の比較用 def main(): N, D = map(int, input().split(" ")) xy = [] for i in range(N): xy.append(list(map(int, input().split(" ")))) D2 = D **2 cnt = 0 for i in range(N): if xy[i][0] **2 + xy[i][1] **2 <= D2: cnt += 1 print(cnt) if __name__ == "__main__": main()
def Base(X, n): if (int(X/n)): return Base(int(X/n), n)+str(X%n) return str(X%n) def main(): N, K = map(int, input().split()) ans1 = Base(N, K) ans = len(ans1) print(ans) main()
0
null
35,263,419,833,580
96
212
n, k, s = map(int, input().split()) for i in range(n): if k == 0: if s-1 > 0: print(s-1, end=' ') else: print(s+1, end=' ') else: print(s, end=' ') k -= 1 print()
N, K, S = map(int, input().split()) if S < 10**9: T = S + 1 else: T = S - 1 ans = [S]*K + [T]*(N-K) print(*ans)
1
91,251,431,064,690
null
238
238
n=[int(i) for i in input().split()] if sum(n)%9==0: print("Yes") else: print("No")
M = 10**9 + 7 n = int(input()) a = [int(i) for i in input().split()] #; print(a) counter = [0] * (n+1) ; counter[0] = 3 ans = 1 for i in range(n): ans *= counter[a[i] - 1 +1] - counter[a[i] +1] ans = ans % M counter[a[i] +1] += 1 print(ans)
0
null
67,241,517,065,060
87
268
n = int(input()) print(sum([i for i in range(1, n + 1) if i % 3 and i % 5]))
N = int(input()) l = [] for i in range(N+1): if i % 5 == 0 or i % 3 == 0: l.append(0) else: l.append(i) print(sum(l))
1
34,762,079,642,808
null
173
173
N = int(input()) R = [int(input()) for _ in range(N)] maxv = -2000000000 minv = R[0] for i in range(1,N): maxv = max([maxv, R[i] - minv ]) minv = min([minv, R[i]]) print(maxv)
n = int(input()) DP = [None] * (n + 1) # 計算結果を保存する配列 DP[0] = 1 # 定義より DP[1] = 1 # 定義より def fib(n): # フィボナッチ数を2からnまで順に求めていく for i in range(2, n + 1): DP[i] = DP[i-1] + DP[i-2] return DP[n] print(fib(n))
0
null
7,872,307,962
13
7
def solve(h, w, m, hw_list): h_count = [0] * (h + 1) w_count = [0] * (w + 1) for h_, w_ in hw_list: h_count[h_] += 1 w_count[w_] += 1 h_max = max(h_count) w_max = max(w_count) res = h_max + w_max h_max_count = 0 w_max_count = 0 for i in range(h + 1): if h_count[i] == h_max: h_max_count += 1 for j in range(w + 1): if w_count[j] == w_max: w_max_count += 1 max_count = h_max_count * w_max_count max_count_cross = 0 for h_, w_ in hw_list: if h_count[h_] == h_max and w_count[w_] == w_max: max_count_cross += 1 if max_count_cross == max_count: return res - 1 else: return res def main(): h, w, m = map(int, input().split()) hw_list = [] for _ in range(m): hw_list.append(list(map(int, input().split()))) res = solve(h, w, m, hw_list) print(res) def test(): assert solve(2, 3, 3, [[2, 2], [1, 1], [1, 3]]) == 3 assert solve(3, 3, 4, [[3, 3], [3, 1], [1, 1], [1, 2]]) == 3 assert solve(5, 5, 10, [[2, 5], [4, 3], [2, 3], [5, 5], [2, 2], [5, 4], [5, 3], [5, 1], [3, 5], [1, 4]]) == 6 if __name__ == "__main__": test() main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from math import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect import heapq # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 INF = float('inf') from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) H,W,M = readInts() dic1 = Counter() dic2 = Counter() s = set() for i in range(M): h,w = map(lambda x:int(x)-1, input().split()) dic1[h] += 1 dic2[w] += 1 s.add((h,w)) # print(dic) ans = 0 # 重なっているもので最大値がある時もあれば # 行、列の交差点でボムなしが一番大きいものがある for h,w in s: ans = max(ans, dic1[h] + dic2[w] - 1) dic1 = dic1.most_common() dic2 = dic2.most_common() max1 = dic1[0][1] max2 = dic2[0][1] for k1,v1 in dic1: if v1 < max1: break # continueする必要がない most_commonで大きい方から集めてるので for k2,v2 in dic2: if v2 < max2: break # 同じく if (k1,k2) in s: # 一度計算したもの continue # 両方とも最大であればok ans = max(ans, v1 + v2) break print(ans)
1
4,692,036,503,600
null
89
89
n = int(input()) p1 = p2 = 0 for _ in range(n): taro,hanako = map(str,input().split(" ")) if taro>hanako: p1 += 3 elif taro<hanako: p2 += 3 else: p1 += 1 p2 += 1 print(p1,p2)
# -*-coding:utf-8 def main(): inputLine = int(input()) taro = hanako = 0 for i in range(inputLine): tokens = list(input().split()) if(tokens[0] > tokens[1]): taro += 3 elif(tokens[0] < tokens[1]): hanako += 3 else: taro += 1 hanako += 1 print('%d %d' % (taro, hanako)) if __name__ == '__main__': main()
1
2,026,538,105,760
null
67
67
x=list(map(int,input().split())) print(sum([1,2,3,4,5])-sum(x))
n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n for i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if i&1else d[i-1],l[i]+d[i-2]) print(d[-1])
0
null
25,479,808,760,320
126
177
N, K = map(int,input().split()) MOD = 10**9 + 7 ans = 0 for k in range(K,N+2): m = (k*(k-1))//2 M = (k*(N+N-k+1))//2 ans += M-m+1 print(ans%MOD)
n, k = map(int, input().split(" ")) MOD = (10**9) + 7 def dSum(s, e): s -= 1 _s = s * (s + 1) // 2 _e = e * (e + 1) // 2 return _e - _s ans = 0 for i in range(k, n + 1): # _sum = dSum(n - i - 1, n) - dSum(0, i - 1) + 1 ans += dSum(i, n) - dSum(0, n - i) + 1 print((ans + 1) % MOD)
1
33,065,375,551,550
null
170
170
x, n = map(int,input().split()) L = list(map(int,input().split())) if n == 0 or x not in L: print(x) exit() for i in range(102): if (x-i) not in L: print(x-i) break elif (x+i) not in L: print(x+i) break
from bisect import bisect x,n=map(int,input().split()) p=list(map(int,input().split())) for i in range(100): if not(x-i in p): print(x-i) break if not(x+i in p): print(x+i) break
1
14,012,512,011,910
null
128
128
H,W,K=map(int,input().split()) S=[[int(s) for s in input()] for i in range(H)] ans=1000000 for i in range(2**(H-1)): tmp=0 L=[] for j in range(H-1): if i>>j&1: L.append(j) tmp+=len(L) L.append(H-1) c=[0]*len(L) for k in range(W): h=0 c1=[0]*len(L) for l in range(len(L)): for m in range(h,L[l]+1): c1[l]+=S[m][k] h=L[l]+1 p=0 for l in range(len(L)): if c1[l]>K: p=2 break elif c[l]+c1[l]>K: p=1 else: c[l]+=c1[l] if p==2: break elif p==1: c=[i for i in c1] tmp+=1 else: ans=min(ans,tmp) print(ans)
n = int(input()) a = list(map(int, input().split())) p = sorted([(x, i) for i, x in enumerate(a)], reverse=True) dp = [[0 for _ in range(n+1)] for _ in range(n+1)] for s in range(1, n+1): for x in range(s+1): y = s-x if x > 0: dp[x][y] = max(dp[x][y], dp[x-1][y] + abs(p[s-1][1] - x + 1) * p[s-1][0]) if y > 0: dp[x][y] = max(dp[x][y], dp[x][y-1] + abs(n-y - p[s-1][1]) * p[s-1][0]) print(max(dp[x][n-x] for x in range(n+1)))
0
null
41,166,479,023,460
193
171
a,b = map(int,input().split()) word = "" for i in range(max(a,b)): word += str(min(a,b)) print(word)
n = int(input()) ans = 0 for i in range(1, n+1): g = n // i ans += i * (g*(g+1))//2 print(ans)
0
null
47,973,696,027,058
232
118
n, m = map(int, input().split()) ac = [0] * n wa = [0] * n for _ in range(m): p, s = input().split() if s == 'AC': ac[int(p) - 1] = 1 elif ac[int(p) - 1] == 0: wa[int(p) - 1] += 1 for i in range(n): if ac[i] == 0: wa[i] = 0 print(sum(ac), sum(wa))
n, m = map(int, input().split()) listAC = [0] * n listWAAC = [0] * n listWA = [0] * n for i in range(m): p, s = map(str, input().split()) p = int(p) - 1 if listAC[p] == 1: continue if s == 'AC': listAC[p] += 1 listWAAC[p] += listWA[p] continue listWA[p] += 1 print(sum(listAC), sum(listWAAC))
1
93,783,379,819,052
null
240
240
n = int(input()) title = [] length = [] for i in range(n): a, b = input().split() title.append(a) length.append(int(b)) i = title.index(input()) print(sum((length[i+1:])))
import sys input=lambda: sys.stdin.readline().strip() n=int(input()) A=[] # PM=[[0,0] for i in range(n)] for i in range(n): now=0 mini=0 for j in input(): if j=="(": now+=1 else: now-=1 ; mini=min(mini,now) PM[i]=[mini,now] if sum( [PM[i][1] for i in range(n)] )!=0 : print("No") exit() MINI=0 NOW=0 PMf=[PM[i] for i in range(n) if PM[i][1]>=0] PMf.sort() for i in range(len(PMf)): MINI=min(MINI , NOW+PMf[-i-1][0] ) NOW+=PMf[-i-1][1] if MINI<0 : print("No") ; exit() PMs=[PM[i] for i in range(n) if PM[i][1]<0] PMs=sorted(PMs , key=lambda x : x[1]-x[0]) for i in range(len(PMs)): MINI=min(MINI , NOW+PMs[-i-1][0] ) NOW+=PMs[-i-1][1] if MINI<0 : print("No") ; exit() print("Yes")
0
null
60,569,652,052,922
243
152
n,r=map(int,input().split()) if n<10: ans=r+(100*(10-n)) else: ans=r print(ans)
n,*l=map(int,open(0).read().split()) a=t=0 for i in l: if i>t: t=i a+=t-i print(a)
0
null
34,101,559,908,470
211
88
A, B, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = min(a) + min(b) for _ in range(m): x, y, c = map(int, input().split()) x -= 1 y -= 1 ans = min(ans, a[x] + b[y] - c) 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()) ans += [A[x-1] + B[y-1] - c] ans += [min(A) + min(B)] print(min(ans))
1
53,773,575,670,092
null
200
200
c = 0 while True: a = input().split(' ') x = int(a[0]) y = int(a[1]) if (x or y) == 0: break; elif x < y: print(x,y) elif x > y: print(y,x) elif x == y: print(x,y) c += 1
from sys import stdin def main(): readline = stdin.readline n = int(readline()) s = tuple(readline().strip() for _ in range(n)) plus, minus = [], [] for c in s: if 2 * c.count('(') - len(c) > 0: plus.append(c) else: minus.append(c) plus.sort(key = lambda x: x.count(')')) minus.sort(key = lambda x: x.count('('), reverse = True) plus.extend(minus) sum = 0 for v in plus: for vv in v: sum = sum + (1 if vv == '(' else -1) if sum < 0 : return print('No') if sum != 0: return print('No') return print('Yes') if __name__ == '__main__': main()
0
null
12,055,433,724,572
43
152
n, k = map(int, input().split()) have = [False]*n for _ in range(k): d = int(input()) A = list(map(int, input().split())) for a in A: have[a-1] = True ans = 0 for i in range(n): if have[i]==False: ans += 1 print(ans)
n=int(input()) arr=list(map(int,input().split())) if n%2==0: ans=-10**18 dp=[[0]*2 for _ in range(n+10)] for i in range(n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) ans=max(ans,dp[n-1][0],dp[n][1]) dp=[[0]*2 for _ in range(n+10)] for i in range(1,n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) ans=max(ans,dp[n][0]) print(ans) else: ans=-10**18 dp=[[0]*3 for _ in range(n+10)] for i in range(n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i]) ans=max(ans,dp[n-2][0],dp[n-1][1],dp[n][2]) dp=[[0]*3 for _ in range(n+10)] for i in range(1,n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i]) ans=max(ans,dp[n-1][0],dp[n][1]) dp=[[0]*3 for _ in range(n+10)] for i in range(2,n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i]) ans=max(ans,dp[n][0]) print(ans)
0
null
31,038,024,438,180
154
177
import itertools n,m,q = list(map(int, input().split())) abcd = [[0] * 4 for _ in range(q)] for i in range(q): abcd[i] = list(map(int, input().split())) M = itertools.combinations_with_replacement(range(m),n) ans = 0 for A in M: for i in range(1,n): if A[i] <= A[i-1]:break temp = 0 for i in range(q): a = A[abcd[i][0]-1] b = A[abcd[i][1]-1] c = abcd[i][2] d = abcd[i][3] if b - a == c: temp += d ans = max(ans,temp) print(ans)
N,K = map(int,input().split()) l = [] mod = 998244353 for i in range(K): L,R = map(int,input().split()) l.append([L,R]) l.sort() a = [0 for i in range(N+1)] a[1] = 1 b = [0 for i in range(N+1)] b[1] = 1 for i in range(2,N+1): for j in range(K): if l[j][0] < i: a[i] += (b[i-l[j][0]]-b[max(0,i-l[j][1]-1)])%mod else: break b[i] = (b[i-1]+a[i])%mod mod = 998244353 print(a[N]%mod)
0
null
15,059,183,783,338
160
74
# Circle Pond R = int(input()) print(R*2 * 3.14159265)
a = int(input()) print(2*a*3.14)
1
31,530,231,921,980
null
167
167
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict from fractions import gcd import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): a,b,m = readInts() A = readInts() B = readInts() ans = float('inf') for i in range(m): x,y,c = readInts() x -=1 y -=1 ans = min(ans,A[x] + B[y] - c) # Aの商品の中で1番最小のやつを買うだけでもいいかもしれない # Bの商品の中で1番最小のやつを買うだけでもいいかもしれない ans = min(ans,min(A) + min(B)) print(ans) if __name__ == '__main__': main()
s=[] p=[] a=i=0 for c in input(): if"\\"==c:s+=[i] elif"/"==c and s: j=s.pop() t=i-j a+=t while p and p[-1][0]>j:t+=p[-1][1];p.pop() p+=[(j,t)] i+=1 print(a) if p:print(len(p),*list(zip(*p))[1]) else:print(0)
0
null
27,178,304,732,092
200
21
while True: a,b = map(int,raw_input().split()) if a == 0: if b==0: break elif b>0: print a,b else: print b,a elif a>=b: print b,a else: print a,b
num = input() list = input().split() ans = 0 for i in range(int(num) - 1): n1 = int(list[i]) n2 = int(list[i+1]) if n1 > n2 : ans += (n1 - n2) list[i+1] = list[i] else: ans += 0 print(ans)
0
null
2,569,005,243,870
43
88
n,x,t=map(int, input().split()) tako = n//x amari = n%x ans = tako*t if amari != 0: ans += t print(ans)
NXT = [int(i) for i in input().split(' ')] import math T_total = ( math.ceil( NXT[0]/ NXT[1] )*NXT[2] ) print (T_total)
1
4,309,375,998,280
null
86
86
#!/usr/bin/env python3 import sys input = sys.stdin.readline def main(): N = [0] + list(map(int, tuple(input().rstrip("\n")))) Ncopy = N.copy() ans = 0 flag = False for i in range(len(N)-1, 0, -1): if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i-1] <= 4): ans += Ncopy[i] flag = False else: Ncopy[i-1] += 1 if not flag: ans += 10 - N[i] else: ans += 9 - N[i] Ncopy[i] = 0 flag = True if Ncopy[0] == 1: ans += 1 print(ans) if __name__ == "__main__": main()
s=input()[::-1]+'0' d=[0,1] for c in s: x=int(c) d=[x+min(d[0],1+d[1]),min(1+d[0],d[1])+9-x] print(min(d))
1
71,219,341,988,730
null
219
219
X, Y = map(int, input().split()) Z = X * 4 - Y if Z % 2 == 0 and X * 2 >= Z >= 0: print('Yes') else: print('No')
X, Y = 3, 8 X, Y = map(int, input().split()) if Y % 2 == 0 and X * 2 <= Y <= X * 4: print('Yes') else: print('No')
1
13,724,515,482,652
null
127
127
n = int(input()) l = list(map(int,input().split())) l.reverse() print(' '.join(map(str,l)))
import sys N = int(input()) p = 0 for i in range(N): A,B = list(map(int, input().split())) if A == B: p += 1 else: p = 0 if p == 3: print("Yes") sys.exit() print("No")
0
null
1,750,203,499,210
53
72
from sys import stdin T1,T2 = [int(x) for x in stdin.readline().rstrip().split()] A1,A2 = [int(x) for x in stdin.readline().rstrip().split()] B1,B2 = [int(x) for x in stdin.readline().rstrip().split()] f = (A1-B1)*T1 s = (A2-B2)*T2 if f + s == 0: print("infinity") else: if (f > 0) and ((f + s) > 0): print(0) elif (f < 0) and ((f + s) < 0): print(0) elif f > 0 and f + s < 0: if f % (-(f + s)) == 0: print((f//-(f+s))*2) else: print((f//-(f+s))*2+1) elif f < 0 and f + s > 0: if (-f) % (f+s) == 0: print((-f//(f+s))*2) else: print((-f//(f+s))*2+1)
#!/usr/bin/env python3 import sys input = sys.stdin.readline import bisect n, m = map(int, input().split()) a = [int(item) for item in input().split()] a.sort() a_rev = sorted(a, reverse=True) cumsum = [0] for item in a: cumsum.append(cumsum[-1] + item) # Use pair which sum goes over mid l = 0; r = 10**10 while r - l > 1: mid = (l + r) // 2 to_use = 0 for i, item in enumerate(a_rev): useless = bisect.bisect_left(a, mid - item) to_use += n - useless if to_use >= m: l = mid else: r = mid ans = 0 total_use = 0 for i, item in enumerate(a_rev): useless = bisect.bisect_left(a, l - item) to_use = n - useless total_use += to_use ans += item * to_use + cumsum[n] - cumsum[n - to_use] print(ans - l * (total_use - m))
0
null
119,843,135,675,360
269
252
n = int(input()) lim_min, lim_max = map(int, input().split()) if lim_min % n == 0 : print('OK') elif lim_min + n - (lim_min % n) <= lim_max: print('OK') else: print('NG')
import sys from math import gcd input = lambda: sys.stdin.readline().rstrip() n = int(input()) A = list(map(int, input().split())) nowgcd = A[0] # 全体のGCDを取る for i in A: nowgcd = gcd(nowgcd, i) if nowgcd != 1: print('not coprime') exit() # osa_k法で前処理 MAXN = 10**6 + 5 sieve = [i for i in range(MAXN + 1)] p = 2 while p * p <= MAXN: # まだチェックされていないなら if sieve[p] == p: # 次のqの倍数からp刻みでチェック入れていく for q in range(2 * p, MAXN + 1, p): if sieve[q] == q: sieve[q] = p p += 1 check = set() for a in A: tmp = set() while (a > 1): tmp.add(sieve[a]) a //= sieve[a] for p in tmp: if p in check: print('setwise coprime') exit() check.add(p) print('pairwise coprime')
0
null
15,355,865,374,372
158
85
n = int(input()) for i in range(n): a, b, c = list(map(int, input().split())) if min(a*a+b*b, min(a*a+c*c, c*c+b*b)) == max(a*a, max(b*b, c*c)): print ("YES") else: print ("NO")
N,P = map(int, input().split()) S = input() if P == 2 or P == 5: ans = 0 for i in range(N): if int(S[i]) % P == 0: ans += i+1 print(ans) else: mod_cnt = [0]*P mod_cnt[0] = 1 k = 0.1 t = 0 for i in range(1, N+1): k = int(k * 10) % P t = (t + k * int(S[-i])) % P mod_cnt[t] += 1 ans = 0 for cnt in mod_cnt: ans += (cnt * (cnt-1)) // 2 print(ans)
0
null
29,056,287,573,280
4
205
a=input() print(a+"e"*(a[-1]=='s')+'s')
n = int(input()) A = list(map(int, input().split())) from collections import Counter C = Counter(A) X = [0]*(10**6+1) A = list(set(A)) A.sort() ans = 0 for a in A: if X[a] == 0 and C[a] == 1: ans += 1 X[a] += 1 j = 2*a while j <= 10**6: X[j] += 1 j += a print(ans)
0
null
8,347,353,899,156
71
129
n = int(input()) nums = list(map(int,input().split())) nums.sort() ans = 0 cnt = {} flag = [0]*1000005 for i in nums: cnt[i] = cnt.get(i,0) + 1 for i in nums: if flag[i] == 0 and cnt[i] == 1: ans += 1 if flag[i] == 1: continue for j in range(i,1000001,i): flag[j] = 1 print(ans)
n = int(input()) a = [int(i) for i in input().split()] max_a = max(a) cnt_d = [0] * (max_a + 1) for ai in a: for multi in range(ai, max_a + 1, ai): cnt_d[multi] += 1 print(sum(cnt_d[ai] == 1 for ai in a))
1
14,412,955,219,428
null
129
129
def main(): h, w, m = map(int, input().split()) mapa = {} strings = [0]*h rows = [0]*w for _ in range(m): h1, w1 = map(int, input().split()) if not mapa.get(h1-1, 0): mapa[h1-1] = [] mapa[h1-1].append(w1-1) strings[h1-1] += 1 rows[w1-1] += 1 max_s = max(strings) max_r = max(rows) strings_max = [] rows_max = [] for i in range(h): if strings[i] == max_s: strings_max.append(i) for i in range(w): if rows[i] == max_r: rows_max.append(i) forbidden_positions = set(mapa[strings_max[0]]) for item in strings_max[1:]: forbidden_positions.intersection_update(set(mapa[item])) answer_set = set(rows_max).difference(forbidden_positions) if answer_set: print(max_s + max_r) else: print(max_s + max_r - 1) main()
N = int(input()) mod = 10**9+7 ans = pow(10, N, mod) - ((pow(9, N, mod) * 2) - pow(8, N, mod)) ans %= mod print(ans)
0
null
3,915,038,407,170
89
78
def f():return map(int,raw_input().split()) n,m = f() A = [f() for _ in [0]*n] B = [input() for _ in [0]*m] for i in range(n): print sum([A[i][j]*B[j] for j in range(m)])
#データ入力 rowNum, columnNum = map(int, input().split()) inMat = [[0] * columnNum for i in range(rowNum)] inColumnVec = [[0] for i in range(columnNum)] for row in range(rowNum): inMat[row] = [int(i) for i in input().split()] for column in range(columnNum): inColumnVec[column] = int(input()) timesAns = [[0] for i in range(rowNum)] #行列計算 for row in range(rowNum): timesAns[row] = 0 for column in range(columnNum): timesAns[row] = timesAns[row] + inMat[row][column] * inColumnVec[column] for row in range(rowNum): print(timesAns[row])
1
1,159,979,083,120
null
56
56
print '1' if int(raw_input().split(' ')[1]) > int(raw_input().split(' ')[1]) else '0'
M1,D1 = map(int, input().split()) M2,D2 = map(int, input().split()) if M1==12 and M2==1 or M1+1==M2: print(1) else: print(0)
1
124,594,248,237,060
null
264
264
import sys ERROR_INPUT = 'input is invalid' def main(): n = get_length() arr = get_array(length=n) sourtLi, count = selectionSort(li=arr, length=n) print(*sourtLi) print(count) return 0 def get_length(): n = int(input()) if n < 0 or n > 100: print(ERROR_INPUT) sys.exit(1) else: return n def get_array(length): nums = input().split(' ') return [str2int(string=n) for n in nums] def str2int(string): n = int(string) if n < 0 or n > 100: print(ERROR_INPUT) sys.exit(1) else: return n def selectionSort(li, length): count = 0 for i in range(0, length - 1): min_index = i for j in range(i, length): if li[j] < li[min_index]: min_index = j if i != min_index: li[i], li[min_index] = li[min_index], li[i] count += 1 return li, count main()
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): N = int(input()) ans = int(N / 2 + 0.6) print(ans) if __name__ == '__main__': solve()
0
null
29,372,808,438,870
15
206
import sys from math import gcd from functools import reduce def enum_div(n): ir=int(n**(0.5))+1 ret=[] for i in range(1,ir): if n%i == 0: ret.append(i) if (i!= 1) & (i*i != n): ret.append(n//i) return ret n=int(input()) ap=list(map(int,input().split())) amin=min(ap) amax=max(ap) if amax==1: print("pairwise coprime") sys.exit() if reduce(gcd,ap)!=1: print("not coprime") sys.exit() if n>=78500 : print("setwise coprime") sys.exit() aa=[0]*(amax+1) for ai in ap: aa[ai]+=1 for pp in range(2,amax+1): psum=sum(aa[pp: :pp]) # print("pp:",pp,psum) if psum>=2: print("setwise coprime") sys.exit() ## max_13.txt ... max_16.txt : "setwise coprime" print("pairwise coprime")
s=input() q=int(input()) quary=[] for i in range(q): temp=list(input().split()) quary.append(temp) switch=False first='' last='' for i in range(q): if quary[i][0]=='1': if switch: switch=False else: switch=True else: if quary[i][1]=='1': if switch: last+=quary[i][2] else: first+=quary[i][2] else: if switch: first+=quary[i][2] else: last+=quary[i][2] s=first[::-1]+s+last if switch: print(s[::-1]) else: print(s)
0
null
30,517,402,644,928
85
204
N = int(input()) a = N % 10 if a == 0 or a == 1 or a == 6 or a == 8: print("pon") elif a == 3: print("bon") else: print("hon")
prime = 10 ** 9 + 7 n = int(input()) ans = 10 ** n - (9 ** n) * 2 + 8 ** n ans %= prime print(ans)
0
null
11,115,068,794,080
142
78
a,b,k=map(int,input().split()) t=min(a,k) s=min(b,k-t) print(a-t,b-s)
n = input() a = map(int, raw_input().split()) c = 0 for i in range(n): mini = i for j in range(i, n): if a[j] < a[mini]: mini = j if a[i] != a[mini]: a[i], a[mini] = a[mini], a[i] c += 1 print(" ".join(map(str, a))) print(c)
0
null
52,034,748,362,130
249
15
N, X, M = map(int, input().split()) tmp = X seq = [] ans = 0 for i in range(N): if X in seq: break seq.append(X) X = (X ** 2) % M ans = sum(seq[:min(N, len(seq))]) N -= len(seq) if N < 1: print(ans) exit() i = seq.index(X) l = len(seq) - i ans += sum(seq[i:]) * (N//l) N %= l ans += sum(seq[i:i+N]) print(ans)
import sys read = sys.stdin.read readlines = sys.stdin.readlines from collections import defaultdict def main(): n, x, m = map(int, input().split()) d1 = defaultdict(int) r = 0 while n: if d1[x]: cycle = d1[x] - n t0 = 0 cycle2 = cycle while cycle2: t0 += x x = x**2 % m cycle2 -= 1 c, rem = divmod(n, cycle) r += c * t0 while rem: r += x x = x**2 % m rem -= 1 print(r) sys.exit() else: d1[x] = n r += x x = x**2 % m n -= 1 print(r) if __name__ == '__main__': main()
1
2,801,588,400,482
null
75
75
n = int(input()) l =list(map(int,input().split())) l.reverse() for i in range(n): if i != n-1: print(f"{l[i]} ",end="") else: print(f"{l[i]}")
from math import sqrt as s N = int(input()) x, y = [], [] for i in range(1, int(s(N))+1): if N % i == 0: x.append(i) y.append(N // i) ans, M = float("INF"), len(x) for i in range(M): ans = min(ans, x[i] + y[i] - 2) print(ans)
0
null
80,952,163,091,398
53
288
M = [0 for i in xrange(10)] for i in xrange(10): M[i] = int(raw_input()) M.sort() M.reverse() for i in xrange(3): print M[i]
import sys import copy R, C, K = map(int, input().split()) item = [[0] * (C + 1) for _ in range(R + 1)] # dp配列と合わせるために, 0行目, 0列目を追加している. for s in sys.stdin.readlines(): r, c, v = map(int, s.split()) r -= 1 c -= 1 item[r][c] = v dp0 = [[0] * (C+1) for r in range(R+1)] dp1 = [[0] * (C+1) for r in range(R+1)] dp2 = [[0] * (C+1) for r in range(R+1)] dp3 = [[0] * (C+1) for r in range(R+1)] for r in range(R): for c in range(C): dp3[r][c] = max(dp3[r][c], dp2[r][c] + item[r][c]) dp2[r][c] = max(dp2[r][c], dp1[r][c] + item[r][c]) dp1[r][c] = max(dp1[r][c], dp0[r][c] + item[r][c]) dp1[r][c+1] = max(dp1[r][c], dp1[r][c+1]) dp2[r][c+1] = max(dp2[r][c], dp2[r][c+1]) dp3[r][c+1] = max(dp3[r][c], dp3[r][c+1]) dp0[r+1][c] = max(dp0[r+1][c], dp1[r][c]) dp0[r+1][c] = max(dp0[r+1][c], dp2[r][c]) dp0[r+1][c] = max(dp0[r+1][c], dp3[r][c]) ans = max(dp0[R-1][C-1], dp1[R-1][C-1]) ans = max(ans, dp3[R-1][C-1]) ans = max(ans, dp2[R-1][C-1]) print(ans)
0
null
2,808,011,743,450
2
94
l=str(input()) if(l[-1]!="s"): l=l+"s" else: l=l+"es" print(l)
s=input() s += "es" if s[-1] == 's' else "s" print(s)
1
2,371,621,962,158
null
71
71
N = int(input()) S, T = input().split() S_list = list(S) T_list = list(T) ans = "" for i, j in zip(S_list, T_list): ans += i + j print(ans)
N = int(input()) S,T = input().split() for s,t in zip(S,T): print(s+t,end="")
1
112,438,650,397,068
null
255
255
#!/usr/bin/env python3 val1 = input() if int(val1) >= 30: print("Yes") else: print("No")
# coding: utf-8 # Your code here! print("Yes"if int(input())>=30 else "No")
1
5,728,510,805,266
null
95
95
def main(): A = map(int, input().split()) print('bust' if sum(A) >= 22 else 'win') if __name__ == '__main__': main()
T1,T2 = map(int,input().split()) A1,A2 = map(int,input().split()) B1,B2 = map(int,input().split()) dis1 = (A1 - B1) * T1 dis2 = (A2 - B2) * T2 if dis1 > 0: dis1 = -dis1 dis2 = -dis2 """ if dis1 + dis2 <0: print(0) elif dis1 == -dis2: print("infinity") """ if dis1 + dis2 == 0: print("infinity") elif dis1+dis2 < 0: print(0) else: S = dis1//(dis1+dis2) R = dis1%(dis1+dis2) if R == 0: ans = S*2 else: ans = S*2 + 1 print(abs(ans))
0
null
125,317,559,307,980
260
269
def isprime(n): if n < 2: return 0 elif n == 2: return 1 if n % 2 == 0: return 0 for i in range(3, n, 2): if i > n/i: return 1 if n % i == 0 : return 0 return 1 N = int(input()) n = [int(input()) for i in range(N)] a = [i for i in n if isprime(i)] print(len(a))
strN = input().rstrip() K = int(input()) maxD = len(strN) dp = [[[0]*(K+1) for j in range(2)] for i in range(maxD+1)] dp[0][0][0] = 1 for d, Nd in enumerate(strN): Nd = int(Nd) for isLtN in range(2): for numNot0 in range(K+1): for x in range(10): if not isLtN and x > Nd: continue isLtN2 = isLtN or x < Nd numNot02 = numNot0 + (x != 0) if numNot02 > K: continue dp[d+1][isLtN2][numNot02] += dp[d][isLtN][numNot0] ans = dp[-1][0][K] + dp[-1][1][K] print(ans)
0
null
37,998,896,506,230
12
224
a, b, k =map(int, input().split()) if k <= a: a = a-k b = b elif a+b <= k: a = 0 b = 0 else: b = a+b-k a = 0 print(a, b)
a,b,k = map(int, input().split(" ")) if a < k: k -= a a = 0 if b < k: b = 0 else: b -= k else: a -= k print(a,b)
1
104,526,771,560,120
null
249
249
import sys s = input() if len(s)%2 == 1: print('No') sys.exit() for i in range(len(s)//2): if s[2*i:2*i+2] != 'hi': print('No') sys.exit() print('Yes')
s=input() ans="No" if len(s)%2==0: if s=="hi"*(len(s)//2): ans="Yes" print(ans)
1
53,079,435,854,224
null
199
199
# -*- coding: utf-8 -*- """ C - Snack https://atcoder.jp/contests/abc148/tasks/abc148_c """ import sys from fractions import gcd def solve(A, B): return A * B // gcd(A, B) def main(args): A, B = map(int, input().split()) ans = solve(A, B) print(ans) if __name__ == '__main__': main(sys.argv[1:])
import math import numpy as np A,B = np.array(input().split(),dtype = int) def gcd(x,y): if y == 0: return x else: return gcd(y,x%y) print(int(A*B/(gcd(A,B))))
1
113,224,702,155,380
null
256
256
n = int(input()) A = list(map(int, input().split())) from collections import defaultdict dic = defaultdict(int) ans = 0 for i in range(n): if i - A[i] in dic: ans += dic[i-A[i]] dic[i+A[i]] += 1 print(ans)
import sys input=sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode('utf-8') from collections import defaultdict def main(): n=II() A=LI() X=defaultdict(int) Y=defaultdict(int) for i,v in enumerate(A): X[i+v]+=1 Y[i-v]+=1 ans=0 for k,v in X.items(): ans+=v*Y[k] print(ans) if __name__=="__main__": main()
1
25,940,845,006,762
null
157
157
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input().strip() ans = [] now = n while now != 0: tmp = False for i in range(m, 0, -1): if now-i >= 0 and s[now-i] == '0': tmp = True now -= i ans.append(i) break if not tmp: print(-1) sys.exit() print(*ans[::-1])
def main(): s = input() print(s[:3]) if __name__ == '__main__': main()
0
null
77,269,543,209,150
274
130
def cub(): x = input() print x ** 3 cub()
import sys x = sys.stdin.readline() x3 = int(x) * int(x) * int(x) print x3
1
276,939,834,810
null
35
35