code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
N, M =map(int,input().split())
A = list(map(int, input().split()))
# x = 宿題をする日の合計
x = sum(A)
if N >= x:
print(N - x)
else:
print("-1")
|
#16D8101023J 久保田凌弥 kubotarouxxx python3
x,y=map(int, input().split())
if x>y:
while 1:
if (x%y)==0:
print(y)
break
a=x%y
x=y
y=a
else:
while 1:
if (y%x)==0:
print(x)
break
a=y%x
y=x
x=a
| 0 | null | 15,998,811,227,082 | 168 | 11 |
import numpy as np
A, B = map(int, input().split())
print(np.lcm(A, B))
|
import sys
d = -float('inf')
n = int(input())
l = int(input())
for s in sys.stdin:
r = int(s)
d = max(d, r-l)
l = min(l, r)
print(d)
| 0 | null | 56,931,123,811,970 | 256 | 13 |
def is_p(s):
return s == s[::-1]
s = input()
l = (len(s) - 1)//2
r = l + 1
print('Yes' if is_p(s) and is_p(s[:l]) and is_p(s[r:]) else 'No')
|
n=int(input())
a=list(map(int,input().split()))
sum_a=sum(a)
x=0
i=0
while x<sum_a/2:
x+=a[i]
i+=1
if n%2==0:
print(min(x-(sum_a-x),sum_a-(x-a[i-1])*2))
else:
print(x-(sum_a-x))
| 0 | null | 94,494,564,686,698 | 190 | 276 |
def solve():
X = int(input())
p = int(X / 100)
q = X % 100
if 0 <= q <= 5 * p:
print(1)
else:
print(0)
if __name__ == "__main__":
solve()
|
X = int(input())
for i in range(105, 100, -1):
while True:
if X % 100 < (X-i) % 100:
break
else:
X = X-i
if X < 0: X = 1
print(1 if X % 100 == 0 else 0)
| 1 | 127,592,506,848,290 | null | 266 | 266 |
# 7
from collections import Counter
import collections
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()
INF = float('inf')
n = I()
d = LI()
mod = 998244353
if d[0] != 0:
print(0)
exit(0)
# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
counts = [0] * (max(d)+1)
for k, v in c.items():
counts[k] = v
if counts[0] > 1:
print(0)
exit(0)
ans = 1
for i in range(1, len(counts)):
ans *= pow(counts[i-1], counts[i])
ans %= mod
print(ans)
|
from 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 = INT()
d = LIST()
mod = 998244353
if d[0] != 0:
print(0)
exit()
c = Counter(d)
counts = [0]*(max(d)+1)
for k, v in c.items():
counts[k] = v
if counts[0] > 1:
print(0)
exit()
ans = 1
for i in range(1, len(counts)):
ans *= pow(counts[i-1], counts[i])
ans %= mod
print(ans)
| 1 | 154,612,684,559,830 | null | 284 | 284 |
X = int(input())
Y = X % 500
answer = (X // 500 * 1000 + Y // 5 * 5)
print(answer)
|
n, k = [int(i) for i in input().split()]
h = sorted([int(i) for i in input().split()])
if k > len(h):
print(0)
elif k == 0:
print(sum(h))
else:
print(sum(h[0:-k]))
| 0 | null | 60,756,475,480,340 | 185 | 227 |
n = int(input())
p = [1,1]
if n <= 1:
print (1)
exit (0)
for i in range(2,n+1):
p.append(p[i-2] + p[i-1])
print (p[n])
|
from sys import stdin
import numpy as np
n, k = map(int, stdin.buffer.readline().split())
a = np.fromstring(stdin.buffer.read(), dtype=np.int, sep=' ')
ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
mid = (ok + ng) >> 1
if np.sum(np.ceil(a / mid) - 1) <= k:
ok = mid
else:
ng = mid
print(ok)
| 0 | null | 3,226,434,340,908 | 7 | 99 |
MOD = 10**9 + 7
def main():
import sys
input = sys.stdin.buffer.readline
_ = int(input())
A = [int(i) for i in input().split()]
def gcd(x, y):
if y == 0:
return x
while y != 0:
x, y = y, x % y
return x
def lcm(x, y):
return x*y//gcd(x, y)
L = A[0]
for a in A[1:]:
L = lcm(L, a)
L %= MOD
ans = 0
for a in A:
ans += L*pow(a, MOD-2, MOD)
print(ans % MOD)
if __name__ == '__main__':
main()
|
import sys
import math
import fractions
from collections import defaultdict
from functools import reduce
import collections
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
INF=10**18
mod=10**9+7
N=int(input())
A=nl()
NMAX=10**6
class Sieve:
def __init__(self,n):
self.n=n
self.f=[0]*(n+1)
self.prime=[]
self.f[0]=self.f[1]=-1
for i in range(2,n+1):
if(self.f[i]):
continue
else:
self.prime.append(i)
self.f[i]=i
for j in range(i*i,n+1,i):
if(~self.f[j]):
self.f[j]=i
def isProme(self,x):
return (self.f[x]==x)
def factorList(self,x):
res=[]
while(x!=1):
res.append(self.f[x])
x//=self.f[x]
return res
def factor(self,x):
fl=self.factorList(x)
return collections.Counter(fl)
def get_sieve_of_eratosthenes(n):
prime = [2]
limit = int(n**0.5)
data = [i + 1 for i in range(2, n, 2)]
while True:
p = data[0]
if limit <= p:
return prime + data
prime.append(p)
data = [e for e in data if e % p != 0]
sieve=Sieve(10**6)
mp=defaultdict(int)
for i in range(N):
f=sieve.factor(A[i])
for key,val in f.items():
mp[key]=max(val,mp[key])
lcm=1
for key,val in mp.items():
lcm*=(key**val)
ans=0
for i in range(N):
ans+=lcm//A[i]
print(ans%mod)
| 1 | 88,179,719,612,920 | null | 235 | 235 |
def print8f(xy):
from decimal import Decimal, ROUND_HALF_UP
acc = Decimal("0.00000001")
x, y = xy
x = Decimal(str(x)).quantize(acc, rounding=ROUND_HALF_UP)
y = Decimal(str(y)).quantize(acc, rounding=ROUND_HALF_UP)
print("{:.8f} {:.8f}".format(x, y))
def kochCurve(p1p2, n, ang):
from math import sin, cos, radians, sqrt
if n == 0:
print8f(p1p2[1])
return
p1, p2 = p1p2
xd3 = (p2[0] - p1[0]) / 3
yd3 = (p2[1] - p1[1]) / 3
s = [p1[0] + xd3, p1[1] + yd3]
t = [p2[0] - xd3, p2[1] - yd3]
st = sqrt((s[0] - t[0])**2 + (s[1] - t[1])**2)
u = [s[0] + cos(radians(ang + 60)) * st,
s[1] + sin(radians(ang + 60)) * st]
kochCurve([p1, s], n - 1, ang)
kochCurve([s, u], n - 1, ang + 60)
kochCurve([u, t], n - 1, ang - 60)
kochCurve([t, p2], n - 1, ang)
def resolve():
n = int(input())
p1p2 = [[0, 0], [100, 0]]
print8f(p1p2[0])
kochCurve(p1p2, n, 0)
resolve()
|
n = int(input())
def three_points(p1,p2):
q1 = ((2*p1[0]+p2[0])/3, (2*p1[1]+p2[1])/3)
q2 = ((p1[0]+2*p2[0])/3, (p1[1]+2*p2[1])/3)
dx,dy = p2[0]-p1[0], p2[1]-p1[1]
q3 = (p1[0]+dx/2-3**0.5/6*dy, p1[1]+dy/2+3**0.5/6*dx)
return [q1,q3,q2]
m = [(0,0),(100,0)]
for i in range(n):
tmpm = []
for j in range(len(m)-1):
tmpm += [m[j]] + three_points(m[j],m[j+1])
tmpm += [m[-1]]
m = tmpm
for x in m:
print(x[0], x[1])
| 1 | 124,685,253,522 | null | 27 | 27 |
n,m=map(int,input().split())
a =list(map(int,input().split()))
day = 0
for i in range(m):
day += a[i]
print(-1 if day>n else n - day)
|
n,k=map(int,input().split(' '))
l=list(map(int, input().split(' ')))
l=sorted(l)
print(sum(l[:max(n-k,0)]))
| 0 | null | 55,627,247,118,116 | 168 | 227 |
n=int(input())
cnt=0
ans=0
for i in range(1,n+1):
cnt+=1
if i%2==1:
ans+=1
print(ans/cnt)
|
N=int(input())
if N%2==0:
print('{:.10f}'.format(0.5))
else:
print('{:.10f}'.format((N+1)/(2*N)))
| 1 | 176,450,314,277,330 | null | 297 | 297 |
n, m, x = list(map(int, input().split()))
books = []
for _ in range(n):
books.append(list(map(int, input().split())))
# 参考書の組み合わせ
price_min = pow(10, 6) * n
found = False
for bits in range(2 ** n):
level = [0] * m
price = 0
# ビットが立っている参考書の理解度と値段を加算
for book in range(n):
if (bits >> book) & 1:
price += books[book][0]
for alg in range(m):
level[alg] += books[book][alg + 1]
# 理解度がXに満たないアルゴリズムを抽出
level = list(filter(lambda lv: lv < x, level))
# 理解度の条件を満たし、かつ合計額が最低値を下回るときに最低値を更新
if len(level) == 0 and price < price_min:
found = True
price_min = price
print(price_min if found else "-1")
|
import numpy as np
N, M, X = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(N)]
cost = float("inf")
for i in range(2**N):
tmp = np.array([0 for _ in range(M+1)])
for j in range(N):
if (i>>j) & 1:
tmp += np.array(C[j])
if min(tmp[1:]) >= X:
cost = min(cost, tmp[0])
print(-1 if cost == float("inf") else cost)
| 1 | 22,232,889,548,188 | null | 149 | 149 |
n= int(raw_input())
print float((n/2) + 1)/n if n % 2 else 0.5
|
a = int(input())
print(1 / 2 if a % 2 == 0 else (a + 1) / (2 * a))
| 1 | 177,492,860,631,460 | null | 297 | 297 |
N, K, S = map(int, input().split())
S2 = S-1 if S == 1000000000 else S+1
As = [S]*K+[S2]*(N-K)
print(" ".join(map(str, As)))
|
n, k, s = map(int, input().split())
ans = []
if s == 10 ** 9:
ans = [1] * n
else:
ans = [10 ** 9] * n
for i in range(k):
ans[i] = s
for i in ans:
print(i)
| 1 | 90,865,029,371,270 | null | 238 | 238 |
from collections import deque
n, d, a = map(int, input().split())
mons = []
for i in range(n):
x, h = map(int, input().split())
mons.append((x, h))
mons = sorted(mons)
q = deque()
dm_sum = 0
ans = 0
for i in range(n):
while dm_sum > 0:
if q[0][0] < mons[i][0]:
cur = q.popleft()
dm_sum -= cur[1]
else:
break
if mons[i][1] <= dm_sum:
continue
rem = mons[i][1] - dm_sum
at_num = rem // a
if rem % a != 0:
at_num += 1
ans += at_num
q.append((mons[i][0] + 2 * d, at_num*a))
dm_sum += at_num*a
print(ans)
|
n,k=map(int,input().split())
ans=n%k
if ans>k//2:
print(abs(ans-k))
elif ans<=k//2:
print(ans)
| 0 | null | 60,827,341,479,960 | 230 | 180 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))
def main():
n, m, l = map(int, input().split())
d = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(n):
d[i][i] = 0
for _ in range(m):
a, b, c = map(int, input().split())
d[a-1][b-1] = c
d[b-1][a-1] = c
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][j] > d[i][k] + d[k][j]:
d[i][j] = d[i][k] + d[k][j]
dl = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(n):
d[i][i] = 0
for i in range(n):
for j in range(i+1, n):
if i != j and d[i][j] <= l:
dl[i][j] = 1
dl[j][i] = 1
for k in range(n):
for i in range(n):
for j in range(n):
if dl[i][j] > dl[i][k] + dl[k][j]:
dl[i][j] = dl[i][k] + dl[k][j]
q = int(input())
for _ in range(q):
s, t = map(int, input().split())
if dl[s-1][t-1] == float("inf"):
print(-1)
else:
print(dl[s-1][t-1] - 1)
if __name__ == '__main__':
main()
|
import sys
input = sys.stdin.readline
r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]
for i in range(k):
rr, cc, vv = map(int, input().split())
rr, cc = rr - 1, cc - 1
v[rr][cc] = vv
dp = [[0 for _ in range(c + 1)] for _ in range(4)]
for y in range(r):
tmp = [[0 for _ in range(c + 1)] for _ in range(4)]
for x in range(c):
for i in range(2, -1, -1):
dp[i + 1][x] = max(dp[i + 1][x], dp[i][x] + v[y][x])
for i in range(4):
tmp[0][x] = max(tmp[0][x], dp[i][x])
dp[i][x + 1] = max(dp[i][x + 1], dp[i][x])
dp = tmp
print(dp[0][c - 1])
| 0 | null | 89,342,613,386,950 | 295 | 94 |
mod=998244353
n,k=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(k)]
DP=[0 for _ in range(n+1)]
SDP=[0 for _ in range(n+1)]
DP[1]=1
SDP[1]=1
for i in range(2,n+1):
for l,r in LR:
DP[i] +=(SDP[max(i-l,0)]-SDP[max(i-r,1)-1])%mod
DP[i] %=mod
SDP[i]=(SDP[i-1]+DP[i])%mod
print(DP[n])
|
n = int(input())
count = 0
for i in range(n):
a,b = map(int,input().split())
if count >2 :
break
elif a==b:
count += 1
else:
count = 0
print('Yes' if count > 2 else 'No')
| 0 | null | 2,616,831,083,584 | 74 | 72 |
S = int(input())
if S < 3:
print(0)
import sys
sys.exit()
DP = [0]*(S+1)
DP[0] = 0
DP[1] = 0
DP[2] = 0
for i in range(3, S + 1):
DP[i] += 1
for j in range(i - 3 + 1):
DP[i] += DP[j]
print(DP[S] % (10 ** 9 + 7))
|
def mod_comb_k(n, k, p):
"""二項係数 0(1)
Args:
n (int): 添字
k (int): 添字
p (int): 除数
Returns:
int: nCk mod p
"""
if n < k or n < 0 or k < 0:
return 0
else:
return fact[n] * fact_inv[k] * fact_inv[n-k] % p
def com_init(n, p):
"""二項係数の計算の前処理 O(N)
Args:
n (int): 上限値
p (int): 除数
"""
for i in range(n):
fact.append(fact[-1] * (i+1) % p)
fact_inv[-1] = pow(fact[-1], p-2, p)
for i in range(n-1, -1, -1):
fact_inv[i] = fact_inv[i+1] * (i+1) % p
s = int(input())
mod = 10 ** 9 + 7
fact = [1]
fact_inv = [0] * (s+1)
com_init(s, mod)
res = 0
for i in range(1, s//3+1):
res = (res + mod_comb_k(s-i*2-1, i-1, mod)) % mod
print(res)
| 1 | 3,279,583,776,128 | null | 79 | 79 |
s = input()
n = len(s)
L=[0]
R=[0]
cnt = 0
for i in range(n):
if s[i] == '<':
cnt += 1
else:
cnt = 0
L.append(cnt)
cnt = 0
s = s[::-1]
for i in range(n):
if s[i] == '>':
cnt += 1
else:
cnt = 0
R.append(cnt)
R = R[::-1]
ans = 0
for i in range(n+1):
ans += max(R[i], L[i])
print(ans)
|
def main():
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
if A[i] % 2 == 0 and (A[i] % 3 != 0 and A[i] % 5 != 0):
return "DENIED"
return "APPROVED"
if __name__ == '__main__':
print(main())
| 0 | null | 112,667,041,985,120 | 285 | 217 |
from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split()]
mapping = defaultdict(int)
for _a, i in zip(range(2, n + 1), a):
mapping[i] += 1
for i in range(1, n + 1):
print(mapping[i])
|
import collections
n = int(input())
x = list(map(int, input().split()))
y = collections.Counter(x)
for i in range(1, len(x)+2):
print(y[i], end = "\n")
| 1 | 32,743,231,064,160 | null | 169 | 169 |
str = input()
n = int(input())
for i in range(n):
args = input().split()
command = args[0]
s = int(args[1])
e = int(args[2])
if command == 'print':
print(str[s:e + 1])
if command == 'reverse':
str = str[0:s] + str[s:e + 1][::-1] + str[e + 1:]
if command == 'replace':
str = str[0:s] + args[3] + str[e + 1:]
|
s = input()
n = int(input())
for i in range(n):
order, a, b, *c = input().split()
a = int(a)
b = int(b)
if order == 'replace':
s = s[:a] + c[0] + s[b+1:]
elif order[0] == 'r':
s = s[:a] + s[::-1][len(s)-b-1:len(s)-a]+ s[b+1:]
else:
print(s[a:b+1])
| 1 | 2,090,034,667,710 | null | 68 | 68 |
even,odd = map(int, input().split())
print(int(even * (even-1)/2 + odd * (odd-1)/2))
|
n,m = map(int,input().split())
ans = 0
for i in range(n-1):
ans = ans + i+1
for b in range(m-1):
ans = ans + b+1
print(ans)
| 1 | 45,287,164,192,348 | null | 189 | 189 |
A, B, M = map(int, input().split())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
ans = min(an)+min(bn)
for i in range(M):
x, y, c = map(int, input().split())
ans = min(ans, an[x-1] + bn[y-1] - c)
print(ans)
|
n, m = input().split()
n = int(n)
m = int(m)
c=0
a = list(map(int, input().split()))
for i in range(n):
c += a[i]
v = c/(4*m)
a.sort(reverse = True)
if a[m-1] < v:
print('No')
else:
print('Yes')
| 0 | null | 46,549,965,765,660 | 200 | 179 |
s=input()*3
if s.find(input()) == -1 :
print('No')
else:
print('Yes')
|
def search(pat, s):
"""find a pattern 'pat' in a ring shaped text 's'
len(s) >= len(p) and both s and p consists of lowercase characters.
>>> search('a', 'a')
True
>>> search('advance', 'vanceknowledgetoad')
True
>>> search('advanced', 'vanceknowledgetoad')
False
"""
return pat in s + s
def run():
s1 = input()
s2 = input()
if search(s2, s1):
print("Yes")
else:
print("No")
if __name__ == '__main__':
run()
| 1 | 1,746,925,106,212 | null | 64 | 64 |
MOD=10**9+7
def facinv(N):
fac,finv,inv=[0]*(N+1),[0]*(N+1),[0]*(N+1)#階乗テーブル、逆元テーブル、逆元
fac[0]=1;fac[1]=1;finv[0]=1;finv[1]=1;inv[1]=1
for i in range(2,N+1):
fac[i]=fac[i-1]*i%MOD
inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i]=finv[i-1]*inv[i]%MOD
return fac,finv,inv
def COM(n,r):
if n<r or r<0:
return 0
else:
return ((fac[n]*finv[r])%MOD*finv[n-r])%MOD
n,k=map(int,input().split())
fac,finv,inv=facinv(2*n)
if k>=n-1:
print(COM(2*n-1,n-1))
else:
ans=COM(2*n-1,n-1)
for i in range(1,n-k):
ans=(ans-COM(n,i)*COM(n-1,i-1)%MOD+MOD)%MOD
print(ans%MOD)
|
def main():
n,k = map(int, input().split())
MOD = 10**9+7
# 0人部屋が0~k個の時の場合の数の和
# Σ(i=[0,k]){comb(n,i)*pow((n-i),i)} を求めれば良い
# しかし上式ではpowの計算量がデカすぎるので、捉え方を変えて下式まで変形
# Σ(i=[0,k]){comb(n,i)*comb((n-1),i)} を求めれば良い
# 注:i=0のとき、つまり0人部屋がない、つまり全部屋に1人ずつ、のケースは1通り
# comb(n,i+1) = comb(n,i) * (n-i)/(i+1) であることを利用する
ans = 0
k1 = 1
k2 = 1
for i in range(min(k+1,n)):
ans += k1*k2
ans %= MOD
k1 *= (n-i)*pow(i+1,MOD-2,MOD)
k1 %= MOD
k2 *= (n-1-i)*pow(i+1,MOD-2,MOD)
k2 %= MOD
print(int(ans))
main()
| 1 | 67,221,587,508,640 | null | 215 | 215 |
n=int(input())
a=[]
b=[]
for i in range(n):
x,y=map(int,input().split())
a.append(x+y)
b.append(x-y)
a=sorted(a)
b=sorted(b)
ans=max(a[-1]-a[0],b[-1]-b[0])
print(ans)
|
def check(p, k, arr):
subtotal = 0
num_of_tracks = 1
for a in arr:
subtotal += a
if subtotal > p:
num_of_tracks += 1
if num_of_tracks > k: return False
subtotal = a
return True
n, k = map(int, input().split())
arr = [int(input()) for i in range(n)]
min_p = max(arr)
max_p = sum(arr)
while min_p < max_p:
mid_p = (min_p + max_p) // 2
if check(mid_p, k, arr):
max_p = mid_p
else:
min_p = mid_p + 1
print(min_p)
| 0 | null | 1,736,790,917,092 | 80 | 24 |
N = int(input())
st = []
for _ in range(N):
s,t = map(str,input().split())
st.append((s,int(t)))
X = input()
ans = 0
flag = False
for s,t in st:
if flag:
ans += t
if s == X:
flag = True
print(ans)
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M, L = lr()
INF = 10 ** 19
dis = [[INF for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
a, b, c = lr()
if c > L:
continue
dis[a][b] = c
dis[b][a] = c
for k in range(N+1): # kが中継地点
for i in range(N+1):
for j in range(i+1, N+1):
x = dis[i][k] + dis[k][j]
if x < dis[i][j]:
dis[i][j] = dis[j][i] = x
supply = [[INF] * (N+1) for _ in range(N+1)]
for i in range(N+1):
for j in range(i+1, N+1):
if dis[i][j] <= L:
supply[i][j] = supply[j][i] = 1
for k in range(N+1): # kが中継地点
for i in range(N+1):
for j in range(i+1, N+1):
y = supply[i][k] + supply[k][j]
if y < supply[i][j]:
supply[i][j] = supply[j][i] = y
Q = ir()
for _ in range(Q):
s, t = lr()
if supply[s][t] == INF:
print(-1)
else:
print(supply[s][t] - 1)
# 59
| 0 | null | 135,593,608,532,180 | 243 | 295 |
def main():
h,w = map(int,input().split(" "))
s = [list(input()) for i in range(h)]
dp = [[0]*w for i in range(h)]
dp[0][0] = 1 if s[0][0]=="#" else 0
for i in range(1,h):
sgmdown = 1 if s[i][0]=="#" and s[i-1][0]=="." else 0
dp[i][0] = dp[i-1][0] + sgmdown
for j in range(1,w):
sgmright = 1 if s[0][j]=="#" and s[0][j-1]=="." else 0
dp[0][j] = dp[0][j-1] + sgmright
for i in range(1,h):
for j in range(1,w):
sgmdown = 1 if s[i][j]=="#" and s[i-1][j]=="." else 0
sgmright = 1 if s[i][j]=="#" and s[i][j-1]=="." else 0
dp[i][j] = min(dp[i-1][j]+sgmdown, dp[i][j-1]+sgmright)
print(dp[h-1][w-1])
main()
|
N,M=map(int, input().split())
S=list(input())
T=S[::-1]
D=[0]*N
if N<=M:
print(N)
exit()
renzoku,ma=0,0
for i in range(1,N+1):
if S[i]=='1':
renzoku+=1
else:
ma=max(ma,renzoku)
renzoku=0
if ma>=M:
print(-1)
exit()
r=0
for i in range(1,M+1):
if T[i]!='1':
r=i
ans=[r]
while r+M<N:
for i in range(M,0,-1):
if T[r+i]=='0':
ans.append(i)
r+=i
break
ans.append(N-r)
print(*ans[::-1])
| 0 | null | 94,340,411,911,382 | 194 | 274 |
N = int(input().rstrip())
flag = False
for i in range(1,10):
for j in range(1,10):
if N == i * j:
flag = True
break
else:
continue
break
print('Yes' if flag else 'No')
|
def solve(a):
for i in range(1, 10):
if a % i == 0 and 1 <= a // i <= 9:
return "Yes"
return "No"
print(solve(int(input())))
| 1 | 159,614,221,639,840 | null | 287 | 287 |
def main():
mod = pow(10, 9)+7
k = int(input())
s = input()
n = len(s)
ans = 0
key = pow(26, k, mod)
sub = 1
c = 1
for i in range(k+1):
ans += key*sub*c
ans %= mod
sub *= 25
sub %= mod
key = key*pow(26, mod-2, mod)%mod
c *= (n+i)
c *= pow(i+1, mod-2, mod)
c %= mod
print(ans)
if __name__ == "__main__":
main()
|
mod = 10**9 + 7
K = int(input())
S = input()
n = len(S)
tmp = pow(26, K, mod)
waru = pow(26, -1, mod)
ans = tmp
for i in range(1, K+1):
tmp = (tmp * 25 * waru)%mod
tmp = (tmp * (i + n -1) * pow(i, -1, mod))%mod
ans = (ans+tmp)%mod
print(ans%mod)
| 1 | 12,878,020,881,400 | null | 124 | 124 |
while True:
H, W = list(map(int, input().split()))
if H == 0 and W == 0:
break
for height in range(H):
if height%2 == 0:
flag = True
else:
flag = False
for wide in range(W):
if flag:
print('#', end='')
else:
print('.', end='')
flag = not(flag)
print('')
print('')
|
#coding:UTF-8
while True:
h,w = map(int,raw_input().split())
if h == 0 and w == 0:
break
for i in range(h):
if i%2 == 1:
if w % 2 == 0:
print ".#" * (w / 2)
else:
print ".#" * (w / 2) + "."
else:
if w % 2 == 0:
print "#." * (w/2)
else:
print "#." * (w/2) + "#"
print ""
| 1 | 856,641,235,520 | null | 51 | 51 |
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())
lst = [int(i) for i in input().split()]
min_n = min(lst)
max_n = max(lst)
min_count = 1000000000
for i in range(min_n, max_n + 1):
count = 0
for j in range(n):
count += (lst[j] - i) ** 2
if count < min_count:
min_count = count
print(min_count)
| 1 | 64,990,746,565,734 | null | 213 | 213 |
n,k = map(int,input().split())
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, n + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
ans = 0
#con = cmb(n,k,mod)
#print(con)
for i in range(min(k+1,n+1)):
ans += cmb(n,i,mod)*cmb(n-1,i,mod)
ans %= mod
print(ans)
|
input()
a = list(map(int, input().split()))
print(min(a),max(a),sum(a))
| 0 | null | 33,867,035,231,262 | 215 | 48 |
N = int(input())
ST = [list(map(str, input().split())) for _ in range(N)]
X = str(input())
ans = 0
flag = False
for s, t in ST:
if flag:
ans += int(t)
else:
if s == X:
flag = True
print (ans)
|
n=int(input())
box1=[]
box2=[]
for i in range(n):
i=input().rstrip().split(" ")
box1.append(i[0])
box2.append(int(i[1]))
num=box1.index(input())
del box2[:num+1]
print(sum(box2))
| 1 | 96,556,586,015,850 | null | 243 | 243 |
# -*- coding: utf-8 -*-
def main():
dictionary = {}
input_num = int(raw_input())
counter = 0
while counter < input_num:
command, key = raw_input().split(' ')
if command == 'insert':
dictionary[key] = True
else:
if key in dictionary:
print 'yes'
else:
print 'no'
counter += 1
if __name__ == '__main__':
main()
|
def main():
N = int(input())
print((N-1)//2)
if __name__ == '__main__':
main()
| 0 | null | 76,404,778,213,870 | 23 | 283 |
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
# c.append(i)
#e1,e2,e3 = map(int,input().split())
#K = input()
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
now=1000
buy=0
sell=0
kabu=0
for i in range(a-1):
if f[i]<f[i+1]:
if now>=f[i]:
buy=now//f[i]
now=now-buy*f[i]
kabu=buy
buy=0
if f[i]>f[i+1] :
if kabu>=1:
sell=kabu
now=now+sell*f[i]
kabu=0
sell=0
if f[i]==f[i+1]:
continue
now = now+f[-1]*kabu
print(now)
|
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
sl = []
flag = False
for i in range(h):
for j in range(w):
if s[i][j] == '.':
sl.append([i, j])
q = deque()
dire = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = 0
for sh, sw in sl:
c = [[0]*w for _ in range(h)]
q.append((sh, sw, 0))
while q:
ph, pw, k = q.pop()
if c[ph][pw] == 0:
ans = max(ans, k)
c[ph][pw] = 1
for dh, dw in dire:
hdh, wdw = ph+dh, pw+dw
if 0 <= hdh < h and 0 <= wdw < w and c[hdh][wdw] == 0:
if s[hdh][wdw] == '.':
q.appendleft((hdh, wdw, k+1))
print(ans)
| 0 | null | 51,110,900,931,672 | 103 | 241 |
def max(a):
max = -10000000
for i in a:
if max < i:
max = i
return max
def min(a):
min = 10000000
for i in a:
if min > i:
min = i
return min
def sum(a):
sum = 0
for i in a:
sum += i
return sum
input()
a = list(map(int, input().split()))
print(min(a), max(a), sum(a))
|
from itertools import permutations
from math import sqrt, pow, factorial
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
def calc(a,b):
[x1, y1] = a
[x2, y2] = b
return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
sum = 0
for i in permutations(range(n)):
distance = 0
for j in range(1, n):
distance = calc(xy[i[j]], xy[i[j-1]])
sum += distance
print(sum/factorial(n))
| 0 | null | 74,897,701,667,360 | 48 | 280 |
_, s, _, t = [[*map(int, o.split())] for o in open(0)]
print(sum(i in s for i in t))
|
a, b = map(int, input().split())
def get_GCD(x, y):
if x > y:
x, y = y, x
y_ = y
while True:
if y % x == 0:
break
else:
y += y_
return y
print(get_GCD(a, b))
| 0 | null | 56,712,971,151,452 | 22 | 256 |
n = int(input())
a = list(map(int, input().split()))
cnt = 0
ave = sum(a)/2
for i in range(n):
cnt += a[i]
if cnt >= ave:
ans = min(cnt*2-ave*2, ave*2-(cnt-a[i])*2)
break
print(int(ans))
|
n, m = map(int, input().split())
a = map(int, input().split())
res = n - sum(a)
if res < 0:
print(-1)
else:
print(res)
| 0 | null | 87,152,376,403,720 | 276 | 168 |
import sys
n = int( sys.stdin.readline() )
cards = { 'S': [ False ] * 13, 'H': [ False ] * 13, 'C': [ False ] * 13, 'D': [ False ] * 13 }
for i in range( n ):
pattern, num = sys.stdin.readline().split( " " )
if "S" == pattern:
cards[ 'S' ][ int( num )-1 ] = True
elif "H" == pattern:
cards[ 'H' ][ int( num )-1 ] = True
elif "C" == pattern:
cards[ 'C' ][ int( num )-1 ] = True
elif "D" == pattern:
cards[ 'D' ][ int( num )-1 ] = True
for pattern in ( 'S', 'H', 'C', 'D' ):
for i in range( 13 ):
if not cards[ pattern ][ i ]:
print( "{:s} {:d}".format( pattern, i+1 ) )
|
while 1:
string = raw_input()
if string == "-":
break
l = len(string)
for i in xrange(int(input())):
h = int(input())
lower = string[0:h]
upper = string[h:l]
string = upper + lower
print string
| 0 | null | 1,457,797,729,380 | 54 | 66 |
N, A, B = map(int, input().split())
d = B-A
if d%2 == 1:
d = min((B + (N-B)*2 + 1) - A, B - (A - (A-1)*2 - 1))
ans = d//2
print(ans)
|
# Function for calc
def match(n, a, b):
if (b - a)% 2 == 0:
print((b-a)/2)
else:
if (n - b) >= a:
print((a)+((b-(a+1))/2))
else:
x=(n-b+1)
print(x+((n-(a+x))/2))
# Run match
in_string = raw_input()
[N, A, B] = [int(v) for v in in_string.split()]
match(N, A, B)
| 1 | 109,709,348,635,768 | null | 253 | 253 |
A,B = map(int,input().split())
print([A-2*B,0][A<=2*B])
|
a,b=(int(x) for x in input().split())
if(a-2*b<0):
print(0)
else:
print(a-2*b)
| 1 | 166,026,227,211,702 | null | 291 | 291 |
import sys
n = int(input())
SENTINEL = 10000000000
COMPAR = 0
A = list(map(int, sys.stdin.readline().split()))
def merge(A, left, mid, right):
global COMPAR
n1 = mid - left
n2 = right - mid
L = A[left:mid]
R = A[mid:right]
L.append(SENTINEL)
R.append(SENTINEL)
j = 0
i = 0
for k in range(left, right):
COMPAR += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
merge_sort(A, 0, n)
print(' '.join(map(str, A)))
print(COMPAR)
|
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja
import sys
input = sys.stdin.readline
N = int(input())
G = [[a-1 for a in list(map(int, input().split()))[2:]] for _ in [0]*N]
visited = [0]*N
history = [[] for _ in [0]*N]
k = 0
def dfs(v=0, p=-1):
global k
visited[v] = 1
k += 1
history[v].append(k)
for u in G[v]:
if u == p or visited[u]:
continue
dfs(u, v)
k += 1
history[v].append(k)
for i in range(N):
if not visited[i]:
dfs(i)
for i, h in enumerate(history):
print(i+1, *h)
| 0 | null | 59,922,904,932 | 26 | 8 |
import collections
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
H, W, *S = open(0).read().split()
H, W = [int(_) for _ in [H, W]]
A = []
B = []
C = []
for i in range(H * W):
x, y = divmod(i, W)
if S[x][y] == '.':
for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
nx, ny = x + dx, y + dy
if not (0 <= nx < H and 0 <= ny < W):
continue
if S[nx][ny] == '.':
A += [i]
B += [nx * W + ny]
C += [1]
F = floyd_warshall(csr_matrix((C, (A, B)), shape=(H*W, H*W)))
print(int(np.max(F[F!=np.inf])))
|
def MI(): return map(int, input().split())
from collections import deque
def bfs(field,s):
q=deque([(0,s)])
dist=[[-1]*W for _ in range(H)]
d,i,j=-1,-1,-1
MOVE=[(-1,0),(0,-1),(1,0),(0,1)]
while q:
d,(i,j)=q.popleft()
if dist[i][j]!=-1:
continue
dist[i][j]=d
for di,dj in MOVE:
ni,nj=i+di,j+dj
if not 0<=ni<H or not 0<=nj<W:
continue
if field[ni][nj]=='#':
continue
if dist[ni][nj]!=-1:
continue
q.append((d+1,(ni,nj)))
return d,i,j
H,W=MI()
field=[input() for _ in range(H)]
ans=0
for i in range(H):
for j in range(W):
if field[i][j]=='.':
d,i,j=bfs(field,(i,j))
ans=max(ans,d)
print(ans)
| 1 | 94,150,423,093,870 | null | 241 | 241 |
x=input().split()
K=int(x[0])
X=int(x[1])
if 500*K>=X:
print('Yes')
else:
print('No')
|
import numpy as np
def convolve(A, B):
# 畳み込み # 要素は整数
# 3 つ以上の場合は一度にやった方がいい
dtype = np.int64
fft, ifft = np.fft.rfft, np.fft.irfft
a, b = len(A), len(B)
if a == b == 1:
return np.array([A[0]*B[0]])
n = a+b-1 # 返り値のリストの長さ
k = 1 << (n-1).bit_length()
AB = np.zeros((2, k), dtype=dtype)
AB[0, :a] = A
AB[1, :b] = B
return np.rint(ifft(fft(AB[0]) * fft(AB[1]))).astype(np.int64)[:n]
import sys
input = sys.stdin.readline
n,m = map(int, input().split())
a = list(map(int, input().split()))
cnt = np.zeros(100001)
for i in a:
cnt[i] += 1
c = convolve(cnt,cnt)
ans = 0
for i in range(len(c))[::-1]:
if c[i] > 0:
p = min(m,c[i])
m -= p
ans += i*p
if m == 0:
break
print(ans)
| 0 | null | 103,095,867,408,380 | 244 | 252 |
N = input()
S = set(map(int, input().split()))
Q = input()
T = set(map(int, input().split()))
intersection = S & T
print(len(intersection))
|
def linear_search(A, n, key):
A.append(key)
i = 0
while A[i] != key:
i += 1
A.pop()
return i != n
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for t in T:
if linear_search(S, n, t):
ans += 1
print(ans)
| 1 | 68,266,200,732 | null | 22 | 22 |
N,R = map(int,input().split())
if N <= 9:
R += 100*(10-N)
print(R)
|
from sys import stdin
def main():
#入力
readline=stdin.readline
n,m=map(int,readline().split())
s=readline().strip()
ans=[]
flag=False
i=n
while True:
max_i=i
for sa in range(1,m+1):
if i-sa==0:
ans.append(sa)
flag=True
break
else:
if s[i-sa]=="0":
max_i=i-sa
if flag: break
else:
if max_i!=i:
ans.append(i-max_i)
i=max_i
else:
break
if flag:
ans.reverse()
print(*ans)
else:
print(-1)
if __name__=="__main__":
main()
| 0 | null | 100,973,161,919,450 | 211 | 274 |
import itertools
n=int(input())
ab = []
for _ in range(n):
a, b = (int(x) for x in input().split())
ab.append([a, b])
narabi = [0+i for i in range(n)]
ans = 0
count = 0
for v in itertools.permutations(narabi, n):
count += 1
tmp_len = 0
for i in range(1,n):
x, y = abs(ab[v[i-1]][0]-ab[v[i]][0])**2, abs(ab[v[i-1]][1]-ab[v[i]][1])**2
tmp_len += (x + y)**0.5
ans += tmp_len
print(ans/count)
|
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
from itertools import permutations
import math
m = math.factorial(n)
per = permutations(xy,n)
d = 0
c = 0
for j in per :
for i in range(n-1):
d += ((j[i+1][0]-j[i][0])**2 + (j[i+1][1]-j[i][1])**2) ** 0.5
print(d/m)
| 1 | 148,716,530,883,870 | null | 280 | 280 |
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
N, M = MI()
A = LI()
ans = N - sum(A)
print(-1 if ans < 0 else ans)
if __name__ == '__main__':
solve()
|
N, M = map(int, input().split(' '))
A_ls = list(map(int, input().split(' ')))
if sum(A_ls) > N:
print(-1)
else:
print(N - sum(A_ls))
| 1 | 31,909,016,692,488 | null | 168 | 168 |
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
from cmath import pi, rect
sys.setrecursionlimit(10**7)
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
A,B,H,M = LI()
H += M / 60
H = H/12 * 2*pi
M = M/60 * 2*pi
# 余弦定理
l = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(H-M) )
# 複素数座標 Aexp(iθ)
zA = A * np.exp(H*1j)
zB = B * np.exp(M*1j)
l=abs(zA - zB)
print(l)
|
import math
A, B, H, M = map(int, input().split())
h_theta = 2 * math.pi * (H+M/60)/12
m_theta = 2 * math.pi * M/60
dx = A * math.cos(h_theta) - B * math.cos(m_theta)
dy = A * math.sin(h_theta) - B * math.sin(m_theta)
print(math.sqrt(dx**2+dy**2))
| 1 | 19,935,050,579,690 | null | 144 | 144 |
import sys
input = sys.stdin.readline
d = {}
for _ in range(int(input())):
s = input().replace("\n", "")
if s in d:
d[s] += 1
else:
d[s] = 1
x = max(d.values())
l = sorted(s for (s, i) in d.items() if i == x)
print(*l, sep="\n")
|
n = int(input())
d = {}
for i in range(n):
s = input()
d[s] = d.get(s, 0) + 1
m = max(d.values())
for s in sorted(s for s in d if d[s] == m):
print(s)
| 1 | 69,726,628,071,328 | null | 218 | 218 |
import math
import bisect
MOD = 1000000007
N = int(input())
ABs = []
count00 = 0
for i in range(N):
A, B = map(int, input().split())
if A == 0:
if B == 0:
count00 += 1
else:
ABs.append([0, -1])
elif B == 0:
ABs.append([1, 0])
else:
mygcd = math.gcd(A, B)
A, B = A//mygcd, B//mygcd
if A < 0:
ABs.append([-A, -B])
else:
ABs.append([A, B])
N2 = N - count00
if N2 == 0:
print(count00)
exit()
ABs.sort(key = lambda x:x[1])
Bs = [i[1] for i in ABs]
index0 = bisect.bisect_left(Bs, 0)
if (index0==0) or (index0==N2):
print((pow(2, N2, MOD) +count00 -1) %MOD)
exit()
btm = ABs[:index0]
top = ABs[index0:]
lenbtm = index0
lentop = N2 - index0
for i in range(lenbtm):
btm[i] = [-btm[i][1], btm[i][0]]
btmdict = {}
topdict = {}
for i in btm:
mykey = str(i[0]) + '-' + str(i[1])
btmdict[mykey] = 0
topdict[mykey] = 0
for j in top:
mykey = str(j[0]) + '-' + str(j[1])
btmdict[mykey] = 0
topdict[mykey] = 0
for i in btm:
mykey = str(i[0]) + '-' + str(i[1])
btmdict[mykey] += 1
for j in top:
mykey = str(j[0]) + '-' + str(j[1])
topdict[mykey] += 1
ans = 1
for i in btmdict:
btmi = btmdict[i]
topi = topdict[i]
if btmi*topi >= 1:
ans = ans * (pow(2, btmi, MOD) +pow(2, topi, MOD) -1) %MOD
elif btmi == 0:
ans = ans * pow(2, topi, MOD) %MOD
else:
ans = ans * pow(2, btmi, MOD) %MOD
ans = (ans +count00 -1) %MOD
print(ans)
|
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [-1] * len(S)
r = 0
d = 1
for i,s in enumerate(S[::-1]):
t = int(s)%mod
r += t*d
r %= mod
d = d*10%mod
p[i] = r
ans = 0
c = Counter(p)
for k,n in c.most_common():
if n > 1:
ans += n*(n-1)//2
else:break
print(ans)
| 0 | null | 25,967,511,610,440 | 146 | 166 |
while True:
H,W = map(int,input().split())
if H == 0 and W == 0:
break
for i in range(H):
for k in range(W):
if i == 0 or i == H-1 or k == 0 or k == W-1:
print("#",end = "")
else:
print(".",end = "")
print()
print()
|
import math
K = int(input())
result = 0
for a in range(1, K+1):
for b in range(1, K+1):
r = math.gcd(a, b)
for c in range(1, K+1):
result += math.gcd(r, c)
print(result)
| 0 | null | 18,319,914,456,988 | 50 | 174 |
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(x):
if DBG:
print(x)
n,k,c = inm()
s = ins()
l = [0]*n
r = [0]*n
for i in range(n):
if s[i]=='x':
l[i] = l[max(0,i-1)]
else:
l[i] = max(l[max(0,i-1)], (l[i-c-1]+1) if i>c else 1)
for i in range(n-1,-1,-1):
if s[i]=='x':
r[i] = r[min(n-1,i+1)]
else:
r[i] = max(r[min(n-1,i+1)], (r[i+c+1]+1) if i<n-c-1 else 1)
#ddprint(l)
#ddprint(r)
ans = []
for i in range(n):
if s[i]=='o' and \
(l[i-1] if i>0 else 0)+(r[i+1] if i<n-1 else 0)==k-1:
ans.append(i+1)
for x in ans:
print(x)
|
# 解説を参考に作成
def solve():
N, K, C = map(int, input().split())
S = input()
left = []
rest = 0
work = 0
for i in range(N):
if S[i] == 'o' and rest == 0:
left.append(i)
rest = C + 1
work += 1
if rest > 0:
rest -= 1
if work == K:
break
right = []
rest = 0
work = 0
for i in reversed(range(N)):
if S[i] == 'o' and rest == 0:
right.append(i)
rest = C + 1
work += 1
if rest > 0:
rest -= 1
if work == K:
break
right = list(reversed(right))
# print(left)
# print(right)
for i in range(len(left)):
if left[i] == right[i]:
print(left[i] + 1)
if __name__ == '__main__':
solve()
| 1 | 40,742,162,475,398 | null | 182 | 182 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict
def f(x):
return (int(str(x)[0]), int(str(x)[-1]))
def main():
N = int(readline())
df = defaultdict(int)
for i in range(1, N+1):
df[f(i)] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += df[(i, j)]*df[(j, i)]
print(ans)
if __name__ == '__main__':
main()
|
N, = map(int, input().split())
print(1-N)
| 0 | null | 44,672,585,440,878 | 234 | 76 |
#!/usr/bin/env python3
N = int(input().split()[0])
a_list = list(map(int, input().split()))
before_a = 0
total = 0
for i, a in enumerate(a_list):
if i == 0:
before_a = a
continue
total += max(before_a - a, 0)
before_a = a + max(before_a - a, 0)
ans = total
print(ans)
|
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n-1):
if a[i] <= a[i+1]:
pass
else:
ans += a[i] - a[i+1]
a[i+1] = a[i]
print(ans)
| 1 | 4,527,663,159,238 | null | 88 | 88 |
s = list(input())
num = 0
n = len(s)
l = 0
i = 0
while i < n:
if s[i] == '<':
l+=num
num+=1
i+=1
if i==n:
l+=num
else:
cur = 0
while i < n and s[i]=='>':
i+=1
cur+=1
if cur <= num:
l+=num
cur-=1
l+=(cur*(cur+1))//2
num = 0
print(l)
|
S = input()
res = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == "<":
res[i + 1] = res[i] + 1
for i in range(len(S)-1, -1, -1):
if S[i]=='>':
res[i] = max(res[i], res[i + 1] + 1)
print(sum(res))
| 1 | 156,388,388,717,652 | null | 285 | 285 |
def set1():
N,M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
set_N = set([i for i in range(1, N+1)])
for i in range(M):
A,B = [int(i) for i in input().split()]
if H[A-1] < H[B-1]:
if A in set_N:
set_N.remove(A)
elif H[B-1] < H[A-1]:
if B in set_N:
set_N.remove(B)
else:
if A in set_N:
set_N.remove(A)
if B in set_N:
set_N.remove(B)
print(len(set_N))
if __name__ == "__main__":
set1()
|
N = int(input())
CardList = [0 for i in range(53)]
for i in range(1, N + 1):
Mark, Rank = map(str, input().split())
if Mark == 'S':
CardList[int(Rank) ] = 1
elif Mark == 'H':
CardList[int(Rank) + 13] = 1
elif Mark == 'C':
CardList[int(Rank) + 26] = 1
else:
CardList[int(Rank) + 39] = 1
for j in range(1, 53):
if CardList[j] == 0:
if 1 <= j <14:
print('S', j)
elif 14 <= j < 27:
print('H', j - 13)
elif 27 <= j <40:
print('C', j - 26)
else:
print('D', j - 39)
| 0 | null | 12,997,172,075,280 | 155 | 54 |
n = int(input())
s = [input() for _ in range(n)]
ans = set()
for i in s:
ans.add(i)
print(len(ans))
|
#!/usr/bin/env python3
import sys
x = int(input())
for i in range(-10 ** 3, 10 ** 3):
for j in range(-10 **3, 10 ** 3):
if (i ** 5) - (j ** 5) == x:
print(i, j)
sys.exit()
| 0 | null | 27,982,964,003,236 | 165 | 156 |
from itertools import accumulate
import sys
N, K = map(int, input().split())
An = list(map(int, input().split()))
for cnt in range(K):
tmp = [0]*(N+1)
for i in range(N):
power = An[i]
left = max(0, i-power)
right = min(N, i+power+1)
tmp[left] += 1
tmp[right] -= 1
An = list(accumulate(tmp))[:-1]
if cnt > 40:
An = [N]*N
print(*An)
sys.exit()
print(*An)
|
import numpy as np
from numba import njit, i8
@njit(i8[:](i8, i8, i8[:]), cache=True)
def myfunc(n, k, A):
for _ in range(k):
l = np.zeros((n + 1,), dtype=np.int64)
for i, a in enumerate(A[:-1]):
l[max(0, i - a)] += 1
l[min(n, i + a + 1)] -= 1
A = np.cumsum(l)
if np.all(A[:-1] == n):
break
return A
def main():
n, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)
A = np.append(A, 0)
print(*myfunc(n, k, A)[:-1])
if __name__ == "__main__":
main()
| 1 | 15,495,402,002,350 | null | 132 | 132 |
n = int(input())
al = list(map(int,input().split()))
lst = [[] for _ in range(n)]
for i in range(1,n+1):
lst[al[i-1]-1] = i
print(*lst)
|
def chebyshev_0(a, b):
return a - b
def chebyshev_1(a, b):
return a + b
N = int(input())
X = [0] * N
Y = [0] * N
for i in range(N):
X[i], Y[i] = map(int, input().split())
max_0 = - (10 ** 9) - 1
min_0 = 2 * (10 ** 9)
for x, y in zip(X, Y):
if chebyshev_0(x, y) > max_0:
max_0 = chebyshev_0(x, y)
if chebyshev_0(x, y) < min_0:
min_0 = chebyshev_0(x, y)
l0 = abs(max_0 - min_0)
max_1 = - (10 ** 9) - 1
min_1 = 2 * (10 ** 9)
for x, y in zip(X, Y):
if chebyshev_1(x, y) > max_1:
max_1 = chebyshev_1(x, y)
if chebyshev_1(x, y) < min_1:
min_1 = chebyshev_1(x, y)
l1 = abs(max_1 - min_1)
print(max([l0, l1]))
| 0 | null | 92,101,390,304,768 | 299 | 80 |
n, a, b = map(int, input().split())
if abs(b-a)%2 == 0:
print(abs(b-a)//2)
else:
print(min((max(a,b)+min(a,b))//2, (2*n-max(a,b)-min(a,b)+1)//2))
|
x,y = map(int,input().split())
if x > 3:
x = 4
if y > 3:
y = 4
ans = 0
if x == y == 1:
ans += 400000
ans += (8-x-y)*100000
print(ans)
| 0 | null | 124,967,812,201,386 | 253 | 275 |
A, B, N = map(int, input().split())
x = min(B-1, N)
ans = (A * x // B) - A * (x // B)
print(ans)
|
N = input()
N = N[::-1]
a = int(N[0])
ans = []
if a==2 or a==4 or a==5 or a==7 or a==9:
ans = "hon"
if a==0 or a==1 or a==6 or a==8:
ans = "pon"
if a==3:
ans = "bon"
print(ans)
| 0 | null | 23,616,075,471,428 | 161 | 142 |
def main():
n = int(input())
print(b(n))
def b(n: int) -> int:
m = 100
i = 0
while m < n:
m = m * 101 // 100
i += 1
return i
if __name__ == '__main__':
main()
|
#coding:utf-8
import math
N,K = map(int,input().split())
A = [int(y) for y in input().split()]
Ma = max(A)
mi = 1
ans = Ma
def execute(f):
count = 0
for i in A:
count += math.ceil(i / f) - 1
if count <= K:
return True
else:
return False
while True:
median = (Ma + mi) // 2
bobo = execute(median)
if bobo:
ans = min(ans,median)
Ma = median
else:
mi = median + 1
if Ma == mi:
break
print("{}".format(ans))
| 0 | null | 16,663,184,647,950 | 159 | 99 |
while(1):
x,y=map(int,input().split())
if x==0 and y==0 :
break
elif x<y:
print(x,y,sep=" ")
else :
print(y,x,sep=" ")
|
N = int(input())
multiplication = []
for x in range(1, 10):
for y in range(1, 10):
multiplication.append(x*y)
if N in multiplication:
print( "Yes" )
else:
print( "No" )
| 0 | null | 80,422,549,813,902 | 43 | 287 |
N = list(input().split())
A = int(N[0])
b1,b2 = N[1].split('.')
B = int(b1+b2)
prd = list(str(A*B))
ans = 0
if len(prd) < 3:
ans = 0
else:
prd.pop()
prd.pop()
ans = int(''.join(prd))
print(ans)
|
k,x=map(int,input().split());print('YNeos'[500*k<x::2])
| 0 | null | 57,218,830,944,480 | 135 | 244 |
from sys import stdin
def main():
readline = stdin.readline
n = int(readline())
s = tuple(readline().strip() for _ in range(n))
plus, minus = [], []
for c in s:
if 2 * c.count('(') - len(c) > 0:
plus.append(c)
else:
minus.append(c)
plus.sort(key = lambda x: x.count(')'))
minus.sort(key = lambda x: x.count('('), reverse = True)
plus.extend(minus)
sum = 0
for v in plus:
for vv in v:
sum = sum + (1 if vv == '(' else -1)
if sum < 0 : return print('No')
if sum != 0:
return print('No')
return print('Yes')
if __name__ == '__main__':
main()
|
N = int(input())
S = [input() for i in range(N)]
LR = []
for s in S:
left, right = 0, 0
for ss in s:
if ss == "(":
left += 1
else:
if left:
left -= 1
else:
right += 1
LR.append([left, right])
#print(LR)
plus = []
minus = []
for l, r in LR:
if l >= r:
plus.append([l, r])
else:
minus.append([l, r])
plus.sort(key = lambda x: x[1])
minus.sort(key = lambda x: -x[0])
cnt = 0
for l, r in plus + minus:
cnt -= r
if cnt < 0:
print("No")
exit()
cnt += l
if cnt == 0:
print("Yes")
else:
print("No")
| 1 | 23,653,366,010,208 | null | 152 | 152 |
import sys
input = sys.stdin.buffer.readline
import copy
def main():
N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
MOD = 10**9+7
fac = [0 for _ in range(N+1)]
fac[0],fac[1] = 1,1
invfac = copy.deepcopy(fac)
for i in range(2,N+1):
fac[i] = (fac[i-1]*i)%MOD
invfac[-1] = pow(fac[-1],MOD-2,MOD)
for i in range(N,0,-1):
invfac[i-1] = (invfac[i]*i)%MOD
def coef(x,y):
num = (((fac[x]*invfac[y])%MOD)*invfac[x-y]%MOD)
return num
p,m = 0,0
for i in range(N-M+1):
comb = coef(N-i-1,M-1)
p += a[-i-1]*comb
m += a[i]*comb
print((p-m)%MOD)
if __name__ == "__main__":
main()
|
def draw(h,w):
s = "#" * w
k = "#" + "." * (w-2) + "#"
print s
for i in range(0,h-2):
print k
print s
print
if __name__ == "__main__":
while True:
h,w = map(int, raw_input().split())
if h==0 and w==0:
break
else:
draw(h,w)
| 0 | null | 48,057,594,247,840 | 242 | 50 |
def main():
if sum(list(map(int, list(input())))) % 9:
print("No")
else:
print("Yes")
main()
|
N=int(input())
S=str(N)
A=len(S)
M=0
for i in range(A):
M=M+int(S[i])
if M%9==0:
print("Yes")
else:
print("No")
| 1 | 4,397,045,536,708 | null | 87 | 87 |
n = int(input())
x = 1
print "",
while x <= n:
if x%3==0:
print str(x),
else:
t = x
while t:
if t%10==3:
print str(x),
t = 0
else:
t /= 10
x += 1
print
|
n=int(input())
result=[]
for i in range(1,n+1):
if i %3==0:
result.append(i)
else:
k=i
for j in range(1,5):
if k%10==3:
result.append(i)
break
else:
k=k//10
else:
continue
print("",*result)
| 1 | 908,452,934,662 | null | 52 | 52 |
a, b, c = map(int,input().split(' '))
k = int(input())
while k > 0:
if c <= b:
c *= 2
elif b <= a:
b *= 2
k -= 1
if a < b and b < c:
print('Yes')
break
else:
print('No')
|
A,B,C=map(int,input().split())
K=int(input())
D=[]
for i in range(K):
for j in range(K-i):
if A*(2**i)<B*(2**j) and B*(2**j)<C*(2**(K-i-j)):
D.append('Yes')
else:
D.append('No')
if ('Yes' in D)==True:
print('Yes')
else:
print('No')
| 1 | 6,985,567,204,980 | null | 101 | 101 |
import math
r = float(input())
a = math.pi * r * r
l = 2 * math.pi * r
print(f'{a} {l}')
|
from math import pi
r = float(input())
print(round(r * r * pi, 7), round(2 * pi * r, 7))
| 1 | 635,093,926,272 | null | 46 | 46 |
import math
N=int(input())
ans=0
for i in range(1,N+1):
for j in range(i,N+1):
for k in range(j,N+1):
if i==j and j==k:
ans+=i
elif i<j and j<k:
ans+=6*math.gcd(i,math.gcd(j,k))
else:
ans+=3*math.gcd(i,math.gcd(j,k))
print(ans)
|
from scipy.special import comb
from collections import Counter
n = int(input())
A = [int(i) for i in input().split()]
count = Counter(A)
combs = {k:comb(count[k], 2) for k in count.keys()}
combs_minas_one = {k:comb(count[k]-1, 2) for k in count.keys()}
all = sum(combs.values())
for a in A:
ans = all - combs[a] + combs_minas_one[a]
print(int(ans))
| 0 | null | 41,634,157,143,250 | 174 | 192 |
x = int(input())
print(int(x/2)+ 1 if x % 2 != 0 else int(x/2))
|
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
import math
print(math.ceil(I()/2))
| 1 | 58,861,659,490,308 | null | 206 | 206 |
A, B, C, K = map(int ,input().split())
Xa = min(K,A)
K2 = K - Xa
Xb = min(K2,B)
Xc = K2 - Xb
print(Xa - Xc)
|
a,b,c,k = map(int,input().split())
if k < a:
print(str(k))
elif k < (a + b):
print(str(a))
else:
print(str(2*a + b - k))
| 1 | 21,842,655,841,650 | null | 148 | 148 |
import math
A, B, H, M = map(int, input().split())
c = math.cos(math.radians(360 - abs(30 * H + 0.5 * M - 6 * M)))
X_2 = A ** 2 + B ** 2 - 2 * A * B * c
X = math.sqrt(X_2)
print(X)
|
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def solve():
N = int(input())
A = list(sorted(list(map(int, input().split())), reverse=True))
ans = A[0]
n = 1
for i in range(1, N):
if n == N - 1:
break
ans += A[i]
n += 1
if n == N - 1:
break
ans += A[i]
n += 1
if n == N - 1:
break
print(ans)
def main():
solve()
if __name__ == '__main__':
main()
| 0 | null | 14,614,667,982,204 | 144 | 111 |
x = int(input())
n = x // 100
if n * 105 >= x:
print(1)
else:
print(0)
|
import itertools
n = int(input())
A = list(map(int,input().split()))
A.sort()
def binary_search(l,r,v):
while r >= l:
h = (l+r) // 2
if A[h] < v:
l = h+1
else:
r = h-1
return r
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
a = binary_search(j,n-1,A[i]+A[j])
ans += a-j
print(ans)
| 0 | null | 150,068,540,331,840 | 266 | 294 |
import bisect
import copy
def check(a, b, bar):
sm = 0
cnt = 0
n = len(a)
for x in a:
i = bisect.bisect_left(a, bar - x)
if i == n:
continue
cnt += n - i
sm += b[i] + x * (n-i)
return cnt, sm
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = copy.deepcopy(a)
for i,_ in enumerate(b[:-1]):
b[n-i-2] += b[n-i-1]
left = 0
right = b[0] * 2
while right - left > 1:
middle = ( right + left ) // 2
if check(a, b, middle)[0] < m:
right = middle
else:
left = middle
print(check(a, b, left)[1] - left * (check(a, b, left)[0]-m) )
|
#!/usr/bin/env python3
import sys
from itertools import accumulate
from bisect import bisect_left
def solve(N: int, M: int, A: "List[int]"):
A.sort()
right = 2*A[-1]+1
left = 0
while right - left > 1:
mid = (left+right)//2
# A[i]+A[j] >= midになるようなi,jの組み合わせの個数 mを 求めたい
# m >= Mならok
m = 0
for i in range(N):
a = A[i]
res = mid - a
# Aからres以上のものを探す
index = bisect_left(A,res)
m += N-index
if m >= M:
left = mid
else:
right = mid
# M通り以上の握手ができる最小の組み合わせの幸福度
B = sorted(A,reverse=True)
accum_B = list(accumulate(B))
answer = 0
handshake_count = 0
for i in range(N):
res = left - A[i]
if res > A[-1]:
continue
index = bisect_left(A,res)
answer += (N-index)*A[i]+accum_B[N-index-1]
handshake_count += (N-index)
# 握手の回数がmを越えたときはその分の幸福度を引く
if handshake_count>M:
answer -= left*(handshake_count-M)
print(answer)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, M, A)
if __name__ == '__main__':
main()
| 1 | 107,998,920,574,610 | null | 252 | 252 |
while 1:
a=input()
if a=='0':break
print(sum([int(s) for s in list(a)]))
|
'''
ITP-1_8-B
??°?????????
?????????????????°???????????????????¨??????????????????°?????????????????????????????????
???Input
?????°??????????????????????????\?????¨??????????????????????????????????????????????????????????????´??° x ?????????????????§?????????????????????
x ??? 1000 ?????\????????´??°??§??????
x ??? 0 ?????¨?????\?????????????????¨??????????????????????????????????????????????????????????????£????????????????????????
???Output
????????????????????????????????????x ???????????????????????????????????????????????????
'''
while True:
# inputData
inputData = input()
if inputData == '0':
break
# outputData
outputData = 0
for cnt0 in inputData:
outputData += int(cnt0)
print(outputData)
| 1 | 1,573,099,655,050 | null | 62 | 62 |
ls = list(map(int, input().split()))
ls.sort()
ls = map(str, ls)
print(' '.join(ls))
|
a,b,c = input().split()
a = int(a)
b = int(b)
c = int(c)
tmp = 0
if c < b:
tmp = b
b = c
c = tmp
if b < a:
tmp = a
a = b
b = tmp
if c < b:
tmp = b
b = c
c = tmp
print (str(a) + " " + str(b) + " " + str(c))
| 1 | 421,101,857,698 | null | 40 | 40 |
from math import *
def gcd(x, y):
while y != 0:
(x, y) = (y, x % y)
return x
def lcm(x,y):
return x*y//gcd(x,y)
n = int(input())
a = [int(x) for x in input().split()]
mod = 1000000000+7
k = 1
for x in a:
k = lcm(k,x)
ans = 0
for x in a:
ans += k//x
print(ans%mod)
|
import sys
a, b = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
print( "{} {}".format( a*b, a*2+b*2 ) )
| 0 | null | 44,059,744,737,568 | 235 | 36 |
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
ans = 0
cnt = 1
# 最大値は一回だけ
ans += A[0]
# N-2個は、2,2,3,3,..i,i,...のように取る
flag = False
for i in range(1, len(A)-1):
ans += A[cnt]
if flag == False:
flag = True
else:
flag = False
cnt += 1
print(ans)
|
n = int(input())
a = list(map(int,input().split()))
sa = sorted(a,reverse=True)
ans = sa[0]
i = 2
for v in sa[1:]:
if i >= n:
break
#print("i:{} ans:{}".format(i,ans))
ans += v
i += 1
if i >= n:
break
#print("i:{} ans:{}".format(i,ans))
ans += v
i += 1
print(ans)
| 1 | 9,170,142,421,220 | null | 111 | 111 |
S = 13 * 0
H = 13 * 1
C = 13 * 2
D = 13 * 3
#???????????????????¨??????????????????????????????????????????????????????????,???????????????:1???
#??????????????????????????????5???S(???0)+5???????????????11???D(???39)+11??§??¨??????
#?????????0???????????¨
card_count = [0 for i in range(53)]
n = int(input())
for i in range(n):
card_type, card_num = input().split()
card_count[eval(card_type)+int(card_num)] += 1 #???????????£????¨??????¨???????????????????????°???1????¶????
for s in ['S','H','C','D']:
for i in range(1, 13+1):
if card_count[eval(s)+i] == 0: #??????????????°???0??????
print("{0} {1}".format(s,i)) #?¨??????¨?????????????????????
|
def az16():
list = []
n = input()
for i in range(0,n):
list.append(raw_input().split())
for mark in ["S","H","C","D"]:
for i in range(1,14):
if [mark,repr(i)] not in list:
print mark,i
az16()
| 1 | 1,036,143,815,000 | null | 54 | 54 |
a, b = input().split()
a = int(a)
b = int(b)
if a > b:
print('a > b')
elif a < b:
print('a < b')
else:
print('a == b')
|
K = int(input())
S = input()
MAX = 2020202
MOD = 10**9 + 7
fac = [0]*MAX
facinv = [0]*MAX
inv = [0]*MAX
def modinv(a, mod):
b = mod
x, u = 1, 0
while b:
q = a//b
a, b = b, a-q*b
x, u = u, x-q*u
x %= mod
return x
def mod_nCr_init(n, mod):
fac[0] = fac[1] = 1
facinv[0] = facinv[1] = 1
inv[1] = 1
for i in range(2, n):
fac[i] = fac[i-1] * i % mod
inv[i] = -inv[mod % i] * (mod // i) % mod
facinv[i] = facinv[i-1] * inv[i] % mod
def mod_nCr(n, r, mod):
if n < r or n < 0 or r < 0:
return 0
return fac[n] * (facinv[r] * facinv[n-r] % mod) % mod
mod_nCr_init(MAX, MOD)
ns = len(S)
ans = 0
for i in range(K+1):
x = pow(26, i, MOD)
x *= pow(25, K-i, MOD)
x %= MOD
x *= mod_nCr(ns+K-i-1, ns-1, MOD)
ans += x
ans %= MOD
print(ans)
| 0 | null | 6,538,169,863,680 | 38 | 124 |
#文字列をリストに変換
list_coffee = list(input())
#判別
if list_coffee[2] == list_coffee[3] and list_coffee[4] == list_coffee[5]:
text = "Yes"
else:
text = "No"
#結果の表示
print(text)
|
s=input()
print('YNeos'[s[2]!=s[3] or s[4]!=s[5]::2])
| 1 | 42,156,714,716,818 | null | 184 | 184 |
a, b, c = list(map(int, input().split()))
frag1 = ((a+b-c)**2 -4*a*b) > 0
frag2 = a+b-c < 0
if frag1 and frag2:
print("Yes")
else:
print("No")
|
s=list(input())
k=0
bef="x"
n=[]
ans=0
def kai(n):
if n==0:
return 0
ret=0
for i in range(1,n+1):
ret+=i
return ret
for i in s:
if bef!=i:
if bef=="x":
st=i
bef=i
k+=1
continue
bef=i
n.append(k)
k=0
k+=1
n.append(k)
n.reverse()
if st==">":
ans+=kai(n.pop())
while len(n)!=0:
if len(n)==1:
ans+=kai(n.pop())
else:
f=n.pop()
s=n.pop()
if f>s:
ans+=kai(f)+kai(s-1)
else:
ans+=kai(f-1)+kai(s)
#print("{} {}".format(f,s))
print(ans)
| 0 | null | 104,172,706,885,120 | 197 | 285 |
N,K = map(int,input().split())
h = list(map(int,input().split()))
cnt = 0
hei = 0
for i in range(N):
hei = h[i]
if hei >= K:
cnt += 1
print(cnt)
|
N = int(input())
A = list(map(int, input().split()))
cun =0
for i in range(N):
if i == N-1:
break
elif A[i] > A[i+1]:
cun += A[i] - A[i+1]
A[i+1] = A[i]
else:
pass
print(cun)
| 0 | null | 91,946,806,531,840 | 298 | 88 |
X = int(input())
j = 2
for i in range(X,(X - 1) * 2):
while i % j != 0 and j <= i:
j += 1
if j == i:
print(i)
break
j = 2
if X == 2:
print(2)
|
import math
def prime(n):
limit = math.floor(math.sqrt(n))
for i in range(2,limit+1):
if n % i == 0:
return prime(n+1)
return n
X = int(input())
print(prime(X))
| 1 | 105,709,421,949,288 | null | 250 | 250 |
# coding: utf-8
import sys
from collections import deque
n, q = map(int, input().split())
total_time = 0
tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
try:
while True:
t = tasks.popleft()
if int(t[1]) - q <= 0:
total_time += int(t[1])
print(t[0], total_time)
else:
t[1] = str(int(t[1]) - q)
total_time += q
tasks.append(t)
except Exception:
pass
|
H, A = (int(x) for x in input().split())
dm = divmod(H,A)
if dm[1] == 0:
print(dm[0])
else:
print(dm[0]+1)
| 0 | null | 38,394,870,665,252 | 19 | 225 |
S = input()
L = len(S)
for i in range((L-1)//2):
if S[i] != S[L-1-i]:
print("No")
exit()
for i in range((L-1)//4):
if S[i] != S[(L-1)//2-1-i]:
print("No")
exit()
for i in range(L-1, L - (L-1)//4, -1):
if S[i] != S[i - (L-1)//2-1]:
print("No")
exit()
print("Yes")
|
n,k = map(int,input().split())
print((n%k) if (n%k) < (k-(n%k)) else (k-(n%k)))
| 0 | null | 42,608,070,882,870 | 190 | 180 |
from queue import deque
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))
count = 0
L, R = deque(), deque()
for i in range(Q):
if Query[i][0] == "1": count += 1
else:
if Query[i][1] == "1":
if count % 2 == 0: L.appendleft(Query[i][2])
else: R.append(Query[i][2])
else:
if count % 2 == 0: R.append(Query[i][2])
else: L.appendleft(Query[i][2])
L, R = "".join(L), "".join(R)
if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1])
|
S = input()
Q = int(input())
lS = ''
for _ in range(Q):
query = input().split()
if query[0] == '1':
lS, S = S, lS
else:
if query[1] == '1':
lS += query[2]
else:
S += query[2]
print(lS[::-1] + S)
| 1 | 57,538,715,332,420 | null | 204 | 204 |
while True:
H,W = map(int,input().split())
if H==0 and W==0: break
idx = ('#'*W + '\n')
con = ""
if W > 2: con = ('#' + '.'*(W-2) + '#\n') * (H-2)
if H >= 2: con =con + idx
print(idx + con)
|
X = int(input())
SUM = 0
(X * 1000 / 500)
Z = X // 500
A = X % 500
SUM = SUM + (Z * 1000)
B = A // 5
SUM = SUM + (B * 5)
print(int(SUM))
| 0 | null | 21,604,206,076,570 | 50 | 185 |
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
def floor(a,b):
return a//b
N,X,M = LI()
# 繰り返しの1回目が終わるまで
used = [-1]*M
end_index = -1
A = [X]
sum_ = 0
for i in range(N):
if i == 0:
sum_ += A[0]
else:
val = pow(A[i-1],2,M)
A.append(val)
if used[val] == -1:
used[val] = i
sum_ += val
else:
end_index = i
start_val = val
start_index = used[val]
break
if end_index == -1:
print(sum_)
exit()
else:
ans = sum_
# 繰り返し全体が終わるまで
n = floor(N-start_index,end_index-start_index)
sum_ = 0
A2 = [start_val]
for j in range(end_index-start_index):
if j == 0:
val2 = start_val
sum_ += val2
else:
val2 = pow(A2[j-1],2,M)
A2.append(val2)
sum_ += val2
ans += (n-1)*sum_
# 残りの部分
sum_ = 0
A2 = [start_val]
for j in range(N-n*end_index+(n-1)*start_index):
if j == 0:
val2 = start_val
sum_ += val2
else:
val2 = pow(A2[j-1],2,M)
A2.append(val2)
sum_ += val2
ans += sum_
print(ans)
|
n,x,m=map(int, input().split())
a=x
ans=a
flg=[0]*m
flg[a]=1
l=[a]
lp=-1
for i in range(1,m+1):
if n <= i:
break
tmp=(a*a)%m
a=tmp
if flg[a]==1:
lp = l.index(a)
break
else:
ans+=tmp
l.append(a)
flg[a]=1
if lp != -1:
l2 = l[lp:]
tmp = sum(l2)
b=(n-len(l))//len(l2)
c=n-len(l)-b*len(l2)
ans=ans+(b*tmp)+sum(l2[:c])
print(ans)
| 1 | 2,789,583,758,818 | null | 75 | 75 |
n,x,t=[int(i) for i in input().split()]
k=n//x
if n%x:
print((k+1)*t)
else:
print(k*t)
|
import numpy as np
list_data = [int(x) for x in input().split(" ")]
print(np.ceil(list_data[0] / list_data[1]).astype(int) * list_data[2])
| 1 | 4,255,468,813,970 | null | 86 | 86 |
N=int(input())
ans = "No"
n=0
for _ in range(N):
x, y = map(int, input().split())
if x == y:
n+=1
else:
n = 0
if n >= 3:
ans="Yes"
print(ans)
|
N,K = map(int,input().split())
height = list(map(int,input().split()))
chibi = [1] * N
for i in range (N):
if height[i] >= K:
chibi[i] = 0
print(N-sum(chibi))
| 0 | null | 90,461,163,470,758 | 72 | 298 |
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
p = make_divisors(n)
x = 0
i = 1
ans = 0
def countf(x):
for j in range(1,x+2):
if (1+j)*j//2 > x:
return j - 1
while n != 1:
if n % p[i] == 0:
x += 1
n = n // p[i]
else:
if x != 0:
ans += countf(x)
x = 0
i += 1
ans += countf(x)
print(ans)
|
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
S = input()
if S == "AC":
AC += 1
elif S == "WA":
WA += 1
elif S == "TLE":
TLE += 1
else:
RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))
| 0 | null | 12,818,189,168,680 | 136 | 109 |
ls = sorted(list(map(int,input().split())))
if ls[0] == ls[1] and ls[0] != ls[2]:
print('Yes')
elif ls[1] == ls[2] and ls[0] != ls[1]:
print('Yes')
elif ls[0] == ls[2] and ls[0] != ls[1]:
print('Yes')
else:
print('No')
|
ABC = input().split()
print("Yes" if len(set(ABC)) == 2 else "No")
| 1 | 67,688,037,090,722 | null | 216 | 216 |
N=int(input())
right=0
left=0
for i in range(N):
a,b=input().split()
if a>b:
left+=3
elif a<b:
right+=3
else:
left+=1
right+=1
print(f"{left} {right}")
|
N = int(input())
ans = []
if N <= 26:
print(chr(96 + N))
else:
while N != 0:
val = N % 26
if val == 0:
val = 26
N = N //26 - 1
else:
N //= 26
ans.append(chr(96 + val))
ans.reverse()
print(''.join(ans))
| 0 | null | 6,942,743,289,108 | 67 | 121 |
a1,a2,a3=map(int,input().split())
ans=a1+a2+a3
if ans>=22:
print("bust")
else:
print("win")
|
a,b,c = map(int,input().split())
if a + b + c >= 22:
print('bust')
if a + b + c <= 21:
print('win')
| 1 | 119,049,152,544,060 | null | 260 | 260 |
N = int(input())
d = {}
for i in [None]*N:
a, b = input().split()
if a == "insert":
d[b] = 1
else:
print("yes" if b in d else "no")
|
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,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 copy import deepcopy
from time import time
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())
k = INT()
s = list('00000000000')
for i in range(k):
for j in range(len(s)):
if s[j] != '9' and ( int("".join(s[j+1:])) == 0 or int(s[j]) < int(s[j+1]) + 1 ):
s[j] = str(int(s[j]) + 1)
else:
continue
while j > 0:
j -= 1
s[j] = str(max(0, int(s[j+1])-1))
break
ans = int("".join(reversed(s)))
print(ans)
| 0 | null | 19,877,609,462,240 | 23 | 181 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.