code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
def resolve(): S, W = list(map(int, input().split())) print("unsafe" if S <= W else "safe") if '__main__' == __name__: resolve()
# coding: utf-8 H, W = list(map(int, input().split())) S = [] for _ in range(H): S.append(list(input())) grid = [[0 for _ in range(W)] for _ in range(H)] for h in range(1,H): if S[h-1][0] == '#' and S[h][0] == '.': grid[h][0] = grid[h-1][0] + 1 else: grid[h][0] = grid[h-1][0] for w in range(1,W): if S[0][w-1] == '#' and S[0][w] == '.': grid[0][w] = grid[0][w-1] + 1 else: grid[0][w] = grid[0][w-1] for w in range(1,W): for h in range(1,H): if S[h-1][w] == '#' and S[h][w] == '.': next_h = grid[h-1][w] + 1 else: next_h = grid[h-1][w] if S[h][w-1] == '#' and S[h][w] == '.': next_w = grid[h][w-1] + 1 else: next_w = grid[h][w-1] grid[h][w] = min([next_w, next_h]) if S[H-1][W-1] == '#': grid[H-1][W-1] += 1 print(grid[H-1][W-1])
0
null
39,461,916,370,778
163
194
import math h,w = map(int, input().split()) print(1 if h==1 or w==1 else math.ceil(h*w/2))
a = int(input()) if a == 1: print(3) else: print(int((a**3-1)*a/(a-1)))
0
null
30,414,151,176,380
196
115
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() def resolve(): l, r, d = map(int, input().split()) print(r // d - (l - 1) // d) resolve()
name = input('') print(name[:3])
0
null
11,184,209,553,312
104
130
import sys input = sys.stdin.readline a, b = input()[:-1].split() print(min(''.join(a for i in range(int(b))), ''.join(b for i in range(int(a)))))
a,b = map(int,input().split()) num = 0 if a <= b: for i in range(b): num += a * 10**i print(num) else: for i in range(a): num += b * 10**i print(num)
1
84,106,861,876,700
null
232
232
n = int(input()) for i in range(1, 10): tmp = (n / i) if tmp.is_integer() and 1<=tmp and tmp <=9: print("Yes") exit() print("No")
N=int(input()) resurt='' for i in range(1,10): if N%i ==0 and N//i<=9: result='Yes' break else: result='No' print(result)
1
159,680,683,254,880
null
287
287
a,b = input().split() a = int(a) b = int(b) if a >= 10 or b >=10: print ('-1') else: print (a * b)
import sys def input(): return sys.stdin.readline()[:-1] n, p = map(int, input().split()) snacks = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0]) dp = [0 for _ in range(p)] ans = snacks[0][1] for i in range(1, n): x, y = snacks[i-1] z = snacks[i][1] for j in range(p-1, 0, -1): if j >= x: dp[j] = max(dp[j], dp[j-x]+y) ans = max(ans, dp[j]+z) print(ans)
0
null
155,026,318,388,510
286
282
A, B = map(int, input().split()) lb_a = int(-(-A // 0.08)) ub_a = int(-(-(A + 1) // 0.08) - 1) lb_b = int(-(-B // 0.1)) ub_b = int(-(-(B + 1) // 0.1) - 1) if ub_b < lb_a or ub_a < lb_b: print(-1) else: print(max(lb_a, lb_b))
import math A, B = map(int, input().split()) ans = -1 for a in range(math.ceil(A/0.08), math.ceil((A+1)/0.08)): if int(a*0.1) == B: ans = a break print(ans)
1
56,341,553,583,480
null
203
203
N = int(input()) if N % 1000 == 0: ans = 0 else: ans = 1000 - (N % 1000) print(ans)
import math def abc173a_payment(): n = int(input()) print(math.ceil(n/1000)*1000 - n) abc173a_payment()
1
8,457,696,716,668
null
108
108
n = int(input()) a = list(map(int, input().split())) que = [-1, -1, -1] ans = 1 for i in range(n): if que[0]+1 == a[i]: if que[0] == que[1] and que[0] == que[2]: ans *= 3 ans %= (10**9 + 7) elif que[0] == que[1]: ans *= 2 ans %= (10**9 + 7) que[0] = a[i] elif que[1]+1 == a[i]: if que[1] == que[2]: ans *= 2 ans %= (10**9 + 7) que[1] = a[i] elif que[2]+1 == a[i]: que[2] = a[i] else: ans = 0 break print(ans)
N = int(input()) a_list = list(map(int, input().split())) MOD = 10**9 + 7 cnts = [0,0,0] sames = 0 ind = -1 res = 1 for a in a_list: for i, cnt in enumerate(cnts): if cnt == a: sames += 1 ind = i res *= sames res %= MOD cnts[ind] += 1 sames = 0 print(res)
1
130,153,460,961,188
null
268
268
#!usr/bin/env python3 import sys # def generate_buidlings(building, floor, room): # empty_buildings = { # key: [[0 for col in range(room)] for row in range(floor)] # for key in range(1, building+1) # } # return empty_buildings # # # def occupy_buildings(empty_buildings): # occupied_buildings = generate_buidlings(4, 3, 10) # n = int(sys.stdin.readline()) # # for i in range(n): # lst = [int(num) for num in sys.stdin.readline().split()] # occupied_buildings[lst[0]][lst[1]-1][lst[2]-1] += lst[3] # # return occupied_buildings def generate_buidlings_with_residents(building, floor, room): buildings = { key: [[0 for col in range(room)] for row in range(floor)] for key in range(1, building+1) } n = int(sys.stdin.readline()) for i in range(n): lst = [int(num) for num in sys.stdin.readline().split()] buildings[lst[0]][lst[1]-1][lst[2]-1] += lst[3] return buildings def print_buildings(): separator = '####################' buildings_with_residents = generate_buidlings_with_residents(4, 3, 10) for idx, (key, value) in enumerate(buildings_with_residents.items()): for floor in value: print(' %s %s %s %s %s %s %s %s %s %s' % tuple(floor)) if key < len(buildings_with_residents): print(separator) def main(): print_buildings() if __name__ == '__main__': main()
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] count = int(input()) for c in range(count): (b, f, r, v) = [int(x) for x in input().split()] data[b - 1][f - 1][r - 1] += v for b in range(4): for f in range(3): for r in range(10): print('',data[b][f][r], end='') print() print('#' * 20) if b < 4 - 1 else print(end='')
1
1,108,046,020,988
null
55
55
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) import math from itertools import combinations, product #import bisect# lower_bound etc #import numpy as np def run(): N,K = map(int, read().split()) k = int(math.log(N, 10)) s = N // (10 ** k) tmp1, tmp2, div = 1, 1, 1 for i in range(K-1): tmp1 *= k-i div *= i+1 tmp2 *= 9 ret = tmp1//div * tmp2 ret *= s-1 tmp1 *= k - (K-1) tmp2 *= 9 div *= K ret += tmp1 * tmp2 // div lis = range(k) nums = range(1,10) base = s * 10 ** k for A in combinations(lis, K-1): for X in product(nums, repeat = K-1): tmp = base for a,x in zip(A,X): tmp += 10 ** a * x if tmp <= N: ret += 1 print(ret) if __name__ == "__main__": run()
n=int(input()) if n==0: print(n+1) if n==1: print(n-1)
0
null
39,379,019,775,020
224
76
import math gun_list = [1] for i in range(11): gun_list.append(gun_list[-1]+26**(i+1)) #print(gun_list) #郡の始まりのnumをしまったリスト a =int(input()) #print() gun_sum = 12 for i in range(13): if gun_list[i] <= a and gun_list[i+1] > a: gun_num = i break #print(gun_num) b = a-gun_list[gun_num] #print(b) x_list = [26**i for i in range(gun_num+1)] x_list = x_list[::-1] #print(x_list) ans_list = [] for i in range(len(x_list)): if i > 0: b -= x_list[i-1]*ans_list[i-1] ans_list.append(math.floor(b/x_list[i])) else: ans_list.append(math.floor(b/x_list[0])) #print(ans_list) ans = '' for i in range(len(ans_list)): ans += chr(97+ans_list[i]) #print(ans) print(ans)
import sys import collections import bisect def main(): n = int(input()) a = [str(i + 1)[0] + str(i + 1)[-1] for i in range(n)] b = [str(i + 1)[-1] + str(i + 1)[0] for i in range(n)] ac, bc = collections.Counter(a), collections.Counter(b) print(sum(ac[i] * bc[i] for i in ac.keys())) if __name__ == '__main__': main()
0
null
49,494,676,359,138
121
234
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n, k = LI() A = [0] + LI() for i in range(1, n + 1): A[i] = (A[i] + A[i - 1] - 1) % k ans = 0 D = defaultdict(int) for j in range(n + 1): if j >= k: D[A[j - k]] -= 1 ans += D[A[j]] D[A[j]] += 1 print(ans)
n, k = map(int, input().split()) q, count = n, 0 while(q >= k): r = q%k; q = q//k count += 1 print(count+1)
0
null
100,887,669,150,200
273
212
import math def is_prime(x): if x == 2: return True if (x % 2 == 0): return False m = math.ceil(math.sqrt(x)) for i in range(3, m + 1): if x % i == 0: return False return True n = int(input()) prime = 0 for i in range(n): x = int(input()) if is_prime(x): prime += 1 print(prime)
import math n = int(input()) count = 0 for i in range(n): a = int(input()) h = math.trunc(math.sqrt(a))+1 b = 0 if a == 1: b = 1 if a == 2: b = 0 elif a % 2 == 0: b = 1 else: i = 3 while i <= h: if a % i == 0: b = 1 i += 2 if b == 0: count += 1 print count
1
10,287,129,148
null
12
12
h, a = input().split() h = int(h) a = int(a) c = 0 while h > 0: h -= a c += 1 print(c)
N = int(input()) S = input() R = set() G = set() B = set() for i, s in enumerate(S): if s == 'R': R.add(i) elif s == 'G': G.add(i) elif s == 'B': B.add(i) ans = 0 for r in R: for g in G: ans += len(B) d = abs(r-g) if (r+g) % 2 == 0 and (r+g)//2 in B: ans -= 1 if r+d in B or g+d in B: ans -= 1 if r-d in B or g-d in B: ans -= 1 print(ans)
0
null
56,493,691,198,252
225
175
#import sys #sys.setrecursionlimit(10**9) H, N = map(int, input().split()) magic = [_ for _ in range(N)] for k in range(N): magic[k] = list(map(int, input().split())) magic[k].append(magic[k][0]/magic[k][1]) magic.sort(key = lambda x: x[2], reverse=True) ans = [0 for _ in range(H+1)] visited = [0] anskouho = [float('inf')] ans2 = float('inf') """ def solve(start, power, point, maryoku): if start == H: print(min(point, min(anskouho))) exit() elif start > H: anskouho.append(point) return 0 elif ans[start] != 0: return 0 else: visited.append(start) ans[start] = point solve(start+power, power, point+maryoku, maryoku) """ for k in range(N): for item in visited: #solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1]) start = item+magic[k][0] power = magic[k][0] point = ans[item]+ magic[k][1] maryoku = magic[k][1] for _ in range(10**5): if start == H: print(min(point, ans2)) exit() elif start > H: ans2 = min(ans2, point) break elif ans[start]!=0: break else: visited.append(start) ans[start] = point start += power point += maryoku print(ans2)
def chmin(dp, i, *x): dp[i] = min(dp[i], *x) INF = float("inf") # dp[i] := min 消耗する魔力 to H -= i h, n = map(int, input().split()) dp = [0] + [INF]*h for _ in [None]*n: a, b = map(int, input().split()) for j in range(h + 1): chmin(dp, min(j + a, h), dp[j] + b) print(dp[h])
1
80,997,076,422,588
null
229
229
import math def resolve(): import sys input = sys.stdin.readline r = int(input().rstrip()) print(r * 2 * math.pi) if __name__ == "__main__": resolve()
N = int(input()) A = list(map(int,input().split())) ans =1 mod = 10**9+7 row = [0] *3 for i in range(N): ans *=row.count(A[i]) ans %=mod for j in range(3): if row[j]==A[i]: row[j]+=1 break print(ans%mod)
0
null
80,992,736,515,702
167
268
class Dictionary_class: def __init__(self): self.dic = set() def insert(self, str): self.dic.add(str) def find(self, str): if str in self.dic: return True else: return False n = int(input()) answer = "" dic = Dictionary_class() for i in range(n): instruction = input().split() if instruction[0] == "insert": dic.insert(instruction[1]) elif instruction[0] == "find": if dic.find(instruction[1]): answer += "yes\n" else: answer += "no\n" print(answer, end = "")
import sys input() rl = sys.stdin.readlines() d = {} for i in rl: c, s = i.split() #if i[0] == 'i': if c[0] == 'i': #d[i[7:]] = 0 d[s] = 0 else: #if i[5:] in d: if s in d: print('yes') else: print('no')
1
78,512,582,008
null
23
23
a = int(input()) b = input().split() c = "APPROVED" for i in range(a): if int(b[i]) % 2 == 0: if int(b[i]) % 3 == 0 or int(b[i]) % 5 == 0: c = "APPROVED" else: c = "DENIED" break print(c)
from collections import deque import itertools def main(): H, W = list(map(int, input().split())) A = [['#'] * (W + 2)] + [['#', ] + list(input()) + ['#', ] for _ in range(H)] + [['#'] * (W + 2)] DXY = [[1, 0], [-1, 0], [0, 1], [0, -1]] ans = 0 INF = 10000 for h in range(1, H + 1): for w in range(1, W + 1): if A[h][w] == '#': continue count = [[-1 if i == '#' else INF for i in a] for a in A] count[h][w] = 0 stack = deque([[h, w], ]) visited = [[0] * W for _ in range(H)] while stack: x, y = stack.popleft() if visited[x - 1][y - 1] == 1: continue else: visited[x - 1][y - 1] = 1 for (dx, dy) in DXY: X = x + dx Y = y + dy if A[X][Y] == '.': if visited[X - 1][Y - 1] == 0: stack.append([X, Y]) count[X][Y] = min(count[X][Y], count[x][y] + 1) count = list(itertools.chain.from_iterable(count)) ans = max(ans, max(count)) print(ans) if __name__ == '__main__': main()
0
null
81,448,143,837,750
217
241
s,t = input().split() a,b = map(int,input().split()) A = input() if A == s:print(a-1,b) else:print(a,b-1)
import numpy as np n, m = map(int,input().split()) a = list(map(int,input().split())) na = np.zeros(2**18) for i in a: na[i] += 1 fa = np.fft.fft(na) c = np.round(np.fft.ifft(fa*fa)).astype(int) ans = 0 cm = 0 for i in range(2**18 - 1, 1, -1): cm += c[i] ans += i*c[i] if cm > m: ans -= i * (cm - m) if cm >= m: break print(ans)
0
null
90,075,484,139,372
220
252
n,m = map(int,input().split()) a = 0 n = n - 1 m = m - 1 while n > 0: a = a + n n = n - 1 while m > 0: a = a + m m = m - 1 print(a)
N=int(input()) #m1,d1=map(int,input().split()) #hl=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] S=list(input()) d=list('0123456789') ans=0 for d1 in d: for d2 in d: for d3 in d: v=d1+d2+d3 i=0 p=0 while i < N : if v[p]==S[i]: p+=1 if p == 3: break i+=1 if p==3 : ans+=1 print(ans)
0
null
86,951,933,554,340
189
267
n,k = map(int, input().split()) ans = 0 for i in range(k,n+2): a = (i-1)*i//2 ans += n*i-2*a+1 print(ans%(10**9+7))
def main(): n = int(stdinput()) S = [*map(int, stdinput().split())] q = int(stdinput()) T = [*map(int, stdinput().split())] S = sorted(S) T = sorted(T) i = j = c = 0 while i < n and j < q: if S[i] == T[j]: c += 1 i += 1 j += 1 elif S[i] > T[j]: j += 1 else: i += 1 print(c) def stdinput(): from sys import stdin return stdin.readline().strip() if __name__ == '__main__': main() # import cProfile # cProfile.run('main()')
0
null
16,487,572,578,176
170
22
def swap(l, i, j): tmp = l[i] l[i] = l[j] l[j] = tmp return l def selection_sort(l): cnt = 0 for i in range(len(l)): minj = i for j in range(i + 1, len(l)): if l[j] < l[minj]: minj = j if i != minj: swap(l, i, minj) cnt += 1 return l, cnt if __name__ == '__main__': N = int(input()) l = list(map(int, input().split())) sl, cnt = selection_sort(l) print(' '.join(map(str, sl))) print(cnt)
N = int(input()) D = list(map(int, input().split())) if D[0] != 0: print(0) else: tmp = [0 for _ in range(10 ** 5)] for i in range(N): tmp[D[i]] += 1 if tmp[0] != 1: print(0) else: ans = 1 flag = False flag2 = False for i in range(1, 10 ** 5 - 1): if flag2 and tmp[i+1] != 0: ans = 0 break if tmp[i+1] == 0: flag2 = True ans = (ans * (tmp[i] ** tmp[i+1])) % 998244353 print(ans)
0
null
77,205,414,019,568
15
284
l = "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" li = [int(x.strip()) for x in l.split(',')] print(li[int(input())-1])
B=[];C=[];S=0 N=int(input()) A=list(map(int,input().split())) Q=int(input()) for i in range(Q): b,c=map(int,input().split()) B.append(b) C.append(c) X=[0]*(10**5+1) for i in range(N): X[A[i]]+=1 S=S+A[i] #print(A) #print(B) #print(C) for i in range(Q): X[C[i]]+=X[B[i]] S=S+X[B[i]]*(C[i]-B[i]) X[B[i]]=0 print(S)
0
null
31,022,650,755,890
195
122
N=int(input()) *A,=map(int, input().split()) B=[(i+1,a) for i,a in enumerate(A)] from operator import itemgetter B.sort(reverse=True, key=itemgetter(1)) dp = [[-1] * (N+1) for _ in range(N+1)] dp[0][0] = 0 for i in range(1,N+1): idx, act = B[i-1] for j in range(i+1): k = i-j if 0<j: dp[j][k] = max(dp[j][k], dp[j-1][k] + act * abs(idx-j)) if 0<k: dp[j][k] = max(dp[j][k], dp[j][k-1] + act * abs(idx-(N-k+1))) ans=0 for j in range(N+1): ans = max(ans, dp[j][N-j]) print(ans)
N, A, B = list(map(int, input().split())) try: blue_num = A * (N // (A + B)) residue = N - ((A + B) * (N // (A + B))) if(residue > A): blue_num += A else: blue_num += residue except ZeroDivisionError: blue_num = 0 print(blue_num)
0
null
44,890,644,529,318
171
202
def resolve(): N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) a, b = [0], [0] for i in range(N): a.append(a[i] + A[i]) for i in range(M): b.append(b[i] + B[i]) count = 0 j = M for i in range(N + 1): if a[i] > K: break while b[j] > K - a[i]: j -= 1 count = max(count, i + j) print(count) if __name__ == "__main__": resolve()
import sys, re from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left, bisect_right from functools import reduce from decimal import Decimal, getcontext # input = sys.stdin.readline def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 6) INF = float('inf') MOD = 10 ** 9 + 7 num_list = [] str_list = [] N,M,K=i_map() A=i_list() B=i_list() cum_A = [0]*(N+1) cum_B = [0]*(M+1) for i in range(1, N+1): cum_A[i] = cum_A[i-1] + A[i-1] for i in range(1, M+1): cum_B[i] = cum_B[i-1] + B[i-1] ans = 0 for i in range(0, N+1): val = K - cum_A[i] if val < 0: continue idx = bisect_right(cum_B, val) - 1 ans = max(ans, i + idx) print(ans)
1
10,681,128,566,508
null
117
117
N = int(input()) A = [int(i) for i in input().split()] L, R = [A[-1]], [A[-1]] for i in range(1, N+1): L.append((L[-1]+1)//2+A[-1-i]) R.append((R[-1]+A[-1-i])) L = L[::-1] R = R[::-1] if L[0] >= 2: print(-1) exit() ans = 1 p = 1 for i in range(1, N+1): ans += min(p*2, R[i]) p = min(p*2, R[i])-A[i] print(ans)
from itertools import product N = int(input()) G = {i:[] for i in range(1,N+1)} for i in range(1,N+1): a = int(input()) G[i] = [list(map(int,input().split())) for _ in range(a)] cmax = 0 for z in product((0,1),repeat=N+1): if z[0]==0: X = [] for i in range(1,N+1): if z[i]==1: X.append(i) A = [] B = [] for i in X: for x,y in G[i]: if y==1: A.append(x) else: B.append(x) flag = 0 for a in A: if a not in X: flag = 1 break for b in B: if b in X: flag = 1 break if flag==0: cmax = max(cmax,sum(z[1:])) print(cmax)
0
null
69,937,939,750,920
141
262
#! python3 # distance.py import math x1, y1, x2, y2 = [float(x) for x in input().split(' ')] print('%.5f'%math.sqrt(pow(x2-x1, 2) + pow(y2-y1, 2)))
x1, y1, x2, y2 = map(float,input().split()) print(f'{((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5:8f}')
1
158,241,808,818
null
29
29
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() a=LI() ALL=0 for i in range(N): ALL=ALL^a[i] ans=[0]*N for i in range(N): ans[i]=ALL^a[i] print(' '.join(map(str, ans))) main()
N = int(input()) a = list(map(int, input().split())) # XOR演算子 ^ # aの要素全てのXORを計算、それをSとする S = 0 for aa in a: S ^= aa # i番目の番号はaiとSのXORで表される ans = [] for ai in a: ans.append(S ^ ai) print(*ans)
1
12,420,480,270,660
null
123
123
#!/usr/bin/python3 import sys from functools import reduce from operator import mul input = lambda: sys.stdin.readline().strip() n, k = [int(x) for x in input().split()] a = sorted((int(x) for x in input().split()), key=abs) sgn = [0 if x == 0 else x // abs(x) for x in a] M = 10**9 + 7 def modmul(x, y): return x * y % M if reduce(mul, sgn[-k:]) >= 0: print(reduce(modmul, a[-k:], 1)) else: largest_unselected_neg = next(i for i, x in enumerate(reversed(a[:-k])) if x < 0) if any(x < 0 for x in a[:-k]) else None largest_unselected_pos = next(i for i, x in enumerate(reversed(a[:-k])) if x > 0) if any(x > 0 for x in a[:-k]) else None smallest_selected_neg = next(i for i, x in enumerate(a[-k:]) if x < 0) if any(x < 0 for x in a[-k:]) else None smallest_selected_pos = next(i for i, x in enumerate(a[-k:]) if x > 0) if any(x > 0 for x in a[-k:]) else None can1 = largest_unselected_neg is not None and smallest_selected_pos is not None can2 = largest_unselected_pos is not None and smallest_selected_neg is not None def ans1(): return list(reversed(a[:-k]))[largest_unselected_neg] * reduce(modmul, (x for i, x in enumerate(a[-k:]) if i != smallest_selected_pos), 1) % M def ans2(): return list(reversed(a[:-k]))[largest_unselected_pos] * reduce(modmul, (x for i, x in enumerate(a[-k:]) if i != smallest_selected_neg), 1) % M if can1 and not can2: print(ans1()) elif can2 and not can1: print(ans2()) elif can1 and can2: if list(reversed(a[:-k]))[largest_unselected_neg] * a[-k:][smallest_selected_neg] > list(reversed(a[:-k]))[largest_unselected_pos] * a[-k:][smallest_selected_pos]: print(ans1()) else: print(ans2()) else: print(reduce(modmul, a[:k], 1))
import sys n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() MOD=10**9+7 plus=[] minus=[] zero=[] for i in range(n): if a[i]>0: plus.append(a[i]) if a[i]<0: minus.append(a[i]) if a[i]==0: zero.append(a[i]) if k==n: ans=1 for i in range(k): ans=(ans*a[i])%MOD print(ans) sys.exit() if len(plus)==0: if k%2!=0: a.reverse() ans=1 for i in range(k): ans=(ans*a[i])%MOD print(ans) sys.exit() if len(plus)+len(minus)<k: print(0) sys.exit() m=len(minus) minus.sort() plus.reverse() plpointer=k if k>len(plus): plpointer=2*(len(plus)//2) if k%2==1: if plpointer+1<=len(plus): plpointer+=1 else: plpointer-=1 mnpointer=k-plpointer while mnpointer<m-1 and plpointer>=2 and minus[mnpointer]*minus[mnpointer+1]>plus[plpointer-1]*plus[plpointer-2]: mnpointer+=2 plpointer-=2 ans=1 for i in range(mnpointer): ans=(ans*minus[i])%MOD for i in range(plpointer): ans=(ans*plus[i])%MOD print(ans)
1
9,434,249,060,164
null
112
112
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)
n, m = map(int, input().split()) x, y = (m+1) // 2, m // 2 for i in range(x): print(1+i, 2*x-i) for i in range(y): print(2*x+1+i, 2*x+1+2*y-i)
0
null
80,793,488,615,720
270
162
x = int(input()) dp = [False] * (x + 1) dp[0] = True items = [100, 101, 102, 103, 104, 105] for i in items: for j in range(x + 1): if j + i >= x + 1: break dp[j + i] |= dp[j] if dp[x]: print(1) else: print(0)
if __name__ == '__main__': W, H, x, y, r = map(int, raw_input().split()) ret = "Yes" if W < x + r or x - r < 0: ret = "No" elif H < y + r or y - r < 0: ret = "No" print ret
0
null
63,614,545,028,820
266
41
N = int(input()) A = list(map(int, input().split())) left = 0 SUM = sum(A) res = SUM for i in range(N): left += A[i] res = min(res,abs(2*left-SUM)) print(res)
# -*- coding: utf-8 -*- # ITP1_10_A import math pos = list(map(float, input().split())) x = abs(pos[2] - pos[0]) y = abs(pos[3] - pos[1]) print(math.sqrt(x**2 + y**2))
0
null
71,348,594,192,018
276
29
def main(): import sys b=sys.stdin.buffer input=b.readline n=int(input()) d=[set()for _ in range(n)]+[{c}for c in input()] for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i] r=[] add=r.append input() for q,a,b in zip(*[iter(b.read().split())]*3): i=int(a)+n-1 if q<b'2': d[i]={b[0]} while i: i>>=1 d[i]=d[i+i]|d[i-~i] continue j=int(b)+n s=set() while i<j: if i&1: s|=d[i] i+=1 if j&1: j-=1 s|=d[j] i>>=1 j>>=1 add(len(s)) print(' '.join(map(str,r))) main()
from sys import stdin input = stdin.readline a = input().rstrip() if a.isupper(): print("A") else: print("a")
0
null
36,894,233,174,850
210
119
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) n,a,b = readInts() ab = abs(b-a) if ab%2 == 0: print(ab//2) else: print(min(a-1, n-b) + 1 + (b-a-1)//2)
n, a, b = map(int, input().split()) ans = 0 if (b - a) % 2 == 0: ans = (b - a) // 2 else: # ans += (b - a) // 2 # a += ans # b -= ans # ans += min(n - a, b - 1) if a - 1 <= n - b: ans += a b -= a a = 1 else: ans += n - b + 1 a += n - b + 1 b = n ans += (b - a) // 2 print(ans)
1
109,186,279,917,428
null
253
253
# coding: utf-8 import sys from collections import deque sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def main(): # 左からgreedyに N, D, A = lr() monsters = [] for _ in range(N): x, h = lr() monsters.append((x, h)) monsters.sort() bomb = deque() answer = 0 attack = 0 for x, h in monsters: while bomb: if bomb[0][0] + D < x: attack -= bomb[0][1] bomb.popleft() else: break h -= attack if h > 0: t = -(-h//A) answer += t bomb.append((x + D, A * t)) attack += A * t print(answer) if __name__ == '__main__': main()
n = int(input()) a = list(map(int, input().split())) a_sum = sum(a) x = 0 y = 0 for i in range(n): x += a[i] if x * 2 >= a_sum: y = a[i] break ans = min(abs(2 * x - a_sum), abs(a_sum - 2 * (x - y))) print(ans)
0
null
112,120,066,138,016
230
276
N = int(input()) tree = [[] for _ in range(N)] for _ in range(N): u, k, *v = map(int, input().split()) tree[u-1] = v ans = [float('inf') for _ in range(N)] ans[0] = 0 from collections import deque q = deque([(0, 0)]) while q: p, d = q.popleft() for c in tree[p]: if ans[c-1] > d+1: ans[c-1] = d+1 q.append((c-1, d+1)) for i in range(N): if ans[i] == float('inf'): print(i+1, -1) else: print(i+1, ans[i])
import sys readline = sys.stdin.buffer.readline k, n = readline().rsplit() A = readline().rsplit() far = int(k) + int(A[0]) - int(A[-1]) for x, y in zip(A[1:], A): if far < int(x) - int(y): far = int(x) - int(y) print(int(k)-far)
0
null
21,661,240,357,120
9
186
from collections import defaultdict N, M = map(int, input().split()) heights = list(map(int, input().split())) d = defaultdict(list) for i in range(M): A, B = map(int, input().split()) d[A].append(B) d[B].append(A) ans_cnt = 0 for i in range(1, N + 1): if d[i] == []: ans_cnt += 1 else: my_height = heights[i - 1] flag = True for j in d[i]: if heights[j - 1] >= my_height: flag = False break if flag: ans_cnt += 1 print(ans_cnt)
time = int(input()) h = time // 3600 m = (time // 60) % 60 t = time % 60 print("{0}:{1}:{2}" .format(h, m, t))
0
null
12,732,119,208,750
155
37
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) cnt = [[0] * 10 for _ in range(10)] for i in range(1, n + 1): i = str(i) head = int(i[0]) foot = int(i[-1]) cnt[head][foot] += 1 res = 0 for i in range(1, n + 1): i = str(i) head = int(i[0]) foot = int(i[-1]) res += cnt[foot][head] print(res) if __name__ == '__main__': resolve()
while True: (H,W) = [int(x) for x in input().split()] if H == W == 0: break for hc in range(H): print('#'*W) print()
0
null
43,697,031,078,382
234
49
s=input() a=s[:len(s)//2+1//2] b=s[len(s)//2+1:] if s==s[::-1] and a==a[::-1] and b==b[::-1]: print("Yes") else: print("No")
S = input() s = list(S) f = s[:int((len(s)-1)/2)] l = s[int((len(s)+3)/2-1):] if f == l: while len(f) > 1: if f[0] == f[-1]: f.pop(0) f.pop() if len(f) <= 1: while len(l) > 1: if l[0] == l[-1]: l.pop(0) l.pop() if len(l) <= 1: print('Yes') else: print('No') else: print('No') else: print('No')
1
46,417,957,186,928
null
190
190
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N = int(readline()) XY = np.array(read().split(),np.int64) X = XY[::2]; Y = XY[1::2] dx = X[:,None] - X[None,:] dy = Y[:,None] - Y[None,:] dist_mat = (dx * dx + dy * dy) ** .5 answer = dist_mat.sum() / N print(answer)
from itertools import permutations n = int(input()) xy = [list(map(int, input().split())) for _ in range(n)] sum = 0 cnt = 0 for i in permutations(xy): for j in range(n - 1): sum += ((i[j][0] - i[j + 1][0]) ** 2 + (i[j][1] - i[j + 1][1]) ** 2) ** 0.5 cnt += 1 print(sum / cnt)
1
148,255,408,437,390
null
280
280
import sys input = sys.stdin.readline def f(n): s = (n*(n+1))//2 return s N,K = map(int,input().split()) m= 10**9+7 ln = list(range(N+1)) num = 0 for i in range(K,N+2): num += f(N+1)-f(N+1-i)-f(i)+1 print(num%m)
n, k = map(int, input().split()) mo = 10 ** 9 + 7 ans = 0 def calc(t): u = (0 + t - 1) * t // 2 v = (n + n - t + 1) * t // 2 return v - u + 1 for i in range(k, n + 2): ans = (ans + calc(i)) % mo print(ans)
1
32,973,910,827,766
null
170
170
while True: h, w = map(int, input().split()) if(w == h == 0): break for i in range(h): for j in range(w): if (i + j) % 2: print('.', end = '') else: print('#', end = '') print('') print('')
while(True): H, W = map(int, input().strip().split()) if(H == W == 0): break for x in range(H): print(''.join('#.'[(x + y) % 2] for y in range(W))) print()
1
858,858,607,102
null
51
51
n,k = map(int,input().split()) MOD = 10**9+7 FAC = [1] INV = [1] for i in range(1,2*n+1): FAC.append((FAC[i-1]*i) % MOD) INV.append(pow(FAC[-1],MOD-2,MOD)) def nCr(n,r): return FAC[n]*INV[n-r]*INV[r] ans = 0 for i in range(min(n-1,k)+1): ans += nCr(n,i)*nCr(n-1,n-i-1) ans %= MOD print(ans)
n = int(input()) ans = '' # 制約条件は高々 26 の 10 乗なので、取り合えずインデックスを13に設定して回す for i in range(1, 13): if n <= 26**i: n -= 1 for j in range(i): ans += chr(ord('a') + n%26) n //= 26 break; else: n -= 26**i print(ans[::-1])
0
null
39,573,568,752,772
215
121
while 1: m, f, r = map(int, input().split()) s = m + f if m == -1 and f == -1 and r == -1: break elif m == -1 or f == -1 or s < 30: print("F") elif s >= 80: print("A") elif s >= 65 and s < 80: print("B") elif s >= 50 and s < 65: print("C") elif s >= 30 and s < 50: if r < 50: print("D") else: print("C")
from sys import stdin for line in stdin: mid, final, make = map(int, line.split()) if mid == -1 and final == -1 and make == -1: break elif mid == -1 or final == -1: print('F') elif mid + final >= 80: print('A') elif mid + final >= 65: print('B') elif mid + final >= 50: print('C') elif mid + final >= 30: if make >= 50: print('C') else: print('D') else: print('F')
1
1,237,475,006,500
null
57
57
a,b,c,d,e=input().split() a=int(a) b=int(b) c=int(c) d=int(d) e=int(e) if a==0: print("1") if b==0: print("2") if c==0: print("3") if d==0: print("4") if e==0: print("5")
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys import resource from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub from copy import deepcopy sys.setrecursionlimit(1000000) s, h = resource.getrlimit(resource.RLIMIT_STACK) # resource.setrlimit(resource.RLIMIT_STACK, (h, h)) input = sys.stdin.readline INF = 2**62-1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().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 @mt def slv(N, M, S): def f(s, p): if p == 0: return s elif p < 0: return None for i in range(M, 0, -1): j = p - i if j < 0 or j >= len(S): continue if S[j] == '1': continue s.append(i) v = f(s, j) if v: return v s.pop() return None m = 0 mm = 0 for c in S: if c == '1': mm += 1 m = max(mm, m) else: mm = 0 if m >= M: return -1 ans = f([], N) if ans: return ' '.join(map(str, reversed(ans))) return -1 def main(): N, M = read_int_n() S = read_str() print(slv(N, M, S)) if __name__ == '__main__': main()
0
null
76,149,162,473,468
126
274
import math def main(): A, B, H, M = map(int, input().split()) h_angle = 30 * H + 0.5 * M if h_angle <= 90: h_angle = math.radians(90 - h_angle) else: h_angle = math.radians(360 - (h_angle - 90)) m_angle = 6 * M if m_angle <= 90: m_angle = math.radians(90 - m_angle) else: m_angle = math.radians(360 - (m_angle - 90)) h_x = A * math.cos(h_angle) h_y = A * math.sin(h_angle) m_x = B * math.cos(m_angle) m_y = B * math.sin(m_angle) print(math.sqrt(abs(h_x - m_x)**2 + abs(h_y - m_y)**2)) if __name__ == '__main__': main()
n=int(input()) l=[list(map(int,input().split())) for i in range(n)] work1=sorted([x[0] for x in l]) work2=sorted([x[1] for x in l]) if n%2==1 : mmin=work1[n//2] mmax=work2[n//2] else: mmin=work1[n//2]+work1[n//2-1] mmax=work2[n//2]+work2[n//2-1] print(mmax-mmin+1)
0
null
18,783,586,399,940
144
137
import sys input = sys.stdin.readline def log(*args): print(*args, file=sys.stderr) def main(): n = int(input().rstrip()) ans = [0 for _ in range(n)] for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): tmp = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x if tmp > n: break # if x == y == z: # ans[tmp - 1] = 1 # elif x == y or y == z or z == x: # ans[tmp - 1] = 3 # else: # ans[tmp - 1] = 6 ans[tmp - 1] += 1 for v in ans: print(v) if __name__ == '__main__': main()
n = int(input()) ANS = [0] * (n+1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): tmp = (x + y + z)**2 - z*(x + y) - (x*y) if tmp > n: continue ANS[tmp] += 1 for ans in ANS[1:]: print(ans)
1
7,921,681,748,640
null
106
106
n=int(input()) A=[int(i) for i in input().split()] mod=10**9+7 ans=0 cnt=[0 for i in range(61)] for i in range(n): now=A[i] bek=1 for q in range(61): if now&1==0: ans+=cnt[q]*bek else: ans+=(i-cnt[q])*bek bek=bek*2%mod cnt[q]+=now&1 now>>=1 ans=ans%mod #print(ans) print(ans)
l,r,f = map(int,input().split()) count = 0 for i in range(l,r+1): if i % f == 0 : count = count + 1 print(count)
0
null
65,346,921,022,480
263
104
N=int(input()) print(-N%1000)
list_data = [input() for _ in range(2)] s = list_data[0] t = list_data[1] len_t = len(t) max_correct = 0 for i in range(len(s)-len(t)+1): correct = 0 for j in range(len(t)): if s[i+j] == t[j]: correct += 1 if max_correct < correct: max_correct = correct print(len_t - max_correct)
0
null
6,040,177,489,552
108
82
a=int(input()) b=int(input()) ab={a,b} s={1,2,3} ss=s-ab print(list(ss)[0])
#ITP1_10-D Distance2 n = int(input()) x = [float(x) for x in input().split(" ")] y = [float(x) for x in input().split(" ")] d1=0.0 for i in range(n): d1 += abs(x[i]-y[i]) print(d1) d2=0.0 for i in range(n): d2 += (x[i]-y[i])**2 print(d2**(1/2)) d3=0.0 for i in range(n): d3 += abs((x[i]-y[i])**3) print(d3**(1/3)) d_inf=0.0 for i in range(n): if abs(x[i]-y[i])>d_inf: d_inf = abs(x[i]-y[i]) print(d_inf)
0
null
55,641,490,187,360
254
32
a, b, c = map(int, input().split()) t = a a = b b = t tt = a a =c c = tt print(a, b, c)
class UnionFind: def __init__(self, n=0): self.d = [-1]*n def find(self, x): if self.d[x] < 0: return x else: self.d[x] = self.find(self.d[x]) return self.d[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.d[x] > self.d[y]: x, y = y, x self.d[x] += self.d[y] self.d[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.d[self.find(x)] n, m, k = map(int, input().split()) deg = [0]*100005 uf = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 deg[a] += 1 deg[b] += 1 uf.unite(a, b) for _ in range(k): c, d = map(int, input().split()) c -= 1 d -= 1 if uf.same(c, d): deg[c] += 1 deg[d] += 1 for i in range(n): print(uf.size(i) - 1 - deg[i], end="") if i == n-1: print() else: print(" ", end="")
0
null
49,751,658,454,560
178
209
# 1 # a,b=map(int,input().split()) # if a+b==15: # ans='+' # elif a*b==15: # ans='*' # else: # ans='x' # print(ans) # 2 X=int(input()) print(8-(X-400)//200)
def main(): import sys N = int(sys.stdin.readline()) L = [0 for i in range(45)] L[0], L[1] = 1, 1 for i in range(2, 45): L[i] = L[i-1] + L[i-2] #print(L) print(L[N]) if __name__=='__main__': main()
0
null
3,322,788,605,444
100
7
n = int(input()) a = map(int,input().split()) ans = "APPROVED" for i in a: if i%2 == 0: if not(i%3==0 or i%5==0): ans = "DENIED" print(ans)
N, K = list(map(int, input().split())) if N >= K: N = N % K print(min(N, max(N-K, K-N)))
0
null
54,170,218,883,104
217
180
import sys d = -float('inf') n = int(input()) l = int(input()) for s in sys.stdin: r = int(s) d = max(d, r-l) l = min(l, r) print(d)
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)
1
13,644,407,180
null
13
13
#!/usr/bin/env python3 import bisect def main(): N = int(input()) L = sorted(map(int, input().split())) ans = 0 for a in range(N - 2): for b in range(a + 1, N - 1): ans += bisect.bisect_right(L, L[a] + L[b] - 1) - b - 1 print(ans) if __name__ == "__main__": main()
import bisect def bisect_right_reverse(a, x): ''' reverseにソートされたlist aに対してxを挿入できるidxを返す。 xが存在する場合には一番右側のidx+1となる。 ''' if a[0] < x: return 0 if x <= a[-1]: return len(a) # 二分探索 ok = len(a) - 1 ng = 0 while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if a[mid] < x: ok = mid else: ng = mid return ok def bisect_left_reverse(a, x): ''' reverseにソートされたlist aに対してxを挿入できるidxを返す。 xが存在する場合には一番左側のidxとなる。 ''' if a[0] <= x: return 0 if x < a[-1]: return len(a) # 二分探索 ok = len(a) - 1 ng = 0 while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if a[mid] <= x: ok = mid else: ng = mid return ok def main2(): n = int(input()) l=[int(i) for i in input().split()] l.sort(reverse = True) res = 0 for i in range(n-1): for j in range(i+1, n-1): #index がj以降で k < c を満たすcで一番小さいc'を探す #index(c')-j - 1が三角形の条件を満たす nibu = l[j+1:] k = max(l[i]-l[j],l[j]-l[i]) left=bisect_left_reverse(nibu,k) res += left print(res) if __name__ == '__main__': main2()
1
171,690,725,731,050
null
294
294
N=int(input()) if N%2==1: print(int((N-1)/2+1)) else: print(int(N/2))
S = int(input()) q , mod = divmod(S , 2) print(q+mod)
1
58,787,132,790,062
null
206
206
w,h,x,y,r=[int(i) for i in raw_input().split()] if x-r<0 or x+r>w or y-r<0 or y+r>h: print 'No' else : print 'Yes'
W, H, x, y, r = map(int, input().split()) print( 'Yes' if r <= x <= W - r and r <= y <= H - r else 'No')
1
462,386,950,450
null
41
41
import sys input = sys.stdin.readline def main(): n, k = map(int, input().split()) products = [int(input()) for _ in range(n)] left = 1 right = 10000 * 100000 # 最大重量 × 最大貨物数 while left < right: mid = (left + right) // 2 # print("left:{}".format(left)) # print("right:{}".format(right)) # print("mid:{}".format(mid)) v = allocate(mid, k, products) # print("count:{}".format(v)) if n <= v: right = mid else: left = mid + 1 print(right) def allocate(capacity, truckNum, products): # print("===== start allocation capacity:{}======".format(capacity)) v = 0 tmp = 0 truckNum -= 1 while len(products) > v: product = products[v] # print("tmp weight:{}".format(tmp)) # print("product weight:{}".format(product)) if product > capacity: # print("capacity over") # そもそも1個も乗らない時避け return 0 if tmp + product <= capacity: # 同じトラックに積み続ける tmp += product else: # 新しいトラックがまだあればつむ if truckNum > 0: # print("new truck") truckNum -= 1 tmp = product else: return v v += 1 return v if __name__ == '__main__': main()
setting = input().split(); package_count = int(setting[0]); truck_count = int(setting[1]); packages = []; for i in range(package_count): packages.append(int(input())); def allocation(): max_p = sum(packages); left = 0; right = max_p; while left < right: mid = (left + right) // 2; load = calculate_load(mid); if load >= package_count: right = mid; else: left = mid + 1; return right; def calculate_load(p): i = 0; j = 0; current_truck_p = p; while i < package_count and j < truck_count: if packages[i] <= current_truck_p: current_truck_p -= packages[i]; i += 1; else: j += 1; current_truck_p = p; return i; print(allocation());
1
85,910,223,520
null
24
24
H, N = map(int,input().split()) A = list(map(int,input().split())) if H > sum(A): print('No') else: print('Yes')
import sys def main(): sec = int(sys.stdin.readline()) hour = int(sec / 3600) sec = sec % 3600 minute = int(sec / 60) sec = sec % 60 print("{0}:{1}:{2}".format(hour,minute,sec)) return if __name__ == '__main__': main()
0
null
39,271,669,963,020
226
37
# 160 A S = input() print('Yes') if S[2:3] == S[3:4] and S[4:5] == S[5:6] else print('No')
co ="coffee" S = input() if S[2]!=S[3]: print("No") elif S[4]!=S[5]: print("No") else: print("Yes")
1
42,047,621,317,930
null
184
184
if __name__ == "__main__": s = int(input()) m = s // 60 h = str(m // 60) m = str(m % 60) s = str(s % 60) print(h + ":" + m + ":" + s)
s, S = divmod(input(), 60) H, M = divmod(s, 60) print '%d:%d:%d' %(H,M,S)
1
324,055,084,532
null
37
37
import sys from collections import deque def read(): return sys.stdin.readline().rstrip() def main(): n, m, k = map(int, read().split()) friend = [[] for _ in range(n)] block = [set() for _ in range(n)] potential = [set() for _ in range(n)] for _ in range(m): a, b = [int(i) - 1 for i in read().split()] friend[a].append(b) friend[b].append(a) for _ in range(k): c, d = [int(i) - 1 for i in read().split()] block[c].add(d) block[d].add(c) sd = set() for u in range(n): if u in sd: continue sn = deque([u]) pf = set() while sn: p = sn.pop() if p in sd: continue sd.add(p) pf.add(p) for f in friend[p]: sn.append(f) for pfi in pf: potential[pfi] = pf print(*[len(potential[i]) - len(block[i] & potential[i]) - len(friend[i]) - 1 for i in range(n)]) if __name__ == '__main__': main()
from sys import setrecursionlimit setrecursionlimit(1 << 30) nv, ne, nBad = map(int, input().split()) g = [[] for _ in range(nv)] for _ in range(ne): u, v = map(lambda x: int(x) - 1, input().split()) g[u].append(v) g[v].append(u) a = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(nBad)] def dfs(v): id[v] = cur comps[-1].append(v) for to in g[v]: if id[to] == None: dfs(to) id = [None] * nv cur = 0 comps = [] for v in range(nv): if id[v] == None: comps.append([]) dfs(v) cur += 1 bad = [0] * nv for u, v in a: if id[u] == id[v]: bad[u] += 1 bad[v] += 1 ret = [None] * nv for v in range(nv): ret[v] = len(comps[id[v]]) - 1 - len(g[v]) - bad[v] print(' '.join(map(str, ret)))
1
61,614,150,708,450
null
209
209
int = int(input()) dev = int % 10 if dev==3: print("bon") elif dev==0 or dev==1 or dev==6 or dev==8: print("pon") else: print("hon")
n = int(input()) s = input() ans = 'No' if n%2 == 0: mid = int(n/2) if s[:mid] == s[mid:]: ans = 'Yes' print(ans)
0
null
82,938,188,391,268
142
279
# -*- coding: utf-8 -*- """ Created on Mon Sep 7 00:38:11 2020 @author: liang """ """ <D - Multiple of 2019> 【方針】 a = b(mod2019) => a - b は 2019の倍数 余りが等しいグループの組み合わせの総数が解になる。 既に2019の倍数であるものは単体で成立するため、[0]のカウントを一つあげておく <累積和> 【計算量削減】 大きな数を使わない ⇒ mod を使う tmp += 7 * 100000000 => 7 * ( 2019*N + α) => 7 * α と同じ   ⇒ 累乗(10**N) に mod をかけると良い 100000000 + γ => (2019*N + β) + γ => β + γ と同じ  ⇒ 累積和 に mod をかけると良い for文で1文字ずつ足し算していくことで実装可能 reversed() : 逆順に並べ替え reversed(input()) : 入力を逆順に取り出す """ S = input() MOD = 2019 counter = [0] * 2019 counter[0] = 1 t = 1 tmp = 0 for i in reversed(S): tmp += int(i)*t tmp %= MOD #累積和を効率化 t *= 10 t %= MOD #累乗を効率化 #print(tmp) counter[tmp] += 1 ans = sum( i*(i-1)//2 for i in counter) print(ans)
#QQ for i in range(1,10): for n in range(1, 10): print("%dx%d=%d" % (i, n, i * n))
0
null
15,479,205,850,400
166
1
import sys import copy #import math #import itertools #import numpy as np #import re def func(x,m): return x**2%m N,X,M=[int(c) for c in input().split()] myset = {X} mydict = {X:0} A = [] A.append(X) s = X i = 0 i_stop = i #i=0は計算したので1から for i in range(1,N): A.append(func(A[i-1],M)) if A[i] in myset: i_stop = i break myset.add(A[i]) mydict[A[i]] = i s+=A[i] if i == N-1: print(s) sys.exit(0) if A[i] == 0: print(s) sys.exit(0) if i!=0: #最後にA[i]が出現したのは? A_repeat = A[mydict[A[i_stop]]:i_stop] s+=((N-1)-(i_stop-1))//len(A_repeat)*sum(A_repeat) for k in range(((N-1)-(i_stop-1))%len(A_repeat)): s+=A_repeat[k] print(s)
n, x, m = map(int, input().split()) A = [0, x] d = {x:1} for i in range(2, n+1): A.append(A[i-1]**2 % m) if A[i] in d: j = d[A[i]] q, r = divmod(n-j+1, i-j) print(sum(A[:j]) + q*sum(A[j:i]) + sum(A[j:j+r])) break else: d[A[i]] = i else: print(sum(A))
1
2,828,543,514,258
null
75
75
import numpy as np def is_good(mid, key): x = A - mid // F return x[x > 0].sum() <= key def binary_search(key): bad, good = -1, 10 ** 18 while good - bad > 1: mid = (bad + good) // 2 if is_good(mid, key): good = mid else: bad = mid return good N, K = map(int, input().split()) A = np.array(input().split(), dtype=np.int64) F = np.array(input().split(), dtype=np.int64) A.sort() F[::-1].sort() print(binary_search(K))
from collections import Counter n, k = map(int, input().split()) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort(reverse=True) la = 10**6+1 cnt = [0] * la for u in a: cnt[u] += 1 for i in range(1, la): cnt[i] += cnt[i-1] def judge(x): y = k for i in range(n): goal = x//f[i] if a[i] > goal: y -= a[i] - goal if y < 0: return False return y >= 0 left = -1 right = 10**12 + 1 while left + 1 < right: mid = (left + right)//2 if judge(mid): right = mid else: left = mid print(right)
1
164,751,047,149,988
null
290
290
import sys input = sys.stdin.readline # A - Study Scheduling h1, m1, h2, m2, k = map(int, input().split()) minute = (h2 - h1) * 60 + (m2 -m1) print(minute - k)
import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(20000000) MOD = 10 ** 9 + 7 INF = float("inf") def main(): H1, M1, H2, M2, K = map(int, input().split()) if M2 >= M1: time = (H2 - H1) * 60 + M2 - M1 else: time = (H2 - H1 - 1) * 60 + M2 + 60 - M1 answer = max(time - K, 0) print(answer) if __name__ == "__main__": main()
1
17,978,463,592,990
null
139
139
import sys, itertools for count, input in zip(itertools.count(1), sys.stdin): if int(input) == 0: break print('Case {0}: {1}'.format(count, input), end='')
# -*- coding: utf-8 -*- n, m, l = list(map(int, input().split())) a = [] b = [] for i in range(n): a.append(list(map(int, input().split()))) for i in range(m): b.append(list(map(int, input().split()))) for i in range(n): for j in range(l): mat_sum = 0 for k in range(m): mat_sum += a[i][k] * b[k][j] if j == l - 1: print('{0}'.format(mat_sum), end='') else: print('{0} '.format(mat_sum), end='') print()
0
null
966,650,816,780
42
60
s=input() con=len(s) ans=['x']*con ANS='' for i in ans: ANS+=i print(ANS)
S=input() N=len(S) M=[] for i in range(N): M.append('x') L=''.join(M) print(L)
1
73,069,763,652,800
null
221
221
# -*- coding: utf-8 -*- from sys import stdin input = stdin.readline MOD = 10**9+7 def main(): D, T, S = list(map(int,input().split())) print('Yes' if D/S <= T else 'No') if __name__ == "__main__": main()
D,T,S = map(int, input().split()) if T-D/S >= 0: print("Yes") else: print("No")
1
3,566,011,169,760
null
81
81
n = int(input()) mod = 10**9+7 ans = 10**n-9**n-9**n+8**n ans %= mod print(ans)
n=int(input()) mod=1000000007 print((pow(10,n,mod)-2*pow(9,n,mod)+pow(8,n,mod))%mod)
1
3,184,379,321,020
null
78
78
# author: Taichicchi # created: 19.09.2020 00:14:21 import sys N = int(input()) S = input() ans = S.count("R") * S.count("G") * S.count("B") for i in range(N - 2): for j in range(i + 1, N - 1): try: k = 2 * j - i if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]): ans -= 1 except: continue print(ans)
N = int(input()) S = input() total = 0 for i in range(N-2): if S[i] == "R": num_G = S[i+1:].count('G') num_B = S[i+1:].count('B') total += num_G * num_B elif S[i] == "G": num_B = S[i+1:].count('B') num_R = S[i+1:].count('R') total += num_B * num_R elif S[i] == "B": num_G = S[i+1:].count('G') num_R = S[i+1:].count('R') total += num_G * num_R for i in range(N-2): for j in range(i+1, N-1): if 2*j-i >= N: continue if S[j] != S[i] and S[2*j-i] != S[j] and S[2*j-i] != S[i]: total -= 1 print(total)
1
36,010,662,105,920
null
175
175
x=int(input()) cnt = x//500 x-=cnt*500 print(5*(x//5) + 1000*cnt)
x = int(input()) v500 = int(x // 500) v5 = int((x % 500 ) //5) print(v500 * 1000 + v5 * 5)
1
42,717,981,181,290
null
185
185
s = input() num = int(input()) for i in range(num): L = input().split() if L[0] == 'print': print(s[int(L[1]):int(L[2])+1]) elif L[0] == 'reverse': ts = s[int(L[1]):int(L[2])+1] s = s[:int(L[1])] + ts[:: -1] + s[int(L[2])+1:] elif L[0] == 'replace': s = s[:int(L[1])] + L[3] + s[int(L[2])+1:]
s = str(input()) q = int(input()) for i in range(q): arr = list(map(str, input().split())) c = arr[0] n1 = int(arr[1]) n2 = int(arr[2]) if c == 'print': print(s[n1:n2 + 1]) if c == 'replace': s = s[0:n1] + arr[3] + s[n2 + 1:len(s)] if c == 'reverse': l = n2 - n1 + 1 reverse = '' for i in range(l): reverse += s[n2 - i] s = s[0:n1] + reverse + s[n2 + 1:len(s)]
1
2,095,487,292,456
null
68
68
def main(): INF = 10 ** 18 N = int(input()) A = list(map(int, input().split(' '))) K = 1 + N % 2 # 余分な×を入れられる個数 # dp[i][j]: i個目までの要素で余分な×をj個使った際の最大値 dp = [[- INF for _ in range(K + 1)] for _ in range(N + 1)] dp[0][0] = 0 for i in range(N): for j in range(K + 1): if j < K: # 余分な×を使う場合 dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]) # 余分な×を使わない場合 now = dp[i][j] if (i + j) % 2 == 0: # 基本はi % 2 == 0の時にA[i]を足していく # ただ、余分な×がj個入っていると、その分ずれる now += A[i] dp[i + 1][j] = max(dp[i + 1][j], now) print(dp[N][K]) if __name__ == '__main__': main()
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
22,821,466,740,380
177
106
from collections import defaultdict from collections import deque from collections import Counter import math import itertools def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() n,x,m = readInts() an = x ans = an moddict = {an:1} for i in range(2,n+1): an = pow(an,2,m) if an in moddict: break else: moddict[an]=i ans += an #print(ans) if an in moddict: rep = (n-len(moddict))//(len(moddict)-moddict[an]+1) rem = (n-len(moddict))%(len(moddict)-moddict[an]+1) #print(rep,rem) rep_sum = 0 boo = 0 for key in moddict: if boo or key==an: boo = 1 rep_sum+=key ans += rep_sum*rep for i in range(rem): ans+=an an=pow(an,2,m) print(ans)
def resolve(): base = 998244353 N, K = map(int, input().split(" ")) LRs = [] for _ in range(K): (L, R) = map(int, input().split(" ")) LRs.append((L, R)) dp = [0] * (N+1) dp_sum = [0] * (N+1) dp[1] = 1 dp_sum[1] = 1 for i in range(2, N+1): for lr in LRs: left = max(i - lr[1] - 1, 0) right = max(i - lr[0], 0) dp[i] += dp_sum[right] - dp_sum[left] if dp[i] >= base: dp[i] %= base dp_sum[i] = dp_sum[i-1] + dp[i] print(dp[-1]) if __name__ == "__main__": resolve()
0
null
2,728,864,726,168
75
74
n, x, m = map(int, input().split()) a = x s = 0 h = [] h.append(a) i = 0 fl = 0 while i < n: s += a a = (a*a) % m if a == 0: break i += 1 if fl == 0 and a in h: fl = 1 po = h.index(a) ss = 0 for j in range(po): ss += h[j] s2 = s - ss f = (n - po) // (i - po) s2 *= f s = s2 + ss i2 = i - po i2 *= f i = i2 + po else: h.append(a) print(s)
n, x, m = map(int, input().split()) lis = [x] flag = [-1 for i in range(m)] flag[x] = 0 left = -1 right = -1 for i in range(n-1): x = x**2 % m if flag[x] >= 0: left = flag[x] right = i break else: lis.append(x) flag[x] = i+1 ans = 0 if left == -1: ans = sum(lis) else: ans += sum(lis[0:left]) length = right - left + 1 ans += sum(lis[left:]) * ((n-left)//length) ans += sum(lis[left:left+((n-left)%length)]) print(ans)
1
2,768,675,070,570
null
75
75
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")
N=int(input()) ok=0 for i in range(1,10): j = N/i if j==int(j) and 1<=j<=9: ok=1 print('Yes') break if ok==0:print('No')
0
null
83,709,442,097,920
101
287
N = int(input()) A = list(map(int, input().split())) mod = 10**9+7 sum = 0 sum_1 = 0 for i in range(N): sum += A[i]%mod sum = (sum**2)%mod for j in range(N): sum_1 += (A[j]**2)%mod sum2=sum-sum_1 if sum2<0: sum2+=mod ans=(sum2*500000004)%mod print(int(ans))
n = int(input()) s=0 a = list(map(int, input().split())) b = sum(a) for i in range(n): b -= a[i] s += a[i]*b s = s % ((10**9)+7) print(s)
1
3,795,756,926,628
null
83
83
r = int(input()) pai = 3.1415 print(2*r*pai)
S = int(input()) h = S//3600 m = S%3600//60 s = S%60 print(f"{h}:{m}:{s}")
0
null
15,936,469,726,520
167
37
import sys def II(): return str(input()) def MI(): return map(int,input().split()) def MI2(): return map(str,input().split()) def LI(): return list(map(int,input().split())) def TI(): return tuple(map(int,input().split())) def RN(N): return [input().strip() for i in range(N)] def main(): S, T = MI2() A, B = MI() U = II() if U == S: A = A-1 elif U == T: B = B-1 print(A, B) if __name__ == "__main__": main()
import sys input = sys.stdin.readline N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] s = []; t = []; for a in A: if a < 0: t.append(a) else: s.append(a) P = 10 ** 9 + 7 # 非負にできるか判定 S = len(s) T = len(t) ok = False if S > 0: if N == K: ok = (T % 2 == 0) else: ok = True else: ok = (K % 2 == 0) ans = 1 if not ok: A.sort(key = lambda x: abs(x)) # 絶対値小→大 for i in range(K): ans = ans * A[i] % P else: # 非負にできる s.sort() # 小→大 t.sort(reverse = True) # 絶対値小→大 if K % 2 == 1: ans *= s.pop() # 一番大きい正の数を確保 p = [] while len(s) >= 2: x = s.pop() x = x * s.pop() p.append(x) while len(t) >= 2: x = t.pop() x = x * t.pop() p.append(x) p.sort(reverse = True) for i in range(K // 2): ans = ans * p[i] % P print(ans % P)
0
null
40,860,647,847,618
220
112
a, b, c =map(int, input().split()) d=(a-1)//c e=b//c ans=e-d print(ans)
# -*- coding: utf-8 -*- # 標準入力を取得 L, R, d = list(map(int, input().split())) # 求解処理 ans = R // d - (L - 1) // d # 結果出力 print(ans)
1
7,549,963,177,988
null
104
104
ARGS=input().split() S=int(ARGS[0]) W=int(ARGS[1]) if S > W: print('safe') else: print('unsafe')
val = input().split() sheep = int(val[0]) wolf = int(val[1]) if (wolf - sheep) >= 0: print("unsafe") else: print("safe")
1
29,227,257,792,288
null
163
163
n = int(input()) ans = 0 d = 10 if n%2==1: print(0) import sys sys.exit() while True: ans += n//d d *= 5 if d>n: break print(ans)
z = int(input()) if z >= 30: print('Yes') else: print('No')
0
null
61,196,958,340,276
258
95
n = int(input()) s = [] t = [] for i in range(n): a,b = input().split() s.append(a) t.append(int(b)) x = s.index(input()) ans = 0 for i in range(x+1,n): ans += t[i] print(ans)
n = int(input()) title = [] length = [] for i in range(n): a, b = input().split() title.append(a) length.append(int(b)) i = title.index(input()) print(sum((length[i+1:])))
1
97,154,724,629,550
null
243
243
x = int(input()) if x == 0: print('1') elif x == 1: print('0')
N, = map(int, input().split()) print(1-N)
1
2,935,893,492,220
null
76
76
n, a, b = map(int,input().split()) tmp = abs(a-b) if tmp%2 == 0: print(tmp//2) else: x = a-1 y = n-b print(min(x,y)+1+((b-a-1)//2))
import itertools import math N = int(input()) citys = [] for i in range(N): citys.append([int(x) for x in input().split()]) a = list(itertools.permutations(range(N), N)) ans = 0 for i in a: b = 0 for j in range(N-1): b += math.sqrt((citys[i[j]][0] - citys[i[j+1]][0])**2 + (citys[i[j]][1] - citys[i[j+1]][1])**2) ans += b print(ans/len(a))
0
null
129,047,109,804,788
253
280
def area_cal(input_fig): stack = [] # area = [[面積計算が始まった位置, 面積],・・・] area = [] total = 0 for i in range(len(input_fig)): fig = input_fig[i] if fig == "\\": stack.append(i) elif fig == "/" and stack: j = stack.pop() width = i - j total += width while area and area[-1][0] > j: width += area[-1][1] area.pop() area.append([i,width]) return area, total input_fig = input() area, total = area_cal(input_fig) print(total) if area: print(len(area),*list(zip(*area))[1]) else: print(0)
from collections import deque S = input() pool_q=deque() slope_q=deque() for i,s in enumerate(S): if s=="\\": slope_q.append(i) pool_q.append((i,0)) elif s=="/": if len(slope_q) > 0: pre_down=slope_q.pop() plus=i-pre_down while 1: pre_pool=pool_q.pop() if pre_pool[0] == pre_down: pool_q.append((pre_down,plus)) break else: plus+=pre_pool[1] SUM = 0 ans=[0] cnt=0 for i in range(len(pool_q)): pool=pool_q.popleft()[1] if pool > 0: ans.append(pool) SUM+=pool cnt+=1 ans[0]=cnt print(SUM) print(*ans)
1
55,533,429,160
null
21
21
a,b = map(str,input().split()) As = a * int(b) Bs = b * int(a) if As<Bs: print(As) else: print(Bs)
X = int(input()) for x in range(1, 361): if x * X % 360 == 0: print(x) exit()
0
null
48,799,828,879,780
232
125
import sys sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline def solve(): s = input() if s[2] == s[3] and s[4] == s[5]: print('Yes') else: print('No') if __name__ == '__main__': solve()
if __name__ == "__main__": nums = map( int, raw_input().split()) nlen = len( nums ) nlast = nlen - 1 while 0 < nlast: j = 0 while j < nlast: if nums[j] > nums[j+1] : d = nums[j+1] nums[j+1] = nums[j] nums[j] = d j += 1 nlast -= 1 nlast = nlen - 1 i = 0 while i < nlen: if i != nlast: print nums[i], else: print nums[i] i += 1
0
null
21,194,038,963,610
184
40
from sys import exit import math def main(): N = int(input()) ran = int(math.sqrt(N)) ans = N for i in range(1,ran+1): if N % i == 0: #print('L') if N / i + i <= ans + 1: ans = ((N / i) + i) -2 #print(i) print(int(ans)) main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) n = I() def yaku(m): ans = [] i = 1 while i*i <= m: if m % i == 0: j = m // i ans.append(i) i += 1 ans = sorted(ans) return ans a = yaku(n) #print(a) ans = float('inf') for v in a: ans = min(ans, (v-1)+(n//v)-1) print(ans)
1
161,400,233,415,392
null
288
288
# n, m, l = map(int, input().split()) # list_n = list(map(int, input().split())) # n = input() # list = [input() for i in range(N) # list = [[i for i in range(N)] for _ in range(M)] import sys input = sys.stdin.readline A, B, M = map(int, input().split()) List_A = list(map(int, input().split())) List_B = list(map(int, input().split())) List_discount = [list(map(int, input().split())) for i in range(M)] # print(List_discount) ans = 2 * 10**5 for d in List_discount: # print(d) p = List_A[d[0]-1] + List_B[d[1]-1] - d[2] ans = min(ans, p) no_discount = min(List_A) + min(List_B) ans = min(ans, no_discount) print(ans)
a, b = map(int, input().split()) ans = 0 if a >= b: for i in range(a): ans += b * 10**i else: for i in range(b): ans += a * 10**i print(ans)
0
null
69,156,011,756,912
200
232
''' Created on 2020/08/31 @author: harurun ''' def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write N=int(pin()) ans="" while N: N-=1 ans+=chr(97+N%26) N=N//26 print(ans[::-1]) return main() #解説AC
N = int(input().strip()) ans = '' while N > 0: ans = chr(ord('a') + (N-1) % 26) + ans N = (N -1) // 26 print(ans)
1
11,875,229,912,952
null
121
121
import math r = float(input()) print("%.5f %.5f" % (math.pi*r *r, 2*math.pi*r))
#coding:utf-8 import math r=float(input()) print("%.6f"%(math.pi*r**2)+" %.6f"%(2*math.pi*r))
1
639,528,162,208
null
46
46
inp = [int(input()) for i in range(10)] m1, m2, m3 = 0, 0, 0 for h in inp: if(h > m1): m3 = m2 m2 = m1 m1 = h elif(h > m2): m3 = m2 m2 = h elif(h > m3): m3 = h print(m1) print(m2) print(m3)
for i in range(1,10): for j in range(1,10): s = i * j print("{0}{3}{1}={2}".format(i, j, s, "x"))
0
null
4,333,978
2
1
S = input() T = input() iteration = len(S) - len(T) + 1 if T in S: ans = 0 else: minimum = len(T) for i in range(iteration): # print('---------------') s = S[i:len(T)+i] # print(s) # print(T) count = 0 for j in range(len(T)): if s[j] != T[j]: count += 1 # print(count) minimum = min(minimum, count) ans = minimum print(ans)
S = str(input()) T = str(input()) s = len(S) t = len(T) ans = [] for i in range(s-t+1): count = 0 U = S[i:i+t] for j in range(t): if U[j] != T[j]: count += 1 ans.append(count) print(min(ans))
1
3,705,132,340,756
null
82
82
A,B,N=map(int,input().split()) if N<B: x=N elif N==B: x=N-1 else: x=(N//B)*B-1 ans=(A*x/B)//1-A*(x//B) print(int(ans))
str1 = raw_input() str2 = raw_input() n = len(str1) for i in xrange(n): j = i s = 0 for k in xrange(len(str2)): if (j+k) > (n-1): j = -k if str1[j+k] != str2[k]: s += 1 if s == 0: print "Yes" break else: print "No"
0
null
14,993,736,739,808
161
64
#from collections import defaultdict, deque #import itertools #import numpy as np #import re import bisect def main(): N = int(input()) SS = [] for _ in range(N): SS.append(input()) S = [] for s in SS: while '()' in s: s = s.replace('()', '') S.append(s) #print(S) S = [s for s in S if s != ''] sum_op = 0 sum_cl = 0 S_both_op = [] S_both_cl = [] for s in S: if not ')' in s: sum_op += len(s) elif not '(' in s: sum_cl += len(s) else: pos = s.find('(') if pos <= len(s) - pos: S_both_op.append((pos, len(s)-pos)) #closeのほうが少ない、'))((('など -> (2,3) else: S_both_cl.append((pos, len(s)-pos)) #closeのほうが多い、')))(('など -> (3,2) # S_both_opは、耐えられる中でより伸ばす順にしたほうがいい? #S_both_op.sort(key=lambda x: (x[0], x[0]-x[1])) #closeの数が小さい順にsortかつclose-openが小さい=伸ばす側にsort #S_both_cl.sort(key=lambda x: (x[0], x[0]-x[1])) #これもcloseの数が小さい順にsortかつclose-openが小さい=あまり縮まない順にsort S_both_op.sort(key=lambda x: x[0]) S_both_cl.sort(key=lambda x: -x[1]) for p in S_both_op: sum_op -= p[0] if(sum_op < 0 ): print('No') exit() sum_op += p[1] for p in S_both_cl: sum_op -= p[0] if(sum_op < 0 ): print('No') exit() sum_op += p[1] if sum_op == sum_cl: print('Yes') else: print('No') if __name__ == "__main__": main()
from operator import itemgetter from itertools import chain N = int(input()) L = [] R = [] for i in range(N): S = input() low = 0 var = 0 for s in S: if s == '(': var += 1 else: var -= 1 low = min(low, var) if var >= 0: L.append((low, var)) else: R.append((low, var)) L.sort(key=itemgetter(0), reverse=True) R.sort(key=lambda x: x[0] - x[1]) pos = 0 for i, (low, var) in enumerate(chain(L, R)): if pos + low < 0: ans = 'No' break pos += var else: ans = 'Yes' if pos == 0 else 'No' print(ans)
1
23,569,347,615,840
null
152
152
MOD = 1000000007 def fast_power(base, power): """ Returns the result of a^b i.e. a**b We assume that a >= 1 and b >= 0 Remember two things! - Divide power by 2 and multiply base to itself (if the power is even) - Decrement power by 1 to make it even and then follow the first step """ result = 1 while power > 0: # If power is odd if power % 2 == 1: result = (result * base) % MOD # Divide the power by 2 power = power // 2 # Multiply base to itself base = (base * base) % MOD return result n,k = [int(j) for j in input().split()] d = dict() ans = k d[k] = 1 sum_so_far = 1 for i in range(k-1, 0, -1): d[i] = fast_power(k//(i),n) for mul in range(i*2, k+1, i): d[i]-=d[mul] # d[i] = max(1, d[i]) ans+=(i*d[i])%MOD # if d[i]>1: # sum_so_far += d[i] print(ans%MOD)
S = input() N = len(S) ans = 'No' # 文字列strの反転は、str[::-1] if S == S[::-1] and S[:(N-1)//2] == S[:(N-1)//2][::-1] and S[(N+1)//2:] == S[(N+1)//2:][::-1]: ans = 'Yes' print(ans)
0
null
41,500,828,859,622
176
190