code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
from collections import deque n,m = map(int,input().split()) to = [[] for _ in range(n)] for i in range(m): x, y = map(int,input().split()) to[x-1].append(y-1) to[y-1].append(x-1) INF = float('inf') dist = [INF]*n dist[0] = 0 pre = [-1]*n que = deque([]) que.append(0) while que: v = que.popleft() for u in to[v]: if dist[u] != INF:continue dist[u] = v + 1 pre[u] = v que.append(u) print("Yes") for i in range(1,n): print(dist[i])
def main(): from collections import deque import sys input = sys.stdin.readline N,M = map(int,input().split()) to = [[] for _ in range(N)] for _ in range(M): a,b = map(int,input().split()) a -= 1 b -= 1 to[a].append(b) to[b].append(a) # print(to) guide = [0] * N guide[0] = 1 q = deque() q.append(0) while len(q) > 0: u = q.popleft() for v in to[u]: # print(guide) if guide[v] != 0: continue guide[v] = u+1 q.append(v) print("Yes") for g in guide[1:]: print(g) if __name__ == '__main__': main()
1
20,385,830,829,748
null
145
145
n,k=map(int,input().split()) ans=1 while n//(k**ans): ans+=1 print(ans)
n,k = map(int,input().split()) ans = 1 while n >= k: ans += 1 n //= k print(ans)
1
64,084,599,808,192
null
212
212
MOD = 1000000007 def fast_power(base, power): """ Returns the result of a^b i.e. a**b We assume that a >= 1 and b >= 0 Remember two things! - Divide power by 2 and multiply base to itself (if the power is even) - Decrement power by 1 to make it even and then follow the first step """ result = 1 while power > 0: # If power is odd if power % 2 == 1: result = (result * base) % MOD # Divide the power by 2 power = power // 2 # Multiply base to itself base = (base * base) % MOD return result n,k = [int(j) for j in input().split()] d = dict() ans = k d[k] = 1 sum_so_far = 1 for i in range(k-1, 0, -1): d[i] = fast_power(k//(i),n) for mul in range(i*2, k+1, i): d[i]-=d[mul] # d[i] = max(1, d[i]) ans+=(i*d[i])%MOD # if d[i]>1: # sum_so_far += d[i] print(ans%MOD)
# -*- 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
93,010,028,528,172
176
281
import sys x,y = map(int,input().split()) for n in range(x+1): kame = x - n tsuru_leg = n*2 kame_leg = kame*4 if y == tsuru_leg + kame_leg: print('Yes') sys.exit() print('No')
def main(): n = int(input()) c = input() r = 0 for i in range(n): if c[i]=='R': r += 1 ans = 0 for i in range(r): if c[i]=='W': ans += 1 print(ans) if __name__ == "__main__": main()
0
null
9,996,957,363,602
127
98
n = int(input()) added_strings = set() for i in range(n): com, s = input().split() if com == 'insert': added_strings.add(s) elif com == 'find': print('yes' if (s in added_strings) else 'no')
def triangle(N, Ls): result = 0 res = [] numbers = {} edgeLength = list(set(Ls)) for i in edgeLength: numbers[i] = Ls.count(i) for i in range(len(edgeLength)): a = edgeLength[i] copy1 = edgeLength[i+1:] for j in range(len(copy1)): b = copy1[j] copy2 = copy1[j+1:] for k in range(len(copy2)): c = copy2[k] if a + b > c and b + c > a and c + a > b: res.append([a, b, c]) for val in res: result += numbers[val[0]] * numbers[val[1]] * numbers[val[2]] return result if __name__ == "__main__": N = list(map(int, input().split())) Ls = list(map(int, input().split())) print(triangle(N, Ls))
0
null
2,580,574,755,748
23
91
str = input() n = int(input()) for i in range(n): args = input().split() command = args[0] s = int(args[1]) e = int(args[2]) if command == 'print': print(str[s:e + 1]) if command == 'reverse': str = str[0:s] + str[s:e + 1][::-1] + str[e + 1:] if command == 'replace': str = str[0:s] + args[3] + str[e + 1:]
n = int(input()) a = list(map(int, input().split())) ans = 0 cnt = 0 for i in range(n) : if a[i] == cnt + 1 : cnt += 1 if cnt > 0 : print(n-cnt) else : print("-1")
0
null
58,708,806,487,300
68
257
import sys 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".split(", ") N = int(sys.stdin.readline().rstrip()) print(A[N-1])
#coding: utf-8 #itp1_9d def rev(s,a,b): b=b+1 t=s[a:b] u=t[::-1] x=s[:a] y=s[b:] return x+u+y def rep(s,a,b,w): b=b+1 x=s[:a] y=s[b:] return x+w+y s=raw_input() n=int(raw_input()) for i in xrange(n): d=raw_input().split() a=int(d[1]) b=int(d[2]) if d[0]=="print": print s[a:b+1] elif d[0]=="reverse": s=rev(s,a,b) elif d[0]=="replace": w=d[3] s=rep(s,a,b,w)
0
null
25,958,495,438,120
195
68
a, b, c, k = map(int, input().split()) ans = 0 if a >= k: ans = k elif a < k and a+b >= k: ans = a else: ans = a - (k-(a+b)) print(ans)
a, b, c, k = map(int, input().split()) if k - a <= 0: print(k) elif k - a > 0 and k - a - b <= 0: print(a) else: s = k - a - b print(a - s)
1
21,815,632,748,640
null
148
148
import sys import time import math import itertools as it def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ A, B = map(int, input().split()) print(int(A*B)) # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
num1, num2 = map(int, input().split()) print(num1*num2)
1
15,818,386,004,392
null
133
133
K=int(input()) A,B=map(int,input().split()) for x in range(A,B+1): if x%K==0: print("OK") break else: print("NG")
import sys K = int(input()) A, B = (int(x) for x in input().split()) num=0 while B>=num: num+=K if A<=num and num<=B: print("OK") sys.exit(0) print("NG")
1
26,627,692,624,930
null
158
158
from sys import stdin def ip(): return [int(i) for i in stdin.readline().split()] def sp(): return [str(i) for i in stdin.readline().split()] s = str(input()) c = 0 for i in s: c += int(i) if (c % 9) == 0: print("Yes") else: print("No")
import sys import math input = sys.stdin.readline def main(): k = int(input()) ans = 0 for a in range( 1 , k+1 ): for b in range( a , k+1 ): x = math.gcd( a , b ) for c in range( b , k+1 ): y = math.gcd( x , c ) if a == b == c: ans += y elif a==b or b==c or c==a: ans += 3 * y else: ans += 6 * y print(ans) main()
0
null
19,945,889,807,966
87
174
n, k = map(int, input().split()) sunukes = [0 for i in range(n)] for i in range(k): d = int(input()) aa = list(map(int, input().split())) for j in range(d): sunukes[aa[j] - 1] += 1 count = sum(1 for sunuke in sunukes if sunuke == 0) print(count)
import math , sys N = int( input() ) A = list(map(int, input().split() ) ) def Prime(x): ub=int(math.sqrt(x))+2 if x==2 or x==3 or x==5 or x==7: return True for i in range(2,ub): if x%i==0: return False return True y = N while not Prime(y): y+=1 def h1(x): return x % y def h2(x): return 1+ x%(y-1) def h(x,i): return (h1(x) + i*h2(x)) % y def insert(T,x): i=0 while True: j=h(x,i) if T[j][0]== -1: T[j][0]=x T[j][1]=1 return j elif x ==T[j][0]: T[j][1]+=1 return j else: i+=1 def search(T,x): i=0 while True: j=h(x,i) if T[j][0] == x: return T[j][1] elif T[j][0] == -1: return -1 else: i+=1 T = [[-1,0] for _ in range(y)] for i in range(N): insert(T , i + A[i]) ans =0 for j in range(N): if j - A[j]>=0: s = search(T, j - A[j]) if s >=0: ans+=s print(ans)
0
null
25,167,976,730,240
154
157
n = int(input()) s = list(input()) r = s.count('R') g = s.count('G') b = s.count('B') ans = r * g * b for i in range(n-2): for j in range(i+1,n-1): if (j - i) + j < n: k = (j - i) + j if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]: ans -= 1 print(ans)
N = int(input()) S = input() ans = S.count("R") * S.count("G") * S.count("B") for i in range(N-2): r = S[i] for j in range(i+1,N-1): g = S[j] if r == g: continue k = 2*j - i if k >= N: continue b = S[k] if r != b and g != b: ans -= 1 print(ans)
1
35,905,663,729,490
null
175
175
#atcoder template def main(): import sys imput = sys.stdin.readline #文字列入力の時は上記はerrorとなる。 #ここにコード #input N = int(input()) A, B = [0] * N, [0] * N for i in range(N): A[i], B[i] = map(int, input().split()) #output import statistics as st import math p = st.median(A) q = st.median(B) # %% if N % 2 == 0: print(int((q-p)/0.5)+1) else: print(int(q-p)+1) #N = 1のときなどcorner caseを確認! if __name__ == "__main__": main()
i = int(input()) while (i > 0): i -= 1000 print(abs(i))
0
null
12,751,057,368,312
137
108
import math import sys def main(): n = int(sys.stdin.readline()) total = 0 for i in range(1,n+1): for j in range(1,n+1): for k in range(1,n+1): total += math.gcd(i, math.gcd(j,k)) print(total) main()
from functools import lru_cache MOD = 10**9+7 x,y = map(int, input().split()) summ = x+y @lru_cache(maxsize=None) def inv(n): return pow(n,-1,MOD) if summ%3 == 0 and summ//3 <= x and summ//3 <= y: mn = min(x,y) n = mn - summ//3 a = summ//3 b = 1 ans = 1 for i in range(n): ans *= a ans *= inv(b) ans %= MOD a -= 1 b += 1 print(ans) else: print(0)
0
null
93,228,400,453,792
174
281
a = [] try: while True: a.append(input()) except EOFError: pass for i in range(len(a)): a[i] = a[i].lower() b=" ".join(a) for j in "abcdefghijklmnopqrstuvwxyz": print(j,":",b.count(j))
from collections import Counter counter = Counter() while True: try: s = input() for c in s: counter[c.lower()] += 1 except: break for c in range(ord('a'), ord('z')+1): print('{} : {}'.format(chr(c), counter[chr(c)]))
1
1,636,639,699,630
null
63
63
N = int(input()) S = input() abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Sn = "" for i in range(len(S)): Sn += abc[(abc.find(S[i])+N) % 26] print(Sn)
a = [int(s) for s in input().split()] b = int(a[0] // (a[1] + a[2])) c = int(a[0] % (a[1] + a[2])) d = b * a[1] if c >= a[1]: d = d + a[1] else: d = d + c print(d)
0
null
95,242,284,795,840
271
202
import sys import math from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)] #隣接リスト 1-order def make_adjlist_d(n, edges): res = [[] for _ in range(n + 1)] for edge in edges: res[edge[0]].append(edge[1]) res[edge[1]].append(edge[0]) return res def make_adjlist_nond(n, edges): res = [[] for _ in range(n + 1)] for edge in edges: res[edge[0]].append(edge[1]) return res #nCr def cmb(n, r): return math.factorial(n) // math.factorial(r) // math.factorial(n - r) def main(): X, Y, A, B, C = NMI() P = NLI() Q = NLI() R = NLI() reds = [[1, p] for p in P] greens = [[2, q] for q in Q] skels = [[0, r] for r in R] apples = reds + greens + skels apples.sort(key=lambda x: x[1], reverse=True) colors = [0, 0, 0] limits = [10**9, X, Y] ans = 0 for color, a in apples: if sum(colors) >= X + Y: break if colors[color] <= limits[color] - 1: colors[color] += 1 ans += a continue print(ans) if __name__ == "__main__": main()
X,Y,A,B,C=list(map(int,input().split())) p=sorted(list(map(int,input().split())),reverse=True) q=sorted(list(map(int,input().split())),reverse=True) r=sorted(list(map(int,input().split())),reverse=True) i=X-1 j=Y-1 k=0 ans=sum(p[:X])+sum(q[:Y]) while k<len(r): if i>-1 and j>-1: if p[i]<q[j]: cmin=p[i] i-=1 else: cmin=q[j] j-=1 if r[k]<=cmin: break ans+=r[k]-cmin k+=1 elif i>-1: cmin=p[i] i-=1 if r[k]<=cmin: break ans+=r[k]-cmin k+=1 elif j>-1: cmin=q[j] j-=1 if r[k]<=cmin: break ans+=r[k]-cmin k+=1 else: break print(ans)
1
44,966,367,573,120
null
188
188
from queue import deque S = input() Q = int(input()) Query = list(input().split() for _ in range(Q)) count = 0 L, R = deque(), deque() for i in range(Q): if Query[i][0] == "1": count += 1 else: if Query[i][1] == "1": if count % 2 == 0: L.appendleft(Query[i][2]) else: R.append(Query[i][2]) else: if count % 2 == 0: R.append(Query[i][2]) else: L.appendleft(Query[i][2]) L, R = "".join(L), "".join(R) if count % 2 == 0: print(L + S + R) else: print(R[::-1] + S[::-1] + L[::-1])
while True: n = int(input()) if n == 0: break s = list(map(float, input().split())) m = sum(s) / n a = (sum((s[i] - m) ** 2 for i in range(n)) / n) ** 0.5 print(a)
0
null
28,838,868,730,180
204
31
l = int(input()) x = l/3 ans = x**3 print(str(ans))
#!/usr/bin/env python3 n = int(input()) n /= 3 print(n**3)
1
47,060,893,263,400
null
191
191
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq n,m = ma() s = input() dp = [-1]*(n+1) #dp[i]:: i番目にたどり着く最小コスト dp[0]=0 r=0 while r<=n-1: l=0 tmp=0 while l+1<=m and r+l+1<=n: l+=1 if s[r+l]=="0": tmp=l dp[r+l]=dp[r]+1 r+=tmp #if r==n:break if tmp==0: print(-1) exit() d = dp[-1] rt = [] dp = dp[::-1] r=0 while r<=n-1: l=0 tmp=0 while l+1<=m and r+l+1<=n: l+=1 if dp[r+l]==d-1: tmp=l rt.append(tmp) d-=1 r+=tmp print(*reversed(rt))
def coin_change(coins, payment): T = [0] + [50001] * payment for c in coins: for i, t in enumerate(zip(T[c:], T), start=c): a, b = t T[i] = min(a, b + 1) return T[payment] n, m = map(int, input().split()) c = list(map(int, input().split())) ans = coin_change(c, n) print(ans)
0
null
69,391,845,425,536
274
28
x = input() print pow(x, 3)
string = input() if string == "ARC": print("ABC") else: print("ARC")
0
null
12,219,393,515,858
35
153
from collections import deque n,m=map(int,input().split()) ab=[list(map(int, input().split())) for _ in range(m)] l=[[] for i in range(n)]#各部屋とつながっている部屋 #print(l,ab) for a,b in ab: l[a-1].append(b) l[b-1].append(a) result=[-1]*n q=deque([1]) #print(l,result) while True: if len(q)==0: break x=q.popleft() for j in l[x-1]: if result[j-1]==-1: result[j-1]=x q.append(j) #print(q,result) print("Yes") [print(i) for i in result[1:]]
from collections import deque def bfs(graph, n, s): visited = [0]*n # 移動回数を保持 visited[s] = 1 # 部屋1の探索は完了としている q = deque([s]) # 探索用にdequeを設定し、初期位置としてs(0)を設定する while q: node = q.popleft() # 先頭から順番に実行 for i in graph[node]: # 各部屋から行ける別の部屋を確認 if not visited[i]: # 値が"0"の場合に処理を実行 visited[i] = node + 1 # 部屋1からの移動回数を保持する q.append(i) # 移動先の部屋をqに格納し、探索を継続する return visited n,m = map(int, input().split()) graph = [[] for _ in range(n)] for _ in range(m): a,b = map(lambda x: int(x)-1, input().split()) graph[a].append(b) graph[b].append(a) visited = bfs(graph, n, 0)[1:] # 幅優先探索を行い、部屋1以外の結果を取得する if all(visited): print("Yes") print(*visited, sep="\n") else: print("No")
1
20,516,371,671,488
null
145
145
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, R = lr() answer = R if N < 10: answer += (10-N) * 100 print(answer)
# coding: utf-8 # Your code here! N=int(input()) count=-1 for i in range(N//2+1): count+=1 if N%2==0: print(count-1) else: print(count)
0
null
107,967,426,235,200
211
283
from statistics import median n=int(input()) A,B=[],[] for _ in range(n): a,b=map(int,input().split()) A.append(a*2) B.append(b*2) ma,mb = int(median(A)),int(median(B)) #print(ma,mb) if n%2 == 0: print(mb-ma+1) else: print((mb-ma)//2+1)
import glob # 問題ごとのディレクトリのトップからの相対パス REL_PATH = 'ABC\\169\\E' # テスト用ファイル置き場のトップ TOP_PATH = 'C:\\AtCoder' class Common: problem = [] index = 0 def __init__(self, rel_path): self.rel_path = rel_path def initialize(self, path): file = open(path) self.problem = file.readlines() self.index = 0 return def input_data(self): try: IS_TEST self.index += 1 return self.problem[self.index - 1] except NameError: return input() def resolve(self): pass def exec_resolve(self): try: IS_TEST for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'): print("Test: " + path) self.initialize(path) self.resolve() print("\n\n") except NameError: self.resolve() class Solver(Common): def resolve(self): N = int(self.input_data()) A = [[0, 0] for i in range(N)] B = [[0, 0] for i in range(N)] for i in range(N): tmp = self.input_data().split() A[i][0] = i A[i][1] = int(tmp[0]) B[i][0] = i B[i][1] = int(tmp[1]) # 最小値群と最大値群を個別に並び替える A_sorted = sorted(A, key=lambda x: x[1]) B_sorted = sorted(B, key=lambda x: x[1]) ''' if N % 2 == 0: for i in range(N): for j in range(N): if A_sorted[j][0] == i: min = A_sorted[j] break for j in range(N): if B_sorted[j][0] == i: max = B_sorted[j] break pass else: pass ''' if N % 2 == 0: median_min = A_sorted[int(N/2)][1] + A_sorted[int(N/2)-1][1] median_max = B_sorted[int(N/2)][1] + B_sorted[int(N/2)-1][1] else: median_min = A_sorted[int(N/2)][1] median_max = B_sorted[int(N/2)][1] result = median_max - median_min + 1 print(str(result)) solver = Solver(REL_PATH) solver.exec_resolve()
1
17,242,870,581,690
null
137
137
n = int(input()) ans = "No" count = 0 for i in range(n): D1,D2 = map(int,input().split()) count=count+1 if D1==D2 else 0 ans="Yes" if count>=3 else ans print(ans)
print(list(map(int,input().split())).index(0) + 1)
0
null
7,970,396,737,952
72
126
n,k=map(int,input().split()) r,s,p=map(int,input().split()) t=input() a=[] for i in range(k): a.append([]) for i in range(n): a[i%k].append(t[i]) for i in range(k): for j in range(len(a[i])): if j>=1: if a[i][j]==a[i][j-1]: a[i][j]=0 ans=0 for i in range(k): for j in range(len(a[i])): if a[i][j]=="r": ans+=p elif a[i][j]=="s": ans+=r elif a[i][j]=="p": ans+=s print(ans)
n,k = map(int, input().split()) r,s,p = map(int, input().split()) t = input() def add(x): if x == 'r': return p elif x == 's': return r else: return s nk =[0]*k for i in range(n): key = i%k if nk[key]==0: nk[key] = [t[i]] else: nk[key].append(t[i]) ans = 0 for j in nk: if j ==0: continue ans += add(j[0]) for k in range(1, len(j)): if j[k]== j[k-1]: j[k]='q' else: ans += add(j[k]) print(ans)
1
107,118,395,282,518
null
251
251
t=input() ans=str() tmp="" for s in t: if s=="P" or s=="D": ans+=s tmp=s else: ans+="D" tmp="D" print(ans)
T = input() N = len(T) after_T = '' for i in range(N): charr=T[i] if(charr=='?'): after_T+='D' else: after_T+=charr print(after_T)
1
18,533,909,625,198
null
140
140
import math f = True N = int(input()) for i in range(N+1): if math.floor(i*1.08) == N: print(i) f = False break if f: print(":(")
N = int(input()) for i in range(1 , N + 1): x = int(i * 1.08) if x == N: print(i) exit() print(':(')
1
126,065,945,856,970
null
265
265
L, R, d = map(int, input().split()) count = 0 if ((L and R and d >=1) and (L and R and d <= 100) ): for L in range(L, R+1): if (L%d == 0): count +=1 print(count)
L, R, d = map(int,input().split()) ans = 0 while L <= R: if L % d == 0: ans += 1 L += 1 print(ans)
1
7,551,541,248,510
null
104
104
import sys n = int(input()) input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()] for i in range(n): input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:] is_visit = [False] * n distance = [0] * n queue = [1] while len(queue) != 0: id = queue.pop(0) is_visit[id-1] = True for node_id in input_line[id-1]: if not is_visit[node_id-1]: distance[node_id-1] = distance[id-1] + 1 queue.append(node_id) is_visit[node_id-1] = True for i in range(n): d = distance[i] if is_visit[i] else -1 print('{0} {1}'.format(i+1, d))
import sys sys.setrecursionlimit(1000000) s=input() #print(s) l=[-1 for _ in range(len(s)+1)] def aa(ix,v): #ixはlベース # print(ix,v,l) if (ix>= len(s) and v==1) or (ix==0 and v==0-1): return if v==1 and s[ix]=="<" and l[ix+1]<=l[ix]: l[ix+1]=l[ix]+1 aa(ix+1,1) elif v==-1 and s[ix-1]==">" and l[ix-1]<=l[ix]: l[ix-1]=l[ix]+1 aa(ix-1,-1) return for i in range(0,len(s)): if i ==0 and s[0]=="<": l[0]=0 aa(i,1) elif i==len(s)-1 and s[-1]==">": l[-1]=0 aa(i+1,-1) elif s[i]==">" and s[i+1]=="<": l[i+1]=0 aa(i+1,1) aa(i+1,-1) print(sum(l))
0
null
78,410,335,029,432
9
285
import sys a=[map(int,i.split()) for i in sys.stdin] [print(len(str(b+c))) for b,c in a]
# -*-coding:utf-8 import fileinput if __name__ == '__main__': for line in fileinput.input(): digit = 0 tokens = list(map(int, line.strip().split())) a, b = tokens[0], tokens[1] num = a + b print(len(str(num)))
1
119,574,838
null
3
3
N, M, K = map(int, input().split()) A=list(map(int, input().split())) B=list(map(int, input().split())) Asum=[0] Bsum=[0] for i, a in enumerate(A): Asum.append(Asum[i]+a) for i, b in enumerate(B): Bsum.append(Bsum[i]+b) ans, b = 0, M for a, asum in enumerate(Asum): if asum > K: break while Bsum[b]>K - asum: b-=1 ans = max(ans, a+b) print(ans)
# ==================================================- # 二分探索 # 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,757,552,060,164
null
117
117
from collections import deque n,x,y = map(int,input().split()) adj = [[] for i in range(n)] adj[x-1].append(y-1) adj[y-1].append(x-1) for i in range(n-1): adj[i].append(i+1) adj[i+1].append(i) ans = [0]*(n-1) for i in range(n): q = deque([]) q.append(i) dist = [-1]*n dist[i] = 0 while len(q) > 0: v = q.popleft() for nv in adj[v]: if dist[nv] != -1: continue dist[nv] = dist[v] + 1 q.append(nv) for i in dist: if i != 0: ans[i-1] += 1 for i in ans: print(i//2)
N,M,X=map(int,input().split()) li=[] ans=100000000000000000000000000000000 for j in range(N): a=list(map(int,input().split())) li.append(a) for k in range(2**N): temp=0 skill=[0]*M k=str(bin(k)) k=k[2:] while len(k)!=N: k="0"+k for l in range(N): if k[l]=="1": temp+=li[l][0] for m in range(1,M+1): skill[m-1]+=li[l][m] if min(skill)>=X: if ans>temp: ans=temp if ans==100000000000000000000000000000000: print(-1) else: print(ans)
0
null
33,280,884,291,428
187
149
n = int(input()) p = [] q = [] r = [] for i in range(2,(int(n**0.5)+1)): N = n if N%i == 0: p.append(i) for i in range(2,(int(n**0.5)+1)): N = n - 1 if N%i == 0: r.append(i) if i != N//i: r.append(N//i) for i in range(len(p)): N = n while N % p[i] == 0: N = N / p[i] if N % p[i] == 1: q.append(p[i]) for i in range(len(r)): if n % r[i] == 1: q.append(r[i]) if n == 2: print(1) else: print(len(q)+2)
def divisors(n): small = [] large = [] i = 1 while i * i <= n: if not n % i: small.append(i) large.append(n // i) i += 1 if small[-1] == large[-1]: large.pop() return small + large[::-1] n = int(input()) res = set(divisors(n - 1)) res.remove(1) for d in divisors(n): if d == 1: continue now = n # simulation while not now % d: now //= d if now % d == 1: res.add(d) print(len(res))
1
41,338,191,252,820
null
183
183
n = int(input()) s = list(input()) alp = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ') for i in range(len(s)): for j in range(26): if s[i] == alp[j]: s[i] = alp[j+n] break print(''.join(s))
import string N = int(input()) S = input() a = string.ascii_uppercase # a = ABCDEFGHIJKLMNOPQRSTUVWXYZ ans = '' for s in S: ans += a[(a.index(s) + N) % len(a)] print(ans)
1
134,476,918,954,500
null
271
271
import math class Circle: def output(self, r): print "%.6f %.6f" % (math.pi * r * r, 2.0 * math.pi * r) if __name__ == "__main__": cir = Circle() r = float(raw_input()) cir.output(r)
x, k, d = map(int, input().split()) x = abs(x) kk = x // d amari = x % d if kk >= k: ans = (kk - k) * d + amari elif (k - kk) % 2 == 1: ans = abs(amari - d) else: ans = amari print(ans)
0
null
2,963,780,874,160
46
92
n = int(input()) arrey = [int(i) for i in input().split()] for i in range(n): v = arrey[i] j = i - 1 while j >= 0 and arrey[j] > v: arrey[j+1] = arrey[j] j = j - 1 arrey[j+1] = v for k in range(n): print(arrey[k]) if k == n-1 else print(str(arrey[k])+' ',end='')
while True: try: a,b = map(int,raw_input().split(' ')) print len(str(a+b)) except: break
0
null
2,633,171,452
10
3
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): s = input() if 'RRR' in s: print(3) elif 'RR' in s: print(2) elif 'R' in s: print(1) else: print(0) if __name__ == '__main__': main()
S = input() ans = 0 cnt = 0 for w in S: if w == 'S': ans = max(ans,cnt) cnt = 0 else: cnt += 1 ans = max(cnt,ans) print(ans)
1
4,869,006,029,120
null
90
90
n = int(input()) buf = list(map(int,input().split())) a = [] for i in range(n): a.append([buf[i],i]) a = sorted(a,reverse=True) dp = [[0]*(n+1) for i in range(n+1)] for i in range(n): for j in range(n-i): cur = i+j temp1 = dp[i][j]+a[cur][0]*abs(n-1-a[cur][1]-j) temp2 = dp[i][j]+a[cur][0]*abs(a[cur][1]-i) dp[i+1][j] = max(dp[i+1][j],temp2) dp[i][j+1] = max(dp[i][j+1],temp1) print(max([max(i) for i in dp]))
import sys def main(): input = sys.stdin.buffer.readline h, n = map(int, input().split()) a = [0] * n b = [0] * n for i in range(n): a[i], b[i] = map(int, input().split()) max_a = max(a) # dp[j]:jダメージ与える魔力の最小値 dp = [1e9] * (h + max_a + 1) dp[0] = 0 for i in range(n): for j in range(1, h + max_a + 1): dp[j] = min(dp[j], dp[max(j - a[i], 0)] + b[i]) print(min(dp[h:])) if __name__ == "__main__": main()
0
null
57,208,919,785,292
171
229
n,d = map(int,input().split()) count = 0 for i in range(n): x,y = map(float,input().split()) if(d*d >= x*x + y*y): count+=1 print(count)
x, k, d = map(int, input().split()) x = abs(x) if x//d >= k: print(x-k*d) else: k -= x//d x -= d*(x//d) if k%2==0: print(abs(x)) else: print(abs(x-d))
0
null
5,582,875,035,584
96
92
H1,M1,H2,M2,K = map(int,input().split()) A1 = H1*60+M1 A2 = H2*60+M2 print(max(0,A2-A1-K))
h1, m1, h2, m2, k = map(int, input().split()) H = h2 - h1 if m1 <= m2: M = m2 - m1 else: M = 60 - m1 + m2 H -= 1 print(H*60 + M - k)
1
17,930,431,613,120
null
139
139
n=int(input()) a=input().split(' ') b=[int(i) for i in a] s=0 for k in range(2,n): for j in range(1,k): for i in range(j): if (b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]): m=max(b[i],b[j],b[k]) if 2*m<b[i]+b[j]+b[k]: s+=1 print(s)
N = int(input()) A = [int(x) for x in input().split()] B = [0]*(N+1) if N == 0: if A[0] != 1: print(-1) exit() else: print(1) exit() if A[0] != 0: print(-1) exit() else: B[0] = 1 C = [0]*(N+1) C[0] = 1 for i in range(1,N+1): C[i] = 2*(C[i-1] - A[i-1]) if C[i] < A[i]: print(-1) exit() #print(C) for i in range(N, 0, -1): if i == N: B[i] = A[i] else: B[i] = min(A[i]+B[i+1], C[i]) print(sum(B))
0
null
12,093,516,452,192
91
141
# coding: utf-8 s = input() print("x" * len(s))
N=input() i=len(N) print('x'*i)
1
73,168,907,299,058
null
221
221
n = int(input()) ans = (n - 1) // 2 print(ans)
s = input() for c in s: if c.islower(): print(c.upper(), end="") else: print(c.lower(), end="") print()
0
null
77,367,139,032,702
283
61
from collections import defaultdict def combination(a, b): if b > a - b: return combination(a, a - b) return fact[a] * ifact[b] * ifact[a-b] MOD = 10**9+7 n, k = map(int, input().split()) k = min(k, n-1) # 階乗を前処理 fact = defaultdict(int) fact[0] = 1 for i in range(1, n+1): fact[i] = fact[i-1] * i fact[i] %= MOD # 階乗の逆元を前処理 ifact = defaultdict(int) ifact[n] = pow(fact[n], MOD-2, MOD) for i in reversed(range(1, n + 1)): ifact[i-1] = ifact[i] * i ifact[i-1] %= MOD ans = 0 for i in range(k+1): ans += combination(n, i) * combination((n-i-1)+i, i) ans %= MOD print(ans % MOD)
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.readline #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) import math #from itertools import combinations def run(): n,k = map(int, input().split()) mod = 10 ** 9 + 7 ret = 0 inv = generate_inv(n, mod) if k >= n-1: k = n-1 left = 1 right = 1 ret = 1 for h in range(1, k+1): right *= (n - h) * inv[h] right %= mod left *= (n - h + 1) * inv[h] left %= mod ret += right * left ret %= mod print(ret) def generate_inv(n,mod): """ 逆元行列 n >= 2 """ ret = [0, 1] for i in range(2,n+1): next = -ret[mod%i] * (mod // i) next %= mod ret.append(next) return ret def comb_mod(n, a, mod): """ return: [n, a] % mod Note: mod must be a prime number """ up = 1 down = 1 for i in range(a): up *= n - i up %= mod down *= i + 1 down %= mod down = pow_mod(down, mod - 2, mod) return (up * down) % mod def pow_mod(n, k, mod): res = 1 while True: if k // 2 >= 1: if k % 2 == 1: res = (res * n) % mod n = (n ** 2) % mod k = k // 2 else: break return (n * res) % mod if __name__ == "__main__": run()
1
66,937,491,705,020
null
215
215
while True: h, w = map(int, input().split()) if h == w == 0: break print(('#' * w + '\n') * h)
while True: H,W = map(int, raw_input().split(" ")) if H == 0 and W == 0: break else: for h in xrange(H): print "#" * W print ""
1
782,049,557,250
null
49
49
import sys input = sys.stdin.readline def inps(): return str(input()) s = inps().rsplit()[0] t = inps().rsplit()[0] cnt = 0 for i in range(len(s)): if s[i]!=t[i]: cnt+=1 print(cnt)
S = input() T = input() if len(S) != len(T): quit() sum = 0 for i in range(len(S)): if T[i] != S[i]: sum = sum + 1 print(sum)
1
10,485,272,831,288
null
116
116
k = int(input()) a,b = [int(x) for x in input().split()] ans = "NG" for i in range(1000): if a <= i * k and i * k <= b: ans = "OK" break print(ans)
a = [i for i in range(1,10)] for b in a: for c in a: print('{}x{}={}'.format(b,c,b*c))
0
null
13,291,842,682,568
158
1
d = input() d = int(d) if d==0: print('1') if d==1: print('0')
i = int(input()) print(i^1)
1
2,890,011,217,512
null
76
76
""" i - j = A[i] + A[j] > i - A[i] = j + A[j] i > j """ from collections import defaultdict N = int(input()) high = list(map(int, input().split())) ans = 0 calc = defaultdict(int) for i in range(1, N+1): ans += calc[i - high[i-1]] calc[i + high[i-1]] += 1 print(ans)
import os import sys import numpy as np def solve(N, K, S, P, R, T): dp = np.zeros((N+1, 3), dtype=np.int64) for i in range(1, N+1): c = T[i] dp[i, 0] = max(dp[i-K, 1], dp[i-K, 2]) + (c == "r") * R dp[i, 1] = max(dp[i-K, 0], dp[i-K, 2]) + (c == "s") * S dp[i, 2] = max(dp[i-K, 0], dp[i-K, 1]) + (c == "p") * P #d = dp.max(1) d = np.zeros(N+1, dtype=np.int64) for i in range(N+1): d[i] = dp[i].max() ans = d[-K:].sum() return ans # >>> numba compile >>> numba_config = [ [solve, "i8(i8,i8,i8,i8,i8,string)"], ] if sys.argv[-1] == "ONLINE_JUDGE": from numba import njit from numba.pycc import CC cc = CC("my_module") for func, signature in numba_config: vars()[func.__name__] = njit(signature)(func) cc.export(func.__name__, signature)(func) cc.compile() exit() elif os.name == "posix": exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}") else: from numba import njit for func, signature in numba_config: vars()[func.__name__] = njit(signature, cache=True)(func) print("compiled!", file=sys.stderr) # <<< numba compile <<< def main(): N, K = map(int, input().split()) S, P, R = map(int, input().split()) T = "_" + input() ans = solve(N, K, S, P, R, T) print(ans) main()
0
null
66,425,015,455,360
157
251
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prl = lambda x: print(*x ,sep='\n') s,w = nm() print('unsafe' if s <= w else 'safe')
import itertools import math s, w = map(int, input().split()) if s <= w: print("unsafe") else: print("safe")
1
28,996,458,127,872
null
163
163
input() d=[abs(s-t)for s,t in zip(*[list(map(int,input().split()))for _ in'12'])] f=lambda n:sum(s**n for s in d)**(1/n) print(f(1),f(2),f(3),max(d),sep='\n')
a = input() a = a.replace('?', 'D') print(a)
0
null
9,276,929,113,120
32
140
def F(x, y): if x % y == 0: return y return F(y, x % y) while True: try: x, y = map(int,input().split()) print('{0} {1}'.format(F(x, y), int(x * y / F(x, y)))) except EOFError: break
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) n, r = inm() print(r if n >= 10 else r + 100 * (10 - n))
0
null
31,936,885,339,072
5
211
nq = str(input()).split() n = int(nq[0]) q = int(nq[1]) p = [str(input()).split() for i in range(n)] p = [(str(i[0]), int(i[1])) for i in p] ans = [] time = 0 while len(p) != 0: t = p.pop(0) if t[1] > q: #p = [(s[0], s[1], s[2]+q) for s in p] time += q p.append((t[0], t[1]-q)) elif t[1] <= q: #p = [(s[0], s[1], s[2]+t[1]) for s in p] ans.append((t[0], t[1]+time)) time += t[1] for t in ans: print('{0} {1}'.format(t[0], t[1]))
h, a = map(int, input().split()) b = 0 while h-a > 0: h = h - a b += 1 print(b + 1)
0
null
38,740,072,145,852
19
225
from copy import deepcopy from sys import stdin input = stdin.readline H,W,K = map(int, input().split()) mat = [list(input()) for _ in range(H)] ans = 0 for b_i in range(2**H): mat_1 = deepcopy(mat) for i in range(H): if b_i >> i & 1: for col in range(W): mat_1[i][col] = '.' for b_j in range(2**W): mat_2 = deepcopy(mat_1) for j in range(W): if b_j >> j & 1: for row in range(H): mat_2[row][j] = '.' cnt = 0 for row in mat_2: cnt += row.count('#') if cnt == K: ans += 1 print(ans)
h, w, k = map(int, input().split()) c = [] for _ in range(h): c.append([c for c in input()]) ans = 0 for i in range(1 << h): for j in range(1 << w): cnt = 0 for n in range(h): for m in range(w): if i >> n & 1: continue if j >> m & 1: continue if c[n][m] == '#': cnt += 1 if cnt == k: ans += 1 print(ans)
1
8,990,906,921,536
null
110
110
n = int(input()) a = list(map(int,input().split())) b = [0]*n for i in range(n): b[i] = a[i] + b[i-1] ans = b[-1] for j in range(n): ans = min(ans,abs(b[-1]-b[j]*2)) print(ans)
N = int(input()) A = list(map(int, input().split())) B = [] R = 0 L = sum(A) for i in range(N): B.append(abs(L-R)) R += A[i] L -= A[i] print(min(B))
1
142,198,889,878,820
null
276
276
X = int(input()) num = X//100 amari = X%100 if num*5 >= amari: print(1) else: print(0)
n = input() x = int(n) for i in range(3,x+1) : if i%3 == 0 or '3' in str(i) : print('',i,end='') print()
0
null
63,737,829,368,972
266
52
import math X = int(input()) ans = 0 while ans == 0: factor = 0 if X % 2 == 0 and X != 2: X +=1 continue for divisor in range(2, X // 2): if X % divisor == 0: factor += 1 if factor == 0: ans =X X +=1 print(ans)
a = int(input()) import math def is_prime(x): if x < 2: return False # 2未満に素数はない if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数 if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数 # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく prime = 7 step = 4 while prime <= math.sqrt(x): if x % prime == 0: return False prime += step step = 6 - step return True while True: if is_prime(a): print(a) break else: a+=1
1
105,802,666,359,518
null
250
250
class Stack(object): def __init__(self, _max): if type(_max) == int: self._array = [None for i in range(0, _max)] self._next = 0 def push(self, value): if self.isFull(): raise IndexError self._array[self._next] = value self._next += 1 def pop(self): if self.isEmpty(): raise IndexError self._next -= 1 value = self._array[self._next] self._array[self._next] = None return value def isEmpty(self): return self._next <= 0 def isFull(self): return self._next >= len(self._array) def calculator(exp): stack = Stack(100) ope = ["+", "-", "*"] for item in exp: if item in ope: val1 = stack.pop() val2 = stack.pop() if item == "+": stack.push(val2 + val1) elif item == "-": stack.push(val2 - val1) elif item == "*": stack.push(val2 * val1) else: raise ValueError else: stack.push(int(item)) return stack.pop() if __name__ == "__main__": exp = input().split() print(calculator(exp))
ops = [op for op in input().split(" ")] stack = [] for op in ops: if op == "+": stack = stack[:-2]+[stack[-2]+stack[-1]] elif op == "-": stack = stack[:-2]+[stack[-2]-stack[-1]] elif op == "*": stack = stack[:-2]+[stack[-2]*stack[-1]] else: stack.append(int(op)) print(stack[0])
1
36,665,750,688
null
18
18
k, n = map(int, input().split()) a = list(map(int, input().split())) a.append(a[0] + k) dist = [a[i + 1] - a[i] for i in range(n)] print(sum(dist) - max(dist))
# -*- coding:utf-8 -*- import sys class Hash(object): def __init__(self, size): self._array = [None] * size self._size = size def _hash(self, key): return key % self._size def insert(self, key, value): j = self._hash(key) if self._array[j] is None: self._array[j] = [value] else: self._array[j].append(value) def find(self, key, value): j = self._hash(key) if self._array[j] is None: return False elif value in self._array[j]: return True else: return False def stoi(s): ret = 0 p = 1 ctoi = {"A": 1, "C": 2, "G": 3, "T": 4} for c in s: ret += ctoi[c] * p p *= 7 return ret def dictionary(lst): h = Hash(1046527) ret = [] for val in lst: if val[0] == "insert": h.insert(stoi(val[1]), val[1]) elif val[0] == "find": if h.find(stoi(val[1]), val[1]): ret.append("yes") else: ret.append("no") else: raise ValueError return ret if __name__ == "__main__": lst = [val.split() for val in sys.stdin.read().splitlines()] n = int(lst.pop(0)[0]) print("\n".join(dictionary(lst)))
0
null
21,612,194,881,148
186
23
a, b, c = map(int,raw_input().split()) count = 0 for x in xrange(a,b+1): if c%x == 0: count+=1 print count
from sys import stdin, stdout import math,sys,heapq from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict from os import path import bisect as bi def yes():print('YES') def no():print('NO') if (path.exists('input.txt')): #------------------Sublime--------------------------------------# sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w'); def I():return (int(input())) def In():return(map(int,input().split())) else: #------------------PYPY FAst I/o--------------------------------# def I():return (int(stdin.readline())) def In():return(map(int,stdin.readline().split())) def dict(a): d={} for x in a: if d.get(x,-1)!=-1: d[x]+=1 else: d[x]=1 return d def find_gt(a, x): 'Find leftmost value greater than x' i = bi.bisect_right(a, x) if i != len(a): return i else: return -1 def main(): try: n,k=In() l=list(In()) ans=[] t=1 last=1 for x in range(k,n): if l[x-k]>=l[x]: print('No') else: print('Yes') except: pass M = 998244353 P = 1000000007 if __name__ == '__main__': #for _ in range(I()):main() for _ in range(1):main()
0
null
3,844,530,269,980
44
102
S = ['0'] + list(input()) + ['0'] N = len(S) flag = False ans = 0 for i in range(N - 1, 0, -1): j = int(S[i]) if flag: j += 1 S[i] = j if j <= 5: if j == 5 and int(S[i - 1]) >= 5: ans += j flag = True else: ans += j flag = False else: ans += 10 - j flag = True if flag: ans += 1 # print (ans) count = 0 for s in S: if s == 5: count += 1 else: ans -= max(0, count - 2) count = 0 print (ans)
import copy n, k = map(int,input().split()) a = [0] + list(map(int,input().split())) dist = [-1] * (n+1) dist[1] = 0 cn = 1 d = 0 cycle = 0 while True: d += 1 nn = a[cn] if d == k: ans = nn break if dist[nn] == -1: dist[nn] = copy.deepcopy(d) elif cycle == 0: cycle = d - dist[nn] k = (k - d) % cycle + d if d == k: ans = nn break cn = nn print(ans)
0
null
46,702,725,329,810
219
150
for i in range(0,9): for j in range(0,9): print("{0}x{1}={2}".format(i+1,j+1,(i+1)*(j+1)))
for i in range(9): i=i+1 for j in range(9): j=j+1 print(str(i)+'x'+str(j)+'='+str(i*j))
1
2,685,980
null
1
1
#10_B import math a,b,C=map(int,input().split()) S=a*b*math.sin((C*2*math.pi)/360)/2 c=math.sqrt(a**2+b**2-2*a*b*math.cos((C*2*math.pi)/360)) L=a+b+c h=2*float(S)/a print(str(S)+'\n'+str(L)+'\n'+str(h)+'\n')
n = int(input()) a = sorted(list(map(int, input().split()))) ans = 1 for i in a: ans *= i if ans > 10**18: print("-1") break else: print(ans)
0
null
8,174,661,945,120
30
134
import bisect n,m=map(int,input().split()) A=list(map(int,input().split())) A.sort() ng=-1 ok=A[-1]*2+1 B=[[0]*n for k in range(2)] ii=0 while ok-ng>1: mid=(ok+ng)//2 d=0 for i in range(n): c=n-bisect.bisect_right(A,mid-A[i],lo=0,hi=len(A)) B[ii][i]=c d=d+c if d<m: ok=mid ii=(ii+1)%2 else: ng=mid D=[0] for i in range(n): D.append(D[-1]+A[n-i-1]) ans=0 for i in range(n): x=B[(ii+1)%2][i] ans=ans+A[i]*x+D[x] ans=ans+(m-sum(B[(ii+1)%2]))*ok print(ans)
def solve(): S = input() if S[2] == S[3] and S[4] == S[5]: print("Yes") else: print("No") if __name__ == "__main__": solve()
0
null
75,009,036,842,432
252
184
N=int(input()) K=set(input().split()) i=len(K) if i==N: print('YES') else: print('NO')
def main(): n = int(input()) a = set(map(int, input().split(" "))) print("YES" if len(a) == n else "NO") main()
1
73,586,269,796,960
null
222
222
n = int(input()) S = input() ans = 0 def ok(i): pin = '{:0=3}'.format(i) j = 0 for s in S: if s == pin[j]: j += 1 if j == 3: return True else: return False for i in range(1000): ans += ok(i) print(ans)
n = int(input()) s = input() cnt = 0 for i in range(1000): c = [i // 100, (i // 10) % 10, i % 10] f = 0 for j in range(n): if s[j] == str(c[f]): f+=1 if f == 3: break if f == 3: cnt += 1 print(cnt)
1
128,842,273,368,300
null
267
267
import math n = input() for i in range(n): flag = 0 a = map(int, raw_input().split()) if(pow(a[0],2)+pow(a[1],2) == pow(a[2],2)): flag = 1 if(pow(a[1],2)+pow(a[2],2) == pow(a[0],2)): flag = 1 if(pow(a[2],2)+pow(a[0],2) == pow(a[1],2)): flag = 1 if flag == 1: print "YES" else: print "NO"
def pascal(xdata): for x in xrange(3): for y in xrange(3): for z in xrange(3): if xdata[x]**2 + xdata[y]**2 == xdata[z]**2: return True return False N = input() data = [map(int, raw_input().split()) for x in range(N)] for x in data: if pascal(x): print "YES" else: print "NO"
1
272,485,792
null
4
4
a,b = map(int,input().split()) astart, aend = int(a//0.08+1), int((a+1)//0.08) #[astart, aend) bstart, bend = int(b//0.10+1), int((b+1)//0.10) alst = set(range(astart,aend)) blst = set(range(bstart,bend)) share = alst & blst if len(share) == 0: print(-1) else: print(list(share)[0])
a,b=map(int,input().split()) c=max(int(100*a/8),10*b) d=min(int(100*a/8+100/8),10*b+10) f=0 for x in range(c,d+1): if f==0 and int(x*0.08)==a and int(x*0.1)==b: f=1 print(x) if f==0: print(-1)
1
56,600,562,094,560
null
203
203
import math from functools import reduce n,m = map(int, input().split()) A = list(map(int, input().split())) def lcm_base(x,y): return x*y//math.gcd(x,y) def lcm(target_list): return reduce(lcm_base, target_list) A_gcd = reduce(math.gcd, A) flg = True for a in A: if a//A_gcd%2==0: flg = False break if flg: min_x = int(lcm(A))//2 ans = m//min_x - m//(2*min_x) print(ans) else: print(0)
N=int(input()) print(int((N-1-(N+1)%2)/2))
0
null
127,330,218,657,852
247
283
L = int(input()) L = L/3 V=1 for i in range (3): V*=L print (V)
N = int(input()) dp = [[0]*10 for _ in range(10)] for a in range(N+1): A = str(a) dp[int(A[0])][int(A[-1])] += 1 ans = 0 for i in range(1,10): for j in range(1,10): ans += dp[i][j]*dp[j][i] print(ans)
0
null
66,811,987,096,102
191
234
N = int(input()) print(N + N**2 + N**3)
# -*- coding:utf-8 -*- import math def insertion_sort(num_list, length, interval): cnt = 0 for i in range(interval, length): v = num_list[i] j = i - interval while j >= 0 and num_list[j] > v: num_list[j+interval] = num_list[j] j = j - interval cnt = cnt + 1 num_list[j+interval] = v return cnt def shell_sort(num_list, length): cnt = 0 h = 4 intervals = [1,] while length > h: intervals.append(h) h = 3 * h + 1 for i in reversed(range(len(intervals))): cnt = cnt + insertion_sort(num_list, length, intervals[i]) print(len(intervals)) print(*reversed(intervals)) print(cnt) input_num = int(input()) input_list = list() for i in range(input_num): input_list.append(int(input())) shell_sort(input_list, input_num) for num in input_list: print(num)
0
null
5,143,793,159,558
115
17
D = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(D)] out = [int(input()) for _ in range(D)] sat = 0 last = [0] * 26 for d in range(D): assert(1 <= out[d] and out[d] <= 26) j = out[d] - 1 last[j] = d + 1 for i in range(26): sat -= (d + 1 - last[i]) * c[i] sat += s[d][j] print(sat)
S = input() S_len = len(S) print("x" * S_len)
0
null
41,392,258,537,630
114
221
N = [0] + list(map(int, list(input()))) L = len(N) ans = 0 for i in range(L-1, -1, -1): if N[i] == 10: if i == 0: ans += 1 else: N[i-1] += 1 N[i] = 0 if N[i] < 5: ans += N[i] elif N[i] > 5: ans += 10 - N[i] N[i-1] += 1 else: if i == 0: ans += N[i] else: if N[i-1] >= 5: N[i-1] += 1 ans += 5 else: ans += N[i] print(ans)
r_input = input().split() r = int(r_input[0]) print(r*r)
0
null
108,105,321,719,440
219
278
import math from numba import jit k=int(input()) @jit def f(): ans=0 for a in range(1,k+1): for b in range(1,k+1): for c in range(1,k+1): g=math.gcd(math.gcd(a,b),c) ans+=g return ans print(f())
def main(): N = int(input()) A = ( 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692) print(A[N - 1]) if __name__ == '__main__': main()
1
35,373,735,569,710
null
174
174
n = int(input()) d = list(map(int,input().split())) m = max(d) if(d[0] != 0 or m >= n): print(0) else: s = [0] * (m+1) for i in d:s[i] += 1 if(0 in s or s[0] != 1): print(0) else: t = 1 for i in range(1,m+1): t *= s[i-1]**s[i] t %= 998244353 print(t)
s = input() if 'A' in s and 'B' in s: print('Yes') else: print('No')
0
null
105,002,047,286,212
284
201
A,B,C = input().split() print(C,A,B)
A,B,C=map(int,input().split()) R=A A=B B=R R=A A=C C=R print(A,B,C)
1
37,906,214,318,080
null
178
178
def main(): S = input() print(S.swapcase()) main()
import math def main(): n = int(input()) A = list(map(int, input().split())) max_node = [0 for i in range(n+1)] min_node = [0 for i in range(n+1)] res = 0 for i in range(n, -1, -1): if i == n: max_node[i] = A[i] min_node[i] = A[i] elif i == 0: max_node[i] = 1 min_node[i] = 1 elif i == 1 and n != 1: max_node[i] = 2 min_node[i] = math.ceil(min_node[i+1] /2) + A[i] else: max_node[i] = max_node[i+1] + A[i] min_node[i] = math.ceil(min_node[i+1] / 2) + A[i] for i in range(n): if i == 0: if n != 0 and A[i] != 0: res = -1 break else: if max_node[i] > 2 * (max_node[i-1] - A[i-1]): max_node[i] = 2 * (max_node[i-1] - A[i-1]) if max_node[i] < min_node[i]: res = -1 break if res == -1: print(res) else: if n == 0 and A[i] != 1: print(-1) else: print(sum(max_node)) if __name__ == '__main__': main()
0
null
10,113,678,166,800
61
141
n = int(input()) ans = 0 flag = 0 for i in range(0, n): x, y = input().split() if x == y: ans = ans + 1 else: ans = 0 if ans >= 3: flag = 1 if flag == 1: print("Yes") else : print("No")
N, P = map(int, input().split()) S = input() ans = 0 if P == 2 or P == 5 : for i in range(N) : if int(S[i])%P == 0 : ans += i+1 print(ans) exit() modP = [0 for _ in range(P)] modP[0] = 1 now = 0 t = 1 for i in range(N) : now += int(S[-1-i]) * t now %= P modP[now] += 1 t = t * 10 % P for r in modP : ans += r*(r-1)//2 print(ans)
0
null
30,395,630,146,112
72
205
n=int(input()) a=list(map(int,input().split())) dp=[0]*(n+1) for i in range(n-1): dp[a[i]]+=1 for i in range(n): print(dp[i+1])
def resolve(): N = int(input()) array = [0 for i in range(N)] buka = [int(i) for i in input().split()] for num in buka: array[num - 1] += 1 for i in array: print(i) resolve()
1
32,279,224,984,282
null
169
169
input() A = [int(i) for i in input().split()] c = 0 def bubble_sort(A): global c flag = True while flag: flag = False for i in range(len(A)-1, 0, -1): if A[i] < A[i -1]: A[i], A[i -1] = A[i -1], A[i] c += 1 flag = True bubble_sort(A) print(*A) print(c)
def bubble_sort(alist): """Sort alist by bubble sort. Returns (number of swap operations, sorted list) >>> bubble_sort([5, 3, 2, 4, 1]) ([1, 2, 3, 4, 5], 8) """ size = len(alist) count = 0 for i in range(size-1): for j in reversed(range(i+1, size)): if alist[j] < alist[j-1]: count += 1 alist[j-1], alist[j] = alist[j], alist[j-1] return (alist, count) def run(): _ = int(input()) # flake8: noqa nums = [int(i) for i in input().split()] (sorted_list, num_swap) = bubble_sort(nums) print(" ".join([str(i) for i in sorted_list])) print(num_swap) if __name__ == '__main__': run()
1
16,633,901,668
null
14
14
a, b = map(int, input().split(" ")) print(int(a*b))
N = int(input()) A = [int(i) for i in input().split()] print(sum(a % 2 for a in A[::2]))
0
null
11,812,807,262,880
133
105
import sys import itertools class UnionFindTree: def __init__(self, n: int) -> None: self.par = list(range(n)) self.rank = [0] * n def find(self, x: int) -> int: if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x: int, y: int) -> None: x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def resolve(in_): N, M = map(int, next(in_).split()) tree = UnionFindTree(N + 1) AB = (map(int, line.split()) for line in itertools.islice(in_, M)) for a, b in AB: tree.unite(a, b) ans = len(frozenset(tree.find(x) for x in range(1, N + 1))) - 1 return ans def main(): ans = resolve(sys.stdin.buffer) print(ans) if __name__ == '__main__': main()
def main(): n, k = map(int, input().split()) results = tuple(map(int, input().split())) for i in range(n-k): print('Yes' if results[i] < results[i+k] else 'No') if __name__ == '__main__': main()
0
null
4,640,135,850,350
70
102
from collections import deque h, w = map(int, input().split()) S = [list(input()) for _ in range(h)] DP = [[10000]*w for _ in range(h)] DP[0][0] = 0 if S[0][0]=='.' else 1 directs = [[0,1], [1,0]] for hi in range(h): for wi in range(w): for dh,dw in directs: if not (0<=hi+dh<h and 0<=wi+dw<w): continue if S[hi][wi]=='.' and S[hi+dh][wi+dw]=='#': DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi]+1) else: DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi]) print(DP[-1][-1])
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) def is_ok(arg): count = 0 for i in range(n): if a[i] % arg != 0: count += a[i] // arg else: count += a[i] // arg - 1 return count <= k def meguru_bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok n, k = MAP() a = LIST() if k == 0: print(max(a)) else: print(meguru_bisect(0, max(a)+1))
0
null
27,775,124,141,700
194
99
X = int(input()) cnt = 1 deg = X while deg%360!=0: deg += X cnt += 1 print(cnt)
def gcd(a,b): a,b=max(a,b),min(a,b) return a if b==0 else gcd(b,a%b) x=int(input()) g=gcd(360,x) print(360//g)
1
13,089,169,006,890
null
125
125
S = input() T = input() S = list(S) T = list(T) result = len(T) x = 0 for i in range(len(S)-len(T)+1): for j in range(len(T)): if S[i+j] != T[j]: x += 1 if result > x: result = x x = 0 print(result)
n = int(input()) a = {} for i in range(n): x,m = input().split() if x[0] =='i':a[m] = 0 else: if m in a: print('yes') else: print('no')
0
null
1,893,379,541,782
82
23
A,B,C=map(int,input().split()) if C-A-B>0 and (C-A-B)**2>4*A*B: print('Yes') else: print('No')
a, b, c = map(int, input().split()) print("No" if c-a-b < 0 or 4*a*b >= (c-a-b)**2 else "Yes")
1
51,561,814,689,212
null
197
197
tes = input() for mak in range(int(input())) : ins = input().split() ins[1], ins[2] = int(ins[1]), int(ins[2]) if ins[0] == 'replace' : tes = tes[ : (ins[1])] + ins[3] + tes[(ins[2] + 1) :] elif ins[0] == 'reverse' : tem = tes[ins[1] : ins[2] + 1] tem = tem[::-1] tes = tes.replace(tes[ins[1] : ins[2] + 1], tem) elif ins[0] == 'print' : print(tes[ins[1] : ins[2] + 1])
a = [list(map(int, input().split())) for _ in range(3)] n = int(input()) for _ in range(n): d = int(input()) for i in range(3): if d in a[i]: a[i][a[i].index(d)] = -1 for i in range(3): if sum(a[i])==-3: print('Yes') exit() s = 0 for j in range(3): s += a[j][i] if s==-3: print('Yes') exit() if a[0][0]+a[1][1]+a[2][2]==-3: print('Yes') exit() if a[0][2]+a[1][1]+a[2][0]==-3: print('Yes') exit() print('No')
0
null
30,819,499,253,282
68
207
while True: h=[] S=input() if S=="-": break m=int(input()) for i in range(m): h=int(input()) if len(S)==h: pass else: S=S[h:]+S[:h] print(S)
while True: s = input() if s == "-": exit() m = int(input()) for i in range(m): h = int(input()) s = s[h:] + s[:h] print(s)
1
1,912,529,115,552
null
66
66
n = int(input()) a = list(map(int, input().split())) ans = 10 ** 16 a_1 = 0 a_2 = sum(a) for i in range(n - 1): a_1 += a[i] a_2 -= a[i] ans = min(ans, abs(a_1 - a_2)) print(ans)
#93 B - Iron Bar Cutting WA (hint) N = int(input()) A = list(map(int,input().split())) # 差が最小の切れ目を見つける length = sum(A) left = 0 dist = 0 mdist = length midx = 0 for i,a in enumerate(A): left += a right = length - left dist = abs(left - right) if dist < mdist: mdist = dist midx = i ans = mdist print(ans)
1
142,080,516,691,024
null
276
276
n,d=list(map(int,input().split())) s=list(map(int,input().split())) s=sorted(s) s.reverse() if d>=n: print(0) else: c=0 s=s[d:n] for i in s: c+=int(i) print(c)
import sys import math def resolve(in_): a, b, n = map(int, next(in_).split()) x = min(b - 1, n) return math.floor(a * x / b) - a * math.floor(x / b) def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
0
null
53,464,328,128,768
227
161
N = int(input()) N_str = str(N) a = 0 for i in range(len(N_str)): a += int(N_str[i]) if a % 9 == 0: print("Yes") else: print("No")
n = list(input()) ans = 0 for i in n: ans += int(i) ans = ans%9 print('Yes' if ans == 0 else 'No')
1
4,369,222,520,222
null
87
87
# -*- coding: utf-8 -*- n = int(raw_input()) num = map(int, raw_input().split()) for e in num[::-1]: if e == num[0]: print e break print e,
a,b,c,d=map(int,input().split()) an=a*c an=max(an,a*d) an=max(an,b*c) an=max(an,b*d) print(an)
0
null
2,006,004,696,290
53
77
N = int(input()) jage = "No" for l in range(1, 10): for r in range(1,10): if N == r * l: jage = "Yes" print(jage)
## coding: UTF-8 #N, M, K = 9, 3, 4 N, M, K = map(int,input().split()) p = 998244353 # 返り値: a と b の最大公約数 # 返り値: ax + by = gcd(a, b) を満たす (x, y) が格納される def aug_gcd(a, b): lq = [] while b > 0: q = int(a/b) r = a % b a = b b = r lq.append(q) x = 1 y = 0 for i in range(len(lq)): tmp = x x = y y = tmp - lq[(-1)*(i+1)] * y return a, x, y #拡張ユークリッドの互除法による逆元計算 #拡張ユークリッドの方が二分累乗法より高速/mが素数でなくとも良い def modinv(a, p): inv = aug_gcd(a, p)[1] #ax == 1(mod p) <==> ax + py == 0, xの値が逆元 if(inv < 0): inv += p #pがマイナスだったらプラスに書き換える return inv #[NC0, NC1, NC2, NC3, ..., NCN % p] def N_Combination_k(N, p): #NCkのリストを作ります l = [1] res = 1 for i in range(1, N+1): res *= (N+1-i) res %= p res *= modinv(i, p) res %= p l.append(res) return l combination_N_1 = N_Combination_k(N-1, p) #print(combination_N_1) Cumulative = [0] #累積和 s = 0 tod = 1 #(M-1) ** (N-1-i) for i in range(N): s += M * tod * combination_N_1[(-1)*(i+1)] s %= p tod *= (M-1) tod %= p Cumulative.append(s) #print(s) #print(Cumulative) ans = Cumulative[-1] - Cumulative[(-1)*(K+2)] if(ans < 0): ans += p print(ans)
0
null
91,440,676,915,108
287
151
import random class Dise: def __init__(self,top,flont,right,left,back,bottom): self.top,self.flont,self.right,self.left,self.back,self.bottom=top,flont,right,left,back,bottom def rot(self,d): if d=='N': self.top,self.flont,self.bottom,self.back=self.flont,self.bottom,self.back,self.top elif d=='E': self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom elif d=='S': self.top,self.flont,self.bottom,self.back=self.back,self.top,self.flont,self.bottom elif d=='W': self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top def gettop(self): return self.top def getfront(self): return self.flont def getright(self): return self.right n=list(map(int,input().split())) m=int(input()) dise=Dise(n[0],n[1],n[2],n[3],n[4],n[5]) for i in range(m): a,b=(int(x) for x in input().split()) for j in range(1000): dise.rot(random.choice('NESW')) if a==dise.gettop() and b==dise.getfront(): print(dise.getright()) break
import numpy as np N, S = [int(_) for _ in input().split()] A = [int(_) for _ in input().split()] dp = np.array([0] * (3001), dtype=int) dp[0] = 2 dp[A[0]] = 1 mod = 998244353 for a in A[1:]: dpn = np.zeros(3001, dtype=int) dpn[a:] = dp[:-a] dpn += dp * 2 dpn %= mod dp = dpn print(dp[S])
0
null
8,937,108,639,860
34
138
import sys input = sys.stdin.readline def main(): N, X, T = map(int, input().split()) ans = (N+X-1)//X * T print(ans) if __name__ == '__main__': main()
word = input() q = int(input()) for _ in range(q): s = input().split(" ") command = s[0] a = int(s[1]) b = int(s[2]) if command == "print": print(word[a:b+1]) elif command == "reverse": word = word[:a] + word[a:b+1][::-1] + word[b+1:] elif command == "replace": word = word[:a] + s[3] + word[b+1:]
0
null
3,166,871,520,438
86
68
import math def main(n: int, x: int, t: int): print(math.ceil(n / x) * t) if __name__ == '__main__': n, x, t = map(int, input().split()) main(n, x, t)
N,X,T = map(int,input().split()) a = N % X if a == 0: ans = (N//X)*T else: ans = ((N//X)+1)*T print(ans)
1
4,289,394,786,560
null
86
86
import math def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def solve(): N, K = read_ints() P = [p-1 for p in read_ints()] C = read_ints() max_score = -math.inf for i in range(N): cycle_score = C[i] scores = [0, C[i]] j = P[i] k = K while k > 1 and i != j: cycle_score += C[j] scores.append(cycle_score) j = P[j] k -= 1 cycle_size = len(scores)-1 cycle_count = K//cycle_size max_score = max(max_score, max(scores[1:])) if cycle_count != 0: max_score = max(max_score, cycle_score*cycle_count+max(scores[:K%cycle_size+1]), cycle_score*(cycle_count-1)+max(scores[1:])) return max_score if __name__ == '__main__': print(solve())
class BinaryIndexTree: # 1-indexed def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def Alp(s): return ord(s)-ord("a") if __name__ == "__main__": N = int(input()) S = list(input()) Q = int(input()) bit = [BinaryIndexTree(N) for _ in range(26)] for i, s in enumerate(S, start=1): bit[Alp(s)].add(i, 1) ans = [] for _ in range(Q): q = input().split() if q[0] == "1": i = int(q[1]) - 1 c = q[2] bit[Alp(c)].add(i+1, 1) bit[Alp(S[i])].add(i+1, -1) S[i] = c else: l = int(q[1]) r = int(q[2]) tmp = 0 for i in range(26): b = bit[i] if b.sum(r) - b.sum(l - 1) > 0: tmp += 1 ans.append(tmp) print(*ans, sep="\n")
0
null
34,115,133,602,470
93
210
n, x, t = map(int, input().split()) ans = t*(n//x) if n % x != 0: ans += t print(ans)
N, X, T = map(int, input().split()) A = N // X B = N % X if B == 0: print(A * T) else: print((A+1)*T)
1
4,218,950,295,450
null
86
86

No dataset card yet

New: Create and edit this dataset card directly on the website!

Contribute a Dataset Card
Downloads last month
0
Add dataset card