code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
def main(): m = list(input()) q = int(input()) A = [] for _ in range(q): A.append(input().split()) for x in range(q): if A[x][0] == "print": A[x][1] = int(A[x][1]) A[x][2] = int(A[x][2]) for y in range(A[x][1], A[x][2] + 1): if y != A[x][2]: print(m[y], end = "") else: print(m[y]) elif A[x][0] == "reverse": A[x][1] = int(A[x][1]) A[x][2] = int(A[x][2]) hoge = [] for y in range(A[x][1], A[x][2] + 1): hoge.append(m[y]) hoge = hoge[::-1] i = 0 for y in range(A[x][1], A[x][2] + 1): m[y] = hoge[i] i += 1 elif A[x][0] == "replace": A[x][1] = int(A[x][1]) A[x][2] = int(A[x][2]) fuga = list(A[x][3]) j = 0 for y in range(A[x][1], A[x][2] + 1): m[y] = fuga[j] j += 1 if __name__ == "__main__": main()
string = input() num = int(input()) orders = [input().split() for _ in range(num)] for order in orders: start = int(order[1]) end = int(order[2]) + 1 if order[0] == "reverse": string = string[:start] + string[start:end][::-1] + string[end:] elif order[0] == "replace": string = string[:start] + order[3] + string[end:] elif order[0] == "print": print(string[start:end])
1
2,071,638,989,132
null
68
68
import bisect import copy import heapq import math import sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) sys.setrecursionlimit(500000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n=int(input()) a=list(map(int,input().split())) dic=defaultdict(int) ans=0 for i in range(n): ans+=dic[i-a[i]] dic[a[i]+i]+=1 print(ans)
n = int(input()) a = list(map(int, input().split())) count = {} for i in range(len(a)):#番号と身長を引く minus = (i+1) - a[i] if minus in count: count[minus] += 1 else: count[minus] = 1 total = 0 for i in range(len(a)): plus = a[i] + (i+1) if plus in count: total += count[plus] print(total)
1
26,030,393,866,180
null
157
157
import math a,b,x = map(int,input().split()) if x > a*a*b/2: tan = 2*(a*a*b - x)/(a*a*a) elif x <= a*a*b/2: tan = a*b*b/(2*x) print(math.degrees(math.atan(tan)))
#!/usr/bin python3 # -*- coding: utf-8 -*- h, n = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] #DP[i] = i までの魔法でモンスターの体力を減らすため消耗する魔力の最小値 dp = [0] * 20001 for i in range(h): dp[i] = min(dp[i-a] + b for a, b in ab) print(dp[h-1])
0
null
121,579,918,101,828
289
229
def main(): import sys input = sys.stdin.readline S = input().rstrip() print(S[:3]) if __name__ == '__main__': main()
n = int(input()) for i in range(n+1): if int((i * 1.08) // 1) == n: print(i) exit() print(":(")
0
null
70,008,878,844,032
130
265
HP, n = map(int, input().split()) AB = [list(map(int,input().split())) for _ in range(n)] # DP ## DP[i]は、モンスターにダメージ量iを与えるのに必要な魔力の最小コスト ## DPの初期化 DP = [float('inf')] * (HP+1); DP[0] = 0 ## HP分だけDPを回す. for now_hp in range(HP): ## 全ての魔法について以下を試す. for damage, cost in AB: ### 与えるダメージは、現在のダメージ量+魔法のダメージか体力の小さい方 next_hp = min(now_hp+damage, HP) ### 今の魔法で与えるダメージ量に必要な最小コストは、-> ####->現在わかっている値か今のHPまでの最小コスト+今の魔法コストの小さい方 DP[next_hp] = min(DP[next_hp], DP[now_hp]+cost) print(DP[-1])
h,n,*t = map(int,open(0).read().split()) dp = [0] + [10**8]* h for a,b in zip(*[iter(t)]*2): for life_point in range(h +1): original_life = max(0,life_point - a) # print(original_life) magic_consum = dp[original_life]+ b # print(magic_consum) dp[life_point] = min(dp[life_point],magic_consum) # print(dp) print(dp[h])
1
81,528,848,461,440
null
229
229
import collections N = int(input()) cnt = collections.defaultdict(int) for _ in range(N): s = input() cnt[s] += 1 max_v = max(cnt.values()) ans = sorted([k for k, v in cnt.items() if v == max_v]) for s in ans: print(s)
import sys input = sys.stdin.readline def solve_K_1(N): S = str(N) d = len(S) return 9 * (d - 1) + int(S[0]) def solve_K_2(N): if N <= 99: return N - solve_K_1(N) S = str(N) d = len(S) res = 0 res += 81 * (d - 1) * (d - 2) // 2 res += 9 * (d - 1) * (int(S[0]) - 1) x = 0 for i in range(1, d): if S[i] != "0": x = int(S[i]) break i += 1 res += x + 9 * (d - i) return res def solve_K_3(N): if N <= 999: return N - solve_K_1(N) - solve_K_2(N) S = str(N) d = len(S) res = 0 for n in range(3, d): res += 729 * (n - 1) * (n - 2) // 2 res += 81 * (d - 1) * (d - 2) // 2 * (int(S[0]) - 1) res += solve_K_2(int(S[1:])) return res def main(): N = int(input()) K = int(input()) if K == 1: ans = solve_K_1(N) elif K == 2: ans = solve_K_2(N) elif K == 3: ans = solve_K_3(N) print(ans) if __name__ == "__main__": main()
0
null
73,039,410,989,310
218
224
first_flag = True while True: H, W = map(int, input().split()) if H == 0 and W == 0: break if not first_flag: print() first_flag = False print(("#" * W + "\n") * H)
if __name__ == "__main__": lis = [] while True: a, b = map( int, input().split() ) if a == b == 0: break lis.append([a,b]) for i in lis: for j in range(i[0]): print('#'*i[1]) print()
1
781,267,770,560
null
49
49
s = [] s = input() if s[-1:] == "s": s += "es" print(s) else: s += "s" print(s)
a, b = map(int,input().split()) c, d = map(int,input().split()) if d == 1: print("1") else: print("0")
0
null
63,652,764,783,808
71
264
#!/usr/bin/env python3 def main(): N, K = map(int, input().split()) H = sorted([int(x) for x in input().split()]) if K == 0: print(sum(H)) elif N > K: print(sum(H[:-K])) else: print(0) if __name__ == '__main__': main()
from sys import exit N, K = [int(x) for x in input().split()] H = list([int(x) for x in input().split()]) if len(H) <= K: print(0) exit() H.sort(reverse=True) H = H[K:] print(sum(H))
1
78,670,445,694,826
null
227
227
r,c=map(int, input().split()) total=[0]*(c+1) for i in range(r): a=list(map(int, input().split())) a.append(sum(a)) print(*a) for j in range(c+1): total[j]+=a[j] print(*total)
r, c = [int (x) for x in input().split(' ')] a = [[0 for i in range(c)] for j in range(r)] for s in range(0,r): a[s] = [int (x) for x in input().split(' ')] for tr in range(0,r): total = 0 for v in a[tr]: total += v a[tr].append(total) total = [0 for i in range(c+1)] for tr in range(0,r): for tc in range(0,c+1): total[tc] += a[tr][tc] a.append(total) for i in range(r+1): a[i] = [str(a[i][j]) for j in range(c+1)] print(' '.join(a[i]))
1
1,363,121,636,800
null
59
59
def main(): X, K, D = map(int, input().split()) X = abs(X) a = X // D ans = 0 if a <= K: K -= a ans = X - D * a if K % 2 != 0: ans = abs(ans - D) else: ans = X - D * K print(ans) if __name__ == "__main__": main()
S = int(input()) n = S // 3 p = 1000000000 + 7 N = 2000 fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) def MOD_binom(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p answer = 0 for i in range(1, n + 1): answer += MOD_binom(S - 2*i - 1, i-1, p) print(answer % p)
0
null
4,233,902,282,136
92
79
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**7) import bisect import heapq import itertools import math import numpy as np from collections import Counter, defaultdict, deque from copy import deepcopy from decimal import Decimal from math import gcd from operator import add, itemgetter, mul, xor def cmb(n,r,mod): bunshi=1 bunbo=1 for i in range(r): bunbo = bunbo*(i+1)%mod bunshi = bunshi*(n-i)%mod return (bunshi*pow(bunbo,mod-2,mod))%mod mod = 10**9+7 def I(): return int(input()) def LI(): return list(map(int,input().split())) def MI(): return map(int,input().split()) def LLI(n): return [list(map(int, input().split())) for _ in range(n)] n = I() #graph[i]には頂点iと繋がっている頂点を格納する graph = [[] for _ in range(n+1)] prev_col = [0]*(n+1) a_b = [] k=0 for i in range(n-1): a,b = MI() a_b.append(str(a)+" "+str(b)) graph[a].append(b) graph[b].append(a) #check[i] == -1ならば未探索 check = [-1]*(n+1) check[0] = 0 check[1] = 0 for i in range(n+1): k = max(len(graph[i]),k) d = deque() d.append(1) ans = dict() while d: v = d.popleft() check[v] = 1 cnt = 0 for i in graph[v]: if check[i] != -1: continue cnt = cnt+1 if prev_col[v] == cnt: cnt = cnt + 1 prev_col[i] = cnt ans[str(min(i,v))+" "+str(max(i,v))]=cnt d.append(i) print(k) for key in a_b: print(ans[key])
S = str(input()) N = len(S) ans = "" for i in range(N): ans += "x" print(ans)
0
null
104,131,721,198,226
272
221
n, k = map(int, input().split()) MOD = 1000000007 def combinations(n, r, MOD): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * fact_inv[r] * fact_inv[n - r] % MOD fact = [1, 1] fact_inv = [1, 1] inv = [0, 1] for i in range(2, n + 1): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) fact_inv.append((fact_inv[-1] * inv[-1]) % MOD) s = 0 for num_zero in range(min(k + 1, n)): # nCz x = combinations(n, num_zero, MOD) # n-zCx y = combinations(n - 1, n - num_zero - 1, MOD) s += (x * y) % MOD print(s % MOD)
n = int(input()) s = input() #print(n , s , ' ') p = "ABC" ans = 0 for i in range(n - 2): if s[i : (i + 3)] == p : ans += 1 print(ans)
0
null
83,517,140,893,440
215
245
from sys import stdin def ip(): return [int(i) for i in stdin.readline().split()] def sp(): return [str(i) for i in stdin.readline().split()] s = str(input()) t = str(input()) ans = len(t) for i in range(len(s) - len(t) + 1): # print(f'{i=} | {ans=}') curr = len(t) for j in range(i, len(t) + i): # print(f'{curr=} | {s[j]=} | {t[j-i]=}') if s[j] == t[j-i]: curr -= 1 ans = min(ans, curr) print(ans)
n = int(input()) y = 1000 - (n % 1000) if y == 1000: y = 0 print(y)
0
null
6,119,771,867,988
82
108
ls = [] while True: try: n = int(raw_input()) except EOFError: break ls.append(n) ls.sort(reverse=True) print ls[0] print ls[1] print ls[2]
a = input() if(a[0]=='7' or a[1]=='7' or a[2]=='7'): print("Yes") else: print("No")
0
null
17,151,574,735,236
2
172
N,K=map(int,input().split()) l=list(map(int,input().split())) import math def f(n): A=0 for i in l: A+=math.ceil(i/n)-1 return A<=K def bis(ng,ok): while abs(ok-ng)>1: mid=(ok+ng)//2 if f(mid): ok=mid else: ng=mid return ok print(bis(0,max(l)))
M1,D1 = [int(i) for i in input().split()] M2,D2 = [int(i) for i in input().split()] if M1 != M2: print(1) else: print(0)
0
null
65,554,677,807,696
99
264
t = input().split() N = int(t[0]) M = int(t[1]) if N == M: print('Yes') else: print('No')
n = int(input()) l = list(map(int, input().split())) f = 1; c = 0 while f > 0: f = 0 for j in range(n-1, 0, -1): if l[j] < l[j-1]: l[j], l[j-1] = l[j-1], l[j] f = 1; c += 1 print(*l) print(c)
0
null
41,416,383,674,854
231
14
N, K = map(int,input().split()) i = 0 while True: if N/(K**i)<K: break i += 1 print(i+1)
N,K=map(int,input().split()) i=0 while True: if N<K**i: print(i) break i+=1
1
64,251,722,913,942
null
212
212
N = int(input().rstrip()) A = list(map(int, input().rstrip().split())) def bubble_sort(A, N): count = 0 flag = 1 while flag: flag = 0 for j in range(N-1, 0, -1): if A[j] < A[j-1]: A[j], A[j-1] = A[j-1], A[j] count += 1 flag = 1 return A, count A, count = bubble_sort(A, N) string = list(map(str, A)) print(' '.join(string)) print(count)
x, y = map(int, input().split()) ans = 'No' for i in range(x + 1): j = x - i if i * 2 + j * 4 == y: ans = 'Yes' break print(ans)
0
null
6,856,092,013,640
14
127
N = int(input()) def digitSum(n): s = str(n) array = list(map(int, s)) return sum(array) if digitSum(N) % 9 == 0: print("Yes") else: print("No")
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,459,732,471,570
null
87
87
# def merge(arr, l, mid, r): # L = [arr[i] for i in range(l, mid)] # R = [arr[i] for i in range(mid, r)] # L.append(int(1e9 + 10)) # R.append(int(1e9 + 10)) # i, j = 0, 0 # cnt = 0 # for k in range(l, r): # if L[i] <= R[j]: # arr[k] = L[i] # i += 1 # else: # arr[k] = R[j] # j += 1 # cnt += 1 # return cnt # def mergeSort(arr, l, r): # cnt = 0 # if l + 1 < r: # mid = (l + r) >> 1 # cnt += mergeSort(arr, l, mid) # cnt += mergeSort(arr, mid, r) # cnt += merge(arr, l, mid, r) # return cnt # triky def count(l, r): cnt = 0 if l + 1 < r: mid = (l + r) >> 1 cnt += count(l, mid) cnt += count(mid, r) cnt += r - l return cnt cnt = count(0, int(input())) arr = list(map(int, input().split())) arr.sort() print(*arr) print(cnt)
N=int(input()) S=str(input()) ans = S.count("R")*S.count("G")*S.count("B") #print(ans) for i in range(N-2): for j in range(i+1,N-1): k = 2*j-i #print(i,j,k) if k <= N-1: if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]: ans -= 1 print(ans)
0
null
18,078,804,831,408
26
175
from bisect import bisect_left n = int(input()) L = list(map(int, input().split())) L.sort() cnt = 0 for a in range(n-2): for b in range(a+1, n-1): cnt += bisect_left(L,L[a]+L[b])-(b+1) print(cnt)
from bisect import bisect_left N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N): for j in range(i + 1, N): c = L[i] + L[j] # a+bが入る場所を返す idx = bisect_left(L, c) ans += max(0, idx - (j + 1)) print(ans)
1
171,964,390,381,348
null
294
294
while True: t = input() if t.find("?") > 0: break print(int(eval(t)))
from copy import copy import random import math import sys input = sys.stdin.readline D = int(input()) c = list(map(int,input().split())) s = [list(map(int,input().split())) for _ in range(D)] last = [0]*26 ans = [0]*D score = 0 for i in range(D): ps = [0]*26 for j in range(26): pl = copy(last) pl[j] = i+1 ps[j] += s[i][j] for k in range(26): ps[j] -= c[k]*(i+1-pl[k]) idx = ps.index(max(ps)) last[idx] = i+1 ans[i] = idx+1 score += max(ps) for k in range(1,37001): na = copy(ans) x = random.randint(1,365) y = random.randint(1,365) z = random.randint(min(x,y),max(x,y)) if x == y: continue na[x-1],na[y-1] = na[y-1],na[x-1] na[x-1],na[z-1] = na[z-1],na[z-1] last = [0]*26 ns = 0 for i in range(D): last[na[i]-1] = i+1 ns += s[i][na[i]-1] for j in range(26): ns -= c[j]*(i+1-last[j]) if k%100 == 1: T = 300-(298*k/37000) p = pow(math.e,-abs(ns-score)/T) if ns > score or random.random() < p: ans = na score = ns for a in ans: print(a)
0
null
5,174,829,929,282
47
113
n = int(input()) d = [list(map(int, input().split())) for _i in range(n)] c = 0 for i, j in d: if i==j: c += 1 if c == 3: print('Yes') import sys sys.exit() else: c = 0 print('No')
n = int(input()) t = 0 for _ in range(n): d1,d2 = map(int, input().split()) if d1 != d2: t = 0 else: t += 1 if t == 3: print("Yes") exit() print("No")
1
2,475,366,856,030
null
72
72
import sys import re from collections import Counter chardict = {chr(i):0 for i in range(97, 97+26)} str1 = sys.stdin.read() str1 = re.sub('[^a-z]', '', str1.lower()) counter = Counter(str1) for word in counter: chardict[word] = counter[word] charlist = sorted(chardict.items()) for x in charlist: print(x[0] + ' : ' + str(x[1]))
count = [0 for i in range(26)] while(1): try: str = raw_input().lower() except EOFError: break for i in range(len(str)): k = 97 for j in range(26): if str[i] == chr(k): count[j] += 1 k += 1 k = 97 for i in range(26): print "%s : %d" % (chr(k), count[i]) k += 1
1
1,667,953,621,050
null
63
63
while True: H, W = list(map(int, input().split())) if H == 0 & W == 0: break print(("#"*W + "\n")*H)
import queue n, quantum = map(int, input().split()) q = queue.Queue() for _ in range(n): name, time = input().split() q.put([name, int(time)]) spend_time = 0 while q.qsize() > 0: name, time = q.get() tmp = min(quantum, time) spend_time += tmp time -= tmp if time == 0: print('{} {}'.format(name, spend_time)) else: q.put([name, time])
0
null
415,258,262,232
49
19
N = int(input()) S = input() count = 0 for i in range(0, N - 2): if S[i] == 'A': if S[i+1] == 'B': if S[i+2] == 'C': count += 1 print(count)
def gcd(m, n): x = max(m, n) y = min(m, n) if x % y == 0: return y else: while x % y != 0: z = x % y x = y y = z return z def lcm(m, n): return (m * n) // gcd(m, n) # input A, B = map(int, input().split()) # lcm snack = lcm(A, B) print(snack)
0
null
106,183,025,831,640
245
256
N = input() print(N[:3])
n=input() print(n[0:3])
1
14,731,878,523,748
null
130
130
n=input() num_list=[int(x) for x in raw_input().split(" ")] for idx in range(1, len(num_list)): print " ".join([str(x) for x in num_list]) key=num_list[idx] jdx = idx - 1 while jdx >= 0 and num_list[jdx] > key: num_list[jdx+1] = num_list[jdx] jdx -= 1 num_list[jdx+1] = key print " ".join([str(x) for x in num_list])
import random D=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split())) for i in [0]*D] for i in range(D): print(random.randint(1,26))
0
null
4,899,360,589,062
10
113
from collections import Counter N,*A = map(int, open(0).read().split()) ac = Counter(A) if len(ac) == N: print('YES') else: print('NO')
#!/usr/bin/python3 # -*- coding: utf-8 -*- n, k, c = map(int, input().split()) S = [1 if a == "o" else 0 for a in input()] count = 0 X = [0] * n Y = [0] * n i = 0 while i < n: if S[i]: count += 1 X[i] = 1 i += c + 1 else: i += 1 if count > k: exit() i = n - 1 while i >= 0: if S[i]: Y[i] = 1 i -= c + 1 else: i -= 1 for i in range(0, n): if X[i] and Y[i]: print(i + 1)
0
null
57,312,132,566,598
222
182
n = int(input()) l = list(map(int,input().split())) if len(l) < 3: print(0) exit() count = 0 l = sorted(l) for i in range(n): for j in range(i+1,n): for k in range(j+1,n): if l[i] != l[j] != l[k] and l[i]+l[j] > l[k]: count += 1 print(count)
n = int(input()) l =list(map(int, input().split())) ans = 0 for i in range(n): for j in range(i+1, n): for k in range(j+1, n): if j > n-2 or k > n-1: continue if l[i] == l[j] or l[j] == l[k] or l[k] == l[i]: continue if abs(l[j] - l[k]) < l[i] < l[j] + l[k]: ans += 1 print(ans)
1
5,057,773,868,992
null
91
91
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,m = inpm() P = [] S = [] for i in range(m): tmp = input().split() P.append(int(tmp[0])) S.append(tmp[1]) AC = [0]*100001 WA = [0]*100001 for i in range(m): if S[i] == 'AC': AC[P[i]] = 1 elif S[i] == 'WA' and AC[P[i]] != 1: WA[P[i]] += 1 cnt_ac = 0 cnt_wa = 0 for i in range(1,n+1): if AC[i] == 1: cnt_ac += 1 cnt_wa += WA[i] print(cnt_ac,cnt_wa)
# -*- coding: utf-8 -*- import sys from collections import deque, defaultdict from math import sqrt, factorial # def input(): return sys.stdin.readline()[:-1] # warning not \n # def input(): return sys.stdin.buffer.readline().strip() # warning bytes # def input(): return sys.stdin.buffer.readline().decode('utf-8') def solve(): n, m = [int(x) for x in input().split()] ac = set() pen = defaultdict(int) pp = 0 for _ in range(m): p, S = [x for x in input().split()] if p not in ac and S == 'AC': ac.add(p) pp += pen[p] else: if not p in ac: pen[p] += 1 print(len(ac), pp) t = 1 # t = int(input()) for case in range(1,t+1): ans = solve() """ """
1
93,611,770,357,270
null
240
240
n = int(input()) a = [int(i) for i in input().split()] k = 1 + n%2 dp = [[-float('inf')] * (k + 2) for i in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(k + 1): dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]) now = dp[i][j] if (i + j) % 2 == 0: now += a[i] dp[i + 1][j] = max(dp[i + 1][j], now) print(dp[n][k])
import sys,math,copy,queue,itertools,bisect LI = lambda : [int(x) for x in sys.stdin.readline().split()] _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) MOD = 10**9 + 7 INF = 10**15 N = NI() A = LI() ans = 0 if N % 2 == 0: for i in range(1,N,2): ans += A[i] x = ans for i in range(0,N,2): x = x + A[i] - A[i+1] ans = max(ans,x) else: dp = [0 for _ in range(3)] for i in range(N): ai = A[i] if i % 2 == 0: dp[1] = max(dp[0],dp[1]) dp[0] = dp[0] + ai if i % 2 == 1: dp[2] = max(dp[1],dp[2]) dp[1] += ai if i % 2 == 0 and i > 0: dp[2] += ai ans = max(dp[1],dp[2]) print (ans)
1
37,459,937,151,868
null
177
177
import numpy as np n = int(input()) a = np.array(list(map(int,input().split()))) ans = np.argsort(a) print(*ans + 1)
while 1: m,f,r=map(int, raw_input().split()) if m==f==r==-1: break s=m+f if m==-1 or f==-1 or s<30: R="F" elif s>=80: R="A" elif s>=65: R="B" elif s>=50: R="C" elif r>=50: R="C" else: R="D" print R
0
null
91,242,214,805,462
299
57
# 解説AC import sys input = sys.stdin.buffer.readline n = int(input()) A = list(map(int, input().split())) B = [] for i, e in enumerate(A): B.append((e, i + 1)) B.sort(reverse=True) # dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値 dp = [[-1] * (n + 1) for _ in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(i + 1): # 左の個数 k = i - j # 右の個数 ni = i + 1 val, idx = B[i] dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val) dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val) ans = 0 for i in range(n + 1): ans = max(ans, dp[n][i]) print(ans)
n = int(input()) s = input() ans = 0 ans = s.count('R')*s.count('G')*s.count('B') for i in range(0,n-2): for j in range(1,n-1): k = -i + 2*j if j < k <= n-1: if s[i] == s[j]: continue if s[i] == s[k]: continue if s[j] == s[k]: continue else: continue ans -= 1 print(ans)
0
null
34,845,359,182,858
171
175
# Forbidden List X, N = [int(i) for i in input().split()] pi = [int(i) for i in input().split()] pl = [] pu = [] for i in pi: if i <= X: pl.append(i) if X <= X: pu.append(i) pl.sort(reverse=True) pu.sort() nl = X for i in pl: if i == nl: nl -= 1 nu = X for i in pu: if i == nu: nu += 1 if X - nl <= nu - X: print(nl) else: print(nu)
import sys, math input = sys.stdin.readline rs = lambda: input().strip() ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) mod = 10**9 + 7 N = ri() print(math.ceil(N / 2) / N)
0
null
95,224,878,612,288
128
297
a,b=map(int,input().split()) while b: a,b=b,a%b print(a)
#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)
1
8,076,533,308
null
11
11
#単位元を設定 ide = 0 class SegmentTree: def __init__(self,n): #セグ木の頂点はindex == 1から。index == 0は無視すること。 #つまり、STtable[0]は無視。頂点はSTtable[1]。 self.n = n tmp = 0 while True: if 2 ** tmp >= self.n: break tmp += 1 self.STtable = [ide] * (2*2**tmp) self.STtable_size = len(self.STtable) def update(self,i,a): #更新のためのインデックスの指定は0_indexedで。 a_bit = 1 << ord(a)-97 i += self.STtable_size//2 self.STtable[i] = a_bit while i > 0: i //= 2 self.STtable[i] = self.STtable[i*2] | self.STtable[i*2+1] def find(self,a,b,k=1,l=0,r=None): #kは頂点番号。初期値は1にすること。 #[a,b)の最小を返す。 #[l,r)からです。 #初期値のrは、self.STtable_size//2にすると、ちょうど要素数と同じ値になって[l,r)のrになる。 #問題に適するように範囲を指定するように注意。大体[l,r]で指定されている。 if r == None: r = self.STtable_size//2 if a >= r or b <= l: return ide elif a <= l and b >= r: return self.STtable[k] else: mid = (l+r)//2 if b <= mid: return self.find(a,b,2*k,l,mid) elif a >= mid: return self.find(a,b,2*k+1,mid,r) else: v1 = self.find(a,mid,2*k,l,mid) v2 = self.find(mid,b,2*k+1,mid,r) return v1 | v2 N = int(input()) solve = SegmentTree(N) S = input() for i in range(N): solve.update(i,S[i]) Q = int(input()) ans = [] for _ in range(Q): a,b,c = map(str, input().split()) if a == '1': solve.update(int(b)-1,c) else: tmp = solve.find(int(b)-1,int(c)) cnt = 0 for i in range(26): if tmp >> i & 1 == 1: cnt += 1 ans.append(cnt) for a in ans: print(a)
from bisect import bisect_left,bisect_right TO_ACII = 97 N = int(input()) S = ["0"] + list(input()) Q = int(input()) ABC = [[]for i in range(0,26,1)]#該当文字a:0 b:1 ...z:26 が何文字目に出てきたかを保持する配列 for i in range(1,N+1,1): ABC[ord(S[i])-TO_ACII].append(i) ans = [] for i in range(0,Q,1): q = list(input().split()) if q[0]=="1":#文字変更 changed = S[int(q[1])] ABC[ord(changed)-TO_ACII].pop(bisect_left(ABC[ord(changed)-TO_ACII],int(q[1]))) ABC[ord(q[2])-TO_ACII].insert(bisect_left(ABC[ord(q[2])-TO_ACII],int(q[1])),int(q[1])) S[int(q[1])]=q[2] else: tmpans = 0 for i in range(0,26,1): if bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) and int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)]: tmpans+=1 ans.append(tmpans) for i in range(0,len(ans),1): print(ans[i])
1
62,493,900,524,058
null
210
210
import sys input = sys.stdin.readline x, y = [int(x) for x in input().split()] ans = 0 for i in [x, y]: if i == 1: ans += 300000 elif i == 2: ans += 200000 elif i == 3: ans += 100000 if x == 1 and y == 1: ans += 400000 print(ans)
import math from collections import deque def main(): t = [int(t)for t in input().split()] x,y = t[0],t[1] earned = 0 if x == 1: earned += 300000 elif x == 2: earned += 200000 elif x == 3: earned += 100000 if y == 1: earned += 300000 elif y == 2: earned += 200000 elif y == 3: earned += 100000 if x == y and x == 1: earned += 400000 print(earned) if __name__ == "__main__": main()
1
140,338,088,630,828
null
275
275
mod = 10**9 + 7 X, Y = map(int, input().split()) if (X+Y) % 3 != 0: print(0) exit() a = (2*Y-X)//3 b = (2*X-Y)//3 if a < 0 or b < 0: print(0) exit() m = min(a, b) ifact = 1 for i in range(2, m+1): ifact = (ifact * i) % mod ifact = pow(ifact, mod-2, mod) fact = 1 for i in range(a+b, a+b-m, -1): fact = (fact * i) % mod print(fact*ifact % mod)
# 最大公約数を求める def gcm(m, n): # mを小さくする if m > n: _temp = n n = m m = _temp while m != 0: #print("{}, {}".format(m, n)) m, n = n % m, m return n a, b, = map(int, input().split()) g = gcm(a, b) print("{}".format((int)(a * b / g)))
0
null
131,984,787,481,510
281
256
N = int(input()) S, T = input().split() L = [S[i]+T[i] for i in range(N)] print(*L, sep="")
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) # INF = float("inf") INF = 10**18 import bisect import statistics mod = 10**9+7 # mod = 998244353 N = int(input()) S, T = map(str, input().split()) ans = "" for i in range(N): ans += S[i] + T[i] print(ans)
1
111,884,996,753,442
null
255
255
import math print(2*float(input())*math.pi)
r = int(input()) print(2*r*3.14159265358)
1
31,502,129,901,998
null
167
167
s=input() t=input() ans=10**8 n=len(s) m=len(t) for i in range(n-m+1): cnt=0 for j in range(m): if s[i+j]!=t[j]: cnt+=1 ans=min(ans,cnt) print(ans)
S = input() T = input() max_match = 0 n = len(T) m = len(S) for i in range(m-n+1): tmp = 0 for j in range(i,i+n): if S[j] == T[j-i]: tmp += 1 if tmp > max_match: max_match = tmp ans = n - max_match print(ans)
1
3,658,115,923,260
null
82
82
a = list(map(int,input().split())) if(a[0] < a[1]): print("a < b") elif(a[0] > a[1]): print("a > b") else: print("a == b")
import re n = int(input()) s = input() res = re.findall(r'ABC',s) print(len(res))
0
null
49,648,463,397,376
38
245
N, K = (int(x) for x in input().split()) ans=0 while(N>=1): N = int(N/K) ans+=1 print(ans)
n,k = map(int, input().split()) for i in range(50): if n < pow(k,i): print(i) exit()
1
64,163,530,828,550
null
212
212
mountains = [] for x in range(10): mountains.append(int(raw_input())) mountains.sort() print(mountains[-1]) print(mountains[-2]) print(mountains[-3])
n = int(input()) inf = 10 ** 10 buy = inf ans = -inf for i in range(n): price = int(input()) ans = max(ans, price - buy) buy = min(buy, price) print(ans)
0
null
6,972,699,888
2
13
t = input().lower() cnt = 0 while True: w = input() if w == 'END_OF_TEXT': break cnt += len(list(filter(lambda x: x == t, [v.lower() for v in w.split(' ')]))) print(cnt)
import re W = input() T = [] count = 0 while(1): line = input() if (line == "END_OF_TEXT"): break words = list(line.split()) for word in words: T.append(word) for word in T: matchOB = re.fullmatch(W, word.lower()) if matchOB: count += 1 print(count)
1
1,803,738,090,870
null
65
65
t1, t2 = map(int, input().split()) a1, a2 = map(int, input().split()) b1, b2 = map(int, input().split()) if a1>b1: a1, a2, b1, b2 = b1, b2, a1, a2 init = (a1-b1)*t1+(a2-b2)*t2 if init<0: print(0) exit(0) elif init==0: print('infinity') exit(0) lim = (b1-a1)*t1 if lim%init==0: print(lim//init*2) else: print(lim//init*2+1)
n=int(input()) a=list(map(int,input().split())) mod=10**9+7 x=sum(a)%mod y=0 for i in range(n): y+=a[i]**2 y%=mod z=pow(2,mod-2,mod) print(((x**2-y)*z)%mod)
0
null
67,487,904,440,022
269
83
def main(): N = int(input()) S = input() cnt = 0 for i in range(N): for j in range(i + 1, N): k = 2 * j - i if k >= N: continue if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]: cnt += 1 print(S.count("R") * S.count("B") * S.count("G") - cnt) if __name__ == "__main__": main()
def solve(N, S): ans = 0 R, G, B = 0, 0, 0 for i in range(N): if S[i] == "R": R += 1 elif S[i] == "G": G += 1 else: B += 1 # print(R, G, B, R*G*B) ans = R * G * B dif = 1 while dif <= N//2+1: idx = 0 while idx + dif + dif < N: if S[idx] != S[idx + dif] and S[idx+dif] != S[idx+2*dif] and S[idx+2*dif] != S[idx]: ans -= 1 idx += 1 dif += 1 print(ans) if __name__ == '__main__': # N = 4000 # S = 'RGBR' * 1000 N = int(input()) S = input() solve(N, S)
1
35,963,278,799,770
null
175
175
import math import collections import fractions import itertools import functools import operator import bisect N = int(input()) def solve(): cnt = 0 for i in range(1, N): cnt += (N-1)//i print(cnt) return 0 if __name__ == "__main__": solve()
#from collections import deque #from heapq import heapify, heappop, heappush #from bisect import insort #from math import gcd #from decimal import Decimal #mod = 1000000007 #mod = 998244353 #N = int(input()) #N, K = map(int, input().split()) #A = list(map(int, input().split())) #flag = True #for k in range(N): #ans = 0 #print(ans) #print('Yes') #print('No') N = int(input()) ans = 0 #N, K = map(int, input().split()) #A = list(map(int, input().split())) #flag = True for B in range(1, N+1): ans += N//B if N%B == 0: ans -= 1 #ans = 0 print(ans) #print('Yes') #print('No')
1
2,573,349,097,752
null
73
73
def my_eval(ar,str): res = True n = len(str) # print(n) # print("start") for i in range(n): # print(i) if(ar[str[i][0]] == 1): # print(str[i][0]) # print(str[i][1]) # print(str[i][2]) # print(ar[str[i][1]-1]) # print(ar[str[i][1]-1] == str[i][2]) # print(ar) # print() if(ar[str[i][1]] != str[i][2]): res = False # print("end") # print() return res if __name__ == "__main__": # 全探索 n = int(input()) str = [] for i in range(n): a = int(input()) for j in range(a): x = list(map(int,input().split())) x.insert(0,i+1) str.append(x) ar = [0] * (n+1) res = 0 # print(str) count = 0 for i in range(2**n): count = 0 for j in range(n): if(i >> j & 1 == 1): ar[j+1] = 1 count += 1 else: ar[j+1] = 0 # print(ar) if(my_eval(ar,str)): res = max(res,count) print(res)
N=int(input()) Ins=[[] for _ in range(N)] ans=0 #0-indexedにしておく for i in range(N): A=int(input()) for _ in range(A): x,y=map(int,input().split()) Ins[i].append((x-1,y)) for i in range(2**N): flag=1 honest=[] unkind=[] for j in range(N): if (i>>j)&1: honest.append(j) else: unkind.append(j) #ここまでは想定の組み合わせを作る作業 for k in honest: #honestな人の証言を見ていく for l in Ins[k]: if l[1]==1 and l[0] in unkind: flag=0 break #honestな人がある人物をhonestと答えたのにも関わらず #その人がunkindに入るような組み合わせは駄目...ケース1 elif l[1]==0 and l[0] in honest: flag=0 break #honestな人がある人物をunkindと答えたのにも関わらず #その人がhonestに入るような組み合わせは駄目...ケース2 if flag==1: ans=max(ans,len(honest)) #ケース1にもケース2にも該当しない場合 #現在のhonestの人数をansと比較して大きい方を採用 print(ans)
1
121,860,911,270,300
null
262
262
from calendar import day_name s = input() for i in range(7): if s == day_name[i][:3].upper(): ans = 6 - i if ans == 0: ans += 7 print(ans) break
# 入力 S = input('') # 比較して出力 if S == str('SUN'): print(7) elif S == str('MON'): print(6) elif S == str('TUE'): print(5) elif S == str('WED'): print(4) elif S == str('THU'): print(3) elif S == str('FRI'): print(2) else: print(1)
1
133,343,316,392,452
null
270
270
def gcd(x, y): if x < y: return gcd(y, x) if y == 0: return x return gcd(y, x % y) x, y = map(int, input().split()) print(gcd(x, y))
n, x, y = int(input()), list(map(int, input().split())), list(map(int, input().split())) def dist(p): return pow(sum(pow(abs(a - b), p) for a, b in zip(x, y)), 1.0 / p) for i in [1, 2, 3]: print(dist(i)) print(max(abs(a - b) for a, b in zip(x, y)))
0
null
108,809,898,528
11
32
N = int(input()) A = list(map(int, input().split())) answer = 'DENIED' for i in range(0, N): if A[i] % 2 == 0: if A[i] % 3 == 0 or A[i] % 5 == 0: answer = 'APPROVED' else: answer = 'DENIED' break else: answer = 'APPROVED' print(answer)
import numpy as np N = int(input()) x = [] y = [] xy1 = [] xy2 = [] for i in range(N): a, b = (int(t) for t in input().split()) x.append(a) y.append(b) xy1.append(a + b) xy2.append(a - b) max1 = max(xy1) - min(xy1) max2 = max(xy2) - min(xy2) print(max((max1, max2)))
0
null
36,305,070,738,840
217
80
for i in range(9): for j in range(9): print "%dx%d=%d" %(i+1,j+1, (i+1)*(j+1))
i = range(1,10) for i in ['%dx%d=%d' % (x,y,x*y) for x in i for y in i]: print i
1
1,171,660
null
1
1
w = input().lower() count = 0 while True: s = input() if s == "END_OF_TEXT": break count += s.lower().split().count(w) print(count)
s = raw_input() s = s.lower().strip() cnt = 0 while True: text = raw_input() if 'END_OF_TEXT' == text.strip(): break text = text.lower() for item in text.split(): if item == s: cnt += 1 print cnt
1
1,792,803,879,060
null
65
65
import queue h,w = map(int,input().split()) v = [(1, 0), (0, 1), (-1, 0), (0, -1)] s = [input() for i in range(h)] ans = 0 que = queue.Queue() for i in range(h * w): c = 0 d = [[h*w] * w for i in range(h)] p = (i//w, i%w) if s[p[0]][p[1]] == '#': continue d[p[0]][p[1]] = 0 que.put(p) while not que.empty(): y,x = que.get() c = d[y][x] for dy, dx in v: yy = y + dy xx = x + dx if yy < 0 or xx < 0 or h <= yy or w <= xx: continue if s[yy][xx] == '#': continue if d[yy][xx] < h*w: continue que.put((yy, xx)) d[yy][xx] = c + 1 ans = max(ans, c) print(ans)
def sol(s, p): n = len(s) cnt = 0 if p == 2 or p == 5: for i in range(n): if (s[i] % p == 0): cnt += i + 1 else: pre = [0] * (n+2) pre[n+1] = 0 b = 1 for i in range(n, 0, -1): pre[i] = (pre[i+1] + s[i-1] * b) % p b = (b * 10) % p rec = [0] * p rec[0] = 1 for i in range(n, 0, -1): cnt += rec[pre[i]] rec[pre[i]] += 1 return cnt if __name__ == "__main__": n, p = map(int, input().split()) s = input() print (sol([int(i) for i in s], p))
0
null
76,329,647,638,280
241
205
def selection_sort(A, N): count = 0 for i in range(N): min_j = i for j in range(i, N): if A[j] < A[min_j]: min_j = j if i != min_j: A[i], A[min_j] = A[min_j], A[i] count += 1 print " ".join(map(str, A)) print count N = input() A = map(int, raw_input().split()) selection_sort(A, N)
h,n = map(int,input().split()) L = list(map(int,input().split())) L.sort(reverse = True) cnt = 0 for i in range(n): cnt += L[i] if cnt >= h: print("Yes") exit() print("No")
0
null
39,193,407,469,892
15
226
print((lambda a: len([i for i in range(a[0], a[1]+1) if a[2] % i == 0]))(list(map(int, input().split()))))
a, b, c = (int(x) for x in input().split()) tmp = 0 for i in range(2): if a > b: tmp = a a = b b = tmp if b > c: tmp = b b = c c = tmp if a > c: tmp = a a = c c = tmp print(a, b, c)
0
null
488,504,705,690
44
40
import sys # sys.setrecursionlimit(100000) def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return [int(i) for i in input().split()] def main(): n = input_int() A = input_int_list() MOD = 10**9 + 7 cnt = 1 x, y, z = 0, 0, 0 for a in A: tmp = 0 is_used = False # x,y,zのどこかに配った。 if a == x: tmp += 1 if not is_used: x += 1 is_used = True if a == y: tmp += 1 if not is_used: y += 1 is_used = True if a == z: tmp += 1 if not is_used: z += 1 is_used = True cnt *= tmp cnt = cnt % MOD print(cnt) return if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし S = LS2() N = len(S)+1 ANS = [0]*N for i in range(N-1): if S[i] == '<': ANS[i+1] = ANS[i]+1 for i in range(N-2,-1,-1): if S[i] == '>': ANS[i] = max(ANS[i],ANS[i+1]+1) print(sum(ANS))
0
null
143,676,905,518,940
268
285
(N,) = [int(x) for x in input().split()] brackets = [input() for i in range(N)] delta = [] minDelta = [] for s in brackets: balance = 0 mn = 0 for c in s: if c == "(": balance += 1 else: balance -= 1 mn = min(mn, balance) delta.append(balance) minDelta.append(mn) if sum(delta) == 0: # Want to get balance as high as possible # Take any positive as long there's enough balance to absorb their minDelta # Can sort since anything that works will only increase balance and the ones with worse minDelta comes later posIndices = [i for i in range(N) if delta[i] > 0] posIndices.sort(key=lambda i: minDelta[i], reverse=True) # At the top can take all with zero delta, just need to absorb minDelta eqIndices = [i for i in range(N) if delta[i] == 0] # When going back down, want to preserve existing balance as much as possible but take a hit for stuff that does need to use the balance to absorb minDelta negIndices = [i for i in range(N) if delta[i] < 0] negIndices.sort(key=lambda i: delta[i] - minDelta[i], reverse=True) balance = 0 for i in posIndices + eqIndices + negIndices: if balance + minDelta[i] < 0 or balance + delta[i] < 0: print("No") exit() balance += delta[i] assert balance == 0 print("Yes") else: print("No")
n=int(input()) stri=[] time=[] for _ in range(n): s,t=input().split() stri.append(s) time.append(t) x=input() ind=stri.index(x) ans=0 for i in range(ind+1,n): ans+=int(time[i]) print(ans)
0
null
60,298,572,835,798
152
243
s = list(input()) k = int(input()) n = len(s) if s == [s[0]]*n: print(n*k//2) else: ss = s*2 ans1 = 0 for i in range(1, n): if s[i] == s[i -1]: s[i] = "" ans1 += 1 ans2 = 0 for i in range(1, 2*n): if ss[i] == ss[i - 1]: ss[i] = "" ans2 += 1 j = ans2 - ans1 print(ans1 + j*(k - 1))
from array import array def readinput(): n=int(input()) a=array('L',list(map(int,input().split()))) return n,a count=0 def merge(a,left,mid,right): INFTY=10**9+1 global count n1=mid-left n2=right-mid #L=[a[left+i] for i in range(n1)] L=a[left:mid] L.append(INFTY) #R=[a[mid+i] for i in range(n2)] R=a[mid:right] R.append(INFTY) i=0;j=0 for k in range(left,right): if(L[i]<=R[j]): a[k]=L[i] i+=1 else: a[k]=R[j] j+=1 count+=1 def mergeSort(a,left,right): if(left+1<right): mid=(left+right)//2 mergeSort(a,left,mid) mergeSort(a,mid,right) merge(a,left,mid,right) return def main(n,a): global count mergeSort(a,0,n) return a,count if __name__=='__main__': n,a=readinput() a,count=main(n,a) print(' '.join(map(str,a))) print(count)
0
null
87,510,751,303,680
296
26
import itertools def solve(): s, t = input().split() return t+s print(solve())
from collections import deque N,u,v = map(int,input().split()) u -= 1 v -= 1 adj = [ [] for _ in range(N) ] for _ in range(N-1): a,b = map(int,input().split()) a -= 1 b -= 1 adj[a].append(b) adj[b].append(a) def bfs(v): visited = [False] * N q = deque([v]) span = [-1] * N s = 0 while q: l = len(q) newq = deque([]) for _ in range(l): node = q.popleft() visited[node] = True span[node] = s for nei in adj[node]: if not visited[nei]: newq.append(nei) q = newq s += 1 return span t = bfs(u) a = bfs(v) ans = 0 for i in range(N): if t[i] <= a[i]: ans = max(ans, a[i]-1) print(ans)
0
null
110,507,024,537,292
248
259
from decimal import Decimal A,B=input().split() A=int(A) B=Decimal(B) Bint=int(B) B1=int((B-Bint)*100) result=A*Bint+A*B1//100 print(result)
N=int(input()) A=[int(i) for i in input().split()] S=set(A) ans=1 for i in A: ans*=i if ans>10**18: ans=-1 break if 0 in S: ans=0 print(ans)
0
null
16,381,255,786,482
135
134
N, M = (int(_) for _ in input().split()) if N % 2 == 0: s = (N - 1) // 4 + 1 ret = [] for i in range(1, s): ret.append((i, N - i)) for i in range(s, N // 2): ret.append((i, N - i - 1)) else: ret = [] for i in range(1, (N // 2) + 1): ret.append((i, N - i)) for r0, r1 in ret[:M]: print(r0, r1)
N=int(input()) s=[] t=[] for i in range(N): x,y=input().split() s.append(x) t.append(int(y)) X=input() begin_idx=s.index(X)+1 print(sum(t[begin_idx:]))
0
null
62,848,695,362,068
162
243
a,b,c,d=map(int,input().split()) for i in range(1001): if i%2==0: c-=b if c<=0: print("Yes") exit(0) else: a-=d if a<=0: print("No") exit(0)
a, b, c, d = map(int, input().split()) def kaisuu(atk, hp): if (hp/atk) > (hp//atk): return hp//atk + 1 else: return hp//atk if kaisuu(b,c) <= kaisuu(d,a): print("Yes") else: print("No")
1
29,701,934,976,160
null
164
164
palavra= input() tam= len(palavra) if palavra[tam-1]=='s': print(palavra+'es') else: print(palavra+'s')
import sys def I(): return int(sys.stdin.readline().rstrip()) def Main(): x = I() for a in range(-118,120): for b in range(-118,120): if a**5-b**5 == x: print(a,b) exit() return if __name__=='__main__': Main()
0
null
13,883,266,606,208
71
156
import math x1,y1,x2,y2 = map(float,raw_input().split(' ')) x = abs(x1-x2); y = abs(y1-y2); a = math.sqrt(x**2 + y**2) print a
a, b = input().split() op = ['==', '>', '<'] result = int(a) - int(b) if result != 0: result = result // abs(result) print('a ' + op[result] + ' b')
0
null
267,735,707,980
29
38
class Dic: def __init__(self): self.end = False self.a = self.c = self.g = self.t = 0 def insert(self, s): node = self index = 0 while index < len(s): c = s[index] child = 0 if c == 'A': if not node.a: node.a = Dic() child = node.a elif c == 'C': if not node.c: node.c = Dic() child = node.c elif c == 'G': if not node.g: node.g = Dic() child = node.g elif c == 'T': if not node.t: node.t = Dic() child = node.t else: return node = child index += 1 node.end = True def find(self, s): node = self index = 0 while index < len(s): c = s[index] child = 0 if c == 'A': child = node.a elif c == 'C': child = node.c elif c == 'G': child = node.g elif c == 'T': child = node.t if child == 0: return False node = child index += 1 return node.end dic = Dic() n = int(input()) for _ in range(n): cmd = list(input().split()) if cmd[0] == 'insert': dic.insert(cmd[1]) elif cmd[0] == 'find': print('yes' if dic.find(cmd[1]) else 'no')
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) point_start_with = [0 for i in range(n)] roop_count = [1 for i in range(n)] for i in range(n): now = (i + 1) now_score = 0 while p[now - 1] != (i + 1): now = p[now - 1] now_score += c[now - 1] roop_count[i] += 1 point_start_with[i] = now_score # 多分0でいい ans = -(10**9 * 5000) for i in range(n): # iからスタートする場合 score = 0 remain_move = 0 cand_score = 0 if point_start_with[i] + c[i] > 0 and k > roop_count[i]: # 一周以上する可能性がある場合 # n週して、残りの動ける回数 # print("Yes") round_count = (k // roop_count[i]) - 1 remain_move = k - round_count * roop_count[i] cand_score = round_count * ( point_start_with[i] + c[i] ) else: remain_move = min(k,roop_count[i]) score = -(10**9 * 5000) cand_score = 0 now = i for j in range(remain_move): now = p[now] - 1 cand_score += c[now] score = max(score, cand_score) # print("start : {} score : {}".format(i,score)) ans = max(score, ans) print(ans)
0
null
2,746,401,282,504
23
93
N = int(input()) import math import sys for i in range(1, 50000+1): if math.floor(i * 1.08) == N: print(i) sys.exit() print(":(")
import itertools # input H, W, K = map(int, input().split()) S = [list(map(int, input())) for _ in range(H)] # process ans = H*W for divr in range(1<<(H-1)): # 横方向の分割を総当たり row = 0 Sr = [[S[0][i] for i in range(W)]] for i in range(1, H): if 1&(divr>>i-1): row += 1 Sr.append([S[i][j] for j in range(W)]) else: Sr[row] = [Sr[row][j]+S[i][j] for j in range(W)] # 縦方向の分割を加算 cnt = [0]*(row+1) ans_ = row flg = True for i in range(W): for j in range(row+1): if Sr[j][i] > K: flg = False break cnt[j] += Sr[j][i] if cnt[j] > K: ans_ += 1 cnt = [0]*(row+1) for l in range(row+1): cnt[l] += Sr[l][i] break if ans_ >= ans or not flg: break if flg: ans = min(ans, ans_) # output print(ans)
0
null
86,872,077,745,572
265
193
N = int(input()) gacha = set() for _ in range(N): gacha.add(input()) print(len(gacha))
N=int(input()) print(len(set([input() for _ in range(N)])))
1
30,371,533,934,004
null
165
165
N=int(input()) A=list(map(int,input().split())) mod=10**9+7 buf=0 s=0 for k in range(N-1): buf=(buf+A[N-1-k])%mod s=(s+A[N-2-k]*buf)%mod print(s)
n = int(input()) a = list(map(int, input().split())) ruiseki = 0 count = 0 for i in range(n-1): ruiseki += a[i] count += ruiseki * a[i+1] mod = 10**9 + 7 if count >= mod: print(count%mod) else: print(count)
1
3,824,227,011,152
null
83
83
import math a = int(input()) if a%2 == 0: print(int((a/2-1))) else: b = int(math.floor(a/2)) print(b)
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) res = 0 for i in range(1, (n + 1) // 2): if i != n - i: res += 1 print(res) if __name__ == '__main__': resolve()
1
152,801,132,685,410
null
283
283
nums = input().split() print(int(nums[0]) * int(nums[1]))
N=int(input()) if N%2==0: ans=0 x=10 while x<=N: ans+=N//x x*=5 else: ans=0 print(ans)
0
null
65,742,814,526,180
133
258
A, B = map(int, input().split()) if A>=10 or B>=10: print('-1') exit() else: print(A*B)
from bisect import bisect_left N, M = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) l = 0 r = 2*10**5+5 while l+1 < r: mid = (l+r) // 2 m = 0 for a in A: idx = bisect_left(A, mid-a) m += N-idx if m >= M: l = mid else: r = mid s = [0] * (N+1) for i in range(N): s[i+1] = s[i] + A[i] ans = 0 m = 0 for a in A: idx = bisect_left(A, l-a) m += N-idx ans += s[N]-s[idx] ans += a*(N-idx) ans -= (m-M)*l print(ans)
0
null
133,068,845,031,710
286
252
from collections import deque as D line, stack = D(input().split()), D() while line: hoge = line.popleft() if hoge.isdigit(): stack.append(hoge) else: a, b = int(stack.pop()), int(stack.pop()) if hoge == "*": stack.append(a*b) elif hoge == "+": stack.append(a+b) elif hoge == "-": stack.append(b-a) else: stack.append(b//a) print(stack.popleft())
N, K = map(int, input().split()) H = list(map(int, input().split())) H.sort() count = 0 for i in range(0, N-K): count += H[i] print(count)
0
null
39,616,931,859,490
18
227
# coding: utf-8 # Your code here! n = input() t = "" for i in range(len(n)): m = str(n[i]) if (n[i].islower()): m = n[i].upper() else: m = n[i].lower() t += m print(t)
n = int(raw_input()) ls = [] for i in range(3,n+1): if i%3==0 or "3" in str(i) : ls.append(i) print " " + " ".join(map(str,ls))
0
null
1,236,400,921,262
61
52
def solve(n, k, s): a = [1 if s == 10**9 else s+1] * n for i in range(k): a[i] = s return " ".join(map(str, a)) n, k, s = map(int, input().split()) print(solve(n, k, s))
from math import gcd N = int(input()) num_lis = list(map(int, input().split())) def osa_k(max_num): lis = [i for i in range(max_num+1)] p = 2 while p**2 <= max_num: if lis[p] == p: for q in range(2*p, max_num+1, p): if lis[q] == q: lis[q] = p p += 1 return lis hoge = 0 for i in num_lis: hoge = gcd(hoge, i) if hoge > 1: print("not coprime") exit() d_lis = osa_k(max(num_lis)) tmp = set() for i in num_lis: num = i new_tmp = set() while num > 1: d = d_lis[num] new_tmp.add(d) num //= d for j in new_tmp: if j in tmp: print("setwise coprime") exit() else: tmp.add(j) print("pairwise coprime")
0
null
47,868,470,972,740
238
85
n=int(input()) s,p=10**100,10**100 t,q=-1000000000000,-1000000000000 for i in range(n): x,y=map(int,input().split()) s=min(s,x+y) t=max(t,x+y) p=min(p,x-y) q=max(q,x-y) print(max(t-s,q-p))
n = int(input()) xy_array = [list(map(int, input().split())) for _ in range(n)] th = pow(10, 9) z_max = -th z_min = th w_max = -th w_min = th for x, y in xy_array: z_max = max(x + y, z_max) z_min = min(x + y, z_min) w_max = max(x - y, w_max) w_min = min(x - y, w_min) ans = max(z_max - z_min, w_max - w_min) print(ans)
1
3,411,714,230,590
null
80
80
N = int(input()) d = {} for i in range(N): key = input() try: d[key] += 1 except KeyError: d[key] = 1 d = sorted(d.items(), key=lambda x: x[1], reverse=True) ans = [] max = 0 for i in d: if i[1] >= max: ans.append(i[0]) max = i[1] else: break for i in sorted(ans): print(i)
N = int(input()) L = list(map(int, input().split())) ans = 0 if N > 2: for i in range(N - 2): for j in range(i + 1, N - 1): for k in range(j + 1, N): tmp = [L[i], L[j], L[k]] if (len(tmp) == len(set(tmp))) and (L[i] + L[j] > L[k]) and ( L[j] + L[k] > L[i]) and (L[k] + L[i] > L[j]): ans += 1 print(ans)
0
null
37,514,944,276,524
218
91
#区間スケジューリング問題 N = int(input()) robots = {} for _ in range(N): X, L = list(map(int, input().split())) robots[X] = (X-L, X+L) #終端が早い順にソートして、取れるものから貪欲法でとっていく robots_sorted = sorted(robots.items(), key=lambda x:x[1][1]) ans = 1 current_robot = robots_sorted[0] for i in range(0, N): if current_robot[1][1] > robots_sorted[i][1][0]: continue ans += 1 current_robot = robots_sorted[i] print(ans)
N = int(input()) XL = [list(map(int, input().split())) for i in range(N)] LR = [[x - l, x + l] for x, l in XL] LR.sort(key=lambda x: x[1]) ans = 0 prev = -float("INF") for l, r in LR: if prev <= l: ans += 1 prev = r print(ans)
1
89,875,600,380,670
null
237
237
T = input() r_T = T.replace('?', 'D') #print(r_T.count('PD')) #print(r_T.count('D')) print(r_T)
T = input() count = 0 for c in T: count += 1 if c == '?' and T[count-1] == 'D': c = 'P' print(c, end="") elif c == '?': c = 'D' print(c, end="") else: print(c, end="")
1
18,391,340,612,868
null
140
140
hs=[int(input()) for i in range(10)] h=sorted(hs,reverse=True) for i in range(3): print(h[i])
# coding: utf-8 # Here your code ! array = [] for i in range(10): line = int(input()) array += [line] result = sorted(array)[::-1] print(result[0]) print(result[1]) print(result[2])
1
27,452,920
null
2
2
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**7) from pprint import pprint as pp from pprint import pformat as pf # @pysnooper.snoop() #import pysnooper # debug import math #from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder import bisect class Part: def __init__(self, string): self.slope, self.floor = self.calc_slope_floor(string) def __repr__(self): return "s{} f{}".format(self.slope, self.floor) def __lt__(self, other): if self.floor > other.floor: return True if self.slope > self.slope: return True return False @staticmethod def calc_slope_floor(string): slope = 0 floor = 0 for c in string: if c == '(': slope += 1 else: slope -= 1 floor = min(floor, slope) return slope, floor def flip(self): self.slope *= -1 self.floor += self.slope def catenate(self, other): assert(self.slope >= 0) if self.slope < abs(other.floor): return False self.slope += other.slope # self.floor is not needed def sum_slope(parts): s = 0 for p in parts: s += p.slope return s def calc_flat_floor(flat): floor = 0 for f in flat: floor = min(floor, f.floor) return floor def enable(parts): parts = sorted(parts) #print('parts') # debug #print(parts) # debug chain = Part("") for p in parts: flg = chain.catenate(p) if flg == False: return False return True def solve(up, down, flat): up_slope = sum_slope(up) down_slope = sum_slope(down) if up_slope != down_slope: return False flat_floor = calc_flat_floor(flat) #print('up_slope') # debug #print(up_slope) # debug #print('flat_floor') # debug #print(flat_floor) # debug if up_slope < abs(flat_floor): return False if not enable(up): return False if not enable(down): return False return True if __name__ == '__main__': n = int(input()) up = [] down = [] flat = [] for _ in range(n): s = input() p = Part(s) if p.slope > 0: up.append(p) elif p.slope < 0: p.flip() down.append(p) else: flat.append(p) ans = solve(up, down, flat) if ans: print("Yes") else: print("No") #print('\33[32m' + 'end' + '\033[0m') # debug
n = int(input()) L, R = [], [] for i in range(n): a, b = 0, 0 for c in input(): if c == '(': b += 1 if c == ')': if b > 0: b -= 1 else: a += 1 if -a + b > 0: L.append((a, b)) else: R.append((a, b)) L.sort(key=lambda x: x[0]) R.sort(key=lambda x: x[1], reverse=True) x = 0 for a, b in L + R: x -= a if x < 0: print('No') exit() x += b if x == 0: print('Yes') else: print('No')
1
23,708,283,437,788
null
152
152
H, N = map(int,input().split()) X = [list(map(int, input().split())) for i in range(N)] X = sorted(X, key = lambda x:x[0]) DP = [float("inf")]*(H+X[-1][0]+X[-1][0]) DP[X[-1][0]-1] = 0 for i in range(X[-1][0], H+2*X[-1][0]): min = float("inf") for j in range(N): if min > DP[i-X[j][0]]+X[j][1]: min = DP[i-X[j][0]]+X[j][1] DP[i] = min kouho = DP[H+X[-1][0]-1] for i in range(X[-1][0]): if kouho > DP[H+X[-1][0]+i]: kouho = DP[H+X[-1][0]+i] print(kouho)
import collections N = int(input()) hList = list(map(int, input().split())) count = 0 n_p = collections.Counter([ i + hList[i] for i in range(len(hList))]) for i in range(N): if i - hList[i] > 0: count += n_p.get(i - hList[i], 0) print(count)
0
null
53,477,854,563,490
229
157
import itertools N = int(input()) c = [] d = 0 for i in range(N): x1, y1 = map(int, input().split()) c.append((x1,y1)) cp = list(itertools.permutations(c)) x = len(cp) for i in range(x): for j in range(N-1): d += ((cp[i][j][0]-cp[i][j+1][0])**2 + (cp[i][j][1] - cp[i][j+1][1])**2)**0.5 print(d/x)
n, m = map(int, input().split(" ")) if n <= 9: print(m + (100 * (10 - n))) else: print(m)
0
null
106,161,697,576,100
280
211
n = int(input()) if n>=3: if n%2==0: print(n//2-1) else: print(n//2) else: print(0)
n = int(input()) print(max((n - 1)// 2, 0))
1
153,038,893,236,438
null
283
283
#3 Range Flip Find Route h,w = map(int,input().split()) s= [None for i in range(h)] for i in range(h): s[i] = input() dp = [[0]*w for i in range(h)] now=0 if s[0][0]=="#": now+=1 dp[0][0]=now for i in range(1,w): if s[0][i-1]=="." and s[0][i]=="#": now+=1 dp[0][i]=now now=0 if s[0][0]=="#": now+=1 for i in range(1,h): if s[i-1][0]=="." and s[i][0]=="#": now+=1 dp[i][0]=now for i in range(1,h): for j in range(1,w): cand1 = dp[i-1][j] + (s[i-1][j]=="." and s[i][j]=="#") cand2 = dp[i][j-1] + (s[i][j-1]=="." and s[i][j]=="#") dp[i][j]=min(cand1,cand2) print(dp[-1][-1])
H, W=map(int, input().split()) S=[] from math import ceil for h in range(H): s=list(input()) S.append(s) dp = [[float("INF")]*W for _ in range(H)] if S[0][0]=="#": dp[0][0]=1 else: dp[0][0]=0 for h in range(H): for w in range(W): if w==0 and h==0: continue if h==0: if S[h][w] == S[h][w-1]: now=0 else: now=1 dp[h][w]=min(dp[h][w-1]+now, dp[h][w]) elif w==0: if S[h][w] == S[h-1][w]: now=0 else: now=1 dp[h][w]=min(dp[h-1][w]+now, dp[h][w]) else: if S[h][w]==S[h][w-1]: noww = 0 else: noww=1 if S[h][w]==S[h-1][w]: nowh = 0 else: nowh=1 dp[h][w] = min(dp[h][w], dp[h][w-1]+noww, dp[h-1][w]+nowh) ans = ceil(dp[-1][-1]/2) print(ans)
1
49,149,910,154,534
null
194
194
N = int(input()) table = list(map(int,input().split())) MAX = 2000 check = [False]*(MAX+1) def recursive(index,tmp_sum): global N if index == N: check[tmp_sum] = True return recursive(index+1,tmp_sum) if tmp_sum+table[index] <= MAX: recursive(index+1,tmp_sum+table[index]) recursive(0,0) num_query = int(input()) for num in list(map(int,input().split())): if check[num]: print("yes") else: print("no")
import bisect N, M, X = map(int, input().split()) C = [0] * N A = [0] * N for i in range(N): x = list(map(int, input().split())) C[i] = x[0] A[i] = [0] * M for j in range(M): A[i][j] = x[j + 1] cnt = [0] * (2 ** N) ans_list = [] for i in range(2 ** N): bag = [] cnt[i] = [0] * M for j in range(N): if ((i >> j) & 1): bag.append(C[j]) for k in range(M): cnt[i][k] += A[j][k] cnt[i].sort() if bisect.bisect_left(cnt[i], X) == 0: ans_list.append(sum(bag)) if ans_list == []: print(-1) else: print(min(ans_list))
0
null
11,179,261,202,212
25
149
import numpy as np n = int(input()) a = [int(x) for x in input().split()] a.sort() m = np.zeros(max(a)+1, dtype=int) cnt = 0 for i in range(n): x = a[i] if i == n-1: if m[x] == 0: cnt +=1 else: if m[x] == 0 and a[i] != a[i+1]: cnt +=1 m[x::x] += 1 print(cnt)
def solve(XL, N): XL.sort(key=lambda x:x[1]) count = N for i in range(1, N): if XL[i][0] < XL[i-1][1]: XL[i][1] = XL[i-1][1] count -= 1 return count N = int(input()) XL = [] for i in range(N): x, l = map(int, input().split(' ')) XL.append([x-l, x+l]) print(solve(XL, N))
0
null
52,060,825,236,562
129
237
ni = lambda: int(input()) nm = lambda: map(int, input().split()) nl = lambda: list(map(int, input().split())) n=ni() c = [1 if _ == 'R' else 0 for _ in input()] b = sum(c) w=0 r=0 for i in range(n): if c[i] == 0 and i < b: r+=1 if c[i] == 1 and i >= b: w+=1 print(max(w,r))
n = int(input()) k = input() a = k.count("R") b = k[:a].count("W") print(b)
1
6,296,289,238,528
null
98
98
N, M = list(map(int, input().split())) A = sorted(list(map(int, input().split())), reverse=True) def check(X): i = N-1 n = 0 for ax in A: while i>=0 and A[i]+ax<X: i-=1 n+=i+1 return n>=M # check(X) := 幸福度がX以上上がる握手をすべて行うとき、握手の回数がM以上になるか? # check(X)==True となる最大のXを二分探索で求める min_ng = 10**6 max_ok = 0 while min_ng-max_ok>1: tgt = (min_ng+max_ok)//2 if check(tgt): max_ok = tgt else: min_ng = tgt i = N-1 k = sum(A) ans = 0 n = 0 for ax in A: while i>=0 and A[i]+ax<max_ok: k-=A[i] i-=1 ans += k + ax*(i+1) n += i+1 print(ans-max_ok*(n-M)) # Mを超えた分を引く
def main(): n = int(input()) p = [int(i) for i in input().split()] Min = [10**9] ans = 0 for i in range(n): Min.append(min(Min[-1],p[i])) for i in range(n): if Min[i]>p[i]: ans += 1 print(ans) main()
0
null
97,069,613,782,780
252
233
N,K=map(int,input().split()) P=list(map(int,input().split())) P=[i-1 for i in P] C=list(map(int,input().split())) import math ans=-10**18 for i in range(N): x=i tot=0 cycle=[] while True: x=P[x] cycle.append(C[x]) tot+=C[x] if x==i: break L=len(cycle) t=0 for i in range(L): t+=cycle[i] if i+1>K: break now=t if tot>0: e=(K-i-1)//L now+=tot*e ans=max(ans,now) print(ans)
N, K = map(int, input().split()) P = [int(i)-1 for i in input().split()] C = [int(i) for i in input().split()] ans = -1e18 for si in range(N): x = si s = [] tot = 0 while True: x = P[x] s.append(C[x]) tot += C[x] if x == si: break l = len(s) t = 0 for i in range(l): t += s[i] if i+1 > K: break now = t if tot > 0: e = (K-i-1)//l now += tot*e ans = max(ans, now) print(ans)
1
5,409,587,511,868
null
93
93
r = int(input()) print(r * 3.1416 * 2)
num=int(input()) print(3.14159265359*num*2)
1
31,298,938,839,362
null
167
167
from decimal import Decimal as D a,b=map(str,input().split()) print(int(D(a)*D(b)))
from collections import Counter N = int(input()) A = list(map(int,input().split())) S1 = Counter() S2 = Counter() for i,a in enumerate(A): S1[i+1+a] += 1 S2[(i+1)-a] += 1 res = 0 for k,v in S1.items(): if S2[k] > 0: res += v*S2[k] print(res)
0
null
21,266,466,733,220
135
157
import re def revPolish(f): f = re.sub(r'(\-?\d+\.?\d*)\s(\-?\d+\.?\d*)\s([\+\-\*/])(?!\d)', lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))), f) if f[-1] in ('+','-','*','/'): return revPolish(f) else: return f if __name__=='__main__': print(revPolish(input()))
n,k,c = map(int,raw_input().split()) s = raw_input() most = [0]*(n+1) i = n days = 0 while i > 0: if s[i-1] == 'o': days += 1 for j in xrange(min(max(1,c),i-1)): #print days #print i,j,1,days most[i-j-1] = days i -= (c+1) else: i -= 1 if i<n: most[i] = most[i+1] remain = k i = 1 while i<=n: if s[i-1] == 'o': if most[i] < remain: print i remain -= 1 i += c+1 else: i += 1
0
null
20,364,858,623,230
18
182
# -*- coding: utf-8 -*- import sys import os import math a, b = list(map(int, input().split())) # a?????§????????????????????? if b > a: a, b = b, a def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) result = gcd(a, b) print(result)
A, B, C = map(int, input().split()) K = int(input()) num = 0 while B <= A: B *= 2 num += 1 while C <= B: C *= 2 num += 1 if num > K: print("No") else: print("Yes")
0
null
3,500,065,592,542
11
101
import itertools import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) # x1+x2+x3+...xN = X (x>=0) def nHk_list(N,X): if N == 0: return [] elif N == 1: return [[X]] border = [i for i in range(X+1)] res = [] for S in itertools.combinations_with_replacement(border, N-1): # print(S) pre = 0 sub = [] for s in S: sub.append(s-pre) pre = s sub.append(X-pre) res.append(sub) return res INF=10**20 def main(): N=ii() alphabet = ["a","b","c","d","e","f","g","h","i","j"] ans = [] for c in range(1,N+1): # print("___\nc",c) for X in nHk_list(c,N-c): # print("X:",X,"c:",c,"N-c:",N-c) V = [] for i in range(len(X)): x = X[i] V.append(list(itertools.product(alphabet[:i+1],repeat=x))) # print("V",V) U = itertools.product(*V) base = alphabet[:c] for u in U: char = "" for i in range(c): char += alphabet[i] + "".join(list(u[i])) ans.append(char) ans.sort() # ans.append("".join(alphabet[:N])) print(*ans,sep='\n') if __name__ == "__main__": main()
from collections import deque n = int(input()) q = deque(["a"]) # 最後に最新の文字数のセットだけ拾う for i in range(n - 1): next_q = deque() for curr in q: suffix = ord(max(curr)) + 1 for x in range(ord("a"), suffix + 1): next_q.append(curr + chr(x)) q = next_q print(*q, sep="\n")
1
52,531,296,690,012
null
198
198
A1, A2, A3 = map(int, input().split()) if A1+A2+A3 >= 22: print('bust') else: print('win')
def main(): a, b, c = map(int, input().split()) if a + b + c > 21: print("bust") else: print("win") if __name__ == "__main__": main()
1
119,273,413,872,518
null
260
260
h,n=map(int,input().split()) ab = [list(map(int,input().split())) for i in range(n)] dp=[float('inf')]*(h+1) dp[0]=0 for i in range(h): for j in range(n): next=i+ab[j][0] if i+ab[j][0]<=h else h dp[next]=min(dp[next],dp[i]+ab[j][1]) print(dp[-1])
h,n=map(int,input().split()) A=[] B=[] for i in range(n): a,b=map(int,input().split()) A.append(a) B.append(b) dp=[10**10 for i in range(h+1)] dp[h]=0 for i in reversed(range(1,h+1)): for j in range(n): if i-A[j]>=0: dp[i-A[j]]=min(dp[i-A[j]],dp[i]+B[j]) else: dp[0]=min(dp[0],dp[i]+B[j]) print(dp[0])
1
81,209,750,632,110
null
229
229