code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
a=list(map(int,input().split())) b=list(map(int,input().split())) if a[0]!=b[0]: print('1') else: print('0')
input1 = list(map(int,input().split())) input2 = list(map(int,input().split())) m1 = input1[0] d1 = input1[1] m2 = input2[0] d2 = input2[1] if m1 == m2: print(0) else: print(1)
1
124,443,708,584,228
null
264
264
import sys for line in sys.stdin: a, b = map(int, line.split()) c = a * b while b: a, b = b, a % b print(str(a) + ' ' + str(c / a))
def gcd(m, n): while n: m, n = n, m % n return m def lcm(m, n): return m // gcd(m, n) * n for line in open(0).readlines(): a, b = map(int, line.split()) print(gcd(a, b), lcm(a, b))
1
543,366,460
null
5
5
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) n, k, c = nm() a = ns() ans = [] al = [] count = 0 dey = 1 for i in a: if i is "o" and count <= 0: al.append(dey) count = c + 1 dey += 1 count -= 1 ar = [] count = 0 dey = n for i in reversed(a): if i is "o" and count <= 0: ar.append(dey) count = c + 1 dey -= 1 count -= 1 al = al[:k] ar = ar[:k] for i in al: j = ar.pop(-1) if i == j: ans.append(i) for i in ans: print(i)
N, K, C = map(int, input().split()) S = input() S_reverse = S[::-1] left_justified = [-1 for _ in range(N)] right_justified = [-2 for _ in range(N)] for i_justified in (left_justified, right_justified): if i_justified == left_justified: i_S = S nearest_position = 1 positioning = 1 else: i_S = S_reverse nearest_position = K positioning = -1 i_K = 0 while i_K <= N-1: if i_S[i_K] == 'o': i_justified[i_K] = nearest_position i_K += C nearest_position += positioning i_K += 1 for i_N in range(N): if left_justified[i_N] == right_justified[N - i_N - 1]: print(i_N + 1)
1
40,686,209,732,334
null
182
182
A1,A2,A3=map(int,input().split()) total=A1+A2+A3 if total>=22: print('bust') else: print('win')
from sys import exit import math import collections ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) a,b,c = mi() if a + b + c >=22: print('bust') else: print('win')
1
119,158,954,197,258
null
260
260
n=int(input()) a=list(map(int,input().split())) q=int(input()) s=sum(a) data=[0]*10**5 for i in a: data[i-1]+=1 for i in range(q): b,c=map(int,input().split()) s+=(c-b)*data[b-1] print(s) data[c-1]+=data[b-1] data[b-1]=0
N = int(input()) A = list(map(int,input().split())) a = {} for i in A: if i in a: a[i] += 1 else: a[i] = 1 Q = int(input()) ans = sum(A) for i in range(Q): B,C = map(int,input().split()) if B in a: ans += (C-B) * a[B] if C in a: a[C] += a[B] else: a[C] = a[B] a[B] = 0 print(ans)
1
12,319,384,992,028
null
122
122
tmp = input().split(" ") S = int(tmp[0]) W = int(tmp[1]) if S <= W: print("unsafe") else: print("safe")
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n, k = LI() A = [0] + LI() for i in range(1, n + 1): A[i] = (A[i] + A[i - 1] - 1) % k ans = 0 D = defaultdict(int) for j in range(n + 1): if j >= k: D[A[j - k]] -= 1 ans += D[A[j]] D[A[j]] += 1 print(ans)
0
null
83,504,216,556,410
163
273
mod = 1000000007 fact = [] fact_inv = [] pow_ = [] pow25_ = [] pow26_ = [] def pow_ini(nn): global pow_ pow_.append(nn) for j in range(62): nxt = pow_[j] * pow_[j] nxt %= mod pow_.append(nxt) return def pow_ini25(nn): global pow25_ pow25_.append(nn) for j in range(62): nxt = pow25_[j] * pow25_[j] nxt %= mod pow25_.append(nxt) return def pow_ini26(nn): global pow26_ pow26_.append(nn) for j in range(62): nxt = pow26_[j] * pow26_[j] nxt %= mod pow26_.append(nxt) return def pow1(k): ansk = 1 for ntmp in range(62): if((k >> ntmp) % 2 == 1): ansk *= pow_[ntmp] ansk %= mod return ansk def pow25(k): ansk = 1 for ntmp in range(31): if((k >> ntmp) % 2 == 1): ansk *= pow25_[ntmp] ansk %= mod return ansk def pow26(k): ansk = 1 for ntmp in range(31): if((k >> ntmp) % 2 == 1): ansk *= pow26_[ntmp] ansk %= mod return ansk def fact_ini(n): global fact global fact_inv global pow_ for i in range(n + 1): fact.append(0) fact_inv.append(0) fact[0] = 1 for i in range(1, n + 1, 1): fact_tmp = fact[i - 1] * i fact_tmp %= mod fact[i] = fact_tmp pow_ini(fact[n]) fact_inv[n] = pow1(mod - 2) for i in range(n - 1, -1, -1): fact_inv[i] = fact_inv[i + 1] * (i + 1) fact_inv[i] %= mod return def nCm(n, m): assert(m >= 0) assert(n >= m) ans = fact[n] * fact_inv[m] ans %= mod ans *= fact_inv[n - m] ans %= mod return ans; fact_ini(2200000) pow_ini25(25) pow_ini26(26) K = int(input()) S = input() N = len(S) ans = 0 for k in range(0, K+1, 1): n = N + K - k anstmp = 1 anstmp *= pow26(k) anstmp %= mod anstmp *= nCm(n - 1, N - 1) anstmp %= mod anstmp *= pow25(n - N) anstmp %= mod ans += anstmp ans %= mod print(ans)
import os import heapq import sys import math import operator from collections import defaultdict from io import BytesIO, IOBase """def gcd(a,b): if b==0: return a else: return gcd(b,a%b)""" # def pw(a,b): # result=1 # while(b>0): # if(b%2==1): result*=a # a*=a # b//=2 # return result def inpt(): return [int(k) for k in input().split()] def main(): k = int(input()) s = input() n = len(s) ans = 0 md = 10 ** 9 + 7 ar26=[1] ar25=[1] a=1 b=1 nn=1 rr=1 num=[1] rum=[1] for i in range(1,n+k+1): nn*=i nn%=md rr*=i rr%=md num.append(nn) rum.append(rr) for i in range(k): a*=25 a%=md b*=26 b%=md ar26.append(b) ar25.append(a) for i in range(k+1): ans+=(num[n+k-i-1]*pow((rum[n-1]*rum[k-i])%md,md-2,md)*ar26[i]*ar25[k-i]) ans%=md print(ans) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main()
1
12,804,804,622,344
null
124
124
#!/usr/bin python3 # -*- coding: utf-8 -*- import sys input = sys.stdin.readline A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] def main(): K = int(input()) print(A[K-1]) if __name__ == '__main__': main()
if __name__ == "__main__": K = int(input()) num_ls = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] ret = num_ls[K-1] print(ret)
1
49,791,628,037,030
null
195
195
# coding=utf-8 from math import floor, ceil, sqrt, factorial, log, gcd from itertools import accumulate, permutations, combinations, product, combinations_with_replacement from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heappushpop import copy import numpy as np import sys INF = float('inf') mod = 10**9+7 sys.setrecursionlimit(10 ** 6) def lcm(a, b): return a * b / gcd(a, b) # 1 2 3 # a, b, c = LI() def LI(): return list(map(int, sys.stdin.buffer.readline().split())) # a = I() def I(): return int(sys.stdin.buffer.readline()) # abc def # a, b = LS() def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() # a = S() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') # 2 # 1 # 2 # [1, 2] def IR(n): return [I() for i in range(n)] # 2 # 1 2 3 # 4 5 6 # [[1,2,3], [4,5,6]] def LIR(n): return [LI() for i in range(n)] # 2 # abc # def # [abc, def] def SR(n): return [S() for i in range(n)] # 2 # abc def # ghi jkl # [[abc,def], [ghi,jkl]] def LSR(n): return [LS() for i in range(n)] # 2 # abcd # efgh # [[a,b,c,d], [e,f,g,h]] def SRL(n): return [list(S()) for i in range(n)] def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p fact = [1, 1] # n! mod p factinv = [1, 1] # (n!)^(-1) mod p tmp = [0, 1] # factinv 計算用 def main(): x, y = LI() ans = 0 if x > 2 * y or x < 0.5 * y or (x + y) % 3 != 0: print(0) return n, m = map(int, [(2 * y - x) / 3, (2 * x - y) / 3]) for i in range(2, n + m + 1): fact.append((fact[-1] * i) % mod) tmp.append((-tmp[mod % i] * (mod // i)) % mod) factinv.append((factinv[-1] * tmp[-1]) % mod) print(cmb(n+m, n, mod)) if __name__ == "__main__": main()
x,y = map(int,input().split()) mod = 10**9+7 def comb(a,b): comb = 1 chld = 1 for i in range(b): comb = comb*(a-i)%mod chld = chld*(b-i)%mod return (comb*pow(chld,mod-2,mod))%mod if (x+y)%3!=0: print(0) else: nm = (x+y)//3 n = y-nm m = x-nm if n>=0 and m>=0: print(comb(n+m,m)) else: print(0)
1
149,923,992,368,458
null
281
281
a, b = map(int,input().split()) print(a*b if a < 10 and b < 10 and a > 0 and b > 0 else -1)
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) 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(): A, B = MI() x = 10 * B for i in range(x, x + 10): y = int(i * 8 / 100) if y == A: print(i) exit() print(-1) if __name__ == "__main__": main()
0
null
107,548,810,072,860
286
203
def calc(a,D,K): if K==1: return a+(D-1)*9 elif K==2: return (a-1)*(D-1)*9 + (D-1)*(D-2)//2*81 else: return (a-1)*(D-1)*(D-2)//2*81 + (D-1)*(D-2)*(D-3)//6*729 N=input() K=int(input()) D = len(N) score=0 for i,a in enumerate(N): if a!="0": score+=calc(int(a),D-i,K) K-=1 if K==0: break print(score)
while True: x = input() if x == '0': break print(sum(int(c) for c in str(x)))
0
null
38,739,300,086,930
224
62
n, k = map(int, input().split()) A = list(map(int, input().split())) l = 1 r = 10**9+1 while l < r: mid = (l+r)//2 count = 0 for i in range(n): if A[i] > mid: count += A[i]//mid if count <= k: r = mid else: l = mid+1 print(l)
S = "ACL" k = int(input()) print(S*k)
0
null
4,362,588,848,640
99
69
#f = open("C:/Users/naoki/Desktop/Atcoder/input.txt") N = int(input()) A = list(map(int, input().split())) A.insert(0, 0) select_num = N//2 inf = -10e+100 Dp_f = [[inf] * (3) for _ in range(N+1)] Dp_s = [[inf] * (3) for _ in range(N+1)] # 3 次元はそれぞれStart~3つに該当 pre_margin = 0 for i in range(1,N+1): Start = (i-1)//2 End = (i+1)//2 cur_margin = Start for j in range(Start,End+1): Dp_f[i][j-cur_margin] = max(Dp_s[i-1][j-pre_margin], Dp_f[i-1][j-pre_margin]) # [0] in 3rd dimension not chosen at last num # must be transfered from [i-1] for j in range(Start,End+1): if j-1 == 0: Dp_s[i][j-cur_margin] = 0 + A[i] else: Dp_s[i][j-cur_margin] = Dp_f[i-1][j-1-pre_margin]+A[i] pre_margin = cur_margin print(max(Dp_f[-1][select_num - cur_margin], Dp_s[-1][select_num - cur_margin]))
import copy n = int(input()) a = list(map(int, input().split())) k = 1 + n%2 INF = 10**18 dp = [[-INF]*4 for i in range(n+5)] dp[0][0] = 0 for i in range(n): for j in range(k+1): dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]) now = copy.deepcopy(dp[i][j]) if (i+j) % 2 == 0: now += a[i] dp[i+1][j] = max(dp[i+1][j], now) print(dp[n][k])
1
37,510,957,446,922
null
177
177
h,w=[int(x) for x in input().rstrip().split()] l=[list(input()) for i in range(h)] move=[[1,0],[-1,0],[0,-1],[0,1]] def bfs(x,y): stack=[[x,y]] done=[[False]*w for i in range(h)] dist=[[0]*w for i in range(h)] max_val=0 while(stack): nx,ny=stack.pop(0) done[ny][nx]=True for dx,dy in move: mx=nx+dx my=ny+dy if not(0<=mx<=w-1) or not(0<=my<=h-1) or done[my][mx]==True or l[my][mx]=="#": continue done[my][mx]=True dist[my][mx]=dist[ny][nx]+1 max_val=max(max_val,dist[my][mx]) stack.append([mx,my]) return max_val ans=0 for i in range(w): for j in range(h): if l[j][i]!="#": now=bfs(i,j) ans=max(ans,now) print(ans)
x, n = map(int,input().split()) L = list(map(int,input().split())) l, r = x-1, x+1 if n == 0 or x not in L: print(x) exit() while True: if l not in L: print(l) break elif r not in L: print(r) break l -= 1 r += 1
0
null
54,629,230,206,260
241
128
N, M = map(int, input().split()) A = sorted(list(map(int, input().split()))) def count_bigger_x(x): cnt = 0 piv = N-1 for a in A: while piv >= 0 and a + A[piv] >= x: piv -= 1 cnt += N - piv - 1 return cnt def is_ok(x): cnt = count_bigger_x(x) return cnt >= M def bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok x = bisect(2 * A[-1] + 1, 2 * A[0] - 1) ans = 0 piv = N-1 for a in A: while piv >= 0 and a + A[piv] >= x: piv -= 1 ans += (N - piv - 1) * a ans *= 2 ans -= 1 * x * (count_bigger_x(x) - M) print(ans)
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) 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()) from collections import defaultdict import bisect def main(): N, K = MI() ans = 0 p = 1 while p <= N: p *= K ans += 1 print(ans) if __name__ == "__main__": main()
0
null
86,083,147,495,520
252
212
while True: x = input() if int(x) == 0: break print(sum([int(i) for i in x]))
while True: n = list(map(int,input())) if n[0] ==0: break else: print(sum(n))
1
1,598,389,594,240
null
62
62
import sys alpha = input() text = 'abcdefghijklmnopqrstuvwxyz' for k in range(26): if text[k] == alpha: print('a') sys.exit() else: if k == 25: print('A')
h,w,k = map(int, input().split()) cake = [input() for i in range(h)] ans = [[0]*w for i in range(h)] now = 1 for i in range(h): for j in range(w): if cake[i][j] == '#': ans[i][j] = now now+=1 for i in range(h): for j in range(1,w): if ans[i][j] == 0: ans[i][j] = ans[i][j-1] for i in range(h): for j in reversed(range(w-1)): if ans[i][j] == 0: ans[i][j] = ans[i][j+1] for i in range(1,h): for j in range(w): if ans[i][j] == 0: ans[i][j] = ans[i-1][j] for i in reversed(range(h-1)): for j in range(w): if ans[i][j] == 0: ans[i][j] = ans[i+1][j] for i in range(h): for j in range(w): print(ans[i][j], end=' ') print()
0
null
77,946,107,099,780
119
277
import sys N,M=map(int,input().split()) adj={} for ln in sys.stdin: A,B=map(int,ln.split()) if A not in adj: adj[A]=[] if B not in adj: adj[B]=[] adj[A].append(B) adj[B].append(A) a=[0]*(N+1) a[1]=-1 que=[1] while que: suc=[] for u in que: for v in adj[u]: if a[v]!=0: continue a[v]=u suc.append(v) que=suc #print(N,M) #print(adj) #print(a) ok=True ans=[] for i in range(2,N+1): if a[i]==0: ok=False break ans.append(a[i]) if not ok: print('No') else: print('Yes') for x in ans: print(x)
from collections import deque def main(): N,M,*AB=map(int,open(0).read().split()) g=[[] for _ in range(N+1)] for a,b in zip(*[iter(AB)]*2): g[a].append(b) g[b].append(a) q=deque([1]) s=[0]*(N+1) s[1]=1 while q: u=q.popleft() for v in g[u]: if not s[v]: s[v] = u q.append(v) print("Yes") print("\n".join(map(str, s[2:]))) if __name__ == "__main__": main()
1
20,605,388,653,472
null
145
145
x = int(input()) cnt_500 = 0 cnt_5 = 0 while x > 4: if x >= 500: x -= 500 cnt_500 += 1 else: x -= 5 cnt_5 += 1 print(1000*cnt_500+5*cnt_5)
a,b = map(int,input().split()) print(a*b if a < 10 and b < 10 else -1)
0
null
100,220,549,079,158
185
286
N=int(input()) A,B=map(str,input().split()) S="" for i in range(N): S+=A[i] S+=B[i] print(S)
def INT(): return int(input()) def LI(): return list(map(int, input().split())) def MI(): return map(int, input().split()) N, K = MI() p = LI() def E(x): return (x + 1) / 2 for i in range(N): p[i] = E(p[i]) ans = sum(p[:K]) E_K = ans for i in range(N - K): E_K += p[i + K] - p[i] ans = max(ans, E_K) print(ans)
0
null
93,497,485,866,428
255
223
def main(): h,w,k = map(int,input().split()) maze = [['.' for j in range(6)] for i in range(6)] for i in range(h): line = list(input()) for j in range(w): maze[i][j] = line[j] # print(maze) ver = [0 for i in range(6)] hor = [0 for i in range(6)] horver = [[0 for i in range(6)] for j in range(6)] total = 0 for i in range(6): for j in range(6): if maze[i][j] == '#': ver[j] += 1 hor[i] += 1 horver[i][j] = 1 total += 1 # print(ver,hor,horver) ans = 0 for bit in range(2**(h+w)): tmp = total valid_hor = [] for i in range(h): if (bit >> i & 1) == 1: valid_hor.append(i) tmp -= hor[i] for j in range(h,h+w): if (bit >> j & 1) == 1: tmp -= ver[j-h] for i in valid_hor: tmp += horver[i][j-h] if tmp == k: ans += 1 print(ans) return if __name__ == '__main__': main()
def main(): S = input() L = len(S) print('x' * L) if __name__ == '__main__': main()
0
null
40,765,714,436,884
110
221
n = int(input()) a = list(map(int,input().split())) s = sum(a) x = 0 m = s for i in range(n): x += a[i] m = min(m, abs(s-x*2)) print(m)
a,b = map(int, raw_input().split()) s = a*b l = 2*a + 2*b print s, l
0
null
71,299,783,124,220
276
36
A, B, C, D = map(int, input().split()) T_HP = A T_AT = B A_HP = C A_AT = D T_count = 0 A_count = 0 while T_HP > 0: T_HP -= A_AT T_count += 1 while A_HP > 0: A_HP -= T_AT A_count += 1 if T_count > A_count: print('Yes') elif T_count == A_count: print('Yes') else: print('No')
class monster: def __init__(self, hp: int, ap: int): self.hit_point = hp self.attack_point = ap self.status = 'healthy' def attack(self, enemy: 'monster'): enemy.defend(self.attack_point) def defend(self, enemy_ap: int): self.hit_point -= enemy_ap if self.hit_point <= 0: self.status = 'dead' def is_alive(self) -> bool: return not self.is_dead() def is_dead(self) -> bool: return self.status == 'dead' def answer(t_hp: int, t_ap: int, a_hp: int, a_ap: int) -> str: taka_monster = monster(t_hp, t_ap) aoki_monster = monster(a_hp, a_ap) while taka_monster.is_alive() and aoki_monster.is_alive(): taka_monster.attack(aoki_monster) if aoki_monster.is_dead(): return 'Yes' aoki_monster.attack(taka_monster) if taka_monster.is_dead(): return 'No' def main(): a, b, c, d = map(int, input().split()) print(answer(a, b, c, d)) if __name__ == '__main__': main()
1
29,786,583,140,024
null
164
164
def solve(string): _, c = string.split() r = c.count("R") return str(c[:r].count("W")) if __name__ == '__main__': import sys print(solve(sys.stdin.read().strip()))
n=int(input()) c=input() a=c.count('R') print(c[:a].count('W'))
1
6,277,576,331,922
null
98
98
from collections import Counter n=int(input()) a=list(map(int,input().split())) i_l=[] j_l=[] for i in range(n): i_l.append(i+a[i]) j_l.append(i-a[i]) ci=Counter(i_l) cl=Counter(j_l) ans=0 for k,v in ci.items(): ans+=v*cl[k] print(ans)
N = int(input()) Alist = list(map(int,input().split())) Aplu = [] Amin = dict() for i in range(N): A = Alist[i] Aplu.append(A+(i+1)) if (i+1)-A not in Amin: Amin[(i+1)-A] = 1 else: Amin[(i+1)-A] += 1 Answer = 0 for k in Aplu: if k in Amin: Answer += Amin[k] print(Answer)
1
25,950,795,658,498
null
157
157
L, R, d = map(int, input().split()) a = 1 ans = 0 while a*d <= R: if a*d >= L: ans += 1 a += 1 print(ans)
L,R,d=map(int,input().split()) ans=0 for i in range(L,R+1): if i%d==0: ans+=1 print(ans)
1
7,506,283,480,502
null
104
104
from sys import stdin class Dice: def __init__(self, nums): self._1 = nums[0] self._2 = nums[1] self._3 = nums[2] self._4 = nums[3] self._5 = nums[4] self._6 = nums[5] self.pos = { "E" : self._3, "W" : self._4, "S" : self._2, "N" : self._5, "T" : self._1, "B" : self._6 } def roll(self, query): for q in query: if q == "E": self.pos["T"], self.pos["E"], self.pos["B"], self.pos["W"] = self.pos["W"], self.pos["T"], self.pos["E"], self.pos["B"] elif q == "W": self.pos["T"], self.pos["E"], self.pos["B"], self.pos["W"] = self.pos["E"], self.pos["B"], self.pos["W"], self.pos["T"] elif q == "S": self.pos["T"], self.pos["S"], self.pos["B"], self.pos["N"] = self.pos["N"], self.pos["T"], self.pos["S"], self.pos["B"] elif q == "N": self.pos["T"], self.pos["S"], self.pos["B"], self.pos["N"] = self.pos["S"], self.pos["B"], self.pos["N"], self.pos["T"] nums = [int(x) for x in stdin.readline().rstrip().split()] queries = stdin.readline().rstrip() d = Dice(nums) d.roll(queries) print(d.pos["T"])
import math n=int(input()) i=1 ans=10**20 while i*i<=n: if n%i==0: x=i y=n//i ans=min(ans,x+y-2) i+=1 print(ans)
0
null
80,634,002,276,840
33
288
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 X=I() if X>=30: print("Yes") else: print("No") main()
import sys, math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial#, gcd from bisect import bisect_left #bisect_left(list, value) sys.setrecursionlimit(10**7) enu = enumerate MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def pri(x): print('\n'.join(map(str, x))) 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 def prime_decomposition2(n): i = 2 table = defaultdict(int) while i*i <= n: while n%i == 0: n //= i table[i] += 1 i += 1 if n > 1: table[n] += 1 return table def make_divisor(n): divisors = [] for i in range(1, int(n**0.5)+1): if n%i == 0: divisors.append(i) if i != n//i: divisors.append(n//i) return divisors N = int(input()) list_pd1 = make_divisor(N) list_pd1.sort() dict_pd2 = prime_decomposition2(N-1) #print(N, ':', list_pd1) #print(N-1, ':', dict_pd2) cnt = 1 # -1 nohou for val in dict_pd2.values(): cnt *= (val+1) cnt -= 1 #print(cnt) for k in list_pd1[1:]: #print('k:', k) sN = N while sN >= k: if sN%k==0: sN //= k else: sN %= k if sN == 1: cnt += 1 print(cnt)
0
null
23,649,747,331,520
95
183
N = int(input()) X = input() n1 = X.count("1") Xn = int(X, 2) Xms = (Xn % (n1 - 1)) if n1 > 1 else 0 Xml = Xn % (n1 + 1) def f(n): if n == 0: return 0 return f(n % bin(n).count("1")) + 1 dp = [0] * ((10 ** 5) * 2 + 1) for i in range(1, len(dp)): dp[i] = f(i) for i in range(N): cnt = 0 Xim = 0 if X[i] == "1" and n1 == 1: print(cnt) elif X[i] == "1": print(dp[(Xms - pow(2, N - i - 1, n1 - 1)) % (n1 - 1)] + 1) else: print(dp[(Xml + pow(2, N - i - 1, n1 + 1)) % (n1 + 1)] + 1)
import sys input = sys.stdin.readline N, M = map(int, input().split()) S = list(input().rstrip()) def cost(S): minCost = [-1]*(N+1) minCost[0] = 0 ind = 1 for i,s in enumerate(S): if s == "1": continue while i < ind <= min(i+M, N): if S[ind] == "0": minCost[ind] = minCost[i] + 1 ind += 1 return minCost M1 = cost(S) M2 = cost(S[::-1])[::-1] if M1[-1] == -1: print(-1) else: C = M1[-1] Inds = [10**14]*(C+1) for i, (m1, m2) in enumerate(zip(M1, M2)): if m1 + m2 == C: Inds[m1] = min(Inds[m1], i) ans = [] for i1, i2 in zip(Inds, Inds[1:]): ans.append(i2-i1) print(*ans)
0
null
73,368,946,932,842
107
274
x,y = map(int,input().split(" ")) def gdp(x,y): if x > y: big = x small = y else: big = y small = x if big%small == 0: print(small) return else: gdp(small,big%small) gdp(x,y)
import sys for i, x in enumerate(iter(sys.stdin.readline, '0\n'), 1): print(f'Case {i}: {x[:-1]}')
0
null
244,021,305,540
11
42
S = input() list = [] for i in S: list.append(i) if list[2]==list[3] and list[4]==list[5]: print("Yes") else: print("No")
import math r=float(input()) S=r*r*math.pi L=2*r*math.pi print('%.5f %.5f'%(S,L))
0
null
21,227,102,897,180
184
46
from math import ceil from bisect import bisect_right n, d, a = map(int, input().split()) l = [] l2 = [] l3 = [] l4 = [0 for i in range(n+1)] l5 = [0 for i in range(n+1)] ans = 0 for i in range(n): x, h = map(int, input().split()) l.append([x, h]) l2.append(x + 2 * d) l3.append(x) l.sort(key=lambda x: x[0]) l2.sort() l3.sort() for i in range(n): cnt = ceil((l[i][1] - l4[i] * a) / a) if cnt > 0: ans += cnt ind = bisect_right(l3, l2[i]) l5[ind] += cnt l4[i] += cnt l4[i+1] = l4[i] - l5[i+1] print(ans)
h1, m1, h2, m2, k = map(int,input().split()) s = -60*h1-m1+60*h2+m2 print(s-k)
0
null
50,212,342,459,872
230
139
#!/usr/bin/env python # coding: utf-8 # In[21]: N,K = map(int, input().split()) R,S,P = map(int,input().split()) T = input() # In[22]: points = {} points["r"] = P points["s"] = R points["p"] = S ans = 0 mylist = [] for i in range(N): mylist.append(T[i]) if i >= K: if T[i] == mylist[-K-1]: mylist[-1] = "x" else: ans += points[T[i]] else: ans += points[T[i]] print(ans) # In[ ]:
from sys import stdin input = stdin.readline def main(): N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) T = input()[:-1] mem = [] hand_map = {'r': 'p', 's': 'r', 'p': 's'} score_map = {'r': P, 's': R, 'p': S} score = 0 for i in range(K): mem.append(hand_map[T[i]]) score += score_map[T[i]] for i in range(K, N): if not mem[i-K] == hand_map[T[i]]: mem.append(hand_map[T[i]]) score += score_map[T[i]] continue cand = ['r', 's', 'p'] # print(mem[i-K]) cand.remove(mem[i-K]) if i+K < N and not(mem[i-K] == hand_map[T[i+K]]): cand.remove(hand_map[T[i+K]]) mem.append(cand[0]) print(score) if(__name__ == '__main__'): main()
1
106,730,940,319,772
null
251
251
def main(): S = input() stack1, stack2 = [], [] sum = 0 N = len(S) for i in range(N): if S[i] == "\\": stack1.append(i) elif S[i] == "/" and stack1: j = stack1.pop() tmp = i - j sum += tmp while stack2 and stack2[-1][0] > j: tmp += stack2.pop()[1] stack2.append([j, tmp]) print(sum) print(len(stack2), *[a for j, a in stack2]) if __name__=="__main__": main()
# coding: utf-8 s = list(input().rstrip()) ht = [] ponds=[] for i, ch in enumerate(s): if ch == "\\": ht.append(i) elif ch == "/": if ht: b = ht.pop() ap = i - b if not ponds: ponds.append([b, ap]) else: while ponds: p = ponds.pop() if p[0] > b: ap += p[1] else: ponds.append([p[0],p[1]]) break ponds.append([b,ap]) else: pass ans = "" area = 0 for point, ar in ponds: area += ar ans += " " ans += str(ar) print(area) print(str(len(ponds)) + ans)
1
56,917,555,268
null
21
21
a, b, c, d = [int(i) for i in input().split()] res = float("-inf") for i in [a,b]: for j in [c,d]: res = max(i * j, res) print(res)
a, b, c, d = map(int, input().split()) if b < 0: if c <= 0: print(a * c) else: print(b * c) elif a <= 0: if d < 0: print(a*c) elif a <= 0: print(max(a*c, b*d)) else: print(b*d) else: if d < 0: print(a * d) else: print(b * d)
1
3,017,226,098,850
null
77
77
n,k = map(int, input().split()) i=0 a=[] while n!=0: a.append(n%k) n=n//k i=i+1 print(len(a))
*abc, k = list(map(int, input().split())) n = [0] * 3 ans = 0 for i, v in enumerate(abc): if k >= v: n[i] = v k -= v else: n[i] = k break print(n[0] + n[1] * 0 + n[2] * -1)
0
null
43,166,050,468,288
212
148
x, n = map(int, input().split()) lis = [] if n == 0: print(x) else: lis = list(map(int, input().split())) if x not in lis: print(x) else: y = x + 1 z = x - 1 while True: if y in lis and z in lis: y += 1 z -= 1 elif z not in lis: print(z) break elif y not in lis: print(y) break
x,n =map(int,input().split()) if n ==0: print(x) exit() p =list(map(int,input().split())) l = [] for i in range(51): if x-i not in p and x+i not in p: print(min(x-i,x+i)) exit() elif x-i not in p and x+i in p: print(x-i) exit() elif x-i in p and x+i not in p: print(x+i) exit()
1
14,157,019,107,572
null
128
128
import sys input = sys.stdin.readline # B - An Odd Problem N = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(N): if i % 2 == 0: if a[i] % 2 == 1: ans += 1 print(ans)
N = int(input()) query = [] ans = 0 for i in range(N): A = int(input()) query.append([list(map(int, input().split())) for j in range(A)]) for i in range(1<<N): count = 0 FLG = True for j in range(N): if (i >> j) & 1: count += 1 for x, y in query[j]: if (i >> (x - 1)) & 1 != y: FLG = False break if not FLG: break else: ans = max(ans, count) print(ans)
0
null
64,536,941,849,560
105
262
def main(): n = int(input()) mod = 10**9+7 print((pow(10, n, mod)-pow(9, n, mod)*2+pow(8, n, mod))%mod) if __name__ == "__main__": main()
# # # author : samars_diary # # 16-09-2020 │ 18:28:11 # # # import sys, os.path, math #if(os.path.exists('input.txt')): #sys.stdin = open('input.txt',"r") #sys.stdout = open('output.txt',"w") sys.setrecursionlimit(10 ** 5) def mod(): return 10**9+7 def i(): return sys.stdin.readline().strip() def ii(): return int(sys.stdin.readline()) def li(): return list(sys.stdin.readline().strip()) def mii(): return map(int, sys.stdin.readline().split()) def lii(): return list(map(int, sys.stdin.readline().strip().split())) #print=sys.stdout.write def solve(): a=ii();print((pow(10,a,mod())+pow(8,a,mod())-2*pow(9,a,mod()))%mod()) for _ in range(1): solve()
1
3,153,539,306,822
null
78
78
from sys import stdin,stdout LI=lambda:list(map(int,input().split())) MAP=lambda:map(int,input().split()) IN=lambda:int(input()) S=lambda:input() import math from collections import Counter,defaultdict n=IN() a=LI() ans=0 for i in range(n): ans^=a[i] for i in range(n): print(ans^a[i],end=" ")
def main(): from sys import stdin n,a,b = map(int,stdin.readline().rstrip().split()) k = b-a-1 if k%2==1: print(k//2+1) else: print(k//2+1+min(n-b,a-1)) main()
0
null
60,737,311,973,040
123
253
import sys input=sys.stdin.readline n=int(input()) x=input().rstrip() x10=int(x,2) pcx=x.count("1") plus=x10%(pcx+1) if pcx>=2: minus=x10%(pcx-1) def popcnt(x): cnt=1 while x>=1: x%=(bin(x).count("1")) cnt+=1 return cnt for i in range(n): if x[i]=="0": amari=(plus+pow(2,n-i-1,pcx+1))%(pcx+1) print(popcnt(amari)) else: if pcx==1: print(0) else: amari=(minus-pow(2,n-i-1,pcx-1))%(pcx-1) print(popcnt(amari))
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): d, t, s = map(int, input().split()) if t * s >= d: print('Yes') else: print('No') if __name__ == '__main__': main()
0
null
5,958,898,727,290
107
81
__author__= 'CIPHER' str = input() numList = str.split(' ') numList = [ int(x) for x in numList] #print(numList) result = 1 length = 0 for x in numList: result *= x length += x print(result,2*length)
# -*- coding: utf-8 -*- a=int(input()) s=a+a**2+a**3 print(s)
0
null
5,211,971,579,360
36
115
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) tmp_time = 0 last_i = -1 for i in range(N): if tmp_time + A[i] <= K: tmp_time += A[i] last_i = i else: break last_j = -1 for j in range(M): if tmp_time + B[j] <= K: tmp_time += B[j] last_j = j else: break ans = last_i + last_j + 2 now = ans while last_i >= 0: tmp_time -= A[last_i] now -= 1 last_i -= 1 while last_j + 1 < M and tmp_time + B[last_j + 1] <= K: tmp_time += B[last_j + 1] last_j += 1 now += 1 ans = max(ans, now) print(ans) def main(): solve() if __name__ == '__main__': main()
# ==================================================- # 二分探索 # functionを満たす,search_listの最大の要素を出力 # 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき import math import sys sys.setrecursionlimit(10 ** 9) def binary_research(start, end,function): if start == end: return start middle = math.ceil((start + end) / 2) if function(middle, k, a_sum, b_sum): start = middle else: end = middle - 1 return binary_research(start, end, function) # ==================================================- n, m, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] a_sum = [0] b_sum = [0] for book in a: a_sum.append(a_sum[-1] + book) for book in b: b_sum.append(b_sum[-1] + book) def can_read(num, k, a_sum, b_sum): min_read_time = 1000000000000 for i in range(max(0, num - m), min(num+1,n+1)): a_num = i b_num = num - i min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num]) if min_read_time <= k: return True return False start = 0 end = n + m print(binary_research(start, end, can_read))
1
10,821,982,299,744
null
117
117
n = int(input()) def calc(m, res): q, mod = divmod(m, 26) if (mod == 0): q = q - 1 mod = 26 res = chr(ord("a") + (mod - 1)) + res else: res = chr(ord("a") + (mod - 1)) + res if (q > 0): calc(q, res) else: print(res) return calc(n, "")
#N, K = map(int, input().split( )) #L = list(map(int, input().split( ))) N = int(input()) i = 0 ans = [] #26^{i}がNを越えるまで以下の操作を繰り返す while N != 0: s = N%26 if s == 0: s = 26 N -= s N //= 26 ans.append(chr(s + 96)) print(''.join(list(reversed(ans))))
1
12,002,609,799,210
null
121
121
_fib = [0] * 45 def fib(n): if n < 2: return 1 if _fib[n] > 0: return _fib[n] _fib[n] = fib(n-1) + fib(n-2) return _fib[n] n = int(input()) print(fib(n))
n = int(raw_input()) a = map(int, raw_input().split()) def print_list(list): for i in range(len(list)-1): print(list[i]), print(list[len(list)-1]) #print("") print_list(a) for i in range(1,n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v print_list(a)
0
null
3,900,937,248
7
10
# -*- 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)] MOD = int(1e09) + 7 # INF = int(1e15) def solve(): MAX = 2 * 10 ** 5 + 10 fac = [0] * MAX inv = [0] * MAX finv = [0] * MAX fac[0] = fac[1] = finv[0] = finv[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 def cmb(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD N, K = Scanner.map_int() ans = 0 for i in range(min(N - 1, K) + 1): ans += cmb(N, i) * cmb(N - 1, i) ans %= 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()
N = int(input()) """ 愚直にやると、Kを2~Nの範囲で全部調べて数え上げる。N <= 10**12 なので間に合わない。 たとえば N=100だと、 [2, 3, 4, 9, 10, 11, 33, 99, 100] が条件を満たす数字になる。 割り算を行わないとき、明らかに N % K = 1 になる これは、「NをKで割ったら、1あまる」であるから、「N-1をKでわったら割り切れる」ともいえる。 なので、割り算が起こらないものは、N-1の約数。 割り算が起こるやつは、割れるだけ割った後、余りを調べればよい。 """ def solve(n): i = 1 ret = set() while i * i <= n: if n % i == 0: ret.add(i) ret.add(n // i) i += 1 return ret div_N_sub_1 = solve(N-1) div_N = solve(N) ans = len(div_N_sub_1) - 1 for i in div_N: if i == 1: continue tmp = N while tmp % i == 0: tmp //= i if tmp % i == 1: ans += 1 print(ans)
0
null
54,329,938,269,760
215
183
x = int(input()) print(2*x*3.14)
import sys import math R = int(input()) if not ( 1 <= R <= 100 ): sys.exit() print((R+R) * math.pi)
1
31,313,956,870,938
null
167
167
A,B,N=map(int,input().split()) # A,B,N=11, 10, 5 ans=0 if N>=B: ans=(A*(B-1))//B - A*((B-1)//B) else: ans=(A*N)//B - A*(N//B) print(ans)
S = input() ans = "Yes" if S == "AAA" or S == "BBB": ans = "No" print(ans)
0
null
41,434,861,066,560
161
201
import math a,b,c = [int(x) for x in input().split()] c = math.radians(c) s = a * b * math.sin(c) / 2 l = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(c)) h = 2 * s / a for i in [s,l,h]: print('{:.12f}'.format(i))
N = int(input()) S = input() if N % 2 or S[:N//2] != S[N//2:]: print("No") else: print("Yes")
0
null
73,712,414,024,470
30
279
#!/usr/bin/env python3 import sys from collections import Counter input = sys.stdin.readline INF = 10**9 n, k = [int(item) for item in input().split()] a = [int(item) - 1 for item in input().split()] cumsum = [0] * (n + 1) for i in range(n): cumsum[i+1] = cumsum[i] + a[i] cumsum[i+1] %= k ls = list(set(cumsum)) dic = dict() for i, item in enumerate(ls): dic[item] = i cnt = [0] * (n + 10) num = 0 ans = 0 for i, item in enumerate(cumsum): index = dic[item] ans += cnt[index] cnt[index] += 1 num += 1 if num >= k: left = cumsum[i - k + 1] index = dic[left] if cnt[index] > 0: cnt[index] -= 1 num -= 1 print(ans)
# -*- coding: utf-8 -*- import sys N=input() bit=[ [ 0 for _ in range(N+1) ] for __ in range(27) ] def add(i,a,w): while a<=N: bit[i][a]+=w a+=a&-a def sum(i,a): ret=0 while 0<a: ret+=bit[i][a] a-=a&-a return ret S=sys.stdin.readline().strip() S=[None]+list(S) #1-indexed for j,x in enumerate(S): if j==0: continue i=ord(x)-96 add(i,j,1) Q=input() for _ in range(Q): q1,q2,q3=sys.stdin.readline().split() if q1=="1": q1=int(q1) q2=int(q2) current_s=q3 former_s=S[q2] former_s=ord(former_s)-96 #1-indexed S[q2]=current_s #文字列で更新された1文字を置き換える current_s=ord(current_s)-96 add(current_s,q2,1) add(former_s,q2,-1) if q1=="2": q2=int(q2) q3=int(q3) begin,end=q2,q3 cnt=0 for i in range(1,27): if 0<sum(i,end)-sum(i,begin-1): cnt+=1 print cnt
0
null
99,941,575,005,828
273
210
def main(): abcd = [int(_x) for _x in input().split()] a = abcd[0] b = abcd[1] c = abcd[2] d = abcd[3] while True: c = c - b if c <= 0: print("Yes") return a = a - d if a <= 0: print("No") return main()
a, b, c, d = map(int, input().split()) print('Yes') if (a-1) // d >= (c-1) // b else print('No')
1
29,692,273,190,280
null
164
164
n = int(input()) a = list(map(int, input().split())) sub_list = [0] * n for i in (a): sub_list[i - 1] += 1 for i in range(n): print(sub_list[i], sep = ',')
def fibonacci(i, num_list): if i == 0 or i == 1: num_list[i] = 1 else: num_list[i] = num_list[i-2] + num_list[i-1] n = int(input()) + 1 num_list = [0 for i in range(n)] for i in range(n): fibonacci(i, num_list) print(num_list[-1])
0
null
16,347,206,112,228
169
7
n = int(input()) shou500 = n//500 shou5 = (n-shou500*500)//5 print(shou500*1000+shou5*5)
l = input().split() print(int(l.index('0'))+1)
0
null
28,013,467,310,972
185
126
import sys #import time compare_counter = 0 array = [0 for x in range(500000)] def merge(left, mid, right): n_fore = mid - left n_rear = right - mid l_fore = array[left:left + n_fore] l_fore.append(sys.maxsize) l_rear = array[mid:mid + n_rear] l_rear.append(sys.maxsize) #print(left, mid, right) i = j = 0 global compare_counter compare_counter += (right - left) for k in range(left, right): if l_fore[i] < l_rear[j]: array[k] = l_fore[i] i += 1 else: array[k] = l_rear[j] j += 1 def merge_sort(left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(left, mid) merge_sort(mid, right) merge(left, mid, right) return def main(): #start = time.time() n = int(input()) for idx, tmp in enumerate(input().split()): array[idx] = int(tmp) #print("time", time.time()-start) merge_sort(0, n) #print("time", time.time()-start) print(" ".join(map(str, array[:n]))) print(compare_counter) #print("time",time.time()-start) return main()
n = int(input()) S = list(map(int, input().split())) count = 0 def merge(A, left, mid, right): global count n1 = mid - left n2 = right - mid L = A[left: left + n1] R = A[mid: mid + n2] L.append(float('inf')) R.append(float('inf')) i = j = 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 count += 1 def merge_sort(A, left, right): if (left + 1) < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) merge_sort(S, 0, n) print(*S) print(count)
1
108,117,044,668
null
26
26
N,M,K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) a = [0] b = [0] for i in range(N): a.append(a[i] + A[i]) for j in range(M): b.append(b[j] + B[j]) ans = 0 j = M for i in range(N+1): if a[i] > K: break while a[i] + b[j] > K: j -= 1 ans = max(ans, i+j) print(ans)
N,M,K=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a_s=[0] b_s=[0] for i in range(N): if a_s[i]+a[i]>K: break a_s.append(a[i]+a_s[i]) for i in range(M): if b_s[i]+b[i]>K: break b_s.append(b[i]+b_s[i]) bn=len(b_s)-1 ans=0 for i in range(len(a_s)): while a_s[i]+b_s[bn]>K: bn-=1 ans=max(ans,i+bn) print(ans)
1
10,680,246,680,950
null
117
117
from collections import deque n = int(input()) x = input() memo = {0: 0} def solve(X): x = X stack = deque([]) while x: if x in memo: break stack.append(x) x = x % bin(x).count("1") cnt = memo[x] + 1 while stack: x = stack.pop() memo[x] = cnt cnt += 1 return cnt - 1 ans = [] px = x.count("1") memo1 = [1 % (px - 1)] if px > 1 else [] memo2 = [1 % (px + 1)] x1 = 0 x2 = 0 for i in range(n): if px > 1: memo1.append(memo1[-1] * 2 % (px-1)) memo2.append(memo2[-1] * 2 % (px+1)) for i in range(n): if x[-i-1] == '1': if px > 1: x1 += memo1[i] x1 %= (px-1) x2 += memo2[i] x1 %= (px+1) for i in range(n): if x[-i-1] == "1": if px > 1: ans.append(solve((x1-memo1[i])%(px-1)) + 1) else: ans.append(0) else: ans.append(solve((x2+memo2[i])%(px+1)) + 1) for ansi in reversed(ans): print(ansi)
n = int(input()) x = list(input()) def popcount(n): bin_n = bin(n)[2:] count = 0 for i in bin_n: count += int(i) return count cnt = 0 for i in range(n): if x[i] == '1': cnt += 1 plus = [0 for i in range(n)] # 2^index を cnt+1 で割った時のあまり minus = [0 for i in range(n)] # 2^index を cnt-1 で割った時のあまり if cnt == 0: plus[0] = 0 else: plus[0] = 1 if cnt != 1: minus[0] = 1 for i in range(1, n): plus[i] = (plus[i-1]*2) % (cnt+1) if cnt != 1: minus[i] = (minus[i-1]*2) % (cnt-1) origin = int(''.join(x), base=2) amariplus = origin % (cnt+1) if cnt != 1: amariminus = origin % (cnt-1) for i in range(n): if x[i] == '0': amari = (amariplus + plus[n-i-1]) % (cnt+1) else: if cnt != 1: amari = (amariminus - minus[n-i-1]) % (cnt-1) else: print(0) continue ans = 1 while amari != 0: ans += 1 amari = amari % popcount(amari) print(ans)
1
8,213,654,392,512
null
107
107
def main(): n = input() S = map(int,raw_input().split()) q = input() T = map(int,raw_input().split()) m = 0 for i in range(q): t = T.pop() for j in range(n): s = S[j] if t == s: m += 1 break print m if __name__ == "__main__": main()
import math import numpy as np n = int(input()) s = math.sqrt(n) i = 2 f = {} while i <= s: while n % i == 0: f[i] = f.get(i,0)+1 n = n // i i += 1 ans = 0 for x in f.values(): e = 0 cumsum = 0 while e + cumsum + 1 <= x: e += 1 cumsum += e ans += e print(ans+(n>1))
0
null
8,497,896,198,848
22
136
from functools import reduce n, a, b = map(int, input().split(" ")) MOD = 10**9 + 7 def comb(n, r, mod=float("inf")): c = 1 m = 1 r = min(n - r, r) for i in range(r): c = c * (n - i) % mod m = m * (i + 1) % mod return c * pow(m, mod - 2, mod) % mod print((pow(2, n, MOD) - comb(n, a, MOD) - comb(n, b, MOD) - 1) % MOD)
mod = 10**9+7 n,a,b = map(int,input().split()) base = pow(2,n,mod)-1 def comb(n,k): comb = 1 for i in range(n-k+1,n+1): comb *= i comb %= mod for i in range(1, k+1): comb *= pow(i,mod-2,mod) comb %= mod return comb print((base-comb(n,a)-comb(n,b))%mod)
1
66,489,904,557,482
null
214
214
class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N, M = map(int, input().split()) u = UnionFind(N+1) for i in range(M): A, B = map(int, input().split()) u.union(A, B) print(max([u.get_size(i) for i in range(1, N+1)]))
def solve(): N,X,Y = [int(i) for i in input().split()] distance_cnt = {} for i in range(1, N+1): for j in range(i+1, N+1): distance = min(j-i, abs(X-i)+abs(Y-j)+1) distance_cnt[distance] = distance_cnt.get(distance, 0) + 1 for i in range(1, N): print(distance_cnt.get(i, 0)) if __name__ == "__main__": solve()
0
null
24,116,601,193,540
84
187
n,k = list(map(int,input().split())) r,s,p = list(map(int,input().split())) t = str(input()) t_list = [] for i in range(k): t_list.append(t[i]) for i in range(k,n): if t[i] != t_list[i-k] or t_list[i-k] == 'all': t_list.append(t[i]) else: t_list.append('all') print(t_list.count('r') * p + t_list.count('s') * r + t_list.count('p') * s)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n, k = map(int, readline().split()) r, s, p = map(int, readline().split()) t = readline().decode().rstrip() t = list(t) for i in range(k, n): if t[i] == t[i - k]: t[i] = 0 ans = t.count('r') * p + t.count('p') * s + t.count('s') * r print(ans)
1
106,859,731,998,272
null
251
251
from collections import deque N, M = map(int, input().split()) edge = [[] for _ in range(N)] sign = [-1] * N for _ in range(M): A, B = map(int, input().split()) edge[A - 1].append(B - 1) edge[B - 1].append(A - 1) d = deque([0]) while d: cur = d.popleft() for adj in edge[cur]: if sign[adj] == -1: sign[adj] = cur d.append(adj) print("Yes") for i in range(1, N): print(sign[i] + 1)
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy # from collections import Counter,defaultdict,deque # from itertools import permutations, combinations # from heapq import heappop, heappush # from fractions import gcd # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n,m = inpm() way = [[] for _ in range(n+1)] for i in range(m): a,b = inpm() way[a].append(b) way[b].append(a) ans = [0 for i in range(n+1)] q = queue.Queue() q.put((1,0)) while not q.empty(): room,sign = q.get() if ans[room] != 0: continue ans[room] = sign for i in way[room]: q.put((i,room)) print('Yes') for i in range(2,n+1): print(ans[i])
1
20,347,760,894,608
null
145
145
r = int(input()) print(r * 2 * 3.1415926535897932384626433)
import math R = int(input()) o = R*2*math.pi print(o)
1
31,205,025,394,720
null
167
167
n = int(input()) a = list(map(int, input().split())) b = a[0] for v in a[1:]: b ^= v print(*map(lambda x: x ^ b, a))
S=input();print(sum(a!=b for a,b in zip(S,S[::-1]))//2)
0
null
65,961,695,581,910
123
261
input() cnt = 0 x = "" for s in input(): if x != s: cnt += 1 x = s print(cnt)
N = int(input()) S = input() count = 1 check = S[0] for c in S: if c != check: count += 1 check = c print(count)
1
169,828,817,621,270
null
293
293
B=[] for i in range(3): A=list(map(int,input().split())) B.append(A[0]) B.append(A[1]) B.append(A[2]) N=int(input()) for j in range(N): b=int(input()) if b in B: B[B.index(b)]=0 if B[0]==0 and B[1]==0 and B[2]==0: print('Yes') elif B[3]==0 and B[4]==0 and B[5]==0: print('Yes') elif B[6]==0 and B[7]==0 and B[8]==0: print('Yes') elif B[0]==0 and B[3]==0 and B[6]==0: print('Yes') elif B[1]==0 and B[4]==0 and B[7]==0: print('Yes') elif B[2]==0 and B[5]==0 and B[8]==0: print('Yes') elif B[0]==0 and B[4]==0 and B[8]==0: print('Yes') elif B[2]==0 and B[4]==0 and B[6]==0: print('Yes') else: print('No')
import sys N = int(input()) List = [[-1] * N for i in range(N)] for i in range(N): A = int(input()) for j in range(A): x, y = map(int, input().split()) List[i][x - 1] = y Max = 0 for i in range(2 ** N): flag = True Sum = 0 for j in range(N): # このループが一番のポイント if ((i >> j) & 1): # 順に右にシフトさせ最下位bitのチェックを行う for k in range(N): if (List[j][k] != int((i >> k) & 1)) and List[j][k] != -1: flag = False Sum += 1 if flag: #print(i,Sum) Max = max(Max, Sum) print(Max)
0
null
90,770,000,865,700
207
262
n=int(input()) a=list(map(int,input().split())) mod=10**9+7 ans=0 for k in range(60): t=1<<k z=o=0 for i in a: if i&t:o+=1 else:z+=1 ans=(ans+(z*o*t))%mod print(ans)
N = int(input()) A = list(map(int, input().split())) A = sorted(A) count = 0 max = A[-1] if max == 0: print(0) exit() import math V = [0]*(math.floor(math.log(max, 2))+1) for i in range (0, N): B = A[i] vount = 0 while B > 0: if B%2 == 0: B = B//2 vount+=1 else: B = (B-1)//2 V[vount]+=1 vount+=1 for i in range (0, len(V)): count+=((V[i]*(N-V[i]))*(2**i)) print(count%(10**9+7))
1
123,016,557,677,220
null
263
263
from collections import defaultdict n = int(input()) A = list(map(int, input().split())) dd = defaultdict(int) ans = 0 for i in range(n): diff = i - A[i] ans += dd[diff] summ = A[i] + i dd[summ] += 1 print(ans)
import math N,M=map(int,input().split()) def C(x): if x>=2: return math.factorial(x)//(math.factorial(x-2)*2) else: return 0 print(C(N)+C(M))
0
null
35,890,835,021,792
157
189
n,k = map(int,input().split()) r,s,p = map(int,input().split()) t = input() l = [[] for i in range(k)] ans = 0 for i in range(n): mod = i%k l[mod].append(t[i]) for i in range(k): h = "" for j in l[i]: if j == "r" and h != "p": ans += p h = "p" elif j == "s" and h != "r": ans += r h = "r" elif j == "p" and h != "s": ans += s h = "s" else: h = "" print(ans)
#!/usr/bin/env python # coding: utf-8 # In[21]: N,K = map(int, input().split()) R,S,P = map(int,input().split()) T = input() # In[22]: points = {} points["r"] = P points["s"] = R points["p"] = S ans = 0 mylist = [] for i in range(N): mylist.append(T[i]) if i >= K: if T[i] == mylist[-K-1]: mylist[-1] = "x" else: ans += points[T[i]] else: ans += points[T[i]] print(ans) # In[ ]:
1
106,607,704,280,140
null
251
251
def II(): return int(input()) def MI(): return map(int, input().split()) A,B,N=MI() def f(x): return A*x//B-A*(x//B) if B-1<=N: ans=f(B-1) else: ans=f(N) print(ans)
a,b,n = list(map(int,input().split())) if n < b : x = n else : x = b-1 print(a*x//b-a*(x//b))
1
28,130,026,138,928
null
161
161
a = input() print("Yes" if (a[2] == a[3]) and (a[4] == a[5]) else "No")
from sys import stdin import math inp = lambda : stdin.readline().strip() s = inp() if s[2] == s[3] and s[4] == s[5]: print("Yes") else: print("No")
1
41,962,437,377,444
null
184
184
def main(): N = int(input()) d = dict() for i in range(1, N+1): u = int(str(i)[0]) v = int(str(i)[-1]) d[(u, v)] = d.get((u, v), 0) + 1 ans = 0 for u, v in d: if (v, u) in d: ans += d[(u, v)] * d[(v, u)] return ans if __name__ == '__main__': print(main())
S = input().rstrip() if S[-1] == 's': print(S + 'es') else: print(S + 's')
0
null
44,502,888,653,106
234
71
N = int(input()) cnt = 0 for A in range(1, N + 1): for B in range(1, N // A + 1): C = N - A * B if C >= 1 and A * B + C == N: cnt += 1 print(cnt)
#!/usr/bin/python # -*- coding: utf-8 -*- # def def int_mtx(N): x = [] for _ in range(N): x.append(list(map(int,input().split()))) return np.array(x) def str_mtx(N): x = [] for _ in range(N): x.append(list(input())) return np.array(x) def int_map(): return map(int,input().split()) def int_list(): return list(map(int,input().split())) def print_space(l): return print(" ".join([str(x) for x in l])) # import import numpy as np import collections as col N = int(input()) ans = 0 for i in range(1,N): if N%i != 0: ans += N//i else: ans += N//i -1 print(ans)
1
2,564,155,793,540
null
73
73
import sys # sys.setrecursionlimit(100000) def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return [int(i) for i in input().split()] def main(): n = input_int() A = input_int_list() MOD = 10**9 + 7 cnt = 1 x, y, z = 0, 0, 0 for a in A: tmp = 0 is_used = False # x,y,zのどこかに配った。 if a == x: tmp += 1 if not is_used: x += 1 is_used = True if a == y: tmp += 1 if not is_used: y += 1 is_used = True if a == z: tmp += 1 if not is_used: z += 1 is_used = True cnt *= tmp cnt = cnt % MOD print(cnt) return if __name__ == "__main__": main()
n=int(input()) d=list(map(int,input().split())) r=1 if d[0]==0 else 0 d=d[1:] d.sort() c=1 nc=0 j=1 mod=998244353 for i in d: if i<j: r=0 elif i==j: nc+=1 r=(r*c)%mod elif i==j+1: j=i c=nc nc=1 r=(r*c)%mod else: r=0 print(r)
0
null
143,057,839,622,560
268
284
n = int(input()) ls = [] rs = [] for _ in range(n): x, y = map(int, input().split()) ls.append(x) rs.append(y) ls = sorted(ls) rs = sorted(rs) if n % 2 == 1: print(rs[len(rs)//2] - ls[len(ls)//2] + 1) else: a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) // 2 b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) // 2 print((a - b) // 5 + 1)
N=int(input()) A=list() B=list() for i in range(N): a,b=map(int,input().split()) A.append(a) B.append(b) A.sort() B.sort() if N%2==1: print(B[int((N-1)/2+0.5)]-A[int((N-1)/2+0.5)]+1) else: print((B[int(N/2+0.5)-1]+B[int(N/2+0.5)])-(A[int(N/2+0.5)-1]+A[int(N/2+0.5)])+1)
1
17,294,766,513,418
null
137
137
H, N = map(int, input().split()) A = list(map(int, input().split())) if H - sum(A) <= 0: print("Yes") else: print("No")
h,n=map(int,input().split()) a=list(map(int,input().split())) sum=0 for i in a: sum += i if sum<h: print("No") else: print("Yes")
1
78,375,910,074,110
null
226
226
N,A,B = map(int,input().split()) if A%2 != 0 and B%2 == 0: ans = (B-A-1)//2 + min(A-1,N-B) + 1 elif A%2 == 0 and B%2 != 0: ans = (B-A-1)//2 + min(A-1,N-B) + 1 else: ans = (B-A)//2 print(ans)
a = list(map(int, input().split())) a.sort() print(*a)
0
null
54,931,583,372,072
253
40
from collections import defaultdict n, k = map(int, input().split()) a = list(map(int, input().split())) a_cs = [0] * (n + 1) for i in range(n): a_cs[i + 1] = a_cs[i] + a[i] ans = 0 d = defaultdict(int) for j in range(n + 1): if j - k >= 0: d[(a_cs[j - k] - (j - k)) % k] -= 1 # print(j, d, d[(a_cs[j] - j) % k]) ans += d[(a_cs[j] - j) % k] d[(a_cs[j] - j) % k] += 1 print(ans)
N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] s = [0] * (N+1) for i in range(N): s[i+1] = s[i] + A[i] s[i+1] %= K s.reverse() for i in range(N+1): s[i] += (i%K) s[i] %= K d = {} ans = 0 for i in range(N+1): if s[i] not in d: d[s[i]] = 0 if i >= K: d[s[i-K]] -= 1 ans += d[s[i]] d[s[i]] += 1 print(ans)
1
137,489,444,964,930
null
273
273
import sys from collections import deque read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): H, W = map(int, readline().split()) S = [[0] * W for _ in range(H)] for i in range(H): S[i] = readline().strip() dxdy4 = ((-1, 0), (0, -1), (0, 1), (1, 0)) ans = 0 for i in range(H): for j in range(W): if S[i][j] == '#': continue dist = [[-1] * W for _ in range(H)] dist[i][j] = 0 queue = deque([(i, j)]) res = 0 while queue: x, y = queue.popleft() for dx, dy in dxdy4: nx, ny = x + dx, y + dy if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.' and dist[nx][ny] == -1: dist[nx][ny] = dist[x][y] + 1 if res < dist[nx][ny]: res = dist[nx][ny] queue.append((nx, ny)) if ans < res: ans = res print(ans) return if __name__ == '__main__': main()
from itertools import product h, w = map(int, input().split()) maze = [input() for _ in range(h)] def neighbors(ih, iw): for ih1, iw1 in ( (ih - 1, iw), (ih + 1, iw), (ih, iw - 1), (ih, iw + 1), ): if 0 <= ih1 < h and 0 <= iw1 < w and maze[ih1][iw1] == '.': yield (ih1, iw1) def len_maze(ih, iw): # BFS if maze[ih][iw] == '#': return 0 stepped = [[False] * w for _ in range(h)] q0 = [(ih, iw)] l = -1 while q0: q1 = set() for ih0, iw0 in q0: stepped[ih0][iw0] = True for ih1, iw1 in neighbors(ih0, iw0): if not stepped[ih1][iw1]: q1.add((ih1, iw1)) q0 = list(q1) l += 1 return l answer = max(len_maze(ih, iw) for ih, iw in product(range(h), range(w))) print(answer)
1
94,934,844,662,420
null
241
241
# coding=utf-8 import itertools def main(): while True: n, t = map(int, raw_input().split()) if n + t == 0: break print sum([1 if sum(three) == t else 0 for three in itertools.combinations(xrange(1, n+1), 3)]) if __name__ == '__main__': main()
from itertools import combinations as comb def get_ans(m, n): ans = sum(1 for nums in comb(range(1, min(m+1,n-2)), 2) if ((n-sum(nums)>0) and (n-sum(nums) > max(nums)) and (n-sum(nums)<=m))) return ans while True: m, n = (int(x) for x in input().split()) if m==0 and n==0: quit() ans = get_ans(m, n) print(ans)
1
1,293,102,059,720
null
58
58
s = input() x = ["hi", "hihi", "hihihi", "hihihihi", "hihihihihi"] if s in x: print("Yes") else: print("No")
S=input(); if(S=="hi" or S=="hihi" or S=="hihihi" or S=="hihihihi" or S=="hihihihihi"): print("Yes"); else: print("No");
1
53,432,457,250,438
null
199
199
S = input() l = len(S) // 2 ll = l // 2 former = S[:l] latter = S[l+1:] for i in range(l): if S[i] != S[-i-1]: print("No") break else: for i in range(ll): if former[i] != former[-i-1] or latter[i] != latter[-i-1]: print("No") break else: print("Yes")
import sys def read_heights(): current = 0 heights = [current] for c in sys.stdin.read().strip(): current += { '/': 1, '\\': -1, '_': 0 }[c] heights.append(current) return heights heights = read_heights() height_index = {} for i, h in enumerate(heights): height_index.setdefault(h, []).append(i) flooded = [False] * len(heights) floods = [] # search from highest points for h in sorted(height_index.keys(), reverse=True): indexes = height_index[h] for i in range(len(indexes) - 1): start = indexes[i] stop = indexes[i + 1] if start + 1 == stop or flooded[start] or flooded[stop]: continue if any(heights[j] >= h for j in range(start + 1, stop)): continue # flood in (start..stop) floods.append((start, stop)) for j in range(start, stop): flooded[j] = True floods.sort() areas = [] for start, stop in floods: area = 0 top = heights[start] for i in range(start + 1, stop + 1): h = heights[i] area += top - h + (heights[i - 1] - h) * 0.5 areas.append(int(area)) print(sum(areas)) print(' '.join([str(v) for v in [len(areas)] + areas]))
0
null
23,124,261,955,092
190
21
from sys import stdin,stdout from collections import deque,defaultdict from math import ceil,floor,inf,sqrt,factorial,gcd,log2 from copy import deepcopy ii1=lambda:int(stdin.readline().strip()) is1=lambda:stdin.readline().strip() iia=lambda:list(map(int,stdin.readline().strip().split())) isa=lambda:stdin.readline().strip().split() mod=1000000007 s=is1() print(s[0:3])
N,P = map(int,input().split()) S = list(map(int,list(input()))) if P==2: cnt = 0 for i in range(N): if S[i]%2==0: cnt += i+1 elif P==5: cnt = 0 for i in range(N): if S[i]==0 or S[i]==5: cnt += i+1 else: A = [0 for _ in range(N)] a = 0 b = 1 for i in range(N-1,-1,-1): a = (a+b*S[i])%P A[i] = a b = (b*10)%P C = {i:0 for i in range(P)} for i in range(N): C[A[i]] += 1 cnt = 0 for i in range(P): cnt += (C[i]*(C[i]-1))//2 cnt += C[0] print(cnt)
0
null
36,510,373,743,910
130
205
from collections import defaultdict N = int(input()) A = list(map(int, input().split())) d = defaultdict(int) for key in A: d[key] += 1 #print(d) Sum = 0 for i in d: n = d[i] Sum += (n * (n - 1)) // 2 #print((n * (n - 1)) // 2) #print(d[A[i]],i) #print(d) #print(Sum) for i in range(N): n = d[A[i]] hoge = Sum - (n*(n-1))//2 n -= 1 hoge += (n*(n-1))//2 print(hoge)
a = [list(map(int, input().split())) for i in range(3)] n = int(input()) b = [int(input()) for i in range(n)] for i in b: for j in range(0,3): for k in range(0,3): if i == a[j][k]: a[j][k] = 0 if a[0][0]==0 and a[0][1]==0 and a[0][2]==0: print("Yes") elif a[1][0]==0 and a[1][1]==0 and a[1][2]==0: print("Yes") elif a[2][0]==0 and a[2][1]==0 and a[2][2]==0: print("Yes") elif a[0][0]==0 and a[1][0]==0 and a[2][0]==0: print("Yes") elif a[0][1]==0 and a[1][1]==0 and a[2][1]==0: print("Yes") elif a[0][2]==0 and a[1][2]==0 and a[2][2]==0: print("Yes") elif a[0][0]==0 and a[1][1]==0 and a[2][2]==0: print("Yes") elif a[0][2]==0 and a[1][1]==0 and a[2][0]==0: print("Yes") else: print("No")
0
null
53,508,442,699,924
192
207
#C問題 import numpy as np X,K,D = map(int, input().split()) ans = 0 if X >= 0 : if int(X/D)<=K: if int(X/D)%2==K%2: ans = X%D else: ans = D-X%D else: ans = abs(X-K*D) if X < 0 : if abs(int(X/D))<=K: if abs(int(X/D))%2==K%2: ans = abs(X)%D else: ans = D-abs(X)%D else: ans = abs(X+K*D) print(ans)
x, k, d = map(int, input().split()) x = abs(x) k_ = min(k, x // d) k = k - k_ x = x-k_*d if k % 2 != 0: x = abs(x-d) print(x)
1
5,236,336,931,120
null
92
92
N,M=list(map(int,input().split())) E={i:[] for i in range(1,N+1)} for i in range(M): a,b=list(map(int,input().split())) E[a].append(b) E[b].append(a) V={i:0 for i in range(1,N+1)} W=[1] while W!=[]: S=[] for a in W: for b in E[a]: if V[b]==0: V[b]=a S.append(b) W=S if -1 in V: print('No') else: print('Yes') for i in range(2,N+1): print(V[i])
text=input() n=int(input()) for i in range(n): order=input().split() a,b=map(int,order[1:3]) if order[0]=="print": print(text[a:b+1]) elif order[0]=="reverse": re_text=text[a:b+1] text=text[:a]+re_text[::-1]+text[b+1:] else : text=text[:a]+order[3]+text[b+1:]
0
null
11,365,927,390,400
145
68
s = list(input()) n = len(s)-1 count = 0 if s != s[::-1]: for i in range(0,(n+1)//2): if s[i] != s[n-i]: count += 1 print(count)
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n, k = map(int, readline().split()) p = list(map(int, readline().split())) l = [i for i in range(1, 1001)] av = np.cumsum(l) / l tmp = [av[i - 1] for i in p] cs = list(np.cumsum(tmp)) if n == k: print(cs[-1]) exit() ans = 0 for i in range(n - k): ans = max(ans, cs[i + k] - cs[i]) print(ans)
0
null
97,759,715,822,902
261
223
#! python3 # dice_i.py class dice(): def __init__(self, arr): self.top = arr[0] self.south = arr[1] self.east = arr[2] self.west = arr[3] self.north = arr[4] self.bottom = arr[5] def rotate(self, ope): if ope == 'S': self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top elif ope == 'N': self.top, self.south, self.bottom, self.north = self.south, self.bottom, self.north, self.top elif ope == 'E': self.top, self.west, self.bottom, self.east = self.west, self.bottom, self.east, self.top elif ope == 'W': self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top dc = dice([int(x) for x in input().split(' ')]) opes = list(input()) for op in opes: dc.rotate(op) print(dc.top)
class Dice(): def __init__(self, *n): self.rolls = n def spin(self, order): if order == "N": self.rolls = [ self.rolls[1], self.rolls[5], self.rolls[2], self.rolls[3], self.rolls[0], self.rolls[4] ] if order == "E": self.rolls = [ self.rolls[3], self.rolls[1], self.rolls[0], self.rolls[5], self.rolls[4], self.rolls[2] ] if order == "S": self.rolls = [ self.rolls[4], self.rolls[0], self.rolls[2], self.rolls[3], self.rolls[5], self.rolls[1] ] if order == "W": self.rolls = [ self.rolls[2], self.rolls[1], self.rolls[5], self.rolls[0], self.rolls[4], self.rolls[3] ] return self.rolls[0] d = Dice(*[int(i) for i in input().split()]) for order in list(input()): l = d.spin(order) print(l)
1
225,715,192,210
null
33
33
n=int(input()) edges=[[] for i in range(1+n)] e={} for i in range(n-1): """#weighted->erase_,__,___=map(int,input().split()) edges[_].append((__,___)) edges[__].append((_,___)) """ _,__=map(int,input().split()) edges[_].append(__) edges[__].append(_) e[(_,__)]=i e[(__,_)]=i """ """#weighted->erase f=max(len(j)for j in edges) print(f) ret=[0]*(n-1) from collections import deque dq=deque([(1,1)]) #pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす) while dq: a,c=dq.popleft() for to in edges[a]: if ret[e[(a,to)]]:continue ret[e[(a,to)]]=c c=c%f+1 dq.append((to,c)) print(*ret,sep="\n")
from collections import deque import sys sys.setrecursionlimit(20000000) N = int(input()) ab = [list(map(int, input().split())) for _ in range(N-1)] routes = [[] for _ in range(N)] for i in range(len(ab)): routes[ab[i][0]-1].append([ab[i][1]-1, i]) routes[ab[i][1]-1].append([ab[i][0]-1, i]) route_color = [-10e+10 for _ in range(len(ab))] route_num = [0]*N max_route = 0 for i in range(N): num = len(routes[i]) route_num[i] = num if max_route < num: max_route = num seen = [False for _ in range(N)] def function(num,pre_color): color_num = -1 for route in routes[num]: color_num += 1 if color_num == pre_color: color_num+=1 if route_color[route[1]] != -10e+10: color_num-=1 pass else: route_color[route[1]] = color_num if seen[route[0]] == False: seen[route[0]] = True function(route[0],route_color[route[1]]) return function(0,-1) print(max_route) for color in route_color: print(color+1)
1
136,229,552,849,468
null
272
272
S=input() ans='Yes' i=0 while i<len(S): if S[i:i+2]!='hi': ans='No' i+=2 print(ans)
import re S = input() print('Yes' if len(re.sub(r'hi', '', S)) == 0 else 'No')
1
53,346,615,033,030
null
199
199
x, n = map(int, input().split()) p = list(map(int, input().split())) def calc(a): return abs(a - x) if not n: print(x) exit() l = [i for i in range(102) if i not in set(p)] print(min(l, key=calc))
def warshall_floid(d): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): d[i][j] = min(d[i][j],d[i][k]+d[k][j]) return d n,m,l = map(int,input().split()) d = [[10**13]*(n+1) for i in range(n+1)] for i in range(m): a,b,c = map(int,input().split()) d[a][b] = c d[b][a] = c for i in range(1,n+1): d[i][i] = 0 d = warshall_floid(d) for i in range(1,n+1): for j in range(1,n+1): if d[i][j] <= l: d[i][j] = 1 else: d[i][j] = 10**13 d = warshall_floid(d) q = int(input()) for i in range(q): s,t = map(int,input().split()) if d[s][t] >= 10**13: print(-1) else: print(d[s][t]-1)
0
null
93,503,740,239,360
128
295
n=int(input()) a=list(map(int,input().split())) ans='APPROVED' for i in range(n): if a[i]%2==0: if a[i]%3!=0 and a[i]%5!=0: ans='DENIED' print(ans)
from math import * H = int(input()) print(2**(int(log2(H))+1)-1)
0
null
74,502,647,817,500
217
228
import math n = int(input()) f = math.floor(n / 1.08) c = math.ceil(n / 1.08) for i in [f, c]: if math.floor(i*1.08) == n: print(i) exit() print(':(')
N = int(input()) for i in range(N+1): X = i * 1.08 if int(X) == N: print(i) exit() print(':(')
1
126,251,244,533,722
null
265
265
from collections import deque import sys n = int(sys.stdin.readline()) #lines = sys.stdin.readlines() lines = [input() for i in range(n)] deq = deque() for i in range(n): o = lines[i].split() if o[0] == 'insert': deq.appendleft(o[1]) elif o[0] == 'delete': try: deq.remove(o[1]) except: continue elif o[0] == 'deleteFirst': deq.popleft() elif o[0] == 'deleteLast': deq.pop() print(' '.join(deq))
from collections import deque if __name__ == '__main__': n = int(input()) dll = deque() for _ in range(n): command = input().split() if command[0] == 'insert': dll.appendleft(command[1]) elif command[0] == 'delete': try: dll.remove(command[1]) except ValueError: pass elif command[0] == 'deleteFirst': dll.popleft() elif command[0] == 'deleteLast': dll.pop() print(*dll)
1
52,298,225,728
null
20
20
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * X = INT() lim = 10**5+1 dp = [0]*lim t = [100 + i for i in range(6)] for i in range(6): dp[100+i] = 100+i for j in range(106, lim): dp[j] += sum([dp[j-k] for k in t]) if dp[X] == 0: print("0") else: print("1")
x=int(input()) if x<100: print(0) exit() if x>=2000: print(1) exit() else: t=x//100 a=x%100 if 0<=a<=t*5: print(1) else: print(0)
1
127,238,926,778,452
null
266
266
# python3 # -*- coding: utf-8 -*- import sys import math import bisect from fractions import gcd from itertools import count, permutations from functools import lru_cache from collections import deque, defaultdict from pprint import pprint INF = float('inf') ii = lambda: int(input()) mis = lambda: map(int, input().split()) lmis = lambda: list(mis()) lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)] sys.setrecursionlimit(1000000000) def lcm(a, b): return (a * b) // gcd(a, b) # main n = ii() alist = lmis() asum = sum(alist[1:n]) sum = 0 for i in range(n-1): sum += alist[i] * asum asum -= alist[i+1] print(sum % 1000000007)
n = int(input()) xpy = [] xmy = [] for i in range(n): x,y = map(int,input().split()) xpy.append(x+y) xmy.append(x-y) xpy.sort() xmy.sort() print(max(abs(xpy[0]-xpy[-1]),abs(xmy[0]-xmy[-1])))
0
null
3,603,610,048,850
83
80
import sys input = lambda: sys.stdin.readline()[:-1] n,k=map(int,input().split()) w = [int(input()) for i in range(n)][::-1] def maxnumber(p): wc=w.copy() for i in range(k): lim=p while len(wc): if wc[-1]<=lim: lim-=wc.pop() else:break return len(wc) minp=float('inf') left,right=1,10**9+1 while left<right: mid=(left+right)//2 maxn=maxnumber(mid) if maxn>0: left=mid+1 else: right=mid minp=min(mid,minp) print(minp)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ???????????? """ inp = input().strip().split(" ") n = int(inp[0]) m = int(inp[1]) l = int(inp[2]) # ?????????????????????????¢???? # A[n][m] B[m][l] C[n][l] A = [[0 for i in range(m)] for j in range(n)] B = [[0 for i in range(l)] for j in range(m)] C = [[0 for i in range(l)] for j in range(n)] # A???????????°?????????????????? for i in range(n): inp = input().strip().split(" ") for j in range(m): A[i][j] = int(inp[j]) # B???????????°?????????????????? for i in range(m): inp = input().strip().split(" ") for j in range(l): B[i][j] = int(inp[j]) # A x B for i in range(n): for j in range(l): for k in range(m): C[i][j] += A[i][k] * B[k][j] print(" ".join(map(str,C[i])))
0
null
754,913,442,580
24
60
n = int(input()) s = set() for i in range(n): a,b = input().strip().split() if a == 'insert': s.add(b) if a == 'find': if b in s: print('yes') else: print('no')
a = int(input()) print((a)+(a ** 2)+(a ** 3))
0
null
5,139,495,228,414
23
115
n=int(input()) d=list(map(int,input().split())) if d[0] != 0: print(0) exit() d.sort() if d[1] == 0: print(0) exit() cnt = 1 pre = 1 ans =1 i = 1 mod = 998244353 while i < n: if d[i]-1 != d[i-1]: ans = 0 while i!=n-1 and d[i+1] == d[i]: i+=1 cnt+=1 ans *= pow(pre,cnt,mod) ans %= mod pre =cnt cnt = 1 i+=1 print(ans)
import collections N = int(input()) D = list(map(int,input().split())) if D[0] != 0 or 0 in D[1:]: print(0) exit() A = collections.Counter(D) A = list(A.items()) A.sort() if len(A) != max(D) + 1: print(0) exit() ans = 1 for i in range(max(D)): ans *= A[i][1]**A[i+1][1] if ans >= 998244353: ans %= 998244353 print(ans)
1
154,727,052,287,860
null
284
284
h,w,m=map(int,input().split()) H,W=[0]*h,[0]*w P=set() for i in range(m): y,x=map(int,input().split()) H[~-y]+=1 W[~-x]+=1 P.add(~-y*w+~-x) mh,mw=max(H),max(W) MH=[i for i,h in enumerate(H) if h==mh] MW=[i for i,v in enumerate(W) if v==mw] for y in MH: for x in MW: if y*w+x not in P: print(mh+mw) exit() print(mh+mw-1)
n,k=map(int,input().split()) a=list(map(int,input().split())) def imos(a): imos_l=[0 for i in range(n)] for i in range(n): left=max(i-a[i],0) right=min(i+a[i],n-1) imos_l[left]+=1 if right+1!=n: imos_l[right+1]-=1 b=[0] for i in range(1,n+1): b.append(b[i-1]+imos_l[i-1]) return b[1:] for i in range(k): a=imos(a) if a.count(n)==n: break print(*a)
0
null
10,067,642,580,392
89
132
import sys from functools import reduce from operator import xor input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) s = reduce(xor, a) print(' '.join([str(xor(s, i)) for i in a]))
n = int(input()) a = [int(an) for an in input().split()] xor_all = 0 for an in a: xor_all = xor_all ^ an anss = [str(xor_all ^ an) for an in a] print(" ".join(anss))
1
12,542,592,818,628
null
123
123