code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
list = []
while True:
line = raw_input().split(" ")
if line[0] == "0" and line[1] == "0":
break
line = map(int, line)
#print line
if line[0] > line[1]:
temp = line[0]
line[0] = line[1]
line[1] = temp
print " ".join(map(str, line)) | small = []
large = []
while True:
input_a, input_b = map(int, raw_input().split())
if input_a == 0 and input_b == 0:
break
else:
if input_a < input_b:
small.append(input_a)
large.append(input_b)
else:
small.append(input_b)
large.append(input_a)
for (n, m) in zip(small, large):
print n, m | 1 | 531,200,830,808 | null | 43 | 43 |
class Combinatorics:
def __init__(self, N, mod):
'''
Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
over the finite field Z/(mod)Z.
Input:
N (int): maximum n
mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
'''
self.mod = mod
self.fact = {i: None for i in range(N+1)} # n!
self.inverse = {i: None for i in range(1, N+1)} # inverse of n in the field Z/(MOD)Z
self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
# preprocess
self.fact[0] = self.fact[1] = 1
self.fact_inverse[0] = self.fact_inverse[1] = 1
self.inverse[1] = 1
for i in range(2, N+1):
self.fact[i] = i * self.fact[i-1] % self.mod
q, r = divmod(self.mod, i)
self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
def perm(self, n, r):
'''
Calculate nPr = n! / (n-r)! % mod
'''
if n < r or n < 0 or r < 0:
return 0
else:
return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
def binom(self, n, r):
'''
Calculate nCr = n! /(r! (n-r)!) % mod
'''
if n < r or n < 0 or r < 0:
return 0
else:
return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
def hom(self, n, r):
'''
Calculate nHr = {n+r-1}Cr % mod.
Assign r objects to one of n classes.
Arrangement of r circles and n-1 partitions:
o o o | o o | | | o | | | o o | | o
'''
if n == 0 and r > 0:
return 0
if n >= 0 and r == 0:
return 1
return self.binom(n + r - 1, r)
MOD = 10**9 + 7
N, K = map(int, input().split())
com = Combinatorics(N, MOD)
ans = 0
for i in range(min(K, N-1) + 1):
ans += (com.binom(N, i) * com.hom(N-i, i)) % MOD
ans %= MOD
print(ans) | n,k=map(int,input().split())
mod=10**9+7
def inv(x):
return pow(x,mod-2,mod)
N=2*10**5
Fact=[0 for i in range(N+1)]
Finv=[0 for i in range(N+1)]
Fact[0]=1
for i in range(N):
Fact[i+1]=(Fact[i]*(i+1))%mod
Finv[N]=inv(Fact[N])
for i in range(N-1,-1,-1):
Finv[i]=((i+1)*Finv[i+1])%mod
def C(a,b):
return (Fact[a]*(Finv[b]*Finv[a-b])%mod)%mod
ans=0
for i in range(min(n,k+1)):
ans+=(C(n,i)*C(n-1,i))%mod
ans%=mod
print(ans)
| 1 | 67,143,994,742,552 | null | 215 | 215 |
H, N = map(int, input().split())
dp = [10 ** 9] * (H + 1)
dp[0] = 0
for _ in range(N):
a, b = map(int, input().split())
for i in range(H):
idx = min(H, i + a)
dp[idx] = min(dp[idx], dp[i] + b)
print(dp[H])
| from copy import copy
import random
import math
import sys
input = sys.stdin.readline
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
ps = [0]*26
for j in range(26):
pl = copy(last)
pl[j] = i+1
ps[j] += s[i][j]
for k in range(26):
ps[j] -= c[k]*(i+1-pl[k])
idx = ps.index(max(ps))
last[idx] = i+1
ans[i] = idx+1
score += max(ps)
for k in range(1,35001):
na = copy(ans)
x = random.randint(1,365)
y = random.randint(1,365)
z = random.randint(min(x,y),max(x,y))
na[y-1] = na[x-1]
na[y-1] = na[z-1]
last = [0]*26
ns = 0
for i in range(D):
last[na[i]-1] = i+1
ns += s[i][na[i]-1]
for j in range(26):
ns -= c[j]*(i+1-last[j])
if k%100 == 1:
T = 300-(298*k/40000)
p = pow(math.e,-abs(ns-score)/T)
if ns > score or random.random() < p:
ans = na
score = ns
for a in ans:
print(a) | 0 | null | 45,477,154,986,592 | 229 | 113 |
n, d, a = map(int, input().split())
xh = []
for _ in range(n):
x, h = map(int, input().split())
xh.append((x, h))
xh.sort(key=lambda x:x[0])
def bisect(x):
ok = n
ng = -1
while abs(ok-ng)>1:
mid = (ok+ng)//2
if xh[mid][0]>x:
ok = mid
else:
ng = mid
return ok
out = [0]*(n+1)
ans = 0
accu = 0
for ind, (x, h) in enumerate(xh):
accu -= out[ind]
h -= accu
if h<=0:
continue
ans += (h+a-1)//a
accu += ((h+a-1)//a)*a
out[bisect(x+2*d)] += ((h+a-1)//a)*a
print(ans) | # -*- coding: utf-8 -*-
import sys
def main():
N = int( sys.stdin.readline() )
c_list = list(sys.stdin.readline().rstrip())
num_R = c_list.count("R")
cnt = 0
for i in range(num_R):
if c_list[i] == "W":
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 44,205,447,025,828 | 230 | 98 |
N = int(input())
ans = (N - (N//2)) / N
print(ans) | N = int(input())
lst = []
for _ in range(N):
a, b, c = map(int,input().split())
lst.append([a, b, c])
for i in lst:
i.sort()
if i[0] ** 2 + i[1] ** 2 == i[2] ** 2:
print('YES')
else:
print('NO')
| 0 | null | 88,591,453,577,678 | 297 | 4 |
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**9
# 個数制限なしナップザック問題
h,n = map(int, input().split())
# 二次元配列で
a,b = [],[]
for i in range(n):
x, y = map(int, input().split())
a.append(x)
b.append(y)
dp = [[INF] * (h + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(h + 1):
if j <= a[i]:
dp[i + 1][j] = min(dp[i][j], b[i])
else:
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i])
print(dp[n][h])
# 一次元配列で
# dp = [INF]*(h+1)
# dp[0] = 0
# for i in range(n):
# a,b = map(int, input().split())
# for j in range(h):
# nj = min(a+j, h)
# dp[nj] = min(dp[nj], dp[j]+b)
# print(dp[-1])
| from sys import stdin
input = stdin.readline
def main():
H, N = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
A[i], B[i] = map(int, input().split())
# dp = [[0]*(H+1) for _ in range(N+1)]
dp = [0]*(H+1)
for j in range(H+1):
dp[j] = float('inf')
dp[0] = 0
for i in range(1, N+1):
for j in range(1, H+1):
# dp[i][j] = dp[i-1][j]
if j > A[i-1]:
dp[j] = min(dp[j], dp[j-A[i-1]]+B[i-1])
else:
dp[j] = min(dp[j], B[i-1])
# for i in range(N+1):
# print(dp[i])
print(dp[H])
if(__name__ == '__main__'):
main() | 1 | 81,103,806,891,240 | null | 229 | 229 |
import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs = lambda: input()
ri = lambda: int(input())
rm = lambda: map(int, input().split())
rai = lambda: [int(x) for x in input().split()]
def solve():
N = ri()
ans = 0
for i in range(1, N + 1):
n = N // i
ans += i * n * (n + 1) // 2
return ans
print(solve()) | s = input()
K = int(input())
n =len(s)
dp = [[[0] * 2 for _ in range(4)] for _ in range(101)]
dp[0][0][0]=1
for i in range(n):
for j in range(4):
for k in range(2):
nd = int(s[i])
for d in range(10):
ni = i+1; nj = j; nk = k
if d != 0 :nj+=1
if nj > K:continue
if k==0:
if d > nd:continue
if d < nd:nk =1
dp[ni][nj][nk] += dp[i][j][k]
# print(d,k)
# print(i,j,k,dp[i][j][k])
# print(ni,nj,nk,dp[ni][nj][nk])
# [print(i) for i in dp]
ans=dp[n][K][0] + dp[n][K][1]
print(ans)
# [print(i) for i in dp] | 0 | null | 43,550,814,728,640 | 118 | 224 |
li = input().split()
li.sort()
print(li[0]*int(li[1])) | import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 1
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
a,b = I()
A = str(a)*b
B = str(b)*a
print(min(A,B)) | 1 | 84,197,694,357,700 | null | 232 | 232 |
a, b, c, d = list(map(int, input().split()))
turn = True
while True:
if turn:
c -= b
if c <= 0:
print("Yes")
import sys
sys.exit()
else:
a -= d
if a <= 0:
print("No")
import sys
sys.exit()
turn ^= True
| R, C, K = map(int, input().split())
score = [[0]*C for i in range(R)]
for i in range(K):
r, c, v = map(int, input().split())
score[r-1][c-1]+=v
ans0 = [[0]*C for i in range(R)]
ans1 = [[0]*C for i in range(R)]
ans2 = [[0]*C for i in range(R)]
ans3 = [[0]*C for i in range(R)]
ans1[0][0]=score[0][0]
ans2[0][0]=score[0][0]
ans3[0][0]=score[0][0]
for i in range(R):
for j in range(C):
if i>0:
ans0[i][j]=max(ans0[i][j],ans3[i-1][j])
ans1[i][j]=max(ans1[i][j],ans3[i-1][j]+score[i][j])
ans2[i][j]=max(ans2[i][j],ans3[i-1][j]+score[i][j])
ans3[i][j]=max(ans3[i][j],ans3[i-1][j]+score[i][j])
if j>0:
ans0[i][j]=max(ans0[i][j],ans0[i][j-1])
ans1[i][j]=max(ans1[i][j],ans0[i][j-1]+score[i][j],ans1[i][j-1])
ans2[i][j]=max(ans2[i][j],ans1[i][j-1]+score[i][j],ans2[i][j-1])
ans3[i][j]=max(ans3[i][j],ans2[i][j-1]+score[i][j],ans3[i][j-1])
print(ans3[R-1][C-1]) | 0 | null | 17,670,911,768,300 | 164 | 94 |
N = int(input())
A = list(map(int,input().split()))
B = [[A[i],i+1]for i in range(N)]
B.sort()
ans = [B[i][1]for i in range(N)]
print(" ".join(map(str,ans))) | x=int(input())
n=x//500
m=x%500//5
ans=1000*n+5*m
print(ans)
| 0 | null | 111,996,757,831,080 | 299 | 185 |
score = list(map(int,input().split()))
answer = 0
if score[3] - score[0] <= 0:
answer += score[3]
else:
answer += score[0]
if score[3] - score[0] - score[1] > 0:
answer -= score[3] - score[0] - score[1]
print(answer) | a,b,c,k = map(int, input().split())
ans = min(a,k)
k -= min(a,k)
k -= min(b,k)
ans -= k
print(ans)
| 1 | 21,793,513,183,620 | null | 148 | 148 |
n, k = map(int, input().split())
MOD = 1000000007
def combinations(n, r, MOD):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * fact_inv[r] * fact_inv[n - r] % MOD
fact = [1, 1]
fact_inv = [1, 1]
inv = [0, 1]
for i in range(2, n + 1):
fact.append((fact[-1] * i) % MOD)
inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
fact_inv.append((fact_inv[-1] * inv[-1]) % MOD)
s = 0
for num_zero in range(min(k + 1, n)):
# nCz
x = combinations(n, num_zero, MOD)
# n-zCx
y = combinations(n - 1, n - num_zero - 1, MOD)
s += (x * y) % MOD
print(s % MOD)
| a,b,c=map(int, input().split())
A=(b*c)
if A>a:
print('Yes')
elif A==a:
print('Yes')
else:
print('No') | 0 | null | 35,383,735,057,188 | 215 | 81 |
import math
import numpy
a,b,c = map(int, input().split())
d = c - a - b
if d > 0 and d*d > 4 * a * b:
print("Yes")
else:
print("No")
| import math
N = int(input())
a = list(map(int,input().split()))
m = max(a)
c = [0] * (m+1)
for i in a:
c[i] += 1
pairwise = True
for i in range(2, m+1, 1):
cnt = 0
for j in range(i, m+1, i):
cnt += c[j]
if cnt > 1:
pairwise = False
break
if pairwise:
print("pairwise coprime")
exit()
g = 0
for i in range(N):
g = math.gcd(g, a[i])
if g == 1:
print("setwise coprime")
exit()
print("not coprime") | 0 | null | 27,699,379,786,428 | 197 | 85 |
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
ans = k * 1
else:
ans = a * 1 + max(0, (k - a)) * 0 + max(0, (k - a - b)) * (-1)
print(ans)
| a = list(map(int, input().split()))
if a[3] <= a[0]:
print(a[3])
elif a[3] <= a[0] + a[1]:
print(a[0])
else:
print(a[0] - (a[3] - a[0] -a[1])) | 1 | 21,852,636,021,440 | null | 148 | 148 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit
INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def mapline(t = int):
return map(t, sysread().split())
def mapread(t = int):
return map(t, read().split())
def run():
N, *A = mapread()
dp = [defaultdict(lambda:0) for _ in range(N+1)]
dp[0][(0,0,0)] = 1
for i in range(N):
a = A[i]
k = i + 1
for key in dp[k-1].keys():
for ii, v in enumerate(key):
if v == a:
tmp = list(key)
tmp[ii] += 1
dp[k][tuple(tmp)] += dp[k-1][key] % mod
ans = 0
for key in dp[N].keys():
ans = (ans + dp[N][key]) % mod
#print(dp)
print(ans)
if __name__ == "__main__":
run()
| n = int(input())
hats = list(map(int, input().split()))
mod = 1000000007
cnt = [0] * 3
ans = 1
for i in range(n):
count = 0
minj = 4
for j in range(3):
if hats[i] == cnt[j]:
count += 1
minj = min(minj, j)
if count == 0:
ans = 0
break
cnt[minj] += 1
ans = ans * count % mod
print(ans) | 1 | 130,173,130,779,850 | null | 268 | 268 |
class Dictionary_class:
def __init__(self):
self.dic = set()
def insert(self, str):
self.dic.add(str)
def find(self, str):
if str in self.dic:
return True
else:
return False
n = int(input())
answer = ""
dic = Dictionary_class()
for i in range(n):
instruction = input().split()
if instruction[0] == "insert":
dic.insert(instruction[1])
elif instruction[0] == "find":
if dic.find(instruction[1]):
answer += "yes\n"
else:
answer += "no\n"
print(answer, end = "") | n=int(input())
A=set()
for i in range(n):
x,y=input().split()
if x == 'insert':
A.add(y)
else:
print('yes'*(y in A)or'no')
| 1 | 78,829,031,710 | null | 23 | 23 |
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def main():
N = int(input())
XY = [[int(x) for x in input().split()] for _ in range(N)]
arr1 = []
arr2 = []
for x, y in XY:
arr1.append(x - y)
arr2.append(x + y)
print(max(abs(max(arr1) - min(arr1)), abs(max(arr2) - min(arr2))))
if __name__ == '__main__':
main()
| n=int(input())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
k,l=map(int,input().split())
a.append((k-l,i))
b.append((k+l,i))
c.append((-k-l,i))
d.append((-k+l,i))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d.sort(reverse=True)
print(max(a[0][0]+d[0][0],b[0][0]+c[0][0])) | 1 | 3,441,332,894,038 | null | 80 | 80 |
n = int(input())
a = n//3
b = n%3
if b == 1:
print((a+1/3)**3)
elif b==2:
print((a+2/3)**3)
else:
print(a**3) | n = float(input())
ans = (n / 3) ** 3
print(ans) | 1 | 47,173,634,832,078 | null | 191 | 191 |
n,m=map(int,input().split())
lst=list(map(int,input().split()))
if n<sum(lst) : print(-1)
else : print(n-sum(lst)) | # import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
# c.append(i)
# e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
f.sort()
count=1
ans=[0 for i in range(a)]
for i in range(len(f)-1):
if f[i]==f[i+1]:
count+=1
else:
ans[f[i]-1]=count
count=1
if count>=1:
ans[f[-1]-1]=count
for i in ans:
print(i) | 0 | null | 32,245,339,253,650 | 168 | 169 |
def main():
N, K, C = map(int, input().split())
S = input()
# greedy
head, tail = [-C - 1] * (K + 1), [N + C + 1] * (K + 1)
idx = 0
for i in range(N):
if S[i] == 'o' and i - head[idx] > C:
idx += 1
head[idx] = i
if idx == K:
break
idx = K
for i in range(N - 1, -1, -1):
if S[i] == 'o' and tail[idx] - i > C:
idx -= 1
tail[idx] = i
if idx == 0:
break
# ans
for i in range(K):
if head[i + 1] == tail[i]:
print(tail[i] + 1)
if __name__ == '__main__':
main()
| N,K,C = map(int, input().split())
S = input()
w = []
for i in range(len(S)):
if S[i]=="o":
w.append(i)
# print(w)
# early date
early = []
tmpwd = -1
for i in range(len(w)):
if len(early) >= K:
continue
if tmpwd<0:
tmpwd = w[i]
elif w[i]>tmpwd+C:
tmpwd = w[i]
else:
continue
early.append(w[i])
# print(early)
# later date
late = []
tmpwd = -1
for i in reversed(range(len(w))):
if len(late)>=K:
continue
if tmpwd < 0:
tmpwd = w[i]
elif w[i] < tmpwd-C:
tmpwd = w[i]
else:
continue
late.append(w[i])
wd = set(early) & set(late)
early.sort()
late.sort()
# print(early,late)
for i in range(K):
if early[i]==late[i]:
print(early[i]+1) | 1 | 40,887,694,759,980 | null | 182 | 182 |
n,m=map(int,input().split())
diffs=set()
idxs=set()
i=1
diff=n-1
cnt=0
while 1:
if i>m:
break
while (diff in diffs and n-diff in diffs) or (i+diff in idxs) or (diff==n-diff):
diff-=1
diffs.add(n-diff)
diffs.add(diff)
idxs.add(i+diff)
print(i,i+diff)
i+=1 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
ge = []
l = 1
r = n-1
for i in range(m):
if i%2:
ge.append(l)
else:
ge.append(r)
l += 1; r -= 1
ge.sort(reverse = True)
for i in range(m):
print(i+1,i+1+ge[i])
| 1 | 28,843,378,234,724 | null | 162 | 162 |
n = int(input())
if(n % 2 !=0):
print(0)
exit()
ketasu = len(str(n))
ans = 0
for i in range(1, 100):
ans += n // (2 * 5 **i)
print(ans) | N = int(input())
S = input()
rgb = [0]*3
for i in range(N):
if S[i] == "R":
rgb[0] += 1
elif S[i] == "G":
rgb[1] += 1
else:
rgb[2] += 1
ans = 0
for i in range(N):
for h in range(N):
j = i+h
k = i+2*h
if k >= N:
break
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
ans += 1
print(rgb[0]*rgb[1]*rgb[2]-ans)
| 0 | null | 76,063,300,216,160 | 258 | 175 |
def memolize(f):
cache = {}
def helper(x):
if x not in cache:
cache[x] = f(x)
return cache[x]
return helper
@memolize
def fib(n):
if n == 0:
return 1
elif n == 1:
return 1
return fib(n - 1) + fib(n - 2)
n = int(input())
print(fib(n))
| n = int(input())
print(10-int(n/200)) | 0 | null | 3,388,194,902,860 | 7 | 100 |
import math
import sys
import os
from operator import mul
import bisect
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
N = I()
S = list(_S())
ans = 0
r = []
g = []
b = []
for i,s in enumerate(S):
if s == 'R':
r.append(i)
if s == 'G':
g.append(i)
if s == 'B':
b.append(i)
# j = bisect.bisect_right(<list>,<value>)
# print(r)
# print(g)
# print(b)
# for i in r:
# for j in g:
# for k in b:
# tmp = sorted([i,j,k])
# if not tmp[1]-tmp[0]==tmp[2]-tmp[1]:
# ans += 1
ans = len(r)*len(g)*len(b)
for i in range(N):
for j in range(i,N):
k = j + (j-i)
if k > N-1:
break
if S[i]==S[j]:
continue
if S[i]==S[k] or S[j]==S[k]:
continue
ans -= 1
print(ans)
# R G B
# R B G
# G B R
# G R B
# B G R
# B R G
# i j k
# - != -
# RBRBGRBGGB
# 1122233333
# 0000111233
# 0112223334
# B*3
# G*4
# GB系: (2,4), (4,5)
# RB系: (1,3), | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def main():
n, p = map(int, input().split())
s = list(input())
if 10 % p == 0:
ans = 0
for i in range(n):
if (ord(s[i])-ord('0')) % p == 0:
ans += i+1
print(ans)
return
d = [0] * (n+1)
ten = 1
for i in reversed(range(n)):
a = (ord(s[i])-ord('0')) * ten % p
d[i] = (d[i+1]+a) % p
ten *= 10
ten %= p
cnt = [0] * p
ans = 0
for i in reversed(range(n+1)):
ans += cnt[d[i]]
cnt[d[i]] += 1
print(ans)
main()
| 0 | null | 47,482,064,828,958 | 175 | 205 |
import sys
input = sys.stdin.readline
n = int(input())
info = [0] * n
for i in range(n):
x, l = map(int, input().split())
info[i] = [x+l, x, l]
info.sort()
ans = 1
right = info[0][1] + info[0][2]
for i in range(1, n):
if right <= info[i][1] - info[i][2]:
ans += 1
right = info[i][1] + info[i][2]
print(ans) | N=int(input())
xl=[list(map(int,input().split()))for _ in range(N)]
rl=[[x+l,x-l]for x,l in xl]
rl.sort()
now=-10**9
ans=0
for r,l in rl:
if l>=now:
ans+=1
now=r
print(ans) | 1 | 89,757,818,122,268 | null | 237 | 237 |
def compare(a, b):
if a > b:
print('a > b')
elif a < b:
print('a < b')
else:
print('a == b')
a, b = [int(x) for x in input().split()]
compare(a, b) | import math
n = int(input())
z = math.floor(math.sqrt(n))
ans = 10 ** 12
for i in range(1,z+1):
if n % i == 0:
m = n // i
ans = min(ans,m+i-2)
print(ans) | 0 | null | 80,547,961,452,032 | 38 | 288 |
N = int(input())
P = list(map(int,input().split()))
Pm = P[0]
ans = 0
for i in range(N):
if P[i] <= Pm:
ans += 1
Pm = P[i]
print(ans) | n = int(input())
S = ['']*n
T = []
for i in range(n):
S[i] = input()
S.sort()
if n == 1:
print(S[0])
exit()
cnt = 1
mxcnt = 1
for i in range(n-1):
if S[i] == S[i+1]:
cnt += 1
else:
cnt = 1
mxcnt = max(mxcnt,cnt)
cnt = 1
for i in range(n-1):
if S[i] == S[i+1]:
cnt += 1
else:
cnt = 1
if cnt == mxcnt:
T.append(S[i])
if mxcnt == 1:
T.append(S[-1])
for t in T:
print(t) | 0 | null | 77,879,346,262,718 | 233 | 218 |
S = input()
q = int(input())
for i in range(q):
L = input().split()
a = int(L[1])
b = int(L[2])
slice1 = S[:a]
slice2 = S[a:b+1]
slice3 = S[b+1:]
if L[0] == 'print':
print(slice2)
elif L[0] == 'reverse':
S = slice1 + slice2[::-1] + slice3
elif L[0] == 'replace':
S = slice1 + L[3] + slice3 | str=input()
s=list(str)
q=int(input())
for i in range(q):
Q=input()
l=list(Q)
if 'print' in Q:
for p in range(6):
l.pop(0)
for X in range(len(l)):
if l[X]==' ':
x=X
A=l[0:x]
a=''.join(A)
a=int(a)
B=l[x+1:len(l)]
b=''.join(B)
b=int(b)+1
t=s[a:b]
str=''.join(t)
print(str)
elif 'reverse' in Q:
for v in range(8):
l.pop(0)
for Y in range(len(l)):
if l[Y]==' ':
y=Y
A=l[0:y]
a=''.join(A)
a=int(a)
B=l[y+1:len(l)]
b=''.join(B)
b=int(b)+1
t=s[a:b]
t.reverse()
s[a:b]=t
elif 'replace' in Q:
for r in range(8):
l.pop(0)
for Z in range(len(l)):
if l[Z]==' ':
z=Z
break
N=0
while True:
if l[z+N+1]==' ':
n=z+N+1
break
else:
N+=1
A=l[0:z]
a=''.join(A)
a=int(a)
B=l[z+1:n]
b=''.join(B)
b=int(b)+1
t=l[n+1:len(l)]
s[a:b]=t
| 1 | 2,093,525,390,460 | null | 68 | 68 |
# coding:utf-8
a, b, c = map(int, input().split())
k = int(input())
counter = 0
while a >= b:
counter += 1
b = b * 2
while b >= c:
counter += 1
c = c * 2
if counter <= k:
print('Yes')
else:
print('No')
| A,B,C=map(int,input().split())
K=int(input())
result='No'
while A>=B:
K-=1
B*=2
while B>=C:
K-=1
C*=2
if K>=0 and C>B and B>A:
result='Yes'
print(result) | 1 | 6,910,585,865,692 | null | 101 | 101 |
N = int(input())
S = [int(x) for x in input().split()]
T = int(input())
Q = [int(x) for x in input().split()]
c = set()
for s in S:
for q in Q:
if s == q:
c.add(s)
print(len(c))
| from math import *
s=0
n=int(input())
for i in range(1,n+1):
for j in range(1,n+1):
for k in range(1,n+1):
g=gcd(i,j)
g=gcd(g,k)
s+=g
print(s)
| 0 | null | 17,695,143,088,350 | 22 | 174 |
from heapq import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
n=II()
ss=[SI() for _ in range(n)]
ms1=[]
ms2=[]
for s in ss:
mn=0
now=0
for c in s:
if c=="(":now+=1
else:now-=1
if now<mn:mn=now
if now>0:ms1.append((mn,now))
else:ms2.append((mn-now,-now))
#print(ms1)
#print(ms2)
cnt=0
for mn,s in sorted(ms1,reverse=True):
if cnt+mn<0:
print("No")
exit()
cnt+=s
cnt2=0
for mn,s in sorted(ms2,reverse=True):
if cnt2+mn<0:
print("No")
exit()
cnt2+=s
if cnt==cnt2:print("Yes")
else:print("No")
main() | N = int(input())
A = [int(i) for i in input().split()]
A.sort()
S = -A[-1]
for i in range(N):
S += A[N-i//2-1]
print(S) | 0 | null | 16,326,181,918,508 | 152 | 111 |
def isPrime(n):
if n == 2 or n == 3:
return True
elif n == 1 or n % 2 == 0 or n % 3 == 0:
return False
N = int(n ** 0.5)
for i in range(5, N + 1, 2):
if n % i == 0:
return False
return True
N = int(input())
ans = 0
for _ in range(N):
a = int(input())
ans += 1 if isPrime(a) else 0
print(ans) | #coding: UTF-8
def isPrime(n):
if n == 1:
return False
import math
m = math.floor(math.sqrt(n))
for i in range(2,m+1):
if n % i == 0:
return False
return True
n = int(input())
count = 0
for j in range(n):
m = int(input())
if isPrime(m):
count += 1
print(count)
| 1 | 9,357,028,710 | null | 12 | 12 |
n = int(input())
s, t = input().split()
combination_of_letters = ''
for i in range(n):
combination_of_letters += s[i] + t[i]
print(combination_of_letters) | a,b,c,d = map(int,input().split())
while True:
c = c - b
if c <= 0:
print("Yes")
break
a = a - d
if a <= 0:
print("No")
break
| 0 | null | 70,759,527,246,664 | 255 | 164 |
n = int(input())
alst = list(map(int, input().split()))
alst.sort()
bef = -1
for a in alst:
if bef == a:
print("NO")
break
bef = a
else:
print("YES") | def selectionSort(N, A):
c= 0
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
if i != minj:
A[i], A[minj] = A[minj], A[i]
c += 1
return (A, c)
A, c = selectionSort(int(input()), list(map(int, input().split())))
print(*A)
print(c) | 0 | null | 36,993,903,944,480 | 222 | 15 |
# F - Bracket Sequencing
import sys
readline = sys.stdin.readline
N = int(input())
L = []
R = []
for _ in range(N):
S = readline().strip()
sums = 0
mins = 0
for s in S:
if s == '(':
sums += 1
else:
sums -= 1
mins = min(mins, sums)
if sums >= 0:
L.append((sums, mins))
else:
R.append((-sums, mins-sums))
L.sort(key=lambda x: x[1], reverse=True)
R.sort(key=lambda x: x[1], reverse=True)
ans = 'Yes'
l_now = 0
for d, min_d in L:
if l_now + min_d < 0:
ans = 'No'
break
else:
l_now += d
r_now = 0
for d, min_d in R:
if r_now + min_d < 0:
ans = 'No'
break
else:
r_now += d
if l_now != r_now:
ans = 'No'
print(ans) | N = int((input()))
C_p = []
C_m = []
for i in range(N):
kakko = input()
temp = 0
temp_min = 0
for s in kakko:
if s == "(":
temp += 1
else:
temp -= 1
temp_min = min(temp, temp_min)
if temp >= 0:
C_p.append((temp_min, temp))
else:
C_m.append((temp_min - temp, temp_min, temp))
C_p.sort(reverse=True)
flag = 0
final = 0
for l, f in C_p:
if final + l < 0:
flag = 1
final += f
C_m.sort()
for _, l, f in C_m:
if final + l < 0:
flag = 1
final += f
if final != 0:
flag = 1
print("Yes" if flag == 0 else "No") | 1 | 23,619,178,179,670 | null | 152 | 152 |
x, n = map(int, input().split())
lis = []
if n == 0:
print(x)
else:
lis = list(map(int, input().split()))
if x not in lis:
print(x)
else:
y = x + 1
z = x - 1
while True:
if y in lis and z in lis:
y += 1
z -= 1
elif z not in lis:
print(z)
break
elif y not in lis:
print(y)
break
| #!/usr/bin/env python3
def solve(S: str):
if S >= 30:
return "Yes"
return "No"
def main():
S = int(input())
answer = solve(S)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 9,880,715,799,152 | 128 | 95 |
import math
a=int(input())
b=100000
for i in range(a):
b=b*1.05
b=b/1000
b=math.ceil(b)
b=b*1000
print(b)
| N=input()
N=N[::-1]+"0"
ans=0
up=0
for i,n in enumerate(N):
d=int(n)+up
if d>5 or (d==5 and i<len(N)-1 and int(N[i+1])>=5):
ans+=(10-d)
up=1
else:
ans+=d
up=0
print(ans) | 0 | null | 35,249,508,182,912 | 6 | 219 |
def main():
input()
A = list(map(int, input().split()))
cusum = [0] * len(A)
cusum[-1] = A[-1]
if A[0] > 1:
print(-1)
return
for i in range(len(A)-2, -1, -1):
cusum[i] = cusum[i+1] + A[i]
pre_node = 1
ans = 1
for i in range(1, len(A)):
node = (pre_node - A[i-1]) * 2
if node < A[i]:
print(-1)
return
pre_node = min(node, cusum[i])
ans += pre_node
print(ans)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = LI()
L = [1]
if a[-1] > 2**n:
print(-1)
quit()
if n == 0:
if a[0] == 0:
print(-1)
quit()
L2 = [a[-1]]
for i in range(n)[::-1]:
L2.append(min(L2[-1] + a[i], 2**i))
L2 = L2[::-1]
ans = 0
for i in range(n+1):
if i == 0:
tmp = 1
else:
tmp = (L[-1] - a[i-1]) * 2
if tmp <= 0:
print(-1)
quit()
ans += min(tmp, L2[i])
L.append(tmp)
if L[-1] - a[-1] < 0:
print(-1)
quit()
print(ans)
| 1 | 18,711,864,291,262 | null | 141 | 141 |
i = list(map(int, input().split()))
a = i[0]
b = i[1]
print('{0} {1} {2:.5f}'.format(a // b, a % b, float(a / b))) | a, b, c, d, e, f = map(int, input().split())
S = list(input())
i = 0
number1 = a
number2 = b
number3 = c
number4 = d
number5 = e
number6 = f
while i < len(S) :
if S[i] == "N" :
number1 = b
number2 = f
number3 = c
number4 = d
number5 = a
number6 = e
elif S[i] == "S" :
number1 = e
number2 = a
number3 = c
number4 = d
number5 = f
number6 = b
elif S[i] == "E" :
number1 = d
number2 = b
number3 = a
number4 = f
number5 = e
number6 = c
elif S[i] == "W" :
number1 = c
number2 = b
number3 = f
number4 = a
number5 = e
number6 = d
a = number1
b = number2
c = number3
d = number4
e = number5
f = number6
i = i + 1
print(number1)
| 0 | null | 415,457,490,246 | 45 | 33 |
n = int(input())
s = str(input())
ans = n
for i in range(1,n):
if s[i-1] == s[i]:
ans -= 1
print(ans) | n = int(input())
s = list(input())
ans = 1
for i in range(1, n):
if s[i-1] != s[i]:
ans += 1
print(ans)
| 1 | 170,257,677,257,112 | null | 293 | 293 |
import math
num1 = int(input())
num2 = math.floor(num1 / 1.08)
num3 = math.ceil(num1 / 1.08)
end = False
if math.floor(math.floor(num1 / 1.08) * 1.08) == num1:
print(math.floor(num1 / 1.08))
end = True
elif math.floor(math.ceil(num1 / 1.08) * 1.08) == num1 and end == False:
print(math.ceil(num1 / 1.08))
else:
print(':(') | N = int(input())
X = N / 1.08
X_down = int(X)
X_up = int(X) + 1
bool_down = int(X_down * 1.08) == N
bool_up = int(X_up * 1.08) == N
if bool_down:
print(X_down)
elif bool_up:
print(X_up)
else:
print(":(")
| 1 | 125,785,695,012,672 | null | 265 | 265 |
X, Y, Z = [int(x) for x in input().split()]
print("%d %d %d" % (Z, X, Y))
| X,Y,Z = map(str,input().split())
print(Z+' '+X+' '+Y) | 1 | 37,995,735,048,772 | null | 178 | 178 |
s=input()
if len(s) % 2 == 0:
if s == "hi"*(len(s)//2):
print("Yes")
else:
print("No")
else:
print("No") | N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
C = [None] * N
for i, (a, f) in enumerate(zip(A, F)):
C[i] = (a * f, f)
def solve(x):
global K, N
t = 0
for c, f in C:
temp = ((c - x) + f - 1) // f
t += max(0, temp)
if t > K:
result = False
break
else:
result = True
return result
ok = A[0] * F[N - 1]
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
print(ok)
| 0 | null | 109,018,235,678,418 | 199 | 290 |
def N():
return int(input())
def L():
return list(map(int,input()))
def NL(n):
return [list(map(int,input())) for _ in range(n)]
import math
k = N() + 1
sum = 0
for i in range(1,k):
for j in range(1,k):
for l in range(1,k):
#print(sum)
sum += math.gcd(math.gcd(i,j),l)
print(sum)
| import math
k=int(input())
ans=0
for i in range(k):
for j in range(k):
q=math.gcd(i+1,j+1)
for l in range(k):
ans+=math.gcd(q,l+1)
print(ans)
| 1 | 35,526,492,936,352 | null | 174 | 174 |
while True:
x, y = list(map(int, input().split(" ")))
if (x, y) == (0, 0):
break
elif (x < y):
print(x, y)
else:
print(y, x) | # encoding:utf-8
while True:
input = map(int, raw_input().split())
x, y = input
if x == y == 0:
break
input.sort()
print(" ".join(map(str, input))) | 1 | 507,875,694,790 | null | 43 | 43 |
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline
def main():
N = int(input())
set_ = set()
for i in range(N):
set_.add(input()[:-1])
print(len(set_))
if(__name__ == '__main__'):
main()
| 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)) | 0 | null | 44,156,618,156,518 | 165 | 205 |
def determine_string_code(bracket_string):
brackets_left = 0 # )
brackets_right = 0 # (
for char in bracket_string:
if char == "(":
brackets_right += 1
else:
if brackets_right > 0:
brackets_right -= 1
else:
brackets_left += 1
return (brackets_left, brackets_right)
def build_left(in_list):
in_list.sort(key=lambda x: x[0])
final_res = (0, 0)
for res in in_list:
if res[0]>final_res[1]:
final_res = (final_res[0]+res[0]-final_res[1], res[1])
elif res[0]<final_res[1]:
final_res = (final_res[0], res[1]+final_res[1]-res[0])
else:
final_res = (final_res[0], res[1])
return final_res
def build_right(in_list):
in_list.sort(key=lambda x: x[1])
final_res = (0, 0)
for res in in_list:
if final_res[0]>res[1]:
final_res = (res[0]+final_res[0]-res[1], final_res[1])
elif final_res[0]<res[1]:
final_res = (res[0], final_res[1]+res[1]-final_res[0])
else:
final_res = (res[0], final_res[1])
return final_res
n = int(input())
residues = list()
for _ in range(n):
new_string = input()
residues.append(determine_string_code(new_string))
first_half = list()
second_half = list()
for res in residues:
if res[1] > res[0]:
first_half.append(res)
else:
second_half.append(res)
first_res = build_left(first_half)
second_res = build_right(second_half)
if first_res[0] == 0 and second_res[1] == 0 and first_res[1] == second_res[0]:
print("Yes")
else:
print("No") | n = int(input())
s=['' for _ in range(n)]
for i in range(n):
s[i]=input()
#x=[[0,0] for _ in range(n)]
hp,hm=0,0
p=[]
m=[]
for i in range(n):
t=s[i]
lv=0
mn=0
for u in t:
if u == '(':
lv+=1
elif u == ')':
lv-=1
mn=min(mn,lv)
#x[i][0],x[i][1]=lv,mn
if lv>=0:
p.append([lv,mn])
hp+=lv
else:
lv*=-1
m.append([lv,mn+lv])
hm+=lv
if hp!=hm:
print('No')
exit()
p.sort(key=lambda x: x[1],reverse=1)
m.sort(key=lambda x: x[1],reverse=1)
h=0
lv,mn=0,0
for a,b in p:
lv+=a
mn+=b
if mn<0:
print('No')
exit()
mn=lv
lv,mn=0,0
for a,b in m:
lv+=a
mn+=b
if mn<0:
print('No')
exit()
mn=lv
print('Yes')
#print(lv,mn)
| 1 | 23,474,678,298,940 | null | 152 | 152 |
dice_init = input().split()
dicry = {'search':"152304",'hittop':'024135', 'hitfront':'310542'}
num = int(input())
def dicing(x):
global dice
dice = [dice[int(c)] for c in dicry[x]]
for _ in range(num):
dice = dice_init
top, front = map(int, input().split())
while True:
if int(dice[0]) == top and int(dice[1]) == front:
break
elif int(dice[0]) == top:
dicing('hittop')
elif int(dice[1]) == front:
dicing('hitfront')
else:
dicing('search')
print(dice[2])
| #coding: utf-8
tfr = ((1, 2, 4, 3), (0, 3, 5, 2), (0, 1, 5, 4),
(0, 4, 5, 1), (0, 2, 5, 3), (1, 3, 4, 2))
label = list(map(int, input().split()))
q = int(input())
for i in range(q):
t, f = map(int, input().split())
idxt = label.index(t)
idxf = label.index(f)
idxr = tfr[idxt].index(idxf) + 1
if idxr == 4:
idxr = 0
print(label[tfr[idxt][idxr]])
| 1 | 258,376,154,340 | null | 34 | 34 |
l, r, d = map(int, input().split())
print(r//d-l//d+int(l%d==0 and r%d==0)) | l,r,n=map(int,input().split())
a=(r//n)-(l//n if l!=n else 0)
if l!=r:print(a)
else: print(1) | 1 | 7,565,224,573,298 | null | 104 | 104 |
a, b, c = map(int, input().split())
def black (a,b,c):
if a+b+c >= 22:
return "bust"
else:
return "win"
print(black(a,b,c)) | numberOfArray=int(input())
arrayList=list(map(int,input().split()))
def bubbleSort():
frag=1
count=0
while frag:
frag=0
for i in range(1,numberOfArray):
if arrayList[i-1]>arrayList[i]:
arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
frag=1
count+=1
arrayForReturn=str(arrayList[0])
for i2 in range(1,numberOfArray):
arrayForReturn+=" "+str(arrayList[i2])
print(arrayForReturn)
print(count)
#------------------main--------------
bubbleSort()
| 0 | null | 59,145,181,835,090 | 260 | 14 |
from sys import stdin
import math
N = int(stdin.readline().rstrip())
for i in range(1, 50000):
if math.floor(i * 1.08) == N:
print(i)
exit()
print(":(")
| A, B, K = map(int, input().split())
if A-K >= 0:
print(A-K, B)
else:
if B-(K-A)<0:
print(0, 0)
quit()
print(0, B-(K-A)) | 0 | null | 115,275,932,530,512 | 265 | 249 |
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
p=[x-1 for x in p]
mi=set(range(n))
g={}
# g[id]=[ary]
while mi:
x0=mi.pop()
ary=[c[x0]]
x=x0
while p[x]!=x0:
x=p[x]
mi.discard(x)
ary.append(c[x])
cnt=len(ary)
tmp=0
ary*=2
cary=[tmp]
for x in ary:
tmp+=x
cary.append(tmp)
g[x0]=[cnt,cary]
ans=-float('inf')
for cnt,cary in g.values():
x,y=divmod(k,cnt)
tmp1=max(0,cary[cnt]*x)
tmp2=-float('inf')
for i in range(cnt):
for j in range(y):
tmp2=max(tmp2,cary[i+j+1]-cary[i])
ans=max(ans,tmp1+tmp2)
if x:
tmp1=max(0,cary[cnt]*(x-1))
tmp2=-float('inf')
for i in range(cnt):
for j in range(cnt):
tmp2=max(tmp2,cary[i+j+1]-cary[i])
ans=max(ans,tmp1+tmp2)
print(ans)
| N = int(input())
adj_list = []
for _ in range(N):
line = list(input().split(" "))
adj_list.append([int(k) - 1 for k in line[2:]])
d = [-1 for _ in range(N)]
f = [-1 for _ in range(N)]
time = 1
visited = set()
def dfs(p):
global time
if p in visited:
return
d[p] = time
time += 1
visited.add(p)
for ad in adj_list[p]:
if ad not in visited:
dfs(ad)
f[p] = time
time += 1
for i in range(N):
dfs(i)
for i in range(N):
print(f"{i + 1} {d[i]} {f[i]}")
| 0 | null | 2,659,405,695,000 | 93 | 8 |
max = [0,0,0]
for a in range(10):
s = int(input())
if max[0] < s:
max[2] = max[1]
max[1] = max[0]
max[0] = s
elif max[1] < s:
max[2] = max[1]
max[1] = s
elif max[2] < s:
max[2] = s
for a in max:
print(a)
| import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
P = int(1e9+7)
def lcm_base(x, y):
ret = (x * y) // math.gcd(x, y)
return ret
def lcm(iter):
return reduce(lcm_base, iter, 1)
lcm_a = lcm(A) % P
ans = 0
for a in A:
a_inv = pow(a, P-2, P)
ans = (ans + lcm_a*a_inv) %P
print(ans)
| 0 | null | 43,800,338,098,840 | 2 | 235 |
# 不親切な人の証言は、正しかろうが間違っていようが検証できないので無視する
# bit全探索で正直者を仮定・固定して、証言に矛盾が出なければ人数を数えて記録する
from itertools import product
n = int(input())
Ev = [[] for _ in range(n)]
for i in range(n):
A = int(input())
for a in range(A):
x, y = map(int, input().split())
Ev[i].append((x - 1, y))
bit = list(product([1, 0], repeat=n))
ans = 0
for b in bit:
for i, v in enumerate(b): # v == 1 or 0
if v == 1:
for x, y in Ev[i]: # 証言1つ1つを取り出して検証
if b[x] != y: # bitで仮定している正直者リストと矛盾する証言を正直者が行ったらアウト
break
else:
continue
break
else:
ans = max(b.count(1), ans)
print(ans) | def main():
n = int(input())
xy = []
for i in range(n):
a = int(input())
xy.append([tuple(map(int, input().split())) for _ in range(a)])
c = 0
for i in range(1 << n):
popcnt = bin(i).count('1')
if popcnt <= c:
continue
all_honest = True
for j in range(n):
if (1 << j) & i != 0:
for x, y in xy[j]:
x -= 1 # 人の番号をひとつずらす
if ((1 << x) & i) >> x != y:
all_honest = False
break
if not all_honest:
break
if all_honest:
c = popcnt
print(c)
if __name__ == '__main__':
main()
| 1 | 121,123,863,786,290 | null | 262 | 262 |
A = 100
X = int(input())
cnt = 0
while X > A:
cnt += 1
A += A // 100
print(cnt) | import sys
a,b = map(int,sys.stdin.readline().split())
print('%d %d %f' % (a/b,a%b,float(a)/float(b))) | 0 | null | 13,832,657,659,512 | 159 | 45 |
#E
H,N=map(int,input().split())
A=[0 for i in range(N)]
dp=[float("inf") for i in range(10**4+1)]
dp[0]=0
for i in range(N):
a,b=map(int,input().split())
A[i]=a
for j in range(10**4+1):
if j+a>10**4:
break
dp[j+a]=min(dp[j]+b,dp[j+a])
if H+max(A)>10**4:
print(min(dp[H:]))
else:
print(min(dp[H:H+max(A)])) | s = int(input())
MOD = 10**9 + 7
b3 = 1; b2 = 0; now = 0 # now == b1
for _ in range(s-2):
b1 = now
now = (b1 + b3) % MOD
b3, b2 = b2, b1
print(now)
| 0 | null | 42,061,850,865,078 | 229 | 79 |
a=input()
print(a+"e"*(a[-1]=='s')+'s') | string = input()
if string[len(string)-1] == "s":
print(string+'es')
else:
print(string+'s')
| 1 | 2,401,055,398,688 | null | 71 | 71 |
n = int(input())
rounded = round(n, -3)
if rounded < n:
rounded += 1000
print(rounded - n) | import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
n = ini()
ans = n % 1000
print(0 if ans == 0 else 1000 - ans) | 1 | 8,524,351,845,378 | null | 108 | 108 |
def main():
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]
MOD = 998244353
dp = [0]*(N+1)
S = [0]*(N+1)
dp[1] = 1
S[1] = 1
for i in range(2, N+1):
for l, r in LR:
if i-l < 0:
continue
else:
dp[i] += S[i-l] - S[max(i-r-1, 0)]
dp[i] %= MOD
S[i] = S[i-1] + dp[i]
print(dp[-1]%MOD)
if __name__ == '__main__':
main()
| n,k=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(k)]
mod=998244353
dp=[0]*(n+1)
csum=[0]*(n+2)
dp[0]=1
for i in range(n):
for j in range(k):
l,r=lr[j]
dp[i]+=csum[max(i+1-l,0)]-csum[max(i-r,0)]
dp[i]%=mod
csum[i+1]+=dp[i]+csum[i]
csum[i+1]%=mod
print(dp[n-1]) | 1 | 2,696,667,705,720 | null | 74 | 74 |
S = input()
if S.count("hi")*2 == len(S):
print("Yes")
else:
print("No") | import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
n = int(input())
nums = list(map(int, input().split()))
ans = 0
l = {}
r = []
for i in range(1,n+1):
if(i + nums[i-1] not in l):
l[i+nums[i-1]] =0
l[i+nums[i-1]]+=1
if((-1*nums[i-1])+i in l):
ans+=l[(-1*nums[i-1])+i]
print(ans)
| 0 | null | 39,839,614,290,892 | 199 | 157 |
#ABC146A
s = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
ss = input()
print(7-s.index(ss)) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = input()
day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - day.index(s)) | 1 | 132,934,878,568,140 | null | 270 | 270 |
n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(0,n):
for j in range(0,n):
if i >= j:
continue
else:
ans += d[i]*d[j]
print(ans) | from collections import defaultdict
d = defaultdict(int)
N = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(N):
ans += d[i-arr[i]]
d[i+arr[i]] += 1
print(ans) | 0 | null | 96,853,089,564,870 | 292 | 157 |
def abc178c():
n = int(input())
print((pow(10, n) - pow(9, n) - pow(9, n) + pow(8, n)) % (pow(10, 9) + 7))
abc178c() | import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
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())
def main():
n = I()
a = LI()
acc = 0
for i in a:
acc ^= i
ans_lst = []
for i in a:
ans = acc^i
ans_lst.append(ans)
print(*ans_lst)
main()
| 0 | null | 7,892,047,442,212 | 78 | 123 |
#!/usr/bin/env python3
#ABC146 F
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n,m = LI()
s = input()
i = 0
cnt = 0
M = 0
while i < n+1:
if s[i] == '1':
cnt += 1
M = max(M,cnt)
else:
cnt = 0
i += 1
if M >= m:
print(-1)
quit()
lst = []
now = n
while now > 0:
if now - m <= 0:
lst.append(now)
now -= m
else:
for j in range(1,m+1)[::-1]:
if s[now-j] == '0':
lst.append(j)
now -= j
break
print(*lst[::-1]) | #!/usr/bin/env python3
import sys
def solve(N: int, M: int, S: str):
# dp = [float('inf')]*(N+1)
# dp[N] = 0
# count = 1
# for i in range(N,-1,-1):
# if S[i] == "1":
# continue
# for j in range()
S = S[::-1]
cur_index = 0
answer = []
while True:
for i in range(M,0,-1):
if cur_index+i >= N:
answer.append(N-cur_index)
answer.reverse()
print(*answer)
return
if S[cur_index+i] == "1":
continue
else:
cur_index += i
answer.append(i)
break
else:
print(-1)
return
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
S = next(tokens)
solve(N, M, S)
if __name__ == '__main__':
main()
| 1 | 138,924,740,194,372 | null | 274 | 274 |
def II(): return int(input())
def MI(): return map(int, input().split())
N=II()
a=[0]*N
x=[[0]*N for i in range(N)]
y=[[0]*N for i in range(N)]
for i in range(N):
a[i]=II()
for j in range(a[i]):
x[i][j],y[i][j]=MI()
x[i][j]-=1
def check(honest):
for i in range(N):
if not honest[i]:
continue
for j in range(a[i]):
if y[i][j]==0 and honest[x[i][j]]:
return False
if y[i][j]==1 and not honest[x[i][j]]:
return False
return True
def dfs(honest):
if len(honest)==N:
if check(honest):
return sum(honest)
else:
return 0
return max(dfs(honest+[True]),dfs(honest+[False]))
print(dfs([])) | import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
N = I()
A = []
xy = []
for _ in range(N):
A.append(I())
xy.append([LI() for _ in range(A[-1])])
ans = 0
for i in range(2 ** N):
# まず正直者を仮定し、正直者の証言に矛盾がないか判定
is_ok = True
num = 0
for j in range(N):
if i >> j & 1:
num += 1
for k in xy[j]:
x, y = k
x -= 1
if i >> x & 1 != y:
is_ok = False
if is_ok:
ans = max(num, ans)
print(ans)
if __name__ == '__main__':
resolve()
| 1 | 121,587,282,782,782 | null | 262 | 262 |
n,x,t = input().split(" ")
s = 0
time = 0
while int(n) > s:
s += int(x)
time += int(t)
print(time) | # A - Takoyaki
from math import ceil
n, x, t = map(int, input().split())
print(ceil(n / x) * t)
| 1 | 4,262,656,445,906 | null | 86 | 86 |
N=int(input())
d=list(map(int,input().split()))
a=0
for i in range(N):
for k in range(1,N-i):
a=a+d[i]*d[i+k]
print(a) | a = int(input())
b = list(map(int, input().split()))
c = 0
for i in range(a-1):
for j in range(1,a-i):
c += b[i]*b[i+j]
print(c)
| 1 | 168,995,288,546,006 | null | 292 | 292 |
import sys; input = sys.stdin.readline
n = int(input())
if n%1000 == 0: print(0)
else: print(1000 - n%1000)
| N=input()
n=int(N)
k=int(n%1000)
if k==0:
print(0)
else:
print(1000-k) | 1 | 8,454,386,862,362 | null | 108 | 108 |
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
worst_score = 10 ** 12
n, k = ns()
a = na()
f = na()
a.sort()
f.sort(reverse=True)
score = [ai * fi for ai, fi in zip(a, f)]
l = -1
r = worst_score + 1
while r - l > 1:
middle = (l + r) // 2
tmp_k = k
for i in range(n):
tmp = math.ceil((score[i] - middle) / f[i])
tmp_k -= max(0, tmp)
if tmp_k < 0:
break
if tmp_k >= 0:
r = middle
else:
l = middle
print(r)
if __name__ == '__main__':
main()
| from math import floor
def solve(X, D, lb, ub):
# min abs(X + t * D) (lb <= t <= ub) (lb, ub, t are int)
ts = [
lb,
ub,
max(min(floor(-X / D), ub), lb),
max(min(floor(-X / D) + 1, ub), lb),
]
return min([abs(X + t * D) for t in ts])
X, K, D = map(int, input().split())
y1 = X - K * D
y2 = X + K * D
if (y1 > 0 and y2 > 0) or (y1 < 0 and y2 < 0): # same sign
print(min(abs(y1), abs(y2)))
else:
if K % 2 == 0:
ans = solve(X, D * 2, -(K // 2), +(K // 2))
else:
ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
ans = min(ans1, ans2)
print(ans)
| 0 | null | 84,876,818,583,440 | 290 | 92 |
# -*- coding: utf-8 -*-
def selection_sort(a, n):
count = 0
for i in range(n):
minj = i
for j in range(i+1, n):
if a[j] < a[minj]:
minj = j
a[i], a[minj] = a[minj], a[i]
if a[i] != a[minj]:
count += 1
return a, count
def main():
input_num = int(input())
input_list = [int(i) for i in input().split()]
ans_list, count = selection_sort(input_list, input_num)
for i in range(input_num):
if i != 0:
print(" ", end="")
print(ans_list[i], end='')
print()
print(count)
if __name__ == '__main__':
main() | import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
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())
def main():
n = I()
a = LI()
acc = 0
for i in a:
acc ^= i
ans_lst = []
for i in a:
ans = acc^i
ans_lst.append(ans)
print(*ans_lst)
main()
| 0 | null | 6,301,757,826,084 | 15 | 123 |
# BFS
from collections import deque
h, w = map(int, input().split())
s = [input() for _ in range(h)]
ans = 0
for i in range(h):
for j in range(w):
if s[i][j] == '#': continue
q = deque([(i, j)])
dist = [[-1]*w for _ in range(h)]
dist[i][j] = 0
while q:
x, y = q.popleft()
for k, l in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
if 0 <= x+k < h and 0 <= y+l < w and dist[x+k][y+l] < 0 and s[x+k][y+l] == '.':
dist[x+k][y+l] = dist[x][y] + 1
ans = max(ans, dist[x+k][y+l])
q.append((x+k, y+l))
print(ans) | from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
h, w = map(int, input().split())
ini_grid = []
ans = 0
for i in range(h):
s = list(input())
ini_grid.append(s)
dd = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for i in range(h):
for j in range(w):
if ini_grid[i][j] == '.':
temp_grid = [row[:] for row in ini_grid]
dis_grid = [[-1]*w for i in range(h)]
dis_grid[i][j] = 0
dq = deque([(i, j, 0)])
temp_grid[i][j] = '#'
while dq:
curr = dq.popleft()
for di, dj in dd:
ni = curr[0] + di
nj = curr[1] + dj
if (0 <= ni <= h-1) and (0 <= nj <= w-1) and temp_grid[ni][nj] == '.':
temp_grid[ni][nj] = '#'
dis_grid[ni][nj] = curr[2] + 1
dq.append((ni, nj, curr[2] + 1))
if curr[2] + 1 > ans:
ans = curr[2] + 1
print(ans) | 1 | 94,369,618,916,102 | null | 241 | 241 |
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
dp=[0]*N
data={'r':P,'s':R,'p':S}
ans=0
for i in range(N):
if 0<=i-K:
if T[i-K]==T[i]:
if dp[i-K]==0:
ans+=data[T[i]]
dp[i]=1
else:
ans+=data[T[i]]
dp[i]=1
else:
dp[i]=1
ans+=data[T[i]]
print(ans) | def main():
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = list(input())
score=0
for i in range(N):
if T[i] == 'r':
score+=P
if i+K<N and T[i+K]=='r':
T[i+K]='x'
if T[i]=='s':
score+=R
if i+K<N and T[i+K]=='s':
T[i+K]='x'
if T[i]=='p':
score+=S
if i+K<N and T[i+K]=='p':
T[i+K]='x'
print(score)
if __name__ == '__main__':
main() | 1 | 106,369,923,124,062 | null | 251 | 251 |
N = int(input())
s = input()
r_count = s.count('R')
new_s = s[:r_count]
print(new_s.count('W'))
| N = int(input())
C = list(input())
Rn = C.count('R')
print(C[:Rn].count('W')) | 1 | 6,268,623,975,890 | null | 98 | 98 |
N,K=map(int,input().split())
ans=[0]*(K+1)
mod=10**9+7
for i in range(K,0,-1):
ans[i]=pow((K//i),N,mod)
ind=2
while i*ind<=K:
ans[i]-=ans[i*ind]
ans[i]%=mod
ind+=1
res=0
for i in range(1,K+1):
res+=i*ans[i]
res%=mod
print(res) | # -*- coding: utf-8 -*-
char = input()
print(char.swapcase())
| 0 | null | 19,216,031,663,598 | 176 | 61 |
m_1,d_1 = map(int,input().split())
m_2,d_2 = map(int,input().split())
if m_1 < m_2:
print('1')
else:
print('0') | a=list(map(int,input().split()))
b=list(map(int,input().split()))
if a[0]!=b[0]:
print('1')
else:
print('0') | 1 | 123,827,032,010,668 | null | 264 | 264 |
import sys
line = sys.stdin.readline()
s = int(line) % 60
i = int(line) / 60
m = i % 60
h = i /60
print str(h) + ":" + str(m) + ":" + str(s) | S = int(input())
h = S//(60*60)
m = (S%(60*60))//60
s = (S%(60*60))%60
print(h, ':', m, ':', s, sep='')
| 1 | 328,233,137,550 | null | 37 | 37 |
def solve():
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
if m1 != m2:
print(1)
else:
print(0)
if __name__ == '__main__':
solve()
| m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
end = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if d1 == end[m1-1]:
print(1)
else:
print(0) | 1 | 124,664,615,209,332 | null | 264 | 264 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
N = INT()
if N%2:
print(0)
exit()
ans = 0
i = 1
while 1:
if 2*5**i <= N:
ans += N //(2*5**i)
i += 1
else:
break
print(ans)
| import sys
input = sys.stdin.readline
n = int(input())
a = 0
if n % 2 == 1:
a == 0
else:
n = n // 2
k = 5
while k <= n:
a += n // k
k *= 5
print(a) | 1 | 116,213,502,409,840 | null | 258 | 258 |
import sys
s = sys.stdin.read()
s = s.lower()
c = 97
while chr(c-1)!='z':
print('{0} : {1}'.format(chr(c),s.count(chr(c))))
c += 1
| 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
n = int(input())
cnt = 0
lis = list(set(prime_factorize(n)))
for i in range(len(lis)):
for j in range(1, 10**9):
if n % lis[i]**j == 0:
n /= lis[i]**j
cnt+=1
else:
break
print(cnt)
| 0 | null | 9,232,187,192,352 | 63 | 136 |
S,T=map(str,input().split())
a,b=map(int,input().split())
U=input()
if U == S:
a +=-1
elif U == T:
b += -1
print(a,b) | (s, t), (n, m), q = input().split(), map(int, input().split()), input()
print(f'{n} {m - 1}' if q == t else f'{n - 1} {m}') | 1 | 71,900,395,873,240 | null | 220 | 220 |
W, H ,x, y, r = map(int, input().split())
if ((x-r)<0) or ((y-r)<0) or ((x+r)>W) or ((y+r)>H):
print("No")
else:
print("Yes") | W, H, x, y, r = map(int, input().split())
delta = [[r, 0], [-r, 0], [0, r], [0, -r]]
for dx, dy in delta:
if 0 <= x + dx <= W and 0 <= y + dy <= H:
pass
else:
print('No')
exit(0)
print('Yes')
| 1 | 449,844,662,840 | null | 41 | 41 |
n, k, c = map(int, input().split())
s = input()
l = len(s) - 1
i = 0
lb = []
le = []
while i < len(s) and len(lb) < k:
if s[i] == 'o':
lb.append(i)
i += c + 1
continue
i += 1
while l > -1 and len(le) < k:
if s[l] == 'o':
le.append(l)
l -= (c + 1)
continue
l -= 1
le.sort()
for j in range(0, len(lb)):
if lb[j] == le[j]:
print(lb[j]+1) | n,k,c = map(int,raw_input().split())
s = raw_input()
most = [0]*(n+1)
i = n
days = 0
while i > 0:
if s[i-1] == 'o':
days += 1
for j in xrange(min(max(1,c),i-1)):
#print days
#print i,j,1,days
most[i-j-1] = days
i -= (c+1)
else:
i -= 1
if i<n:
most[i] = most[i+1]
remain = k
i = 1
while i<=n:
if s[i-1] == 'o':
if most[i] < remain:
print i
remain -= 1
i += c+1
else:
i += 1 | 1 | 40,556,750,507,458 | null | 182 | 182 |
S = input()
if S == "AAA" or S == "BBB":
print("No")
else:
print("Yes")
| S = input()
Q = int(input())
T = ""
for q in range(Q):
que = input().split()
if que[0]=="1":
S,T = T,S
else:
if que[1]=="1":
T+=que[2]
else:
S+=que[2]
print(T[::-1]+S) | 0 | null | 55,916,050,395,432 | 201 | 204 |
def main():
N = int(input())
comment = []
for i in range(1, N + 1):
A = int(input())
for j in range(1, A + 1):
c = [i]
c.extend(list(map(int, input().split())))
comment.append(c)
ans = 0
for i in range(1, 2**N):
flg = True
for h, t, c in comment:
#発言者が正直者か
if i & (1 << h - 1):
#発言が適切か
if ((i >> t - 1) & 0b1) ^ c:
flg = False
break
if flg:
tmp = 0
for j in range(N):
if i & (1 << j):
tmp += 1
ans = max(ans, tmp)
print(ans)
if __name__ == '__main__':
main() | def main():
import itertools
n = int(input())
test = []
for i in range(n):
a = int(input())
t = []
for j in range(a):
x,y = map(int,input().split())
t.append([x,y])
test.append(t)
stats = ((0,1) for i in range(n))
ans = 0
for k in itertools.product(*stats):
tf = [-1 for i in range(n)]
flg = 0
for i in range(len(k)):
if k[i]==1:
for t in test[i]:
if tf[t[0]-1]==-1:
tf[t[0]-1] = t[1]
else:
if tf[t[0]-1] != t[1]:
flg = 1
break
for i in range(len(k)):
if tf[i] != -1:
if tf[i] != k[i]:
flg = 1
break
if flg == 0:
if ans < sum(k):
ans = sum(k)
print(ans)
if __name__ == "__main__":
main()
| 1 | 121,151,577,886,934 | null | 262 | 262 |
N,K = map(int,input().split())
ans=1
p=K
while p <= N:
p *= K
ans+=1
print(ans) | N, M = map(int, input().split())
A = list(map(int, input().split()))
total_days = sum(A)
if total_days <= N:
print(N - total_days)
else:
print(-1)
| 0 | null | 48,000,537,414,560 | 212 | 168 |
n, x, t = map(int,input().split(' '))
r = int(n / x) + (1 if n % x > 0 else 0)
print(r * t) | s = input()
print(s[:3].lower()) | 0 | null | 9,488,771,219,232 | 86 | 130 |
X=int(input())
big=X//500
small=(X%500)//5
print(1000*big+5*small) | x = int(input())
n_500 = int(x / 500)
h = 1000 * n_500
x -= 500 * n_500
n_5 = int(x / 5)
h += 5 * n_5
print(int(h))
| 1 | 42,905,199,736,608 | null | 185 | 185 |
def selectionSort(a,b):
for i in range(len(a)):
mini = i
for j in range(i,len(a)):
if a[j] < a[mini]:
mini = j
if i != mini:
ret = a[i]
a[i] = a[mini]
a[mini] = ret
ret = b[i]
b[i] =b[mini]
b[mini] = ret
output = []
for i in range(len(a)):
output.append(str(b[i])+str(a[i]))
print(" ".join(output))
return output
def bubblesort(a,b):
swap = True
while swap:
swap = False
for j in range(1,len(a))[::-1]:
if a[j] < a[j-1]:
ret = a[j]
a[j] = a[j-1]
a[j-1] = ret
ret = b[j]
b[j] = b[j-1]
b[j-1] = ret
swap = True
output = []
for i in range(len(a)):
output.append(str(b[i])+str(a[i]))
print(" ".join(output))
return output
n = int(input())
card = input().split()
number = []
mark = []
number2 = []
mark2 = []
for i in range(n):
number.append(int(list(card[i])[1]))
mark.append(list(card[i])[0])
number2.append(int(list(card[i])[1]))
mark2.append(list(card[i])[0])
output1 = bubblesort(number,mark)
print("Stable")
output2 = selectionSort(number2, mark2)
print("Stable" if output1 == output2 else "Not stable" ) | import sys
readline = sys.stdin.readline
li = []
for i, s in enumerate(readline().strip()):
if s == "\\":
li.append([i, 0])
elif s == "/":
if li:
if li[-1][1] == 0:
li[-1][1] = i - li[-1][0]
else:
for j in range(len(li) - 1, -1, -1):
if li[j][1] == 0:
li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]]
break
ans = []
for a in li:
if a[1] != 0:
ans.append(a[1])
print(sum(ans))
print(len(ans), *ans)
| 0 | null | 44,398,301,932 | 16 | 21 |
import sys
dataset = sys.stdin.readlines()
def gcd(a, b):
if b > a: return gcd(b, a)
if a % b == 0: return b
return gcd(b, a % b)
def lcd(a, b):
return a * b // gcd(a, b)
for item in dataset:
a, b = list(map(int, item.split()))
print(gcd(a, b), lcd(a,b)) | from decimal import Decimal
x = int(input())
t = 100
n = 0
while t < x:
t += t // 100
n += 1
print(n) | 0 | null | 13,519,060,234,600 | 5 | 159 |
n=int(input())
x=[-1]*(10**7+5)
x[0]=0
x[1]=1
i=2
x=[-1]*(10**7+5) #2以上の自然数に対して最小の素因数を表す
x[0]=0
x[1]=1
i=2
prime=[]
while i<=10**7+1:
if x[i]==-1:
x[i]=i
prime.append(i)
for j in prime:
if i*j>10**7+1 or j>x[i]:break
x[j*i]=j
i+=1
def f(k):
if k==1:
return 1
z=[]
p=x[k]
m=1
ans=1
while k>=2:
k=k//p
if p==x[k]:
m+=1
else:
z.append(m)
m=1
p=x[k]
for i in range(len(z)):
ans*=z[i]+1
return ans
s=0
for i in range(1,n+1):
s+=i*f(i)
print(s)
| import math
N = int(input())
cnt_list = [0] * N
for i in range(1, N + 1):
for j in range(i, N + 1, i):
cnt_list[j - 1] += 1
ans = 0
for h in range(1, N + 1):
ans += h * cnt_list[h -1]
print(ans) | 1 | 11,120,574,279,328 | null | 118 | 118 |
import sys
def f(x,y):
return x-y,x+y
def main():
n = int(input())
x = [0]*n
y = [0]*n
for i in range(n):
x[i],y[i] = map(int,input().split())
f0 = [0]*n
f1 = [0]*n
for i in range(n):
f0[i],f1[i] = f(x[i],y[i])
print(max(max(f0)-min(f0),max(f1)-min(f1)))
if __name__ == "__main__":
main() | import sys
input = sys.stdin.readline
def main():
H = int(input())
W = int(input())
N = int(input())
q, r, = divmod(N, max(H, W))
ans = q
ans += 1 if r > 0 else 0
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 46,247,687,816,908 | 80 | 236 |
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
s.append(list(map(int, input().split())))
t = []
for _ in range(D):
t.append(int(input()))
# last(d, i)を計算するためのメモ
dp = [0] * 26
def dec(d):
# d日の終わりに起こる満足度の減少計算の関数
s = 0
for j in range(26):
s += c[j] * (d - dp[j])
return s
# vは満足度
v = 0
for i in range(D):
# 初日の満足度
if (i == 0):
v += s[i][t[i] - 1]
# 開催されたコンテストの日付をメモ
dp[t[i] - 1] = (i + 1)
v -= dec(i + 1)
print(v)
continue
# elif (0 < i and i < D - 1):
v += s[i][t[i] - 1]
dp[t[i] - 1] = (i + 1)
v -= dec(i + 1)
print(v)
| # ####################################################################
# import io
# import sys
# _INPUT = """\
# 5
# 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
# 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
# 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
# 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
# 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
# 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
# 1
# 17
# 13
# 14
# 13
# """
# sys.stdin = io.StringIO(_INPUT)
# ####################################################################
D = int(input())
C = [int(i) for i in input().split()]
SS = [[int(i) for i in input().split()] for _ in range(D)]
T = [int(input()) for _ in range(D)]
L = [0]*26
v = 0
for d, t in enumerate(T):
t -= 1
L[t] = d+1
v += SS[d][t]
for c, l in zip(C, L):
v -= c * (d+1 - l)
# v += C[t]
print(v)
| 1 | 9,931,352,706,928 | null | 114 | 114 |
import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
def cal(x):
s = 0
for aa in a:
s += math.ceil(aa / x) - 1
if s <= K: return True
else: return False
l = 0
r = max(a)
while r - l > 1:
mid = (l + r) // 2
if cal(mid):
r = mid
else:
l = mid
print(r) | import sys
#from collections import deque
#from functools import *
#from fractions import Fraction as f
from copy import *
from bisect import *
#from heapq import *
from math import gcd,ceil,sqrt
from itertools import permutations as prm,product
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def inc(d,c,x=1):
d[c]=d[c]+x if c in d else x
def bo(i):
return ord(i)-ord('A')
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a,b):
if(a>b):
return 2
return 2 if a==b else 0
def gi():
return [xx for xx in input().split()]
def fi():
return int(input())
def pro(a):
return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
a[i],a[j]=a[j],a[i]
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def isvalid(i,j):
return 0<=i<n and 0<=j<m and a[i][j]!="."
def bo(i):
return ord(i)-ord('a')
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
t=1
mod=998244353
while t>0:
t-=1
n,k,m=mi()
vis={}
cycle=[]
i=ans=0
while k not in vis:
cycle.append(k)
vis[k]=i
i+=1
ans+=k
if i==n:
print(ans)
exit(0)
k=(k**2)%m
if k in vis:
cycle=cycle[vis[k]:]
n-=i
s=sum(cycle)
p=n%len(cycle)
z=len(cycle)
print(ans+(n//z)*s+sum(cycle[:p]))
| 0 | null | 4,704,292,565,388 | 99 | 75 |
a,b,c = map(int,input().split())
if 4*a*b < (c-a-b)**2 and c-a-b > 0:
ans = 1
else:
ans = 0
print(["No","Yes"][ans]) | #coding:utf-8
import math
N,K = map(int,input().split())
A = [int(y) for y in input().split()]
Ma = max(A)
mi = 1
ans = Ma
def execute(f):
count = 0
for i in A:
count += math.ceil(i / f) - 1
if count <= K:
return True
else:
return False
while True:
median = (Ma + mi) // 2
bobo = execute(median)
if bobo:
ans = min(ans,median)
Ma = median
else:
mi = median + 1
if Ma == mi:
break
print("{}".format(ans)) | 0 | null | 28,950,672,132,872 | 197 | 99 |
import math
X, K, D = map(int, input().split())
kyori = abs(X)
kaisu = math.ceil(kyori / D)
if(K < kaisu):
ans = kyori - (K * D)
#if(X < 0):
# print(-ans)
#else:
# print(ans)
else:
if((K - kaisu) % 2 == 0):
ans = kyori - (kaisu * D)
else:
ans = kyori - (kaisu * D) + D
#if(X < 0):
# print(-ans)
#else:
# print(ans)
print(abs(ans)) | import sys
# x = abs(int(input()))
# k = int(input())
# d = int(input())
array = list(map(int, input().strip().split()))
x = abs(array[0])
k = array[1]
d = array[2]
if (d == 0):
amari = abs(x)
else:
move_cnt = int(x / d)
if (move_cnt <= k):
k -= move_cnt
amari = x - move_cnt * d
else:
amari = x - k * d
k = 0
if (k > 0):
if (k % 2 == 1):
if (amari > 0):
amari -= d
else:
amari += d
print(abs(amari)) | 1 | 5,227,836,371,300 | null | 92 | 92 |
n=int(input())
s=str(input())
if(n%2!=0):
print('No')
else:
if(s[0:len(s)//2]==s[len(s)//2:]):
print('Yes')
else:
print('No') | 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")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
N = int(input())
S = input()
if N % 2 == 0:
if S[:N//2] == S[N//2:]:
print("Yes")
else:
print("No")
else:
print("No") | 1 | 146,893,813,413,258 | null | 279 | 279 |
N = int(input())
ans = 0
ans = -(-N//2)
print(ans) | N = int(input())
a = 0
b = 0
if N % 2 == 0:
a = N // 2
print(a)
else:
b = N // 2 + 1
print(b) | 1 | 58,893,081,839,680 | null | 206 | 206 |
n = int(input())
g = []
for i in range(n):
a = list(map(int,input().split()))
g.append(a[2:])
d = [0]*n
f = [0]*n
global t
t = 0
def find(x):
global t
if len(g[x-1]) == 0:
t += 1
f[x-1] = t
else:
for i in g[x-1]:
if d[i-1] == 0:
t += 1
d[i-1] = t
find(i)
t += 1
f[x-1] = t
for i in range(n):
if d[i] == 0:
t += 1
d[i] = t
find(i+1)
for i in range(n):
print(i+1, d[i], f[i])
| h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
a[i], b[i] = map(int, input().split())
dp = [[1e18] * (h + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(h + 1):
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
dp[i + 1][min(j + a[i], h)] = min(dp[i + 1][min(j + a[i], h)], dp[i + 1][j] + b[i])
print(dp[n][h]) | 0 | null | 40,362,090,215,160 | 8 | 229 |
# -*- 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) | from math import *
def az9():
r = float(input())
print "%5f"%(pi*r*r), "%5f"%(2*pi*r)
az9() | 1 | 649,052,112,368 | null | 46 | 46 |
''' ===========================================
from collections import deque
appendleft() = push_front(), append = push_back()
popfleft() = pop_front(), pop() = pop_back()
import heapq #heappush(trgt, val) heappop(trgt) trgt[0] __lt__<
=========================================== '''
##======================================python3
import sys
import collections
from sys import stdin #read(), readline()
sys.setrecursionlimit(10**6)
INF = 1<<50
MINI = 100005
class gv:
input = None;
def build():
gv.str = input()
def solve():
slen = len(gv.str)
if (slen&1) == 1:
print("No")
return
for i in range(0,slen,2):
if (gv.str[i:i+2] == "hi") :
pass
else :
print("No")
return
print("Yes")
if __name__ == '__main__':
build()
solve()
| import sys
# sys.setrecursionlimit(100000)
from collections import deque
from collections import defaultdict
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():
# 各ノードで幅優先探索を行う
# 計算量(O(n^2))
n, x, y = input_int_list()
g = defaultdict(list)
g[x].append(y)
g[y].append(x)
for i in range(1, n):
g[i].append(i + 1)
g[i + 1].append(i)
ans = [0] * (n + 1)
for i in range(1, n + 1):
# 幅優先探索
seen = set()
dq = deque()
dq.append((i, 0)) # node,depth
while dq:
p, d = dq.popleft()
if p > i: # 整数の組(i,j) (1 <= i <= j <= N)
ans[d] += 1
for q in g[p]:
if q not in seen:
dq.append((q, d + 1))
seen.add(q)
for i in range(1, n):
print(ans[i])
return
if __name__ == "__main__":
main()
| 0 | null | 48,809,957,919,090 | 199 | 187 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.