code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
a,b = map(int,input().split())
for i in range(1,1251):
if int(i*0.08)==a and int(i*0.1)==b:
print(i); break
else:
print('-1')
|
import math
A,B=map(int, input().split())
for i in range(1,1001):
if math.floor(i*0.08)==A and math.floor(i*0.1)==B:
print(i)
break
if i==1000:
print(-1)
| 1 | 56,464,228,977,538 | null | 203 | 203 |
import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)
def main():
m, d = na()
n, s = na()
if s == 1:
print(1)
else:
print(0)
if __name__ == '__main__':
main()
|
M1,D1 = [ int(i) for i in input().split() ]
M2,D2 = [ int(i) for i in input().split() ]
print("1" if M1 != M2 else "0")
| 1 | 124,438,534,892,520 | null | 264 | 264 |
x = list(map(int,input().split()))
x[0],x[1] = x[1],x[0]
x[0],x[2] = x[2],x[0]
print(str(x[0]) +" " + str(x[1]) + " "+ str(x[2]))
|
X, Y, Z = map(int, input().split())
print('{} {} {}'.format(Z, X, Y))
| 1 | 37,895,486,343,582 | null | 178 | 178 |
from itertools import permutations as p
from math import factorial as f
from math import sqrt as s
def func(x1, x2, y1, y2): return s((x2-x1) ** 2 + (y2-y1) ** 2)
N = int(input())
xy = list(list(map(int,input().split())) for _ in range(N))
total = 0
for l in p(range(1, N+1)):
for i in range(N-1):
total += func(xy[l[i]-1][0], xy[l[i+1]-1][0], xy[l[i]-1][1], xy[l[i+1]-1][1])
print(total / f(N))
|
import itertools
import math
N = int(input())
x_list = [0] * N
y_list = [0] * N
for i in range(N):
x_list[i], y_list[i] = map(int, input().split())
l_sum = 0
l = 0
for comb in itertools.combinations(range(N), 2):
l = (
(x_list[comb[0]] - x_list[comb[1]]) ** 2
+ (y_list[comb[0]] - y_list[comb[1]]) ** 2
) ** 0.5
l_sum += l
ans = 2 * l_sum / N
print(ans)
| 1 | 148,473,550,550,752 | null | 280 | 280 |
a=[str(i) for i in range(1,10)]
i=0
while len(a)<100000:
if a[i][-1]!="0":
a.append(a[i]+str(int(a[i][-1])-1))
a.append(a[i]+str(int(a[i][-1])))
if a[i][-1]!="9":
a.append(a[i]+str(int(a[i][-1])+1))
i+=1
# print(a[:30])
k=int(input())
print(a[k-1])
|
def is_prime(x):
if x == 2:
return True
elif x < 2 or x % 2 == 0:
return False
else:
i = 3
while i <= x ** 0.5:
if x % i == 0:
return False
i += 2
return True
n = int(input())
ret = 0
while n:
x = int(input())
if is_prime(x): ret += 1
n -= 1
print(ret)
| 0 | null | 19,992,154,109,580 | 181 | 12 |
while True:
h, w = map(int, input().split())
if(w == h == 0): break
for i in range(h):
for j in range(w):
if (i + j) % 2:
print('.', end = '')
else:
print('#', end = '')
print('')
print('')
|
#!/usr/bin/python
ar = []
while True:
tmp = [int(i) for i in input().split()]
if tmp == [0,0]:
break
else:
ar.append(tmp)
for i in range(len(ar)):
for j in range(ar[i][0]):
for k in range(ar[i][1]):
if ( j + k ) % 2 == 0:
print('#' , end='' if k !=ar[i][1]-1 else '\n' if j != ar[i][0]-1 else '\n\n')
else:
print('.' , end='' if k !=ar[i][1]-1 else '\n' if j != ar[i][0]-1 else '\n\n')
| 1 | 878,991,227,570 | null | 51 | 51 |
N1=int(input())
array1=input().split()
N2=int(input())
array2=input().split()
c=0
for n2 in range(N2):
if array2[n2] in array1:
c+=1
print(c)
|
n = int(input())
S = set(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
sum = 0
for i in T:
if i in S:
sum +=1
print(sum)
| 1 | 67,769,683,892 | null | 22 | 22 |
n,t=map(int,input().split())
dish=[list(map(int,input().split())) for i in range(n)]
dish.sort()
dp=[0]*6001
for i in range(n):
a,b=dish[i]
for j in range(t-1,-1,-1):
dp[j+a]=max(dp[j+a],dp[j]+b)
print(max(dp))
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
class UnionFind:
def __init__(self,n):
self.par = [i for i in range(n+1)] # 親のノード番号
self.rank = [0]*(n+1)
self.X = [1]*(n+1)
def find(self,x): # xの根のノード番号
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def same_check(self,x,y): # x,yが同じグループか否か
return self.find(x) == self.find(y)
def unite(self,x,y): # x,yの属するグループの併合
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
x,y = y,x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
self.par[y] = x
self.X[x] += self.X[y]
N,M = MI()
UF = UnionFind(N)
for i in range(M):
a,b = MI()
if not UF.same_check(a, b):
UF.unite(a,b)
print(max(UF.X))
| 0 | null | 77,558,946,406,690 | 282 | 84 |
import sys
input = sys.stdin.readline
# 二分木
import bisect
n,d,a = map(int,input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort()
x = [ tmp[0] for tmp in xh]
damage = [0] * (n+1)
ans = 0
for i in range(n):
damage[i+1] += damage[i]
if( damage[i+1] >= xh[i][1] ):
continue
atk_num = (xh[i][1] - damage[i+1] - 1)//a +1
ans += atk_num
damage[i+1] += atk_num * a
right = bisect.bisect_right(x, xh[i][0] + 2*d)
if( right < n):
damage[right+1] -= atk_num * a
print(ans)
|
import sys
def input():
return sys.stdin.readline()[:-1]
N,D,A=map(int,input().split())
s=[tuple(map(int, input().split())) for i in range(N)]
s.sort()
d=2*D+1
t=0
p=0
l=[0]*N
a=0
for n,i in enumerate(s):
while 1:
if t<N and s[t][0]<i[0]+d:
t+=1
else:
break
h=i[1]-p*A
if h>0:
k=-(-h//A)
a+=k
p+=k
l[t-1]+=k
p-=l[n]
print(a)
| 1 | 82,002,804,008,840 | null | 230 | 230 |
while 1:
n,x=map(int,input().split())
if n == 0 and x == 0: break
print(len([1 for a in range(1,n+1) for b in range(a+1,n+1) for c in range(b+1,n+1) if a + b + c == x]))
|
while True:
count=0
n,x = map(int,input().split())
if n==x==0: break
for a in range(n):
for b in range(n):
for c in range(n):
if a<b<c and a+b+c==x-3:
count+=1
print(count)
| 1 | 1,293,323,143,920 | null | 58 | 58 |
str = input()
num = int(str)
if num % 2 == 0:
print('-1');
else:
i = 1
j = 7
while j % num != 0 and i <= num:
j = (j % num) * 10 + 7
i += 1
if i > num:
print('-1');
else:
print(i);
|
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
k = II()
sevens = 7%k
for i in range(1, k+1):
if sevens % k == 0:
print(i)
return
sevens = (10*sevens + 7)%k
print(-1)
if __name__ == '__main__':
main()
| 1 | 6,127,644,489,592 | null | 97 | 97 |
def resolve():
n,k = map(int,input().split())
print(min(n-k*(n//k),abs(n-k*(n//k)-k)))
resolve()
|
n,k = map(int,input().split())
a = n%k
b = k-a
print(min(a,b))
| 1 | 39,466,947,197,180 | null | 180 | 180 |
n = int(input())
S=[]
for i in range(n):
S.append(input())
S.sort()
c=1
for i in range(n-1):
if S[i]!=S[i+1] :
c+=1
print( c )
|
N = int(input())
get = set()
for _ in range(N):
s = str(input())
get.add(s)
print(len(get))
| 1 | 30,213,678,495,812 | null | 165 | 165 |
s = str(input())
p = str(input())
if p[0] not in s:
print("No")
elif p in s:
print("Yes")
else:
for i in range(len(s)):
s = s[1:] + s[:1]
if p in s:
print("Yes")
break
else:
print("No")
|
s = input()
p = input()
if (s * 2).find(p) >= 0:
print("Yes")
else:
print("No")
| 1 | 1,738,076,446,480 | null | 64 | 64 |
while True:
x = [int(z) for z in input().split(" ")]
if x[0] == 0 and x[1] == 0: break
for h in range(0,x[0]):
dot = h % 2
for w in range(0,x[1]):
if (dot == 0 and w % 2 == 0) or (dot == 1 and w % 2 == 1):
print("#", end="")
else:
print(".", end="")
print("\n", end="")
print("")
|
n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
def can_load(W, k, q, n):
i = 0
for _ in range(k):
s = 0
while i < n and s + W[i] <= q:
s += W[i]
i += 1
if i == n:
return True
else:
return False
# 積載量をmidと仮定して二分探索
hi = 10 ** 9 # OK
lo = 0 # NG
while hi - lo > 1:
mid = (hi + lo) // 2
if can_load(W, k, mid, n):
hi = mid
else:
lo = mid
print(hi)
| 0 | null | 478,212,363,992 | 51 | 24 |
n,k=map(int,input().split())
a=list(map(lambda x:(int(x)-1)%k,input().split()))
s=[0]
for i in a:
s.append((s[-1]+i)%k)
mp={}
ans=0
for i in range(len(s)):
if i-k>=0:
mp[s[i-k]]-=1
if s[i] in mp:
ans+=mp[s[i]]
mp[s[i]]+=1
else:
mp[s[i]]=1
print(ans)
|
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
def main():
n,m,k = map(int,ipt().split())
fl = [[] for i in range(n)]
bl = [set() for i in range(n)]
for i in range(m):
a,b = map(int,ipt().split())
fl[a-1].append(b-1)
fl[b-1].append(a-1)
for i in range(k):
c,d = map(int,ipt().split())
bl[c-1].add(d-1)
bl[d-1].add(c-1)
ans = [-1]*n
al = [True]*n
for i in range(n):
if al[i]:
q = [i]
al[i] = False
st = set([i])
while q:
qi = q.pop()
for j in fl[qi]:
if al[j]:
st.add(j)
al[j] = False
q.append(j)
lst = len(st)
for j in st:
tmp = lst-len(fl[j])-1
for k in bl[j]:
if k in st:
tmp -= 1
ans[j] = tmp
print(" ".join(map(str,ans)))
return None
if __name__ == '__main__':
main()
| 0 | null | 99,704,229,815,860 | 273 | 209 |
INF = 10**18
def solve(n, a):
# 現在の位置 x 選んだ個数 x 直前を選んだかどうか
dp = [{j: [-INF, -INF] for j in range(i//2-1, (i+1)//2 + 1)} for i in range(n+1)]
dp[0][0][False] = 0
for i in range(n):
for j in dp[i].keys():
if (j+1) in dp[i+1]:
dp[i+1][j+1][True] = max(dp[i+1][j+1][True], dp[i][j][False] + a[i])
if j in dp[i+1]:
dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][False])
dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][True])
return max(dp[n][n//2])
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
|
n,*l=map(int,open(0).read().split())
p=[0,0]
d=p[:]
for l in l:d+=max(l+d[-2],[d,p][len(d)&1][-1]),;p+=l+p[-2],
print(d[-1])
| 1 | 37,297,314,735,408 | null | 177 | 177 |
def main():
a,b = list(map(int, input().split()))
ans = a - 2*b
ans = 0 if ans < 0 else ans
print(ans)
if __name__ == '__main__':
main()
|
t = input()
ans = ""
if t[len(t)-1] == "s":
ans = t + "es"
else:
ans = t + "s"
print(ans)
| 0 | null | 84,337,842,522,932 | 291 | 71 |
N,M = map(int,input().split())
print(sum(range(0,N))+sum(range(0,M)))
|
#!/usr/bin/python
#-coding:utf8-
for i in range(10)[1:]:
for j in range(10)[1:]:
print "%dx%d=%d" % ( i,j,i*j )
| 0 | null | 22,826,547,452,928 | 189 | 1 |
A, B = map(int,input().split())
mult = A * B
print(mult)
|
import numpy as np
# 複数個格納
# A,B = map(int, input().split())
#A = int(input())
# 行列化
# A = np.array(A)
# A=A.reshape(1,-1)
# A=A.T
#行列の比較
#C=((A%2 == vector0).all())
#行列の作成
#A=(np.arange(0,2000,500)).reshape(1,-1)
A,B = map(int, input().split())
print(A*B)
| 1 | 15,774,447,011,558 | null | 133 | 133 |
N = int(input())
edges = [[] for _ in range(N)]
for i in range(N - 1):
fr, to = map(lambda a: int(a) - 1, input().split())
edges[fr].append((i, to))
edges[to].append((i, fr))
ans = [-1] * (N - 1)
A = [set() for _ in range(N)]
st = [0]
while st:
now = st.pop()
s = 1
for i, to in edges[now]:
if ans[i] != -1:
continue
while s in A[now]:
s += 1
ans[i] = s
A[to].add(s)
A[now].add(s)
st.append(to)
print(max(ans))
print(*ans, sep="\n")
|
import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *AB = map(int, read().split())
G = [[] for _ in range(N)]
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
G[a - 1].append((i, b - 1))
G[b - 1].append((i, a - 1))
color = [0] * (N - 1)
def dfs(v, p, pc):
c = 1
for i, nv in G[v]:
if nv == p:
continue
if c == pc:
c += 1
color[i] = c
dfs(nv, v, c)
c += 1
dfs(0, -1, 0)
print(max(color))
print('\n'.join(map(str, color)))
return
if __name__ == '__main__':
main()
| 1 | 136,615,213,986,588 | null | 272 | 272 |
import bisect
n = int(input())
l_li = list(map(int,input().split()))
l_li.sort()
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
ind = bisect.bisect_left(l_li,l_li[i]+l_li[j])
num = ind-1 - j
ans += num
print(ans)
|
def main():
a = int(input())
print(a + a**2 + a**3)
if __name__ == '__main__':
main()
| 0 | null | 90,734,089,751,408 | 294 | 115 |
n = int(input()[-1])
if n in [2, 4, 5, 7, 9]:
print("hon")
elif n == 3:
print("bon")
else:
print("pon")
|
import sys
read = sys.stdin.read
def main():
h, n = map(int, input().split())
m = map(int, read().split())
mm = zip(m, m)
large_num = 10**9
dp = [large_num] * (h + 10**4 + 1)
dp[0] = 0
for a, b in mm:
for i1 in range(h + 1):
if dp[i1 + a] > dp[i1] + b:
dp[i1 + a] = dp[i1] + b
r = min(dp[h:])
print(r)
if __name__ == '__main__':
main()
| 0 | null | 50,015,187,827,968 | 142 | 229 |
# Sum of Numbers
end = 0
while end == 0:
number = list(input())
if number == ["0"]:
end += 1
else:
# print(number)
digitTotal = 0
for digit in number:
digitTotal += int(digit)
print(digitTotal)
|
K = int(input())
verbose = False
path = set()
a = 0
step = 0
while True:
step += 1
a = (a*10 + 7) % K
if verbose: print (step, ':', a)
if a == 0:
print (step)
break
if a in path:
print ('-1')
break
path.add(a)
| 0 | null | 3,822,884,724,160 | 62 | 97 |
l, r, d = map(int, input().split())
result=0
for i in range(r-l+1):
if (l+i) % d == 0:
result+=1
print(result)
|
import math
lrd=input().split()
l=int(lrd[0])
r=int(lrd[1])
d=int(lrd[2])
a=math.ceil(l/d)
b=math.floor(r/d)
print(b-a+1)
| 1 | 7,543,294,807,520 | null | 104 | 104 |
# -*- coding: utf-8 -*-
## Library
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
## input
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split())
# P = [list(map(int,input().split())) for i in range(M)]
# S = []
# for _ in range(N):
# S.append(list(input()))
N=int(input())
for i in range(1,N+1):
if floor(i*1.08)==N:
print(i)
sys.exit()
print(":(")
|
l,r,d =map(int,input().split())
rd = r//d
ld = (l-1)//d
answer = rd -ld
print(answer)
| 0 | null | 66,439,031,277,178 | 265 | 104 |
import sys
import numpy as np
sys.setrecursionlimit(10 ** 9)
N = int(input())
A = list(map(int,input().split()))
dp = np.full((N, 3), 0, dtype=int)
dp[0][0] = A[0]
dp[1][1] = A[1]
if N != 2:
dp[2][2] = A[2]
dp[2][0] = A[0] + A[2]
for i in range(3,N):
if i & 1:
dp[i][1] = max(dp[i-3][0], dp[i-2][1]) + A[i]
else:
dp[i][0] = dp[i-2][0] + A[i]
dp[i][2] = max(dp[i-4][0], dp[i-3][1], dp[i-2][2]) + A[i]
if N & 1:
ans = max(dp[-3][0], dp[-2][1], dp[-1][2])
else:
ans = max(dp[-2][0], dp[-1][1])
print(ans)
|
import sys
#import copy
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read
inf = float('inf')
#inf = pow(10, 10)
def main():
# input
N = int(readline())
A = list(map(int, readline().split()))
K = N//2
DP0 = [-inf] * N
DP1 = [-inf] * N
DP2 = [-inf] * N
DP2[0] = A[0]
DP2[1] = max(A[0], A[1])
DP1[:2] = [0] * 2
DP0[:4] = [0] * 4
for i in range(2, N):
if i%2 == 0:
DP2[i] = DP2[i-2] + A[i]
DP1[i] = max(DP2[i-1], DP1[i-2] + A[i])
DP0[i] = max(DP1[i-1], DP0[i-2] + A[i])
else:
DP2[i] = max(DP2[i-2] + A[i], DP2[i-1])
DP1[i] = max(DP1[i-1], DP1[i-2] + A[i])
DP0[i] = max(DP0[i-1], DP0[i-2] + A[i])
if N%2 == 0:
ans = DP2[N-1]
else:
ans = DP1[N-1]
#print(DP0)
#print(DP1)
#print(DP2)
print(ans)
if __name__ == "__main__":
main()
| 1 | 37,114,013,326,350 | null | 177 | 177 |
N = int(input())
X = list(map(int, input().split()))
p = 0
s = sum(X)
for n in range(N):
s -= X[n]
s = s % (10**9 + 7)
p += s * X[n]
p = p % (10**9 + 7)
print(p)
|
A,B,C = map(int,input().split())
K = int(input())
for i in range(K):
if A >= B:
B = B*2
else:
C = C*2
print("Yes" if A < B and B < C else "No")
| 0 | null | 5,388,550,446,300 | 83 | 101 |
import sys
N = int(input())
A = tuple(map(int, input().split()))
count = [0] * (10 ** 5 + 1)
for a in A:
count[a] += 1
s = sum(A)
Q = int(input())
for _ in range(Q):
b, c = map(int, sys.stdin.readline().split())
s -= count[b] * b
s += count[b] * c
count[c] += count[b]
count[b] = 0
print(s)
|
def main():
import sys
from collections import Counter
input = sys.stdin.readline
input()
a = Counter(map(int, input().split()))
ans = sum(k * v for k, v in a.items())
for _ in range(int(input())):
b, c = map(int, input().split())
if b in a:
ans += (c - b) * a[b]
print(ans)
a[c] = a[c] + a[b] if c in a else a[b]
del a[b]
else:
print(ans)
if __name__ == "__main__":
main()
| 1 | 12,188,157,468,498 | null | 122 | 122 |
import sys
from functools import reduce
def input():
return sys.stdin.readline()[:-1]
a, b, c, d = map(int, input().split())
ans1 = a * c
ans2 = b * d
ans3 = b * c
ans4 = a * d
print(max([ans1, ans2, ans3, ans4]))
|
a,b,c,d = map(int,input().split())
e = a*c
f = a*d
g = b*c
h = b*d
xy =[e,f,g,h]
print(int(max(xy)))
| 1 | 3,029,502,226,940 | null | 77 | 77 |
k = int(input())
S = input()
n = len(S)
mod = 10**9+7
facs = [1] * (n+k)
# invs = [1] * (n+k)
nfac = 1
for i in range(1, n+k):
nfac = nfac * i % mod
facs[i] = nfac
# invs[i] = pow(facs[i], mod-2, mod)
invn1 = pow(facs[n-1], mod-2, mod)
ans = 0
for i in range(k+1):
left = facs[i+n-1] * pow(facs[i], mod-2, mod) * invn1 % mod
left = left * pow(25, i, mod) % mod
ans += left * pow(26, k-i, mod) % mod
ans %= mod
print(ans)
|
K = int(input())
S = input()
mod = 10**9 + 7
class Combination:
def __init__(self, n):
self.facts = [1 for i in range(n+1)]
self.invs = [1 for i in range(n+1)]
for i in range(1, n+1):
self.facts[i] = self.facts[i-1] * i % mod
self.invs[i] = pow(self.facts[i], mod-2, mod)
def ncr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.facts[n] * self.invs[r] * self.invs[n-r] % mod
def nhr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.ncr(n+r-1, n-1)
N = K+len(S)
pow25 = [1] * (N+1)
pow26 = [1] * (N+1)
for i in range(1, N+1):
pow25[i] = (pow25[i-1] * 25) % mod
pow26[i] = (pow26[i-1] * 26) % mod
comb = Combination(K+len(S))
ans = 0
for i in range(K+1):
ans = (ans + comb.ncr(N-i-1, len(S)-1) * pow25[N-i-len(S)] * pow26[i]) % mod
print(ans)
| 1 | 12,790,316,099,780 | null | 124 | 124 |
X,Y=map(int,input().split())
if 2*Y<X or 2*X<Y:
print(0)
exit()
if not((X%3==0 and Y%3==0) or (X%3==1 and Y%3==2) or (X%3==2 and Y%3==1)):
print(0)
exit()
P=10**9+7
A=(2*Y-X)//3
B=(2*X-Y)//3
num = 1
for i in range(A+1, A+B+1):
num=num*i%P
den = 1
for j in range(1, B+1):
den = den*j%P
den = pow(den,P-2,P)
print((num*den)%P)
|
X, Y = map(int, input().split())
MOD = 10 ** 9 + 7
S = -X + 2 * Y
T = 2 * X - Y
if S < 0 or T < 0:
print(0)
exit()
if S % 3 != 0 or T % 3 != 0:
print(0)
exit()
S //= 3
T //= 3
def cmb(n, r, p):
r = min(n - r, r)
if r == 0:
return 1
over = 1
for i in range(n, n - r, -1):
over = over * i % p
under = 1
for i in range(1, r + 1):
under = under * i % p
inv = pow(under, p - 2, p)
return over * inv % p
# print(S, T)
ans = cmb(S + T, S, MOD) % MOD
print(ans % MOD)
| 1 | 150,441,956,095,218 | null | 281 | 281 |
S = input()
N = len(S)
if N % 2 == 0:
tmp = N // 2
else:
tmp = (N + 1) // 2
ans = 0
for i in range(tmp, N):
if S[i] != S[N - i - 1]:
ans += 1
print(ans)
|
n = int(input())
root = int(n**0.5)
yakusu = 0
for i in range(root, 0, -1):
if n % i == 0:
yakusu = i
break
another = n // yakusu
print(yakusu + another - 2)
| 0 | null | 141,073,681,910,432 | 261 | 288 |
n=int(input())
A=list(input())
w=0 ; r=A.count("R") ; ans=10**7
for i in range(n+1):
ans=min(ans, max(w,r))
if i==n:print(ans);exit()
if A[i]=="R":
r-=1
else:
w+=1
|
import sys
from collections import deque
n = int(sys.stdin.readline().strip())
edges = [[] for _ in range(n)]
for _ in range(n):
tmp = list(map(int, sys.stdin.readline().strip().split(" ")))
for node in tmp[2:]:
edges[tmp[0] - 1].append(node-1)
# print(edges)
distance = [0] * n
q = deque()
q.append((0, 0))
visited = set()
while q:
node, d = q.popleft()
# print(node, d)
if node in visited:
continue
distance[node] = d
visited.add(node)
for next in edges[node]:
# print("next", next)
q.append((next, d + 1))
for i, d in enumerate(distance):
if i == 0:
print(1, 0)
else:
print(i + 1, d if d > 0 else -1)
| 0 | null | 3,193,148,350,650 | 98 | 9 |
n = int(input())
x = list(input())
count = x.count('1')
one_count = count - 1
zero_count = count + 1
one_mod = 0
zero_mod = 0
for b in x:
if one_count:
one_mod = (one_mod * 2 + int(b)) % one_count
zero_mod = (zero_mod * 2 + int(b)) % zero_count
f = [0] * 2000001
pop_count = [0] * 200001
for i in range(1, 200001):
pop_count[i] = pop_count[i//2] + i % 2
f[i] = f[i % pop_count[i]] + 1
for i in range(n):
if x[i] == '1':
if one_count:
nxt = one_mod
nxt -= pow(2, n-i-1, one_count)
nxt %= one_count
print(f[nxt] + 1)
else:
print(0)
if x[i] == '0':
nxt = zero_mod
nxt += pow(2, n-i-1, zero_count)
nxt %= zero_count
print(f[nxt] + 1)
|
if __name__ == "__main__":
A,B,C = map(int,input().split())
K = int(input())
count = 0
while A>=B:
B *= 2
count += 1
while B>=C:
C *= 2
count += 1
print("Yes" if count <= K else "No")
| 0 | null | 7,472,536,354,382 | 107 | 101 |
N = int(input())
for i in range(1 , N + 1):
x = int(i * 1.08)
if x == N:
print(i)
exit()
print(':(')
|
print(max(0,eval(input().replace(' ','-')+'*2')))
| 0 | null | 146,644,907,501,358 | 265 | 291 |
import math
n, m = map(int, input().split())
r = 2
if (n > 1):
cn = math.factorial(n) / (2 * math.factorial(n - r))
else:
cn = 0
if (m > 1):
cm = math.factorial(m) / (2 * math.factorial(m - r))
else :
cm = 0
print(int(cn+cm))
|
import sys,math,collections,itertools
input = sys.stdin.readline
H,N=list(map(int,input().split()))
AB = []
amax = 0
for _ in range(N):
a,b=map(int,input().split())
amax = max(amax,a)
AB.append([a,b])
HN = [float('inf')]*(H+amax+1)
HN[0] = 0
for i in range(H+amax+1):
for j in range(N):
if AB[j][0]<=i:
tmp = HN[i-AB[j][0]]+AB[j][1]
HN[i] = min(HN[i],tmp)
else:
tmp = AB[j][1]
HN[i] = min(HN[i],tmp)
print(min(HN[H:]))
| 0 | null | 63,134,522,768,630 | 189 | 229 |
from collections import defaultdict
N = int(input())
As = list(map(int, input().split()))
l_count = defaultdict(int)
r_count = defaultdict(int)
for i, A in enumerate(As):
l_count[i + A] += 1
r_count[i - A] += 1
ans = 0
for k, lv in l_count.items():
rv = r_count[k]
ans += lv * rv
print(ans)
|
k = int(input())
if k % 7 == 0:
l = 9*k // 7
else:
l = 9*k
if l % 2 == 0 or l % 5 == 0:
print(-1)
else:
pmo = 1
for i in range(1, l + 1):
mo = (pmo * 10) % l
if mo == 1:
print(i)
break
else:
pmo = mo
| 0 | null | 16,001,449,117,930 | 157 | 97 |
n = int(input())
s = ['a']*(n)
#print(''.join(s))
def dfs(x,alp):
if x == n:
print(''.join(s))
return
for i in range(alp+1):
#print(x,alp,i)
s[x] = chr(i+ord("a"))
dfs(x+1,max(i+1,alp))
#print(alp)
dfs(0,0)
|
N = int(input())
a_num = 97
def dfs(s, n): #s: 現在の文字列, n: 残りの文字数, cnt: 現在の文字列の最大の値
if n == 0:
print(s)
return
for i in range(ord("a"), ord(max(s))+2):
dfs(s+chr(i), n-1)
dfs("a", N-1)
| 1 | 52,605,540,619,352 | null | 198 | 198 |
n = int(input())
person = [[0 for _ in range(10)] for _ in range(12)]
for _ in range(n):
b, f, r, v = [int(m) for m in input().split()]
person[3*(b-1)+f-1][r-1] += v
for index, p in enumerate(person):
print(" "+" ".join([str(m) for m in p]))
if (index+1)%3 == 0 and index < len(person)-1:
print("####################")
|
N,*X = map(int, open(0).read().split())
ans = float('inf')
for i in range(1,max(X)+1):
temp = 0
for j in range(N):
temp += (X[j]-i) ** 2
ans = min(ans,temp)
print(ans)
| 0 | null | 32,956,558,469,150 | 55 | 213 |
N = int(input())
if N%2==1:
print(0)
else:
ans = 0
judge = 10
while True:
if judge > N:
break
else:
ans += N//judge
judge *= 5
print(ans)
|
import sys
read = sys.stdin.read
def main():
n = int(input())
if n <= 9 or n % 2 == 1:
print(0)
sys.exit()
n5 = 5
r = 0
while n >= n5 * 2:
r += n // (n5 * 2)
n5 *= 5
print(r)
if __name__ == '__main__':
main()
| 1 | 115,773,069,055,764 | null | 258 | 258 |
N = int(input())
A = list(map(int, input().split()))
kane=1000
kabu=0
for i in range(N-1):
#print(kane,kabu)
if A[i]<A[i+1]:
kane=kabu*A[i]+kane
kabu=kane//A[i]
kane=kane-kabu*A[i]
else:
kane=kabu*A[i]+kane
kabu=0
print(kane+kabu*A[N-1])
|
n = int(raw_input())
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if M[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
BFS(e)
for i in range(n):
G = map(int, raw_input().split())
for j in range(G[1]):
M[G[0]-1][G[2+j]-1] = 1
d[0] = 0
for s in range(n):
BFS(s)
for s in range(n):
if d[s] == 99999:
d[s] = -1
for s in range(n):
print'{0} {1}'.format(s+1, d[s])
| 0 | null | 3,673,216,046,152 | 103 | 9 |
import math
def main():
v = list(map(int, input().split()))
n = v[0]
a = v[1]
b = v[2]
answer = 0
if n < a:
answer = n
elif n < a+b:
answer = a
elif a == 0 and b == 0:
answer = 0
else:
answer += math.floor(n / (a+b)) * a
rest = n % (a+b)
if rest <= a:
answer += rest
else:
answer += a
print(answer)
if __name__ == "__main__":
main()
|
NN =input().split()
N =int(NN[0])
A = int(NN[1])
B = int(NN[2])
X =A+B
Y =N//X
Z = N%X
if Z >=A:
ans = A
else:
ans = Z
ans1 = Y*A + ans
print(ans1)
| 1 | 55,970,199,768,338 | null | 202 | 202 |
W = input().lower()
ans = 0
while True:
s = input()
if s == "END_OF_TEXT":
break
s = s.lower().split()
ans += s.count(W)
print(ans)
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import floor
from decimal import Decimal
def main():
x = int(input())
n = Decimal(100)
r = 0
while n < x:
n = Decimal(floor((n * 101 / 100)))
r += 1
print(r)
if __name__ == '__main__':
main()
| 0 | null | 14,473,500,005,360 | 65 | 159 |
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
if (a1*t1-b1*t1)*(a1*t1+a2*t2-b1*t1-b2*t2)>0:print(0)
elif (a1*t1-b1*t1)*(a1*t1+a2*t2-b1*t1-b2*t2)==0:print('infinity')
else:print(-(a1*t1-b1*t1)//(a1*t1+a2*t2-b1*t1-b2*t2)*2+((a1*t1-b1*t1)%(a1*t1+a2*t2-b1*t1-b2*t2)!=0))
|
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
#
def main():
T1,T2 = mis()
A1,A2 = mis()
B1,B2 = mis()
d1 = T1*A1 - T1*B1
d2 = T2*A2 - T2*B2
if d1 + d2 == 0:
print('infinity')
elif d1 < 0 > d2 or d1 > 0 < d2:
print(0)
else:
if d1 < 0:
d1 *= -1
d2 *= -1
if d1 + d2 > 0:
print(0)
elif d1 % (d1+d2) == 0:
print(d1 // abs(d1+d2) * 2)
else:
print(d1 // abs(d1+d2) * 2 + 1)
main()
| 1 | 131,443,313,268,142 | null | 269 | 269 |
N = int(input())
ans = (N - (N//2)) / N
print(ans)
|
N=int(input())
print(((N+1)//2)/N)
| 1 | 177,469,033,525,628 | null | 297 | 297 |
import math
a, b, x = map(int, input().split())
ans = 0
if a*a*b/2 < x:
t = 2*x/(a*a) - b
ans = math.degrees(math.atan((b-t)/a))
else:
t = 2*x/(a*b)
ans = math.degrees(math.atan(b/t))
print(ans)
|
import math
a, b, x = map(int, input().split())
if a*a*b / 2 > x:
h = x / b * 2 / a
deg = math.atan(h/b)
deg = math.degrees(deg)
deg = 90 - deg
else:
x = a*a*b - x
h = x / a * 2 / a
deg = math.atan(h/a)
deg = math.degrees(deg)
print(deg)
| 1 | 163,493,059,125,200 | null | 289 | 289 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.union(a, b)
ans = 0
for r in uf.roots():
ans = max(ans, uf.size(r))
print(ans)
|
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []
for i in range(1,n):
b.append(a[i] - a[i-1])
b.append(k - a[n-1] + a[0])
b = sorted(b)
print(sum(b[:-1]))
| 0 | null | 23,863,597,599,492 | 84 | 186 |
import itertools
from collections import deque
from sys import stdin
input = stdin.readline
def main():
H, W = list(map(int, input().split()))
M = [input()[:-1] for _ in range(H)]
def bfs(start):
dist = [[float('inf')]*W for _ in range(H)]
dist[start[0]][start[1]] = 0
is_visited = [[0]*W for _ in range(H)]
is_visited[start[0]][start[1]] = 1
q = deque([start])
max_ = 0
while len(q):
now_h, now_w = q.popleft()
if M[now_h][now_w] == '#':
return
for next_h, next_w in ((now_h+1, now_w),
(now_h-1, now_w),
(now_h, now_w-1),
(now_h, now_w+1)):
if not(0 <= next_h < H) or not(0 <= next_w < W) or \
(is_visited[next_h][next_w] == 1) or \
M[next_h][next_w] == '#':
# (dist[next_h][next_w] != float('inf')) or \
continue
dist[next_h][next_w] = dist[now_h][now_w] + 1
is_visited[next_h][next_w] = 1
max_ = max(max_, dist[next_h][next_w])
q.append((next_h, next_w))
return max_
max_ = 0
for h in range(H):
for w in range(W):
if M[h][w] == '.':
max_ = max(bfs((h, w)), max_)
print(max_)
if(__name__ == '__main__'):
main()
|
N, M = list(map(int, input().split()))
import math
ans = []
if M == 1:
ans.append((1, 2))
else:
m0 = (1, M+1)
m1 = (M+2, 2*M+1)
for _ in range(math.ceil(M/2)):
if m0[0] < m0[1]:
ans.append(m0)
if m1[0] < m1[1]:
ans.append(m1)
m0 = (m0[0]+1, m0[1]-1)
m1 = (m1[0]+1, m1[1]-1)
for a in ans:
print(a[0], a[1])
| 0 | null | 61,264,698,602,340 | 241 | 162 |
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
a, b = 0, 0
A, B = set(), set()
for i in range(N):
n = N - i - 1
m = P[i] - i - 1
for ai in A:
if ai < P[i]:
m -= 1
a += m * math.factorial(n)
A.add(P[i])
for i in range(N):
n = N - i - 1
m = Q[i] - i - 1
for bi in B:
if bi < Q[i]:
m -= 1
b += m * math.factorial(n)
B.add(Q[i])
print(abs(a - b))
|
def generate_arr(a):
if len(a) == N:
arr.append(a)
return
for i in range(1,N+1):
if i not in a:
generate_arr(a+[i])
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
arr = []
generate_arr([])
arr.sort()
ans_p = 0
ans_q = 0
for i in range(len(arr)):
if arr[i] == P:
ans_p = i+1
if arr[i] == Q:
ans_q = i+1
print(abs(ans_p-ans_q))
| 1 | 100,217,462,317,278 | null | 246 | 246 |
class UnionFind:
def __init__(self, sz: int):
self._par: list[int] = [-1] * sz
def root(self, a: int):
if self._par[a] < 0:
return a
self._par[a] = self.root(self._par[a])
return self._par[a]
def size(self, a: int):
return -self._par[self.root(a)]
def unite(self, a, b):
a = self.root(a)
b = self.root(b)
if a != b:
if self.size(a) < self.size(b):
a, b = b, a
self._par[a] += self._par[b]
self._par[b] = a
if __name__ == '__main__':
N, M = map(int, input().split())
uf = UnionFind(N + 1)
for i in range(M):
a, b = map(int, input().split())
uf.unite(a, b)
ans = 1
for i in range(1, N + 1):
ans = max(ans, uf.size(i))
print(ans)
|
num = int(input())
val = num + num **2 + num **3
print(val)
| 0 | null | 7,061,302,655,620 | 84 | 115 |
(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
A.append([int(j) for j in input().split()])
for r in range(m):
b.append(int(input()))
for i in range(n):
s = 0
for j in range(m):
s += A[i][j] * b[j]
print(s)
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
S, W = map(int, input().split())
if W >= S:
print('unsafe')
else:
print('safe')
if __name__ == '__main__':
main()
| 0 | null | 15,290,655,598,438 | 56 | 163 |
W = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
S = input()
print(len(W) - W.index(S))
|
s = input()
S = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7-S.index(s))
| 1 | 132,870,243,702,754 | null | 270 | 270 |
s,w=map(int,input().split())
print("un"*(w>=s)+"safe")
|
a, b, c = map(int, input().split())
k = int(input())
count = 0
while True:
if b > a:
break
b *= 2
count += 1
while True:
if c > b:
break
c *= 2
count += 1
if count <= k:
print('Yes')
else:
print('No')
| 0 | null | 18,097,381,693,090 | 163 | 101 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = map(int, read().split())
C = [0] * N
for a in A:
C[a-1] += 1
print(*C, sep='\n')
return
if __name__ == '__main__':
main()
|
import numpy as np
N=int(input())
A=input().split()
n=np.zeros(N)
for i in range(N-1):
n[int(A[i])-1]+=1
for l in n :
print(int(l))
| 1 | 32,513,793,781,460 | null | 169 | 169 |
import math
n,m=map(int,input().split())
print(n*(n-1)//2+m*(m-1)//2)
|
n = int(input())
a = [int(i) for i in input().split()]
num = 0
is_swapped = True
i = 0
while is_swapped:
is_swapped = False
for j in range(n-1, i, -1):
if a[j] < a[j-1]:
tmp = a[j]
a[j] = a[j-1]
a[j-1] = tmp
is_swapped = True
num += 1
i += 1
print(' '.join([str(i) for i in a]))
print(num)
| 0 | null | 22,915,446,470,062 | 189 | 14 |
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
a,b,c,d,k=mp()
print(c*60+d-a*60-b-k)
|
import math
a,b,x = map(int,input().split())
if x <= b*a*a*1/2:
dum = 2*x/(a*b)
ans = 90-(math.degrees(math.atan(dum/b)))
else:
x -= b*a*a*1/2
dum = b-(x*2/(a*a))
ans = math.degrees(math.atan(dum / a))
print(ans)
| 0 | null | 90,814,826,368,980 | 139 | 289 |
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
def count(x):
ret = 0
for a in A:
ret += N - bisect_left(A, x - a)
return ret
overEq = 0
less = 10**7
while less - overEq > 1:
mid = (less + overEq) // 2
if count(mid) >= M:
overEq = mid
else:
less = mid
ans = 0
cnt = [0] * N
for a in A:
i = (N - bisect_left(A, overEq - a))
ans += i * a
if i > 0:
cnt[-i] += 1
for i in range(1, N):
cnt[i] += cnt[i - 1]
for a, c in zip(A, cnt):
ans += a * c
ans -= overEq * (count(overEq) - M)
print(ans)
|
n=int(input())
if n%2==1:
print(0)
exit(0)
n//=2
from math import floor,factorial
ans=0
deno=5
while deno<=n:
ans+=n//deno
deno*=5
print(ans)
| 0 | null | 112,345,054,313,092 | 252 | 258 |
a,b=input().split()
a=int(a)
b=int(b)
e=a
d=b
c=1
if a>b:
for i in range(1,e):
if a%(e-i)==0 and b%(e-i)==0:
a=a/(e-i)
b=b/(e-i)
c=c*(e-i)
print(int(a*b*c))
if a<b:
for i in range(1,d):
if a%(d-i)==0 and b%(d-i)==0:
a=a/(d-i)
b=b/(d-i)
c=c*(d-i)
print(int(a*b*c))
|
import math
a, b = map(int, input().split())
if a%b == 0:
ans = a
elif b%a == 0:
ans = b
else:
ans = int(a*b / math.gcd(a, b))
print(ans)
| 1 | 113,224,305,432,410 | null | 256 | 256 |
import sys
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
h1,m1,h2,m2,k = Mi()
ans = h2*60+m2-h1*60-m1-k
print(ans)
|
h1, m1, h2, m2, k = map(int, input().split())
d = (h2 - h1) * 60 + (m2 - m1)
print(max(d - k, 0))
| 1 | 18,169,784,953,408 | null | 139 | 139 |
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
x,k,d = mi()
x = abs(x)
count = min(k,x//d)
k -= count
x -= d*count
if k % 2 == 0:
print(x)
else:
print(d-x)
|
n = int(input())
s = input()
ans = n
if n == 1:
print("1")
else:
for i in range(n-1):
if s[i] == s[i+1]:
ans -= 1
print(ans)
| 0 | null | 87,868,638,686,104 | 92 | 293 |
a=input()
if a in "abcdefgeijklmnopqrstuvwxyz":
print('a')
else:
print('A')
|
if input().islower() == True:
print("a")
else:
print("A")
| 1 | 11,425,564,043,140 | null | 119 | 119 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
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()))
def f(x):
cnt = 0
while x%2 == 0:
cnt += 1
x //= 2
return cnt
def lcm(x,y):
return x*y//math.gcd(x,y)
n,m = inpl()
a = inpl()
a = list(set(a))
c = list(set([f(x) for x in a]))
if len(c) != 1:
print(0)
quit()
c = c[0]
x = 1
for i in range(len(a)):
x = lcm(a[i]//2, x)
# print(x)
print((m+x)//(2*x))
|
INF = 10**9
def solve(h, w, s):
dp = [[INF] * w for r in range(h)]
dp[0][0] = int(s[0][0] == "#")
for r in range(h):
for c in range(w):
for dr, dc in [(-1, 0), (0, -1)]:
nr, nc = r+dr, c+dc
if (0 <= nr < h) and (0 <= nc < w):
dp[r][c] = min(dp[r][c], dp[nr][nc] + (s[r][c] != s[nr][nc]))
return (dp[h-1][w-1] + 1) // 2
h, w = map(int, input().split())
s = [input() for r in range(h)]
print(solve(h, w, s))
| 0 | null | 75,298,488,356,520 | 247 | 194 |
#!/usr/bin/env python3
import sys
import decimal
def input():
return sys.stdin.readline()[:-1]
def main():
A, B = map(int, input().split())
for i in range(1, 10 ** 4):
a = int(decimal.Decimal(i * 0.08))
b = int(decimal.Decimal(i * 0.1))
if a == A and b == B:
print(i)
exit()
print(-1)
if __name__ == '__main__':
main()
|
import math
a, b, h, m = map(int, input().split())
dega = - 30*h - 0.5*m + 90
degb = - 6*m + 90
x_a = a*math.cos(math.radians(dega))
y_a = a*math.sin(math.radians(dega))
x_b = b*math.cos(math.radians(degb))
y_b = b*math.sin(math.radians(degb))
# print(dega, degb)
# print(x_a, x_b, y_a, y_b)
print(((x_a-x_b)**2+(y_a-y_b)**2)**0.5)
| 0 | null | 38,506,269,548,208 | 203 | 144 |
from collections import deque
from sys import stdin
input = stdin.readline
def main():
N = int(input())
G = [[] for _ in range(N)]
dic = {}
for i in range(N-1):
a, b = map(lambda x: int(x)-1, input().split())
G[a].append(b)
G[b].append(a)
dic[(a, b)] = i
dic[(b, a)] = i
color = [0]*(N-1)
upcol = [0]*(N)
upcol[0] = None
visited = set()
q = deque([0])
max_col = 0
while len(q):
now = q.popleft()
visited.add(now)
c = 0
for next_ in G[now]:
if next_ in visited:
continue
c += 1
if upcol[now] == c:
c += 1
color[dic[(now, next_)]] = c
upcol[next_] = c
q.append(next_)
max_col = max(max_col, c)
print(max_col)
print(*color, sep='\n')
if(__name__ == '__main__'):
main()
|
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
class Math():
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n ** 0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
@staticmethod
def fact(N):
res = {}
tmp = N
for i in range(2, int(N ** 0.5 + 1) + 1):
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if cnt > 0:
res[i] = cnt
if tmp != 1:
res[tmp] = 1
if res == {}:
res[N] = 1
return res
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
MOD = int(1e09) + 7
INF = int(1e15)
class Edge:
def __init__(self, to_, id_):
self.to = to_
self.id = id_
ans = None
G = None
K = None
def dfs(to, c):
global G
global ans
nc = c % K + 1
for g in G[to]:
if ans[g.id] != -1:
continue
ans[g.id] = nc
dfs(g.to, nc)
nc = nc % K + 1
def solve():
global G
global ans
global K
N = Scanner.int()
G = [[] for _ in range(N)]
for i in range(N - 1):
x, y = Scanner.map_int()
x -= 1
y -= 1
G[x].append(Edge(y, i))
G[y].append(Edge(x, i))
K = 0
for i in range(N):
K = max(K, len(G[i]))
ans = [-1 for _ in range(N - 1)]
dfs(0, 0)
print(K)
print(*ans, sep='\n')
def main():
sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
| 1 | 135,984,675,293,190 | null | 272 | 272 |
class Modulo_Error(Exception):
pass
class Modulo():
def __init__(self,a,n):
self.a=a%n
self.n=n
def __str__(self):
return "{} (mod {})".format(self.a,self.n)
#+,-
def __pos__(self):
return self
def __neg__(self):
return Modulo(-self.a,self.n)
#等号,不等号
def __eq__(self,other):
if isinstance(other,Modulo):
return (self.a==other.a) and (self.n==other.n)
elif isinstance(other,int):
return (self-other).a==0
def __neq__(self,other):
return not(self==other)
#加法
def __add__(self,other):
if isinstance(other,Modulo):
if self.n!=other.n:
raise Modulo_Error("異なる法同士の演算です.")
return Modulo(self.a+other.a,self.n)
elif isinstance(other,int):
return Modulo(self.a+other,self.n)
def __radd__(self,other):
if isinstance(other,int):
return Modulo(self.a+other,self.n)
#減法
def __sub__(self,other):
return self+(-other)
def __rsub__(self,other):
if isinstance(other,int):
return -self+other
#乗法
def __mul__(self,other):
if isinstance(other,Modulo):
if self.n!=other.n:
raise Modulo_Error("異なる法同士の演算です.")
return Modulo(self.a*other.a,self.n)
elif isinstance(other,int):
return Modulo(self.a*other,self.n)
def __rmul__(self,other):
if isinstance(other,int):
return Modulo(self.a*other,self.n)
#Modulo逆数
def Modulo_Inverse(self):
x0, y0, x1, y1 = 1, 0, 0, 1
a,b=self.a,self.n
while b != 0:
q, a, b = a // b, b, a % b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
if a!=1:
raise Modulo_Error("{}の逆数が存在しません".format(self))
else:
return Modulo(x0,self.n)
#除法
def __truediv__(self,other):
return self*other.Modulo_Inverse()
#累乗
def __pow__(self,m):
u=abs(m)
r=Modulo(1,self.n)
while u>0:
if u%2==1:
r*=self
self*=self
u=u>>1
if m>=0:
return r
else:
return r.Modulo_Inverse()
#-------------------------------------------------------------------------
M=10**9+7
n,a,b=map(int,input().split())
C=[Modulo(1,M)]*(b+1)
for k in range(1,b+1):
C[k]=C[k-1]*Modulo(n-(k-1),M)/Modulo(k,M)
print((Modulo(2,M)**n-(C[a]+C[b])-1).a)
|
s = input()
n = len(s)
t = [0]*(n+1)
tmp=0
for i in range(n):
tmp+=1
if s[i]=="<":
t[i]=tmp-1
t[i+1]=tmp
else:
tmp=0
tmp=0
for j in range(n)[::-1]:
tmp+=1
if s[j]==">":
t[j+1]=max(tmp-1,t[j+1])
t[j]=max(tmp,t[j])
else:
tmp=0
#print(t)
print(sum(t))
| 0 | null | 110,908,361,586,450 | 214 | 285 |
def gcm(a, b):
if a<b: a,b = b,a
if (a%b ==0):
return b
else:
return gcm(b, a%b)
def lcm(a, b):
return a/gcm(a,b)*b
while True:
try:
a, b = map(int, raw_input().split())
except:
break
print "%d %d" %(gcm(a,b), lcm(a,b))
|
import sys
for i in sys.stdin:
a, b = map(int, i.split())
p, q = max(a, b), min(a, b)
while True:
if p % q == 0:
break
else:
p, q = q, p % q
print("{} {}".format(q, int(a * b / q)))
| 1 | 676,514,390 | null | 5 | 5 |
#!/usr/bin/env python
n, k = map(int, input().split())
mod = 10**9+7
d = [-1 for _ in range(k+1)]
d[k] = 1
for i in range(k-1, 0, -1):
d[i] = pow(k//i, n, mod)
j = 2*i
while j <= k:
d[i] -= d[j]
j += i
#print('d =', d)
ans = 0
for i in range(1, k+1):
ans += (i*d[i])%mod
print(ans%mod)
|
while True:
input = raw_input()
if input == '0': break
print sum(map(int, input))
| 0 | null | 19,291,485,328,338 | 176 | 62 |
from enum import IntEnum
class Direction(IntEnum):
NORTH = 0
EAST = 1
SOUTH = 2
WEST = 3
class Dice:
"""Dice class implements the structure of a dice
having six faces.
"""
def __init__(self, v1, v2, v3, v4, v5, v6):
self.top = 1
self.heading = Direction.NORTH
self.values = [v1, v2, v3, v4, v5, v6]
def to_dice_axis(self, d):
return (d - self.heading) % 4
def to_plain_axis(self, d):
return (self.heading + d) % 4
def roll(self, d):
faces = [[(2, Direction.NORTH), (6, Direction.NORTH),
(6, Direction.WEST), (6, Direction.EAST),
(6, Direction.SOUTH), (5, Direction.SOUTH)],
[(4, Direction.EAST), (4, Direction.NORTH),
(2, Direction.NORTH), (5, Direction.NORTH),
(3, Direction.NORTH), (4, Direction.WEST)],
[(5, Direction.SOUTH), (1, Direction.NORTH),
(1, Direction.EAST), (1, Direction.WEST),
(1, Direction.SOUTH), (2, Direction.NORTH)],
[(3, Direction.WEST), (3, Direction.NORTH),
(5, Direction.NORTH), (2, Direction.NORTH),
(4, Direction.NORTH), (3, Direction.EAST)]]
f, nd = faces[self.to_dice_axis(d)][self.top-1]
self.top = f
self.heading = self.to_plain_axis(nd)
def value(self):
return self.values[self.top-1]
def run():
values = [int(v) for v in input().split()]
dice = Dice(*values)
for d in input():
if d == 'N':
dice.roll(Direction.NORTH)
if d == 'E':
dice.roll(Direction.EAST)
if d == 'S':
dice.roll(Direction.SOUTH)
if d == 'W':
dice.roll(Direction.WEST)
print(dice.value())
if __name__ == '__main__':
run()
|
S = int(input())
print("%d:%d:%d"%(S/3600,(S%3600)/60,S%60))
| 0 | null | 271,237,253,120 | 33 | 37 |
import sys
def input(): return sys.stdin.readline().rstrip()
A, B, N = map(int, input().split())
if B <= N:
N = B - 1
print((A*N)//B - A*(N//B))
|
#!/usr/bin/env python3
def main():
import sys
input = sys.stdin.readline
A, B, N = map(int, input().split())
x = min(B - 1, N)
print((A * x) // B - A * (x // B))
if __name__ == '__main__':
main()
| 1 | 28,101,834,082,002 | null | 161 | 161 |
n=int(input())
a=list(map(int,input().split()))
ans=10**20
p=sum(a)
q=0
for i in range(n-1):
q+=a[i]
ans=min(ans,abs(p-q-q))
print(ans)
|
import math
a,b,C = map(float,input().split())
C = math.pi* C / 180
area = (a * b * math.sin(C) / 2)
print(area)
print(a + b + math.sqrt(a**2 + b**2 - 2 * a * b* math.cos(C)))
print(area * 2 / a)
| 0 | null | 70,933,420,419,980 | 276 | 30 |
def modinv(a,m):
b, u, v = m, 1, 0
while b:
t = a//b
a -= t*b
a,b = b,a
u -= t * v
u,v = v,u
u %= m
return u
n,a,b = map(int, input().split())
MOD = 10**9+7
ncnt = pow(2,n,MOD)-1
acnt = 1
for i in range(a):
acnt *= (n-i)
acnt *= modinv(i+1,MOD)
acnt %= MOD
bcnt = 1
for i in range(b):
bcnt *= (n-i)
bcnt *= modinv(i+1,MOD)
bcnt %= MOD
ans = ncnt - acnt - bcnt
print(ans%MOD)
|
n = input().split()
x = int(n[0])
y = int(n[1])
if x < y:
bf = x
x = y
y = bf
while y > 0:
r = x % y
x = y
y = r
print(str(x))
| 0 | null | 33,235,214,936,770 | 214 | 11 |
# Queue
class MyQueue:
def __init__(self):
self.queue = [] # list
self.top = 0
def isEmpty(self):
if self.top==0:
return True
return False
def isFull(self):
pass
def enqueue(self, x):
self.queue.append(x)
self.top += 1
def dequeue(self):
if self.top>0:
self.top -= 1
return self.queue.pop(0)
else:
print("there aren't enough values in Queue")
def main():
n, q = map(int, input().split())
A = [
list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
for i in range(n)
]
A = [{'name': name, 'time': time} for name, time in A]
queue = MyQueue()
for a in A:
queue.enqueue(a)
elapsed = 0
while not queue.isEmpty():
job = queue.dequeue()
if job['time']>q:
elapsed += q
job['time'] = job['time'] - q
queue.enqueue(job)
else:
elapsed += job['time']
print(job['name']+ ' ' + str(elapsed))
main()
|
n, q = map(int, input().split())
tasks = []
for _ in range(n):
ni, ti = input().split()
tasks.append((ni, int(ti)))
t = 0
while len(tasks) > 0:
ni, ti = tasks.pop(0)
if ti <= q:
t += ti
print(f'{ni} {t}')
else:
tasks.append((ni, ti - q))
t += q
| 1 | 41,824,283,140 | null | 19 | 19 |
#!/usr/bin/env python3
n = int(input())
ans = [0] * (n + 1)
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
w = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
if w <= n:
ans[w] += 1
for i in range(1, n + 1):
print(ans[i])
|
def solve():
N = int(input())
A = [0] * (N + 1)
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
s = x * x + y * y + z * z + x * y + x * z + y * z
if s <= N:
A[s] += 1
for i in range(1, N + 1):
print(A[i])
solve()
| 1 | 7,984,908,978,240 | null | 106 | 106 |
words = input()
if words[-1] != "s":
words += "s"
else:
words += "es"
print(words)
|
st = input()
if st[-1] == "s":
st += "es"
else:
st += "s"
print(st)
| 1 | 2,378,106,880,192 | null | 71 | 71 |
c = 0
while True:
x = int(input())
if x == 0:
break;
c += 1
print('Case', str(c) + ':', x)
|
i = 0
while True:
t = int(input())
if t == 0:
break
else:
i += 1
print('Case '+str(i)+': '+str(t))
| 1 | 498,321,650,460 | null | 42 | 42 |
#
import sys
input=sys.stdin.readline
def main():
A,B,C=map(int,input().split())
if (A==B or B==C or C==A) and not A==B==C:
print("Yes")
else:
print("No")
if __name__=="__main__":
main()
|
print("YNeos"[len(set(input().split())) != 2::2])
| 1 | 68,141,038,408,550 | null | 216 | 216 |
N, M = map(int, input().split())
def solve(N,M):
dp = [[float('inf')]*(N+1) for _ in range(M+1)]
C = list(map(int, input().split()))
dp[0][0] = 0
for i in range(1,M+1):
dp[i][0] = 0
for j in range(1,N+1):
dp[i][j] = dp[i-1][j]
if j>=C[i-1]:
dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
ans = dp[M][N]
return ans
print(solve(N,M))
|
n,m = map(int,input().split())
D = list(map(int,input().split()))
INF = 10**5
dp = [INF for i in range(n+1)]
dp[0] = 0
for i in range(n+1):
for d in D:
if i+d <= n:
dp[i+d] = min(dp[i+d],dp[i]+1)
print(dp[n])
| 1 | 142,419,956,778 | null | 28 | 28 |
n=int(input())
x=n
c=1
while(x%360):
x+=n
x%=360
c+=1
print(c)
|
n = int(input())
p = list(map(int,input().split()))
p2 = [0]*n
for x in p:
p2[x-1] = p2[x-1] + 1
for x in p2:
print(x)
| 0 | null | 22,748,370,088,520 | 125 | 169 |
u, s, e, w, n, d = input().split()
t = input()
for i in t:
if i == 'N':
u, s, n, d = s, d, u, n
elif i == 'E':
u, e, w, d = w, u, d, e
elif i == 'S':
u, s, n, d = n, u, d, s
elif i == 'W':
u, e, w, d = e, d, u, w
print(u)
|
a1, a2, a3 = (map(int, input().split()))
if sum([a1, a2, a3]) >= 22:
print('bust')
else:
print('win')
| 0 | null | 59,496,131,937,920 | 33 | 260 |
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
#import queue
from copy import copy, deepcopy
from operator import itemgetter
import bisect#2分探索
#bisect_left(l,x), bisect(l,x)
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#q=heapq.heapify(l),heappush(q,a),heappop(q)
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])
#mod = 10**9+7
#N = int(input())
N, P = map(int, input().split())
S=input()
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get()
#q = queue.LifoQueue() #q.put(i) #q.get()
#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a) #2次元配列はこうコピーする
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
# primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)
#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入
if P!=2 and P!=5:
pc=[0]*P
pc[0]=1
count=0
ans=0
p10=1
for i in range(1,N+1):
count+=int(S[N-i])*p10
count%=P
ans+=pc[count]
pc[count]+=1
p10*=10
p10%=P
print(ans)
else:
ans=0
for i in range(1,N+1):
if int(S[N-i])%P==0:
ans+=N-i+1
print(ans)
|
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n,p = mi()
s = input()
srev = s[::-1]
if p == 2 or p == 5:
ans = 0
for i in range(n):
if int(s[i]) % p == 0:
ans += i +1
print(ans)
exit()
acum = []
from collections import defaultdict
d = defaultdict(lambda :0)
d = [0] * p
num = 0
tenpow = 1
for i in range(0,n):
a = int(srev[i])
a = num + a *tenpow
tenpow = tenpow * 10 % p
modd = a % p
num = modd
d[modd] += 1
acum.append((modd,d[modd]))
ans = d[0]
for i in range(n):
ans += d[acum[i][0]] - acum[i][1]
print(ans)
| 1 | 58,022,060,687,452 | null | 205 | 205 |
def showrooms(building,floor,rooms):
for x in xrange(0,floor):
for y in xrange(0,rooms):
if y==0:
print "",
print building[x][y],
elif y ==rooms-1:
print building[x][y]
else:
print building[x][y],
FLOOR = 3
ROOMS = 10
n = input()
building1 = [[0 for i in range(ROOMS)] for j in range(FLOOR)]
building2 = [[0 for i in range(ROOMS)] for j in range(FLOOR)]
building3 = [[0 for i in range(ROOMS)] for j in range(FLOOR)]
building4 = [[0 for i in range(ROOMS)] for j in range(FLOOR)]
# for x in xrange(0,n):
for x in xrange(0,n):
b,f,r,v = map(int,raw_input().split())
f=f-1
r=r-1
if b==1:
building1[f][r] += v
elif b==2:
building2[f][r] += v
elif b==3:
building3[f][r] += v
elif b==4:
building4[f][r] += v
else:
print "your input is invalid format."
break
showrooms(building1,FLOOR,ROOMS)
print "####################"
showrooms(building2,FLOOR,ROOMS)
print "####################"
showrooms(building3,FLOOR,ROOMS)
print "####################"
showrooms(building4,FLOOR,ROOMS)
|
room = [0 for i in range(120)]
c = int(input())
for i in range(c):
b, f, r, v = [int(s) for s in input().split()]
index = (30 * (b - 1)) + (10 * (f - 1)) + (r - 1)
room[index] += v
for i in range(12):
if (i != 0) and (i % 3 == 0):
print('#' * 20)
print(' ' + ' '.join([str(v) for v in room[i*10:i*10+10]]))
| 1 | 1,081,517,459,918 | null | 55 | 55 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
s=input()
if len(s)%2==1:
print("No")
sys.exit()
for i in range(len(s)//2):
if s[2*i:2*i+2]!="hi":
print("No")
break
else:print("Yes")
if __name__=='__main__':
main()
|
s = input()
x = ["hi", "hihi", "hihihi", "hihihihi", "hihihihihi"]
if s in x:
print("Yes")
else:
print("No")
| 1 | 53,196,754,078,382 | null | 199 | 199 |
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
mini = i
for j in range(i, N):
if A[j] < A[mini]:
mini = j
if i != mini:
A[i], A[mini] = A[mini], A[i]
count += 1
print(*A)
print(count)
|
import sys
from functools import reduce
def gcd(a, b): return gcd(b, a % b) if b else abs(a)
def lcm(a, b): return abs(a // gcd(a, b) * b)
n, m, *a = map(int, sys.stdin.read().split())
def main():
for i in range(n):
a[i] //= 2
b = set()
for x in a:
cnt = 0
while x % 2 == 0:
x //= 2
cnt += 1
b.add(cnt)
if len(b) == 2: print(0); return
l = reduce(lcm, a, 1)
res = (m // l + 1) // 2
print(res)
if __name__ == '__main__':
main()
| 0 | null | 50,816,007,801,220 | 15 | 247 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
fac = [1, 1]
f_inv = [1, 1]
inv = [0, 1]
def prepare(n, mod):
for i in range(2, n+1):
fac.append((fac[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod//i)) % mod)
f_inv.append((f_inv[-1] * inv[-1]) % mod)
def modcmb(n, r, mod):
if n < 0 or r < 0 or r > n:
return 0
return fac[n] * f_inv[r] * f_inv[n-r] % mod
def main():
N,K = map(int, readline().split())
prepare(N, MOD)
ans = 0
for i in range(min(N-1, K)+1):
ans += modcmb(N, i, MOD) * modcmb(N-1, i, MOD)
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
|
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
if n < r:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
def main():
n, k = map(int,input().split())
MOD = 10 ** 9 + 7
comb = Combination(10 ** 6)
ans = 0
if n - 1 <= k:
ans = comb(n + n - 1, n)
else:
ans = 1
for i in range(1,k+1):
ans += comb(n,i) * comb(n - 1, i)
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| 1 | 66,943,802,075,190 | null | 215 | 215 |
n = int(input())
ll = list(map(int, input().split()))
def bubble_sort(a, n):
flag = True
count = 0
while flag:
flag = False
for i in range(n-2, -1, -1):
if a[i] > a[i+1]:
a[i], a[i+1] = a[i+1], a[i]
flag = True
count += 1
print(" ".join(map(str, a)))
print(count)
bubble_sort(ll, n)
|
input()
l = [int(i) for i in input().split()]
input()
c = 0
for i in input().split():
for j in l:
if int(i) == j:
c += 1
break
print(c)
| 0 | null | 42,002,570,490 | 14 | 22 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ar=[0]*(n+1)
br=[0]*(m+1)
ans=0
for i in range(n):
ar[i+1]=ar[i]+a[i]
for i in range(m):
br[i+1]=br[i]+b[i]
for i in range(m+1):
sup=k-br[i]
if sup<0:
break
res=bisect.bisect_right(ar,sup)+i-1
ans=max(res,ans)
print(ans)
|
# coding: utf-8
# Your code here!
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=a[k-1]
for i in range(n-k):
if a[i]<a[i+k]:
print('Yes')
else:
print('No')
| 0 | null | 8,825,124,932,430 | 117 | 102 |
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
X = Counter([i - a for i, a in enumerate(A)])
ans = 0
for i, a in enumerate(A):
X[i - a] -= 1
ans += X[i + a]
print(ans)
|
def e_yutori():
# 参考: https://drken1215.hatenablog.com/entry/2020/04/05/163400
N, K, C = [int(i) for i in input().split()]
S = input()
def sub_solver(string):
"""string が表す労働日時に対して、労働数が最大になるように働いたとき、
i 日目には何回働いているかのリストを返す"""
n = len(string)
current, last = 0, -C - 1 # 最初に 'o' があっても動作するように設定
ret = [0] * (n + 1)
for i in range(n):
if i - last > C and string[i] == 'o':
current += 1
last = i
ret[i + 1] = current
return ret
left = sub_solver(S)
right = sub_solver(S[::-1])
ans = []
for i in range(N):
if S[i] == 'x':
continue
if left[i] + right[N - i - 1] < K:
ans.append(i + 1)
return '\n'.join(map(str, ans))
print(e_yutori())
| 0 | null | 33,531,772,880,088 | 157 | 182 |
a,b=map(int,input().split())
s1=str(a)*b
s2=str(b)*a
print(s1 if s2>s1 else s2)
|
import sys
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]
def main():
a, b = MI()
L = sorted([a, b])
if L[0] == a:
ans = int(str(a)*b)
else:
ans = int(str(b)*a)
print(ans)
if __name__ == "__main__":
main()
| 1 | 84,597,902,746,280 | null | 232 | 232 |
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 = [99999999999]*(H+1)
dp[0]=0
for h in range(H):
for i in range(N):
dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])
|
[H, N] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
a = sum(A)
if H > a:
print('No')
else:
print('Yes')
| 0 | null | 79,636,419,494,900 | 229 | 226 |
x = int(input())
if -40 <= x and x <= 40:
if x >= 30:
print("Yes")
else:
print("No")
|
# -*- coding: utf-8 -*-
x = int(input())
if x >= 30:
print('Yes')
else:
print('No')
| 1 | 5,778,288,442,080 | null | 95 | 95 |
alp_list = list('abcdefghijklmnopqrstuvwxyz')
C = str(input())
z = alp_list.index(C)
z += 1
print(alp_list[z])
|
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
R=[]
for i in range(N):
a=max(0,XL[i][0]-XL[i][1])
b=XL[i][1]+XL[i][0]
R.append([b,a])
R.sort()
ans=0
con_l=0
for i in range(N):
if con_l <= R[i][1]:
ans += 1
con_l = R[i][0]
print(ans)
| 0 | null | 90,871,960,910,990 | 239 | 237 |
print(int(input())*3.1415*2)
|
import sys
from collections import deque
input = sys.stdin.readline
class Node:
def __init__(self, num):
self.link = []
self.costs = [num, num]
self.check = False
def clear_nodes(nodes):
for node in nodes:
node.check = False
def main():
N, u, v = map(int, input().split())
nodes = [Node(N+1) for i in range(N+1)]
for i in range(N-1):
a, b = map(int, input().split())
nodes[a].link.append(nodes[b])
nodes[b].link.append(nodes[a])
starts = [u, v]
for i in range(2):
clear_nodes(nodes)
q = deque()
q.append((nodes[starts[i]], 0))
while len(q) > 0:
node, cost = q.popleft()
node.costs[i] = cost
for next_node in node.link:
if not next_node.check:
q.append((next_node, cost + 1))
next_node.check = True
if nodes[u].costs[1] == 1:
print(0)
return
clear_nodes(nodes)
q = deque()
ans = 0
q.append(nodes[u])
while len(q) > 0:
node = q.popleft()
ans = max(ans, node.costs[1])
for next_node in node.link:
if (not next_node.check) and next_node.costs[0] < next_node.costs[1]:
q.append(next_node)
next_node.check = True
print(ans - 1)
if __name__ == "__main__":
main()
| 0 | null | 74,444,371,168,840 | 167 | 259 |
from math import *
def trycut(val):
ret = 0
for i in range(n):
ret += ceil(a[i]/val)-1
return ret
n,k=map(int,input().split())
a = [int(i) for i in input().split()]
low = 0
high = 1000000000
ans =-1
while low <= high:
mid = (low + high)/2
cut = trycut(mid)
# ~ print("low=",low, "high=", high,"val = ",mid,"ret = ",cut)
if cut <= k:
high = mid-0.0000001
ans = mid
else:
low = mid+0.0000001
# ~ if low < high: print(low, high, "je reviens")
ans = int(ans*1000000)/1000000
# ~ print(ans)
print(int(ceil(ans)))
|
"""ABC174E diff: 1158
"""
N,K=map(int,input().split())
A=list(map(int, input().split()))
if K == 0:
print(max(A))
exit()
def f(x):
"""
K回以内のカットで全ての丸太の長さをX以下にできるか?
X: int
Return: bool
"""
cnt = 0
for a in A:
if a % x == 0:
cnt += a//x - 1
else:
cnt += a//x
if cnt <= K:
return True
else:
return False
left = 0
right = max(A) + 10
while right - left > 1:
mid = (left+right) // 2
if f(mid):
right = mid
else:
left = mid
print(right)
| 1 | 6,434,451,925,150 | null | 99 | 99 |
def multi():
for i in range(1, 10):
for j in range(1, 10):
print(str(i) + "x" + str(j) + "=" + str(i * j))
if __name__ == '__main__':
multi()
|
def solve():
for i in range(1,10):
for j in range(1,10):
print("{0}x{1}={2}".format(i,j,i*j))
solve()
| 1 | 1,661,088 | null | 1 | 1 |
N,M=map(int,input().split())
A_M=list(map(int,input().split()))
if N >= sum(A_M):
print(N-sum(A_M))
else:
print(-1)
|
n, m = map(int , input().split())
a = [int(num) for num in input().split()]
st = sum(a)
if (n >= st):
print(n-st)
else :
print(-1)
| 1 | 32,170,161,694,702 | null | 168 | 168 |
n, K = map(int, input().split())
a = list(map(int, input().split()))
s = [[0]*n for _ in range(100)]
s[0] = a
tmp = [0] * (n+1)
for i in range(K):
if sum(s[i]) == n**2:
print(*([n] * n))
break
for j in range(n):
x = s[i][j]
l, r = max(0, j-x), min(n, j+x+1)
tmp[l] += 1
tmp[r] -= 1
for j in range(n):
tmp[j+1] = tmp[j] + tmp[j+1]
s[i+1][j] += tmp[j]
tmp = [0] * (n+1)
else: print(*s[K])
|
import sys
N,K = map(int,input().split())
array_hight = list(map(int,input().split()))
if not ( 1 <= N <= 10**5 and 1 <= K <= 500 ): sys.exit()
count = 0
for I in array_hight:
if not ( 1 <= I <= 500): sys.exit()
if I >= K:
count += 1
print(count)
| 0 | null | 97,396,528,942,460 | 132 | 298 |
r,cr,c = map(int,input().split())
matrix_a = [list(map(int,input().split())) for i in range(r)]
matrix_b = [list(map(int,input().split())) for i in range(cr)]
matrix_c = [ [0 for a in range(c)] for b in range(r)]
for j in range(r):
for k in range(c):
for l in range(cr):
matrix_c[j][k] += matrix_a[j][l]*matrix_b[l][k]
for x in matrix_c:
print(" ".join(list(map(str,x))))
|
# ????????????
n,m,l = list(map(int,input().split()))
matrixA,matrixB = [],[]
for i in range(n):
matrixA.append(list(map(int,input().split())))
for j in range(m):
matrixB.append(list(map(int,input().split())))
matrix = []
for i in range(l):
mtr = []
for j in range(m):
mtr.append(matrixB[j][i])
matrix.append(mtr)
matrixC = []
for i in range(l):
mtr = []
for j in range(n):
num_sum = 0
# print(matrixA[j],matrix[i])
for a,b in zip(matrixA[j],matrix[i]):
num_sum += a*b
mtr.append(num_sum)
matrixC.append(mtr)
matrix = []
for i in range(n):
out = ''
for j in range(l):
out += str(matrixC[j][i]) + ' '
print(out[:-1])
| 1 | 1,412,078,851,238 | null | 60 | 60 |
A,B,C,D=map(int,input().split())
t=0
a=0
while A>0:
A-=D
t+=1
while C>0:
C-=B
a+=1
if t>=a:
print('Yes')
else:
print('No')
|
A,B,C,D=map(int,input().split())
x=(A-1)//D+1
y=(C-1)//B+1
if x<y:
print("No")
else:
print("Yes")
| 1 | 29,641,541,536,438 | null | 164 | 164 |
try:
D,T,S = [int(e) for e in input().split()]
except:
print('Error')
else:
tmp = T * S
if D > tmp:
print('No')
else:
print('Yes')
|
import re
s = input()
if s == "hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s== "hihihihihi":
print("Yes")
else:
print("No")
| 0 | null | 28,466,615,409,892 | 81 | 199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.