code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
def main(): N = int(input()) # 文字列または整数(一変数) print(N**2) if __name__ == '__main__': main()
# 問題:https://atcoder.jp/contests/abc145/tasks/abc145_a print(int(input()) ** 2)
1
145,582,607,361,910
null
278
278
h = int(input()) counter = 0 while h > 0 : h //= 2 counter += 1 print(pow(2, counter) - 1)
print(2**int(input()).bit_length()-1)
1
80,091,857,859,650
null
228
228
#!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)] @lru_cache(maxsize=1024*1024) def fact(n): return math.factorial(n) def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return fact(n) // (fact(r) * fact(n-r)) alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" sys.setrecursionlimit(1000000) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 INF = float("inf") class FactInv: def __init__(self, N, MOD=1000000007): fact, inv = [1]*(N+1), [None]*(N+1) for i in range(1, N+1): fact[i] = fact[i - 1] * i % MOD inv[N] = pow(fact[N], MOD - 2, MOD) for i in range(N)[::-1]: inv[i] = inv[i + 1] * (i + 1) % MOD self.N, self.MOD, self.fact, self.inv = N, MOD, fact, inv def perm(self, a, b): if a > self.N or b > self.N: raise ValueError("\nPermutaion arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b)) return self.fact[a] * self.inv[a-b] % self.MOD def comb(self, a, b): if a > self.N or b > self.N: raise ValueError("\nCombination arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b)) return self.fact[a] * self.inv[b] * self.inv[a-b] % self.MOD def main(): N, K = LI() A = sorted(LI()) factinv = FactInv(N + 1) ans = 0 for i, x in enumerate(A): maxc = factinv.comb(i, K - 1) if i >= K - 1 else 0 minc = factinv.comb(len(A) - i - 1, K - 1) if len(A) - i - 1 >= K - 1 else 0 ans = (ans + x * (maxc - minc)) % MOD print(ans % MOD) if __name__ == '__main__': main()
a,b,c,d = map(int,input().split()) li = list() li.append(a * c) li.append(a * d) li.append(b * c) li.append(b * d) print(max(li))
0
null
49,437,678,541,258
242
77
import math r=int(input()) L=2*math.pi*r print('{0}'.format(L))
# 因数分解して、入れ子で掛け算して、inで入ってるか見る N = int(input()) nums = [] mul = [] for i in range(1, 9 + 1): if N % i == 0: nums.append(i) else: pass # print(nums) for i in nums: for j in nums: mul.append(i * j) # print(mul) if N in mul: print('Yes') else: print('No')
0
null
95,208,905,551,912
167
287
N, K = map(int, input().split()) H = tuple(map(int, input().split())) assert len(H) == N print(len([h for h in H if h >= K]))
n, k = map(int, input().split()) h = list(map(int, input().split())) ans = len([i for i in h if i >= k]) print(ans)
1
179,614,197,905,308
null
298
298
n = int(input()) i = 1 while i <= n: if i%3 == 0: print(' ' + str(i), end="") else: num = i while 0 < num: if num % 10 == 3: print(' ' + str(i), end="") break num //= 10 i += 1 print()
num = input() print "", for x in xrange(1,num+1): if x%3==0: print x, elif "3" in str(x): print x, else: pass
1
929,360,671,708
null
52
52
n = int(input()) # 動的計画法 def fibonacci(n): F = [0]*(n+1) F[0] = 1 F[1] = 1 for i in range(2, n+1): F[i] = F[i-2] + F[i-1] return F f = fibonacci(n) print(f[n])
def solve(n): dp=[1]*(n+1) for i in range(2,n+1): dp[i]=dp[i-1]+dp[i-2] return dp[n] n=int(input()) print(solve(n))
1
1,733,890,168
null
7
7
n = int(input()) ans = [0] * 10010 def get_ans(n): cnt = 0 for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): k = x**2 + y**2 + z**2 + x*y + y*z + z*x if(k <= 10000): ans[k] += 1 return ans ans = get_ans(n) for i in range(1, n+1): print(ans[i])
N = int(input()) ans = [0] * N for i in range(1, 101): for j in range(1, 101): for k in range(1, 101): tmp = i**2+j**2+k**2+i*j+j*k+k*i if tmp <= N: ans[tmp-1] += 1 print(*ans, sep='\n')
1
7,970,790,515,752
null
106
106
def main(): N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) total_T_in_A = [0] * (N+1) total_T_in_B = [0] * (M+1) for i in range(1, N+1): total_T_in_A[i] = total_T_in_A[i-1] + A[i-1] for i in range(1, M+1): total_T_in_B[i] = total_T_in_B[i-1] + B[i-1] result = 0 for i in range(N+1): # A から i 冊読むときにかかる時間 i_A_T = total_T_in_A[i] if K < i_A_T: continue if K == i_A_T: result = max(result, i) continue rem_T = K - i_A_T # total_T_in_B は累積和を格納した、ソート済の配列 # B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す first = total_T_in_B[1] last = total_T_in_B[M] if rem_T < first: result = max(result, i) continue if last <= rem_T: result = max(result, i + M) continue # assume that first <= rem_T <= last first = 1 last = M while first < last: if abs(last - first) <= 1: break mid = (first + last) // 2 if rem_T < total_T_in_B[mid]: last = mid else: first = mid result = max(result, i + first) print(result) main()
a,b=map(int,input().split(' ')) count=0 if a==b: print("Yes") else: print("No")
0
null
47,005,154,783,232
117
231
N = int(input()) N_ri = round(pow(N, 1/2)) for i in range(N_ri, 0, -1): if N % i == 0: j = N // i break print(i + j - 2)
n,m=map(int,input().split()) matA=[list(map(int,input().split())) for i in range(n)] matB=[int(input()) for i in range(m)] for obj in matA: print(sum(obj[i] * matB[i] for i in range(m)))
0
null
80,952,444,520,022
288
56
#26 N,A,B = map(int,input().split()) num = int(N/(A+B)) blue = 0 blue = num*A if (N-num*(A+B)) <= A: blue += (N-num*(A+B)) else: blue += A print(blue)
N,A,B = map(int,input().split()) i = N // (A + B) N -= (A + B) * i cnt_A = i * A if N < A: cnt_A += N else: cnt_A += A print(cnt_A)
1
56,011,680,608,000
null
202
202
from math import gcd from collections import defaultdict N, P = map(int, input().split()) S = list(map(int, input())) answer = 0 if P == 2 or P == 5: # Case when only last digit matters for j in range(N - 1, -1, -1): # Enumerate right endpoint if S[j] % P == 0: answer += j + 1 else: # Enuerate left endpoint from right to left # Find number of right endpoints that make the substr % P == 0 cnts = defaultdict(int) suffix = 0 base = 1 for i in range(N - 1, -1, -1): suffix = (suffix + S[i] * base) % P answer += cnts[suffix] # Substr with length >= 2 answer += 1 if suffix == 0 else 0 # Substr with length = 1 cnts[suffix] += 1 base = base * 10 % P print(answer)
s = input() count = 1; memo = 0; x = 0 for i in range(1, len(s)): if s[i-1] == "<" and s[i] == ">": x += count*(count-1)//2 memo = count count = 1 elif s[i-1] == ">" and s[i] == "<": x += count*(count-1)//2+max(count, memo) memo = 0 count = 1 else: count += 1 else: if s[-1] == "<": x += count*(count+1)//2 else: x += count*(count-1)//2+max(count, memo) print(x)
0
null
107,219,056,299,330
205
285
N = int(input()) a = list(map(int, input().split())) n = 1 C = 0 for ai in a: if ai != n: C += 1 else: n += 1 if n == 1: print('-1') else: print(C)
N = int(input()) a = list(map(int,input().split())) check = 1 ans = 0 for i in a: ans+=1 if i == check: ans -=1 check+=1 if a==[j for j in range(1,N+1)]: print(0) exit() elif ans==N: print(-1) exit() print(ans)
1
114,788,496,504,934
null
257
257
import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) A=[int(i) for i in input().split()] mon=1000 stk=0 for i in range(n-1): if A[i]<=A[i+1]: stk+=mon//A[i] mon%=A[i] else: mon+=stk*A[i] stk=0 mon+=stk*A[-1] print(mon)
n = int(input()) s = input() x = n // 2 print(["Yes", "No"][n % 2 != 0 or s[:x] != s[x:]])
0
null
77,193,453,060,864
103
279
N = int(input()) #stones = list(input()) stones = input() #print(stones) a = stones.count('W') b = stones.count('R') left_side =stones.count('W', 0, b) print(left_side)
N = int(input()) s = input() num_R = s.count('R') print(s[:num_R].count('W'))
1
6,279,432,603,588
null
98
98
while True: H,W = map(int,input().split()) if H==0 and W==0: break for i in range(H): for k in range(W): if (i+k)%2 == 0: print("#",end = "") else: print(".",end = "") print() print()
def print_it(l, n): print(''.join([l[x % 2] for x in range(n)])) matrix = [] while True: values = input() if '0 0' == values: break matrix.append([int(x) for x in values.split()]) sc = ['#', '.'] cs = ['.', '#'] for height, width in matrix: for i in range(height): if 0 == i % 2: print_it(sc, width) else: print_it(cs, width) print()
1
886,144,540,184
null
51
51
n,m = map(int,input().split()) AB = [[] for _ in range(n)] for i in range(m): a,b = map(int,input().split()) AB[a-1].append(b-1) AB[b-1].append(a-1) visited = set() ans = [0]*n stack = [0] for i in stack: # このへんあやしい for j in AB[i]: if j in visited: continue visited.add(j) ans[j] = i+1 stack.append(j) # このへんまで for i in ans[1:]: if i==0: print('No') exit() print('Yes') for i in ans[1:]: print(i)
A, B = map(int,input().split()) import math c = math.gcd(A,B) d = (A*B) / c print(int(d))
0
null
66,878,544,328,930
145
256
n=int(input()) x=[] y=[] for i in range(n): a,b=map(int,input().split()) x.append(a) y.append(b) p=1 for i in range(n): p*=i+1 def D(a,b): a=a-1 b=b-1 return ((x[a]-x[b])**2+(y[a]-y[b])**2)**(0.5) def f(x): ans=0 while x>0: ans+=x%2 x=x//2 return ans def r(x): ans=1 for i in range(x): ans*=(i+1) return ans dp=[[0]*(n+1) for _ in range(2**n)] for i in range(1,2**n): for j in range(1,n+1): for k in range(1,n+1): if (i>>(j-1))&1 and not (i>>(k-1)&1): dp[i+2**(k-1)][k]+=dp[i][j]+r((f(i)-1))*D(j,k) print(sum(dp[2**n-1])/p)
from itertools import permutations from math import sqrt, pow, factorial n = int(input()) xy = [list(map(int, input().split())) for _ in range(n)] def calc(a,b): [x1, y1] = a [x2, y2] = b return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)) sum = 0 for i in permutations(range(n)): distance = 0 for j in range(1, n): distance = calc(xy[i[j]], xy[i[j-1]]) sum += distance print(sum/factorial(n))
1
148,684,958,295,552
null
280
280
import sys sys.setrecursionlimit(10**9) n,m = list(map(int,input().split())) d = {} for i in range(m): fr, to = list(map(int,input().split())) d[fr] = d.get(fr, []) + [to] d[to] = d.get(to, []) + [fr] visited = [0 for i in range(n+1)] def connect(node, i): visited[node] = i if node in d: for neig in d[node]: if visited[neig] == 0: connect(neig, i) ans = 1 for key in range(1,n+1): if visited[key] == 0: connect(key, ans) ans += 1 print(max(visited)-1)
from bisect import bisect_right n, d, a = map(int, input().split()) xh = sorted(list(map(int, input().split())) for _ in range(n)) x = [0] * (n + 1) h = [0] * (n + 1) s = [0] * (n + 1) for i, (f, g) in enumerate(xh): x[i], h[i] = f, g x[n] = 10 ** 10 + 1 ans = 0 for i in range(n): if i > 0: s[i] += s[i - 1] h[i] -= s[i] if h[i] > 0: num = 0 - - h[i] // a ans += num s[i] += num * a j = bisect_right(x, x[i] + d * 2) s[j] -= num * a print(ans)
0
null
41,991,952,968,766
70
230
import sys s_max = -float('inf') s = 0 n = int(input()) r = list(map(int, sys.stdin.read().split())) for i in range(1, n): s = max(s, 0) + r[i] - r[i-1] s_max = max(s, s_max) print(s_max)
import sys def get_maximum_profit(): element_number = int(input()) v0 = int(input()) v1 = int(input()) min_v = min(v0, v1) max_profit = v1-v0 for v in map(int, sys.stdin.readlines()): max_profit = max(max_profit, v-min_v) min_v = min(min_v, v) print(max_profit) if __name__ == '__main__': get_maximum_profit()
1
13,728,862,308
null
13
13
import bisect from collections import deque import math n, d, A = map(int, input().split()) xh = [] for _ in range(n): x, h = map(int, input().split()) xh.append([x, h]) xh.sort(key=lambda x: x[0]) monster_x = [] monster_hp = [] for i in range(n): monster_x.append(xh[i][0]) monster_hp.append(xh[i][1]) dist = 2 * d ans = 0 damage = 0 cum_damage = [0] * (n + 1) for i in range(n): cum_damage[i + 1] += cum_damage[i] damage = cum_damage[i + 1] * A if damage < monster_hp[i]: min_attack_num = math.ceil((monster_hp[i] - damage) / A) index = bisect.bisect_right(monster_x, monster_x[i] + dist) cum_damage[i + 1] += min_attack_num if index < n: t = min(index + 1, n) cum_damage[t] -= min_attack_num ans += min_attack_num print(ans)
n,d,a = map(int,input().split()) xh = [list(map(int,input().split())) for _ in range(n)] xh.sort() ans = 0 att = [0]*n cnt = 0 f = [] f1 = [0]*n for x,h in xh: f.append(h) for i in range(n): tmp = xh[i][0] + 2 * d while cnt < n: if xh[cnt][0] <= tmp: cnt += 1 else: break att[i] = min(cnt-1, n-1) for i in range(n): if f[i] > 0: da = -(-f[i]//a) ans += da f1[i] -= da * a if att[i]+1 < n: f1[att[i]+1] += da * a if i < n-1: f1[i+1] += f1[i] f[i+1] += f1[i+1] print(ans)
1
82,578,061,515,678
null
230
230
N = int(input()) memo = [] memo = [1,1] + [0] * (N - 1) def f(n): if memo[n] == 0: memo[n] = f(n-1) + f(n-2) return(memo[n]) if memo[n] != 0: return(memo[n]) print(f(N))
list =[] i=0 index=1 while(index != 0): index=int(input()) list.append(index) i +=1 for i in range(0,i): if list[i] == 0: break print("Case",i+1,end='') print(":",list[i])
0
null
249,579,472,402
7
42
N = int(input()) S = input() s = list(S) for i in range(len(S)): if (ord(s[i]) - 64 + N) % 26 == 0: p = 90 else: p = (ord(s[i]) - 64 + N) % 26 + 64 s[i] = chr(p) print("".join(s))
N = int(input()) S = input() A = [] for s in S: a = ord(s)+N if a<=90: A.append(chr(a)) else: A.append(chr(64+(a-90))) print(*A,sep="")
1
134,094,273,462,500
null
271
271
n = int(input()) x = 0 for i in range(1, 10): if n % i == 0 and n / i < 10: x += 1 break else: pass if x == 1: print('Yes') else: print('No')
n = int(input()) print('Yes' if any(i*j == n for i in range(1, 10) for j in range(1, 10)) else 'No')
1
160,538,769,371,898
null
287
287
#axino's copy def move(up, bottom, right, left, front, back, direction): if direction == 'N': return(front, back, right, left, bottom, up) elif direction == 'S': return(back, front, right, left, up, bottom) elif direction == 'E': return(left, right, up, bottom, front, back) elif direction == 'W': return(right, left, bottom, up, front, back) def check(up, bottom, right, left, front, back, up_current, front_current): if front_current == front and up_current == up: print(right) elif front_current == front: if left == up_current: print(up) elif bottom == up_current: print(left) elif right == up_current: print(bottom) elif up_current == up: if right == front_current: print(back) elif back == front_current: print(left) elif left == front_current: print(front) else: up, bottom, right, left, front, back = move(up, bottom, right, left, front, back, 'S') check(up, bottom, right, left, front, back, up_current, front_current) up, front, right, left, back, bottom = input().split() times = int(input()) for i in range(times): up_current, front_current = input().split() check(up, bottom, right, left, front, back, up_current, front_current)
def main(): s, t = input().split() print(t, s, sep='') if __name__ == '__main__': main()
0
null
51,901,248,127,940
34
248
n=int(input()) X=input() x=X.count('1') x_plus=int(X,2)%(x+1) keta=n-1 if x==1: for i in range(n): tmp=0 ans=1 if X[i]=='0': tmp+=x_plus tmp+=pow(2,keta,(x+1)) tmp%=(x+1) while tmp: tmp=tmp%(bin(tmp).count('1')) ans+=1 print(ans) else: print(0) keta-=1 else: x_minus=int(X,2)%(x-1) for i in range(n): tmp=0 ans=1 if X[i]=='0': tmp+=x_plus tmp+=pow(2,keta,(x+1)) tmp%=(x+1) while tmp: tmp=tmp%(bin(tmp).count('1')) ans+=1 print(ans) else: tmp+=x_minus tmp-=pow(2,keta,(x-1)) tmp%=(x-1) while tmp: tmp=tmp%(bin(tmp).count('1')) ans+=1 print(ans) keta-=1
N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) loop_flags = [False] * N loops = [] for i in range(N): if loop_flags[i]: continue next_cell = i loop = [] while not loop_flags[next_cell]: loop_flags[next_cell] = True loop.append(C[next_cell]) next_cell = P[next_cell] - 1 if loop: loops.append(loop) # print(loops) ans = C[0] for loop in loops: work_loop_sum = [] now = 0 tmp_ans = 0 one_loop_point = sum(loop) if one_loop_point <= 0 or K <= len(loop): for i in range(1, min(K + 1, len(loop) + 1)): tmp_ans = sum(loop[:i]) for j in range(len(loop)): ans = max(tmp_ans, ans) tmp_ans = tmp_ans - loop[j] + loop[(i + j) % len(loop)] else: for i in range(min(K + 1, len(loop) + 1)): tmp_ans = sum(loop[:i]) + ((K - i) // len(loop)) * one_loop_point for j in range(len(loop)): ans = max(tmp_ans, ans) tmp_ans = tmp_ans - loop[j] + loop[(i + j) % len(loop)] print(ans)
0
null
6,798,964,939,598
107
93
N = int(input()) li = [] for i in input().split(): li.append(int(i)) a = 1 count = 0 for i in li: if a % 2 == 1 and i % 2 == 1: count += 1 a += 1 print(count)
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(N): if i % 2 == 0 and A[i] % 2 == 1: ans += 1 print(ans)
1
7,759,939,189,354
null
105
105
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() S = LI() if len(set(S)) == N: print("YES") else: print("NO") main()
N, M = map(int,input().split()) ans = "Yes" if N == M else "No" print(ans)
0
null
78,269,703,400,648
222
231
n = int(input()) x = list(map(int, input().split())) min_x = 100 * 100 * 100 + 1 for p in range(1, 100+1, 1): total = 0 for xi in x: total += (xi - p) ** 2 min_x = min([min_x, total]) print(min_x)
N = int(input()) X = list(map(int, input().split())) total_list = [] for p in range(min(X), max(X) + 1): total = 0 for x in X: total += (x - p) ** 2 total_list.append(total) print(min(total_list))
1
65,236,317,532,870
null
213
213
N = int(input()) s = [input().split() for _ in range(N)] X = input() for i in range(N): if X == s[i][0]: break ans = 0 for j in range(i+1, N): ans += int(s[j][1]) print(ans)
def upper(word): Word = '' str = list(word) for i in range(len(str)): if str[i].islower(): Word += str[i].upper() else: Word += str[i] return Word key_word = str(upper(input())) sen = [] count = 0 while True: a = str(input()) if a == 'END_OF_TEXT': break a = upper(a) sen.extend(a.split()) for i in range(len(sen)): if sen[i] == key_word: count+= 1 print(count)
0
null
49,303,242,145,794
243
65
n= int(input()) if n%2==0: print(int(n*0.5)) else: print(int(0.5*n)+1)
A, B, C, K = map( int, input().split()) ret = min( A, K ) if A < K: ret -= max( 0, K - A - B ) print( ret )
0
null
40,497,990,133,392
206
148
K, N= map(int, input().split()) A = list(map(int, input().split())) max=K-(A[N-1]-A[0]) for i in range(N-1): a=A[i+1]-A[i] if max<a: max=a print(K-max)
k,n = map(int,input().split(" ")) a = list(map(int,input().split(" "))) m = a[0] + k - a[n-1] for i in range(n-1): l = a[i+1] - a[i] if l > m: m = l ans = k - m print(ans)
1
43,491,733,540,368
null
186
186
#!/usr/bin/env python # coding: utf-8 def gcd ( ax, ay): x = ax y = ay while (True): if x < y : tmp = x x = y y = tmp x=x %y if x == 0: return y elif x == 1: return 1 x,y = map(int, input().split()) print(gcd(x,y))
temp = int(input()) print("Yes" if temp>= 30 else "No")
0
null
2,889,731,835,540
11
95
n = int(input()) if n%2 : print(n//2) else: print(n//2 - 1)
N,M = map(int,input().split()) L = [list(map(int,input().split())) for i in range(M)] dict = {} if M == 0 : if N == 1 : print(0) else : print(10**(N-1)) exit() for x in L : dict.setdefault(x[0],[]) dict[x[0]].append(x[1]) dict.setdefault(1,[1]) for k,v in dict.items(): dict[k] = set(v) ansList = ["0"]*N for i in range(N) : if i+1 in dict : ansList[i] = str(list(dict[i+1])[0]) isZeroHead = 2 <= N and ansList[0] == "0" isOverlapping = any([ 2 <= len(v) for v in dict.values()]) ans = -1 if isZeroHead or isOverlapping else int("".join(ansList)) # print(dict) # print("isZeroHead :",isZeroHead) # print("isOverlapping :",isOverlapping) print(ans)
0
null
107,497,921,577,860
283
208
N = int(input()) ans = "" while N > 0: N -= 1 N, digit = divmod(N, 26) ans += chr(ord('a') + digit) print(ans[::-1])
n=int(input()) abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] ans = '' while n: ans += abc[(n-1)%len(abc)] n = (n-1)//len(abc) print(ans[::-1])
1
11,887,035,718,080
null
121
121
N = int(input()) S, T = input().split() i = '' for j in zip(S, T): for k in j: i += k print(i)
n = int(input()) graph = [-1] + [list(map(int, input().split())) for _ in range(n)] seen = [False]*(n+1) seen[0] = True d = [-1]*(n+1) f = [-1]*(n+1) time = 0 def dfs(v): global time time += 1 d[v] = time seen[v] = True k = graph[v][1] if k > 0: for i in range(k): w = graph[v][i+2] if seen[w] is False: dfs(w) time += 1 f[v] = time v = 0 while v <= n: if seen[v] is False: dfs(v) v += 1 for i in range(1, n+1): print(i, d[i], f[i])
0
null
55,797,198,097,798
255
8
k, n = map(int,input().split()) a = list(map(int,input().split())) n_1 = k - a[-1] + a[0] l = [] # 各家間の距離リスト(i=1,2~) for i in range(n-1): l.append(a[i+1]-a[i]) l.append(n_1) print(k-max(l))
k, n = map(int, input().split()) a = sorted(list(map(int, input().split()))) x = [(a[i]-a[i-1]) for i in range(1,n)] x.append(k-a[n-1]+a[0]) y=sorted(x) print(sum(y[:-1]))
1
43,463,929,872,000
null
186
186
s = input() n = len(s) s_ = s[:(n-1)//2] if s == s[::-1] and s_ == s_[::-1]: print('Yes') else: print('No')
num = int(input()) if num%2==0: print((num//2) / num) else: print(((num//2)+1) / num)
0
null
111,598,274,215,988
190
297
import sys import numpy as np from numba import njit @njit('(i8[:],)', cache=True) def solve(inp): def bitree_sum(bit, t, i): s = 0 while i > 0: s += bit[t, i] i ^= i & -i return s def bitree_add(bit, n, t, i, x): while i <= n: bit[t, i] += x i += i & -i def bitree_lower_bound(bit, n, d, t, x): sum_ = 0 pos = 0 for i in range(d, -1, -1): k = pos + (1 << i) if k <= n and sum_ + bit[t, k] < x: sum_ += bit[t, k] pos += 1 << i return pos + 1 def initial_score(d, ccc, sss): bit_n = d + 3 bit = np.zeros((26, bit_n), dtype=np.int64) INF = 10 ** 18 for t in range(26): bitree_add(bit, bit_n, t, bit_n - 1, INF) ttt = np.zeros(d, dtype=np.int64) last = np.full(26, -1, dtype=np.int64) score = 0 for i in range(d): best_t = 0 best_diff = -INF costs = ccc * (i - last) costs_sum = costs.sum() for t in range(26): tmp_diff = sss[i, t] - costs_sum + costs[t] if best_diff < tmp_diff: best_t = t best_diff = tmp_diff ttt[i] = best_t last[best_t] = i score += best_diff bitree_add(bit, bit_n, best_t, i + 2, 1) return bit, score, ttt def calculate_score(d, ccc, sss, ttt): last = np.full(26, -1, dtype=np.int64) score = 0 for i in range(d): t = ttt[i] last[t] = i score += sss[i, t] - (ccc * (i - last)).sum() return score def update_score(bit, bit_n, bit_d, ccc, sss, ttt, d, q): diff = 0 t = ttt[d] k = bitree_sum(bit, t, d + 2) c = bitree_lower_bound(bit, bit_n, bit_d, t, k - 1) - 2 e = bitree_lower_bound(bit, bit_n, bit_d, t, k + 1) - 2 b = ccc[t] diff -= b * (d - c) * (e - d) diff -= sss[d, t] k = bitree_sum(bit, q, d + 2) c = bitree_lower_bound(bit, bit_n, bit_d, q, k) - 2 e = bitree_lower_bound(bit, bit_n, bit_d, q, k + 1) - 2 b = ccc[q] diff += b * (d - c) * (e - d) diff += sss[d, q] return diff d = inp[0] ccc = inp[1:27] sss = np.zeros((d, 26), dtype=np.int64) for r in range(d): sss[r] = inp[27 + r * 26:27 + (r + 1) * 26] bit, score, ttt = initial_score(d, ccc, sss) bit_n = d + 3 bit_d = int(np.log2(bit_n)) loop = 6 * 10 ** 6 tolerant_min = -3000.0 best_score = score best_ttt = ttt.copy() for lp in range(loop): cd = np.random.randint(0, d) ct = np.random.randint(0, 26) while ttt[cd] == ct: ct = np.random.randint(0, 26) diff = update_score(bit, bit_n, bit_d, ccc, sss, ttt, cd, ct) progress = lp / loop if diff > (1 - progress) * tolerant_min: score += diff bitree_add(bit, bit_n, ttt[cd], cd + 2, -1) bitree_add(bit, bit_n, ct, cd + 2, 1) ttt[cd] = ct if score > best_score: best_score = score best_ttt = ttt.copy() return best_ttt + 1 inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ') ans = solve(inp) print('\n'.join(map(str, ans)))
x = int(input()) yen_500 = 0 yen_5 = 0 amari = 0 happy = 0 if x>= 500: yen_500 = x//500 amari = x - 500 * yen_500 yen_5 = amari//5 happy = 1000 * yen_500 + 5 * yen_5 print(happy) else: yen_5 = x//5 happy = 5 * yen_5 print(happy)
0
null
26,195,707,836,990
113
185
from collections import Counter s = input() n = len(s) dp = [0] mod = 2019 a = 0 for i in range(n): a = a + int(s[n-i-1]) * pow(10, i, mod) a %= mod dp.append(a%mod) ans = 0 c = Counter(dp) for value in c.values(): ans += value * (value-1) / 2 print(int(ans))
def inN(): return int(input()) def inL(): return list(map(int,input().split())) def inNL(n): return [list(map(int,input().split())) for i in range(n)] s = input() n = int(s) l = len(s) cnt = 0 mod = [0]*2019 m = 0 for i in range(l): m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019 mod[m] += 1 cnt += mod[0] for i in range(2019): if mod[i] > 1: cnt += (mod[i]*(mod[i]-1))/2 #print(i) print(int(cnt))
1
30,889,565,850,224
null
166
166
def main(): print(list(set(["ABC", "ARC"])-{input()})[0]) if __name__ == "__main__": main()
word = input() if word == "ABC": print("ARC") else: print("ABC")
1
24,027,419,899,222
null
153
153
n = int(input()) A = list(map(int, input().split())) maxV = (10 ** 6 + 1) sieve = [i for i in range(maxV)] p = 2 while p*p < maxV: if sieve[p] == p: for q in range(p*2, maxV, p): if sieve[q] == q: sieve[q] = p p += 1 from math import gcd g = 0 primes = set() for a in A: g = gcd(g, a) v = a if g > 1: print('not coprime') exit() for a in A: temp_prime = set() while a > 1: prime = sieve[a] temp_prime.add(prime) a = a // prime for t in temp_prime: if t in primes: print('setwise coprime') exit() primes.add(t) print('pairwise coprime')
X,K,D = map(int,input().split()) A = abs(X) ans = 0 if A >= D*K: print( A - (D * K)) else : e = A//D K -= e A %= D if K%2 == 0: print(A) else: print(D-A)
0
null
4,666,091,069,976
85
92
N = int(input()) P = list(map(int,input().split())) a = 0 s = 10**6 for p in P: if p<s: a+=1 s = min(s,p) print(a)
n = int(input()) l = list(map(int, input().split())) s = 0 m = l[0] for i in range(n): if m >= l[i]: m = l[i] s += 1 print(s)
1
85,518,853,798,910
null
233
233
rooms = [0] * (4*3*10) n = input(); for i in xrange(n): b,f,r,v = map(int, raw_input().split()) rooms[(b-1)*30+(f-1)*10+(r-1)] += v sep = "#" * 20 for b in xrange(4): for f in xrange(3): t = 30*b + 10*f print ""," ".join(map(str, rooms[t:t+10])) if b < 3: print sep
N = int(input()) ans = "" while N > 0: N -= 1 q, r = N//26, N%26 ans += chr(ord("a") + r) N = q print(ans[::-1])
0
null
6,578,226,621,302
55
121
N = input() ans = "No" for s in N: if s == "7": ans = "Yes" break print(ans)
N = input() flag = 0 for n in N: if int(n) == 7: flag = 1 break if flag==0: print("No") else: print("Yes")
1
34,417,298,613,190
null
172
172
def main(): P = 2019 S = [int(s) for s in input()] ans = 0 if P == 2: for i, v in enumerate(S, start=1): if v % 2 == 0: ans += i elif P == 5: for i, v in enumerate(S, start=1): if v == 0 or v == 5: ans += i else: cnt = [0]*P d = 1 pre = 0 cnt[pre] += 1 for v in S[::-1]: v *= d v += pre v %= P cnt[v] += 1 d *= 10 d %= P pre = v ans = sum(cnt[i]*(cnt[i]-1)//2 for i in range(P)) print(ans) if __name__ == '__main__': main()
S = input() N = len(S) A = [int(S[i]) for i in range(N)] A = A[::-1] MOD = 2019 p10 = [1] * N for i in range(1, N): p10[i] = (p10[i - 1] * 10) % MOD for i in range(N): A[i] = (A[i] * p10[i]) % MOD cumsum = [A[0]] * N for i in range(1, N): cumsum[i] = (cumsum[i - 1] + A[i]) % MOD cnt = [0] * MOD cnt[0] = 1 for i in range(N): cnt[cumsum[i]] += 1 ans = 0 for i in range(MOD): ans += cnt[i] * (cnt[i] - 1) // 2 print(ans)
1
30,830,020,676,950
null
166
166
a,b,c=map(int,input().split()) a1=b b1=a a2=c c1=a1 print(a2, b1, c1)
x, y, z = [int(i) for i in input().split(" ")] print(z, x, y)
1
37,805,881,847,370
null
178
178
def main(): n = input() res = 0 for ni in n: res = (res + int(ni)) % 9 print(('Yes', 'No')[res != 0]) if __name__ == '__main__': main()
N=str(input()) NN=0 for i in range(len(N)): NN=NN+int(N[i]) if NN%9==0:print('Yes') else:print('No')
1
4,408,977,606,770
null
87
87
N=int(input()) Taro=0 Hanako=0 for i in range(N): T,H=map(str,input().split()) if T<H: Hanako+=3 elif H<T: Taro+=3 else: Hanako+=1 Taro+=1 print(Taro,Hanako)
import math import sys import bisect import array m=10**9 + 7 sys.setrecursionlimit(1000010) (N,K) = map(int,input().split()) A = list( map(int,input().split())) # print(N,K,A) B = list( map(lambda x: x % K, A)) C = [0] x = 0 i = 0 for b in B: x = (x + b ) % K C.append((x-i-1) % K) i += 1 # print(B,C) E={} ans=0 for i in range(N+1): if C[i] in E: ans += E[C[i]] E[C[i]] = E[C[i]] + 1 else: E[C[i]] = 1 if i >= K-1: E[C[i-K+1]] = E[C[i-K+1]] - 1 if E[C[i-K+1]] == 0: E.pop(C[i-K+1]) print(ans) exit(0)
0
null
69,536,283,770,202
67
273
import os import sys import numpy as np def solve(N, U, V, AB): G = [[0]*0 for _ in range(N+1)] for idx_ab in range(len(AB)): a, b = AB[idx_ab] G[a].append(b) G[b].append(a) P1 = np.zeros(N+1, dtype=np.int64) def dfs1(u): st = [u] while st: v = st.pop() p = P1[v] for u in G[v]: if p != u: st.append(u) P1[u] = v dfs1(U) path_u2v = [U] v = V while v != U: v = P1[v] path_u2v.append(v) path_u2v.reverse() l = len(path_u2v) half = (l-2) // 2 c = path_u2v[half] ng = path_u2v[half+1] Depth = np.zeros(N+1, dtype=np.int64) def dfs2(c): st = [c] P = np.zeros(N+1, dtype=np.int64) while st: v = st.pop() p = P[v] d = Depth[v] for u in G[v]: if p != u and u != ng: st.append(u) P[u] = v Depth[u] = d + 1 dfs2(c) c_ = path_u2v[l-1-half] v = c_ while v != c: Depth[v] = 0 v = P1[v] d = l%2 ans = max(Depth) + half + d return ans # >>> numba compile >>> numba_config = [ [solve, "i8(i8,i8,i8,i8[:,:])"], ] 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, u, v = map(int, input().split()) if N==2: print(0) return AB = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N-1, 2) ans = solve(N, u, v, AB) print(ans) main()
from fractions import gcd def lcm(a,b): return a*b//gcd(a,b) n,m=map(int,input().split()) a=list(map(int,input().split())) h=list(map(lambda x:x//2,a)) l=1 for i in range(n): l=lcm(l,h[i]) for i in range(n): if (l//h[i])%2==0: print(0) exit() print((m//l+1)//2)
0
null
109,955,145,298,888
259
247
s = input() line = int(input()) for i in range(line): param = input().split(" ") if len(param) == 4: ope, a, b, p = param else: ope, a, b = param a,b = int(a), int(b) if ope == "print": print(s[a:b+1]) elif ope == "reverse": rev = s[a:b+1][::-1] s = (s[:a] + rev + s[b+1:]) elif ope == "replace": s = (s[:a] + p + s[b+1:])
moto = input() num = int(input()) for i in range(num): order = input().split() if order[0] == "print": m,n=int(order[1]),int(order[2]) print(moto[m:n+1]) elif order[0] == "reverse": m,n=int(order[1]),int(order[2]) moto = moto[:m]+moto[m:n+1][::-1]+moto[n+1:] elif order[0] == "replace": m,n,l=int(order[1]),int(order[2]),order[3] moto = moto[:m]+order[3]+moto[n+1:]
1
2,111,876,605,540
null
68
68
n, k = [ int( val ) for val in raw_input( ).split( " " ) ] w = [] maxW = sumW = 0 for i in range( n ): num = int( raw_input( ) ) sumW += num w.append( num ) if maxW < num: maxW = num minP = 0 if 1 == k: minP = sumW elif n == k: minP = maxW else: left = maxW right = 100000*10000 while left <= right: middle = ( left+right )//2 truckCnt = i = loadings = 0 while i < n: loadings += w[i] if middle < loadings: truckCnt += 1 if k < truckCnt+1: break loadings = w[i] i += 1 if truckCnt+1 <= k: minP = middle if k < truckCnt+1: left = middle + 1 else: right = middle - 1 print( minP )
def is_ok(W, truck, middle): loaded = 0 for t in range(truck): this_total = 0 while this_total + W[loaded] <= middle: this_total += W[loaded] loaded += 1 if loaded == len(W): return True return False def meguru_bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(w, k, mid): ok = mid else: ng = mid return ok n, k = map(int,input().split()) w = [0]*n for i in range(n): w[i] = int(input()) ans = meguru_bisect(-1,10**10+1) print(ans)
1
90,529,391,878
null
24
24
from collections import Counter a = int(input()) num_list = list(map(int, input().split())) D = Counter(num_list) for i in range(a): print(D[i+1])
import bisect,collections,copy,heapq,itertools,math,numpy,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()) N = I() A = LI() ans_list = [0] * N for a in A: ans_list[a - 1] += 1 for i in range(N): print(ans_list[i])
1
32,442,381,138,180
null
169
169
values = input() W, H, x, y, r = [int(x) for x in values.split()] flag = True if x - r < 0 or x + r > W: flag = False if y - r < 0 or y + r > H: flag = False if flag: print('Yes') else: print('No')
# coding: utf-8 # Here your code ! W, H , x ,y ,r = list(map(int, input().split())) t1_x = x + r t1_y = y + r t2_x = x - r t2_y = y - r if 0 <= t1_x <= W and 0 <= t1_y <= H and 0 <= t2_x <= W and 0 <= t2_y <= H: print("Yes") else: print("No")
1
451,330,385,488
null
41
41
import sys input = sys.stdin.readline N = int(input()) S = input()[:-1] R = S.count('R') accR = [0] for Si in S: accR.append(accR[-1]+(1 if Si=='R' else 0)) ans = 10**18 for i in range(N+1): ans = min(ans, abs(i-R)+abs(i-accR[i])) print(ans)
n=input() if n=='ABC': print('ARC') else: print('ABC')
0
null
15,304,386,265,040
98
153
A, B = map(int, input().split()) ans = 0 for i in range(B): ans += A if ans%B == 0: break print(ans)
from scipy.sparse.csgraph import floyd_warshall import numpy as np N, M, L = map(int, input().split()) inf = 10**9 + 1 dist = [[inf] * N for i in range(N)] for i in range(M): A, B, C = map(int, input().split()) dist[A-1][B-1] = dist[B-1][A-1] = C dist = floyd_warshall(dist, directed=False) dist = np.where(dist <= L, 1, inf) dist = floyd_warshall(dist, directed=False) dist = np.where(dist < inf, dist-1, -1) Q = int(input()) for i in range(Q): s, t = map(int, input().split()) print(int(dist[s-1, t-1]))
0
null
144,101,758,811,852
256
295
if __name__ == '__main__': n = int(input()) R = [int(input()) for i in range(n)] minv = R[0] maxv = R[1] - R[0] for j in range(1, n): if (maxv < R[j] - minv): maxv = R[j] - minv if (R[j] < minv): minv = R[j] print(maxv)
def count(i, s): left = right = 0 for e in s: if e == "(": left += 1 else: if left == 0: right += 1 else: left -= 1 return left-right, left, right, i n = int(input()) S = [input() for i in range(n)] s1 = [] s2 = [] for i, e in enumerate(S): c = count(i, e) # print(i, c) if c[0] >= 0: s1.append((c[2], c[3])) else: s2.append((-c[1], c[3])) s1.sort() s2.sort() # print(s1, s2) s = [] for e in s1: s.append(S[e[1]]) for e in s2: s.append(S[e[1]]) # print(s) _, left, right, _ = count(0, "".join(s)) if left == right == 0: print("Yes") else: print("No")
0
null
11,855,973,816,648
13
152
hon=[2,4,5,7,9] pon=[0,1,6,8] bon=[3] N=int(input()) if N%10 in hon: print('hon') elif N%10 in pon: print('pon') else: print('bon')
N = int(input()) if (N % 10 == 0) or (N % 10 == 1) or (N % 10 == 6) or (N % 10 == 8): print("pon") elif N % 10 == 3: print("bon") else: print("hon")
1
19,199,760,506,812
null
142
142
x='123' for _ in range(2): x=x.replace(input(),'') print(x)
import itertools N = int(input()) l = [] for i in itertools.permutations(list(range(1,N+1))): l.append(i) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) a = 1 b = 1 for i in l: if i < P: a += 1 for i in l: if i < Q: b += 1 print(abs(a-b))
0
null
105,898,369,043,536
254
246
import fractions while True: try: a,b = map(int,input().split()) except: break print(fractions.gcd(a,b),a*b // fractions.gcd(a,b))
import sys e=[list(map(int,x.split()))for x in sys.stdin];n=e[0][0]+1 [print(*x)for x in[[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])]for c in e[1:n]]]
0
null
709,533,451,280
5
60
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap class Mod: def __init__(self, m): self.m = m def add(self, a, b): return (a + b) % self.m def sub(self, a, b): return (a - b) % self.m def mul(self, a, b): return ((a % self.m) * (b % self.m)) % self.m def div(self, a, b): return self.mul(a, pow(b, self.m-2, self.m)) def pow(self, a, b): return pow(a, b, self.m) class Combination: def __init__(self, n, mod): g1 = [1, 1] g2 = [1, 1] inverse = [0, 1] for i in range(2, n + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod//i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) self.MOD = mod self.N = n self.g1 = g1 self.g2 = g2 self.inverse = inverse def __call__(self, n, r): if (r < 0 or r > n): return 0 r = min(r, n-r) return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD @mt def slv(K, S): M = 10**9+7 C = Combination(2*(10**6), M) MOD = Mod(M) ans = 0 S = len(S) N = S + K for k in range(K+1): r = K -k a = MOD.pow(26, r) b = MOD.mul(MOD.pow(25, k), C(k+S-1, k)) ans = MOD.add(ans, MOD.mul(a, b)) return ans def main(): K = read_int() S = read_str() print(slv(K, S)) if __name__ == '__main__': main()
n = int(input()) ans = [1]*n T = [[-1]*n for _ in range(n)] for ni in range(n): a = int(input()) for ai in range(a): x, y = map(int,input().split()) T[ni][x-1] = y mx = 0 for i in range(pow(2,n)): tmx = -1 B = bin(i)[2:].zfill(n) S = [i for i,b in enumerate(B) if b=='1'] for s in S: _Ts = [i for i,t in enumerate(T[s]) if t==1] _Tf = [i for i,t in enumerate(T[s]) if t==0] if not (set(_Ts)<=set(S) and set(_Tf)&set(S)==set()): tmx = 0 break if tmx==-1: tmx=len(S) mx = max(mx, tmx) print(mx)
0
null
67,429,211,359,016
124
262
import sys readline = sys.stdin.readline N = int(readline()) S = readline().rstrip() ans = 0 numlist = [[] for i in range(10)] for i in range(len(S)): numlist[int(S[i])].append(i) ans = 0 import bisect for i in range(1000): target = str(i).zfill(3) now = 0 for j in range(len(target)): tar = int(target[j]) pos = bisect.bisect_left(numlist[tar], now) if pos >= len(numlist[tar]): break now = numlist[tar][pos] + 1 else: ans += 1 print(ans)
A,B=list(map(int,input().split())) def gcd(A, B): if B==0: return(A) else: return(gcd(B, A%B)) print(gcd(A,B))
0
null
64,450,868,014,470
267
11
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if A > B: x = A A = B B = x if V <= W: ans="NO" elif T*V+A-B >= T*W: ans="YES" else: ans="NO" print(ans)
# coding: utf-8 # Your code here! import numpy as np import sys N,A,B=map(int,input().split()) count=int(N/(A+B)) s=N%(A+B) if s<=A: print(A*count+s) else: print(A*count+A)
0
null
35,493,930,654,708
131
202
from collections import deque import numpy as np H, W = map(int, input().split()) grid = [input() for _ in range(H)] ini = -1 q = deque() dy = (-1, 0, 1, 0) dx = (0, 1, 0, -1) ans = 0 for y in range(H): for x in range(W): dist = [[ini for _ in range(W)] for _ in range(H)] if grid[y][x] == "#": continue dist[y][x] = 0 q.append((y, x)) while(len(q) > 0): oy, ox = q.popleft() for di in range(4): ny = oy + dy[di] nx = ox + dx[di] if (ny < 0 or ny >= H or nx < 0 or nx >= W): continue if grid[ny][nx] == "#": continue if dist[ny][nx] != ini: continue dist[ny][nx] = dist[oy][ox] + 1 q.append((ny, nx)) ans = max(np.max(dist), ans) print(ans)
H, W = map(int, input().split()) maze = [input() for i in range(H)] direction = [ (0, 1), (1, 0), (-1, 0), (0, -1) ] def bfs(sy, sx): reached = [[-1] * W for _ in range(H)] reached[sy][sx] = 0 from collections import deque que = deque([[sy, sx]]) #d_max = 0 while que: iy, ix = que.popleft() for d in direction: tx, ty = ix + d[0], iy + d[1] if tx >= W or ty >= H or tx < 0 or ty < 0: continue if reached[ty][tx] != -1 or maze[ty][tx] == '#': continue reached[ty][tx] = reached[iy][ix] + 1 #d_max = max(reached[ty][tx], d_max) que.append([ty, tx]) d_max = 0 for i in range(H): for j in range(W): d_max = max(d_max,reached[i][j]) return d_max ans = 0 for i in range(H): for j in range(W): if maze[i][j] == '.': ans = max(ans, bfs(i, j)) # for i in range(H): # for j in range(i, W): # for k in range(H): # for l in range(k, W): # if maze[i][j] == '#' or maze[k][l] == '#': # continue # else: # ans = max(ans, bfs(i, j, k, l)) print(ans)
1
94,711,336,537,532
null
241
241
#!/usr/bin python3 # -*- coding: utf-8 -*- import sys input = sys.stdin.readline def main(): a, b, c = map(int, input().split()) x = ((c-a-b)**2-4*a*b > 0 ) and (c > a+b) print('NYoe s'[x::2]) if __name__ == '__main__': main()
L = input().split() n = len(L) A = [] top = -1 for i in range(n): if L[i] not in {"+","-","*"}: A.append(int(L[i])) top += 1 else: if(L[i] == "+"): A[top - 1] = A[top - 1] + A[top] elif(L[i] == "-"): A[top - 1] = A[top -1] - A[top] elif(L[i] == "*"): A[top - 1] = A[top - 1] * A[top] del A[top] top -= 1 print(A[top])
0
null
25,697,301,764,312
197
18
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from heapq import heappush, heappop from functools import reduce from decimal import Decimal, ROUND_CEILING def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 R, C, K = MAP() dp = [[0]*4 for _ in range(C+1)] field = [[0]*(C+1)] + [[0]*(C+1) for _ in range(R)] for _ in range(K): r, c, v = MAP() field[r][c] = v for i in range(1, R+1): dp_next = [[0]*4 for _ in range(C+1)] for j in range(1, C+1): up_max = max(dp[j]) p = field[i][j] dp_next[j][0] = max(up_max, dp[j-1][0]) dp_next[j][1] = max(up_max+p, dp_next[j-1][1], dp_next[j-1][0]+p) dp_next[j][2] = max(dp_next[j-1][2], dp_next[j-1][1]+p) dp_next[j][3] = max(dp_next[j-1][3], dp_next[j-1][2]+p) dp = dp_next print(max(dp[-1]))
from copy import deepcopy def getval(): r,c,k = map(int,input().split()) item = [[0 for i in range(c)] for i in range(r)] for i in range(k): ri,ci,vi = map(int,input().split()) item[ri-1][ci-1] = vi return r,c,k,item def main(r,c,k,item): #DP containing the information of max value given k items picked in i,j prev = [[0 for i in range(4)]] inititem = item[0][0] prev[0] = [0,inititem,inititem,inititem] for i in range(1,r): initval = prev[i-1][3] temp = [] cur = item[i][0] for j in range(4): temp.append(initval) for j in range(1,4): temp[j] += cur prev.append(temp) for j in range(1,c): init = deepcopy(prev[0]) for i in range(1,4): init[i] = max(prev[0][i],prev[0][i-1]+item[0][j]) curcol = [init] for i in range(1,r): cur = item[i][j] left = curcol[-1] down = prev[i] temp = [max(left[3],down[0])] for k in range(1,4): temp.append(max(max(left[3],down[k-1])+cur,down[k])) curcol.append(temp) prev = curcol print(max(prev[-1])) if __name__=="__main__": r,c,k,item = getval() main(r,c,k,item)
1
5,549,494,868,448
null
94
94
N = int(input()) a = list(map(int,input().split())) i=0 for x,y in enumerate (a): b=x+1 if b%2!=0 and y%2!=0: i+=1 print(i)
N = int(input()) i = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる s = 0 for j in range(0,N,2): if i[j] % 2 == 1 : s += 1 print(s)
1
7,788,712,209,148
null
105
105
def main(): a,b = input().split() b = b[0] + b[2:] print(int(a)*int(b)//100) if __name__ == "__main__": main()
a,b= input().split() a = int(a) b,c = map(int,b.split(".")) print(a*(100*b+c)//100)
1
16,521,989,127,670
null
135
135
A=int(input()) #pr#print(A) int(A) B=int(input()) if A + B == 3: print(3) elif A+B==4: print(2) else: print(1)
a =sorted( [int(input()) for i in range(2)]) print("1" if a == [2,3] else "2" if a == [1,3] else "3")
1
110,800,075,705,880
null
254
254
D, T, S = map(int, input().split()) print("Yes" if(((T*S) - D) >= 0) else "No")
n = int(input()) a_list = list(map(int, input().split())) dai = 0 for i in range(1, n): if a_list[i] < a_list[i-1]: dai += a_list[i-1] - a_list[i] a_list[i] += a_list[i-1] - a_list[i] # print(dai) else: continue print(dai)
0
null
4,044,543,459,890
81
88
x=int(input()) for i in range(x,10**6+1): now=i-1 flag=0 while(2<=now): if i%now==0: flag=1 break now-=1 if flag==0: print(i) break
import math n = int(input()) def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True i = 1 while i > 0: if is_prime(n): break n += 1 print (n)
1
105,798,173,162,670
null
250
250
def backoutput(y): if y.isupper(): return y.lower() elif y.islower(): return y.upper() else: return y first_input = list(map(backoutput, input())) print(*first_input, sep='')
from sys import stdin s = list(stdin.readline()) for i in range(len(s)): if s[i].islower(): s[i] = s[i].upper() elif s[i].isupper(): s[i] = s[i].lower() print(*s, sep="", end="")
1
1,523,357,694,560
null
61
61
a, b, c = map(int, input().split()) if a % b == 0: print(a//b * c) else: print((a//b + 1) * c)
from collections import Counter N=int(input()) Alist=list(map(int,input().split())) count=Counter(Alist) flag=True for value in count.values(): if value>1: flag=False print('YES' if flag else 'NO')
0
null
39,195,296,838,200
86
222
n,k,s = map(int, raw_input().split()) r = [s] * k if s == 10 ** 9: for i in range(n - k): r.append((10 ** 9) - 2) else: for i in range(n - k): r.append(s + 1) for a in r: print a,
#input K = int(input()) S = str(input()) #output # (o以外) o (o以外) o (f以外) f (何でも) #こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。 mod = pow(10, 9) + 7 n_ = 5 * pow(10, 6) fun = [1] * (n_+1) for i in range(1, n_+1): fun[i] = fun[i-1] * i % mod rev = [1] * (n_+1) rev[n_] = pow(fun[n_], mod-2, mod) for i in range(n_-1, 0, -1): rev[i] = rev[i+1] * (i+1) % mod def cmb(n,r): if n < 0 or r < 0 or r > n: return 0 return fun[n] * rev[r] % mod * rev[n-r] % mod #重複組み合わせはH(n, r) = cmb(n+r-1, r) L = len(S) answer = 0 for i in range(K+1): answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(L-1+i, i) answer %= mod print(answer)
0
null
51,769,468,912,600
238
124
a, b = map(int, input().split()) print('%d %d %f' % (a / b, a % b, a / b))
# -*- coding: utf-8 -*- def main(): Num = input().split() area = int(Num[0]) * int(Num[1]) sur = 2 * (int(Num[0])+int(Num[1])) print(area, sur) if __name__ == '__main__': main()
0
null
437,004,902,052
45
36
# coding=UTF-8 from collections import deque from operator import itemgetter from bisect import bisect_left, bisect import itertools import sys import math import numpy as np import time sys.setrecursionlimit(10**6) input = sys.stdin.readline queue = deque() def main(): k = int(input()) queue.extend([1, 2, 3, 4, 5, 6, 7, 8, 9]) for i in range(k-1): x = queue[0] queue.popleft() if x % 10 != 0: queue.append(10 * x + x % 10 - 1) queue.append(10 * x + x % 10) if x % 10 != 9: queue.append(10 * x + x % 10 + 1) print(queue[0]) if __name__ == '__main__': main()
now = int(input()) if now >= 30: print('Yes') else: print('No')
0
null
22,998,464,182,800
181
95
from math import log2 N = int(input()) log = int(log2(N)+1) ans = (2**log-1) print(ans)
h = int(input()) ans = 0 n_enemy = 1 while h > 1: h //= 2 ans += n_enemy n_enemy *= 2 if h == 1: ans += n_enemy print(ans)
1
79,947,364,647,712
null
228
228
import math H = int(input()) print(2**(math.floor(math.log2(H))+1)-1)
import sys def main(args): h, n = map(int,input().split()) magic = [0]*n maxim = 0 for i in range(n): dam, mp = map(int,input().split()) magic[i] = (dam, mp) maxim = max(maxim, dam) damage = [float('inf')]*(2*10**4) damage[0] = 0 for i in range(max(2*h, 2*maxim)): for m in magic: dam, mp = m damage[i] = min(damage[i-dam]+mp, damage[i]) print(min(damage[h:])) if __name__ == '__main__': main(sys.argv[1:])
0
null
80,608,459,942,548
228
229
x,y,a,b,c = map(int,input().split()) p = list(map(int,input().split())) q = list(map(int,input().split())) r = list(map(int,input().split())) p.sort(reverse=True) q.sort(reverse=True) apples = p[:x] + q[:y] + r apples.sort(reverse=True) print(sum(apples[:x+y]))
from collections import deque x,y,a,b,c = map(int,input().split()) ls = [] la = list(map(int,input().split())) lb = list(map(int,input().split())) lc = list(map(int,input().split())) la.sort(reverse=True) lb.sort(reverse=True) lc.sort(reverse=True) for i in range(a): ls.append([la[i],1]) for j in range(b): ls.append([lb[j],2]) for l in range(c): ls.append([lc[l],3]) ls.sort(key=lambda x:x[0],reverse=True) ls = deque(ls) s,t,k = 0,0,0 cnt = 0 while True: now = ls.popleft() if now[1] == 1: if s < x: cnt += now[0] s += 1 elif now[1] == 2: if t < y: cnt += now[0] t += 1 else: cnt += now[0] k += 1 if s + t + k == x + y: print(cnt) break
1
44,954,319,160,310
null
188
188
n,p=map(int,input().split()) s=input() ans=0 if p==2: for i in range(n): if int(s[i])%2==0: ans+=i+1 print(ans) elif p==5: for i in range(n): if int(s[i])%5==0: ans+=i+1 print(ans) else: s=s[::-1] accum=[0]*n d=dict() for i in range(n): accum[i]=int(s[i])*pow(10,i,p)%p for i in range(n-1): accum[i+1]+=accum[i] accum[i+1]%=p accum[-1]%=p #print(accum) for i in range(n): if accum[i] not in d: if accum[i]==0: ans+=1 d[accum[i]]=1 else: if accum[i]==0: ans+=1 ans+=d[accum[i]] d[accum[i]]+=1 #print(d) print(ans)
from decimal import Decimal a,b,c = map(int,input().split()) d = Decimal(0.5) ans = "Yes" if a**d + b**d < c**d else "No" print(ans)
0
null
54,858,965,107,908
205
197
S = input() flag = 0 N = len(S) s1 = int((N-1)/2) s2 = int((N+3)/2) if S[0:s1] == S[s1+1:]: flag = 1 else: flag = 0 if S[s2-1:] == S[:s2-2]: flag = 1 else: flag = 0 if flag == 1: print("Yes") else: print("No")
S = input() s = list(S) f = s[:int((len(s)-1)/2)] l = s[int((len(s)+3)/2-1):] if f == l: while len(f) > 1: if f[0] == f[-1]: f.pop(0) f.pop() if len(f) <= 1: while len(l) > 1: if l[0] == l[-1]: l.pop(0) l.pop() if len(l) <= 1: print('Yes') else: print('No') else: print('No') else: print('No')
1
46,323,120,555,740
null
190
190
#coding:utf-8 while True: h, w = map(int, raw_input().split()) if h == w == 0: break print(w * "#") for i in xrange(h - 2): print("#" +"." *(w - 2) +"#") print(w * "#") print("")
n, m = map(int, input().split()) number = [0] * n cou = [0] * n #logging.debug(number)# for i in range(m): s, c = map(int, input().split()) s -= 1 if cou[s] > 0 and c != number[s]: print(-1) exit() else: cou[s] += 1 number[s] = c #logging.debug("number = {}, cou = {}".format(number, cou)) if n > 1 and number[0] == 0 and cou[0] >= 1: print(-1) exit() elif n > 1 and number[0] == 0: number[0] = 1 number = map(str, number) print(''.join(number))
0
null
30,851,066,927,264
50
208
import sys from operator import itemgetter N = int(input()) S = sys.stdin.read().split() HT_high = [] HT_low = [] for s in S: t = 0 h = 0 for c in s: if c == "(": h += 1 else: h -= 1 if h < t: t = h if h >= 0: HT_high.append((h, t)) else: HT_low.append((h, t)) HT_high.sort(key=itemgetter(1), reverse=True) HT_low.sort(key=lambda x: x[0]-x[1], reverse=True) h0 = 0 for h, t in HT_high + HT_low: if h0 + t < 0: print("No") exit() h0 += h if h0 != 0: print("No") else: print("Yes")
import sys input = sys.stdin.readline def main(): n = int(input()) a = [] b = [] for i in range(n): s = input() c1, c2 = 0, 0 for i in range(len(s)): if s[i] == "(": c2 += 1 if s[i] == ")": if c2: c2 -= 1 else: c1 += 1 if c1 >= c2: b.append((c2, c1)) else: a.append((c1, c2)) a.sort() b.sort(reverse=True) ans = False sub = 0 for value in a: k1, k2 = value[0], value[1] if sub < k1: ans = True break sub += k2-k1 for value in b: k2, k1 = value[0], value[1] if ans or sub < k1: ans = True break sub += k2-k1 print("No" if ans or sub else "Yes") if __name__ == "__main__": main()
1
23,806,274,981,470
null
152
152
X = int(input()) bank = 100 cnt = 0 while bank < X: bank = bank + bank//100 cnt += 1 print(cnt)
n=raw_input() k=n.split() k.sort() print k[0], print k[1], print k[2]
0
null
13,768,742,824,628
159
40
N =int(input()) S, T = input().split() for i in range(N): print(S[i], end="") print(T[i], end="") print()
N = int(input()) S, T = map(list, input().split(' ')) result = '' for s, t in zip(S, T): result = result + s + t print(result)
1
112,205,425,318,868
null
255
255
S,T=list(input().split()) T+=S print(T)
from itertools import accumulate n = int(input()) a = list(map(int, input().split())) ac = list(accumulate(a)) total = ac[-1] ans = float('inf') for i in range(n-1): l, r = ac[i], total - ac[i] ans = min(ans, abs(l-r)) print(ans)
0
null
122,792,056,759,360
248
276
tmp = 0 while True: i = raw_input().strip().split() a = int(i[0]) b = int(i[1]) if a == 0 and b == 0: break if a > b: tmp = a a = b b = tmp print a,b
import numpy as np def cumsum(x): return list(np.cumsum(x)) def cumsum_number(N,K,x): ans=[0]*(N-K+1) number_cumsum = cumsum(x) number_cumsum.insert(0,0) for i in range(N-K+1): ans[i]=number_cumsum[i+K]-number_cumsum[i] return ans """ int #整数 float #小数 #for for name in fruits: #fruitの頭から操作 print(name) #リスト list0 = [] #リスト生成 list0 = [1,2,3,4] #初期化 list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0] list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] list1 = list(map(int, input().split())) # 複数の入力をリストに入れる number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに list1 = list1 + [6, 7, 8] #リストの追加 list2.append(34) #リストの追加 最後に()内が足される list.insert(3,10) #リストの追加 任意の位置(追加したい位置,追加したい値) len(list4) #リストの要素数 max(sa) #list saの最小値 list5.count(2) #リスト(文字列も可)内の2の数 list1.sort() #並び替え小さい順 list1.sort(reverse=True) #並び替え大きい順 set(list1) #list1内の重複している要素を削除し、小さい順に並べる sum([2,3, ,3]) #リストの合計 abs(a) #aの絶対値 max(a,b) min(a,b) #最大値 最小値 text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える) exit(0) #強制終了 cumsum(リスト) #累積和をリストで返す cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す """ N=int(input()) ans=0 for j in range(N): if (j+1)%3!=0 and (j+1)%5!=0: ans += j+1 print(ans)
0
null
17,731,173,253,694
43
173
import math x = int(input()) # -100 ~ 100 ^ 5 pow5 = {} for i in range(-1000, 1001): pow5[i] = int(math.pow(i, 5)) for i in range(-1000, 1001): a = x + pow5[i] for j in range(-1000, 1001): if a == pow5[j]: print(j, i) exit()
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline n, x, m = map(int, input().split()) ans = 0 aa = x ans += aa aset = set([aa]) alist = [aa] for i in range(1,n): aa = pow(aa,2,m) if aa in aset: offset = alist.index(aa) loop = alist[offset:i] nloop, tail = divmod(n-offset, len(loop)) ans += sum(loop)*(nloop-1) ans += sum(loop[0:tail]) break else: ans += aa aset.add(aa) alist.append(aa) print(ans)
0
null
14,109,216,564,000
156
75
import sys def input(): return sys.stdin.readline().rstrip() class mod_comb3: def __init__(self,mod=10**9+7,n_max=1): self.mod,self.n_max=mod,n_max self.fact,self.inv,self.factinv=[1,1],[0,1],[1,1] if 1<n_max:setup_table(n_max) def comb(self,n,r): if r<0 or n<r:return 0 if self.n_max<n:self.setup_table(n) return self.fact[n]*(self.factinv[r]*self.factinv[n-r]%self.mod)%self.mod def setup_table(self,t): for i in range(self.n_max+1,t+1): self.fact.append(self.fact[-1]*i%self.mod) self.inv.append(-self.inv[self.mod%i]*(self.mod//i)%self.mod) self.factinv.append(self.factinv[-1]*self.inv[-1]%self.mod) self.n_max=t def main(): n,k=map(int,input().split()) A=list(map(int,input().split())) com=mod_comb3() A.sort() mod=10**9+7 max_a,min_a=0,0 for i in range(n): max_a=(max_a+A[i]*com.comb(i,k-1))%mod min_a=(min_a+A[i]*com.comb(n-i-1,k-1))%mod print((max_a-min_a)%mod) if __name__=='__main__': main()
n,k = map(int,input().split()) a = list(map(int,input().split())) mod = 10**9 + 7 a.sort(reverse = True) class Combination: """ O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms) 使用例: comb = Combination(1000000) print(comb(5, 3)) # 10 """ def __init__(self, n_max, mod=10**9+7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n+1): fac.append(fac[i-1] * i % self.mod) facinv.append(facinv[i-1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n+1) modinv[1] = 1 for i in range(2, n+1): modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod return modinv comb = Combination(100010) ans = 0 for i in range(n-k+1): ans += a[i] * comb(n-i-1, k-1) ans %= mod a = a[::-1] for i in range(n-k+1): ans -= a[i] * comb(n-i-1, k-1) ans %= mod print(ans)
1
95,616,935,628,492
null
242
242
from math import sqrt from math import floor n = int(input()) ans = 10 ** 12 m = floor(sqrt(n)) for i in range(1,m+1): if n % i == 0: j = n // i ans = min(ans,i+j-2) print(ans)
n = int(input()) tp = ((1,1),(1,-1)) for i in range(200): for j in range(200): for k in tp: a,b = i*k[0],j*k[1] if((a**5 - b**5)==n): print(a,b) exit()
0
null
93,861,856,640,270
288
156
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy # from collections import Counter,defaultdict,deque # from itertools import permutations, combinations # from heapq import heappop, heappush # # input = sys.stdin.readline # sys.setrecursionlimit(10**8) # mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() S = input() ans = 0 for a,b,c in itertools.product(map(str,range(10)),repeat=3): aa = False bb = False for s in S: if aa == False and s == a: aa = True continue if bb == False and aa == True and s == b: bb = True continue if aa == True and bb == True and s == c: ans += 1 break print(ans)
def input_li(): return list(map(int, input().split())) def input_int(): return int(input()) N = input_int() S = input() ans = 0 for i in range(1000): str_i = str(i) s = '0' * (3 - len(str_i)) + str_i idx = 0 for j in range(N): if S[j] == s[idx]: idx += 1 if idx == 3: ans += 1 break print(ans)
1
128,543,779,505,372
null
267
267
N = int(input()) ac = 0 wa = 0 re = 0 tle = 0 for i in range(N): s = input() if s=="AC": ac += 1 elif s=="WA": wa += 1 elif s=="RE": re += 1 elif s=="TLE": tle += 1 print("AC x "+str(ac)) print("WA x "+str(wa)) print("TLE x "+str(tle)) print("RE x "+str(re))
import bisect n = int(input().strip()) S = list(input().strip()) L=[[] for _ in range(26)] for i,s in enumerate(S): L[ord(s)-ord("a")].append(i) q = int(input().strip()) for _ in range(q): query=input().strip().split() if query[0]=="1": i=int(query[1]) i-=1 c=query[2] if S[i]!=c: delInd=bisect.bisect_left(L[ord(S[i])-ord("a")],i) del L[ord(S[i])-ord("a")][delInd] bisect.insort(L[ord(c)-ord("a")], i) S[i]=c else: l,r=map(int,[query[1],query[2]]) l-=1; r-=1 ans=0 for j in range(26): ind=bisect.bisect_left(L[j],l) if ind<len(L[j]) and L[j][ind]<=r: ans+=1 print(ans)
0
null
35,754,447,452,490
109
210
import math while(1): a=0 n=int(input()) if n==0: break; s=list(map(int,input().split())) m=sum(s)/len(s) for i in range(n): a=a+pow(s[i]-m,2) print(math.sqrt(a/n))
import statistics while True: n = int(input()) if n == 0: break scores = list((int(x) for x in input().split())) std = statistics.pstdev(scores) print("{0:.8f}" . format(round(std,8)))
1
193,649,395,962
null
31
31
x,y,a,b,c = map(int,input().split()) p = list(map(int,input().split())) q = list(map(int,input().split())) r = list(map(int,input().split())) p = sorted(p,reverse=True) q = sorted(q,reverse=True) r = sorted(r,reverse=True) lis = p[:x] lis.extend(q[:y]) lis = sorted(lis) #print(lis) ans = [] lr = len(r) for i in range(len(lis)): if i<lr: ans.append(max(lis[i],r[i])) else: ans.append(lis[i]) print(sum(ans))
def sep(): return map(int,input().strip().split(" ")) def lis(): return list(sep()) import sys sys.setrecursionlimit(10**6) x,y,a,b,c=sep() red=lis() green=lis() colorless=lis() red.sort(reverse=True) green.sort(reverse=True) colorless.sort() red=red[:x][::-1] green=green[:y][::-1] i=0 j=0 while(colorless): if j>=y and i>=x: break elif j<y and i>=x: if colorless[-1]>green[j]: green[j]=colorless[-1] colorless.pop() j+=1 else: break elif i<x and j>=y: if colorless[-1]>red[i]: red[i]=colorless[-1] colorless.pop() i+=1 else: break elif red[i]<=green[j]: if colorless[-1]>red[i]: red[i]=colorless[-1] colorless.pop() i+=1 else: break else: if colorless[-1]>green[j]: green[j]=colorless[-1] colorless.pop() j+=1 else: break #print(red,green) print(sum(red) + sum(green))
1
44,970,944,772,700
null
188
188
from sys import stdin N = int(stdin.readline().rstrip()) C = stdin.readline().rstrip() rc = C.count('R') ans = 0 for i in range(rc): if C[i] == 'W': ans += 1 print(ans)
N,M = input().split() N = int(N) M = int(M) if N == M : print('Yes') else : print('No')
0
null
44,847,885,849,362
98
231
from collections import* n,u,v=map(int,input().split()) e=[[]for _ in range(n+1)] INF=10**18 d=[INF]*(n+1) for _ in range(n-1): a,b=map(int,input().split()) e[a]+=[b] e[b]+=[a] q=deque([(v,0)]) while q: now,c=q.popleft() d[now]=c for to in e[now]: if d[to]!=INF:continue q.append((to,c+1)) q=[(u,0)] ans=0 vis=[1]*(n+1) while q: now,c=q.pop() vis[now]=0 f=1 for to in e[now]: if vis[to]: f=0 if d[to]>c+1:q+=[(to,c+1)] if d[to]==c+1:ans=max(c+1,ans) else:ans=max(c,ans) if len(e[now])==1:ans=max(d[to],ans) print(ans)
import numpy as np A,B,N = map(int,input().split()) if B <= N: x = B-1 print(int(np.floor(A*x/B))) else: print(int(np.floor(A*N/B)))
0
null
72,831,254,861,144
259
161
# D - Caracal vs Monster H = int(input()) def rec(x): if x==1: return 1 else: return 2*rec(x//2)+1 print(rec(H))
H = int(input()) ans = 0 cnt = 0 while True: ans += 2 ** cnt if H == 1: break H = H//2 cnt += 1 print(ans)
1
80,141,004,636,672
null
228
228
N = int(input()) d = {} for i in range(N): s = input() if s in d.keys(): d[s] += 1 else: d[s] = 1 mx = 0 for i in d.values(): mx = max(mx, i) for i in sorted(d.items()): if i[1] == mx: print(i[0])
line = list(input()) for k,v in enumerate(line): line[k] = v.swapcase() print(''.join(line))
0
null
35,962,018,396,436
218
61
letter = input() if "a" <= letter <= "z": print("a") elif "A" <= letter <= "Z": print("A")
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy time = 1 def dfs(node): global time if visited[node] != -1: return visited[node] = 0 d[node] = time time += 1 for v in edge[node]: dfs(v) f[node] = time time += 1 if __name__ == "__main__": n = int(input()) edge = [] for i in range(n): u,k,*v_li = map(int,input().split()) for j in range(len(v_li)): v_li[j] -= 1 u-=1 edge.append(v_li) d = {} f = {} visited = [-1]*n for i in range(n): dfs(i) for i in range(n): print(i+1,d[i],f[i])
0
null
5,617,754,701,952
119
8
# -*- coding: utf-8 -*- from scipy.sparse.csgraph import floyd_warshall N, M, L = map(int,input().split()) d = [[0 for i in range(N)] for j in range(N)] for i in range(M): x,y,z = map(int,input().split()) d[x-1][y-1] = z d[y-1][x-1] = z for i in range(N): d[i][i] = 0 d = floyd_warshall(d, directed = False) LN = [[0 for i in range(N)] for j in range(N)] for i in range(N): for j in range(N): if d[i][j] <= L: LN[i][j] = 1 LN[j][i] = 1 LN = floyd_warshall(LN, directed = False) s = [] t = [] Q = int(input()) for i in range(Q): s1, t1 = map(int,input().split()) s.append(s1) t.append(t1) for i in range(Q): if LN[s[i]-1][t[i]-1] == float("inf"): print(-1) else: print(int(LN[s[i]-1][t[i]-1]-1))
#--------------------------------------------------------------- # coding: utf-8 # Python 3+ import sys #file = open("test.txt") file = sys.stdin a, b, c = map(int, file.readline().split()) if a < b < c : print("Yes") else : print("No")
0
null
86,599,116,989,362
295
39