code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
a, b = map(int, input().split()) q=a%b if q==0: print(int(a/b)) else: print(int(a/b)+1)
N=int(input()) N_26=[] while N>0: N-=1 N_mod=N%26 N=N//26 N_26.append(chr(97+N_mod)) print("".join(list(reversed(N_26))))
0
null
44,490,762,059,920
225
121
import math def average(l): return sum(l) / len(l) def var(l): a = average(l) return sum(map(lambda x: (x-a)**2, l)) / len(l) def std(l): return math.sqrt(var(l)) if __name__ == '__main__': while True: n = int(input()) if n == 0: break l = [int(i) for i in input().split()] print("{0:.5f}".format(std(l)))
import math while 1: n=input() if n==0: break s=map(int,raw_input().split()) m=0.0 for i in range(n): m+=s[i] m=m/n a=0.0 for i in range(n): a+=(s[i]-m)**2 a=(a/n)**0.5 print a
1
190,921,584,640
null
31
31
from collections import defaultdict iim = lambda: map(int, input().rstrip().split()) def resolve(): N = int(input()) A = list(iim()) ans = 0 dp = [0]*N for i, ai in enumerate(A): x = i + ai if x < N: dp[x] += 1 x = i - ai if x >= 0: ans += dp[x] print(ans) resolve()
def main(): N = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] + sum(A[i//2+1] for i in range(N-2)) print(ans) if __name__ == "__main__": main()
0
null
17,787,535,024,950
157
111
def main(A,B,C,K): ans=False while K >= 0: if A < B: if B < C: ans=True return ans else: C = C * 2 else: B = B * 2 K=K-1 return ans A,B,C=map(int, input().split()) K=int(input()) ans=main(A,B,C,K) print('Yes' if ans else 'No')
A, B, C = list(map(int, input().split())) K = int(input()) while(B <= A): B *= 2 K -= 1 while(C <= B): C *= 2 K -= 1 if(K >= 0): print("Yes") else: print("No")
1
6,897,962,444,450
null
101
101
def readinput(): n=int(input()) return n def main(n): if n==2: return 2 nmax=2*10**5 isprime=[1]*(nmax) isprime[0]=0 isprime[1]=0 m=4 while(m<nmax): isprime[m]=0 m+=2 for i in range(3,nmax,2): if isprime[i]==0: continue else: if i>=n: return i m=2*i while(m<nmax): isprime[m]=0 m+=i return -1 if __name__=='__main__': n=readinput() ans=main(n) print(ans)
n = int(input()) import math N = math.ceil(math.sqrt(n)) from collections import defaultdict counter = defaultdict(int) from collections import defaultdict counter = defaultdict(int) for x in range(1,N + 1): answer_x = x * x for y in range(x, N + 1): answer_y = answer_x + y * y + x * y if answer_y > n: continue for z in range(y, N + 1): answer_z = answer_y + z * z + x * z + y * z if answer_z <= n: if x == y and x == z: counter[answer_z] += 1 elif x == y or x == z or y == z: counter[answer_z] += 3 else: counter[answer_z] += 6 for i in range(1,n+1): print(counter[i])
0
null
56,954,362,179,232
250
106
N=int(input()) if N%2==1: print(0) exit(0) ans=N//10 cur=N//10 while cur//5>0: cur//=5 ans+=cur print(ans)
n = int(input()) if n%2==1: print(0) else: ans = 0 div = 10 pt = 1 while div<=n: ans += n//div div *=5 print(ans)
1
116,128,278,738,308
null
258
258
#!/usr/bin/env python3 import sys from itertools import product def input(): return sys.stdin.readline()[:-1] def main(): N, M, X = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(N)] for m in range(1, M + 1): s = 0 for n in range(N): s += A[n][m] if s < X: print(-1) exit() # bit全探索 # repeat=2だと(0,0), (0,1), (1,0), (1,1)になる ans = 10 ** 15 for i in product([0,1], repeat=N): c = 0 for m in range(1, M + 1): s = 0 for n in range(N): if i[n] == 1: s += A[n][m] if s >= X: c += 1 if c == M: money = 0 for n in range(N): if i[n] == 1: money += A[n][0] ans = min(ans, money) print(ans) if __name__ == '__main__': main()
from math import ceil from collections import deque n,d,a = map(int,input().split()) m = [list(map(int,input().split())) for _ in range(n)] m.sort() l = [(x, ceil(h/a)) for x,h in m] ans = 0 damage = 0 que = deque([]) for x,h in l: while que and que[0][0] < x: s,t = que.popleft() damage -= t need = max(0, h - damage) ans += need damage += need if need: que.append((x+2*d, need)) print(ans)
0
null
52,277,107,325,040
149
230
n,m=map(int,input().split()) h=list(map(int,input().split())) t=['W']*n for i in range(m): a,b=map(int,input().split()) if h[a-1]>=h[b-1]: t[b-1]='L' if h[a-1]<=h[b-1]: t[a-1]='L' print(t.count('W'))
a,b = input().split() a=int(a) b=int(b) if a>=1 and a<=9 and b>=1 and b<=9: print(a*b) else: print("-1")
0
null
91,392,017,628,758
155
286
# coding: utf-8 # Here your code ! import sys import collections #import numpy import statistics import unittest def calculate_standard_deviation(): lines = sys.stdin.readlines() data = [] i = 0 while(i < len(lines)): if(int(lines[i].rstrip()) == 0) : break else: data.append([ int(score) for score in lines[i+1].rstrip().split() ]) i += 2 for scores in data: mean = statistics.mean(scores) print(statistics.pstdev(scores)) # print(numpy.std(scores)) def __input_error(): print("input error") return -1 class __TestValueClass(unittest.TestCase): def testEqual(self,func,tuples): self.testFunction(self.assertEqual,func,tuples) def testFunction(self,assertfunc,func,tuples): #tuples[index] = ([*arguments of func], compared value) for item in tuples: try: if isinstance(item[0], collections.Iterable): assertfunc(func(*item[0]),item[1]) else: assertfunc(func(item[0]),item[1]) except Exception as msg: swidth = 15 print("="*50) print("-- Assertion Error in '" + func.__name__ + "' --") print("arguments".ljust(swidth)+":",item[0]) print("compared value".ljust(swidth)+":",item[1]) print("message".ljust(swidth)+":") print(msg) sys.exit() print(func.__name__,": succeeded") #test if __name__ == "__main__" : calculate_standard_deviation() # test = __TestValueClass()
a = [] while True: d = list(map(int,input().split())) if d == [0,0]: break a.append(d) for H,W in a: print('#'*W) for i in range(0,H-2): print('#'+'.'*(W-2)+'#') print('#'*W) print('')
0
null
498,595,130,770
31
50
import math i = 0 k = 0 q = 0 while k == 0 : N = int(input()) if N == 0 : k = k + 1 else : S = list(map(float, input().split())) while k ==0 and i < N : m = sum(S) / N q = q + ((S[i] - m)**2) i = i + 1 print(math.sqrt(q / N)) q = 0 i = 0
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): A, B, K = map(int, readline().split()) if A>=K: A -= K else: B = max(B-(K-A),0) A = 0 print(A, B) if __name__ == '__main__': main()
0
null
51,953,507,383,592
31
249
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): from itertools import permutations N = int(readline()) P = tuple(map(int, readline().split())) Q = tuple(map(int, readline().split())) d = {x: i for i, x in enumerate(permutations(range(1, N + 1)))} print(abs(d[Q] - d[P])) if __name__ == '__main__': main()
#import sys #input = sys.stdin.readline import math from collections import defaultdict,deque ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) ips=lambda:input().split() """========main code===============""" t=1 for _ in range(t): l,r,d=ml() ans=0 for i in range(l,r+1): if(i%d==0): ans+=1 print(ans)
0
null
54,289,542,672,600
246
104
N, M = map(int,input().split()) ans = "Yes" if N == M else "No" print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, m = map(int, readline().split()) if n == m: print('Yes') else: print('No')
1
83,156,833,136,428
null
231
231
N = int(input()) T = [input() for i in range(N)] T.sort() c = 1 pre = T[0] for i in range(1,N): if T[i] == pre: pass else: c += 1 pre = T[i] print(c)
from itertools import permutations n = int( input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) a = [i for i in range(1,n+1)] x = list(permutations(a,n)) y = x.index(p) z = x.index(q) print(abs(y-z))
0
null
65,745,782,939,552
165
246
a, b = map(str, input().split()) if (len(a) == 1 and len(b) ==1): print(int(a) * int(b)) else: print(-1)
a,b=[int(i) for i in input().split()] if(a<=9 and b<=9): print(a*b) else: print(-1)
1
158,100,500,554,690
null
286
286
N = input() ans = 'ABC' if N == 'ARC' else 'ARC' print(ans)
n = int(input()) """ 6:3 3141:13 314159265358:9 """ #約分 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) # divisors.sort() return divisors r = len(make_divisors(n-1)) - 1 w = make_divisors(n) for wi in w: if wi == 1: continue i = 1 while n % (wi**i) == 0: i += 1 if (n / (wi**(i-1))) % wi == 1: r += 1 print(r)
0
null
32,844,936,104,370
153
183
N,K = map(int,input().split()) R,S,P = map(int,input().split()) T = input() V = {"s":R, "p":S, "r":P} ans = 0 for i in range(K): check = T[i] ans += V[T[i]] while True: i += K if i >= N: break if check == T[i]: check = -1 else: ans += V[T[i]] check = T[i] print(ans)
n,k=map(int,input().split()) r,s,p=map(int,input().split()) t=input() t2 = [[] for _ in range(k)] score = [0]*n for i,c in enumerate(t): t2[i%k].append(c) score = {'r':p,'s':r,'p':s} total = 0 for t3 in t2: if len(t3)==0: continue if len(t3)==1: total += score[t3[0]] continue for i in range(len(t3)-1): if t3[i] == 'e': continue total += score[t3[i]] if t3[i] == t3[i+1]: t3[i+1]='e' if t3[-1] != 'e': total += score[t3[-1]] print(total)
1
106,879,847,399,562
null
251
251
from math import gcd _, *e = [[*map(int, t.split())] for t in open(0)] ans = 1 mod = 10 ** 9 + 7 slope_dict = {} zeros = 0 for x, y in e: if x == y == 0: zeros += 1 else: d = gcd(x, y) x //= d y //= d if x < 0 or x == 0 < y: x, y = -x, -y s = 0 if y < 0: x, y, s = -y, x, 1 if (x, y) not in slope_dict: slope_dict[(x, y)] = [0, 0] slope_dict[(x, y)][s] += 1 for k in slope_dict: ans = ans * (pow(2, slope_dict[k][0], mod) + pow(2, slope_dict[k][1], mod) - 1) % mod print((ans + zeros - 1) % mod)
N = int(input()) A = input().split() ans = 'YES' if len(A) - len(set(A)) == 0 else 'NO' print(ans)
0
null
47,453,312,504,600
146
222
import itertools, math N = int(input()) lst1 = [] for _ in range(N): x, y = map(int, input().split()) lst1.append((x, y)) lst2 = list(itertools.combinations(lst1, 2)) p = math.factorial(N) * (N - 1) c = len(list(itertools.combinations(lst1, 2))) total = 0 for i in lst2: d = ((i[1][0] - i[0][0]) ** 2 + (i[1][1] - i[0][1]) ** 2) ** 0.5 total += d num = int(p/c) fct = math.factorial(N) print(total * num / fct)
from itertools import combinations N = int(input()) town = [] for n in range(N): x, y = map(int,input().split()) town.append((x,y)) ans = 0 for i,j in combinations(town,2): ans += ((i[0]-j[0])**2 + (i[1]-j[1])**2)**0.5 print (2*ans/N)
1
148,505,194,669,348
null
280
280
n,a,b = map(int,input().split()) Mod = 10**9+7 def Mod_pow(x, n): x = x%Mod if n==0: return 1 elif n%2==1: return (x*Mod_pow(x,n-1)%Mod) else: return (Mod_pow(x*x,n/2)%Mod) def comb(n,r): x,y = 1,1 for i in range(n-r+1,n+1): x = x*i%Mod for i in range(1,r+1): y = y*i%Mod #この問題の特徴,フェルマーの小定理よりyで除算することはy^(Mod-2)をかけることと同値 y = Mod_pow(y,Mod-2) return x*y%Mod ans = (Mod_pow(2,n)-1-comb(n,a)-comb(n,b)) while ans<0: ans += Mod print(ans)
n, a, b = map(int,input().split()) M = 10**9+7 Answer = pow(2,n,M)-1 factorial=1 for i in range(1,a+1): factorial = (factorial*(n+1-i)*pow(i,M-2,M))%M Answer -= factorial%M factorial =1 for j in range(1,b+1): factorial = (factorial*(n+1-j)*pow(j,M-2,M))%M Answer -= factorial%M Answer = Answer%M print(Answer)
1
65,871,477,576,010
null
214
214
#!/usr/bin/env python3 a, b = map(int, input().split()) print(a * b * (a < 10 and b < 10) or -1)
import sys input = sys.stdin.readline from collections import defaultdict def prime(n: int) -> defaultdict: f, i = defaultdict(int), 2 while i * i <= n: while n % i == 0: f[i] += 1; n //= i i += 1 if n != 1: f[n] = 1 return f def solve(n: int) -> int: if n == 1: return 1 r, l = n, 0 while (r - l) > 1: m = (l + r) // 2 if m * (m + 1) // 2 <= n: l = m else: r = m return l n, res = int(input()), 0 for k, v in prime(n).items(): res += solve(v) print(res)
0
null
87,254,220,448,066
286
136
k , n= map(int, input().split()) a_list = list(map(int, input().split())) diff_list = [] for i in range(n-1): diff_list.append(a_list[i+1]- a_list[i]) diff_list.append(k-a_list[n-1] + a_list[0]) print(sum(diff_list)-max(diff_list))
n = int(input()) g = [[] for _ in range(n)] inv = [0] * n for i in range(n - 1): a, b = map(int, input().split()) g[a - 1].append((b - 1, i)) inv[a - 1] += 1 g[b - 1].append((a - 1, i)) inv[b - 1] += 1 k = max(inv) print(k) s = [0] d = [-1] * n d[0] = [-2] ans = [0] * (n - 1) while s: p = s.pop() c = 1 for node, idx in g[p]: if d[node] == -1: if c == d[p]: c += 1 d[node] = c ans[idx] = c c += 1 s.append(node) for x in ans: print(x)
0
null
89,330,520,014,048
186
272
N, K = list(map(int, input().split(' '))) table = {l for l in range(1, N + 1)} have = set() for i in range(K): d = int(input()) nums = list(map(int, input().split(' '))) have = have | set(nums) ans = len(table - have) print(ans)
# inputList = list(map(int, '''6 # 5 6 4 2 1 3'''.split())) # N = inputList.pop(0) def formatting(nums): for i in range(len(nums)): if i != len(nums) - 1: print(nums[i], end=' ') else: print(nums[i]) def selectionSort(A, N): count = 0 for i in range(N - 1): minJ = i for j in range(i, N): if A[j] < A[minJ]: minJ = j if i != minJ: A[i], A[minJ] = A[minJ], A[i] count += 1 formatting(A) print(count) N = int(input()) inputList = list(map(int, input().split())) selectionSort(inputList, N)
0
null
12,387,571,589,382
154
15
n, m, x = map(int, input().split()) c = [0] * n a = [0] * n for i in range(n): xs = list(map(int, input().split())) c[i] = xs[0] a[i] = xs[1:] ans = 10 ** 9 for i in range(2 ** n): csum = 0 asum = [0] * m for j in range(n): if (i >> j) & 1: csum += c[j] for k in range(m): asum[k] += a[j][k] if len(list(filter(lambda v: v >= x, asum))) == m: ans = min(ans, csum) print(-1 if ans == 10 ** 9 else ans)
s = input() t = input() if t[:len(s)]==s: print("Yes") else: print("No")
0
null
21,912,131,497,476
149
147
#!/usr/bin/env python3 def main(): import sys input = sys.stdin.readline K = int(input()) S = input().rstrip() if len(S) <= K: print(S) else: print(S[:K] + '...') if __name__ == '__main__': main()
n = int(input()) A = sorted(list(map(int, input().split()))) dp = [0] * (10 ** 6 + 10) for x in A: i = 0 while x + i <= 10 ** 6 + 10: if dp[(x-1)] == 2: break else: dp[(x-1) + i] += 1 i += x cnt = 0 for x in A: if dp[x-1] == 1: cnt += 1 print(cnt)
0
null
17,118,255,378,212
143
129
def main(): a, b, c = map(int, input().split()) if (a == b and b != c) or (b == c and a != b) or (a == c and a != b): print('Yes') else: print('No') main()
import collections li = list(map(int,input().split())) c = collections.Counter(li) if len(c) == 2: print('Yes') else: print('No')
1
67,713,186,240,882
null
216
216
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) inf = 10**17 mod = 10**9+7 n = int(input()) s = input() ans = 0 for i in range(n): if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C': ans += 1 print(ans)
# Sheep and Wolves S, W = map(int, input().split()) print(['safe', 'unsafe'][W >= S])
0
null
64,054,752,388,720
245
163
import sys input = sys.stdin.readline from collections import defaultdict def main(): N, M = map(int, input().split()) passed = set([]) penalty = defaultdict(int) for _ in range(M): p, S = input().split() if S == "WA" and p not in passed: penalty[p] += 1 elif S == "AC": passed.add(p) ans = sum([penalty[p] for p in passed]) print(len(passed), ans) if __name__ == '__main__': main()
num = int(input()) i = 1 while i <= 9: j = 1 while j <= 9: if (i * j) / num == 1: print("Yes") exit() else: j += 1 i += 1 print("No")
0
null
126,558,834,455,212
240
287
# coding: utf-8 a, b = map(int, input().split()) ans = -1 if a < 10 and b < 10: ans = a * b print(ans)
import numpy as np n, t = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort() dp = np.zeros(t, dtype=np.int64) ans = 0 for a, b in ab: ans = max(ans, dp[-1] + b) np.maximum(dp[a:], dp[:-a] + b, out=dp[a:]) print(ans)
0
null
155,460,878,184,900
286
282
n = int(input()) mn = int(input()) ans = -1 * 10 ** 10 for i in range(n - 1): r = int(input()) diff = r - mn if diff > ans: ans = diff mn = min(mn, r) print(ans)
#ALDS 1-B: Greatest Common Divisor x = input().split() a = int(x[0]) b = int(x[1]) while(a % b != 0): c = b b = a % b a = c print(b)
0
null
10,889,773,248
13
11
splited = input().split(" ") f = int(splited[0])/int(splited[1]) r = int(splited[0])%int(splited[1]) d = int(splited[0])//int(splited[1]) print('%s %s %.5f' % (d, r, f))
# -*- coding: utf-8 -*- import sys import os a, b = list(map(int, input().split())) d = a // b r = a % b f = a / b print('{} {} {:.10f}'.format(d, r, f))
1
584,721,465,442
null
45
45
import sys l = sys.stdin.readlines() minv = int(l[1]) maxv = -1000000000 for r in map(int,l[2:]): m = r-minv if maxv < m: maxv = m if m < 0: minv = r elif m < 0: minv = r print(maxv)
from collections import Counter N = int(input()) d = list(map(int, input().split())) MOD = 998244353 dn = Counter(d) ans = 1 if dn[0] != 1 or d[0] != 0: ans = 0 else: for i in range(1, max(d)+1): ans *= (dn[i-1]**dn[i]) ans %= MOD print(ans)
0
null
77,097,227,896,638
13
284
def main(): from sys import stdin input = stdin.readline n = int(input()) S = [input() for _ in [0]*n] s2 = [] s3 = [] for s in S: temp = [0, 0] m = 0 now = 0 for i in s.strip('\n'): if i == "(": now += 1 else: now -= 1 m = min(m, now) temp = [-m, (s.count("(")-s.count(")"))-m] if temp[0] < temp[1]: s2.append(temp) else: s3.append(temp) s2.sort(key=lambda x: (x[0])) s3.sort(key=lambda x: (-x[1])) cnt = 0 for i, j in s2: cnt -= i if cnt < 0: print("No") return cnt += j for i, j in s3: cnt -= i if cnt < 0: print("No") return cnt += j if cnt != 0: print("No") return print("Yes") main()
N = int((input())) C_p = [] C_m = [] for i in range(N): kakko = input() temp = 0 temp_min = 0 for s in kakko: if s == "(": temp += 1 else: temp -= 1 temp_min = min(temp, temp_min) if temp >= 0: C_p.append((temp_min, temp)) else: C_m.append((temp_min - temp, temp_min, temp)) C_p.sort(reverse=True) flag = 0 final = 0 for l, f in C_p: if final + l < 0: flag = 1 final += f C_m.sort() for _, l, f in C_m: if final + l < 0: flag = 1 final += f if final != 0: flag = 1 print("Yes" if flag == 0 else "No")
1
23,580,437,731,520
null
152
152
import collections def U1(a,b): if b > a: b, a = a, b while a%b != 0: r = a%b a = b b = r return b K = int(input()) c = 0 arr = [] for i in range(1,K+1): for j in range(1,K+1): arr.append(U1(i,j)) arr=collections.Counter(arr) for key,value in arr.items(): for k in range(1,K+1): c += U1(k,key)*value print(c)
import math cnt=0 n=int(input()) for i in range(1,n+1): for j in range(1,n+1): wk=math.gcd(i,j) for k in range(1,n+1): cnt+=math.gcd(wk,k) print(cnt)
1
35,720,939,893,922
null
174
174
X = int(input()) # If a is positive: n ** 5 - (n - 1) ** 5 exceeds 10 ** 9 when i = 120 # If a is non-positive: n ** 5 - (n - 1) ** 5 exceeds 10 ** 9 when i = -119 # So, the valid range of A is from -118 to 119 for a in range(-118, 119 + 1): tgt = a ** 5 - X for b in range(-119, 119): if tgt == b ** 5: print(a, b) exit()
import sys x = int(input()) for a in range(-(10 ** 3), 10 ** 3): for b in range(-(10 ** 3), 10 ** 3): if a ** 5 - b ** 5 == x: print(a, b) sys.exit()
1
25,708,030,390,300
null
156
156
import queue def main(): n = int(input()) A = list(map(int,input().split())) A = sorted(A,reverse=True) q = queue.PriorityQueue() q.put([-1*A[0],-1*A[0]]) ans = 0 for a in A[1:]: _min, _max = map(lambda x:-1*x,q.get()) ans += _min q.put([-1*a,-1*_min]) q.put([-1*a,-1*_max]) print(ans) return if __name__ == "__main__": main()
N = int(input()) X = input() mod0 = X.count("1") + 1 mod1 = X.count("1") - 1 full0 = 0 full1 = 0 for i in range(N): if X[i] == "1": full0 = (full0 + pow(2, N - i - 1, mod0)) % mod0 if mod1 > 0: full1 = (full1 + pow(2, N - i - 1, mod1)) % mod1 ans = [0] * N for i in range(N): if X[i] == "0": cur = (full0 + pow(2, N - i - 1, mod0)) % mod0 res = 1 else: if mod1 > 0: cur = (full1 - pow(2, N - i - 1, mod1)) % mod1 res = 1 else: cur = 0 res = 0 while cur > 0: cur %= bin(cur).count("1") res += 1 ans[i] = res print(*ans, sep="\n")
0
null
8,614,196,855,690
111
107
def modpow(x, n, p): res = 1 while n > 0: if n & 1: res = res * x % p x = x * x % p n >>= 1 return res MOD = pow(10, 9) + 7 k = int(input()) s = input() n = len(s) fact = [1 for _ in range(n + k + 1)] p25 = [1 for _ in range(n + k + 1)] for i in range(1, n + k + 1): fact[i] = fact[i - 1] * i % MOD p25[i] = p25[i - 1] * 25 % MOD inv = [1 for _ in range(n + k + 1)] inv[n + k] = modpow(fact[n + k], MOD - 2, MOD) for i in range(n + k - 1, -1, -1): inv[i] = inv[i + 1] * (i + 1) % MOD ans = modpow(26, n + k, MOD) for i in range(n): ans -= fact[n + k] * inv[i] % MOD * inv[n + k - i] % MOD * p25[n + k - i] % MOD if ans < 0: ans += MOD print(ans)
from collections import Counter def solve(): N = int(input()) c = Counter([input() for _ in range(N)]) cnt = -1 ans = [] for i in c.most_common(): if cnt == -1: cnt = i[1] ans.append(i[0]) elif cnt == i[1]: ans.append(i[0]) else: break for a in sorted(ans): print(a) if __name__ == "__main__": solve()
0
null
41,604,878,023,268
124
218
from sys import stdin from itertools import permutations n = int(stdin.readline().strip()) rank = dict([(val, i) for i, val in enumerate(sorted([int(''.join([str(v) for v in l])) for l in permutations(list(range(1, n+1)), n)])[::-1])]) p_rank = rank[int(''.join(stdin.readline().split()))] q_rank = rank[int(''.join(stdin.readline().split()))] print(abs(p_rank - q_rank))
from itertools import permutations N = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) r = 0 for i, x in enumerate(permutations([j for j in range(1,N+1)])): if x == P: r = abs(r-i) if x == Q: r = abs(r-i) print(r)
1
100,323,674,730,880
null
246
246
i = int(input()) h = i // 3600 i -= h * 3600 m = i // 60 i -= m * 60 s = i print("{}:{}:{}".format(h, m, s))
n=int(input()) for x in range(n+1): if int(x*1.08)==n: print(x) exit() print(":(")
0
null
63,255,310,763,328
37
265
import numpy as np a, b, c, d = map(int, input().split()) x = np.array([a, b]) y = np.array([c, d]) z = np.outer(x, y) print(z.max())
a, b, c, d = map(int, input().split()) L = [a*c, a*d, b*c, b*d] ans = max(L) print(ans)
1
3,035,951,751,340
null
77
77
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): H, W, M = map(int, readline().split()) row = [0] * H column = [0] * W grid = set() for _ in range(M): h, w = map(int, readline().split()) row[h-1] += 1 column[w-1] += 1 grid.add((h-1,w-1)) max_row = max(row) max_column = max(column) idx_row = [i for i,x in enumerate(row) if x == max_row] idx_column = [i for i,x in enumerate(column) if x == max_column] ans = max_row+max_column flag = False for h in idx_row: for w in idx_column: if not (h,w) in grid: flag = True break if flag: print(ans) else: print(ans-1) if __name__ == '__main__': main()
#from random import randint import numpy as np def f(h,w,m,ins): yp = np.zeros(h,dtype=np.int32) xp = np.zeros(w,dtype=np.int32) s = set() for hi,wi in ins: s.add((hi-1,wi-1)) yp[hi-1] += 1 xp[wi-1] += 1 ypm = yp.max() xpm = xp.max() yps = np.where(yp == ypm)[0].tolist() xps = np.where(xp == xpm)[0].tolist() ans = yp[yps[0]]+xp[xps[0]] for ypsi in yps: for xpsi in xps: if not (ypsi,xpsi) in s: return ans return ans-1 if __name__ == "__main__": if False: while True: h,w = randint(1,10**5*3),randint(10**5,10**5*3) m = randint(1,min(h*w,10**5*3)) ins = [(randint(1,h),randint(1,w)) for i in range(m)] ans = f(h,w,m,ins) print(ans) else: h,w,m = map(int,input().split()) ans = f(h,w,m,[list(map(int,input().split())) for i in range(m)]) print(ans)
1
4,716,119,735,360
null
89
89
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)
A, B = map(int, input().split()) for x in range(10**3+1): if int(x * 0.08) == A and int(x * 0.1) == B: print(x) exit() print(-1)
0
null
34,174,907,872,742
121
203
a,b = map(int, input().split()) print(f'{a//b} {a%b} {(a/b):.6f}')
a, b = input().split() a = int(a) b = int(b) d = int(a/b) r = a%b f = a/b print(str(d) + " " + str(r) + " " + "%.8f" % (f))
1
586,178,757,890
null
45
45
from collections import deque Q=deque(list(input())) q=int(input()) cnt=0 for i in range(q): x=input() if x[0]=='1': cnt+=1 cnt%=2 elif x[0]=='2': if x[2]=='1': if cnt%2==0: Q.appendleft(x[4]) else: Q.append(x[4]) else: if cnt%2==0: Q.append(x[4]) else: Q.appendleft(x[4]) if cnt%2==1: Q.reverse() print(''.join(Q))
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) xyc= [list(map(int, input().split())) for _ in range(M)] minmoney = min(a) + min(b) for obj in xyc: summoney = a[obj[0] - 1] + b[obj[1] - 1] - obj[2] minmoney = min(minmoney, summoney) print(minmoney)
0
null
55,570,805,906,912
204
200
print('1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51'.split(',')[int(input())-1])
import sys # sys.stdin = open('input.txt') k = int(input()) string = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51' s = [i for i in map(int, string.split(', '))] print(s[k-1])
1
49,894,248,112,600
null
195
195
n,a,b=map(int,input().split()) print(min(n%(a+b),a)+n//(a+b)*a)
N, A, B = map(int, input().split()) # 周期 # 青 A個, 赤 B個 ans = N // (A + B) * A n = N % (A + B) if A <= n: ans += A else: ans += n print(ans)
1
55,429,959,379,950
null
202
202
import sys; for line in sys.stdin: n = int(line); for i in range(0, n): a = [int(num) for num in input().split()]; a.sort(); if a[2] ** 2 == (a[0] ** 2) + (a[1] ** 2): print('YES'); else: print('NO');
def main(): n = int(input()) inlis = list(map(int, input().split())) anslis = [0] * n for i in range(n): num = inlis[i] anslis[num-1] = i+1 print(*anslis) if __name__ == "__main__": main()
0
null
90,797,495,821,320
4
299
import math def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**5+5 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 ) N,K = list(map(int,input().split())) A = sorted(tuple(map(int,input().split()))) B = tuple(A[i+1]-A[i] for i in range(len(A)-1)) lim = math.ceil(len(B)/2) L = 10**9+7 ans = 0 multi = cmb(N,K,mod) for j in range(lim): front = j + 1 back = N - front tmp_b = 0 tmp_f = 0 if front >= K: tmp_f = cmb(front,K,mod) if back >= K: tmp_b = cmb(back,K,mod) if j == (len(B)-1)/2: ans += (multi - tmp_b - tmp_f)*(B[j]) % L else: ans += (multi - tmp_b - tmp_f)*(B[j]+B[len(B)-1-j]) % L print(ans%L)
#n<=10**5まで def cmb(n, k, mod, fac, ifac): k = min(k, n-k) return fac[n] * ifac[k] * ifac[n-k] % mod def make_tables(mod, n): fac = [1, 1] # 階乗テーブル・・・(1) ifac = [1, 1] #逆元の階乗テーブル・・・(2) inverse = [0, 1] #逆元テーブル・・・(3) for i in range(2, n+1): fac.append((fac[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod//i)) % mod) ifac.append((ifac[-1] * inverse[-1]) % mod) return fac, ifac n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() mod = 1000000007 fac, ifac = make_tables(mod, n) ans = 0 for i in range(n-k+1): c = cmb(n-1-i, k-1, mod, fac, ifac) ans += ((a[n-1-i] - a[i]) * c) % mod print(ans%mod)
1
95,621,210,232,350
null
242
242
class Factorial(): def __init__(self, mod=10**9 + 7): self.mod = mod self._factorial = [1] self._size = 1 self._factorial_inv = [1] self._size_inv = 1 def __call__(self, n): return self.fact(n) def fact(self, n): ''' n! % mod ''' if n >= self.mod: return 0 self._make(n) return self._factorial[n] def _make(self, n): if n >= self.mod: n = self.mod if self._size < n+1: for i in range(self._size, n+1): self._factorial.append(self._factorial[i-1]*i % self.mod) self._size = n+1 def fact_inv(self, n): ''' n!^-1 % mod ''' if n >= self.mod: raise ValueError('Modinv is not exist! arg={}'.format(n)) self._make(n) if self._size_inv < n+1: self._factorial_inv += [-1] * (n+1-self._size_inv) self._size_inv = n+1 if self._factorial_inv[n] == -1: self._factorial_inv[n] = self.modinv(self._factorial[n]) return self._factorial_inv[n] @staticmethod def xgcd(a, b): ''' Return (gcd(a, b), x, y) such that a*x + b*y = gcd(a, b) ''' x0, x1, y0, y1 = 0, 1, 1, 0 while a != 0: (q, a), b = divmod(b, a), a y0, y1 = y1, y0 - q * y1 x0, x1 = x1, x0 - q * x1 return b, x0, y0 def modinv(self, n): g, x, _ = self.xgcd(n, self.mod) if g != 1: raise ValueError('Modinv is not exist! arg={}'.format(n)) return x % self.mod def comb(self, n, r): ''' nCr % mod ''' if r > n: return 0 t = self(n)*self.fact_inv(n-r) % self.mod return t*self.fact_inv(r) % self.mod def comb_with_repetition(self, n, r): ''' nHr % mod ''' t = self(n+r-1)*self.fact_inv(n-1) % self.mod return t*self.fact_inv(r) % self.mod def perm(self, n, r): ''' nPr % mod ''' if r > n: return 0 return self(n)*self.fact_inv(n-r) % self.mod n, m, k = map(int, input().split()) mod = 998244353 comb = Factorial(mod).comb s = 0 for i in range(k+1, n): t = comb(n-1, i)*m % mod t = t*pow(m-1, n-1-i, mod) % mod s = (s+t) % mod ans = (pow(m, n, mod)-s) % mod print(ans)
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 998244353 ############# # Main Code # ############# # N:ブロック # M:色(バリエーション) # K:隣合う組み # N, M, K = 6, 2, 3のとき # K = 0 のとき # 121212, 212121 # K = 1のとき, # 12121 のどこかに同じ数字を挟み込めば # 112121, 122121という風にできる # K = 2のとき # 1212 のどこかに同じ数字を挟む を2回行う # 112212, 112122もできるし # 111212, 122212もできる N, M, K = getNM() # 重複組み合わせのため # 繰り返し使うのでこのタイプ Y = N + K + 1 fact =[1] #階乗 for i in range(1, Y + 1): fact.append(fact[i - 1] * i % mod) facv = [0] * (Y + 1) #階乗の逆元 facv[-1] = pow(fact[-1], mod - 2 , mod) for i in range(Y - 1, -1, -1): facv[i] = facv[i + 1] * (i + 1) % mod def cmb(n, r): if n < r: return 0 return fact[n] * facv[r] * facv[n - r] % mod ans = 0 for i in range(K + 1): opt = M * pow(M - 1, N - i - 1, mod) * cmb(N - i + i - 1, i) ans += opt % mod print(ans % mod)
1
23,266,105,532,398
null
151
151
def main(): from sys import stdin readline = stdin.readline N = int(readline().rstrip()) c0 , c1 , c2 , c3 = 0 , 0 , 0 , 0 for i in range(N): test = readline().rstrip() if test == "AC": c0 += 1 elif test == "WA": c1 += 1 elif test == "TLE": c2 += 1 elif test == "RE": c3 += 1 c0 = "AC x " + str(c0) c1 = "WA x " + str(c1) c2 = "TLE x " + str(c2) c3 = "RE x " + str(c3) print(c0 + "\n" + c1 + "\n" + c2 + "\n" + c3) main()
n=int(input()) li=[input() for i in range(n)] ans=[0,0,0,0] for i in range(n): if li[i]=="AC": ans[0]+=1 elif li[i]=="WA": ans[1]+=1 elif li[i]=="TLE": ans[2]+=1 elif li[i]=="RE": ans[3]+=1 print("AC x " + str(ans[0])) print("WA x "+ str(ans[1])) print("TLE x "+str(ans[2])) print("RE x "+str(ans[3]))
1
8,696,777,092,832
null
109
109
#ABC146A s = ["SUN","MON","TUE","WED","THU","FRI","SAT"] ss = input() print(7-s.index(ss))
s = input() day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] num = [7, 6, 5, 4, 3, 2, 1] dic = dict(zip(day, num)) print(dic[s])
1
132,604,675,191,940
null
270
270
user_input = int(input()) print(user_input + user_input**2 + user_input**3)
a = lambda x: x+(x**2)+(x**3) n = int(input()) print(a(n))
1
10,283,857,480,480
null
115
115
h, w = map(int, input().split()) if h==1 or w == 1: print(1) else: ans = h * w //2 + (h*w)%2 print(ans)
h,w=map(int,input().split()) print((h*w+1)//2 if h*w>h+w else 1)
1
50,793,461,325,540
null
196
196
#a = list(map(int, input().split(' '))) a = input() b = input() if a == b[:-1]: print('Yes') else: print('No')
S = input() T = input() S = S + T[-1] print("Yes" if S == T else "No")
1
21,472,220,941,248
null
147
147
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n = str(readline().rstrip().decode('utf-8')) d = {"2": "hon", "4": "hon", "5": "hon", "7": "hon", "9": "hon", "0": "pon", "1": "pon", "6": "pon", "8": "pon", "3": "bon"} print(d[n[-1]]) if __name__ == '__main__': solve()
dic = {} for b in range(1,5): for f in range(1,4): for r in range(1,11): dic[(b,f,r)] = 0 n = int(raw_input()) for k in range(n): b,f,r,v = map(int,raw_input().split()) dic[(b,f,r)] += v j = 0 for b in range(1,5): for f in range(1,4): ls = [] for r in range(1,11): ls.append(dic[(b,f,r)]) print ' ' + ' '.join(map(str,ls)) else: if j < 3: print '#'*20 j +=1
0
null
10,110,544,078,770
142
55
from math import * A,B,N = map(int,input().split()) print(floor(A*min(N,B-1)/B))
if __name__ == "__main__": n = int(input()) taro, hanako = 0, 0 for _ in range(n): tw, hw = input().split() if tw > hw: taro += 3 elif tw < hw: hanako += 3 else: taro += 1 hanako += 1 print(taro, hanako)
0
null
14,954,275,598,184
161
67
s,t=list(input().split()) a,b=list(map(int,input().split())) u=input() ball={s:a,t:b} ball[u] =max(0,ball[u]-1) print(ball[s],ball[t])
import sys n = int(input()) # ?????£?????????????????????????????° pic_list = ['S', 'H', 'C', 'D'] card_dict = {'S':[], 'H':[], 'C':[], 'D':[]} # ?????£?????????????????\?????????????????° lost_card_dict = {'S':[], 'H':[], 'C':[], 'D':[]} # ?¶??????????????????\?????????????????° # ?????????????¨??????\??????????????? for i in range(n): pic, num = input().split() card_dict[pic].append(int(num)) # ?¶???????????????????????¨??????\????¨???? for pic in card_dict.keys(): for j in range(1, 14): if not j in card_dict[pic]: lost_card_dict[pic].append(j) # ????????????????????? for pic in card_dict.keys(): lost_card_dict[pic] = sorted(lost_card_dict[pic]) # ?¶???????????????????????????? for pic in pic_list: for k in range(len(lost_card_dict[pic])): print(pic, lost_card_dict[pic][k])
0
null
36,444,396,786,328
220
54
a, b = map(int, input().split()) def gcd(a, b): if a > b: a, b = b, a if b % a == 0: return a else: return gcd(a, b % a) print(gcd(a, b))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, M = map(int, readline().split()) if M == 0: print([0, 10, 100][N - 1]) exit() m = map(int, read().split()) S, C = zip(*zip(m, m)) def test(n): st = str(n) if len(st) != N: return False for i, c in zip(S, C): i -= 1 if st[i] != str(c): return False return True def main(): for n in range(1000): if test(n): return n return -1 print(main())
0
null
30,357,391,059,108
11
208
def main2(): h,w,k = map(int,input().split()) G = [] for _ in range(h): c = list(input()) G.append(c) ans = 0 for ib in range(1<<h): for jb in range(1<<w): ct = 0 for i in range(h): for j in range(w): if (ib>>i)&1 and (jb>>j)&1 and G[i][j]=="#": ct+=1 if ct == k: ans+=1 print(ans) main2()
n,m,k = map(int,input().split()) ans = 0 g = [[i for i in input()] for i in range(n)] for maskY in range(1 << n): ng = [[0]*m for i in range(n)] for bit in range(n): if maskY & (1 << bit): for i in range(m): ng[bit][i] = 1 for maskX in range(1 << m): ngg = [[i for i in j] for j in ng] # print(ngg) for bit in range(m): if maskX & (1 << bit): for i in range(n): ngg[i][bit] = 1 cnt = 0 for y in range(n): for x in range(m): if g[y][x]=="#" and ngg[y][x]==0: cnt += 1 # print(cnt) if cnt == k: ans += 1 print(ans)
1
8,918,261,089,890
null
110
110
n = list(input()) n1 = list(input()) i = 0 cou = 0 while i != len(n): if n[i] != n1[i]: cou += 1 i += 1 print(cou)
mojiretsua=input() mojiretsub=input() count=0 for i in range(len(mojiretsua)): if mojiretsua[i] != mojiretsub[i]: count=count+1 print(count)
1
10,481,811,892,740
null
116
116
import sys x = int(sys.stdin.readline().strip()) print('%d' % (x ** 3))
input_value = input() value = int(input_value) print(value**3)
1
277,270,456,628
null
35
35
#!/usr/bin/python3 import sys input = lambda: sys.stdin.readline().strip() L = int(input()) print(f'{(L / 3) ** 3:.6f}')
def main(): from collections import deque N, M, K = map(int, input().split()) f = [set() for _ in range(N + 1)] b = [set() for _ in range(N + 1)] for _ in range(M): i, j = map(int, input().split()) f[i].add(j) f[j].add(i) for _ in range(K): i, j = map(int, input().split()) b[i].add(j) b[j].add(i) visited = [False] * (N + 1) ans = [0] * (N + 1) for i in range(1, N+1): if visited[i]: continue visited[i] = True link = {i} todo = deque([i]) while len(todo) != 0: c = todo.pop() for p in f[c]: if not(visited[p]): link.add(p) todo.append(p) visited[p] = True for j in link: ans[j] = len(link) - len(link & f[j]) - len(link & b[j]) - 1 print(*ans[1:]) if __name__ == '__main__': main()
0
null
54,593,176,035,372
191
209
# AtCoder from collections import deque S = input() Q = int(input()) qs = [input().split() for i in range(Q)] ans = deque(S) flag = 0 count = 0 for q in qs: if q[0] == '1': if flag == 0: flag = 1 else: flag = 0 count += 1 else: if flag == 0: if q[1] == '1': ans.appendleft(q[2]) else: ans.append(q[2]) else: if q[1] == '1': ans.append(q[2]) else: ans.appendleft(q[2]) if count % 2 == 1: ans.reverse() print(*ans, sep='')
from collections import deque if __name__ == '__main__': s = input() n = int(input()) rvflg = False d_st = deque() d_ed = deque() for _ in range(n): q = input() if len(q) == 1: if rvflg: rvflg = False else: rvflg = True else: i,f,c = map(str,q.split()) if f == "1":#先頭に追加 if rvflg: #末尾に追加 d_ed.append(c) else: #先頭に追加 d_st.appendleft(c) else:#末尾に追加 if rvflg: #先頭に追加 d_st.appendleft(c) else: #末尾に追加 d_ed.append(c) ans = "".join(d_st) + s + "".join(d_ed) #最後に反転するかを決定 if rvflg: ans = ans[::-1] print(ans)
1
57,407,036,433,012
null
204
204
mount_list = [] for i in range(10): mount_list.append(int(input())) mount_list.sort(reverse = True) for i in range(3): print(mount_list[i])
n = str(input()) if(n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] == "7" or n[-1] == "9"): print("hon") elif(n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8"): print("pon") else: print("bon")
0
null
9,652,723,491,650
2
142
num=int(input()) print(3.14159265359*num*2)
R = int(input()) print(R * 6.28318530717958623200)
1
31,517,100,932,214
null
167
167
s=input();print(('No','Yes')[s==input()[:len(s)]])
def insertionSort(n, A, g): global cnt for i in range(g, n): temp = A[i] j = i - g while j >= 0 and A[j] > temp: A[j + g] = A[j] j -= g cnt += 1 A[j + g] = temp return A def shellSort(A, n): global m global G h = 1 while True: if h > n: break G.append(h) h = 3 * h + 1 G.reverse() m =len(G) for i in range(m): insertionSort(n, A, G[i]) if __name__ == "__main__": n = int(input()) A = [int(input()) for i in range(n)] G = [] m = 0 cnt = 0 shellSort(A, n) print(m) print(*G) print(cnt) for i in range(n): print(A[i])
0
null
10,621,311,473,324
147
17
S = int(input()) R = "ACL" print(R * S)
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def MAP1() : return map(lambda x:int(x)-1,input().split()) def LIST() : return list(MAP()) def LIST1() : return list(MAP1()) def solve(): N = INT() a = [] b = [] for i in range(N): A, B = MAP() a.append(A) b.append(B) a.sort() b.sort() if N % 2 == 1: am = a[(N+1)//2-1] bm = b[(N+1)//2-1] ans = bm - am + 1 else: am = ( a[N//2-1]+a[N//2] ) / 2 bm = ( b[N//2-1]+b[N//2] ) / 2 ans = int( ( bm - am ) * 2 + 1 ) print(ans) if __name__ == '__main__': solve()
0
null
9,716,807,656,698
69
137
k = int(input()) print(int(k+k**2+k**3))
import sys for line in sys.stdin: H, W = map(int, line.split()) if H == 0 and W == 0: break for _ in range(H): print( '#' * W ) print("")
0
null
5,526,085,331,092
115
49
S = list(input()) K = int(input()) S1 = list(S) cnt1 = 0 for i in range(1, len(S1)): if S1[i] == S1[i - 1]: S1[i] = '*' cnt1 += 1 S2 = list(S) * 2 cnt2 = 0 for i in range(1, len(S2)): if S2[i] == S2[i - 1]: S2[i] = '*' cnt2 += 1 S3 = list(S) * 3 cnt3 = 0 for i in range(1, len(S3)): if S3[i] == S3[i - 1]: S3[i] = '*' cnt3 += 1 # print("#", S1, S2, S3) # print("#", cnt1, cnt2, cnt3) ans = cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2) print(ans)
import sys a = list(input().split()) stack = [] for i in range(len(a)): n = len(stack) if a[i] == '+': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp = int(stack.pop(n-1)) + int(stack.pop(n-2)) stack.append(tmp) elif a[i] == '-': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp_1 = int(stack.pop(n-1)) tmp_2 = int(stack.pop(n-2)) tmp = tmp_2 - tmp_1 stack.append(tmp) elif a[i] == '*': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp = int(stack.pop(n-1)) * int(stack.pop(n-2)) stack.append(tmp) elif a[i] == '/': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp_1 = int(stack.pop(n-1)) tmp_2 = int(stack.pop(n-2)) tmp = tmp_2 / tmp_1 stack.append(tmp) else: stack.append(int(a[i])) print(stack[0])
0
null
88,001,811,919,098
296
18
s=str(input()) if s=="hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s=="hihihihihi": print("Yes") else: print("No")
S=input() if S=="hi" or S=="hihi" or S=="hihihi" or S=="hihihihi" or S=="hihihihihi": print("Yes") else: print("No")
1
53,186,332,949,640
null
199
199
# -*- coding: utf-8 -*- n, k = map(int, input().split()) cnt = 0 h = list(map(int, input().split())) for high in h: if high >= k: cnt += 1 print(cnt)
N, K = map(int, input().split()) H = list(map(int, input().split())) print(len(list(filter(lambda x: x >= K, H))))
1
179,740,483,013,440
null
298
298
def factorization(n): res = [] tmp = n for i in range(2, int(-(-n**0.5//1))+1): if tmp % i == 0: cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i res.append([i, cnt]) if tmp!=1: res.append([tmp, 1]) return res N = int(input()) ans = 0 for tmp,cnt in factorization(N): i = 1 while i<=cnt: ans += 1 cnt-=i i += 1 print(ans)
def shuffle(): h = int(input()) for i in range(h): s.append(s[0]) del s[0] while True: s = list(input()) if s == ['-']: break m = int(input()) for i in range(m): shuffle() print(''.join(s))
0
null
9,396,155,598,496
136
66
S = input() S_size = len(S) S_hi = S.count('hi') if S_size == S_hi*2: print('Yes') else: print('No')
s=input();print("Yes"if s=="hi"*(len(s)//2)else"No")
1
53,261,268,922,550
null
199
199
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 N = int(readline()) if N % 2 == 1: print(0) else: count2 = 0 count5 = 0 compare = 1 while N >= compare * 2: compare *= 2 count2 += N // compare compare = 1 N //= 2 while N >= compare * 5: compare *= 5 count5 += N // compare ans = min(count2, count5) print(ans) if __name__ == '__main__': solve()
N = int(input()) if N%2 != 0: print(0) else: answer = 0 m = 10 while m <= N: answer += N//m m *= 5 print(answer)
1
115,979,801,429,156
null
258
258
N = int(input()) A = [] B = [] for _ in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) def median(arr): arr.sort() n = len(arr) if n % 2 == 1: return arr[(n + 1) // 2 - 1] else: return (arr[n//2 - 1] + arr[n//2]) / 2 med_a = median(A) med_b = median(B) if N % 2 == 1: ans = int(med_b) - int(med_a) + 1 else: ans = med_b * 2 - med_a * 2 + 1 ans = int(ans) print(ans)
a,b,c = input().split(' ') a=int(a) b=int(b) c=int(c) ret="Yes" if a<b<c else "No" print(ret)
0
null
8,931,939,651,182
137
39
n = int(input()) ans = 0 for i in range(1, n + 1): for j in range(1, n//i + 1): if i * j <= n: ans += i * j else: break print(ans)
import bisect n=int(input()) a=list(map(int,input().split())) suma=[] sumans=0 for i in range(n): sumans += a[i] suma.append(sumans) u=bisect.bisect_right(suma, sumans//2) print(min(abs(2*suma[u-1]-sumans), abs(2*suma[u]-sumans)))
0
null
76,611,660,519,940
118
276
import math n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) p=[1,2,3,math.inf] p1=0 p2=0 p3=0 p4=0 #p=1 for i in range(n): p1+=(abs(a[i]-b[i])) print("{:10f}".format(p1)) #p=2 q=0 for i in range(n): q+=((abs(a[i]-b[i]))**2) p2=math.sqrt(q) print("{:10f}".format(p2)) #3 q=0 for i in range(n): q+=((abs(a[i]-b[i]))**3) p3=q**(1/3) print("{:10f}".format(p3)) #inf q=0 for i in range(n): q=(abs(a[i]-b[i])) if q>p4: p4=q print("{:10f}".format(p4))
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N = int(input()) A = np.array(input().split(), np.int64) B = np.append(0, A.cumsum()) C = A[::-1].cumsum() C = np.append(C[::-1], 0) print(np.abs(B-C).min()) if __name__ == '__main__': main()
0
null
70,946,986,072,512
32
276
import sys input = sys.stdin.readline ''' ''' s = input().rstrip() if s == "MON": print(6) elif s == "SAT": print(1) elif s == "FRI": print(2) elif s == "THU": print(3) elif s == "WED": print(4) elif s == "TUE": print(5) else: print(7)
wd = ['SUN','MON','TUE','WED','THU','FRI','SAT'] s = input() print(str(7 - wd.index(s) % 7))
1
132,796,322,728,780
null
270
270
N, K = map(int, input().split()) if N%K == 0: print(0) if N%K != 0 and N > K : a = N%K b = K%a if a >= b : print(b) if a < b: print(a) if N%K != 0 and N < K : c = K-N if c > N: print(N) if c < N: print(c)
N, K = map(int, input().split()) if N % K == 0: print(0) elif N % K > abs((N%K)-K): print(abs((N%K)-K)) else: print(N%K)
1
39,315,842,935,754
null
180
180
def divisor(N:int): res = set() i = 1 while i * i <= N: if N % i == 0: res.add(i) if i != N // i: res.add(N // i) i += 1 return res def check(N:int, K:int): while N % K == 0: N //= K return True if N % K == 1 else False def main(): N = int(input()) ans = set() for K in divisor(N): if K == 1: continue if check(N, K): ans.add(K) ans |= divisor(N - 1) ans.remove(1) print(len(ans)) if __name__ == "__main__": main()
""" Nが1になるようなKは、 ・K^x = NになるようなKか ・K^x(K*y+1) = N になるようなKである。 後者は前者を包括するので、後者についてのみカウントすればよい。 Kの数を求めるために、後者をさらに2種類に分ける ・x > 0の場合 ・x == 0の場合 前者の場合、KはNの約数なので、Nの約数全部に関して条件を満たすか調べればよい。Nの約数はそんなに多くならないので、時間はかからない。 後者の場合だと、KはN-1の約数の数だけ存在するのでN-1の約数の数を求めればよい。 """ from collections import Counter def gcd(a,b): return a if b==0 else gcd(b,a%b) N = int(input()) ans = 0 #x>0の場合を調べる #Nを素因数分解する devisers = [] d = 2 while d*d < N: if N % d == 0: devisers.append(d) devisers.append(N//d) d += 1 if d*d == N: devisers.append(d) for d in devisers: dummyN = N while dummyN % d == 0: dummyN //= d if dummyN%d == 1: ans += 1 #x == 0 になるようなKの数を調べる。 #N-1を素因数分解する。 tmp = [] dummyN = N-1 ceil = int(dummyN**0.5) for d in range(2,ceil+1): while dummyN % d == 0: tmp.append(d) dummyN //= d if dummyN != 1: tmp.append(dummyN) dummyN //= dummyN divideN = Counter(tmp) commonDCnt = 1 for v in divideN.values(): commonDCnt *= (v+1) ans += commonDCnt print(ans)
1
41,245,382,048,508
null
183
183
while True: string = input() if string == "-": break else: s = 0 for i in range(int(input())): s += int(input()) s = s % len(string) print(string[s:len(string)] + string[0:s])
# -*- coding: utf-8 -*- from collections import Counter, defaultdict, deque import math 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 from fractions import Fraction def f(a, b): if a== 0 and b == 0: return (1, 0, 0) if b == 0: return (1, 1, 0) f = Fraction(a, b) a = f.numerator b = f.denominator if a < 0: s = -1 a *= -1 else: s = 1 return s, a, b 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) @mt def slv(N, AB): adb = Counter() for a, b in AB: s, a, b = f(a, b) adb[(s*a, b)] += 1 M = Mod(1000000007) ans = 1 done = set() for k, v in adb.items(): if k in done: continue if k == (0, 0): continue a, b = k if a < 0: s = 1 a = abs(a) elif a == 0: s = 1 else: s = -1 n = adb[(s*b, a)] done.add(k) done.add((s*b, a)) t = M.sub(M.pow(2, v) + M.pow(2, n), 1) ans = M.mul(ans, t) return M.add(M.sub(ans, 1), adb[(0, 0)]) def main(): N = read_int() AB = [read_int_n() for _ in range(N)] print(slv(N, AB)) if __name__ == '__main__': main()
0
null
11,337,978,408,370
66
146
N = int(input()) A = list(map(int, input().split())) # number_to_prime[i]: i の最小の素因数, iが素数ならば0 number_to_prime = [0] * (10**6 + 1) # preprocess for i in range(2, 10**6+1): if not number_to_prime[i]: j = 1 while j*i <= 10**6: number_to_prime[j*i] = i j += 1 def is_pair_copr(A): import numpy as np U = 1 << 20 div_p = np.arange(U) for p in range(2, U): if div_p[p] != p: continue div_p[p::p] = p used = np.zeros(U, np.bool_) for x in A: while x > 1: p = div_p[x] while x % p == 0: x //= p if used[p]: return False used[p] = True return True def is_pairwise(): used_primes = set() pairwise_flag = 1 for a in A: curr_primes = set() while a > 1: prime = number_to_prime[a] curr_primes.add(prime) a //= prime if used_primes & curr_primes: pairwise_flag = 0 break else: used_primes = used_primes | curr_primes return pairwise_flag def is_setwise(*A): import math from functools import reduce return reduce(math.gcd, A) == 1 if is_pair_copr(A): print("pairwise coprime") elif is_setwise(*A): print("setwise coprime") else: print("not coprime")
s = input() q = int(input()) head = [] tail = [] flip = 0 for i in range(q): query = input().split() if query[0] == "1": flip ^=1 else: f = int(query[1]) - 1 c = query[2] if (f ^ flip) == 0: head.append(c) else: tail.append(c) if flip: head, tail = tail, head s = s[::-1] head = "".join(head) tail = "".join(tail) print(head[::-1] + s + tail)
0
null
30,505,405,726,368
85
204
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def MAP1() : return map(lambda x:int(x)-1,input().split()) def LIST() : return list(MAP()) def LIST1() : return list(MAP1()) def solve(): N = INT() a = [] b = [] for i in range(N): A, B = MAP() a.append(A) b.append(B) a.sort() b.sort() if N % 2 == 1: am = a[(N+1)//2-1] bm = b[(N+1)//2-1] ans = bm - am + 1 else: am = ( a[N//2-1]+a[N//2] ) / 2 bm = ( b[N//2-1]+b[N//2] ) / 2 ans = int( ( bm - am ) * 2 + 1 ) print(ans) if __name__ == '__main__': solve()
from statistics import median def main(): N = int(input()) A = [None] * N B = [None] * N for i in range(N): A[i], B[i] = map(int, input().split()) min_median = median(A) max_median = median(B) if N % 2 == 1: print(max_median - min_median + 1) else: print(round((max_median-min_median)*2)+1) if __name__ == "__main__": main()
1
17,330,243,464,578
null
137
137
X,Y=map(int,input().split()) def ans170(X:int, Y:int): if Y<=X*4 and Y>=X*2 and Y%2==0: return("Yes") else: return("No") print(ans170(X,Y))
import heapq 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) r.sort(reverse=True) ans=[] for i in range(x): ans.append(p[i]) for j in range(y): ans.append(q[j]) ans.sort() heapq.heapify(ans) for j in range(c): min_a=heapq.heappop(ans) if min_a<=r[j]: heapq.heappush(ans,r[j]) else: heapq.heappush(ans,min_a) break print(sum(ans))
0
null
29,202,596,401,440
127
188
N = int(input()) S = input() ans = 0 for i in range(0, 1000): if 0 <= i and i <= 9: num = "00"+str(i) elif 10 <= i and i <= 99: num = "0"+str(i) else: num = str(i) num_pos = 0 s_pos = 0 while True: if S[s_pos] == num[num_pos]: num_pos += 1 if num_pos == 3: ans += 1 break s_pos += 1 if s_pos == N: break print(ans)
L = int(input()) a = float(L/3) b = float(L/3) c = float(L / 3) print(a * b * c)
0
null
87,989,768,023,288
267
191
def q_d(): n = int(input()) a = list(map(int, input().split())) break_num = 0 current_index = 1 for i in range(n): if a[i] == current_index: current_index += 1 else: break_num += 1 if break_num == n: print(-1) else: print(break_num) if __name__ == '__main__': q_d()
import sys N = int(input()) A = list(map(int,input().split())) if A.count(1) == 0: print(-1) sys.exit() else: cnt = 0 for a in range(len(A)): if A[a] == cnt+1: cnt += 1 print(len(A)-cnt)
1
114,311,212,724,160
null
257
257
while True: n = input() if n == 0: break print sum(map(int, list(str(n))))
#coding:utf-8 #1_8_B 2015.4.7 while True: number = input() if number == '0': break print(sum(int(i) for i in number))
1
1,613,401,567,026
null
62
62
def solve(s): dp = [0]*(s+1) dp[0] = 1 MOD = 10**9+7 x = 0 for i in range(1,s+1): for j in range(0,i-3+1): dp[i] += dp[j] dp[i] %= MOD return dp[s] s = int(input()) print(solve(s))
n,k = map(int, input().split()) a = [0]*n for i in range(k): c = int(input()) L = list(map(int, input().split())) for l in L: a[l-1] = 1 print(a.count(0))
0
null
13,854,783,012,042
79
154
# -*- coding: utf-8 -*- N = int(input()) S = list() words = {} for i in range(N): s = input() S.append(s) if s in words: words[s] += 1 else: words[s] = 1 max_value = max(words.values()) max_list = list() for k,v in words.items(): if v == max_value: max_list.append(k) ans_list = sorted(max_list) for ans in ans_list: print(ans)
#coding:utf-8 while True: h, w = map(int, raw_input(). split()) if h == w == 0: break for i in xrange(h): print("#" * w) print("")
0
null
35,287,493,223,960
218
49
a, b = map(int, raw_input().split()) d = a / b r = a % b f = a * 1.0 / b print '%d %d %f' % (d,r,f)
a, b = map(int, input().split()) print('{:d} {:d} {:.10f}'.format(a//b, a%b, a/b))
1
601,939,774,072
null
45
45
import math a, b, x = map(float, input().split()) if a * a * b <= x * 2: h = 2 * (b - x / a / a) ret = math.degrees(math.atan2(h, a)) else: h = 2 * x / a / b ret = 90 - math.degrees(math.atan2(h, b)) print(ret)
a, b, n = map(int, input().split()) if n <= b - 1: x = n else: x = n - (n%b + 1) ans = a*x//b - a*(x//b) print(ans)
0
null
95,870,610,476,220
289
161
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n, *a = map(int, read().split()) r = 0 minp = a[0] for i1 in range(n): if minp >= a[i1]: r += 1 minp = a[i1] print(r) if __name__ == '__main__': main()
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): S, W = map(int, input().split()) if W >= S: print('unsafe') else: print('safe') if __name__ == '__main__': main()
0
null
57,684,028,418,220
233
163
N = int(input()) originalN = 0 +N if N == 2: print(1) exit() ans = 0 primenum = [2] count = [0 for _ in range(int(N**0.5)+2)] for k in range(3, len(count), 2): if count[k] == 0: primenum.append(k) for j in range(k, len(count), k): count[j] = 1 def factorization(n): lis = [] k = 0 while primenum[k] <= n: if n%primenum[k] == 0: c = 0 while n%primenum[k] == 0: n //= primenum[k] c += 1 lis.append([primenum[k], c]) else: k += 1 if k > len(primenum)-1: break if n > 1: lis.append([n, 1]) return lis list1 = factorization(N-1) #print(factorization(N-1)) ans1 = 1 for k in range(len(list1)): ans1*= list1[k][1]+1 ans1 -= 1 ans += ans1 #print(ans1) def operation(K): N = originalN while N%K == 0: N //= K if N%K == 1: return True else: return False list2 = factorization(N) #print(list2) factorlist = [1] for l in range(len(list2)): list3 = [] for j in range(list2[l][1]): for k in range(len(factorlist)): list3.append(factorlist[k]*list2[l][0]**(j+1)) factorlist += list3 factorlist = factorlist[1:-1] #print(factorlist) ans2 = 1 for item in factorlist: if operation(item): #print(item) ans2 +=1 ans += ans2 #print(ans2) print(ans)
n=int(input()) ans=set() ans.add(n) i=2 x = 1 while x * x <= n-1 : if (n-1) % x == 0: ans.add(x) ans.add((n-1)//x) x += 1 while i*i<=n: t=n while t%i==0: t/=i if t%i==1: ans.add(i) i+=1 print(len(ans)-1)
1
41,390,075,888,630
null
183
183
N, M, K = map(int, input().split()) friend = {} for i in range(M): A, B = map(lambda x: x-1, map(int, input().split())) if A not in friend: friend[A] = [] if B not in friend: friend[B] = [] friend[A].append(B) friend[B].append(A) block = {} for i in range(K): C, D = map(lambda x: x-1, map(int, input().split())) if C not in block: block[C] = [] if D not in block: block[D] = [] block[C].append(D) block[D].append(C) first = {} for i in range(N): if i not in first: first[i] = i if i in friend: queue = [] queue.extend(friend[i]) counter = 0 while counter < len(queue): item = queue[counter] first[item] = i if item in friend: for n in friend[item]: if n not in first: queue.append(n) counter += 1 size = {} for key in first: if first[key] not in size: size[first[key]] = 1 else: size[first[key]] += 1 for i in range(N): if i not in friend: print(0) continue no_friend = 0 if i in block: for b in block[i]: if first[b] == first[i]: no_friend += 1 print(size[first[i]] - len(friend[i]) - no_friend - 1)
n , m = map(int,input().split(" ")) if n * 500 >= m: print("Yes") elif n * 500 < m: print("No")
0
null
79,577,603,024,768
209
244
#!/usr/bin/env python3 S = input() print(len(S) * 'x')
s=input() a=['x' for _ in range(len(s))] ans='' for aa in a: ans+=aa print(ans)
1
72,993,818,909,242
null
221
221
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) ans = abs(b - a) - (v - w) * t if ans > 0: print('NO') else: print('YES')
import bisect def solve(n, k, a): s = [0] * (n+1) for i in range(n): s[i+1] = s[i] + a[i] D = {} for i in range(n+1): p = (s[i] - i) % k if not p in D: D[p] = [] D[p].append(i) res = 0 for vs in D.values(): m = len(vs) for j, vj in enumerate(vs): i = bisect.bisect_left(vs, vj+k) - 1 res += i - j return res n, k = map(int, input().split()) a = list(map(int, input().split())) print(solve(n, k, a))
0
null
76,336,194,766,400
131
273
def solve(): a,b,c,d=[int(v) for v in input().split()] print(max(a*c, a*d, b*c, b*d)) t = 1 #int(input()) for _ in range(t): solve()
a, b = map(int, input().split()) al = [] b_lis = [] for _ in range(a): g = list(map(int, input().split())) g.append(sum(g)) al.append(g) for i in range(b+1): p = 0 for j in range(a): p += al[j][i] b_lis.append(p) al.append((b_lis)) for i in al: print(' '.join([str(v) for v in i]))
0
null
2,228,667,213,578
77
59
def insertionSort(A,n,g): cnt = 0 for i in range(g,n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v return cnt def shellsort(A,n): cnt = 0 h = 1 G = [] while h <= n: G.append(h) h = 3*h + 1 G.reverse() m = len(G) print(m) print(" ".join(map(str,G))) for i in range(m): cnt += insertionSort(A,n,G[i]) print(cnt) for i in A: print(i) n = int(input()) A = [] for _ in range(n): A.append(int(input())) shellsort(A,n)
N,M=list(map(int,input().split())) E={i:[] for i in range(1,N+1)} for i in range(M): a,b=list(map(int,input().split())) E[a].append(b) E[b].append(a) V={i:0 for i in range(1,N+1)} W=[1] while W!=[]: S=[] for a in W: for b in E[a]: if V[b]==0: V[b]=a S.append(b) W=S if -1 in V: print('No') else: print('Yes') for i in range(2,N+1): print(V[i])
0
null
10,329,928,913,080
17
145
import sys def slove(goods, carnum, P): tot_good = len(goods) cur_good = 0 for _ in range(carnum): load = 0 while cur_good < tot_good and goods[cur_good] <= P -load: load += goods[cur_good] cur_good += 1 if cur_good == tot_good: return True else: return False if __name__ == '__main__': datas = input().split(' ') good_num = int(datas[0]) car_num = int(datas[1]) goods = [] for _ in range(good_num): goods.append(int(input())) left = 0 right = sys.maxsize while left < right: mid = (left + right) // 2 if slove(goods, car_num, mid): # 当前的P较大 right = mid else: left = mid + 1 print(right)
n,t = map(int,input().split()) ab = [list(map(int,input().split())) for _ in range(n)] ab.sort() # 食べるのが早い順にソート # ナップザック問題に落とし込む dp = [[0 for i in range(t+1)]for j in range(n+1)] for i in range(n): ti,vi = ab[i] for j in range(t+1): # 食べたほうがよい(t秒以内かつ満足度が上がるならば) if j + ti <= t: dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi) # 食べなかった場合の最高値を更新 dp[i+1][j] = max(dp[i][j],dp[i+1][j]) ma = 0 for i in range(n): # 最後にi番目の皿を食べることができる ma = max(ma,dp[i][t-1]+ab[i][1]) print(ma)
0
null
75,612,141,915,968
24
282
N = int(input()) A = list(map(int, input().split())) j=0 for i in range(N): if A[i]==j+1: j+=1 if j == 0: print(-1) else: print(N-j)
N = int(input()) S, T = input().split() assert len(S) == N assert len(T) == N print(''.join([s + t for s, t in zip(S, T)]))
0
null
113,362,664,926,972
257
255
h,n = map(int,input().split()) lst = list(map(int,input().split())) if sum(lst) < h: print('No') else: print('Yes')
N = int(input()) S = input() slime = S[0] for i in range(1, N): if S[i] != slime[-1]: slime += S[i] print(len(slime))
0
null
124,014,624,132,662
226
293