code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
a, b = input().split() a = int(a) b = int(b.replace('.', '')) ans = a * b // 100 print(ans)
ini = lambda : int(input()) inm = lambda : map(int,input().split()) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y a,b = input().split() b = b[:-3] + b[-2:] ans = int(a) * int(b) ans = ans // 100 print(ans)
1
16,547,376,002,512
null
135
135
def main(): x = list(map(int, input().split(" "))) for i in range(5): if x[i] == 0: print(i +1) if __name__ == "__main__": main()
def solution(): user_input = input() user_input = user_input.split() for i in range(len(user_input)): if user_input[i] == '0': print(i+1) solution()
1
13,412,054,724,520
null
126
126
a,b = list(map(int, input().split())) if a > b: sep = '>' elif a < b: sep = '<' else: sep = '==' print('a', sep, 'b')
S = input() ss = S[::-1] if ss[0]=='s': S += 'es' else: S += 's' print(S)
0
null
1,356,750,712,800
38
71
#coding:UTF-8 n = map(int,raw_input().split()) n.sort() print n[0],n[1],n[2]
list=sorted([int(x) for x in input().split()]) print(str(list[0])+" "+str(list[1])+" "+str(list[2]))
1
420,549,324,440
null
40
40
N,M = map(int,input().split()) print(("No","Yes")[N == M])
from sys import stdin def readline_from_stdin() -> str: return stdin.readline().rstrip if __name__ == '__main__': N, K, = input().split() A = [int(i) for i in input().split()] N, K = int(N), int(K) for i in range(N-K): if A[i] < A[K+i]: print("Yes") else: print("No")
0
null
45,093,908,562,976
231
102
n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) flag = [False] * 2000 for i in range(2 ** n): total = 0 for j in range(n): if((i >> j) & 1): total += A[j] flag[total] = True for m in M: print('yes' if flag[m] else 'no')
N = int(input().rstrip()) A = [int(_) for _ in input().rstrip().split(" ")] Q = int(input().rstrip()) M = [int(_) for _ in input().rstrip().split(" ")] import itertools from functools import lru_cache @lru_cache(maxsize=2**12) def solve(i, m): if m == 0: return True elif i >= N: return False res = solve(i+1, m) or solve(i+1, m - A[i]) return res for m in M: if solve(0, m): print("yes") else: print("no")
1
98,176,546,446
null
25
25
import sys sys.setrecursionlimit(10**7) 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 LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N = I() print(sum((i*(N//i)*(N//i+1)//2) for i in range(1,N+1)))
N = int(input()) sum_ = lambda n:(n*(n+1))//2 ret = sum(d*sum_(N//d) for d in range(1,N+1)) # print([d*sum_(N//d) for d in range(1,N+1)]) print(ret)
1
11,107,469,758,242
null
118
118
n=int(input()) a=input() if n%2!=0: print('No') exit() t1=a[0:int(n/2)] t2=a[int(n/2):n] if t1==t2: print('Yes') else: print('No')
n = int(input()) s = input() if n % 2 == 1: print('No') exit() mid= int(len(s)/2) if s[:mid] == s[mid:]: print('Yes') else: print('No')
1
146,588,816,724,658
null
279
279
def main(): h,w = map(int,input().split(" ")) s = [list(input()) for i in range(h)] dp = [[0]*w for i in range(h)] dp[0][0] = 1 if s[0][0]=="#" else 0 for i in range(1,h): sgmdown = 1 if s[i][0]=="#" and s[i-1][0]=="." else 0 dp[i][0] = dp[i-1][0] + sgmdown for j in range(1,w): sgmright = 1 if s[0][j]=="#" and s[0][j-1]=="." else 0 dp[0][j] = dp[0][j-1] + sgmright for i in range(1,h): for j in range(1,w): sgmdown = 1 if s[i][j]=="#" and s[i-1][j]=="." else 0 sgmright = 1 if s[i][j]=="#" and s[i][j-1]=="." else 0 dp[i][j] = min(dp[i-1][j]+sgmdown, dp[i][j-1]+sgmright) print(dp[h-1][w-1]) main()
import bisect,collections,copy,itertools,math,string def I(): return int(input()) def S(): return input() def LI(): return list(map(int,input().split())) def LS(): return list(input().split()) ################################################## H,W = LI() S = [S() for _ in range(H)] dp = [[-1]*W for _ in range(H)] for i in range(H): for j in range(W): judge = 1 if S[i][j]=='#' else 0 if i==0: #0行目 if j==0: dp[0][0] = judge else: dp[0][j] = dp[0][j-1]+judge*(0 if S[0][j-1]=='#' else 1) else: #0行目以外 if j==0: dp[i][0] = dp[i-1][0]+judge*(0 if S[i-1][j]=='#' else 1) else: temp1 = dp[i][j-1]+judge*(0 if S[i][j-1]=='#' else 1) temp2 = dp[i-1][j]+judge*(0 if S[i-1][j]=='#' else 1) dp[i][j] = min(temp1,temp2) print(dp[-1][-1])
1
49,297,439,274,580
null
194
194
#!/usr/bin/env pypy import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**6) INF = float("inf") import math def solve(x, N, K, A, F): total = 0 for i in range(N): total += max(0, math.ceil((A[i]*F[i] - x) / F[i])) if total <= K: return True else: return False def main(): N,K = map(int,input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) ok = 10**13+1 ng = -1 while ok - ng > 1: mid = (ng + ok) // 2 if solve(mid, N, K, A, F): ok = mid else: ng = mid print(ok) if __name__ == "__main__": main()
X = int(input()) if 1800 <= X: print(1) elif 1600 <= X: print(2) elif 1400 <= X: print(3) elif 1200 <= X: print(4) elif 1000 <= X: print(5) elif 800 <= X: print(6) elif 600 <= X: print(7) else: print(8)
0
null
85,648,876,243,330
290
100
n = int(input()) a = 0 b = 0 for _ in range(n): word_a, word_b = input().split() words = [word_a, word_b] words.sort() if word_a == word_b: a += 1 b += 1 elif words.index(word_a) == 1: a += 3 else: b += 3 print(a, b)
s=input().split('S') print(len(max(s)))
0
null
3,469,030,131,282
67
90
s = input() q = int(input()) for i in range(q): command = input().split() command[1] = int(command[1]) command[2] = int(command[2]) if command[0] == 'print': print(s[command[1]:command[2]+1]) elif command[0] == 'reverse': s = s[command[1]:command[2]+1][::-1].join([s[:command[1]], s[command[2]+1:]]) elif command[0] == 'replace': s = command[3].join([s[:command[1]], s[command[2]+1:]])
# -*- coding: utf-8 -*- import sys import os s = input().strip() N = int(input()) for i in range(N): lst = input().split() command = lst[0] if command == 'replace': a = int(lst[1]) b = int(lst[2]) p = lst[3] s = s[:a] + p + s[b+1:] elif command == 'reverse': a = int(lst[1]) b = int(lst[2]) part = s[a:b+1] part = part[::-1] s = s[:a] + part + s[b+1:] elif command == 'print': a = int(lst[1]) b = int(lst[2]) print(s[a:b+1]) else: print('error') #print('s', s)
1
2,105,953,240,688
null
68
68
SN=[5,1,2,6] WE=[4,1,3,6] def EWSN(d): global SN,WE if d == "S" : SN = SN[3:4] + SN[0:3] WE[3] = SN[3] WE[1] = SN[1] elif d == "N": SN = SN[1:4] + SN[0:1] WE[3] = SN[3] WE[1] = SN[1] elif d == "E": WE = WE[3:4] + WE[0:3] SN[3] = WE[3] SN[1] = WE[1] elif d == "W": WE = WE[1:4] + WE[0:1] SN[3] = WE[3] SN[1] = WE[1] dice = list(map(int,input().split(" "))) op = input() for i in op: EWSN(i) print(dice[SN[1] - 1])
d = input().split() dicry = {'N':'152304', 'E':'310542', 'W':'215043','S':'402351'} for i in input(): d = [d[int(c)] for c in dicry[i]] print(d[0])
1
230,939,426,672
null
33
33
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D sample_input = list(range(3)) # sample_input[0] = '''\\//''' # sample_input[1] = '''\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\''' # sample_input[2] = '''''' sample_input[0] = '''\\\\//''' sample_input[1] = '''\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\''' sample_input[2] = '''''' give_sample_input = None if give_sample_input is not None: sample_input_list = sample_input[give_sample_input].split('\n') def input(): return sample_input_list.pop(0) # main # a list of tuples (h, l, r) # h = the hight # l, r = max of heights of points which is left (right) or equal to this point terrain_data = [] str_input = input() list_input = list(str_input) height = 0 left_max_height = 0 terrain_data.append([height,left_max_height, None]) for path in list_input: if path == '/': height += 1 elif path == '\\': height -= 1 left_max_height = max(left_max_height, height) terrain_data.append([height,left_max_height, None]) right_max_height = None # dealt as negative infinity for index in range(len(terrain_data)-1, -1, -1): height = terrain_data[index][0] if right_max_height is None: right_max_height = height else: right_max_height = max(right_max_height, height) terrain_data[index][2] = right_max_height pool_left = -1 pool_right = -1 area = 0 areas = [] prev_depth = 0 for data in terrain_data: depth = min(data[1], data[2]) - data[0] area += (prev_depth + depth)/2 if depth == 0: if pool_left < pool_right: areas.append(int(area)) area = 0 pool_right += 1 pool_left = pool_right else: pool_right += 1 prev_depth = depth print(sum(areas)) output = str(len(areas)) + ' ' for a in areas: output += str(a) + ' ' print(output[:-1])
n=int(input()) #V[u]=[k,[v],d,f] V=[[0,[],0,0]] for i in range(n): v=[int(i) for i in input().split(" ")] u=v.pop(0) k=v.pop(0) v.sort() V.append([k,v,0,0]) def is_finished(Id): k=V[Id][0] v=V[Id][1] for i in range(k): if V[v[i]][2]==0: return v[i] return -1 time=1 while time<=2*n: for i in range(1,n+1): if V[i][2]==0: cur=i log=[i] break while len(log)>0: if V[cur][2]==0: V[cur][2]=time time+=1 x=is_finished(cur) if x!=-1: cur=x log.append(cur) else: try: log.pop(-1) V[cur][3]=time time+=1 if V[cur][3]==V[cur][2]: time+=1 V[cur][3]+=1 cur=log[-1] except: pass for i in range(1,n+1): print(i,V[i][2],V[i][3])
0
null
30,811,900,668
21
8
N, X, T = map(int, input().split()) ans = (N // X) * T if N % X != 0: ans += T print(ans)
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n+1) def sum(self, i): # sum in [0, i] s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): # i > 0 assert i > 0 while i <= self.size: self.tree[i] += x i += i & -i class BitImos: """ ・範囲すべての要素に加算 ・ひとつの値を取得 の2種類のクエリをO(logn)で処理 """ def __init__(self, n): self.bit = Bit(n+1) def add(self, s, t, x): # [s, t)にxを加算 self.bit.add(s, x) self.bit.add(t, -x) def get(self, i): return self[i] def __getitem__(self, key): # 位置iの値を取得 return self.bit.sum(key) N, K = map(int, input().split()) LR = [tuple(map(int, input().split())) for _ in range(K)] bit = BitImos(N+2) bit.add(1, 2, 1) mod = 998244353 for i in range(1, N+1): cur = bit.get(i) % mod for l, r in LR: if i + l > N: continue bit.add(i+l, min(i + r + 1, N + 2), cur) print(bit.get(N) % mod)
0
null
3,437,090,892,960
86
74
N,M = map(int,input().split()) if N > M: ans = str(M)*N else: ans = str(N)*M print(ans)
a,b=input().split();print([b*int(a),a*int(b)][a<b])
1
84,139,776,865,718
null
232
232
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 from collections import Counter import bisect from functools import reduce def main(): H, N = MI() A = LI() A_sum = sum(A) if A_sum >= H: print('Yes') else: print('No') if __name__ == "__main__": main()
h, n, *a = map(int, open(0).read().split()) print(["No", "Yes"][h <= sum(a)])
1
77,682,235,092,308
null
226
226
from decimal import Decimal x = int(input()) money = 100 ans = 0 while 1: ans += 1 money = money + int(money * Decimal(str(0.01))) if money >= x: print(ans) exit()
x = int(input()) y=100 c=0 while 1: if y>=x : break y=y*101//100 c+=1 print(c)
1
27,084,148,412,828
null
159
159
x, y = map(int, input().split()) def shokin(z): if z == 1: return 300000 elif z == 2: return 200000 elif z == 3: return 100000 else: return 0 v = 0 if x == 1 and y == 1: v = 400000 print(shokin(x)+shokin(y)+v)
X,Y=map(int,input().split());print((max((4-X),0)+max((4-Y),0)+(0,4)[X*Y<2])*10**5)
1
141,023,169,269,178
null
275
275
X, K, D = map(int, input().split()) X = abs(X) if K%2 == 1: K -= 1 X -= D K_ = K // 2 min_Y = X - K_ * (2 * D) if min_Y > 0: print(min_Y) else: min_Y_p = X % (2 * D) min_Y_m = 2 * D - X % (2 * D) print(min(min_Y_p, min_Y_m ))
a, b = map(int, input().split()) print('{:d} {:d} {:.10f}'.format(a//b, a%b, a/b))
0
null
2,890,209,428,610
92
45
def main(): n = int(input()) l_0 = [] r_0 = [] ls_plus = [] ls_minus = [] sum_l = 0 sum_r = 0 for i in range(n): s = input() left, right = 0, 0 for j in range(len(s)): if s[j] == '(': right += 1 else: if right > 0: right -= 1 else: left += 1 if left == right == 0: continue if left == 0: l_0.append((left, right)) elif right == 0: r_0.append((left, right)) elif left < right: ls_plus.append((left, right)) else: ls_minus.append((left, right)) sum_l += left sum_r += right if len(ls_plus) == len(ls_minus) == len(l_0) == len(r_0) == 0: print("Yes") return if len(l_0) == 0 or len(r_0) == 0: print("No") return if sum_l != sum_r: print("No") return # r-lの大きい順 ls_plus.sort(key=lambda x: x[1] - x[0], reverse=True) # lの小さい順 ls_plus.sort(key=lambda x: x[0]) # l-rの小さい順 ls_minus.sort(key=lambda x: x[0] - x[1]) # lの大さい順 ls_minus.sort(key=lambda x: x[0], reverse=True) now_r = 0 for ll in l_0: now_r += ll[1] for _ in ls_plus: r = _[1] x = now_r - _[0] if x >= 0: now_r = x + r else: print("No") return for _ in ls_minus: r = _[1] x = now_r - _[0] if x >= 0: now_r = x + r else: print("No") return print("Yes") main()
from functools import reduce n, *s = open(0).read().split() u = [] for t in s: close_cnt = 0 tmp = 0 for c in t: tmp += (1 if c == '(' else -1) close_cnt = min(close_cnt, tmp) u.append((close_cnt, tmp - close_cnt)) M = 10**6 + 1 acc = 0 for a, b in sorted(u, key=lambda z: (- M - z[0] if sum(z)>= 0 else M - z[1])): if acc + a < 0: print("No") exit(0) else: acc += a + b print(("No" if acc else "Yes"))
1
23,561,694,414,740
null
152
152
def lstToInt(l,x=0): if len(l) == 0: return x else: return lstToInt(l[1:], x*10 + l[0]) n,m = map(int,input().split()) c = [-1]*n for i in range(m): s, num = map(int,input().split()) if c[s-1] != -1 and c[s-1] != num: print(-1) exit() elif s == 1 and num == 0 and n != 1: print(-1) exit() else: c[s-1] = num if c[0] == -1 and n != 1: c[0] = 1 ans = lstToInt(list(0 if c[i] == -1 else c[i] for i in range(n))) print(ans)
# C - Guess The Number N, M = map(int, input().split()) SC = [list(map(int, input().split())) for _ in range(M)] ans = [0,0,0] # 条件だけで不適がわかるものは弾く for i in range(M): for j in range(i+1,M): if (SC[i][0] == SC[j][0]) and (SC[i][1] != SC[j][1]): print(-1) quit() # 各桁を指定をする for k in range(M): ans[SC[k][0]-(N-2)] = str(SC[k][1]) # 頭の桁が0で指定されると不適(str型かどうかで判定する) if (ans[3-N] == "0") and (N == 1): print(0) quit() elif ans[3-N] == "0": print(-1) quit() # N桁の文字列にする ans = [str(ans[i]) for i in range(3)] res = "".join(ans) res = res[(3-N):4] # 頭の桁が指定無しの0だったら1に変える if (res[0] == "0") and (N == 1): res = "0" elif res[0] == "0": ref = list(res) ref[0] = "1" res = "".join(ref) print(res)
1
60,845,279,031,040
null
208
208
n = len(input()) print("x" * n)
S = input() result = '' for _ in S: result += 'x' print(result)
1
72,842,147,290,280
null
221
221
W, H, x, y, r = map(int, input().split()) if x - r < 0: #left print("No") elif x + r > W: #right print("No") elif y - r < 0: print("No") elif y + r > H: print("No") else: print("Yes")
N = int(input()) A = list(map(int,input().split())) M = max(A) X = [1]*(M+1) for a in A: X[a]-=1 for i in range(a*2,M+1,a): X[i]=-2 ans = 0 for a in A: if X[a]>=0: ans+=1 print(ans)
0
null
7,436,291,252,412
41
129
ondo = int(input()) if ondo>=30: print('Yes') else: print('No')
import math A, B = input().split() A = int(A) B = int(''.join(B.split('.'))) print((A * B) // 100)
0
null
11,070,082,974,240
95
135
n = int(input()) nums = input().split() max = int(nums[0]) min = int(nums[0]) sum = int(nums[0]) for i in range(n-1): m = int(nums[i+1]) if m > max: max = m if m < min: min = m sum = sum + m print(min, max, sum)
def main(): D = int(input()) c = list(map(int,input().split())) s = [] for d in range(D): s.append(list(map(int,input().split()))) t = [] for d in range(D): t.append(int(input())-1) last = [0 for i in range(26)] v = 0 for d in range(D): v += s[d][t[d]] last[t[d]] = d+1 for i in range(26): v -= c[i]*(d+1-last[i]) print(v) if __name__ == '__main__': main()
0
null
5,303,700,464,352
48
114
n = int(input().rstrip()) red = [] white = [] stones = input().rstrip() for idx, stone in enumerate(stones): if stone == "R": red.append(idx) if stone == "W": white.append(idx) red_len = len(red) white_len = len(white) cnt = 0 for i in range(min(red_len, white_len)): red_idx = red[-1-i] white_idx = white[i] if red_idx> white_idx: cnt += 1 else: break print(cnt)
s=input() l=set(s) if(len(l)==1): print("No") else: print("Yes")
0
null
30,510,541,505,632
98
201
n = int(input()) d = {} for i in range(n): s = input() d[s] = d.get(s, 0) + 1 m = max(d.values()) for s in sorted(s for s in d if d[s] == m): print(s)
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) A = str(input()) B = str(input()) ans = [str(i) for i in range(1,4)] ans.remove(A) ans.remove(B) print(ans[0])
0
null
90,179,800,829,092
218
254
x = int(input()) print(8 - ((x - 400) // 200))
a,b,c,d=map(int,input().split()) for i in range(1001): if i%2==0: c-=b if c<=0: print("Yes") exit(0) else: a-=d if a<=0: print("No") exit(0)
0
null
18,097,364,346,278
100
164
from collections import deque n = int(input()) q = deque() for i in range(n): c = input() if c[0] == 'i': q.appendleft(c[7:]) elif c[6] == ' ': try: q.remove(c[7:]) except: pass elif c[6] == 'F': q.popleft() else: q.pop() print(*q)
_ = input() a = list(input()) cnt = 0 word = 0 for i in a: if word == 0 and i == 'A': word = 1 elif word == 1 and i =='B': word = 2 elif word == 2 and i =='C': word = 0 cnt += 1 else: if i == 'A': word = 1 else: word = 0 print(cnt)
0
null
49,505,065,427,142
20
245
N = int(input()) P = list(map(int,input().split())) min_num = float('inf') ans = 0 for i in P: if i < min_num: ans+=1 min_num = i print(ans)
from itertools import groupby s = input() A = [(key, sum(1 for _ in group)) for key, group in groupby(s)] tmp = 0 ans = 0 for key, count in A: if key == '<': ans += count*(count+1)//2 tmp = count else: if tmp < count: ans -= tmp ans += count ans += (count-1)*count//2 tmp = 0 print(ans)
0
null
120,660,603,648,240
233
285
import bisect N = int(input()) l = list(map(int, input().split())) l.sort() ans = 0 for i in range(N - 1): for j in range(i + 1, N): p = l[:i] a, b = l[i], l[j] low = b - a + 1 high = a + b ans += bisect.bisect_left(p, high) - bisect.bisect_left(p, low) print(ans)
N=int(input()) S={} for n in range(N): s=input() S[s]=S.get(s,0)+1 maxS=max(S.values()) S=[k for k,v in S.items() if v==maxS] print('\n'.join(sorted(S)))
0
null
121,005,264,956,280
294
218
# Python 3 if __name__ == "__main__": a, b, c = input().split() a, b, c = int(a), int(b), int(c) count = 0 for i in range(a, b + 1): if c % i == 0: count += 1 print(count)
n=int(input()) s=[input() for i in range(n)] ac=s.count("AC") wa=s.count("WA") tle=s.count("TLE") re=s.count("RE") print("AC x "+str(ac)) print("WA x "+str(wa)) print("TLE x "+str(tle)) print("RE x "+str(re))
0
null
4,670,752,423,138
44
109
a=int(input()) b=list(map(int,input().split())) b.sort() c=0 for i in range(a-1): if b[i]==b[i+1]: c=c+1 if c==0: print("YES") else: print("NO")
R,C,k = map(int,input().split()) dp1 = [[0]*(C+1) for i in range(R+1)] dp2 = [[0]*(C+1) for i in range(R+1)] dp3 = [[0]*(C+1) for i in range(R+1)] for i in range(k): r,c,v = map(int,input().split()) dp1[r][c] = v for i in range(1,R+1): for j in range(1,C+1): a = dp1[i][j] dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1]) dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1]) dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a) print(max(dp1[R][C],dp2[R][C],dp3[R][C]))
0
null
39,490,017,701,472
222
94
def func(S): T = S[::-1] ans = sum(1 for s, t in zip (S, T) if s != t) // 2 return ans if __name__ == "__main__": S = input() print(func(S))
h = int(input()) w = int(input()) n = int(input()) cnt = 0 blk = 0 if h > w: for i in range(w): blk += h cnt += 1 if blk >= n: break else: for j in range(h): blk += w cnt += 1 if blk >= n: break print(cnt)
0
null
104,508,569,116,070
261
236
a,b,c,d=map(int,input().split()) temp_q=(c+b-1)//b temp_g=(a+d-1)//d if temp_q>temp_g: print("No") else: print("Yes")
#!/usr/bin/env python3 print(len({*open(0).read().split()}) - 1)
0
null
29,785,807,850,268
164
165
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)
from bisect import bisect_left from itertools import accumulate n, m = map(int, input().split()) hands = [int(x) for x in input().split()] increasing = sorted(hands) hands = list(reversed(increasing)) xs = [0] + list(accumulate(hands)) max_x = 2 * 10**5 + 1 min_x = 0 def canGet(x): count = 0 for hand in increasing: idx = bisect_left(increasing, x-hand) count += n - idx return count >= m while max_x - min_x > 1: # left mid = (max_x + min_x) // 2 if canGet(mid): min_x = mid else: max_x = mid ans = 0 count = 0 for Ai in hands: idx = bisect_left(increasing, min_x-Ai) ans += Ai*(n-idx) + xs[n-idx] count += n-idx print(ans-(count-m)*min_x)
1
108,028,928,373,754
null
252
252
from collections import defaultdict d = defaultdict(int) n = int(input()) for _ in range(n): d[input()] += 1 s = sorted(d.items(), key=lambda x: (-x[1], x[0])) nmax = s[0][1] for i in s: if i[1] != nmax: break print(i[0])
import collections N = int(input()) S = [input() for i in range(N)] S = sorted(S) C = collections.Counter(S) M = C.most_common() V = C.values() MAX = max(V) for i in range(len(M)): if M[i][1] == MAX: print(M[i][0])
1
69,771,295,355,150
null
218
218
N = int(input()) import collections a = [] for i in range(N): S = input() a.append(S) l = collections.Counter(a) x = max(l.values()) ans = [k for k, v in l.items() if v == x] ans = sorted(ans) for i in ans: print(i)
from math import gcd from functools import reduce import sys input = sys.stdin.readline def lcm(a, b): return a*b // gcd(a, b) def count_factor_2(num): count = 0 while num % 2 == 0: num //= 2 count += 1 return count def main(): n, m = map(int, input().split()) A = list(map(lambda x: x//2, set(map(int, input().split())))) check = len(set(map(count_factor_2, A))) if check != 1: print(0) return lcm_a = reduce(lcm, A) step = lcm_a * 2 ans = (m + lcm_a) // step print(ans) if __name__ == "__main__": main()
0
null
86,043,895,672,348
218
247
N, M = list(map(int, input().split())) sc = [] for i in range(M): s, c = list(map(int, input().split())) sc.append([s, c]) for i in range(10**N): stri = str(i) if len(stri) == N: for j in range(M): k = sc[j][0] if not stri[k-1] == str(sc[j][1]): break else: print(i) break else: print(-1)
def main(): N = input() a = [input() for y in range(N)] a_max = -10**9 a_min = a[0] for j in xrange(1,len(a)): if a[j] - a_min > a_max: a_max = a[j] - a_min if a[j] < a_min: a_min = a[j] print a_max main()
0
null
30,294,155,159,742
208
13
def readInt(): return list(map(int, input().split())) n = int(input()) a = readInt() b = 0 ans = 0 for i in a: b += i ** 2 # print(sum(a)) ans = ((sum(a) ** 2 - b) // 2) % (10 ** 9 + 7) print(ans)
n = int( input().rstrip()) numbers = list( map(int, input().rstrip().split(" ")) ) total = sum(numbers) m = 10 ** 9 + 7 result = 0 for number in numbers[:-1]: total -= number result += (total * number) result %= m print(result)
1
3,859,571,313,600
null
83
83
import sys read = sys.stdin.buffer.read #input = sys.stdin.readline #input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode('utf-8') import math def main(): k=II() ans=0 li=[[0]*(k+1) for i in range(k+1)] for a in range(1,k+1): for b in range(1,k+1): li[a][b]=math.gcd(a,b) for a in range(1,k+1): for b in range(1,k+1): for c in range(1,k+1): ans+=math.gcd(li[a][b],c) print(ans) if __name__ == "__main__": main()
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)] def main(): H, W = NMI() grid = [SI() for _ in range(H)] DH = [-1, 1, 0, 0] DW = [0, 0, -1, 1] def bfs(sh, sw): queue = deque() seen = make_grid(H, W, -1) queue.append([sh, sw]) seen[sh][sw] = 0 while queue: now_h, now_w = queue.popleft() for dh, dw in zip(DH, DW): next_h = now_h + dh next_w = now_w + dw if not(0 <= next_h < H and 0 <= next_w < W): continue if seen[next_h][next_w] != -1 or grid[next_h][next_w] == "#": continue queue.append([next_h, next_w]) seen[next_h][next_w] = seen[now_h][now_w] + 1 return max([max(l) for l in seen]) ans = 0 for h in range(H): for w in range(W): if grid[h][w] == ".": ans = max(ans, bfs(h, w)) print(ans) if __name__ == "__main__": main()
0
null
65,312,230,884,356
174
241
def resolve(): N = int(input()) g = {} for i in range(N-1): a, b = list(map(int, input().split())) g.setdefault(a-1, []) g[a-1].append((b-1, i)) g.setdefault(b-1, []) g[b-1].append((a-1, i)) nodes = [(None, 0)] colors = [None for _ in range(N-1)] maxdeg = 0 while nodes: prevcol, node = nodes.pop() maxdeg = max(maxdeg, len(g[node])) color = 1 if prevcol != 1 else 2 for nxt, colidx in g[node]: if colors[colidx] is None: colors[colidx] = color nodes.append((color, nxt)) color += 1 if prevcol != color+1 else 2 print(maxdeg) for col in colors: print(col) if '__main__' == __name__: resolve()
import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(input()) def LI(): return list(map(int, input().split())) def LIR(row,col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return map(list, zip(*read_all)) ################# T1,T2 = LI() A1,A2 = LI() B1,B2 = LI() if A1 > B1 and A2 > B2: print(0) exit() if A1 < B1 and A2 < B2: print(0) exit() if A1 > B1: t = (A1-B1)*T1 / (B2-A2) delta = (A1-B1)*T1+(A2-B2)*T2 if t == T2: print('infinity') exit() elif t > T2: print(0) exit() else: if delta > 0: print(math.floor((T2-t)*(B2-A2)/delta) + 1) exit() else: x = (A1-B1)*T1 / (-delta) if int(x) == x: print(2*int(x)) else: print(2*math.floor(x)+1) else: t = (B1-A1)*T1 / (A2-B2) delta = (B1-A1)*T1+(B2-A2)*T2 if t == T2: print('infinity') exit() elif t > T2: print(0) exit() else: if delta > 0: print(math.floor((T2-t)*(A2-B2)/delta) + 1) exit() else: x = (B1-A1)*T1 / (-delta) if int(x) == x: print(2*int(x)) else: print(2*math.floor(x)+1)
0
null
133,673,087,528,062
272
269
def resolve(): N = int(input()) A = list(map(int, input().split())) mp = dict() ans = 0 for i in range(N): x = i - A[i] ans += mp.get(x, 0) y = A[i] + i mp[y] = mp.get(y, 0) + 1 print(ans) if __name__ == "__main__": resolve()
s = input() n = len(s) left = [0 for _ in range(n+1)] right = [0 for _ in range(n+1)] tmp = 0 for i in range(n): if s[i] == '<': tmp += 1 else: tmp = 0 left[i+1] = tmp tmp = 0 for i in range(n-1, -1, -1): if s[i] == '>': tmp += 1 else: tmp = 0 right[i] = tmp ans = 0 for i in range(n+1): ans += max(right[i], left[i]) print(ans)
0
null
90,881,454,503,330
157
285
s, t = [input() for i in range(2)] c = [] for i in range(len(s) - len(t) + 1): d = len(t) for a, b in zip(s[i:], t): if a == b: d -= 1 c.append(d) print(min(c))
# -*- coding: utf-8 -*- import sys import os import math PI = math.pi r = float(input()) s = r * r * PI l = 2 * PI * r print(s, l)
0
null
2,145,901,669,680
82
46
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) d = abs(A-B) if d-(V-W)*T<=0: print("YES") else: print("NO")
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if a == b: print("NO") As = v * t + a Bs = w * t + b if v > w: if abs(a - b)/abs(v - w) <= t: print("YES") else: print("NO") else: print("NO")
1
15,151,730,230,640
null
131
131
n = input() taro = 0 hanako = 0 for i in xrange(n): t_card, h_card = raw_input().split(" ") if t_card < h_card: hanako += 3 elif t_card > h_card: taro += 3 elif t_card == h_card: taro += 1 hanako += 1 print taro, hanako
def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a dum = prime_factorize(int(input())) dum_len = len(dum) num = 0 ans = 0 cnt = 0 check = 0 for i in range(dum_len): if num == dum[i]: cnt += 1 if cnt >= check: check += 1 ans += 1 cnt = 0 else: num = dum[i] ans += 1 cnt = 0 check = 2 print(ans)
0
null
9,528,747,421,480
67
136
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) if a<b and v<=w: print("NO") elif w>v: print("NO") else: if abs(b-a)<=t*abs(v-w): print("YES") else: print("NO")
a, v = list(map(int, input().split())) b, w = list(map(int, input().split())) t = int(input()) x = abs(a-b) y = (v - w) * t if y >= x: print('YES') else: print('NO')
1
15,114,647,234,896
null
131
131
import sys import math import time sys.setrecursionlimit(int(1e6)) if False: dprint = print else: def dprint(*args): pass n, k = list(map(int, input().split())) A = list(map(int, input().split())) dprint("n, k = ", n, k) lx = int(0) # NG rx = int(1e9) # OK #ans = 0 while ((rx-lx)>1): x = (rx + lx) // 2 dprint("lx, x, rx = ", lx, x, rx) n = 0 for i in range(len(A)): #n += math.ceil(A[i] / x) - 1 n += (A[i]-1) // x if n > k: break dprint("n = ", n) if n <= k: dprint(" smaller x") rx = x else: dprint(" cut less, bigger x") lx = x #ans = math.ceil(rx) print(rx)
s = input() l = len(s) ss = "" for x in range(l): ss = ss+'x' print(ss)
0
null
39,492,745,607,338
99
221
from sys import stdin,stdout def fn(pos,res,k): if pos==n:return (k==0) ans=0 if (pos,res,k) in dp:return dp[pos,res,k] cur=ord(s[pos])-48 if res: for d in range(cur+1): if d==0:ans+=fn(pos+1,d==cur,k) elif d!=0 and k>0:ans+=fn(pos+1,d==cur,k-1) else: for d in range(10): if d == 0:ans += fn(pos + 1,0, k) elif d != 0 and k > 0:ans += fn(pos + 1,0, k - 1) dp[pos,res,k]=ans return ans #a,b=map(int,stdin.readline().split()) s=input() n=len(s) k1=int(stdin.readline()) dp={} ans=0 for d in range(10): if d+48<=ord(s[0]): ans+=fn(1,(d==ord(s[0])-48),(k1-(d!=0))) print(ans)
def main(): n = list(input()) k = int(input()) N = len(n) for i in range(N): n[i] = int(n[i]) dp1 = [[0 for _ in range(k+1)] for _ in range(N+1)] dp2 = [[0 for _ in range(k+1)] for _ in range(N+1)] dp1[0][0] = 1 for i in range(N): for j in range(k+1): dp2[i+1][j] += dp2[i][j] if j < k: dp2[i+1][j+1] += dp2[i][j]*9 if n[i]: dp2[i+1][j] += dp1[i][j] if j == k: continue dp1[i+1][j+1] += dp1[i][j] dp2[i+1][j+1] += dp1[i][j] * (n[i]-1) else: dp1[i+1][j] += dp1[i][j] print(dp1[N][k]+dp2[N][k]) if __name__ == "__main__": main()
1
76,032,684,557,648
null
224
224
def segfunc(x,y): return set(x)|set(y) ide_ele=set() class SegTree(): def __init__(self,init_val,segfunc,ide_ele): n=len(init_val) self.segfunc=segfunc self.ide_ele=ide_ele self.num=1<<(n-1).bit_length() self.tree=[ide_ele]*2*self.num for i in range(n): self.tree[self.num+i]=init_val[i] for i in range(self.num-1,0,-1): self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1]) def update(self,k,x): k+=self.num self.tree[k]=x while k>1: self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1]) k>>=1 def query(self,l,r): res=self.ide_ele l+=self.num r+=self.num while l<r: if l&1: res=self.segfunc(res,self.tree[l]) l+=1 if r&1: res=self.segfunc(res,self.tree[r-1]) l>>=1 r>>=1 return res n=int(input()) s=input() q=int(input()) st=SegTree(s,segfunc,ide_ele) for _ in range(q): q,c,r=input().split() if q=='1':st.update(int(c)-1,r) else:print(len(st.query(int(c)-1,int(r))))
import bisect n=int(input()) s=list(input()) #アルファベットの各文字に対してからのリストを持つ辞書 alpha={chr(i):[] for i in range(97,123)} #alpha[c]で各文字ごとに出現場所をソートして保管 for i,c in enumerate(s): bisect.insort(alpha[c],i+1) for i in range(int(input())): p,q,r=input().split() if p=='1': q=int(q) b=s[q-1] if b!=r: alpha[b].pop(bisect.bisect_left(alpha[b],q)) bisect.insort(alpha[r],q) s[q-1]=r else: count=0 for l in alpha.values(): pos=bisect.bisect_left(l,int(q)) if pos<len(l) and l[pos]<=int(r): count+=1 print(count)
1
62,473,822,235,680
null
210
210
from math import pi r = float(input()) print("{0:.6f} {1:.6f}".format(float(r*r*pi), float(2*r*pi)))
r=input();p=3.141592653589;print "%.9f"%(p*r*r),r*2*p
1
636,256,013,760
null
46
46
mod=10**9+7 n,k=map(int,input().split()) cnt=[0]*k for i in range(k,0,-1): cnt[i-1]=pow(k//i,n,mod) for j in range(i*2,k+1,i): cnt[i-1]-=cnt[j-1] cnt[i-1]%=mod ans=0 for i in range(k): ans+=cnt[i]*(i+1)%mod print(ans%mod)
N, K = map(int, input().split()) MOD = 10**9+7 c = [0]*(K+1) for i in range(1, K+1)[::-1]: c[i] = pow(K//i, N, MOD) for j in range(i*2, K+1, i): c[i] -= c[j] if c[i]<0: c[i] += MOD ans = 0 for i in range(1, K+1): ans += i*c[i] ans %= MOD print(ans)
1
36,735,232,223,440
null
176
176
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): for lhs in range(1,9+1): for rhs in range(1,9+1): print("{}x{}={}".format(lhs, rhs, lhs*rhs)) if __name__ == "__main__": main()
def exe(): for i in range(1,10): for j in range(1,10): print(str(i)+'x'+str(j)+'='+str(i*j)) if __name__ == '__main__': exe()
1
1,670,380
null
1
1
X = int(input()) A = 0 f = 1 while f: a = A ** 5 B = 0 while f: b = B ** 5 if a <= X: if a + b == X: print(str(A)+" "+str(-B)) f = 0 elif a + b > X: break if a > X: if a - b == X: print(str(A)+" "+str(B)) f = 0 elif a - b < X: break B += 1 A += 1
import os, sys, re, math from functools import reduce def lcm(vals): return reduce((lambda x, y: (x * y) // math.gcd(x, y)), vals, 1) (A, B) = [int(n) for n in input().split()] print(lcm([A, B]))
0
null
69,608,681,472,512
156
256
# import itertools # import math # import sys # sys.setrecursionlimit(500*500) # import numpy as np # import heapq # from collections import deque # N = int(input()) S = input() T = input() # n, *a = map(int, open(0)) # N, M = map(int, input().split()) # A = list(map(int, input().split())) # B = list(map(int, input().split())) # tree = [[] for _ in range(N + 1)] # B_C = [list(map(int,input().split())) for _ in range(M)] # S = input() # B_C = sorted(B_C, reverse=True, key=lambda x:x[1]) # all_cases = list(itertools.permutations(P)) # a = list(itertools.combinations_with_replacement(range(1, M + 1), N)) # itertools.product((0,1), repeat=n) # A = np.array(A) # cum_A = np.cumsum(A) # cum_A = np.insert(cum_A, 0, 0) # def dfs(tree, s): # for l in tree[s]: # if depth[l[0]] == -1: # depth[l[0]] = depth[s] + l[1] # dfs(tree, l[0]) # dfs(tree, 1) # def factorization(n): # arr = [] # temp = n # for i in range(2, int(-(-n**0.5//1))+1): # if temp%i==0: # cnt=0 # while temp%i==0: # cnt+=1 # temp //= i # arr.append([i, cnt]) # if temp!=1: # arr.append([temp, 1]) # if arr==[]: # arr.append([n, 1]) # return arr ma = 0 s = len(S) t = len(T) for i in range(s - t + 1): cnt = 0 for j in range(t): if S[i + j] == T[j]: cnt += 1 if cnt > ma: ma = cnt print(t - ma)
N = int(input()) A = list(map(int, input().split())) A_set = set(A) if len(A) == len(A_set): print('YES') else: print('NO')
0
null
38,710,106,296,512
82
222
def make_divisors(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()) ans = len(make_divisors(n - 1)) divisors = [] for i in make_divisors(n): j = n if i != 1: while j % i == 0: j //= i if (j - 1) % i == 0: divisors.append(i) print(ans + len(divisors) - 1)
class SegTree(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return True def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() self.seg = [self.ide_ele] * 2 * self.num for i in range(n): self.seg[i+self.num-1] = init_val[i] for i in range(self.num-2,-1,-1): self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2]) def update(self, idx, val): idx += self.num-1 self.seg[idx] = val while idx: idx = (idx-1)//2 self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2]) def addition(self, idx, val): idx += self.num-1 self.seg[idx] += val while idx: idx = (idx-1)//2 self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2]) def multiplication(self, idx, val): idx += self.num-1 self.seg[idx] *= val while idx: idx = (idx-1)//2 self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2]) def query(self, begin, end): if end <= begin: return self.ide_ele begin += self.num-1 end += self.num-2 res = self.ide_ele while begin + 1 < end: if begin&1 == 0: res = self.segFunc(res, self.seg[begin]) if end&1 == 1: res = self.segFunc(res, self.seg[end]) end -= 1 begin = begin//2 end = (end-1)//2 if begin == end: res = self.segFunc(res, self.seg[begin]) else: res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end]) return res def getLargestIndex(self, begin, end): L, R = begin, end if not self.searchIndexFunc(self.query(begin, end)): return None while L+1 < R: P = (L+R)//2 if self.searchIndexFunc(self.query(P, R)): L = P else: R = P return L def getSmallestIndex(self, begin, end): L, R = begin, end if not self.searchIndexFunc(self.query(begin, end)): return None while L+1 < R: P = (L+R+1)//2 if self.searchIndexFunc(self.query(L, P)): R = P else: L = P return L def main(): n = int(input()) s = input() alp = [[0]*n for _ in range(26)] for i, c in enumerate(s): alp[ord(c) - ord("a")][i] = 1 seg = [SegTree(0, alp[i]) for i in range(26)] q = int(input()) ans = [] for _ in range(q): a, b, c = map(str, input().split()) if a == "1": b = int(b) - 1 for i in range(26): if alp[i][b] == 1: alp[i][b] = 0 seg[i].update(b, 0) alp[ord(c) - ord("a")][b] = 1 seg[ord(c) - ord("a")].update(b, 1) else: b, c = int(b)-1, int(c) cnt = 0 for i in range(26): if seg[i].query(b, c) > 0: cnt += 1 ans.append(cnt) for v in ans: print(v) if __name__ == "__main__": main()
0
null
52,209,719,003,888
183
210
n = int(input()) a = list(map(int,input().split())) A = 0 for i in range(n): A ^= a[i] ans = [] for i in range(n): ans.append(A^a[i]) print(" ".join(map(str,ans)))
n=int(input()) l=list(map(int,input().split())) s=0 for i in range(n): s=s^l[i] k=s y=0 for i in range(n): y=k^l[i] print(y,end=" ")
1
12,559,927,441,138
null
123
123
_ = input() arr = list(map(int, input().split())) min = arr[0] max = arr[0] sum = 0 for a in arr: if a < min: min = a if max < a: max = a sum += a print(min, max, sum)
k=raw_input().split() k=raw_input().split() k.sort() for i in range(len(k)): k[i]=int(k[i]) k.sort() print min(k), print max(k), print sum(k)
1
746,193,483,620
null
48
48
a = input() t = list(a) if t[len(t)-1] == "?": t[len(t)-1] = "D" if t[0] == "?": if t[1] == "D" or t[1] == "?": t[0] = "P" else: t[0] = "D" for i in range(1, len(t)-1): if t[i] == "?" and t[i-1] == "P": t[i] = "D" elif t[i] == "?" and t[i+1] == "D": t[i] = "P" elif t[i] == "?" and t[i+1] == "?": t[i] = "P" elif t[i] == "?": t[i] = "D" answer = "".join(t) print(answer)
from collections import Counter n = int(input()) a = [int(x) for x in input().split()] arr1 = [] arr2 = [] for i in range(1, n + 1): arr1.append(i - a[i - 1]) arr2.append(i + a[i - 1]) dis1 = Counter(arr1) dis2 = Counter(arr2) ans = 0 for i in dis1.keys(): ans += dis1[i] * dis2[i] print(ans)
0
null
22,203,189,904,668
140
157
k=int(input()) a,b = map(int,input().split()) ans="NG" for i in range(1001): if a<=(i*k)<=b : ans = "OK" print(ans)
k = int(input()) a, b = map(int, input().split()) if b // k - a // k > 0: print('OK') elif a % k == 0: print('OK') else: print('NG')
1
26,574,322,633,860
null
158
158
import sys input = lambda: sys.stdin.readline().rstrip() N, K = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) F = sorted(list(map(int, input().split()))) def binary_search(min_n, max_n): while max_n - min_n != 1: tn = (min_n + max_n) // 2 if judge(tn): max_n = tn else: min_n = tn return max_n def judge(tn): k = 0 for i in range(N): if A[i] * F[i] > tn: k += A[i] - (tn // F[i]) if k > K: return False return True def solve(): ans = binary_search(-1, 10**12) print(ans) if __name__ == '__main__': solve()
from decimal import Decimal x = int(input()) t = 100 n = 0 while t < x: t += t // 100 n += 1 print(n)
0
null
95,565,047,596,200
290
159
numbers = [] while True: x=int(input()) if x==0: break numbers.append(x) for i in range(len(numbers)): print("Case ",i+1,": ",numbers[i],sep="")
class dise: def __init__(self, label): self.label1 = label[0] self.label2 = label[1] self.label3 = label[2] self.label4 = label[3] self.label5 = label[4] self.label6 = label[5] def N_rotation(self): reg = self.label1 self.label1 = self.label2 self.label2 = self.label6 self.label6 = self.label5 self.label5 = reg def E_rotation(self): reg = self.label1 self.label1 = self.label4 self.label4 = self.label6 self.label6 = self.label3 self.label3 = reg def S_rotation(self): reg = self.label1 self.label1 = self.label5 self.label5 = self.label6 self.label6 = self.label2 self.label2 = reg def W_rotation(self): reg = self.label1 self.label1 = self.label3 self.label3 = self.label6 self.label6 = self.label4 self.label4 = reg def right_rotation(self): reg = self.label2 self.label2 = self.label3 self.label3 = self.label5 self.label5 = self.label4 self.label4 = reg def search(self, value): while True : self.N_rotation() if value[0] == self.label1: break self.E_rotation() if value[0] == self.label1: break while True : self.right_rotation() if value[1] == self.label2: break init_dise = input().split() times = int(input()) for i in range(times): dise1 = dise(init_dise) order = input().split() dise1.search(order) print(dise1.label3)
0
null
361,132,836,288
42
34
A,B,C,K = map(int,input().split()) if K-A > 0: if K-A-B > 0: print(A-(K-A-B)) else: print(A) else: print(K)
cards=input() new=cards.split() a=int(new[0]) b=int(new[1]) c=int(new[2]) k=int(new[3]) if a>k: print(k) else: if a+b>k: print(a) else: sum=a+(k-(a+b))*(-1) print(sum)
1
21,718,418,206,968
null
148
148
S = input() if S == 'AAA': print('No') elif S == 'BBB': print('No') else: print('Yes')
s = list(input()) if s[0] != s[1] or s[1] != s[2]: print("Yes") else: print("No")
1
54,950,923,218,550
null
201
201
def resolve(): A, B = list(map(int, input().split())) if A >= 10 or B >= 10: print(-1) else: print(A*B) if '__main__' == __name__: resolve()
a,b=map(int,input().split()) print(a*b if a<10 and b<10 else '-1')
1
158,156,868,656,910
null
286
286
n=int(input()) k=[1] ans=[] c=26 wa=0 while wa+c<n: k.append(c) wa+=c c=c*26 n=n-1-wa for i in k[::-1]: ans.append(n//i) n=n%i t='' for i in ans: t+=chr(97+i) print(t)
S = list("abcdefghijklmnopqrstuvwxyz") N = int(input()) P = 0 for i in range(1,15): if P+26**i >= N: n = i break else: P += 26**i X = [0]*n NN = N - P - 1###0-indexedの26進法なので for i in range(n): X[n-i-1] = S[NN % 26] NN //= 26 print("".join(X))
1
11,838,942,736,192
null
121
121
N,M,K=map(int,input().split()) par=[0]*(N+1) num=[0]*(N+1) group = [1]*(N+1) for i in range(1,N+1): par[i]=i def root(x): if par[x]==x: return x return root(par[x]) def union(x,y): rx = root(x) ry = root(y) if rx==ry: return par[max(rx,ry)] = min(rx,ry) group[min(rx,ry)] += group[max(rx,ry)] def same(x,y): return root(x)==root(y) for _ in range(M): a,b=map(int,input().split()) union(a,b) num[a]+=1 num[b]+=1 for _ in range(K): c,d=map(int,input().split()) if same(c,d): num[c]+=1 num[d]+=1 for i in range(1,N+1): print(group[root(i)]-num[i]-1,end=" ")
N,K=map(int,input().split()) L=list(map(int,input().split())) R=list() if K>=N: sums=0 c=dict() for i in range(N): sums+=L[i] sums%=K a=(sums-i-1)%K if a in c: c[a]+=1 else: c[a]=1 ans=0 for i in c: ans+=(c[i]-1)*c[i]//2 if 0 in c: print(ans+c[0]) else: print(ans) else: ans=0 c=[0]*K sums=0 for i in range(N): sums+=L[i] sums%=K a=(sums-i-1)%K R.append(a) for i in range(K-1): c[R[i]]+=1 ans+=c[0] c[R[K-1]]+=1 for i in range(N): if i<N-K: ans+=c[R[i]]-1 c[R[i]]-=1 c[R[i+K]]+=1 else: ans+=c[R[i]]-1 c[R[i]]-=1 print(ans)
0
null
99,865,704,798,420
209
273
import sys n=int(input()) s=[input() for i in range(n)] t=[2*(i.count("("))-len(i) for i in s] if sum(t)!=0: print("No") sys.exit() st=[[t[i]] for i in range(n)] for i in range(n): now,mi=0,0 for j in s[i]: if j=="(": now+=1 else: now-=1 mi=min(mi,now) st[i].append(mi) #st.sort(reverse=True,key=lambda z:z[1]) u,v,w=list(filter(lambda x:x[1]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st)) v.sort(reverse=True) v.sort(reverse=True,key=lambda z:z[1]) w.sort(key=lambda z:z[0]-z[1],reverse=True) lu=len(u) lv=len(v) now2=0 for i in range(n): if i<lu: now2+=u[i][0] elif i<lu+lv: if now2+v[i-lu][1]<0: print("No") break now2+=v[i-lu][0] else: #いや、間違ってるのここなんかーーい if now2+w[i-lu-lv][1]<0: print("No") break now2+=w[i-lu-lv][0] else: print("Yes")
def actual(s): N = len(s) count_operation = 0 for i in range(N): head = s[i] tail = s[N - 1 - i] if head != tail: count_operation += 1 return int(count_operation / 2) s = input() print(actual(s))
0
null
71,925,972,949,040
152
261
a1, a2, a3 = [int(n) for n in input().split()] print('bust' if a1+a2+a3 >= 22 else 'win')
import sys a,b,c = map(int,input().split()) d = a+b+c if(d > 21): print("bust") else: print("win")
1
118,826,248,156,690
null
260
260
# coding: utf-8 import sys from collections import defaultdict sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # MODの管理をして右から進める N, P = lr() S = sr() dic = defaultdict(int) dic[0] = 1 num = 0 power = 1 answer = 0 if P%2 == 0 or P%5 == 0: x = [i for i, y in enumerate(S, 1) if int(y) % P == 0] answer = sum(x) else: for s in S[::-1]: s = int(s) num += s * power num %= P answer += dic[num] dic[num] += 1 power *= 10; power %= P print(answer) # 14
N, P = map(int, input().split()) S = [int(x) for x in input()] if P == 2: ans = 0 for i in range(N): if S[N-1-i] % 2 == 0: ans += N-i elif P == 5: ans = 0 for i in range(N): if S[N-1-i] % 5 == 0: ans += N-i else: ans = 0 cnt = [0] * P cnt[0] = 1 dec_mod, pre_mod = 1, 0 for i in range(N): mod = (S[N-1-i] * dec_mod + pre_mod) % P ans += cnt[mod] cnt[mod] += 1 dec_mod = dec_mod * 10 % P pre_mod = mod print(ans)
1
58,223,159,850,950
null
205
205
D=int(input()) c=list(map(int,input().split())) s=[] t=[] v=0 lastday=[0 for i in range(26)] for i in range(D): tmp=list(map(int,input().split())) s.append(tmp) for i in range(D): tmp=int(input())-1 t.append(int(tmp)) for i in range(1,D+1): v+=s[i-1][t[i-1]] lastday[t[i-1]]=i for j in range(26): v-=c[j]*(i-lastday[j]) print(v)
n = int(input()) acl = "ACL" * n print(acl)
0
null
6,011,465,904,750
114
69
import sys import copy import math import itertools H = int(input()) cnt = 0 for i in range(int(math.log2(H))+1): cnt+=2**i print(cnt)
ans = 100000 n = int(raw_input()) for i in xrange(n): ans *= 1.05 ans = int((ans+999)/1000)*1000; print ans
0
null
39,960,123,281,780
228
6
a = input().split() n, d = int(a[0]), int(a[1]) x = [] a = d * d res = 0 for i in range(n): [x, y] = input().split() if int(x)**2 + int(y)**2 <= a: res += 1 print(res)
import sys input = sys.stdin.readline N, D = map(int, input().split()) count = 0 for i in range(N): a, b = map(int, input().split()) if (a*a + b*b) <= D*D: count += 1 print(count)
1
5,889,090,208,562
null
96
96
n = int(input()) a = list(map(int, input().split())) tmp = 0 sum = 0 for i in a: if tmp > i: dif = tmp - i sum += dif else: tmp = i print(sum)
n = int(input()) if n % 2 == 0: work = int(n / 2) s = input() a = s[:work] b = s[work:] if a == b: print("Yes") else: print("No") else: print("No")
0
null
75,517,824,978,260
88
279
# -*- coding: utf-8 -*- import collections n, q = map(int, raw_input().split()) prolist = [raw_input().split() for i in range(n)] prolist = collections.deque(prolist) time_sum = 0 while len(prolist): process = prolist.popleft() time = int(process[1]) if time <= q: time_sum += time print "%s %d" %(process[0], time_sum) else: time_sum += q process[1] = str(time-q) prolist.append(process)
from collections import Counter N = int(input()) S = input() cnt = Counter(S) ans = cnt['R']*cnt['G']*cnt['B'] #まずansに要請1を満たす(i, j, k)の組の数を入れておき,ここから,要請2を満たさないものを除いていく。 for i in range(N-2): for j in range(i+1, N-1): k = j + (j - i) #kは j - i = k - j を満たす。ただし,(i, j, k)が要請1を満たしているとは限らない。 if k < N: if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]: ans -= 1 print(ans)
0
null
18,122,532,896,620
19
175
WHITE = 0 GRAY = 1 BLACK = 2 NIL = -1 def dfs(u): global time color[i] = GRAY time += 1 d[u] = time for v in range(n): if m[u][v] and (color[v] == WHITE): dfs(v) color[u] = BLACK time += 1 f[u] = time def next(u): for v in range(nt[u], n + 1): nt[u] = v + 1 if m[u][v]: return v return NIL n = int(input()) m = [[0 for i in range(n + 1)] for j in range(n + 1)] vid = [0] * n d = [0] * n f = [0] * n S = [] color = [WHITE] * n time = 0 nt = [0] * n tmp = [] for i in range(n): nums=list(map(int,input().split())) tmp.append(nums) vid[i] = nums[0] for i in range(n): for j in range(tmp[i][1]): m[i][vid.index(tmp[i][j + 2])] = 1 for i in range(n): if color[i] == WHITE: dfs(i) for i in range(n): print(vid[i], d[i], f[i])
import sys N,K=map(int,input().split()) alist=list(map(int,input().split())) flist=list(map(int,input().split())) alist.sort() flist.sort(reverse=True) #print(alist) #print(flist) def check(m): cnt=0 for i in range(N): if alist[i]*flist[i]>m: cnt+=-(-(alist[i]*flist[i]-m)//flist[i]) #print(m,cnt,K) if cnt<=K: return True else: return False if sum(alist)<=K: print(0) sys.exit(0) baseline=0 for i in range(N): baseline=max(baseline,alist[i]*flist[i]) #print(baseline) l,r=0,baseline while l<=r: mid=(l+r)//2 #print(l,mid,r) if not check(mid-1) and check(mid): print(mid) break elif not check(mid): l=mid+1 else: r=mid-1
0
null
82,467,658,696,700
8
290
import math p=math.pi r=int(input()) print(2*r*p)
r = int(input()) pai = 3.1415 print(2*r*pai)
1
31,454,918,661,498
null
167
167
def dist(x, y, i, j): dx = x[i] - x[j] dy = y[i] - y[j] return (dx * dx + dy * dy) ** 0.5 n = int(input()) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = map(int, input().split()) ans = 0 for i in range(n): for j in range(i + 1, n): ans += dist(x, y, i, j) * 2 / n print(ans)
n = int(input()) xy = [list(map(int,input().split())) for i in range(n)] from itertools import permutations import math m = math.factorial(n) per = permutations(xy,n) d = 0 c = 0 for j in per : for i in range(n-1): d += ((j[i+1][0]-j[i][0])**2 + (j[i+1][1]-j[i][1])**2) ** 0.5 print(d/m)
1
148,340,861,413,712
null
280
280
while True : m, f, r = map(int, input().split()) if(m == -1 and f == -1 and r == -1) : break elif(m == -1 or f == -1) : print("F") elif(m + f >= 80) : print("A") elif(65 <= m + f and m + f < 80) : print("B") elif(50 <= m + f and m + f < 65) : print("C") elif(30 <= m + f and m + f < 50) : if(50 <= r) : print("C") else : print("D") else : print("F")
# -*- coding: utf-8 -*- while True: score = list(map(int, input().split())) if score[0] == -1 and score[1] == -1 and score[2] == -1: break elif -1 in (score[0], score[1]) or (score[0] + score[1]) < 30: print('F') elif (score[0] + score[1]) >= 80: print('A') elif 65 <= (score[0] + score[1]) < 80: print('B') elif 50 <= (score[0] + score[1]) < 65 or (30 <= (score[0] + score[1]) < 50 <= score[2]): print('C') elif 30 <= (score[0] + score[1]) < 50: print('D')
1
1,225,569,582,500
null
57
57
R = int(input()) import math pi = math.pi around = 2 * R * pi print(around)
from math import pi def main(): R = int(input()) print(2*pi*R) if __name__ == '__main__': main()
1
31,193,798,784,220
null
167
167
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools, bisect import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def S(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def LR(n): return [L() for _ in range(n)] alphabets = "abcdefghijklmnopqrstuvwxyz" sys.setrecursionlimit(1000000) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 # nodeをリストに変換したらクソ遅かった import pprint class BalancingTree: def __init__(self, n): self.N = n self.root = self.node(1<<n, 1<<n) def __str__(self): def debug_info(nd): return (nd.value - 1, nd.left.value - 1 if nd.left else None, nd.right.value - 1 if nd.right else None) def debug_node(nd): v = debug_info(nd) if nd.value else () left = debug_node(nd.left) if nd.left else [] right = debug_node(nd.right) if nd.right else [] return [v, left, right] return pprint.PrettyPrinter(indent=4).pformat(debug_node(self.root)) __repr__ = __str__ def append(self, v):# v を追加(その時点で v はない前提) v += 1 nd = self.root while True: # v がすでに存在する場合に何か処理が必要ならここに書く if v == nd.value: return 0 else: mi, ma = min(v, nd.value), max(v, nd.value) if mi < nd.pivot: nd.value = ma if nd.left: nd = nd.left v = mi else: p = nd.pivot nd.left = self.node(mi, p - (p&-p)//2) break else: nd.value = mi if nd.right: nd = nd.right v = ma else: p = nd.pivot nd.right = self.node(ma, p + (p&-p)//2) break def leftmost(self, nd): return self.leftmost(nd.left) if nd.left else nd def rightmost(self, nd): return self.rightmost(nd.right) if nd.right else nd def find_l(self, v): # vより真に小さいやつの中での最大値(なければ-1) v += 1 nd = self.root prev = nd.value if nd.value < v else 0 while True: if v <= nd.value: if nd.left: nd = nd.left else: return prev - 1 else: prev = nd.value if nd.right: nd = nd.right else: return prev - 1 def find_r(self, v): # vより真に大きいやつの中での最小値(なければRoot) v += 1 nd = self.root prev = nd.value if nd.value > v else 0 while True: if v < nd.value: prev = nd.value if nd.left: nd = nd.left else: return prev - 1 else: if nd.right: nd = nd.right else: return prev - 1 def max(self): return self.find_l((1<<self.N)-1) def min(self): return self.find_r(-1) def delete(self, v, nd = None, prev = None): # 値がvのノードがあれば削除(なければ何もしない) v += 1 if not nd: nd = self.root if not prev: prev = nd while v != nd.value: prev = nd if v <= nd.value: if nd.left: nd = nd.left else: return else: if nd.right: nd = nd.right else: return if (not nd.left) and (not nd.right): if nd.value < prev.value: prev.left = None else: prev.right = None elif not nd.left: if nd.value < prev.value: prev.left = nd.right else: prev.right = nd.right elif not nd.right: if nd.value < prev.value: prev.left = nd.left else: prev.right = nd.left else: nd.value = self.leftmost(nd.right).value self.delete(nd.value - 1, nd.right, nd) # v以下のものの中での最大値 def upper_bound(self, v): upper = self.find_r(v) return self.find_l(upper) def lower_bound(self, v): lower = self.find_l(v) return self.find_r(lower) def __contains__(self, v: int) -> bool: return self.find_r(v - 1) == v class node: def __init__(self, v, p): self.value = v self.pivot = p self.left = None self.right = None def main(): N = I() s = S() Q = I() query = LR(Q) trees = {ch: BalancingTree(25) for ch in alphabets} for i, ch in enumerate(s): trees[ch].append(i) for q in query: if q[0] == "1": _, i, c = q i = int(i) - 1 prev = s[i] trees[prev].delete(i) s[i] = c trees[c].append(i) else: _, l, r = q l, r = int(l) - 1, int(r) - 1 count = 0 for _, tree in trees.items(): first = tree.lower_bound(l) if first != tree.root.value - 1 and first <= r: count += 1 print(count) if __name__ == '__main__': main()
#!python3 import sys input = sys.stdin.readline def resolve(): N = int(input()) S = list(input()) Q = int(input()) c0 = ord('a') smap = [1<<(i-c0) for i in range(c0, ord('z')+1)] T = [0]*N + [smap[ord(S[i])-c0] for i in range(N)] for i in range(N-1, 0, -1): i2 = i << 1 T[i] = T[i2] | T[i2|1] ans = [] #print(T) for cmd, i, j in zip(*[iter(sys.stdin.read().split())]*3): i = int(i) - 1 if cmd == "1": if S[i] == j: continue S[i] = j i0 = N + i T[i0] = smap[ord(j)-c0] while i0 > 1: i0 = i0 >> 1 T[i0] = T[i0+i0] | T[i0-~i0] elif cmd == "2": i += N j = int(j) + N d1 = 0 while i < j: if i & 1: d1 |= T[i] i += 1 if j & 1: j -= 1 d1 |= T[j] i >>= 1; j >>=1 ans.append(bin(d1).count('1')) print(*ans, sep="\n") if __name__ == "__main__": resolve()
1
62,622,558,200,540
null
210
210
A,B,C,K = map(int,input().split()) koa = 0 if A<K: koa = A else : koa = K kob = 0 if B<K-koa: kob = B else : kob = K-koa #print (koa) #print (kob) sum = koa+0*kob+(K-(koa+kob))*-1 print (sum)
a, b, c, k = (int(i) for i in input().split()) re = k na = min(a, re) re -= na nb = min(b, re) re -= nb nc = min(c, re) print(na - nc)
1
21,765,687,645,580
null
148
148
N = int(input()) ans = N // 1000 if N % 1000 == 0: print(0) else: print(1000*(ans+1) - N)
N = int(input()) while True: N -= 1000 if N <= 0: break print(abs(N))
1
8,445,253,551,812
null
108
108
import sys input=lambda: sys.stdin.readline().strip() n=int(input()) A=[] # PM=[[0,0] for i in range(n)] for i in range(n): now=0 mini=0 for j in input(): if j=="(": now+=1 else: now-=1 ; mini=min(mini,now) PM[i]=[mini,now] if sum( [PM[i][1] for i in range(n)] )!=0 : print("No") exit() MINI=0 NOW=0 PMf=[PM[i] for i in range(n) if PM[i][1]>=0] PMf.sort() for i in range(len(PMf)): MINI=min(MINI , NOW+PMf[-i-1][0] ) NOW+=PMf[-i-1][1] if MINI<0 : print("No") ; exit() PMs=[PM[i] for i in range(n) if PM[i][1]<0] PMs=sorted(PMs , key=lambda x : x[1]-x[0]) for i in range(len(PMs)): MINI=min(MINI , NOW+PMs[-i-1][0] ) NOW+=PMs[-i-1][1] if MINI<0 : print("No") ; exit() print("Yes")
n=int(input()) print(-n%1000)
0
null
16,105,723,529,672
152
108
from itertools import groupby s = input() k = int(input()) if len(set(s)) == 1: print(len(s)*k//2) exit() g = [len(list(v)) for _, v in groupby(s)] ans = sum(i//2 for i in g)*k if s[0] != s[-1]: print(ans) exit() a, *_, b = g ans -= (a//2 + b//2 - (a+b)//2)*(k-1) print(ans)
import functools import operator n = functools.partial(functools.reduce, operator.mul) N,K = map(int,input().split()) A = list(map(int,input().split())) # print(n(A)) for i in range(K,N): if A[i-K] < A[i]: print("Yes") else: print("No")
0
null
91,236,026,472,962
296
102
def isIncremental(a, b, c): """ a: int b: int c: int returns "Yes" if a < b < c, otherwise "No" >>> isIncremental(1, 3, 8) 'Yes' >>> isIncremental(3, 8, 1) 'No' >>> isIncremental(1, 1, 1) 'No' """ if a >= b: return "No" elif b >= c: return "No" else: return "Yes" if __name__ == '__main__': # import doctest # doctest.testmod() ival = input().split(' ') print(isIncremental(int(ival[0]), int(ival[1]), int(ival[2])))
import math n = int(input()) m = 100000.0 for i in range(n): m = math.ceil((m * 1.05)/1000)*1000 print(int(m))
0
null
199,775,787,790
39
6
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)
S = input() for i in range(1,6): if S == "hi" * i: print("Yes") exit(0) print("No")
0
null
35,407,214,679,708
137
199
from collections import Counter N = int(input()) A = list(map(int, input().split())) L = dict(Counter([i+A[i] for i in range(N)])) R = dict(Counter([i-A[i] for i in range(N)])) cnt = 0 for x in L: cnt += L[x]*R.get(x, 0) print(cnt)
# https://atcoder.jp/contests/abc166/tasks/abc166_e """ 変数分離すれば互いに独立なので、 連想配列でO(N)になる。 """ import sys input = sys.stdin.readline from collections import Counter N = int(input()) A = list(map(int, input().split())) P = (j+1-A[j] for j in range(N)) M = (i+1+A[i] for i in range(N)) dic = Counter(P) res = 0 for m in M: res += dic.get(m,0) print(res)
1
26,213,419,891,370
null
157
157
n = int(input()) d = list(map(int, input().split())) m = 1 num = 0 for s in range(0,n-1): for t in range(m,n): num += (d[s]*d[t]) m += 1 print(num)
a = input() if(a[0]=='7' or a[1]=='7' or a[2]=='7'): print("Yes") else: print("No")
0
null
100,972,206,041,366
292
172
N=int(input()) A=list(map(int, input().split())) ans=[0]*N for i in range(N-1): a=A[i] ans[a-1]+=1 for a in ans: print(a)
n, m = map(int, input().split()) def ark(a, b): return min(abs(a - b), n - abs(a - b)) a, b = n, 1 S = set() for i in range(m): if 2 * ark(a, b) == n or ark(a, b) in S: a -= 1 print(a, b) S.add(ark(a, b)) a -= 1 b += 1
0
null
30,452,736,527,612
169
162
k = int(input()) print('ACL' * k)
N=int(input()) u="ACL" print(u*N)
1
2,183,790,169,498
null
69
69
N,K=map(int,input().split()) a=0 while N>0: a+=1 N=N//K print(a)
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()
1
64,254,224,191,520
null
212
212
input();print(input().count('ABC'))
# -*- coding: utf-8 -*- i = 1 while (i <= 9) : j = 1 while (j <= 9) : print '%sx%s=%s' % (i, j, i * j) j = j + 1 i = i + 1
0
null
49,463,195,512,582
245
1
r = float(input()) pi = 3.141592653589 s = pi * r**2 h = 2 * pi * r print("{:.6f}".format(s), "{:.6f}".format(h))
import sys def ISI(): return map(int, sys.stdin.readline().rstrip().split()) a, b = ISI() if a<2*b:print(0) else:print(a-2*b)
0
null
83,452,628,057,902
46
291
N,K,C=list(map(int,input().split())) S=input() R=[] L=[] i=0 while i<N: if S[i]=="o": R.append(i) i+=C+1 else: i+=1 i=N-1 while i>=0: if S[i]=="o": L.append(i) i-=(C+1) else: i-=1 R=R[:K+1] L=L[:K+1] L.reverse() for i in range(K): if R[i]==L[i]: print(str(R[i]+1),end=" ")
def main(): N, K, C = map(int, input().split()) S = input() i = 0 c = 0 p = [-1] * N while c < K: if S[i] == 'o': p[i] = c c += 1 i += C i += 1 i = N - 1 c = K - 1 q = [-1] * N while c >= 0: if S[i] == 'o': q[i] = c c -= 1 i -= C i -= 1 for i in range(N): if ~p[i] and p[i] == q[i]: print(i + 1) if __name__ == '__main__': main()
1
40,478,678,242,632
null
182
182
A, B = input().split() # 方針:少数の計算を避け、整数の範囲で計算する # [A*B] = [A*(100*B)/100]と見る # Bを100倍して整数に直す操作は、文字列のまま行う A = int(A) B = int(B.replace('.', '')) # 100で割った整数部分を求める操作は、100で割った商を求めることと同じ ans = (A*B) // 100 print(ans)
from decimal import Decimal ''' def main(): a, b = input().split(" ") a = int(a) b = Decimal(b) print(int(a*b)) ''' def main(): a, b = input().split(" ") a = int(a) b = int(b.replace(".","") ) print(a*b // 100) if __name__ == "__main__": main()
1
16,531,500,592,892
null
135
135
#ABC165-A K = int(input()) X = list(map(int,input().split())) if (X[0] // K + 1) * K <= X[1] or X[0] % K == 0: print("OK") else: print("NG")
A, B = [int(_) for _ in input().split()] print(A * B)
0
null
21,082,054,527,900
158
133
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) A = str(input()) B = str(input()) ans = [str(i) for i in range(1,4)] ans.remove(A) ans.remove(B) print(ans[0])
def insert_sort(A, N): 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(*A) N = int(input()) A = [int(n) for n in input().split()]; print(*A) insert_sort(A, N)
0
null
55,226,823,535,104
254
10
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) A, B = input().split() B = int(''.join(B.split('.'))) print(int(A)*B//100)
a, b = map(int, input().replace(".","").split()) print(a*b//100)
1
16,417,581,328,580
null
135
135