code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): r = int(input()) print(r**2) if __name__ == '__main__': main()
def main(): n, m = map(int, input().split()) if n%2: for i in range(m): print(i+1, n-i) else: for i in range(m): if n-2*i-1 > n//2: print(i+1, n-i) else: print(i+1, n-i-1) if __name__ == "__main__": main()
0
null
86,614,421,353,804
278
162
from bisect import bisect_right N, M = map(int, input().split()) S = [N - i for i, s in enumerate(input()) if s == '0'] S = S[::-1] ans = [] now = 0 while now < N: i = bisect_right(S, now + M) - 1 if S[i] == now: print('-1') exit() ans.append(S[i] - now) now = S[i] print(*ans[::-1])
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 10**9 for i in range(M): x, y, c = map(int, input().split()) if ans > a[x-1] + b[y-1] - c: ans = a[x-1] + b[y-1] - c if min(a) + min(b) < ans: ans = min(a) + min(b) print(ans)
0
null
96,306,167,569,942
274
200
a,b,c = map(int, raw_input().split()) lists = [a,b,c] new_lists = sorted(lists) print new_lists[0], new_lists[1], new_lists[2]
N = int(input()) slist = [] tlist = [] from itertools import accumulate for _ in range(N): s, t = input().split() slist.append(s) tlist.append(int(t)) cum = list(accumulate(tlist)) print(cum[-1]-cum[slist.index(input())])
0
null
48,516,127,269,050
40
243
import sys BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 P = str(input()).upper() line = [] while True: tmp_line = str(input()) if tmp_line == 'END_OF_TEXT': break line += tmp_line.upper().split() ans = 0 for tmp_word in line: if tmp_word == P: ans += 1 print("%d"%(ans))
W = input() count = 0 #T = input().lower() #print(T) #while T != 'END_OF_TEXT': while True: T = input() if T == 'END_OF_TEXT': break for i in T.lower().split(): if W == i: count += 1 #T = input().lower() #print(i) print(count)
1
1,857,158,111,160
null
65
65
from collections import deque infinity=10**6 import sys input = sys.stdin.readline N,u,v = map(int,input().split()) u -= 1 v -= 1 G=[[] for i in range(N)] for i in range(N-1): A,B = map(int,input().split()) A -= 1 B -= 1 G[A].append(B) G[B].append(A) ends = [] for i in range(N): if len(G[i]) == 1: ends.append(i) #幅優先探索 def BFS (s): queue = deque() d = [infinity]*N queue.append(s) d[s]= 0 while len(queue)!=0: u = queue.popleft() for v in G[u]: if d[v] == infinity: d[v] = d[u]+1 queue.append(v) return d d_nigeru = BFS(u) d_oni = BFS(v) ans=0 for u in ends: if d_nigeru[u] < d_oni[u]: ans = max(ans,d_oni[u]-1) print(ans)
K = int(input()) A, B = map(int, input().split()) cnt = 0 while 1: cnt+=K if A <= cnt <= B: print("OK") break if B < cnt: print("NG") break
0
null
71,697,956,059,840
259
158
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): S, T = input().split() A, B = map(int, input().split()) U = input() if S == U: A -= 1 if T == U: B -= 1 print(A, B) if __name__ == '__main__': solve()
n, p = map(int, input().split()) s = list(map(int, input())) ans = 0 if p == 2 or p == 5: for i, x in enumerate(s): if (p == 2 and not x % 2) or (p == 5 and (x == 0 or x == 5)): ans += i+1 print(ans) exit() s.reverse() cum = [0] * (n+1) for i in range(n): cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p t = [0] * p for x in cum: t[x] += 1 for x in t: ans += x * (x-1) // 2 print(ans)
0
null
64,819,039,864,098
220
205
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 idx = 1 def resolve(): def dfs(v): global idx begin[v] = idx idx += 1 for u in edge[v]: if begin[u] != 0: continue else: dfs(u) end[v] = idx idx += 1 n = int(input()) edge = [[] for _ in range(n)] for _ in range(n): u, k, *V = map(int, input().split()) for v in V: edge[u - 1].append(v - 1) begin = [0] * n end = [0] * n for i in range(n): if begin[i] == 0: dfs(i) for i in range(n): print(i + 1, begin[i], end[i]) if __name__ == '__main__': resolve()
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] t = [0] def DFS_visit(s): st[s] = 1 t[0] += 1 d[s] = t[0] for e in range(n): if M[s][e] == 1 and st[e] == 0: DFS_visit(e) st[s] == 2 t[0] += 1 f[s] = t[0] def DFS(): for s in range(n): if st[s] == 0: DFS_visit(s) for s in range(n): print'{0} {1} {2}'.format(s+1, d[s], f[s]) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): M[G[0]-1][G[2+j]-1] = 1 DFS()
1
3,262,874,692
null
8
8
a=int(input()) print(sum(divmod(a,2)))
s=input() l=len(s) list_s=list(s) ans="" if(s[l-1]!="s"): list_s.append("s") elif(s[l-1]=="s"): list_s.append("es") for i in range(0,len(list_s)): ans+=list_s[i] print(ans)
0
null
30,590,649,697,010
206
71
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)
import sys input = sys.stdin.readline rs = lambda: input().strip() ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) mod = 10**9 + 7 N, M = rl() if N == M: print('Yes') else: print('No')
0
null
98,160,906,418,960
256
231
import sys readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines read = sys.stdin.buffer.read sys.setrecursionlimit(10 ** 7) H, W = map(int, readline().split()) import math if H == 1 or W == 1: print(1) exit() total = H * W ans = (total + 2 - 1) // 2 print(ans)
h, w = map(int, input().split()) ans = (h * w + 1) // 2 if h == 1 or w ==1: print('1') else: print(ans)
1
50,801,243,838,672
null
196
196
# annealing is all you need # hyper parameter tune is all you need from time import time t0 = time() import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(read()) def ints(): return list(map(int, read().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right, insort_left from functools import reduce from random import randint, random from math import exp D = a_int() C = ints() S = read_tuple(D) def annealing(oldscore, newscore, T): '''p(newscore-oldscore,T)=min(1,exp((newscore-oldscore)/T)) の確率でnewscoreを採用する newが選ばれた時はTrueを返す''' if oldscore < newscore: return True else: p = exp((newscore - oldscore) / T) return random() < p def T_to_date_by_contest(T): '''Tを日付形式にしつつscoreも計算''' date_by_contest = [[-1] for _ in range(26)] for d, t in enumerate(T): date_by_contest[t].append(d) for i in range(26): date_by_contest[i].append(D) # 番兵 return date_by_contest def eval(D, C, S, date_by_contest): '''2~3*D回のループでスコアを計算する''' score = 0 for c, dates in enu(date_by_contest): for d in dates[1:-1]: score += S[d][c] for i in range(len(dates) - 1): dd = (dates[i + 1] - dates[i]) # for ddd in range(dd): # score -= C[c] * (ddd) score -= C[c] * (dd - 1) * dd // 2 return score def maximizer(newT, bestT, bestscore): '''具体的なTの最大化用''' tmpscore = eval(D, C, S, T_to_date_by_contest(newT)) if tmpscore > bestscore: return newT, tmpscore else: return bestT, bestscore def ret_init_T(): '''greedyで作ったTを初期値とする。 return ---------- T, score ... 初期のTとそのTで得られるscore ''' def _make_T(n_days): # editorialよりd日目の改善は、改善せずにd+n_days経過したときの関数にしたほうが # 最終的なスコアと相関があるんじゃない? T = [] last = [-1] * 26 for d in range(D): ma = -INF for i in range(26): tmp = S[d][i] dd = d - last[i] tmp += C[i] * (((dd + n_days + dd) * (n_days) // 2)) if tmp > ma: t = i ma = tmp last[t] = d # Tを選んだあとで決める T.append(t) return T T = _make_T(2) sco = eval(D, C, S, T_to_date_by_contest(T)) for i in range(3, 16): T, sco = maximizer(_make_T(i), T, sco) return T, sco class Schedule: def __init__(self, T: list, date_by_contest, score: int): self.T = T self.date_by_contest = date_by_contest self.score = score def try_change_contest(self, d, j): '''d日目をjに変更したときのscore''' score = self.score i = self.T[d] # コンテストi→jに変化する if i == j: return score # 変化しないので score += S[d][j] - S[d][i] # iの変化についてscoreを計算し直す # d_i_idx = bisect_left(self.date_by_contest[i], d) # iにおけるdのindex d_i_idx = self.date_by_contest[i].index(d) # iにおけるdのindex dd = self.date_by_contest[i][d_i_idx + 1] - \ self.date_by_contest[i][d_i_idx - 1] score -= C[i] * (dd - 1) * dd // 2 dd = self.date_by_contest[i][d_i_idx + 1] - d score += C[i] * (dd - 1) * dd // 2 dd = d - self.date_by_contest[i][d_i_idx - 1] score += C[i] * (dd - 1) * dd // 2 # jの変化についてscoreを計算し直す d_j_idx = bisect_left(self.date_by_contest[j], d) dd = self.date_by_contest[j][d_j_idx] - \ self.date_by_contest[j][d_j_idx - 1] score += C[j] * (dd - 1) * dd // 2 dd = self.date_by_contest[j][d_j_idx] - d score -= C[j] * (dd - 1) * dd // 2 dd = d - self.date_by_contest[j][d_j_idx - 1] score -= C[j] * (dd - 1) * dd // 2 return score def change_contest(self, d, j): '''d日目をjに変更する''' self.score = self.try_change_contest(d, j) i = self.T[d] self.T[d] = j self.date_by_contest[i].remove(d) insort_left(self.date_by_contest[j], d) def trial(sche, thre_p, days_near, Tt): '''確率的にどちらかの操作を行ってよかったらScheduleを更新する 1.日付dとコンテストqをランダムに選びd日目に開催するコンテストのタイプをqに変更する 2.10日以内の点でコンテストを入れ替える thre_pはどちらの行動を行うかを調節、days_nearは近さのパラメータ''' if random() < thre_p: # 一点更新 d = randint(0, D - 1) q = randint(0, 25) if annealing(sche.score, sche.try_change_contest(d, q), Tt): sche.change_contest(d, q) return sche # 参照渡しだから変わらんけどね else: T = sche.T.copy() i = randint(0, D - 2) j = randint(i - days_near, i + days_near) j = max(j, 0) j = min(j, D - 1) if i == j: j += 1 T[i], T[j] = T[j], T[i] new_score = eval(D, C, S, T_to_date_by_contest(T)) if annealing(sche.score, new_score, Tt): return Schedule(T, T_to_date_by_contest(T), new_score) else: return sche bestT, bestscore = ret_init_T() sche = Schedule(bestT, T_to_date_by_contest(bestT), bestscore) T0 = 200 T1 = 0.1 TL = 1.915 now = time() while now - t0 < TL: Tt = (T0**((now - t0) / TL)) * (T1**(1 - (now - t0) / TL)) for _ in range(2000): sche = trial(sche, 0.9, 20, Tt) now = time() # print(sche.score) # print(score(D, C, S, T)) print(*mina(*sche.T, sub=-1), sep='\n')
import sys import numpy as np from numba import njit @njit('(i8[:],)', cache=True) def solve(inp): def bitree_sum(bit, t, i): s = 0 while i > 0: s += bit[t, i] i ^= i & -i return s def bitree_add(bit, n, t, i, x): while i <= n: bit[t, i] += x i += i & -i def bitree_lower_bound(bit, n, d, t, x): sum_ = 0 pos = 0 for i in range(d, -1, -1): k = pos + (1 << i) if k <= n and sum_ + bit[t, k] < x: sum_ += bit[t, k] pos += 1 << i return pos + 1 def initial_score(d, ccc, sss): bit_n = d + 3 bit = np.zeros((26, bit_n), dtype=np.int64) INF = 10 ** 18 for t in range(26): bitree_add(bit, bit_n, t, bit_n - 1, INF) ttt = np.zeros(d, dtype=np.int64) last = np.full(26, -1, dtype=np.int64) score = 0 for i in range(d): best_t = 0 best_diff = -INF costs = ccc * (i - last) costs_sum = costs.sum() for t in range(26): tmp_diff = sss[i, t] - costs_sum + costs[t] if best_diff < tmp_diff: best_t = t best_diff = tmp_diff ttt[i] = best_t last[best_t] = i score += best_diff bitree_add(bit, bit_n, best_t, i + 2, 1) return bit, score, ttt def calculate_score(d, ccc, sss, ttt): last = np.full(26, -1, dtype=np.int64) score = 0 for i in range(d): t = ttt[i] last[t] = i score += sss[i, t] - (ccc * (i - last)).sum() return score def update_score(bit, bit_n, bit_d, ccc, sss, ttt, d, q): diff = 0 t = ttt[d] k = bitree_sum(bit, t, d + 2) c = bitree_lower_bound(bit, bit_n, bit_d, t, k - 1) - 2 e = bitree_lower_bound(bit, bit_n, bit_d, t, k + 1) - 2 b = ccc[t] diff -= b * (d - c) * (e - d) diff -= sss[d, t] k = bitree_sum(bit, q, d + 2) c = bitree_lower_bound(bit, bit_n, bit_d, q, k) - 2 e = bitree_lower_bound(bit, bit_n, bit_d, q, k + 1) - 2 b = ccc[q] diff += b * (d - c) * (e - d) diff += sss[d, q] return diff d = inp[0] ccc = inp[1:27] sss = np.zeros((d, 26), dtype=np.int64) for r in range(d): sss[r] = inp[27 + r * 26:27 + (r + 1) * 26] bit, score, ttt = initial_score(d, ccc, sss) bit_n = d + 3 bit_d = int(np.log2(bit_n)) loop = 6 * 10 ** 6 tolerant_min = -3000.0 best_score = score best_ttt = ttt.copy() for lp in range(loop): cd = np.random.randint(0, d) ct = np.random.randint(0, 26) while ttt[cd] == ct: ct = np.random.randint(0, 26) diff = update_score(bit, bit_n, bit_d, ccc, sss, ttt, cd, ct) progress = lp / loop if diff > (1 - progress) * tolerant_min: score += diff bitree_add(bit, bit_n, ttt[cd], cd + 2, -1) bitree_add(bit, bit_n, ct, cd + 2, 1) ttt[cd] = ct if score > best_score: best_score = score best_ttt = ttt.copy() return best_ttt + 1 inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ') ans = solve(inp) print('\n'.join(map(str, ans)))
1
9,705,187,815,940
null
113
113
r=int(input()) r0=1*1 s1=r*r s=s1/r0 print('%d'%s)
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)
0
null
134,270,656,926,672
278
263
import math A, B, C, D = map(int, input().split()) T_kougeki = C / B # 高橋くんが攻撃して、青木くんの体力が0になるまでの回数 A_kougeki = A / D # 青木くんが攻撃して、高橋くんの体力0になるまでの回数 if math.ceil(T_kougeki) <= math.ceil(A_kougeki): #切り上げた値で少ない方、同数なら先行の高橋くんの勝ち print('Yes') else: print('No')
x=input().split() a,b,c=int(x[0]),int(x[1]),int(x[2]) if a<b<c: print("Yes") else: print("No")
0
null
15,077,226,186,400
164
39
import math import time from collections import defaultdict, deque from sys import stdin, stdout from bisect import bisect_left, bisect_right s,w=map(int,stdin.readline().split()) if(w>=s): print("unsafe") else: print("safe")
#n, m, q = map(int, input().split()) #List = list(map(int, input().split())) s, w = map(int, input().split()) if s > w: print('safe') else : print("unsafe")
1
29,417,653,548,566
null
163
163
import math a, b = input().split(" ") a = int(a) b = int(b) print(int(a * b / math.gcd(a, b)))
# Python 3+ #------------------------------------------------------------------------------- import sys #ff = open("test.txt", "r") ff = sys.stdin cnt = 1 for line in ff : if int(line) == 0 : break print("Case {0}: {1}".format(cnt, line), end="") cnt += 1
0
null
56,672,466,117,188
256
42
import sys if __name__ == "__main__": n = int(sys.stdin.readline()) inp = sys.stdin.readlines() lis = set() for i in range(n): com = inp[i].split() if com[0] == "insert": lis.add(com[1]) elif com[1] in lis: print("yes") else: print("no")
class HashTable: def __init__(self, size = 1000003): self.size = size self.hash_table = [None] * size def _gen_key(self, val): raw_hash_val = hash(val) h1 = raw_hash_val % self.size h2 = 1 + (raw_hash_val % (self.size - 1)) for i in range(self.size): candidate_key = (h1 + i * h2) % self.size if not self.hash_table[candidate_key] or self.hash_table[candidate_key] == val: return candidate_key def insert(self, val): key = self._gen_key(val) self.hash_table[key] = val def search(self, val): key = self._gen_key(val) if self.hash_table[key]: print('yes') else: print('no') import sys n = int(sys.stdin.readline()) simple_dict = HashTable() ans = '' for i in range(n): operation = sys.stdin.readline() if operation[0] == 'i': simple_dict.insert(operation[7:]) else: simple_dict.search(operation[5:])
1
74,018,664,040
null
23
23
s = raw_input().rstrip().split(" ") a = int(s[0]) b = int(s[1]) c = int(s[2]) if a<b and b<c:print "Yes" else:print "No"
l = map(int,raw_input().split()) if l[0] < l[1] < l[2]: print 'Yes' else: print 'No'
1
393,279,545,020
null
39
39
string = input() height = 0 height_list = [[0, False]] for s in string: if s == '\\': height += -1 elif s == '/': height += 1 else: pass height_list.append([height, False]) highest = 0 for i in range(1, len(height_list)): if height_list[i-1][0] < height_list[i][0] <= highest: height_list[i][1] = True highest = max(highest, height_list[i][0]) puddles = [] area = 0 surface_level = None for i in range(len(height_list)-1, -1, -1): if surface_level != None: area += surface_level - height_list[i][0] if surface_level == height_list[i][0]: puddles += [area] surface_level = None area = 0 if surface_level == None and height_list[i][1]: surface_level = height_list[i][0] puddles = puddles[::-1] print(sum(puddles)) print(len(puddles), *puddles)
def main(): from sys import stdin input=stdin.readline import numpy as np import scipy.sparse.csgraph as sp n, m, l = map(int, input().split()) abc = [list(map(int, input().split())) for _ in [0]*m] q = int(input()) st = [list(map(int, input().split())) for _ in [0]*q] inf = 10**12 dist = np.full((n, n), inf, dtype=np.int64) for i in range(n): dist[i][i] = 0 for a, b, c in abc: dist[a-1][b-1] = c dist[b-1][a-1] = c dist = sp.shortest_path(dist) inf = 10**3 dist2 = np.full((n, n), inf, dtype=np.int16) for i in range(n): for j in range(n): if dist[i][j] <= l: dist2[i][j] = 1 dist2 = sp.shortest_path(dist2) for i in range(n): for j in range(n): if dist2[i][j] == inf: dist2[i][j] = -1 else: dist2[i][j] -= 1 for s, t in st: print(int(dist2[s-1][t-1])) main()
0
null
86,750,472,386,112
21
295
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf 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() ans = 0 for x in range(1, n+1): y = n // x ans += y * (y + 1) * x // 2 print(ans)
n = int(input()) A = list(map(int,input().split())) q = int(input()) M = list(map(int,input().split())) flag = [0]*(2000+1) for status in range(2**n): tmp = 0 for mask in range(n): if status&(1<<mask): tmp += A[mask] flag[tmp] = True for m in M: print('yes' if flag[m] else 'no')
0
null
5,556,590,441,732
118
25
n = int(input()); s = input().split() q = int(input()); t = input().split() cnt = 0 for i in t: if i in s: cnt += 1 print(cnt)
N=int(input()) def num_divisors_table(n): table=[0]*(n+1) for i in range(1,n+1): for j in range(i,n+1,i): table[j]+=1 return table l=num_divisors_table(N) ans=0 for i in range(1,N+1): ans+=i*l[i] print(ans)
0
null
5,588,204,554,030
22
118
# -*-coding:utf-8 import random class Dice: def __init__(self, diceList): self.d1, self.d2, self.d3, self.d4, self.d5, self.d6 = diceList def diceRoll(self, r): if(r == 'N'): self.d1, self.d2, self.d5, self.d6 = self.d2, self.d6, self.d1, self.d5 elif(r == 'E'): self.d1, self.d3, self.d4, self.d6 = self.d4, self.d1, self.d6, self.d3 elif(r == 'W'): self.d1, self.d3, self.d4, self.d6 = self.d3, self.d6, self.d1, self.d4 elif(r == 'S'): self.d1, self.d2, self.d5, self.d6 = self.d5, self.d1, self.d6, self.d2 def main(): orderList = ['N', 'E', 'W', 'S'] inputDiceList = list(map(int, input().split())) inputNum = int(input()) d = Dice(inputDiceList) for i in range(inputNum): x, y = map(int, input().split()) while True: if(d.d1 == x and d.d2 == y): print(d.d3) break else: r = random.randint(0, 3) d.diceRoll(orderList[r]) if __name__ == '__main__': main()
i = 1 while True: num = int(input()) if num == 0: break print('Case {}: {}'.format(i, num)) i+=1
0
null
372,959,783,900
34
42
n = input() if int(n[-1]) in [2,4,5,7,9]: ans = "hon" elif int(n[-1]) in [0,1,6,8]: ans = "pon" elif int(n[-1])==3: ans ="bon" print(ans)
n = input() hon = [2, 4, 5, 7, 9] pon = [0, 1, 6, 8] if int(n[-1]) in hon: print("hon") elif int(n[-1]) in pon: print("pon") else: print("bon")
1
19,130,568,753,520
null
142
142
# D - Triangles import bisect N=int(input()) Li=list(map(int,input().split())) Li.sort() ans=0 for i in range(N): for j in range (i+1,N): a=Li[i]+Li[j] t=bisect.bisect_left(Li,a) ans+=t-(j+1) print(ans)
import itertools n = int(input()) A = list(map(int,input().split())) A.sort() def binary_search(l,r,v): while r >= l: h = (l+r) // 2 if A[h] < v: l = h+1 else: r = h-1 return r ans = 0 for i in range(n-2): for j in range(i+1,n-1): a = binary_search(j,n-1,A[i]+A[j]) ans += a-j print(ans)
1
171,796,026,778,560
null
294
294
#!/usr/bin/python3 # -*- coding:utf-8 -*- from functools import reduce def main(): n = int(input()) la = list(map(int, input().strip().split())) x = reduce(lambda x, y: x ^ y, la) print(' '.join([str(x ^ a) for a in la])) if __name__=='__main__': main()
n = int(input()) a = list(map(int, input().split())) x = 0 for i in a: x ^= i for i in range(n): a[i] ^= x print(*a)
1
12,484,434,552,450
null
123
123
import math n = int(input()) while n: s = list(map(float, input().split())) m = sum(s) / n tmp = 0 for si in s: tmp += (si - m) ** 2 print(math.sqrt(tmp / n)) n = int(input())
import math while True: n = int(input()) if n == 0: break Student=list(map(float,input().split())) #print(n) #print(Student) #m=average average=sum(Student)/n #print(m) #a^2=dispersion s=0.0 for i in Student: s+=(i-average)**2 dispersion=s/n print("%.6f"%(math.sqrt(dispersion)))
1
187,299,947,810
null
31
31
X, Y = map(int, input().split()) MOD = 10 ** 9 + 7 def modpow(x, n): ret = 1 while n > 0: if n & 1: ret = ret * x % MOD x = x * x % MOD n >>= 1 return ret def modinv(x): return modpow(x, MOD - 2) def modf(x): ret = 1 for i in range(2, x + 1): ret *= i ret %= MOD return ret ans = 0 if (X + Y) % 3 == 0: m = (2 * X - Y) // 3 n = (2 * Y - X) // 3 if m >= 0 and n >= 0: ans = modf(m + n) * modinv(modf(n) * modf(m)) ans %= MOD print(ans)
# -*- coding:utf-8 def main(): N = int(input()) A = list(map(int, input().split())) insertionSort(A, N) print(' '.join(map(str, A))) def insertionSort(A, N): for i in range(1, N): print(' '.join(map(str, A))) v = A[i] j = i-1 while(j>=0 and A[j]>v): A[j+1] = A[j] j -= 1 A[j+1] = v if __name__ == '__main__': main()
0
null
74,748,707,434,148
281
10
import sys import decimal # 10進法に変換,正確な計算 def input(): return sys.stdin.readline().strip() def main(): n = int(input()) n = decimal.Decimal(n) if n % 2 == 0: print(1/decimal.Decimal(2)) return print(((n-1)/2+1)/n) main()
def resolve(): N = int(input()) print((N//2+1)/N if N%2==1 else 0.5) if '__main__' == __name__: resolve()
1
177,153,485,469,166
null
297
297
l,r,d= map(int,input().split()) print(sum([1 if t%d==0 else 0 for t in range(l,r+1)]))
print(input().replace(*'?D'))
0
null
13,023,410,492,792
104
140
#coding:utf-8 import math N,K = map(int,input().split()) A = [int(y) for y in input().split()] Ma = max(A) mi = 1 ans = Ma def execute(f): count = 0 for i in A: count += math.ceil(i / f) - 1 if count <= K: return True else: return False while True: median = (Ma + mi) // 2 bobo = execute(median) if bobo: ans = min(ans,median) Ma = median else: mi = median + 1 if Ma == mi: break print("{}".format(ans))
# M-SOLUTIONS プロコンオープン 2020: B – Magic 2 A, B, C = [int(i) for i in input().split()] K = int(input()) is_success = 'No' for i in range(K + 1): for j in range(K + 1): for k in range(K + 1): if i + j + k <= K and A * 2 ** i < B * 2 ** j < C * 2 ** k: is_success = 'Yes' print(is_success)
0
null
6,670,365,951,662
99
101
N=int(input()) A=[int(i) for i in input().split()] S=set(A) ans=1 for i in A: ans*=i if ans>10**18: ans=-1 break if 0 in S: ans=0 print(ans)
import numpy as np N = int(input()) x = [] y = [] xy1 = [] xy2 = [] for i in range(N): a, b = (int(t) for t in input().split()) x.append(a) y.append(b) xy1.append(a + b) xy2.append(a - b) max1 = max(xy1) - min(xy1) max2 = max(xy2) - min(xy2) print(max((max1, max2)))
0
null
9,778,148,271,642
134
80
# -*- coding: utf-8 -*- from collections import deque N = int(input()) q = deque() for i in range(N): lst = input().split() command = lst[0] if command == 'insert': q.appendleft(lst[1]) elif command == 'delete': try: q.remove(lst[1]) except Exception: pass elif command == 'deleteFirst': q.popleft() elif command == 'deleteLast': q.pop() print(*q)
N = int(input()) set_list = [input().split() for _ in range(N)] X = input() ans = 0 flg = False for i in range(N): if flg == True: ans += int(set_list[i][1]) if set_list[i][0] == X: flg = True print(ans)
0
null
48,486,481,632,372
20
243
W, H, x, y, r = map(int, input().split()) print( 'Yes' if r <= x <= W - r and r <= y <= H - r else 'No')
# 2019-11-19 10:28:31(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # import re # import heapq # import array # from scipy.misc import comb # (default: exact=False) from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall import numpy as np def main(): n, m, l = map(int, sys.stdin.readline().split()) ABCQST = np.array(sys.stdin.read().split(), np.int64) ABC = ABCQST[:m * 3] A, B, C = ABC[::3], ABC[1::3], ABC[2::3] ST = ABCQST[m * 3 + 1:] S, T = ST[::2], ST[1::2] dist = csr_matrix((C, (A, B)), (n+1, n+1)) min_dist = floyd_warshall(dist, directed=False) filling_times = np.full((n+1, n+1), np.inf) np.diagonal(filling_times, 0) filling_times[min_dist <= l] = 1 min_filling_times = floyd_warshall(filling_times, directed=False) min_filling_times[min_filling_times == np.inf] = 0 # 最後に-1する min_filling_times = min_filling_times.astype(int) res = min_filling_times[S, T] - 1 print('\n'.join(res.astype(str))) if __name__ == "__main__": main()
0
null
87,270,247,459,680
41
295
n = int(input()) x = input() def popcount(ni): n_b = str(bin(ni)) return n_b.count("1") def ans(n,x): x_i = int(x, 2) x_orig = popcount(x_i) x_i_t = x_i % (x_orig+1) if x_orig != 1: x_i_b = x_i % (x_orig-1) else: x_i_b = x_i solve = 0 for i in range(n): x_count = x_orig if x[i] == "0": x_count += 1 solve = x_i_t + pow(2,n-1-i,x_count) else: x_count -= 1 if x_count != 0: solve = x_i_b - pow(2,n-1-i,x_count) else: print(0) continue count = 0 if x_count != 0 : solve = solve % x_count count+=1 while solve > 0: solve = solve % popcount(solve) count+=1 print(count) ans(n,x)
N=int(input()) x=input() def popcount(X,ones,count): #print(count,bin(X),X,ones) if ones==0: return count else: X=X%ones count+=1 ones=str(bin(X)).count("1") return popcount(X,ones,count) GroundOnes=x.count("1") GroundX=int(x,2) if GroundOnes>1: CaseOne= GroundX%(GroundOnes-1) else: CaseOne=2 CaseZero= GroundX%(GroundOnes+1) TwoPowerCaseOne=[] TwoPowerCaseZero=[] # if GroundOnes>1: # for j in range(N): # TwoPowerCaseOne.append(pow(2,(N-j-1) , (GroundOnes-1))) # TwoPowerCaseZero.append(pow(2**(N-j-1), (GroundOnes+1))) # else: # for j in range(N): # TwoPowerCaseZero.append(pow(2**(N-j-1), (GroundOnes+1))) for i in range(N): #CaseOne if x[i]=="1": ones=GroundOnes-1 if ones>0: X=CaseOne-pow(2,N-i-1,ones) else: X=0 #CaseZero else: ones=GroundOnes+1 X=CaseZero+pow(2,N-i-1,ones) # print("for loop",i) # print("ones",ones) # print("new2bit",new2bit) #print(" ------ return --- ",popcount(X,ones,0)) print(popcount(X,ones,0))
1
8,322,481,622,208
null
107
107
def main(): sectionalview = input() stack = [] a_surface = 0 surfaces = [] for cindex in range(len(sectionalview)): if sectionalview[cindex] == "\\": stack.append(cindex) elif sectionalview[cindex] == "/" and 0 < len(stack): if 0 < len(stack): left_index = stack.pop() a = cindex - left_index a_surface += a while 0 < len(surfaces): if left_index < surfaces[-1][0]: a += surfaces.pop()[1] else: break surfaces.append((cindex, a)) t = [i[1] for i in surfaces] print(sum(t)) print(" ".join(map(str, [len(t)] + t))) if __name__ == "__main__": import os import sys if len(sys.argv) > 1: if sys.argv[1] == "-d": fd = os.open("input.txt", os.O_RDONLY) os.dup2(fd, sys.stdin.fileno()) main() else: main()
x = int(input()) ans = x*x*x print(ans)
0
null
165,195,897,980
21
35
#!python3.8 # -*- coding: utf-8 -*- # abc179/abc179_a import sys s2nn = lambda s: [int(c) for c in s.split(' ')] ss2nn = lambda ss: [int(s) for s in list(ss)] ss2nnn = lambda ss: [s2nn(s) for s in list(ss)] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [i2s() for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) def main(): S = i2s() if S[-1] != 's': print(S + 's') else: print(S + 'es') return main()
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) mod = 10**9+7 # mod = 998244353 dir = [(-1,0),(0,-1),(1,0),(0,1)] alp = "abcdefghijklmnopqrstuvwxyz" INF = 1<<32-1 # INF = 10**18 def main(): s = input() if s[-1] == "s": print(s+"es") else: print(s+"s") return None if __name__ == '__main__': main()
1
2,380,056,464,818
null
71
71
a,b = map(int,input().split()) x = int(a // b) y = int(a - b*x) z = a / b print(x,y,f"{z:.5f}")
from collections import deque l=deque() for _ in range(input()): a=raw_input().split() c=a[0][-4] if c=="i": l.popleft() elif c=="L": l.pop() elif c=="s": l.appendleft(a[1]) else: try: l.remove(a[1]) except: pass print " ".join(l)
0
null
335,203,322,800
45
20
N=input() A=input() Alist=A.split() counts=0 for i in Alist: if int(i)%2==1: counts=counts elif int(i)%3==0: counts=counts elif int(i)%5==0: counts=counts else: counts=counts+1 if counts>=1: print("DENIED") else: print("APPROVED")
while True: n = int(input()) if n == 0: break s = list(map(float, input().split())) m = sum(s) / n a = (sum((s[i] - m) ** 2 for i in range(n)) / n) ** 0.5 print(a)
0
null
34,764,941,585,730
217
31
N = int(input()) A = [int(i) for i in input().split()] A = sorted(A, reverse=True) A += A[1:] A = sorted(A, reverse=True) print(sum(A[:N-1]))
n = int(input()) a = list(map(int, input().split())) a.sort() if n % 2 == 0: suma = 2*sum(a[-int((n/2)):])-a[-1] else: suma = 2*sum(a[-int(((n+1)/2)):])-a[-1]-a[-int(((n+1)/2))] print(suma)
1
9,123,022,930,892
null
111
111
h, n = [int(i) for i in input().split()] a = [int(i) for i in input().split()] print('Yes' if sum(a) >= h else 'No')
h,n=map(int,input().split()) a=list(map(int,input().split())) ans=0 if sum(a)>=h: print('Yes') else: print('No')
1
77,775,313,450,652
null
226
226
S=input() ans=0 if 'R' in S: ans+=1 if S[0]=='R' and S[1]=='R': ans+=1 if S[1]=='R' and S[2]=='R': ans+=1 print(ans)
s=input().split('S') print(len(max(s)))
1
4,903,368,279,800
null
90
90
n,*a=map(int,open(0).read().split()) b=[0]*n for i in range(n): b[a[i]-1]=str(i+1) print(' '.join(b))
h = int(input()) w = int(input()) n = int(input()) if h >= w: print(-(-n//h)) elif w > h: print(-(-n//w))
0
null
134,915,840,814,090
299
236
import heapq n,k = map(int,input().split()) a = [int(i) for i in input().split()] low = 0 high = 10**9 if k == 0: print(max(a)) exit() while low+1 < high: tmp = 0 mid = (low + high) //2 for i in range(n): tmp += ((a[i]+mid-1) // mid)-1 if tmp <= k: high = mid else: low = mid print(high)
s = str(input()) if s == 'SUN': print(7) elif s == 'MON': print(6) elif s == 'TUE': print(5) elif s == 'WED': print(4) elif s == 'THU': print(3) elif s == 'FRI': print(2) else: print(1)
0
null
69,405,867,213,678
99
270
class process: def __init__(self, name, time): self.name = name self.time = time def queue(q, ps): time = 0 while len(ps) != 0: p = ps.pop(0) if p.time > q: p.time -= q time += q ps.append(p) else: time += p.time print p.name + " " + str(time) if __name__ == "__main__": L = map(int, raw_input().split()) N = L[0] q = L[1] processes = [] for i in range(N): L = raw_input().split() processes.append(process(L[0], int(L[1]))) queue(q, processes)
n,q = map(int,input().split()) name = [] time = [] for i in range(n): tmp = input().split() name.append(str(tmp[0])) time.append(int(tmp[1])) total = 0 result = [] while True: try: if time[0] > q: total += q time[0] = time[0] - q tmp = time.pop(0) time.append(tmp) tmp = name.pop(0) name.append(tmp) elif q >= time[0] and time[0] > 0: total += time[0] time.pop(0) a = name.pop(0) print(a,total) else: break except: break
1
43,404,186,208
null
19
19
def main(): N = int(input()) A = [int(a) for a in input().split()] xor_all = A[0] for i in range(1, N): xor_all ^= A[i] for i in range(N): if i != N - 1: print(A[i]^xor_all, end=" ") else: print(A[i]^xor_all) if __name__ == "__main__": main()
n = int(input()) a = list(map(int, input().split())) m = max(a) ans = [0] * n z = 1 while True: b = False for i in range(n): if a[i] & z: b = not b for i in range(n): if not b: if a[i] & z: ans[i] |= z else: if not (a[i] & z): ans[i] |= z z <<= 1 if z > m: break print(' '.join([str(x) for x in ans]))
1
12,366,811,753,988
null
123
123
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入 import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(input()) n = I() A = readInts() dic = defaultdict(int) for i in range(n): dic[i+1] = 0 for a in A: dic[a] += 1 for i in range(n): print(dic[i+1])
import sys read = sys.stdin.read readlines = sys.stdin.readlines from math import pi def main(): n, *a = map(int, read().split()) cnt = [0] * n for ae in a: cnt[ae-1] += 1 print(*cnt, sep='\n') if __name__ == '__main__': main()
1
32,338,682,417,892
null
169
169
import sys n = int(input()) ans = float("inf") flag = 0 for i in range(2,int(n**(1/2))+1): if n%i == 0: ans = min(ans, i+(n//i)-2) flag = 1 if flag: print(ans) else: print(n-1)
x = int(input()) print((1999-x)//200+1)
0
null
83,757,296,359,270
288
100
r, c = map(int, input().split(' ')) matrix = [] total_cols = [0 for i in range(c+1)] for i in range(r): rows = list(map(int, input().split(' '))); total = sum(rows) rows.append(total) total_cols = [ total_cols[i] + x for i, x in enumerate(rows) ] matrix.append(rows) matrix.append(total_cols) for row in matrix: print(' '.join([str(i) for i in row]))
# coding: utf-8 row, col = map(int, input().split()) spreadsheet = [] for i in range(row): val = list(map(int, input().split())) val.append(sum(val)) spreadsheet.append(val) for r in spreadsheet: print(' '.join(map(str, r))) last_row = [] for j in range(len(spreadsheet[0])): col_sum = 0 for i in range(len(spreadsheet)): col_sum += spreadsheet[i][j] last_row.append(col_sum) print(' '.join(map(str, last_row)))
1
1,368,769,908,000
null
59
59
N,K = map(int ,input().split()) D = [] A = [] for _ in range(K): D.append(int(input())) A.append(list(map(int, input().split()))) # お菓子を持っている人を数える。すると持っていない人間は、Nから持っている人の数を引いたもの l = [0]*N for i in range(K): for j in range(D[i]): l[A[i][j]-1] = 1 print(N - sum(l))
n,k = map(int, input().split()) sunuke = [] for i in range(n): sunuke.append(1) for i in range(k): d = int(input()) a = list(map(int, input().split())) for j in range(d): sunuke[a[j]-1] = 0 print(sum(sunuke))
1
24,483,538,408,540
null
154
154
def main(): A, B, K = map(int, input().split()) r = max(0, A + B - K) a = min(r, B) t = r - a print(t, a) if __name__ == '__main__': main()
A, B, K = [int(x) for x in input().split()] if K <= A: print(A - K, B) else: print(0, max(0, A + B - K))
1
103,911,358,347,020
null
249
249
A, B, C, D = map(int, input().split()) while A > 0 and C > 0: A -= D C -= B if C <= 0: print('Yes') else: print('No')
import math A, B, C, D = map(int, input().split()) if math.ceil(C/B) <= math.ceil(A/D): print('Yes') else: print('No')
1
29,822,952,394,608
null
164
164
a, b = map(int,input().split()) print(a*b if a < 10 and b < 10 and a > 0 and b > 0 else -1)
f=input n,s,q=int(f()),list(f()),int(f()) d={chr(97+i):[] for i in range(26)} for i in range(n): d[s[i]]+=[i] from bisect import * for i in range(q): a,b,c=f().split() b=int(b)-1 if a=='1': if s[b]==c: continue d[s[b]].pop(bisect(d[s[b]],b)-1) s[b]=c insort(d[c],b) else: t=0 for l in d.values(): m=bisect(l,b-1) if m<len(l) and l[m]<int(c): t+=1 print(t)
0
null
110,683,499,463,200
286
210
s = input() a = "x"*len(s) print(a)
s = input() h = s/3600 m = s%3600/60 s = s%3600%60 print '{0}:{1}:{2}'.format(h, m, s)
0
null
36,574,770,931,698
221
37
import bisect import copy def check(a, b, bar): sm = 0 cnt = 0 n = len(a) for x in a: i = bisect.bisect_left(a, bar - x) if i == n: continue cnt += n - i sm += b[i] + x * (n-i) return cnt, sm n,m = map(int, input().split()) a = list(map(int, input().split())) a.sort() b = copy.deepcopy(a) for i,_ in enumerate(b[:-1]): b[n-i-2] += b[n-i-1] left = 0 right = b[0] * 2 while right - left > 1: middle = ( right + left ) // 2 if check(a, b, middle)[0] < m: right = middle else: left = middle print(check(a, b, left)[1] - left * (check(a, b, left)[0]-m) )
N, M = map(int, input().split()) A = list(map(int, input().split())) cnt = 0 total = sum(A) for a in A: if a >= total / (4*M): cnt += 1 ans = 'Yes' if cnt >= M else 'No' print(ans)
0
null
73,380,722,761,360
252
179
n, m = map(int, input().split()) c = [int(i) for i in input().split()] dp = [[-1 for _ in range(m + 1)] for _ in range(n + 1)] for i in range(1, n + 1): dp[i][1] = i for j in range(1, m + 1): dp[0][j] = 0 # dp[1][j] = 1 for i in range(n + 1): for j in range(1, m): if c[j] > i: dp[i][j + 1] = dp[i][j] else: dp[i][j + 1] = min(dp[i][j], dp[i - c[j]][j + 1] + 1) print(dp[n][m])
import sys def main(): input = sys.stdin.buffer.readline n, m = map(int, input().split()) c = [0] + list(map(int, input().split())) dp = [list(range(n + 1)) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(n + 1): if j - c[i] >= 0: dp[i][j] = min(dp[i - 1][j], dp[i][j - c[i]] + 1) else: dp[i][j] = dp[i - 1][j] print(dp[m][n]) if __name__ == "__main__": main()
1
141,672,725,830
null
28
28
# -*- coding: utf-8 -*- """ Created on Tue Sep 8 20:45:37 2020 @author: liang """ def gcc(a,b): if b == 0: return a return gcc(b, a%b) A, B = map(int, input().split()) if A < B: A ,B = B, A print(A*B//gcc(A,B))
N, M = map(int, input().split()) A = map(int, input().split()) A_sum = sum(A) if (N - A_sum) >= 0: print(N - A_sum) else: print(-1)
0
null
72,699,936,488,322
256
168
N = int(input()) evidences = [[] for _ in range(N)] for i in range(N): A = int(input()) for _ in range(A): x, y = map(int, input().split()) evidences[i].append((x - 1, y)) ans = 0 for i in range(1, 2 ** N): consistent = True for j in range(N): if (i >> j) & 1 == 0: continue for x, y in evidences[j]: if (i >> x) & 1 != y: consistent = False break #if not consistent: #break if consistent: ans = max(ans, bin(i)[2:].count('1')) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) # あるbit列に対するコストの計算 def count(zerone): one = 0 cnt = 0 for i in range(N): flag = True if zerone[i] == 1: one += 1 for j in range(len(A[i])): if A[i][j][1] != zerone[A[i][j][0]-1]: flag = False break if flag: cnt += 1 if cnt == N: return one else: return 0 # bit列の列挙 def dfs(bits): if len(bits) == N: return count(bits) res = 0 for i in range(2): bits.append(i) res = max(res, dfs(bits)) bits.pop() return res # main N = int(input()) A = [[] for _ in range(N)] for i in range(N): a = int(input()) for _ in range(a): A[i].append([int(x) for x in input().split()]) ans = dfs([]) print(ans)
1
122,125,839,965,360
null
262
262
import math N = int(input()) flag = True for i in range(N+1): if math.floor(i * 1.08) == N: print(i) flag = False break if flag: print(':(')
N = int(input()) x = (N+1) * 100 // 108 if x * 108 // 100 == N: print(x) else: print(":(")
1
125,785,907,612,400
null
265
265
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) X = input() cnt_init = X.count("1") x_init = int(X, 2) a = x_init % (cnt_init + 1) if cnt_init - 1 != 0: b = x_init % (cnt_init - 1) for i in range(n): if X[i] == "0": cnt = cnt_init + 1 x = (a + pow(2, (n - i - 1), cnt)) % cnt res = 1 else: cnt = cnt_init - 1 if cnt != 0: x = (b - pow(2, (n - i - 1), cnt)) % cnt res = 1 else: x = 0 res = 0 while x: cnt = bin(x).count("1") x %= cnt res += 1 print(res) if __name__ == '__main__': resolve()
#template def inputlist(): return [int(j) for j in input().split()] #template """ H,W = inputlist() st = inputlist() gl = inputlist() maze = ['0']*H for i in range(H): maze[i] = list(input()) table = [[10**9+7]*W for _ in range(H)] """ D,T,S = inputlist() time = D//S + int(D%S != 0) if time <= T: print("Yes") else: print("No")
0
null
5,894,067,653,628
107
81
def main(): n = int(input()) l_0 = [] r_0 = [] ls_plus = [] ls_minus = [] sum_l = 0 sum_r = 0 for i in range(n): s = input() left, right = 0, 0 for j in range(len(s)): if s[j] == '(': right += 1 else: if right > 0: right -= 1 else: left += 1 if left == right == 0: continue if left == 0: l_0.append((left, right)) elif right == 0: r_0.append((left, right)) elif left < right: ls_plus.append((left, right)) else: ls_minus.append((left, right)) sum_l += left sum_r += right if len(ls_plus) == len(ls_minus) == len(l_0) == len(r_0) == 0: print("Yes") return if len(l_0) == 0 or len(r_0) == 0: print("No") return if sum_l != sum_r: print("No") return # r-lの大きい順 ls_plus.sort(key=lambda x: x[1] - x[0], reverse=True) # lの小さい順 ls_plus.sort(key=lambda x: x[0]) # l-rの小さい順 ls_minus.sort(key=lambda x: x[0] - x[1]) # lの大さい順 ls_minus.sort(key=lambda x: x[0], reverse=True) now_r = 0 for ll in l_0: now_r += ll[1] for _ in ls_plus: r = _[1] x = now_r - _[0] if x >= 0: now_r = x + r else: print("No") return for _ in ls_minus: r = _[1] x = now_r - _[0] if x >= 0: now_r = x + r else: print("No") return print("Yes") main()
N = int(input()) Up = [] Down = [] for _ in range(N): S = input() L = [0] mi = 0 now = 0 for __ in range(len(S)): if S[__] == '(': now += 1 else: now -= 1 mi = min(mi, now) if now > 0: Up.append((mi, now)) else: Down.append((mi - now, mi, now)) Up.sort(reverse=True) Down.sort() now = 0 for i, j in Up: if now + i < 0: print('No') exit() else: now += j for _, i, j in Down: if now + i < 0: print('No') exit() else: now += j if now == 0: print('Yes') else: print('No')
1
23,613,187,931,540
null
152
152
def answer(x: int) -> int: dict = {500: 1000, 5: 5} happiness = 0 for coin in sorted(dict, reverse=True): q, x = divmod(x, coin) happiness += dict[coin] * q return happiness def main(): x = int(input()) print(answer(x)) if __name__ == '__main__': main()
import math N = int(input()) M = int(math.sqrt(N)) ans = 0 check = [True for _ in range(M + 1)] e = [0 for _ in range(M + 1)] for p in range(2, M + 1): if check[p] == True: for j in range(2, M // p + 1): check[p * j] = False while N % p == 0: N = N // p e[p] += 1 ans += int((math.sqrt(1 + 8 * e[p]) - 1)/2) if N > 1: ans += 1 print(ans)
0
null
29,732,655,658,680
185
136
import bisect, collections, copy, heapq, itertools, math, string from functools import reduce import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) N = I() S = S() R_num = [n for n, v in enumerate(S) if v == 'R'] G_num = [n for n, v in enumerate(S) if v == 'G'] B_num = [n for n, v in enumerate(S) if v == 'B'] cnt = 0 for r in R_num: for g in G_num: x = r + g if x % 2 == 0: if x // 2 in B_num: cnt += 1 for g in G_num: for b in B_num: x = g + b if x % 2 == 0: if x // 2 in R_num: cnt += 1 for r in R_num: for b in B_num: x = r + b if x % 2 == 0: if x // 2 in G_num: cnt += 1 ans = len(R_num) * len(G_num) * len(B_num) - cnt print(ans)
n=int(input()) s,t = map(str, input().split()) print(''.join([s[i] + t[i] for i in range(0,n)]))
0
null
73,676,797,760,992
175
255
N,K = map(int,input().split()) A = [int(a) for a in input().split()] n = 0 for i in range(K,N): if A[i] > A[n] : print("Yes") else: print("No") n+=1
r, c, k = map(int, input().split()) dp = [[[0,0,0,0] for _j in range(c+1)] for _i in range(2)] bord = [[0]*(c+1) for _i in range(r)] for _i in range(k): _r, _c, _v = map(int, input().split()) bord[_r-1][_c-1] = _v for i in range(r): for j in range(c): dp[1][j][0] = max(dp[0][j]) dp[1][j][1] = dp[1][j][0] + bord[i][j] for x in range(1, 4): dp[1][j][x] = max( dp[1][j][x], dp[1][j-1][x], dp[1][j-1][x-1]+bord[i][j], ) dp[0] = dp[1][::] print(max(dp[1][c-1]))
0
null
6,383,047,443,540
102
94
INF = 10 ** 10 def merge(A, left, mid, right): c = 0 n1 = mid - left n2 = right - mid Left = [A[left+i] for i in range(n1)] Right = [A[mid+i] for i in range(n2)] Left.append(INF) Right.append(INF) i=0 j=0 for k in range(left, right): c += 1 if Left[i] <= Right[j]: A[k] = Left[i] i += 1 else: A[k] = Right[j] j += 1 return c def mergeSort(hoge, left, right): c = 0 if left+1 < right: mid = (left + right) // 2 c += mergeSort(hoge, left, mid) c += mergeSort(hoge, mid, right) c += merge(hoge, left, mid, right) return c if __name__ == '__main__': _ = input() hoge = [int(x) for x in input().split()] c = mergeSort(hoge, 0, len(hoge)) print (' '.join([str(x) for x in hoge])) print (c)
a,b=open(0);c=1; for i in sorted(b.split()): c*=int(i) if c>10**18:print(-1);exit() print(c)
0
null
8,095,955,225,120
26
134
H,N = (int(x) for x in input().split()) A = [int(x) for x in input().split()] if sum(A)>=H: print('Yes') else: print('No')
H,N=map(int,input().split()) lst=list(map(int,input().split())) s=sum(lst) if s>=H: print("Yes") else: print("No")
1
78,285,979,355,374
null
226
226
i = raw_input().strip().split() l = [int(i[0]),int(i[1]),int(i[2])] tmp = 0 for j in range(3): for k in range(3): if l[k] > l[j]: tmp = l[j] l[j] = l[k] l[k] = tmp print str(l[0])+" "+str(l[1])+" "+str(l[2])
n = map(int,raw_input().split()) for i in range(0,3): for k in range(i,3): if n[i]>n[k]: temp = n[i] n[i] = n[k] n[k]= temp for j in range(0,3): print str(n[j]),
1
426,408,456,172
null
40
40
n,m = map(int,input().split()) dac = {} for i in range(1,n+1): dac[str(i)] = 0 dwa = {} for i in range(1,n+1): dwa[str(i)] = 0 for i in range(m): p,s = input().split() if s == 'AC': dac[p] = 1 if s == 'WA' and dac[p] == 0: dwa[p] += 1 ac = 0 wa = 0 for k,v in dac.items(): ac += v for k,v in dwa.items(): if dac[k] == 1: wa += v print(ac,wa)
N, K = list(map(int, input().split())) P = list(map(int, input().split())) s = sum(P[:K]) ans = s for i in range(N-K): s = s - P[i] + P[i+K] ans = max(ans,s) print((ans + K) / 2)
0
null
84,092,266,646,392
240
223
n,m = [int(i) for i in input().split()] a = [[0 for i in range(m)] for j in range(n)] for i in range(n): a[i] = [int(j) for j in input().split()] b = [0 for i in range(m)] for i in range(m): b[i] = int(input()) for i in range(n): sum = 0 for j in range(m): sum += a[i][j] * b[j] print(sum)
a,b=map(int,raw_input().split()) print a/b,a%b,'%.8f'%(a/(b+0.0))
0
null
899,255,173,138
56
45
N=int(input()) S=input() if N%2==1: print('No') exit() n=N//2 for i in range(n): if S[i]!=S[n+i]: print('No') break else: print('Yes')
n = int(input()) s = input() a = s.split() def value(a, i): return int(a[i][-1]) def isstable(s, a, n): for i in range(n - 1): if value(a, i) == value(a, i + 1): v1 = s.index(a[i]) v2 = s.index(a[i + 1]) if v1 > v2: return "Not stable" return "Stable" for i in range(n - 1): for j in range(i + 1, n)[::-1]: if value(a, j) < value(a, j - 1): a[j], a[j - 1] = a[j - 1], a[j] print(" ".join(a)) print(isstable(s.split(), a, n)) a = s.split() for i in range(n - 1): minj = i for j in range(i + 1, n): if value(a, j) < value(a, minj): minj = j a[i], a[minj] = a[minj], a[i] print(" ".join(a)) print(isstable(s.split(), a, n))
0
null
73,153,375,201,030
279
16
# Date [ 2020-08-23 14:02:31 ] # Problem [ e.py ] # Author Koki_tkg # After Contest import sys; from decimal import Decimal import math; from numba import njit, i8, u1, b1 import bisect; from itertools import combinations, product import numpy as np; from collections import Counter, deque, defaultdict # sys.setrecursionlimit(10 ** 6) MOD = 10 ** 9 + 7 INF = 10 ** 9 PI = 3.14159265358979323846 def read_str(): return sys.stdin.readline().strip() def read_int(): return int(sys.stdin.readline().strip()) def read_ints(x=0): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split()) def read_str_list(): return list(sys.stdin.readline().strip().split()) def read_int_list(): return list(map(int, sys.stdin.readline().strip().split())) def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b) def solve(h,w,bomb): row = np.zeros(h, dtype=np.int64) column = np.zeros(w, dtype=np.int64) for y, x in bomb: row[y] += 1 column[x] += 1 max_row = np.max(row) max_col = np.max(column) val = max_row + max_col max_row_lis = np.ravel(np.where(row == row.max())) max_col_lis = np.ravel(np.where(column == column.max())) for r in max_row_lis: for c in max_col_lis: if (r, c) not in bomb: return val return val - 1 def Main(): h, w, m = read_ints() bomb = set([tuple(read_ints(x=1)) for _ in range(m)]) print(solve(h, w, bomb)) if __name__ == '__main__': Main()
def kougeki(H): if H == 1: return 1 else: return 2 * kougeki(H//2) + 1 H = int(input()) print(kougeki(H))
0
null
42,223,364,051,570
89
228
# -*- coding: utf-8 -*- k = int(input()) ans = 0 n = 7 if k % 2 == 0 or k % 5 == 0: print(-1) exit(0) c = 1 while True: if n % k == 0: break n = (n * 10 + 7) % k c += 1 print(c)
import bisect n, k = map(int, input().split()) l = list(map(int, input().split())) l.sort() a = bisect.bisect(l, k-1) print(n-a)
0
null
92,504,740,463,880
97
298
# B 1% import math X = int(input()) Y = 100 cnt = 0 while Y < X: cnt += 1 # Y = math.floor(Y*1.01) Y = Y + Y//100 print(cnt)
x = int(input()) deposit = 100 year = 0 rate = 101 while(deposit < x): deposit = deposit * rate // 100 year += 1 print(year)
1
27,134,562,160,820
null
159
159
a, b = input().split() print(int(a)*int(b[0]+b[2]+b[3])//100)
a, b = map(float, input().split()) ib = b * 100 ans = int(a) * round(ib) // 100 print(ans)
1
16,578,391,602,720
null
135
135
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) def main(): N, M = map(int, readline().split()) A = list(set(map(int, readline().split()))) B = A[::] while not any(b % 2 for b in B): B = [b // 2 for b in B] if not all(b % 2 for b in B): print(0) return semi_lcm = 1 for a in A: semi_lcm = lcm(semi_lcm, a // 2) if semi_lcm > M: print(0) return print((M // semi_lcm + 1) // 2) return if __name__ == '__main__': main()
import sys from fractions import gcd read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def merge(a, b): g = gcd(a, b) a //= g b //= g if a % 2 == 0: return 0 if b % 2 == 0: return 0 n = a * b * g if n > 10 ** 9: return 0 return n n, m = map(int, readline().split()) a = list(map(int, readline().split())) a = [x >> 1 for x in a] for i in range(n-1): a[i+1] = merge(a[i], a[i+1]) z = a[n-1] if z == 0: print("0") else: ans = (m//z) - (m//(z+z)) print(ans)
1
102,063,890,004,648
null
247
247
n = int(input()) values = [int(input()) for i in range(n)] maxv = -999999999 minimum = values[0] for i in range(1, n): if values[i] - minimum > maxv: maxv = values[i] - minimum if values[i] < minimum: minimum = values[i] print(maxv)
N = input() a = [input() for i in range(N)] maxv = a[-1] - a[0] minv = a[0] for i in range(1,N): maxv = max(maxv,a[i]-minv) minv = min(minv,a[i]) print maxv
1
13,539,942,488
null
13
13
import sys X, Y, Z = map(int, sys.stdin.readline().split()) print(Z, X, Y)
X,Y,Z = map(int,input().split()) G = X X = Y Y = G G = X X = Z Z = G print(f'{X} {Y} {Z}')
1
37,825,064,808,702
null
178
178
import math,sys for e in sys.stdin: a,b=list(map(int,e.split()));g=math.gcd(a,b) print(g,a*b//g)
import sys;print"\n".join("%d %d"%(lambda x:(x[2],x[0]/x[2]*x[1]))((lambda f,x:(x[0],x[1],f(f,x[0],x[1])))(lambda f,a,b:a%b==0 and b or f(f,b,a%b),map(int,s.split(' '))))for s in sys.stdin)
1
628,442,852
null
5
5
import sys from fractions import gcd read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def lcm(x, y): return x * y // gcd(x, y) def main(): N, M, *A = map(int, read().split()) B = A[::] while not any(b % 2 for b in B): B = [b // 2 for b in B] if not all(b % 2 for b in B): print(0) return semi_lcm = 1 for a in A: semi_lcm = lcm(semi_lcm, a // 2) print((M // semi_lcm + 1) // 2) return if __name__ == '__main__': main()
n, k = list(map(int, input().split())) # 先頭に0番要素を追加すれば、配列の要素番号と入力pが一致する p = [0] + list(map(int, input().split())) c = [0] + list(map(int, input().split())) ans = -float('inf') # 開始ノードをsi for si in range(1, n+1): # 閉ループのスコアを取り出す x = si s = list() # ノードの各スコアを保存 #s_len = 0 tot = 0 # ループ1周期のスコア while 1: x = p[x] s.append(c[x]) #s[s_len] = c[x] #s_len += 1 tot += c[x] if (x == si): break # 始点に戻ったら終了 # siを開始とする閉ループのスコア(s)を全探 s_len = len(s) t = 0 for i in range(s_len): t += s[i] # i回移動したときのスコア if (i+1 > k): break # 移動回数の上限を超えたら終了 # 1周期のスコアが正ならば、可能な限り周回する if tot > 0: e = (k-(i+1))//s_len # 周回数 now = t + tot*e # i回移動と周回スコアの合計 else: now = t ans = max(ans, now) print(ans)
0
null
53,369,563,969,476
247
93
for i in xrange(1,10): for j in xrange(1,10): print str(i)+ "x" + str(j) + "=" + str(i*j)
def main(): for N in range(1,10): for M in range(1,10): print(str(N)+"x"+str(M)+"="+str(N*M)) if __name__ == '__main__': main()
1
1,079,650
null
1
1
MOD=10**9+7 def facinv(N): fac,finv,inv=[0]*(N+1),[0]*(N+1),[0]*(N+1)#階乗テーブル、逆元テーブル、逆元 fac[0]=1;fac[1]=1;finv[0]=1;finv[1]=1;inv[1]=1 for i in range(2,N+1): fac[i]=fac[i-1]*i%MOD inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD finv[i]=finv[i-1]*inv[i]%MOD return fac,finv,inv def COM(n,r): if n<r or r<0: return 0 else: return ((fac[n]*finv[r])%MOD*finv[n-r])%MOD n,k=map(int,input().split()) fac,finv,inv=facinv(2*n) if k>=n-1: print(COM(2*n-1,n-1)) else: ans=COM(2*n-1,n-1) for i in range(1,n-k): ans=(ans-COM(n,i)*COM(n-1,i-1)%MOD+MOD)%MOD print(ans%MOD)
n, k = map(int, input().split()) MOD = 10 ** 9 + 7 def factorial(n): global fct global invfct fct = [0] * (n + 1) fct[0] = 1 for i in range(1, n+1): fct[i] = fct[i-1] * i % MOD invfct = [0] * (n + 1) invfct[n] = pow(fct[n], MOD - 2, MOD) for i in range(n-1, -1, -1): invfct[i] = invfct[i+1] * (i + 1) % MOD def binomial(n, k): return fct[n] * invfct[n-k] % MOD * invfct[k] % MOD factorial(2 * n) if k >= n: print(binomial(2 * n - 1, n) % MOD) else: answer = 0 for i in range(k+1): answer += binomial(n, i) * binomial(n-1, i) answer %= MOD print(answer)
1
67,199,680,453,400
null
215
215
N, R = list(map(int, input().split())) if N >= 10: print(R) else: ans = 100 * (10 - N) + R print(ans)
n = int(input()) a = [int(i) for i in input().split()] max_a = max(a) cnt_d = [0] * (max_a + 1) for ai in a: for multi in range(ai, max_a + 1, ai): cnt_d[multi] += 1 print(sum(cnt_d[ai] == 1 for ai in a))
0
null
39,155,859,303,748
211
129
import numpy as np N = int(input()) A = list(map(int, input().split())) ans = 1 if 0 in A: ans = 0 for i in range(N): ans *= A[i] if ans > 1000000000000000000: ans = -1 break print(ans)
N =int(input()) A = sorted(list(map(int,input().split()))) B = 1 C = 10 ** 18 for i in range(N): B = B * A[i] if B == 0: break elif B > C: B = -1 break print(B)
1
16,263,030,280,740
null
134
134
import sys sys.setrecursionlimit(4100000) import math INF = 10**9 import fractions def main(): a,b = map(int, input().split()) print(a*b//fractions.gcd(a, b)) if __name__ == '__main__': main()
n = int(input()) a = list(map(int, input().split())) pm = sum(a) e = 1 te = 1 for i in a: pm -= i e = min((e-i)*2, pm) if e < 0: break te += e if e < 0: print(-1) else: print(te)
0
null
65,826,829,269,590
256
141
class DP: def __init__(self, value, variety, coins): self.value = value self.variety = variety self.coins = coins self.DP = [[0 for _ in range(value + 1)] for _ in range(variety)] self.DPinit() def monitor(self): for (i, row) in enumerate(self.DP): print(coins[i], row) def DPinit(self): for row in self.DP: row[1] = 1 self.DP[0] = [i for i in range(self.value + 1)] def DPcomp(self): for m in range(self.variety): if m == 0: continue for n in range(self.value + 1): self.DP[m][n] = self.numberOfCoin(m, n) def numberOfCoin(self, m, n): if n >= self.coins[m]: return min(self.DP[m - 1][n], self.DP[m][n - self.coins[m]] + 1) else: return self.DP[m - 1][n] def answer(self): self.DPcomp() return self.DP[self.variety - 1][self.value] if __name__ == "__main__": status = list(map(int,input().split())) coins = list(map(int,input().split())) dp = DP(status[0],status[1],coins) print(dp.answer())
n,m=map(int,input().split()) a=[0]*n ans=0 for i in range(m): p,s=input().split() p=int(p)-1 if a[p]!=1: if s=='WA':a[p]-=1 else: ans-=a[p] a[p]=1 for i in range(n): a[i]=max(a[i],0) print(sum(a),ans)
0
null
46,931,032,105,042
28
240
N=int(input()) c=input() R=c.count('R') RR=c[0:R].count('R') print(min(R-RR,R,N-R))
n=int(input()) s = input() Ra = s.count('R') t = s[:Ra] Rb = t.count('R') print(Ra-Rb)
1
6,323,272,330,882
null
98
98
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 mans = inf ;ans = 0 ;count = 0 ;pro = 1 n = int(input()) A = list(map(int,input().split())) dp0 = [0] * (n+11) dp1 = [0] * (n+11) dp2 = [0] * (n+11) for i,ai in enumerate(A): dp2[i+11] = (max(dp0[i+7] + ai, dp1[i+8] + ai, dp2[i+9] + ai) if i >= 2 else 0) dp1[i+11] = (max(dp0[i+8] + ai, dp1[i+9] + ai) if i >= 1 else 0) dp0[i+11] = dp0[i+9] + ai if n % 2 == 0: print(max(dp0[n + 9], dp1[n + 10])) else: print(max(dp0[n + 8], dp1[n + 9], dp2[n + 10])) # debug # print(dp0,dp1,dp2,sep="\n")
#!/usr/bin/env python3 # coding: utf-8 import collections import math def debug(arg): if __debug__: pass else: import sys print(arg, file=sys.stderr) def main(): pass N, *A = map(int, open(0).read().split()) a = dict(enumerate(A, 1)) dp = collections.defaultdict(lambda: -float("inf")) dp[0, 0] = 0 dp[1, 0] = 0 dp[1, 1] = a[1] for i in range(2, N + 1): jj = range(max(math.floor(i // 2 - 1), 1), math.ceil((i + 1) // 2) + 1) for j in jj: x = dp[i - 2, j - 1] + a[i] y = dp[i - 1, j] dp[i, j] = max(x, y) print(dp[N, N // 2]) if __name__ == "__main__": main()
1
37,371,212,424,640
null
177
177
d,t,s=map(int, input().split()) if d/s <=t: print("Yes") else:print("No")
#! python3 a, b, c = [int(x) for x in input().strip().split(' ')] r = 0 for i in range(a, b+1): if c % i == 0: r += 1 print(r)
0
null
2,074,443,856,982
81
44
#!/usr/bin/env python3 import sys import math # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product # product(iter, repeat=n) # from itertools import accumulate # accumulate(iter[, f]) # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from copy import deepcopy # to copy multi-dimentional matrix without reference # from fractions import gcd # for Python 3.4 def main(): mod = 1000000007 # 10^9+7 inf = float('inf') sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) n, d, a = mi() monsters = sorted([lmi() for _ in range(n)]) monster_points = [] monster_hps= [] for pair in monsters: monster_points.append(pair[0]) monster_hps.append(pair[1]) # どの monster_points[ind] での ind の表すモンスターまで巻き込めるか (右端) right_end_monster_ind = [0] * (n) for i in range(n): right_end_monster_ind[i] = bisect_right(monster_points, monster_points[i]+2*d) - 1 # print(right_end_monster_ind) imos_list = [0] * (n+1) damage = 0 ans = 0 for i in range(n): damage += imos_list[i] rest_hp = max(0, monster_hps[i] - damage) # print("rest {}".format(rest_hp)) cnt = math.ceil(rest_hp / a) ans += cnt imos_list[i+1] += (a * cnt) imos_list[right_end_monster_ind[i]+1] -= (a * cnt) # print(imos_list) print(ans) if __name__ == "__main__": main()
import math N,D,A = map(int,input().split()) l = [] for i in range(N): l.append(list(map(int,input().split()))) l.sort() lx = [] lc = [] for i in l: X,H = i[0],i[1] lx.append(X) lc.append(math.ceil(H/A)) migi = [] m = 0 i = 0 while i <= N-1: if lx[m] - lx[i] > 2*D: migi.append(m) i += 1 elif m != N-1: m += 1 elif m == N-1: migi.append(-1) i += 1 cnt = 0 dam = [0 for i in range(N)] for i in range(N): if dam[i] < lc[i]: c = lc[i] - dam[i] dam[i] += c if migi[i] >= 0: dam[migi[i]] -= c cnt += c if i <=N-2: dam[i+1] += dam[i] print(cnt)
1
81,802,762,963,918
null
230
230
A, B = [int(s) for s in input().split()] ans = A * B print(ans)
str=input() arr=str.split(' ') A=int(arr[0]) B=int(arr[1]) if 1<=A<=100 and 1<=A<=100: print(A*B)
1
15,929,306,845,012
null
133
133
n,q = [int(s) for s in input().split()] queue = [] for i in range(n): name,time = input().split() queue.append([name,int(time)]) time = 0 while queue: processing = queue.pop(0) t = min(processing[1], q) time += t processing[1] -= t if processing[1] == 0: print(processing[0],time) else: queue.append(processing)
from collections import deque n, qt = map(int, input().split()) queue = deque() for i in range(n): name, time = input().split() queue.append([name, int(time)]) total_time = 0 while queue: q_t = queue.popleft() if q_t[1] <= qt: total_time += q_t[1] print(q_t[0], total_time) else: total_time += qt q_t[1] -= qt queue.append(q_t)
1
42,021,190,458
null
19
19
n,d=list(map(int,input().split())) s=list(map(int,input().split())) s=sorted(s) s.reverse() if d>=n: print(0) else: c=0 s=s[d:n] for i in s: c+=int(i) print(c)
n = int(input()) ans = 0 count = 0 a, b, c = 1, 1, 1 while a <= n: # print("A : {0}".format(a)) # print("追加パターン : {0}".format( (n // a) )) if a == 1 : ans = ans + ( (n // a) - 1) else : if n // a == 1 : ans = ans + 1 else : if n % a == 0 : ans = ans + ( (n // a) - 1) else : ans = ans + ( (n // a) ) # if n % a == 0 : # ans = ans + ( (n / a) - 1 ) # else : # ans = ans + ( (n // a) - 1 ) # ans = ans + (n / a) - 1 # print("A : {0}".format(a)) # while a * b < n: # print("B : {0}".format(b)) # ans += 1 # b += 1 # c = 1 a += 1 b, c = 1, 1 # print("計算実行回数 : {0}".format(count)) print(ans - 1)
0
null
40,592,550,650,912
227
73
N, X, Y = map(int, input().split()) d = Y-X+1 l = [0]*(N+1) for i in range(1, N+1): for j in range(i, N+1): m = min(j-i, abs(X-i)+1+abs(Y - j)) l[m] += 1 print(*l[1:-1], sep="\n")
N,X,Y=map(int,input().split()) d=[0]*N for i in range(N): for j in range(N): if not i<j: continue dist=min([j-i,abs((X-1)-i)+1+abs(j-(Y-1))]) d[dist]+=1 print(*d[1:],sep='\n')
1
44,319,377,268,032
null
187
187
A,B,K = map(int,input().split()) if A>=K: answer = A-K,B elif A+B>=K: answer = 0,B-(K-A) else: answer = 0,0 print(answer[0],answer[1])
import sys class UnionFind: def __init__(self, n): self.table = [-1] * n def _root(self, x): stack = [] tbl = self.table while tbl[x] >= 0: stack.append(x) x = tbl[x] for y in stack: tbl[y] = x return x def find(self, x, y): return self._root(x) == self._root(y) def union(self, x, y): r1 = self._root(x) r2 = self._root(y) if r1 == r2: return d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.table[r1] += d2 else: self.table[r1] = r2 self.table[r2] += d1 def main(): n, m, k = map(int, sys.stdin.buffer.readline().split()) uf = UnionFind(n) fb = [0]*n i = 0 for x in sys.stdin.buffer.readlines(): if i < m: a, b = map(int, x.split()) fb[a-1] += 1 fb[b-1] += 1 uf.union(a-1, b-1) else: c, d = map(int, x.split()) if uf._root(c-1) == uf._root(d-1): fb[c-1] += 1 fb[d-1] += 1 i += 1 ans = [-uf.table[uf._root(i)]-1-fb[i] for i in range(n)] print(*ans) if __name__ == "__main__": main()
0
null
83,412,218,343,520
249
209
#それぞれの桁を考えた時にその桁を一つ多めに払うのかちょうどで払うのかで場合分けする n=[int(x) for x in list(input())]#それぞれの桁にアクセスするためにイテラブルにする k=len(n) #それぞれの桁を見ていくが、そのままと一つ多い状態から引く場合と二つあることに注意 dp=[[-1,-1] for _ in range(k)] dp[0]=[min(1+(10-n[0]),n[0]),min(1+(10-n[0]-1),n[0]+1)] for i in range(1,k): dp[i]=[min(dp[i-1][1]+(10-n[i]),dp[i-1][0]+n[i]),min(dp[i-1][1]+(10-n[i]-1),dp[i-1][0]+n[i]+1)] print(dp[k-1][0])
s = input() s = '0' + s[::-1] dp = [[0, 0] for _ in range(len(s) + 1)] for i in range(len(s)): for j in range(2): if j == 0: #ぴったり dp[i + 1][j] = min(dp[i]) + int(s[i]) else: #1枚多めに払う dp[i + 1][j] = min(dp[i][1] + 9 - int(s[i]), dp[i][0] + 11 - int(s[i])) print(min(dp[-1]))
1
70,928,308,712,268
null
219
219
total = 0 n = int(input()) for i in range(1, n + 1): if not ((i % 5 == 0) or (i % 3 == 0)): total = total + i print(total)
input_data = input().split(" ") items = [int(cont) for cont in input_data] keys = ['T', 'S', 'E', 'W', 'N', 'B'] dice = dict(zip(keys, items)) def q1(): def rot_func_list(rot, dice): if rot == "N": keys = ['T', 'S', 'B', 'N'] items = dice['S'], dice['B'], dice['N'], dice['T'] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "S": keys = ['T', 'S', 'B', 'N'] items = dice['N'], dice['T'], dice['S'], dice['B'] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "E": keys = ['T', 'E', 'B', 'W'] items = dice['W'], dice['T'], dice['E'], dice['B'] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "W": keys = ['T', 'E', 'B', 'W'] items = dice['E'], dice['B'], dice['W'], dice['T'] new_dice = dict(zip(keys, items)) dice.update(new_dice) controls = list(input()) for i in controls: rot_func_list(i, dice) print(dice["T"]) def q2(): def search_surf(conds, dice): a,b=conds a_key = [k for k, v in dice.items() if v == a ] b_key = [k for k, v in dice.items() if v == b ] key_list = a_key + b_key part_st = ''.join(key_list) def search(part_st): if part_st in "TNBST": return "W" if part_st in "TSBNT": return "E" if part_st in "TEBWT": return "N" if part_st in "TWBET": return "S" if part_st in "NESWN": return "B" if part_st in "NWSEN": return "T" target_key = search(part_st) print(dice[target_key]) a = input() repeater = int(a) for neee in range(repeater): control_input = input().split(" ") conds = [int(i) for i in control_input] search_surf(conds, dice) q2()
0
null
17,536,420,071,136
173
34
from collections import deque que = deque() l = input() S = 0 S2 = [] for j in range(len(l)): i = l[j] if i == '\\': que.append(j) continue elif i == '/': if len(que) == 0: continue k = que.pop() pond_sum = j-k S += pond_sum while S2 and S2[-1][0] > k: pond_sum += S2[-1][1] S2.pop() S2.append([k,pond_sum]) elif i == '_': continue data = [i for j,i in S2] print(S) print(len(S2),*data)
li1 = [] li2 = [] for i, s in enumerate(input()): if s == "\\": li1.append(i) elif s == "/" and li1: j = li1.pop() c = i - j while li2 and li2[-1][0] > j: c += li2[-1][1] li2.pop() li2.append((j, c)) if li2: li3 = list(zip(*li2))[1] print(sum(li3)) print(len(li3), *li3) else: print(0, 0, sep="\n")
1
55,306,474,272
null
21
21
a = int(input()) b = list(map(int, input().split())) b = sorted(b) c = b[0] if c == 0: print(c) exit() else: for i in range(a-1): c *= b[i+1] if c > 1000000000000000000: break if c > 1000000000000000000: print(-1) else: print(c)
import math N, K = map(int, input().split()) A = [int(x) for x in input().split()] left, right = 0, max(A) while right - left > 1: mid = (left + right) // 2 res = 0 for i in range(N): res = res + math.ceil(A[i]/mid) - 1 if res <= K: right = mid else: left = mid print(right)
0
null
11,357,335,265,180
134
99
n = int(input()) a_list = [int(x) for x in input().split()] a_sum = sum(a_list) m = 10 ** 9 + 7 ans = 0 for i in range(n - 1): a_sum -= a_list[i] ans = (ans + a_list[i] * a_sum) % m print(ans)
N = int(input()) A = list(map(int,input().split())) cums = [0] for a in A: cums.append(cums[-1] + a) MOD = 10**9+7 ans = 0 for i in range(N-1): ans += A[i] * (cums[-1] - cums[i+1]) ans %= MOD print(ans)
1
3,835,029,844,130
null
83
83
while 1: H, W = map(int, raw_input().split()) if H == W == 0: break print ('#'*W + '\n')*H
while True: h,w = map(int,input().split()) if h == w == 0: break for x in range(int(h)): for y in range(int(w)): print("#",end="") print("") print("")
1
772,444,965,952
null
49
49
n = int(input()) S = input() beforeChara = "" cnt = 0 for s in S: if s != beforeChara: cnt += 1 beforeChara = s print(cnt)
N = int(input()) S = input() count = 0 for i in range(1, N): if S[i-1] != S[i]: count += 1 print(count+1)
1
170,362,227,067,602
null
293
293
S = input() K = int(input()) N = len(S) p = S[0] c = 0 if N == 1: print(K//2) exit() if len(set(S)) == 1: print(N*K//2) exit() for i in range(1,N): if S[i] == p: c += 1 p = '' else: p = S[i] ans = c*K if S[0] == S[-1]: p = S[0] c = 1 for i in range(1,N): if p == S[i]: c += 1 else: break d = 1 for i in range(2,N+1): if p == S[-i]: d += 1 else: break if (c%2)*(d%2) == 1: ans += K-1 print(ans)
s=input() k=int(input()) cnt=1 temp=[] for i in range(len(s)-1): if s[i]==s[i+1]: cnt+=1 else: temp.append([s[i],cnt]) cnt=1 if cnt>=1: temp.append([s[-1],cnt]) if len(temp)==1: print(k*len(s)//2) exit() ans=0 if temp[0][0]!=temp[-1][0]: for pair in temp: if pair[1]!=1: ans+=pair[1]//2 print(ans*k) else: for pair in temp[1:-1]: if pair[1]!=1: ans+=pair[1]//2 ans*=k ans+=(k-1)*((temp[0][1]+temp[-1][1])//2) ans+=temp[0][1]//2+temp[-1][1]//2 print(ans)
1
175,157,461,588,264
null
296
296