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
N, M =map(int, input().split()) H=list(map(int, input().split())) A=[True]*N for i in range(M): a, b = map(int, input().split()) if H[a-1]>H[b-1]: A[b-1]=False elif H[a-1]==H[b-1]: A[a-1]=False A[b-1]=False elif H[a-1]<H[b-1]: A[a-1]=False print(sum(A))
s = int(input()) dp = [0] * (s + 11) mod = 10 ** 9 + 7 dp[0] = 1 dp[1] = 0 dp[2] = 0 dp[3] = 1 c = 2 for i in range(4, s + 1): dp[i] = (c - dp[i - 1] - dp[i - 2]) % mod c = (c + dp[i]) % mod print(dp[s])
0
null
14,189,588,970,032
155
79
n=int(input()) s=[input() for _ in range(n)] d0={} d1={} ma=0 mab=0 for si in s: a,b=0,0 for x in si: if x=='(': b+=1 else: b-=1 a=min(b,a) a=-a if b>=0: if a in d0: d0[a].append([a,b]) else: d0[a]=[[a,b]] ma=max(ma,a) else: if a+b in d1: d1[a+b].append([a,b]) else: d1[a+b]=[[a,b]] mab=max(mab,a+b) now=0 for i in range(ma+1): if i not in d0:continue if now>=i: for a,b in d0[i]: now+=b else: print('No') exit() for i in range(mab,-1,-1): if i not in d1:continue for a,b in d1[i]: if now>=a: now+=b else: print('No') exit() if now==0: print('Yes') else: print('No')
a,b,n = map(int,input().split()) if n < b: print(a*n//b) else: print(a*(b-1)//b)
0
null
25,784,451,469,370
152
161
A, B, C, K = map(int, input().split()) # KをA,B,Cの順に割り振る a = min(A, K) K -= a b = min(B, K) K -= b c = min(C, K) print(1 * a + -1 * c)
def main(a, b,c,k): m = 0 if k <=a: m = k elif k <=(a+b): m = a elif k <= a+b+c: m = (a-(k-(a+b))) return m a, b, c , k = map(int, input().split()) print(main(a,b,c,k))
1
21,842,256,218,412
null
148
148
def main(): s = input() p = input() if p in s*2: print("Yes") else: print("No") if __name__ == '__main__': main()
N=int(input()) A=list(map(int,input().split())) count=[0 for i in range(N)] for i in A: count[i-1]+=1 def chose(n): return int(n*(n-1)/2) total=0 for i in count: total+=chose(i) for i in range(N): ans=total ans-=chose(count[A[i]-1]) count[A[i]-1]-=1 ans+=chose(count[A[i]-1]) count[A[i]-1]+=1 print(ans)
0
null
24,654,745,910,550
64
192
from math import log2 N = int(input()) log = int(log2(N)+1) ans = (2**log-1) print(ans)
H = int(input()) Ans = 0 n = 0 while True: if H != 1: H = H//2 Ans += 2**n n += 1 else: Ans += 2**n break print(Ans)
1
79,817,553,575,318
null
228
228
D = int(input()) c = list(map(int, input().split())) s_matrix = [list(map(int, input().split())) for _ in range(D)] t = [int(input()) for _ in range(D)] last = [0] * 26 satis = 0 for i in range(D): test = t[i] - 1 satis += s_matrix[i][test] last[test] = i + 1 for j in range(26): satis -= c[j] * (i+1 - last[j]) print(satis)
while(True): H, W = map(int, input().strip().split()) if(H == W == 0): break for x in range(H): print(''.join('#.'[(x + y) % 2] for y in range(W))) print()
0
null
5,345,628,434,170
114
51
from sys import stdin n = int(stdin.readline().rstrip()) A = [int(x) for x in stdin.readline().rstrip().split()] ans = [0] * n for i, a in enumerate(A): ans[a-1] = i+1 print(' '.join(map(str, ans)))
def gotoS(org, n): res = [0] * n for i in range(1, n+1): res[org[i-1]-1] = i return res n = int(input()) org = list(map(int, input().split())) print(*gotoS(org, n))
1
181,225,413,513,802
null
299
299
n=int(input()) i=int(n**0.5) while n%i: i-=1 print(i+n//i-2)
n,m,x = map(int,input().split()) ca = [list(map(int,input().split())) for i in range(n)] c = [0]*n a = [0]*n for i in range(n): c[i],a[i] = ca[i][0],ca[i][1:] INF = 10**9 ans = INF for i in range(1<<n): understanding = [0]*m cost = 0 for j in range(n): if ((i>>j)&1): cost += c[j] for k in range(m): understanding[k] += a[j][k] ok = True for s in range(m): if understanding[s] < x: ok = False if ok: ans = min(ans, cost) if ans == INF: ans = -1 print(ans)
0
null
91,645,968,651,058
288
149
def insertion_sort(l, g): cnt = 0 for i in range(g, len(l)): tmp = l[i] j = i - g while j >= 0 and l[j] > tmp: l[j+g] = l[j] cnt += 1 j -= g l[j+g] = tmp return l, cnt def shell_sort(l, lg): tot = 0 for g in lg: sl, cnt = insertion_sort(l, g) tot += cnt return sl, tot if __name__ == '__main__': N = int(input()) l = [] for _ in range(N): l.append(int(input())) lg = [1] while True: gc = 3 * lg[-1] + 1 if gc > N: break lg.append(gc) lg = lg[::-1] print(len(lg)) print(' '.join(map(str, lg))) sl, tot = shell_sort(l, lg) print(tot) for e in sl: print(e)
def insertionSort(A,g): global cnt for i in range(g,len(A)): 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 def shellSort(A): global cnt cnt = 0 h = 1 g = [] while h <= len(A): g.append(h) h = 3*h+1 g.reverse() m = len(g) print(m) print(' '.join(map(str,g))) for i in range(m): insertionSort(A,g[i]) n = int(input()) A = [int(input()) for i in range(n)] shellSort(A) print(cnt) for i in A: print(i)
1
28,946,598,268
null
17
17
while 1: l=map(str,raw_input().split()) answer = 0 if l[1] == '+': answer = int (l[0]) + int (l[2]) if l[1] == '-': answer = int (l[0]) - int (l[2]) if l[1] == '*': answer = int (l[0]) * int (l[2]) if l[1] == '/': answer = int (l[0]) / int (l[2]) if l[1] == '?': break; print answer
import math while(True): a,op,b=input().split() a = int(a) b = int(b) if (op == '+'):print(a + b) elif (op == '-'):print(a - b) elif (op == '*'):print(a * b) elif (op == '/'):print(int(a / b)) elif (op == '?'):break
1
679,278,668,762
null
47
47
count = int(raw_input()) arr = map(int, raw_input().split()) arr.reverse() print(" ".join(map(str, arr)))
input() ls = input().split() print(' '.join(reversed(ls)))
1
979,108,234,788
null
53
53
n=int(input()) table=[[0]*n for i in range(60)] for i,v in enumerate(map(int,input().split())): for j in range(60): table[j][n-1-i]=v%2 v//=2 if v==0:break #print(*table,sep='\n') ans=0 mod1,mod2=10**9+7,998244353 mod=mod1 a=1 for t in table: o,z=0,0 for v in t: if v: o+=1 ans=(ans+z*a)%mod else: z+=1 ans=(ans+o*a)%mod a=a*2%mod print(ans)
n = int(input()) a = list(map(int, input().split())) mod = 10 ** 9 + 7 MAX = 60 acc = [0] * MAX ans = [0] * MAX num = a[0] for i in range(MAX): if num & 1: acc[i] = 1 num >>= 1 for i, e in enumerate(a[1:], 1): for j in range(MAX): if e & 1: ans[j] += i - acc[j] acc[j] += 1 else: ans[j] += acc[j] e >>= 1 ans_num = 0 for i, e in enumerate(ans): ans_num += pow(2, i, mod) * e ans_num %= mod print(ans_num)
1
122,386,527,259,542
null
263
263
import sys def m(): d={};input() for e in sys.stdin: if'f'==e[0]:print('yes'if e[5:]in d else'no') else:d[e[7:]]=0 if'__main__'==__name__:m()
n = int(input()) order = [''] * n st = [''] * n for i in range(n): order[i], st[i] = map(str, input().split()) dic = {} for i in range(n): if order[i] == 'insert': dic.setdefault(st[i], 0) else: if st[i] in dic: print('yes') else: print('no')
1
76,146,292,960
null
23
23
import sys input = lambda: sys.stdin.readline().rstrip() h1, m1, h2, m2, k = map(int, input().split()) m = 60 - m1 h1 += 1 m += (h2 - h1)*60 + m2 print(max(0, m - k))
from collections import deque K = int(input()) q = deque() for i in range(1, 10): q.append(i) i = 0 run = [] while i < K: i += 1 x = q.popleft() if x % 10 != 0: q.append(10*x + x%10 - 1) q.append(10*x + x%10) if x % 10 != 9: q.append(10*x + x%10 + 1) run.append(x) print(run[K - 1])
0
null
29,057,076,270,472
139
181
from collections import Counter n = int(input()) s = [input() for i in range(n)] num = Counter(s) mx = max(num.values()) for i in sorted(num): if num[i] == mx: print(i)
import collections N = int(input()) S_list = [] for i in range(N): s = input() S_list.append(s) c = collections.Counter(S_list) c_max = c.most_common() max_num = c.most_common()[0][1] ans_list = [] ans_list.append(c.most_common()[0][0]) for i in range(1, len(c_max)): if c_max[i][1] != max_num: break else: ans_list.append(c_max[i][0]) print(*sorted(ans_list), sep='\n')
1
70,304,452,604,188
null
218
218
def input_array(): return list(map(int,input().split())) n=int(input()) D=[input_array() for i in range(n)] count=0 for d in D: if d[0]==d[1]: count+=1 else: count=0 if count==3: break if count==3: print("Yes") else: print("No")
N = int(input()) 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 add(X): counter = 0 while True: if counter * (counter + 1) <= X * 2: counter += 1 else: counter -= 1 break # print(X, counter) return counter facts = factorization(N) answer = 0 for f in facts: if f[0] != 1: answer += add(f[1]) print(answer)
0
null
9,732,554,237,950
72
136
n = int(input()) S = input() a = ord('A') z = ord('Z') ans = '' for s in S: if ord(s) + n <= 90: ans += chr(ord(s) + n) else: ans += chr(a + ord(s) + n - z - 1) print(ans)
n = int(input()) s = list(input()) for i, char in enumerate(s): x = ord(char) + n if x > 90: x = x - 90 + 64 s[i] = chr(x) print("".join(s))
1
134,600,244,569,768
null
271
271
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# N,K = getNM() ans = 0 rec = [0] * (K + 1) for X in range(K, 0, -1): rec[X] = pow(K//X, N, mod) for i in range(2, K // X + 1): rec[X] -= rec[i * X] % mod ans += (X * rec[X]) % mod print(ans % mod)
class Dice: def __init__(self, ary): # [top, front, right, left, back, bottom] self.__top = ary[0] self.__fro = ary[1] self.__rit = ary[2] self.__lft = ary[3] self.__bak = ary[4] self.__btm = ary[5] def turn_e(self): # 右に転がる self.__top, self.__lft, self.__btm, self.__rit = \ self.__lft, self.__btm, self.__rit, self.__top def turn_s(self): # 手前に転がる self.__top, self.__fro, self.__btm, self.__bak = \ self.__bak, self.__top, self.__fro, self.__btm def turn_w(self): # 左に転がる self.__top, self.__lft, self.__btm, self.__rit = \ self.__rit, self.__top, self.__lft, self.__btm def turn_n(self): # 奥に転がる self.__top, self.__fro, self.__btm, self.__bak = \ self.__fro, self.__btm, self.__bak, self.__top def spin_r(self): # 右回転 self.__rit, self.__fro, self.__lft, self.__bak = \ self.__bak, self.__rit, self.__fro, self.__lft def spin_l(self): # 左回転 self.__rit, self.__fro, self.__lft, self.__bak = \ self.__fro, self.__lft, self.__bak, self.__rit def is_same_setting(self, ary): # 同じように置いているか if self.__top == ary[0] and self.__fro == ary[1] and self.__rit == ary[2] and \ self.__lft == ary[3] and self.__bak == ary[4] and self.__btm == ary[5]: return True def is_same_dice(self, ary): # 回転させて同じダイスになるか is_same = False for _ in range(2): for _ in range(3): for _ in range(4): if self.is_same_setting(ary): is_same = True self.spin_r() self.turn_n() self.spin_r() self.turn_s() return is_same def show_top(self): # 上面の値を表示 return self.__top surfaces = list(map(int,input().split())) instructions = list(input()) dice = Dice(surfaces) for inst in instructions: if inst == "E": dice.turn_e() if inst == "N": dice.turn_n() if inst == "S": dice.turn_s() if inst == "W": dice.turn_w() print(dice.show_top())
0
null
18,529,814,239,328
176
33
import sys import math lines = sys.stdin.readlines() # print(lines) n = int(lines[0].rstrip()) heights = [int(x) for x in lines[1].rstrip().split()] # print(heights) tot = 0 for i in range(n-1): if heights[i] <= heights[i+1]: continue else: diff = heights[i] - heights[i+1] heights[i+1] += diff tot += diff print(tot)
import sys def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) for line in sys.stdin: line = line.strip() if line == "": break X = int(line) ans = 360 // gcd(X, 360) print(ans)
0
null
8,891,268,722,570
88
125
s=input() n=len(s) d=[0]*2019 d[0]=1 j=1 ans=0 now=0 for i in s[::-1]: now=(now+int(i)*j)%2019 ans+=d[now] d[now]+=1 j*=10 j%=2019 print(ans)
s=input()[::-1] n=len(s) p=2019 S=[0 for i in range(n+1)] ans=[0]*p x10=1 for j, i in enumerate(s): S[j+1]=(S[j]+(x10*int(i)))%p x10*=10 x10%=p ans[S[j+1]]+=1 cnt=ans[0] for a in ans: cnt+=(a*(a-1))//2 print(cnt)
1
30,884,047,688,768
null
166
166
X = int(input()) for a in range(-118,119): for b in range(-119,118): if a**5 - b**5 == X: break else: continue break print(str(a)+" "+str(b))
import sys n = int(input()) for a in range(-200, 201): for b in range(-200, 201): if a * a * a * a * a - b * b * b * b * b == n: print(a, b) sys.exit(0)
1
25,515,948,911,386
null
156
156
n,m=map(int,input().split()) q=[list(map(int,input().split())) for _ in range(m)] for i in range(10**n): i=str(i) if len(i)!=n: continue f=1 for j in q: if i[j[0]-1]!=str(j[1]): f=0 break if f: print(i) exit() print("-1")
x = int(input()) t = False if x >= 30: t = True if t == True: print('Yes') else: print('No')
0
null
33,223,042,347,550
208
95
while True: H,W= map(int, input().split()) if H==0 and W==0: break s = "#" a = H b = "." for i in range(H): if 1<a<H: y = s+b*(W-2)+s print(y) a-=1 elif a==H or a==1: x = s*W print(x) a-=1 print("")
while True: H,W = [int(i) for i in input().split()] if H == 0 and W == 0: break else: for line in list(range(1,H+1,1)): for column in list(range(1,W+1,1)): if line == 1 or line == H: if column == W: print("#") else: print("#", end = "") else: if column == 1: print("#", end = "") elif column == W: print("#") else: print(".", end = "") print("")
1
802,425,016,008
null
50
50
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------- fast io -------------------- from math import gcd, ceil def pre(s): n = len(s) pi = [0] * n for i in range(1, n): j = pi[i - 1] while j and s[i] != s[j]: j = pi[j - 1] if s[i] == s[j]: j += 1 pi[i] = j return pi def prod(a): ans = 1 for each in a: ans = (ans * each) return ans def lcm(a, b): return a * b // gcd(a, b) def binary(x, length=16): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def solve(h, w, k, board): ans = 0 for row in range(1 << h): for col in range(1 << w): count = 0 for i in range(h): for j in range(w): if (row >> i) & 1 == 0: continue if (col >> j) & 1 == 0: continue if board[i][j] == '#': count += 1 if count == k: ans += 1 return ans h, w, k = map(int, input().split()) board = [] for i in range(h): board += [list(input())] print(solve(h, w, k, board))
from itertools import combinations h,w,k = map(int,input().split()) mat = [input() for i in range(h)] r = [0 for i in range(h)] c = [0 for i in range(w)] black = 0 for i in range(h): for j in range(w): if mat[i][j]=="#": r[i] += 1 c[j] += 1 black += 1 ans = 0 for i in range(h): for combr in combinations(range(h),i): for j in range(w): for combc in combinations(range(w),j): temp = 0 for x in combr: temp += r[x] for y in combc: temp += c[y] overlap = 0 for x in combr: for y in combc: if mat[x][y]=="#": overlap += 1 if black+overlap-temp==k: ans += 1 print(ans)
1
8,933,304,031,638
null
110
110
n_1=input() n_1_List=map(int,raw_input().split()) n_2=input() n_2_List=map(int,raw_input().split()) n_1_List=set(n_1_List) n_2_List=set(n_2_List) print(len(n_1_List.intersection(n_2_List)))
#!/usr/bin/env python3 import sys sys.setrecursionlimit(1000000) from collections import deque # 整数の入力 a = int(input()) print(a+a**2+a**3)
0
null
5,191,099,685,952
22
115
def cgd(x,y): while(True): r=x%y if r==0: m=y break x=y y=r return m a,b=map(int,input().split()) if a>b: m=cgd(a,b) elif a<b: m=cgd(b,a) else: m=a print(m)
inp = map(int, raw_input().split()) x = max(inp) y = min(inp) while True: r = x % y x = y y = r if y == 0: break print x
1
8,415,476,700
null
11
11
n, m = map(int, input().split()) lis = sorted(list(map(int, input().split())), reverse=True) limit = sum(lis) / (4 * m) judge = 'Yes' for i in range(m): if lis[i] < limit: judge = 'No' break print(judge)
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)
0
null
67,171,888,050,050
179
242
N=int(input()) s=input() ans=s.count('ABC') print(ans)
#65 import math while True: n=int(input()) if n==0: break s=list(map(int,input().split())) m=sum(s)/n a=0 for i in range(n): a+=(s[i]-m)**2 b=math.sqrt(a/n) print(b)
0
null
49,836,435,061,672
245
31
n = int(input()) for i in range(1,10): if n // i == n/i and n//i in range(1,10): print('Yes') break else: print('No')
N = int(input()) for i in range(1,10): if N % i == 0 and 1<=N/i<=9: print('Yes') break elif i == 9: print('No') # break:その後の処理を行わない。
1
159,853,953,102,168
null
287
287
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] z = input() n = int(z) - 1 print(l[n])
i = 1 while True: factor = input() if factor == '0': break print('Case ', i, ': ', factor, sep='') i += 1
0
null
25,322,828,099,370
195
42
x, y, a, b, c = map(int, input().split()) list_A = list(map(int, input().split())) list_B = list(map(int, input().split())) list_C = list(map(int, input().split())) list_A.sort(reverse=True) list_B.sort(reverse=True) list_C.sort(reverse=True) list_N = list_A[:x] + list_B[:y] + list_C[:min(c, x + y)] list_N.sort(reverse=True) print(sum(list_N[:x+y]))
A, B = map(int,input().split()) import math c = math.gcd(A,B) d = (A*B) / c print(int(d))
0
null
79,021,953,119,020
188
256
def get_sieve_of_eratosthenes(n): if not isinstance(n, int): raise TypeError("n is int-type.") if n < 2: raise ValueError("n is more than 2") data = [i for i in range(2, n + 1)] for d in data: data = [x for x in data if (x == d or x % d != 0)] return data p_list = get_sieve_of_eratosthenes(10**3) def factorization_counta(n): arr = [] temp = n for i in p_list: if i * i > n: break elif temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append(cnt) if temp != 1: arr.append(1) if arr == []: arr.append(1) return arr def main(): N = int(input()) ans = 1 for c in range(2, N): p = factorization_counta(c) tmp = 1 for v in p: tmp *= (v + 1) ans += tmp return ans if __name__ == '__main__': print(main())
apex = ((1,2,3), (1,4,2), (1,5,4), (1,3,5), (2,1,4), (2,3,1), (2,6,3), (2,4,6), (3,1,2), (3,5,1), (3,6,5), (3,2,6), (4,1,5), (4,2,1), (4,6,2), (4,5,6), (5,3,6), (5,1,3), (5,4,1), (5,6,4), (6,3,2), (6,5,3), (6,4,5), (6,2,4) ) dice = {} label = [] label[:] = map(int,input().split()) #print('label: {}'.format(label)) for i in range(0,6): dice[label[i]] = i+1 #print('dice: {}'.format(dice)) q = int(input()) for _ in range(0,q): numbers = [] numbers[:] = map(int,input().split()) right = 0 for t in apex: if (t[0] == dice[numbers[0]] and t[1] == dice[numbers[1]]): right = t[2] #print('{} {} {}'.format(t[0],t[1],t[2])) break for key, n in dice.items(): if (n == right): print(key) break
0
null
1,449,128,583,110
73
34
N=int(input()) L=list(map(int,input().split())) A=1 if 0 in L: print(0) exit() for i in range(N): A=A*L[i] if 10**18<A: print(-1) exit() if 10**18<A: print(-1) else: print(A)
n = int(input()) a = list(map(int, input().split())) m = 1 if 0 in a: print(0) else: for i in range(n): m = m * a[i] if m > 10 ** 18: print(-1) break elif i == n - 1: print(m)
1
16,027,620,985,980
null
134
134
N=int(input()) a=[0]*10**4 for j in range(1,101): for k in range(1,101): for h in range(1,101): tmp=h**2+j**2+k**2+h*j+j*k+k*h if tmp<=10000: a[tmp-1]+=1 for i in range(N): print(a[i])
n = int(input()) import math N = math.ceil(math.sqrt(n)) from collections import defaultdict counter = defaultdict(int) from collections import defaultdict counter = defaultdict(int) for x in range(1,N + 1): answer_x = x * x for y in range(x, N + 1): answer_y = answer_x + y * y + x * y if answer_y > n: continue for z in range(y, N + 1): answer_z = answer_y + z * z + x * z + y * z if answer_z <= n: if x == y and x == z: counter[answer_z] += 1 elif x == y or x == z or y == z: counter[answer_z] += 3 else: counter[answer_z] += 6 for i in range(1,n+1): print(counter[i])
1
7,941,942,780,138
null
106
106
N, K = [int(_) for _ in input().split()] P = [int(_) - 1 for _ in input().split()] C = [int(_) for _ in input().split()] def f(v, K): if K == 0: return 0 if max(v) < 0: return max(v) n = len(v) X = [0] for i in range(n): X.append(X[-1] + v[i]) ans = -(10 ** 10) for i in range(n + 1): for j in range(i): if i - j > K: continue ans = max(ans, X[i] - X[j]) return(ans) X = [False for _ in range(N)] ans = -(10 ** 10) for i in range(N): if X[i]: continue t = i v = [] while X[t] is False: X[t] = True v.append(C[t]) t = P[t] n = len(v) if K > n: s = sum(v) x = f(v * 2, n) if s > 0: a = s * (K // n - 1) + max(s + f(v * 2, K % n), x) else: a = x else: a = f(v * 2, K) ans = max(a, ans) print(ans)
n,m,k = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) t = sum(b) ans = 0 j = m for i in range(n+1): while j > 0 and t>k: j -= 1 t -= b[j] if t>k: break ans = max(ans, i+j) if i==n: break t += a[i] print(ans)
0
null
8,119,558,308,200
93
117
X = int(input()) c = X // 100 if c * 100 <= X <= c * 105: print(1) else: print(0)
# coding=utf-8 import sys n, q = map(int, sys.stdin.readline().split()) queue = [] total_time = 0 finished_loop = 0 for i in range(n): name, time = input().split() queue.append([name, int(time)]) while queue: n -= finished_loop finished_loop = 0 for i in range(n): poped = queue.pop(0) name = poped[0] time = poped[1] if time > q: queue.append([name, time - q]) total_time += q else: total_time += time print(name, total_time) finished_loop += 1
0
null
63,873,079,710,058
266
19
base = input().split() if int(base[0])*500 >= int(base[1]): print("Yes") else: print("No")
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): K, X = map(int, readline().split()) if 500 * K >= X: print('Yes') else: print('No') if __name__ == '__main__': main()
1
98,208,581,422,270
null
244
244
import numpy as np def main(): n = int(input()) x = np.arange(n + 1) x[x % 3 == 0] = 0 x[x % 5 == 0] = 0 print(x.sum()) if __name__ == '__main__': main()
n = int(input()) answer = 0 for i in range(1, n + 1): if i % 3 == 0 or i % 5 == 0: i = 0 else: answer = answer + i print(answer)
1
34,869,056,754,880
null
173
173
from collections import deque import sys n = int(sys.stdin.readline()) #lines = sys.stdin.readlines() lines = [input() for i in range(n)] deq = deque() for i in range(n): o = lines[i].split() if o[0] == 'insert': deq.appendleft(o[1]) elif o[0] == 'delete': try: deq.remove(o[1]) except: continue elif o[0] == 'deleteFirst': deq.popleft() elif o[0] == 'deleteLast': deq.pop() print(' '.join(deq))
from collections import deque n=int(input()) commands=[input().split() for i in range(n)] List=deque() for list_command in commands: if 'insert' in list_command: List.appendleft(list_command[1]) elif 'delete' in list_command: try: List.remove(list_command[1]) except: pass elif 'deleteFirst' in list_command: List.popleft() elif 'deleteLast' in list_command: List.pop() print(*List)
1
51,423,476,842
null
20
20
print("0" if input()=="1" else "1")
n = int(input()) if n == 0: print(1) if n == 1: print(0)
1
2,968,197,148,700
null
76
76
s = int(input()) mod = 10**9+7 dp = [0]*(s+1) dp[0] = 1 for i in range(1,s+1): for j in range(0,(i-3)+1): dp[i] += dp[j] dp[i] %= mod print(dp[s])
import math mod = 10**9+7 N = int(input()) M = math.ceil(N/3)+1 x = [[0]*(N+1) for _ in range(M)] for i in range(3,N+1): x[1][i] = 1 for i in range(2,M): for j in range(i*3,N+1): x[i][j] = (x[i][j-1] + x[i-1][j-3]) % mod ans = 0 for i in range(1,M): ans = (ans + x[i][N]) % mod print(ans)
1
3,281,161,564,000
null
79
79
n=int(input()) s=str(input()) if n<=2: print(0) exit() r=s.count('R') g=s.count('G') b=s.count('B') ans=r*g*b for i in range(n-2): for j in range(i+1,n-1): if 2*j-i>n-1: break if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]: ans-=1 print(ans)
n = int(input()) s = input() total = 1 for c in 'RGB': total *= s.count(c) for i in range(1, n - 1): for j in range(1, min(i + 1, n - i)): if s[i] != s[i - j] and s[i - j] != s[i + j] and s[i] != s[i + j]: total -= 1 print(total)
1
36,062,502,774,880
null
175
175
K = int(input()) S = input() print(S if len(S) <= K else S[:K] + '...')
K = int(input())#asking lenght of string wanted to be shorted S = input()#asking string if len(S)>K:##set that S must be greater than K print (S[:K], "...",sep="")# to print only the K number of the string else: print (S)
1
19,726,021,169,718
null
143
143
t = str(input()) ans = t.replace("?","D") print(ans)
N,M = map(int,(input().split())) s = list(input()) s.reverse() now = 0 me = [] flag = 0 while now != N: for i in range(1,M+1,)[::-1]: if now + i <= N and s[now+i] == "0": now += i me.append(i) break else: print(-1) flag = 1 break if flag == 0: me.reverse() print(*me)
0
null
78,932,625,441,990
140
274
import math r=input() print "%.9f"%(math.pi*r*r), math.pi*r*2
# -*- coding: utf-8 -*- import sys import os import math PI = math.pi r = float(input()) s = r * r * PI l = 2 * PI * r print(s, l)
1
646,225,240,588
null
46
46
d,t,s=map(int,input().split()) if(d<=t*s): print("Yes") else: print("No")
a = int(input()) calc = (a) + (a**2) + (a**3) print(calc)
0
null
6,847,636,857,152
81
115
s = input() t = input() slist = list(s) tlist = list(t) count = 0 if len(slist)+1 == len(tlist): for i in range(len(slist)): if slist[i] == tlist[i]: count += 1 if count ==len(slist): print("Yes") else: print("No") break else: print("No")
import math import collections #2,4,5,7,9 hon #0,1,6,8 pon #3, bon N = int(input()) a = N%10 B = [0,1,6,8] if a == 3: print('bon') elif a in B: print('pon') else: print('hon')
0
null
20,361,958,095,808
147
142
N = int(input()) X = list(map(int, input().split())) ans = 1000000000 for i in range(1, max(X)+1): l = 0 for j in range(N): l += (i - X[j]) ** 2 ans = min(ans, l) print(ans)
from itertools import permutations as perm N = int(input()) XYS = [list(map(int, input().split())) for _ in range(N)] s = 0 for indexes in perm(list(range(N))): xys = [XYS[i] for i in indexes] x0, y0 = xys[0] for x1, y1 in xys: s += ((x0 - x1)**2 + (y0 - y1)**2) ** 0.5 x0 = x1 y0 = y1 nf = 1 for i in range(1, N+1): nf *= i ans = s / nf print(ans)
0
null
107,140,896,012,388
213
280
n = int(input()) t_point = h_point = 0 for i in range(n): t_card,h_card = [x for x in input().split( )] if t_card > h_card: t_point += 3 elif t_card < h_card: h_point += 3 else: t_point += 1 h_point += 1 print(t_point,h_point)
S = input() T = input() print('Yes' if T.startswith(S) else 'No')
0
null
11,787,079,493,930
67
147
x,n= map(int,input().split()) p = list(map(int,input().split())) ans,i = 0,0 while True: if x-i not in p: ans = x-i break if x+i not in p: ans = x+i break i = i+1 print(ans)
def main(): x, n = map(int, input().split()) arr = set(list(map(int, input().split()))) for d in range(0, 1000): for m in range(-1, 2, 2): y = x + m * d if y not in arr: print(y) return main()
1
14,122,857,449,370
null
128
128
N = int(input()) A = list(map(int, input().split())) Q = int(input()) B = [] C = [] for q in range(Q): b, c = map(int, input().split()) B.append(b) C.append(c) sam = sum(A) baketu = [0]*(100001) for a in A: baketu[a] += 1 for q in range(Q): sam = sam + baketu[B[q]] * (C[q] - B[q]) baketu[C[q]] += baketu[B[q]] baketu[B[q]] = 0 #print(baketu) print(sam)
import collections def main(): n = int(input()) a = list(map(int, input().split())) q = int(input()) a_dict = collections.Counter(a) a_dict = {key: key*value for key, value in a_dict.items()} answer = sum(a_dict.values()) for _ in range(q): b, c = map(int, input().split()) diff = 0 if b in a_dict: b_sum = a_dict.pop(b) c_add = b_sum//b * c diff = c_add - b_sum if c in a_dict: a_dict[c] += c_add else: a_dict[c] = c_add answer += diff print(answer) if __name__ == '__main__': main()
1
12,197,187,234,540
null
122
122
# 解説を参考に作成 # import sys # sys.setrecursionlimit(10 ** 6) # import bisect # from collections import deque import math # from decorator import stop_watch # # # @stop_watch def solve(N, K, As): ans = max(As) l, r = 1, ans for _ in range(30): m = (l + r) // 2 cnt = 0 for A in As: cnt += math.ceil(A / m) - 1 if cnt <= K: ans = min(ans, m) r = m - 1 else: l = m + 1 if l > r: break print(ans) if __name__ == '__main__': # S = input() # N = int(input()) N, K = map(int, input().split()) As = [int(i) for i in input().split()] # Bs = [int(i) for i in input().split()] solve(N, K, As)
import math def check(A, x, k): cut_count = 0 for number in A: cut_count += (math.ceil(number / x)) -1 return cut_count <= k n, k = map(int,input().split()) a = list(map(int, input().split())) ans = 0 l = 0 r = 10 ** 9 while r - l > 1: x = (r + l) // 2 if check(a, x, k): r = x else: l = x print(r)
1
6,475,245,487,844
null
99
99
import collections N=int(input()) S=[""]*N for i in range(N): S[i]=input() print(len(collections.Counter(S)))
n = int(input()) print(len(set([input() for i in range(n)])))
1
30,365,975,035,572
null
165
165
s = input() n = len(s) + 1 A = [0] * n for i in range(1, n): if s[i - 1] == "<": A[i] = A[i - 1] + 1 for i in range(n - 1, 0, -1): if s[i - 1] == ">": A[i - 1] = max(A[i - 1], A[i] + 1) print(sum(A))
s = input() def addAll(end): return (end * (end + 1)) // 2 total = 0 index = 0 while len(s) > index: leftCount = 0 rightCount = 0 while len(s) > index and s[index] == "<": leftCount += 1 index += 1 while len(s) > index and s[index] == ">": rightCount += 1 index += 1 maxCount = max(leftCount, rightCount) minCount = min(leftCount, rightCount) total += addAll(maxCount) + addAll(max(minCount - 1, 0)) print(total)
1
155,955,254,378,320
null
285
285
import math A, B = [i for i in input().split()] A = int(A) tmp = B.split('.') B = 100 * int(tmp[0]) + int(tmp[1]) print((A*B)//100)
from decimal import Decimal a, b = map(str, input().split()) a = int(a) b = Decimal(b) print(int(a * b))
1
16,487,404,515,740
null
135
135
w = str(input()) s = [] for k in(list(w)): s.append(k) if s[2] == s[3]: if s[4] == s[5]: print("Yes") else: print("No") else: print("No")
chars = [c for c in input()] print('Yes' if chars[2] == chars[3] and chars[4] == chars[5] else 'No')
1
42,106,542,914,600
null
184
184
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if abs(a - b) - (v - w)*t <= 0: print("YES") else: print("NO")
N = int(input()) A = list(map(int,input().split())) ans = 1000 for i in range(N-1): if A[i] < A[i+1]: ans += ans // A[i] * (A[i+1] - A[i]) print(ans)
0
null
11,298,799,625,672
131
103
def mpow(a,b,m): ans=1 while b >0 : if b&1: ans = (ans*a)%m a=(a*a)%m b=b>>1 return ans def calcmod(X,m,N): mod=0 X=X[::-1] # print(X) for i in range(N): if X[i] == '1': # if X & (1<<i) >0: mod += mpow(2,i,m) mod%=m return mod def popcount(m): return bin(m).count("1") def findsteps(mm): cnt=0 while mm !=0: cnt+=1 mm=mm%popcount(mm) return cnt N=int(input()) x=input() X=int(x,2) ##we need to find X%(m-1) and X%(m+1) m=popcount(X) m1=m+1 m2=m-1 firstmod=calcmod(x,m1,N) if m2 !=0: secondmod=calcmod(x,m2,N) fans=[0 for i in range(N)] k=0 for i in range(N-1,-1,-1): if X & (1<<i) >0: ##the bit was set ##we need to find X%(m-1) - (2^i)%(m-1) if m2 == 0: ans=0 else: mm=secondmod - mpow(2,i,m2) if mm < 0: mm+=m2 mm=mm%m2 ans=1+findsteps(mm) else: mm = firstmod + mpow(2,i,m1) mm=mm%m1 ans=1+findsteps(mm) fans[k] = ans k+=1 ##the bit was not set for i in fans: print(i)
def solve(n,m): if not n:return 1 n%=m return-~solve(n,bin(n).count('1')) n=int(input()) s=input() a=int(s,2) *x,=map(int,s) h=sum(x) try:a,b=a%(h-1),a%(h+1) except:b=a%(h+1) for i in range(n): if x[i]: if not h-1: print(0) continue x[i]=0 t=(a-pow(2,~i+n,h-1))%(h-1) else: x[i]=1 t=(b+pow(2,~i+n,h+1))%(h+1) r=solve(t,bin(t).count('1')) x[i]^=1 print(r)
1
8,291,504,941,252
null
107
107
N ,D = map(int , input().split()) sum = 0 for i in range(N): a,b = map(int , input().split()) if(((a ** 2 + b ** 2)**(1/2)) <= D): sum += 1 print(sum)
S = input() L = len(S) for i in range((L-1)//2): if S[i] != S[L-1-i]: print("No") exit() for i in range((L-1)//4): if S[i] != S[(L-1)//2-1-i]: print("No") exit() for i in range(L-1, L - (L-1)//4, -1): if S[i] != S[i - (L-1)//2-1]: print("No") exit() print("Yes")
0
null
26,015,118,564,400
96
190
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()
import sys def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 wn, wm, wwl = list(map(int, input().rstrip('\n').split())) inf = 10 ** 13 wl = [[inf] * wn for _ in range(wn)] for i in range(wn): wl[i][i] = 0 for i in range(wm): wa, wb, wc = list(map(int, input().rstrip('\n').split())) wl[wa - 1][wb - 1] = wc wl[wb - 1][wa - 1] = wc for i in range(wn): for j in range(wn): for k in range(wn): wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k]) nwl = [[inf] * wn for _ in range(wn)] for i in range(wn): for j in range(wn): if wl[i][j] <= wwl: nwl[i][j] = 1 for i in range(wn): for j in range(wn): for k in range(wn): nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k]) q = int(input().rstrip('\n')) for i in range(q): s, t = list(map(int, input().rstrip('\n').split())) print(nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1) if __name__ == '__main__': solve()
1
173,970,971,254,432
null
295
295
import os, sys, re, math (N, K) = [int(n) for n in input().split()] H = [int(n) for n in input().split()] print(len(list(filter(lambda h: h >= K, H))))
n, k = map(int, input().split()) h = list(map(int, input().split())) ans = len([i for i in h if i >= k]) print(ans)
1
179,379,955,667,650
null
298
298
N, A, B = map(int, input().split()) d = B-A if d%2 == 1: d = min((B + (N-B)*2 + 1) - A, B - (A - (A-1)*2 - 1)) ans = d//2 print(ans)
n,a,b = map(int, input().split()) if a%2==b%2: print((b-a)//2) exit() print(min(a-1,n-b) +1+ (b-a-1)//2)
1
109,718,012,179,778
null
253
253
def judge(): cnt = 0 for _ in range(N): x, y = map(int, input().split()) if x == y: cnt += 1 else: cnt = 0 if cnt == 3: return True return False N = int(input()) if judge(): print("Yes") else: print("No")
n,inc,dec=int(input()),[],[] for _ in range(n): s,d,r=input(),0,0 for c in s: d=d+(1 if c=='(' else -1) r=max(r,-d) (dec if d<0 else inc).append((d,r)) inc.sort(key=lambda x:x[1]) dec.sort(key=lambda x:x[0]+x[1]) p1,p2,ok=0,0,True for s in inc: ok&=s[1]<=p1 p1+=s[0] for s in dec: ok&=p2>=s[0]+s[1] p2-=s[0] ok&=p1==p2 print('Yes'if ok else'No')
0
null
13,039,717,657,318
72
152
H, W = map(int, input().split()) S = [] for _ in range(H): S.append(input()) import queue, itertools dxy = ((1,0), (-1,0), (0,1), (0,-1)) ans = 0 for s in itertools.product(range(H), range(W)): if S[s[0]][s[1]] == '#': continue q = queue.Queue() dist = [[-1]*W for _ in range(H)] q.put(s) dist[s[0]][s[1]] = 0 while not q.empty(): y, x = q.get() for dx, dy in dxy: nx, ny = x+dx, y+dy if nx<0 or ny<0 or nx>=W or ny>=H or S[ny][nx] == '#' or dist[ny][nx] >= 0: continue dist[ny][nx] = dist[y][x] + 1 q.put((ny, nx)) ans = max(ans, max(map(max, dist))) print(ans)
from collections import deque import copy H, W = map(int, input().split()) maze = [list(input()) for _ in range(H)] # すべての.についてスタート地点と仮定してBFS def bfs(i, j): dq = deque() maze_c = copy.deepcopy(maze) maze_c[i][j] = 0 dq.appendleft([i, j]) res = 0 while len(dq) > 0: ni, nj = dq.pop() if maze_c[ni][nj] == "#": continue for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)): if ni + di < 0 or nj + dj < 0 or ni + di >= H or nj + dj >= W: continue if maze_c[ni + di][nj + dj] == ".": maze_c[ni + di][nj + dj] = maze_c[ni][nj] + 1 res = max(res, maze_c[ni + di][nj + dj]) dq.appendleft([ni + di, nj + dj]) return res ans = 0 for i in range(H): for j in range(W): if maze[i][j] == ".": ans = max(ans, bfs(i, j)) print(ans)
1
94,491,358,717,540
null
241
241
import math import sys input = sys.stdin.readline def isPrime(n): i = 2 flag = True while i * i <= n: if n % i == 0: flag = False break else: i += 1 return flag x = int(input()) while True: if isPrime(x): print(x) break else: x += 1
for val in range(input()): x = map(int,raw_input().split(' ')) x.sort() if x[0]**2+x[1]**2==x[2]**2: print 'YES' else: print 'NO'
0
null
52,899,169,193,660
250
4
s=raw_input() target=raw_input() ring=s+s[0:len(target)] f=0 for i in range(len(s)): if ring[i:i+len(target)]==target: f=1 break if f==1: print "Yes" else: print "No"
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()
0
null
48,571,459,640,572
64
242
s = list(input()) if s[-1] == 's': s.append('es') else: s.append('s') print(''.join(s))
# # 179A # s = input() s1 = list(s) if s1[len(s)-1]=='s': print(s+'es') else: print(s+'s')
1
2,376,760,318,208
null
71
71
def main(): x = int(input()) for A in range(-118,120): for B in range(-119,119): if (A**5 - B**5) == x: return([A,B]) ans = main() print(' '.join(str(n) for n in ans))
import numpy as np X = int(input()) def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] div = make_divisors(X) for i in range(len(div)): x = div[i] z = x**4 - X/x if z%5 == 0: s = z / 5 if x**4 - 4*s >=0: y1 =( -x**2 + np.sqrt(x**4 - 4 * s)) / 2 y2 =( -x**2 - np.sqrt(x**4 - 4 * s)) / 2 B1 = (-x + np.sqrt(x**2 + 4*y1))/2 if B1.is_integer(): B = B1 A = B + x break B12 = (-x + np.sqrt(x**2 + 4*y2))/2 if B12.is_integer(): B = B12 A = B + x break B2 = (-x - np.sqrt(x**2 + 4*y1))/2 if B2.is_integer(): B = B2 A = B + x break B21 = (-x - np.sqrt(x**2 + 4*y2))/2 if B21.is_integer(): B = B21 A = B + x break print(int(A),int(B))
1
25,608,190,900,112
null
156
156
N,M=map(int, input().split()) A=[list(map(int, input().split())) for _ in range(M)] A = sorted(A, reverse=False, key=lambda x: x[0]) if M==0: if N==3: print(100) exit(0) elif N==2: print(10) exit(0) elif N==1: print(0) exit(0) if N!=1 and A[0][0]==1 and A[0][1]==0: print(-1) exit(0) i=1 j=len(A) while i<j: if A[i][0]==A[i-1][0] and A[i][1]==A[i-1][1]: A.pop(i) j-=1 continue elif A[i][0]==A[i-1][0] and A[i][1]!=A[i-1][1]: print(-1) exit(0) i+=1 ans=[None]*N for i,j in A: ans[i-1]=j for i in range(len(ans)): if ans[i]==None: if i==0: ans[i]=1 else: ans[i]=0 print(''.join(map(str,ans)))
N, M = map(int, input().split()) lst = [list(map(int, input().split())) for _ in range(M)] ans = [10] * N for l in lst: if ans[l[0]-1] < 10 and ans[l[0]-1] != l[1]: print(-1) exit() ans[l[0]-1] = l[1] if ans[0] == 10: if N == 1: ans[0] = 0 else: ans[0] = 1 for i in range(1, N): if ans[i] == 10: ans[i] = 0 if N != 1 and ans[0] == 0: print(-1) exit() ans = list(map(str, ans)) print("".join(ans))
1
60,947,390,516,030
null
208
208
while True: [H,W]=[int(x) for x in input().split()] if [H,W]==[0,0]: break unit="#." for i in range(0,H): print(unit*(W//2)+unit[0]*(W%2)) unit=unit[1]+unit[0] print("")
while 1: H,W = map(int,input().split()) if H == 0 and W == 0: break col1 = "#." * ((W + 1) // 2) col2 = ".#" * ((W + 1) // 2) print((col1[:W] + "\n" + col2[:W] + "\n") * (H // 2) + (col1[:W] + "\n") * (H % 2))
1
880,760,692,032
null
51
51
icase=0 if icase==0: a,b=map(int,input().split()) print(max(a-2*b,0))
A, B = [int(n) for n in input().split()] print(max(0, int(A-2*B)))
1
167,153,382,631,432
null
291
291
N = int(input()) S = input() ans = 0 for i in range(0, 1000): if 0 <= i and i <= 9: num = "00"+str(i) elif 10 <= i and i <= 99: num = "0"+str(i) else: num = str(i) num_pos = 0 s_pos = 0 while True: if S[s_pos] == num[num_pos]: num_pos += 1 if num_pos == 3: ans += 1 break s_pos += 1 if s_pos == N: break print(ans)
N,A,B=map(int,input().split()) t=N//(A+B) s=N%(A+B) ans = t*A + min(s,A) print(ans)
0
null
92,571,732,221,528
267
202
n=int(input()) l=list(map(int,input().split())) ans=[0]*n for i in range(len(l)): ans[l[i]-1]=i+1 print(*ans)
n = int(input()) a = list(map(int,input().split())) b = [None] * n for i in range(n): b[a[i]-1] = i+1 for i in range(n): print(b[i],end = ' ')
1
181,316,102,836,228
null
299
299
num = list(map(int,input().split())) num.sort() print("%d %d %d" %(num[0],num[1],num[2]))
import bisect import sys input=sys.stdin.readline n,d,a=map(int,input().split()) l=[list(map(int,input().split())) for i in range(n)] l.sort() data0=[0]*(n+1) data1=[0]*(n+1) def _add(data,k,x): while k<=n: data[k]+=x k+=k&-k def add(l,r,x): _add(data0,l,-x*(l-1)) _add(data0,r,x*(r-1)) _add(data1,l,x) _add(data1,r,-x) def _get(data,k): s=0 while k: s+=data[k] k-=k&-k return s def query(l,r): return _get(data1,r-1)*(r-1)+_get(data0,r-1)-_get(data1,l-1)*(l-1)-_get(data0,l-1) x=[] for i in range(n): x.append(l[i][0]) add(i+1,i+2,l[i][1]) Right=[] for i in range(n): Right.append(bisect.bisect_right(x,x[i]+2*d)) p=0 ans=0 while p<n: Q=query(p+1,p+2) add(p+1,Right[p]+1,-((Q+a-1)//a)*a) ans+=(Q+a-1)//a p=min(p+1,n-1) while query(p+1,p+2)<=0: p+=1 if p==n: break print(ans)
0
null
41,204,768,267,560
40
230
n = int(input()) P = list(map(int,input().split())) k=0 bc=0 c=0 i=0 while k < n : if P[k]!=i+1 : bc+=1 else: i+=1 c+=1 k+=1 if c==0 : bc = -1 print(bc)
x = 0 m_list = [] f_list = [] r_list = [] while x < 50: m, f, r = map(int, input().split()) if m == -1 and f == -1 and r == -1: break m_list.append(m) f_list.append(f) r_list.append(r) x = x+1 for(mlist,flist,rlist) in zip(m_list,f_list,r_list): if mlist == -1 or flist == -1: print("F") elif 80 <= mlist + flist: print("A") elif 65 <= mlist + flist and mlist + flist < 80: print("B") elif 50 <= mlist + flist and mlist + flist < 65: print("C") elif 30 <= mlist + flist and mlist + flist < 50: if 50 <= rlist: print("C") else: print("D") elif mlist + flist < 30: print("F")
0
null
57,801,556,834,092
257
57
X, Y, A, B, C = map(int, input().split()) *p, = map(int, input().split()) *q, = map(int, input().split()) *r, = map(int, input().split()) p.sort(key=lambda x: -x) q.sort(key=lambda x: -x) p = p[:X] q = q[:Y] pqr = p+q+r pqr.sort(key=lambda x: -x) print(sum(pqr[:X+Y]))
import math import sys import collections import bisect readline = sys.stdin.readline def main(): x, y, a, b, c = map(int, input().split()) p = sorted(list(map(int, input().split())), reverse=True)[0:x] q = sorted(list(map(int, input().split())), reverse=True)[0:y] r = sorted(list(map(int, input().split())), reverse=True) pq = sorted((p + q)) for i in range(min(c, (x + y))): if pq[i] > r[i]: break pq[i] = r[i] print(sum(pq)) if __name__ == '__main__': main()
1
44,842,799,357,248
null
188
188
import math def main(): r = int(input()) print(r * math.pi * 2) main()
x=float(input()) p=2*3.14*x A="dlfnsdfjsdjfsdfjsdfnksdkjnfjksndfkjnskjfkjsdkjfnskjdfknsdkjfskdnfkjsdn" print(p)
1
31,501,931,371,358
null
167
167
N, K, C = map(int, input().split()) S = input() must = set() i = len(S)+C for j in range(K): i = S.rindex("o", 0, i-C) must.add(i) if i<=C or "o" not in S[:i-C]: i = -C-1 for j in range(K): i = S.index("o", i+C+1) if i in must: print(i+1)
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush import math #from math import gcd #inf = 10**17 #mod = 10**9 + 7 n,k,c = map(int, input().split()) s = input().rstrip() left = [0]*n day = 0 temp = 0 while day < n: if s[day] == 'o': temp += 1 left[day] = temp for i in range(c): if day+i+1 < n: left[day+i+1] = temp day += c else: left[day] = temp day += 1 right = [0]*n day = n-1 temp = 0 while 0 <= day: if s[day] == 'o': temp += 1 right[day] = temp for i in range(c): if day-i-1 >= 0: right[day-i-1] = temp day -= c else: right[day] = temp day -= 1 res = [] for i in range(n): if s[i] == 'o': if i-c-1 < 0: pre = 0 else: pre = left[i-c-1] if i+c+1 >= n: pos = 0 else: pos = right[i+c+1] if pre + pos == k-1: res.append(i+1) for i in range(len(res)): if i-1>=0: l = res[i-1] else: l = -1000000 if i+1<len(res): r = res[i+1] else: r = 10000000 if res[i]-l>c and r-res[i] > c: print(res[i]) if __name__ == '__main__': main()
1
40,405,122,094,332
null
182
182
a=input() b=int(input()) while b>0: tmp=input().split(" ") if tmp[0]=="replace": a=a[:int(tmp[1])]+tmp[3]+a[int(tmp[2])+1:] if tmp[0]=="reverse": tmp2="".join(list(a)[int(tmp[1]):int(tmp[2])+1])[::-1] a=a[:int(tmp[1])]+tmp2+a[int(tmp[2])+1:] if tmp[0]=="print": print(a[int(tmp[1]):int(tmp[2])+1]) b-=1
str0 = raw_input() q = int(raw_input()) for i in xrange(q): # print "###########################" # print "str0 = " + str0 line = raw_input().split(" ") temp = str0[int(line[1]):int(line[2])+1] if line[0] == "print": print temp elif line[0] == "reverse": temp2 = [] # print "temp = " + temp for j in xrange(len(temp)): temp2.append(temp[len(temp) - j - 1]) str0 = str0[:int(line[1])] + "".join(temp2) + str0[int(line[2]) + 1:] # print "str0 = " + str0 elif line[0] == "replace": str0 = str0[:int(line[1])] + line[3] + str0[int(line[2]) + 1:] # print "str0 = " + str0
1
2,052,656,021,878
null
68
68
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect import heapq # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) a,b = map(decimal.Decimal,input().split()) print(int(a*b))
from decimal import Decimal a, b = map(str, input().split()) a = int(a) b = Decimal(b) print(int(a * b))
1
16,504,498,108,032
null
135
135
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N, K = map(int, input().split()) A = list(map(int, input().split())) ng = 0 ok = 10 ** 9 # able(X) を、すべての丸太を X 以下の長さに切れる場合 1 , そうでない場合 0 を返す関数とする # 二分探索によって、able(X) が 1 に切り替わる X 点を見つける def able(x): count = 0 for i in range(N): if A[i] % x: count += A[i] // x else: count += A[i] // x - 1 if count <= K: return True else: return False while ok - ng > 1: mid = ng + (ok - ng) // 2 if able(mid): ok = mid else: ng = mid print(ok)
import sys n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] l, r = 0, max(a) while r - l > 1: # satisfy l < t < r t = (l + r) // 2 c = sum([(e-1) // t for e in a]) if k < c: l = t else: r = t print(r)
1
6,442,273,540,978
null
99
99
a,b=map(int,input().split()) num=1 while 1: if int(num*0.08)==a and int(num*0.1)==b: print(num) break if int(num*0.08)>a and int(num*0.1)>b: print(-1) break num+=1
from bisect import bisect_left X, N = list(map(int, input().split())) P = list(map(int, input().split())) P.sort() S = set(P) if N == 0: print(X) exit() def bisectsearch_left(L, a): i = bisect_left(L, a) return(i) k = bisectsearch_left(P, X) if X != P[k]: print(X) else: ct = 0 while True: ct += 1 if X-ct not in S: print(X-ct) break elif X+ct not in S: print(X+ct) break
0
null
35,170,113,324,412
203
128
N = int(input()) S = input() ans = S.count("R")*S.count("G")*S.count("B") for i in range(N): for j in range(i+1,N): k = 2*j-i if k<N and S[i]!=S[j]!=S[k]!=S[i]: ans-=1 print(ans)
from itertools import permutations n = int(input()) s = input() out = 0 ans = s.count("R")*s.count("G")*s.count("B") combi = list(permutations(["R","G","B"],3)) for i in range(1,n): for j in range(n-i*2): if (s[j], s[j+i], s[j+i*2]) in combi: ans -= 1 print(ans)
1
36,095,575,959,900
null
175
175
n = int(input()) c = input() d = c.count('R') e = c[:d].count('R') print(d-e)
n = int(input()) a = [int(i) for i in input().split()] a.sort(reverse=True) i = 1 ans = a[0] c = 1 while c < n - 1: k = min(2, n - 1 - c) c += k ans += a[i] * k i += 1 print(ans)
0
null
7,718,748,356,358
98
111
n, k = map(int, input().split()) a = list(map(int, input().split())) def cut(x): cut_count = 0 for i in range(n): cut_count += (a[i]-1)//x return cut_count l = 0 r = 10**9 while r-l > 1: mid = (l+r)//2 if k >= cut(mid): r = mid else: l = mid print(r)
while 1: x=raw_input() if x=='0':break sum=0 for i in x: sum+=int(i) print sum
0
null
3,984,331,972,190
99
62
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,u,v = LI() ab = [LI() for _ in range(n-1)] e = collections.defaultdict(list) for a,b in ab: e[a].append(b) e[b].append(a) def search(s, ea): d = collections.defaultdict(lambda: inf) d[s] = 0 q = [] heapq.heappush(q, (0, s)) v = collections.defaultdict(bool) for u in ea: v[u] = True while len(q): k, u = heapq.heappop(q) if v[u]: continue v[u] = True for uv in e[u]: if v[uv]: continue vd = k + 1 if d[uv] > vd: d[uv] = vd heapq.heappush(q, (vd, uv)) return d du = search(u, []) dv = search(v, []) r = 0 for i in range(n): if du[v] - du[u] < 3: break r += 1 for c in e[u]: if dv[u] > dv[c]: u = c break for c in e[v]: if du[v] > du[c]: v = c break ea = [] t = dv[u] for c in range(1, n+1): if dv[c] < t: ea.append(c) d = search(u, ea) m = max(d.values()) r += m s = t - dv[v] if s > 1: r += 1 return r print(main())
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10 ** 9 + 1 # sys.maxsize # float("inf") MOD = 10 ** 9 + 7 def debug(*x): print(*x, file=sys.stderr) def solve0(N, K, PS, CS): PS = [x - 1 for x in PS] debug(": PS", PS) CS = [CS[PS[i]] for i in range(N)] PSS = [PS] CSS = [CS] prevPS = PS prevCS = CS for i in range(30): PS2 = [prevPS[prevPS[i]] for i in range(N)] CS2 = [prevCS[i] + prevCS[prevPS[i]] for i in range(N)] PSS.append(PS2) CSS.append(CS2) prevPS = PS2 prevCS = CS2 score = [0] * N pos = list(range(N)) length = [0] * N maxbit = K.bit_length() - 1 for i in range(maxbit, -1, -1): # debug(": i", i) # debug(": 2**i", 2**i) # debug(": CSS[i]", CSS[i]) # debug(": PSS[i]", PSS[i]) # debug(": score", score) # debug(": length", length) for j in range(N): # debug(": length[j] + 2 ** i <= K", length[j] + 2 ** i <= K) # debug(": CSS[i][pos[j]]", CSS[i][pos[j]]) if length[j] + 2 ** i <= K and CSS[i][pos[j]] > 0: # debug("add: j", j) score[j] += CSS[i][pos[j]] pos[j] = PSS[i][pos[j]] length[j] += 2 ** i # if CSS[i][j] > score[j]: # # debug("reset: j", j) # # debug(": CSS[i][i], score[j]", CSS[i][i], score[j]) # pos[j] = PSS[i][j] # score[j] = CSS[i][j] # length[j] = 2 ** i # debug("finish: score", score) ret = max(score) if ret == 0: ret = max(CS) return ret def solve(N, K, PS, CS): PS = [x - 1 for x in PS] CS = [CS[PS[i]] for i in range(N)] visited = {} loops = [] loopScore = [] for i in range(N): loop = [] c = 0 while i not in visited: visited[i] = True c += CS[i] i = PS[i] loop.append(i) if loop: loops.append(loop) loopScore.append(c) # debug(": loops", loops) # debug(": loopScore", loopScore) scores = [0] * N pos = list(range(N)) from collections import defaultdict ret = 0 for i, loop in enumerate(loops): if loopScore[i] > 0: baseScore = loopScore[i] * (K // len(loop)) r = K % len(loop) if r == 0: r = len(loop) baseScore -= loopScore[i] # debug("r==0: baseScore", baseScore) maxscore = 0 scores = defaultdict(int) for i in range(r): for x in loop: scores[x] += CS[pos[x]] pos[x] = PS[pos[x]] maxscore = max(maxscore, max(scores.values())) # debug("posi: maxscores", scores) ret = max(maxscore + baseScore, ret) else: r = len(loop) maxscore = -INF scores = defaultdict(int) for i in range(r): for x in loop: scores[x] += CS[pos[x]] pos[x] = PS[pos[x]] # debug("neg: scores", scores) maxscore = max(maxscore, max(scores.values())) ret = max(maxscore, ret) if ret == 0: ret = max(CS) return ret def main(): # parse input N, K = map(int, input().split()) PS = list(map(int, input().split())) CS = list(map(int, input().split())) print(solve(N, K, PS, CS)) # tests T1 = """ 5 2 2 4 5 1 3 3 4 -10 -8 8 """ TEST_T1 = """ >>> as_input(T1) >>> main() 8 """ T2 = """ 2 3 2 1 10 -7 """ TEST_T2 = """ >>> as_input(T2) >>> main() 13 """ T3 = """ 3 3 3 1 2 -1000 -2000 -3000 """ TEST_T3 = """ >>> as_input(T3) >>> main() -1000 """ T4 = """ 10 58 9 1 6 7 8 4 3 2 10 5 695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719 """ TEST_T4 = """ >>> as_input(T4) >>> main() 29507023469 """ T5 = """ 3 1000 2 3 1 1 0 2 """ TEST_T5 = """ >>> as_input(T5) >>> main() 1001 """ T6 = """ 3 1000 2 3 1 1 1 -3 """ TEST_T6 = """ >>> as_input(T6) >>> main() 2 """ T7 = """ 4 1000 2 1 4 3 1 1 -10000 10000 """ TEST_T7 = """ >>> as_input(T7) >>> main() 10000 """ T8 = """ 4 1000 2 1 4 3 1 1 -10000 10001 """ TEST_T8 = """ >>> as_input(T8) >>> main() 10001 """ def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
0
null
61,434,593,018,260
259
93
t = input().split() a = int(t[0]) b = int(t[1]) if a < b : print("a < b") if a == b: print("a == b") if a > b : print("a > b")
import itertools n = int(input()) p = tuple([int(i) for i in input().split()]) q = tuple([int(i) for i in input().split()]) lst = list(itertools.permutations(list(range(1, n + 1)))) print(abs(lst.index(p) - lst.index(q)))
0
null
50,383,605,139,940
38
246
a, b = input().split() c = a a = a*int(b) b = b*int(c) for i in range(len(a)): if a[i]<b[i]: print(a) break elif a==b: print(a) break else: print(b) break
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools, bisect import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def S(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def LR(n): return [L() for _ in range(n)] @lru_cache(maxsize=1024*1024) def fact(n): return math.factorial(n) def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return fact(n) // (fact(r) * fact(n-r)) alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" sys.setrecursionlimit(1000000) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 INF = float("inf") class FactInv: def __init__(self, N, MOD=1000000007): fact, inv = [1]*(N+1), [None]*(N+1) for i in range(1, N+1): fact[i] = fact[i - 1] * i % MOD inv[N] = pow(fact[N], MOD - 2, MOD) for i in range(N)[::-1]: inv[i] = inv[i + 1] * (i + 1) % MOD self.N, self.MOD, self.fact, self.inv = N, MOD, fact, inv def perm(self, a, b): if a > self.N or b > self.N: raise ValueError("\nPermutaion arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b)) return self.fact[a] * self.inv[a-b] % self.MOD def comb(self, a, b): if a > self.N or b > self.N: raise ValueError("\nCombination arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b)) return self.fact[a] * self.inv[b] * self.inv[a-b] % self.MOD def main(): N, K = LI() A = sorted(LI()) factinv = FactInv(N + 1) ans = 0 for i, x in enumerate(A): maxc = factinv.comb(i, K - 1) if i >= K - 1 else 0 minc = factinv.comb(len(A) - i - 1, K - 1) if len(A) - i - 1 >= K - 1 else 0 ans = (ans + x * (maxc - minc)) % MOD print(ans % MOD) if __name__ == '__main__': main()
0
null
89,940,951,332,160
232
242
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools, bisect import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def S(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def LR(n): return [L() for _ in range(n)] alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" sys.setrecursionlimit(1000000) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 def main(): N = I() A = LI() def lcm(a, b): return a * b // math.gcd(a, b) l = reduce(lcm, A, 1) % MOD ans = 0 for ai in A: ans = (ans + l * pow(ai, MOD - 2, MOD)) % MOD print(ans) if __name__ == '__main__': main()
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) INF = float("inf") import bisect N, K = list(map(int, input().split())) a = [0] + list(map(int, input().split())) s = list(itertools.accumulate(a)) # print(s) for i in range(0, N+1): s[i] = (s[i] - i) % K # print(s) d = defaultdict(int) count = 0 for j in range(1,N+1): d[s[j-1]] += 1 if j-K >= 0: d[s[j-K]] -= 1 # print(j,s[j],d) count += d[s[j]] # print(d) print(count)
0
null
112,834,070,269,748
235
273
N=int(input()) A=map(int, input().split()) P=1000000007 ans = 1 cnt = [3 if i == 0 else 0 for i in range(N + 1)] for a in A: ans=ans*cnt[a]%P if ans==0: break cnt[a]-=1 cnt[a+1]+=1 print(ans)
def resolve(): MOD = 1000000007 N = int(input()) A = list(map(int, input().split())) C = [0]*(N+1) C[0] = 3 ans = 1 for i in range(N): a = A[i] ans *= C[a] ans %= MOD C[a] -= 1 C[a+1] += 1 print(ans) if __name__ == "__main__": resolve()
1
130,381,535,114,250
null
268
268
N, R = [int(i) for i in input().split(" ")] if N >= 10: print(R) else: print(R + 100 * (10 - N))
import sys input = sys.stdin.readline def main(): N, R = map(int, input().split()) print(R+100*(10-N)) if N < 10 else print(R) if __name__ == '__main__': main()
1
63,622,692,375,088
null
211
211
import math while True: n = int(input()) if n == 0: break L = list(map(float, input().split())) m = sum(L) / n Sum = 0 for i in range(n): Sum = (L[i]-m)**2 + Sum a = math.sqrt(Sum / n) print(a)
# coding: utf-8 # Your code here! S=list(input()) S=list(map(int,S))[::-1] mod=[0]*2019 mod[0]+=1 ans=0 temp=0 p=1 for i in range(len(S)): temp+=S[i]*p p=p*10%2019 temp%=2019 ans+=mod[temp] mod[temp]+=1 print(ans)
0
null
15,397,181,785,550
31
166
# コッホ曲線 Koch curve import math class Point(): def __init__(self, x, y): self.x = x self.y = y def __repr__(self): return str(self.x) + " " + str(self.y) def Koch(p1, p2, n): if n == 0: print(p1) else: s = Point(p1.x * 2 / 3 + p2.x * 1 / 3, p1.y * 2 / 3 + p2.y * 1 / 3) u = Point(p1.x / 2 + p2.x / 2 + p1.y * r3 / 6 - p2.y * r3 / 6, p1.y / 2 + p2.y / 2 + p2.x * r3 / 6 - p1.x * r3 / 6) t = Point(p1.x * 1 / 3 + p2.x * 2 / 3, p1.y * 1 / 3 + p2.y * 2 / 3) Koch(p1, s, n - 1) Koch(s, u, n - 1) Koch(u, t, n - 1) Koch(t, p2, n - 1) r3 = math.sqrt(3) start = Point(0, 0) goal = Point(100, 0) n = int(input()) Koch(start, goal, n) print(goal)
from collections import namedtuple import math Co = namedtuple('Co', 'x y') def f(i, n, l, r): if i >= n: return il = Co(x=(1/3 * r.x + (1 - 1/3) * l.x), y=(1/3 * r.y + (1 - 1/3) * l.y)) ir = Co(x=(2/3 * r.x + (1 - 2/3) * l.x), y=(2/3 * r.y + (1 - 2/3) * l.y)) trix = 1/2 * (ir.x + il.x - math.sqrt(3) * ir.y + math.sqrt(3) * il.y) triy = 1/2 * (math.sqrt(3) * ir.x - math.sqrt(3) * il.x + ir.y + il.y) trico = Co(trix, triy) f(i+1, n, l, il) print(il.x, il.y) f(i+1, n, il, trico) print(trico.x, trico.y) f(i+1, n, trico, ir) print(ir.x, ir.y) f(i+1, n, ir, r) if __name__ == '__main__': n = int(input()) print(0, 0) f(0, n, Co(0,0), Co(100,0)) print(100, 0)
1
122,606,204,950
null
27
27
cnt = 0 a, b, c = map(int, input().split()) if (a >= 1 and a <= 10000) and (b >= 1 and b <= 10000) and (c >= 1 and c <= 10000): if a <= b: for i in range(a, b+1): if c % i == 0: cnt += 1 print("{0}".format(str(cnt))) else: pass else: pass
def table_composition(N): table = [] i = 1 while i <= N/2: if N%i == 0: table.append(i) i += 1 table.append(N) return table a, b, c = map(int, input().split()) table = table_composition(c) count = 0 for ele in table: if ele >= a and ele <= b: count += 1 print(count)
1
557,811,596,458
null
44
44
N=[] while True: n=raw_input() if n=='0': break N.append(n) for i in range(len(N)): print('%d'%sum(map(int,N[i])))
while True: text = input() if text == '0': break total = 0 for a in range(len(text)): total += int(text[a]) print(total)
1
1,594,527,399,670
null
62
62
N = int(input()) A = [int(a) for a in input().split()] next_target = 1 idx = [] for i, a in enumerate(A): if a == next_target: idx.append(i) next_target += 1 if not idx: print(-1) else: prev = -1 sum_ = 0 if idx[-1] != N - 1: sum_ += N - (idx[-1] + 1) for x in idx: sum_ += x - prev - 1 prev = x print(sum_)
N=int(input()) A=list(map(int,input().split())) ans=[0] cnt=0 hit=0 while cnt<N: if ans[hit]+1==A[cnt]: hit+=1 ans.append(hit) cnt+=1 print(N-len(ans[1:]) if len(ans)>1 else -1)
1
114,543,489,722,048
null
257
257
import os, sys, re, math N = int(input()) A = [int(n) for n in input().split()] A = sorted(A) answer = 'YES' for i in range(1, len(A)): if A[i - 1] == A[i]: answer = 'NO' break print(answer)
H, N = map(int, input().split()) AB = [] for _ in range(N): A, B = map(int, input().split()) AB.append([A, B]) AB = sorted(AB, key=lambda x:x[0], reverse=True) INF = float("inf") dp = [INF for _ in range(H+1)] dp[0] = 0 # DP for i in range(1, H+1): for a, b in AB: if a >= i: dp[i] = min(dp[i], b) continue else: dp[i] = min(dp[i], dp[i-a]+b) print(dp[-1])
0
null
77,321,602,289,712
222
229
n=int(input()) s=input() ans=0 for i in range(10): idx1=s.find(str(i)) for j in range(10): idx2=s.find(str(j),idx1+1,n) for k in range(10): idx3=s.find(str(k),idx2+1,n) if idx1==-1 or idx2==-1 or idx3==-1: continue else: ans+=1 print(ans)
k = int(input()) s = list(input()) an_lis = [] if len(s) <= k: ans = "".join(s) print(ans) else: for i in range(k): an_lis.append(s[i]) an_lis.append("...") ans = "".join(an_lis) print(ans)
0
null
74,063,333,412,028
267
143
s,t,count=input(),input(),0 for i in range(len(s)): if s[i]!=t[i]: count+=1 print(count)
a = input() b = input() c = 0 d = 0 for x in a: if x != b[c]: d += 1 c += 1 print(d)
1
10,510,829,531,968
null
116
116
N = int(input()) A = list(map(int, input().split())) mod = 10**9+7 G = [0]*3 ans = 1 for i in range(N): x = 0 cnt = 0 for j, g in enumerate(G): if g == A[i]: x = j if cnt == 0 else x cnt += 1 G[x] += 1 ans *= cnt ans = ans % mod print(ans)
N=int(input()) S=['A']*N T=[0]*N for i in range(N): s,t=input().split() S[i]=s T[i]=int(t) print(sum(T[S.index(input())+1:]))
0
null
113,278,986,723,360
268
243