code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
def odd(num): return num//2+num%2 N=int(input()) num = odd(N)/N print("{:.10f}".format(num))
import sys import heapq from decimal import Decimal input = sys.stdin.readline n = int(input()) alpha_list = [chr(i) for i in range(97, 97+26)] def dfs(s,used_count): if len(s) == n: print(s) return for i in range(used_count+1): if i == used_count: dfs(s+alpha_list[i],used_count+1) else: dfs(s+alpha_list[i],used_count) dfs("a",1)
0
null
114,424,351,681,498
297
198
N = int(input()) A = 2*list(map(int, input().split())) A.sort() print(sum(A[N:-1]))
N = int(input()) g = 0 for n in range(1, N + 1): if n % 2 == 0: g += 1 ANS = (N - g) / N print(ANS)
0
null
93,253,219,229,422
111
297
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 t1, t2 = list(map(int, sys.stdin.buffer.readline().split())) a1, a2 = list(map(int, sys.stdin.buffer.readline().split())) b1, b2 = list(map(int, sys.stdin.buffer.readline().split())) da1 = t1 * a1 da2 = t2 * a2 db1 = t1 * b1 db2 = t2 * b2 if da1 + da2 > db1 + db2: a1, b1 = b1, a1 a2, b2 = b2, a2 da1, db1 = db1, da1 da2, db2 = db2, da2 # b のほうがはやい # 無限 if da1 + da2 == db1 + db2: print('infinity') exit() # 1回も会わない if da1 < db1: print(0) exit() # t1 で出会う回数 cnt = abs(da1 - db1) / abs(da1 + da2 - db1 - db2) ans = int(cnt) * 2 + 1 if cnt == int(cnt): ans -= 1 print(ans)
t1,t2=map(int,input().split()) a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) d1=t1*a1+t2*a2 d2=t1*b1+t2*b2 import sys if d1>d2: dif=d1-d2 gap=(b1-a1)*t1 elif d1<d2: dif=d2-d1 gap=(a1-b1)*t1 else: print('infinity') sys.exit() if (b1-a1)*(b2-a2)>0 or (b1-a1)*(d2-d1)>0: print(0) sys.exit() if gap%dif!=0: print(gap//dif*2+1) else: print(gap//dif*2)
1
131,296,726,540,372
null
269
269
# -*- 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)] def solve(): H, W, K = Scanner.map_int() S = Scanner.string_list(H) ans = int(1e15) for i in range(1 << (H - 1)): cut = 0 pc = 1 whites = [[0 for _ in range(W)] for _ in range(H)] for j in range(H - 1): for w in range(W): whites[cut][w] += S[j][w] == '1' if i >> j & 1: cut += 1 pc += 1 for w in range(W): whites[cut][w] += S[-1][w] == '1' flag = True for line in whites: for cnt in line: if cnt > K: flag = False if not flag: continue cnt = [0 for _ in range(pc)] for w in range(W): flag = True for j in range(pc): if cnt[j] + whites[j][w] > K: flag = False if not flag: cnt = [0 for _ in range(pc)] cut += 1 for j in range(pc): cnt[j] += whites[j][w] ans = min(ans, cut) print(ans) def main(): # sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
# E - Dividing Chocolate import numpy as np H, W, K = map(int, input().split()) S = np.zeros((H, W), dtype=np.int64) ans = H+W for i in range(H): S[i] = list(str(input())) for m in range(1<<(H-1)): cut = bin(m).count('1') if cut >= ans: continue wp = np.zeros((cut+1, W), dtype=np.int64) wp[0] = S[0] c = 0 for n in range(H-1): if m>>n&1: c += 1 wp[c] += S[n+1] if np.count_nonzero(wp > K): continue wq = np.zeros((cut+1, ), dtype=np.int64) for j in range(W): wq += wp[:,j] if np.count_nonzero(wq > K): cut += 1 wq = wp[:,j] ans = min(ans, cut) print(ans)
1
48,448,592,409,238
null
193
193
import sys import copy #import math #import itertools #import numpy as np #import re def func(x,m): return x**2%m N,X,M=[int(c) for c in input().split()] myset = {X} mydict = {X:0} A = [] A.append(X) s = X i = 0 i_stop = i #i=0は計算したので1から for i in range(1,N): A.append(func(A[i-1],M)) if A[i] in myset: i_stop = i break myset.add(A[i]) mydict[A[i]] = i s+=A[i] if i == N-1: print(s) sys.exit(0) if A[i] == 0: print(s) sys.exit(0) if i!=0: #最後にA[i]が出現したのは? A_repeat = A[mydict[A[i_stop]]:i_stop] s+=((N-1)-(i_stop-1))//len(A_repeat)*sum(A_repeat) for k in range(((N-1)-(i_stop-1))%len(A_repeat)): s+=A_repeat[k] print(s)
H, M = map(int, input().split()) A = list(map(int, input().split())) a = (sum(A)) if a >= H: ans = "Yes" else: ans = "No" print(ans)
0
null
40,237,852,310,208
75
226
import sys def input(): return sys.stdin.readline().rstrip() def main(): S = input() n = 0 for s in S: n += int(s) if n%9 == 0: print("Yes") else: print("No") if __name__=='__main__': main()
import sys import itertools class UnionFindTree: def __init__(self, n: int) -> None: self.par = list(range(n)) self.rank = [0] * n def find(self, x: int) -> int: if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x: int, y: int) -> None: x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def resolve(in_): N, M = map(int, next(in_).split()) tree = UnionFindTree(N + 1) AB = (map(int, line.split()) for line in itertools.islice(in_, M)) for a, b in AB: tree.unite(a, b) ans = len(frozenset(tree.find(x) for x in range(1, N + 1))) - 1 return ans def main(): ans = resolve(sys.stdin.buffer) print(ans) if __name__ == '__main__': main()
0
null
3,298,802,337,318
87
70
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) max_score = -float('inf') for i in range(n): loop_score_array = [] loop_score = 0 loop_len = 0 pos = i while True: pos = p[pos] - 1 loop_score += c[pos] loop_score_array.append(loop_score) loop_len+=1 if pos == i: break for i, score in enumerate(loop_score_array): if k-i-1 < 0: continue loop_num = (k-i-1)//loop_len score_sum = score + max(0, loop_score)*loop_num max_score = max(score_sum, max_score) print(max_score)
IN = list(map(int, input().split())) N, K = IN[0], IN[1] P = [None] + list(map(int, input().split())) C = [None] + list(map(int, input().split())) MAX_N = 45000 #N = 1000 #K = 10**7 #P = [None] + [random.choice(list(itertools.chain(range(1,i), range(i+1,N)))) for i in range(1, N+1)] #C = [None] + random.choices(range(-10**9, 10**9), k=N) verbose = False def cumsum(a): tmp = [0]*(len(a)+1) for i in range(1, len(a)+1): tmp[i] = a[i-1] + tmp[i-1] return tmp[1:] def find_cycle(p, pos): cnt = 0 steps = [0] * (MAX_N+1) path = [False] * (MAX_N+1) while True: steps[cnt] = pos path[pos] = True cnt += 1 pos = p[pos] if path[pos]: break # found closure st = steps.index(pos) # start of closure return [steps[:st], steps[st:cnt]] def score(steps, c): ret = [0]*len(steps) for i in range(len(steps)): ret[i] = c[steps[i]] return ret maxsc = -10**9-1 done = [False] * (N+1) for i in range(1, N+1): if verbose: print('entering', i) if done[i]: continue [preclosure_path, closure_path] = find_cycle(P, i) if verbose: print('closure found:', closure_path) closure_scores = score(closure_path, C) preclosure_scores = score(preclosure_path, C) closure_score = sum(closure_scores) preclosure_len, closure_len = len(preclosure_path), len(closure_path) cycles = (K-preclosure_len)//closure_len resid = (K-preclosure_len)%closure_len if cycles>=1: cycles -= 1 abbrev = closure_score * cycles trail = preclosure_scores + closure_scores * 3 path = preclosure_path + closure_path*3 if verbose: print('score trail:', trail) if verbose: print('path:', preclosure_path + closure_path*3) if verbose: print('mark:', mark) mark = min(K, len(preclosure_path+closure_path)+resid) localmax = max(cumsum(trail[0:mark])) + max(0, closure_score*cycles) if verbose: print('localmax:', localmax, 'cycles:', cycles) maxsc = max(localmax, maxsc) if verbose: print('going greedy') for j in range(1, closure_len): if K<=mark+j: break target = path[j] if done[target]: continue localmax = max(cumsum(trail[j:mark+j])) + max(0, closure_score*cycles) maxsc = max(localmax, maxsc) done[target] = True if verbose: print('done:', target, 'with', localmax) print(maxsc)
1
5,406,102,977,380
null
93
93
import sys def main(): S=sys.stdin.readline().strip() print('ARC') if S=='ABC' else print('ABC') if __name__=='__main__':main()
import sys from copy import copy read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: map(int, readline().split()) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: map(int, read().split()) in_s = lambda: readline().rstrip().decode('utf-8') INF = 10**9 + 7 def main(): H, W = in_nn() s = [list(in_s()) for _ in range(H)] dp = [INF] * W if s[0][0] == '#': dp[0] = 1 else: dp[0] = 0 for x in range(W - 1): if s[0][x] == '.' and s[0][x + 1] == '#': dp[x + 1] = dp[x] + 1 else: dp[x + 1] = dp[x] for y in range(1, H): next_dp = [INF] * W for x in range(W): if s[y - 1][x] == '.' and s[y][x] == '#': next_dp[x] = min(next_dp[x], dp[x] + 1) else: next_dp[x] = min(next_dp[x], dp[x]) for x in range(1, W): if s[y][x - 1] == '.' and s[y][x] == '#': next_dp[x] = min(next_dp[x], next_dp[x - 1] + 1) else: next_dp[x] = min(next_dp[x], next_dp[x - 1]) dp = next_dp print(dp[-1]) if __name__ == '__main__': main()
0
null
36,734,974,923,442
153
194
n = int(input()) s = [''] * n for i in range(n): s[i] = input() print(len(set(s)))
def main(): n = int(input()) s = set() for _ in range(n): s.add(input()) print(len(s)) if __name__ == "__main__": main()
1
30,171,420,853,810
null
165
165
N = int(input()) S = input() s = list(S) for i in range(len(S)): if (ord(s[i]) - 64 + N) % 26 == 0: p = 90 else: p = (ord(s[i]) - 64 + N) % 26 + 64 s[i] = chr(p) print("".join(s))
n = int(input()) s = list(input()) ans = [] for i in range(len(s)): a = ord(s[i]) moji = a + n if a + n <= 90 else a + n -26 ans += [chr(moji)] print("".join(ans))
1
134,491,381,989,540
null
271
271
a,b,c=map(int,input().split()) list=[a,b,c] list.sort() print(list[0],list[1],list[2])
i=list(map(int,input().split())) x=[[0,1],[0,2],[1,2]] for a in range(3): if( i[ x[a][0] ] > i[ x[a][1] ]): swap=i[ x[a][0] ] i[ x[a][0] ]= i[ x[a][1] ] i[ x[a][1] ]=swap print(i[0],end=' ') print(i[1],end=' ') print(i[2],end='\n')
1
415,006,219,840
null
40
40
import math import itertools n = int(input()) xy = [] for i in range(n): xy.append(list(map(int,input().split()))) total_distance = 0 list_keiro = [] for team in itertools.permutations(range(n)): list_keiro.append(team) def distance(x1,x2,y1,y2): return (math.sqrt((x1-x2)**2 + (y1-y2)**2)) for i in list_keiro: dis_tmp = 0 for j in range(n-1): dis_tmp += distance(xy[i[j]][0],xy[i[j+1]][0],xy[i[j]][1],xy[i[j+1]][1]) total_distance += dis_tmp print(total_distance / len(list_keiro))
N = int(input()) A = tuple(map(int, input().split())) dupcount = [0] * (N + 1) for a in A: dupcount[a] += 1 allc = 0 for a in range(1, N + 1): c = dupcount[a] if c > 1: allc += (c * (c - 1) // 2) for a in A: ans = allc c = dupcount[a] if c > 0: ans -= (c - 1) print(ans)
0
null
97,659,370,318,868
280
192
data = "" data_1 = [chr(ord('a') + i) for i in range(26)] while True: try: data += input().lower() except EOFError: break for i in data_1: j = data.count(i) print(f'{i} : {j}')
import sys s = sys.stdin.read() for c in [chr(i) for i in range(97,97+26)]: print(c, ":", s.lower().count(c))
1
1,666,371,224,682
null
63
63
MOD = pow(10, 9)+7 def combi(n, k, MOD): numer = 1 for i in range(n, n-k, -1): numer *= i numer %= MOD denom = 1 for j in range(k, 0, -1): denom *= j denom %= MOD return (numer*(pow(denom, MOD-2, MOD)))%MOD def main(): n, a, b = map(int, input().split()) allsum = pow(2, n, MOD) s1 = combi(n, a, MOD) s2 = combi(n, b, MOD) ans = (allsum - s1 - s2 - 1)%MOD print(ans) if __name__ == "__main__": main()
s=str(input().upper()) if s=="ABC": print("ARC") if s=="ARC": print("ABC")
0
null
45,022,758,964,692
214
153
n = int(input()) arr = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] for i in range(n): s = input().split(" ") nums = list(map(int, s)) arr[nums[0]-1][nums[1]-1][nums[2]-1] += nums[3] for k in range(4): for j in range(3): for i in range(10): print(" {0}".format(arr[k][j][i]),end="") print("") if k < 3: for l in range(20): print("#",end="") print("")
n,d,a = map(int,input().split()) xh = [list(map(int,input().split())) for _ in range(n)] xh.sort() ans = 0 att = [0]*n cnt = 0 f = [] f1 = [0]*n for x,h in xh: f.append(h) for i in range(n): tmp = xh[i][0] + 2 * d while cnt < n: if xh[cnt][0] <= tmp: cnt += 1 else: break att[i] = min(cnt-1, n-1) for i in range(n): if f[i] > 0: da = -(-f[i]//a) ans += da f1[i] -= da * a if att[i]+1 < n: f1[att[i]+1] += da * a if i < n-1: f1[i+1] += f1[i] f[i+1] += f1[i+1] print(ans)
0
null
41,893,499,981,200
55
230
while True: x = [] x = input().split( ) y = [int(s) for s in x] if sum(y) == -3: break if y[0] == -1 or y[1] == -1: print("F") elif y[0] + y[1] < 30: print("F") elif y[0] + y[1] >= 30 and y[0] + y[1] <50: if y[2] >= 50: print("C") else: print("D") elif y[0] + y[1] >= 50 and y[0] + y[1] <65: print("C") elif y[0] + y[1] >= 65 and y[0] + y[1] <80: print("B") elif y[0] + y[1] >= 80: print("A")
#!/usr/bin python3 # -*- coding: utf-8 -*- def main(): mod = 10**9+7 K = int(input()) S = input() Nk = len(S) ret = 0 nCk = 1 pw25 = 1 pw26 = pow(26,K,mod) inv26 = pow(26,mod-2,mod) for i in range(K+1): ret += nCk * pw25 * pw26 ret %= mod nCk *= (i+Nk) * pow(i+1,mod-2,mod) nCk %= mod pw25 = (pw25*25)%mod pw26 = (pw26*inv26)%mod print(ret) if __name__ == '__main__': main()
0
null
7,092,337,369,810
57
124
N = int(input()) A = list(map(int, input().split())) money = 1000 kabu = 0 for i in range(N-1): if kabu > 0: money += kabu*A[i] kabu = 0 if A[i] < A[i+1]: kabu = money//A[i] money -= kabu*A[i] if kabu > 0: money += kabu*A[-1] print(money)
(W, H, x, y, r) = [int(i) for i in input().rstrip().split()] if x + r <= W and x - r >= 0 and y + r <= H and y - r >= 0: print('Yes') else: print('No')
0
null
3,880,689,476,900
103
41
N, K = list(map(int, input().split())) A = list(map(int, input().split())) dp = [0] * (N + 1) for k in range(K): sta = [max(i-A[i], 0) for i in range(N)] end = [min(i+A[i]+1, N) for i in range(N)] for s in sta: dp[s] += 1 for e in end: dp[e] -= 1 for i in range(1, len(dp)-1): dp[i] += dp[i-1] B = dp[:-1] if A == B: break A = B dp = [0] * (N + 1) print(' '.join(map(str, A)))
n = int(input()) a = list(map(int, input().split())) ans = 1 for i in a: if i == 0: ans = 0 if ans != 0: for i in a: ans *= i if ans > 10**18: ans = -1 break print(ans)
0
null
15,833,992,826,652
132
134
N, M = map(int, input().split()) if N - M == 0 : print('Yes') else : print('No')
def colorchange(i,l,r,col): k=i-1 while(k>=0): if not '#' in G[k]: for j in range(l+1,r+1): A[k][j]=col else: break k-=1 k=i+1 while(k<H): if not '#' in G[k]: for j in range(l+1,r+1): A[k][j]=col else: break k+=1 H,W,K=map(int,input().split()) G=[list(input()) for i in range(H)] s=set() A=[[-1]*W for i in range(H)] now=1 for i in range(H): if not '#' in G[i]: continue last=-1 first=True for j in range(W): if G[i][j]=='#' and j==0: first=False A[i][j]=now if j==W-1: colorchange(i,last,j,now) now+=1 elif G[i][j+1]=='#': if first: first=False else: colorchange(i,last,j,now) last=j now+=1 for i in range(H): print(*A[i])
0
null
113,834,924,073,178
231
277
x,y=map(int,input().split()) ans=0 if x==1: ans=ans+300000 if y==1: ans=ans+300000 if x==2: ans=ans+200000 if y==2: ans=ans+200000 if x==3: ans=ans+100000 if y==3: ans=ans+100000 if x==1 and y==1: ans=ans+400000 print(ans)
n = input() a = [raw_input() for _ in range(n)] b = [] for i in ['S ','H ','C ','D ']: for j in range(1,14): b.append(i+str(j)) for i in a: b.remove(i) for i in b: print i
0
null
70,731,300,898,662
275
54
cards = [[False for i in range(13)] for j in range(4)] pattern = ["S", "H", "C", "D"] cnt = int(input()) for i in range(cnt): ch,rank = input().split() rank = int(rank) cards[pattern.index(ch)][rank-1] = True for i in range(4): for j in range(13): if cards[i][j] == False: print(pattern[i], j+1)
n = int(input()) my_cards = {input() for _ in range(n)} lost_cards = ( "{} {}".format(s, i) for s in ('S', 'H', 'C', 'D') for i in range(1, 13 + 1) if "{} {}".format(s, i) not in my_cards ) for card in lost_cards: print (card)
1
1,038,256,554,922
null
54
54
import bisect n, m, k = list(map(int, input().split())) book_a = list(map(int, input().split())) book_b = list(map(int, input().split())) a_time_sum = [0] b_time_sum = [] for i in range(n): if i == 0: a_time_sum.append(book_a[0]) else: a_time_sum.append(a_time_sum[i]+book_a[i]) for i in range(m): if i == 0: b_time_sum.append(book_b[0]) else: b_time_sum.append(b_time_sum[i-1]+book_b[i]) ans = 0 # Aから何冊か読む for i in range(n+1): read = i a_time = a_time_sum[i] time_remain = k - a_time if time_remain < 0: break # このときBから何冊よめる? b_read = bisect.bisect_right(b_time_sum, time_remain) read += b_read ans = max(ans, read) print(ans)
n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) aa = [0] for i in a: aa.append(aa[-1]+i) bb = [0] for i in b: bb.append(bb[-1]+i) ans = 0 j = m for i in range(n+1): if aa[i] > k: break while aa[i] + bb[j] > k and j > 0: j -= 1 ans = max(ans, i+j) print(ans)
1
10,808,125,502,028
null
117
117
n = int(input()) playList = [] sumTerm = 0 for i in range(n) : song = input().split() song[1] = int(song[1]) playList.append(song) sumTerm += song[1] x = input() tmpSumTerm = 0 for i in range(n) : tmpSumTerm += playList[i][1] if playList[i][0] == x : print(sumTerm - tmpSumTerm) break
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10 ** 9 + 7 # K回の移動が終わった後、人がいる部屋の数はNからN-K def cmb(n, k): if k < 0 or k > n: return 0 return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD def cumprod(arr, MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64); x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10 ** 6 # 階乗テーブルの上限 fact, fact_inv = make_fact(U, MOD) N, K = lr() answer = 0 for x in range(N, max(0, N-K-1), -1): # x個の家には1人以上いるのでこの人たちは除く can_move = N - x # x-1の壁をcan_move+1の場所に入れる answer += cmb(N, x) * cmb(x - 1 + can_move, can_move) answer %= MOD print(answer % MOD) # 31
0
null
82,432,678,246,188
243
215
k,n = map(int,(input().split())) a = list(map(int,input().split())) maxDis = 0 for i in range(len(a)-1): if i == 0: maxDis = a[i]+k-a[i-1] elif abs(a[i]-a[i-1]) > maxDis: maxDis = abs(a[i]-a[i-1]) if abs(a[i]-a[i+1]) > maxDis: maxDis = abs(a[i]-a[i+1]) print(k-maxDis)
N,K=map(int,input().split()) A=list(map(int,input().split())) B=[N-A[K-1]+A[0]] for i in range(K-1): b=A[i+1]-A[i] B.append(b) B.sort() print(sum(B)-B[K-1])
1
43,465,904,365,712
null
186
186
Residents = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) for l in range(n): b, f, r, v = list(map(int, input().split())) Residents[b-1][f-1][r-1] += v for k in range(4): for j in range(3): print(' '+' '.join(map(str, Residents[k][j]))) if k == 3: break print('####################')
import math a, b, C = map(int, input().split()) C = C / 180 * math.pi S = a * b * math.sin(C) / 2 print(S) print(a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))) print(2 * S / a)
0
null
640,827,995,038
55
30
import math def hoge(a): return a * a x1, y1, x2, y2 = map(float, input().split()) print (math.sqrt(hoge(math.fabs(x1-x2)) + hoge(math.fabs(y1-y2))))
x1,y1,x2,y2=map(float,input().split()) a=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1) print(a**(1/2))
1
160,629,162,902
null
29
29
x,k,d = map(int,input().split()) count = abs(x)//d if x<0: before_border = x+d*count after_border = x+d*(count+1) else: before_border = x-d*count after_border = x-d*(count+1) if count >= k: if x<0: print(abs(x+d*k)) else: print(abs(x-d*k)) else: if (count-k)%2 == 0: print(abs(before_border)) else: print(abs(after_border))
X, K, D = list(map(int, input().split())) X = abs(X) if(X >= K * D): print(X - K * D) else: q = X // D r = X % D if((K - q) % 2 == 0): print(r) else: print(abs(r - D))
1
5,215,465,120,416
null
92
92
def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v n = int(input()) A = [int(input()) for _ in range(n)] cnt = 0 G = [int(pow(4, i) + 3*pow(2, i-1) + 1) for i in range(10)[::-1]] + [1] G = [v for v in G if v <= n] m = len(G) for i in range(m): insertionSort(A, n, G[i]) print(m) print(*G) print(cnt) print(*A, sep='\n')
a,b,c,d=map(int,input().split()) prd=[a*c,a*d,b*c,b*d] if (a<0<b or c<0<d) and max(prd)<0: print(0) else: print(max(prd))
0
null
1,510,565,530,602
17
77
import copy def main(): N, M, Q = [int(n) for n in input().split(" ")] q = [[int(a) for a in input().split(" ")] for i in range(Q)] all_series = get_series(N, M) points = [0] for l in all_series: points.append(get_score(l, q)) print(max(points)) def get_score(l, q): return sum([q[i][3] if l[q[i][1] - 1] - l[q[i][0] - 1] == q[i][2] else 0 for i in range(len(q))]) def get_series(N, M): # N: number of elms # M: upper limit of val of elm all_series = [] checked = [[0] * M for i in range(N)] to_check = [[0, j + 1] for j in range(M)] series = [0 for k in range(N)] while len(to_check) > 0: checking = to_check.pop(-1) series[checking[0]] = checking[1] if checking[0] == N - 1: l = copy.deepcopy(series) all_series.append(l) else: to_check.extend([[checking[0] + 1, k] for k in range(checking[1], M + 1)]) return all_series main()
from itertools import accumulate from collections import defaultdict N,K = map(int,input().split()) A = list(map(int,input().split())) S = [0] + list(accumulate(A)) S = [ s%K for s in S ] ans = 0 counter = defaultdict(int) queue = [] for i,s in enumerate(S): t = (s-i) % K ans += counter[t] counter[t] += 1 queue.append(t) if len(queue) >= K: counter[queue[0]] -= 1 queue.pop(0) print(ans)
0
null
82,989,337,958,732
160
273
s = str(raw_input()) p = str(raw_input()) i = 0 while(1): if i == len(s): print "No" break if i+len(p) >= len(s): str = s[i:len(s)] + s[0:len(p)-len(s[i:len(s)])] else: str = s[i:i+len(p)] if str == p: print "Yes" break else: i += 1
# 問題:https://atcoder.jp/contests/abc142/tasks/abc142_b n, k = map(int, input().strip().split()) h = list(map(int, input().strip().split())) res = 0 for i in range(n): if h[i] < k: continue res += 1 print(res)
0
null
89,928,506,685,500
64
298
# coding: utf-8 # Here your code ! def func(): try: line = input() except: print("input error") return -1 marks = ("S","H","C","D") cards = [] while(True): try: line = input().rstrip() elements = line.split(" ") if(elements[0] in marks): elements[1]=int(elements[1]) cards.append(elements) else: print("1input error") return -1 except EOFError: break except : print("input error") return -1 result="" for mark in marks: for i in range(1,14): if([mark,i] not in cards): result += mark+" "+str(i)+"\n" if(len(result)>0): print(result.rstrip()) func()
from itertools import * c = [f'{x} {y}' for x, y in product('SHCD', range(1, 14))] for _ in range(int(input())): c.remove(input()) if c: print(*c, sep='\n')
1
1,053,487,775,328
null
54
54
h1, m1, h2, m2, k = map(int, input().split()) s = h1*60+m1 t = h2*60+m2 ans = t-s-k print (max(ans,0))
import collections N=int(input()) A=list(map(int,input().split())) D = collections.Counter(A) s=0 for i in D: s+=D[i]*(D[i]-1)//2 for i in range(N): print(s-(D[A[i]]-1))
0
null
32,724,593,291,672
139
192
a,b = map(float, raw_input().split()) if b > 10**6: f = 0.0 else: f = a/b d = int(a/b) r = int(a%b) print d, r, f
N, A, B = map(int, input().split(' ')) if N - N // (A + B) * (A + B) > A: tail = A else: tail = N - N // (A + B) * (A + B) print(N // (A + B) * A + tail)
0
null
28,256,451,080,550
45
202
n, k = map(int, input().split()) a = list(map(int, input().split())) d = [[-1] * n for _ in range(70)] for i in range(n): d[0][i] = a[i] - 1 for i in range(1, 70): for j in range(n): d[i][j] = d[i - 1][d[i - 1][j]] dst = 0 while k: i = 70 while pow(2, i) & k <= 0: i -= 1 dst = d[i][dst] k -= pow(2, i) print(dst + 1)
N, D, A = map(int, input().split()) monster = [] for k in range(N): monster.append(list(map(int, input().split()))) monster.sort(key = lambda x: x[0]) for k in range(N): monster[k][1] = int((monster[k][1]-0.1)//A + 1) ans = 0 final = monster[-1][0] ruiseki = 0 minuslist = [] j = 0 for k in range(N): while (j < len(minuslist)): if monster[k][0] >= minuslist[j][0]: ruiseki -= minuslist[j][1] j += 1 else: break if ruiseki < monster[k][1]: ans += monster[k][1] - ruiseki if monster[k][0] + 2*D +1 <= final: minuslist.append([monster[k][0]+2*D+1, monster[k][1] - ruiseki]) ruiseki = monster[k][1] print(ans)
0
null
52,727,075,225,330
150
230
k, n = list(map(int, input().split())) a = list(map(int, input().split())) d = [] for i in range(n): if i == n - 1: d.append(a[0] + (k - a[i])) else: d.append(a[i + 1] - a[i]) d.sort() print(sum(d[:-1]))
a,b,k=map(int,input().split()) if a<=k: k-=a a=0 if b<=k: print(0,0) else: b-=k print(a,b) elif k<a: a-=k print(a,b)
0
null
74,308,521,011,880
186
249
while True: h,w = map(int,input().split()) if h == w == 0: break for y in range(h): for x in range(w): if (y+x)%2 == 0: print('#',end="") if (y+x)%2 == 1: print('.',end="") print() print()
S = input() K = int(input()) if len(S) == 1: print(K//2) exit() if len(set(S)) == 1: ans = len(S)*K//2 print(ans) exit() if S[0] != S[-1]: ans = 0 tmp = "" for s in S: if s == tmp: ans += 1 tmp = "" continue else: tmp = s ans *= K print(ans) exit() elif S[0] == S[-1]: A = 0 B = 0 for s in S: if s == S[0]: A+=1 else: break for s in S[::-1]: if s == S[0]: B+=1 else: break ans = 0 tmp = "" for s in S: if s == tmp: ans += 1 tmp = "" continue else: tmp = s ans *= K ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1) print(ans) exit()
0
null
88,118,701,239,612
51
296
results = [] while True: cards = input() if cards == '-': break for i in range(int(input())): n = int(input()) cards = cards[n:] + cards[:n] results.append(cards) for line in results: print(line)
while True: string = input() if string == "-": break else: s = 0 for i in range(int(input())): s += int(input()) s = s % len(string) print(string[s:] + string[:s])
1
1,880,667,350,012
null
66
66
n = input() ret = 0 for s in n: ret *= 10 ret %= 9 ret += int(s) ret %= 9 if ret == 0: print("Yes") else: print("No")
N = int(input()) if(N % 9 == 0): ans = True else: ans = False print("Yes" if ans else "No")
1
4,429,210,639,702
null
87
87
while 1: x=raw_input() if x=='0': break print sum([int(v) for v in x])
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product, accumulate, combinations, product #import bisect# lower_bound etc #import numpy as np #from copy import deepcopy #from collections import deque def run(): N = input() S = input() dp = [0] * 1000 ans = 0 for n in S: n = int(n) #print(dp) for i in range(1000): if i // 100 == n and dp[i] == 0: dp[i] = 1 #print(f'{i} -> 1') elif (i // 10) % 10 == n and dp[i] == 1: dp[i] = 2 #print(f'{i} -> 2') elif i % 10 == n and dp[i] == 2: dp[i] = 3 #print(f'{i} -> 3') ans += 1 print(ans) #print(factorials) if __name__ == "__main__": run()
0
null
65,125,692,936,252
62
267
# -*- coding: utf-8 -*- str = raw_input() for _ in xrange(input()): ops = raw_input().split() na = int(ops[1]) nb = int(ops[2]) + 1 op = ops[0] if op[0]=="p": print str[na:nb] elif op[2]=="v": t = str[na:nb] str = str[:na] + t[::-1] + str[nb:] else: str = str[:na] + ops[3] + str[nb:]
r=input().split() N=int(r[0]) d_pre=input().split() d=[int(s) for s in d_pre] ans=N-sum(d) if ans>=0: print(ans) else: print(-1)
0
null
16,900,506,334,220
68
168
a,b,c = sorted(map(int,raw_input().split())) print a,b,c
class Dice(object): def __init__(self, line): self.top = 1 self.bottom = 6 self.south = 2 self.east = 3 self.west = 4 self.north = 5 self.convert = [int(s) for s in line.split()] def move(self, direction): if 'N' == direction: self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom elif 'S' == direction: self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top elif 'W' == direction: self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top elif 'E' == direction: self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom def search(self, line): top, south = [int(s) for s in line.split()] for direction in 'NNNNWNNNN': self.move(direction) if self.convert[self.south - 1] == south: break for direction in 'WWWW': self.move(direction) if self.convert[self.top - 1] == top: break return self.result() def result(self): return self.convert[self.east - 1] dice = Dice(input()) for i in range(int(input())): print(dice.search(input()))
0
null
337,604,463,142
40
34
ri = lambda S: [int(v) for v in S.split()] def rii(): return ri(input()) a, b = rii() print(min(str(a) * b, str(b) * a))
n, m= map(int, input().split(" ")) print(min(str(n)*m, str(m)*n))
1
84,404,911,280,128
null
232
232
ri = lambda S: [int(v) for v in S.split()] def rii(): return ri(input()) H, A = rii() H, r = divmod(H, A) r = 1 if r else r print(H + r)
score = list(map(int,input().split())) kaisu = 1 hp = score[0] while hp > score[1]: kaisu += 1 hp -= score[1] print(kaisu)
1
76,565,963,249,212
null
225
225
while True: s = raw_input().split() a = int(s[0]) b = int(s[2]) if s[1] == "?": break elif s[1] == '+': print a + b elif s[1] == '-': print a - b elif s[1] == '*': print a * b elif s[1] == '/': print a / b
import sys for x in sys.stdin: if "?" in x: break print(eval(x.replace("/", "//")))
1
695,902,817,664
null
47
47
N=int(input()) DMY=10**9 mmax=None mmin=None dmax=None dmin=None for i in range(N): x,y = map(int, input().split()) if not mmax: mmax=(x,y,x+y) mmin=(x,y,x+y) dmax=(x,y,x+DMY-y) dmin=(x,y,x+DMY-y) continue if x+y > mmax[2]: mmax=(x,y,x+y) elif x+y < mmin[2]: mmin=(x,y,x+y) if x+DMY-y > dmax[2]: dmax=(x,y,x+DMY-y) elif x+DMY-y < dmin[2]: dmin=(x,y,x+DMY-y) print(max(mmax[2]-mmin[2],dmax[2]-dmin[2]))
import numpy as np A,B,N = map(int,input().split()) if B <= N: x = B-1 print(int(np.floor(A*x/B))) else: print(int(np.floor(A*N/B)))
0
null
15,802,936,809,244
80
161
import sys def f(x): p=0 cnt=0 for i in range(n-1,-1,-1): while p<n and a[i]+a[p]<x: p+=1 cnt+=n-p return cnt n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort() l,r=a[0]*2,a[n-1]*2 while True: if r-l<=1: if f(r)==m: md=r;break else: md=l;break md=(r+l)//2 k=f(md) if k==m: break elif k>m: l=md else: r=md p=0 cnt=0 ans=0 for q in range(n-1,-1,-1): while p<n and a[q]+a[p]<=md: p+=1 if p==n: break cnt+=n-p ans+=a[q]*(n-p)*2 ans+=(m-cnt)*md print(ans)
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict import bisect con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) def Binary_Search(A, N, M): #初期化 left = 0 right = 10 ** 7 ans = 0 #累積和 Asum = [0] for i in range(N): Asum.append(Asum[i] + A[-1 - i]) leftj = [INF, INF] rightj = [0, 0] #二分探索 while left <= right: mid = (left + right) // 2 var = 0 happiness = 0 for i in range(N): ind = bisect.bisect_left(A, mid - A[i]) ind = N - ind var += ind happiness += ind * A[i] + Asum[ind] # print(var, happiness) if var == M: return happiness elif var > M: leftj = min(leftj, [var, -mid]) left = mid + 1 else: ans = max(ans, happiness) rightj = max(rightj, [var, -mid]) right = mid - 1 # print(ans) # print(leftj) # print(rightj) ans = ans + (M - rightj[0]) * (-leftj[1]) return ans #処理内容 def main(): N, M = getlist() A = getlist() A.sort() ans = Binary_Search(A, N, M) print(ans) if __name__ == '__main__': main()
1
107,635,034,354,940
null
252
252
import itertools def actual(n, D): """ combinations でゴリ押し """ comb = itertools.combinations(D, 2) # return sum([x * y for x, y in comb]) """ 「順番を考慮しない2要素の選び方」を全探索する際のポイント 内側のループ変数の始点を外側のループ変数 +1 から始めるとよい。 これにより、内側のループで選ぶインデックスが必ず外側のループで選ぶインデックスより大きくなり、 同じ選び方を 2 回見てしまうことを回避できます。 """ # s = 0 # for i in range(len(D)): # for j in range(i + 1, len(D)): # s += D[i] * D[j] # # return s """ O(N)で解くパターン ex: a, b, c, d a*b + a*c + a*d = a * (b + c +d) b*c + b*d = b * ( c +d) c*d = c * ( d) """ s = 0 for i in range(len(D) - 1): s += D[i] * sum(D[i + 1:]) return s n = int(input()) D = list(map(int, input().split())) print(actual(n, D))
def main(): n = int(input()) for i in range(1,10): if(n % i == 0 and n//i < 10): print("Yes") exit(0) print("No") if __name__ == "__main__": main()
0
null
164,357,293,079,420
292
287
cont = input() if cont == 'ABC': print('ARC') else: print('ABC')
def main(): a, b, c, d = (int(i) for i in input().split()) print(max(a*c, b*d, a*d, b*c)) if __name__ == '__main__': main()
0
null
13,592,194,314,272
153
77
l = [int(i) for i in input().split()] l.sort() print(str(l[0])+' '+str(l[1])+' '+str(l[2]))
H, W, K = map(int, input().split()) sl = [] for _ in range(H): sl.append(list(input())) ans = 10**8 for i in range(2 ** (H-1)): fail_flag = False comb = [] for j in range(H-1): if ((i >> j) & 1): comb.append(j) comb.append(H-1) # print(comb) sections = [] for k in range(0,len(comb)): if k == 0: sections.append( sl[0:comb[0]+1] ) else: sections.append( sl[comb[k-1]+1:comb[k]+1] ) # print(sections) partition_cnt = 0 sections_w_cnts = [0]*len(sections) for w in range(W): sections_curr_w_cnts = [0]*len(sections) partition_flag = False for i, sec in enumerate(sections): for row in sec: if row[w] == '1': sections_curr_w_cnts[i] += 1 sections_w_cnts[i] += 1 if sections_curr_w_cnts[i] > K: fail_flag = True break if sections_w_cnts[i] > K: partition_flag = True if fail_flag: break if fail_flag: break if partition_flag: sections_w_cnts = [v for v in sections_curr_w_cnts] # sections_w_cnts[:] = sections_curr_w_cnts[:] partition_cnt += 1 if not fail_flag: ans = min(len(comb)-1+partition_cnt, ans) print(ans)
0
null
24,390,488,736,940
40
193
N = int(input()) X = list(map(int, input().split())) INF = 10**6 + 1 mintotal = INF for p in range(1, 101): total = 0 for x in X: total += (x-p)**2 mintotal = min(mintotal, total) print(mintotal)
from itertools import product N = int(input()) A = [None] * N lst = [[] for _ in range(N)] for i in range(N): A[i] = int(input()) lst[i] = [list(map(int, input().split())) for _ in range(A[i])] bit_lst = list(product(range(2), repeat=N)) #N桁のビット ans = 0 for bit in bit_lst: f = True #このbitの証言が無意味になったらFalse for a in range(N): #1人ずつ順番に聞く : a人目の証言 if f: for b in range(A[a]): #b個目の証言 if bit[a] == 1: #この人が正直者なとき if lst[a][b][1] != bit[lst[a][b][0]-1]: #正直者の証言と現実が食い違う f = False break else: #正直者ではないとき break if f: ans = max(ans, sum(bit)) print(ans)
0
null
93,670,355,010,548
213
262
for i in range(10000): x = input() x = int(x) if x == 0: break else: print("Case "+ str(i+1) + ": " + str(x))
count = 0 while True: count += 1 num = int(input()) if num == 0: break print("Case", str(count) + ":", num)
1
488,353,862,500
null
42
42
x,k,d = list(map(int, input().split())) x = abs(x) a,b = divmod(x, d) a = min(a, k) x -= a * d #print('a=',a) #print('x=',x) #print('ka=',k-a) x -= d * ((k-a) % 2) print(abs(x))
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) from bisect import bisect_left from itertools import product def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI_(): return list(map(lambda x: int(x)-1, input().split())) def LF(): return list(map(float, input().split())) def LC(): return [c for c in input().split()] def LLI(n): return [LI() for _ in range(n)] def NSTR(n): return [input() for _ in range(n)] def array2d(N, M, initial=0): return [[initial]*M for _ in range(N)] def copy2d(orig, N, M): ret = array2d(N, M) for i in range(N): for j in range(M): ret[i][j] = orig[i][j] return ret INF = float("inf") MOD = 10**9 + 7 def main(): X, K, D = MAP() # 到達候補は0に近い正と負の二つの数 d, m = divmod(X, D) cand = (m, m-D) if X >= 0: if K <= d: print(X-K*D) return else: rest = (K-d) if rest % 2 == 0: print(cand[0]) return else: print(-cand[1]) return else: if K <= -d-1: print(abs(X+K*D)) return else: rest = K-(-d-1) if rest % 2 == 0: print(-cand[1]) return else: print(cand[0]) return return if __name__ == '__main__': main()
1
5,243,091,575,348
null
92
92
K = int(input()) s = input() n=len(s) def find_power(n,mod=10**9+7): powlist=[0]*(n+1) powlist[0]=1 powlist[1]=1 for i in range(2,n+1): powlist[i]=powlist[i-1]*i%(mod) return powlist def find_inv_power(n,mod=10**9+7): powlist=find_power(n) check=powlist[-1] first=1 uselist=[0]*(n+1) secondlist=[0]*30 secondlist[0]=check secondlist[1]=check**2 for i in range(28): secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7) a=format(10**9+5,"b") for j in range(30): if a[29-j]=="1": first=(first*secondlist[j])%(10**9+7) uselist[n]=first for i in range(n,0,-1): uselist[i-1]=(uselist[i]*i)%(10**9+7) return uselist mod = 10**9+7 NUM = (2*10**6)+100 p_lis=find_power(NUM,mod) ip_lis=find_inv_power(NUM,mod) def comb(n,r,mod=10**9+7): if n<r: return 0 elif n>=r: return (p_lis[n]*ip_lis[r]*ip_lis[n-r])%(mod) ans=0 for k in range(K+1): ans+=(comb(n-1+K-k,n-1)* pow(25,K-k,mod)* pow(26,k,mod)) print(ans%mod)
MAX = 10**6 * 3 MOD = 10**9+7 fac = [0] * MAX finv = [0] * MAX inv = [0] * MAX #前処理 逆元テーブルを作る def COMinit(): fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fac[i] = fac[i-1] * i % MOD inv[i] = MOD - inv[MOD%i] * (MOD//i)%MOD finv[i] = finv[i-1] * inv[i] % MOD #実行 def COM(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD k = int(input()) s = input() n = len(s) COMinit() ans = 0 for i in range(k+1): pls = pow(25, i, MOD) pls *= pow(26,k-i, MOD) pls %= MOD pls *= COM(i+n-1, i) ans += pls ans %= MOD print(ans%MOD)
1
12,765,362,188,682
null
124
124
n = int(input()) ab=[list(map(int,input().split())) for i in range(n)] import math from collections import defaultdict d = defaultdict(int) zerozero=0 azero=0 bzero=0 for tmp in ab: a,b=tmp if a==0 and b==0: zerozero+=1 continue if a==0: azero+=1 continue if b==0: bzero+=1 continue absa=abs(a) absb=abs(b) gcd = math.gcd(absa,absb) absa//=gcd absb//=gcd if a*b >0: d[(absa,absb)]+=1 else: d[(absa,-absb)]+=1 found = defaultdict(int) d[(0,1)]=azero d[(1,0)]=bzero ans=1 mod=1000000007 for k in list(d.keys()): num = d[k] a,b=k if b>0: bad_ab = (b,-a) else: bad_ab = (-b,a) if found[k]!=0: continue found[bad_ab] = 1 bm=d[bad_ab] if bm == 0: mul = pow(2,num,mod) if k==bad_ab: mul = num+1 else: mul = pow(2,num,mod) + pow(2,bm,mod) -1 ans*=mul ans+=zerozero ans-=1 print(ans%mod)
from collections import defaultdict from itertools import groupby, accumulate, product, permutations, combinations from math import gcd def reduction(x,y): g = gcd(x,y) return abs(x)//g,abs(y)//g def solve(): mod = 10**9+7 dplus = defaultdict(lambda: 0) dminus = defaultdict(lambda: 0) N = int(input()) x0,y0,xy0 = 0,0,0 for i in range(N): x,y = map(int, input().split()) if x==0 and y==0: xy0 += 1 elif x==0 and y!=0: x0 += 1 elif y==0: y0 += 1 elif x*y>0: dplus[reduction(x,y)] += 1 else: dminus[reduction(-y,x)] += 1 ans = pow(2,x0,mod)+pow(2,y0,mod)-1 other = N-x0-y0-xy0 for k,v in dplus.items(): ans *= pow(2,dminus[k],mod)+pow(2,v,mod)-1 other -= dminus[k]+v ans *= pow(2,other,mod) ans += xy0-1 ans %= mod return ans print(solve())
1
21,019,984,549,188
null
146
146
N = int(input()) from functools import reduce import math sum=0 for i in range(1,N+1): for j in range(1,N+1): a = math.gcd(i,j) for k in range(1,N+1): sum+=math.gcd(a,k) print(sum)
X, Y = map(int, input().split()) if X>=2*Y: print(X-2*Y) else: print(0)
0
null
100,857,724,497,660
174
291
N,A,B = map(int,input().split()) if (B-A)%2 == 0: print((B-A)//2) else: s = (A-1) + (B-A+1)//2 ss = (N-B) + (B-A+1)//2 print(min(s,ss))
n, a, b = map(int, input().split()) ans = 0 if (b - a) % 2 == 0: ans = (b - a) // 2 else: # ans += (b - a) // 2 # a += ans # b -= ans # ans += min(n - a, b - 1) if a - 1 <= n - b: ans += a b -= a a = 1 else: ans += n - b + 1 a += n - b + 1 b = n ans += (b - a) // 2 print(ans)
1
109,169,036,629,620
null
253
253
N = int(input()) def calc(start, end): n = end // start return (n * (n+1) // 2) * start ans = 0 for i in range(1, N+1): ans += calc(i, N//i * i) print(ans)
n=int(input()) a=list(map(int,input().split())) b=[] for i in range(n): tmp=[i+1,a[i]] b.append(tmp) b=sorted(b,key=lambda x:x[1]) ans=[] for j in b: ans.append(j[0]) print(*ans)
0
null
95,596,362,800,160
118
299
num = int(input()) k = input().split() for i in range(len(k)): k[i] = int(k[i]) k.sort() mul = 1 for i in range(num): mul *= int(k[i]) if mul > 10**18: break if mul > 10**18: print(-1) else: print(mul)
def insertionSort(A, n, g): cnt_local = 0 for i in range(g, n): v = A[i] j = i - g while (j >= 0 and A[j] > v): A[j+g] = A[j] j = j - g cnt_local += 1 A[j+g] = v return cnt_local cnt_all = 0 n = int(input()) A = [] for _ in range(n): A.append(int(input())) G = [int((3**i-1)/2)for i in range(17,0,-1)] G = [v for v in G if v <= n] m = len(G) for i in range(m): cnt_all += insertionSort(A, n, G[i]) print(m) print(*G) print(cnt_all) print(*A, sep='\n')
0
null
8,042,016,140,190
134
17
n,m,k=map(int,input().split()) g=998244353 r=1 p=pow(m-1,n-1,g) for i in range(1,k+1): r=(r*(n-i)*pow(i,g-2,g))%g p=(p+r*pow(m-1,n-1-i,g))%g print((m*p)%g)
#入力部 C= 998244353 N,M,K=map(int,input().split()) #定義部 U=max(N+1,K) F=[0]*U G=[0]*U F[0]=1 for i in range(1,U): F[i]=(F[i-1]*i)%C G[i]=pow(F[-1],C-2,C) for j in range(U-2,-1,-1): G[j]=(G[j+1]*(j+1))%C def nCr(n,r): if r<0 or n<r: return 0 else: return (F[n]*G[r]*G[n-r]) #メイン部 S=0 for k in range(0,K+1): S=(S+M*pow(M-1,N-k-1,C)*nCr(N-1,k))%C print(S%C)
1
23,167,784,437,382
null
151
151
s = list(input()) ans = [] for c in s: if c.islower(): ans.append(c.upper()) elif c.isupper(): ans.append(c.lower()) else: ans.append(c) print("".join(ans))
string = input() for s in string: if s.isupper(): print(s.lower(), end='') else: print(s.upper(), end='') print('')
1
1,499,709,245,860
null
61
61
# imos解 n,d,a=map(int,input().split()) xh=[] for i in range(n): xx,hh=map(int,input().split()) xh.append([xx,hh]) xh.sort(key=lambda x:x[0]) xl=[x for x,h in xh] # print(xh) from math import ceil from bisect import bisect_right ans=0 damage=[0]*(n+1) for i in range(n): x,h=xh[i] if damage[i]<h: need=ceil((h-damage[i])/a) right=x+2*d # 爆発に巻き込まれる範囲の右端のindexを取得する r_idx=bisect_right(xl,right) # imosしながら爆発させる damage[i]+=need*a damage[r_idx]-=need*a ans+=need # imosの累積和を取る damage[i+1]+=damage[i] print(ans)
from collections import deque from math import ceil n,d,a = map(int,input().split()) M = [list(map(int,input().split())) for i in range(n)] M = sorted([(x,ceil(h/a)) for x,h in M]) que = deque() ans = 0 atack = 0 for x,h in M: while len(que) > 0 and que[0][0] < x: tx,ta = que.popleft() atack -= ta bomb_num = max(0, h-atack) atack += bomb_num ans += bomb_num if bomb_num > 0: que.append([x+d*2,bomb_num]) print(ans)
1
82,327,449,188,608
null
230
230
# -*- coding: utf-8 -*- import sys def top_k_sort(data, k=3, reverse=True): data.sort(reverse=True) return data[:k] def main(): data = [] for line in sys.stdin: data.append(int(line)) for h in top_k_sort(data): print(h) if __name__ == '__main__': main()
import sys height_li = [] for i in range(10): height_li.append(int(input())) for i in range(3): print(sorted(height_li,reverse=True)[i])
1
16,785,930
null
2
2
a,b=map(int,input().split()) def gcd(x, y): while y: x, y = y, x % y return x l=gcd(a,b) print(int(a*b/l))
N = int(input()) A = list(map(int,input().split())) for a in A: if a%2==0 and a%3!=0 and a%5!=0: print("DENIED") exit() print("APPROVED")
0
null
91,124,951,254,652
256
217
s=input().lower() cnt=0 while True: l=input().split() if l[0]=='END_OF_TEXT': break for i in range(len(l)): lg=len(l[i])-1 if not l[i][lg].isalpha(): l[i]=l[i][:lg] cnt+=(s==l[i].lower()) print(cnt)
w = raw_input() words = [] while True: line = raw_input() if line == "END_OF_TEXT": break else: line_list = line.split(" ") words += line_list #print words cnt = 0 for word in words: if w.lower() == word.lower(): cnt += 1 print cnt
1
1,840,676,822,428
null
65
65
a,b,c =map(int, input().split()) if a<b and b<c: print(a,b,c) elif a>b: if b>=c: a,c = c,a print(a,b,c) else: a,b = b,a b,c = c,b print(a,b,c) else: if a>c: a,b = b,a a,c = c,a print(a,b,c) else: b,c = c,b print(a,b,c)
nums = map(int, raw_input().split()) for i in range(2): for j in range(2-i): if nums[j] > nums[j+1]: temp = nums[j] nums[j] = nums[j+1] nums[j+1] = temp print(str(nums[0]) + " " + str(nums[1]) + " " + str(nums[2]))
1
417,800,187,364
null
40
40
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): A, B = map(int, readline().split()) print(max(A - 2 * B, 0)) if __name__ == '__main__': main()
from collections import deque n , k = map(int,input().split()) a = list(map(int,input().split())) mod = 10**9 + 7 ans = 1 plus = [] minus = [] if n == k: for i in range(n): ans *= a[i] ans %= mod print(ans) exit() for i in range(n): if a[i] >= 0: plus.append(a[i]) elif a[i] < 0: minus.append(a[i]) if not plus and k % 2 == 1: minus.sort(reverse=True) for i in range(k): ans *= minus[i] ans %= mod print(ans) exit() plus.sort(reverse=True) minus.sort() plus = deque(plus) minus = deque(minus) cou = [] while True: if len(cou) == k: break elif len(cou) == k-1: cou.append(plus.popleft()) break else: if len(plus)>=2 and len(minus)>=2: p1 = plus.popleft() p2 = plus.popleft() m1 = minus.popleft() m2 = minus.popleft() if p1*p2 > m1*m2: cou.append(p1) plus.appendleft(p2) minus.appendleft(m2) minus.appendleft(m1) else: cou.append(m1) cou.append(m2) plus.appendleft(p2) plus.appendleft(p1) elif len(plus) < 2: m1 = minus.popleft() m2 = minus.popleft() cou.append(m1) cou.append(m2) elif len(minus) < 2: p1 = plus.popleft() cou.append(p1) for i in cou: ans *= i ans %= mod print(ans)
0
null
87,804,860,106,770
291
112
def resolve(): a,b = map(int, input().split()) if a*500 >= b: print("Yes") else: print("No") resolve()
base = input().split() if int(base[0])*500 >= int(base[1]): print("Yes") else: print("No")
1
97,959,572,947,320
null
244
244
# input N, M = map(int, list(input().split())) A = list(map(int, input().split())) # process A.sort(reverse=True) # 1回の握手の幸福度がx以上となるものの数、幸福度の合計を求める def calc(x): count, sum = 0, 0 j, t = 0, 0 for i in reversed(range(N)): while j < N and A[i]+A[j] >= x: t += A[j] j += 1 count += j sum += A[i]*j + t return (count, sum) # 2分探索で答えを求める def binary_search(x, y): mid = (x+y)//2 count, sum = calc(mid) if count < M: return binary_search(x, mid) else: if x == mid: print(sum-(count-M)*mid) else: return binary_search(mid, y) # 実行 binary_search(0, A[0]*2+1)
n, m = map(int, input().split()) l = list(map(int, input().split())) l.sort() import bisect def func(x): C = 0 for p in l: q = x -p j = bisect.bisect_left(l, q) C += n-j if C >= m: return True else: return False l_ = 0 r_ = 2*10**5 +1 while l_+1 < r_: c_ = (l_+r_)//2 if func(c_): l_ = c_ else: r_ = c_ ans = 0 cnt = 0 lr = sorted(l, reverse=True) from itertools import accumulate cum = [0] + list(accumulate(lr)) for i in lr: j = bisect.bisect_left(l, l_-i) ans += i*(n-j) + cum[n-j] cnt += n -j ans -= (cnt-m)*l_ print(ans)
1
107,999,384,576,720
null
252
252
n = int(input()) base = [mark + str(rank) for mark in ["S ", "H ", "C ", "D "] for rank in range(1,14)] for card in [input() for i in range(n)]: base.remove(card) for elem in base: print(elem)
ini = lambda : int(input()) inm = lambda : map(int,input().split()) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def 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) divisors.sort() return divisors #maincode------------------------------------------------- n = ini() s = input() r = s.count('R') g = s.count('G') b = s.count('B') ans = r*g*b for j in range(n): for i in range(j): k = 2*j-i if k < n: if (s[i] == s[j]): continue if (s[i] == s[k]): continue if (s[j] == s[k]): continue ans -= 1 print(ans)
0
null
18,451,452,538,642
54
175
# F - Playing Tag on Tree # https://atcoder.jp/contests/abc148/tasks/abc148_f from heapq import heappop, heappush INF = float("inf") def dijkstra(n, G, s): dist = [INF] * n dist[s] = 0 hq = [(0, s)] while hq: d, v = heappop(hq) if dist[v] < d: continue for child, child_d in G[v]: if dist[child] > dist[v] + child_d: dist[child] = dist[v] + child_d heappush(hq, (dist[child], child)) return dist n, u, v = map(int, input().split()) graph = [[] for _ in range(n)] edge = [list(map(int, input().split())) for _ in range(n - 1)] for a, b in edge: graph[a - 1].append((b - 1, 1)) graph[b - 1].append((a - 1, 1)) from_u = dijkstra(n, graph, u - 1) from_v = dijkstra(n, graph, v - 1) # print(from_u) # print(from_v) fil = filter(lambda x : x[0] < x[1], [[fu, fv] for fu, fv in zip(from_u, from_v)]) sfil = sorted(list(fil), key=lambda x: [-x[1], -x[0]]) # print(sfil) print(sfil[0][1] - 1)
import sys #f = open("test.txt", "r") f = sys.stdin num_rank = 14 s_list = [False] * num_rank h_list = [False] * num_rank c_list = [False] * num_rank d_list = [False] * num_rank n = f.readline() n = int(n) for i in range(n): [suit, num] = f.readline().split() num = int(num) if suit == "S": s_list[num] = True elif suit == "H": h_list[num] = True elif suit == "C": c_list[num] = True else: d_list[num] = True for i in range(1, num_rank): if not s_list[i]: print("S " + str(i)) for i in range(1, num_rank): if not h_list[i]: print("H " + str(i)) for i in range(1, num_rank): if not c_list[i]: print("C " + str(i)) for i in range(1, num_rank): if not d_list[i]: print("D " + str(i))
0
null
59,037,641,761,020
259
54
k, n = map(int, input().split()) a_list = list(map(int, input().split())) longest = 0 for i in range(n-1): distance = a_list[i+1] - a_list[i] longest = max(longest, distance) print(k-max(longest, k-a_list[n-1]+a_list[0]))
k, n = map(int, input().split()) A = list(map(int, input().split())) farthest = (k-A[-1])+A[0] for i in range(len(A)-1): farthest = max(farthest, A[i+1]-A[i]) print(k-farthest)
1
43,356,099,917,692
null
186
186
N = int(input()) S = list(input()) print("".join(chr(65+(ord(s)-65+N)%26) for s in S))
#!/usr/bin/env python3 import sys def solve(N: int, R: int): if N >= 10: print(R) if N < 10: print(R + 100*(10-N)) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int R = int(next(tokens)) # type: int solve(N, R) if __name__ == '__main__': main()
0
null
98,745,408,856,832
271
211
N=list(input()) n=[int(s) for s in N] if n[-1]==2 or n[-1]== 4 or n[-1]== 5 or n[-1]== 7 or n[-1]== 9: print('hon') elif n[-1]==0 or n[-1]==1 or n[-1]== 6 or n[-1]== 8: print('pon') else : print('bon')
n = int(input()) ls = [0]*n param_list = [0]*2**n for i in range(2**n): l = [False]*n for id_r, row in enumerate(ls): if i & (2 ** id_r) >0: l[id_r] = True param_list[i] = l for i in range(n): A = int(input()) for k in range(A): a,b = map(int, input().split()) b = (1==b) new_param =[] for d in param_list: if d[i]: if d[a-1] == b: new_param.append(d) pass else: #print(2) pass else: new_param.append(d) #if d[a-1] is b: #print(3) #pass #else: #print(4) #new_param.append(d) #pass param_list = new_param #print(param_list) ans = 0 for d in param_list: ans = max(ans, d.count(True)) print(ans)
0
null
70,072,846,935,520
142
262
import math n,D = map(int,input().split()) cnt = 0 for i in range(n): p,q = map(int,input().split()) d = math.sqrt(p**2 + q ** 2) if D >= d: cnt += 1 print(cnt)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): from itertools import permutations N = int(readline()) P = tuple(map(int, readline().split())) Q = tuple(map(int, readline().split())) d = {x: i for i, x in enumerate(permutations(range(1, N + 1)))} print(abs(d[Q] - d[P])) if __name__ == '__main__': main()
0
null
53,416,580,204,948
96
246
N, K = map(int, input().split()) A = [0]*(N+2) for i in range(N+1): A[i+1] += A[i] + i ans = 0 for i in range(K, N+2): minv = A[i] maxv = A[N+1]-A[N-i+1] ans += maxv-minv+1 ans %= 10**9+7 print(ans)
a = int(input()) b = input().split() c = "APPROVED" for i in range(a): if int(b[i]) % 2 == 0: if int(b[i]) % 3 == 0 or int(b[i]) % 5 == 0: c = "APPROVED" else: c = "DENIED" break print(c)
0
null
51,085,238,951,710
170
217
N=int(input()) S=input() cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B') ans=cntR*cntG*cntB for i in range(N-2): for j in range(i+1,N-1): if S[i]!=S[j]: k=2*j-i if k<N and S[k]!=S[i] and S[k]!=S[j]: ans-=1 print(ans)
def main(): n = int(input()) s = input() ans = s.count('R') * s.count('G') * s.count('B') for i in range(n-2): for j in range(i+1, n-1): if j - i > n - j - 1: break if s[i] != s[j] and s[j] != s[2*j-i] and s[2*j-i] != s[i]: ans -= 1 print(ans) if __name__ == '__main__': main()
1
35,920,065,061,912
null
175
175
n = int(input()) A = list(map(int, input().split())) T = [0]*n for a in A: T[a-1] += 1 for t in T: print(t)
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
46,054,769,372,498
169
207
from collections import Counter word = input() count = 0 while True: text = input() if text == 'END_OF_TEXT': break count += Counter(text.lower().split())[word.lower()] print(count)
str_search = input().upper() int_cnt = 0 len_search = len(str_search) while True: str_line = input() if str_line == "END_OF_TEXT": break str_line = str_line.upper() int_cnt = int_cnt + str_line.split().count(str_search) print(str(int_cnt))
1
1,820,008,039,658
null
65
65
from collections import deque N, M = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(M)] g = [set() for _ in range(N)] for a, b in AB: a, b = a-1, b-1 g[b].add(a) g[a].add(b) mark = [-1]*N mark[0] = 0 q = deque([0]) while q: t = q.popleft() for c in g[t]: if mark[c] == -1: mark[c] = t q.append(c) print("Yes") for m in mark[1:]: print(m+1)
N,M=map(int,input().split()) G=[[] for _ in range(N+1)] for i in range(M): a,b=map(int,input().split()) G[a].append(b) G[b].append(a) ans=[0]*(N+1) d=[1] while d: c=d.pop(0) for g in G[c]: if not ans[g]: d.append(g) ans[g]=c print('Yes') for i in range(2, N+1): print(ans[i])
1
20,504,578,178,272
null
145
145
S = input() print(S.replace('?', 'D'))
s = input() for i in range(len(s)): if s[i] == '?': if i == 0 and len(s) == 1: s = s.replace('?','D',1) elif i == 0 and s[1] == 'D': s = s.replace('?','P',1) elif i == 0 and s[1] == 'P': s = s.replace('?','D',1) elif i == 0 and s[1] == '?': s = s.replace('?','D',1) elif s[i-1] =='P': s = s.replace('?','D',1) elif s[i-1] =='D' and (i ==len(s)-1): s = s.replace('?','D',1) elif s[i-1] =='D' and (i <len(s)-1 and(s[i+1] == 'P' or s[i+1] == '?')): s = s.replace('?','D',1) else: s = s.replace('?','P',1) print(s)
1
18,430,901,455,410
null
140
140
import bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) N,K = LI() H = LI() Hs = np.array(sorted(H, reverse=True)) ans = np.sum(Hs[K:]) print(ans)
""" 逆元を利用し、nCrを高速で求めるクラス """ class Cmb: def __init__(self, N=10**5, mod=10**9+7): self.fact = [1,1] self.fact_inv = [1,1] self.inv = [0,1] """ 階乗を保存する配列を作成 """ for i in range(2, N+1): self.fact.append((self.fact[-1]*i) % mod) self.inv.append((-self.inv[mod%i] * (mod//i))%mod) self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod) """ 関数として使えるように、callで定義 """ def __call__(self, n, r, mod=10**9+7): if (r<0) or (n<r): return 0 r = min(r, n-r) return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod N,K = map(int,input().split()) A = list(map(int,input().split())) mod=10**9+7 A.sort() A_rev = A[::-1] f_max, f_min = 0, 0 cmb = Cmb(mod=mod) for i, num in enumerate(A): f_max += num*cmb(i, K-1) if i >= K-1 else 0 for i, num in enumerate(A_rev): f_min += num*cmb(i, K-1) if i >= K-1 else 0 print((f_max - f_min)%mod)
0
null
87,007,426,642,792
227
242
def solve(): from bisect import bisect_right, bisect, bisect_left x = int(input()) n = 100100 primes = set(range(2, n + 1)) for i in range(2, int(n ** 0.5 + 1)): if i not in primes: i += 1 else: ran = range(i * 2, n + 1, i) primes.difference_update(ran) primes = list(primes) y = bisect_left(primes, x) print(primes[y]) solve()
import sys input = sys.stdin.readline def main(): N = int(input()) R = [[] for i in range(N)] for i in range(N): A = int(input()) R[i] = [list(map(int, input().split())) for i in range(A)] ans = 0 for i in range(1<<N): CNT = 0 for j in range(N): if not (i>>j & 1): continue CNT += 1 for x, y in R[j]: if y == 1 and (i>>(x-1) & 1): continue elif y == 0 and (not (i>>(x-1) & 1)): continue else: CNT = 0 break else: continue break ans = max(ans, CNT) print(ans) if __name__ == '__main__': main()
0
null
113,521,758,238,812
250
262
N=int(input()) A=N//2+N%2 print(A)
import sys X = int(sys.stdin.readline()) a = X // 500 b = (X - a * 500) // 5 print(a * 1000 + b * 5)
0
null
50,738,638,818,360
206
185
x = input().strip() if x[-1] == 's': x += "es" else: x += 's' print(x)
s = list(input()) if s[-1] == 's': s.append('es') else: s.append('s') print(''.join(s))
1
2,345,146,290,660
null
71
71
from itertools import accumulate def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) for _ in range(K): arr = [0]*(N+1) for i, a in enumerate(A): left = max(0, i-a) right = min(N, i+a+1) arr[left] += 1 arr[right] -= 1 A = list(accumulate(arr[:-1])) if all(a == N for a in A): break print(*A, sep=" ") if __name__ == "__main__": main()
import sys sys.setrecursionlimit(1000000000) import math from math import gcd def lcm(a, b): return a * b // gcd(a, b) from itertools import count, permutations, chain, accumulate from functools import lru_cache from collections import deque, defaultdict from pprint import pprint ii = lambda: int(input()) mis = lambda: map(int, input().split()) lmis = lambda: list(mis()) INF = float('inf') N1097 = 10**9 + 7 def meg(f, ok, ng): while abs(ok-ng)>1: mid = (ok+ng)//2 if f(mid): ok=mid else: ng=mid return ok def get_inv(n, modp): return pow(n, modp-2, modp) def factorials_list(n, modp): # 10**6 fs = [1] for i in range(1, n+1): fs.append(fs[-1] * i % modp) return fs def invs_list(n, fs, modp): # 10**6 invs = [get_inv(fs[-1], modp)] for i in range(n, 1-1, -1): invs.append(invs[-1] * i % modp) invs.reverse() return invs def comb(n, k, modp): num = 1 for i in range(n, n-k, -1): num = num * i % modp den = 1 for i in range(2, k+1): den = den * i % modp return num * get_inv(den, modp) % modp def comb_from_list(n, k, modp, fs, invs): return fs[n] * invs[n-k] * invs[k] % modp # class UnionFindEx: def __init__(self, size): #正なら根の番号、負ならグループサイズ self.roots = [-1] * size def getRootID(self, i): r = self.roots[i] if r < 0: #負なら根 return i else: r = self.getRootID(r) self.roots[i] = r return r def getGroupSize(self, i): return -self.roots[self.getRootID(i)] def connect(self, i, j): r1, r2 = self.getRootID(i), self.getRootID(j) if r1 == r2: return False if self.getGroupSize(r1) < self.getGroupSize(r2): r1, r2 = r2, r1 self.roots[r1] += self.roots[r2] #サイズ更新 self.roots[r2] = r1 return True Yes = 'Yes' No = 'No' def main(): N,K = mis() A = lmis() for _ in range(K): l = [0]*(N+1) for i in range(N): a = A[i] l[max(0, i-a)] += 1 l[min(N, i+a+1)] -= 1 A = list(accumulate(l))[:-1] if all(a==N for a in A): break print(*A) main()
1
15,473,609,155,268
null
132
132
n,m = map(int,input().split()) tbl=[[] for i in range(n)] for i in range(n): tbl[i] = list(map(int,input().split())) tbl2=[[]*1 for i in range(m)] for i in range(m): tbl2[i] = int(input()) for k in range(n): x=0 for l in range(m): x +=tbl[k][l]*tbl2[l] print("%d"%(x))
n, m = map(int, input().split()) A = [[int(e) for e in input().split()] for i in range(n)] b = [] for i in range(m): e = int(input()) b.append(e) for i in range(n): p = 0 for j in range(m): p += A[i][j] * b[j] print(p)
1
1,180,363,939,848
null
56
56
n=int(input()) L=list(map(int,input().split())) if L.count(0)!=0: print(0) else: L_1=sorted(L) x=1 for i in range(n): x*=L_1[i] if x>10**18: x=-1 break print(x)
import numpy as np N = int(input()) max_z = -np.Inf min_z = np.inf max_w = -np.Inf min_w = np.inf for _ in range(N): x, y = map(int, input().split()) z = x + y w = x - y max_z = max(max_z, z) min_z = min(min_z, z) max_w = max(max_w, w) min_w = min(min_w, w) print(max(max_z-min_z, max_w-min_w))
0
null
9,797,112,448,000
134
80
def main(): x = int(input()) for i in range(-118, 120): for j in range(-119, 119): if i**5 - j**5 == x: print(i, j) exit() if __name__ == '__main__': main()
import math X= int(input()) for A in range(-120,121): for B in range(-120,A+1): if A**5-B**5 == X: print(A,B) exit()
1
25,430,841,196,232
null
156
156
def solve(): A,B = input().split() A = int(A) B = int(''.join(B.split('.'))) print(A*B//100) if __name__ == "__main__": solve()
N = int(input()) A = list(map(int, input().split())) A = sorted(A) result=1 max=10**18 for a in A: result *= a if result>max: print(-1) break else: print(result)
0
null
16,503,599,589,460
135
134
s = input() if s[0]==s[1]: print("No") elif s[2] != s[3]: print("No") elif s[4] != s[5]: print("No") else: print("Yes")
n=int(input()) a=[0]*n a=list(map(int,input().split())) left=a[0] right=sum(a[1::]) t=abs(right-left) for i in range(1,n): left+=a[i] right-=a[i] t=min(t,abs(right-left)) print(t)
0
null
91,800,710,958,880
184
276
import collections li = list(map(int,input().split())) c = collections.Counter(li) if len(c) == 2: print('Yes') else: print('No')
def main(): n, m = map(int, input().split()) # マイナスの場合は leader であり、同時にサイズ(*-1)を保持する uf = [-1] * (n+1) def uf_leader(a): if uf[a]<0: return a uf[a] = uf_leader(uf[a]) return uf[a] def uf_unite(a, b): ua, ub = uf_leader(a), uf_leader(b) if ua==ub: return False if uf[ua] > uf[ub]: ua, ub = ub, ua uf[ua] += uf[ub] uf[ub] = ua return True def uf_leaders(): return [v for v in range(1,n+1) if uf[v]<0] # print(uf[1:]) for _ in range(m): a, b = map(int, input().split()) uf_unite(a, b) # print(uf[1:]) # print(uf_leaders()) ans = len(uf_leaders())-1 print(ans) main()
0
null
35,066,038,898,368
216
70
n = int(input()) l = list(map(int, input().split())) ans = 0 for i in range(n): for j in range(i+1, n): for k in range(j+1, n): _lst = [l[i], l[j], l[k]] if len(set(_lst)) == 3: _max = max(_lst) _lst.remove(_max) if _max < sum(_lst): ans += 1 print(ans)
# string # a, b, c = input().split() # str_list = list(input().split()) # number # a, b, c = map(int, input().split()) # num_list = list(map(int, input().split())) # lows # str_list = [input() for _ in range(n)] # many inputs # num_list = [] # for i in range(n): num_list.append(list(map(int, input().split()))) n = int(input()) l = list(map(int, input().split())) l.sort(reverse = True) ctr = 0 for i in range(n-2): for j in range(i+1, n-1): if l[i] == l[j]: continue for k in range(j+1, n): if l[j] == l[k]: continue if l[i] < l[j] + l[k]: ctr += 1 print(ctr)
1
5,044,335,313,912
null
91
91
MOD = 10 ** 9 + 7 INF = 10 ** 10 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) def main(): n,k,c = map(int,input().split()) s = input() R = [-1] * k L = [-1] * k day = INF cnt = 0 for i in range(n): if s[i] == 'o': if day > c: L[cnt] = i cnt += 1 if cnt == k: break day = 1 else: day += 1 else: day += 1 day = INF cnt = k - 1 for i in range(n - 1,-1,-1): if s[i] == 'o': if day > c: R[cnt] = i cnt -= 1 if cnt < 0: break day = 1 else: day += 1 else: day += 1 ans = [] for j in range(k): if R[j] == L[j]: ans.append(R[j] + 1) print(*ans,sep = '\n') if __name__ =='__main__': main()
n, k, c = map(int, input().split()) s = input() left = [] i = 0 while len(left) < k: if s[i] == 'o': left.append(i) i += c + 1 else: i += 1 right = [] i = n - 1 while len(right) < k: if s[i] == 'o': right.append(i) i -= c + 1 else: i -= 1 right = right[::-1] for i in range(k): if left[i] == right[i]: print(left[i] + 1)
1
40,822,711,513,850
null
182
182
n,k= map(int, input().split()) p= list(map(int, input().split())) c= list(map(int, input().split())) ans=-float('inf') x=[0]*n for i in range(n): if x[i]==0: x[i]=1 y=p[i]-1 # 累積和を格納 aa=[0,c[i]] # 2周させる life=2 for j in range(2*n+2): x[y]=1 if life>0: aa.append(aa[-1]+c[y]) y=p[y]-1 if y==i: life-=1 else: break # 各回数での取れるスコアの最大値 x1=(len(aa)-1)//2 a=[-float('inf')]*(x1+1) for ii in range(len(aa)-1): for j in range(ii+1,len(aa)): if j-ii<=x1: a[j - ii] = max(a[j - ii], aa[j] - aa[ii]) v=k//x1 w=k%x1 if v==0: ans=max(ans,max(a[:k+1])) elif v==1: ans = max(ans, max(a), v * aa[x1] + max(a[:w + 1])) else: ans=max(ans,max(a),v * aa[x1] + max(a[:w + 1]),(v-1)*aa[x1]+max(a)) print(ans)
import math a, b, c = map(int, input().split()) PI = 3.1415926535897932384 c = math.radians(c) print('{:.5f}'.format(a * b * math.sin(c) / 2)) A = a - b * math.cos(c) B = b * math.sin(c) print('{:.5f}'.format(math.sqrt(A * A + B * B) + a + b)) print('{:.5f}'.format(B))
0
null
2,743,134,842,114
93
30
N=int(input()) S=[int(s) for s in input().split()] for i in range(N): if S[i]%2==0 and S[i]%5!=0 and S[i]%3!=0: print("DENIED") break elif i==N-1: print("APPROVED")
MM = int(input()) AA = input().split() count = 0 for j in AA: i = int(j) if i%2 ==0: if i%3 !=0 and i%5 !=0: count +=1 if count == 0: print('APPROVED') else: print('DENIED')
1
69,282,388,105,370
null
217
217
from scipy.special import comb n, k = map(int, input().split()) num, ans = 0, 0 for i in range(n+1): num += n-2*i if i >= k-1: ans += num+1 ans = ans%(10**9+7) print(ans)
N, K = map(int, input().split()) MOD = 10 ** 9 + 7 ans = 1 for i in range(K, N + 1): ans += i * (2 * N - i + 1) // 2 % MOD - i * (i - 1) // 2 % MOD + 1 ans %= MOD print(ans)
1
33,020,879,388,640
null
170
170
n, m = map(int, input().split()) a = list(map(int, input().split())) num = sum(a) cnt = 0 for i in range(n): if a[i] < num/(4*m): continue else: cnt += 1 if cnt >= m: print("Yes") else: print("No")
N, M = map(int, input().split()) A = list(map(int, input().split())) cnt = 0 th = sum(A)/(4*M) for i in range(len(A)): if A[i] >= th: cnt += 1 ans = 'Yes' if cnt >= M else 'No' print(ans)
1
38,703,375,008,030
null
179
179
from itertools import groupby, accumulate, product, permutations, combinations h,w,k = map(int, input().split()) l = [input() for i in range(h)] ans = 0 for i in product([0,1],repeat=h): for j in product([0,1],repeat=w): Ans = 0 for m in range(h): for n in range(w): if l[m][n] == '#' and i[m] == 1 and j[n] == 1: Ans += 1 if Ans == k: ans +=1 print(ans)
def cardgame(animal1, animal2, taro, hanako): if animal1==animal2: return [taro+1, hanako+1] anim_list = sorted([animal1, animal2]) if anim_list[0]==animal1: return [taro, hanako+3] else: return [taro+3, hanako] n = int(input()) taro, hanako = 0, 0 for i in range(n): data = input().split() result = cardgame(data[0], data[1], taro, hanako) taro, hanako = result[0], result[1] print(taro, end=" ") print(hanako)
0
null
5,484,297,214,010
110
67
n,r=map(int,input().split()) if n>=10:print(r) else:print(r+100*(10-n))
from fractions import gcd a, b = map(int, raw_input().split()) print gcd(a, b)
0
null
31,534,579,134,730
211
11
n = int(raw_input()) S = [] S = map(int, raw_input().split()) q = int(raw_input()) T = [] T = map(int, raw_input().split()) count = 0 for i in T: if i in S: count += 1 print count
print(int((int(input())+1)/2))
0
null
29,719,459,619,826
22
206