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
|
---|---|---|---|---|---|---|
def main():
a, b, c = map(int, input().split())
if(a+b+c >= 22):
print('bust')
else:
print('win')
return 0
if __name__ == '__main__':
main()
|
n, k = map(int,input().split())
lst = list(map(int,input().split()))
ans = 0
for i in range(n):
if (lst[i] >= k):
ans = ans + 1
print(ans)
| 0 | null | 148,588,692,075,520 | 260 | 298 |
while 1:
h,w=map(int,raw_input().split())
if h==w==0:break
print '#'*w
for i in range(h-2):
if w>=2:
print '#'+'.'*(w-2)+'#'
else :
print '#'
print '#'*w
print''
|
H = int(input())
W = int(input())
N = int(input())
m = max(H, W)
print((N + m - 1) // m)
| 0 | null | 45,015,886,713,570 | 50 | 236 |
N = int(input())
if N % 2 != 0:
print('0')
else:
count = 0
i = 1
while True:
dif = (N // 2) // (5 ** i)
count += dif
if dif == 0:
break
i += 1
print(count)
|
N = int(input())
if N%2 != 0:
print(0)
else:
answer = 0
m = 10
while m <= N:
answer += N//m
m *= 5
print(answer)
| 1 | 115,894,567,604,298 | null | 258 | 258 |
import sys
read = sys.stdin.buffer.read
def main():
N, D, A, *XH = map(int, read().split())
monster = [0] * N
for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)):
monster[i] = (x, (h + A - 1) // A)
monster.sort()
X = [x for x, h in monster]
S = [0] * (N + 1)
idx = 0
ans = 0
for i, (x, h) in enumerate(monster):
d = h - S[i]
if d > 0:
right = x + 2 * D
while idx < N and X[idx] <= right:
idx += 1
S[i] += d
S[idx] -= d
ans += d
S[i + 1] += S[i]
print(ans)
return
if __name__ == '__main__':
main()
|
n=int(input())
x=0
y=1
if n==0 or n==1:
print(1)
else:
for i in range(n):
x,y=y,x+y
i+=1
print(y)
| 0 | null | 41,021,659,188,378 | 230 | 7 |
n, x, m = map(int, input().split())
lis = set()
loop_lis = []
cnt = 0
while x not in lis:
cnt += 1
lis.add(x)
loop_lis.append(x)
x = pow(x, 2) % m
if cnt == n:
print(sum(lis))
exit()
start = loop_lis.index(x)
length = len(loop_lis) - start
loop_sum = sum(loop_lis[start:])
before = sum(loop_lis[:start])
loop = loop_sum * ((n - start) // length)
remain = sum(loop_lis[start : (start + (n - start) % length)])
print(before + loop + remain)
|
# -*- coding:utf-8 -*-
def solve():
N, X, M = list(map(int, input().split()))
def f(x, m):
return x%m
# A[i]の値は必ず mod Mの範囲に収まる
# ということはたかだかMの周期でループする
# ただし、ループして戻るのはA[0]とは限らず、適当なA[?]に戻る
# 注意として、A[i]=0になったら、A[i+1]以降は必ず0
A = [0]*(10**5+2) # A[i]
Ar = [0]*(10**5+2) # Ar[i] := A[i]以下の累積和
A[0], Ar[0] = X, X
Adic = {X:0} # Adic[A[i]]=i => 過去のA[i]はi番目に出現した
stop_i = 0
is_zero = False
for i in range(1, N):
A[i] = f(pow(A[i-1], 2, M), M)
Ar[i] = Ar[i-1] + A[i]
if A[i] == 0:
is_zero = True
stop_i = i
break
if A[i] in Adic:
stop_i = i
break
Adic[A[i]] = i
if stop_i == 0:
print(Ar[N-1])
elif is_zero:
print(Ar[stop_i])
else:
start_i = Adic[A[stop_i]]
t = stop_i - start_i
restN = N - start_i
if start_i-1 >= 0:
ans = Ar[start_i-1]
ans += (Ar[stop_i-1] - Ar[start_i-1]) * (restN//t)
ans += Ar[start_i-1+(restN%t)] - Ar[start_i-1]
else:
ans = Ar[stop_i-1] * (restN//t)
ans += Ar[start_i-1+(restN%t)]
print(ans)
if __name__ == "__main__":
solve()
| 1 | 2,779,862,099,760 | null | 75 | 75 |
icase=0
if icase==0:
a,b=map(int,input().split())
print(max(a-2*b,0))
|
a,b,c,k = map(int,input().split())
#l = [1 for i in range(a)] + [0 for i in range(b)] + [-1 for i in range(c)]
#ans = sum(l[:k])
if k <= a:
ans = k
elif (a < k) & (k <= a + b):
ans = a
elif (a + b < k) & (k <= a + b + c):
ans = a - (k - (a + b))
print(ans)
| 0 | null | 94,410,815,847,300 | 291 | 148 |
import math
a, b, x = map(int, input().split())
c = x/a**2 # c : height of water
if c >= b/2:
tanth = 2*(b-c)/a
deg = math.atan(tanth)*180/math.pi
else:
tanth = b**2/(2*a*c)
deg = math.atan(tanth)*180/math.pi
print(deg)
|
"""
keyword: ラジアン, 度
最大限傾けたとき、水と接している面は横から見ると台形ないし三角形となる
水と接している面の面積 x/a が a*b/2 より大きい場合は台形となり、それ以下の場合は三角形となる
・台形の場合
最大限傾けたとき、水と接している台形の上辺の長さをhとすると
(h+b)*a/2 = x/a
h = 2*x/(a**2) - b
求める角度をthetaとすると
tan(theta) = (b-h)/a
theta = arctan((b-h)/a)
・三角形の場合
最大限傾けたとき、水と接している三角形の底辺の長さをhとすると
h*b/2 = x/a
h = 2*x/(a*b)
求める角度をthetaとすると
tan(theta) = b/h
theta = arctan(b/h)
"""
import sys
sys.setrecursionlimit(10**6)
a,b,x = map(int, input().split())
import numpy as np
if x/a > a*b/2:
h = 2*x/(a**2) - b
theta = np.arctan2(b-h, a) # radian表記なので戻り値の範囲は[-pi/2, pi/2]
theta = np.rad2deg(theta)
else:
h = 2*x/(a*b)
theta = np.arctan2(b, h)
theta = np.rad2deg(theta)
print(theta)
| 1 | 163,193,710,145,308 | null | 289 | 289 |
L,R,d = [int(i) for i in input().split()]
ans = 0
for i in range(L,R+1):
if i%d == 0:
ans += 1
print(ans)
|
l = [i for i in range(1,10)]
for i in l:
for j in l:
print(str(i)+ 'x' + str(j) + '=' + str(i*j))
| 0 | null | 3,717,392,389,244 | 104 | 1 |
n,*a = map(int,open(0).read().split())
cnt = [3]+[0]*n
ans = 1
mod = 10**9+7
for i in a:
ans = ans * cnt[i] % mod
cnt[i] -= 1
cnt[i+1] += 1
print(ans)
|
# similar to problem if n person are arranged in a row and have 3 different hats to wear
# no of ways of wearing hats so that every adjacent person wears different hats
# so ith person cannot wear more than 3 no of different ways
mod = 10**9+7
def main():
ans =1
n = int(input())
arr = list(map(int , input().split()))
col=[0 for i in range(0 , 6)]
for i in range(0 , n):
cnt , cur =0 , -1
if arr[i]==col[0]:
cnt = cnt+1
cur = 0
if arr[i]==col[1]:
cnt = cnt+1
cur = 1
if arr[i]==col[2]:
cnt = cnt+1
cur = 2
if cur ==-1:
print(0)
exit()
col[cur]=col[cur]+1
ans = (ans*cnt)%mod
ans = ans%mod
print(ans)
if __name__ =="__main__":
main()
| 1 | 129,600,276,893,024 | null | 268 | 268 |
n,k=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(2*n):f+=[f[-1]*(i+1)%mod]
def comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod
ans=comb(2*n-1,n-1)
for i in range(n-1,k,-1):ans=(ans-comb(n,n-i)*comb(n-1,i))%mod
print(ans)
|
n,k=map(int,input().split())
P=10**9+7
class FactInv:
def __init__(self,N,P):
fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
for i in range(1,N):
fact[i+1]=(fact[i]*(i+1))%P
ifact[-1]=pow(fact[-1],P-2,P)
for i in range(N,0,-1):
ifact[i-1]=(ifact[i]*i)%P
self.fact=fact;self.ifact=ifact;self.P=P
def comb(self,n,k):
return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
C=FactInv(2*n+10,P)
ans=0
for i in range(0,min(k+1,n)):
ans+=(C.comb(n,i)*C.comb(n-1,n-i-1))%P
ans%=P
print(ans)
| 1 | 67,321,669,037,888 | null | 215 | 215 |
import numpy as np
n, k = map(int, input().split())
a = np.arange(n+1, dtype='int')
b = np.cumsum(a)
s = 0
for i in range(k, n+1):
s += (b[n] - b[n-i]) - b[i-1] + 1
s = s % 1000000007
s += 1
s = s % 1000000007
print(s)
|
from collections import deque
n = int(input())
G = []
for _ in range(n):
tmp = list(map(int, input().split()))
u = tmp.pop(0)
k = tmp.pop(0)
t = []
for i in range(k):
a = tmp.pop(0)
t.append(a-1)
G.append(t)
dist = [-1]*n
dist[0] = 0
que = deque()
que.append(0)
while que:
v = que.popleft()
for nv in G[v]:
if dist[nv] != -1:
continue
dist[nv] = dist[v] + 1
que.append(nv)
for i in range(n):
print(i+1, dist[i])
| 0 | null | 16,437,851,304,380 | 170 | 9 |
n = int(input())
mod = 1000000007
def _mod(x, y):
res = 1
for i in range(y):
res = (res * x) % mod
return res
ans = _mod(10, n) - _mod(9, n) - _mod(9, n) + _mod(8, n)
ans %= mod
ans = (ans + mod) % mod
print(ans)
|
import sys
n = int(input())
pmax = 10 ** 9 + 7
if n == 1 or n== 0 :
print('0')
sys.exit()
elif n == 2:
print('2')
sys.exit()
x = 10 ** n % pmax
y = 9 ** n % pmax
z = 9 ** n % pmax
yz = 8 ** n % pmax
ans = (x - y - z + yz) % pmax
print(ans)
| 1 | 3,156,295,674,430 | null | 78 | 78 |
A, B = map(int, input().split())
N = 1000
p1 = 0.08
p2 = 0.1
for i in range(1, N + 1):
if int(i * p1) == A and int(i * p2) == B:
print(i)
exit()
print("-1")
|
n = int(input())
#n, m = map(int, input().split())
al = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
mod = 10**9+7
add = 0
ans = 0
for i in range(n-1, 0, -1):
add = (add+al[i]) % mod
ans = (ans+add*al[i-1]) % mod
print(ans)
| 0 | null | 30,218,340,967,360 | 203 | 83 |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): 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
count = 0
N,K = I()
h = l()
for i in range(N):
if h[i] >= K:
count += 1
print(count)
|
n,k=map(int,input().split())
n=list(map(int,input().split()))
a=0
for i in n:
if i>=k:
a+=1
print(a)
| 1 | 178,828,112,067,282 | null | 298 | 298 |
def main():
import sys
input = sys.stdin.readline
inf = 1 << 60
N, M, L = map(int, input().split())
dist = [[inf] * N for _ in range(N)]
for _ in range(M):
A, B, C = map(int, input().split())
A -= 1
B -= 1
dist[A][B] = dist[B][A] = C
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(
dist[i][j],
dist[i][k] + dist[k][j]
)
g = [[inf] * N for _ in range(N)] # 到達に必要な補充回数
for A in range(N):
for B in range(N):
if dist[A][B] <= L:
g[A][B] = 1
for k in range(N):
for i in range(N):
for j in range(N):
g[i][j] = min(
g[i][j],
g[i][k] + g[k][j]
)
Q = int(input())
for _ in range(Q):
s, t = (int(x) - 1 for x in input().split())
d = g[s][t]
if d == inf:
print(-1)
else:
print(d - 1)
if __name__ == '__main__':
main()
|
from scipy.sparse.csgraph import floyd_warshall as fw
N, M, L = map(int, input().split())
# 町間の道の長さのマトリックスを初期値無限で作成
S = [[float("INF") for i in range(N)] for i in range(N)]
# 町間の道の長さ情報をマトリックスに入力
for i in range(M):
a, b, c = map(int,input().split())
S[a-1][b-1] = c
S[b-1][a-1] = c
# ワーシャルフロイド法で最短距離のマップを生成
Sf = fw(S)
T = [[float("INF")for i in range(N)] for i in range(N)]
# 町間を補給なしで通行可能な場合は1、不可能な場合はINFとしてマトリックスを作成
# (町間距離がタンク容量より大きい場合は通行不可)
for i in range(N):
for j in range(N):
if Sf[i][j] <= L:
T[i][j] = 1
# ワーシャルフロイド法で町間移動可否のマップを生成
# すぐ上のfor文で、補給なしで移動できない町間の移動コストはINFにしたが、
# この処理で複数回の補給を行えば移動できる距離を
Tf = fw(T)
for i in range(int(input())):
a, b = map(int, input().split())
if Tf[a-1][b-1] != float("INF"):
print(int(Tf[a-1][b-1])-1)
else:
print(-1)
| 1 | 173,612,917,709,840 | null | 295 | 295 |
n=int (input())
a=list(input().split(" "))
for i in range(0,n):
print(a[0][i]+a[1][i],end="")
|
回数 = int(input())
a, b = list(map(str, input().split()))
c = ""
for i in range(回数):
c = c + a[i]
c = c + b[i]
print(c)
| 1 | 111,521,006,431,640 | null | 255 | 255 |
n=int(input())
l = [int(x) for x in input().split(' ')]
c=0
for i in range(0,len(l),2):
if((i+1)%2!=0 and l[i]%2!=0):
c+=1
print(c)
|
a, b = input().split()
a = int(a)
b = int(round(float(b) * 100))
print(a * b // 100)
| 0 | null | 12,121,299,575,738 | 105 | 135 |
c = input()
alpha_list = 'abcdefghijkfmnopqrstuvrxyz'
for i in range(len(alpha_list)):
if c == alpha_list[i]:
print(alpha_list[i+1])
break
|
n = input()
a = map(int, raw_input().split())
if len(a) == n:
a.reverse()
print ' '.join(map(str, a))
| 0 | null | 46,764,319,795,112 | 239 | 53 |
s,w = (int(x) for x in input().split())
if s <= w:
print("unsafe")
else:
print("safe")
|
S, W = map(int, input().split())
print('unsafe') if S <= W else print('safe')
| 1 | 29,082,451,256,640 | null | 163 | 163 |
n=int(input())
s=input().split()
q=int(input())
t=input().split()
cnt=0
for i in range(q):
for j in range(n):
if s[j]==t[i]:
cnt+=1
break
print(cnt)
|
input()
s = input().split()
input()
t = input().split()
cnt = 0
for t1 in t:
for s1 in s:
if t1 == s1:
cnt += 1
break
print(cnt)
| 1 | 67,193,280,548 | null | 22 | 22 |
n = int(input())
min_value = 10**10
result = -(10**10)
for _ in [0]*n:
current = int(input())
result = max(result, current-min_value)
min_value = min(min_value, current)
print(result)
|
n,a,b = map(int, input().split())
if a%2==b%2:
print((b-a)//2)
exit()
print(min(a-1,n-b) +1+ (b-a-1)//2)
| 0 | null | 54,878,414,160,570 | 13 | 253 |
a,b,c,d,e=map(int,input().split())
if a == 0:
print('1')
elif b== 0:
print('2')
elif c == 0:
print('3')
elif d==0:
print('4')
elif e == 0:
print('5')
|
n = map(int, input().split(" "))
for index, i in enumerate(n, 1):
if i == 0:
print(index)
| 1 | 13,445,940,856,484 | null | 126 | 126 |
i = list(map(int, input().split()))
r = [ i[0]*i[2], i[1]*i[2], i[0]*i[3], i[1]*i[3] ]
print(max(r))
|
a, b, c, d = map(int, input().split())
print(max(a * c, a * d, b * c, b * d))
| 1 | 3,019,259,567,470 | null | 77 | 77 |
def main():
import sys
readline = sys.stdin.buffer.readline
n, x, y = map(int, readline().split())
l = [0] * (n-1)
for i in range(1, n):
for j in range(i+1, n+1):
s = min(j-i, abs(x-i)+abs(j-y)+1)
l[s-1] += 1
for i in l:
print(i)
main()
|
N, X, Y = map(int, input().split())
ans = [0] * (N + 1)
for i in range(1, N):
for j in range(i+1, N+1):
dis1 = j-i
dis2 = abs(X-i) + 1 + abs(Y - j)
dis3 = abs(Y-i) + 1 + abs(X - j)
d = min(dis1,dis2,dis3)
ans[d] += 1
for i in range(1, N):
print(ans[i])
| 1 | 44,036,334,189,848 | null | 187 | 187 |
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
def lcm(a, b):
"""最小公倍数"""
from math import gcd
return (a * b) // gcd(a, b)
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, M, As):
if sum([a % 2 for a in As]) > 0:
print(0)
return
As = [a // 2 for a in As]
all_lcm = 1
for a in As:
all_lcm = lcm(all_lcm, a)
if all_lcm > M:
print(0)
return
for a in As:
if (all_lcm // a) % 2 == 0:
print(0)
return
from math import ceil
print(ceil(M // all_lcm / 2))
if __name__ == '__main__':
N, M = map(int, input().split())
As = [int(i) for i in input().split()]
# import random
# N, M = 10 ** 5, 10 ** 9
# As = [random.randint(5, 5) * 2 for _ in range(N)]
solve(N, M, As)
|
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
b=[int(input()) for i in range(n)]
d=[[0]*3 for i in range(3)]
for i in range(3):
for j in range(3):
if a[i][j] in b:
d[i][j]=1
if d[0][0]==1 and d[0][1]==1 and d[0][2]==1:
print('Yes')
elif d[1][0]==1 and d[1][1]==1 and d[1][2]==1:
print('Yes')
elif d[2][0]==1 and d[2][1]==1 and d[2][2]==1:
print('Yes')
elif d[0][0]==1 and d[1][1]==1 and d[2][2]==1:
print('Yes')
elif d[0][0]==1 and d[1][0]==1 and d[2][0]==1:
print('Yes')
elif d[0][1]==1 and d[1][1]==1 and d[2][1]==1:
print('Yes')
elif d[0][2]==1 and d[1][2]==1 and d[2][2]==1:
print('Yes')
elif d[0][2]==1 and d[1][1]==1 and d[2][0]==1:
print('Yes')
else:
print('No')
| 0 | null | 80,333,005,016,770 | 247 | 207 |
N = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
K = []
# N = K**n*(K*m+1)
# n >= 1
K1 = make_divisors(N)
K1.pop(0)
# print(K1)
for k in K1:
# print("k=",k)
n=0
while N-k**n >= 0:
# print((N-k**n)%(k**(n+1)))
# print("n=",n)
if (N-k**n)%(k**(n+1))==0:
K.append(k)
n += 1
# print(K)
# n == 0
K2 = make_divisors(N-1)
K2.pop(0)
K += K2
# print(K)
print(len(K))
|
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
N = int(input())
ans = len(make_divisors(N-1))-1
for i in make_divisors(N):
if i == 1:
continue
Ni = int(N/i)
while Ni % i == 0:
Ni = int(Ni/i)
if Ni % i == 1:
ans+=1
print(ans)
| 1 | 41,247,791,875,628 | null | 183 | 183 |
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b,c=[],[]
for _ in range(q):
bi,ci=map(int,input().split())
b.append(bi)
c.append(ci)
number=[0 for i in range(10**5+1)]
for i in range(n):
number[a[i]]+=1
s=sum(a)
for i in range(q):
s+=(c[i]-b[i])*number[b[i]]
number[c[i]]+=number[b[i]]
number[b[i]]=0
print(s)
|
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
#BC=[]
#for i in range(Q):
# BC.append(list(map(int,input().split())))
A_sum=sum(A)
A_count=Counter(A)
for i in range(Q):
B,C=(map(int,input().split()))
A_sum+=(C-B)*A_count[B]
A_count[C]+=A_count[B]
A_count[B]=0
print(A_sum)
| 1 | 12,265,020,182,272 | null | 122 | 122 |
import time
start = time.time()
n = int(input())
a = list(map(int,input().split()))
b = []
m = 0
for i in range(1,n):
m = m ^ a[i]
b.append(m)
for j in range(1,n):
m = m ^ a[j-1]
m = m ^ a[j]
b.append(m)
b = map(str,b)
print(' '.join(b))
|
#import numpy as np
N = int(input())
a = list(map(int, input().split()))
all_xor = 0
for _a in a:
all_xor = all_xor ^ _a
for _a in a:
print(all_xor ^ _a)
| 1 | 12,435,664,228,338 | null | 123 | 123 |
N = int(input())
XYS = [list(map(int, input().split())) for _ in range(N)]
s = 0
def perm(ns):
acc = []
def fill(ms, remains):
if remains:
for m in remains:
fill(ms + [m], [x for x in remains if x != m])
else:
acc.append(ms)
fill([], ns)
return acc
s = 0
for indexes in perm(list(range(N))):
xys = [XYS[i] for i in indexes]
x0, y0 = xys[0]
for x1, y1 in xys:
s += ((x0 - x1)**2 + (y0 - y1)**2) ** 0.5
x0 = x1
y0 = y1
nf = 1
for i in range(1, N+1):
nf *= i
ans = s / nf
print(ans)
|
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors[1:]
n = int(input())
a = make_divisors(n-1)
b = make_divisors(n)
count = 0
for kk in b:
mom = n
while mom % kk == 0:
mom //= kk
if mom % kk == 1:
count +=1
print(len(a) + count)
| 0 | null | 94,475,094,780,000 | 280 | 183 |
r = float(input())
pi = 3.141592653589
s = pi * r**2
h = 2 * pi * r
print("{:.6f}".format(s), "{:.6f}".format(h))
|
import math
r=input()
a=r*r*math.pi
b=2*r*math.pi
print "%f %f"%(a,b)
| 1 | 628,725,803,562 | null | 46 | 46 |
n, k = map(int, input().split())
w = []
for i in range(n):
w.append(int(input()))
def carriable(P, n, k, w):
j = 0
for i in range(k):
sum = 0
while j < n and sum + w[j] <= P:
sum += w[j]
j += 1
return j
def binary_search(p_left, p_right, n, k, w):
if p_left == p_right:
return p_left
else:
p_center = (p_left + p_right)//2
# because we have to search for the smallest p which satisfies carriable(p, n, k, w) = n,
# be careful of the inequality condition
if carriable(p_center, n, k, w) >= n:
return binary_search(p_left, p_center, n, k, w)
else:
return binary_search(p_center + 1, p_right, n, k, w)
p_left = 0
p_right = sum(w)
print(binary_search(p_left, p_right, n, k, w))
|
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
A = A[::-1]
MOD = 2019
p10 = [1] * N
for i in range(1, N):
p10[i] = (p10[i - 1] * 10) % MOD
for i in range(N):
A[i] = (A[i] * p10[i]) % MOD
cumsum = [A[0]] * N
for i in range(1, N):
cumsum[i] = (cumsum[i - 1] + A[i]) % MOD
cnt = [0] * MOD
cnt[0] = 1
for i in range(N):
cnt[cumsum[i]] += 1
ans = 0
for i in range(MOD):
ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
| 0 | null | 15,461,822,135,540 | 24 | 166 |
s = input()
t = input()
count = 0
for l in range(len(s)):
if s[l] != t[l]:
count += 1
print(count)
|
s = input()
S1 = list(s)
T = list(input())
cnt =0
for i in range(len(s)):
if S1[i] != T[i]:
cnt+=1
print(cnt)
| 1 | 10,494,515,138,458 | null | 116 | 116 |
N=int(input())
N_26=[]
while N>0:
N-=1
N_mod=N%26
N=N//26
N_26.append(chr(97+N_mod))
print("".join(list(reversed(N_26))))
|
S,T = input().split()
T+=S
print(T)
| 0 | null | 57,308,556,297,258 | 121 | 248 |
def main():
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
count += (i != minj)
A[i], A[minj] = A[minj], A[i]
print(" ".join(map(str,A)))
print(count)
if __name__ == "__main__":
import os
import sys
if len(sys.argv) > 1:
if sys.argv[1] == "-d":
fd = os.open("input.txt", os.O_RDONLY)
os.dup2(fd, sys.stdin.fileno())
main()
else:
main()
|
N = int(raw_input())
lst = map(int, raw_input().split())
cnt = 0
for i in range(0, len(lst)):
m = i
for j in range(i, len(lst)):
if lst[m] > lst[j]:
m = j
if m != i:
lst[i], lst[m] = lst[m], lst[i]
cnt+=1
print " ".join(map(str,lst))
print (cnt)
| 1 | 19,949,952,448 | null | 15 | 15 |
n = int(input())
ans = 0
flag = 0
for i in range(0, n):
x, y = input().split()
if x == y:
ans = ans + 1
else:
ans = 0
if ans >= 3:
flag = 1
if flag == 1:
print("Yes")
else :
print("No")
|
from collections import Counter
def solve(n, ddd):
if ddd[0] != 0:
return 0
cnt = Counter(ddd)
if cnt[0] != 1:
return 0
max_c = max(cnt)
for i in range(max_c + 1):
if i not in cnt:
return 0
MOD = 998244353
ans = 1
for i in range(max_c):
prev = cnt[i]
curr = cnt[i + 1]
ans = ans * pow(prev, curr, MOD) % MOD
return ans
n = int(input())
ddd = list(map(int, input().split()))
print(solve(n, ddd))
| 0 | null | 78,375,020,927,590 | 72 | 284 |
while True:
x = []
x = input().split( )
y = [int(s) for s in x]
if sum(y) == -3:
break
if y[0] == -1 or y[1] == -1:
print("F")
elif y[0] + y[1] < 30:
print("F")
elif y[0] + y[1] >= 30 and y[0] + y[1] <50:
if y[2] >= 50:
print("C")
else:
print("D")
elif y[0] + y[1] >= 50 and y[0] + y[1] <65:
print("C")
elif y[0] + y[1] >= 65 and y[0] + y[1] <80:
print("B")
elif y[0] + y[1] >= 80:
print("A")
|
result = []
while True:
(m, f, r) = [int(i) for i in input().split()]
sum = m + f
if m == f == r == -1:
break
if m == -1 or f == -1:
result.append('F')
elif sum >= 80:
result.append('A')
elif sum >= 65:
result.append('B')
elif sum >= 50:
result.append('C')
elif sum >= 30:
if r >= 50:
result.append('C')
else:
result.append('D')
else:
result.append('F')
[print(result[i]) for i in range(len(result))]
| 1 | 1,247,869,638,970 | null | 57 | 57 |
S = input()
N = int(input())
for i in range(N):
operate = input().split()
if operate[0] == "replace":
n = int(operate[1])
m = int(operate[2])+1
left_str = S[:n]
right_str = S[m:]
center_str = operate[3]
S = left_str + center_str + right_str
elif operate[0] == "reverse":
n = int(operate[1])
m = int(operate[2])+1
left_str = S[:n]
center_str = S[n:m]
right_str = S[m:]
center_str = center_str[::-1]
S = left_str + center_str + right_str
elif operate[0] == "print":
n = int(operate[1])
m = int(operate[2])+1
left_str = S[:n]
center_str = S[n:m]
right_str = S[m:]
print(center_str)
|
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
num = Counter(s)
mx = max(num.values())
for i in sorted(num):
if num[i] == mx:
print(i)
| 0 | null | 36,100,071,307,508 | 68 | 218 |
import sys
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.readline
n, m, energy = map(int, input().split())
edges = [[float('INF')]*n for _ in range(n)]
for i in range(m):
a, b, c = map(int, input().split())
edges[a-1][b-1] = c
edges[b-1][a-1] = c
G = csgraph_from_dense(edges, null_value=float('INF'))
dist = floyd_warshall(G) # dist[i][j] = min_distance between i and j
L_edges = [[0]*n for _ in range(n)]
for i in range(n-1):
for j in range(i, n):
if dist[i][j] <= energy:
L_edges[i][j] = 1
L_edges[j][i] = 1
G = csgraph_from_dense(L_edges, null_value=0)
answers = floyd_warshall(G)
for i in range(n):
for j in range(n):
if answers[i][j] == float('INF'):
answers[i][j] = 0
answers[j][i] = 0
Q = int(input())
for i in range(Q):
s, t = map(int, input().split())
ans = answers[s-1][t-1] - 1
print(int(ans))
|
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n, k = MAP()
R, S, P = MAP()
t = input()
s = ''
ans = 0
for i in range(len(t)):
if t[i] == 'r':
if i >= k and s[i-k] == 'p':
s += 'x'
else:
ans += P
s += 'p'
elif t[i] == 's':
if i >= k and s[i-k] == 'r':
s += 'x'
else:
ans += R
s += 'r'
else:
if i >= k and s[i-k] == 's':
s += 'x'
else:
ans += S
s += 's'
print(ans)
| 0 | null | 140,145,909,908,242 | 295 | 251 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = [(a-1) % K for a in A]
S = [0 for i in range(N+1)]
for i in range(1, N+1):
S[i] = (S[i-1] + A[i-1]) % K
kinds = set(S)
counts = {}
ans = 0
for k in kinds:
counts[k] = 0
for i in range(N+1):
counts[S[i]] += 1
if i >= K:
counts[S[i-K]] -= 1
ans += (counts[S[i]] - 1)
print(ans)
|
# -*- coding: utf-8 -*-
import sys
N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
A=map(lambda a: (a-1)%K, A)
S=[0]
for a in A:
S.append( (S[-1]+a)%K ) #累積和
d=dict() #要素:要素の数を持つ
ans=0
for i in range(N+1):
x=S[i]%K
if i==0:
d[x]=1
else:
if x in d:
if 2<=K: #K=1の時は自分の値も見てはいけない
ans+=d[x] #自分より前に同じ出現した、自分と同じ要素の数を答えに追加
d[x]+=1
else:
d[x]=1
if 0<=i-K+1:
x_head=S[i-K+1]%K #長さK-1の範囲で配列Sを見るため、1つ進んだら一番先頭の要素を辞書から削除する
d[x_head]-=1
print ans
| 1 | 137,690,828,378,180 | null | 273 | 273 |
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
me = ""
ans = 0
for i in range(n):
if t[i] == "r":
if i < k:
me += "p"
ans += p
elif me[i-k] != "p":
me += "p"
ans += p
else:
if t[i-k] == "p":
me += "p"
ans += p
else:
me += "r"
elif t[i] == "s":
if i < k:
me += "r"
ans += r
elif me[i-k] != "r":
me += "r"
ans += r
else:
if t[i-k] == "r":
me += "r"
ans += r
else:
me += "s"
else:
if i < k:
me += "s"
ans += s
elif me[i-k] != "s":
me += "s"
ans += s
else:
if t[i-k] == "s":
me += "s"
ans += s
else:
me += "p"
print(ans)
|
N, K = map(int, input().split())
ls1 = list(map(int, input().split()))
d = dict()
ls2 = ['r', 's', 'p']
for x, y in zip(ls1, ls2):
d[y] = x
T = input()
S = T.translate(str.maketrans({'r': 'p', 's': 'r', 'p': 's'}))
ans = 0
for i in range(K):
cur = ''
for j in range(i, N, K):
if cur != S[j]:
ans += d[S[j]]
cur = S[j]
else:
cur = ''
print(ans)
| 1 | 107,161,241,182,530 | null | 251 | 251 |
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
ans = 12345678901234
cnt = 0
for i in range(n):
cnt += a[i]
ans = min(ans,abs(s-cnt - cnt))
print(ans)
|
N, K = map(int, input().split())
MOD = 1000000007
fact = [0] * (N+1)
finv = [0] * len(fact)
inv = [0] * len(fact)
fact[0] = fact[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, len(fact)):
fact[i] = fact[i-1] * i % MOD
# inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
inv[i] = - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
nCr = lambda n, r: fact[n] * finv[n-r] * finv[r] % MOD
nHr = lambda n, r: nCr(n+r-1, r)
# ans = 0
# for i in range(min(N-1, K) + 1):
# ans += nCr(N, i) * nHr(N-i, i)
# ans = sum(nCr(N, i) * nHr(N-i, i) for i in range(min(N-1, K) + 1))
ans = sum(nCr(N, i) * nCr(N-1, i) for i in range(min(N-1, K) + 1))
print(ans % MOD)
| 0 | null | 104,837,794,152,158 | 276 | 215 |
N = int(input())
result = 0
for i in range(1, (N + 1)):
if i % 15 == 0:
'Fizz Buzz'
elif i % 3 == 0:
'Fizz'
elif i % 5 == 0:
'Buzz'
else:
result = result + i
print(result)
|
N = int(input())
result = 0
for i in range(1, N+1):
if i % 3 == 0 and i % 5 == 0:
pass
elif i % 3 == 0:
pass
elif i % 5 == 0:
pass
else:
result += i
print(result)
| 1 | 34,923,405,636,460 | null | 173 | 173 |
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import defaultdict
def resolve():
N = ir()
A = lr()
dp = defaultdict(lambda: -float('inf'))
dp[0, 0, 0] = 0
for i in range(N):
for j in range(max(i//2-1, 0), i//2+2):
dp[i+1, j+1, 1] = dp[i, j, 0]+A[i]
dp[i+1, j, 0] = max(dp[i, j, 0], dp[i, j, 1])
# print(dp)
print(max(dp[N, N//2, 1], dp[N, N//2, 0]))
resolve()
|
if __name__ == '__main__':
s = input()
t = input()
if s == t[:-1]:
print("Yes")
else:
print("No")
| 0 | null | 29,471,350,266,860 | 177 | 147 |
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 30 11:23:30 2018
ALDS1-4a most simple implementation using the features of the python
@author: maezawa
"""
n = int(input())
s = map(int, input().split())
q = int(input())
t = map(int, input().split())
s_set = set(s)
t_set = set(t)
sandt = s_set & t_set
print(len(sandt))
|
def main():
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
count = 0
for t in T:
for s in S:
if t == s:
count += 1
break
print(count)
if __name__ == '__main__':
main()
| 1 | 70,223,748,180 | null | 22 | 22 |
n=int(input())
for i in range(1,361):
if (n*i)%360==0:
print(i);exit()
|
import math
x = int(input())
def lcm(x, y):
return (x * y) // math.gcd(x, y)
print(lcm(x, 360)//x)
| 1 | 13,078,494,002,200 | null | 125 | 125 |
N = int(input())
A = list(map(int, input().split()))
x = 0
ans = list()
for ai in A:
x = x ^ ai
for ai in A:
ans.append(x ^ ai)
print(*ans)
|
s = "0"+input()
ans = 0
n = len(s)
f = 0
p = 0
for i in range(1,n+1):
n = int(s[-i])
# n += f
if p+(n>4) > 5:
f = 1
else:
# ans += f
f = 0
n += f
ans += min(n,10-n)
p = n
# ans += f
print(ans)
| 0 | null | 41,889,123,894,940 | 123 | 219 |
n, m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for j in range(m)]
ans = []
for a in A:
multi_list = [x * y for (x, y) in zip(a, b)] # 書き方:リストの要素同士の積
arg = 0
for k in multi_list:
arg += k
print(arg)
|
s = input()
p = input()
if (s*2).count(p) == 0 :
print('No')
else :
print('Yes')
| 0 | null | 1,433,727,471,762 | 56 | 64 |
# D - Banned K
from collections import Counter
def main():
N, *A = map(int, open(0).read().split())
cnt = Counter(A)
total = sum(v * (v - 1) // 2 for v in cnt.values())
res = [total - (cnt[a] - 1) for a in A]
print("\n".join(map(str, res)))
if __name__ == "__main__":
main()
|
n = int(input())
a = list(map(int,input().split()))
count = [0]*n
for i in range(n):
count[a[i]-1] += 1
ans = 0
for i in range(n):
ans += count[i]*(count[i]-1)//2
for i in a:
before = count[i-1]*(count[i-1]-1)//2
after = (count[i-1]-1)*(count[i-1]-2)//2
print(ans - before + after)
| 1 | 47,853,437,035,712 | null | 192 | 192 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
A, B, M = getNM()
# それぞれ冷蔵庫の値段
ref_a = getList()
ref_b = getList()
# 一枚だけ使える
ticket = [getList() for i in range(M)]
ans = min(ref_a) + min(ref_b)
for i in ticket:
opt = ref_a[i[0] - 1] + ref_b[i[1] - 1] - i[2]
ans = min(ans, opt)
print(ans)
|
A,B,M=[int(i) for i in input().split() ]
a = [int(i) for i in input().split() ]
b = [int(i) for i in input().split() ]
mlist = []
for i in range(M):
mlist.append( [ int(i) for i in input().split() ] )
print( min(min(a) + min(b), min( [a[i[0]-1] + b[i[1]-1] - i[2] for i in mlist ])))
| 1 | 54,324,663,101,280 | null | 200 | 200 |
n = int(input())
def memoize(f):
memo = [1, 1] + [0] * max(0, n - 1)
def main(i):
if memo[i]:
return memo[i]
result = memo[i] = f(i)
return result
return main
@memoize
def fibonacci(i):
return fibonacci(i - 1) + fibonacci(i - 2)
print(fibonacci(n))
|
def binary_search(*, ok, ng, func):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if func(mid):
ok = mid
else:
ng = mid
return ok
def main():
N, K = map(int, input().split())
*A, = sorted(map(int, input().split()))
*F, = sorted(map(int, input().split()), reverse=True)
def is_ok(score):
rest = K
for a, f in zip(A, F):
exceed = max(0, a * f - score)
if exceed:
need = (exceed + f - 1) // f
if need > a or need > rest:
return False
rest -= need
return True
ans = binary_search(ok=10 ** 12, ng=-1, func=is_ok)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 82,347,762,899,612 | 7 | 290 |
n = int(input())
a = list(map(int, input().split()))
dp = [0]*(n+1)
dp[0] = 1000
for i in range(1, n):
dp[i] = dp[i-1]
for j in range(i):
stock = dp[j]//a[j]
cost = dp[j]+(a[i]-a[j])*stock
dp[i] = max(dp[i], cost)
print(dp[n-1])
|
N = int(input())
A = list(map(int,input().split()))
money=1000
pos = 1
kabu = 0
for i in range(1,N):
if A[i-1]<A[i]:
kabu = money//A[i-1]
money += kabu*(A[i]-A[i-1])
print(money)
| 1 | 7,360,343,469,340 | null | 103 | 103 |
n, k = map(int, input().split())
mod = 10**9 + 7
cnt = [0]*(k + 1)
ans = 0
for i in range(k, 0, -1):
cnt[i] = (pow(k//i, n, mod) - sum(cnt[2*i:k+1:i])) % mod
ans = (ans + i*cnt[i]) % mod
print(ans)
|
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
c = [0] * (K + 1)
for i in range(K, 0, -1):
t = pow(K // i, N, MOD)
for j in range(2, K // i + 1):
t -= c[i * j]
t %= MOD
c[i] = t
result = 0
for i in range(1, K + 1):
result += c[i] * i
result %= MOD
print(result)
| 1 | 36,743,784,497,196 | null | 176 | 176 |
n = int(input())
l = [0 for _ in range(10**4)]
def fib(n):
if n==0:
l[0]=1
return 1
if n==1:
l[1]=1
return 1
if l[n]!=0:
return l[n]
else:
l[n]=fib(n-1)+fib(n-2)
return fib(n-1)+fib(n-2)
print(fib(n))
|
from sys import stdin,stdout
from collections import defaultdict
n,e=list(map(int,stdin.readline().split()))
h=list(map(int,stdin.readline().split()))
g=defaultdict(list)
for _ in range(e):
a,b=map(int,stdin.readline().split())
g[a]+=[b]
g[b]+=[a]
ans=0
for cur in range(1,n+1):
f=1
for neigh in g[cur]:
if h[neigh-1]>=h[cur-1]:
f=0
break
if f:ans+=1
print(ans)
| 0 | null | 12,612,731,979,520 | 7 | 155 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
a[i] = a[i] % k
if k == 1:
print(0)
exit()
ruiseki = [0]
for i in range(n):
ruiseki.append((a[i]+ruiseki[-1])%k)
mini = 0
dic = {}
ans = 0
for j in range(1, n+1):
if j-k+1 > mini:
dic[(ruiseki[mini]-mini)%k] -= 1
mini += 1
if (ruiseki[j-1]-(j-1))%k in dic:
dic[(ruiseki[j-1]-(j-1))%k] += 1
else:
dic[(ruiseki[j-1]-(j-1))%k] = 1
if (ruiseki[j]-j)%k in dic:
ans += dic[(ruiseki[j]-j)%k]
print(ans)
|
n,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
for i in range(n):
a[i+1] += a[i]
a[i+1] %=k
cnt = {}
ans = 0
for i in range(n+1):
left = i-k
if left >=0:
ldiff = (a[left] - left)%k
cnt[ldiff] -= 1
x = (a[i] - i)%k
if x <0:x+=k
if x not in cnt:cnt[x] = 0
ans+= cnt[x]
cnt[x] +=1
print(ans)
| 1 | 137,228,062,008,316 | null | 273 | 273 |
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
def gcd(a, b):
if a % b == 0:
return b
else:
return gcd(b, a % b)
def main():
X = ri()
K = 360 // gcd(360, X)
print(K)
if __name__ == '__main__':
main()
|
import sys
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
for line in sys.stdin:
line = line.strip()
if line == "":
break
X = int(line)
ans = 360 // gcd(X, 360)
print(ans)
| 1 | 13,157,476,922,050 | null | 125 | 125 |
#! python3
# matrix_multiplication.py
n, m, l = [int(x) for x in input().split(' ')]
mat1 = [[int(x) for x in input().split(' ')] for i in range(n)]
mat2 = [[int(x) for x in input().split(' ')] for j in range(m)]
rst_mat = [[0 for k in range(l)] for i in range(n)]
for i in range(n):
for k in range(l):
for j in range(m):
rst_mat[i][k] += mat1[i][j] * mat2[j][k]
for i in range(n):
print(' '.join([str(x) for x in rst_mat[i]]))
|
mod=998244353
N,M,K=map(int,input().split())
MAX_N=N+1
Fact=[0 for i in range(MAX_N+1)]
Finv=[0 for i in range(MAX_N+1)]
Fact[0]=1
for i in range(MAX_N):
Fact[i+1]=(i+1)*Fact[i]
Fact[i+1]%=mod
Finv[-1]=pow(Fact[-1],mod-2,mod)
for i in range(MAX_N-1,-1,-1):
Finv[i]=(i+1)*Finv[i+1]
Finv[i]%=mod
def C(n,k):
return (Fact[n]*Finv[k]*Finv[n-k])%mod
'''
i in range(K+1)で総和を取る
隣り合うブロックの色が同じ色なのはi通り
隣り合うブロックの色が異なるのはN-1-i通り
|の選び方はN-1Ci
同じものをつなげてN-i個のブロックと見なせる
これに対してM*((M-1)のN-1-i)乗だけある
0<=i<=K
よりN-1-i>=N-1-K>=0
問題なし
'''
ans=0
for i in range(K+1):
ans+=(C(N-1,i)*M*pow(M-1,N-1-i,mod))%mod
ans%=mod
print(ans)
| 0 | null | 12,221,368,007,772 | 60 | 151 |
#!/usr/bin/env python3
import sys
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
N, M, K = map(int, readline().split())
def graph_input(N, M):
G = [[] for _ in range(N+1)]
for _ in range(M):
a, b = map(int, readline().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
return G
friend = graph_input(N, M)
block = graph_input(N, K)
seen = [0] * N
def dfs(x, group):
# DFS で頂点 x がどの group に属するかを記録していく
# 後に、各 group に対して、seen[x] = group となるがいくつあるか数えれば連結成分数もわかる
seen[x] = group
for y in friend[x]:
if seen[y]:
continue
else:
seen[y] = group
dfs(y, group)
group = 1
for x in range(N):
if seen[x] == 0:
dfs(x, group)
group += 1
counter = Counter(seen) # リストの値の出現回数を Counter で数えることで各連結成分数を得ている
res = []
for x in range(N):
# x 自身を連結成分数から除く-1 さらに friend[x] を除く
cand_n = counter[seen[x]] - len(friend[x]) - 1
# block[x]と xの連結成分の共通部分の抜くのが難しい
for a in block[x]:
if seen[a] == seen[x]:
cand_n -= 1
res.append(cand_n)
print(" ".join(map(str, res)))
if __name__ == '__main__':
print()
|
import numpy as np
pi = np.pi
a = int(input())
print(2 * a * pi)
| 0 | null | 46,257,480,866,828 | 209 | 167 |
N, K, C = map(int, input().split())
S = input()
L = []
R = []
count_L = C
count_R = C
for i in range(N):
if S[i] == "o" and count_L >= C:
count_L = 0
L.append(i)
else:
count_L += 1
if S[N-i-1] == "o" and count_R >= C:
count_R = 0
R.append(N-i-1)
else:
count_R += 1
if len(L) >= K and len(R) >= K:
break
for l, r in zip(L, R[::-1]):
if l == r:
print(l+1)
|
def f(s):
a=[-c]
for i,s in enumerate(s,1):
if s<'x'and a[-1]+c<i:a+=i,
return a[1:k+1]
n,s=open(0)
n,k,c=map(int,n.split())
for a,b in zip(f(s[:n]),f(s[-2::-1])[::-1]):
if a==n+1-b:print(a)
| 1 | 40,668,313,262,288 | null | 182 | 182 |
string = input()
if string[2] == string[3] and string[4] == string[5]:
print("Yes")
else:
print("No")
|
s = input()
print('Yes') if s[2:3] == s[3:4] and s[4:5] == s[5:6] else print('No')
| 1 | 42,026,568,306,940 | null | 184 | 184 |
n = int(input())
a = list(map(int, input().split()))
dict_diffs = dict()
for i in range(1, n+1):
dict_diffs[i+a[i-1]] = dict_diffs.get(i+a[i-1], 0) + 1
total = 0
for j in range(1, n+1):
total += dict_diffs.get(j-a[j-1], 0)
print(total)
|
a=input()
l=a.split(" ")
b=l.index("0")
print(b+1)
| 0 | null | 19,619,411,434,458 | 157 | 126 |
a, b, c = map(int, input().split())
k = int(input())
r = 0
while b <= a :
b = 2 * b
r += 1
while c <= b:
c = 2 * c
r += 1
if r <= k:
print("Yes")
else:
print("No")
|
import sys
def gcd(a,b):
if a%b == 0:
return b
else:
return gcd(b, a%b)
for line in sys.stdin:
a,b = map(int, line.split())
if a<b:
tem = a
a = b
b = tem
gc = gcd(a,b)
print(gc, a*b//gc)
| 0 | null | 3,428,222,347,930 | 101 | 5 |
from itertools import combinations as comb
def get_ans(m, n):
ans = sum(1 for nums in comb(range(1, min(m+1,n-2)), 2) if ((n-sum(nums)>0) and (n-sum(nums) > max(nums)) and (n-sum(nums)<=m)))
return ans
while True:
m, n = (int(x) for x in input().split())
if m==0 and n==0:
quit()
ans = get_ans(m, n)
print(ans)
|
S = input()
print('Yes' if (S[2] == S[3]) & (S[4] == S[5]) else 'No')
| 0 | null | 21,540,571,928,782 | 58 | 184 |
n,m,l= map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = [list(map(int,input().split())) for i in range(m)]
for u in range(n):
for w in range(l):
c=0
for z in range(m):
c+=a[u][z]*b[z][w]
if w==l-1:
print(c)
else:
print(c,end=" ")
|
#ITP1_7_D
n,m,l=map(int,input().split())
a=[]
b=[]
for _ in range(n):
a.append(list(map(int,input().split())))
for _ in range(m):
b.append(list(map(int,input().split())))
c=[[0 for _ in range(l)] for _ in range(n)]
for i in range(n):
for j in range(l):
for k in range(m):
c[i][j]+=a[i][k]*b[k][j]
for i in range(n):
for j in range(l-1):
print(c[i][j],end=" ")
print(c[i][-1])
| 1 | 1,424,816,980,548 | null | 60 | 60 |
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)
|
import sys
input = sys.stdin.buffer.readline
def main():
n = int(input())
A = list(map(int, input().split()))
L = [(a, i+1) for i, a in enumerate(A)]
L.sort(reverse=True)
dp = [[-1]*(n+1) for _ in range(n+1)]
dp[0][0] = 0
ans = 0
for i in range(n+1):
for j in range(n+1-i):
a, idx = L[i+j-1]
if i:
dp[i][j] = max(dp[i][j], dp[i-1][j]+a*(idx-i))
if j:
dp[i][j] = max(dp[i][j], dp[i][j-1]+a*(n+1-j-idx))
if i+j == n:
ans = max(ans, dp[i][j])
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 35,284,267,738,266 | 176 | 171 |
n,k = input().split()
n = int(n)
k = int(k)
a = [True for i in range(n)]
while k>0:
d = int(input())
b = input().split()
for e in b:
a[int(e)-1] = False
k-=1
print(sum(a))
|
n = int(input())
d = dict()
for i in range(n):
s = input()
if(s not in d.keys()):
d[s] = 1
else:
d[s] +=1
max = max(d.values())
ans = []
for i in d.keys():
if(d[i] == max):
ans.append(i)
for i in sorted(ans):
print(i)
| 0 | null | 47,496,776,624,512 | 154 | 218 |
# -*- 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)
def modinv(a):
b = MOD
u = 1
v = 0
while b:
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
u %= MOD
if u < 0:
u += MOD
return u
def factorial(N):
if N == 0 or N == 1:
return 1
res = N
for i in range(N - 1, 1, -1):
res *= i
res %= MOD
return res
def solve():
X, Y = Scanner.map_int()
if (X + Y) % 3 != 0:
print(0)
return
B = (2 * Y - X) // 3
A = (2 * X - Y) // 3
if A < 0 or B < 0:
print(0)
return
n = factorial(A + B)
m = factorial(A)
l = factorial(B)
ans = n * modinv(m * l % MOD) % MOD
print(ans)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
|
x,y = map(int,input().split())
mod = 10**9+7
def comb(N,x):
numerator = 1
for i in range(N-x+1,N+1):
numerator = numerator * i % mod
denominator = 1
for j in range(1,x+1):
denominator = denominator * j % mod
d = pow(denominator,mod-2,mod)
return numerator * d % mod
if (x+y) % 3 == 0:
a = (2*y-x) //3
b = (2*x-y) //3
if a >= 0 and b >= 0:
print(comb(a+b,a))
exit()
print(0)
| 1 | 149,796,572,748,940 | null | 281 | 281 |
n = int(input())
a = list(map(int,input().split()))
ans = {}
for i in range(n):
ans[a[i]] = i + 1
s = [ans[i+1] for i in range(n)]
print(*s)
|
S = int(input())
s = S%60
m = (S-s)/60%60
h = S/3600%24
answer = str(int(h))+":"+str(int(m))+":"+str(s)
print(answer)
| 0 | null | 90,463,619,066,238 | 299 | 37 |
def Qc():
x, n = map(int, input().split())
if 0 < n:
p = list(map(int, input().split()))
for i in range(101):
if x - i not in p:
print(x - i)
exit()
if x + i not in p:
res = x + 1
print(x + i)
exit()
else:
# 整数列がなにもない場合は自分自身が含まれていない最近値になる
print(x)
exit()
if __name__ == "__main__":
Qc()
|
X,N=map(int,input().split())
*P,=sorted(map(int,input().split()))
from bisect import bisect_left
if N==0:
t=X
else:
l = bisect_left(P, X)
for i in range(100):
t=X-i
if l-i<0 or t!=P[l-i]: break
t=X+i
if N<=l+i or t!=P[l+i]: break
print(t)
| 1 | 14,141,424,933,130 | null | 128 | 128 |
from collections import Counter
S = list(map(int, list(input())))
A = [0]
for i, s in enumerate(S[::-1]):
A.append((A[-1] + s * pow(10, i, 2019)) % 2019)
print(sum([v * (v - 1) // 2 for v in Counter(A).values()]))
|
k=int(input())
s="ACL"
for i in range(k):
print(s,end="")
| 0 | null | 16,519,154,872,360 | 166 | 69 |
import sys
from collections import deque
input = sys.stdin.readline
def main():
h, w, k = map(int, input().split())
board = [input().strip() for i in range(h)]
group = [[0 for i in range(w)] for j in range(h)]
state = 0 # 0:not found, 1:one strawberry
num = 1
stock = 1
pre = -1
for i in range(h):
if "#" not in board[i]:
stock += 1
continue
for j in range(w):
if board[i][j] == "#":
if state == 0:
state = 1
else:
num += 1
group[i][j] = num
else:
group[i][j] = num
for k in range(stock):
for j in range(w):
print(group[i][j], end=" ")
print()
num += 1
state = 0
stock = 1
pre = i
for k in range(h-pre-1):
for j in range(w):
print(group[pre][j], end=" ")
print()
if __name__ == "__main__":
main()
|
n1 = int(input())
nums1 = list(map(int, input().split()))
n2 = int(input())
nums2 = list(map(int, input().split()))
def linear_search(nums1, n1, key):
nums1[n1] = key
index = 0
while nums1[index] != key:
index += 1
return index != n1
output = 0
nums1.append(None)
for key in nums2:
if linear_search(nums1, n1, key):
output += 1
print(output)
| 0 | null | 72,075,595,586,000 | 277 | 22 |
n,m = map(int,input().split())
*hl, = map(int,input().split())
ansl = [1]*n
for _ in [0]*m:
a,b = map(int,input().split())
if hl[a-1] > hl[b-1]:
ansl[b-1] = 0
elif hl[a-1] < hl[b-1]:
ansl[a-1] = 0
else:
ansl[a-1] = 0
ansl[b-1] = 0
print(sum(ansl))
|
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
n, m = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()]for j in range(m)] # nは行数
tmp = [True for i in range(n + 1)]
res = 0
for i in range(m):
a, b = A[i]
if H[a - 1] <= H[b - 1]:
tmp[a] = False
if H[a - 1] >= H[b - 1]:
tmp[b] = False
for i in range(1, n + 1):
if tmp[i]:
res += 1
print(res)
| 1 | 25,194,613,668,000 | null | 155 | 155 |
A=int(input())
l=list(map(int,input().split()))
right=l[0]
left=sum(l[1:])
ans=left-right
for i in range(A-2):
right+=l[i+1]
left-=l[i+1]
ans=min(ans,abs(right-left))
print(ans)
|
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
total = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
b = L[j]
# j以降の項で、初めてL[k] < a-bとなるkを二分探索する
if L[-1] > a - b: # 一番最後の項でもOKな場合(j+1以降全部OK)
total += N - j - 1
elif L[j+1] <= a - b: # 一番最初の項からNGな場合
continue
else:
head = j+1 # head はL[head] > a - bを満たす(OK側)
tail = N-1 # tail はL[tail] <= a - bを満たす(NG側)
while head+1 != tail:
if L[(head + tail)//2] > a - b: # 中間地点はOK側
head = (head + tail) // 2
else: # 中間地点はNG側
tail = (head + tail) // 2
total += head - j
print(total)
| 0 | null | 157,124,431,784,958 | 276 | 294 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
n, k = map(int, input().split())
a = tuple(map(int, input().split()))
def kaisu(long):
return(sum([ceil(ae/long) - 1 for ae in a]))
def bs_meguru(key):
def isOK(index, key):
if kaisu(index) <= key:
return True
else:
return False
ng = 0
ok = max(a)
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid, key):
ok = mid
else:
ng = mid
return ok
print(bs_meguru(k))
if __name__ == '__main__':
main()
|
n=int(input())
s,t=input().split()
l=[]
for i in range(2*n):
if i%2==0:
l.append(s[i//2])
else:
l.append(t[(i-1)//2])
l=''.join(l)
print(l)
| 0 | null | 59,487,087,189,322 | 99 | 255 |
n,m,k = map(int,input().split())
mod = 998244353
ans = 0
fact = [1,1]
finv = [1,1]
for i in range(2, n+1):
fact += [fact[i-1] * i % mod]
finv += [pow(fact[i], mod-2, mod)]
def comb(n,k, mod):
return (fact[n] * finv[k] * finv[n-k]) % mod
for i in range(0, k+1):
ans += m * pow(m-1, n-i-1, mod) * comb(n-1, i, mod)
ans %= mod
print(ans)
|
#atcoder template
def main():
import sys
imput = sys.stdin.readline
#ここにコード
#input
N, M, K = map(int, input().split())
#output
mod = 998244353
n_ = 4*10**5 + 5
fun = [1]*(n_+1)
for i in range(1,n_+1):
fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
rev[i] = rev[i+1]*(i+1)%mod
def cmb(n,r):
if n <= 0 or r < 0 or r > n: return 0
return fun[n]*rev[r]%mod*rev[n-r]%mod
answer = 0
for i in range(K+1):
answer += M*pow(M-1, N-(i+1), mod)*cmb(N-1, i) % mod
answer %= mod
if N == 1:
print(M)
exit()
print(answer)
if __name__ == "__main__":
main()
| 1 | 23,183,032,551,832 | null | 151 | 151 |
#a問題
n=int(input())
print(n+(n**2)+(n**3))
|
n = int(input())
lst = list(map(int,input().split()))
lst2 = [0 for i in range(n)]
for i in range(n):
x = lst[i]
lst2[x - 1] = i + 1
for i in range(n):
if (i != n - 1):
print(lst2[i], end = ' ')
else:
print(lst2[i])
| 0 | null | 95,313,096,601,672 | 115 | 299 |
import sys
S = sys.stdin.readline().strip()
N = 2019
L = len(S)
curr = 0
seen = {}
INV = 210
seen[curr] = 1
for i in range(L):
curr = (curr * 10 + int(S[i])) % N
t = (curr * pow(10, L-i, N)) %N
if t not in seen: seen[t] = 0
seen[t] += 1
res = 0
for i in range(N):
if i not in seen: continue
t = seen[i]
res += t * (t-1)//2
print(res)
|
S = input()
s_rev = S[::-1]
r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
num += d*int(s_rev[i])
num %= 2019
r_list[num] += 1
d *= 10
d %= 2019
ans = 0
for i in range(2019):
ans += r_list[i]*(r_list[i]-1)//2
print(ans)
| 1 | 30,926,979,320,628 | null | 166 | 166 |
s = input()
a = [-1] * (len(s) + 1)
if s[0] == "<":
a[0] = 0
if s[-1] == ">":
a[-1] = 0
for i in range(len(s) - 1):
if s[i] == ">" and s[i + 1] == "<":
a[i + 1] = 0
for i in range(len(a)):
if a[i] == 0:
l = i - 1
while 0 <= l - 1:
if s[l] == ">" and s[l - 1] == ">":
a[l] = a[l + 1] + 1
else:
break
l -= 1
r = i + 1
while r + 1< len(a):
if s[r - 1] == "<" and s[r] == "<":
a[r] = a[r - 1] + 1
else:
break
r += 1
for i in range(len(a)):
if a[i] == -1:
if i == 0:
a[i] = a[i + 1] + 1
elif i == len(a) - 1:
a[i] = a[i - 1] + 1
else:
a[i] = max(a[i - 1], a[i + 1]) + 1
ans = sum(a)
print(ans)
|
s = list(input())
num = 0
n = len(s)
l = []
i = 0
while i < n:
if s[i] == '<':
l.append(num)
num+=1
i+=1
if i==n:
l.append(num)
else:
cur = 0
while i < n and s[i]=='>':
i+=1
cur+=1
if cur <= num:
l.append(num)
cur-=1
l.append((cur*(cur+1))//2)
num = 0
print(sum(l))
| 1 | 155,763,680,414,940 | null | 285 | 285 |
n = input()
print(n.replace(n,'x'*len(n)))
|
import math
def koch(left, right, n):
if n < 1: print(" ".join(map(str, left))); return
s, t, u = [0] * 2, [0] * 2, [0] * 2
s[0] = (2 * left[0] + right[0]) / 3.0
s[1] = (2 * left[1] + right[1]) / 3.0
t[0] = (left[0] + 2 * right[0]) / 3.0
t[1] = (left[1] + 2 * right[1]) / 3.0
u[0] = (t[0] - s[0]) * math.cos(math.pi/3) - (t[1] - s[1]) * math.sin(math.pi/3) + s[0]
u[1] = (t[0] - s[0]) * math.sin(math.pi/3) + (t[1] - s[1]) * math.cos(math.pi/3) + s[1]
koch(left, s, n-1)
koch(s, u, n-1)
koch(u, t, n-1)
koch(t, right, n-1)
n = int(input())
left = [0, 0]
right = [100, 0]
koch(left, right, n)
print(right[0], right[1])
| 0 | null | 36,615,353,871,878 | 221 | 27 |
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
t = LI()
a = LI()
b = LI()
a[0] -= b[0]
a[1] -= b[1]
if t[0]*a[0] == -t[1]*a[1]:
print("infinity")
return
if a[0] < 0:
a[0] *= -1
a[1] *= -1
if t[0]*a[0]+t[1]*a[1] > 0:
print(0)
return
A = t[0]*a[0]+t[1]*a[1]
k = t[0]*a[0]
l = 0
r = 10**20
while r-l > 1:
x = (l+r) >> 1
if A*x+k > 0:
l = x
else:
r = x
ans = 2*l+1
if A*r+k == 0:
ans += 1
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
|
#!/usr/bin/env python3
from itertools import combinations
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
t1, t2 = [int(item) for item in input().split()]
a1, a2 = [int(item) for item in input().split()]
b1, b2 = [int(item) for item in input().split()]
a1 *= t1
b1 *= t1
a2 *= t2
b2 *= t2
if a1 + a2 == b1 + b2:
print("infinity")
exit()
if a1 + a2 > b1 + b2:
a1, a2, b1, b2 = b1, b2, a1, a2
diff = (b1 + b2) - (a1 + a2)
mid_diff = b1 - a1
if mid_diff > 0:
print(0)
else:
ans = (abs(mid_diff) + diff - 1) // diff * 2
if abs(mid_diff) % diff == 0:
ans += 1
print(ans - 1)
| 1 | 131,458,436,734,468 | null | 269 | 269 |
def main():
s,w = list(map(int,input().split()))
if s>w:
print("safe")
else:
print("unsafe")
main()
|
results = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
N = int(input())
for _ in range(N):
S = input()
results[S] = results[S] + 1
for k, v in results.items():
print(k, 'x', v)
| 0 | null | 18,944,130,061,980 | 163 | 109 |
import math
mod=10**9+7
def mul(a, b):
return ((a % mod) * (b % mod)) % mod
def div(a, b):
return mul(a, pow(b, mod-2,mod))
x,y=map(int,input().split())
x,y=min(x,y),max(x,y)
s=y-x
if (x-s)<0 or 3*((x-s)//3)+2*s!=y:
print(0)
else:
a=(x-s)//3
b=(y-2*s)//3+s
A=1
B=1
C=1
for i in range(1,a+b+1):
A*=i
A%=mod
for i in range(1,a+1):
B*=i
B%=mod
for i in range(1,b+1):
C*=i
C%=mod
print(div(A,mul(B,C)))
|
X,Y = list(map(int,input().split()))
MAXN = 2*(10**6)+10
p = 10**9+7
f = [1]
for i in range(MAXN):
f.append(f[-1] * (i+1) % p)
def nCr(n, r, mod=p):
return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod
Z = (X+Y)//3
if Z*3!=X+Y:
print(0)
else:
P,Q = X-Z, Y-Z
if P<0 or Q<0:
print(0)
else:
print(nCr(Z,P))
| 1 | 150,254,826,189,992 | null | 281 | 281 |
import numpy as np
N = int(input())
N_List = list(map(int,input().split()))
ans = (100**2)*100
for i in range(1,101):
ca = sum(map(lambda x:(x-i)**2,N_List))
if ca < ans:
ans = ca
print(ans)
|
N = int(input())
cnt = 0
for _ in range(N):
a, b = map(int, input().split())
if a == b:
cnt += 1
else:
cnt = 0
if cnt == 3:
print('Yes')
exit()
print('No')
| 0 | null | 33,680,440,525,562 | 213 | 72 |
s=input()
print("A" if s.upper()==s else "a")
|
#!/usr/bin/env python3
a = input()
ans = "a" if a == a.lower() else "A"
print(ans)
| 1 | 11,408,323,277,680 | null | 119 | 119 |
import math
def CalcCoordinate(xa, ya, xb, yb):
arg = math.atan2(yb-ya, xb-xa) #角度
d = math.sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya)) #AとBの距離
xc = d/2 #ピタゴラスの定理より
#S = math.sqrt(3)*d*d/2
#正三角形にヘロンの公式を適用(3辺の長さが同じなので3*d)
yc = math.sqrt(3)*d/2
#if(yb <= ya):
ux = xc*math.cos(arg) - yc*math.sin(arg) + xa
uy = xc*math.sin(arg) + yc*math.cos(arg) + ya
return ux, uy
"""
else:
ux = xc*math.cos(arg) + yc*math.sin(arg) + xa
uy = xc*math.sin(arg) - yc*math.cos(arg) + ya
return ux, uy
"""
def MakeTriangle(x1, y1, x2, y2, n):
if(n != 0):
sx = (2*x1 + x2) / 3
sy = (2*y1 + y2) / 3
tx = (x1 + 2*x2) / 3
ty = (y1 + 2*y2) / 3
ux, uy = CalcCoordinate(sx, sy, tx, ty)
MakeTriangle(x1, y1, sx, sy, n-1)
print(sx, sy)
MakeTriangle(sx, sy, ux, uy, n-1)
print(ux, uy)
MakeTriangle(ux, uy, tx, ty, n-1)
print(tx, ty)
MakeTriangle(tx, ty, x2, y2, n-1)
else:
return
x1 = 0
y1 = 0
x2 = 100
y2 = 0
n = int(input())
print(x1, y1)
MakeTriangle(x1, y1, x2, y2, n)
print(x2, y2)
|
while(1):
comb = []
count =0
inp = raw_input().split(" ")
if inp[0] == "0" and inp[1] == "0":
break
for i in range(1,int(inp[0])+1):
for j in range(1,int(inp[0])+1):
if i == j:
break
sum = i + j
if sum > int(inp[1]):
j = int(inp[0])
break
for k in range(1,int(inp[0])+1):
if i == j or i == k or j == k:
break
sum = i + j + k
if sum > int(inp[1]):
k = int(inp[0])
break
if sum == int(inp[1]):
if not ([i,j,k] in comb or [i,k,j] in comb or [j,k,i] in comb or [j,i,k] in comb or [k,i,j] in comb or [k,j,i] in comb):
comb.append([i,j,k])
count += 1
print count
| 0 | null | 700,674,174,460 | 27 | 58 |
while True:
H, W = list(map(int, input().split()))
if (H == 0) & (W == 0):
break
print(W * "#")
for _ in range(H-2):
print("#", end="")
print((W-2) * ".", end="")
print("#")
print(W * "#")
print("")
|
import sys
while True:
a,b = map(int, raw_input().split())
if a ==0 and b == 0:
break
for i in range(a):
for j in range(b):
if i == 0 or i == a-1 or j == 0 or j == b-1:
sys.stdout.write("#")
else:
sys.stdout.write(".")
print
print
| 1 | 812,753,710,902 | null | 50 | 50 |
X=int(input())
for x in range(X,2*X):
for i in range(2,int(x**.5)+1):
if x%i==0:
break
else:
print(x)
break
|
H = int(input())
a = 1
an = 1
while a < H:
a *= 2
if a<=H:
an += a
else:
break
print(an)
| 0 | null | 93,003,380,634,440 | 250 | 228 |
from sys import stdin
import sys
a = stdin.readline().rstrip()
b = stdin.readline().rstrip()
count = 0
for i in range(len(a)):
if a[i] != b[i]: count = count + 1
print (count)
|
S = list(str(input()))
T = list(str(input()))
tt = 0
cnt = 0
for i in S:
if i != T[tt]:
cnt += 1
tt += 1
print(cnt)
| 1 | 10,442,777,671,534 | null | 116 | 116 |
MAX = 10**6 * 3
MOD = 10**9+7
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
#前処理 逆元テーブルを作る
def COMinit():
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i-1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD//i)%MOD
finv[i] = finv[i-1] * inv[i] % MOD
#実行
def COM(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
k = int(input())
s = input()
n = len(s)
COMinit()
ans = 0
for i in range(k+1):
pls = pow(25, i, MOD)
pls *= pow(26,k-i, MOD)
pls %= MOD
pls *= COM(i+n-1, i)
ans += pls
ans %= MOD
print(ans%MOD)
|
N, K = list(map(int, input().split(' ')))
table = {l for l in range(1, N + 1)}
have = set()
for i in range(K):
d = int(input())
nums = list(map(int, input().split(' ')))
have = have | set(nums)
ans = len(table - have)
print(ans)
| 0 | null | 18,803,208,196,762 | 124 | 154 |
N = int(input())
M = 10
ans = 0
if N % 2 == 0:
while N >= M:
ans += N//M
M *= 5
print(ans)
|
# 解説見ました。
n = int(input())
ans = 0
if n%2 == 0:
m = 1
for _ in range(25):
ans += n//(m*10)
m *= 5
print(ans)
| 1 | 115,589,138,980,118 | null | 258 | 258 |
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
d[0]=1
ans=0
for i in range(1,n+1):
a[i]+=a[i-1]-1
if i>=k:
d[a[i-k]]-=1
a[i]%=k
d[a[i]]+=1
ans+=d[a[i]]-1
print(ans)
|
s=input()
l=len(s)
l2=l//2
count=0
for i in range(l2):
if s[i]!=s[l-1-i]:
count+=1
print(count)
| 0 | null | 128,676,845,702,272 | 273 | 261 |
N=int(input());a=10;b=0
if N&1==0:
while a<=N:b+=N//a;a*=5
print(b)
|
#E
import math
n = int(input())
ans = 0
i = 1
if n % 2 == 0:
tmp = 5 ** i * 2
while tmp <= n:
tmp = 5 ** i * 2
ans += n //tmp
i += 1
print(ans)
else:
print(0)
| 1 | 116,254,481,895,130 | null | 258 | 258 |
X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = None
diff = 1000
if X not in p:
ans = X
else:
for i in range(-1, max(max(p), X)+2):
if i in p:continue
if abs(X - i) < diff:
diff = abs(X - i)
ans = i
print(ans)
|
k=int(input())
line="ACL"*k
print(line)
| 0 | null | 8,160,498,769,712 | 128 | 69 |
from math import *
def main():
n = int(input())
print(n+n**2+n**3)
main()
|
n=int(input())
N=10**4+20;M=103
a=[0 for _ in range(N)]
for x in range(1,M):
for y in range(1,M):
for z in range(1,M):
res=x*x+y*y+z*z+x*y+y*z+z*x;
if res<N:a[res]+=1
for i in range(n):
print(a[i+1])
| 0 | null | 9,097,230,498,490 | 115 | 106 |
N ,K = map(int, input().split())
lst = [i for i in range(N+1)]
rlst = [i for i in range(N,-1,-1)]
P = 10**9 + 7
rlt = 0
mini = sum(lst[:K-1])
maxi = sum(rlst[:K-1])
for i in range(N -K + 2):
mini += lst[K+i-1]
maxi += rlst[K+i-1]
rlt += maxi -mini + 1
rlt %= P
print(rlt)
|
N = int(input().rstrip())
r = (N + 1) / 2
print(int(r))
| 0 | null | 46,149,361,230,508 | 170 | 206 |
def main():
A, B = map(int,input().split())
print( A * B if (A // 10 == 0) & (B // 10 == 0) else -1)
return 0
if __name__ == '__main__':
main()
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
assert len(A) == M
# M個の宿題, それぞれAi日かかる
yasumi = N - sum(A)
if yasumi >= 0:
print(yasumi)
else:
print(-1)
| 0 | null | 94,802,506,078,642 | 286 | 168 |
print(" ".join(
list(map(str,
sorted(
list(map(int,input().split()))
)
)
)
)
)
|
a, b, c, d = map(int, input().split())
x = 0
y = 0
while c > 0:
c -= b
x += 1
while a > 0:
a -= d
y += 1
if x <= y:
print('Yes')
else:
print('No')
| 0 | null | 15,144,042,925,000 | 40 | 164 |
def main(A,B,C,K):
ans=False
while K >= 0:
if A < B:
if B < C:
ans=True
return ans
else:
C = C * 2
else:
B = B * 2
K=K-1
return ans
A,B,C=map(int, input().split())
K=int(input())
ans=main(A,B,C,K)
print('Yes' if ans else 'No')
|
import itertools
a, b, c = map(int, input().split(" "))
k = int(input())
f = False
for conb in list(itertools.combinations_with_replacement([0, 1, 2], k)):
a_i = conb.count(0)
b_i = conb.count(1)
c_i = conb.count(2)
if (a * (2 ** a_i) < b * (2 **b_i)) and (b * (2 ** b_i) < c * (2 ** c_i)):
f = True
if f:
print("Yes")
else:
print("No")
| 1 | 6,808,896,602,910 | null | 101 | 101 |
import math
a = int(input())
print(a + ( a ** 2) + ( a ** 3))
|
from collections import *
N=int(input())
S=input()
c=Counter(S)
ans=c['R']*c['G']*c['B']
for i in range(1,N//2+1):
for j in range(i,N-i):
if S[j-i]!=S[j] and S[j]!=S[j+i] and S[j+i]!=S[j-i]:
ans-=1
print(ans)
| 0 | null | 23,182,854,278,854 | 115 | 175 |
s = "#."
while True:
H,W= map(int, input().split())
if H==0 and W==0:
break
elif W%2==0 :
w1=s*(W//2)
w2="."+s*(W//2-1)+"#"
elif W%2==1:
w1=s*((W-1)//2)+"#"
w2="."+s*((W-1)//2)
for i in range(H):
if i%2==0:
print(w1)
elif i%2==1:
print(w2)
print("")
|
import sys
for l in sys.stdin:
H, W = map(int,l.split())
if H == 0 and W == 0:
break
for i,h in enumerate(range(H)):
if i % 2 == 0:
print (('#.' * (int(W/2)+1))[:W])
else:
print(('.#' * (int(W/2)+1))[:W])
print ('')
| 1 | 861,429,634,048 | null | 51 | 51 |
#!/usr/bin/env python3
import sys
import numpy as np
input = sys.stdin.readline
def ST():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(MI())
S = ST()
cnt = np.zeros(2019)
cnt[0] = 1
res = 0
tmp = 1
for s in S[::-1]:
res += int(s) * tmp
res %= 2019
cnt[res] += 1
tmp *= 10
tmp %= 2019
ans = 0
for c in cnt[cnt >= 2]:
ans += c * (c - 1) // 2
print(int(ans))
|
s=input()
n=len(s)
a=0
t=1
d=[1]+[0]*2018
for i in range(n):
a+=int(s[n-1-i])*t
a%=2019
t*=10
t%=2019
d[a]+=1
ans=0
for i in d:
ans+=i*(i-1)//2
print(ans)
| 1 | 31,003,254,007,180 | null | 166 | 166 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.