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
from collections import deque s = input() n = int(input()) q_list = [input().split() for _ in range(n)] d = deque(list(s)) r_flag = False for q in q_list: if q[0] == "1": r_flag = not r_flag elif q[0] == "2": if q[1] == "1": if r_flag: d.append(q[2]) else: d.appendleft(q[2]) elif q[1] == "2": if r_flag: d.appendleft(q[2]) else: d.append(q[2]) if r_flag: d.reverse() print("".join(d))
from collections import deque def main(): s = input() q = int(input()) d = deque(s) is_reversed = False for _ in range(q): query = list(input().split()) if query[0] == "1": if is_reversed: is_reversed = False else: is_reversed = True elif query[0] == "2": if query[1] == "1": if is_reversed: d.append(query[2]) else: d.appendleft(query[2]) elif query[1] == "2": if is_reversed: d.appendleft(query[2]) else: d.append(query[2]) if is_reversed: print(*(list(d)[::-1]), sep="") else: print(*list(d), sep="") if __name__ == "__main__": main()
1
57,139,663,817,318
null
204
204
import itertools n,m,q=map(int,input().split()) d=[list(map(int,input().split())) for i in range(q)] ans=0 for i in list(itertools.combinations_with_replacement(list(range(1,m+1)), n)): a=list(i) hantei=0 for j in range(q): if (a[d[j][1]-1]-a[d[j][0]-1])==d[j][2]: hantei+=d[j][3] ans=max(ans,hantei) print(ans)
import math def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(map(int, input().split())) def i_row(N): return [int(input()) for _ in range(N)] def i_row_list(N): return [list(map(int, input().split())) for _ in range(N)] mnum,snum=i_map() snholder=set() for i in range(snum): d=i_input() ls=i_list() snholder=snholder | set(ls) print(mnum-len(snholder))
0
null
26,103,517,641,718
160
154
N = int(input()) if N ==2: print(1) exit() def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: #素数の場合はここ arr.append([temp, 1]) if arr==[]: #1の場合はここ arr.append([n, 1]) return arr def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] A = make_divisors(N) ans = 0 #自分自身の一個を足しておく SET = set([N]) #print(A) for i in range(1,len(A)): M = N*1 while M%A[i]==0: M = M//A[i] if M%A[i] == 1: ans += 1 SET.add(A[i]) #ans = len(SET) #print(SET) #print(ans) N -= 1 B = factorization(N) yakusu = 1 #print(B) for i in range(len(B)): yakusu *= (B[i][1]+1) #print(yakusu) ans += yakusu-1 print(ans)
import math N = int(input()) def enumerate_divisors(N): all_divisors = set() for divisor in range(1, int(math.sqrt(N)) + 1): if N%divisor == 0: if divisor == 1: all_divisors.add(N/divisor) else: all_divisors = all_divisors | {divisor, N/divisor} all_divisors = list(all_divisors) return all_divisors def calculate_reminder(N, d): while True: reminder = N%d if reminder == 0: N /= d else: return reminder if N == 2: counter = 1 else: counter = len(enumerate_divisors(N-1)) for div in enumerate_divisors(N): if calculate_reminder(N, div) == 1: counter += 1 print(counter)
1
41,338,248,554,848
null
183
183
def main(): N = int(input()) x, y = map(int, input().split()) a1 = x + y a2 = x + y b1 = y - x b2 = y - x N -= 1 while N != 0: x, y = map(int, input().split()) a1 = max(a1, x + y) a2 = min(a2, x + y) b1 = max(b1, y - x) b2 = min(b2, y - x) N = N - 1 print(max(a1 - a2, b1 - b2)) main()
def main(): N, X, Y = (int(i) for i in input().split()) cnt = [0]*N for i in range(1, N+1): for j in range(i+1, N+1): d = min(abs(i-j), abs(i-X)+1+abs(j-Y), abs(i-X)+abs(X-Y)+abs(j-Y)) cnt[d] += 1 for d in cnt[1:]: print(d) if __name__ == '__main__': main()
0
null
23,909,403,799,632
80
187
print(('Yes','No')[sum(map(int,input()))%9>0])
n = int(input()) sumOfN = sum(int(i) for i in list(str(n))) print("No" if sumOfN%9 else "Yes")
1
4,386,503,268,190
null
87
87
import math from typing import List, Any def read_int() -> int: return int(input().strip()) def read_ints() -> List[int]: return list(map(int, input().strip().split(' '))) def solve() -> Any: H, W = read_ints() last_S = '' INF = 10**9+1 dist = [ [INF for _ in range(H*W)] for _ in range(H*W) ] for i in range(H*W): dist[i][i] = 0 for i in range(H): S = input().strip() for j in range(W): if S[j] == '#': continue top = (i-1)*W+j left = i*W+j-1 current = i*W+j if j > 0 and S[j-1] == '.': dist[left][current] = dist[current][left] = 1 if i > 0 and last_S[j] == '.': dist[top][current] = dist[current][top] = 1 last_S = S for k in range(H*W): for i in range(H*W): for j in range(H*W): dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]) return max(cell for row in dist for cell in row if cell != INF) if __name__ == '__main__': print(solve())
import networkx as nx H, W = map(int, input().split()) maze = [input() for _ in range(H)] G = nx.Graph() # 辺を加えていく for h in range(H): for w in range(W - 1): if maze[h][w] == maze[h][w + 1] == '.': G.add_edge((h, w), (h, w + 1)) for h in range(H - 1): for w in range(W): if maze[h][w] == maze[h + 1][w] == '.': G.add_edge((h, w), (h + 1, w)) def bfs(sy, sx): d = dict() d[(sy, sx)] = 0 for coordinate_from, coordinate_to in nx.bfs_edges(G, (sy, sx)): d[coordinate_to] = d[coordinate_from] + 1 return max(d.values()) ans = 0 for y in range(H): for x in range(W): if maze[y][x] == '.': ans = max(ans, bfs(y, x)) print(ans)
1
94,531,154,143,128
null
241
241
def main(): from itertools import product H, W, K = map(int, input().split()) S = [input() for _ in range(H)] S_T = [[int(s[w]) for s in S] for w in range(W)] sumS = sum(map(sum, S_T)) ans = (H - 1) * (W - 1) if sumS <= K: print(0) else: for i in product([True, False], repeat=H-1): cnt = sum(i) if cnt >= ans: continue M = [[0]] for j, k in enumerate(i): if k: M.append([]) M[-1].append(j+1) A = [0] * len(M) for s_t in S_T: for l, m in enumerate(M): A[l] += sum(s_t[i] for i in m) if any(a > K for a in A): cnt += 1 if cnt >= ans: break A = [sum(s_t[i] for i in m) for m in M] if any(a > K for a in A): cnt = ans + 1 break ans = min(cnt, ans) print(ans) if __name__ == '__main__': main()
def main(): K = int(input()) work = 7 answer = -1 for i in range(1, K+1): i_mod = work % K if i_mod == 0 : answer = i break work = i_mod * 10 + 7 print(answer) main()
0
null
27,173,753,535,474
193
97
def main(): x, y = map(int, input().split()) print('Yes' if 2*x <= y <= 4*x and y % 2 == 0 else 'No') if __name__ == '__main__': main()
N,M=map(int,input().split()) A_M=list(map(int,input().split())) if N >= sum(A_M): print(N-sum(A_M)) else: print(-1)
0
null
22,863,067,698,570
127
168
def main(): N, S = map(int, input().split()) A = list(map(int, input().split())) MOD = 998244353 dp = [[0] * (S+5) for _ in range(N+5)] dp[0][0] = 1 for i in range(N): for j in range(S+1): dp[i+1][j] += 2 * dp[i][j] dp[i+1][j] %= MOD if j + A[i] <= S: dp[i+1][j+A[i]] += dp[i][j] dp[i+1][j+A[i]] %= MOD print(dp[N][S]) if __name__ == "__main__": main()
n = int(input()) a = [int(i) for i in input().split()] a.sort(reverse=True) i = 1 ans = a[0] c = 1 while c < n - 1: k = min(2, n - 1 - c) c += k ans += a[i] * k i += 1 print(ans)
0
null
13,542,075,987,260
138
111
n = int(input()) for i in range(1,n+1): ans = int(i*1.08) if ans == n: print(i) break else: print(":(")
n = int(input()) found = False for i in range(1, n + 1): x = int ( i * 1.08 ) if x == n : print(i) found = True break if not found: print(":(")
1
125,501,278,964,352
null
265
265
from sys import exit import copy #import numpy as np #from collections import deque d, = map(int, input().split()) c= list(map(int, input().split())) s=[list(map(int, input().split())) for _ in range(d)] # t=[int(input()) for _ in range(d)] sche=[0 for _ in range(d)] s_tmp=float("inf")*(-1) for off in range(0,13): last=[0 for _ in range(26)] sche=[0 for _ in range(d)] for day in range(1,d+1): idx=day-1 d_tmp=float("inf")*(-1) i_tmp=0 for t in range(26): delta=0 l_tmp=copy.copy(last) delta+=s[idx][t] l_tmp[t]=day for l in range(26): delta-=0.5*(off+1)*c[l]*((day-l_tmp[l])+(day+off-l_tmp[l])) if delta>=d_tmp: d_tmp=delta i_tmp=t sche[idx]=i_tmp+1 # score+=d_tmp last[i_tmp]=day # print(score) # print(i_tmp+1) score=0 last=[0 for _ in range(26)] for i in range(1,d+1): idx=i-1 score+=s[idx][sche[idx]-1] for l in range(26): score-=c[l]*(i-last[l]) last[sche[idx]-1]=i # print(score) if score>=s_tmp: s_tmp=score sche_tmp=copy.copy(sche) for i in sche_tmp: print(i) # print(s_tmp)
D = int(input()) C = list(map(int, input().split())) S = [list(map(int, input().split())) for _ in range(D)] import copy MAX_SCORE = -float('inf') MAX_ANS = -1 for K in range(26): v = 0 ans = [0]*D L = [0]*26 for i in range(1, D+1): max_score = -float('inf') max_idx = 0 for j in range(26): temp = v temp += S[i-1][j] L_ = copy.copy(L) L_[j] = i for k in range(26): for l in range(i, min(i+K+1, D+1)): temp -= C[k]*(l-L_[k]) if temp >= max_score: max_score = temp max_idx = j v += S[i-1][max_idx] L[max_idx] = i for k in range(26): v -= C[k]*(i-L[k]) ans[i-1] = max_idx+1 if v >= MAX_SCORE: MAX_SCORE = v MAX_ANS = ans print(*MAX_ANS, sep='\n')
1
9,684,651,172,768
null
113
113
count = 0 def marge(A,left,mid,right): global count n1 = mid -left n2 = right -mid L = [] R = [] for i in range(left,n1+left): L.append(A[i]) for i in range(mid,n2+mid): R.append(A[i]) L.append(float("inf")) R.append(float("inf")) r_id,l_id = 0,0 for k in range(left,right): count += 1 if(L[l_id] <= R[r_id]): A[k] = L[l_id] l_id += 1 else: A[k] = R[r_id] r_id += 1 def margeSort(A,left,right): if left+1 < right: mid = int((left+right)/2) margeSort(A,left,mid) margeSort(A,mid,right) marge(A,left,mid,right) n = int(raw_input()) s = raw_input() A = [] A = map(int,s.split()) margeSort(A,0,n) A_str = map(str,A) print(" ".join(list(A_str))) print count
import math inf = math.inf def merge(A, left, mid, right): global cnt L = [] R = [] for i in A[left:mid]: L.append(i) for i in A[mid:right]: R.append(i) L.append(inf) R.append(inf) i = 0 j = 0 for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if right - left > 1: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) _ =input() A = list(map(int, input().rstrip().split(" "))) cnt = 0 mergeSort(A, 0, len(A)) print(" ".join(list(map(str, A)))) print(cnt)
1
108,880,249,420
null
26
26
nums = [] while True: num = [int(e) for e in input().split()] if num[0]==0 and num[1]==0: break nums.append(num) for i in range(len(nums)): for j in range(len(nums[i])): for k in range(j): if nums[i][k] > nums[i][j]: a = nums[i][k] nums[i][k] = nums[i][j] nums[i][j] = a for i in range(len(nums)): print(" ".join(map(str, nums[i])))
while True: m = map(int,raw_input().split()) if m[0] == 0 and m[1] == 0: break if m[0] >= m[1]: print m[1],m[0] else: print m[0],m[1]
1
518,907,357,588
null
43
43
n = int(input()) s = input() t = "" for i in range(n // 2): t += s[i] if s == (t + t): print('Yes') else: print('No')
N=int(input()) S=input() x="Yes" if N%2==1: print("No") else: for i in range(0,N//2): if S[i]!=S[i+N//2]: x="No" break print(x)
1
147,030,751,008,442
null
279
279
import math x, y = map(int, input().split()) MOD = 10**9+7 def combination(n, r, mod): r = min(r, n-r) num = 1 d = 1 for i in range(1, r+1): num = num * (n+1-i) % mod d = d * i % mod return num * pow(d, mod-2, mod) % mod if (x+y)%3 != 0: print (0) exit() n = (x+y)/3 yy = (2*x-y)/3 xx = (2*y-x)/3 if yy < 0: print (0) exit() if xx < 0: print (0) exit() if xx.is_integer() and yy.is_integer(): print (combination(int(xx+yy),int(xx),MOD)) else: print (0)
#n回,m回  X =n + 2*m Y = 2*n + m X,Y = map(int,input().split()) import numpy as np from functools import reduce import math a = [[1, 2], [2, 1]] #次に逆行列を求めます。 mod = pow(10,9)+7 b = np.linalg.inv(a) Z = np.array([[X],[Y]]) n,m=np.dot(b,Z) p,q = *n,*m def comb(n,k,p): if k==0: return 1 A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)]) B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)]) return A*pow(B,p-2,p)%p if p<0 or q<0: print(0) elif not abs(p-round(p))<pow(10,-3) or not abs(q-round(q))<pow(10,-3): print(0) elif p==0 and q==0: print(0) elif p==0: print(1) elif q==0: print(1) else: n = int(round(p)) m = int(round(q)) ans = comb(n+m,m,mod) print(ans%mod)
1
150,170,097,150,000
null
281
281
n=int(input()) k=[1] ans=[] c=26 wa=0 while wa+c<n: k.append(c) wa+=c c=c*26 n=n-1-wa for i in k[::-1]: ans.append(n//i) n=n%i t='' for i in ans: t+=chr(97+i) print(t)
a='abcdefghijklmnopqrstuvwxyz' N=int(input()) name='' while N>0: N-=1 name+=a[N%26] N//=26 print(name[::-1])
1
11,843,868,024,032
null
121
121
import numpy as np a, b, x = map(int,input().split()) if x >= a**2*b/2: ans = np.arctan(2*(b-x/a**2)/a) else: ans = np.arctan(a*b/2/x*b) print(ans*180/np.pi)
import sys from operator import itemgetter import math sys.setrecursionlimit(10**9) input = sys.stdin.readline def ii(): return int(input()) def mi(): return map(int, input().split()) def lmi(): return list(map(int, input().split())) def lmif(n): return [list(map(int, input().split())) for _ in range(n)] def ss(): return input().split() def main(): a, b, x = mi() V = a**2 * b if V // 2 < x: X = 2*x / a**2 - b Y = b - X ans = math.degrees(math.asin(Y/math.sqrt(a**2 + Y**2))) else: X = 2*x / (a*b) ans = math.degrees(math.asin(b/math.sqrt(X**2 + b**2))) print(ans) return main()
1
163,583,585,651,488
null
289
289
from itertools import product import numpy as np n, _, x = map(int, input().split()) arr1 = np.array([list(map(int, input().split())) for _ in range(n)]) ans = 1200000 if np.all(arr1.sum(0)[1:] >= x): for i in product((0, 1), repeat=n): arr2 = (i * arr1.T).sum(1) if np.all(arr2[1:] >= x): ans = min(ans, arr2[0]) print(ans) else: print(-1)
h,n=map(int,input().split()) inf=100000000000 dp=[inf]*(h+1) dp[h]=0 for i in range(n): a,b=map(int,input().split()) for j in range(h,-1,-1): dp[max(j-a,0)]=min(dp[max(j-a,0)],dp[j]+b) print(dp[0])
0
null
51,983,064,599,090
149
229
''' ITP-1_8-A ??§????????¨?°????????????\????????? ????????????????????????????°?????????¨??§???????????\????????????????????°???????????????????????????????????? ???Input ????????????1??????????????????????????? ???Output ????????????????????????????°?????????¨??§???????????\???????????????????????????????????????????????? ??¢????????????????????\??????????????????????????????????????????????????? ''' # inputData inputData = input() for i in range(len(inputData)): if "a"<=inputData[i]<="z": # ??§???????????? print(inputData[i].upper(),end='') elif "A"<=inputData[i]<="Z": # ?°????????????? print(inputData[i].lower(),end='') else: # ??¢????????????????????\????????????????????? print(inputData[i],end='') # ???????????? print('')
a = list(map(int, input().split())) print('un' * (a[0] <= a[1]) + 'safe')
0
null
15,316,928,804,812
61
163
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # 二分探索 N, K = lr() A = np.array(lr()) F = np.array(lr()) A.sort() F = np.sort(F)[::-1] def check(x): count = np.maximum(0, (A - (x // F))).sum() return count <= K left = 10 ** 12 # 可能 right = -1 # 不可能 while left > right + 1: mid = (left+right) // 2 if check(mid): left = mid else: right = mid print(left) # 51
q = int(input()) sort1 = list(map(int, input().split())) def bubblesort(ary): cnt = 0 for i in range(q): for j in range(q-1, i, -1): if ary[j] < ary[j-1]: ary[j-1], ary[j] = ary[j], ary[j-1] cnt += 1 return (ary, cnt) ary, cnt = bubblesort(sort1) print(" ".join(map(str, ary))) print(cnt)
0
null
82,623,383,755,332
290
14
import sys sys.setrecursionlimit(10000) ERROR_INPUT = 'input is invalid' OPECODE = ['+', '-', '*'] BUF = [] def main(): stack = get_input() ans = calc_stack(stack=stack) print(ans) def calc_stack(stack): if stack[-1] in OPECODE: BUF.append(stack[-1]) stack.pop() return calc_stack(stack=stack) else: right_num = int(stack[-1]) stack.pop() if stack[-1] in OPECODE: BUF.append(right_num) BUF.append(stack[-1]) stack.pop() return calc_stack(stack=stack) else: left_num = int(stack[-1]) stack.pop() stack.append(calc(left_num, right_num, BUF[-1])) BUF.pop() stack.extend(reversed(BUF)) BUF.clear() if len(stack) == 1: return stack[0] else: return calc_stack(stack=stack) def calc(left, right, ope): if ope == '+': return left + right elif ope == '-': return left - right elif ope == '*': return left * right def get_input(): inp = input().split(' ') opecode_count = 0 OPECODE_count = 0 for i in inp: if i in OPECODE: opecode_count += 1 elif int(i) < 0 or int(i) > 10**6: print(ERROR_INPUT) sys.exit(1) else: OPECODE_count += 1 if opecode_count < 1 or opecode_count > 100: print(ERROR_INPUT) sys.exit(1) if OPECODE_count < 2 or OPECODE_count > 100: print(ERROR_INPUT) sys.exit(1) return inp main()
L = input().split() n = len(L) A = [] top = -1 for i in range(n): if L[i] not in {"+","-","*"}: A.append(int(L[i])) top += 1 else: if(L[i] == "+"): A[top - 1] = A[top - 1] + A[top] elif(L[i] == "-"): A[top - 1] = A[top -1] - A[top] elif(L[i] == "*"): A[top - 1] = A[top - 1] * A[top] del A[top] top -= 1 print(A[top])
1
38,083,726,560
null
18
18
a, b, c = map(int, input().split()) sahen = 4*a*b uhen = (c-a-b)**2 if c-a-b < 0: ans = "No" elif sahen < uhen: ans = "Yes" else: ans = "No" print(ans)
rs = [(x - l, x + l) for x, l in (map(int, input().split()) for _ in range(int(input())))] rs.sort(key=lambda x: x[1]) last = - 10 ** 9 ans = 0 for l, r in rs: if last <= l: ans += 1 last = r print(ans)
0
null
70,704,109,846,190
197
237
N = input() total = 0 for i in N: total += int(i) print('Yes') if total % 9 == 0 else print('No')
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) C1 = A1 - B1 C2 = A2 - B2 if C1 * C2 >= 0: print(0) else: if C1 < 0: C1, C2 = -C1, -C2 P = T1 * C1 Q = P + T2 * C2 if Q > 0: print(0) elif Q == 0: print('infinity') else: hi = 10**18 lo = -1 while hi - lo > 1: mid = (hi + lo) // 2 if Q * mid + P <= 0: hi = mid else: lo = mid if Q * hi + P == 0: print(hi * 2) else: print(hi * 2 - 1)
0
null
67,757,132,266,172
87
269
# -*- 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()
inputs = input().split() a = int(inputs[0]) b = inputs[1] b = 100 * int(b[0]) + 10 * int(b[2]) + int(b[3]) print(a * b // 100)
0
null
8,981,814,400,002
60
135
mountains = [] for x in range(10): mountains.append(int(raw_input())) mountains.sort() print(mountains[-1]) print(mountains[-2]) print(mountains[-3])
taro_point = 0 hanako_point = 0 N = int(input()) for _ in range(N): taro,hanako = input().split() list = [taro,hanako] list_new = sorted(list) if taro == hanako: taro_point += 1 hanako_point += 1 elif list_new[1] == hanako: hanako_point +=3 elif list_new[1] == taro: taro_point += 3 print(str(taro_point),str(hanako_point))
0
null
1,007,825,134,580
2
67
import math a, b, C = map(int, input().split()) S = a * b * math.sin(math.radians(C)) / 2 L = a + b + (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(C))) ** 0.5 h = b * math.sin(math.radians(C)) print('%.7f\n%.7f\n%.7f\n' % (S, L, h))
import math a,b,c=map(float,input().split()) c=math.radians(c) h=b*math.sin(c) s=a*h/2 d=math.sqrt(a**2+b**2-2*a*b*math.cos(c)) l=a+b+d print(s,l,h)
1
178,339,901,630
null
30
30
N = int(input()) ints = map(int, input().split()) for i in ints: if i % 2 == 0: if i % 3 != 0 and i % 5 != 0: print('DENIED') exit() print('APPROVED')
print("YNeos"['7' not in input()::2])
0
null
51,617,933,369,768
217
172
n=int(input()) xy=[list(map(int,input().split())) for _ in range(n)] from itertools import permutations ans=0 for i in permutations(range(n),n): for j in range(1,n): ans+=((xy[i[j]][0]-xy[i[j-1]][0])**2+(xy[i[j]][1]-xy[i[j-1]][1])**2)**0.5 for i in range(1,n+1): ans/=i print(ans)
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): X, Y, Z = MI() A = [Z, X, Y] print(' '.join(map(str, A))) if __name__ == "__main__": main()
0
null
92,936,738,979,392
280
178
from math import ceil, floor def resolve(): N = int(input()) tax = 0.08 if floor(ceil(N/(1+tax))*(1+tax)) == N: print(ceil(N/(1+tax))) else: print(":(") if __name__ == "__main__": resolve()
N = int(input()) A = list(map(int,input().split())) ans = sum(A) X = [0]*(10**5+1) for x in A: X[x] += 1 Q = int(input()) for _ in range(Q): B,C = map(int,input().split()) ans += (C-B)*X[B] X[C] += X[B] X[B] = 0 print(ans)
0
null
69,145,743,958,228
265
122
H , W = map(int,input().split()) if H == 1 or W ==1: print(1) exit() if H %2 == 0: tate = H/2 ans = tate * W else: tate1 = H // 2 + 1 tate2 = H // 2 if W % 2 == 0: ans = (tate1 + tate2) * W/2 else: ans = tate1*((W//2)+1) + tate2*(W//2) print(int(ans))
n = int(input()) alst = list(map(int, input().split())) alst.sort() bef = -1 for a in alst: if bef == a: print("NO") break bef = a else: print("YES")
0
null
62,519,474,492,170
196
222
from fractions import gcd from functools import reduce import numpy as np def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm(numbers): return reduce(lcm_base, numbers, 1) N, M = map(int, input().split()) A = list(map(int, input().split())) A = list(map(lambda x: x // 2 , A)) A = np.array(A) l = lcm(A) if ((l//A % 2 == 1).sum() != N): print(0) else: ans = (M//l + 1) // 2 print(ans)
# -*- coding:utf-8 -*- h,w = map(int,input().split()) if h == 1 or w == 1: print(1) elif w %2 == 0: print(h * w //2) elif h % 2 == 0: print(h * w //2) else: print(h*w//2+1)
0
null
76,012,117,015,592
247
196
import itertools a=int(input()) b=list(map(int,input().split())) c=list(map(int,input().split())) n=sorted(b) m=list(itertools.permutations(n)) m=[list(i) for i in m] print(abs(m.index(b)-m.index(c)))
import itertools N = int(input()) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) lis = list(itertools.permutations(range(1,N+1))) a = lis.index(P)+1 b = lis.index(Q)+1 ans = abs(a-b) print(ans)
1
100,545,101,608,900
null
246
246
import collections n = int(input()) dic = collections.defaultdict(int) for _ in range(n): s = input() dic[s] +=1 sorted_dic = sorted(dic.items(), key = lambda x:(-x[1],x[0])) val = sorted_dic[0][1] for k,v in sorted_dic: if v==val: print(k)
# abc155_c.py # https://atcoder.jp/contests/abc155/tasks/abc155_c # C - Poll / # 実行時間制限: 2 sec / メモリ制限: 1024 MB # 配点: 300点 # 問題文 # N枚の投票用紙があり、i (1≤i≤N) 枚目には文字列 Siが書かれています。 # 書かれた回数が最も多い文字列を全て、辞書順で小さい順に出力してください。 # 制約 # 1≤N≤2×105 # Siは英小文字のみからなる文字列 (1≤i≤N) # Siの長さは 1 以上 10 以下 (1≤i≤N) # 入力 # 入力は以下の形式で標準入力から与えられる。 # N # S1 # : # SN # 出力 # あてはまる文字列を全て辞書順で小さい順に、改行区切りで出力せよ。 # 入力例 1 # 7 # beat # vet # beet # bed # vet # bet # beet # 出力例 1 # beet # vet # 書かれた回数は beet と vet が 2回、beat と bed と bet が 1 回です。したがって、2回書かれた beet と vet を出力します。 # 入力例 2 # 8 # buffalo # buffalo # buffalo # buffalo # buffalo # buffalo # buffalo # buffalo # 出力例 2 # buffalo # 入力例 3 # 7 # bass # bass # kick # kick # bass # kick # kick # 出力例 3 # kick # 入力例 4 # 4 # ushi # tapu # nichia # kun # 出力例 4 # kun # nichia # tapu # ushi global FLAG_LOG FLAG_LOG = False def log(value): # FLAG_LOG = True # FLAG_LOG = False if FLAG_LOG: print(str(value)) def calculation(lines): # S = lines[0] N = int(lines[0]) # N, M = list(map(int, lines[0].split())) # values = list(map(int, lines[1].split())) # values = list(map(int, lines[2].split())) values = list() for i in range(N): values.append(lines[i+1]) # valueses = list() # for i in range(N): # valueses.append(list(map(int, lines[i+1].split()))) dic = dict() for value in values: if value in dic: dic[value] += 1 else: dic[value] = 1 tmp = list() for key in dic: tmp.append(dic[key]) ma = max(tmp) results = list() for key in dic: if dic[key] == ma: results.append(key) results.sort() return results # 引数を取得 def get_input_lines(): line = input() N = int(line) lines = list() lines.append(line) for _ in range(N): lines.append(input()) return lines # テストデータ def get_testdata(pattern): if pattern == 1: lines_input = ['7', 'beat', 'vet', 'beet', 'bed', 'vet', 'bet', 'beet'] lines_export = ['beet', 'vet'] if pattern == 2: lines_input = ['8', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo'] lines_export = ['buffalo'] if pattern == 3: lines_input = ['7', 'bass', 'bass', 'kick', 'kick', 'bass', 'kick', 'kick'] lines_export = ['kick'] if pattern == 4: lines_input = ['4', 'ushi', 'tapu', 'nichia', 'kun'] lines_export = ['kun', 'nichia', 'tapu', 'ushi'] return lines_input, lines_export # 動作モード判別 def get_mode(): import sys args = sys.argv global FLAG_LOG if len(args) == 1: mode = 0 FLAG_LOG = False else: mode = int(args[1]) FLAG_LOG = True return mode # 主処理 def main(): import time started = time.time() mode = get_mode() if mode == 0: lines_input = get_input_lines() else: lines_input, lines_export = get_testdata(mode) lines_result = calculation(lines_input) for line_result in lines_result: print(line_result) # if mode > 0: # print(f'lines_input=[{lines_input}]') # print(f'lines_export=[{lines_export}]') # print(f'lines_result=[{lines_result}]') # if lines_result == lines_export: # print('OK') # else: # print('NG') # finished = time.time() # duration = finished - started # print(f'duration=[{duration}]') # 起動処理 if __name__ == '__main__': main()
1
70,304,344,306,240
null
218
218
N = int(input()) l = [i for i in range(1, N + 1) if i % 3 != 0 and i % 5 != 0] s = sum(l) print(s)
n, x, m = (int(x) for x in input().split()) A = [x] used = {x, } while True: x = pow(x, 2, m) if x in used: index = A.index(x) break else: A.append(x) used.add(x) if n <= len(A): print(sum(A[:n])) else: ans = sum(A) n -= len(A) m = len(A) - index ans += (n // m) * sum(A[index:]) ans += sum(A[index:index + (n % m)]) print(ans)
0
null
18,939,194,309,616
173
75
from scipy.sparse.csgraph import floyd_warshall N,M,L = list(map(int, input().split())) edges = [[0] * N for _ in range(N)] for _ in range(M): A,B,C = list(map(int, input().split())) edges[A-1][B-1] = C edges[B-1][A-1] = C Q = int(input()) queries = [] for _ in range(Q): queries.append(list(map(int,input().split()))) # use flord warshall to find min path between all towns edges = floyd_warshall(edges) # if the two towns can be travelled to on one tank, add to our fuel graph with distance 1 for i in range(N): for j in range(N): if edges[i][j] <= L: edges[i][j] = 1 else: edges[i][j] = 0 # use flord warshall to find min number of fuel tanks to travel between two towns edges = floyd_warshall(edges) for query in queries: s = query[0] - 1 t = query[1] - 1 num_tanks = edges[s][t] - 1 if num_tanks != float('inf'): print(int(num_tanks)) else: print("-1")
import sys input = sys.stdin.readline N,M,L = map(int, input().split()) INF = float("inf") dist1 = [[INF]*N for i in range(N)] dist2 = [[INF]*N for i in range(N)] for i in range(M): A,B,C = map(int, input().split()) A -= 1 B -= 1 dist1[A][B] = C dist1[B][A] = C for i in range(N): dist1[i][i] = 0 dist2[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): d = dist1[i][k]+dist1[k][j] if dist1[i][j] <= d: continue dist1[i][j] = d for i in range(N): for j in range(N): if dist1[i][j] > L or i==j: continue dist2[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): d = dist2[i][k]+dist2[k][j] if dist2[i][j] <= d: continue dist2[i][j] = d Q = int(input()) for i in range(Q): s,t = map(int, input().split()) print(dist2[s-1][t-1]-1 if dist2[s-1][t-1]<=L else -1)
1
173,742,116,000,704
null
295
295
def func(N): strN = str(N) sum = 0 for s in strN: sum += int(s) return "Yes" if sum % 9 == 0 else "No" if __name__ == "__main__": N = str(input()) print(func(N))
def main(): k = int(input()) a,b = map(int,input().split()) flag = 0 for i in range(a, b + 1): if i % k == 0: flag += 1 if flag > 0: print('OK') else: print('NG') main()
0
null
15,454,191,667,152
87
158
import collections N=int(input()) A=list(map(int,input().split())) X=collections.Counter(A) Q=int(input()) ans=sum(A) for i in range(Q): B,C=map(int,input().split()) ans+=(C-B)*X[B] print(ans) X[C]+=X[B] X[B]=0
H,N = map(int,input().split()) INF = 10 ** 10 dp = [INF] * (H + 1) dp[0] = 0 for i in range(N): attack,magic = map(int,input().split()) for j in range(len(dp)): if dp[j] == INF: continue target = j + attack if j + attack > H: target = H if dp[target] > dp[j] + magic: dp[target] = dp[j] + magic print(dp[-1])
0
null
46,910,832,945,992
122
229
import math , sys N , M = list(map( int, input().split() )) cor = 0 pen = 0 F = [False]*N C = [0]*N for i in range(M): A , B = list( input().split() ) A = int(A)-1 if B == "WA" and not F[A]: C[A]+=1 #print(C) if B == "AC" and not F[A]: F[A] = True cor += 1 pen +=C[A] print(cor,pen)
import itertools import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def score(A): res = 0 for a, b, c, d in abcd: if A[b - 1] - A[a - 1] == c: res += d return res def main(n, m, abcd): p = itertools.combinations_with_replacement(range(1, m+1), n) L = list(p) ans = 0 for A in L: ans = max(ans, score(list(A))) return ans n, m, q = map(int, readline().split()) abcd = [list(map(int, readline().split())) for _ in range(q)] print(main(n, m, abcd))
0
null
60,391,742,640,000
240
160
list = input().split(" ") a = int(list[0]) b = int(list[1]) print(a * b)
import math N, K=map(int, input().split()) A=list(map(int, input().split())) F=list(map(int, input().split())) A=sorted(A, reverse=False) F=sorted(F, reverse=True) a=-1 b=max([A[i]*F[-i-1] for i in range(N)]) while b-a>1: tmp=(a+b)//2 c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)]) if c<=K: b=tmp else: a=tmp print(b)
0
null
90,637,475,536,130
133
290
import random import time t_start = time.time() d = int(input()) c = list(map(int,input().split())) s = [list(map(int,input().split())) for i in range(d)] def calc_score(day, contest, score, last): t_last = last[:] t_last[contest] = day + 1 contest_score = s[day][contest] score += contest_score dis = 0 for i in range(26): dis += c[i] * ((day + 1) - t_last[i]) score -= dis return score score = 0 last = [0 for i in range(26)] for day in range(d): t_score = 0 for each_contest in range(26): each_t_score = calc_score(day, each_contest, score, last) if each_t_score > t_score: t_score = each_t_score contest = each_contest score = t_score last[contest] = day + 1 print(contest + 1)
for i in range(365): print(1)
1
9,722,327,716,640
null
113
113
n = int(input()) if n >= 400 and n <= 599: kyu = 8 elif n >= 600 and n <= 799: kyu = 7 elif n >= 800 and n <= 999: kyu = 6 elif n >= 1000 and n <= 1199: kyu = 5 elif n >= 1200 and n <= 1399: kyu = 4 elif n >= 1400 and n <= 1599: kyu = 3 elif n >= 1600 and n <= 1799: kyu = 2 elif n >= 1800 and n <= 1999: kyu = 1 print(kyu)
n, q = map(int, input().split(' ')) L = [] i = 0 while i < n: name, time = map(str, input().split(' ')) L.append([name, int(time)]) i += 1 t = 0 fin = [] while len(L) != 0: if L[0][1] > q: t += q name = L[0][0] time = L[0][1] - q L.append([name, time]) L.pop(0) else: t += L[0][1] name = L[0][0] time = t fin.append([name, time]) L.pop(0) ans = '' for f in fin: ans += f[0] + ' ' + str(f[1]) + '\n' print(ans[:-1])
0
null
3,388,757,846,280
100
19
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()
if __name__ == "__main__": S = input() count_right = 0 count_left = 0 prev = "" a = [] current = 0 for i, s in enumerate(S): if prev == ">" and s == "<": a.append((count_left, count_right)) count_left = 0 count_right = 0 if s == ">": count_right += 1 prev = ">" # a.append((count_left) else: count_left += 1 prev = "<" a.append((count_left, count_right)) s = 0 for x in a: large = max(x[0], x[1]) small = min(x[0], x[1]) s += sum(range(large + 1)) + sum(range(small)) print(s)
0
null
83,310,405,183,668
117
285
import itertools import math def calc_dist(pos1, pos2): x1,y1=pos1 x2,y2=pos2 return math.sqrt(pow(x1-x2, 2)+pow(y1-y2, 2)) N=int(input()) distance_mat = [[-1000 for _ in range(N)] for _ in range(N)] pos = [] for _ in range(N): pos.append(list(map(int, input().split()))) perms = itertools.permutations(list(range(N)), N) result=[] for perm in perms: dist_sum = 0 for i in range(1, N): source = perm[i-1] sink = perm[i] if distance_mat[source][sink]==-1000: dist = calc_dist(pos[source], pos[sink]) distance_mat[source][sink] = dist distance_mat[sink][source] = dist else: dist = distance_mat[source][sink] dist_sum+=dist result.append(dist_sum) import numpy as np print(np.average(result))
def main(): from itertools import permutations from math import hypot N = int(input()) xys = [] for _ in range(N): x, y = map(int, input().split()) xys.append((x, y)) ans = 0 for perm in permutations(xys, r=2): x1, y1 = perm[0] x2, y2 = perm[1] d = hypot(x2 - x1, y2 - y1) ans += d ans /= N print(ans) if __name__ == '__main__': main()
1
148,583,985,417,154
null
280
280
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)
import math #import numpy as np import queue from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) def main(): n,m = map(int,ipt().split()) a = [int(i) for i in ipt().split()] a.sort() maa = max(a) pn = [0]*(2*maa+1) pn[0] = n pa = 0 for i in a: for j in range(pa+1,i+1): pn[j] = pn[pa] pn[i+1] = pn[pa]-1 pa = i+1 l = 0 r = 2*maa while l < r: mid = l+(r-l+1)//2 nm = 0 for i in a: if mid <= i: nm += n else: nm += pn[mid-i] if nm >= m: l = mid else: r = mid-1 pt = [0]*(2*maa+1) pp = maa+1 for i in a[::-1]: for j in range(pp-1,i,-1): pt[j] = pt[pp] pt[i] = pt[pp]+i pp = i for j in range(pp-1,-1,-1): pt[j] = pt[pp] ans = 0 sm = 0 for i in a: sm += pn[max(0,l-i)] ans += pt[max(0,l-i)]+pn[max(0,l-i)]*i print(ans-l*(sm-m)) return if __name__ == '__main__': main()
0
null
54,265,828,404,840
13
252
n, k = map(int, input().split()) h = sorted(list(map(int, input().split()))) if k==0: print(sum(h)) else: print(sum(h[:-k]))
x, y = map(int,input().split()) if (y%2 == 1): print("No") else: if (y < x*2): print("No") elif (y > x*4): print("No") else: print("Yes")
0
null
46,531,122,000,858
227
127
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): n = int(input()) A = list(map(int, input().split())) ans = 1 mod = 10 ** 9 + 7 for i in range(n): A[i] += 1 cnt = [0] * (n + 1) # cnt[i]は、Aのなかでこれまでに何個iが登場したか。つまりiの候補数。 cnt[0] = 3 for j in range(n): i = A[j] ans *= cnt[i - 1] cnt[i - 1] -= 1 cnt[i] += 1 if cnt[i] > 3: ans = 0 if cnt[i - 1] < 0: ans = 0 print(ans % mod) resolve()
from collections import Counter s = input() n = len(s) dp = [0] mod = 2019 a = 0 for i in range(n): a = a + int(s[n-i-1]) * pow(10, i, mod) a %= mod dp.append(a%mod) ans = 0 c = Counter(dp) for value in c.values(): ans += value * (value-1) / 2 print(int(ans))
0
null
80,687,805,203,350
268
166
num = [] while True: l = map(int, raw_input().split()) if l[0] == l[1] == l[2] == -1: break if l[0]*l[1] < 0: num.append("F") else: sum = l[0] + l[1] if sum >= 80: num.append("A") elif sum >= 65: num.append("B") elif sum >= 50: num.append("C") elif sum >= 30: if l[2] >= 50: num.append("C") else: num.append("D") else: num.append("F") for i in range(len(num)): print num[i]
while True: m,f,r=list(map(int,input().split())) if m==f==r==-1: break s=m+f print('F' if m*f<0 or s<30 else 'D' if 30<=s<50 and r<50 else 'C' if 50<=s<65 or 30<=s<50 and 50<=r else 'B' if 65<=s<80 else 'A')
1
1,197,092,226,770
null
57
57
numbers = input() numbers = numbers.split(" ") W = int(numbers[0]) H = int(numbers[1]) x = int(numbers[2]) y = int(numbers[3]) r = int(numbers[4]) if (r <= x <= W - r) and (r <= y <= H - r): print("Yes") else: print("No")
x = int(input()) print('Yes') if x >= 30 else print('No')
0
null
3,075,999,083,520
41
95
def main(): alphabets_table = [0 for i in range(26)] while True: try: input_string = input() lower_string = input_string.lower() for i, _letter in enumerate("abcdefghijklmnopqrstuvwxyz"): alphabets_table[i] += lower_string.count(_letter) except EOFError: break for i, _letter in enumerate("abcdefghijklmnopqrstuvwxyz"): print('%s : %s' % (_letter, alphabets_table[i])) main()
n = int(input()) al = list(map(int, input().split())) al.sort(reverse=True) ans = al[0] for i in range(n-2): ans += al[i//2+1] print(ans)
0
null
5,404,085,297,708
63
111
""" 入力例 1 11 3 2 ooxxxoxxxoo ->6 入力例 2 5 2 3 ooxoo ->1 ->5 入力例 3 5 1 0 ooooo -> 入力例 4 16 4 3 ooxxoxoxxxoxoxxo ->11 ->16 """ n,k,c = map(int,input().split()) s = input() r=[0]*n l=[0]*n ki=0 ci=100000 for i in range(n): ci += 1 if s[i]=='x': continue if ci > c: ci = 0 ki+=1 l[i]=ki if ki == k: break ki=k ci=100000 for i in range(n): ci += 1 if s[n-1-i]=='x': continue if ci > c: ci = 0 r[n-1-i]=ki ki-=1 if ki == 0: break ret=[] for i in range(n): if r[i]==l[i] and r[i]!=0: ret.append(i+1) # print(l) # print(r) for i in range(len(ret)): print(ret[i])
import sys # import re import math import collections # import decimal import bisect import itertools import fractions # import functools import copy import heapq import decimal # import statistics import queue # import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): s = input() cnt = [0 for _ in range(2019)] cnt[0] += 1 dec = 1 num = 0 for i in reversed(s): num += int(i) * dec num %= 2019 dec *= 10 dec %= 2019 cnt[num] += 1 ans = 0 for c in cnt: ans += c * (c - 1) // 2 print(ans) if __name__ == '__main__': main()
0
null
35,510,219,647,110
182
166
a,b,c=sorted(map(int,input().split())) print(a,b,c)
import math X = int(input()) i = 1 while True: net = (i * X)/360 if math.floor(net) == math.ceil(net): break else: i+=1 print(i)
0
null
6,787,179,528,240
40
125
n=int(input()) cards = [[s+" "+str(n) for n in range(1,14)] for s in ["S","H","C","D"]] for _ in range(n): suit,num =input().split() if suit=="S": cards[0][int(num)-1]=0 elif suit=="H": cards[1][int(num)-1]=0 elif suit=="C": cards[2][int(num)-1]=0 elif suit=="D": cards[3][int(num)-1]=0 for s in cards: for n in s: if n!=0: print(n)
import math def resolve(): import sys input = sys.stdin.readline row1 = [int(x) for x in input().rstrip().split(" ")] h = row1[0] w = row1[1] if h == 1 or w == 1: print(1) return ans = (h-(h%2))*(w-(w%2))/2 ans += (h%2)*(w-(w%2))/2 ans += (w%2)*(h-(h%2))/2 ans += (w%2)*(h%2) print(int(ans)) if __name__ == "__main__": resolve()
0
null
26,124,971,445,540
54
196
def selection_sort(A, N): cnt = 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] cnt += 1 return A, cnt N = int(input().rstrip()) A = list(map(int, input().rstrip().split())) A, cnt = selection_sort(A, N) string = list(map(str, A)) print(' '.join(string)) print(cnt)
def selectionSort(lst, n): cnt = 0 for i in range(0, n): minj = i for j in range(i, n): if lst[j] < lst[minj]: minj = j if i != minj: tmp = lst[i] lst[i] = lst[minj] lst[minj] = tmp cnt += 1 return (lst, cnt) if __name__ == "__main__": n = int(input()) lst = [int(n) for n in input().split()] result, cnt = selectionSort(lst, n) print(" ".join(str(n) for n in result)) print(cnt)
1
20,059,288,570
null
15
15
# -*- coding: utf-8 -*- pi = 3.141592653589793 r = float( input() ) area = r * r * pi circle = 2 * r * pi print(format(area, '.10f'), format(circle, '.10f'))
from sys import stdin from math import pi r = float(stdin.readline().rstrip()) area = pi*r*r circumference = 2*pi*r print("%lf %lf" % (area, circumference))
1
639,325,996,700
null
46
46
import math from functools import reduce def gcd_list(numbers): return reduce(math.gcd, numbers) N=int(input()) A=list(map(int,input().split())) mA = max(A) D = [-1]*(mA+1) D[0]=1 D[1]=1 for i in range(2,mA+1): if D[i] != -1: continue D[i] = i cnt = 2*i while cnt < mA+1: if D[cnt] == -1: D[cnt]=i cnt += i done = set() for a in A: tmp = set() while a > 1: tmp.add(D[a]) a //= D[a] if len(done&tmp) > 0: if gcd_list(A) == 1: print('setwise coprime') else: print('not coprime') exit() done |= tmp print('pairwise coprime')
from math import gcd n=int(input()) a=list(map(int,input().split())) g=gcd(a[0],a[1]) for i in range(n-2): g=gcd(g,a[i+2]) if a==[1]*n: print("pairwise coprime") exit() if g!=1: print("not coprime") exit() temp=[i for i in range(10**6+5)] p=2 while p*p<=10**6+5: if temp[p]==p: for q in range(2*p,10**6+5,p): if temp[q]==q: temp[q]=p p+=1 ans=[0]*(10**6+10) for j in a: count=set() while j>1: count.add(temp[j]) j//=temp[j] for k in count: ans[k]+=1 if max(ans)!=1: print("setwise coprime") else: print("pairwise coprime")
1
4,086,203,267,690
null
85
85
values=input().split() x1=float(values[0]) y1=float(values[1]) x2=float(values[2]) y2=float(values[3]) x_distance=x2-x1 y_distance=y2-y1 print(pow(pow(x_distance,2)+pow(y_distance,2),0.5))
#ITP1_10-A Distance x1,y1,x2,y2 = input().split(" ") x1=float(x1) y1=float(y1) x2=float(x2) y2=float(y2) print ( ((x1-x2)**2.0 + (y1-y2)**2.0 )**0.5)
1
153,098,395,648
null
29
29
k = int(input()) a, b = map(int, input().split()) f = False for i in range(a, b+1): if i%k == 0: print('OK') f = True break if f is False: print('NG')
while True: m = map(int,raw_input().split()) if m[0] == 0 and m[1] == 0: break if m[0] >= m[1]: print m[1],m[0] else: print m[0],m[1]
0
null
13,591,759,592,822
158
43
s = input() n = len(s) cnt = 0 t =s[::-1] for i in range(n//2): if s[i]!=t[i]: cnt += 1 print(cnt)
a=input() l=len(a) z=0 for i in range(l): if a[i]!=a[l-1-i]: z+=1 z//=2 print(z)
1
120,325,594,926,976
null
261
261
s,t=input().split() S,T=map(int,input().split()) dis=input() if s==dis: print(S-1,T) else: print(S,T-1)
s, t = input().split() a, b = map(int, input().split()) u = input() if s == u: a -= 1 else: b -= 1 print('{} {}'.format(a, b))
1
71,926,408,519,040
null
220
220
n = int(input()) ansl = [] def dfs(s, max_s): if len(s) == n: ansl.append(s) return ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' for i in range(max_s+1): dfs(s+ascii_lowercase[i], max(i+1, max_s)) dfs("", 0) for a in ansl: print(a)
#設定 import sys input = sys.stdin.buffer.readline #ライブラリインポート from collections import defaultdict con = 10 ** 9 + 7 #入力受け取り def getlist(): return list(map(int, input().split())) #処理内容 def main(): N = int(input()) ansL = [[] for i in range(10)] ansL[0].append(["a", 1]) for i in range(N - 1): n = len(ansL[i]) for j in range(n): for k in range(ansL[i][j][1]): ansL[i + 1].append([ansL[i][j][0] + chr(97 + k), ansL[i][j][1]]) ansL[i + 1].append([ansL[i][j][0] + chr(97 + ansL[i][j][1]), ansL[i][j][1] + 1]) n = len(ansL[N - 1]) for i in range(n): print(ansL[N - 1][i][0]) if __name__ == '__main__': main()
1
52,034,442,629,822
null
198
198
def resolve(): s = input() print(s[:3]) if 'unittest' not in globals(): resolve()
def main(): L, R, d = map(int, input().split(' ')) total = 0 for i in range(L, R + 1): if i % d == 0: total += 1 print(total) main()
0
null
11,198,610,995,558
130
104
n = int(input()) d = {} for i in range(n): cmd = input() if cmd[0] == 'i': d[cmd[7:]] = 0 else: print('yes' if cmd[5:] in d else 'no')
N = int(input()) ans = 0 def tot(x, i): base = x//i n = base*(base+1)//2 return i*n for i in range(1, N+1): ans += tot(N, i) print(ans)
0
null
5,624,458,195,652
23
118
L = int(input()) x = L/3 y = L/3 z = L/3 V = x * y * z print(V)
line = int(input()) nums = [[[0 for x in range(0, 10)] for x in range(0, 3)] for x in range(0, 4)] input1 = [] for i in range(line): input1.append(input()) for e in input1: efbv = e.split(" ") e_b, e_f, e_r, e_v = map(int, efbv) nums[e_b - 1][e_f - 1][e_r -1] += e_v for b in range(4): for f in range (3): print(" " + " ".join(map(str, nums[b][f]))) if b != 3: print("#" * 20)
0
null
24,128,385,581,300
191
55
X=int(input()) for a in range(10**4): for b in range(10**4): if a**5-b**5==X:print(a,b);exit() elif a**5+b**5==X:print(a,-b);exit()
if __name__ == '__main__': n = int(input()) s = set(input().split()) if len(s) == n: print("YES") else: print("NO")
0
null
49,655,601,163,458
156
222
import sys, math input = sys.stdin.readline H, N = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(N)] max_a = max([a for a, b in ab]) dp = [math.inf] * (H+max_a+1) dp[0] = 0 for i in range(H + 1): for a, b in ab: dp[i + a] = min(dp[i + a], dp[i] + b) print(min(dp[H:]))
from copy import copy import random 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 i in range(40000): na = copy(ans) x = random.randint(1,365) y = random.randint(1,365) if x == y: continue na[x-1],na[y-1] = na[y-1],na[x-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 ns > score: ans = na score = ns for a in ans: print(a)
0
null
45,236,495,156,590
229
113
X=int(input()) i=1 while True: if (X*i)%360==0: print(i) exit() i+=1
# -*- coding: utf-8 -*- x=int(input()) a=360 b=x r=a%b while r!=0: a=b b=r r=a%b lcm=x*360/b k=int(lcm/x) print(k)
1
13,203,673,648,502
null
125
125
S = input().replace("><", "> <").split() ans = 0 for s in S: up = s.count("<") down = len(s) - up if up < down: up -= 1 ans += up * (up+1) // 2 + down * (down+1) // 2 else: down -= 1 ans += up * (up+1) // 2 + down * (down+1) // 2 print(ans)
N,K=int(input()),int(input()) def f(n,k): if k<1: return 1 if n<10: if k<2: return n return 0 d,m=n//10,n%10 return f(d,k-1)*m+f(d-1,k-1)*(9-m)+f(d,k) print(f(N,K))
0
null
116,512,223,085,348
285
224
import sys def LI(): return list(map(int, input().split())) N, K, S = LI() if K == 0: if S == 10**9: for i in range(N): print(1, end=" ") else: for i in range(N): print(10**9, end=" ") sys.exit() for i in range(K): print(S, end=" ") if S == 10**9: for i in range(N-K): print(S-1, end=" ") else: for i in range(N-K): print(S+1, end=" ")
N, K, S = map(int, input().split()) ans = [] n = N-K for i in range(K): ans.append(S) for i in range(n): if S == 10**9: ans.append(S-1) else: ans.append(S+1) ans=[str(a) for a in ans] ans=" ".join(ans) print(ans)
1
90,800,157,830,260
null
238
238
import math n=int(input()) a=list(map(int,input().split())) soin = [0]*(10**6+1) if a.count(1)==n: print("pairwise coprime") exit() def factorization(n): arr = [] temp = n for i in range(2, int(-(-n ** 0.5 // 1)) + 1): if temp % i == 0: while temp % i == 0: temp //= i arr.append(i) if temp != 1: arr.append(temp) if arr == []: arr.append(n) return arr if len(a)>80000: ans=a[0] for i in a: ans=math.gcd(ans,i) if ans==1: print("setwise coprime") else: print("not coprime") else: for i in a: if i ==1:continue for num in factorization(i): soin[num]+=1 if max(soin)==1: print("pairwise coprime") elif max(soin)==n and 1 not in a: print("not coprime") else:print("setwise coprime")
from math import gcd N = int(input()) num_lis = list(map(int, input().split())) c1 = True #setwise c2 = True #pairwise 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: c1 = False if c1: 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: c2 = False break else: tmp.add(j) else: continue break else: c2 = False if c2: print("pairwise coprime") elif c1: print("setwise coprime") else: print("not coprime")
1
4,117,752,112,320
null
85
85
n,m, x = map(int,input().split()) text=[] buy=10**10 for i in range(n): text.append(list(map(int,input().split()))) for i in range(2**n): bag=[0]*(m+1) for j in range(n):#いれる過程 if ((i>>j)&1):#j冊目のフラグがあれば for k in range(m+1): bag[k]+= text[j][k]#bagにいれる if min(bag[1:])>=x and bag[0]<buy: buy=bag[0] if buy==10**10: buy=-1 print(buy)
N, M, X = map(int, input().split()) I = [list(map(int, input().split())) for i in range(N)] C = [0] * N A = [[0] * M] * N for i in range(N): C[i] = I[i][0] A[i] = I[i][1:] ans = -1 anslist = [] for i in range(2**N): flag = 0 c = 0 total = [0] * M for j in range(N): if ((i >> j) & 1): c += C[j] for k in range(M): total[k] += A[j][k] for k in range(M): if total[k] < X: flag = 1 break if flag == 1: continue anslist.append(c) if len(anslist) != 0: anslist.sort() ans = anslist[0] print(ans)
1
22,330,363,629,932
null
149
149
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()
F = [0 for i in range(50)] F[0] = 1 F[1] = 1 def fib(n) : if n == 0 or n == 1: F[n] = 1 return F[n] else: if F[n] == 0: F[n] = fib(n-1) + fib(n-2) return F[n] else: return F[n] n = int(input()) print(fib(n))
1
1,891,329,440
null
7
7
import math a,b,x=map(int,input().split()) v = a * b x = x / a if x < v/2: c = x * 2 / b d = math.sqrt(b * b + c * c) print(math.degrees(math.asin(b/d))) else: rest = v - x c = rest * 2 / a d = math.sqrt(a * a + c * c) print(math.degrees(math.acos(a/d)))
#--------------------------------------------------------------- # coding: utf-8 # Python 3+ import sys #file = open("test.txt") file = sys.stdin a, b, c = map(int, file.readline().split()) if a < b < c : print("Yes") else : print("No")
0
null
81,896,991,567,104
289
39
n,k,*a=map(int, open(0).read().split()) b=[0] for t in a:b+=(t-1+b[-1])%k, d={k:0} a=0 for l,r in zip([k]*min(k,n+1)+b,b):d[l]-=1;t=d.get(r,0);a+=t;d[r]=t+1 print(a)
import sys, os import collections MOD = 10 ** 9 + 7 def solve(input_stream): N, K = read_ints(input_stream) numbers = [int(i) - 1 for i in input_stream.readline().strip().split()] cumulative_sum = [0 for i in range(N + 1)] mods = {} ans = 0 for index, number in enumerate(numbers): cumulative_sum[index + 1] = (cumulative_sum[index] + number) % K queue = [] for index in range(N+1): if cumulative_sum[index] not in mods: mods[cumulative_sum[index]] = 0 ans += mods[cumulative_sum[index]] mods[cumulative_sum[index]] += 1 queue.append(cumulative_sum[index]) if len(queue) == K: target = queue.pop(0) mods[target] -= 1 return [str(ans)] def read_ints(input_stream): return [i for i in map(int, input_stream.readline().strip().split())] def read_int(input_stream): return int(input_stream.readline().strip()) if __name__ == "__main__": outputs = solve(sys.stdin) for line in outputs: print(line)
1
137,806,703,632,776
null
273
273
import sys input = sys.stdin.readline n,m=map(int,input().split()) d={i+1:[] for i in range(n)} for i in range(m): x,y=map(int,input().split()) d[x].append(y) d[y].append(x) visit=set() ans= 0 for i in range(1,n+1): if i not in visit: ans+=1 stack = [i] while stack: c=stack.pop() visit.add(c) for i in d[c]: if i not in visit: stack.append(i) print(ans-1)
N=int(input()) s=0 for i in range(1,N+1): s+=int(N/i) if N%i==0: s-=1 print(s)
0
null
2,406,273,301,968
70
73
class Dice(): def __init__(self, spots): self.spots = [spots[i] for i in range(6)] def roll(self, direction): if direction == 0: self.spots = [self.spots[i] for i in [1, 5, 2, 3, 0, 4]] elif direction == 1: self.spots = [self.spots[i] for i in [3, 1, 0, 5, 4, 2]] elif direction == 2: self.spots = [self.spots[i] for i in [4, 0, 2, 3, 5, 1]] elif direction == 3: self.spots = [self.spots[i] for i in [2, 1, 5, 0, 4, 3]] spots = list(map(int, input().split())) moves = input() my_dice = Dice(spots=spots) for move in moves: if move == 'N': my_dice.roll(0) elif move == 'E': my_dice.roll(1) elif move == 'S': my_dice.roll(2) elif move == 'W': my_dice.roll(3) print(my_dice.spots[0])
s, t = [input() for i in range(2)] c = [] for i in range(len(s) - len(t) + 1): d = len(t) for a, b in zip(s[i:], t): if a == b: d -= 1 c.append(d) print(min(c))
0
null
1,938,876,313,688
33
82
n, k = map(int,input().split()) lst = list(map(int,input().split())) ans = 0 for i in range(n): if (lst[i] >= k): ans = ans + 1 print(ans)
from collections import deque n = int(input()) u = [[] for i in range(n+1)] #隣接リスト for i in range(n): v = list(map(int, input().split())) u[v[0]] = v[1:] #v = [次数, 頂点...] d = [-1] * (n+1) visited = [False] * (n+1) d[1] = 0 visited[1] = True que = deque([1]) while len(que) > 0: c = que.popleft() for i in range(1, u[c][0]+1): if not visited[u[c][i]]: que.append(u[c][i]) visited[u[c][i]] = True d[u[c][i]] = d[c] + 1 for i in range(1, n+1): print(i, d[i])
0
null
89,376,476,570,220
298
9
N = int(input()) A = list(map(int, input().split())) a = [0] for i in range(N): a.append(a[i] + A[i]) cnt = 0 for i in range(N-1): cnt += A[i] * (a[N] - a[i+1]) mod = 10 ** 9 + 7 ans = cnt % mod print(ans)
N = int(input()) *A, = map(int, input().split()) mod = 10**9 + 7 ans = 1 cnt = [0, 0, 0] for a in A: if a not in cnt: ans = 0 break ans = ans * cnt.count(a) % mod cnt[cnt.index(a)] += 1 print(ans)
0
null
66,777,313,470,840
83
268
A,B,C = map(int,input().split()) if A+B+C <= 21: print("win") else: print("bust")
a,b,c = map(int,input().split()) if a + b + c >= 22: print('bust') if a + b + c <= 21: print('win')
1
119,076,589,543,872
null
260
260
A,B= map(int,input().split()) res = A*B print(res)
def main(): _, *S = open(0) print(len(set(S))) if __name__ == "__main__": main()
0
null
22,954,847,671,040
133
165
num = [] while True: l = map(int, raw_input().split()) if l[0] == l[1] == l[2] == -1: break if l[0]*l[1] < 0: num.append("F") else: sum = l[0] + l[1] if sum >= 80: num.append("A") elif sum >= 65: num.append("B") elif sum >= 50: num.append("C") elif sum >= 30: if l[2] >= 50: num.append("C") else: num.append("D") else: num.append("F") for i in range(len(num)): print num[i]
st = list() while True: a = list(map(lambda x: int(x),input().split(" "))) if min(a[0:2]) == -1: if max(a) == -1: break else: st += {"F"} else: if 80 <= sum(a[0:2]): st += {"A"} elif 65 <= sum(a[0:2]): st += {"B"} elif 50 <= sum(a[0:2]): st += {"C"} elif 30 <= sum(a[0:2]): if 50 <= a[2]: st += {"C"} else: st += {"D"} else: st += {"F"} for s in st: print(s)
1
1,220,884,596,360
null
57
57
X,Y=map(int,input().split()) mod=10**9+7 if (X+Y)%3!=0: print(0);exit() if X*2<Y or Y*2<X: print(0);exit() t=(X+Y)//3 f=[1] for i in range(1,t+100): f.append(f[-1]*i%mod) def comb(a,b,m): return f[a]*pow(f[b],m-2,m)*pow(f[a-b],m-2,m)%m print(comb(t,X-t,mod))
# 163 B N,M = list(map(int, input().split())) A = list(map(int, input().split())) print(N-sum(A)) if sum(A) <= N else print(-1)
0
null
90,757,965,943,492
281
168
from itertools import accumulate import bisect n,m,k = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) a_acc = [0] + list(accumulate(a)) b_acc = list(accumulate(b)) #print(a_acc) #print(b_acc) ans = 0 for an in range(n + 1): rem = k - a_acc[an] if rem < 0: break bn = bisect.bisect_right(b_acc, rem) #print(bn) ans = max(ans, an + bn) print(ans)
n = int(input()) a, b = input().split() s = "" for i, j in zip(a, b): s += i + j print(s)
0
null
61,341,771,348,628
117
255
n=int(input()) f = False match=0 for i in range(n): a,b=map(int,input().split()) if a==b: match+=1 f |= (match == 3) else: match=0 if f: print("Yes") else: print("No")
n = int(input()) cnt = 0 judge = False for i in range(n): a,b = map(int,input().split()) if a == b: cnt += 1 else: cnt = 0 if cnt == 3: judge = True if judge: print("Yes") else: print("No")
1
2,477,397,138,928
null
72
72
a, b, c, k = map(int, input().split()) ans = 0 if a >= k: print(k) exit() ans += a k -= a if b >= k: print(ans) exit() k -= b ans -= k print(ans)
A,B,C,K = map(int,input().split()) SCO = 0 if A>K: SCO+=K else: SCO+=A if B<=(K-A): if C<=(K-A-B): SCO-=C else: SCO-=K-A-B print(SCO)
1
21,911,722,942,660
null
148
148
N = int(input()) arr = sorted(list(map(int, input().split())),reverse=True) arr2 = [arr[0]] for i in range(1,N,1): arr2.append(arr[i]) arr2.append(arr[i]) ans = 0 for i in range(N-1): ans += arr2[i] print(ans)
def main(): n = int(input()) A = list(map(int,input().split())) A.sort(reverse=True) k = n//2 if n%2==0: print(A[0]+2*sum(A[1:k])) else: print(A[0]+2*sum(A[1:k])+A[k]) main()
1
9,186,952,190,022
null
111
111
# -*- coding: utf-8 -*- n = int(raw_input()) num = map(int, raw_input().split()) for e in num[::-1]: if e == num[0]: print e break print e,
x = [int(x) for x in input().split()] if (sum(x)>21): print('bust') else: print('win')
0
null
59,746,966,535,718
53
260
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(input()) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=' '): print(k.join(list(map(str, lst)))) INF = float('inf') # from math import ceil, floor, log2 # from collections import deque, defaultdict # from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush # import numpy as np # cumsum # from bisect import bisect_left, bisect_right def solve(): N, K = MI() S = [] mod = 998244353 for i in range(K): l, r = MI() S.append((l, r)) dp = [0] * (N+1) dp[1] = 1 C = [0] * (N+1) C[1] = 1 for i in range(2, N+1): for s in S: l = max(1, i - s[1]) r = i - s[0] if r < 1: continue dp[i] += (C[r] - C[l-1]) % mod C[i] += (dp[i] + C[i-1]) % mod print(dp[N] % mod) if __name__ == '__main__': solve()
n = int(input()) ans = "" for i in range(1,n+1): if (i % 3 == 0 or '3' in str(i)) : ans += " " + str(i) print(ans)
0
null
1,812,681,459,918
74
52
## coding: UTF-8 N, P = map(int,input().split()) S = input()[::-1] remainder = [0] * P tmp = 0 rad = 1 #10**(i) % P ''' if(P == 2 or P == 5): for i in range(N): r = int(S[i]) tmp += r * rad tmp %= P remainder[tmp] += 1 rad *= 10 ''' if(P == 2): ans = 0 for i in range(N): r = int(S[i]) if(r % 2 == 0): ans += N-i print(ans) elif(P == 5): ans = 0 for i in range(N): r = int(S[i]) if(r % 5 == 0): ans += N-i print(ans) else: for i in range(N): r = int(S[i]) tmp += r * rad tmp %= P remainder[tmp] += 1 rad *= 10 rad %= P remainder[0] += 1 #print(remainder) ans = 0 for i in range(P): e = remainder[i] ans += e*(e-1)/2 print(int(ans))
a = [int(c) for c in input().split()] r = a[0]*a[1] if a[0] == 1 or a[1] == 1: print(1) elif r % 2 == 0: print(int(r/2)) else: print(int(r/2+1))
0
null
54,414,111,921,960
205
196
from math import ceil debt=100000 bigets=1000 interest_rate=1.05 def calc_debt(n): d=debt//bigets while n>0: d=ceil(d*interest_rate) n -= 1 return d*bigets n=int(input()) print(calc_debt(n))
i = int(input()) x = 100000 for _ in range(i): x *= 1.05 x = int((x+999) / 1000) * 1000 print(x)
1
1,178,203,476
null
6
6
import copy n = int(input()) l = list(input().split()) C1 = [] for v in l: s = v[0] m = int(v[1]) C1.append((s, m)) C2 = copy.deepcopy(C1) for i in range(n): for j in range(n-1, i, -1): if C1[j][1] < C1[j-1][1]: C1[j], C1[j-1] = C1[j-1], C1[j] for i in range(n): minj = i for j in range(i,n): if C2[j][1] < C2[minj][1]: minj = j C2[i], C2[minj] = C2[minj], C2[i] result1 = [t[0]+str(t[1]) for t in C1] result2 = [t[0]+str(t[1]) for t in C2] print(" ".join(result1)) print("Stable") print(" ".join(result2)) if result1 == result2: print("Stable") else: print("Not stable")
K = list(map(int,input().split())) m = K[0]*500 if m >= K[1]: print('Yes') else: print('No')
0
null
49,079,883,900,462
16
244
a,b,k = map(int, input().split()) m = k if a > k else a a -= m b -= min(k-m, b) print(f'{a} {b}')
# abc149_b A, B, K = map(int, input().split(" ")) if A>=K: print(A-K, B) elif B>=K-A: print(0, B+A-K) else: print(0, 0)
1
103,986,529,640,138
null
249
249
N = int(input()) A = sorted(map(int, input().split())) X = 0 Y = 0 B = [] for i in range(N-2): X = i + 1 for j in range(X,N-1): Y = j + 1 for k in range(Y, N): if A[k] < A[i] + A[j]: if A[k] != A[i] and A[i] != A[j] and A[k] != A[j]: B.append((A[i],A[j],A[k])) print(len(B))
from itertools import combinations N = int(input()) L = list(map(int, input().split())) count = 0 for C in combinations(L, 3): l_list = list(C) l_list.sort() if l_list[2] > l_list[1] and l_list[1] > l_list[0]: if l_list[2] < l_list[1] + l_list[0]: count += 1 print(count)
1
5,050,472,725,610
null
91
91
N = int(input()) pi = 360 while True: if pi % N == 0: print(pi//N) exit() else: pi+=360
x,y=map(int,input().split()) print(('No','Yes')[2*x<=y<=4*x and -~y%2])
0
null
13,524,449,110,652
125
127
h,w = map(int,input().split()) s = [list(str(input())) for i in range(h)] dp = [[10 ** 10] * w for i in range(h)] if s[0][0] == "#":dp[0][0] = 1 else:dp[0][0] = 0 for i in range(w): for j in range(h): if s[j][i] == "#": s[j][i] = 1 else: s[j][i] = 0 for i in range(1,h+w-1): for j in range(i+1): if 0 < j < h and 0 <= i-j < w: dp[j][i-j] = min(dp[j-1][i-j]+(s[j][i-j]&~s[j-1][i-j]),dp[j][i-j]) if 0 < i-j < w and 0 <= j < h: dp[j][i-j] = min(dp[j][i-j-1]+(s[j][i-j]&~s[j][i-j-1]),dp[j][i-j]) print(dp[h-1][w-1])
a,b,c = map(int,input().split(" ")) right = c- a- b if right > 0 and right ** 2 > 4 * a* b: print("Yes") else: print("No")
0
null
50,515,169,140,400
194
197
N = int(input()) r = (N +2-1)//2 print(r)
n=int(input()) print(int(n/2)+int(n%2))
1
59,070,334,309,220
null
206
206
# input n, q = map(int, raw_input().split()) procs = [raw_input().split() for i in xrange(n)] procs = list(reversed(procs)) # procsessing cnt, lack = 0, 1 while lack > 0: lack = 0 tprocs = [] for i in xrange(n): proc = procs.pop() t = int(proc[1]) if t <= q: cnt += t print proc[0], cnt n -= 1 else: # t > q cnt += q t = t - q lack += t proc[1] = str(t) tprocs.append(proc) procs = list(reversed(tprocs))
n, q = [int(i) for i in input().split()] process = [] for i in range(n): name, time = input().split() process.append([name, int(time)]) count = 0 while True: if len(process) == 0: break if process[0][1] <= q: count += process[0][1] print(process[0][0], count) process[0][1] = process[0][1] - q process.pop(0) else: count += q process[0][1] = process[0][1] - q process.append(process.pop(0))
1
43,529,044,438
null
19
19
N = int(input()) L = list(map(int,input().split())) ans = [0 for i in range(N)] for i in range(len(L)): ans[L[i]-1] += 1 for i in range(N): print(ans[i])
def gcd(a, b): while True: a, b = b, a%b if b == 0: return a def lcm(a, b): return int((a*b) // gcd(a, b)) a, b = map(int, input().split()) print(lcm(a, b))
0
null
72,693,803,270,528
169
256
x,y=map(int,input().split()) def nCr(n,r,mod=10**9+7): r=min(r,n-r) a=b=1 for i in range(1,r+1): a=a*n%mod b=b*i%mod n-=1 return a*pow(b,mod-2,mod)%mod z=x+y if z%3!=0 or x-(z//3)<0 or y-(z//3)<0: print(0) else: z//=3 # print(z) # print(min(x,y)-z) print(nCr(z,min(x,y)-z))
import sys from collections import deque, defaultdict, Counter from itertools import accumulate, product, permutations, combinations from operator import itemgetter from bisect import bisect_left, bisect_right from heapq import heappop, heappush from math import ceil, floor, sqrt, gcd, inf from copy import deepcopy import numpy as np import scipy as sp INF = inf MOD = 1000000007 k = int(input()) s = input() tmp = 0 res = 0 if len(s) <= k: res = s else: res = s[:k] + "..." print(res)
0
null
85,011,163,951,868
281
143
input_list = [int(num) for num in input().split()] D = input_list[0] T = input_list[1] S = input_list[2] if D/S <= T: print("Yes") else: print("No")
s = input().split() d = int(s[0]) t = int(s[1]) s = int(s[2]) if d <= t * s: print("Yes") else: print("No")
1
3,567,416,280,120
null
81
81
from collections import deque N = int(input()) graph = [list(map(int, input().split())) for _ in range(N)] seen = [-1]*(N+1) todo = deque() def bfs(v): u = v-1 next_v = graph[u][2:] for i in next_v: if seen[i] == -1: seen[i] = seen[v] + 1 todo.append(i) todo.append(1) seen[1] = 0 while len(todo) > 0: bfs(todo.popleft()) for i in range(1, N+1): print(i, seen[i])
import sys Stack = [] def push(x): Stack.append(x) def pop(): Stack.pop(-1) def cul(exp): for val in exp: if val in ["+", "-", "*"]: a = int(Stack[-2]) b = int(Stack[-1]) if val == "+": x = a + b elif val == "-": x = a - b elif val == "*": x = a * b for i in range(2): pop() push(x) else: push(val) return Stack[0] if __name__ == "__main__": exp = sys.stdin.read().strip().split(" ") ans = cul(exp) print ans
0
null
18,948,203,580
9
18