code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
import sys s = input() k = int(input()) n = len(s) all_same = True for i in range(n-1): if s[i] != s[i+1]: all_same = False if all_same: print((n*k)//2) sys.exit() head_same = 1 for i in range(n-1): if s[i] == s[i+1]: head_same += 1 else: break tail_same = 1 for i in range(n-1,0,-1): if s[i] == s[i-1]: tail_same += 1 else: break head_tail_same = 0 if s[0] == s[-1]: head_tail_same = head_same + tail_same def return_internal_same(ls): i = 0 same_count = 1 return_value = 0 while i < len(ls)-1: if ls[i] != ls[i+1]: i += 1 return_value += same_count // 2 same_count = 1 continue else: same_count += 1 i += 1 return_value += same_count // 2 return return_value # head_tial_sameがあるかどうかで場合わけ if head_tail_same > 0: ans = head_same//2 + tail_same//2 ans += (k-1) * (head_tail_same//2) ans += k*(return_internal_same(s[head_same:n-tail_same])) else: ans = k*(head_same//2 + tail_same//2) ans += (k-1) * (head_tail_same//2) ans += k*(return_internal_same(s[head_same:n-tail_same])) print(ans)
s = input() k = int(input()) if len(set(s)) == 1: print((len(s)*k)//2) else: t = [1] for i in range(1, len(s)): if s[i-1] == s[i]: t[-1] += 1 else: t.append(1) a = 0 for i in t: a += (i//2)*k if s[0] == s[-1]: if t[0] % 2 == t[-1] % 2 == 1: a += k-1 print(a)
1
174,796,745,649,668
null
296
296
from collections import Counter def prime_factorization(n): A = [] while n % 2 == 0: n //= 2 A.append(2) i = 3 while i * i <= n: if n % i == 0: n //= i A.append(i) else: i += 2 if n != 1: A.append(n) return A n = int(input()) A = list(Counter(prime_factorization(n)).values()) ans = 0 e = 1 while True: cnt = 0 for i in range(len(A)): if A[i] >= e: A[i] -= e cnt += 1 if cnt == 0: break ans += cnt e += 1 print(ans)
n=int(input()) def prime(n): dic={} f=2 m=n while f*f<=m: r=0 while n%f==0: n//=f r+=1 if r>0: dic[f]=r f+=1 if n!=1: dic[n]=1 return dic def counter(dic): ans=0 for val in dic.values(): i=1 while i*(i+3)/2<val: i+=1 ans+=i return ans print(counter(prime(n)))
1
16,867,530,178,590
null
136
136
n, k = map(int, input().split()) l = [0] * n for i in range(k): d = int(input()) a = list(map(int, input().split())) for j in range(d): l[a[j] - 1] += 1 count = 0 for i in range(n): if l[i] == 0: count += 1 print(count)
N,M = map(int, input().split()) flag = [False]*N ac = wa = 0 wal = [0]*N for i in range(M): p, s = input().split() if s == "AC": if flag[int(p)-1] == False: ac+=1 wa+=wal[int(p)-1] flag[int(p)-1] = True if s == "WA": if flag[int(p)-1] == False: wal[int(p)-1]+=1 print(ac,wa)
0
null
59,289,712,512,202
154
240
import math; in_put = input(""); cube=math.pow(float(in_put),3); print(int(cube));
(A, B, M), aa, bb, *xyc = [list(map(int, s.split())) for s in open(0)] ans = min(aa)+min(bb) for x, y, c in xyc: ans = min(ans, aa[x-1]+bb[y-1]-c) print(ans)
0
null
27,277,136,696,196
35
200
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) a,b=map(str,input().split()) print(int(a*int(b)) if int(a)<=int(b) else int(b*int(a)))
# -*- coding: utf-8 -*- import io import sys import math def solve(a,b): # implement process s = str(min(a,b)) n = max(a,b) return s * n def main(): # input a,b = map(int, input().split()) # process ans = str( solve(a,b) ) # output print(ans) return ans ### DEBUG I/O ### _DEB = 0 # 1:ON / 0:OFF _INPUT = """\ 7 7 """ _EXPECTED = """\ 7777777 """ def logd(str): """usage: if _DEB: logd(f"{str}") """ if _DEB: print(f"[deb] {str}") ### MAIN ### if __name__ == "__main__": if _DEB: sys.stdin = io.StringIO(_INPUT) print("!! Debug Mode !!") ans = main() if _DEB: print() if _EXPECTED.strip() == ans.strip(): print("!! Success !!") else: print(f"!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
1
84,553,880,571,020
null
232
232
def main(): X, Y = map(int, input().split()) ans = 0; if X == 1: ans += 300000 elif X == 2: ans += 200000 elif X == 3: ans += 100000 if Y == 1: ans += 300000 elif Y == 2: ans += 200000 elif Y == 3: ans += 100000 if X == 1 and Y == 1: ans += 400000 print(ans) if __name__ == '__main__': main()
x,y = map(int,input().split()) k = [0,3,2,1] + [0]*1000 ans = k[x]+k[y] if x == y == 1: ans += 4 print(ans*100000)
1
140,629,223,306,180
null
275
275
n = int(input()) list = [i for i in input().split()] list.reverse() print(" ".join(list))
n = input() nums = [a for a in input().split()] nums.reverse() print(' '.join(nums))
1
965,072,083,500
null
53
53
N = int(input()) z = [] zz = [] for _ in range(N): x, y = map(int, input().split()) zz.append(x-y) z.append(x+y) z.sort() zz.sort() ans = z[-1]-z[0] ans = max(ans, zz[-1]-zz[0]) 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') def main(): n=II() XY=[LI() for _ in range(n)] A=[] B=[] for x,y in XY: A.append(x+y) B.append(x-y) A.sort() B.sort() a=A[-1]-A[0] b=B[-1]-B[0] print(max(a,b)) if __name__=="__main__": main()
1
3,398,494,844,258
null
80
80
def main(): import sys input=sys.stdin.readline s,w=map(int,input().split()) if s<=w: print("unsafe") else: print("safe") if __name__ == '__main__': main()
NUM = list(map(int,input().split())) if(NUM[0] > NUM[1]): print("safe") elif(NUM[0] <= NUM[1]): print("unsafe")
1
29,010,744,278,152
null
163
163
# # abc157 c # import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """3 3 1 7 3 2 1 7""" output = """702""" self.assertIO(input, output) def test_入力例_2(self): input = """3 2 2 1 2 3""" output = """-1""" self.assertIO(input, output) def test_入力例_3(self): input = """3 1 1 0""" output = """-1""" self.assertIO(input, output) def resolve(): N, M = map(int, input().split()) SC = [list(map(int, input().split())) for _ in range(M)] SC = set(map(tuple, SC)) SC = list(set(SC)) SC.sort() ans = -1 for i in range(10**N): si = str(i) if len(si) != N: continue for sc in SC: s, c = sc if si[s-1] != str(c): break else: ans = i break print(ans) if __name__ == "__main__": # unittest.main() resolve()
N,M = map(int,input().split()) a = [0]*N b = [None]*N for i in range(M): s,c = map(int,input().split()) if b[s-1] == c: continue else: a[s-1] +=1 b[s-1] =c count = 0 for i in range(N): if a[i]>=2: count=-1 elif b[0]==0 and N>1: count =-1 elif i==0: if b[i] is None: if N==1: b[i] =0 else: b[i]=1 elif i>0: if b[i] is None: b[i]=0 b.reverse() if count == 0: for i in range(N): count+=b[i]*10**i print(count)
1
60,947,334,855,260
null
208
208
n = int(input()) a = 10000 ans = (a - n) % 1000 print(ans)
t = input().split() a = int(t[0]) b = int(t[1]) if a < b : print("a < b") if a == b: print("a == b") if a > b : print("a > b")
0
null
4,453,854,439,360
108
38
import sys import string s = sys.stdin.read().lower() for c in string.ascii_lowercase: print(c, ":", s.count(c))
N = int(input()) print(int(N / 2)) if N % 2 != 0 else print(int(N / 2) - 1)
0
null
77,379,253,548,172
63
283
import sys input=sys.stdin.readline class list2D: def __init__(self, H, W, num): self.__H = H self.__W = W self.__dat = [num] * (H * W) def __getitem__(self, a): return self.__dat[a[0]*self.__W+a[1]] def __setitem__(self, a, b): self.__dat[a[0]*self.__W+a[1]] = b def debug(self): print(self.__dat) class list3D: def __init__(self, H, W, D, num): self.__H = H self.__W = W self.__D = D self.__X = W * D self.__dat = [num] * (H * W * D) def __getitem__(self, a): return self.__dat[a[0]*self.__X+a[1]*self.__D + a[2]] def __setitem__(self, a, b): self.__dat[a[0]*self.__X+a[1]*self.__D + a[2]] = b def debug(self): print(self.__dat) def main(): r,c,k=map(int,input().split()) v = list2D(r, c, 0) for _ in range(k): ri,ci,a=map(int,input().split()) v[ri-1, ci-1] = a dp = list3D(r, c, 4, 0) #print(dp) if v[0, 0]>0: dp[0, 0, 1]=v[0, 0] for i in range(r): for j in range(c): val = v[i, j] if i>0: x = max(dp[i-1, j, 0], dp[i-1, j, 1], dp[i-1, j, 2], dp[i-1, j, 3]) dp[i, j, 1]=max(dp[i, j, 1],x+val) dp[i, j, 0]=max(dp[i, j, 0],x) if j>0: X = dp[i, j-1, 0] Y = dp[i, j-1, 1] V = dp[i, j-1, 2] Z = dp[i, j-1, 3] dp[i, j, 0]=max(dp[i, j, 0],X) dp[i, j, 1]=max(dp[i, j, 1],X+val,Y) dp[i, j, 2]=max(dp[i, j, 2],Y+val,V) dp[i, j, 3]=max(dp[i, j, 3],V+val,Z) #print(dp) ans=0 for i in range(4): ans=max(dp[r-1, c-1, i],ans) return print(ans) if __name__=="__main__": main()
n,k=map(int,input().split()) p=list(map(int,input().split())) p_list=sorted(p, reverse=False) sum=0 for i in range(k): sum+=p_list[i] print(sum)
0
null
8,554,293,714,378
94
120
n, k = map(int, input().split()) arr = list(map(int, input().split())) expected = [] cumsum = [] for x in arr: sum = (x * (x + 1)) // 2 ex = sum / x expected.append(ex) sum = 0 maxi = 0 taken = 0 bad = 0 for x in expected: sum += x taken += 1 if taken == k: maxi = max(maxi, sum) elif taken > k: sum -= expected[bad] bad += 1 maxi = max(maxi, sum) print(maxi)
N,K=map(int,input().split()) P=list(map(int,input().split())) L=[] M=[0] c=0 m=0 x=0 for i in range(200100): c+=i L.append(c) for i in P: m+=L[i]/i M.append(m) if N!=K: for i in range(N-K+1): x=max(M[K+i]-M[i],x) else: x=M[K]-M[0] print(x)
1
74,901,632,446,852
null
223
223
import math n = int(input()) print(360*n//math.gcd(360,n)//n)
x = int(input()) now = 0 ans = 0 while True: ans += 1 now += x if now % 360 == 0: print(ans) exit()
1
13,090,028,017,418
null
125
125
import math john=[] while True: try: john.append(input()) except EOFError: break for i in john: k=list(map(int,i.split())) print(int(math.gcd(k[0],k[1])),int(k[0]*k[1]/math.gcd(k[0],k[1])))
# ABC145 D X,Y=map(int,input().split()) a,b=-1,-1 if not (2*X-Y)%3: b=(2*X-Y)//3 if not (2*Y-X)%3: a=(2*Y-X)//3 N=10**6 p=10**9+7 f,finv,inv=[0]*N,[0]*N,[0]*N def nCr_init(L,p): for i in range(L+1): if i<=1: f[i],finv[i],inv[i]=1,1,1 else: f[i]=(f[i-1]*i)%p inv[i]=(p-inv[p%i]*(p//i))%p finv[i]=(finv[i-1]*inv[i])%p def nCr(n,r,p): if 0<=r<=n and 0<=n: return (f[n]*finv[n-r]*finv[r])%p else: return 0 nCr_init(a+b+1,p) if a>=0 and b>=0: print(nCr(a+b,b,p)) else: print(0)
0
null
74,986,300,469,346
5
281
n,m = map(int,input().split()) l=1 if n%2==1: r=n for i in range(m): d=min(abs(l-r),n-abs(l-r)) print(l,r) l+=1 r-=1 else: if n%4==0: r=n-1 else: r=n rev=False for i in range(m): d=min(abs(l-r),n-abs(l-r)) if d == n//2: rev=True l+=1 print(l,r) else: print(l,r) l+=1 r-=1
n,m=map(int,input().split()) lange=[1]*(n+1) for i in range(1,n+1): a=i b=n-a if lange[a]:lange[b]=0 langes=[] for i in range(1,n): if lange[i]: if len(langes)%2:langes.append(i) else:langes.append(n-i) langes.sort(reverse=1) for i in range(m):print(i+1,i+1+langes[i])
1
28,707,044,174,590
null
162
162
import bisect import sys,io import math from collections import deque from heapq import heappush, heappop input = sys.stdin.buffer.readline def sRaw(): return input().rstrip("\r") def iRaw(): return int(input()) def ssRaw(): return input().split() def isRaw(): return list(map(int, ssRaw())) INF = 1 << 29 DIV = (10**9) + 7 #DIV = 998244353 def mod_inv_prime(a, mod=DIV): return pow(a, mod-2, mod) def mod_inv(a, b): r = a w = b u = 1 v = 0 while w != 0: t = r//w r -= t*w r, w = w, r u -= t*v u, v = v, u return (u % b+b) % b def CONV_TBL(max, mod=DIV): fac, finv, inv = [0]*max, [0]*max, [0]*max fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, max): fac[i] = fac[i-1]*i % mod inv[i] = mod - inv[mod % i] * (mod//i) % mod finv[i] = finv[i-1]*inv[i] % mod class CONV: def __init__(self): self.fac = fac self.finv = finv pass def ncr(self, n, k): if(n < k): return 0 if(n < 0 or k < 0): return 0 return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV return CONV() def cumsum(As): s = 0 for a in As: s += a yield s sys.setrecursionlimit(200005) def dijkstra(G,start=0): heap = [] cost = [INF]*len(G) heappush(heap,(0,start)) while len(heap)!=0: c,n = heappop(heap) if cost[n] !=INF: continue cost[n]=c for e in G[n]: ec,v = e if cost[v]!=INF: continue heappush(heap,(ec+c,v)) return cost def main(): R,C,K = isRaw() mas = [[0 for _ in range(C)]for _ in range(R)] for k in range(K): r,c,v = isRaw() mas[r-1][c-1]=v dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(3)] dp0 = dp[0] dp1 = dp[1] dp2 = dp[2] dp0[0][0]=mas[0][0] dp1[0][0]=mas[0][0] dp2[0][0]=mas[0][0] for r in range(R): for c in range(C): mrc = mas[r][c] dp0[r][c] = mrc dp1[r][c] = mrc dp2[r][c] = mrc if r>0: dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc) dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc) dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc) if c>0: dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc) dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc) dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc) print(max([dp[ni][-1][-1] for ni in range(3)])) main()
h=int(input()) res=1 ans=0 while h>1: h=int(h/2) ans+=res res*=2 print(ans+res)
0
null
42,759,302,111,500
94
228
S = input() q = int(input()) for i in range(q): cmd = input().split() a = int(cmd[1]) b = int(cmd[2]) if cmd[0] == "print": print(S[a:b+1]) elif cmd[0] == "replace": S = S[0:a] + cmd[3] + S[b+1:len(S)] elif cmd[0] == "reverse": r = S[a:b+1] S = S[0:a] + r[::-1] + S[b+1:len(S)]
def main(): a, b = map(int, input().split()) if a < 10 and b < 10: print(a*b) else: print(-1) main()
0
null
80,295,657,713,572
68
286
def main(): N = int(input()) A = [[i for i in input().split()] for j in range(N)] X = input() ans = 0 flag = False for a, b in A: if a == X: flag = True continue if flag: ans += int(b) print(ans) if __name__ == '__main__': main()
N = int(input()) ST = [] cnt = 0 for _ in range(N): s, t = input().split() ST.append([s, t]) cnt += int(t) X = input() for i in range(N): s, t = ST[i] cnt -= int(t) if s == X: break print(cnt)
1
96,524,759,879,438
null
243
243
nums = [int(e) for e in input().split()] if (nums[2]+nums[4])<=nums[0] and (nums[3]+nums[4])<=nums[1] and (nums[2]-nums[4])>=0 and (nums[3]-nums[4])>=0: print("Yes") else: print("No")
W,H,x,y,r=map(int, input().split(" ")) if x<r or y<r or x+r>W or y+r>H : print('No') else : print('Yes')
1
450,089,891,070
null
41
41
N, M = map(int, input().split()) print('Yes' if N <= M else 'No')
input_line = input() Line = input_line.split() Line = [int(s) for s in Line] if Line[0] == Line[1]: print("Yes") else: print("No")
1
82,875,870,653,632
null
231
231
def insertionSort(A,n,g,count): for i in range(g,N): v = A[i] j = i-g while j >= 0 and A[j] > v: A[j+g] = A[j] j -= g count += 1 A[j+g] = v return count def shellSort(A,n): count = 0 m = 0 G = [] while (3**(m+1)-1)//2 <= n: m += 1 G.append((3**m-1)//2) for i in range(m): count = insertionSort(A,n,G[-1-i],count) return m,G,count import sys input = sys.stdin.readline N = int(input()) A = [int(input()) for _ in range(N)] m,G,count = shellSort(A,N) print(m) print(*G[::-1]) print(count) print('\n'.join(map(str,A)))
from sys import stdin def main(): a = set() _ = int(stdin.readline()) for command,value in (line.split() for line in stdin.readlines()): if command == "insert": a.add(value) else: print("yes" if value in a else "no") main()
0
null
56,750,959,808
17
23
N = int(input()) P = list(map(int, input().split())) ans = [0]*N min_cal = [0]*N min_cal[0] = P[0] for i in range(N-1): min_cal[i+1] = min(min_cal[i],P[i+1]) for i in range(N): if min_cal[i] >= P[i]: ans[i] = 1 print(sum(ans))
n = int(input()) p = list(map(int,input().split())) maxp = 999999 cnt=0 for x in p: if maxp >= x: cnt += 1 maxp = x print(cnt)
1
85,489,522,200,088
null
233
233
def f(n): if n == 0: return 0 return f(n % bin(n).count("1")) + 1 def solve(): N = int(input()) X = input() p = X.count("1") rem_plus = 0 rem_minus = 0 for i in range(N): k = N - i - 1 if X[i] == "0": continue elif p > 1: rem_minus = (rem_minus + pow(2, k, p - 1)) % (p - 1) rem_plus = (rem_plus + pow(2, k, p + 1)) % (p + 1) for i in range(N): k = N - i - 1 if X[i] == "0": print(f((rem_plus + pow(2, k, p + 1)) % (p + 1)) + 1) elif p > 1: print(f((rem_minus - pow(2, k, p - 1)) % (p - 1)) + 1) else: print(0) if __name__ == "__main__": solve()
import sys def I(): return int(sys.stdin.readline().rstrip()) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし N = I() X = LI2() X.reverse() if N == 1 and len(X) == 1 and X[0] == 0: print(1) exit() def popcount(n): res = 0 m = n.bit_length() for i in range(m): res += (n >> i) & 1 return res # 1回の操作で 2*10**5 未満になることに注意 F = [0]*(2*10**5) # F[i] = f(i) for i in range(1,2*10**5): F[i] = 1 + F[i % popcount(i)] a = sum(X) b = a-1 c = a+1 if a == 1: C = [1] # 2冪をcで割った余り xc = 0 # Xをcで割った余り for i in range(N): if X[i] == 1: xc += C[-1] xc %= c C.append((2 * C[-1]) % c) ANS = [] for i in range(N): if X[i] == 1: ANS.append(0) else: ANS.append(1 + F[(xc + C[i]) % c]) ANS.reverse() print(*ANS, sep='\n') exit() B,C = [1],[1] # 2冪をb,cで割った余り xb,xc = 0,0 # Xをb,cで割った余り for i in range(N): if X[i] == 1: xb += B[-1] xc += C[-1] xb %= b xc %= c B.append((2*B[-1])%b) C.append((2*C[-1])%c) ANS = [] for i in range(N): if X[i] == 1: ANS.append(1 + F[(xb-B[i]) % b]) else: ANS.append(1 + F[(xc+C[i]) % c]) ANS.reverse() print(*ANS,sep='\n')
1
8,180,563,370,590
null
107
107
N, X, M = map(int, input().split()) if X <= 1: print(X*N) exit() check = [0]*(M+1) check[X] += 1 A = X last_count = 0 while True: A = (A**2)%M if check[A] != 0: last_count = sum(check) target_value = A break check[A] += 1 A2 = X first_count = 0 while A2 != target_value: first_count += 1 A2 = (A2**2)%M roop_count = last_count-first_count A3 = target_value mass = A3 for i in range(roop_count-1): A3 = (A3**2)%M mass += A3 if roop_count == 0: print(N*X) exit() if first_count != 0: ans = X A = X for i in range(min(N,first_count)-1): A = (A**2)%M ans += A else: ans = 0 if N > first_count: ans += ((N-first_count)//roop_count)*mass A4 = target_value if (N-first_count)%roop_count >= 1: ans += A4 for i in range(((N-first_count)%roop_count)-1): A4 = (A4**2)%M ans += A4 print(ans)
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N, X, M = MI() rep = [] rep_set = set([]) i = 1 rep.append(X) rep_set.add(X) flag = True while flag and i < N: x = rep[i-1] ** 2 % M if x in rep_set: rep.append(x) break rep.append(x) rep_set.add(x) i += 1 if i == N: print(sum(rep)) else: l = rep.index(rep[-1]) rep_leng = i - l rep_sum = sum(rep[l:i]) ans = 0 ans += sum(rep[:l]) N -= l rep_num = N // rep_leng rep_amari = N % rep_leng ans += rep_sum * rep_num ans += sum(rep[l:l+rep_amari]) print(ans) main()
1
2,843,896,776,370
null
75
75
def main(): N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) total_T_in_A = [0] * (N+1) total_T_in_A[1] = A[0] total_T_in_B = [0] * M total_T_in_B[0] = B[0] for i in range(1, N+1): total_T_in_A[i] = total_T_in_A[i-1] + A[i-1] for i in range(1, M): total_T_in_B[i] = total_T_in_B[i-1] + B[i] result = 0 for i in range(N+1): # A から i 冊読むときにかかる時間 i_A_T = total_T_in_A[i] if K < i_A_T: continue if K == i_A_T: result = max(result, i) continue rem_T = K - i_A_T # total_T_in_B は累積和を格納した、ソート済の配列 # B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す first = total_T_in_B[0] last = total_T_in_B[M-1] if rem_T < first: result = max(result, i) continue if last <= rem_T: result = max(result, i + M) continue # assume that first <= rem_T <= last first_i = 0 last_i = M - 1 while first_i < last_i: if abs(last_i - first_i) == 1: break mid_i = (first_i + last_i) // 2 if rem_T < total_T_in_B[mid_i]: last_i = mid_i else: first_i = mid_i result = max(result, i + first_i + 1) print(result) main()
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N ** 0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def modinv(a): b = MOD u = 1 v = 0 while b: t = a // b a -= t * b a, b = b, a u -= t * v u, v = v, u u %= MOD if u < 0: u += MOD return u def factorial(N): if N == 0 or N == 1: return 1 res = N for i in range(N - 1, 1, -1): res *= i res %= MOD return res def solve(): X, Y = Scanner.map_int() if (X + Y) % 3 != 0: print(0) return B = (2 * Y - X) // 3 A = (2 * X - Y) // 3 if A < 0 or B < 0: print(0) return n = factorial(A + B) m = factorial(A) l = factorial(B) ans = n * modinv(m * l % MOD) % MOD print(ans) def main(): # sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
0
null
80,036,388,125,470
117
281
a, b = map(int, input().split()) print("{} {} {:.12f}".format(a // b, a % b, a * 1.0 / b))
import sys [a, b] = [int(x) for x in sys.stdin.readline().split()] d = a / b r = a - a / b * b f = round(1.0 * a / b, 7) print d, r, f
1
608,465,642,818
null
45
45
#In[]: x = int(input()) money = 100 year = 0 while True: money += money//100 year += 1 if money >= x: print(year) break
import sys read = sys.stdin.readline import time import math import itertools as it def inp(): return int(input()) def inpl(): return list(map(int, input().split())) start_time = time.perf_counter() # ------------------------------ X = inp() yen = 100 for i in range(10**4): yen += (yen // 100) if yen >= X: print(i+1) break # ----------------------------- end_time = time.perf_counter() print('time:', end_time-start_time, file=sys.stderr)
1
27,090,440,290,450
null
159
159
n = int(input()) A = list(map(int, input().split())) print(' '.join(list(map(str, A)))) for i in range(1,n): key = A[i] j = i - 1 while j >= 0 and A[j] > key: A[j+1] = A[j] j -= 1 A[j+1] = key print(' '.join(list(map(str, A))))
from sys import stdin def main(): #入力 readline=stdin.readline A,B=map(int,readline().split()) C=max(0,A-B*2) print(C) if __name__=="__main__": main()
0
null
83,485,032,018,752
10
291
l = int(input()) print(l * l * l / 27)
''' def main(): S = input() cnt = 0 ans = 0 f = 1 for i in range(3): if S[i] == 'R': cnt += 1 else: cnt = 0 ans = max(ans, cnt) print(ans) ''' def main(): S = input() p = S[0] == 'R' q = S[1] == 'R' r = S[2] == 'R' if p and q and r : print(3) elif (p and q) or (q and r): print(2) elif p or q or r: print(1) else: print(0) if __name__ == "__main__": main()
0
null
25,800,876,066,680
191
90
#!usr/bin/env python3 from collections import defaultdict, deque, Counter from heapq import heappush, heappop from itertools import permutations import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): a, b, c = LI() k = I() for i in range(k): if a >= b: b *= 2 elif b >= c: c *= 2 if a < b < c: print('Yes') else: print('No') return # Solve if __name__ == "__main__": solve()
a=list(map(int,input().split())) k=int(input()) while a[0]>=a[1]: k-=1 a[1]*=2 while a[1]>=a[2]: k-=1 a[2]*=2 if k>=0: print("Yes") else: print("No")
1
6,904,477,335,220
null
101
101
l=int(input()) print(str(l*l*l/27)+"\n")
l = int(input()) ans = l * l * l / 27 print(ans)
1
47,297,132,566,474
null
191
191
n ,q = map(int, input().split()) ntlist = [] for i in range(n): nt = list(map(str, input().split())) ntlist.append(nt) tp = 0 while (len(ntlist)): nt = ntlist.pop(0) if (int(nt[1])> q): nt[1] = int(nt[1]) - q tp += q ntlist.append(nt) else: tp += int(nt[1]) nt[1] = 0 print(nt[0], tp)
def main(): # データ入力 n, q = input().split() n = int( n ) q = int( q ) name = [] time = [] for i in range(n): tmp_n, tmp_t = input().split() name.append( tmp_n ) time.append( int( tmp_t ) ) # 処理 count = 0 while n > 0: if time[0] > q: time[0] -= q count += q time.append( time[0] ) time.pop( 0 ) name.append( name[0] ) name.pop( 0 ) else : count += time[0] print( name[0], end=" " ) print( str( count ) ) time.pop( 0 ) name.pop( 0 ) n -= 1 if __name__ == '__main__': main()
1
41,936,192,360
null
19
19
input() x = input() a = x.split() b = list(map(int,a)) print("{} {} {}".format(min(b),max(b),sum(b)))
def inp(): return input() def iinp(): return int(input()) def inps(): return input().split() def miinps(): return map(int,input().split()) def linps(): return list(input().split()) def lmiinps(): return list(map(int,input().split())) def lmiinpsf(n): return [list(map(int,input().split()))for _ in range(n)] n,x,t = miinps() ans = (n + (x - 1)) // x ans *= t print(ans)
0
null
2,523,585,722,240
48
86
global cnt cnt = 0 def merge(A, left, mid, right): L = A[left:mid] + [float("inf")] R = A[mid:right] + [float("inf")] i = 0 j = 0 global cnt for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 cnt += 1 def mergesort(A, left, right): rsl = [] if left+1 < right: mid = int((left+right)/2) mergesort(A, left, mid) mergesort(A, mid, right) rsl = merge(A, left, mid, right) return rsl n = int(input()) S = list(map(int, input().split())) mergesort(S, 0, n) print(*S) print(cnt)
N = int(input()) x = [[0] * (N-1) for _ in range(N)] y = [[0] * (N-1) for _ in range(N)] A = [0] * N for i in range(N): A[i] = int(input()) for j in range(A[i]): x[i][j], y[i][j] = list(map(int, input().split())) n = 2 ** N Flag = 0 ans = 0 while(n < 2 ** (N+1)): Flag = 0 for i in range(N): if(int(bin(n)[i + 3]) == 1): for j in range(A[i]): if(y[i][j] != int(bin(n)[x[i][j] + 2])): Flag = 1 break if(Flag == 1): break else: ans = max(ans, sum(list(map(int,bin(n)[3:])))) n += 1 print(ans)
0
null
61,151,339,981,760
26
262
# -*- coding: utf-8 -*- input_list = input().split() stack = list() for i in input_list: if i.isdigit(): stack.append(int(i)) else: b = stack.pop() a = stack.pop() if i == '+': stack.append(a + b) elif i == '-': stack.append(a - b) elif i == '*': stack.append(a * b) print(stack.pop())
N = [x for x in input().split(' ')] #データを格納するための整数型1次元配列 stack = [] for i in N: # +が入っていた場合 if i == '+': num1 = stack.pop() num2 = stack.pop() stack.append(num1 + num2) # -が入っていた場合 elif i == '-': num2 = stack.pop() num1 = stack.pop() stack.append(num1 - num2) # *が入っていた場合 elif i == '*': num1 = stack.pop() num2 = stack.pop() stack.append(num1 * num2) #算術演算子( + - *)以外が入っていた場合 else: stack.append(int(i)) #表示 print(stack.pop())
1
35,434,919,182
null
18
18
def main(): while True: m, f, r = tuple(map(int, input().split())) if m == f == r == -1: break elif m == -1 or f == -1: print('F') elif m + f >= 80: print('A') elif m + f >= 65: print('B') elif m + f >= 50: print('C') elif m + f >= 30: if r >= 50: print('C') else: print('D') else: print('F') if __name__ == '__main__': main()
def solve(a, op, b): if op == '+': return a + b elif op == '-': return a - b elif op == '*': return a * b elif op == '/': return a // b return None if __name__ == '__main__': while True: a, op, b = input().split() if op == '?': break print(solve(int(a), op, int(b)))
0
null
962,394,935,532
57
47
N = int(input()) A = [] for i in range(N+1): if i % 15 == 0: pass elif i % 3 == 0: pass elif i % 5 == 0: pass else: A.append(i) print(sum(A))
from decimal import Decimal T = tuple(map(Decimal, input().split())) A = list(map(Decimal, input().split())) B = list(map(Decimal, input().split())) ans = 0 if A[0] < B[0]: tmp = (A[0], A[1]) A[0], A[1] = B[0], B[1] B[0], B[1] = tmp[0], tmp[1] a = abs(T[0]*A[0] - T[0]*B[0]) b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1]) if b == 0: print("infinity") elif b < 0: print(0) exit(0) else: ans += 1 if b > a: print(1) elif b == a: print("infinity") else: if a % b == 0: print((a//b)*2) else: print((a//b)*2 + 1)
0
null
83,083,256,320,092
173
269
N, M = (int(x) for x in input().split()) if N==M: print("Yes") else: print("No")
# -*- coding: utf-8 -*- import io import sys import math def solve(): # implement process pass def main(): # input m, n = map(int, input().split()) # process ans = "Yes" if m == n else "No" # output print(ans) return ans ### DEBUG I/O ### _DEB = 0 # 1:ON / 0:OFF _INPUT = """\ 2 3 """ _EXPECTED = """\ Yes """ def logd(str): """usage: if _DEB: logd(f"{str}") """ if _DEB: print(f"[deb] {str}") ### MAIN ### if __name__ == "__main__": if _DEB: sys.stdin = io.StringIO(_INPUT) print("!! Debug Mode !!") ans = main() if _DEB: print() if _EXPECTED.strip() == ans.strip(): print("!! Success !!") else: print(f"!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
1
83,531,348,650,568
null
231
231
tmp = "abcdefghijklmnopqrstuvwxyz" alph = list(tmp) alphcount = [0]*26 while True: try: letter = input() letterarray = list(letter.lower()) # print(letterarray) except: break for x in letterarray: for i in range(26) : if (x == alph[i]): alphcount[i] += 1 else : continue for i in range(26): print(str(alph[i])+" : "+str(alphcount[i]))
import sys a = sys.stdin.read() alphabet = "abcdefghijklmnopqrstuvwxyz" for i in alphabet: print(i + " : " + str(a.lower().count(i)) )
1
1,676,590,196,610
null
63
63
import math def print_list_split_whitespace(a): for x in a[:-1]: print(x, end=' ') print(a[-1]) def insertion_sort(a, n, g, cnt): for i in range(g, n, 1): v = a[i] j = i - g while j >= 0 and a[j] > v: a[j + g] = a[j] j -= g cnt += 1 a[j+g] = v return cnt def shell_sort(a, n): cnt = 0 m = math.floor(math.log(2 * n + 1, 3)) print(m) gs = [1] for i in range(1, m, 1): gs.append(gs[i - 1] * 3 + 1) gs.reverse() print_list_split_whitespace(gs) for i in range(m): cnt = insertion_sort(a, n, gs[i], cnt) print(cnt) n = int(input()) a = [] for i in range(n): a.append(int(input())) shell_sort(a, n) for x in a: print(x)
a,b,c=map(int,input().split()) if (b*c >= a): print('Yes') else: print('No')
0
null
1,761,694,066,798
17
81
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines H,W = map(int,readline().split()) S = ''.join(read().decode().split()) INF = 10 ** 9 N = H*W U = 250 dp = [[INF] * U for _ in range(N)] # そのマスをいじる回数 → 総回数の最小値 dp[0] = list(range(U)) for n in range(H*W): for i in range(U-1,0,-1): if dp[n][i-1]> dp[n][i]: dp[n][i-1] = dp[n][i] for i in range(1,U): if dp[n][i-1] + 1 < dp[n][i]: dp[n][i] = dp[n][i-1] + 1 s = S[n] if s == '#': for i in range(0,U,2): dp[n][i] = INF else: for i in range(1,U,2): dp[n][i] = INF x,y = divmod(n,W) to = [] if y < W - 1: to.append(n+1) if x < H - 1: to.append(n+W) for m in to: for i in range(U): if dp[m][i] > dp[n][i]: dp[m][i] = dp[n][i] print(min(dp[-1]))
from collections import deque S = deque(input()) n = int(input()) Q = [list(map(str, input().split())) for _ in range(n)] flg = True for q in Q: if q[0] == "1": flg = not flg else: F = int(q[1]) if not flg: F = 3 - F if F == 1: S.appendleft(q[2]) if F == 2: S.append(q[2]) if not flg: S.reverse() print("".join(S))
0
null
53,200,635,685,606
194
204
def fibonacci(n): if n == 0 or n == 1: F[n] = 1 return F[n] if F[n] is not None: return F[n] F[n] = fibonacci(n - 1) + fibonacci(n - 2) return F[n] n = int(input()) F = [None]*(n + 1) print(fibonacci(n))
n = int(input()) p = [1,1] if n <= 1: print (1) exit (0) for i in range(2,n+1): p.append(p[i-2] + p[i-1]) print (p[n])
1
1,891,870,828
null
7
7
n, m = map(int, input().split()) for i in range(1, m+1): a, b = i, n-i+1 if not n % 2 and b-a <= n//2: print(a, b-1) else: print(a, b)
N,M = map(int,input().split()) ans = [] s = 1 e = M+1 while e>s: ans.append([s,e]) s += 1 e -= 1 s = M+2 e = 2*M+1 while e>s: ans.append([s,e]) s += 1 e -= 1 for s,e in ans: print(s,e)
1
28,574,325,107,140
null
162
162
import math n=input() m=10**2 for i in range(n): m=m*1.05 m=math.ceil(m) print int(m*(10**3))
num = 100000 n = int(input()) for i in range(n): num*=1.05 if num % 1000 >= 1 : a = num % 1000 num = int(num+1000-a) else: num = int(num) print(num)
1
1,252,712,072
null
6
6
N = int(input()) word = [str(input()) for i in range(N)] dic = {} for i in word: if i in dic: dic[i] += 1 else: dic[i] = 1 max_num = max(dic.values()) can_word = [] for i,j in dic.items(): if j == max_num: can_word.append(i) can_word.sort() for i in can_word: print(i)
N=int(input()) S=[input() for i in range(N)] L=dict() for i in range(N): if S[i] in L: L[S[i]]+=1 else: L[S[i]]=1 M=max(L.values()) ans=list() for X in L: if L[X]==M: ans.append(X) ans.sort() for X in ans: print(X)
1
69,954,025,962,650
null
218
218
N = int(input()) S = list(input()) check = 0 for i in range(N-1): if S[i] != "*": if S[i:i+3] == ["A","B","C"]: check += 1 S[i:i+3] = ["*"]*3 print(check)
input() w = input() print(w.count('ABC'))
1
99,120,809,276,952
null
245
245
import sys input = lambda: sys.stdin.readline().rstrip("\r\n") n, m = map(int, input().split()) if n % 2 == 0: n -= 1 ans = [] left_range = n//2 right_range = n//2 - 1 left1 = 1 right1 = 1 + left_range left2 = right1 + 1 right2 = left2 + right_range while True: if left1 >= right1: break ans.append([left1, right1]) left1 += 1 right1 -= 1 while True: if left2 >= right2: break ans.append([left2, right2]) left2 += 1 right2 -= 1 for i in range(m): print(*ans[i])
a,b,c,d = map(int,input().split()) cnt = d-a if cnt > 0: num = 1*a cnt -=b if cnt > 0: num = a + (d-a-b)*(-1) else: num = 1*d print(num)
0
null
25,359,833,915,162
162
148
n = int(input()) A = [input() for _ in range(n)] print("AC x " + str(A.count("AC"))) print("WA x " + str(A.count("WA"))) print("TLE x " + str(A.count("TLE"))) print("RE x " + str(A.count("RE")))
N = int(input()) S = list() for i in range(N): S.append(input()) judge = ['AC', 'WA', 'TLE', 'RE'] count = [0] * 4 for i in range(N): letter = S[i] ind = judge.index(letter) count[ind] += 1 for i in range(len(judge)): print(judge[i], "x", str(count[i]))
1
8,672,071,627,590
null
109
109
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(input()) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=' '): print(k.join(list(map(str, lst)))) INF = float('inf') # from math import ceil, floor, log2 # from collections import deque # from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush # import numpy as np # from numpy import cumsum # accumulate from fractions import gcd # from math import gcd def lcm(x, y): return x // gcd(x, y) * y def solve(): a, b = MI() print(lcm(a, b)) if __name__ == '__main__': solve()
N=int(input()) ans=0 for num in range(1,N+1): count=N//num ans+=count*(count+1)//2*num print(ans)
0
null
61,995,526,403,620
256
118
from sys import stdin n = int(stdin.readline()) for i in range(1,n+1): x = i if x % 3 == 0 or x % 10 == 3: print('', i, end='') continue x //= 10 while x != 0: if x % 10 == 3: print('', i, end='') break x //= 10 print()
s = input() a = ["x"]*len(s) print("".join(a))
0
null
36,737,305,025,820
52
221
n,m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] a.sort(reverse = True) s = sum(a) res = "Yes" for i in range(m): if a[i] * 4 * m < s: res = "No" print(res)
class Dice: def __init__(self, labels): self.up = labels[0] self.front = labels[1] self.right = labels[2] self.left = labels[3] self.back = labels[4] self.down = labels[5] def east(self): self.up, self.right, self.down, self.left = self.left, self.up, self.right, self.down def north(self): self.up, self.back, self.down, self.front = self.front, self.up, self.back, self.down def south(self): self.up, self.front, self.down, self.back = self.back, self.up, self.front, self.down def west(self): self.up, self.left, self.down, self.right = self.right, self.up, self.left, self.down def clockwise(self): self.front, self.left, self.back, self.right = self.right, self.front, self.left, self.back def counterclockwise(self): self.front, self.right, self.back, self.left = self.left, self.front, self.right, self.back def set_up(self, up): for i in range(6): if up == self.up: break if i % 2: self.east() else: self.north() def set_front(self, front): while True: if front == self.front: break self.clockwise() dice = Dice(list(map(int, input().split()))) for _ in range(int(input())): up, front = map(int, input().split()) dice.set_up(up) dice.set_front(front) print(dice.right)
0
null
19,628,636,202,980
179
34
n, m = [int(i) for i in input().split()] lst_pena = [[False, 0] for i in range(n)] cnt_pena = 0 cnt_ca = 0 for i in range(m): n, m = [j for j in input().split()] n = int(n) - 1 if lst_pena[n][0] == False and m == 'AC': lst_pena[n][0] = True cnt_ca += 1 elif lst_pena[n][0] == False and m == 'WA': lst_pena[n][1] += 1 sum_pena = sum([i[1] if i[0] else 0 for i in lst_pena]) print(f'{cnt_ca} {sum_pena}')
N = int(input()) n = str(N) le = len(n) M = 0 for i in range(le): nn = int(n[i]) M += nn if M % 9 == 0: print("Yes") else: print("No")
0
null
48,726,774,816,220
240
87
import sys rr = lambda: sys.stdin.readline().rstrip() ri = lambda: int(sys.stdin.readline()) s = rr() k = ri() cnt = 0 i = 0 if len(set(s)) == 1: print(int(len(s)*k/2)) exit() while i < len(s)-1: if s[i] == s[i+1]: cnt += 1 i += 1 i += 1 cnt1 = 0 i1 = 0 s *= 2 while i1 < len(s)-1: if s[i1] == s[i1+1]: cnt1 += 1 i1 += 1 i1 += 1 print((cnt1 - cnt)*(k-1) + cnt)
from collections import Counter S1 = input() K = int(input()) S1C = Counter(S1) if len(S1C) == 1: print(len(S1) * K // 2) exit() start = S1[0] end = S1[-1] now = S1[0] a1 = 0 flag = False for s in S1[1:]: if flag: flag = False now = s continue else: if s == now: a1 += 1 flag = True now = s S2 = S1 + S1 start = S2[0] end = S2[-1] now = S2[0] a2 = 0 flag = False for s in S2[1:]: if flag: flag = False now = s continue else: if s == now: a2 += 1 flag = True now = s b = a2 - 2 * a1 print(a1 * K + b * (K-1))
1
175,471,148,366,780
null
296
296
def main(): N = int(input()) digits = [] while N != 0: digits.append(N % 26) if digits[-1] == 0: digits[-1] = 26 N //= 26 N -= 1 else: N //= 26 digits.reverse() for d in digits: print(chr(96 + d), end='') print() # 改行 if __name__ == '__main__': main()
S = input() cnt = 0 for i in range(int(len(S)/2)): if S[i] == S[len(S)-1-i]: continue else: cnt += 1 #print(i, S[i], S[len(S)-1-i]) print(cnt)
0
null
65,709,557,516,382
121
261
N,K= list(map(int, input().split())) Ps = list(map(int, input().split())) ruisekiwa = [0] for P in Ps: ruisekiwa.append(P + ruisekiwa[-1]) #print(ruisekiwa) ans = 0 for i in range(N-K+1): ans = max(ans, (ruisekiwa[i+K] - ruisekiwa[i] + K) / 2) # print(ans) print(ans)
import sys sys.setrecursionlimit(10**6) n, u, v = map(int, input().split()) u -= 1 v -= 1 graph = [[] for _ in range(n)] for _ in range(n-1): a, b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) pre = [None]*n def dfs(node, p_node=-1): for c_node in graph[node]: if c_node==p_node: continue pre[c_node] = node dfs(c_node, node) dfs(u) path = [v] now = v while now!=u: now = pre[now] path.append(now) s1 = path[len(path)//2] p1 = path[len(path)//2-1] def dfs2(node, depth, p_node): mx = depth for c_node in graph[node]: if c_node==p_node: continue mx = max(mx, dfs2(c_node, depth+1, node)) return mx print(dfs2(s1, 0, p1)+len(path)//2-1)
0
null
96,059,264,914,620
223
259
print(' ' + ' '.join(str(i) for i in range(1, int(input()) + 1) if i % 3 == 0 or '3' in str(i)))
import sys input = sys.stdin.readline a,b=map(int,input().split()) if a>b: print(str(b)*a) else: print(str(a)*b)
0
null
42,745,123,321,042
52
232
def main(): N = input() len_N = len(N) K = int(input()) dp = [[[0] * 2 for _ in range(K + 5)] for _ in range(len_N + 5)] dp[0][0][0] = 1 for i in range(len_N): tmp = int(N[i]) for j in range(K+1): # l : 1 => N より小さいことが確定 for l in range(2): for x in range(10): if l == 0: if x > tmp: continue elif x == tmp: if x == 0: dp[i+1][j][0] += dp[i][j][0] else: dp[i+1][j+1][0] += dp[i][j][0] else: if x == 0: dp[i+1][j][1] += dp[i][j][0] else: dp[i+1][j+1][1] += dp[i][j][0] if l == 1: if x == 0: dp[i+1][j][1] += dp[i][j][1] else: dp[i+1][j+1][1] += dp[i][j][1] print(dp[len_N][K][0] + dp[len_N][K][1]) if __name__ == "__main__": main()
K = int(input()) S = input() def answer(K: int, S: str) -> str: if len(S) <= K: return S else: return S[:K]+ '...' print(answer(K, S))
0
null
47,892,942,861,292
224
143
n=int(input()) A=list(map(int,input().split())) q=int(input()) M=list(map(int,input().split())) pattern=[] for i in range(2**n): s=0 for j in range(n): if i >> j & 1: s+=A[j] pattern.append(s) P=set(pattern) for m in M: print('yes' if m in P else 'no')
A = int(input()) B = int(input()) abc = {1, 2, 3} ab = {A, B} print(list(abc-ab)[0])
0
null
55,218,168,303,210
25
254
H = int(input()) ans = 1 if H != 1: h = H for i in range(1, 40): if int(h/2) >= 2: # print(i, ans, h, 'a') ans += 2**i h = int(h/2) else: # print(i, ans, h, 'b') ans += 2**i break print(ans)
#区間スケジューリング問題 N = int(input()) robots = {} for _ in range(N): X, L = list(map(int, input().split())) robots[X] = (X-L, X+L) #終端が早い順にソートして、取れるものから貪欲法でとっていく robots_sorted = sorted(robots.items(), key=lambda x:x[1][1]) ans = 1 current_robot = robots_sorted[0] for i in range(0, N): if current_robot[1][1] > robots_sorted[i][1][0]: continue ans += 1 current_robot = robots_sorted[i] print(ans)
0
null
84,790,556,501,182
228
237
n = int(input()) #nを素因数分解したリストを返す def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n /= i table.append(i) i += 1 if n > 1: table.append(n) return table a = prime_decomposition(n) list_num=[] for i,n in enumerate(a): if i ==0: list_num.append(n) if n in list_num: continue elif n not in list_num: list_num.append(n) count = 0 for i in list_num: num = a.count(i) handan = True j = 1 counter = 0 while handan == True: num -=j if num<0: handan =False elif num>=0: counter+=1 j+=1 count +=counter print(count)
import sys from io import StringIO import unittest import os # 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む) sys.setrecursionlimit(999999999) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n ** 0.5 // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if not arr: arr.append([n, 1]) return arr # 実装を行う関数 def resolve(test_def_name=""): n = int(input()) target_s = factorization(n) # 素因数1だけ処理対象外。 if sum([i[1] for i in target_s]) == 1: if target_s[0][0] == 1: print(0) else: print(1) return # 少ない物から使っていく。 cnt = 0 for i in range(1, 1000): if not any([True if j[1] >= i else False for j in target_s]): break for target in target_s: if target[1] < i: continue target[1] -= i cnt += 1 print(cnt) # テストクラス class TestClass(unittest.TestCase): def assertIO(self, assert_input, output): stdout, sat_in = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(assert_input) resolve(sys._getframe().f_back.f_code.co_name) sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, sat_in self.assertEqual(out, output) def test_input_1(self): test_input = """24""" output = """3""" self.assertIO(test_input, output) def test_input_2(self): test_input = """1""" output = """0""" self.assertIO(test_input, output) def test_input_3(self): test_input = """64""" output = """3""" self.assertIO(test_input, output) def test_input_4(self): test_input = """1000000007""" output = """1""" self.assertIO(test_input, output) def test_input_5(self): test_input = """997764507000""" output = """7""" self.assertIO(test_input, output) def test_1original_1(self): test_input = """108""" output = """3""" self.assertIO(test_input, output) # 実装orテストの呼び出し if __name__ == "__main__": if os.environ.get("USERNAME") is None: # AtCoder提出時の場合 resolve() else: # 自PCの場合 unittest.main()
1
16,938,170,351,430
null
136
136
a,b=map(str,input().split()) c,d=map(int,input().split()) k=input() if k==a: c-=1 else: d-=1 print(c,d)
s, t = map(str, input().split()) a, b = map(int, input().split()) u = str(input()) sums = 0 if s == u: a -= 1 if t == u: b -= 1 print(a, b)
1
71,858,343,857,630
null
220
220
from itertools import combinations n=int(input()) D=list(map(int,input().split())) ans=0 for a,b in combinations(range(n),2): ans+=D[a]*D[b] print(ans)
N = int(input()) d = list(map(int,input().split())) amount = 0 b = [0] * N for i in range(N): b[i] = amount amount += d[N-1-i] ans = 0 for i in range(N): ans += d[i]*b[N-1-i] print(ans)
1
167,785,079,047,940
null
292
292
n = int(input()) m = range(1,n + 1) a = range(1,n + 1,2) b = len(a) / len(m) print(b)
import queue import numpy as np import math n = int(input()) A = list(map(int, input().split())) A = np.array(A,np.int64) ans = 0 for i in range(60 + 1): a = (A >> i) & 1 count1 = np.count_nonzero(a) count0 = len(A) - count1 ans += count1*count0 * pow(2, i) ans%=1000000007 print(ans)
0
null
149,639,123,104,150
297
263
# -*-coding:utf-8 import fileinput import math def main(): for line in fileinput.input(): a, b, c = map(int, line.strip().split()) if(a < b and b <c): print('Yes') else: print('No') if __name__ == '__main__': main()
import sys input = sys.stdin.readline MOD = pow(10, 9) + 7 n = int(input()) a = list(map(int, input().split())) m = max(a) num = [0] * 61 for x in a: for j in range(61): if (x >> j) & 1: num[j] += 1 s = 0 #print(num) for i in range(61): s += (n - num[i]) * num[i] * pow(2, i, MOD) % MOD print(s % MOD)
0
null
61,737,583,957,152
39
263
#!/usr/bin/env python3 from pprint import pprint from collections import deque, defaultdict import itertools import math import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.buffer.readline INF = float('inf') n_nodes = int(input()) graph = [[] for _ in range(n_nodes)] for _ in range(n_nodes): line = list(map(int, input().split())) u, k = line[0], line[1] if k > 0: for v in line[2:]: graph[u - 1].append(v - 1) # pprint(graph) def dfs(v): global time time += 1 for v_adj in graph[v]: if d[v_adj] == -1: d[v_adj] = time dfs(v_adj) f[v] = time time += 1 d = [-1] * n_nodes f = [-1] * n_nodes time = 1 for v in range(n_nodes): if d[v] == -1: d[v] = time dfs(v) # pprint(d) # pprint(f) for v in range(n_nodes): print(f"{v + 1} {d[v]} {f[v]}")
import bisect,collections,copy,heapq,itertools,math,string import sys def S(): return sys.stdin.readline().rstrip() def M(): return map(int,sys.stdin.readline().rstrip().split()) 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()) a, b, k = M() if k >= a: k -= a a = 0 else: a -= k k = 0 if k >= b: b = 0 else: b -= k print(a, b)
0
null
52,319,115,459,692
8
249
a,b,c,d=map(int,input().split()) for i in range(1001): if i%2==0: c-=b if c<=0: print("Yes") exit(0) else: a-=d if a<=0: print("No") exit(0)
import math A, B, C, D = map(int, input().split()) T_kougeki = C / B # 高橋くんが攻撃して、青木くんの体力が0になるまでの回数 A_kougeki = A / D # 青木くんが攻撃して、高橋くんの体力0になるまでの回数 if math.ceil(T_kougeki) <= math.ceil(A_kougeki): #切り上げた値で少ない方、同数なら先行の高橋くんの勝ち print('Yes') else: print('No')
1
29,623,720,095,200
null
164
164
dice_init = input().split() dicry = {'search':"152304",'hittop':'024135', 'hitfront':'310542'} num = int(input()) def dicing(x): global dice dice = [dice[int(c)] for c in dicry[x]] for _ in range(num): dice = dice_init top, front = map(int, input().split()) while True: if int(dice[0]) == top and int(dice[1]) == front: break elif int(dice[0]) == top: dicing('hittop') elif int(dice[1]) == front: dicing('hitfront') else: dicing('search') print(dice[2])
import random class Cube: def __init__(self, u, s, e, w, n, d): self.u = u self.s = s self.e = e self.w = w self.n = n self.d = d def rotate(self, dic): if dic == "N": tmp = self.u self.u = self.s self.s = self.d self.d = self.n self.n = tmp elif dic == "E": tmp = self.u self.u = self.w self.w = self.d self.d = self.e self.e = tmp elif dic == "W": tmp = self.u self.u = self.e self.e = self.d self.d = self.w self.w = tmp else: tmp = self.u self.u = self.n self.n = self.d self.d = self.s self.s = tmp def main(): u, s, e, w, n, d = map(int, input().split()) cube = Cube(u, s, e, w, n, d) q = int(input()) for i in range(q): upper, front = map(int, input().split()) while True: cube.rotate(random.choice("NWES")) if upper == cube.u and front == cube.s: print(cube.e) break if __name__ == '__main__': main()
1
259,936,144,420
null
34
34
N, S = map(int, input().split()) A = list(map(int, input().split())) MOD = 998244353 def main(): dp = [0]*(S+1) dp[0] = 1 for i in range(1, N+1): p = [0]*(S+1) dp, p = p, dp for j in range(0, S+1): dp[j] += 2*p[j] dp[j] %= MOD if j-A[i-1] >= 0: dp[j] += p[j-A[i-1]] dp[j] %= MOD print(dp[S]) if __name__ == "__main__": main()
N, S=list(map(int,input().split())) A=list(map(int,input().split())) A=[0]+A dp=[[0 for j in range(S+1)] for i in range(N+1)] dp[0][0]=1 for i in range(1,N+1): for j in range(S+1): dp[i][j]=(dp[i][j]+2*dp[i-1][j]) %998244353 # x[i]を入れないが、大きい方に入れるか入れないかが二通り for j in range(S-A[i]+1): dp[i][j+A[i]]=(dp[i][j+A[i]]+dp[i-1][j]) %998244353 # x[i]を入れる print(dp[N][S])
1
17,589,510,972,990
null
138
138
n, k = map(int, input().split()) A = set([]) for i in range(k): d = input() A = A | set(map(int, input().split())) ans = 0 for i in range(n): if i+1 not in A: ans += 1 print(ans)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 5 3 1 3 4 3 output: 3 """ import sys def solve(): # write your code here max_profit = -1 * float('inf') min_stock = prices[0] for price in prices[1:]: max_profit = max(max_profit, price - min_stock) min_stock = min(min_stock, price) return max_profit if __name__ == '__main__': _input = sys.stdin.readlines() p_num = int(_input[0]) prices = list(map(int, _input[1:])) print(solve())
0
null
12,364,839,122,770
154
13
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n = I() dic = collections.defaultdict(int) while n != 1: prime = 0 limit = int(n**(1/2)) for i in range(2,limit+1): if n%i == 0: prime = i break else: prime = n while n%prime == 0: n //= prime dic[prime] += 1 ans = 0 for key,value in dic.items(): cnt = 0 while value>=cnt+1: cnt += 1 value -= cnt ans += cnt # print(dic) print(ans) main()
n = int(input()) m = n p = 2 res = 0 st = [0 for i in range(100)] for i in range(100): if i * (i + 1) // 2 >= 100: break st[i * (i + 1) // 2] = i for i in range(1, 100): st[i] = st[i - 1] if st[i] == 0 else st[i] #print(st) while p * p <= n: l = 0 while m % p == 0: m //= p l += 1 res += st[l] #print(p, res, l) p += 1 res += m > 1 print(res)
1
16,856,031,882,342
null
136
136
while True: m,f,r=map(int,input().split()) if (m,f,r)==(-1,-1,-1): break h=m+f if m == -1 or f == -1: print('F') elif h >= 80: print('A') elif h>=65 and h<80: print('B') elif h>=50 and h<65: print('C') elif h>=30 and h<50 and r>=50: print('C') elif h>=30 and h<50 and r<50: print('D') else: print('F')
date=[[],[],[]] a,b,c=0,0,0 while True: if a < 0 and b < 0 and c < 0: break else: a,b,c =[int(i) for i in input().split()] date[0].append(a) date[1].append(b) date[2].append(c) for h in range(0,len(date[0])-1): if date[0][h] == -1 or date[1][h] == -1: print("F") elif date[0][h] == date[1][h] == date[2][h]: break else: if date[0][h] + date[1][h] >= 80: print("A") else: if date[0][h] + date[1][h] >= 65: print("B") else: if date[0][h] + date[1][h] >= 50: print("C") else: if date[0][h] + date[1][h] >=30: if date[2][h] >= 50: print("C") else: print("D") else: print("F")
1
1,204,803,410,048
null
57
57
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) cnt = 1 def dfs(x): global cnt if s[x] == None: s[x] = cnt cnt += 1 for v in edges[x]: if s[v] == None: dfs(v) g[x] = cnt cnt += 1 return n = I() edges = [[] for _ in range(n)] for i in range(n): edges[i] = list(map(lambda x:x-1,LI()[2:])) s = [None]*n g = [None]*n for i in range(n): if s[i] == None: dfs(i) for i in range(n): print(i+1,s[i],g[i])
n = input() min_val = float("inf") max_val = -float("inf") for i in range(n): tmp = input() max_val = max(max_val, tmp - min_val) min_val = min(min_val, tmp) print max_val
0
null
8,083,534,382
8
13
#16D8101014F 久留米 竜之介 Kurume Ryunosuke Python All = 0 q = [] Queue = [] tmp,time = map(int,input().split()) for i in range(tmp): p,zi =input().split() q.append([p,int(zi)]) while len(q) > 0: if q[0][1]<= time: All+=q[0][1] v=q.pop(0) Queue.append([v[0],All]) else: All+=time q[0][1]-=time last=q.pop(0) q.append(last) for i in range(len(Queue)): print("{0} {1}".format(Queue[i][0],Queue[i][1]))
N, M = map(int, input().split()) A = list(map(int, input().split())) for i in A: N -= i if N >= 0: print(N) else: print(-1)
0
null
15,946,324,166,530
19
168
n=int(input()) c=input() a=c.count('R') print(c[:a].count('W'))
N = int(input()) C = input() r_n = 0 ans = 0 for c in C: if c == 'R': r_n += 1 for i in range(r_n): if C[i] == 'W': ans += 1 print(ans)
1
6,331,043,015,452
null
98
98
import sys sys.setrecursionlimit(10000000) class Graph: def __init__(self,n,side): self.side = side self.neighbor = [set() for i in range(n+1)] self.visited = [False]*(n+1) self.group =[0]*n self.product() def product(self): for a,b in self.side: self.neighbor[a].add(b) self.neighbor[b].add(a) def dfs(self,x,a): self.group[a] += 1 self.visited[x] = True for i in self.neighbor[x]: if self.visited[i]:continue self.dfs(i,a) def all_dfs(self): a = 0 for i in range(1,n+1): if not self.visited[i]: self.dfs(i,a) a += 1 n,m = map(int,input().split()) side = list(tuple(map(int,input().split()))for i in range(m)) graph1 = Graph(n,side) graph1.all_dfs() print(max(graph1.group))
from collections import defaultdict, deque dic = defaultdict(list) N, M = map(int, input().split()) for i in range(M): a, b = map(int, input().split()) dic[a].append(b) dic[b].append(a) ans = 0 now = 1 seen = [-1]*N queue = deque() for i in range(N): if seen[i]!=-1: continue queue.append(i+1) seen[i]=now temp=0 while queue: temp+=1 q = queue.popleft() for j in dic[q]: if seen[j-1]!=-1: continue queue.append(j) seen[j-1]=now now+=1 ans = max(ans, temp) print(ans)
1
3,954,469,399,958
null
84
84
lakes = [] # [(左岸位置, 断面積)] lefts = [] # lefts[i]: まだ対になっていない上から i 番目の左岸位置 for i, c in enumerate(input()): if c == '\\': lefts.append(i) elif c == '/': if lefts: left = lefts.pop() area = i - left while lakes: sub_left, sub_area = lakes[-1] if left < sub_left: area += sub_area lakes.pop() else: break lakes.append((left, area)) L = [lake[1] for lake in lakes] print(sum(L)) print(len(L), *L)
class Flood: """ begin : int 水たまりの始まる場所 area : int 水たまりの面積 """ def __init__(self, begin, area): self.begin = begin self.area = area down_index_stack = [] # \の場所 flood_stack = [] # (水たまりの始まる場所, 面積) for i, c in enumerate(input()): if c == '\\': down_index_stack.append(i) if c == '/': if len(down_index_stack) >= 1: # 現在の/に対応する\が存在したら l = down_index_stack.pop() # 現在の水たまりの始まる場所 area = i - l # 現在の水たまりの現在の高さの部分の面積はi-l # 現在の水たまりが最後の水たまりを内包している間は # (現在の水たまりの始まる場所が最後の水たまりの始まる場所より前にある間は) while len(flood_stack) >= 1 and l < flood_stack[-1].begin: # 最後の水たまりを現在の水たまりに取り込む last_flood = flood_stack.pop() area += last_flood.area flood_stack.append(Flood(l, area)) # 現在の水たまりを最後の水たまりにして終了 area_list = [flood.area for flood in flood_stack] print(sum(area_list)) print(' '.join(list(map(str, [len(area_list)] + area_list))))
1
59,455,261,110
null
21
21
n = input() S = map(int,raw_input().split()) q = input() T = map(int,raw_input().split()) ans = 0 for t in T: if t in S: ans+=1 print ans
# coding: utf-8 cnt = int() m = int() g = [] def insersion_sort(a, n, g): global cnt for i in xrange(g, n): v = a[i] j = i - g while j >= 0 and a[j] > v: a[j+g] = a[j] j = j - g cnt += 1 a[j+g] = v return list(a) def shell_sort(a, n): global cnt global m global g cnt = 0 m = 0 g = [] nn = n while True: nn /= 2 if nn <= 0: break g.append(nn) m += 1 if n == 1: m = 1 g = [1] for i in g: a = insersion_sort(a, n, i) return a def main(): global cnt global m global g n = input() a = [] for i in xrange(n): a.append(input()) a = shell_sort(a, n) print m print " ".join(map(str, g)) print cnt for i in xrange(n): print a[i] main()
0
null
49,449,275,300
22
17
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def main(): N = int(input()) ans = 1e18 for i in range(1, N + 1): if i * i > N: break if N % i != 0: continue j = N // i ans = min(ans, i + j - 2) print(ans) if __name__ == '__main__': main()
N = int(input()) D_ls = list(map(int, input().split(' '))) result = 0 for i in range(N): for j in range(i+1, N): result += D_ls[i] * D_ls[j] print(result)
0
null
165,447,892,203,312
288
292
def INT(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) N = INT() cnt = 0 for _ in range(N): D1, D2 = MI() if D1 == D2: cnt += 1 else: cnt = 0 if cnt == 3: print("Yes") exit() print("No")
n = int(input()) s = input() ans = s.count('R')*s.count('G')*s.count('B') for i in range(n-2): for j in range(i, n-1): if s[i] != s[j]: if 2*j-i <= n-1 and s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]: ans -= 1 print(ans)
0
null
19,372,931,417,050
72
175
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) Ax = A1 * T1 + A2 * T2 Bx = B1 * T1 + B2 * T2 diff = abs(Ax - Bx) if diff == 0: print('infinity') exit() if not ((A1 * T1 > B1 * T1 and Ax < Bx) or (A1 * T1 < B1 * T1 and Ax > Bx)): print(0) exit() ans = 2 * ((abs(B1 - A1) * T1) // diff) if (abs(B1 - A1) * T1) % diff != 0: ans += 1 print(ans)
a, b = eval(input().replace(' ', ',')) print("a {} b".format("<" if a < b else ">" if a > b else "=="))
0
null
65,745,053,111,140
269
38
from decimal import Decimal a,b,c = list(map(Decimal,input().split())) d = Decimal('0.5') A = a ** d B = b ** d C = c ** d if A + B < C: print('Yes') else: print('No')
N = int(input()) A = list(map(int, input().split())) ans = 'DENIED' for a in A: if a%2 == 0: if a%3 == 0 or a%5 == 0: continue else: break else: ans = 'APPROVED' print(ans)
0
null
60,584,732,515,930
197
217
N, M = map(int, input().split()) assert 2*M+1 <= N if M % 2 == 1: step_m1 = M step_m2 = M - 1 else: step_m1 = M - 1 step_m2 = M assert step_m1 + 1 + step_m2 + 1 <= N ans = [] a = 0 for step in range(step_m1, -1, -2): # print(step) # print(a, a+step) ans.append([a+1, a+step+1]) a += 1 a = step_m1 + 1 for step in range(step_m2, 0, -2): # print(step) # print(a, a+step) ans.append([a+1, a+step+1]) a += 1 print('\n'.join(map(lambda L: ' '.join(map(str, L)), ans)))
N=int(input()) st=[] for i in range(N): s,t=input().split() st.append((s,int(t))) X=input() time=0 s=False for i in range(N): if s: time+=st[i][1] if st[i][0]==X: s=True print(time)
0
null
62,856,972,021,792
162
243
w,h,x,y,r=map(int, input().split()) x_max=int(x+r) x_min=int(x-r) y_max=int(y+r) y_min=int(y-r) #print(x_max,x_min,y_max,y_min) if y_max > h: print("No") else: if y_min < 0: print("No") else: if x_max > w: print("No") else: if x_min < 0: print("No") else: print("Yes")
W,H,x,y,r=map(int,input().split()) print('Yes'if(False if x<r or W-x<r else False if y<r or H-y<r else True)else'No')
1
457,902,313,880
null
41
41
X,N=map(int,input().split()) p=list(map(int,input().split())) i=0 j=0 while X+i in p: i+=1 while X-j in p: j+=1 if i>j: print(X-j) elif i<j: print(X+i) else: print(min([X+i,X-j]))
N=int(input()) A=list(map(int,input().split())) a,b,c=0,0,0 ans=1 mod=10**9+7 for i in A: ans=ans*[a,b,c].count(i)%mod if i==a: a+=1 elif i==b: b+=1 elif i==c: c+=1 print(ans)
0
null
72,370,591,299,588
128
268
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): N, M = LI() used = [0 for _ in range(N)] cur = 0 pairs = [] used = set() if N % 2 == 0: a = 1 b = N while len(pairs) < M: if b-a in used or N + a -b in used or b - a == N//2: b -= 1 pairs.append((a, b)) used.add(b-a) used.add(N+a - b) a += 1 b -= 1 else: a = 1 b = N - 1 while len(pairs) < M: pairs.append((a, b)) a += 1 b -= 1 for p in pairs: print(p[0], p[1]) main()
import functools N = int(input()) A = list(map(int,input().split())) #print(A) s = A[0] for num in A[1:]: s ^= num res = [0] * N for i,num in enumerate(A): res[i] = s^num print(*res)
0
null
20,532,444,990,820
162
123
N, u, v = map(int, input().split()) u, v = u-1, v-1 ABs = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)] #%% roots = [[] for _ in range(N)] for AB in ABs: roots[AB[0]].append(AB[1]) roots[AB[1]].append(AB[0]) #BFS def BFS(roots, start): from collections import deque seen = [-1 for _ in range(N)] seen[start] = 0 todo = deque([start]) while len(todo) > 0: checking = todo.pop() for root in roots[checking]: if seen[root] == -1: seen[root] = seen[checking] +1 todo.append(root) return seen from_u = BFS(roots, u) from_v = BFS(roots, v) from collections import deque todo = deque([u]) max_distance = from_v[u] position = u seen = [False for _ in range(N)] seen[u] = True while len(todo) > 0: checking = todo.pop() for root in roots[checking]: if from_u[root] < from_v[root] and seen[root] == False: seen[root] = True todo.append(root) if max_distance < from_v[root]: max_distance = from_v[root] position = root print(max_distance-1)
N=int(input()) L=list(map(int, input().split())) count=0 for i in range(N-2): for j in range(i+1,N-1): for k in range(j+1,N): if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]: if max(L[i],L[j],L[k])<L[i]+L[j]+L[k]-max(L[i],L[j],L[k]): count += 1 else: pass print(count)
0
null
61,550,055,549,110
259
91
import numpy as np N=int(input()) A=list(map(int,input().split())) SUM=sum(A) Q=int(input()) List=np.array([0 for _ in range(10**5+1)]) for a in A: List[a]+=1 for q in range(Q): B,C=map(int,input().split()) SUM-=B*List[B] SUM+=C*List[B] List[C]+=List[B] List[B]=0 print(SUM)
n = int(raw_input()) A = map(int, raw_input().split()) d = {} def soleve(i, m, n): if m == 0: return True if i >= n: return False if d.has_key((i, m)): return d[(i, m)] res = soleve(i + 1, m, n) or soleve(i + 1, m - A[i], n) d[(i, m)] = res return res q = int(raw_input()) M = map(int, raw_input().split()) for m in M: if soleve(0, m, n): print 'yes' else: print 'no'
0
null
6,198,483,992,480
122
25
N = int(input()) A = list(map(int, input().split())) bosses = [0 for _ in range(N+1)] for boss in A: bosses[boss] += 1 for i in range(1, N+1): print(bosses[i])
import sys readline = sys.stdin.readline N,X,M = map(int,readline().split()) MAXD = 55 # nex[t][v] = v (mod M)から2 ** tステップ進んだ先の値 # まずnex[0][v] は、v (mod M)から1ステップ進んだ先の値を入れておく # sums[t][v] = v (mod M)から2 ** tステップ進んだ総和 # まずsums[0][v]は、各項がvそのものになる(1ステップだから) nex = [[-1] * M for i in range(MAXD + 1)] sums = [[0] * M for i in range(MAXD + 1)] # まず、1ステップ進んだ先の値を入れる for r in range(M): nex[0][r] = r * r % M sums[0][r] = r for p in range(MAXD): for r in range(M): nex[p + 1][r] = nex[p][nex[p][r]] sums[p + 1][r] = sums[p][r] + sums[p][nex[p][r]] # 最初は、1ステップ(今いる場所)の場合の総和が入っている。次の進み先の総和と足すことで、 # 今いる場所と次の場所の総和となり、2つ進んだ場合の総和が求められる # これで2つ進んだ場合の総和を求めるリストになるため、 # ここで同じことをやることで、「2つ分の総和とその次の2つ分の総和」->「4つ分の総和」となる res = 0 cur = X for p in range(MAXD, -1, -1): if N & (1 << p): res += sums[p][cur] cur = nex[p][cur] print(res)
0
null
17,597,388,556,036
169
75
w=raw_input().lower() c=0 while 1: t=map(str,raw_input().split()) if t[0]=="END_OF_TEXT": break for i in range(len(t)): if t[i].lower()==w: c+=1 print c
W = input().lower() count = 0 while True: l = input() if l == 'END_OF_TEXT': break for i in l.lower().split(): if i == W: count += 1 print(count)
1
1,803,980,271,008
null
65
65
# coding: utf-8 def main(): n, m = map(int, input().split()) A_array = list(map(int, input().split())) tmp_A_array = [x for x in A_array if x >= sum(A_array)/(4*m)] # print(sum(A_array)/(4*m), tmp_A_array, m, sep="\n") if len(tmp_A_array) >= m: print("Yes") else: print("No") main()
n = int(input()) deck = input().split() bd = list(deck) for i in range(n): for j in reversed(range(i + 1, n)): if bd[j][1] < bd[j - 1][1]: bd[j], bd[j - 1] = bd[j - 1], bd[j] print(' '.join(bd)) print('Stable') sd = list(deck) for i in range(n): mi = i for j in range(i, n): if sd[j][1] < sd[mi][1]: mi = j sd[i], sd[mi] = sd[mi], sd[i] print(' '.join(sd)) if (bd == sd): print('Stable') else: print('Not stable')
0
null
19,253,986,660,302
179
16
N = int(input()) S = 'X' + input() cnt_R, cnt_G, cnt_B = 0, 0, 0 for s in S[1:]: if s == 'R': cnt_R += 1 elif s == 'G': cnt_G += 1 elif s == 'B': cnt_B += 1 ans = cnt_R * cnt_G * cnt_B for i in range(1,N-1): for j in range(i+1,N): k = 2*j - i if k > N: break a = S[i]; b = S[j]; c = S[k] if a != b and b != c and c != a: ans -= 1 print(ans)
import sys import os MOD = 10 ** 9 + 7 def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") K, X = list(map(int, sys.stdin.buffer.readline().split())) print('Yes' if K*500 >= X else 'No') if __name__ == '__main__': main()
0
null
67,113,741,787,618
175
244
n = int(input()) y = 1 while y <= n : if(y % 3 == 0): print(' %d'%y,end='') else: p = y while(p != 0): if(p % 10 == 3): print(' %d'%y,end='') break p //= 10 y+=1 print()
n = int(input()) for i in range(1, n + 1): if i % 3 == 0: print(' ' + str(i), end='') else: s = str(i) if '3' in s: print(' ' + str(i), end='') print('')
1
927,467,930,520
null
52
52
n = int(input()) a = list(map(int, input().split())) mod = 10**9 + 7 ans = 0 for i in range(60): cnt = 0 digit = 1 << i for j in a: if digit & j: cnt += 1 ans += digit*cnt*(n - cnt)%mod print(ans%mod)
MOD = 10 ** 9 + 7 n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(60): cnt = 0 for x in a: if (x >> i) & 1: cnt += 1 ans += cnt * (n - cnt) * (1 << i) print(ans % MOD)
1
122,810,949,823,520
null
263
263
dim = int(input()) a, b = list(map(int, input().split())), list(map(int, input().split())) dif = [ abs(x-y) for x, y in zip(a, b)] print("%lf\n%lf\n%lf\n%lf" % (sum(dif), sum([i ** 2 for i in dif]) ** (1 / 2), sum([i ** 3 for i in dif]) ** (1 / 3), max(dif) ))
from sys import stdin input = stdin.readline K = int(input()) print("ACL" * K)
0
null
1,216,859,934,272
32
69
n=int(input()) c0=0 c1=0 c2=0 c3=0 for i in range(n): Sn=input() if Sn=="AC": c0+=1 elif Sn=="WA": c1+=1 elif Sn=="TLE": c2+=1 elif Sn=="RE": c3+=1 print("AC x "+(str(c0))) print("WA x "+(str(c1))) print("TLE x "+(str(c2))) print("RE x "+(str(c3)))
N = int(input()) S = [input() for _ in range(N)] C0 = 0 C1 = 0 C2 = 0 C3 = 0 for i in range(N): if S[i] == "AC": C0 += 1 elif S[i] == "WA": C1 += 1 elif S[i] == "TLE": C2 += 1 else: C3 += 1 print("AC x "+ str(C0)) print("WA x "+ str(C1)) print("TLE x "+ str(C2)) print("RE x "+ str(C3))
1
8,769,562,596,940
null
109
109
#初期定義 global result global s_list result = 0 #アルゴリズム:ソート def merge(left, mid, right): global result n1 = mid - left n2 = right - mid inf = 10**9 L_list = s_list[left: mid] + [inf] R_list = s_list[mid: right] + [inf] i = 0 j = 0 for k in range(left, right): result += 1 if L_list[i] <= R_list[j]: s_list[k] = L_list[i] i += 1 else: s_list[k] = R_list[j] j += 1 #アルゴリズム:マージソート def mergeSort(left, right): if (left + 1) < right: mid = (left + right) // 2 mergeSort(left, mid) mergeSort(mid, right) merge(left, mid, right) #初期値 n = int(input()) s_list = list(map(int, input().split())) #処理の実行 mergeSort(0, n) #結果の表示 print(" ".join(map(str, s_list))) print(result)
cnt = 0 INF = pow(10, 18) def merge(A, left, mid, right): L = A[left:mid] + [INF] R = A[mid:right] + [INF] i = 0 j = 0 for k in range(left, right): global cnt cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) n = int(input()) s = list(map(int, input().split())) mergeSort(s, 0, n) print(*s) print(cnt)
1
111,055,359,590
null
26
26
import sys def gcd(a,b): while a % b != 0: a, b = b, a % b return b def lcm(a,b,g): _a = a // g _b = b // g return _a * _b * g def run(): data = [] for n in sys.stdin: a, b = list(map(int, n.split())) data.append((a,b)) for _data in data: a, b = _data g = gcd(a,b) l = lcm(a,b,g) print(g, l) if __name__ == '__main__': run()
import sys # 最大公約数(greatest common divisor)を求める関数 def gcd(a, b): while b: a, b = b, a % b return a # 最小公倍数(least common multiple)を求める関数 # //は切り捨て除算 def lcm(a, b): return a * b // gcd(a, b) lines = sys.stdin.readlines() for line in lines: a = list(map(int, line.split(" "))) print(gcd(a[0], a[1]), lcm(a[0], a[1]))
1
784,452,192
null
5
5
inputted = list(map(int, input().split())) K = inputted[0] X = inputted[1] total = 500 * K; answer = 'Yes' if total >= X else 'No'; print(answer);
import sys sys.setrecursionlimit(1000000) input = lambda: sys.stdin.readline().rstrip() K, X = map(int, input().split()) if K * 500 >= X: print("Yes") else: print("No")
1
98,373,953,548,118
null
244
244