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
def stackable(pack, tmp_p, k): cur_w = 0 trucks = 1 for i in range(len(pack)): if tmp_p < pack[i]: return False if cur_w + pack[i] <= tmp_p: cur_w += pack[i] else: cur_w = pack[i] trucks += 1 if k < trucks: return False return True n, k = map(int, input().split()) pack = [] for i in range(n): pack.append(int(input())) left = int(sum(pack) / k) right = max(pack) * n while left < right - 1: tmp_p = int((left + right) / 2) if stackable(pack, tmp_p, k): right = tmp_p else: left = tmp_p if stackable(pack, left, k): print(left) else: print(right)
MOD = 10 ** 9 + 7 class ModFactorial: """ 階乗, 組み合わせ, 順列の計算 """ def __init__(self, n, MOD=10 ** 9 + 7): """ :param n: 最大の要素数. :param MOD: """ kaijo = [0] * (n + 10) gyaku = [0] * (n + 10) kaijo[0] = 1 kaijo[1] = 1 for i in range(2, len(kaijo)): kaijo[i] = (i * kaijo[i - 1]) % MOD gyaku[0] = 1 gyaku[1] = 1 for i in range(2, len(gyaku)): gyaku[i] = pow(kaijo[i], MOD - 2, MOD) self.kaijo = kaijo self.gyaku = gyaku self.MOD = MOD def nCm(self, n, m): return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD def nPm(self, n, m): return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD def factorial(self, n): return self.kaijo[n] N, K = [int(_) for _ in input().split()] modf = ModFactorial(N) A = [int(_) for _ in input().split()] A.sort() i = 1 maxv = 0 for i in range(N): if K - 1 <= i: maxv += modf.nCm(i, K - 1) * A[i] maxv %= MOD # print(maxv) A.reverse() minv=0 for i in range(N): if K - 1 <= i: minv += modf.nCm(i, K - 1) * A[i] minv %= MOD print((maxv-minv)%MOD)
0
null
47,988,341,265,880
24
242
from collections import deque mod = int(1e9+7) def add(a, b): c = a + b if c >= mod: c -= mod return c def main(): n, m = map(int,raw_input().split()) adj_list = [[] for _ in range(n+5)] q = deque() ans = [-1] * (n+5) failed = False for _ in range(m): a, b = map(int,raw_input().split()) adj_list[a].append(b) adj_list[b].append(a) q.append(1) #print(adj_list) visited = set() visited.add(1) while len(q): sz = len(q) for _ in range(sz): cur = q.popleft() for nei in adj_list[cur]: if nei not in visited: ans[nei] = cur q.append(nei) visited.add(nei) print('Yes') for i in range(2, n+1): print(ans[i]) main()
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) n, m = map(int, input().split()) graph = [0] + [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) from collections import deque def bfs(graph, queue, dist, prev): while queue: current = queue.popleft() for _next in graph[current]: if dist[_next] != -1: continue else: dist[_next] = dist[current] + 1 prev[_next] = current queue.append(_next) queue = deque([1]) dist = [0] + [-1] * n prev = [0] + [-1] * n dist[1] = 0 bfs(graph, queue, dist, prev) if -1 in dist: print('No') else: print('Yes') for v in prev[2:]: print(v)
1
20,373,124,418,140
null
145
145
import sys N=int(input()) if N==2: print(1) sys.exit(0) answer_set=set() for i in range(2,int(N**0.5)+1): N2=N while N2%i==0: N2//=i if N2%i==1: answer_set.add(i) #print(answer_set) for i in range(1,int(N**0.5)+1): if (N-1)%i==0: answer_set.add((N-1)//i) #print(answer_set) answer_set.add(N) print(len(answer_set))
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors N = int(input()) d1 = make_divisors(N) d2 = make_divisors(N - 1) ans = len(d2) - 1 for n in d1: if n == 1: continue n2 = N while n2 % n == 0: n2 //= n if n2 % n == 1: if n not in d2: ans += 1 print(ans)
1
41,389,916,429,990
null
183
183
H, N = map(int, input().split()) l = [] for i in range(N): l.append(list(map(int, input().split()))) dp = [0] * 20000 for i in range(1, 20001): dp[i] = min(dp[i-a]+b for a, b in l) if i == H: break print(dp[H])
h,n=map(int,input().split()) a_=0 magic=[] for i in range(n): a,b=map(int,input().split()) a_=max(a,a_) c=[a,b] magic.append(c) dp=[10**8+1]*(h+a_+1) dp[0]=0 for i in range(n): a,b=magic[i] for j in range(len(dp)): if j+a<=h+a_: dp[j+a]=min(dp[j+a],dp[j]+b) print(min(dp[h:]))
1
81,167,632,970,370
null
229
229
A, B, C, K = map(int, input().split()) if A >= K: print(K) elif A + B >= K: print(A) elif A + B + C >= K: print(A + (-1) *(K - A - B)) else: print(A - B)
x=int(input()) if x>=2100: print(1) exit() ans=[0]*2100 for a in range(22): for b in range(22): for c in range(22): for d in range(22): for e in range(22): for f in range(21): y=a*100+b*101+c*102+d*103+e*104+f*105 if y<=2099: ans[y]=1 print(ans[x])
0
null
74,919,075,244,178
148
266
from itertools import combinations n, a, q, ms, cache = int(input()), list(map(int, input().split())), input(), map(int, input().split()), {} l = set(sum(t) for i in range(n) for t in combinations(a, i + 1)) for m in ms: print('yes' if m in l else 'no')
N = int(input()) A = list(map(int, input().split())) Q = int(input()) M = list(map(int, input().split())) combinations = {} def create_combinations(idx, sum): combinations[sum] = 1 if idx >= N: return create_combinations(idx+1, sum) create_combinations(idx+1, sum+A[idx]) return create_combinations(0, 0) for target in M: if target in combinations.keys(): print("yes") else: print("no")
1
99,798,646,862
null
25
25
n,k=map(int,input().split()) mod=10**9+7 count=[0]*(k+1) def getnum(m): ret = pow(k//m,n,mod) mul=2 while m*mul<=k: ret-=count[m*mul] mul+=1 return ret%mod ans=0 for i in range(1,k+1)[::-1]: g=getnum(i) count[i]=g ans+=g*i ans%=mod print(ans)
N, K = list(map(int, input().split())) mod = 10**9+7 ans = [0]*(K+1) s = 0 for i in range(K, 0, -1): ans[i] = pow(K//i, N, mod) for j in range(2*i, K+1, i): ans[i] -= ans[j] s += ans[i]*i%mod print(s%mod)
1
36,661,678,218,660
null
176
176
import sys def gcd(m, n): if n != 0: return gcd(n, m % n) else: return m for line in sys.stdin.readlines(): m, n = map(int, line.split()) g = gcd(m, n) l = m * n // g # LCM print(g, l)
# UnionFind: https://note.nkmk.me/python-union-find/ class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) def find(self, x): if self.root[x] < 0: return x else: self.root[x] = self.find(self.root[x]) return self.root[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.root[x] > self.root[y]: x, y = y, x self.root[x] += self.root[y] self.root[y] = x def is_same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.root[self.find(x)] n, m = map(int, input().split()) friends = UnionFind(n) for i in range(m): a, b = map(int, input().split()) friends.unite(a, b) print(max(friends.size(i) for i in range(n)))
0
null
1,956,158,119,552
5
84
h,w = [int(i) for i in input().split()] if h == 1 or w == 1: print(1) elif h % 2 == 1 and w % 2 == 1: print(int(h*w/2) + 1) else: print(int(h*w/2))
import sys def rs(): return sys.stdin.readline().rstrip() def ri(): return int(rs()) def rs_(): return [_ for _ in rs().split()] def ri_(): return [int(_) for _ in rs().split()] H, W = ri_() if H == 1 or W == 1: print(1) else: print(-(-H * W // 2))
1
50,839,991,813,358
null
196
196
N = int(input()) a = list(map(int, input().split())) ans = 0 i = 1 for num in a: if num != i: ans += 1 else: i += 1 print(ans if ans < len(a) else -1)
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N ** 0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def solve(): X, Y, A, B, C = Scanner.map_int() P = Scanner.map_int() Q = Scanner.map_int() R = Scanner.map_int() P.sort(reverse=True) P = P[:X] Q.sort(reverse=True) Q = Q[:Y] R.sort(reverse=True) R = R[:min(X + Y, C)] ans = P + Q + R ans.sort(reverse=True) print(sum(ans[:X + Y])) def main(): # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
0
null
79,737,218,433,732
257
188
def main(): a, b, c = map(int,input().split()) _set = set() if a <= c and b >= c: _set.add(c) if c // 2 < b: b = c // 2 if c % 2 == 0: _set = _set | set(range(a, b+1)) else: if a % 2 == 0: _set = _set | set(range(a+1, b+1, 2)) else: _set = _set | set(range(a, b+1, 2)) print(sum(map(lambda x: c % x == 0, _set))) main()
[N, R] = [int(i) for i in input().split()] print(R + 100*max(10-N, 0))
0
null
31,815,169,296,064
44
211
#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 # (string,3) 3回 #from collections import deque #from collections import defaultdict #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()) H,W,K = readInts() cake = [input() for _ in range(H)] ans = [] no = 0 cnt = 0 for h in range(H): if cake[h] == "."*W: no += 1 continue else: cnt += 1 same = [] arrived = False for w in range(W): if cake[h][w] == "#": if not arrived: arrived = True else: cnt += 1 same.append(cnt) for _ in range(no+1): ans.append(same) no = 0 for _ in range(no): ans.append(ans[-1]) for a in ans: print(*a,sep=" ")
a = int(input()) out = a + a**2 + a**3 print(out)
0
null
76,711,678,284,566
277
115
N = int(input()) print(1 - N)
K = int(input()) S = input() N = len(S) MOD = 10**9 + 7 fct = [1] invfct = [1] pow25 = [1] pow26 = [1] for i in range(1, K+N+1): fct.append(fct[i-1] * i % MOD) invfct.append(pow(fct[i], MOD-2, MOD)) pow25.append(pow25[i-1] * 25 % MOD) pow26.append(pow26[i-1] * 26 % MOD) def cmb(n, k): return fct[n] * invfct[k] * invfct[n-k] ans = 0 for i in range(K+1): temp = pow25[i] temp *= cmb(i+N-1, N-1) temp *= pow26[K-i] ans += temp ans %= MOD print(ans)
0
null
7,889,245,558,580
76
124
class Solution: def solve(self, N: int, P: int, S: str): if P == 2 or P == 5: answer = 0 for idx, s in enumerate(S): if int(s) % P == 0: answer += idx + 1 else: answer = 0 U = [0] * P # int(S[i,N] mod P U[0] += 1 num = 0 base10_mod_p = 1 for i in range(N): num = (num + int(S[N-i-1]) * base10_mod_p) % P base10_mod_p = (base10_mod_p * 10) % P U[num] += 1 for u in U: answer += u * (u-1) // 2 return answer if __name__ == '__main__': # standard input N, P = map(int, input().split()) S = input() # solve solution = Solution() answer = solution.solve(N, P, S) print(answer)
import sys # import numba as nb import numpy as np input = sys.stdin.readline # @nb.njit("i8(i8[:],i8,i8)", cache=True) def solve(N, K, L): dp = np.zeros(shape=(L + 1, 2, K + 1), dtype=np.int64) dp[0][0][0] = 1 for i in range(L): D = N[i] for j in range(2): d_max = 9 if j == 1 else D for k in range(K + 1): if k < K: for d in range(d_max + 1): dp[i + 1][int(j or (d < D))][k + int(d > 0)] += dp[i][j][k] else: dp[i + 1][j][k] += dp[i][j][k] return dp[L][0][K] + dp[L][1][K] def main(): N = np.array(list(input().rstrip()), dtype=np.int64) K = int(input()) L = N.shape[0] ans = solve(N, K, L) print(ans) if __name__ == "__main__": main()
0
null
67,295,490,530,244
205
224
import math class Point: def __init__(self,arg_x,arg_y): self.x = arg_x self.y = arg_y def roll(div1,div2): tmp_start = Point(div2.x-div1.x,div2.y-div1.y) tmp_end = Point(tmp_start.x*math.cos(math.pi/3) -tmp_start.y*math.sin(math.pi/3), tmp_start.x*math.sin(math.pi/3) + tmp_start.y*math.cos(math.pi/3)) ret = Point(tmp_end.x + div1.x,tmp_end.y + div1.y) return ret; def outPut(point): print("%.8f %.8f"%(point.x,point.y)) def calc(left,right,count): div1 = Point((2*left.x + right.x)/3,(2*left.y + right.y)/3) div2 = Point((2*right.x + left.x)/3,(2*right.y + left.y)/3) peek = roll(div1,div2) if count > 1: calc(left,div1,count-1) calc(div1,peek,count-1) calc(peek,div2,count-1) calc(div2,right,count-1) else: outPut(left); outPut(div1); outPut(peek); outPut(div2); N = int(input()) left = Point(0,0) right = Point(100,0) if N == 0: outPut(left) outPut(right) else: calc(left,right,N) outPut(right)
N=int(input()) A=list(map(int,input().split())) B=sum(A) b=0 ans=202020202020 for a in A: b+=a ans=min(ans,abs(B-b*2)) print(ans)
0
null
71,261,986,003,030
27
276
import numpy as np A = [] for i in range(3): b = list(map(int, input().split())) A.append(b) N = int(input()) NP_A = np.array(A) b = [] for n in range(N): b.append(int(input())) for n in range(N): NP_A = np.where(NP_A==b[n], 0, NP_A) ans = "No" for i in range(2): if 0 in NP_A.sum(axis=i): ans = "Yes" break if ans == "Yes": pass else: sum = 0 for i in range(3): sum += NP_A[i, i] if sum == 0: ans = "Yes" else: sum = NP_A[0, 2] + NP_A[1, 1] + NP_A[2, 0] if sum == 0: ans = "Yes" print(ans)
import math n,m,t = map(int,input().split()) if n%m == 0: print(int(n/m)*t) else: print(math.ceil(n/m)*t)
0
null
32,035,612,429,652
207
86
X,Y,A,B,C =map(int,input().split()) P = list(map(int,input().split())) Q = list(map(int,input().split())) R = list(map(int,input().split())) P.sort() Q.sort() R.sort() P_new = P[-X::] Q_new = Q[-Y::] agg = P_new + Q_new +R agg.sort() print(sum(agg[-X-Y::]))
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): X, Y, A, B, C = map(int, input().split()) p = sorted(list(map(int, input().split())), reverse=True) q = sorted(list(map(int, input().split())), reverse=True) r = sorted(list(map(int, input().split()))) ans = [] ans += p[:X] ans += q[:Y] ans.sort(reverse=True) #print(ans, r) cl = 0 while len(ans) and len(r): if ans[-1] < r[-1]: cl += r[-1] ans.pop(-1) r.pop(-1) else: break #print(ans, cl) print(sum(ans) + cl) if __name__ == '__main__': solve()
1
44,857,000,733,380
null
188
188
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10 ** 9) 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())) INF=float('inf') N=INT() nodes=[[] for i in range(N)] for i in range(N): l=LIST() u=l[0] l=l[2:] for v in l: nodes[u-1].append(v-1) nodes[u-1].sort() ans=[[0]*2 for i in range(N)] visited=[False]*N time=0 def rec(u): if visited[u]: return visited[u]=True global time time+=1 ans[u][0]=time for v in nodes[u]: rec(v) time+=1 ans[u][1]=time for i in range(N): rec(i) for i in range(N): d,f=ans[i] print(i+1, d, f)
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja import sys input = sys.stdin.readline N = int(input()) G = [[a-1 for a in list(map(int, input().split()))[2:]] for _ in [0]*N] visited = [0]*N history = [[] for _ in [0]*N] k = 0 def dfs(v=0, p=-1): global k visited[v] = 1 k += 1 history[v].append(k) for u in G[v]: if u == p or visited[u]: continue dfs(u, v) k += 1 history[v].append(k) for i in range(N): if not visited[i]: dfs(i) for i, h in enumerate(history): print(i+1, *h)
1
2,875,695,904
null
8
8
import sys input = sys.stdin.readline def main(): n, k = map(int, input().split()) products = [int(input()) for _ in range(n)] left = 1 right = 10000 * 100000 # 最大重量 × 最大貨物数 while left < right: mid = (left + right) // 2 # print("left:{}".format(left)) # print("right:{}".format(right)) # print("mid:{}".format(mid)) v = allocate(mid, k, products) # print("count:{}".format(v)) if n <= v: right = mid else: left = mid + 1 print(right) def allocate(capacity, truckNum, products): # print("===== start allocation capacity:{}======".format(capacity)) v = 0 tmp = 0 truckNum -= 1 while len(products) > v: product = products[v] # print("tmp weight:{}".format(tmp)) # print("product weight:{}".format(product)) if product > capacity: # print("capacity over") # そもそも1個も乗らない時避け return 0 if tmp + product <= capacity: # 同じトラックに積み続ける tmp += product else: # 新しいトラックがまだあればつむ if truckNum > 0: # print("new truck") truckNum -= 1 tmp = product else: return v v += 1 return v if __name__ == '__main__': main()
N, K = [int(s) for s in raw_input().split()] ws = [int(raw_input()) for _ in xrange(N)] lo, hi = max(ws) - 1, sum(ws) while hi - lo > 1: p = P = (lo + hi) / 2 k = 1 for w in ws: if w > p: p = P k += 1 p -= w if k <= K: hi = P else: lo = P print hi
1
84,397,854,552
null
24
24
x = int(input()) prlist = [] n = 2 sosuu = 0 answer = 0 while n**2 < x: for i in prlist: if n % i == 0: sosuu = 1 break if sosuu == 0: prlist.append(n) sosuu = 0 n += 1 sosuu = 1 while answer == 0: for j in prlist: if x % j == 0: sosuu = 2 break if sosuu == 1: answer = x sosuu = 1 x += 1 print(answer)
S = str(input()) T = "x" * len(S) print(T)
0
null
89,154,571,973,510
250
221
#! /usr/local/bin/python3 # coding: utf-8 print(int(input()) ** 3)
_ = input() a = list(input()) cnt = 0 word = 0 for i in a: if word == 0 and i == 'A': word = 1 elif word == 1 and i =='B': word = 2 elif word == 2 and i =='C': word = 0 cnt += 1 else: if i == 'A': word = 1 else: word = 0 print(cnt)
0
null
49,622,258,550,420
35
245
class dictionary: def __init__(self): self._d = set() def insert(self, s): self._d.add(s) def find(self, s): if s in self._d: print("yes") else: print("no") if __name__ == '__main__': dd = dictionary() n = int(input()) for _ in range(n): args = input().split() if args[0] == "insert": dd.insert(args[1]) elif args[0] == "find": dd.find(args[1])
N, X, T = map(int, input().split()) times = N // X if N % X != 0: times += 1 print(T * times)
0
null
2,137,289,342,498
23
86
def main(): X, Y, Z = map(int, input().split()) return " ".join(map(str, [Z, X, Y])) if __name__ == '__main__': print(main())
n,k = input().split() k = int(k) #print(n,k) p = [int(s) for s in input().split()] p.sort() #print(p) #print(k) p2 = p[0:k] #print(p2) s = sum(p) #print(s) print(sum(p2))
0
null
24,786,536,827,558
178
120
n, p = map(int, input().split()) if p in (2, 5): c = 0 for i, x in enumerate(map(int, input()[::-1])): if x % p == 0: c += n-i print(c) else: c = [0] * p y = 0 t = 1 for x in map(int, input()[::-1]): y = (y + t*x) % p c[y] += 1 t = (10 * t) % p print(sum(i * (i-1) // 2 for i in c) + c[0])
import sys while True: h, w = [ int( val ) for val in sys.stdin.readline().split( " " ) ] if 0 ==h and 0 == w: break pa = [ "#", "." ] ouput = [] for i in range( h ): for j in range( w ): ouput.append( pa[(i+j)%2] ) ouput.append( "\n" ) print( "".join( ouput ) )
0
null
29,394,001,314,820
205
51
s = input() t = "" for i in range(len(s)): if s[i].islower(): t += s[i].upper() elif s[i].isupper(): t += s[i].lower() else: t += s[i] print(t)
# -*- coding: utf-8 -*- char = input() print(char.swapcase())
1
1,526,359,424,660
null
61
61
n = int(input()) print((n-1)//2)
S=input() flg = True for i in range(len(S)): if len(S)%2 == 1: flg = False break if i%2==0: if S[i]+S[i+1] != "hi": flg = False if flg == True: print("Yes") else: print("No")
0
null
103,544,440,781,180
283
199
import re import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def v(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 6) mod = 10**9+7 cnt = 0 ans = 0 inf = float("inf") al = "abcdefghijklmnopqrstuvwxyz" AL = al.upper() n = k() a = l() sum = 1000 for i in range(n-1): if a[i] > a[i+1]: xx = a[cnt:i+1] b = sum//min(xx) sum += (max(xx)-min(xx))*b cnt = i+1 xx = a[cnt:] b = sum//min(xx) sum += (max(xx)-min(xx))*b print(sum)
import sys from collections import defaultdict sys.setrecursionlimit(10**8) N = int(input()) graph = [[] for _ in range(N)] numOfEdges = [0 for _ in range(N)] visited = [0 for _ in range(N)] edges = defaultdict(int) for i in range(1, N): a, b = map(int, input().split()) a -= 1; b -= 1; numOfEdges[a] += 1 numOfEdges[b] += 1 edges[(a, b)] = 0 graph[a].append(b) graph[b].append(a) def dfs(prev, now, col): if visited[now]: return visited[now] = 1 i = 1 for adj in graph[now]: if adj == prev: continue if now < adj: edges[(now, adj)] = col + i else: edges[(adj, now)] = col + i dfs(now, adj, col+i) i += 1 dfs(-1, 0, 1) maxColor = max(numOfEdges) print(maxColor) for k, i in edges.items(): e = i % maxColor if e: print(e) else: print(maxColor)
0
null
71,444,969,076,360
103
272
# coding: utf-8 """ import codecs import sys sys.stdout = codecs.getwriter("shift_jis")(sys.stdout) # ?????? sys.stdin = codecs.getreader("shift_jis")(sys.stdin) # ??\??? # ??\??¬?????????print??????????????´?????? print(u'?????????') ??¨?????? # ??\??¬?????????input??? input(u'?????????') ??§OK # ??°?¢???????????????????????????´??????6,7???????????????????????¢?????? """ s = raw_input() p = raw_input() #s = "abaabbaabbaaaaaabbaabba" #p = "aabbaabaabb" cnt = s.count(p[0]) #????§?????£?????????° flag = 0 if cnt == -1: #p???????????????????????¨????????? print("No") else: #????§?????£?????????¨?????? start_search = 0 #????´¢?????????????§??????? while cnt > 0: index = s.find(p[0], start_search) #????§???????????????? ans = 1 for i in range(len(p)): if index + i >= len(s): #????°?????????????????????´?????????????????????????????????????????? j = i - len(s) else: j = i if s[index + j] != p[i]: #1????????§????????£????????????????????§??¢?´¢?????? ans = 0 break if ans == 1: print("Yes") flag = 1 break start_search = index + 1 #print(start_search) cnt -= 1 if flag == 0: print("No")
import sys read = sys.stdin.readline import time import math import itertools as it def inp(): return int(input()) def inpl(): return list(map(int, input().split())) start_time = time.perf_counter() # ------------------------------ A = inpl() A.sort() if A[0]!=A[2]: if A[0]==A[1]: print('Yes') sys.exit() if A[1]==A[2]: print('Yes') sys.exit() print('No') # ----------------------------- end_time = time.perf_counter() print('time:', end_time-start_time, file=sys.stderr)
0
null
34,741,548,524,782
64
216
from sys import stdin, setrecursionlimit def main(): s, t = map(str, stdin.readline().split()) a, b = map(int, stdin.readline().split()) u = stdin.readline()[:-1] if s == u: a -= 1 else: b -= 1 print(a, b) if __name__ == "__main__": setrecursionlimit(10000) main()
from collections import defaultdict N, K = map(int, input().split()) A = list(map(int, input().split())) visited = [0] * N current = 0 i = 1 while i <= K: current = A[current] - 1 if visited[current] == 0: visited[current] = i else: loop = i - visited[current] num_loop = (K - i) // loop i += loop * num_loop i += 1 ans = current + 1 print(ans)
0
null
47,212,980,991,136
220
150
import sys class UnionFind(): def __init__(self, n): self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x N, M = map(int, input().split()) uf = UnionFind(N) for _ in range(M): a, b = map(lambda x: int(x) - 1, sys.stdin.readline().split()) uf.union(a, b) print(sum(p < 0 for p in uf.parents) - 1)
from collections import deque N,M = map(int,input().split()) l = [[] for _ in range(N+1)] for _ in range(M): a,b = map(int,input().split()) l[a].append(b) l[b].append(a) check = [0]*(N+1) cnt = 0 for i in range(1,N+1): if check[i] == 1: continue st = deque([i]) check[i] = 1 while st: s = st.popleft() for t in l[s]: if check[t] == 0: check[t] = 1 st.append(t) continue cnt += 1 print(cnt-1)
1
2,289,580,428,498
null
70
70
N, X, T = map(int, input().split()) S = int((N+X-1)/X) print(S*T)
def main(N, X, T): ans = N//X * T if N%X != 0: ans += T return ans if __name__ == '__main__': N, X, T = map(int, input().split()) ans = main(N, X, T) print(ans)
1
4,246,197,331,340
null
86
86
k,n=map(int,input().split()) a=list(map(int,input().split())) a.sort() dm=0 for i in range(n): dis=(a[i]-a[i-1])%k dm=max(dm,dis) print(k-dm)
# -*- coding: utf-8 -*- k, n = map(int, input().split()) a = list(map(int, input().split())) fst = a[0] a.append(k+fst) dis= [] for i in range(n): dis.append(a[i+1]-a[i]) print(sum(dis)-max(dis))
1
43,333,114,921,760
null
186
186
import itertools N,K = map(int,input().split()) A = list(map(int,input().split())) for i in range(K): TEMP = [0]*(N+1) for j in range(N): TEMP[max(0,j-A[j])] +=1 TEMP[min(N,j+A[j]+1)] -=1 A = list(itertools.accumulate(TEMP)) if A[0] == N and A[N-1] == N: break A.pop() print(*A)
import math N, K = map(int, input().split()) lightPow = list(map(int, input().split())) for i in range(K): newLightPow = [0]*(N+1) #print(lightPow) for pos in range(1, N+1): low = pos - lightPow[pos-1] high = pos + lightPow[pos-1] low = min(max(1, low), N) high = min(max(1, high), N) newLightPow[low-1] += 1 newLightPow[high] -= 1 #print("pos:"+str(pos)) #print("low"+str(low)+" high"+str(high)) #print(newLightPow) check = True for i in range(0, N): if (i > 0): newLightPow[i] += newLightPow[i-1] if (newLightPow[i] < N): check = False lightPow = newLightPow if (check): break print(*lightPow[:-1])
1
15,417,021,824,036
null
132
132
mod = 10 ** 9 + 7 mod2 = 2**61+1 from collections import deque import heapq from bisect import bisect_left, insort_left, bisect_right def iip(listed=True): ret = [int(i) for i in input().split()] if len(ret) == 1 and not listed: return ret[0] return ret def iip_ord(): return [ord(i) - ord("a") for i in input()] def main(): ans = solve() if ans is not None: print(ans) def solve(): N, T = iip() dp1 = [[0 for _ in range(T)] for _ in range(N + 1)] dp2 = [[0 for _ in range(T)] for _ in range(N + 1)] AB = [iip() for i in range(N)] for i, ab in enumerate(AB, 1): a, b = ab for j in range(T): dp1[i][j] = dp1[i-1][j] for j in reversed(list(range(T))): if j+a >= T: continue dp1[i][j + a] = max(dp1[i][j + a], dp1[i][j] + b) for i, ab in enumerate(reversed(AB), 1): a, b = ab for j in range(T): dp2[i][j] = dp2[i-1][j] for j in reversed(list(range(T))): if j + a >= T: continue dp2[i][j + a] = max(dp2[i][j + a], dp2[i][j] + b) #dp2.reverse() mm = 0 for i in range(N): for j in range(T): ii1 = i ii2 = N-i-1 ii3 = i ij1 = j ij2 = T-j-1 a = dp1[ii1][ij1] b = dp2[ii2][ij2] c = AB[ii3][1] #print(ii1, ii2, ij1, ij2, ii3, a, b, c, a+b+c) #print(a, b, c) mm = max(a+b+c, mm) #print(i, j, cur, a, b) #print(dp1) #print(dp2) print(mm) #####################################################ライブラリ集ここから def fprint(s): for i in s: print(i) def split_print_space(s): print(" ".join([str(i) for i in s])) def split_print_enter(s): print("\n".join([str(i) for i in s])) def koenai_saidai_x_index(sorted_list, n): l = 0 r = len(sorted_list) if len(sorted_list) == 0: return False if sorted_list[0] > n: return False while r - l > 1: x = (l + r) // 2 if sorted_list[x] == n: return x elif sorted_list[x] > n: r = x else: l = x return l def searchsorted(sorted_list, n, side): if side not in ["right", "left"]: raise Exception("sideはrightかleftで指定してください") l = 0 r = len(sorted_list) if n > sorted_list[-1]: # print(sorted_list) return len(sorted_list) if n < sorted_list[0]: return 0 while r - l > 1: x = (l + r) // 2 if sorted_list[x] > n: r = x elif sorted_list[x] < n: l = x else: if side == "left": r = x elif side == "right": l = x if side == "left": if sorted_list[l] == n: return r - 1 else: return r if side == "right": if sorted_list[l] == n: return l + 1 else: return l def soinsuu_bunkai(n): ret = [] for i in range(2, int(n ** 0.5) + 1): while n % i == 0: n //= i ret.append(i) if i > n: break if n != 1: ret.append(n) return ret def conbination(n, r, mod, test=False): if n <= 0: return 0 if r == 0: return 1 if r < 0: return 0 if r == 1: return n ret = 1 for i in range(n - r + 1, n + 1): ret *= i ret = ret % mod bunbo = 1 for i in range(1, r + 1): bunbo *= i bunbo = bunbo % mod ret = (ret * inv(bunbo, mod)) % mod if test: # print(f"{n}C{r} = {ret}") pass return ret def inv(n, mod): return power(n, mod - 2) def power(n, p, mod_= mod): if p == 0: return 1 if p % 2 == 0: return (power(n, p // 2, mod_) ** 2) % mod_ if p % 2 == 1: return (n * power(n, p - 1, mod_)) % mod_ if __name__ == "__main__": main()
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])
0
null
100,747,184,905,248
282
195
times, disp_rate = map(int, input().split()) int_rate = 0 # 参加回数が10回未満の場合 if times < 10: # 内部レートを計算する int_rate = disp_rate + 100 * (10-times) else: int_rate = disp_rate print(int_rate)
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): 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): 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 ide_ele=0 def segfunc(x,y): return x|y def popcount(x): x = x - ((x >> 1) & 0x55555555) x = (x & 0x33333333) + ((x >> 2) & 0x33333333) x = (x + (x >> 4)) & 0x0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) return x & 0x0000007f import sys input=sys.stdin.readline N=int(input()) S=input().rstrip() init_val=[1<<(ord(S[i])-97) for i in range(N)] test=SegTree(init_val,segfunc,ide_ele) for _ in range(int(input())): t,l,r=input().split() t,l=int(t),int(l) if t==1: val=ord(r)-97 test.update(l-1,1<<val) else: r=int(r) res=test.query(l-1,r) print(popcount(res))
0
null
63,398,140,248,832
211
210
s = input() p = input() flag = 0 for i in range(len(s)): if flag == 1: break if s[i] == p[0]: if len(p) == 1: print("Yes") flag = 1 break for j in range(1, len(p)): i = (i + 1) % len(s) if s[i] != p[j]: break if j == len(p)-1: print("Yes") flag = 1 break if flag == 0: print("No")
''' ITP-1_8-D ????????° ???????????????????????°??¶???????????? ss ???????????????????????????????¨????????????£?¶????????????????????????????????????§??? ????????? pp ??????????????????????????????????????°???????????????????????????????????? ???Input ????????????????????? ss ???????????????????????? ????????????????????? pp ???????????????????????? ???Output pp ??????????????´?????? Yes ??¨?????????????????´?????? No ??¨???????????????????????????????????? ''' # inputData x = str(input()) y = str(input()) xString = [] for i in x: xString.append(i) yString = [] for i in y: yString.append(i) n = len(yString) flag = 0 for i in range(len(xString)): if xString[i:i+n] == yString: flag = 1 break if i+n > len(xString): if xString[i:]+xString[0:(i+n)%len(xString)] == yString: flag = 1 break # outputCheck if flag == 0: print('No') elif flag == 1: print('Yes')
1
1,744,705,334,190
null
64
64
s = int(input()) print((1000-s%1000)%1000)
from collections import Counter N,MOD=map(int,input().split()) S=input() res=0 if MOD==2 or MOD==5: for i in range(N): if(int(S[N-i-1])%MOD==0): res+=N-i else: Cum=[0]*(N+1) for i in range(N): Cum[i+1]=(Cum[i]+int(S[N-i-1])*pow(10,i,MOD))%MOD c=Counter(Cum).most_common() for a,b in c: res+=b*(b-1)//2 print(res)
0
null
33,245,702,417,892
108
205
N, K = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(K)] mod = 998244353 dp = [0] * N dp[0] = 1 now = 0 for i in range(1, N): for l, r in LR: if i - l >= 0: now += dp[i - l] now %= mod if i - r - 1 >= 0: now -= dp[i - r - 1] now %= mod dp[i] = now #print(dp) print(dp[-1])
N=int(input()) for a in range(1,10): for b in range(1,10): if a*b==N: print('Yes') exit() print('No')
0
null
81,143,560,936,042
74
287
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n,m = inpl() h = inpl() g = [[] for _ in range(n)] for _ in range(m): a,b = inpl() a,b = a-1,b-1 g[a].append(b) g[b].append(a) res = 0 for i in range(n): for j in g[i]: if h[j] >= h[i]: break else: res += 1 print(res)
n, m = map(int, input().split()) hlist = list(map(int, input().split())) num = [0]*n for j in range(m): a, b = map(int, input().split()) if hlist[a-1] > hlist[b-1]: num[b-1] = 1 elif hlist[a-1] < hlist[b-1]: num[a-1] = 1 elif hlist[a-1] == hlist[b-1]: num[a-1] = 1 num[b-1] = 1 print(num.count(0))
1
25,259,606,234,048
null
155
155
from math import gcd K = int(input()) goukei = 0 for a in range(1,K+1): for b in range(1,K+1): G = gcd(a,b) for c in range(1,K+1): goukei += gcd(G,c) print(goukei)
import math k = int(input()) ans = 0 for h in range(1, k+1): for i in range(1, k+1): g = math.gcd(h, i) for j in range(1, k+1): ans += math.gcd(g, j) print(ans)
1
35,624,779,450,600
null
174
174
# -*- coding: UTF-8 -*- #Selection Sort #標準入力から N = int(input()) #要素数 A = list(map(int,input().split())) #ソート対象(スペース区切り→配列に展開) #交換回数 cnt = 0 #Sort処理 for i in range(N): cnt_flg = 0 minj = i for j in range(i,N): if A[j] < A[minj]: minj = j cnt_flg = 1 tmp = A[i] A[i] = A[minj] A[minj] = tmp if cnt_flg == 1: cnt+=1 #回答 print(' '.join(map(str,A))) print(cnt)
n = int(input()) k = [int(i) for i in input().split()] m = 0 for i in range(n): minj = i for j in range(i,n): if k[j] < k[minj]: minj = j x = k[i] k[i] = k[minj] k[minj]=x if k[i] != k[minj]: m += 1 print(' '.join(map(str, k))) print(m)
1
21,752,496,822
null
15
15
import sys while True: n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ] if 0 == n and 0 == x: break cnt = 0 for i in range( 1, n-1 ): if x <= i: break for j in range( i+1, n ): if x <= ( i+j ): break for k in range( j+1, n+1 ): s = ( i + j + k ) if x == s: cnt += 1 break elif x < s: break print( cnt )
a = input() N = int(a) A = list(map(int,input().split())) flag = 0 y = 1000 for i in range(1,N): if A[i-1] < A[i] and flag == 0: x = y//A[i-1] y = y % A[i-1] flag = 1 if (A[i-1] > A[i]) and flag == 1: y = y + A[i-1]*x flag = 0 if flag == 1 and i == N-1: y = y + A[i]*x print(y)
0
null
4,253,738,041,290
58
103
N = int(input()) A = list(map(int,input().split())) cnt = 0 for i in range(N): minj = i for j in range(i+1,N): if A[j] < A[minj]: minj = j if i != minj: A[i],A[minj] = A[minj],A[i] cnt += 1 print(*A) print(cnt)
def SelectionSort(A, n): sw = 0 for i in xrange(n): minj = i for j in xrange(i, n): if A[j] < A[minj]: minj = j temp = A[minj] A[minj] = A[i] A[i] = temp if i != minj: sw += 1 return sw def printArray(A, n): for i in xrange(n): if i < n-1: print A[i], else: print A[i] n = input() arr = map(int, raw_input().split()) cnt = SelectionSort(arr, n) printArray(arr, n) print cnt
1
19,738,864,860
null
15
15
S = input()[::-1] ## 余りを0~2018で総数保持 counts = [0]*2019 ## 0桁の余りは0 counts[0] = 1 num, d = 0, 1 for c in S: ## 右から~桁の数字 num += int(c) * d num %= 2019 ## 次の桁 d *= 10 d %= 2019 counts[num] += 1 ans = 0 for cnt in counts: ## nC2の計算 ans += cnt * (cnt-1) //2 print(ans)
s = list(map(int,input())) s.reverse() t = len(s) mod = 2019 arr = [0] * (t+1) arr[-2] = s[0] for i in range(1,t): arr[t-i-1] = (arr[t-i] + s[i]*pow(10,i,mod)) % mod from collections import Counter arr = Counter(arr) ans = 0 for i in arr: ans += (arr[i] - 1) * arr[i] // 2 print(ans)
1
30,729,976,640,482
null
166
166
import sys input = lambda: sys.stdin.readline()[:-1] n,k=map(int,input().split()) w = [int(input()) for i in range(n)][::-1] def maxnumber(p): wc=w.copy() for i in range(k): lim=p while len(wc): if wc[-1]<=lim: lim-=wc.pop() else:break return len(wc) minp=float('inf') left,right=1,10**9+1 while left<right: mid=(left+right)//2 maxn=maxnumber(mid) if maxn>0: left=mid+1 else: right=mid minp=min(mid,minp) print(minp)
N, K = map(int, input().split()) W = [int(input()) for w in range(N)] def check(p): i = 0 for _ in range(K): s = 0 while s + W[i] <= p: s += W[i] i += 1 if i == N: return N return i left = 0 right = 100000 * 10000 mid = 0 while 1 < right - left: mid = (left + right) / 2 v = check(mid) if v >= N: right = mid else: left = mid print(int(right))
1
88,725,859,080
null
24
24
S = input() ans = 'Yes' while S: if S.startswith('hi'): S = S[2:] else: ans = 'No' break print(ans)
# 726 diff 1000 # 解法 836 XYへ到達する場合はどの経路も合計の長さは同じ = 動き方1,2の合計は同じ. # なので合計値 L がわかればLについてmove1=i,move2=L-iとして,実際の経路の構成の仕方は,L_C_iなので move1 = [1,2] move2 = [2,1] X,Y = map(int,input().split()) # まず,目的地へ到達できるか?到達できる場合は合計どれだけの移動量が必要かを計算する max_move1 = int(Y/2) move2_num = -1 move1_num = -1 for i in range(max_move1+1): rest = [X-i,Y-2*i] if (X-i) == 2*(Y-2*i): move1_num = i move2_num = (Y-2*i) if move1_num == -1: print(0) exit() # 到達するのに必要な合計の移動量がわかったので,それらの並べ替えについて考える. # 求めるのは nCk すなわち,いつもの奴 large = 10**9 + 7 # mod(x^p-1,p) = 1 よってmod(x^p-2,p) = 1/x となる. ans = 1 for i in range(move1_num): ans *= (move1_num+move2_num - i) ans %= large for j in range(2,move1_num+1): ans *= pow(j,large-2,large) ans %= large print(ans)
0
null
101,622,948,693,760
199
281
n, k = map(int, input().split()) data = list(map(int, input().split())) left = 0 right = k while right < n: if data[left] < data[right]: print('Yes') else: print('No') left += 1 right += 1
n,a,b=map(int,input().split()) res=n//(a+b)*a if n%(a+b)>=a: res+=a else: res+=n%(a+b) print(res)
0
null
31,204,677,272,348
102
202
Flag = True data = [] while Flag: H, W = map(int, input().split()) if H == 0 and W == 0: Flag = False else: data.append((H, W)) #print(data) for (H, W) in data: for i in range(H): print('#' * W) print('\n', end="")
α=input() if α.isupper(): print('A') elif α.islower(): print('a')
0
null
6,017,530,364,862
49
119
from math import ceil, floor N = int(input()) half = floor(N / 2) count = 0 for i in range(half): count = count + 1 if N % 2 != 0: print(count) else: print(count - 1)
print((int(input())-1)>>1)
1
152,887,339,575,298
null
283
283
def main(): from bisect import bisect_left as bl from itertools import accumulate as ac n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() aa = [0]+list(ac(a)) an = aa[n] ok = 0 ng = 10**10 while abs(ok-ng) > 1: mid = (ok+ng)//2 if sum([n-bl(a, mid-a[i]) for i in range(n)]) >= m: ok = mid else: ng = mid c = -m+sum([n-bl(a, ok-a[i]) for i in range(n)]) ans = -c*ok for i in range(n): d = bl(a, ok-a[i]) ans += an-aa[d]+(n-d)*a[i] print(ans) main()
import sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = [-10**10] + LI() A.sort() mod = 10**9+7 B = [0]*(K-1) + [1] # B[i] = i_C_(K-1) for i in range(K,N): B.append((B[-1]*i*pow(i-(K-1),mod-2,mod)) % mod) ans = 0 for i in range(1,N+1): ans += (B[i-1]-B[N-i])*A[i] ans %= mod print(ans)
0
null
101,720,046,205,778
252
242
n = int(input()) input_line = input().split() member = [int(input_line[i]) for i in range(n)] stands = 0 for i in range(1,n): stand = member[i-1] - member[i] if stand > 0: stands += stand member[i] += stand print(stands)
def main(): N, A = int(input()), list(map(int, input().split())) ans = 0 for idx in range(1, N): if A[idx] < A[idx - 1]: diff = A[idx - 1] - A[idx] ans += diff A[idx] = A[idx - 1] print('{}'.format(ans)) if __name__ == '__main__': main()
1
4,553,290,187,310
null
88
88
A,B=map(int,input().split()) for money in range(1,1001): if int(money*0.08)==A and int(money*0.1)==B: print(money) break else: print(-1)
# coding: utf-8 def main(): A, B = map(int, input().split()) ans = -1 for i in range(10001): if i * 8 // 100 == A and i // 10 == B: ans = i break print(ans) if __name__ == "__main__": main()
1
56,706,206,823,100
null
203
203
import math def resolve(): a, b, x = map(int, input().split()) met = a ** 2 * b / 2 if x > met: y = 2 * b - 2 * x / a**2 ans = math.atan2(y, a) elif x == met: ans = math.pi / 4 else: y = 2 * x / a / b ans = math.pi / 2 - math.atan2(y, b) print(math.degrees(ans)) resolve()
import math a, b, x = map(int, input().split()) if a*a*b == x: print(0) elif a*a*b <= 2*x: print(90-math.degrees(math.atan(a*a*a/(2*a*a*b-2*x)))) else: print(90-math.degrees(math.atan(2*x/(a*b*b))))
1
162,821,790,459,748
null
289
289
#!/usr/bin python3 # -*- coding: utf-8 -*- n, m = map(int, input().split()) s = input() s = s[::-1] INF = 2*n if '1'*m in s: print(-1) exit() dp = [-1] * (n+1) nw = 0 st = 0 nst = 0 ret = [] while nw < (n+1): if s[nw]=='1': dp[nw] = INF else: dp[nw] = dp[st] + 1 nst = nw nw += 1 if nw == n+1: ret.append(nst-st) elif nw > st + m: ret.append(nst-st) st = nst print(' '.join(map(str,ret[::-1])))
N = int(input()) arr = [int(n) for n in input().split()] swap_cnt = 0 for i in range(0, N): minj = i for j in range(i + 1, N): if arr[j] < arr[minj]: minj = j if (i != minj): arr[i], arr[minj] = arr[minj], arr[i] swap_cnt += 1 print(' '.join(map(str, arr))) print(swap_cnt)
0
null
69,588,960,049,680
274
15
H,W,K = list(map(int, input().split())) table = [input() for _ in range(H)] ans = 0 for mask_h in range(2 ** H): for mask_w in range(2 ** W): black = 0 for i in range(H): for j in range(W): if ((mask_h >> i) & 1 == 0) and ((mask_w >> j) & 1 == 0) and table[i][j] == '#': # 塗り潰し行、列ではなくて、色が黒'#'の場合 black += 1 if black == K: ans += 1 print(str(ans))
from sys import stdin def main(): #入力 readline=stdin.readline n,m=map(int,readline().split()) s=readline().strip() ans=[] flag=False i=n while True: max_i=i for sa in range(1,m+1): if i-sa==0: ans.append(sa) flag=True break else: if s[i-sa]=="0": max_i=i-sa if flag: break else: if max_i!=i: ans.append(i-max_i) i=max_i else: break if flag: ans.reverse() print(*ans) else: print(-1) if __name__=="__main__": main()
0
null
73,601,782,394,578
110
274
#!/usr/bin/env python def solve(A: int, B: int, C: int, K: int): if A >= K: return K K -= A if B >= K: return A K -= B return A - K def main(): A, B, C, K = map(int, input().split()) answer = solve(A, B, C, K) print(answer) if __name__ == "__main__": main()
A,B,C,K = [int(x) for x in input().split()] if(A >= K): print(K) exit() K = K - A if(B >= K): print(A) exit() K = K - B print(A-K)
1
21,845,578,821,250
null
148
148
dic = set() n = int(input()) for i in range(n): cmd, val = input().split() if cmd == "insert": dic.add(val) elif cmd == "find": print("yes" if val in dic else "no") else: print("wrong command")
def insert(cnt, data): T[str(data)] = cnt cnt = 0 T = {} n = int(input()) for i in range(n): Order, data_S = input().split() if Order[0] =="i": insert(cnt, data_S) cnt +=1 else: if str(data_S) in T: print("yes") else: print("no")
1
80,390,031,358
null
23
23
n = int(input()) num_list = input().split() mod_value = 10**9 + 7 sum_all = 0 sum_int = 0 for index in range(len(num_list) - 1): sum_int += int(num_list[index]) sum_all += sum_int * int(num_list[index + 1]) if sum_all > mod_value: sum_all %= mod_value print(sum_all)
card = [] check = [[0, 0, 0] for i in range(3)] for i in range(3): card.append(list(map(int, input().split()))) n = int(input()) for i in range(n): b = int(input()) for j in range(3): for k in range(3): if b == card[j][k]: check[j][k] = 1 flag = 0 for i in range(3): if check[i][0] == check[i][1] == check[i][2] == 1: flag = 1 break elif check[0][i] == check[1][i] == check[2][i] == 1: flag = 1 break elif check[0][0] == check[1][1] == check[2][2] == 1: flag = 1 break elif check[0][2] == check[1][1] == check[2][0] == 1: flag = 1 break if flag: print('Yes') else: print('No')
0
null
31,861,797,168,708
83
207
import sys readline = sys.stdin.readline INF = 10 ** 10 def main(): N, M = map(int, readline().rstrip().split()) C = list(map(int, readline().rstrip().split())) dp = [INF] * (N + 1) dp[0] = 0 for c in C: for i in range(c, N+1): dp[i] = min(dp[i], dp[i-c] + 1) print(dp[N]) if __name__ == '__main__': main()
# https://onlinejudge.u-aizu.ac.jp/problems/DPL_1_A INF = float('inf') if __name__ == "__main__": N, M = list(map(int, input().split())) C = list(map(int, input().split())) dp = [INF for _ in range(N+1)] dp[0] = 0 for i in range(M): c = C[i] for n in range(c, N+1): if dp[n-c] == INF: continue else: dp[n] = min(dp[n-c] + 1, dp[n]) print(dp[N])
1
137,417,884,172
null
28
28
H,A = map(int,input().split()) ans = H // A if H % A != 0: ans += 1 print(ans)
print((lambda x: (x[0]-1)//x[1]+1)(list(map(int,input().split()))))
1
76,893,893,807,590
null
225
225
#!/usr/bin/env python #coding: UTF-8 import sys while True: hight,width = map (int,raw_input().split()) if hight+width == 0: break else: for h in range(hight): if h%2 == 0: for w in range(width): if w%2 == 0: sys.stdout.write("#") else: sys.stdout.write(".") print "" else: for w in range(width): if w%2 == 0: sys.stdout.write(".") else: sys.stdout.write("#") print "" print ""
while 1: H, W = map(int,raw_input().split()) if H ==0 and W == 0: break for i in range(H): if i%2==0: if W%2==0: print "#."*(W/2) elif W%2==1: print "#."*(W/2)+"#" elif i%2==1: if W%2==0: print ".#"*(W/2) elif W%2==1: print ".#"*(W/2)+"." print ""
1
883,018,812,422
null
51
51
N = int(input()) S = input() if N%2 == 1: print("No") else: a = 0 for i in range(N//2): if S[i] != S[N//2+i]: a += 1 if a == 0: print("Yes") else: print("No")
a = [list(map(int, input().split())) for _ in range(3)] n = int(input()) for _ in range(n): d = int(input()) for i in range(3): if d in a[i]: a[i][a[i].index(d)] = -1 for i in range(3): if sum(a[i])==-3: print('Yes') exit() s = 0 for j in range(3): s += a[j][i] if s==-3: print('Yes') exit() if a[0][0]+a[1][1]+a[2][2]==-3: print('Yes') exit() if a[0][2]+a[1][1]+a[2][0]==-3: print('Yes') exit() print('No')
0
null
102,832,991,249,180
279
207
a,b,c = [int(i) for i in input().split()] res = 0 for num in range(a,b+1): if c%num == 0: res += 1 print(res)
a, b, c = map(int, input().split()) l = [n for n in range (a,b+1) if c % n == 0] print(len(l))
1
567,852,747,880
null
44
44
while(True): a = input() if '?' in a: break print(int(eval(a)))
while True: a, b, c = input().split() a = int(a) c = int(c) if b == "?": break if b == "+": print(a + c) if b == "-": print(a - c) if b == "*": print(a * c) if b == "/": print(a // c)
1
675,503,111,272
null
47
47
s = list(str(input())) q = int(input()) from collections import deque s = deque(s) cnt = 0 for i in range(q): query = list(map(str, input().split())) if len(query) == 1: cnt += 1 else: t, f, c = query if f == '1': if cnt%2 == 0: s.appendleft(c) else: s.append(c) else: if cnt%2 == 0: s.append(c) else: s.appendleft(c) s = list(s) if cnt%2 == 1: s.reverse() print(''.join(s))
s = str(input()) Q = int(input()) forward = 1 front = "" back = "" for i in range(Q): q = list(input().split()) if q[0] == "1": forward *= -1 else: if q[1] == "1": if forward == 1: front = q[2] + front else: back = back + q[2] else: if forward == 1: back = back + q[2] else: front = q[2] + front s = front + s + back if forward == -1: s = s[::-1] print(s)
1
57,277,742,269,870
null
204
204
N = int(input()) music = [] time = [] for i in range(N): m,t = input().split() music.append(m) time.append(int(t)) S = input() ans = 0 ans += sum(time[music.index(S)+1:]) print(ans)
N = int(input()) A = list(map(int, input().split())) s = 0 height = 0 for a in A: height = max(height, a) s += height - a print(s)
0
null
51,012,362,370,500
243
88
def dist(x,y,p): d = 0 for i in range(len(x)): d += abs(x[i]-y[i])**p d = d**(1/p) return d n = int(input()) x = list(map(int,input().split())) y = list(map(int,input().split())) print('{0:.6f}'.format(dist(x,y,1))) print('{0:.6f}'.format(dist(x,y,2))) print('{0:.6f}'.format(dist(x,y,3))) print('{}'.format(max([abs(x[i]-y[i])for i in range(n)])))
import math n = int(input()) x = [int(i) for i in input().split()] y = [int(i) for i in input().split()] for p in range(1,4): s = [math.fabs(x[i]-y[i])**p for i in range(n)] z = math.pow(sum(s), 1/p) print("{:.6f}".format(z)) t = [math.fabs(x[i]-y[i]) for i in range(n)] print("{:.6f}".format(max(t)))
1
208,111,832,374
null
32
32
a,b,c,k=[int(x) for x in input().split()] ans=0 if a<=k: ans+=a k-=a elif k>0: ans+=k k=0 if b<=k: k-=b elif k>0: k=0 if k>0: ans-=k print(ans)
a, b, c, k = map(int, input().split()) ans = 0 if k < a: ans = 1 * k elif k <= a + b: ans = 1 * a elif k > a + b: ans = 1 * a - 1 * (k-a-b) print(ans)
1
21,672,842,973,340
null
148
148
#input() ans=1 for i in map(int,input().split()):ans*=i print(int(ans))
n = int(input()) lst = [int(i) for i in input().split()] min_n = min(lst) max_n = max(lst) min_count = 1000000000 for i in range(min_n, max_n + 1): count = 0 for j in range(n): count += (lst[j] - i) ** 2 if count < min_count: min_count = count print(min_count)
0
null
40,488,513,417,474
133
213
S, T = input().split() A, B = list(map(int, input().split())) U = input() if S == U: print("{} {}".format(A - 1, B)) else: print("{} {}".format(A, B - 1))
from collections import deque K = int(input()) q = deque(list(range(1, 10))) for _ in range(K - 1): u = q.popleft() n = u % 10 for x in range(max(0, n - 1), min(9, n + 1) + 1): q.append(u * 10 + x) print(q.popleft())
0
null
56,213,150,125,120
220
181
# collections.deque is implemented using doubly linked list at C level.. from collections import deque linkedlist = deque() for _ in range(int(input())): input_command = input() if input_command == 'deleteFirst': linkedlist.popleft() elif input_command == 'deleteLast': linkedlist.pop() else: com, num = input_command.split() if com == 'insert': linkedlist.appendleft(num) elif com == 'delete': try: linkedlist.remove(num) except: pass print(' '.join(linkedlist))
from collections import deque n = int(input()) linked_list = deque([]) for i in range(n): line = input().split() cmd = line[0] if len(line) == 2: value = line[1] if cmd == "insert": linked_list.appendleft(value) elif cmd == "delete": if value in linked_list: linked_list.remove(value) elif cmd == "deleteFirst": linked_list.popleft() elif cmd == "deleteLast": linked_list.pop() print(*linked_list)
1
51,670,817,348
null
20
20
import sys inint = lambda: int(sys.stdin.readline()) inintm = lambda: map(int, sys.stdin.readline().split()) inintl = lambda: list(inintm()) instrm = lambda: map(str, sys.stdin.readline().split()) instrl = lambda: list(instrm()) n = inint() A = inintl() cnt = 1 ans = 0 for a in A: if a != cnt: ans += 1 continue else: cnt += 1 if cnt == 1: if ans == 0: print(ans) else: print(-1) else: print(ans)
def solve(): N = int(input()) A = list(map(int, input().split())) ans = 0 p = 1 for a in A: if a==p: p += 1 else: ans += 1 if p==1: ans = -1 return ans print(solve())
1
114,722,235,849,100
null
257
257
r = input() print(r[0:3])
name = str(input()) print(name[0:3])
1
14,814,925,494,850
null
130
130
N, K = map(int, input().split()) ans = min(N % K, K - N % K) print(ans)
n,k = map(int,input().split()) if n < k: rival_n = k - n if n >= rival_n: print(rival_n) else: print(n) elif n == k: print(0) else: n = n % k rival_n = k - n if n >= rival_n: print(rival_n) else: print(n)
1
39,125,984,439,140
null
180
180
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from bisect import bisect_right, bisect_left import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor, gamma, log from operator import mul from functools import reduce from copy import deepcopy sys.setrecursionlimit(2147483647) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 n = I() def make_divisors(n): divisors = set() for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.add(i) divisors.add(n // i) return divisors # sortしたリストで欲しい時はsorted(divisors) ret = 0 a = make_divisors(n) for k in a: if k == 1: continue m = n while m % k == 0: m //= k if m % k == 1: ret += 1 s = make_divisors(n - 1) s.discard(1) print(ret + len(s))
from sys import stdin rs = stdin.readline ri = lambda : int(rs()) ril = lambda : list(map(int, rs().split())) def main(): N = ri() c = rs() x = 0 y = c.count('R') for e in c: if x == y: break elif e == 'W': x += 1 else: y -= 1 print(y) if __name__ == '__main__': main()
0
null
23,715,726,853,632
183
98
x = input() if '7' in x: print('Yes') else: print('No')
print("Yes" if "7" in input() else "No")
1
34,175,687,658,818
null
172
172
import sys from itertools import accumulate def solve(n,k,a): for _ in range(k): if a==[n]*n: return a t = [0]*(n+1) for i,x in enumerate(a): t[max(0,i-x)] += 1 t[min(n,i+x+1)] -=1 a = list(accumulate(t))[:-1] return a n,k = map(int,sys.stdin.readline().rstrip().split()) a = list(map(int,sys.stdin.readline().rstrip().split())) print(*solve(n,k,a))
N,K = map(int,input().split()) n = N - K * (N//K) n = min(n, abs(n-K)) print(n)
0
null
27,438,554,248,040
132
180
A, B, C, K = map(int, input().split()) a = min(A, K) K -= a b = min(B, K) K -= b c = min(C, K) print(a-c)
A, B, C, K = list(map(lambda x : int(x), input().split(" "))) if A >= K: print(K) elif A + B >= K: print(A) else: print(2 * A + B - K)
1
21,823,396,569,640
null
148
148
# 解説を参考に作成 def solve(): N, M = map(int, input().split()) m = 0 # 奇数の飛び oddN = M oddN += (oddN + 1) % 2 for i in range(oddN // 2): print(i + 1, oddN - i) m += 1 if m == M: return # 偶数の飛び for i in range(M): print(oddN + i + 1, M * 2 + 1 - i) m += 1 if m == M: return if __name__ == '__main__': solve()
n,k=map(int,input().split()) l=list(map(int,input().split())) l.sort(reverse=True) s=sum(l[k:]) print(s)
0
null
53,958,714,278,140
162
227
import sys input = sys.stdin.readline n = int(input()) num = list(map(int, input().split())) mod = 10**9+7 import fractions lc = num[0] for i in range(1, n): lc = lc * num[i] // fractions.gcd(lc, num[i]) lc %= mod def modinv(a, mod=10**9+7): return pow(a, mod-2, mod) ans =0 for i in range(n): ans += lc*modinv(num[i],mod) ans %= mod print(ans)
def gcd(m, n): r = m % n return gcd(n, r) if r else n def lcm(m, n): return m//gcd(m, n)*n MOD = 10**9+7 n = int(input()) a = list(map(int, input().split())) l = a[0] for x in a[1:]: l = lcm(x, l) l %= MOD ans = 0 for x in a: ans = (ans + l * pow(x, MOD-2, MOD)%MOD)%MOD print(ans)
1
87,809,763,181,660
null
235
235
N, K = [int(_) for _ in input().split()] MOD = 10 ** 9 + 7 ans = 0 class ModFactorial: """ 階乗, 組み合わせ, 順列の計算 """ def __init__(self, n, MOD=10 ** 9 + 7): """ :param n: 最大の要素数. :param MOD: """ kaijo = [0] * (n + 10) gyaku = [0] * (n + 10) kaijo[0] = 1 kaijo[1] = 1 for i in range(2, len(kaijo)): kaijo[i] = (i * kaijo[i - 1]) % MOD gyaku[0] = 1 gyaku[1] = 1 for i in range(2, len(gyaku)): gyaku[i] = pow(kaijo[i], MOD - 2, MOD) self.kaijo = kaijo self.gyaku = gyaku self.MOD = MOD def nCm(self, n, m): return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD def nPm(self, n, m): return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD def factorial(self, n): return self.kaijo[n] mf = ModFactorial(N, MOD) for i in range(1, N + 1): if N - i > K: continue p = N - i # print(i, p, mf.nCm(p + i - 1, i - 1)) ans += mf.nCm(p + i - 1, i - 1) * mf.nCm(N, i) ans %= MOD print(ans)
n, k = map(int, input().split()) MOD = 1000000007 def combinations(n, r, MOD): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * fact_inv[r] * fact_inv[n - r] % MOD fact = [1, 1] fact_inv = [1, 1] inv = [0, 1] for i in range(2, n + 1): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) fact_inv.append((fact_inv[-1] * inv[-1]) % MOD) s = 0 for num_zero in range(min(k + 1, n)): # nCz x = combinations(n, num_zero, MOD) # n-zCx y = combinations(n - 1, n - num_zero - 1, MOD) s += (x * y) % MOD print(s % MOD)
1
67,155,821,268,832
null
215
215
import bisect N = int(input()) L = list(map(int,input().split())) ans = 0 L = sorted(L) for i in range(N): for j in range(N): if i >= j: continue a = L[i] b = L[j] c = bisect.bisect_left(L,a+b) ans += c - j - 1 print(ans)
import sys from bisect import bisect_left,bisect_right sys.setrecursionlimit(10**7) input = sys.stdin.readline N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for b in range(N): for a in range(b): ab = L[a] + L[b] r = bisect_left(L, ab) l = b + 1 ans += max(0, r - l) print(ans)
1
171,976,962,826,688
null
294
294
def main(): X,Y = map(int,input().split()) for x in range(101): for y in range(101): if x+y==X and 2*x+4*y==Y: return True return False if __name__ == '__main__': print("Yes" if main() else "No")
def main(): N = int(input()) mod = 10 ** 9 + 7 mod_1 = 1 mod_2 = 1 mod_3 = 1 for _ in range(N): mod_1 = (mod_1 * 10) % mod mod_2 = (mod_2 * 9) % mod mod_3 = (mod_3 * 8) % mod v = (mod_1 - 2 * mod_2 + mod_3) % mod print(v) if __name__ == '__main__': main()
0
null
8,429,613,145,720
127
78
N=int(input()) ans=[0]*(N+1) for x in range(1,101): for y in range(1,101): for z in range(1,101): fn=x**2+y**2+z**2+x*y+y*z+z*x if fn>N: break else: ans[fn]=ans[fn]+1 for n in range(1,N+1): print(ans[n])
while True: s = raw_input() if(s == "-"): break m = input() for i in range(m): h = input() temp = "" for j in range(h, len(s)): temp += s[j] for j in range(h): temp += s[j] s = temp print(s)
0
null
4,913,602,462,660
106
66
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, m = map(int, readline().split()) if m % 2 == 0: rem = m for i in range(m // 2): print(i + 1, m + 1 - i) rem -= 1 if rem == 0: return for i in range(n): print(m + 2 + i, 2 * m + 1 - i) rem -= 1 if rem == 0: return else: rem = m for i in range((m - 1) // 2): print(i + 1, m - i) rem -= 1 if rem == 0: return for i in range(n): print(m + 1 + i, 2 * m + 1 - i) rem -= 1 if rem == 0: return if __name__ == '__main__': main()
N, M = map(int, input().split()) ans = [] n = M // 2 m = 2 * n + 1 l = 2 * M + 1 for i in range(n): ans.append([i + 1, m - i]) for i in range(M - n): ans.append([m + i + 1, l - i]) for v in ans: print(*v)
1
28,692,788,669,268
null
162
162
import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] tin=lambda : map(int, input().split()) lin=lambda : list(tin()) mod=1000000007 #+++++ def main(): k = int(input()) #b , c = tin() #s = input() l=['_']*50 l[0]=0 for _ in range(k): for i, v in enumerate(l): l[i]+=1 if l[i] == 10 and l[i+1]=='_': l[i+1]=1 l[:i+1]=[0]*(i+1) break elif l[i] == 10: l[i]=l[i+1] elif l[i+1]=='_': #l[:i]=[l[i]-1]*(i) for j in range(1,i+1): l[i-j]=max(0, l[i-j+1]-1) break elif l[i] <= l[i+1]+1: #l[:i]=[l[i]-1]*i for j in range(1,i+1): l[i-j]=max(0, l[i-j+1]-1) break #print(*l) print(''.join([str(c) for c in l[::-1] if c != '_'])) #+++++ isTest=False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform =='ios': if input_method==input_methods[0]: ic=input_clipboard() input = lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else: pass isTest=True else: pass #input = sys.stdin.readline ret = main() if ret is not None: print(ret)
import math while True: x = int(input()) # x = 5 if x==0: break data = list(map(float, input().split())) # data = list(map(float, '70 80 100 90 20'.split())) average = sum(data)/x temp = 0 for d in data: temp += math.pow(d - average, 2) # print(math.pow(d - average, 2)) stdev = math.sqrt(temp / x) print(stdev)
0
null
20,241,986,247,732
181
31
def main(): s = input() for _ in range(len(s)): print("x",end= "") print() if __name__ == "__main__": main()
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) n = INT() a = LIST() q = INT() count = [0]*(10**5+1) for x in a: count[x] += 1 ans = 0 for i in range(10**5+1): ans += i * count[i] for i in range(q): b, c = MAP() ans += (c - b) * count[b] count[c] += count[b] count[b] = 0 print(ans)
0
null
42,335,078,866,340
221
122
x = int(input()) cnt = x // 100 y = x % 100 print(1 if cnt * 5 >= y else 0)
def main(): a, b, k = map(int, input().split()) if k >= a and b >= k-a: print(0, b-(k-a)) elif k >= a and b < k-a: print(0, 0) else: print(a-k, b) if __name__ == '__main__': main()
0
null
116,281,933,429,218
266
249
n=int(input()) t = [[0 for _ in range(10)] for _ in range(10)] for i in range(1,n+1):t[int(str(i)[0])][int(str(i)[-1])]+=1 g=0 for i in range(1,10): for j in range(1,10): g+=t[i][j]*t[j][i] print(g)
def main(): n, k = map(int, input().split()) a_list = list(map(int, input().split())) visited_list = [-1] * n # 何ワープ目で訪れたか visited_list[0] = 0 city, loop, non_loop = 1, 0, 0 # 今いる街、何ワープでループするか、最初にループするまでのワープ数 for i in range(1, n + 1): city = a_list[city - 1] if visited_list[city - 1] != -1: loop = i - visited_list[city - 1] non_loop = visited_list[city - 1] - 1 break else: visited_list[city - 1] = i city = 1 if k <= non_loop: for _ in range(k): city = a_list[city - 1] else: for _ in range(non_loop + (k - non_loop) % loop + loop): city = a_list[city - 1] print(city) if __name__ == "__main__": main()
0
null
54,499,967,946,368
234
150
n, m, l = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] b = [list(map(int, input().split())) for _ in range(m)] for i in range(n): answer = [] for j in range(l): answer.append(sum([a[i][k]*b[k][j] for k in range(m)])) print(*answer)
n,m,l = (int(x) for x in input().split()) t1 = [[0 for i in range(m)] for j in range(n)] t2 = [[0 for i in range(l)] for j in range(m)] t3 = [[0 for i in range(l)] for j in range(n)] i = 0 while i < n: t1[i] = list(int(x) for x in input().split()) i += 1 i = 0 while i < m: t2[i] = list(int(x) for x in input().split()) i += 1 # cal t3 i = 0 while i < n: j = 0 while j < l: k,c = 0,0 while k < m: #print(str(i) + " " + str(k)) c += t1[i][k] * t2[k][j] k += 1 if j != 0: print(' ', end='') print(c, end='') j += 1 print ('') i += 1
1
1,429,565,134,930
null
60
60
for i in range(9): for j in range(9): print "%dx%d=%d" %(i+1,j+1, (i+1)*(j+1))
def run(): for i in range(1,10): for j in range(1,10): print('{0}x{1}={2}'.format(i,j,i*j)) if __name__ == '__main__': run()
1
1,139,522
null
1
1
import sys #import string #from collections import defaultdict, deque, Counter #import bisect #import heapq #import math #from itertools import accumulate #from itertools import permutations as perm #from itertools import combinations as comb #from itertools import combinations_with_replacement as combr #from fractions import gcd #import numpy as np stdin = sys.stdin sys.setrecursionlimit(10 ** 7) MIN = -10 ** 9 MOD = 10 ** 9 + 7 INF = float("inf") IINF = 10 ** 18 def solve(): #n = int(stdin.readline().rstrip()) s,t = map(str, stdin.readline().rstrip().split()) #l = list(map(int, stdin.readline().rstrip().split())) #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin] #word = [stdin.readline().rstrip() for _ in range(n)] #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)] #zeros = [[0] * w for i in range(h)] print(t+s) if __name__ == '__main__': solve()
inputted = input().split() S = inputted[0] T = inputted[1] answer = T + S print(answer)
1
102,862,275,493,754
null
248
248
while True: H, W = map(int, input().split()) if H == 0 and W == 0: break square = [['#'] * W] * H for row in square: print(''.join(row)) print()
import collections N = int(input()) A_list = list(map(int, input().split())) c = collections.Counter(A_list) c_value_list = list(c.values()) #print(c_value_list) ans = 0 for i in range(len(c_value_list)): ans += c_value_list[i]*(c_value_list[i] - 1) // 2 for k in range(N): ans_temp = ans - c[A_list[k]] + 1 print(ans_temp)
0
null
24,353,151,584,500
49
192
from sys import stdin N = int(stdin.readline().rstrip()) if N % 2 == 0: print(N//2-1) else: print(N//2)
N = int(input()) A = list(map(int,input().split())) chk = [] for i in range(N-1): if A[i+1] > A[i]: chk.append(1) else: chk.append(0) ans = 1000 for i in range(N-1): if chk[i] == 1: ans += (A[i+1] - A[i]) * (ans//A[i]) print(ans)
0
null
80,454,784,739,228
283
103
def solve(): N, K = map(int, input().split()) As = list(map(int, input().split())) Fs = list(map(int, input().split())) As.sort() Fs.sort(reverse=True) def isOK(score): d = 0 for A, F in zip(As, Fs): if A*F > score: d += -(-(A*F-score) // F) return d <= K ng, ok = -1, 10**12 while abs(ok-ng) > 1: mid = (ng+ok) // 2 if isOK(mid): ok = mid else: ng = mid print(ok) solve()
import sys if __name__ == '__main__': r = int(input()) print(r * r)
0
null
155,052,035,707,560
290
278
import math n,d=map(int,input().split()) c=0 for _ in range(n): x,y=map(int,input().split()) k=math.sqrt(x**2+y**2) if k<=d: c+=1 print(c)
n,d = map(int,input().split()) l=[] for _ in range(n): x,y=map(int,input().split()) l.append(((x**2)+(y**2))**(0.5)) l.sort() c=0 for i in l: if i>d: break else: c+=1 print(c)
1
5,910,134,977,600
null
96
96
x=int(input()) X=x k=1 while X%360!=0: k+=1 X+=x print(k)
x = int(input()) xSum = 0 cnt = 1 while True: xSum += x if xSum%360 == 0: break cnt += 1 print(cnt)
1
13,050,259,258,246
null
125
125
n = input() a, b = 0, 100 for i in n: j = int(i) a, b = min(a+j,b+j), min(a+11-j,b+9-j) if j == 0: b = a+100 print(min(a,b))
N=input() dp0=[0]*(len(N)+1) dp1=[0]*(len(N)+1) dp1[0]=1 for i in range(len(N)): n=int(N[i]) dp0[i+1]=min(dp0[i]+n, dp1[i]+(10-n)) n+=1 dp1[i+1]=min(dp0[i]+n, dp1[i]+(10-n)) #print(dp0) #print(dp1) print(dp0[-1])
1
71,154,499,215,842
null
219
219
def insertionSort(A, N): for i in range(N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v B = A.copy() for t in range(N): B[t] = str(B[t]) print(" ".join(B)) n = int(input()) a = list(map(int, input().split())) insertionSort(a, n)
# from math import factorial,sqrt,ceil,gcd # from itertools import permutations as permus # from collections import deque,Counter # import re # from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000) # from decimal import Decimal, getcontext # # getcontext().prec = 1000 # # eps = Decimal(10) ** (-100) import numpy as np # import networkx as nx # from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson # from scipy.sparse import csr_matrix # from scipy.special import comb # slist = "abcdefghijklmnopqrstuvwxyz" N = int(input()) # arrA = list(map(int,input().split())) arrA = np.array(input().split(),dtype=np.int64) arrA = arrA.cumsum() high = arrA[-1] ans = 2020202020*200000+2 for i in arrA[:-1]: num = abs(high - i*2) ans = min(ans,num) print(ans) # print(*ans) # unpackして出力。間にスペースが入る # for row in board: # print(*row,sep="") #unpackして間にスペース入れずに出力する # print("{:.10f}".format(ans)) # print("{:0=10d}".format(ans))
0
null
71,284,918,984,800
10
276
def factorial(n, mod): fac = [0] * (n + 1) inv = [0] * (n + 1) fac[0], inv[0] = 1, 1 for i in range(1, n + 1): fac[i] = fac[i-1] * i % mod inv[i] = inverse(fac[i], mod) return fac, inv def inverse(a, mod): a %= mod # 除数が正なら正になる p = mod x, y = 0, 1 while a > 0: n = p // a p, a = a, p % a, x, y = y, x - n * y return x % mod # 除数が正なら正になる mod = 10 ** 9 + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() fac, inv = factorial(n, mod) ans = 0 for i in range(0, n-k+1): m = n - i - 1 ans = (ans + (a[-i-1] - a[i]) % mod * fac[m] % mod * inv[m-k+1] % mod * inv[k-1]) % mod print(ans)
N,K=list(map(int,input().split())) A=sorted(list(map(int,input().split()))) mod=10**9+7 def modinv(x): return pow(x,mod-2,mod) comb=1 ans=0 for i in range(N-K+1): ans+=comb*A[K-1+i] ans-=comb*A[N-K-i] ans%=mod comb*=(K+i)*modinv(i+1) comb%=mod print(ans)
1
95,676,493,609,152
null
242
242