code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from functools import reduce, lru_cache import functools import collections, heapq, itertools, bisect import math, fractions import sys, copy def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline().rstrip()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline().rstrip()) 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)] sys.setrecursionlimit(1000000) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 def main(): N = I() A = LI() C0, C1 = [0] * 60, [0] * 60 for d in range(60): for ai in A: C0[d] += (ai >> d & 1) == 0 C1[d] += (ai >> d & 1) == 1 ans = 0 for (d, (a, b)) in enumerate(zip(C0, C1)): ans = (ans + a * b * (1 << d % MOD)) % MOD print(ans % MOD) if __name__ == '__main__': main()
#!/usr/bin/env python3 n, *a = map(int, open(0).read().split()) b = [0] * 60 c = [0] * 60 ans = 0 for i in range(n): for j in range(60): c[j] += i - b[j] if a[i] >> j & 1 else b[j] b[j] += a[i] >> j & 1 for j in range(60): ans += c[j] << j print(ans % (10**9 + 7))
1
122,825,442,652,718
null
263
263
import math a = raw_input() for i, b in enumerate(a.split()): if i==0: W=int(b) elif i==1: H=int(b) elif i==2: x=int(b) elif i==3: y=int(b) else: r=int(b) if r<=x<=W-r and r<=y<=H-r: print 'Yes' else: print 'No'
import sys input = sys.stdin.readline rs = lambda: input().strip() ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) mod = 10**9 + 7 K, X = rl() if K*500 >= X: print('Yes') else: print('No')
0
null
49,342,683,568,530
41
244
a,b = list(map(int, input().split())) c,d = list(map(int, input().split())) if (a != c): print(1) else: print(0)
import bisect import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 M1 , _ = list(map(int, sys.stdin.buffer.readline().split())) M2 , _ = list(map(int, sys.stdin.buffer.readline().split())) print((M2 - M1) % 12)
1
124,697,633,946,818
null
264
264
inArray = str(input()).split(" ") if int(inArray[0]) < int(inArray[-1]): print("a < b") elif int(inArray[0]) > int(inArray[-1]): print("a > b") else: print("a == b")
s = input() s = s.split() n = [] for i in s: n.append(int(i)) a = n[0] b = n[1] print("a",end = " ") if a > b: print(">",end = " ") elif a < b: print("<",end = " ") else: print("==",end = " ") print("b")
1
369,709,480,726
null
38
38
a = int(input()) print(a*((a+1)*(a+1)-a))
a = int(input()) s = a + a**2 + a**3 print(int(s))
1
10,142,324,068,762
null
115
115
S = input() T = input() if T.startswith(S): print('Yes') else: print('No')
S = input() T = input() if(S == T[0:-1] and len(S) + 1 == len(T)): print("Yes") else: print("No")
1
21,402,173,618,010
null
147
147
num = int(input()) 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'] print(l[num - 1])
string = list(input()) times = int(input()) #a = [int(i) for i in range(0,5)] #print(a) for i in range(times): order = input().split() #print(order) if order[0] == "replace": replace_string = order[3] #print(string) count = 0 for j in range(int(order[1]), int(order[2]) + 1): string[j] = replace_string[count] count += 1 #print(count) #print(string) elif order[0] == "reverse": #print(string) reverse_string = string[int(order[1]):int(order[2]) + 1] reverse_string.reverse() #for j in range(int(order[1]), int(order[2]) + 1): # string[j] = reverse_string[j] string = string[:int(order[1])] + reverse_string + string[int(order[2])+1:] #print(j) #print(string) #string[int(order[1]):int(order[2]) + 1].reverse() #print(string) #string[int(order[1]):int(order[2])] = string[int(order[1]):int(order[2])].reverse() elif order[0] == "print": #print(string) print("".join(string[int(order[1]):int(order[2]) + 1])) #print(string)
0
null
25,926,366,957,862
195
68
import sys from functools import lru_cache from collections import defaultdict inf = float('inf') readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def read(): return int(readline()) def reads(): return map(int, readline().split()) a,b,n=reads() x=min(b-1,n) print(int((a*x)/b))
import sys A,B,N = map(int, input().split()) def calc(a,b,x): num = ((a*x)//b)-a*(x//b) return num if B == N: X = N-1 print(calc(A,B,X)) sys.exit() if B < N: X = B-1 print(calc(A,B,X)) sys.exit() if B > N: X = N print(calc(A,B,X)) sys.exit()
1
28,210,071,008,350
null
161
161
input() line = input().split() line.reverse() print(' '.join(line))
input() print(*reversed([int(e) for e in input().split()]))
1
967,707,897,520
null
53
53
import os, sys, re, math (A, B) = [int(n) for n in input().split()] print(max(A - B * 2, 0))
a=list(map(int,input().split())) if a[0]>a[1]*2: print(a[0]-a[1]*2) else: print('0')
1
166,460,531,884,610
null
291
291
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) 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(): n = I() a = LI() acc = 0 for i in a: acc ^= i ans_lst = [] for i in a: ans = acc^i ans_lst.append(ans) print(*ans_lst) main()
import queue n,u,v = map(int, input().split()) u -= 1 v -= 1 path = [[] for i in range(n)] for i in range(n-1): a,b = map(int, input().split()) a -= 1 b -= 1 path[a].append(b) path[b].append(a) t = [10**9]*n t[u]=0 q = queue.Queue() q.put(u) while not q.empty(): p = q.get() for x in path[p]: if t[x]>t[p]+1: q.put(x) t[x]=t[p]+1 a = [10**9]*n a[v]=0 q = queue.Queue() q.put(v) while not q.empty(): p = q.get() for x in path[p]: if a[x]>a[p]+1: q.put(x) a[x]=a[p]+1 c = [a[i] for i in range(n) if a[i]>t[i]] print(max(c)-1)
0
null
64,842,855,973,664
123
259
import sys sys.setrecursionlimit(100000) input = sys.stdin.readline def main(): alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] c = input().strip() print(alphabet[alphabet.index(c) + 1]) main()
import sys input = lambda: sys.stdin.readline().rstrip() def main(): c = input() str = list('abcdefghijklmnopqrstuvwxyz') print(str[str.index(c)+1]) if __name__ == '__main__': main()
1
92,104,797,169,632
null
239
239
s, t = input(), input() print('Yes' if s == t[:-1] else 'No')
S = input() T = input() if(S == T[0:-1] and len(S) + 1 == len(T)): print("Yes") else: print("No")
1
21,319,375,710,192
null
147
147
A,B,C,D = map(int,input().split()) #高橋体力A 高橋攻撃B #青木体力C 青木攻撃D result = "No" turn = "t" while 1: if turn == "t": C -= B turn = "a" if C <= 0: result = "Yes" break elif turn == "a": A -= D turn = "t" if A <= 0: result = "No" break print(result)
from collections import Counter n=int(input()) a=list(map(int,input().split())) dic=Counter(a) for val in dic.values(): if val>=2: print("NO") exit() print("YES")
0
null
51,471,697,077,762
164
222
import math def resolve(): import sys input = sys.stdin.readline # row = [int(x) for x in input().rstrip().split(" ")] # n = int(input().rstrip()) abm = [int(x) for x in input().rstrip().split(" ")] a_list = [int(x) for x in input().rstrip().split(" ")] b_list = [int(x) for x in input().rstrip().split(" ")] # 最小値 ans = min(a_list) + min(b_list) for i in range(abm[2]): xyc = [int(x) for x in input().rstrip().split(" ")] price = a_list[xyc[0] - 1] + b_list[xyc[1] - 1] - xyc[2] if price < ans: ans = price print(ans) if __name__ == "__main__": resolve()
def move_dice(d, dir): if(dir == 'N'): d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4] if(dir == 'S'): d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1] if(dir == 'E'): d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2] if(dir == 'W'): d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3] dice = list(map(int, input().split())) command = input() for c in command: move_dice(dice, c) print(dice[0])
0
null
27,118,078,981,840
200
33
a,b=input().split() a=int(a) b=int(b) if a%b==0: print(int(a/b)) else: print(int((a/b)+1))
H1,M1,H2,M2,K = map(int,input().split()) print((H2-H1)*60+(M2-M1)-K if (M2-M1) >= 0 else (H2-H1)*60+(M2-M1)-K)
0
null
47,735,880,816,700
225
139
n={i:0 for i in range(int(input()))} for i in list(map(int,input().split())): n[i-1]+=1 [print(i) for i in n.values()]
n=int(input()) a=list(input().split()) l = [0 for _ in range(n+1)] for i in a: l[int(i)]+=1 for j in range(1,n+1): print(l[j])
1
32,571,336,139,460
null
169
169
N, K = map(int,input().split()) H = list(map(int,input().split())) s = 0 for i in H: if K <= i: s += 1 print(s)
import sys MAXINT = 1000000001 n = int(input()) S = list(map(int,input().split())) def merge(A, l, m, r, cnt): n1 = m - l n2 = r - m L = [A[i] for i in range(l, l+n1)] R = [A[i] for i in range(m, m+n2)] L.append(MAXINT) R.append(MAXINT) i = 0 j = 0 for k in range(l,r): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 return cnt def mergesort(A, l, r, cnt): if l + 1 < r: m = (l + r) // 2 cnt = mergesort(A, l, m, cnt) cnt = mergesort(A, m, r, cnt) cnt = merge(A,l,m,r, cnt) return cnt cnt = 0 cnt = mergesort(S, 0, n, cnt) print(" ".join(map(str,S))) print(cnt)
0
null
89,903,186,141,638
298
26
a = list(map(int, input().split())) b = list(map(int, input().split())) if a[0] == b[0]: print(0) else: print(1)
#!/usr/bin/env python3 import sys from itertools import chain def solve(N: int, K: int, A: "List[int]"): M = [-1 for _ in range(N)] M[0] = 0 current = 1 n = 1 while n <= K: current = A[current - 1] if M[current - 1] == -1: # 一度も通ったことがない M[current - 1] = n # n ステップ目に通った事を記録 else: loop_len = n - M[current - 1] # ループの長さ rest = K - n # 残り長さ rest = rest % loop_len # 残り長さをループの余剰にする K = n + rest n += 1 return current def main(): tokens = chain(*(line.split() for line in sys.stdin)) # N, K, A = map(int, line.split()) N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" answer = solve(N, K, A) print(answer) if __name__ == "__main__": main()
0
null
73,975,909,129,472
264
150
n, m = map(int, input().split()) mat = [map(int,input().split()) for i in range(n)] vec = [int(input()) for i in range(m)] for row in mat: print(sum([a*b for (a,b) in zip(row, vec)]))
print 6 - int(raw_input()) - int(raw_input())
0
null
55,923,980,797,032
56
254
import functools, operator r,c = tuple(int(n) for n in input().split()) A = [[int(a) for a in input().split()] for i in range(r)] for a in A: a.append(sum(a)) R = [functools.reduce(operator.add, x) for x in zip(*A)] A.append(R) for j in A: print(" ".join(map(str,j)))
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): N, P = map(int, input().split()) S = str(input()) def main(): if P == 2: res = 0 for i in range(N): if int(S[N - 1 - i]) % 2 == 0: res += N - i elif P == 5: res = 0 for i in range(N): if int(S[N - 1 - i]) == 0 or int(S[N - 1 - i]) == 5: res += N - i else: mods = [0] * P # mods[i]はPで割ったあまりがiである連続部分列の個数 tenfactor = 1 mod = 0 mods[mod] += 1 for i in range(N): mod = (mod + int(S[N - i - 1]) * tenfactor) % P tenfactor = (tenfactor * 10) % P mods[mod] += 1 res = 0 for p in range(P): res += mods[p] * (mods[p] - 1) // 2 return res print(main()) resolve()
0
null
29,838,216,356,522
59
205
import sys ## io IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) MIIZ = lambda: list(map(lambda x: x-1, MII())) ## dp INIT_VAL = 0 MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)] MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)] ## math DIVC = lambda x,y: -(-x//y) DIVF = lambda x,y: x//y def main(): n, p = MII() s = list(map(int, IS())) if 10%p == 0: # pが2または5の場合 cnt = 0 for i, si in enumerate(s): if si%p == 0: cnt += i+1 print(cnt) return None d = [0]*p d[0] = 1 # 0(mod p)はそれ単体で割り切れるため+1しておく ss = 0 x = 1 for si in s[::-1]: ss += x*si ss %= p d[ss] += 1 x = (10*x)%p # %p無しだとTLE cnt = 0 for di in d: cnt += di*(di-1)//2 # calc combination(n_C_2) print(cnt) if __name__ == "__main__": main()
import sys input = sys.stdin.readline N, P = map(int, input().split()) S = list(input().rstrip()) if P in {2, 5}: ans = 0 for i, s in enumerate(S): if int(s) % P == 0: ans += i+1 else: ans = 0 T = [0]*P T[0] = 1 tmp = 0 k = 1 for s in reversed(S): tmp = (tmp + k * int(s)) % P k = k * 10 % P ans += T[tmp] T[tmp] += 1 print(ans)
1
58,407,787,958,340
null
205
205
N = int(input()) ls = [] for i in range(N): s = input().split() ls.append(s) X = input() ans = 0 mode = 0 for i in range(N): if ls[i][0] == X: mode = 1 else: if mode == 1: ans += int(ls[i][1]) print(ans)
N = int(input()) music = [] for _ in range(N): s, t = map(str, input().split()) music.append([s, int(t)]) number = input() ans = 0 flag = False for i in range(N): if flag: ans += music[i][1] elif number == music[i][0]: flag = True print(ans)
1
97,086,500,862,230
null
243
243
n=int(input()) s,t=input().split() ans=str() for i in range(n): ans+=s[i]+t[i] print(ans)
x=int(input()) for a in range(-200,200,1): for b in range(-200,200,1): if a**5 - b**5 == x: print(a,b) exit()
0
null
68,874,593,082,800
255
156
alp = 'abcdefghijklmnopqrstuvwxyz' print(alp[alp.index(input())+1])
alp_list = list('abcdefghijklmnopqrstuvwxyz') C = str(input()) z = alp_list.index(C) z += 1 print(alp_list[z])
1
92,208,312,536,340
null
239
239
from math import gcd N = int(input()) A = list(map(int, input().split())) prime = list(range(max(A) + 1)) for i in range(2, len(prime)): if prime[i] != i: continue for j in range(i, len(prime), i): if prime[j] != j: continue prime[j] = i used = set() pc = True for a in A: used_this = set() while a != 1: div = prime[a] if div in used: pc = False break used_this.add(div) a //= div used.update(used_this) if pc: print('pairwise coprime') exit() buf = A[0] for a in A[1:]: buf = gcd(buf, a) if buf == 1: print('setwise coprime') else: print('not coprime')
import math N = int(input()) a = list(map(int,input().split())) m = max(a) c = [0] * (m+1) for i in a: c[i] += 1 pairwise = True for i in range(2, m+1, 1): cnt = 0 for j in range(i, m+1, i): cnt += c[j] if cnt > 1: pairwise = False break if pairwise: print("pairwise coprime") exit() g = 0 for i in range(N): g = math.gcd(g, a[i]) if g == 1: print("setwise coprime") exit() print("not coprime")
1
4,164,883,117,460
null
85
85
import sys for line in sys.stdin: if len(line)>1: x1, y1, x2, y2 = line.strip('\n').split() x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2) print ((x1-x2)**2+(y1-y2)**2)**0.5
# Take both input K & S, then compare the length of S with K and assign it to length # If the length is <= K print all # And if length is >K print some of the character K = int(input()) S = input() x = 0 length = len(S) if length <= K: print(S) else: while x < K: print(S[x], end=("")) x += 1 print("...")
0
null
9,820,527,157,122
29
143
h,w,k = map(int,input().split()) c = [] for i in range(0,h): c.append(input()) def white(c,r,co): count = 0 for i in range(0,h): for j in range(0,w): if r[i] != 0 and co[j] != 0 and c[i][j] == "#": count += 1 return count import itertools listr = list(itertools.product([0,1],repeat = h)) listc = list(itertools.product([0,1],repeat = w)) ans = 0 for i in range(0,2**h): for j in range(0,2**w): if white(c,listr[i],listc[j]) == k: ans += 1 print(ans)
N = int(input()) V = [0]*10000 for j in range (1, 100): for k in range (1, 100): for l in range (1, 100): if j**2+k**2+l**2+j*k+k*l+j*l < 10001: V[j**2+k**2+l**2+j*k+k*l+j*l-1]+=1 for i in range (0, N): print(V[i])
0
null
8,414,486,104,096
110
106
import sys import numpy as np import numba from numba import njit, b1, i4, i8, f8 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines uf_t = numba.types.UniTuple(i8[:], 2) @njit((uf_t, i8), cache=True) def find_root(uf, x): root = uf[0] while root[x] != x: root[x] = root[root[x]] x = root[x] return x @njit((uf_t, i8, i8), cache=True) def merge(uf, x, y): root, size = uf x, y = find_root(uf, x), find_root(uf, y) if x == y: return False if size[x] < size[y]: x, y = y, x size[x] += size[y] root[y] = root[x] return True @njit((i8, i8, i8[:]), cache=True) def main(N, M, AB): ans = N - 1 root = np.arange(N + 1, dtype=np.int64) size = np.ones_like(root) uf = (root, size) for i in range(0, len(AB), 2): a, b = AB[i:i + 2] if merge(uf, a, b): ans -= 1 return ans N, M = map(int, readline().split()) AB = np.array(read().split(), np.int64) print(main(N, M, AB))
def main(): N = int(input()) S = input() dict = {'R':0, 'B':0, 'G':0} for i in range(N): dict[S[i]] += 1 ans = dict['R']*dict['B']*dict['G'] for i in range(N-2): if (N-i)%2 == 0: tmp = int((N-i)/2)-1 else: tmp = (N-i)//2 for j in range(1,tmp+1): if S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]: ans = ans - 1 return ans print(main())
0
null
19,333,085,007,740
70
175
n = int(input()) minv = int(input()) maxv = -1000000000 for i in range(1,n): r = int(input()) m = r-minv if maxv < m < 0: maxv = m minv = r elif maxv < m: maxv = m elif m < 0: minv = r print(maxv)
while True: (x, y) = [int(i) for i in input().split()] if x < y: print(x, y) elif x > y: print(y, x) elif x == y: if x == 0 and 0 == y: break print(x, y)
0
null
261,119,394,532
13
43
import sys input = sys.stdin.readline import bisect import math # 持っているビスケットを叩き、1枚増やす # ビスケット A枚を 1円に交換する # 1円をビスケット B枚に交換する def main(): a, b, n = input_list() x = min(b-1, n) aa = math.floor((a*x)/b) - (a * math.floor(x/b)) print(aa) def bi(num, a, b, x): print((a * num) + (b * len(str(b)))) if (a * num) + (b * len(str(b))) <= x: return False return True def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
import sys from collections import deque N = int(sys.stdin.readline()) lines = sys.stdin.readlines() l = deque() for i in range(N): command = lines[i].split() if command[0] == 'deleteFirst': l.popleft() elif command[0] == 'deleteLast': l.pop() elif command[0] == 'insert': l.appendleft(command[1]) else: if command[1] in l: l.remove(command[1]) print(' '.join(map(str, l)))
0
null
14,004,771,540,032
161
20
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) diff = abs(A - B) dspeed = V - W if dspeed * T >= diff: print("YES") else: print("NO")
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=jp #?????????????????? #??????????????????????°???????????????£?????´???????????´?????¨??\?????????????????????????????????????????´???????????? #??????????????????????????????????°????????????????????????´???????????????????????????????????????????????¨?????? def bubble_sort(origin_list): list_length = len(origin_list) target_list = [i for i in origin_list]#??°???????????????????????? flag = True change_count = 0 top_index = 1 while flag: flag = False for i in range(top_index, list_length)[::-1]: if target_list[i][1] < target_list[i - 1][1]: tmp = target_list[i] target_list[i] = target_list[i - 1] target_list[i - 1] = tmp change_count += 1 flag = True top_index += 1 return target_list def selection_sort(origin_list): list_length = len(origin_list) target_list = [i for i in origin_list]#??°???????????????????????? change_count = 0 for i in range(list_length): min_index = i for j in range(i, list_length): if target_list[j][1] < target_list[min_index][1]: min_index = j else: if not i == min_index: tmp = target_list[i] target_list[i] = target_list[min_index] target_list[min_index] = tmp change_count += 1 return target_list def check_stable(origin_list, target_list): for i, origin_v in enumerate(origin_list): for origin_v2 in origin_list[i+1:]: if origin_v[1] == origin_v2[1]: for j, target_v in enumerate(target_list): for target_v2 in target_list[j+1:]: if origin_v == target_v2 and origin_v2 == target_v: return "Not stable" return "Stable" def stable_sort(target_list): print(*bubble_sort(target_list)) print(check_stable(target_list, bubble_sort(target_list))) print(*selection_sort(target_list)) print(check_stable(target_list, selection_sort(target_list))) def main(): n_list = int(input()) target_list = [a for a in input().split()] stable_sort(target_list) if __name__ == "__main__": main()
0
null
7,628,822,684,120
131
16
n, m, l = map(int, input().split()) A, B = [], [] C = [[0 for i in range(l)] for j in range(n)] for i in range(n): A.append([int(i) for i in input().split()]) for i in range(m): B.append([int(i) for i in input().split()]) B = list(zip(*B)) for i, line_A in enumerate(A): for j, line_B in enumerate(B): for x, y in zip(line_A, line_B): C[i][j] += x * y for line in C: for i, x in enumerate(line): if i == l - 1: print(x) else: print(x, end=" ")
n,m=map(int,input().split()) H=list(map(int,input().split())) ans = [1]*n for i in range(m): a,b=map(int,input().split()) if H[a-1]>H[b-1]: ans[a-1] *= 1 ans[b-1] *= 0 elif H[a-1]<H[b-1]: ans[a-1] *= 0 ans[b-1] *= 1 else: ans[a-1] *= 0 ans[b-1] *= 0 print(sum(ans))
0
null
13,248,642,663,320
60
155
import math PI = math.pi r = input() men = r*r * PI sen = r*2 * PI print('%.6f %.6f' % (men, sen))
import math r = float(input()) s = '{:.6f}'.format(r * r * math.pi) l = '{:.6f}'.format(2 * r * math.pi) print(s,l)
1
641,770,581,142
null
46
46
n = int(input()) num = int(n / 2) if n % 2 == 1: num += 1 print(num)
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) b = 0 tb = 0 for i in range(M): if tb + B[i] > K: break tb += B[i] b = i+1 ans = [0, b] m = b a = 0 ta = 0 for i in range(N): if ta + A[i] > K: break a = i+1 ta += A[i] while True: if ta + tb > K: if b == 0:break b -= 1 tb -= B[b] else: if a + b > m: m = a + b ans = [a, b] break print(ans[0]+ans[1])
0
null
34,687,180,322,692
206
117
X = int(input()) happy = X // 500 * 1000 happy += X % 500 // 5 * 5 print(happy)
#!/usr/bin/env python # -*- coding: utf-8 -*- # # FileName: B # CreatedDate: 2020-06-27 15:34:06 +0900 # LastModified: 2020-06-27 15:35:45 +0900 # import os import sys # import numpy as np # import pandas as pd def main(): h, n = map(int, input().split()) a = list(map(int, input().split())) if sum(a)>=h: print("Yes") else: print("No") if __name__ == "__main__": main()
0
null
60,254,896,412,172
185
226
n=int(input()) s=input() q=int(input()) query=[] for i in range(q): query.append(input()) ide_ele = set() def segfunc(x, y): return x | y class SegTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): # param k: index(0-index) # param x: update value k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): #[l, r)segfunc, 0-index res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res al = [{s[i]} for i in range(n)] seg = SegTree(al, segfunc, ide_ele) for q in query: que,a,b=q.split() if que == "1": seg.update(int(a)-1,set(b)) else: ret=seg.query(int(a)-1,int(b)) print(len(ret))
n=int(input()) a=list(map(int,input().split())) q=int(input()) s=sum(a) data=[0]*10**5 for i in a: data[i-1]+=1 for i in range(q): b,c=map(int,input().split()) s+=(c-b)*data[b-1] print(s) data[c-1]+=data[b-1] data[b-1]=0
0
null
37,430,269,010,816
210
122
import math import sys from decimal import Decimal a,b,c = map(int,input().split()) if c-a-b <= 0: print('No') sys.exit() if Decimal((c-a-b)*(c-a-b) - 4*a*b) > 0: print("Yes") else: print('No')
S=input() if S[-1] == 's': print(S+"es") else: print(S+"s")
0
null
27,048,726,620,960
197
71
n = int(input()) a = [] xy = [] for i in range(n): temp_a = int(input()) s = [list(map(int, input().split())) for _ in range(temp_a)] a.append(temp_a) xy.append(s) ans = 0 for bit in range(1<<n): h = [0]*n flag = True sum = 0 for i in range(n): if (bit>>i) & 1: h[i] = 1 sum += 1 for i in range(n): if (bit>>i) & 1: for j in range(a[i]): if xy[i][j][1] != h[xy[i][j][0]-1]: flag =False if flag: ans = max((ans, sum)) print(ans)
#!/usr/bin/env python3 from itertools import product def solve(n,a): testimony = product([0,1],repeat=n) ans = 0 for l in testimony: flag = True for test in a: if l[test[0]] and l[test[1]] and (test[2] == 0): flag = False if l[test[0]] and l[test[1]]==0 and test[2]: flag = False if flag: ans = max(ans,sum(l)) return ans def main(): N = int(input()) a = [] for i in range(N): tmp = int(input()) for _ in range(tmp): x,y = map(int,input().split()) a.append([i,x-1,y]) print(solve(N,a)) return if __name__ == '__main__': main()
1
121,147,003,209,882
null
262
262
n,k = input().split() k = int(k)-1 a = list() a = input().split(" ") b = list() for i in a: b.append(int(i)) b.sort() sum = 0 while k>=0: sum += b[k] k -= 1 print(sum)
n,k = map(int, input().split()) l = list(map(int, input().split())) l.sort() c = 0 i = 0 while i < k: c += l[i] i += 1 print(c)
1
11,519,780,342,522
null
120
120
S,T = input().split() print(T,S, sep='')
n,m=map(int,input().split()) lst=list(map(int,input().split())) if n<sum(lst) : print(-1) else : print(n-sum(lst))
0
null
67,378,137,796,750
248
168
#!usr/bin/env python3 def string_two_numbers_spliter(): a, b = [int(i) for i in input().split()] return a, b def main(): a, b = string_two_numbers_spliter() if a < b: print('a < b') elif a > b: print('a > b') else: print('a == b') if __name__ == '__main__': main()
x = raw_input().split() if float(x[0]) < float(x[1]): print "a < b" elif float(x[0]) > float(x[1]): print "a > b" else: print "a == b"
1
356,814,463,392
null
38
38
import bisect n = int(input()) l = list(map(int, input().split())) l.sort() ans = 0 for a in range(0, n-2): for b in range(a+1, n-1): c = l[a] + l[b] ans += bisect.bisect_left(l, c) - b - 1 print(ans)
import bisect N = int(input()) num_list = list(map(int,input().split())) num_list.sort() res = 0 for a in range(N-2): for b in range(a+1,N-1): k = bisect.bisect_left(num_list,num_list[a]+num_list[b]) res += max(k-(b+1),0) print(res)
1
171,714,274,184,882
null
294
294
def resolve(): word=input() print(chr(ord(word)+1)) resolve()
A = int(input()) B = int(input()) AB = [A,B] Ans = [x for x in range(1,4) if x not in AB] print(Ans[0])
0
null
101,464,374,482,958
239
254
x, y, z = input().split() a = int(x) b = int(y) c = int(z) count = 0 num = a while num <= b: if c % num == 0: count += 1 else: pass num += 1 print(count)
a, b, c = map(int, input().split()) i = a ans = 0 while i <= b: if c % i == 0: ans += 1 i += 1 print(ans)
1
552,552,147,498
null
44
44
N = int(input()) s = [""] * N t = [0] * N for i in range(N): a, b = map(str, input().split()) s[i] = a t[i] = int(b) X = input() sleep_index = s.index(X) ans = 0 for i in range(sleep_index+1, N): ans += t[i] print(ans)
N = int(input()) music = [] for i in range(N): music.append(input().split()) X = (input()) Time = 0 kama = False for s,t in music: if kama: Time += int(t) if s == X: kama = True print(Time)
1
97,026,632,908,712
null
243
243
import sys input = sys.stdin.readline MOD = 10**9 + 7 INF = float('INF') def main(): r = int(input()) print(r**2) if __name__ == '__main__': main()
def main(): r = int(input()) print(r**2) return 0 if __name__ == '__main__': main()
1
144,924,417,543,658
null
278
278
from collections import deque def main(): doubly_liked_list = deque() n = int(input()) for i in range(n): command = input() if command == 'deleteFirst': doubly_liked_list.popleft() elif command == 'deleteLast': doubly_liked_list.pop() else: command = command.split() if command[0] == 'insert': doubly_liked_list.appendleft(int(command[1])) elif command[0] == 'delete': try: doubly_liked_list.remove(int(command[1])) except: pass print(*doubly_liked_list) if __name__ == "__main__": main()
from collections import deque n = int(input()) d = deque() for i in range(n): c = input() if ' ' in c: c, num = c.split() if c == 'insert': d.appendleft(num) elif c == 'delete' and num in d: d.remove(num) else: if c == 'deleteFirst' and d: d.popleft() elif c == 'deleteLast' and d: d.pop() print(' '.join(d))
1
51,212,476,798
null
20
20
h = int(input()) cnt = 0 ans = 0 while h > 1: h = h//2 cnt += 1 ans += 2**cnt print(ans+1)
# D - Caracal vs Monster H = int(input()) def rec(x): if x==1: return 1 return 2*rec(x//2)+1 print(rec(H))
1
80,042,224,674,622
null
228
228
a,b,c = map(int,raw_input().split()) if a>b: tmp = a a = b b = tmp if b>c: tmp = b b = c c = tmp if a>b: tmp = a a = b b = tmp print "%d %d %d" %(a,b,c)
list = [int(a) for a in input().split()] list.sort() print(*list)
1
422,128,392,840
null
40
40
def convert(s): o = ord(s) if o >= 65 and o <= 90: return s.lower() elif o >= 97 and o <= 122: return s.upper() return s def main(): strings = input() answer = "" for s in strings: s = s answer += convert(s) print(answer) if __name__ == "__main__": main()
INF = 10**12 def warshall_floyd(d,n): #d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d def main(): n,m,l = map(int, input().split()) d = [ [INF]*(n) for _ in range(n) ] for _ in range(m): a,b,c = map(int, input().split()) d[a-1][b-1] = c d[b-1][a-1] = c warshall_floyd(d, n) d2 = [ [INF]*(n) for _ in range(n) ] for i in range(n): for j in range(n): if d[i][j] <= l: d2[i][j] = 1 warshall_floyd(d2,n) ans = [] q = int(input()) for _ in range(q): s,t = map(int, input().split()) dist = d2[s-1][t-1] if dist == INF: dist = 0 ans.append(dist-1) for a in ans: print(a) if __name__ == "__main__": main()
0
null
87,565,911,350,294
61
295
import math n = int(input()) xn_list = list(map(int, input().split())) ans = float('inf') for i in range(1, 100): temp = 0 for j in xn_list: temp += (j-i)**2 ans = min(ans, temp) print(ans)
taro_p = 0 hana_p = 0 for i in range(input()): taro,hana = raw_input().split(' ') if taro > hana: taro_p = taro_p + 3 hana_p = hana_p + 0 elif taro < hana: taro_p = taro_p + 0 hana_p = hana_p + 3 else: taro_p = taro_p + 1 hana_p = hana_p + 1 print taro_p,hana_p
0
null
33,672,281,396,740
213
67
import sys from bisect import bisect_left input = sys.stdin.readline def main(): N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for a in range(N - 2): for b in range(a + 1, N - 1): x = bisect_left(L, L[a] + L[b]) ans += (x - 1 - b) print(ans) if __name__ == "__main__": main()
import bisect as bs N = int(input()) L = list(map(int,input().split())) L.sort() ans = 0 for i in range(len(L)-1): for j in range(i+1, len(L)): ans += bs.bisect_left(L, L[i]+L[j])-j-1 print(ans)
1
171,515,018,867,784
null
294
294
n=int(input()) a=list(map(int,input().split())) ans=0 step=0 for i in range(n-1): if a[i]+step<=a[i+1]: step=0 else: ans+=a[i]+step-a[i+1] step=a[i]+step-a[i+1] print(ans)
a,b = map(int,input().split()) if a<=b: [print(a,end="") for _ in range(b)] else: [print(b,end="") for _ in range(a)]
0
null
44,346,547,701,692
88
232
X = int(input()) total = 0 happiness_500 = X // 500 *1000 total += happiness_500 y = X % 500 happiness_5 = y //5 *5 total += happiness_5 print(total)
def main(): X = int(input()) p, r = divmod(X, 500) q, r = divmod(r, 5) print(p * 1000 + q * 5) if __name__ == '__main__': main()
1
42,969,924,238,400
null
185
185
from math import cos, sin, pi def make_koch_curve(N, n1, n2): s = ((2 * n1[0] + n2[0]) / 3, (2 * n1[1] + n2[1]) / 3) t = ((n1[0] + 2 * n2[0]) / 3, (n1[1] + 2 * n2[1]) / 3) u = ((t[0] - s[0])*cos(pi/3) - (t[1] - s[1])*sin(pi/3) + s[0], (t[0] - s[0])*sin(pi/3) + (t[1] - s[1])*cos(pi/3) + s[1]) if N == 0: return make_koch_curve(N-1, n1, s) print(*s) make_koch_curve(N-1, s, u) print(*u) make_koch_curve(N-1, u, t) print(*t) make_koch_curve(N-1, t, n2) def main(): N = int(input()) n1 = (0., 0.) n2 = (100., 0.) print(*n1) make_koch_curve(N, n1, n2) print(*n2) if __name__ == '__main__': main()
import math n = int(input()) cos60 = math.cos(math.radians(60)) sin60 = math.sin(math.radians(60)) def koch(d, p1, p2): if d == 0: return s = [ (2.0*p1[0]+1.0*p2[0])/3.0, (2.0*p1[1]+1.0*p2[1])/3.0 ] t = [ (1.0*p1[0]+2.0*p2[0])/3.0, (1.0*p1[1]+2.0*p2[1])/3.0 ] u = [ (t[0]-s[0])*cos60 - (t[1]-s[1])*sin60 + s[0], (t[0]-s[0])*sin60 + (t[1]-s[1])*cos60 + s[1] ] koch(d-1, p1, s) print(f"{s[0]} {s[1]}") koch(d-1, s, u) print(f"{u[0]} {u[1]}") koch(d-1, u, t) print(f"{t[0]} {t[1]}") koch(d-1, t, p2) return print(f"{0} {0}") koch(n, [0, 0], [100, 0]) print(f"{100} {0}")
1
127,624,160,088
null
27
27
s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51" s = s.replace(' ','') a = list(s.split(',')) n = int(input()) print(a[n-1])
S = int(input()) if S % 9 == 0: W = 'Yes' else: W = 'No' print(W)
0
null
27,257,881,364,448
195
87
string = input() if string[-1] == 's': out = string + "es" else: out = string + "s" print(out)
import sys import time import math def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ N = int(input()) d = inpl() ans = 0 for i in range(N-1): for j in range(i+1, N): ans += d[i] * d[j] print(ans) # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
0
null
85,738,125,908,150
71
292
import sys w=input().upper() c=0 for s in sys.stdin: if "END_OF_TEXT" in s: break c += str(s).upper().split().count(w) print(c)
W = input().lower() count = 0 while True: l = input() if l == 'END_OF_TEXT': break for i in l.lower().split(): if i == W: count += 1 print(count)
1
1,802,582,709,628
null
65
65
# A Curtain a, b = map(int, input().split()) x = a-(b * 2) if x > 0: print(x) else: print(0)
from itertools import permutations N = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) a=0 b=0 for i,p in enumerate(permutations(range(1,N+1))): if p==P: a = i if p==Q: b = i print (abs(a-b))
0
null
133,201,771,882,720
291
246
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline n, x, m = map(int, input().split()) ans = 0 aa = x ans += aa aset = set([aa]) alist = [aa] for i in range(1,n): aa = pow(aa,2,m) if aa in aset: offset = alist.index(aa) loop = alist[offset:i] nloop, tail = divmod(n-offset, len(loop)) ans += sum(loop)*(nloop-1) ans += sum(loop[0:tail]) break else: ans += aa aset.add(aa) alist.append(aa) print(ans)
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)
1
2,821,926,846,848
null
75
75
n = int(input()) S = input() res = 1 tmp = S[0] for i in range(1,n): if S[i] != tmp: res += 1 tmp = S[i] print(res)
n=int(input()) s=list(input()) for x in range(n-1): if s[x]==s[x+1]: s[x]='1' print(len(s)-s.count('1'))
1
170,431,897,724,550
null
293
293
a, b = map(int, input().split()) ans = 1001 for n in range(1001): if n * 8 // 100 == a and n * 10 // 100 == b: ans = min(ans, n) if ans < 1001: print(ans) else: print(-1)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines H1, M1, H2, M2, K = map(int, read().split()) hr = (H2- H1) * 60 if M2 >= M1: _min = M2 - M1 hr = (H2- H1) * 60 ans = hr + _min else: _min = (M2 + 60) - M1 hr = (H2- H1 -1) * 60 ans = hr + _min print(ans - K)
0
null
37,460,593,887,780
203
139
from random import * D=int(input()) C=list(map(int,input().split())) S=[list(map(int,input().split())) for i in range(D)] X=[0]*26 XX=X[:] Y=X[:] YY=X[:] P=[] SC=0 N,M,L,O=0,0,0,0 for i in range(D): for j in range(26): X[j]+=C[j] XX[j]+=X[j] N,M=-1,-10**20 L,O=N,M for j in range(26): if Y==-1: N,M=0,X[0]+S[i][0] if M<X[j]+S[i][j]: L,O=N,M N,M=j,X[j]+S[i][j] elif O<X[j]+S[i][j]: L,O=j,X[j]+S[i][j] XX[N]-=X[N] X[N]=0 P.append([N,L]) SC+=X[N] SC2=0 for i in range(10**5): SC2=SC d,q=randrange(0,D),randrange(0,26) SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX) or randrange(0,1000)==0: P[d][0]=q XX=YY[:] SC=SC2 for d in range(D): for q in range(26): SC2=SC SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 for i in range(D): SC2=SC d,q=i,P[i][1] SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d]=P[d][::-1] XX=YY[:] SC=SC2 for i in range(D): print(P[i][0]+1)
from sys import stdin operate = { '+': lambda lhs, rhs: lhs + rhs, '-': lambda lhs, rhs: lhs - rhs, '*': lambda lhs, rhs: lhs * rhs, '/': lambda lhs, rhs: lhs // rhs, } while True: arr = (stdin.readline().rstrip().split()) a, op, b = int(arr[0]), arr[1], int(arr[2]) if op == '?': break answer = operate[op](a, b) print(answer)
0
null
5,148,478,580,230
113
47
# import matplotlib.pyplot as plt import math def lcm(x, y): if x > y: z = x else: z = y while(True): if((z % x == 0) and (z % y == 0)): lcm = z break z += 1 return lcm X = int(input()) print(int(lcm(X, 360) / X))
# -*- coding: utf-8 -*- moji=[] moji.append("eraser") moji.append("erase") moji.append("dreamer") moji.append("dream") user = "erasedream" user = int(input()) result = user count = 1 while result != 0: result += user result %= 360 count += 1 print(count,end="")
1
13,069,001,032,240
null
125
125
# 解説を参考に作成 # import sys # sys.setrecursionlimit(10 ** 6) # import bisect # from collections import deque import math # from decorator import stop_watch # # # @stop_watch def solve(N, K, As): ans = max(As) l, r = 1, ans for _ in range(30): m = (l + r) // 2 cnt = 0 for A in As: cnt += math.ceil(A / m) - 1 if cnt <= K: ans = min(ans, m) r = m - 1 else: l = m + 1 if l > r: break print(ans) if __name__ == '__main__': # S = input() # N = int(input()) N, K = map(int, input().split()) As = [int(i) for i in input().split()] # Bs = [int(i) for i in input().split()] solve(N, K, As)
###2分探索 import sys N,K = map(int,input().split()) A = list(map(int,input().split())) p = 0###無理(そこまで小さくできない) q = max(A)###可能 if K == 0: print(q) sys.exit(0) while q-p > 1: r = (p+q)//2 count = 0 for i in range(N): if A[i]/r == A[i]//r: count += A[i]//r - 1 else: count += A[i]//r if count > K: p = r else: q = r #print(p,q) print(q)
1
6,501,083,134,562
null
99
99
#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 # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(input()) n,m = readInts() A = readInts() sumA = sum(A) div = sumA * (1/(4*m)) A = sorted(A,reverse=True) for i in range(m): if A[i] < div: print('No') exit() print('Yes')
N,M,*A = map(int, open(0).read().split()) A.sort() if A[-M]*4*M >= sum(A): print('Yes') else: print('No')
1
38,532,304,440,768
null
179
179
# coding: utf-8 import math N, K = (int(x) for x in input().split()) A = [int(x) for x in input().split()] A.sort() p = 10**9 + 7 facts = [1, 1] for i in range(2, N+1): facts.append((facts[i-1] * i) % p) invs = [1 for i in range(N+1)] invs[N] = pow(facts[N], p-2, p) for i in range(N, 1, -1): invs[i-1] = invs[i] * i % p sum_max_s = 0 for i in range(K, N+1): sum_max_s += A[i-1] * (facts[i-1] * invs[K-1] * invs[i-K] % p) % p sum_min_s = 0 for i in range(1, N-K+2): sum_min_s += A[i-1] * (facts[N-i] * invs[K-1] * invs[N-i-K+1] % p) % p print(str(int(sum_max_s - sum_min_s) % p))
s=int(input()) A=[0,0,1] for i in range(3,s): A+=[A[i-1]+A[i-3]] print(A[s-1]%(10**9+7))
0
null
49,492,365,144,462
242
79
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") a,b = map(int, input().split()) ab = str(a)*b ba = str(b)*a if ab<ba: ans = ab else: ans = ba print(ans)
ls = list(map(int,input().split())) print(str(min(ls))*max(ls))
1
84,350,382,795,514
null
232
232
S=str(input()) if S.isupper()==True: print("A") else: print("a")
x,y,a,b,c=map(int, input().split()) p=sorted(list(map(int, input().split())), reverse=True)[:x] q=sorted(list(map(int, input().split())), reverse=True)[:y] r=sorted(list(map(int, input().split())), reverse=True)[:x+y] new=sorted(p+q+r, reverse=True) print(sum(new[:x+y]))
0
null
27,891,333,100,010
119
188
score = list(map(int,input().split())) answer = 0 if score[3] - score[0] <= 0: answer += score[3] else: answer += score[0] if score[3] - score[0] - score[1] > 0: answer -= score[3] - score[0] - score[1] print(answer)
import sys, math from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from itertools import combinations, permutations, product from heapq import heappush, heappop from functools import lru_cache input = sys.stdin.readline rs = lambda: input().strip() ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) mat = lambda x, y, v: [[v]*y for _ in range(x)] ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)] mod = 1000000007 sys.setrecursionlimit(1000000) N, X, M = rl() Xs = [None] * M ans = 0 dif_i = 0 dif_v = 0 cur_i = 0 for i in range(1, N+1): ans += X if Xs[X] != None: cur_i = i dif_v = ans - Xs[X][1] dif_i = i - Xs[X][0] cur_x = X break Xs[X] = (i, ans) X = (X**2) % M if cur_i > 0 and cur_i < N: remain = N - cur_i ans += (remain // dif_i) * dif_v X = cur_x for i in range(remain % dif_i): X = (X**2) % M ans += X print(ans)
0
null
12,289,135,883,280
148
75
x,y = map(int,input().split()) s = max(0,(4-x)*100000)+max(0,(4-y)*100000) print(s if s!=600000 else s+400000)
h,n=map(int,input().split()) l=list(map(int,input().split())) a=0 for i in range(n): a+=l[i] if a>=h: print("Yes") else: print("No")
0
null
109,564,977,400,504
275
226
n=int(input()) a=list(map(int,input().split())) c=a[0] for i in range(1,n): c=c^a[i] for i in range(n): print(c^a[i])
N = int(input()) a = list(map(int,input().split())) sum = 0 for i in a: sum = i^sum for i in a: print(sum^i,end=' ')
1
12,517,008,792,274
null
123
123
from time import time from random import random limit_secs = 2 start_time = time() D = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(D)] def calc_score(): score = 0 S = 0 last = [-1] * 26 for d in range(D): S += s[d][t[d]] last[t[d]] = d for i in range(26): S -= c[i] * (d - last[i]) score += max(10 ** 6 + S, 0) return score def solution(): return [i % 26 for i in range(D)] t = solution() score = calc_score() while time() - start_time + 0.14 < limit_secs: d = int(random() * D) q = int(random() * 26) old = t[d] t[d] = q new_score = calc_score() if new_score < score: t[d] = old else: score = new_score print(*[e + 1 for e in t])
from numba import njit import numpy as np d = int(input()) cs = list(map(int, input().split())) cs = np.array(cs, dtype=np.int64) sm = [list(map(int, input().split())) for _ in range(d)] sm = np.array(sm, dtype=np.int64) @njit('i8(i8[:], i8)', cache=True) def total_satisfaction(ts, d): ls = np.zeros(26, dtype=np.int64) s = 0 for i in range(d): t = ts[i] t -= 1 s += sm[i][t] ls[t] = i + 1 dv = cs * ((i+1) - ls) s -= dv.sum() return s @njit('i8(i8, i8, i8, i8, i8[:])', cache=True) def differential(s, i, t, d, ls): t -= 1 bk = ls[t] s += sm[i][t] ls[t] = i + 1 dv = cs * ((i+1) - ls) s -= dv.sum() ls[t] = bk return s ts = np.array([], dtype=np.int64) for i in range(d): sc = 0 if len(ts) > 0: tt = np.array(ts, dtype=np.int64) sc = total_satisfaction(tt, i) ls = np.zeros(26, np.int64) for i, t in enumerate(ts, 1): ls[t-1] = i mx = -99999999 mxt = -1 for t in range(1, 26+1): df = differential(sc, len(ts), t, i + 1, ls) s = sc + df if s > mx: mx = s mxt = t ts = np.append(ts, [mxt]) print(mxt)
1
9,706,093,049,478
null
113
113
S = input() K = int(input()) N = len(S) #全て同じ文字の時 if len(set(S)) == 1: print(N*K//2) exit() #隣合う文字列が何個等しいか cycle = 0 tmp = S[0] cnt = 1 for i in range(1, N): if tmp != S[i]: cycle += cnt//2 tmp = S[i] cnt = 1 else: cnt += 1 cycle += cnt//2 if S[0] == S[-1]: i = 0 a = 0 tmp = S[0] while S[i] == tmp: i += 1 a += 1 j = N-1 b = 0 tmp = S[-1] while S[j] == tmp: j -= 1 b += 1 print((cycle*K) - (a//2 + b//2 - (a+b)//2)*(K-1)) else: print(cycle*K)
S = list(input()) N = len(S) K = int(input()) if len(set(S)) == 1: print((N*K)//2) exit() ans = 0 i = 0 while i < N-1: if S[i] == S[i+1]: ans += 1 i += 1 i += 1 if S[0] != S[N-1]: print(ans*K) exit() a = 1 while S[0] == S[a]: a += 1 b = 1 while S[N-1] == S[N-1-b]: b += 1 print(ans*K - (K-1)*(a//2 + b//2 - (a+b)//2))
1
175,157,399,238,730
null
296
296
import math H = int(input()) ans = 2 ** int(math.log2(H) + 1) - 1 print(ans)
h = int(input()) num = 0 t = 0 while h != 1: h = h//2 num += 2**t t += 1 num += 2**t print(num)
1
80,119,485,031,182
null
228
228
from operator import mul from functools import reduce import sys def cmb(n,r): r=min(n-r,r) if r==0: return 1 over=reduce(mul,range(n,n-r,-1)) under=reduce(mul,range(1,r+1)) return over//under N,P=map(int,input().split()) S=list(map(int,list(input()))) if P==2: ans=0 for i in range(N): if S[i]%2==0: ans+=i+1 print(ans) sys.exit() if P==5: ans=0 for i in range(N): if S[i]==0 or S[i]==5: ans+=i+1 print(ans) sys.exit() data=[1]*N for i in range(N-2,-1,-1): data[i]=data[i+1]*10%P data[-1]=data[-1]*S[-1]%P for i in range(N-2,-1,-1): data[i]=(data[i]*S[i]+data[i+1])%P data.sort() cnt=1 ans=data.count(0) for i in range(1,N): if data[i]==data[i-1]: cnt+=1 else: if cnt>=2: ans+=cmb(cnt,2) cnt=1 if cnt>=2: ans+=cmb(cnt,2) print(ans)
from copy import copy from collections import defaultdict n, p = map(int, input().split()) s = input() ans = 0 if p == 2 or p == 5: for i in range(n): if int(s[i]) % p == 0: ans += i + 1 else: dp = [0] * p dp[0] = 1 tmp = 0 for i in range(n)[::-1]: tmp = (int(s[i]) * pow(10, n - i - 1, p) + tmp) % p # tmp = (int(s[i]) * 10 ** (n - i - 1) + tmp) % p # print(tmp, int(s[i]) * 10 ** (n - i - 1)) ans += dp[tmp] dp[tmp] += 1 # print(dp) print(ans)
1
58,186,379,862,600
null
205
205
X=int(input()) for i in range(1,10000): if (i*X)%360==0: print(i) break
n,k=[int(i) for i in input().strip().split(" ")] arr=[int(i) for i in input().strip().split(" ")] ans=0 arr=sorted(arr) for i in range(k): ans+=arr[i] print(ans)
0
null
12,298,649,374,270
125
120
import sys input = sys.stdin.readline from bisect import * def judge(x): cnt = 0 for i in range(N): idx = bisect_left(A, x-A[i]) cnt += N-idx return cnt>=M def binary_search(): l, r = 0, 10**11 while l<=r: mid = (l+r)//2 if judge(mid): l = mid+1 else: r = mid-1 return r N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort() border = binary_search() acc = [0] for Ai in A: acc.append(acc[-1]+Ai) ans = 0 cnt = 0 for i in range(N): idx = bisect_left(A, border-A[i]+1) ans += A[i]*(N-idx)+acc[N]-acc[idx] cnt += N-idx ans += (M-cnt)*border print(ans)
N,M = map(int,input().split()) A = list(map(int,input().split())) A.sort() B = [0 for i in range(10**5+1)] S = [0] s = 0 for i in range(N): B[A[i]] += 1 s += A[i] S.append(s) for i in range(2,10**5+2): B[-i] += B[-i+1] d = 0 u = 2*10**5 for i in range(30): x = (u+d)//2 if i == 28: x += 1 m = 0 for i in range(N): a = A[i] y = max(x - a,0) if y <= 10**5: m += B[y] if m >= M: d = x else: u = x ans = 0 for i in range(N): a = A[i] x = max(d - a,0) if x <= 10**5: y = B[x] else: y = 0 ans += (S[N] - S[N-y]) + a*y ans -= (m-M)*d print(ans)
1
108,385,478,204,810
null
252
252
def main(): k,n = map(int, input().split()) s = list(map(int, input().split())) l = [] for i in range(n): if i == 0: l.append(k - (s[-1] - s[0])) else: a = s[i] - s[i-1] l.append(a) print(k - max(l)) if __name__ == '__main__': main()
import math n = int(input()) def koch(n, p1_x, p2_x, p1_y, p2_y): if n == 0: return s_x = (2*p1_x + p2_x) / 3 s_y = (2*p1_y + p2_y) / 3 t_x = (p1_x + 2*p2_x) / 3 t_y = (p1_y + 2*p2_y) / 3 u_x = (t_x - s_x)/2 - (t_y - s_y) * math.sqrt(3)/2 + s_x u_y = (t_x - s_x) * math.sqrt(3)/2 + (t_y - s_y)/2 + s_y koch(n-1, p1_x, s_x, p1_y, s_y) print (s_x, s_y) koch(n-1, s_x, u_x, s_y, u_y) print (u_x, u_y) koch(n-1, u_x, t_x, u_y, t_y) print (t_x, t_y) koch(n-1, t_x, p2_x, t_y, p2_y) p1_x = 0.0 p1_y = 0.0 p2_x = 100.0 p2_y = 0.0 print (p1_x, p1_y) koch(n, 0, 100, 0, 0) print (p2_x, p2_y)
0
null
21,599,951,860,068
186
27
N = int(input()) A = list(map(int, input().split())) t = [-1] * (N + 1) t[0] = 1000 for i in range(N): k = t[i] // A[i] y = t[i] % A[i] for j in range(i, N): t[j + 1] = max(t[j + 1], k * A[j] + y) print(t[N])
n = int(input()) a = list(map(int,input().split())) m = 1000 stocks = 0 drops = [False]*(n-1) for i in range(n-1): if a[i] > a[i+1]: drops[i] = True for i in range(n-1): if drops[i]: m+=stocks*a[i] stocks = 0 else: stocks+=m//a[i] m -= (m//a[i])*a[i] print(m + stocks*a[-1])
1
7,315,920,953,568
null
103
103
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from itertools import permutations, accumulate, combinations, combinations_with_replacement from math import sqrt, ceil, floor, factorial from bisect import bisect_left, bisect_right, insort_left, insort_right from copy import deepcopy from operator import itemgetter from functools import reduce, lru_cache # @lru_cache(None) from fractions import gcd import sys def input(): return sys.stdin.readline().rstrip() sys.setrecursionlimit(10**6) # ----------------------------------------------------------- # a, v = (int(x) for x in input().split()) b, w = (int(x) for x in input().split()) t = int(input()) if a == b: print("YES") elif a < b: if a + t*v >= b + t*w: print("YES") else: print("NO") else: if a - t*v <= b - t*w: print("YES") else: print("NO")
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
51,001,165,118,758
131
234
n = int(input()) x = list(map(int,input().split())) m = sum(x)/len(x) m = int(round(m)) power = sum([(i - m)**2 for i in x]) print(power)
while(True): num = input() if num == '0': break x = 0 for i in num: x += int(i) print(x)
0
null
33,278,882,985,532
213
62
def ifTriangle(a, b, c): if (a**2) + (b**2) == c**2: print("YES") else: print("NO") n=int(input()) for i in range(n): lines=list(map(int, input().split())) lines.sort() ifTriangle(lines[0], lines[1], lines[2])
x = input() for i in xrange(x): inp = map(int ,raw_input().split()) inp.sort() if inp[2]**2 == inp[0]**2 + inp[1]**2: print "YES" else: print "NO"
1
282,472,652
null
4
4
h, a = map(int, input().split()) if h % a > 0: number_of_times = h // a + 1 print(number_of_times) else: print(h // a)
n,k=map(int,input().split()) H = list(map(int, input().split())) if n <= k: print('0') exit() H.sort() H.reverse() print(sum(H)-sum(H[0:k]))
0
null
77,815,451,458,108
225
227
import math N = int(input()) A = list(int(input()) for _ in range(N)) def insertionSort(A,n,g,cnt): for i in range(g,n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v return cnt def shellSort(A,n): cnt = 0 G = [] bet = 0 while True: bet = 3*bet + 1 if bet <= n: G.insert(0,bet) else: break m = len(G) for i in range(m): cnt = insertionSort(A,n,G[i],cnt) print(m) outputNumList(G) print(cnt) def outputNumList(A): tmp = map(str,A) text = " ".join(tmp) print(text) shellSort(A,N) for k in range(N): print(A[k])
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Shell Sort ?¬????????????°?????????????????\?????????????????¨?????? n ????????´??°???????????°??? A ??????????????´?????????????????°????????§?????? 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) shellSort(A, n) ????????????????????? g ????????¢??????????´??????????????±???¨???????????\???????????§?????? insertionSort(A, n, g) ?????????????????§??????????????? g ????????????????????°?????????????????? ??????????????§??????????????¨?¨????????????? ???????????????????????? ? ??????????????????????????°??????????????????????????????????????? n ??¨??°??? A ???????????????????????§????????????????????????m??? m ????????´??° Gi(i=0,1,...,m???1)??? ??\??? A????????????????????????????????????????????°???????????????????????????????????? ???????????????????????\???????????¶???????????????????????????????????? 1???m???100 0???Gi???n cnt ????????? [n^1.5] ????¶?????????????????????? """ import sys def insertionSort(A, n, g): """ ?????\????????? """ c = 0 for i in range(g, n): v = A[i] j = i - g while j >=0 and A[j] > v: A[j+g] = A[j] j = j - g c += 1 A[j+g] = v return c def shellSort(A, n): cnt = 0 G = [] i = 1 while i <= n: G.insert(0,i) i = i * 3 + 1 m = len(G) for i in range(0, m): cnt += insertionSort(A, n, G[i]) # ?????? print(m) print(" ".join(map(str,G))) print(cnt) for i in A: print(i) # ????????? n = int(input().strip()) a = [] for i in range(n): a.append(int(input().strip())) shellSort(a,n)
1
30,344,778,020
null
17
17
import sys def input(): return sys.stdin.readline().rstrip() from itertools import product def main(): h, w, k = map(int,input().split()) C = [input() for _ in range(h)] comb_list = list(product([False, True], repeat = h + w)) ans = 0 for comb in comb_list: cunt = 0 for i in range(h): if not comb[i]: continue for j in range(w): if not comb[h+j]: continue if C[i][j] == '#': cunt += 1 if cunt == k: ans += 1 print(ans) if __name__=='__main__': main()
def main(): N = int(input()) st = [list(input().split()) for i in range(N)] X = input() ans = 0 for i in range(N): if st[i][0] == X: i += 1 break for j in range(i,N,1): ans += int(st[j][1]) return ans print(main())
0
null
52,695,128,820,348
110
243
x,y = map(int,input().split()) def point(a): if a == 1: return 300000 elif a == 2: return 200000 elif a == 3: return 100000 else: return 0 c = point(x) b = point(y) if x == 1 and y == 1: print(1000000) else: print(c+b)
import sys import math import collections def set_debug(debug_mode=False): if debug_mode: fin = open('input.txt', 'r') sys.stdin = fin def int_input(): return list(map(int, input().split())) def get(s): return str(s % 9) + '9' * (s // 9) if __name__ == '__main__': # set_debug(True) # t = int(input()) t = 1 for ti in range(1, t + 1): n = int(input()) A = int_input() cur = 0 for x in A: cur = x ^ cur res = [] for x in A: res.append(cur ^ x) print(*res)
0
null
76,323,339,545,612
275
123
print(sum([i//500*1000+i%500//5*5 for i in [int(input())]]))
#!/usr/bin/env python3 from networkx.utils import UnionFind import sys def input(): return sys.stdin.readline().rstrip() def main(): n,m=map(int, input().split()) uf = UnionFind() for i in range(1,n+1): _=uf[i] for _ in range(m): a,b=map(int, input().split()) uf.union(a, b) # aとbをマージ print(len(list(uf.to_sets()))-1) #for group in uf.to_sets(): # すべてのグループのリストを返す #print(group) if __name__ == '__main__': main()
0
null
22,468,011,329,540
185
70
from collections import defaultdict def main(): _, S = open(0).read().split() indices, doubled_indices = defaultdict(list), defaultdict(set) for i, c in enumerate(S): indices[c].append(i) doubled_indices[c].add(2 * i) cnt = S.count("R") * S.count("G") * S.count("B") for x, y, z in ["RGB", "GBR", "BRG"]: cnt -= sum(i + j in doubled_indices[z] for i in indices[x] for j in indices[y]) print(cnt) if __name__ == "__main__": main()
# 17-Character-Counting_Characters.py # ????????????????????? # ?????????????????±??????????????????????????¢???????????????????????°?????°??????????????°????????????????????????????????? # ??????????°?????????¨??§??????????????\??????????????? # Input # ?????°????????????????????????????????±??????????????????????????? # Output # ?????????????????±???????????????????????¢???????????????????????°?????\??????????????¢?????§???????????????????????? # a : a????????° # b : b????????° # c : c????????° # . # . # z : z????????° # Constraints # ??±???????????????????????° < 1200 # Sample Input # This is a pen. # Sample Output # a : 1 # b : 0 # c : 0 # d : 0 # e : 1 # f : 0 # g : 0 # h : 1 # i : 2 # j : 0 # k : 0 # l : 0 # m : 0 # n : 1 # o : 0 # p : 1 # q : 0 # r : 0 # s : 2 # t : 1 # u : 0 # v : 0 # w : 0 # x : 0 # y : 0 # z : 0 import sys s = str() alphabet = "abcdefghijklmnopqrstuvwxyz" for line in sys.stdin: s += line.lower() # print(list(s)) for c in alphabet: print("{} : {}".format(c, s.count(c)) )
0
null
18,986,270,101,240
175
63
import fileinput n, r = map(int, input().split()) if n >= 10: print(r) else: rr = r + 100 * (10 - n) print(rr)
from sys import stdin def main(): #入力 readline=stdin.readline n,r=map(int,readline().split()) if n>=10: print(r) else: print(r+100*(10-n)) if __name__=="__main__": main()
1
63,264,957,108,948
null
211
211
a,b,c=map(int, input().split(" ")) if a>c : k=c c=a a=k if c<b : k=b b=c c=k if b<a : k=b b=a a=k a,b,c=map(str,(a,b,c)) print(a+' '+b+' '+c)
n = int(input()) l = list(sorted(map(int, input().split()))) x = 0 if n >= 3: for k in range(n - 2): for j in range(k + 1): for i in range(j + 1): if l[i] < l[j + 1] < l[k + 2] and l[i] + l[j + 1] > l[k + 2]: x += 1 print(x)
0
null
2,742,749,103,642
40
91
def foo(x,y,z): return x**2 + y**2 + z**2 + x*y + y*z + z*x N = int(input()) A = [0 for i in range(10050)] for i in range(1,105): for j in range(1,105): for k in range(1,105): tmp = foo(i,j,k) if tmp < 10050: A[tmp] += 1 for i in range(1,N+1): print(A[i])
n = int(input()) N = n arr = [n] while n % 2 == 0: arr.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: arr.append(f) n //= f else: f += 2 if n != 1: arr.append(n) arr.sort() import collections c = collections.Counter(arr) k = list(c.keys()) v = list(c.values()) x = [] for i in range(len(k)): for p in range(1,v[i]+1): x.append(k[i]**p) x.sort() ans = 0 n = N while n != 1 and len(x) != 0: if n % x[0] == 0: n //= x[0] x.pop(0) ans += 1 else: x.pop(0) print(ans)
0
null
12,374,284,708,160
106
136
n = int(input()) lst = list(input()) cnt = 0 Num = [] for i in range(10): for j in range(10): for k in range(10): s = [str(i),str(j),str(k)] Num.append(s) for num in Num: flag1 = False flag2 = False memo1 = 0 memo2 = 0 for x in range(n-2): if num[0] == lst[x]: flag1 = True memo1 = x break if flag1: for y in range(memo1+1,n-1): if num[1] == lst[y]: flag2 = True memo2 = y break if flag2: for z in range(memo2+1,n): if num[2] == lst[z]: cnt += 1 break print(cnt)
n=int(input()) s=input() from itertools import product cnt=0 for i,j in product("0123456789",repeat=2): try: ind_i=s.index(i) except: continue try: ind_j=s.rindex(j) except: continue if ind_i>ind_j: continue for k in "0123456789": cnt+=(k in s[ind_i+1:ind_j]) print(cnt)
1
128,230,542,190,000
null
267
267
# coding: utf-8 def gcd(a, b): if a < b: a, b = b, a while b: a, b = b, a % b return a def main(): a, b = map(int, raw_input().split()) print gcd(a, b) if __name__ == '__main__': main()
def gcd(a,b): if a%b==0: return b else : return gcd(b,a%b) def main(): a,b=map(int,raw_input().split()) print(gcd(a,b)) if __name__=='__main__': main()
1
7,700,664,060
null
11
11
import sys r, c = [ int( val ) for val in sys.stdin.readline().split( " " ) ] csums = [0]*c rsum = 0 output = [] for k in range( r ): matrix = [ int( val ) for val in sys.stdin.readline().split( " " ) ] rsum = 0 for i in range( c ): rsum += matrix[i] output.append( "{:d} ".format( matrix[i] ) ) csums[i] += matrix[i] output.append( "{:d}\n".format( rsum ) ) rsum = 0 for val in csums: rsum += val output.append( "{:d} ".format( val ) ) output.append( "{:d}".format( rsum ) ) print( "".join( output ) )
def gcd(x, y): '''?????????????????????????????? x>=y?????¨??????gcd(x, y)??¨gcd(y, x%y)?????????????????¨????????¨??????''' if x < y: x, y = y, x while y > 0: x, y = y, x % y return x def test(): '''??? input = 147 105 -> 21''' x, y = map(int, input().split()) result = gcd(x, y) print(result) if __name__ == '__main__': test()
0
null
668,892,158,572
59
11
N = int(input()) A = [int(x) for x in input().split()] # M以下の整数の素因数分解を高速に # 前処理O(MloglogM) # 一計算O(logK) def mae_syori(M): D = [0] * (M + 1) for i in range(2, M+1): if D[i] != 0: continue # print(i, list(range(i*2, M + 1, i))) for j in range(i*2, M+1, i): if D[j] == 0: D[j] = i return D def p_bunkai(K): assert 2 <= K <= len(D)-1 k = K ret = [] while True: if k == 1: break if D[k] == 0: ret.append((k, 1)) break else: p = D[k] count = 0 while k % p == 0: count += 1 k //= p ret.append((p, count)) return ret # 最大公約数 # ユークリッドの互除法 def my_gcd(a, b): if b == 0: return a else: return my_gcd(b, a%b) c_gcd = A[0] for a in A: c_gcd = my_gcd(c_gcd, a) if c_gcd == 1: max_A = max(A) D = mae_syori(max_A) yakusu = set() ok = True for a in A: if a == 1: continue p_bunkai_result = p_bunkai(a) p_list = [p[0] for p in p_bunkai_result] for p in p_list: if p not in yakusu: yakusu.add(p) else: ok = False if not ok: break if ok: print('pairwise coprime') else: print('setwise coprime') else: print('not coprime')
from sys import stdin readline = stdin.buffer.readline def r_map(): return map(int, readline().rstrip().split()) def r_list(): return list(r_map()) def main(): N = int(readline().rstrip()) A = r_list() M = max(A) d = [0] * (M + 1) g = True for a in A: d[a] += 1 for i in range(2, M + 1): c = sum(d[i::i]) if c == N: print("not coprime") exit() elif c > 1: g = False if g: print('pairwise coprime') else: print('setwise coprime') if __name__ == "__main__": main()
1
4,134,203,591,138
null
85
85
import math a,b=map(int,input().split()) count=1 while True: c=count*0.08 d=count*0.1 if math.floor(c)==a and math.floor(d)==b: print(count) break count+=1 if count>1500: print(-1) break
#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 # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g import sys sys.setrecursionlimit(10000000) #mod = 10**9 + 7 #mod = 9982443453 mod = 998244353 def readInts(): return list(map(int,input().split())) def I(): return int(input()) #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 # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 def readInts(): return list(map(int,input().split())) def I(): return int(input()) n = I() A = sorted(readInts(), reverse=True) ans = 0 dic = defaultdict(int) dq = deque() for i in range(n): if i == 0: dq.append(A[i]) else: ans += dq.popleft() for j in range(2): dq.append(A[i]) print(ans)
0
null
32,702,473,886,460
203
111
#coding:utf-8 N = int(input()) A = [int(i) for i in input().split()] A.sort(reverse = True) k = N-2 index = 1 ans = A[0] while k > 0: if k > 1: k -= 2 ans += A[index] * 2 elif k == 1: k -= 1 ans += A[index] index += 1 print("{}".format(ans))
def main(): n = int(input()) a_list = sorted(list(map(int, input().split())), reverse=True) ans = a_list[0] cnt = 1 i = 1 while True: if cnt >= n - 2: break ans += a_list[i] * 2 i += 1 cnt += 2 if cnt == n - 2: ans += a_list[i] print(ans) if __name__ == "__main__": main()
1
9,219,187,899,390
null
111
111
n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) total = a[0] for i in range(n-2): total += a[i//2+1] print(total)
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) l = [A[0]] for i in range(1, N): l.append(A[i]) l.append(A[i]) print(sum(l[:N-1]))
1
9,089,209,999,816
null
111
111