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
# 7 from collections import Counter import collections import sys def input(): return sys.stdin.readline().strip() def I(): return int(input()) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return input() def LS(): return input().split() INF = float('inf') n = I() d = LI() mod = 998244353 if d[0] != 0: print(0) exit(0) # 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると # d_pi = d_i - 1 となる # 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める c = Counter(d) counts = [0] * (max(d)+1) for k, v in c.items(): counts[k] = v if counts[0] > 1: print(0) exit(0) ans = 1 for i in range(1, len(counts)): ans *= pow(counts[i-1], counts[i]) ans %= mod print(ans)
from collections import defaultdict import sys MOD=998244353 N=int(input()) dlist=list(map(int,input().split())) if dlist[0]!=0: print(0) sys.exit(0) ddic=defaultdict(int) for d in dlist: ddic[d]+=1 if ddic[0]!=1: print(0) sys.exit(0) max_d=max(dlist) answer=1 for d in range(1,max_d+1): if ddic[d]==0: print(0) sys.exit(0) term=pow(ddic[d-1],ddic[d],MOD) answer*=term answer%=MOD print(answer)
1
154,481,807,044,150
null
284
284
n = int(input()) XY = [[] for _ in range(n)] ans = 0 for i in range(n): a = int(input()) for _ in range(a): x, y = map(int, input().split()) XY[i].append((x-1, y)) for i in range(2**n): correct = [False]*n tmp_cnt = 0 flag = True for j in range(n): if i&(1<<j): correct[j] = True tmp_cnt += 1 for j in range(n): if correct[j]: for x, y in XY[j]: if (y==0 and correct[x]) or (y==1 and not correct[x]): flag = False if flag: ans = max(tmp_cnt, ans) print(ans)
a = int(input()) s = a*a c = a*a*a t = a+s+c print(int(t))
0
null
65,779,207,170,612
262
115
# Date [ 2020-08-29 21:59:01 ] # Problem [ e.py ] # Author Koki_tkg # After Contest import sys import math # import bisect # import numpy as np # from decimal import Decimal # from numba import njit, i8, u1, b1 #JIT compiler # from itertools import combinations, product # 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(): return map(int, sys.stdin.readline().strip().split()) def read_ints2(x): 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 GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b) def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b) # osa_k 法 O(NloglogN + logA) class PrimeFactorization(): def __init__(self, num): self.num = num self.factor_table = [0] * (num + 1) self.eratosthenes() def eratosthenes(self): for i in range(2, self.num + 1): if self.factor_table[i] == 0: self.factor_table[i] = i for j in range(i * i, self.num + 1, i): if self.factor_table[j] == 0: self.factor_table[j] = i def factorization(self, a): now = a ret = [] while now > 1: cnt = 0 prime = self.factor_table[now] while now % prime == 0: cnt += 1 now //= prime ret.append((prime, cnt)) return ret def Main(): n = read_int() a = read_int_list() max_num = max(a) pf = PrimeFactorization(max_num + 1) used_prime = [False] * (max_num + 1) for x in a: factor = pf.factorization(x) for prime, cnt in factor: if used_prime[prime]: break used_prime[prime] = True else: continue break else: print('pairwise coprime') exit() gcd_num = a[0] for x in a[1:]: gcd_num = math.gcd(gcd_num, x) print('setwise coprime' if gcd_num == 1 else 'not coprime') if __name__ == '__main__': Main()
# -*- coding: utf-8 -*- def main(): from math import gcd import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) max_a = 10 ** 6 numbers = [0 for _ in range(max_a + 1)] # KeyInsight: # 調和級数: 計算量 O(AlogA) # ◯: 素因数分解をすればよいことには気がつけた。 # △: 4ケースWA・TLEが取れず for ai in a: numbers[ai] += 1 is_pairwise = True # 素因数の判定 # 素因数の倍数の要素を数えている for i in range(2, max_a + 1): count = 0 for j in range(i, max_a + 1, i): count += numbers[j] # 2つ以上ある数の倍数があった場合は、少なくともpairwiseではない if count > 1: is_pairwise = False if is_pairwise: print("pairwise coprime") exit() value_gcd = 0 # 全ての要素のGCDが1かどうかを判定 for i in range(n): value_gcd = gcd(value_gcd, a[i]) if value_gcd == 1: print("setwise coprime") exit() print("not coprime") if __name__ == '__main__': main()
1
4,050,975,572,070
null
85
85
A, B, K = list(map(int, input().split())) if A <= K: K = K - A A = 0 if B <= K: K = K - B B = 0 else: B = B - K else: A = A - K print(str(A) + ' ' + str(B))
h,w,k = map(int, input().split()) s = [list(map(str,list(input()))) for i in range(h)] ans =0 for ii in range(1<<h): for jj in range(1<<w): cnt = 0 for i in range(h): for j in range(w): if (ii >> i & 1): continue if (jj >> j & 1): continue if (s[i][j] == '#'): cnt += 1 if cnt == k: ans += 1 print(ans)
0
null
56,577,370,344,352
249
110
n, d, a = map(int, input().split()) D = True pos = [] pos1 = [] for i in range(n): x, h = map(int, input().split()) pos.append((x, h)) pos.sort(key=lambda x: x[0]) bombs = 0 damage = 0 y, z = 0, 0 while y < n: x0 = pos[y][0] try: x1 = pos1[z][0] except IndexError: x1 = 1e16 if x0 <= x1: health = pos[y][1] health -= damage number = max(0, (health-1) // a + 1) bombs += number damage += number*a pos1.append((x0+2*d, number*a)) y+=1 else: damage -= pos1[z][1] z += 1 print(bombs)
# coding: utf-8 import sys from collections import deque readline = sys.stdin.readline sr = lambda: readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # 左からgreedyに N, D, A = lr() monsters = [] for _ in range(N): x, h = lr() monsters.append((x, h)) monsters.sort() bomb = deque() answer = 0 attack = 0 for x, h in monsters: while bomb: if bomb[0][0] + D < x: attack -= bomb[0][1] bomb.popleft() else: break h -= attack if h > 0: t = -(-h//A) answer += t bomb.append((x + D, A * t)) attack += A * t print(answer)
1
81,956,226,671,904
null
230
230
import sys def input(): return sys.stdin.readline().strip() def resolve(): x,y=map(int, input().split()) ans=0 if x==3: ans+=100000 elif x==2: ans+=200000 elif x==1: ans+=300000 if y==3: ans+=100000 elif y==2: ans+=200000 elif y==1: ans+=300000 if x==1 and y==1: ans+=400000 print(ans) resolve()
a,b=map(int,input().split()) dic={1:3*10**5,2:2*10**5,3:1*10**5} c=0 if a in dic and b in dic: if a==1 and b==1: c+=dic[a]+dic[b]+4*10**5 print(c) else: c+=dic[a]+dic[b] print(c) elif a in dic and b not in dic: c+=dic[a] print(c) elif b in dic and a not in dic: c+=dic[b] print(c) else: print(c)
1
140,098,472,240,980
null
275
275
import math def koch(n, a, b): if n == 0: return s, t, u = [0, 0], [0, 0], [0, 0]; th = math.pi * 60.0 / 180.0; s[0] = (2.0 * a[0] + 1.0 * b[0]) / 3.0 s[1] = (2.0 * a[1] + 1.0 * b[1]) / 3.0 t[0] = (1.0 * a[0] + 2.0 * b[0]) / 3.0 t[1] = (1.0 * a[1] + 2.0 * b[1]) / 3.0 u[0] = (t[0] - s[0]) * math.cos(th) - (t[1] - s[1]) * math.sin(th) + s[0] u[1] = (t[0] - s[0]) * math.sin(th) + (t[1] - s[1]) * math.cos(th) + s[1] koch(n - 1, a, s) print "%.8f %.8f" % (s[0], s[1]) koch(n - 1, s, u); print "%.8f %.8f" % (u[0], u[1]) koch(n - 1, u, t) print "%.8f %.8f" % (t[0], t[1]) koch(n - 1, t, b); def main(): a, b = [0, 0], [0, 0] n = int(raw_input()) a[0], a[1] = 0, 0 b[0], b[1] = 100, 0; print "%.8f %.8f" % (a[0], a[1]) koch(n, a, b); print "%.8f %.8f" % (b[0], b[1]) main()
A = [list(map(int, input().split())) for _ in range(3)] N = int(input()) B = [int(input()) for _ in range(N)] a = [] Atf = [[False] * 3 for _ in range(3)] for i in range(3): for aa in A[i]: a.append(aa) for b in B: if b in a: for i in range(3): for j in range(3): if A[i][j] == b: Atf[i][j] = True res = False for i in range(3): if Atf[i][0] and Atf[i][1] and Atf[i][2]: res = True break elif Atf[0][i] and Atf[1][i] and Atf[2][i]: res = True break if not res: if Atf[0][0] and Atf[1][1] and Atf[2][2]: res = True elif Atf[0][2] and Atf[1][1] and Atf[2][0]: res = True if res: print("Yes") else: print("No")
0
null
30,094,070,166,020
27
207
S = input() N = len(S) ans = [0] * (N+1) for i in range(N): if S[i] == '<': ans[i+1] = ans[i] + 1 for i in range(N-1, -1, -1): if S[i] == '>' and ans[i] <= ans[i+1]: ans[i] = ans[i+1]+1 print(sum(ans))
#!/usr/bin/env python # coding: utf-8 # In[86]: # ans = [0]*(len(S)+1) # for i in range(len(S)): # count_left = 0 # count_right = 0 # for j in range(i): # if S[i-j-1] == "<": # count_left += 1 # else: # j -= 1 # break # for k in range(i,len(S)): # if S[k] == ">": # count_right += 1 # else: # k -= 1 # break # ans[i] = max(count_left, count_right) # # print(count_left, count_right) # # print(S[i-j-1:i], S[i:k+1]) # # print(ans) # print(sum(ans)) # In[87]: from collections import deque S = input() left = deque([0]) right = deque([0]) cnt = 0 for s in S: if s == '<': cnt += 1 else: cnt = 0 left.append(cnt) cnt = 0 for s in S[::-1]: if s == '>': cnt += 1 else: cnt = 0 right.appendleft(cnt) ans = 0 for l, r in zip(left, right): ans += max(l, r) print(ans) # In[ ]:
1
156,256,809,552,000
null
285
285
import sys sys.setrecursionlimit(10**6) input = lambda: sys.stdin.readline().rstrip() inf = float("inf") # 無限 s = input() # question_count = s.count("?") # max_str = {"point":0,"str":""} # for i in range(2**question_count): # swap_str = "" # for j in range(question_count): # if ((i>>j)&1): # swap_str += "P" # else: # swap_str += "D" # check_str = str(s) # for char in range(question_count): # check_str = check_str.replace("?",swap_str[char],1) # point = 0 # point += check_str.count("D") # point += check_str.count("PD") # if max_str["point"] < point: # max_str["point"] = point # max_str["str"] = check_str # print(point,check_str) # print(max_str["str"]) print(s.replace("?","D"))
# B T = str(input()) try: for i in range(T.count("?")): index = T.index("?") if T[index - 1] == "P": T = T.replace("?","D",1) elif T[index + 1] == "D": T = T.replace("?","P",1) elif T[index + 1] == "?": T = T.replace("?","P",1) else: T = T.replace("?","D",1) print(T) except: print(T.replace("?","D"))
1
18,540,534,392,758
null
140
140
import re n = input() if len(re.findall("2|4|5|7|9", n[-1])) > 0: print("hon") elif len(re.findall("0|1|6|8", n[-1])) > 0: print("pon") else: print("bon")
print("pphbhhphph"[int(input())%10]+"on")
1
19,267,373,392,508
null
142
142
n = int(input()) a = list(map(int, input().split())) if 1 in a: num = 1 for i in range(n): if a[i] == num: a[i] = 0 num += 1 else: a[i] = 1 print(sum(a)) else: print(-1)
import sys import collections input = sys.stdin.readline MOD = 998244353 def main(): N = int(input()) D = list(map(int, input().split())) if D[0] != 0: print(0) return D.sort() Dmax = max(D) Ditems = collections.Counter(D).items() Dcount = list(zip(*Ditems)) Dset = set(Dcount[0]) if Dset != set(range(Dmax+1)): print(0) return if Dcount[1][0] != 1: print(0) return ans = 1 for i in range(2, Dmax+1): ans *= pow(Dcount[1][i-1], Dcount[1][i], MOD) ans %= MOD print(ans%MOD) if __name__ == "__main__": main()
0
null
135,109,624,943,520
257
284
N = int(input()) A = list(map(int, input().split())) l = {a: i for i, a in enumerate(A, start=1)} print(' '.join([str(l[i+1]) for i in range(N)]))
n = int(input()) a = list(map(int,input().split())) b = ['0']*n for i in range(n): m = a[i] b[m-1] = str(i+1) print(' '.join(b))
1
180,597,210,271,368
null
299
299
n = int(input()) s = input() result = 0 for i in range(1000): i = str(i).zfill(3) # print(i) # print(s.find(i[0]), s.find(i[1]), s.find(i[2])) index0 = s.find(i[0]) if -1 < index0: index1 = s.find(i[1], index0+1) if -1 < index1: index2 = s.find(i[2], index1+1) if -1 < index2: # print(i, 'あたり') result += 1 print(result)
import sys import re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() S = input() ans = 0 for i in range(1000): cnt = 0 for j in range(N): if S[j] == str(i).zfill(3)[cnt]: cnt += 1 if cnt == 3: ans += 1 break print(ans)
1
128,630,084,217,260
null
267
267
import itertools n = int(input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) t,h = 0,0 a = list(itertools.permutations(range(1,n+1))) for i,c in enumerate(a): if p == c: t = i if q == c: h = i print(abs(t-h))
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] #a = [input() for _ in range(n)] import itertools n = int(input()) p = list(map(int, input().split())) q = list(map(int, input().split())) if (p == q): print(0) exit() seq = [] for i in range(1,n+1): seq.append(i) t = list(itertools.permutations(seq)) ans = [] for i in range(len(t)): if list(t[i]) == p or list(t[i]) == q: ans.append(i) print(ans[1]-ans[0])
1
100,724,195,888,186
null
246
246
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return map(int, sys.stdin.readline().split()) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini]*i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value #from itertools import accumulate #list(accumulate(A)) S = input() N = len(S) K = ii() cnt = 0 #for i in range(1, N): i = 1 flag = 0 if S.count(S[0]) == N: print(N * K // 2) exit() while i < N: if S[i] == S[i-1]: cnt += 1 if i + 1 < N and S[i] == S[i+1]: i += 1 if i == N-1: flag = 1 i += 1 if flag and S[0] == S[-1]: cnt += 1 cnt_sub = 0 S = S[1:] + S[0] i = 1 flag = 0 while i < N: if S[i] == S[i-1]: cnt_sub += 1 if i + 1 < N and S[i] == S[i+1]: i += 1 i += 1 print(cnt + cnt_sub * (K-2) + cnt_sub - 1) else: print(cnt * K)
S = list(input()) K = int(input()) S.extend(S) prev = '' cnt = 0 for s in S: if s == prev: cnt += 1 prev = '' else: prev = s b = 0 if K % 2 == 0: b += 1 if K > 2 and S[0] == S[-1]: mae = 1 while mae < len(S) and S[mae] == S[0]: mae += 1 if mae % 2 == 1 and mae != len(S): usiro = 1 i = len(S) - 2 while S[i] == S[-1]: usiro += 1 i -= 1 if usiro % 2 == 1: b = K // 2 if K % 2 == 0: res = cnt * (K // 2) + (b - 1) else: res = cnt * (K // 2) + cnt // 2 + b print(res)
1
175,945,392,508,350
null
296
296
a, b = map(int, raw_input().split()) print "%d %d %.6f"%(a/b, a%b, a*1.0/b)
a, b = list(map(int, input().split())) d = a // b r = a % b f = float(a) / float(b) print("{0} {1} {2:.5f}".format(d, r, f))
1
593,012,245,400
null
45
45
n=int(input()) s=input() ans="" alp=[i for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"] for i in s: ind=alp.index(i) ind+=n if 25<ind: ind=ind-26 ans+=alp[ind] print(ans)
N, A, B = map(int, input().split()) if (A + B) % 2 == 0: print(B - (A + B) // 2) exit() to1 = A - 1 toN = N - B if to1 < toN: B -= to1 + 1 print(to1 + 1 + B - (1 + B) // 2) else: A += toN + 1 print(toN + 1 + N - (A + N) // 2)
0
null
122,097,730,229,240
271
253
N, M = map(int, input().split()) data = list(map(int, input().split())) if N - sum(data) >= 0: print(N-sum(data)) else: print(-1)
ret = [3,14,39,84,155,258,399,584,819,1110] s = int(input()) print(ret[s-1])
0
null
20,958,950,290,318
168
115
n = int(input()) m = range(1,n + 1) a = range(1,n + 1,2) b = len(a) / len(m) print(b)
n = int(input()) d = {} for _ in range(n): s = input() if not s in d.keys(): d[s] = 1 print(len(d))
0
null
103,289,278,906,330
297
165
user_input=input() i=len(user_input)-1 number=0 while i>=0: number+=int(user_input[i]) i=i-1 if number%9==0: print("Yes") else : print("No")
h, w, k = map(int, input().split()) s = [] for _ in range(h): s.append(input()) sum = [[0] * (w+1) for _ in range(h+1)] for i in range(h): for j in range(w): sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (1 if s[i][j] == '1' else 0) ans = h + w - 2 for ptn in range(1<<h-1): cand = 0 sep = [0] for i in range(h-1): if((ptn >> i) & 1): sep.append(i+1) cand += 1 sep.append(h) left = 0 for pos in range(w): cur = [] for i in range(len(sep)-1): cur.append(sum[sep[i+1]][pos+1] - sum[sep[i+1]][left] - sum[sep[i]][pos+1] + sum[sep[i]][left]) if max(cur) > k: if left == pos: cand = h * w break else: cand += 1 left = pos ans = cand if cand < ans else ans print(ans)
0
null
26,569,831,048,192
87
193
o = list() top = -1 for s in input().split(): if s.isdigit(): o.append(int(s)) top += 1 else: if s is "+": n = o[top]+o[top-1] o.pop(top) top-=1 o.pop(top) top-=1 o.append(n) top+=1 if s is "-": n = o[top-1] - o[top] o.pop(top) top -= 1 o.pop(top) top -= 1 o.append(n) top+=1 if s is "*": n = o[top]*o[top-1] o.pop(top) top -= 1 o.pop(top) top -= 1 o.append(n) top+=1 print(o[0])
l = input().split() stack = [] for op in l: if op.isdigit(): stack.append(int(op)) elif op == '+': stack.append(stack.pop() + stack.pop()) elif op == '-': stack.append(- stack.pop() + stack.pop()) elif op == '*': stack.append(stack.pop() * stack.pop()) print(stack[-1])
1
36,960,803,708
null
18
18
from sys import stdin, setrecursionlimit def main(): n = int(stdin.readline()) print(n // 2) if n % 2 == 0 else print((n + 1) // 2) if __name__ == "__main__": setrecursionlimit(10000) main()
def cmb(n,r,mod): if r<0 or r>n: return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]%mod k=int(input()) s=list(input()) n=len(s) mod=10**9+7 g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,2*10**6+1): g1.append((g1[-1]*i)%mod) inverse.append((-inverse[mod%i]*(mod//i))%mod) g2.append((g2[-1]*inverse[-1])%mod) pow25=[1] for i in range(n+k+1): pow25.append((pow25[-1]*25)%mod) pow26=[1] for i in range(n+k+1): pow26.append((pow26[-1]*26)%mod) ans=0 for i in range(n,n+k+1): ans+=cmb(i-1,n-1,mod)*pow25[i-n]*pow26[n+k-i] ans%=mod print(ans)
0
null
36,087,915,191,108
206
124
def prepare(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs n, k = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() MOD = 10 ** 9 + 7 facts, invs = prepare(n, MOD) ans_max = 0 for i in range(k - 1, n): ans_max += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD arr.sort(reverse=True) ans_min = 0 for i in range(k - 1, n): ans_min += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD print((ans_max - ans_min) % MOD)
H, W = map(int, input().split()) dp = [[H*W for __ in range(W)] for _ in range(H)] dh = [1, 0] dw = [0, 1] S = [] for i in range(H): s = input() S.append(s) if (S[0][0] == '#'): dp[0][0] = 1 else: dp[0][0] = 0 for i in range(H): for j in range(W): for k in range(2): nh = i + dh[k] nw = j + dw[k] if nh >= H or nw >= W: continue add = 0 if (S[nh][nw] == "#" and S[i][j] == "."): add = 1 dp[nh][nw] = min(dp[nh][nw], dp[i][j] + add) print(dp[H-1][W-1])
0
null
72,924,441,660,782
242
194
while True: x = input() if x == '0': break length = len(x) tot = 0 for i in range(length): tot += int(x[i:i + 1]) print(tot)
while True: num = raw_input() if num == "0": break output = 0 for i in num: output += int(i) print output
1
1,602,264,194,200
null
62
62
N = int(input()) c = input() len_r = 0 len_w = 0 for i in range(N): if c[i] == 'R': len_r += 1 len_w = N - len_r n_r = 0 for j in range(len_r): if c[j] == 'R': n_r += 1 ans = len_r - n_r print(ans)
# coding: utf-8 # Your code here! x1, y1, x2, y2 = map(float,input().split()) x = (x2 - x1) y = (y2 - y1) s = (x*x + y*y)**(1/2) print(s)
0
null
3,215,189,373,186
98
29
import bisect, collections, copy, heapq, itertools, math, string 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()) from collections import defaultdict from collections import deque import bisect from decimal import * def main(): a, b, c, d = MI() print(max(a * c, b * d, a * d, b * c)) if __name__ == "__main__": main()
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def nPr(n: int, r: int) -> int: return math.factorial(n) // math.factorial(n - r) def nCr(n: int, r: int) -> int: return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def solve(N: int, M: int): return (nCr(N, 2)if N > 1 else 0) + (nCr(M, 2) if M > 1 else 0) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int print(f'{solve(N, M)}') if __name__ == '__main__': main()
0
null
24,407,671,173,520
77
189
word = raw_input() text = [] while True: raw = raw_input() if raw == "END_OF_TEXT": break text += raw.lower().split() print(text.count(word)) # print(text.lower().split().count(word))
N = int(input()) D = [] for _ in range(N): D.append([int(x) for x in input().split()]) count = 0 for i in range(N): if(D[i][0] == D[i][1]): count +=1 if(count == 3): break else: count = 0 if(count == 3): print('Yes') else: print('No')
0
null
2,168,247,608,000
65
72
n,m = map(int,input().split()) a = map(int,input().split()) x = n-sum(a) if x >= 0: print(x) else: print(-1)
N, M = input().split() N = int(N) M = int(M) A = list(map(int, input().split())) LA = len(A) i = 0 SUM = 0 for i in range(LA): SUM = SUM + A[i] if SUM > N: print('-1') else: print(N - SUM)
1
32,029,068,198,144
null
168
168
import math x1, y1, x2, y2 = map(float, input().split()) x = abs(x1 - x2) y = abs(y1 - y2) ans = math.sqrt(x**2 + y**2) print('{:.5f}'.format(ans))
import math r = float(input()) a = r * r * math.pi b = r * 2 * math.pi print('{0:f} {1:f}'.format(a, b))
0
null
388,363,619,798
29
46
from decimal import Decimal X=int(input()) c =Decimal(100) C=0 while c<X: c=Decimal(c)*(Decimal(101))//Decimal(100) C+=1 print(C)
h,n=map(int,input().split()) a=[] b=[] for i in range(n): aa,bb=map(int,input().split()) a.append(aa) b.append(bb) inf=10**10 f=h+max(a)+1 dp=[f*[inf]for _ in range(n+1)] dp[0][0]=0 for i in range(1,n+1): dp[i]=dp[i-1] for j in range(f): if j+a[i-1]<f: dp[i][j+a[i-1]]=min(dp[i][j+a[i-1]],dp[i][j]+b[i-1]) for j in range(f-1,0,-1): dp[i][j-1]=min(dp[i][j-1],dp[i][j]) print(dp[-1][h])
0
null
54,200,548,150,240
159
229
def main(): k, n = map(int, input().split()) a_lst = list(map(int, input().split())) d_lst = [0 for _ in range(n)] for i in range(n - 1): d_lst[i] = a_lst[i + 1] - a_lst[i] d_lst.append(a_lst[0] + k - a_lst[n - 1]) ans = k - max(d_lst) print(ans) if __name__ == "__main__": main()
H, A = map(int,input().split()) a = int(H/A) b = H/A if a==b: print(a) else: c = a+1 print(c)
0
null
60,366,922,907,068
186
225
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): def solve(p): cur = p cnt = 1 while cur > 0: pop = f'{cur:b}'.count("1") cur = cur % pop cnt += 1 return cnt n = int(readline()) s = input() c = s.count("1") cp = c + 1 cm = c - 1 fp = 0 fm = 0 for i, x in enumerate(s[::-1]): if x == "1": if cp <= n: fp += pow(2, i, cp) fp %= cp if cm > 0: fm += pow(2, i, cm) fm %= cm for i in range(n): if s[i] == "0": a = pow(2, n - (i + 1), cp) cur = (fp + a) % cp print(solve(cur)) else: if cm > 0: a = pow(2, n - (i + 1), cm) cur = (fm - a) % cm print(solve(cur)) else: print(0) if __name__ == '__main__': main()
from functools import lru_cache def popcnt(x): return bin(x).count("1") @lru_cache(maxsize=None) def rec(n): if n == 0: return 0 else: return rec(n % popcnt(n)) + 1 n = int(input()) arr = input() ALL_ARR = int(arr, 2) # ALL_ARR mod popcnt±1を予め計算しておく cnt = popcnt(int(arr, 2)) init_big = ALL_ARR % (cnt + 1) if cnt == 1: init_small = 0 else: init_small = ALL_ARR % (cnt - 1) # 変更部分だけ調整して剰余を再計算する # 調整部分だけでも数が大きいためpowの引数modで高速化 li = [0] * n for i in range(n): if arr[i] == "0": li[i] = (init_big + pow(2, n - i - 1, cnt + 1)) % (cnt + 1) # 0除算回避のためにフラグを立てておく elif ALL_ARR - (1 << (n - i - 1)) == 0 or cnt - 1 == 0: li[i] = "flg" else: li[i] = (init_small - pow(2, n - i - 1, cnt - 1)) % (cnt - 1) ans = [] for x in li: if x == "flg": ans.append(0) else: ans.append(rec(x) + 1) print(*ans, sep="\n")
1
8,247,495,974,728
null
107
107
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n,m = inpm() way = [[] for _ in range(n+1)] for i in range(m): a,b = inpm() way[a].append(b) way[b].append(a) ans = [0 for i in range(n+1)] q = queue.Queue() q.put((1,0)) while not q.empty(): room,sign = q.get() if ans[room] != 0: continue ans[room] = sign for i in way[room]: q.put((i,room)) print('Yes') for i in range(2,n+1): print(ans[i])
import sys from collections import deque N, M = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(M): a, b = map(int, sys.stdin.readline().split()) G[a-1].append(b-1) G[b-1].append(a-1) ars = [0] * N todo = deque([0]) done = {0} while todo: p = todo.popleft() for np in G[p]: if np in done: continue todo.append(np) ars[np] = p + 1 done.add(np) if len(done) == N: print("Yes") for i in range(1, N): print(ars[i]) else: print("No")
1
20,340,715,045,920
null
145
145
n, p = map(int, input().split()) s = list(input()) ans = 0 if p == 2 or p == 5: for i in range(n): if int(s[i]) % p == 0: ans += i + 1 else: d = [0] * (n + 1) ten = 1 for i in range(n - 1, -1, -1): a = int(s[i]) * ten % p ten *= 10 ten %= p d[i - 1] = (d[i] + a) % p cnt = [0] * p for i in range(n, -1, -1): cnt[d[i]] += 1 for i in cnt: ans+=i*(i-1)/2 print(int(ans))
N,K = list(map(int,input().split())) print(min(N%K, abs((N%K)-K)))
0
null
48,731,055,396,968
205
180
import math N = int(input()) n_max = int(math.sqrt(N)) a = [] for i in range(1,n_max + 1): if N % i == 0: a.append(i) ans = 2 * N for i in a: if (i + (N // i) - 2) < ans: ans = i + (N // i) - 2 print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(read()) lim = int(n ** 0.5) fact = [1] for i in range(2, lim + 1): if (n % i == 0): fact.append(i) else: pass if (len(fact) == 1): ans = n - 1 else: tar = fact[-1] ans = tar + int(n // tar) - 2 print(ans)
1
161,064,087,181,952
null
288
288
a,b,c=map(int,input().split()) k=int(input()) while a>=b: k-=1 b*=2 if k>=0: print('Yes' if c*(2**k)>b else 'No') else: print('No')
a,b,c = map(int,input().split()) k = int(input()) for i in range(k): if b<=a: b*=2 else: c*=2 if b>a and c>b: print('Yes') else: print('No')
1
6,909,203,021,052
null
101
101
#Take input separated by space(?) h,a = map(int, input().split()) #Divide, just round off and add 1 if decimal hit = round(h//a) if h%a != 0: hit = hit + 1 print(hit)
x = input() print(0 if x == '1'else 1)
0
null
39,991,181,400,430
225
76
N = int(input()) res = 0 for j in range(1, N+1): div_num = N//j res += (div_num +1) * div_num * j // 2 print(res)
n,k,s = map(int,input().split()) x = [0]*n for i in range(k): x[i] = s if s == 1000000000: for i in range(k,n): x[i] = s-1 else: for i in range(k,n): x[i] = s+1 for i in x: print(i,end = " ")
0
null
51,201,097,523,632
118
238
import sys k = 0 while k == 0: r = raw_input() H, W = r.split() H = int(H) W = int(W) if H == 0 and W == 0: k = 1 else: for j in range(H): for i in range(W): if i == 0 or i == W-1 or j == 0 or j == H-1: sys.stdout.write("#") else: sys.stdout.write(".") print("") print("")
t = int(raw_input()) a = raw_input().split() small = int(a[0]) large = int(a[0]) total = 0 for i in a: v = int(i) if v < small: small = v if v > large: large = v total = total + v print small,large,total
0
null
772,470,845,590
50
48
from collections import defaultdict def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() n = readInt() a = readInts() sum_a = sum(a) v = sum(a)/2 ans = float("inf") t = 0 for i in range(len(a)): t+=a[i] ans = min(ans,abs(sum_a-2*t)) print(ans)
n = input() nums = [a for a in input().split()] nums.reverse() print(' '.join(nums))
0
null
71,662,087,490,720
276
53
import sys import decimal # 10進法に変換,正確な計算 def input(): return sys.stdin.readline().strip() def main(): r = int(input()) print(r**2) main()
r = int(input()) ans = int(r ** 2) print(ans)
1
145,269,664,082,998
null
278
278
n = int(input()) s = list(input()) a = [] for i in s: num = ord(i)+n if num > 90: num -= 26 a.append(chr(num)) print(''.join(a))
W = input().rstrip() lst = [] while True: line = input().rstrip() if line == "END_OF_TEXT": break lst += line.lower().split() print(lst.count(W))
0
null
68,270,225,526,610
271
65
def main(): N = int(input()) cnt = [[0] * 10 for i in range(10)] for n in range(1, N + 1): cnt[int(str(n)[0])][int(str(n)[-1])] += 1 ans = 0 for i in range(10): for j in range(10): ans += cnt[i][j] * cnt[j][i] print(ans) if __name__ == '__main__': main()
def main(): N = int(input()) dp = [[0] * 10 for _ in range(10)] for i in range(1,N+1): tmp = str(i) left = int(tmp[0]) right = int(tmp[-1]) if left == 0 or right == 0: continue dp[left][right] += 1 ans = 0 for i in range(10): for j in range(10): ans += dp[i][j] * dp[j][i] print(ans) if __name__ == "__main__": main()
1
86,679,603,263,708
null
234
234
from sys import stdin, setrecursionlimit def main(): input = stdin.buffer.readline l = int(input()) print((l / 3) ** 3) if __name__ == "__main__": setrecursionlimit(10000) main()
from decimal import Decimal l=int(input()) print(Decimal((l/3)**3))
1
46,967,165,797,560
null
191
191
import sys # sys.setrecursionlimit(100000) def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return [int(i) for i in input().split()] def main(): n = input_int() arms = [] # 区間スケジューリング for _ in range(n): x, l = input_int_list() arms.append((x - l, x + l)) arms = sorted(arms, key=lambda x: x[1]) prev_r = -float("inf") cnt = 0 for left, right in arms: if prev_r > left: continue cnt += 1 prev_r = right print(cnt) return if __name__ == "__main__": main()
n = int(input()) X = [[] for _ in range(n)] for i in range(n): x,l = list(map(int, input().split())) X[i] = [x-l,x+l] X.sort(key = lambda x: x[1]) cnt = 1 mx = X[0][1] for i in range(1,n): if mx <= X[i][0]: cnt += 1 mx = X[i][1] print(cnt)
1
89,731,649,138,448
null
237
237
import collections zzz = 1 nn = int(input()) ans = 0 def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a for i in range(1,nn): zzz = 1 cc = collections.Counter(prime_factorize(i)) hoge = cc.values() for aaa in hoge: zzz *= aaa + 1 ans += zzz print(ans)
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64) import base64 import subprocess import zlib exe_bin = "c%1E9e{dUhcK_;!V<mPZIXH<41dAZJm?XkV>|iJLVcAl$;^f2^JCIVsMwaAQM3!7>6&xl&I3?lsj3C@FG@YYu+H0?2rc=1~u4OtmhfTN`ZrU3|OPdys3s;~Lg-HT5I3bDp-gm!WX?LwX?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_x~W%?_oTDKjze>(qCFd{|Tb5`L67bamx3Rc+-!+tkdW3+nmnm<efVDv`(MDmvgF*mrY0iNT<)=BRE~8+edI}S@K<-K7SwJRKI<o@Bed5pFgYd_aXgzkzSwE?-T9(H~RkrqwBw<)93pOoX+YJULVibbozWBg43IH^7{Gn7E$V3`MzJ}{}~isA8-Bm{TEU83b;OhkL_Mw-Cw=_r=&8suvPwFgk4{?eyH`hUq@M=^!uwjnic-|mt6mnPQU!V#0Z~fdVSu^Y(ur&f2QBW^mo;DY2>?g`n4wI`udGQuHT}=tL>Xt`=<_p>CdwHgZCj1nY(_>SNX2-lP&!FbqTA_p9TZ{AF+kk`6cW3{{kH-Ur7" open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod +x ./kyomu"], shell=True) subprocess.run(["./kyomu"], shell=True)
1
2,588,083,485,340
null
73
73
import sys input = sys.stdin.readline def main(): X = int(input()) for A in range(-119, 120 + 1): for B in range(-119, 120 + 1): if A ** 5 - B ** 5 == X: print(A, B) exit() if __name__ == "__main__": main()
X=int(input()) a=True while a==True: for i in range(-1000,1001): for j in range(i,1001): if j**5-i**5==X: print(j,i) exit()
1
25,567,157,000,412
null
156
156
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): N = int(input()) A = list(sorted(list(map(int, input().split())), reverse=True)) ans = A[0] n = 1 for i in range(1, N): if n == N - 1: break ans += A[i] n += 1 if n == N - 1: break ans += A[i] n += 1 if n == N - 1: break print(ans) def main(): solve() if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): N, M = map(int, input().split()) H = [None] H.extend(list(map(int, input().split()))) bad = set([]) for _ in range(M): A, B = map(int, input().split()) if H[A] > H[B]: bad.add(B) elif H[A] < H[B]: bad.add(A) else: bad.add(A) bad.add(B) print(N - len(bad)) if __name__ == '__main__': main()
0
null
17,160,821,235,232
111
155
import sys input = sys.stdin.readline N, D = map(int, input().split()) count = 0 for i in range(N): a, b = map(int, input().split()) if (a*a + b*b) <= D*D: count += 1 print(count)
A, B = map(int, input().split()) times = A * B if A < B: A, B = B, A while B > 0: temp = A % B A = B B = temp print(int(times/A))
0
null
59,503,978,892,984
96
256
N = int(input()) A = [int(s) for s in input().split(' ')] print('YES' if N == len(set(A)) else 'NO')
n=int(input()) a=list(map(int,input().split())) a.sort() for i in range(n-1): if a[i]==a[i+1]: print("NO") exit() print("YES")
1
73,942,591,431,654
null
222
222
D = int(input()) C = [int(T) for T in input().split()] S = [[] for TD in range(0,D)] for TD in range(0,D): S[TD] = [int(T) for T in input().split()] Type = 26 Last = [0]*Type SatD = [0]*D SatA = [0]*(D+1) for TD in range(0,D): Test = int(input())-1 Last[Test] = TD+1 SatD[TD] = S[TD][Test] for TC in range(0,Type): SatD[TD] -= C[TC]*(TD+1-Last[TC]) SatA[TD+1] = SatA[TD]+SatD[TD] print('\n'.join(str(T) for T in SatA[1:]))
d=int(input()) c=list(map(int,input().split())) s=[] for _ in range(d): s_i=list(map(int,input().split())) s.append(s_i) t=[] for _ in range(d): t_i=int(input()) t.append(t_i) dp=[0]*26 ans=0 for i in range(d): s_i = s[i][t[i]-1] ans+=s_i dp[t[i]-1]=i+1 tmp=0 for j in range(26): tmp+=c[j]*((i+1)-dp[j]) ans -= tmp print(ans)
1
9,971,609,634,714
null
114
114
from scipy.sparse.csgraph import floyd_warshall as fw N, M, L = map(int, input().split()) S = [[float("inf") for i in range(N)] for i in range(N)] for i in range(M): a, b, c = map(int, input().split()) S[a-1][b-1] = c S[b-1][a-1] = c Sdist = fw(S) Ssup_init = [[float("inf") for i in range(N)] for i in range(N)] for i in range(N): for j in range(N): if Sdist[i][j]<=L: Ssup_init[i][j] = 1 Ssup = fw(Ssup_init) Q = int(input()) for i in range(Q): s, t = map(int, input().split()) if Ssup[s-1][t-1]==float("inf"): print(-1) else: print(int(Ssup[s-1][t-1]-1))
def resolve(): from scipy.sparse.csgraph import floyd_warshall import numpy as np import sys input = sys.stdin.readline n, m, l = map(int, input().split()) inf = 10 ** 20 ar = [[0] * n for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) ar[a - 1][b - 1] = c ar[b - 1][a - 1] = c x = floyd_warshall(ar) br = [[0] * n for _ in range(n)] for i in range(n): for j in range(i + 1, n): if x[i, j] <= l: br[i][j] = 1 br[j][i] = 1 y = floyd_warshall(br) q = int(input()) for _ in range(q): s, t = map(int, input().split()) p = y[s - 1, t - 1] print(int(p) - 1 if p < inf else -1) if __name__ == "__main__": resolve()
1
173,282,991,809,968
null
295
295
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) ans = 0 MOD = 10**9+7 for i in range(63): one, zero = 0, 0 for Aj in A: if (Aj>>i)&1: one += 1 else: zero += 1 ans += 2**i*one*zero ans %= MOD print(ans)
s = input() ans = s if s[-1] == "s": ans += "e" print(ans+"s")
0
null
62,653,266,900,822
263
71
def main(): n, m, x = map(int, input().split(" ")) ca =[] a = [] c = [] INF = 1e7 ans = INF for i in range(n): ca.append(list(map(int, input().split(" ")))) for i in range(n): c.append(ca[i][0]) a.append(ca[i][1:]) for i in range(1<<n): a_sum = [0]*m c_sum = 0 for j in range(n): if i >> j & 1 == 1: for k in range(m): a_sum[k] += a[j][k] c_sum += c[j] if min(a_sum) >= x and c_sum < ans: ans = c_sum if ans == INF: print(-1) else: print(ans) if __name__ == "__main__": main()
n = int(input()) a = sorted(map(int,input().split()))[::-1] ans = 2 * sum(a[:(n-1)//2+1]) - a[0] if n % 2 == 1: ans -= a[(n-1)//2] print(ans)
0
null
15,743,028,997,696
149
111
n = int(input()) dp = [0] * 45 dp[0], dp[1] = 1, 1 for i in range(2, 44+1): dp[i] += dp[i-1] + dp[i-2] print(dp[n])
n = int(input()) dp = [1] * (n+1) for j in range(n-1): dp[j+2] = dp[j+1] + dp[j] print(dp[n])
1
1,970,247,260
null
7
7
n = int(input()) a = list(map(int, input().split())) lists = [0] * n for i in range(n): lists[a[i] - 1] = i + 1 for i in lists: print(i , end =' ')
n = int(input()) al = list(map(int,input().split())) lst = [[] for _ in range(n)] for i in range(1,n+1): lst[al[i-1]-1] = i print(*lst)
1
180,469,960,090,428
null
299
299
def solve(): N, P = map(int, input().split()) S = input() if P == 2 or P == 5: res = 0 for i in range(N): if int(S[i]) % P == 0: res += i + 1 print(res) else: res = 0 count = [0] * P r = 0 for i in range(N-1, -1, -1): r = (int(S[i]) * pow(10, N-1 - i, P) + r) % P if r == 0: res += 1 res += count[r] count[r] += 1 print(res) if __name__ == '__main__': solve()
N = int(input()) kotae = [] for i in range(1,N+1): for j in range(1,N+1): for k in range(1,N+1): s = i t = j u = k x = 1 while x != 0: v = t%s if v != 0: t = s s = v else: t = s x = u%t if x != 0: u = t t = x else: kotae.append(t) print(sum(kotae))
0
null
47,136,171,799,458
205
174
while True: m,f,r=map(int,input().split()) if m==f and f==r and r==-1: break if m==-1 or f==-1: print("F") elif (m+f)>=80: print("A") elif 65<=(m+f): print("B") elif 50<=(m+f) or r>=50: print("C") elif 30<=(m+f): print("D") else: print("F")
ans = '' while True: m, f, r = map(int, input().split(' ')) if (m == -1 and f == -1) and r == -1: break else: x = m + f if (m == -1) or (f == -1): ans += 'F\n' elif x >= 80: ans += 'A\n' elif x >= 65: ans += 'B\n' elif x >= 50: ans += 'C\n' elif x >= 30: if r >= 50: ans += 'C\n' else: ans += 'D\n' else: ans += 'F\n' if ans != '': print(ans[:-1])
1
1,227,168,739,830
null
57
57
n,m=input().split() n=int(n) m=int(m) f=[0]*n wa=[0]*n ac=0 for i in range(m): p,s=input().split() p=int(p)-1 if f[p]==1: continue if s=="WA": wa[p]+=1 else: ac+=1 f[p]=1 x=0 for i in range(n): if f[i]==1: x+=wa[i] print(ac,x)
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float("inf") def solve(N: int, M: int, p: "List[int]", S: "List[str]"): ac = [0 for _ in range(N)] for i in set(x[0] for x in zip(p, S) if x[1] == "AC"): ac[i - 1] = 1 wa = 0 for x in zip(p, S): ac[x[0] - 1] &= x[1] == "WA" wa += ac[x[0] - 1] return f'{len(set(x[0] for x in zip(p,S) if x[1] == "AC"))} {wa}' def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int p = [int()] * (M) # type: "List[int]" S = [str()] * (M) # type: "List[str]" for i in range(M): p[i] = int(next(tokens)) S[i] = next(tokens) print(f"{solve(N, M, p, S)}") if __name__ == "__main__": main()
1
93,133,276,888,858
null
240
240
import numpy as np n, k = map(int, input().split()) fruits = np.array(input().split(),dtype=np.int64) fruits.sort() ans = 0 cnt = 0 for i in fruits: if(cnt < k): ans += i cnt += 1 print(ans)
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import itertools import math import sys INF = float('inf') def solve(X: int, Y: int, Z: int): return f"{Z} {X} {Y}" def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int Z = int(next(tokens)) # type: int print(f'{solve(X, Y, Z)}') if __name__ == '__main__': main()
0
null
24,905,851,990,460
120
178
A,B = input().split() A = int(A) B1, B2 = B.split('.') B = int(B1)*10**len(B2)+int(B2) print((A*B)//10**len(B2))
A,B,C=map(int,input().split()) if 4*A*B<(C-A-B)*(C-A-B) and C>A+B: print("Yes") else: print("No")
0
null
34,024,210,447,358
135
197
N = int(input()) S = input() if S[:int(N/2)] == S[int(N/2):N]: print("Yes") else: print("No")
N = int(input()) S = input() if S == S[:N//2]*2: print("Yes") else: print("No")
1
146,305,373,929,360
null
279
279
a,b= map(int,input().split()); if a < b : print("a < b" ); elif a > b : print("a > b" ); elif a == b : print("a == b") ;
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) SA = T1 * A1 + T2 * A2 SB = T1 * B1 + T2 * B2 if SA == SB or A1 == B1: print('infinity') exit() if SA > SB and A1 < B1: M = (B1 - A1) * T1 d = SA - SB cnt = M // d ans = cnt * 2 if M % d != 0: ans += 1 print(max(0, ans)) elif SB > SA and B1 < A1: M = (A1 - B1) * T1 d = SB - SA cnt = M // d ans = cnt * 2 if M % d != 0: ans += 1 print(max(0, ans)) else: print(0)
0
null
65,970,840,041,458
38
269
n = int(input()) a = list(map(int, input().split())) x = 0 m = a[0] for i in range(n): if a[i] < m: x += m - a[i] else: m = a[i] print(x)
n = int(input()) a = [int(s) for s in input().split()] t=a[0] total=0 for i in range(n): if t>a[i]: total=total+t-a[i] else: t=a[i] print(total)
1
4,530,259,790,402
null
88
88
#!/usr/bin/env python3 import sys from itertools import chain YES = "Yes" # type: str NO = "No" # type: str def solve(H: int, N: int, A: "List[int]"): if H <= sum(A): return YES else: return NO def main(): tokens = chain(*(line.split() for line in sys.stdin)) H = int(next(tokens)) # type: int N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" answer = solve(H, N, A) print(answer) if __name__ == "__main__": main()
h,n=map(int,input().split()) A=list(map(int,input().split())) attack=0 for i in range(n): attack+=A[i] if attack>=h: print("Yes") else: print("No")
1
78,161,935,624,030
null
226
226
n = int(input()) aas = list(map(int, input().split())) res = 0 pre = aas[0] for i in range(1,len(aas)): if pre > aas[i]: res += pre - aas[i] else: pre = aas[i] print(res)
N = int(input()) A = list(map(int, input().split())) cun =0 for i in range(N): if i == N-1: break elif A[i] > A[i+1]: cun += A[i] - A[i+1] A[i+1] = A[i] else: pass print(cun)
1
4,582,339,559,068
null
88
88
N = int(input()) cnt = 0 for _ in range(N): d1, d2 = map(int, input().split()) if d1 == d2: cnt += 1 else: cnt = 0 if cnt == 3: print("Yes") break else: print("No")
N = int(input()) A = [list(map(int, input().split())) for _ in range(N)] for i in range(N - 2): if all(x == y for (x, y) in A[i:i+3]): print('Yes') break else: print('No')
1
2,511,770,906,500
null
72
72
def judge(): if t > h: point["t"] += 3 elif t < h: point["h"] += 3 else: point["t"] += 1; point["h"] += 1 n = int(input()) point = {"t": 0, "h": 0} for i in range(n): t, h = input().split() judge() print(point["t"], point["h"])
N = int(input()) GACHA={} for n in range(N): g=input() GACHA[g]=GACHA.get(g,0) print(len(GACHA))
0
null
16,084,835,574,972
67
165
f=[1,1] for _ in[0]*43:f+=[f[-2]+f[-1]] print(f[int(input())])
def memoize(f): cache = {} def helper(x): if x not in cache: cache[x] = f(x) return cache[x] return helper @memoize def fib(n): if n in (0, 1): return 1 else: return fib(n - 1) + fib(n - 2) print(fib(int(input())))
1
1,484,962,048
null
7
7
#入力 n, u, v = map(int, input().split()) mapdata = [list(map(int,input().split())) for _ in range(n-1)] #グラフ作成 graph = [[] for _ in range(n+1)] for i, j in mapdata: graph[i].append(j) graph[j].append(i) #探索 def dfs(v): dist = [-1] * (n + 1) stack = [v] dist[v] = 0 while stack: v = stack.pop() dw = dist[v] + 1 for w in graph[v]: if dist[w] >= 0: continue dist[w] = dw stack.append(w) return dist du, dv = dfs(u), dfs(v) ans = 0 for u, v in zip(du[1:], dv[1:]): if u < v: x = v-1 if ans < x: ans = x print(ans)
import sys sys.setrecursionlimit(10**9) N, u, v = map(int, input().split()) u, v = u-1, v-1 edge = [[] for _ in range(N)] for i in range(N-1): a, b = map(int, input().split()) a, b = a-1, b-1 edge[a].append(b) edge[b].append(a) taka = [0] * N aoki = [0] * N def dfs(v, pre, cost, i): for e in edge[v]: if e == pre: continue cost = dfs(e, v, cost, i+1) cost[v] = i return cost taka = dfs(u, -1, [0] * N, 0) aoki = dfs(v, -1, [0] * N, 0) m = 0 for i in range(N): if taka[i] < aoki[i]: m = max(m, aoki[i]) print(m-1)
1
117,519,141,410,562
null
259
259
n=int(input()) num=[1,1] for i in range(43): b=(num[-2])+(num[-1]) num.append(b) print(num[(n)])
N = int(input()) if N % 10 in [2, 4, 5, 7, 9]: print("hon") elif N % 10 in [0, 1, 6, 8]: print("pon") else: print("bon")
0
null
9,597,796,661,670
7
142
from itertools import combinations as comb N = int(input()) L = list(map(int,input().split())) count = 0 for a, b, c in comb(L, 3): if a != b and b != c and c != a and a + b > c and b + c > a and c + a > b: count += 1 print(count)
import fileinput s, t = input().split() print(t + s)
0
null
54,350,386,868,668
91
248
N, K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] check = [0]*N ima = 0 for i in range(K): if check[A[ima]-1] != 0: loopen = ima check[ima] = i+1 looplen = check[ima] - check[A[ima]-1] + 1 loopend = i break if i == K-1: print(A[ima]) exit() check[ima] = i+1 ima = A[ima]-1 offset = (K-(i-looplen)-1)%looplen ima = 0 for i in range(loopend-looplen+offset+1): ima = A[ima]-1 print(ima+1)
import math K=int(input()) ans=0 for a in range(1,K+1): for b in range(1,K+1): g=math.gcd(a,b) for c in range(1,K+1): ans+=math.gcd(g,c) print(ans)
0
null
29,079,887,538,790
150
174
n = int(input()) G = {i:[] for i in range(1, n+1)} for _ in range(n): ukv = list(map(int, input().split())) u = ukv[0] k = ukv[1] for i in range(2, 2+k): G[u].append(ukv[i]) d = [-1 for _ in range(n+1)] f = [-1 for _ in range(n+1)] counter = 0 def dfs(n): global counter counter += 1 d[n] = counter for n_i in G[n]: if d[n_i]==-1: dfs(n_i) counter += 1 f[n] = counter for i in range(1, n+1): if d[i]==-1: dfs(i) for id_i, (d_i, f_i) in enumerate(zip(d[1:], f[1:]), 1): print(id_i, d_i, f_i)
tmp = -1 cnt = 1 output = [] while tmp != 0: tmp = int(input()) if tmp == 0: break output += ["Case " + str(cnt) + ": " + str(tmp)] cnt += 1 for x in output: print(x)
0
null
248,604,180,160
8
42
N=int(input()) alp=["a","b","c","d","e","f","g","h","i","j"] alp=alp[:N] ans=[] def dfs(now): if len(now)==N: ans.append(now) return for i,s in enumerate(alp): if len(set(now))>=i: next_s=now+s dfs(next_s) dfs("a") ans=sorted(ans) for a in ans: print(a)
N, A, B = map(int, input().split()) h = N//(A+B) i = N%(A+B) ans = h*A + min(i, A) print(ans)
0
null
53,757,822,822,912
198
202
a,b,c,d=map(int,input().split()) def ret(a,b,c,d): return max(b*d,a*c,0 if (a*b<=0 or c*d<=0) else -1e64,a*d,b*c) print(ret(a,b,c,d))
N = int(input()) c = [[0 for _ in range(10)] for __ in range(10)] for x in range(1, N+1): check = str(x) it = int(check[0]) jt = int(check[-1]) c[it][jt] += 1 ans = 0 for i in range(0,10): for j in range(0,10): ans += c[i][j] * c[j][i] print(ans)
0
null
44,766,584,008,720
77
234
N = int(input()) A = list(map(int, input().split())) money = 1000 stock = 0 for i in range(N-1) : if A[i] > A[i+1] : money += stock * A[i] stock = 0 elif A[i] < A[i+1] : temp = int(money / A[i]) stock += temp money -= temp * A[i] money += stock * A[N-1] stock = 0 print(money)
n = int(input()) a = list(map(int, input().split())) ans = 1000 stock = 0 for i in range(n-1): if a[i+1] > a[i]: buy = ans//a[i] stock += buy ans -= buy*a[i] else: ans += stock*a[i] stock = 0 ans += stock*a[-1] print(ans)
1
7,308,865,115,182
null
103
103
n, m, l = map(int, input().split()) A = [list(map(int, input().split())) for i in range(n)] B = [list(map(int, input().split())) for i in range(m)] for ARow in A: result = [] for BCol in zip(*B): result.append(sum([ARow[i] * BCol[i] for i in range(m)])) print(*result)
import numpy as np n = int(input()) a = list(map(int,input().split())) a = np.array(a, dtype='int64') MOD = 10**9+7 ans = 0 for i in range(60): ca = a >> i & 1 c1 = int(ca.sum()) c0 = n - c1 c0c1 = (c0 * c1) % MOD c0c1pow = (c0c1 * 2**i) % MOD ans = (ans + c0c1pow) % MOD print(ans)
0
null
61,910,977,223,420
60
263
while 1: n=int(input()) if n==0:break s=list(map(int,input().split())) print((sum([(m-sum(s)/n)**2 for m in s])/n)**.5)
import math while True: n=int(input()) if n==0: break else: a=list(map(int,input().split())) m=sum(a)/n l=0 for i in range(n): l+=(a[i]-m)**2 b=math.sqrt(l/n) print("{:.8f}".format(b))
1
193,026,216,702
null
31
31
N = int(input()) A = list(map(int, input().split())) N_MAX = 200000 A_MAX = 10 ** 9 temp = dict() for i in A: if i in temp: print("NO") exit() else: temp[i] = 0 print("YES")
n = int(input()) a = list(map(int,input().split())) b = sorted(a) memo = 0 for i in range(n-1): if(b[i]==b[i+1]): memo +=1 if(memo==0): print("YES") else: print("NO")
1
73,609,493,292,718
null
222
222
while input()!='0': l=list(map(float,input().split())) m=sum(l)/len(l) s=0 for i in range(len(l)): s+=(l[i]-m)**2 print('%.8f'%((s/len(l))**.5))
N = int(input()) s = {} t = [] for i in range(N): st = input().split() s[st[0]] = i t.append(int(st[1])) X = input() print(sum(t[s[X]+1:]))
0
null
48,426,970,839,312
31
243
def LinearSearch1(S, n, t): for i in range(n): if S[i] == t: return i break else: return -1 """ def LinearSearch2(S, n, t): S.append(t) i = 0 while S[i] != t: i += 1 S.pop() if i == n: return -1 else: return i """ n = int(input()) S = [int(s) for s in input().split()] q = int(input()) T = {int(t) for t in input().split()} ans = sum(LinearSearch1(S, n, t) >= 0 for t in T) print(ans)
if __name__ == '__main__': def linearSearch(t): S.append(t) #print(S) i=0 while S[i]!=t: i+=1 del S[n] return 1 if i!=n else 0 n=int(input()) S=list(map(int,input().split())) q=int(input()) T=set(map(int,input().split())) ans=0 for t in T: ans+=linearSearch(t) #print(t,ans) print(ans)
1
65,761,012,324
null
22
22
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil from operator import itemgetter def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI2(): return [int(input()) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf = 10**17 mod = 10**9 + 7 #s=input().rstrip() n=I() lis=[[]for i in range(n)] lis[0].append([1]) for i in range(n-1): for j in lis[i]: for m in range(max(j)+1): lis[i+1].append(j+[m+1]) #print(max(j)) #print(lis[n-1]) alpha=["a","b","c","d","e","f","g","h","i","j"] for u in lis[n-1]: ans="" for j in u: ans+=alpha[j-1] print(ans)
# https://atcoder.jp/contests/panasonic2020/submissions/12881278 # D - String Equivalence import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) def dfs(S, available): if len(S) == n: print("".join(S)) return for i in range(available + 1): S.append(chr(97 + i)) dfs(S, max(available, i + 1)) S.pop() dfs([], 0) if __name__ == '__main__': resolve()
1
52,343,777,350,880
null
198
198
N,K=map(int,input().split()) A=list(map(lambda x:int(x)%K,input().split())) cum=[0]*(N+1) for i in range(N): cum[i+1]=(cum[i]+A[i]) x=[(cum[i]-i)%K for i in range(N+1)] dic={} ans=0 for i in range(N+1): if i>=K: dic[x[i-K]]-=1 ans+=dic.get(x[i],0) if not x[i] in dic: dic[x[i]]=1 else: dic[x[i]]+=1 print(ans)
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import time,random sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 mod2 = 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def JA(a, sep): return sep.join(map(str, a)) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def main(): n,k = LI() aa = LI() c = collections.defaultdict(int) c[0] = 1 t = [0] r = 0 for i in range(n): a = aa[i] tt = (t[-1] + a - 1) % k t.append(tt) if i >= k-1: # print("k", t[i-k+2],i-k+2) c[t[i-k+1]] -= 1 r += c[tt] c[tt] += 1 # print("ar", a,tt,r,sorted(c.items()), t) return r print(main())
1
138,064,023,227,808
null
273
273
N, K = map(int, input().split()) A = sorted(list(map(int, input().split()))) def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p p = 10 ** 9 + 7 fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) ans = 0 for i in range(N - K + 1): ans -= A[i] * cmb(N - 1 - i, K - 1, p) A = A[::-1] for i in range(N - K + 1): ans += A[i] * cmb(N - 1 - i, K - 1, p) print(ans % p)
def prepare(n, MOD): # 1! - n! の計算 f = 1 factorials = [1] # 0!の分 for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) # n!^-1 の計算 inv = pow(f, MOD - 2, MOD) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs def main(): n,k=map(int, input().split()) A=[int(i) for i in input().split()] MOD = 10**9 + 7 fac, invs = prepare(n,MOD) ans = 0 A.sort() for i in range(n): tmp=0 tmp2=0 if i<n-k+1: tmp = (fac[n-(i+1)]%MOD * invs[k-1]%MOD * invs[n-(i+1) - (k-1)]%MOD)%MOD if i>=k-1: tmp2 = (fac[i]%MOD * invs[k-1]%MOD * invs[i-(k-1)]%MOD)%MOD #print("最大になる回数", tmp2, " 最小になる回数", tmp, "A[i]", A[i]) ans = ans%MOD + (tmp2*A[i]%MOD - tmp*A[i]%MOD)%MOD ans%=MOD if k==1: ans = 0 print(ans) if __name__ == '__main__': main()
1
95,391,797,979,042
null
242
242
n = int(input()) s = input() ans = '' for c in s: nc_ord = ord(c) + n while nc_ord > ord('Z'): nc_ord -= 26 ans += chr(nc_ord) print(ans)
length, Max, q = map(int,input().split()) query = [[0]*4 for _ in range(q)] for i in range(q): a,b,c,d = map(int,input().split()) query[i] = [a-1,b-1,c,d] ans = 0 def dfs(A): if len(A) == length: global ans score = 0 for i in range(q): a,b,c,d = query[i] if A[b] - A[a] == c: score += d ans = max(ans, score) return last = A[-1] for i in range(last,Max+1): A.append(i) dfs(A) A.pop() dfs([1]) print(ans)
0
null
80,872,874,472,510
271
160
from math import * while True: n = input() if n==0: break score_li = map(int,raw_input().split()) score_sum = sum(score_li) ave = score_sum/float(n) variance = 0 for i in xrange(n): variance += (score_li[i]-ave)**2 variance /=float(n) sd = sqrt(variance) #sd:standard deviation print sd
import bisect N=int(input()) arr=list(map(int,input().split())) arr.sort() ans=0 for i in range(N-2): for j in range(i+1,N-1): k=bisect.bisect_left(arr,arr[i]+arr[j]) if k>j: ans+=k-j-1 else: pass print(ans)
0
null
86,217,707,387,504
31
294
MOD = 998244353 N, S = map(int, input().split()) A = list(map(int, input().split())) dp = [[0] * (S + 1) for i in range(N)] dp[0][0] = 2 if A[0] < S + 1: dp[0][A[0]] = 1 for i in range(1, N): for j in range(S + 1): dp[i][j] = (2 * dp[i - 1][j]) % MOD if 0 <= j - A[i] <= S: dp[i][j] = (dp[i][j] + dp[i - 1][j - A[i]]) % MOD print(dp[-1][-1])
#!/usr/bin/env python3 import sys # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # 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 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 datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # 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 (e.g. list is not allowed) # 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, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import gcd # for Python 3.4 (previous contest @AtCoder) def main(): mod = 998244353 # 10^9+7 inf = float('inf') # sys.float_info.max = 1.79...e+308 # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19 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()) # def my_update(seq, L): # n = len(seq) # for i in range(n-1): # seq[i+1] += L[i] # n, s = mi() # L = lmi() # dp = [[0] * (n + 1) for j in range(s + 1)] # chain の長さ、場合のかず # # print(dp) # for i in range(n): # for j in range(s, -1, -1): # if j == 0 and L[i] <= s: # dp[L[i]][1] += 1 # elif j + L[i] <= s and dp[j]: # my_update(dp[j + L[i]], dp[j]) # counter # # print(dp) # ans = 0 # for chain_len, num in enumerate(dp[s]): # ans = (ans + pow(2, n - chain_len, mod) * num) % mod # print(ans) # write-up solution """ Ai それぞれ選ぶ or 選ばないと選択して行った時、足して S にできる組み合わせは何パターンできるか? -> まさに二項定理の発想 fi = 1+x^Ai として T = {1, 2, 3} に対する答えは [x^S]f1*f2*f3 T = {1, 2} に対する答えは [x^S]f1*f2 のように計算していく 全パターン f1*f2*f3 + f1*f2 + f1*f3 + f2*f3 + f1 + f2 + f3 の [x^S] の値が答え -> (1+f1)*...*(1+fi)*...*(1+fn) の x^S の係数と一致 [x^S] Π{i=1...n} (2 + x^Ai) を計算せよ、という問である """ n, s = mi() A = lmi() power_memo = [0] * (s + 1) power_memo[0] = 2 if A[0] <= s: power_memo[A[0]] = 1 for i in range(1, n): # print(power_memo) for j in range(s, -1, -1): tmp = (power_memo[j] * 2) % mod if j - A[i] >= 0 and power_memo[j - A[i]]: tmp += power_memo[j - A[i]] power_memo[j] = tmp % mod # print(power_memo) print(power_memo[s]) if __name__ == "__main__": main()
1
17,607,428,152,150
null
138
138
N = int(input()) print(N//2 if N%2 else N//2-1)
N = int(input()) print((N // 2) - 1 if N % 2 == 0 else N // 2)
1
152,833,432,271,978
null
283
283
import sys n = int(input()) x = sorted(list(map(int, input().split()))) if len(list(set(x))) == 1: print(0) sys.exit() if n == 1: print(0) sys.exit() x_min = x[0] x_max = x[n-1] min_sum = 10000000 for p in range(x_min, x_max): sum = 0 for e in x: len = (e - p)**2 sum += len # print("p", p, "sum", sum, "min_sum", min_sum) if sum <= min_sum: min_sum = sum print(min_sum)
############################################## N = int(input()) X = list(map(int, input().split())) ans = float('inf') for i in range(min(X), max(X)+1): cost = 0 for x in X: cost += (x - i) ** 2 ans = min(ans, cost) print(ans)
1
65,269,205,099,150
null
213
213
def gcd2(x,y): if y == 0: return x return gcd2(y,x % y) def lcm2(x,y): return x // gcd2(x,y) * y a,b = map(int,input().split()) print(lcm2(a,b))
N,K,S=[int(x) for x in input().rstrip().split()] ans=[] if S==10**9: for i in range(N): if i+1<=K: ans.append(S) else: ans.append(1) else: for i in range(N): if i+1<=K: ans.append(S) else: ans.append(S+1) print(*ans)
0
null
102,061,604,676,370
256
238
n = int(input()) for i in range(1, n + 1): if i % 3 == 0 or str(i).find("3") != -1: print(" {}".format(i), end = '') print()
n = int(raw_input()) output = "" for i in range(1, n + 1): x = i if x % 3 == 0: output += " " output += str(i) continue while True: if x % 10 == 3: output += " " output += str(i) break else: x /= 10 if x == 0: break print output
1
941,658,094,958
null
52
52
N, M, K = map(int, input().split()) mod = 998244353 MAX = 510000 fac = [0]*MAX facinv = [0]*MAX inv = [0]*MAX def modinv(a, mod): b = mod x, u = 1, 0 while b: q = a//b a, b = b, a-q*b x, u = u, x-q*u x %= mod return x def mod_nCr_init(n, mod): fac[0] = fac[1] = 1 facinv[0] = facinv[1] = 1 inv[1] = 1 for i in range(2, n): fac[i] = fac[i-1] * i % mod inv[i] = -inv[mod % i] * (mod // i) % mod facinv[i] = facinv[i-1] * inv[i] % mod def mod_nCr(n, r, mod): if n < r or n < 0 or r < 0: return 0 return fac[n] * (facinv[r] * facinv[n-r] % mod) % mod mod_nCr_init(MAX, mod) ans = 0 for i in range(K+1): ans += mod_nCr(N-1, i, mod) * M * pow(M-1, N-i-1, mod) ans %= mod print(ans)
class Card: def __init__(self, label): suits = ['S', 'H', 'C', 'D'] suit, value = list(label) assert(suit in suits and 0 < int(value) < 10) self.suit = suit self.value = int(value) def __eq__(self, other): """equal >>> Card('S1') == Card('D9') False >>> Card('D9') == Card('S1') False >>> Card('C5') == Card('C5') True """ return self.value == other.value def __lt__(self, other): """less than >>> Card('S1') < Card('D9') True >>> Card('D9') < Card('S1') False """ return self.value < other.value def __gt__(self, other): """greater than >>> Card('S1') > Card('D9') False >>> Card('D9') > Card('S1') True """ return self.value > other.value def __hash__(self): return hash((self.suit, self.value)) def __str__(self): return self.suit + str(self.value) def bubble_sort(deck): """sort deck by bubble sort >>> deck = [Card('H4'), Card('C9'), Card('S4'), Card('D2'), Card('C3')] >>> print(" ".join([str(c) for c in bubble_sort(deck)])) D2 C3 H4 S4 C9 """ size = len(deck) for i in range(size): for j in reversed(range(i+1, size)): if deck[j] < deck[j-1]: deck[j-1], deck[j] = deck[j], deck[j-1] return deck def selection_sort(deck): """sort deck by selection sort >>> deck = [Card('H4'), Card('C9'), Card('S4'), Card('D2'), Card('C3')] >>> print(" ".join([str(c) for c in selection_sort(deck)])) D2 C3 S4 H4 C9 """ size = len(deck) for i in range(size): mini = i for j in range(i, size): if deck[mini] > deck[j]: mini = j deck[i], deck[mini] = deck[mini], deck[i] return deck def is_stable_sorted(org, deck): """check if deck is sorted by stable manner >>> c1 = Card('S1') >>> c2 = Card('D1') >>> is_stable_sorted([c1, c2], [c1, c2]) True >>> is_stable_sorted([c1, c2], [c2, c1]) False """ idx = {c:i for (i, c) in enumerate(org)} return all([c1 < c2 or idx[c1] < idx[c2] for (c1, c2) in zip(deck[:-1], deck[1:])]) def check_stable(org, deck): if is_stable_sorted(org, deck): return "Stable" else: return "Not stable" def run(): _ = int(input()) # flake8: noqa deck = [] for lb in input().split(): deck.append(Card(lb)) db = bubble_sort(deck[:]) print(" ".join([str(c) for c in db])) print(check_stable(deck, db)) ds = selection_sort(deck[:]) print(" ".join([str(c) for c in ds])) print(check_stable(deck, ds)) if __name__ == '__main__': run()
0
null
11,711,573,731,342
151
16
s = input() k = int(input()) s_len = len(s) if s_len == 1: print(k//2) exit() if s.count(s[0]) == s_len: print((k*s_len)//2) exit() cnt = 0 ans = 0 flag = "off" while cnt <= s_len-2: if s[cnt] == s[cnt+1]: if cnt == s_len-2: flag = "on" ans += 1 cnt += 1 cnt += 1 dum = s[0] check1 = 0 for i in s: if dum == i: check1 += 1 else: break dum = s[-1] check2 = 0 for i in s[::-1]: if dum == i: check2 += 1 else: break if (check1+check2)%2 == 0 and s[0] == s[-1]: print(ans*k+(k-1)) else: print(ans*k)
S = list(input()) N = len(S) K = int(input()) old = S[0] a = 0 c = 1 for i in range(1,N): if S[i] == old: c += 1 else: a += c // 2 old = S[i] c = 1 b = 0 a += c // 2 for i in range(N): if S[i] == old: b += 1 else: break ans = a * K + ((b + c) // 2 - b // 2 - c // 2) * (K - 1) if c == N: ans = N * K // 2 print(ans)
1
174,938,545,353,920
null
296
296
n,m,l=map(int,raw_input().split()) A=[] B=[] for i in range(n): A.append(map(int,raw_input().split())) for i in range(m): B.append(map(int,raw_input().split())) for i in range(n): print(' '.join(map(str,[sum([A[i][j]*B[j][k] for j in range(m)]) for k in range(l)])))
import sys input = sys.stdin.readline MOD = 10**9 + 7 INF = float('INF') def main(): k, x = list(map(int,input().split())) if 500 * k >= x: print('Yes') else: print('No') if __name__ == '__main__': main()
0
null
49,713,758,932,060
60
244
#!/usr/bin python3 # -*- coding: utf-8 -*- from bisect import bisect_left, bisect_right n, d, a = map(int, input().split()) x = [] xh = dict() for _ in range(n): xi, hi = map(int, input().split()) x.append(xi) xh[xi] = hi x.sort() l = 0 ret = 0 ai = [0] * (n+1) anow = 0 while l < n: xl = x[l] hl = xh[xl] anow += ai[l] hl -= a * anow if hl > 0: r = bisect_right(x, xl+2*d) k = (hl+(a-1))//a ret += k anow += k ai[r] -= k l += 1 print(ret)
from bisect import * from math import * N,D,A=map(int,input().split()) monsters=[list(map(int,input().split())) for _ in range(N)] monsters.sort(key=lambda x:x[0]) killingrange=[0]*N monsterspoint=[] monstershp=[] imos=[0]*N for i in range(N): monsterspoint.append(monsters[i][0]) monstershp.append(monsters[i][1]) for i in range(N): ind=bisect(monsterspoint,monsterspoint[i]+2*D) killingrange[i]=ind #print(killingrange) cnt=0 for i in range(N): monstershp[i]=monstershp[i]+imos[i] if (monstershp[i]>0): cnt=cnt+ceil(monstershp[i]/A) imos[i]=imos[i]-A*ceil(monstershp[i]/A) if killingrange[i]<N: imos[killingrange[i]]=imos[killingrange[i]]+A*ceil(monstershp[i]/A) monstershp[i]=monstershp[i]-A*ceil(monstershp[i]/A) if i<N-1: imos[i+1]=imos[i]+imos[i+1] #print(monstershp,imos) print(cnt)
1
82,552,998,422,932
null
230
230
INF=10**30 H,N=map(int,input().split()) A,B=[],[] for i in range(N): a,b=map(int,input().split()) A.append(a);B.append(b) dp=[INF]*(H+10) dp[0]=0 for i in range(N): for j in range(H+1): if(j<A[i]): dp[j]=min(dp[j],dp[0]+B[i]) else: dp[j]=min(dp[j],dp[j-A[i]]+B[i]) print(dp[H])
import heapq H, N = map(int, input().split()) A = [] #W B = [] #V for i in range(N): ai, bi = map(int, input().split()) A += [ai] B += [bi] maxA = max(A) dp = [[0 for j in range(H+maxA+1)]for i in range(N+1)] for j in range(1, H+maxA+1): dp[0][j] = float('inf') for i in range(N): for j in range(H+maxA+1): if j - A[i] < 0: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + B[i]) ans = float('inf') for j in range(H, H+maxA+1): ans = min(ans, dp[N][j]) print(ans)
1
81,230,785,897,596
null
229
229
import math a,b = map(int,input().split()) print(int(a * b / math.gcd(a,b)))
a,b=map(int,input().split()) m=min(a,b) kouyakusuu=1 for i in range(1,m+1): if a%i==0 and b%i==0: kouyakusuu=i print(a*b//kouyakusuu)
1
113,294,930,888,272
null
256
256
import re strings = input() def swapletter(match): word = match.group() return word.swapcase() data = re.sub(r"\w+", swapletter, strings) print(data)
c=str(input()) cl=list(c) for i in range(len(cl)): if cl[i].islower(): cl[i]=cl[i].upper() print(cl[i],end='') elif cl[i].isupper(): cl[i] =cl[i].lower() print(cl[i], end='') elif not cl[i].isalpha(): print(cl[i], end='') print('')
1
1,516,733,450,870
null
61
61
import sys import math from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)] def main(): N = NI() A = NLI() B = [[0]*2 for _ in range(62)] for a in A: for i in range(62): B[i][(a >> i) & 1] += 1 ans = 0 for i, b in enumerate(B): ans += b[0] * b[1] * pow(2, i, MOD) print(ans % MOD) if __name__ == "__main__": main()
import sys import numpy as np input = sys.stdin.buffer.readline N = int(input()) A = np.array(list(map(int, input().split()))) MOD = 10**9 + 7 answer = 0 for n in range(63): B = (A >> n) & 1 x = np.count_nonzero(B) y = N - x x *= y for _ in range(n): x = x * 2 % MOD answer += x answer %= MOD print(answer)
1
123,489,270,520,228
null
263
263