code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
A, B, C, K = map( int, input().split()) ret = min( A, K ) if A < K: ret -= max( 0, K - A - B ) print( ret )
x = input().split() for i in range(5): if x[i] == '0': print(i+1)
0
null
17,791,815,129,242
148
126
str=input() l=len(str) n=0 while l>0: n=n+int(str[l-1]) l=l-1 if n%9 == 0: print("Yes") else : print("No")
print((1000 - (int(input()) % 1000)) % 1000)
0
null
6,395,916,348,040
87
108
from collections import Counter N = int(input()) S = input() ans = 0 for x in range(10): for y in range(10): hantei = [] for i in range(N): if x != int(S[i]): continue for j in range(i+1, N): if y != int(S[j]): continue for k in range(j+1, N): hantei.append(S[k]) ans += len(Counter(hantei)) break break print(ans)
import sys import heapq, math from itertools import zip_longest, permutations, combinations, combinations_with_replacement from itertools import accumulate, dropwhile, takewhile, groupby from functools import lru_cache from copy import deepcopy class UnionFind: def __init__(self, n: int): self._n = n self._parents = [i for i in range(n)] self._rank = [1 for _ in range(n)] def unite(self, x: int, y: int) -> None: px = self.find(x) py = self.find(y) # 一致していないときはリンクをつける if px != py: self._link(px, py) def _link(self, x: int, y: int): if self._rank[x] < self._rank[y]: self._parents[x] = y elif self._rank[x] > self._rank[y]: self._parents[y] = x else: self._parents[x] = y self._rank[y] += 1 def same(self, x: int, y: int) -> bool: px = self.find(x) py = self.find(y) return px == py def find(self, x: int) -> int: if self._parents[x] == x: return x self._parents[x] = self.find(self._parents[x]) return self._parents[x] N, M = map(int, input().split()) uf = UnionFind(N + 1) for i in range(M): A, B = map(int, input().split()) uf.unite(A, B) s = set() for i in range(1, N + 1): s.add(uf.find(i)) print(len(s) - 1)
0
null
65,256,021,876,500
267
70
n = int(input()) s = input() r, g, b = [], [], [] cnt = 1 for i in s: if i == 'R': r.append(cnt) elif i == 'G': g.append(cnt) else: b.append(cnt) cnt += 1 rd = set(map(lambda x: x * 2, r)) #以下2つ目の条件を満たさないもの(j - i = k - j)の数え上げ gd = set(map(lambda x: x * 2, g)) bd = set(map(lambda x: x * 2, b)) ddc = 0 for i in r: for j in g: if i + j in bd: ddc += 1 for j in g: for k in b: if j + k in rd: ddc += 1 for i in r: for k in b: if i + k in gd: ddc += 1 print(len(r) * len(g) * len(b) - ddc) #1つ目の条件を満たすモノから2つ目の条件を満たさないものを引く
N = int(input()) S = input() r = [0 for _ in range(N + 1)] g = [0 for _ in range(N + 1)] b = [0 for _ in range(N + 1)] for i in reversed(range(N)): r[i] = r[i + 1] g[i] = g[i + 1] b[i] = b[i + 1] if S[i] == "R": r[i] += 1 if S[i] == "G": g[i] += 1 if S[i] == "B": b[i] += 1 ans = 0 for i in range(N): if S[i] == "R": for j in range(i + 1, N): if S[j] == "G": if 2 * j - i < N: if S[2 * j - i] == "B": ans += (b[j + 1] - 1) else: ans += b[j + 1] else: ans += b[j + 1] for i in range(N): if S[i] == "R": for j in range(i + 1, N): if S[j] == "B": if 2 * j - i < N: if S[2 * j - i] == "G": ans += (g[j + 1] - 1) else: ans += g[j + 1] else: ans += g[j + 1] for i in range(N): if S[i] == "B": for j in range(i + 1, N): if S[j] == "R": if 2 * j - i < N: if S[2 * j - i] == "G": ans += (g[j + 1] - 1) else: ans += g[j + 1] else: ans += g[j + 1] for i in range(N): if S[i] == "B": for j in range(i + 1, N): if S[j] == "G": if 2 * j - i < N: if S[2 * j - i] == "R": ans += (r[j + 1] - 1) else: ans += r[j + 1] else: ans += r[j + 1] for i in range(N): if S[i] == "G": for j in range(i + 1, N): if S[j] == "R": if 2 * j - i < N: if S[2 * j - i] == "B": ans += (b[j + 1] - 1) else: ans += b[j + 1] else: ans += b[j + 1] for i in range(N): if S[i] == "G": for j in range(i + 1, N): if S[j] == "B": if 2 * j - i < N: if S[2 * j - i] == "R": ans += (r[j + 1] - 1) else: ans += r[j + 1] else: ans += r[j + 1] print(ans)
1
36,083,121,817,080
null
175
175
S,T=map(str,input().split()) res =T+S print(res)
#!/usr/bin/env python3 import sys import numpy as np import numba from numba import i8 input = sys.stdin.buffer.readline mod = 998244353 def I(): return int(input()) def MI(): return map(int, input().split()) @numba.njit((i8, i8[:]), cache=True) def main(N, LR): L, R = LR[::2], LR[1::2] K = len(L) dp = np.zeros(N + 1, np.int64) dpsum = np.zeros(N + 1, np.int64) dp[1] = 1 dpsum[1] = 1 for i in range(2, N + 1): for k in range(K): li = i - R[k] ri = i - L[k] if ri < 0: continue li = max(li, 1) dp[i] += dpsum[ri] - dpsum[li - 1] dp[i] %= mod dpsum[i] = dpsum[i - 1] + dp[i] dpsum[i] %= mod return dp[N] N, K = MI() LR = np.array(sys.stdin.buffer.read().split(), np.int64) print(main(N, LR))
0
null
52,959,390,857,620
248
74
from collections import Counter n,*a = map(int,open(0).read().split()) s = set(a) c = Counter(a) m = max(s) l = [True]*(m+1) ans = 0 for i in range(1,m+1): if i in s and l[i]: if c[i] == 1: ans += 1 for j in range(1,m//i+1): l[i*j] = False print(ans)
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys def main(N, A): C = [0] * (10**6 + 1) for a in A: if C[a] == 1: C[a] = -1 continue if C[a] == -1: continue C[a] = 1 for b in range(a + a, 10 ** 6 + 1, a): C[b] = -1 ans = 0 for a in A: if C[a] == 1: ans += 1 print(ans) if __name__ == '__main__': input = sys.stdin.readline N = int(input()) *A, = map(int, input().split()) main(N, A)
1
14,500,425,851,010
null
129
129
N = int(input()) A = list(map(int, input().split())) MOD = 10**9 + 7 def gcd(n, m): if m == 0: return n return gcd(m, n % m) def lcm(a, b): return a * b // gcd(a, b) L = 1 for a in A: L = lcm(L, a) L %= MOD coef = 0 for a in A: coef += pow(a, MOD - 2, MOD) print((L * coef) % MOD)
s,t=map(str,input().split()) print(t,s,sep="")
0
null
95,755,991,206,880
235
248
import collections n = int(input()) num_list = list(map(int, input().split())) all = 0 c = collections.Counter(num_list) for i in c: all += c[i]*(c[i]-1)//2 for k in range(n): print(all - c[num_list[k]] + 1)
N = int(input()) As = list(map(int, input().split())) count_dict = {} def calc_combo(n): return int(n * (n - 1) / 2) for i in range(N): try: count_dict[As[i]] += 1 except KeyError: count_dict[As[i]] = 1 combo = 0 for key in count_dict: combo += calc_combo(count_dict[key]) for i in range(N): num_delete = As[i] try: num_count = count_dict[num_delete] out = combo - calc_combo(num_count) + calc_combo(num_count - 1) print(out) except KeyError: print(combo)
1
47,661,372,897,082
null
192
192
n, q = map(int, input().split()) que = [] for i in range(n): p, t = map(str, input().split()) que.append([p, int(t)]) total = 0 while que != []: pt = que.pop(0) if pt[1] <= q: total += pt[1] print(pt[0], total) else: total += q que.append([pt[0], pt[1]-q])
import collections import sys n,q = map(int,input().split()) data = [[i for i in input().split()]for i in range(n)] time = 0 while data: task = data[0] del data[0] if int(task[1]) <= q: time += int(task[1]) print(task[0],time) else: time += q task[1] = str(int(task[1]) - q) data.append(task)
1
44,156,859,780
null
19
19
k = int(input()) a, b = map(int, input().split()) ans = 0 for i in range(a, b+1, 1): if i%k == 0: ans = 1 break if ans == 1: print("OK") else: print("NG")
K = int(input()) A,B = map(int,input().split()) li = [] for i in range(A,B+1): li.append(i) ans = False for j in li: if j%K == 0: ans = True break else: ans = False if ans == True:print("OK") else:print("NG")
1
26,553,412,989,990
null
158
158
N=int(input()) A=list(map(int, input().split())) if len(set(A))==N: print("YES") else: print("NO")
import sys N=int(input()) A=list(map(int,input().split())) A.sort() for i in range(N-1): if(A[i]==A[i+1]): print("NO") sys.exit() print("YES")
1
74,218,692,546,460
null
222
222
x=input() arr=['SUN','MON','TUE','WED','THU','FRI','SAT'] print(7-arr.index(x))
import math n = int(input()) class Coordinate: def __init__(self,x,y): self.x = x self.y = y def Koch(n,p1,p2): if n == 0: return else: s = Coordinate(2/3 * p1.x + 1/3 * p2.x, 2/3 * p1.y + 1/3 * p2.y) u = Coordinate(1/3 * p1.x + 2/3 * p2.x, 1/3 * p1.y + 2/3 * p2.y) t = Coordinate(1/2*(u.x-s.x) - math.sqrt(3)/2*(u.y-s.y) + s.x, math.sqrt(3)/2*(u.x-s.x) + 1/2*(u.y-s.y) + s.y) Koch(n-1,p1,s) print(str(s.x) +" "+str(s.y)) Koch(n-1,s,t) print(str(t.x) +" "+str(t.y)) Koch(n-1,t,u) print(str(u.x) +" "+str(u.y)) Koch(n-1,u,p2) p1 = Coordinate(0,0) p2 = Coordinate(100,0) print(str(p1.x) +" "+str(p1.y)) Koch(n,p1,p2) print(str(p2.x) +" "+str(p2.y))
0
null
66,276,749,519,082
270
27
S=input() B=0 B=S[0]+S[1]+S[2] print(B)
S = input() ans = S[0] + S[1] + S[2] print(ans)
1
14,812,955,563,290
null
130
130
from time import time from random import randint def func(s, x): last = [0] * 26 score = 0 for i, v in enumerate(x, 1): last[v] = i c = 0 for j in range(26): c += s[j] * (i - last[j]) score += s[i * 26 + v] - c return score def main(): start = time() d, *s = map(int, open(0).read().split()) x = ([*range(26)] * 15)[:d] M = func(s, x) while time() - start < 1.8: y = x[:] if randint(0, 1): y[randint(0, d - 1)] = randint(0, 25) elif randint(0, 1): i=randint(0, d - 16) j=randint(i + 1, i + 15) y[i], y[j] = y[j], y[i] else: i = randint(0, d - 15) j = randint(i + 1, i + 7) k = randint(j + 1, j + 7) if randint(0, 1): y[i], y[j], y[k] = y[j], y[k], y[i] else: y[i], y[j], y[k] = y[k], y[i], y[j] t = func(s, y) if t > M: M = t x = y for t in x: print(t + 1) main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines import numpy as np def main(): n, m, k = map(int, input().split()) a = np.array(readline().split(), np.int64) b = np.array(readline().split(), np.int64) aa = a.cumsum() ba = b.cumsum() r = np.searchsorted(ba, k, side='right') for i1, aae in enumerate(aa): if k < aae: break r = max(r, np.searchsorted(ba, k - aae, side='right') + i1 + 1) print(r) if __name__ == '__main__': main()
0
null
10,213,766,180,892
113
117
N = int(input()) A = list(map(int,input().split())) minm = A[0] ans = 0 for i in range(1,N): if A[i] < minm: ans += minm - A[i] if A[i] > minm: minm = A[i] print(ans)
n = int(input()) a = list(map(int,input().split())) ans = 0 for i in range(n-1): if a[i] <= a[i+1]: pass else: ans += a[i] - a[i+1] a[i+1] = a[i] print(ans)
1
4,518,374,983,612
null
88
88
from collections import defaultdict import bisect N = int(input()) S = input() # s2i = [[] for i in range(10)] s2i = defaultdict(list) for i, si in enumerate(S): s2i[si] += [i] ans = 0 for i in range(1000): pin = str(i).zfill(3) ii = -1 flag = True for p in pin: s2ip = s2i[p] if s2ip: iii = bisect.bisect_right(s2ip, ii) if iii == len(s2ip): flag = False break ii = s2ip[iii] else: flag = False break if flag: ans += 1 print(ans)
s = input() l = s.split(" ") a,b = int(l[0]), int(l[1]) print(a*b)
0
null
72,455,341,020,180
267
133
from itertools import combinations n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) answer = ['no']*q for i in range(1, n+1): for nums in combinations(a, i): val = sum(nums) if val in m: index = [i for i, num in enumerate(m) if val == num] for i in index: answer[i] = 'yes' for i in answer: print(i)
# -*- coding: utf-8 -*- """ 全探索 ・再帰で作る ・2^20でTLEするからメモ化した """ N = int(input()) aN = list(map(int, input().split())) Q = int(input()) mQ = list(map(int, input().split())) def dfs(cur, depth, ans): # 終了条件 if cur == ans: return True # memo[現在位置]に数値curがあれば、そこから先はやっても同じだからやらない if cur in memo[depth]: return False memo[depth].add(cur) # 全探索 for i in range(depth, N): if dfs(cur+aN[i], i+1, ans): return True # 見つからなかった return False for i in range(Q): memo = [set() for j in range(N+1)] if dfs(0, 0, mQ[i]): print('yes') else: print('no')
1
100,772,298,130
null
25
25
while True: s = raw_input() if s == '0': break n = 0 for i in s: n += int(i) print n
while True: input = raw_input() if input == "0": break sum = 0 for i in xrange(len(input)): sum += int(input[i]) print sum
1
1,588,063,571,960
null
62
62
n = input() list = map(int, input().split()) num = 1 a = 0 for i in list: if i == num: num = num +1 else: a = a + 1 if num == 1: print(-1) else: print(a)
for i in range(9): i=i+1 for j in range(9): j=j+1 print(str(i)+'x'+str(j)+'='+str(i*j))
0
null
57,249,138,698,720
257
1
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * X = INT() lim = 10**5+1 dp = [0]*lim t = [100 + i for i in range(6)] for i in range(6): dp[100+i] = 100+i for j in range(106, lim): dp[j] += sum([dp[j-k] for k in t]) if dp[X] == 0: print("0") else: print("1")
X = int(input()) dp = [False]*(X+1) dp[0] = True for i in range(100, X+1): if i < 106: dp[i] = True continue if dp[i-100] or dp[i-101] or dp[i-102] or dp[i-103] or dp[i-104] or dp[i-105]: dp[i] = True print(1) if dp[len(dp)-1] else print(0)
1
127,076,101,912,760
null
266
266
import sys from decimal import Decimal sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): a, b, c = input().split() print("Yes" if Decimal(a) ** Decimal(0.5) + Decimal(b) ** Decimal(0.5) < Decimal(c) ** Decimal(0.5) else "No") if __name__ == '__main__': resolve()
A, B, C = map(int, input().split()) x = A * B * 4 y = (C - A - B) ** 2 if x < y and C - A - B > 0: print("Yes") else: print("No")
1
51,519,872,610,828
null
197
197
mod = pow(10, 9) + 7 def main(): N, K = map(int, input().split()) table = [0]*(K+1) for k in range(K, 0, -1): m = K//k tmp = pow(m, N, mod) for l in range(2, m+1): tmp -= table[l*k] tmp %= mod table[k] = tmp ans = 0 for i in range(len(table)): ans += (i * table[i])%mod ans %= mod #print(table) print(ans) if __name__ == "__main__": main()
H = int(input()) W = int(input()) N = int(input()) N += max(H-1,W-1) ans = N//max(H,W) print(ans)
0
null
62,356,750,348,874
176
236
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * a, b, c = MAP() if Decimal(a)**Decimal("0.5") + Decimal(b)**Decimal("0.5") < Decimal(c)**Decimal("0.5"): print("Yes") else: print("No")
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n = int(input()) s = input() res = s.count('R') * s.count('G') * s.count('B') if res == 0: print(0) sys.exit() for i1 in range(n): for i2 in range(i1+1, n): i3 = i2 * 2 - i1 if i3 <= n - 1: if s[i1] != s[i2] and s[i1] != s[i3] and s[i2] != s[i3]: res -= 1 print(res) if __name__ == '__main__': main()
0
null
43,887,236,214,332
197
175
def main(): H, W, M = map(int, input().split()) cnth = [[0, i] for i in range(H)] cntw = [[0, i] for i in range(W)] L = set() for _ in range(M): h, w = map(lambda x: int(x) - 1, input().split()) cnth[h][0] += 1 cntw[w][0] += 1 L.add((h, w)) cnth.sort(reverse=True) cntw.sort(reverse=True) mh = set() ph = cnth[0] for h in cnth: if ph[0] == h[0]: mh.add(h[1]) else: break ph = h mw = set() pw = cntw[0] for w in cntw: if pw[0] == w[0]: mw.add(w[1]) else: break pw = w maxans = cnth[0][0] + cntw[0][0] for h in mh: for w in mw: if not ((h, w) in L): print(maxans) break else: continue break else: print(maxans - 1) if __name__ == "__main__": main()
r, c = map(int, input().split()) mat = [list(map(int, input().split())) for i in range(r)] for row in mat: row.append(sum(row)) print(*row) colSum = [sum(col) for col in zip(*mat)] print(*colSum)
0
null
3,031,341,383,170
89
59
def main(): a = list(map(int,input().split())) ans = 0 for i in range(5): ans += a[i] print(15 - ans) main()
std_value = [] while True: n = int(input()) if n == 0: break s = [int(i) for i in input().split()]#生徒の点数 sum_value=0 s_ave = 0 for i in range(len(s)):#平均値計算 sum_value += s[i] ave = sum_value/len(s) for j in range(len(s)): s_ave += (s[j]-ave)**2 std_value.append((s_ave/len(s))**(1/2)) for k in range(len(std_value)): print("{:.8f}".format(std_value[k]))
0
null
6,840,162,368,718
126
31
n = int(input()) a = list(map(int, input().split())) num = [0]*(10**6+1) for x in a: if num[x] != 0: num[x] = 2 continue for i in range(x, 10**6+1, x): num[i] += 1 ans = 0 for x in a: if num[x] == 1: ans += 1 print(ans)
import sys import math from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)] #隣接リスト 1-order def make_adjlist_d(n, edges): res = [[] for _ in range(n + 1)] for edge in edges: res[edge[0]].append(edge[1]) res[edge[1]].append(edge[0]) return res def make_adjlist_nond(n, edges): res = [[] for _ in range(n + 1)] for edge in edges: res[edge[0]].append(edge[1]) return res #nCr def cmb(n, r): return math.factorial(n) // math.factorial(r) // math.factorial(n - r) def main(): N = NI() A = NLI() A = sorted(A) ma = A[-1] hurui = [0] * (ma + 10) for a in A: if hurui[a] == 0: hurui[a] = 1 else: hurui[a] = 10 for a in A: if hurui[a] == 0: continue for i in range(a*2, ma+10, a): hurui[i] = 0 print(hurui.count(1)) if __name__ == "__main__": main()
1
14,393,015,828,760
null
129
129
n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) b2=[] b2.append(0) for i in range(1,m+1): b2.append(b2[i-1]+b[i-1]) a.insert(0,0) cnt=0 a_sum=0 for i in range(n+1): j=m a_sum+=a[i] while True: if k>=a_sum+b2[j]: cnt=max(cnt,i+j) m=j break j-=1 if j <0: break print(cnt)
n, m, k = map(int, input().split(" ")) a = [0]+list(map(int, input().split(" "))) b = [0]+list(map(int, input().split(" "))) for i in range(1, n+1): a[i] += a[i - 1] for i in range(1, m+1): b[i] += b[i - 1] j,mx= m,0 for i in range(n+1): if a[i]>k: break while(b[j]>k-a[i]): j-=1 if (i+j>mx): mx=i+j print(mx)
1
10,765,696,702,882
null
117
117
def partpall(s,n): if s!=s[::-1]: return False else: return True def pall(s,n): if s!=s[::-1]: return False return partpall(s[n//2 +1 :],n) and partpall(s[:n//2 ],n) # s=input("enter:") s=input() # print("sucess",s,s[::-1]) # revStr=s[::-1] n=len(s) # print(n) if pall(s,n): print("Yes") else: print("No")
# String Palindrome def is_palindrome(s): res = s == s[::-1] return res S = input() N = len(S) ans = ['No', 'Yes'][is_palindrome(S) & is_palindrome(S[:((N-1)//2)]) & is_palindrome(S[((N+1)//2):])] print(ans)
1
46,113,394,209,568
null
190
190
N,K = map(int,input().split()) M = list(map(int,input().split())) M =sorted(M,reverse=True) print(sum(M[K:]))
N,K = map(int,input().split()) H = list(map(int,input().split())) H.sort() reversed(H) for i in range(K): if len(H)==0: break else: H.pop() if len(H)==0: print(0) else: print(sum(H))
1
79,237,699,499,832
null
227
227
# print('input >>') N, K = map(int,(input().split())) ps = list(map(int,(input().split()))) ps.sort() # print('-----output-----') print(sum(ps[:K]))
#B問題 ans = 0 n, k = map(int, input().split()) P = list(map(int, input().split())) for i in range(k): ans += min(P) P.remove(min(P)) print(ans)
1
11,578,676,832,040
null
120
120
n,x,y = map(int,input().split()) ans = [0]*n for i in range(1,n+1): for j in range(i+1,n+1): if i <= x and j >= y: a = abs(j-i)-abs(y-x)+1 b = abs(i-x)+abs(j-y)+1 ans[min(a,b)] += 1 else: c = abs(x-i)+abs(y-j)+1 d = abs(j-i) ans[min(c,d)] += 1 for i in range(1,n): print(ans[i])
import itertools n, x, y = map(int, input().split()) k = [0] * n for v in itertools.combinations(list(range(1,n+1)), 2): k[min(abs(v[1]-v[0]),abs(x-min(v))+1+abs(y-max(v)))] += 1 for item in k[1:]: print(item)
1
44,123,277,259,876
null
187
187
import math n, x, t = input().split() answer = math.ceil(int(n) / int(x)) * int(t) print(answer)
n, x, t = map(lambda x: int(x), input().split()) if n % x == 0: group = n // x else: group = n // x + 1 answer = group * t print(answer)
1
4,259,753,299,424
null
86
86
from math import factorial as fac x,y=map(int,input().split()) a=2*y-x b=2*x-y mod=10**9+7 if a>=0 and b>=0 and a%3==0 and b%3==0: a=a//3 b=b//3 a1=1 a2=1 n3=10**9+7 for i in range(a): a1*=a+b-i a2*=i+1 a1%=n3 a2%=n3 a2=pow(a2,n3-2,n3) print((a1*a2)%n3) else: print(0)
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): S = SS() len_S = len(S) ans = 0 for i in range(len_S // 2): if S[i] != S[len_S-1-i]: ans += 1 print(ans) if __name__ == '__main__': resolve()
0
null
135,206,837,937,230
281
261
N=input().split(" ");print(N[1]+N[0])
N, K = map(int,input().split()) P = list(map(int,input().split())) P.sort() price = sum(P[:K]) print(price)
0
null
57,395,996,006,610
248
120
s = input() k = int(input()) li = list(s) lee = len(s) if len(list(set(li))) == 1: print((lee)*k//2) exit() def motome(n,list): count = 0 kaihi_flag = False li = list*n for i,l in enumerate(li): if i == 0: continue if l == li[i-1] and not kaihi_flag: count += 1 kaihi_flag = True else: kaihi_flag = False #print(count) #print(count*k) return count if k >= 5 and k%2 == 1: a = motome(3,li) b = motome(5,li) diff = b - a ans = b + (k-5)//2*diff print(ans) elif k >=5 and k%2 == 0: a = motome(2,li) b = motome(4,li) diff = b - a ans = b + (k-4)//2*diff print(ans) else: count = 0 kaihi_flag = False li = li*k for i,l in enumerate(li): if i == 0: continue if l == li[i-1] and not kaihi_flag: count += 1 kaihi_flag = True else: kaihi_flag = False #print(count) #print(count*k) print(count)
s = input() k = int(input()) s_list = [] ans = 0 def rle(s): tmp, count = s[0], 1 for i in range(1, len(s)): if tmp == s[i]: count += 1 else: s_list.append(count) tmp = s[i] count = 1 s_list.append(count) return rle(s) if len(s_list) >= 2: for i in range(len(s_list)): if s_list[i] >= 2: ans += s_list[i] // 2 ans *= k if (s_list[0] + s_list[-1]) % 2 == 0 and s[0] == s[-1]: ans += k - 1 else: ans = len(s) * k // 2 print(ans)
1
176,016,630,255,450
null
296
296
N = list(map(int, input().split())) if sum(N) % 9: print('No') else: print('Yes')
# def f(n): # if n < 2: # return 1 # else: # return n * f(n - 2) # for i in range(2, 150, 2): # print(i, f(i)) N = int(input()) if N % 2 == 1: print(0) exit() k = 10 cnt = 0 while k <= N: cnt += N // k k *= 5 print(cnt)
0
null
59,920,072,496,338
87
258
a,b,c = map(int,input().split(" ")) ptn = 0 if a==b and a==c: print(1) ptn = 1 if a==b and a!=c: if a < c: print(1) ptn=2 else: print(0) ptn=2 cnt = 0 for i in range(a,b+1): if c%i == 0: cnt += 1 if ptn != 1 and ptn != 2: print(cnt)
#!python3 from time import perf_counter tick = perf_counter() + 1.92 import sys iim = lambda: map(int, sys.stdin.readline().rstrip().split()) from random import randrange from bisect import bisect def resolve(): G = 26 it = map(int, sys.stdin.read().split()) D = next(it) C = [next(it) for i in range(G)] S = [[next(it) for i in range(G)] for i in range(D)] L = [[-1] for i in range(G)] T = [0] * D def update(di, qi): score = 0 t0 = T[di] score += S[di][qi]-S[di][t0] a1 = li = L[t0][:] ii = li.index(di) la = D if len(li)-1 == ii else li[ii+1] score -= C[t0] * (di-li[ii-1])*(la-di) li.pop(ii) a2 = li = L[qi][:] ii = bisect(li, di) li.insert(ii, di) la = D if len(li)-1 == ii else li[ii+1] score += C[qi] * (di-li[ii-1])*(la-di) return score, (a1, a2) U = 7 def calc(i, j): score = S[i][j] for k in range(G): u = k - L[k][-1] score -= C[k] * (u + u + U) * U // 2 score += C[k] * U * (i-L[j][-1]) return score for di in range(D): i, score = 0, calc(di, 0) for qi in range(1, G): x = calc(di, qi) if x > score: i, score = qi, x T[di] = i L[i].append(di) while perf_counter() < tick: di, qi = randrange(0, D), randrange(0, G) diff, swap = update(di, qi) if diff > 0: score += diff q0, T[di] = T[di], qi L[q0], L[qi] = swap print(*(i+1 for i in T), sep="\n") if __name__ == "__main__": resolve()
0
null
5,075,671,966,688
44
113
N = int(input()) A = list(map(int,input().split())) MOD = 10**9 + 7 S = sum(A) ans = 0 for i in range(N): S = S - A[i] ans += A[i]*S print(ans%MOD)
#cやり直し import numpy n = int(input()) a = list(map(int, input().split())) ans = 0 mod = 10**9 +7 before = a[-1] for i in range(n-1,0,-1): ans += (a[i-1]*before)%mod before += a[i-1] print(ans%mod)
1
3,825,334,989,362
null
83
83
import sys import copy #import math #import itertools #import numpy as np #import re def func(x,m): return x**2%m N,X,M=[int(c) for c in input().split()] myset = {X} mydict = {X:0} A = [] A.append(X) s = X i = 0 i_stop = i #i=0は計算したので1から for i in range(1,N): A.append(func(A[i-1],M)) if A[i] in myset: i_stop = i break myset.add(A[i]) mydict[A[i]] = i s+=A[i] if i == N-1: print(s) sys.exit(0) if A[i] == 0: print(s) sys.exit(0) if i!=0: #最後にA[i]が出現したのは? A_repeat = A[mydict[A[i_stop]]:i_stop] s+=((N-1)-(i_stop-1))//len(A_repeat)*sum(A_repeat) for k in range(((N-1)-(i_stop-1))%len(A_repeat)): s+=A_repeat[k] print(s)
N, X, M = map(int, input().split()) NN = N li = [] isused = [False] * M while isused[X] == False and N != 0: li.append(X) isused[X] = True X = (X ** 2) % M N -= 1 if N == 0: print(sum(li)) elif N != 0 and X in li: l = len(li) s = li.index(X) T = l - s q = (NN - s) // T r = (NN - s) % T print(sum(li) + sum(li[i] for i in range(s, len(li))) * (q-1) + sum(li[i] for i in range(s, s + r)))
1
2,805,384,578,656
null
75
75
from typing import List from collections import deque def bfs(G: List[int], s: int) -> None: d[s] = 0 color[s] = "GRAY" Q = deque() Q.append(s) while Q: u = Q.popleft() for v in G[u]: if color[v] == "WHITE": color[v] = "GRAY" d[v] = d[u] + 1 pi[v] = u Q.append(v) color[u] = "BLACK" if __name__ == "__main__": n = int(input()) G = [[] for _ in range(n)] for _ in range(n): u, k, *adj = list(map(int, input().split())) u -= 1 G[u] = [v - 1 for v in adj] color = ["WHITE" for _ in range(n)] d = [-1 for _ in range(n)] pi = [None for _ in range(n)] bfs(G, 0) for i in range(n): print(f"{i + 1} {d[i]}")
from collections import deque def main(): n = int(input()) _next = [[] for _ in range(n)] for _ in range(n): u, k, *v = map(lambda s: int(s) - 1, input().split()) _next[u] = v queue = deque() queue.append(0) d = [-1] * n d[0] = 0 while queue: u = queue.popleft() for v in _next[u]: if d[v] == -1: d[v] = d[u] + 1 queue.append(v) for i, v in enumerate(d, start=1): print(i, v) if __name__ == '__main__': main()
1
3,705,497,368
null
9
9
x = int(input()) def prime_check(n): f = 3 while f * f <= n: if n % f == 0: return False else: f += 2 else: return True if x != 2: if x % 2 == 0: x += 1 while 1: if prime_check(x) == True: print(x) break else: x += 2 else: print(2)
X = int(input()) def is_prime(n): a = 2 while a*a < n: if n%a == 0: return False a += 1 return True while True: if is_prime(X): break X += 1 print(X)
1
105,376,549,850,650
null
250
250
a, b, h, m = map(int, input().split()) from math import cos,sin, sqrt, radians x_a = - a * cos(radians(360/12.0*h+360/12/60*m)) y_a = a * sin(radians(360/12.0*h+360/12/60*m)) x_b = - b * cos(radians(360/60.0*m)) y_b = b * sin(radians(360/60.0*m)) print(sqrt((x_a-x_b)**2+(y_a-y_b)**2))
import sys R, C, K = list(map(int, input().split())) d = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)] t = [[0] * (C+1) for _ in range(R+1)] for i in range(K): r,c,v = list(map(int, input().split())) t[r][c] = v for i in range(R+1): for j in range(C+1): for k in range(4): if i!=0: d[0][i][j] = max(d[0][i][j], d[k][i-1][j]) d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j]) if j!=0: d[k][i][j] = max(d[k][i][j], d[k][i][j-1]) if k != 0: d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j]) a = 0 for i in range(4): a = max(a, d[i][-1][-1]) print(a)
0
null
12,794,650,425,030
144
94
n = int(input()) ns = list(map(int, input().split())) print(min(ns), max(ns), sum(ns))
C = input() N = ord(C) print(chr(N + 1))
0
null
46,333,952,774,120
48
239
a,c,b = list(map(int, input().split())) a = abs(a) b = abs(b) c = abs(c) if b*c <= a: print(a - (b*c)) else: c -= a//b a = a%b #print(a,b,c) if c%2==0: print(a) else: print(abs(a-b))
def maximum_volume(): """ 立方体に近いほど体積が大きくなる """ # 入力 L = int(input()) # 処理 one_side = L / 3 # 体積 return one_side ** 3 result = maximum_volume() print(result)
0
null
26,086,320,652,448
92
191
inp = input().split() A = int(inp[0]) B = int(inp[1].replace('.','')) print(A*B//100)
from decimal import Decimal import sys A,B = map(Decimal,input().split()) ans = int(A*B) print(ans)
1
16,546,492,087,850
null
135
135
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): H, W, K = map(int, input().split()) grid = [[_ for _ in input()] for _ in range(H)] ans = [[0] * W for _ in range(H)] cnt = 0 for h in range(H): for w in range(W): if grid[h][w] == '#': cnt += 1 ans[h][w] = cnt now = -1 for h in range(H): for w in range(W): if ans[h][w] != 0: now = ans[h][w] if ans[h][w] == 0: if now != -1: ans[h][w] = now now = -1 now = -1 for h in range(H): for w in reversed(range(W)): if ans[h][w] != 0: now = ans[h][w] if ans[h][w] == 0: if now != -1: ans[h][w] = now now = -1 for h in range(1,H): if ans[h][0] == 0: for w in range(W): ans[h][w] = ans[h - 1][w] for h in reversed(range(H-1)): if ans[h][0] == 0: for w in range(W): ans[h][w] = ans[h + 1][w] for a in ans: print(*a) resolve()
H, W, K = map(int, input().split()) cake = [input() for _ in range(H)] # 答え memo = [[0] * W for _ in range(H)] #print(memo) # 行にケーキが何個あるか cake_count_row = [0] * H for y in range(H): count = 0 for x in range(W): if cake[y][x] == "#": count += 1 cake_count_row[y] = count # イチゴがある行について色塗り count = 1 for y in range(H): first = True if cake_count_row[y] == 0: continue for x in range(W): if cake[y][x] == "#": if first: first = False else: count += 1 memo[y][x] = count count += 1 # イチゴがない行について色塗り # 上から下に for y in range(1, H): if cake_count_row[y] == 0: for x in range(W): memo[y][x] = memo[y-1][x] # 下から上に for y in range(H-1)[::-1]: if cake_count_row[y] == 0: for x in range(W): memo[y][x] = memo[y+1][x] # 出力 for i in range(H): print(" ".join(list(map(str, memo[i]))))
1
143,572,964,918,280
null
277
277
from collections import deque if __name__ == '__main__': n, q = map(int, input().split()) Q = deque() for i in range(n): name, time = input().split() Q.append([name, int(time)]) sum = 0 while Q: qt = Q.popleft() if qt[1] <= q: sum += qt[1] print(qt[0], sum) else: sum += q qt[1] -= q Q.append(qt)
# ALDS1_3_B # coding: utf-8 from collections import deque n, q = [int(i) for i in raw_input().split()] d = deque() for i in range(n): name, time = raw_input().split() time = int(time) d.append([name, time]) total = 0 while len(d) > 0: p = d.popleft() if p[1] <= q: # 終わり total += p[1] print "{} {}".format(p[0], total) else: total += q p[1] -= q d.append(p)
1
41,426,375,680
null
19
19
n=int(input()) print(int(n/2)-1 if n%2==0 else int((n-1)/2))
n = int(input()) print((n - (n+1)%2)//2)
1
153,185,722,472,352
null
283
283
N = int(input()) A_li = list(map(int, input().split())) is_rising = False money = 1000 stock = 0 for i in range(N - 1): if i == 0: if A_li[0] < A_li[1]: # できるだけ買う stock = money // A_li[0] money -= A_li[0] * stock is_rising = True else: if is_rising: if A_li[i] > A_li[i + 1]: # 全て売る money += A_li[i] * stock stock = 0 is_rising = False else: if A_li[i] < A_li[i + 1]: # できるだけ買う stock = money // A_li[i] money -= A_li[i] * stock is_rising = True if i + 1 == N - 1: # 全て売って終了 money += A_li[i+1] * stock stock = 0 print(money)
# Debt Hell n = int(input()) value = 100000 for i in xrange(n): value *= 1.05 if value % 1000 != 0: value = int(value / 1000 + 1) * 1000 print value
0
null
3,692,760,124,662
103
6
while(1): try: i = raw_input() a, b = map(int, i.split()) x, y = a, b while(b != 0): tmp = b b = a % b a = tmp print a, print x*y/a except: break
import math while True: try: a = list(map(int,input().split())) b = (math.gcd(a[0],a[1])) c = ((a[0]*a[1])//math.gcd(a[0],a[1])) print(b,c) except EOFError: break
1
455,154,612
null
5
5
import numpy as np N, T = map(int, input().split()) AB = [] for i in range(N): A, B = map(int, input().split()) AB.append([A, B]) AB.sort() dp = np.zeros(T, dtype=int) ans = 0 for a, b in AB: ans = max(ans, dp[-1] + b) dp[a:] = np.maximum(dp[a:], dp[:-a] + b) print(ans)
from itertools import chain N, T = map(int, input().split()) # A = [0]*(N+1) # B = [0]*(N+1) AB = [(0, 0)] for i in range(1, N+1): a, b = map(int, input().split()) # A[i] = a # B[i] = b AB.append((a, b)) AB.sort() dp = [[-1]*(6000+1) for _ in range(N+1)] #dp[i][t]: 注文後にt秒になっている時、i番目までを考慮したとき、 #の最大 dp[0][0] = 0 for i in range(1, N+1): a, b = AB[i] for t in range(T): dp[i][t+a] = max(dp[i][t+a], dp[i-1][t] + b) dp[i][t] = max(dp[i][t], dp[i-1][t]) print(max(chain.from_iterable(dp)))
1
151,938,466,665,270
null
282
282
s = int(input()) a = [] a.append(1) a.append(0) a.append(0) for i in range(3,s+1): a.append(sum(a)-a[i-1]-a[i-2]) ans = a[-1] % (10**9 + 7) print(ans)
MOD = 10**9 + 7 fac = [1 for k in range(200010)] inv = [1 for k in range(200010)] finv = [1 for k in range(200010)] for k in range(2,200010): fac[k] = (fac[k-1]*k)%MOD inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD finv[k] = (finv[k - 1] * inv[k]) % MOD; def nCr(n,r): return (fac[n]*finv[r]*finv[n-r])%MOD N, K = map(int,input().split()) A = sorted(list(map(int,input().split()))) m = 0 for k in range(N-K+1): m += A[k]*nCr(N-k-1,K-1) m %= MOD A = A[::-1] M = 0 for k in range(N-K+1): M += A[k]*nCr(N-k-1,K-1) M %= MOD print(M-m if M>=m else M-m+MOD)
0
null
49,282,162,895,222
79
242
n = int(input()) sum = (1 + n) * n // 2 sho_3 = n // 3 sho_5 = n // 5 sho_15 = n // 15 s_3 = (sho_3 * 3 + 3) * sho_3 // 2 s_5 = (sho_5 * 5 + 5) * sho_5 // 2 s_15 = (sho_15 * 15 + 15) * sho_15 // 2 print(sum - s_3 - s_5 + s_15)
import math import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") N = list(_S()) ans = 'No' for s in N: if s == '7': ans = 'Yes' break print(ans)
0
null
34,863,544,278,628
173
172
def gcd(m, n): x = max(m, n) y = min(m, n) if x % y == 0: return y else: while x % y != 0: z = x % y x = y y = z return z def lcm(m, n): return (m * n) // gcd(m, n) # input A, B = map(int, input().split()) # lcm snack = lcm(A, B) print(snack)
from math import gcd as g a, b = map(int, input().split()) print((a*b)//g(a,b))
1
113,060,554,020,942
null
256
256
x = int(input()) print((1999-x)//200+1)
X = int(input()) rank = -1 if X <= 599: rank = 8 elif X <= 799: rank = 7 elif X <= 999: rank = 6 elif X <= 1199: rank = 5 elif X <= 1399: rank = 4 elif X <= 1599: rank = 3 elif X <= 1799: rank = 2 else: rank = 1 print(rank)
1
6,706,241,599,430
null
100
100
c=str(input()) print('Yes' if c[2]==c[3] and c[4]==c[5] else'No')
s = input() ans = 'Yes' if s[2] != s[3]: ans = 'No' if s[4] != s[5]: ans = 'No' print(ans)
1
42,040,132,311,232
null
184
184
K = int(input()) s = '' for i in range(K): s = s + 'ACL' print(s)
#!/usr/bin/env python k = int(input()) s = 'ACL' ans = '' for i in range(k): ans += s print(ans)
1
2,152,856,891,660
null
69
69
s1 = input() s2 = input() if s2 in s1+s1: print("Yes") else: print("No")
N=input() N=N+N S=input() if S in N: print("Yes") else: print("No")
1
1,751,680,433,180
null
64
64
import sys def input(): return sys.stdin.readline().rstrip() def main(): a, b = input().split() a = int(a) b = int(b[0]+b[2:4]) print(a*b//100) if __name__=='__main__': main()
a,b,k=map(int,input().split()) if k<=a: print(a-k,b) elif k>a and k<=a+b: print(0,a+b-k) else: print(0,0)
0
null
60,350,272,442,838
135
249
n = int(input()) a = list(map(int,input().split())) maxketa = max([len(bin(a[i])) for i in range(n)])-2 mod = 10**9+7 ans = 0 for i in range(maxketa): ones = 0 for j in range(n): if (a[j] >> i) & 1: ones += 1 ans = (ans + (n-ones)*ones*(2**i)) % mod print(ans)
# input() # int(input()) # map(int, input().split()) # list(map(int, input().split())) # list(map(int, list(input()))) # スペースがない数字リストを読み込み import math import fractions import sys import bisect import heapq # 優先度付きキュー(最小値取り出し) import collections from collections import Counter from collections import deque import pprint sr = lambda: input() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) """nを素因数分解""" """2以上の整数n => [[素因数, 指数], ...]の2次元リスト""" def factorization(n): arr = [] temp = n if n == 1: return arr 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==[]: arr.append([n, 1]) return arr # a^n def power(a,n,mod): x = 1 while n: if n & 1: x *= a % mod n >>= 1 a *= a % mod return x % mod # n*(n-1)*...*(l+1)*l def kaijo(n, l, mod): if n == 0: return 1 a = n tmp = n-1 while(tmp >= l): a = a*tmp%mod tmp -= 1 return a inf = 10**18 mod = 10**9+7 n = ir() a = lr() dp = [0 for i in range(60)] for num in a: for j in range(60): if ((num >> j) & 1): dp[j]+=1 ans = 0 for i in range(60): k = dp[i] tmp = k*(n-k)*power(2,i,mod)%mod ans = (ans+tmp)%mod print(ans)
1
123,119,741,237,330
null
263
263
n = int(input()) def binary_search(l, target): left = 0 right = len(l) while left<right: mid = (left+right)//2 if target == l[mid]: return True elif target < l[mid]: right = mid else: left = mid+1 return False seki = [i*j for i in range(1, 10) for j in range(1, 10)] seki.sort() if binary_search(seki, n): print('Yes') else: print('No')
n = int(input()) ans = 360 / n i = 1 while int(ans * i) != ans * i: i += 1 print(int(ans * i))
0
null
86,793,015,133,850
287
125
s=input() print("Yes"if s==input()[:-1]else"No")
s = input() T = input() if T[:len(T)-1] == s and len(s)+1 == len(T): print("Yes") else: print("No")
1
21,450,286,437,810
null
147
147
A, B = list(map(int,input().split())) if A>0 and A<10 and B>0 and B<10: print(A*B) else: print(-1)
def main(S, T): ans = 0 for i in range(len(S)): if S[i] != T[i]: ans += 1 return ans if __name__ == '__main__': S = input() T = input() ans = main(S, T) print(ans)
0
null
84,025,064,317,600
286
116
N, D = map(int, input().split()) X = [list(map(int, input().split())) for l in range(N)] count = 0 for i in range(N): if (X[i][0])**2 + (X[i][1])**2 - D**2 <= 0: count = count + 1 print(count)
# -*- coding: utf-8 -*- import sys import os def input_to_list(): return list(map(int, input().split())) H, W = input_to_list() M = [] for i in range(H): lis = input_to_list() s = sum(lis) lis.append(s) M.append(lis) # vertical sum last = [] for i in range(W + 1): s = 0 for j in range(H): s += M[j][i] last.append(s) M.append(last) # print for i in range(H + 1): print(*M[i])
0
null
3,656,966,388,710
96
59
X = int(input()) i = 1 while (360*i) % X != 0: i += 1 ans = 360*i//X print(ans)
n = int(input()) ans = 360 / n i = 1 while int(ans * i) != ans * i: i += 1 print(int(ans * i))
1
13,129,885,961,982
null
125
125
n,m,x=map(int,input().split()) A=[list(map(int,input().split())) for _ in range(n)] a=[] ans=[] for i in range(2**n): b=bin(i)[2:].zfill(n) a.append(b) for bit in a: Skills=[] for i in range(1,1+m): skill=0 for j in range(n): if bit[j]=="1": skill+=A[j][i] Skills.append(skill) cost=0 if min(Skills)>=x: for j in range(n): if bit[j]=="1": cost+=A[j][0] ans.append(cost) if len(ans)==0: ans.append(-1) print(min(ans))
from itertools import product n, m, x = map(int, input().split()) CA = [list(map(int, input().split())) for _ in range(n)] ans = 10**12+1 for t in product([0,1], repeat=n): # (1, 0, 0) cost = 0 understanding = [0] * m for i, b in enumerate(t): if b == 1: cost += CA[i][0] for j, a in enumerate(CA[i][1:]): understanding[j] += a if sum(True for u in understanding if u >= x) == m: ans = min(ans, cost) if ans == 10**12+1: print(-1) else: print(ans)
1
22,224,103,551,790
null
149
149
def main(): import math a, b, n = map(int, input().split()) if n >= b: ans = math.floor(a * (b-1)/b) else: ans = math.floor(a * n / b) print(ans) if __name__ == "__main__": main()
a,b,n=map(int,input().split()) import math if n/b >= 1: print(math.floor(a*(b-1)/b)) else: print(math.floor(a*n/b))
1
27,977,663,143,670
null
161
161
N,M=map(int, input().split()) if N in [0,1]:n=0 else: n=N*(N-1)/2 if M in [0,1]:m=0 else: m=M*(M-1)/2 print(int(n+m))
n, p = map(int, input().split()) s = input() ruisekiwa = [0 for _ in range(0, n + 1)] if 10 % p == 0: ans = 0 for i in range(0, n): if (ord(s[i]) - ord('0')) % p == 0: ans += i + 1 print(ans) exit() ten = 1 for _i in range(0, n): i = n - _i - 1 ruisekiwa[n - i] = ((ord(s[i]) - ord('0')) * ten + ruisekiwa[n - i - 1]) % p ten *= 10 ten %= p ans = 0 cnt = [0 for _ in range(0, p)] for i in range(0, n+1): ans += cnt[ruisekiwa[i]] cnt[ruisekiwa[i]] += 1 print(ans)
0
null
52,071,760,474,560
189
205
def gcd(a, b): if b == 0: return a else: return gcd(b, a%b) def lcm(a, b): return a // gcd(a, b) * b N, M = map(int, input().split()) A = list(map(int, input().split())) A = [a//2 for a in A] while A[0] % 2 == 0: for i in range(N): if A[i] % 2 != 0: print(0) exit() A[i] //= 2 M //= 2 for i in range(N): if A[i] % 2 == 0: print(0) exit() lcm_ = 1 for i in range(N): lcm_ = lcm(lcm_, A[i]) if M < lcm_: print(0) exit() print((M // lcm_ + 1) // 2)
N=int(input()) flag=0 for i in range(1,10): for j in range(1,10): if N==i*j: flag+=1 if flag==0: print('No') else: print('Yes')
0
null
130,719,938,594,432
247
287
x,k,d = map(int, input().split()) if x == 0: if k % 2 == 1: x = d elif x > 0: if x >= k*d: x -= k*d else: n = x//d x -= n*d k -= n if k%2 ==1: x -= d else: if x <= -(k*d): x += k*d else: n = abs(x)//d x += n*d k -= n if k%2 ==1: x += d print(abs(x))
import math n = int(input()) x = [int(i) for i in input().split()] y = [int(j) for j in input().split()] p_1 = p_2 = p_3 = p_m = 0 for i in range(n): diff = math.fabs(x[i]-y[i]) p_1 += diff p_2 += diff*diff p_3 += diff*diff*diff if p_m < diff: p_m = diff p_2 = math.sqrt(p_2) p_3 = math.pow(p_3, 1/3) print('%.5f\n%.5f\n%.5f\n%.5f'% (p_1, p_2, p_3, p_m))
0
null
2,713,453,660,928
92
32
N= int(input()) S = input() abc = "ABC" ans = 0 j = 0 for i in range(N): if S[i] == abc[j]: j += 1 if S[i] == "C": j = 0 ans += 1 elif S[i] == "A": j = 1 else: j = 0 print(ans)
import math a, b, x = map(int, input().split()) x = x / a if x >= a*b/2: K = (a*b - x)/a*2 L = K/math.sqrt(K**2+a**2) ans = math.degrees(math.asin(L)) print(ans) else: K = 2*x/b L = b/math.sqrt(K**2+b**2) ans = math.degrees(math.asin(L)) print(ans)
0
null
130,978,854,403,910
245
289
import math import collections import fractions import itertools import functools import operator import bisect def solve(): n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ruia, ruib = [0], [0] for i in range(n): ruia.append(a[i]+ruia[i]) for i in range(m): ruib.append(b[i]+ruib[i]) ans = 0 j = m for i in range(n+1): if ruia[i] > k: break while(ruib[j]>k-ruia[i]): j -= 1 ans = max(ans, i+j) print(ans) return 0 if __name__ == "__main__": solve()
def main(): n, a, b = map(int, input().split()) if (b - a) % 2 == 0: ans = (b - a) // 2 else: if b - 1 < n - a: g = (b - a + 1) // 2 ans = a + g - 1 else: g = (2 * n + a - b + 1) // 2 ans = 2 * n - b - g + 1 print(ans) if __name__ == "__main__": main()
0
null
59,838,681,901,440
117
253
if "7" in input(): print("Yes") else: print("No")
def resolve(): print("Yes" if "7" in input() else "No") if '__main__' == __name__: resolve()
1
34,249,393,477,738
null
172
172
total_stack = [] single_stack = [] def main(): input_line = input() total = 0 for i,s in enumerate(input_line): if s == "\\": total_stack.append(i) elif s == "/" and len(total_stack) != 0: a = total_stack.pop() total += i - a area = 0 while len(single_stack) != 0 and a < single_stack[-1][0]: area += single_stack.pop()[1] single_stack.append([a, area + i - a]) print(total) print(' '.join([str(len(single_stack))] + [str(i[1]) for i in single_stack])) if __name__ == '__main__': main()
S = raw_input() S1, S2 = [], [] ans = pool = 0 for i in xrange(len(S)): if S[i] == "/" and len(S1) > 0: j = S1.pop() ans += i - j a = i - j while (len(S2) > 0 and S2[-1][0] > j): a += S2.pop()[1] S2.append([j, a]) if S[i] == "\\": S1.append(i) print ans if len(S2) > 0: print len(S2), " ".join(map(str, [a for j, a in S2])) else: print 0
1
57,706,770,460
null
21
21
count = int(raw_input()) arr = map(int, raw_input().split()) arr.reverse() print(" ".join(map(str, arr)))
D = int(input()) C = list(map(int, input().split())) S = list(list(map(int, input().split())) for i in range(D)) T = list(int(input()) for i in range(D)) manzoku = 0 yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] #1日目 for day in range(D): yasumi = list(map(lambda x: x + 1, yasumi)) yasumi[T[day] - 1] = 0 manzoku += S[day][T[day] - 1] for i in range(26): manzoku -= C[i] * yasumi[i] print(manzoku)
0
null
5,504,678,489,898
53
114
import sys sys.setrecursionlimit(10 ** 6) # input = sys.stdin.readline #### int1 = lambda x: 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 printlist(lst, k='\n'): print(k.join(list(map(str, lst)))) INF = float('inf') from collections import deque def solve(): N = II() E = [[] for _ in range(N)] for i in range(N-1): a, b = MI1() E[a].append((b, i)) E[b].append((a, i)) q = deque([(0, -1, -1)]) ans = [0] * (N-1) while len(q) > 0: current, v_pre, c_pre = q.popleft() color = 1 for (nv, idx) in E[current]: if nv == v_pre: continue if color == c_pre: color += 1 q.append((nv, current, color)) ans[idx] = color color += 1 print(max(ans)) printlist(ans) if __name__ == '__main__': solve()
import bisect import sys from bisect import bisect_left from operator import itemgetter 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 main(): N = ii() L = lmi() L.sort() # print(L) # 2辺を固定して、2辺の和より長い辺の数を数える count = 0 for i in range(N): for j in range(i+1, N): limit = L[i] + L[j] longer = bisect_left(L, limit) tmp = longer - (j + 1) # print(limit, longer, tmp) count += longer - (j + 1) print(count) return main()
0
null
154,089,916,952,060
272
294
n, a, b = map(int, input().split()) if (a%2 and b%2) or (a%2==0 and b%2==0): print((b-a)//2) else: print(min(a-1, n-b)+1+(b-a-1)//2)
N, A, B = map(int, input().split()) distance =(B - A - 1 )//2 if( (A % 2 == 0 and B % 2 ==0) or (A%2==1 and B%2==1)): ans=(B - A)//2 else: ans = min(A-1,N - B) + 1 + distance print(ans)
1
109,437,070,728,118
null
253
253
K = int(input()) Ans = 'ACL' for i in range(K-1): Ans += 'ACL' print(Ans)
K = int(input()) string = 'ACL' for i in range(K - 1): string = string + 'ACL' print(string)
1
2,201,090,851,182
null
69
69
import math a = int(input()) for i in range(50001): if math.floor(i*1.08) == a: print(i) exit() print(":(")
def main(): n = int(input()) d_lst = list(map(int, input().split())) ans = 0 for i in range(n - 1): for j in range(i + 1, n): ans += d_lst[i] * d_lst[j] print(ans) if __name__ == "__main__": main()
0
null
146,530,424,310,656
265
292
from decimal import * getcontext().prec=1000 a,b,c=map(int,input().split()) A=Decimal(a)**Decimal("0.5") B=Decimal(b)**Decimal("0.5") C=Decimal(c)**Decimal("0.5") D= Decimal(10) ** (-100) if A+B+D<C: print("Yes") else: print("No")
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==[]: arr.append([n, 1]) return arr def main(): n=int(input()) a=list(map(int,input().split())) mod=pow(10,9)+7 lcma={} for ai in a: f=factorization(ai) for fi in f: if fi[0] in lcma: lcma[fi[0]]=max(lcma[fi[0]],fi[1]) else: lcma[fi[0]]=fi[1] l=1 for k,v in lcma.items(): l*=pow(k,v,mod) l%=mod ans=0 for ai in a: ans+=l*pow(ai,mod-2,mod) ans%=mod print(ans) main()
0
null
69,532,155,845,930
197
235
n = int(input()) s = input() r, g, b = [], [], [] cnt = 1 for i in s: if i == 'R': r.append(cnt) elif i == 'G': g.append(cnt) else: b.append(cnt) cnt += 1 rd = set(map(lambda x: x * 2, r)) #以下2つ目の条件を満たさないもの(j - i = k - j)の数え上げ gd = set(map(lambda x: x * 2, g)) bd = set(map(lambda x: x * 2, b)) ddc = 0 for i in r: for j in g: if i + j in bd: ddc += 1 for j in g: for k in b: if j + k in rd: ddc += 1 for i in r: for k in b: if i + k in gd: ddc += 1 print(len(r) * len(g) * len(b) - ddc) #1つ目の条件を満たすモノから2つ目の条件を満たさないものを引く
def main(): nums = list(map(int,input().split())) for i,n in enumerate(nums): if n == 0: return i + 1 if __name__ == '__main__': print(main())
0
null
24,632,515,953,010
175
126
s = input() b = s.swapcase() print(b)
import string s = input() print(s.translate(str.maketrans(string.ascii_uppercase+string.ascii_lowercase, string.ascii_lowercase+string.ascii_uppercase)))
1
1,519,708,543,250
null
61
61
score = input() scin = score.split() ans = int(scin[0]) * int(scin[1]) print(ans)
s = input() a = [0] * (len(s)+1) larger_count = 0 for i in range(len(s)): if s[i] == '>': larger_count += 1 continue for j in range(larger_count+1): a[i-j] = max(a[i-j], j) larger_count = 0 a[i+1] = a[i] + 1 for j in range(larger_count+1): a[len(a)-j-1] = max(a[len(a)-j-1], j) print(sum(a))
0
null
85,906,967,704,128
133
285
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # 998244353 input=lambda:sys.stdin.readline().rstrip() def resolve(): n = int(input()) A = list(map(int,input().split())) if n & 1 == 0: res = -INF score = sum(A[::2]) res = max(res, score) for i in range(n-1,-1,-1): if i & 1: score += A[i] else: score -= A[i] res = max(res, score) print(res) return front_dp = [None] * n choose = -INF not_choose = 0 for i in range(1, n, 2): choose, not_choose = max(choose, not_choose) + A[i], not_choose + A[i-1] front_dp[i] = max(choose, not_choose) back_dp = [None] * n choose = -INF not_choose = 0 for i in range(n-2, -1, -2): choose, not_choose = max(choose, not_choose) + A[i], not_choose + A[i+1] back_dp[i] = max(choose, not_choose) res = -INF for i in range(1, n, 2): if i + 2 < n: res = max(res, front_dp[i] + back_dp[i+2]) res = max(res, front_dp[-2]) res = max(res, back_dp[1]) print(res) resolve()
n=int(input()) arr=list(map(int,input().split())) acum1=[0] acum2=[0] for i in range(n): if i%2==0: acum1.append(acum1[-1]+arr[i]) acum2.append(acum2[-1]+0) else: acum1.append(acum1[-1]+0) acum2.append(acum2[-1]+arr[i]) if n%2==0: ans=max(acum1[n-1]-acum1[0],acum2[n]-acum2[1]) for i in range(1,n+1,2): if i+3>n: continue tmp=(acum1[i]-acum1[0])+(acum2[n]-acum2[i+2]) ans=max(ans,tmp) else: ans=max(acum1[n-2]-acum1[0],acum2[n-1]-acum2[1],acum1[n]-acum1[2]) for i in range(1,n+1,2): if i+3>n-1: continue tmp=(acum1[i]-acum1[0])+(acum2[n-1]-acum2[i+2]) ans=max(ans,tmp) for i in range(2,n+1,2): if i+3>n: continue tmp=(acum2[i]-acum2[1])+(acum1[n]-acum1[i+2]) ans=max(ans,tmp) for i in range(1,n+1,2): if i+4>n: continue tmp=(acum1[i]-acum1[0])+(acum1[n]-acum1[i+3]) ans=max(ans,tmp) acummax=[-10**18] for i in range(1,n+1): if i+2>n: acummax.append(-10**18) else: if i%2==0: acummax.append(acum2[i]+acum1[n]-acum1[i+2]) else: acummax.append(-10**18) for i in range(n-1,-1,-1): acummax[i]=max(acummax[i],acummax[i+1]) for i in range(1,n+1,2): if i+6>n: continue tmp=(acum1[i]-acum1[0]-acum2[i+2])+acummax[i+3] ans=max(ans,tmp) print(ans)
1
37,329,103,538,304
null
177
177
#!/usr/bin python3 # -*- coding: utf-8 -*- r, c, k = map(int, input().split()) itm = [[0]*(c) for _ in range(r)] for i in range(k): ri, ci, vi = map(int, input().split()) itm[ri-1][ci-1] = vi dp0 = [[0]*4 for c_ in range(3005)] dp1 = [[0]*4 for c_ in range(3005)] for i in range(r): for j in range(c): nowv = itm[i][j] dp0[j][3] = max(dp0[j][3], dp0[j][2] + nowv) dp0[j][2] = max(dp0[j][2], dp0[j][1] + nowv) dp0[j][1] = max(dp0[j][1], dp0[j][0] + nowv) dp0[j+1][0] = max(dp0[j+1][0], dp0[j][0]) dp0[j+1][1] = max(dp0[j+1][1], dp0[j][1]) dp0[j+1][2] = max(dp0[j+1][2], dp0[j][2]) dp0[j+1][3] = max(dp0[j+1][3], dp0[j][3]) dp1[j][0] = max(dp1[j][0], max(dp0[j])) dp0 = dp1.copy() print(max(dp1[c-1]))
import sys input = sys.stdin.buffer.readline R, C, K = map(int, input().split()) G = [[None for j in range(C)] for i in range(R)] for _ in range(K): r, c, v = map(int, input().split()) G[r - 1][c - 1] = v dp = [[0, 0, 0, 0] for _ in range(C)] for i in range(R): for j in range(C): if G[i][j] is not None: dp[j][0], dp[j][1] = max(dp[j]), max(dp[j]) + G[i][j] dp[j][2], dp[j][3] = 0, 0 else: dp[j][0] = max(dp[j]) dp[j][1], dp[j][2], dp[j][3] = 0, 0, 0 for j in range(1, C): if G[i][j] is not None: dp[j][0] = max(dp[j - 1][0], dp[j][0]) dp[j][1] = max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1]) if dp[j - 1][1] != 0: dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2]) if dp[j - 1][2] != 0: dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3]) else: dp[j][0] = max(dp[j - 1][0], dp[j][0]) dp[j][1] = max(dp[j - 1][1], dp[j][1]) dp[j][2] = max(dp[j - 1][2], dp[j][2]) dp[j][3] = max(dp[j - 1][3], dp[j][3]) print(max(dp[-1]))
1
5,606,494,903,200
null
94
94
K=int(input()) res=1 x=0 for i in range(K): x+=7*res x%=K if x%K==0: print(i+1) break res*=10 res%=K else: print(-1)
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline() def down_pleasure(c_list, day_num, contest_last_day): """その日の満足度低下を返す""" sum_down_pl = 0 for i in range(26): sum_down_pl += c_list[i] * (day_num - contest_last_day[i]) return sum_down_pl def calc_pleasure(s_list, t_list, d, c_list, contest_last_day): pleasure = 0 for day, t_num in zip(range(d), t_list): pleasure += s_list[day][t_num-1] contest_last_day[t_num-1] = day + 1 pleasure -= down_pleasure(c_list, day+1, contest_last_day) print(pleasure) return pleasure def resolve(): d = int(input().rstrip()) c_list = list(map(int, input().split())) s_list = [list(map(int, input().split())) for i in range(d)] t_list = [] for i in range(d): t_list.append(int(input().rstrip())) contest_last_day = [] for i in range(26): contest_last_day.append(0) pleasure = calc_pleasure(s_list, t_list, d, c_list, contest_last_day) if __name__ == "__main__": resolve()
0
null
7,948,496,833,376
97
114
from bisect import bisect N, M, K = map(int, input().split()) A = map(int, input().split()) B = map(int, input().split()) a_cum = [0] cum = 0 for x in A: cum += x a_cum.append(cum) b_cum = [] cum = 0 for x in B: cum += x b_cum.append(cum) answer = 0 for i, a in enumerate(a_cum): remain = K - a if remain < 0: break t = bisect(b_cum, remain) # print('remain', remain, 't', t) answer = max(answer, i + t) print(answer)
from itertools import accumulate from bisect import bisect_left ri = lambda S: [int(v) for v in S.split()] def rii(): return ri(input()) N, M, K = rii() A = rii() B = rii() i = j = 0 pA = [0] + list(accumulate(A)) pB = [0] + list(accumulate(B)) ans = 0 for i, a in enumerate(pA): br = 0 if K >= a: r = K - a br = i if r: j = bisect_left(pB, r) if j != len(pB): if pB[j] > r: j -= 1 br += j ans = max(ans, br) print(ans)
1
10,874,771,854,638
null
117
117
from bisect import bisect_left, bisect_right, insort_left n = int(input()) s = list(input()) q = int(input()) d = {} flag = {} for i in list('abcdefghijklmnopqrstuvwxyz'): d.setdefault(i, []).append(-1) flag.setdefault(i, []).append(-1) for i in range(n): d.setdefault(s[i], []).append(i) for i in range(q): q1,q2,q3 = map(str,input().split()) if q1 == '1': q2 = int(q2) - 1 if s[q2] != q3: insort_left(flag[s[q2]],q2) insort_left(d[q3],q2) s[q2] = q3 else: ans = 0 q2 = int(q2) - 1 q3 = int(q3) - 1 if q2 == q3: print(1) continue for string,l in d.items(): res = 0 if d[string] != [-1]: left = bisect_left(l,q2) right = bisect_right(l,q3) else: left = 0 right = 0 if string in flag: left2 = bisect_left(flag[string],q2) right2 = bisect_right(flag[string],q3) else: left2 = 0 right2 = 0 if left != right: if right - left > right2 - left2: res = 1 ans += res #print(string,l,res) print(ans)
print(input().find('0')//2+1)
0
null
38,102,448,609,202
210
126
a, b = map(int, input().split()) if a % b > 0: print(a//b + 1) else: print(a//b)
n, m = map(int,input().split()) sc = [list(map(int,input().split())) for _ in range(m)] ans = -1 for i in range(1000): s_i = str(i) if len(s_i) == n and all(int(s_i[s-1])==c for s,c in sc): ans = i break print(ans)
0
null
68,858,480,312,798
225
208
N = int(input()) Ans = [0] * (N + 1) def calc(a, b, c): return a ** 2 + b ** 2 + c ** 2 + a * b + b * c + c * a for i in range(1, N): for j in range(1, N): for k in range(1, N): x = calc(i, j, k) if x > N: break Ans[x] += 1 for a in Ans[1:]: print(a)
s = input() if s[1] == 'R': print('ABC') else: print('ARC')
0
null
16,093,725,944,310
106
153
s=input() t=input() max_=0 for i in range(len(s)-len(t)+1): c = 0 for j in range(len(t)): if s[i+j] == t[j]: c += 1 max_ = max(max_, c) print(len(t)-max_)
#177B S=input() T=input() Ss=[] Ts=[] Us=[] Vs=[] len_T=len(T) len_S=len(S) s=0 #初期配列を作成 for t in range(len_T): Ts.append(T[t]) Ss.append(S[t]) #一致していない箇所の個数を数え、記録 for t in range(len_T): Us.append(Ts[t]!=Ss[t]) Vs.append(sum(Us)) for s in range(1,len_S-len_T+1): #Ss配列をずらす Ss.append(S[len_T+s-1]) Ss.remove(S[s-1]) #Usをリセットして、一致していない箇所の個数を数え、記録 Us=[] for t in range(len(T)): Us.append(Ts[t]!=Ss[t]) Vs.append(sum(Us)) print(str(min(Vs)))
1
3,681,077,340,540
null
82
82
import math n = int(input()) a = list(map(int, input().split())) nmax = 10**6 check = [0]*(nmax + 5) for i in a: check[i] += 1 pairwise = True for i in range(2, nmax + 5): cnt = 0 for j in range(i, nmax + 5, i): cnt += check[j] if cnt > 1: pairwise = False if pairwise == True: print('pairwise coprime') exit() x = 0 for i in a: x = math.gcd(x,i) if x == 1: print('setwise coprime') else: print('not coprime')
n,k,s = map(int, input().split()) ans = [] if s == 10**9: for i in range(k): ans.append(10**9) for i in range(n-k): ans.append(1) else: for i in range(k): ans.append(s) for i in range(n-k): ans.append(s+1) print(*ans)
0
null
47,737,546,082,212
85
238
import heapq def main(): _ = int(input()) A = sorted(list(map(int, input().split())), reverse=True) q = [] heapq.heapify(q) ans = A[0] tmp_score = min(A[0], A[1]) heapq.heappush(q, (-tmp_score, A[0], A[1])) heapq.heappush(q, (-tmp_score, A[1], A[0])) for a in A[2:]: g = heapq.heappop(q) ans += -g[0] tmp_score1 = min(a, g[1]) tmp_push1 = (-tmp_score1, a, g[1]) tmp_score2 = min(a, g[2]) tmp_push2 = (-tmp_score2, a, g[2]) heapq.heappush(q, tmp_push1) heapq.heappush(q, tmp_push2) print(ans) if __name__ == '__main__': main()
N = int(input()) A = list(map(int,input().split())) A.sort(reverse = True) ans = A[0] j = 1 for i in range(2,N): ans += A[j] if i % 2 == 1: j += 1 print(ans)
1
9,235,761,191,140
null
111
111
import numpy as np n, k = map(int, input().split()) aa = list(map(np.int64, input().split())) aa = np.array(aa) def mul(dd): mod = 10**9+7 ret = 1 for d in dd: ret = (ret*d)%mod return ret def sol(aa, n, k): mod = 10**9+7 aap = aa[aa>0] aam = aa[aa<0] if n == k: return mul(aa) if len(aap) + 2*(len(aam)//2) < k: return 0 # マイナスのみ if len(aam) == n: aam.sort() if k%2==1: return mul(aam[-k:]) else: return mul(aam[:k]) aap = aa[aa>=0] aap.sort() aap = aap[::-1] aam.sort() ret=1 if k%2 >0: k = k-1 ret *= aap[0] aap = aap[1:] aap2 = [aap[2*i]*aap[2*i+1] for i in range(len(aap)//2)] aam2 = [aam[2*i]*aam[2*i+1] for i in range(len(aam)//2)] aap2.extend(aam2) aap2.sort(reverse=True) aap2 = [i%mod for i in aap2] return (ret*mul(aap2[:k//2]))%mod print(sol(aa, n, k))
from math import log10 n, k = map(int, input().split()) a = list(map(int, input().split())) MOD = 10**9+7 a.sort() cnt_neg = 0 cnt_pos = 0 for i in a: if i <= 0: cnt_neg += 1 else: cnt_pos += 1 is_minus = False k_tmp = k while k_tmp > 0: if k_tmp >= 2: if cnt_neg >= 2: cnt_neg -= 2 elif cnt_pos >= 2: cnt_pos -= 2 else: is_minus = True break k_tmp -= 2 else: if cnt_pos > 0: cnt_pos -= 1 k_tmp -= 1 else: is_minus = True break k_1 = k ans1 = 1 l = 0 r = n - 1 if k_1 % 2: ans1 *= a[-1] r -= 1 k_1 -= 1 while k_1 >= 2: if a[l] * a[l+1] > a[r-1] * a[r]: ans1 *= a[l] * a[l+1] l += 2 else: ans1 *= a[r-1] * a[r] r -= 2 k_1 -= 2 ans1 %= MOD a.sort(key=abs) # print(a) ans2 = 1 for i in a[:k]: ans2 *= i ans2 %= MOD if is_minus: print(ans2) else: print(ans1)
1
9,330,011,154,002
null
112
112
n = int(input()) A = list(map(int, input().split())) MAX_N = max(A)+ 1 cnt = [0] * MAX_N for a in A: for i in range(a, MAX_N, a): if cnt[i] <= 2: cnt[i] += 1 ans = 0 for a in A: if cnt[a] == 1: ans += 1 print(ans)
import numpy as np import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline from numba import njit def getInputs(): D = int(readline()) CS = np.array(read().split(), np.int32) C = CS[:26] S = CS[26:].reshape((-1, 26)) return D, C, S @njit('(i8, i4[:], i4[:, :], i4[:], )', cache=True) def _compute_score1(D, C, S, out): score = 0 last = np.zeros(26, np.int32) for d in range(len(out)): i = out[d] score += S[d, i] last[i] = d + 1 score -= np.sum(C * (d + 1 - last)) return last, score def step1(D, C, S): #out = np.zeros(D, np.int32) out = [] LAST = 0 for d in range(D): max_score = -10000000 best_i = 0 for i in range(26): #out[d] = i out.append(i) last, score = _compute_score1(D, C, S, np.array(out, np.int32)) if max_score < score: max_score = score LAST = last best_i = i out.pop() #out[d] = best_i out.append(best_i) return np.array(out), LAST, max_score def output(out): out += 1 print('\n'.join(out.astype(str).tolist())) D, C, S = getInputs() out, _, score = step1(D, C, S) output(out)
0
null
11,985,717,423,538
129
113
from collections import deque K = int(input()) que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) for i in range(K): num = que.popleft() if i == K-1: print(num) break if num%10 == 0: que.append(num*10 + num%10) que.append(num*10 + num%10 + 1) elif num%10 == 9: que.append(num*10 + num%10 - 1) que.append(num*10 + num%10) else: que.append(num*10 + num%10 - 1) que.append(num*10 + num%10) que.append(num*10 + num%10 + 1)
n = int(input()) a = list(map(int, input().split())) s = sum(a) q = int(input()) l = [0] * 100000 for i in a: l[i-1] += 1 for i in range(q): x,y = map(int, input().split()) hoge = l[x-1] s -= hoge*x s += hoge*y l[y-1] += hoge l[x-1] = 0 print(s)
0
null
26,040,013,187,548
181
122
from collections import deque def main(): n, m = map(int, input().split()) to = [[] for _ in range(n+1)] for _ in range(m): a, b = map(int, input().split()) to[a].append(b) to[b].append(a) q = deque([1]) ans = [None]*(n+1) while q: p = q.pop() for child in to[p]: if ans[child] is None: ans[child] = p q.appendleft(child) print("Yes") print("\n".join(list(map(str, ans[2:])))) if __name__ == "__main__": main()
from collections import deque from sys import stdin input = stdin.readline def main(): N, M = list(map(int, input().split())) G = [[] for _ in range(N+1)] for i in range(M): a, b = map(int, input().split()) G[a].append(b) G[b].append(a) from_ = [0]*(N+1) q = deque([1]) seen = set() seen.add(1) while len(q): now = q.popleft() for next_ in G[now]: if next_ not in seen: seen.add(next_) q.append(next_) from_[next_] = now print('Yes') for i in range(2, N+1): print(from_[i]) if(__name__ == '__main__'): main()
1
20,503,669,862,840
null
145
145
import sys input = sys.stdin.readline from collections import deque def main(): n = int(input().strip()) v = [[] for _ in range(n)] for i in range(n): v[i] = list(map(int, input().strip().split())) l = [-1] * (n+1) q = deque() q.append((1, 0)) while len(q) != 0: id, d = q.popleft() # print("id", id) if l[id] != -1: # print("b") continue l[id] = d # l[id] = min(d, l[id]) # print(id, d) for i in range(v[id-1][1]): q.append((v[id-1][2+i], d+1)) # if id == 8: # print("##", id, v[id-1][2+i]) # print(repr(q)) for i in range(1, n+1): print(i, l[i]) if __name__ == '__main__': main()
from collections import deque N = int(input()) Graph = {} Node = [] visited = [-1]*(N) for i in range(N): tmp = input().split() if int(tmp[1]) != 0: Graph[i] = [int(x)-1 for x in tmp[2:]] else: Graph[i] = [] queue = deque([0]) visited[0] = 0 while queue: x = queue.popleft() for i in Graph[x]: if visited[i] == -1: visited[i] = visited[x] + 1 queue.append(i) for i,j in enumerate(visited, 1): print(i, j)
1
4,440,007,770
null
9
9
def r(i): indr = s.find('<', i) return indr - i if indr != -1 else n - i - 1 def l(i): indl = s.rfind('>', 0, i) return i - indl -1 if indl != -1 else i s = input() n = len(s) + 1 print(sum([max(r(i), l(i)) for i in range(n)]))
from sys import stdin import collections def ip(): return [int(i) for i in stdin.readline().split()] def sp(): return [str(i) for i in stdin.readline().split()] # 4 6 # 1 2 # 1 3 # 1 4 # 2 3 # 2 4 # 3 4 def find(d,x): root = x while root != d[root]: root = d[root] while x != root: nxt = d[x] d[x] = root x = nxt return d,root def merge(d,s,x,y): d,x = find(d,x) d,y = find(d,y) if x == y: return d,s if s[x] > s[y]: s[x] += s[y] d[y] = d[x] else: s[y] += s[x] d[x] = d[y] return d,s n,m = ip() d = {i+1: i+1 for i in range(n)} s = {i+1: 1 for i in range(n)} seen = set() for _ in range(m): # print(d,s) x,y = ip() if (x,y) in seen or (y,x) in seen: continue seen.add((x,y)) seen.add((y,x)) d,s = merge(d,s,x,y) ans = 0 for i in s: ans = max(ans, s[i]) print(ans)
0
null
80,576,725,533,652
285
84
n = int(input()) mod = 10**9+7 ls = list(map(int,input().split())) di = [i**2 for i in ls] print((((sum(ls)**2)-(sum(di)))//2)%mod)
def main(): n=int(input()) a=list(map(int, input().split())) mod=10**9+7 ans=((sum(a)%mod)**2)%mod for i in range(n): ans-=a[i]**2 ans%=mod m=pow(2,mod-2,mod) print(ans*m%mod) main()
1
3,841,149,650,140
null
83
83