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
|
---|---|---|---|---|---|---|
N=int(input())
A=list(map(int,input().split()))
M=1000050
dp=[0 for i in range(M)]
ans=0
for x in A:
if dp[x]!=0:
dp[x]=2
continue
for i in range(x,M,x):
dp[i]+=1
for x in A:
if dp[x]==1:
ans+=1
print(ans)
|
n, k = list(map(int, input().split(' ')))
print(sum([tall >= k for tall in list(map(int, input().split(' ')))]))
| 0 | null | 97,043,804,963,638 | 129 | 298 |
import fractions
a, b = map(int, input().split())
print(int(a*b / fractions.gcd(a,b)))
|
N = int(input())
X = input()
n1 = X.count("1")
Xn = int(X, 2)
Xms = (Xn % (n1 - 1)) if n1 > 1 else 0
Xml = Xn % (n1 + 1)
def f(n):
if n == 0:
return 0
return f(n % bin(n).count("1")) + 1
dp = [0] * ((10 ** 5) * 2 + 1)
for i in range(1, len(dp)):
dp[i] = f(i)
for i in range(N):
cnt = 0
Xim = 0
if X[i] == "1" and n1 == 1:
print(cnt)
elif X[i] == "1":
print(dp[(Xms - pow(2, N - i - 1, n1 - 1)) % (n1 - 1)] + 1)
else:
print(dp[(Xml + pow(2, N - i - 1, n1 + 1)) % (n1 + 1)] + 1)
| 0 | null | 60,966,772,664,460 | 256 | 107 |
N = int(input())
N=N+1
a_ =sum(list(range(1,N,1)))
a_3=sum(list(range(3,N,3)))
a_5=sum(list(range(5,N,5)))
a_15=sum(list(range(15,N,15)))
ans=a_ + a_15 -(a_3+a_5)
print(ans)
|
N = int(input())
S = 0
for i in range(1, N+1):
if i % 3 == 0 and i % 5 == 0:
i = "FizzBuzz"
elif i % 3 == 0:
i = "Fizz"
elif i % 5 == 0:
i = "Buzz"
else:
S += i
print(S)
| 1 | 34,925,682,301,680 | null | 173 | 173 |
import sys
input = sys.stdin.readline
import bisect
from itertools import accumulate
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort()
left = -1
right = 1 + 2 * 10 ** 5
def shake(x):
cnt = 0
for i in A:
cnt += N - bisect.bisect_left(A, x - i)
if cnt >= M:
return 1
else:
return 0
while True:
mid = (left + right) // 2
if shake(mid):
if not shake(mid + 1):
X = mid
break
else:
left = mid
else:
if shake(mid - 1):
X = mid - 1
break
else:
right = mid
happy = 0
cumsum_A = list(accumulate(A))
for j in A:
idx = bisect.bisect_right(A, X - j)
cnt = N - idx
if cnt == N:
happy += cumsum_A[-1] + cnt * j
else:
happy += cumsum_A[-1] - cumsum_A[idx - 1] + cnt * j
M -= cnt
happy += M * X
print(happy)
|
import bisect
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
#C[i]=パワーがi以下の人数
C=[0]*(10**5*2+1)
for a in A:
C[a]+=1
for i in range(1,len(C)):
C[i]+=C[i-1]
#和がx以上になる組み合わせの総数を求める関数
def pattern_num_ge_x(x):
p=0
for a in A:
p+=(N-(C[x-a-1] if x-a-1>=0 else 0))
return(p)
#pattern_num_ge_x(x)がM未満になる最小のxを探す(=r)
#lはM以上になる最大のx
l=-1
r=10**5*2+1
while r-l>1:
m=(r+l)//2
if pattern_num_ge_x(m)<M:
r=m
else:
l=m
#和がr以上になる組み合わせの総和を求める(累積和を使用)
S=[0]+list(reversed(A[:]))
for i in range(1,N+1):
S[i]+=S[i-1]
ans=0
for a in A:
idx=bisect.bisect_left(A,r-a)
ans+=a*(N-idx) + S[N-idx]
M-=(N-idx)
#回数のあまり分lを足す
ans+=l*M
print(ans)
| 1 | 108,449,688,881,600 | null | 252 | 252 |
n ,q = map(int, input().split())
ntlist = []
for i in range(n):
nt = list(map(str, input().split()))
ntlist.append(nt)
tp = 0
while (len(ntlist)):
nt = ntlist.pop(0)
if (int(nt[1])> q):
nt[1] = int(nt[1]) - q
tp += q
ntlist.append(nt)
else:
tp += int(nt[1])
nt[1] = 0
print(nt[0], tp)
|
# coding: utf-8
# Here your code !
import collections
p,q=map(int,input().split())
count =0
deq = collections.deque()
finished=[]
while 1:
try:
deq.append(input().split())
except EOFError:
break
while deq:
d = deq.popleft()
d[1]=int(d[1])
if d[1]<=q:
count+=d[1]
d[1]=count
finished.append(map(str,d))
elif d[1]>q:
d[1]-=q
count+=q
deq.append(d)
for f in finished:
print(" ".join(f))
| 1 | 43,801,702,468 | null | 19 | 19 |
n = input()[::-1]
dp = [[0, 0] for i in range(len(n) + 1)]
dp[0][1] = 1
for i in range(len(n)):
dp[i + 1][0] = min(dp[i][0] + int(n[i]), dp[i][1] - int(n[i]) + 10)
dp[i + 1][1] = min(dp[i][0] + int(n[i]) + 1, dp[i][1] - int(n[i]) + 9)
print(dp[len(n)][0])
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
h, w, k = list(map(int, readline().split()))
a = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)]
no = 0
is_f = True
for i in range(h):
if a[i].count("#") != 0:
row_f = True
no += 1
for j in range(w):
if a[i][j] == "#":
if not row_f:
no += 1
else:
row_f = False
a[i][j] = no
if is_f:
is_f = False
if i != 0:
for j in range(i - 1, -1, -1):
for k in range(w):
a[j][k] = a[i][k]
else:
for j in range(w):
a[i][j] = a[i-1][j]
for i in range(h):
print(*a[i])
if __name__ == '__main__':
solve()
| 0 | null | 107,371,167,134,042 | 219 | 277 |
n = int(input())
if n%2:print(0);exit()
two = 0
five = 0
val = 2
while val<=n:
two+=n//val
val *= 2
val = 5
while val<=n:
five +=(n//val)//2
val *=5
print(min(two,five))
|
def gcd(u, v):
if (v == 0): return u
return gcd(v, u % v)
def lcm(u, v):
return (u * v) // gcd(u, v)
while 1:
try:
inp = input()
except EOFError:
break
else:
u, v = inp.split(' ')
u = int(u)
v = int(v)
print(gcd(u, v), lcm(u, v))
| 0 | null | 57,691,708,681,080 | 258 | 5 |
#E
N,T=map(int,input().split())
A=[0 for i in range(N+1)]
B=[0 for i in range(N+1)]
for i in range(1,N+1):
A[i],B[i]=map(int,input().split())
dp1=[[0 for i in range(6001)] for j in range(N+1)]
dp2=[[0 for i in range(6001)] for j in range(N+2)]
for i in range(1,N+1):
for j in range(T+1):
if j>=A[i]:
dp1[i][j]=max(dp1[i-1][j],dp1[i-1][j-A[i]]+B[i])
else:
dp1[i][j]=dp1[i-1][j]
for i in range(N,0,-1):
for j in range(T+1):
if j>=A[i]:
dp2[i][j]=max(dp2[i+1][j],dp2[i+1][j-A[i]]+B[i])
else:
dp2[i][j]=dp2[i+1][j]
ans=0
for i in range(1,N+1):
for j in range(T):
ans=max(ans,dp1[i-1][j]+dp2[i+1][T-1-j]+B[i])
print(ans)
|
def solve():
import numpy as np
from sys import stdin
f_i = stdin
N, T = map(int, f_i.readline().split())
AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
AB.sort()
max_Ai = AB[-1][0]
dp = [[0] * T for i in range(N + 1)]
dp = np.zeros(max_Ai + T, dtype=int)
for A_i, B_i in AB:
dp[A_i:A_i+T] = np.maximum(dp[A_i:A_i+T], dp[:T] + B_i)
print(max(dp))
solve()
| 1 | 151,632,778,215,720 | null | 282 | 282 |
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n = int(lines.pop(0))
s = lines.pop(0)
count = 0
prev_c = None
for c in s:
if c != prev_c:
count += 1
prev_c = c
print(count)
|
h,w=[int(x) for x in input().rstrip().split()]
l=[list(input()) for i in range(h)]
move=[[1,0],[-1,0],[0,-1],[0,1]]
def bfs(x,y):
stack=[[x,y]]
done=[[False]*w for i in range(h)]
dist=[[0]*w for i in range(h)]
max_val=0
while(stack):
nx,ny=stack.pop(0)
done[ny][nx]=True
for dx,dy in move:
mx=nx+dx
my=ny+dy
if not(0<=mx<=w-1) or not(0<=my<=h-1) or done[my][mx]==True or l[my][mx]=="#":
continue
done[my][mx]=True
dist[my][mx]=dist[ny][nx]+1
max_val=max(max_val,dist[my][mx])
stack.append([mx,my])
return max_val
ans=0
for i in range(w):
for j in range(h):
if l[j][i]!="#":
now=bfs(i,j)
ans=max(ans,now)
print(ans)
| 0 | null | 132,242,358,081,920 | 293 | 241 |
X = int(input())
if X >= 400 and 599 >= X:
print("8")
elif X >= 600 and 799 >= X:
print("7")
elif X >= 800 and 999 >= X:
print("6")
elif X >= 1000 and 1199 >= X:
print("5")
elif X >= 1200 and 1399 >= X:
print("4")
elif X >= 1400 and 1599 >= X:
print("3")
elif X >= 1600 and 1799 >= X:
print("2")
elif X >= 1800 and 1999 >= X:
print("1")
|
x = int(input())
ans = 8
if x < 600: ans=8
elif x < 800: ans=7
elif x < 1000: ans=6
elif x < 1200: ans=5
elif x < 1400: ans=4
elif x < 1600: ans=3
elif x < 1800: ans=2
else: ans=1
print(ans)
| 1 | 6,742,725,320,528 | null | 100 | 100 |
n = int(input())
x = list(map(int,input().split()))
ans = 10 ** 12
for i in range(1,101):
p = 0
for j in x:
p += (j - i) ** 2
ans = min(ans,p)
print(ans)
|
n,a,b = map(int,input().split())
t = n // (a+b)
ans = t*a
s = n % (a+b)
if s <= a:
ans += s
else:
ans += a
print(ans)
| 0 | null | 60,151,568,824,280 | 213 | 202 |
n, *a = map(int, open(0).read().split())
mita = [0] * -~n
mita[-1] = 3
mod = 10 ** 9 + 7
c = 1
for i in range(n):
c = c * (mita[a[i] - 1] - mita[a[i]]) % mod
mita[a[i]] += 1
print(c)
|
X, Y = map(int, input().split())
MOD = 10**9+7
def mod_pow(n, m):
res = 1
while m > 0:
if m & 1:
res = (res*n)%MOD
n = (n*n)%MOD
m >>= 1
return res
if (2*Y-X)%3 != 0 or (2*X-Y)%3 != 0 or 2*Y < X or 2*X < Y:
print(0)
else:
A = (2*X-Y)//3
B = (2*Y-X)//3
m = 1
n = 1
for i in range(A):
m = (m*(A+B-i))%MOD
n = (n*(A-i))%MOD
inverse_n = mod_pow(n, MOD-2)
print((m*inverse_n)%MOD)
| 0 | null | 140,575,263,937,280 | 268 | 281 |
r = int(input())
print(2*r*3.1415926535)
|
x = list(map(int, input().split()))
ans = 0
for i in x:
if i == 1:
ans += 300000
elif i == 2:
ans += 200000
elif i == 3:
ans += 100000
if sum(x) == 2:
ans += 400000
print(ans)
| 0 | null | 86,258,190,234,272 | 167 | 275 |
while True:
h, w = map(int, input().split())
if not h and not w:
break
result = []
w2 = w >> 1
if w % 2:
for i in range(h):
if i % 2:
result.append(".#" * w2 + ".")
else:
result.append("#." * w2 + "#")
else:
for i in range(h):
if i % 2:
result.append(".#" * w2)
else:
result.append("#." * w2)
print("\n".join(result) + "\n")
|
n = int(input())
lst = list(map(int, input().split()))
count = 0
for x in range(1,n+1,2):
if lst[x-1]%2 != 0:
count +=1
print(count)
| 0 | null | 4,358,056,604,428 | 51 | 105 |
import os
import sys
import numpy as np
def solve(N, U, V, AB):
G = [[0]*0 for _ in range(N+1)]
for idx_ab in range(len(AB)):
a, b = AB[idx_ab]
G[a].append(b)
G[b].append(a)
P1 = np.zeros(N+1, dtype=np.int64)
def dfs1(u):
st = [u]
while st:
v = st.pop()
p = P1[v]
for u in G[v]:
if p != u:
st.append(u)
P1[u] = v
dfs1(U)
path_u2v = [U]
v = V
while v != U:
v = P1[v]
path_u2v.append(v)
path_u2v.reverse()
l = len(path_u2v)
half = (l-2) // 2
c = path_u2v[half]
ng = path_u2v[half+1]
Depth = np.zeros(N+1, dtype=np.int64)
def dfs2(c):
st = [c]
P = np.zeros(N+1, dtype=np.int64)
while st:
v = st.pop()
p = P[v]
d = Depth[v]
for u in G[v]:
if p != u and u != ng:
st.append(u)
P[u] = v
Depth[u] = d + 1
dfs2(c)
c_ = path_u2v[l-1-half]
v = c_
while v != c:
Depth[v] = 0
v = P1[v]
d = l%2
ans = max(Depth) + half + d
return ans
# >>> numba compile >>>
numba_config = [
[solve, "i8(i8,i8,i8,i8[:,:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
vars()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
from numba import njit
for func, signature in numba_config:
vars()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
# <<< numba compile <<<
def main():
N, u, v = map(int, input().split())
if N==2:
print(0)
return
AB = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N-1, 2)
ans = solve(N, u, v, AB)
print(ans)
main()
|
string = input()
if string == "ARC": print("ABC")
else: print("ARC")
| 0 | null | 70,911,821,403,708 | 259 | 153 |
counter = 0
while True:
n = int(input())
counter += 1
if(n == 0):break
print('Case {}: {}'.format(counter,n))
|
# -*- coding: utf-8 -*-
"""
E - Travel by Car
https://atcoder.jp/contests/abc143/tasks/abc143_e
"""
import sys
from scipy.sparse.csgraph import floyd_warshall
def main(args):
N, M, L = map(int, input().split())
g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
for i in range(N+1):
g1[i][i] = 0
for _ in range(M):
A, B, C = map(int, input().split())
g1[A][B] = g1[B][A] = C
d1 = floyd_warshall(g1)
g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
for i in range(N+1):
for j in range(N+1):
if i == j:
g2[i][j] = 0
elif d1[i][j] <= L:
g2[i][j] = g2[j][i] = 1
d2 = floyd_warshall(g2)
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1)
if __name__ == '__main__':
main(sys.argv[1:])
| 0 | null | 86,833,683,788,828 | 42 | 295 |
n=int(input())
print((n//2)+(n%2))
|
X, K, D = map(int, input().split())
X = abs(X)
q, m = divmod(X, D)
if q >= K:
print(X-K*D)
elif (q+K)%2==0:
print(m)
else:
print(-(m-D))
| 0 | null | 32,144,437,121,930 | 206 | 92 |
import numpy as np
a,b,h,m=list(map(int,input().split()))
deg = min(abs(h*360/12+m*360/12/60-m*360/60),360-abs(h*360/12+m*360/12/60-m*360/60))
theta = deg * np.pi /180
ans = np.sqrt(np.power(a,2)+np.power(b,2)-2*a*b*np.cos(theta))
print(ans)
|
import math
rad = math.pi/180
A, B, H, M = map(int, input().split())
x = 6*M*rad
y = (60*H + M) * 0.5 * rad
print(math.sqrt(A**2 + B**2 -2*A*B*math.cos(x-y)))
| 1 | 20,231,144,023,932 | null | 144 | 144 |
# coding: utf-8
n = int(input())
A = list(map(int, input().split()))
mini = 1
c = 0
for i in range(n):
mini = i
for j in range(i, n):
if A[j] < A[mini]:
mini = j
A[i], A[mini] = A[mini], A[i]
if mini != i:
c += 1
print(" ".join(map(str, A)))
print(c)
|
n = int(input())
k = [int(i) for i in input().split()]
m = 0
for i in range(n):
minj = i
for j in range(i,n):
if k[j] < k[minj]:
minj = j
x = k[i]
k[i] = k[minj]
k[minj]=x
if k[i] != k[minj]:
m += 1
print(' '.join(map(str, k)))
print(m)
| 1 | 20,686,659,370 | null | 15 | 15 |
n = int(input())
s = list(input())
count_red = s.count('R')
count_white = 0
A = []
for i in range(n):
if s[i] == 'R':
count_red -= 1
if s[i] == 'W':
count_white += 1
A.append(max(count_red, count_white))
if len(set(s)) == 1 and list(set(s)) == ['W']:
print(0)
else:
print(min(A))
|
while True:
s=input()
if s=="0":
break
n=list(map(int, list(s)))
print(sum(n))
| 0 | null | 3,910,114,951,500 | 98 | 62 |
letters = 'abcdefghijklmnopqrstuvwxyz'
c = input("")
res = ""
for i in range(len(letters)):
if c == letters[i]:
res+=letters[i + 1]
print(res)
|
l ='abcdefghijklmnopqrstuvwxyz'
c = input()
x = l.index(c)
print(l[x + 1])
| 1 | 92,324,125,874,130 | null | 239 | 239 |
inputValues = [int(i) for i in input().split()]
n = inputValues[0]
k = inputValues[1]
res = n%k
res = min(k-res,res)
print(res)
|
n, k = map(int, input().split())
tmp = n%k
print(min(tmp, abs(tmp-k)))
| 1 | 39,147,776,113,600 | null | 180 | 180 |
i=0
j = int(input())
numlist = list(int(i) for i in input().split())
while i < j-1:
print(numlist[j-i-1],end='')
print(' ',end='')
i += 1
print(numlist[0])
|
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
mod = 1000000007
def ST():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(MI())
N, K = MI()
MAX = sum(range(N - K + 2, N + 1))
MIN = sum(range(0, K - 1))
ans = 0
for k in range(K, N + 2):
MAX += N - k + 1
MIN += k - 1
ans += (MAX - MIN + 1) % mod
print(ans % mod)
| 0 | null | 17,096,329,767,440 | 53 | 170 |
N, X, M = map(int, input().split())
existence = [False] * M
a = []
A = X
for i in range(N):
if existence[A]:
break
existence[A] = True
a.append(A)
A = A * A % M
for i in range(len(a)):
if a[i] == A:
break
loop_start = i
result = sum(a[:loop_start])
a = a[loop_start:]
N -= loop_start
loops = N // len(a)
remainder = N % len(a)
result += sum(a) * loops + sum(a[:remainder])
print(result)
|
total = 0
n = int(input())
for i in range(1, n + 1):
if not ((i % 5 == 0) or (i % 3 == 0)):
total = total + i
print(total)
| 0 | null | 18,843,297,641,856 | 75 | 173 |
# C - Traveling Salesman around Lake
k,n = map(int,input().split())
a = list(map(int,input().split()))
bet = [a[0]+k-a[n-1]]
for i in range(n-1):
bet.append(a[i+1]-a[i])
print(k-max(bet))
|
a,b = map(int, input().split())
hirosa = a*b
nagasa = 2*(a+b)
print(hirosa,nagasa)
| 0 | null | 21,818,058,281,712 | 186 | 36 |
R = int(input())
print(R*2*3.14159265358979)
|
import sys
import math
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
r = int(readline())
print(r * 2 * math.pi)
if __name__ == '__main__':
solve()
| 1 | 31,329,120,223,714 | null | 167 | 167 |
HW = input().split()
H = int(HW[0])
W = int(HW[1])
while H != 0 or W != 0:
for i in range(H):
for j in range(W):
print("#", end = "")
print("")
HW = input().split()
H = int(HW[0])
W = int(HW[1])
print("")
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
n, m, k = map(int, input().split())
a = tuple(accumulate(map(int, input().split())))
b = tuple(accumulate(map(int, input().split())))
r = bisect(b, k)
for i1, ae in enumerate(a):
if k < ae:
break
r = max(r, bisect(b, k - ae) + i1 + 1)
print(r)
if __name__ == '__main__':
main()
| 0 | null | 5,795,819,263,460 | 49 | 117 |
h, w, k = map(int, input().split())
s = [""] * h
for i in range(h):
s[i] = input()
ans = [[0 for i in range(w)] for j in range(h)]
lcnt = [0] * h
cnt = 0
for i in range(h):
for j in range(w):
if s[i][j] == "#":
lcnt[i] += 1
flag = 0
mem = [0] * w
a = 1
for i in range(h):
t = 0
j = 0
while t < lcnt[i]:
if s[i][j] == "#":
t += 1
ans[i][j] = a
a += 1
else:
ans[i][j] = a
j += 1
for l in range(j, w):
ans[i][l] = a - 1
for i in range(h):
if lcnt[i] > 0:
for j in range(w):
mem[j] = ans[i][j]
break
t = 0
while lcnt[t] == 0:
for i in range(w):
ans[t][i] = mem[i]
lcnt[t] = 1
t += 1
for i in range(1, h):
if lcnt[i] == 0:
for j in range(w):
ans[i][j] = ans[i - 1][j]
for i in range(h):
for j in range(w):
print(ans[i][j], end="")
if j != w - 1:
print(" ", end="")
print()
|
N, M, K = map(int, input().split())
chess = [input() for i in range(N)]
ans = [[0 for i in range(M)] for j in range(N)]
index = 0
def ok(r, h, t):
for i in range(h, t+1):
if ans[r][i] or chess[r][i] == '#':
return False
return True
def color(r, h, t):
for i in range(h, t+1):
ans[r][i] = index
# mother fucker
for i in range(N):
j = 0
while j < M:
if chess[i][j] == '.':
j += 1
continue
index += 1
l = j - 1
while l >= 0 and chess[i][l] == '.' and ans[i][l] == 0:
l -= 1
l += 1
r = j + 1
while r < M and chess[i][r] == '.' and ans[i][r] == 0:
r += 1
r -= 1
# [l,r]
# color
color(i, l, r)
for k in range(i-1, -1, -1):
if ok(k, l, r):
color(k, l, r)
else:
break
for k in range(i+1, N):
if ok(k, l, r):
color(k, l, r)
else:
break
j = r + 1
for i in range(N):
for j in range(M-1):
print(ans[i][j], end='')
print(' ', end='')
print(ans[i][M-1], end='')
print("")
| 1 | 143,951,823,863,762 | null | 277 | 277 |
def main(S, T):
ans = len(T)
for w in range(len(S)-len(T)+1):
tmp = len(T)
for s, t in zip(S[w:w+len(T)], T):
if s == t:
tmp -= 1
if tmp < ans:
ans = tmp
return ans
if __name__ == '__main__':
S = input()
T = input()
ans = main(S, T)
print(ans)
|
S = input()
T = input()
# S = "cabacc"
# T = "abc"
lt = len(T)
def diff(s1, s2):
d = len(s1)
d -= len([i for i,j in zip(s1, s2) if i == j])
return d
dlen = 1000000000
for i in range(len(S)):
if i + lt <= len(S):
dlen = min(dlen, diff(T, S[i:i+lt]))
print(dlen)
| 1 | 3,680,693,435,962 | null | 82 | 82 |
import statistics
def main():
n = int(input())
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
a[i], b[i] = map(int, input().split())
amed = statistics.median(a)
bmed = statistics.median(b)
if n % 2:
print(int(bmed - amed + 1))
else:
print(int((bmed - amed) * 2 + 1))
if __name__ == '__main__':
main()
|
from bisect import bisect_right as br
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MergeSort(aa, left=0, right=-1):
def merge(aa, left2, mid2, right2):
res=0
inf = float("inf")
L = aa[left2:mid2] + [inf]
R = aa[mid2:right2] + [inf]
Li = Ri = 0
for ai in range(left2, right2):
res+=1
if L[Li] < R[Ri]:
aa[ai] = L[Li]
Li += 1
else:
aa[ai] = R[Ri]
Ri += 1
return res
res=0
if right == -1: right = len(aa)
if left + 1 < right:
mid = (left + right) // 2
res+=MergeSort(aa, left, mid)
res+=MergeSort(aa, mid, right)
res+=merge(aa, left, mid, right)
return res
def main():
n=int(input())
aa=list(map(int, input().split()))
cnt=MergeSort(aa)
print(*aa)
print(cnt)
main()
| 0 | null | 8,688,000,880,192 | 137 | 26 |
n = input()
s = input().split()
q = input()
t = input().split()
ans = 0
for c1 in t:
for c2 in s:
if c1 == c2:
ans += 1
break
print(ans)
|
import sys
n = int(sys.stdin.readline()[:-1])
S = sorted(list(map(int, (sys.stdin.readline()[:-1]).split())))
q = int(sys.stdin.readline()[:-1])
T = sorted(list(map(int, (sys.stdin.readline()[:-1]).split())))
count = 0
for i in T:
x = 0
while x < len(S):
if i == S[x]:
count += 1
S = S[x:]
break
x += 1
print(count)
| 1 | 67,193,411,220 | null | 22 | 22 |
X=int(input())
x=100
ans=0
while x<X:
x=101*x//100
ans+=1
print(ans)
|
K=int(input())
cnt=0
n=100
while n<K:
n+=n//100
cnt+=1
print(int(cnt))
| 1 | 27,250,749,997,998 | null | 159 | 159 |
from functools import lru_cache
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int,read().split())
@lru_cache(None)
def F(N, K):
if N < 10:
if K == 0:
return 1
if K == 1:
return N
return 0
q, r = divmod(N, 10)
ret = 0
if K >= 1:
ret += F(q, K-1) * r
ret += F(q-1, K-1) * (9-r)
ret += F(q, K)
return ret
print(F(N, K))
|
s = input()
t = input()
if s == t[:-1]: print('Yes')
else: print('No')
| 0 | null | 48,767,705,948,890 | 224 | 147 |
A, B = input().split()
A = int(A)
B = int(B.replace('.',''))
print(f'{A*B//100}')
|
A, B = [s for s in input().split()]
A = int(A)
B = int(float(B) * 100 + .5)
C = A * B
ans = int(C // 100)
print(ans)
| 1 | 16,483,736,205,428 | null | 135 | 135 |
# -*- coding:utf-8 -*-
import math
r = float(input())
a = r*r*math.pi
d = 2*r*math.pi
print(a,d,sep=' ')
|
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, a, b = map(int, input().split())
MOD = 10**9 + 7
# 二項展開より 2**n - 1 - nCa - nCb を MOD 10**9 + 7 で求めればよい
def combination(n, a):
# nCk = n! / k! (n-k)! のうち、 n!/(n-k)! を計算する
res = 1
div = 1
for i in range(a):
res *= n-i
res %= MOD
div *= a - i
div %= MOD
# print(f'n {n}, a {a}, res {res}, div {div}')
res = (res * pow(div, MOD-2, MOD)) % MOD
return res
count = (pow(2, n, MOD) - 1 - combination(n, a) - combination(n, b)) % MOD
print(count)
| 0 | null | 33,309,597,649,340 | 46 | 214 |
import sys
youbi = ["MON", "TUE", "WED", "THU", "FRI", "SAT"]
S = input()
if S == "SUN":
print(7)
sys.exit()
for i, youbi in enumerate(youbi):
if S == youbi:
print(6-i)
|
youbi = ['SUN','MON','TUE','WED','THU','FRI','SAT']
y = input()
for i in range(7):
if y == youbi[i]:
print(7-i)
| 1 | 133,052,477,906,208 | null | 270 | 270 |
N = int(input())
N += 1
print(N // 2)
|
L, R, d = map(int, input().split())
lst = list()
for x in range(R+1):
y = d * x
if y>=L and y<=R:
lst.append(y)
print(len(lst))
| 0 | null | 33,367,033,105,562 | 206 | 104 |
def main():
n = int(input())
s = input()
if n < 4:
print(0)
return
ans = s.count("R") * s.count("G") * s.count("B")
for i, si in enumerate(s[:-2]):
for j, sj in enumerate(s[i+1:-1]):
if si == sj:
continue
if i + 2*j+2 < n and si != s[i + 2*j+2] != sj:
ans -= 1
print(ans)
if __name__ == '__main__':
main()
|
n,k = map(int,input().split())
w = []
for loop in range(n):
w.append(int(input()))
left = max(w)
right = 100000 * 10000
mid = (left+right)//2
ans = right
def check(P):
tmp_sum = 0
cnt = 1
for loop in range(n):
if tmp_sum + w[loop] <= P:
tmp_sum += w[loop]
else:
tmp_sum = w[loop]
cnt += 1
if cnt > k:
return False
return True
while left <= right:
if check(mid):
ans = mid
right = mid - 1
else:
left = mid + 1
mid = (left+right)//2
print(ans)
| 0 | null | 18,081,308,845,432 | 175 | 24 |
S = str(input())
s = list(map(str,S))
if s[2] == s[3] and s[4] == s[5]:
print('Yes')
else:
print('No')
|
s = input()
ans = "No"
if s[2]==s[3] and s[4]==s[5] :
ans = "Yes"
print(ans)
| 1 | 41,789,173,748,388 | null | 184 | 184 |
i=0
while True:
i+=1
a=input()
if a==0:
break
else:
print("Case "+str(i)+": "+str(a))
|
(lambda *_: None)(
*map(print,
map('Case {0[0]}: {0[1]}'.format,
enumerate(iter(input, '0'), 1))))
| 1 | 479,943,310,912 | null | 42 | 42 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, a, b = map(int, input().split())
MOD = 10**9 + 7
# 二項展開より 2**n - 1 - nCa - nCb を MOD 10**9 + 7 で求めればよい
def combination(n, a):
# nCk = n! / k! (n-k)! のうち、 n!/(n-k)! を計算する
res = 1
div = 1
for i in range(a):
res *= n-i
res %= MOD
div *= a - i
div %= MOD
# print(f'n {n}, a {a}, res {res}, div {div}')
res = (res * pow(div, MOD-2, MOD)) % MOD
return res
count = (pow(2, n, MOD) - 1 - combination(n, a) - combination(n, b)) % MOD
print(count)
|
def a():
l = map(int, input().split())
res = [i + 1 for i, v in enumerate(l) if v == 0]
if len(res) > 1:
r = res[-1]
else:
r = res[0]
print(r)
if __name__ == "__main__":
a()
| 0 | null | 39,721,928,397,030 | 214 | 126 |
print((lambda a: len([i for i in range(a[0], a[1]+1) if a[2] % i == 0]))(list(map(int, input().split()))))
|
a, b, c = (int(i) for i in input().split())
divisor = 0
for i in range(a, b + 1):
if c % i == 0:
divisor += 1
print(str(divisor))
| 1 | 568,614,652,870 | null | 44 | 44 |
n = int(raw_input())
S = []
S = map(int, raw_input().split())
q = int(raw_input())
T = []
T = map(int, raw_input().split())
count = 0
for i in T:
if i in S:
count += 1
print count
|
n = input()
s = list(map(int, input().split()))
nn = input()
t = list(map(int, input().split()))
t_and_s = len(set(s) & set(t))
print(t_and_s)
| 1 | 65,234,193,660 | null | 22 | 22 |
str1 = input()
str2 = input()
idx = 0
cnt = 0
for _ in range(len(str1)):
if str1[idx] != str2[idx]:
cnt += 1
idx += 1
print(cnt)
|
s = input()
t = input()
c = 0
for i in range(len(s)):
if s[i] != t[i]:
c += 1
print(str(c))
| 1 | 10,431,204,849,260 | null | 116 | 116 |
NUM = list(map(int,input().split()))
if(NUM[0] > NUM[1]):
print("safe")
elif(NUM[0] <= NUM[1]):
print("unsafe")
|
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: 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)]
INF = float('inf')
def solve():
s, w = MI()
if w >= s:
print('unsafe')
else:
print('safe')
if __name__ == '__main__':
solve()
| 1 | 29,195,125,703,118 | null | 163 | 163 |
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
tmp = [n+1 for n in range(N)]
parms = list(itertools.permutations(tmp, N))
for i in range(len(parms)):
if parms[i] == P:
a = i
if parms[i] == Q:
b = i
print(abs(a-b))
|
N, K = map(int, input().split())
A = [-1] * (N+1)
for i in range(K):
d_list = int(input())
B = input().split()
B = [int(x) for x in B]
for i in range(1, N+1):
if i in B:
A[i] = 1
count = 0
for i in range(1, N+1):
if A[i] == -1:
count += 1
print(count)
| 0 | null | 62,552,042,764,402 | 246 | 154 |
def GCD_calc(A,B):
if(A>=B):
big = A
small = B
else:
big = B
small = A
r=big%small
if r == 0:
return small
else:
return GCD_calc(small,r)
a,b = map(int,input().split())
print(GCD_calc(a,b))
|
def dictionary():
n = int(input())
s = set()
for i in range(n):
command, value = input().split()
if command == 'insert':
s.add(value)
elif command == 'find':
if value in s:
print('yes')
else:
print('no')
if __name__ == '__main__':
dictionary()
| 0 | null | 42,385,719,142 | 11 | 23 |
import sys
n = int(input())
dic =set()
t = sys.stdin.readlines()
for i in t:
i,op = i.split()
if i == 'insert':
dic.add(op)
else:
if op in dic:
print('yes')
else:
print('no')
|
n = int(input())
dic = set()
for i in range(n):
x = input()
if 'insert' in x:
dic.add(x.strip('insert '))
else :
if x.strip('find ') in dic:
print('yes')
else :
print('no')
| 1 | 78,298,994,038 | null | 23 | 23 |
A, B, C, K = map(int, input().split())
if K <= A:
print(K)
elif K > A and K <= A + B:
print(A)
else:
K -= A + B
print(A - K)
|
a, b, c, k = map(int, input().split())
ans = 0
ans += min(a, k)
k -= min(a, k)
k -= min(b, k)
ans -= min(c, k)
print(ans)
| 1 | 21,786,445,729,190 | null | 148 | 148 |
import math
a = int(input())
b = a /1000
B = math.ceil(b)
print(B * 1000 -a)
|
n = int(input())
rem = n%1000
if rem!=0:rem = 1000 - rem
print(rem)
| 1 | 8,406,719,010,354 | null | 108 | 108 |
# your code goes here
i = int(input())
print(i * i * i)
|
n = int(input())
x = list(map(int, input().split()))
m = 10**9
for i in range(min(x),max(x)+1):
t = 0
for h in x:
t += (h-i)**2
if t < m:
m = t
print(m)
| 0 | null | 32,699,103,700,890 | 35 | 213 |
from enum import Enum
from queue import Queue
import collections
import sys
import math
class Info:
def __init__(self,arg_start,arg_end,arg_S):
self.start = arg_start
self.end = arg_end
self.S = arg_S
LOC=[]
POOL=[]
line = input()
loc = 0
sum_S = 0
for ch in line:
if ch == '\\':
LOC.append(loc)
elif ch == '/':
if len(LOC) ==0:
continue
tmp_start = int(LOC.pop())
tmp_end = loc
tmp_S = tmp_end-tmp_start
sum_S += tmp_S
while len(POOL) > 0:
if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
tmp_S += POOL[-1].S
POOL.pop()
else:
break
POOL.append(Info(tmp_start,tmp_end,tmp_S))
else:
pass
loc += 1
print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")
while len(POOL) > 0:
print(" %d"%(POOL[0].S),end = "") #先頭から
POOL.pop(0)
print()
|
# F - Sugoroku
import sys
sys.setrecursionlimit(10 ** 9)
n,m = map(int,input().split())
s = input()
# r[i]:sを後ろから見ていって、iから最小何手でゴールするかを求める。
INF = float('inf')
r = [INF for _ in range(n+1)]
r[n] = 0
idx = n
for i in range(n-1,-1,-1):
while(idx-i > m or r[idx] == INF):
idx -= 1
if idx <= i:
print(-1)
exit()
if s[i] == '0':
r[i] = r[idx]+1
p = r[i]
#print(r)
# rを先頭から見ていき、rの数字が変わる直前まで進むようにすれば
# 最短で辞書順最小なルートが求まる。
ans = []
c = 0
for i in range(n+1):
if r[i] != INF and r[i] != p:
p = r[i]
ans.append(c)
c = 1
else:
c += 1
print(*ans)
# mnr = [m for _ in range(n+1)]
# mnl = n+1
# def dfs(x,c):
# global mnr,mnl
# #print(x,c)
# if x == n:
# #print(r)
# if len(r) < mnl or (len(r) == mnl and r < mnr):
# mnr = r[:]
# mnl = len(r)
# return True
# if c >= mnl or x > n or s[x] == '1':
# return False
# for i in range(m,0,-1):
# r.append(i)
# dfs(x+i,c+1)
# r.pop()
# dfs(0,0)
# if mnl < n+1:
# print(*mnr)
# else:
# print(-1)
| 0 | null | 69,916,141,483,174 | 21 | 274 |
import sys
def main():
s = input()
if len(s) % 2 == 1:
print('No')
sys.exit()
s1 = s[::2]
s2 = s[1::2]
s1t = [c == 'h' for c in s1]
s2t = [c == 'i' for c in s2]
if all(s1t) and all(s2t):
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
|
S = input()
import re
print('Yes' if re.match(r'^(hi)+$', S) else 'No')
| 1 | 53,121,964,392,480 | null | 199 | 199 |
n = int(input())
ac = wa = tle = re = 0
for i in range(n):
s = input()
if s == "AC":
ac += 1
elif s == "WA":
wa += 1
elif s == "TLE":
tle += 1
elif s == "RE":
re += 1
print("AC x", ac)
print("WA x", wa)
print("TLE x ", tle)
print("RE x", re)
|
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 | 20,334,557,602,090 | 109 | 168 |
x = int(input())
import math
def check(n):
if n == 1: return False
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
n = x
while check(n) == False:
n += 1
print(n)
|
X=int(input())
while True:
for x in range(2,X):
if X%x==0:
break
else:
print(X)
break
X+=1
| 1 | 105,659,041,460,430 | null | 250 | 250 |
x=input()
y=x.split(" ")
n=int(y[0])
g=input()
h=g.split(" ")
su=0
for b in h:
su+=int(b)
if(su>n):
print(-1)
else:
print(n-su)
|
N,X = map(int,input().split())
Y = N - sum(map(int,input().split()))
print(("-1",Y)[Y >= 0])
| 1 | 31,888,349,657,306 | null | 168 | 168 |
a_len = int(input())
a = {n for n in input().split(" ")}
b_len = int(input())
b = {n for n in input().split(" ")}
print(len(a & b))
|
#coding: Shift_JIS
def set_array(a,n):
str=input()
array=str.split()
for i in range(n):
a.append(int(array[i]))
n=int(input())
S=[]
set_array(S,n)
q=int(input())
T=[]
set_array(T,q)
C=0
def linear_search(S,x):
S.append(x)
l=len(S)
i=0
while(l>i):
if S[i]==x:
break
i=i+1
S.pop(-1)
if i!=l-1:
return 1;
else:
return 0;
for v in T:
C+=linear_search(S,v)
print(C)
| 1 | 68,376,142,072 | null | 22 | 22 |
from collections import Counter
n = int(input())
a = Counter(map(int, input().split()))
for i in range(1, n + 1):
print(a[i])
|
N = int(input())
A = [0]*(N)
for i in input().split():
A[int(i)-1] = A[int(i)-1]+1
for i in A:
print(i)
| 1 | 32,459,692,503,468 | null | 169 | 169 |
n=int(input())
z_max,z_min=-10**10,10**10
w_max,w_min=-10**10,10**10
for i in range(n):
a,b=map(int,input().split())
z=a+b
w=a-b
z_max=max(z_max,z)
z_min=min(z_min,z)
w_max=max(w_max,w)
w_min=min(w_min,w)
print(max(z_max-z_min,w_max-w_min))
|
# coding:UTF-8
import sys
def resultSur97(x):
return x % (1000000000 + 7)
if __name__ == '__main__':
# ------ 入力 ------#
# 1行入力
n = int(input()) # 数字
# a = input() # 文字列
# aList = list(map(int, input().split())) # スペース区切り連続数字
# aList = input().split() # スペース区切り連続文字列
# aList = [int(c) for c in input()] # 数字→単数字リスト変換
# 定数行入力
x = n
# aList = [int(input()) for _ in range(x)] # 数字
# aList = [input() for _ in range(x)] # 文字
aList = [list(map(int, input().split())) for _ in range(x)] # スペース区切り連続数字(行列)
# aList = [input().split() for _ in range(x)] # スペース区切り連続文字
# aList = [[int(c) for c in input()] for _ in range(x)] # 数字→単数字リスト変換(行列)
# スペース区切り連続 数字、文字列複合
# aList = []
# for _ in range(x):
# aa, bb = input().split()
# a.append((int(aa), bb))
# ------ 処理 ------#
zmin = aList[0][0] + aList[0][1]
zmax = aList[0][0] + aList[0][1]
wmin = aList[0][0] - aList[0][1]
wmax = aList[0][0] - aList[0][1]
for i in range(len(aList)):
x = aList[i][0]
y = aList[i][1]
z = x + y
w = x - y
if z < zmin:
zmin = z
if z > zmax:
zmax = z
if w < wmin:
wmin = w
if w > wmax:
wmax = w
disMax = max(zmax-zmin, wmax-wmin)
# ------ 出力 ------#
print("{}".format(disMax))
# if flg == 0:
# print("YES")
# else:
# print("NO")
| 1 | 3,451,700,248,060 | null | 80 | 80 |
def make_divisors(n):
ans = 10 ** 12 + 10
i = 1
while i*i <= n:
if n % i == 0:
t = 0
if i != n // i:
t = i + (n//i) - 2
else:
t = i * 2 - 2
#print(i, n//i, t)
if ans > t:
ans = t
i += 1
return ans
n = int(input())
print(make_divisors(n))
|
n = int(input())
ans = 0
for i in range(1, n):
ans += n//i if n%i != 0 else n//i-1
print(ans)
| 0 | null | 82,099,571,252,324 | 288 | 73 |
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,a,b=n1()
def comb(n,k):
nCk = 1
MOD = 10**9+7
for i in range(n-k+1, n+1):
nCk *= i
nCk %= MOD
for i in range(1,k+1):
nCk *= pow(i,MOD-2,MOD)
nCk %= MOD
return nCk
MOD = 10**9+7
a1=comb(n, a)
b1=comb(n, b)
ans=pow(2,n,MOD)-a1-b1-1
print(ans%MOD)
|
n, a, b = map(int, input().split())
ans = pow(2,n,10**9+7)-1
A = 1
for i in range(1,a+1):
A = (A*(n-i+1))%(10**9+7)
x = pow(i,10**9+5,10**9+7)
A *= x
B = 1
for i in range(1,b+1):
B = (B*(n-i+1))%(10**9+7)
y = pow(i,10**9+5,10**9+7)
B *= y
ans = ans-A-B
if ans < 0:
ans = ans+10**9+7
ans = int(ans%(10**9+7))
print(ans)
| 1 | 65,865,267,817,560 | null | 214 | 214 |
ri = lambda S: [int(v) for v in S.split()]
def rii(): return ri(input())
a, b = rii()
print(min(str(a) * b, str(b) * a))
|
dic = {}
pat = ['S','H','C','D']
rank = [k for k in range(1,14)]
for k in pat:
for j in rank:
dic[(k,j)]=0
n = int(raw_input())
for k in range(n):
p,r = raw_input().split()
r = int(r)
dic[(p,r)] +=1
for k in pat:
for j in rank:
if dic[(k,j)]==0:
print '%s %d' % (k,j)
| 0 | null | 42,591,969,388,288 | 232 | 54 |
a,b,c,d = map(int,input().split())
answers = []
one = a*c
two = a*d
three = b*c
four = b*d
answers.append(one)
answers.append(two)
answers.append(three)
answers.append(four)
print(max(answers))
|
a,b,c,d=map(int,input().split())
m=max(a*c,a*d,b*c,b*d)
print(m)
| 1 | 3,054,097,795,968 | null | 77 | 77 |
N, K = map(int, input().split())
p=list(map(int,input().split()))
for i in range(N):
p[i]=(1+p[i])/2
ans=[0]*(N-K+1)
ans[0]=sum(p[:K])
for i in range(1, N-K+1):
ans[i]=ans[i-1]-p[i-1]+p[i+K-1]
print(max(ans))
|
N,K=map(int,input().split())
p=list(map(int,input().split()))
q=[]
q.append(0)
for i in range(len(p)):
q.append(q[-1]+p[i])
maxi=q[K]-q[0]
for i in range(1,N-K+1):
sub=q[K+i]-q[i]
if sub>=maxi:
maxi=sub
print((maxi+K)/2)
| 1 | 75,133,660,505,092 | null | 223 | 223 |
N,M,K = list(map(int, input().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N)
V = [[] for _ in range(N)]
for _ in range(M):
a,b = map(int, input().split())
a,b = a-1, b-1
V[a].append(b)
V[b].append(a)
uf.union(a,b)
for _ in range(K):
a,b = map(int, input().split())
a,b = a-1, b-1
if uf.same(a,b):
V[a].append(b)
V[b].append(a)
ans = [-1] * N
for i in range(N):
ans[i] = uf.size(i) - len(V[i]) - 1
print(" ".join(list(map(str, ans))))
|
import math
import itertools
n = int(input())
l = list(range(n))
pos_list =[list(map(int, input().split())) for _ in range(n)]
ans = 0
def clc_distandce(a,b):
[x1, y1] = a
[x2, y2] = b
dist = math.sqrt((a[0] - b[0])**2 + (a[1]-b[1])**2)
return dist
for i in itertools.permutations(l,n):
#print(i)
#print(list(i)[0])
for k in range(1,n):
dist = clc_distandce(pos_list[list(i)[k]],pos_list[list(i)[k-1]])
ans += dist
#print(ans)
#print()
print(ans/math.factorial(n))
| 0 | null | 104,926,426,019,328 | 209 | 280 |
import math
I = lambda: list(map(int, input().split()))
n, d, a = I()
l = []
for _ in range(n):
x, y = I()
l.append([x,y])
l.sort()
j = 0
limit = []
for i in range(n):
while l[j][0] - l[i][0] <= 2*d:
j+=1
if j == n: break
j-=1
limit.append(j)
ans = 0
num=[0]*(n+1)
cnt=0
for i in range(n):
l[i][1]-=(ans-cnt)*a
damage_cnt=max(0,(l[i][1]-1)//a + 1)
ans+=damage_cnt
num[limit[i]]+=damage_cnt
cnt+=num[i]
print(ans)
|
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
def zaatsu(nums):
ref = list(set(copy.copy(nums)))
ref.sort()
dic = dict()
for i, num in enumerate(ref):
dic[num] = i
return [dic[num] for num in nums]
def solve():
n, d, a = getList()
li = []
for i in range(n):
li.append(getList())
li.sort()
ichi = [x[0] for x in li]
imos = [0] * n
cur = 0
ans = 0
for i, (x, h) in enumerate(li):
cur -= imos[i]
hp = h - cur * a
if hp <= 0:
continue
thr = hp // a
if hp % a != 0:
thr += 1
ans += thr
cur += thr
owari = bisect_right(ichi, x + 2 * d)
if owari != n:
imos[owari] += thr
print(ans)
def main():
n = getN()
for _ in range(n):
solve()
return
if __name__ == "__main__":
# main()
solve()
| 1 | 82,370,391,816,640 | null | 230 | 230 |
#!/usr/bin/env python3
def main():
A, B, C, D = map(int, input().split())
print('Yes' if - (-A // D) >= -(-C // B) else 'No')
if __name__ == '__main__':
main()
|
a,b,c,d = list(map(int,input().split()))
while a > 0 or c > 0:
c -= b
if c <= 0:
exit(print('Yes'))
a -= d
if a <= 0:
exit(print('No'))
| 1 | 29,552,939,469,182 | null | 164 | 164 |
# coding: utf-8
def main():
a, b, c, d = map(int, input().split())
for _ in range(100):
c -= b
if c <= 0:
print("Yes")
break
a -= d
if a <=0:
print("No")
break
main()
|
import sys
S = input()
cond = (S[2]==S[3]) & (S[4]==S[5])
ans = "Yes" if cond else "No"
print(ans)
| 0 | null | 35,828,508,401,030 | 164 | 184 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def bs(ok, ng, solve):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
return ok
ans = bs(n, 0, lambda x: x * 1.08 >= n)
if int(ans * 1.08) == n:
print(ans)
else:
print(':(')
|
def resolve():
import math as m
N = int(input())
nn = m.ceil(N / 1.08)
if m.floor(nn * 1.08) == N:
print(nn)
else:
print(":(")
resolve()
| 1 | 125,643,473,161,668 | null | 265 | 265 |
from collections import *
import copy
N,K=map(int,input().split())
A=list(map(int,input().split()))
lst=[0]
for i in range(0,N):
lst.append((A[i]%K+lst[i])%K)
for i in range(len(lst)):
lst[i]-=i
lst[i]%=K
dic={}
count=0
for i in range(0,len(lst)):
if lst[i] in dic:
count+=dic[lst[i]]
dic[lst[i]]+=1
else:
dic.update({lst[i]:1})
a=i-K+1
if a>=0:
dic[lst[a]]-=1
print(count)
|
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
n,k=map(int,input().split())
A=list(map(int,input().split()))
S=[0]*(n+1)
for i in range(n):
S[i+1]=S[i]+A[i]
for i in range(n+1):
S[i]-=i
S[i]%=k
ans=0
D=defaultdict(int)
for i in range(n+1):
s=S[i]
ans+=D[s]
D[s]+=1
if(i>=k-1):
D[S[i-k+1]]-=1
print(ans)
resolve()
| 1 | 136,926,229,582,450 | null | 273 | 273 |
a, b = map(int, input().split())
ans = -1
for money in range(pow(10, 4)):
if int(money*0.08) == a and int(money*0.1) == b:
ans = money
break
print(ans)
|
import math
import fractions
import collections
import itertools
from collections import deque
S=input()
N=len(S)
cnt=0
l=[]
"""
cnt=0
p=10**9+7
for i in range(K,N+2):
cnt=(cnt+((N-i+1)*i)+1)%p
#print(((N-i+1)*i)+1)
print(cnt)
"""
amari=[0]*(N+1)
num=0
for i in range(N):
num=num+pow(10,i,2019)*int(S[N-1-i])
amari[i+1]=num%2019
#print(amari)
c=collections.Counter(amari)
values=list(c.values()) #aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys()) #先のvalue値に相当する要素のリスト(要素1,要素2,…)
#for i in range(len(key)):
# l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
for i in range(len(values)):
cnt=cnt+(values[i]*(values[i]-1))//2
print(cnt)
| 0 | null | 43,646,825,532,608 | 203 | 166 |
N = int(input())
t = 0
max_run_length = 0
for _ in range(N):
D1, D2 = map(int, input().split())
if D1 == D2:
t += 1
else:
t = 0
max_run_length = max(max_run_length, t)
if max_run_length >= 3:
print('Yes')
else:
print('No')
|
n = int(input())
ren = 0
for i in range(n):
a, b = (int(x) for x in input().split())
if a == b:
ren += 1
elif ren >= 3:
continue
else:
ren = 0
if ren >= 3:
print("Yes")
else:
print("No")
| 1 | 2,483,012,421,930 | null | 72 | 72 |
#coding:utf-8
#1_1_B
def gcd(x, y):
while x%y != 0:
x, y = y, x%y
return y
x, y = map(int, input().split())
print(gcd(x, y))
|
def gcd(x, y):
x, y = max(x, y), min(x, y)
while y != 0:
x, y = y, x % y
return x
X, Y = (int(s) for s in input().split())
print(gcd(X, Y))
| 1 | 7,720,493,312 | null | 11 | 11 |
a, b = map(int, raw_input().split())
print(str(a*b) + " " + str(2*(a+b)))
|
a, b = map(int, input().split())
A = str(a) * b
B = str(b) * a
print(A) if A < B else print(B)
| 0 | null | 42,273,305,730,526 | 36 | 232 |
H,W,M=map(int,input().split())
h,w,bomb=[0]*H,[0]*W,[]
for i in range(M):
a,b=map(int,input().split())
bomb.append((a-1,b-1))
h[a-1]+=1
w[b-1]+=1
max_h=max(h)
max_w=max(w)
bomb_and_max=0
for i,j in bomb:
if h[i]==max_h and w[j]==max_w:
bomb_and_max+=1
if bomb_and_max==h.count(max_h)*w.count(max_w):
print(max_h+max_w-1)
else:
print(max_h+max_w)
|
H, W, M = map(int, input().split())
R = [0]*H #各行にある爆弾の個数
C = [0]*W #各列にある爆弾の個数
bombs = []
for _ in range(M):
h, w = map(lambda x: int(x)-1, input().split())
R[h] += 1
C[w] += 1
bombs.append((h, w))
R_max = max(R)
C_max = max(C)
### Rが最大かつCが最大な座標であって、
# そこに爆弾がない場合があれば
# 答えがR_max+C_max
# なければR_max+C_max-1
count = 0 # 爆弾がある座標であって、Rが最大かつCが最大の組の個数
for bx, by in bombs:
if R[bx] == R_max and C[by] == C_max:
count += 1
count_R = R.count(R_max)
count_C = C.count(C_max)
if count >= count_R*count_C:
ans = R_max + C_max - 1
else:
ans = R_max + C_max
print(ans)
| 1 | 4,780,497,448,012 | null | 89 | 89 |
str = input()
if str=="ABC":
print("ARC")
else:
print("ABC")
|
import sys
def main():
s = input()
if len(s) % 2 == 1:
print('No')
sys.exit()
s1 = s[::2]
s2 = s[1::2]
s1t = [c == 'h' for c in s1]
s2t = [c == 'i' for c in s2]
if all(s1t) and all(s2t):
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 0 | null | 38,596,237,619,590 | 153 | 199 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
for i in range(H):
if i % 2:
print('.#' * (W // 2) + '.' * (W % 2))
else:
print('#.' * (W // 2) + '#' * (W % 2))
print()
|
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
H, N = il()
magic = [il() for _ in range(N)]
dp = [0] * (H + 1)
dp[0] = 0
for h in range(1, H + 1):
for n in range(N):
if n == 0:
if magic[n][0] <= h:
dp[h] = dp[h - magic[n][0]] + magic[n][1]
else:
dp[h] = magic[n][1]
else:
if magic[n][0] <= h:
dp[h] = min(dp[h], dp[h - magic[n][0]] + magic[n][1])
else:
dp[h] = min(dp[h], magic[n][1])
print(dp[-1])
if __name__ == '__main__':
main()
| 0 | null | 41,153,977,616,700 | 51 | 229 |
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
|
values = []
while True:
value = input().split()
if int(value[0]) == 0 and int(value[1]) == 0:
break
else:
values.append(value)
for value in values:
m = int(value[0])
n = int(value[1])
for i in range(m):
row_output = ""
for j in range(n):
if i == 0 or i == m -1:
row_output += "#"
else:
if j == 0 or j == n - 1:
row_output += "#"
else:
row_output += "."
print(row_output)
print()
| 1 | 821,351,807,162 | null | 50 | 50 |
N = int(input())
print(N//2 if N%2 else N//2-1)
|
n,k = map(int,input().split())
mod = 10**9+7
from itertools import accumulate
N = list(range(n+1))
N_acc = [0]+list(accumulate(N))
ans = 0
for i in range(k,n+2):
ans += ((N_acc[-1]-N_acc[-i-1])-N_acc[i]+1)%mod
print(ans%mod)
| 0 | null | 92,966,907,290,638 | 283 | 170 |
n=int(input())
dept=100000
for i in range(n):
dept*=1.05
if dept%1000!=0:
dept=dept-dept%1000+1000
print(int(dept))
|
n = int(input())
S = 100000
for i in range(n):
S = int(S*1.05)
slist = list(str(S))
if slist[-3:] == ['0','0','0'] :
S = S
else:
S = S - int(slist[-3])*100 - int(slist[-2])*10 - int(slist[-1])*1 + 1000
print(S)
| 1 | 1,036,941,088 | null | 6 | 6 |
h,a = map(int,input().split())
h -= 1
print(1 + h // a)
|
m, n = map(int, input().split())
print((m + n - 1)//n)
| 1 | 76,907,633,864,010 | null | 225 | 225 |
st = input().split()
ab = map(int, input().split())
rb = input()
di = dict(zip(st, ab))
di[rb] -= 1
print(*list(di.values()))
|
n = int(input())
s = input().rstrip()
i=0
j=n-1
c= 0
while i!=j:
while s[j]!='R' and j>i:
j-=1
while s[i]=='R' and j>i:
i+=1
if i!=j:
c+= 1
i+= 1
j-=1
if i>=j:
break
print(c)
| 0 | null | 39,050,767,463,488 | 220 | 98 |
import sys
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def MAP(): return map(int, input().split())
inf = sys.maxsize
h, w, k = MAP()
s = [[int(i) for i in STR()] for _ in range(h)]
ans = inf
for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(500)
hdiv = [1 for _ in range(h)]
for j in range(h - 1):
tmp = 2 ** j
hdiv[j] = 1 if i & tmp else 0
sh = sum(hdiv)
tmpans = sh - 1
wdiv = [0 for _ in range(w - 1)]
partsum = [0 for _ in range(sh + 1)]
j = 0
cnt = 0
while j < w: #O(2 * 10 ** 4)
tmp = 0
idx = 0
for kk in range(h): #O(10)
tmp += s[kk][j]
if hdiv[kk]:
partsum[idx] += tmp
tmp = 0
idx += 1
flag = True
for kk in range(sh + 1):
if partsum[kk] > k:
tmpans += 1
partsum = [0 for _ in range(sh + 1)]
flag = False
if flag:
j += 1
cnt = 0
else:
cnt += 1
if cnt > 2:
tmpans = inf
break
ans = min(ans, tmpans)
print(ans)
|
a, b = map(int, input().split())
c = str(a)*b
d = str(b)*a
my_list = [c, d]
my_list.sort()
print(my_list[0])
| 0 | null | 66,304,479,605,390 | 193 | 232 |
# ng, ok = 0, 10**9+1
n,k = map(int, input().split())
al = list(map(int, input().split()))
ng, ok = 0, 10**9+1
while abs(ok-ng) > 1:
mid = (ok+ng)//2
ok_flag = True
# ...
cnt = 0
for a in al:
cnt += (a-1)//mid
if cnt <= k:
ok = mid
else:
ng = mid
print(ok)
|
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0;r=10**10
while r-l>1:
x=(l+r)//2
ct=0
for i in range(n):
ct+=(a[i]-1)//x
if ct<=k:
r=x
else:
l=x
print(r)
| 1 | 6,455,372,643,830 | null | 99 | 99 |
height_list = []
for i in range(10):
height_list.append(input())
height_list.sort()
height_list.reverse()
for height in height_list[:3]:
print height
|
import sys
input = sys.stdin.readline
def main():
H, N = map(int, input().split())
A = []
B = []
for _ in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A_max = max(A)
dp = [1e14] * (H+A_max + 1) # ダメージ量がiの最小コスト
dp[0] = 0
for i in range(H):
for j in range(N):
dp[i+A[j]] = min(dp[i+A[j]], dp[i]+B[j])
ans = 1e30
for i in range(H, H+A_max+1):
ans = min(ans, dp[i])
print(ans)
main()
| 0 | null | 40,530,348,127,880 | 2 | 229 |
import math
def findNumberOfDigits(n, b):
dig = (math.floor(math.log(n) /math.log(b)) + 1)
return dig
n, k = map(int, input().strip().split())
print(findNumberOfDigits(n, k))
|
a=int(input())
b=''
for i in range(a):
b=b+'ACL'
print(b)
| 0 | null | 33,065,994,587,846 | 212 | 69 |
n = int(input())
a = list(map(int, input().split()))
a.sort()
m = a[-1]
c = [0] * (m + 1)
for ai in a:
for i in range(ai, m + 1, ai):
c[i] += 1
ans = 0
for ai in a:
if c[ai] == 1:
ans += c[ai]
print(ans)
|
while(True):
H, W = map(int, input().split())
if(H == W == 0):
break
first = False
for i in range(H):
print("#" * W)
print()
| 0 | null | 7,595,987,382,240 | 129 | 49 |
n = int(input())
ans = (n - 1) // 2
print(ans)
|
n,m = map(int,input().split(" "))
c = tuple(map(int,input().split(" ")))
m = min(c)
dp = [2**60 for _ in range(n+1)]
dp[0] = 0
for i in range(1,n+1):
for v in c:
if i >= v:
dp[i] = min(dp[i],dp[i-v]+1)
print(dp[n])
| 0 | null | 76,677,812,522,704 | 283 | 28 |
import itertools
a=int(input())
b=list(map(int,input().split()))
c=list(map(int,input().split()))
n=sorted(b)
m=list(itertools.permutations(n))
m=[list(i) for i in m]
print(abs(m.index(b)-m.index(c)))
|
import itertools
def main():
n = int(input())
p_list = list(itertools.permutations ([i+1 for i in range(n)]))
p = tuple(map(int, input().split(" ")))
q = tuple(map(int, input().split(" ")))
pn = 0
qn = 0
for i in range(len(p_list)):
if p == p_list[i]:
pn = i
if q == p_list[i]:
qn = i
print(abs(pn-qn))
if __name__ == "__main__":
main()
| 1 | 100,180,910,881,050 | null | 246 | 246 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
A1 = sum(A)
if N - A1 >= 0:
print(N - A1)
else:
print("-1")
|
N, M = map(int, input().split())
A_list = list(map(int, input().split()))
for i in range(M):
N -= A_list[i]
if N < 0:
print(-1)
break
if i == M-1:
print(N)
| 1 | 31,922,807,774,660 | null | 168 | 168 |
import math
A,B = map(int,input().split())
#print(math.gcd(A,B))
C = A*B //(math.gcd(A,B))
print(C)
|
x=input()
x=x*x*x
print(x)
| 0 | null | 56,717,517,981,982 | 256 | 35 |
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
n = ni()
s = str(n)
K = ni()
dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(len(s) + 1)]
dp[0][0][0] = 1
for i in range(len(s)):
for j in range(K + 1):
for k in range(2):
dmax = 9 if k else int(s[i])
for d in range(dmax + 1):
ni = i + 1
nj = j + (d != 0)
nk = k | (d < dmax)
dp[ni][nj][nk] += dp[i][j][k]
print(dp[len(s)][K][0] + dp[len(s)][K][1])
|
N = input()
K = int(input())
# K = 1の時の組み合わせを求める関数
def func_1(N):
Nm = int(N[0])
return Nm + 9 * (len(N) - 1)
# K = 2の時の組み合わせを求める関数
def func_2(N):
#NはStringなので
#print(N[0])
Nm = int(N[0])
m = len(N)
#if m == 1:
# print("0")
#print((Nm-1)*(m-1)*9)
#print((m - 1) * (m - 2) * 9 * 9 / 2)
x = int(N) - Nm * pow(10, m-1)
#print(x)
#print(1)
#print(func_1(str(x)))
return int((Nm-1)*(m-1)*9+(m-1)*(m-2)*9*9/2+func_1(str(x)))
def func_3(N):
#print("OK")
Nm = int(N[0])
m = len(N)
# if m == 1 or m == 2:
# print("0")
return int(pow(9,3)*(m-1)*(m-2)*(m-3)/6+(Nm-1)*(m-1)*(m-2)*9*9/2+func_2(str(int(N)-Nm*(10**(m-1)))))
if K == 1:
print(func_1(N))
elif K == 2:
print(func_2(N))
elif K == 3:
print(func_3(N))
| 1 | 76,320,888,659,548 | null | 224 | 224 |
N = int(input())
if N % 2 == 0:
result = N//2 - 1
else:
result = N//2
print(result)
|
import math
a = math.ceil(int(input())/2)
print(int(a-1))
| 1 | 153,098,249,925,280 | null | 283 | 283 |
def solve():
N=n=int(input())
q=int(n**0.5)
ans=0
for d in range(2,q+1) :
a=0
while n % d == 0 :
a+=1
n//=d
if a>0 :
ans+=int(((a*8+1)**0.5-1)/2)
if n > 1 :
ans+=1
return ans
print(solve())
|
import sys
import bisect
N = int(input())
a = list(map(int,input().split()))
numdic = {}
for i, num in enumerate(a):
if num not in numdic:
numdic[num] = [i+1]
else:
numdic[num].append(i+1)
if 1 not in numdic:
print(-1)
sys.exit()
nowplace = 0
count = 0
for i in range(1,N+1):
if i not in numdic:
break
else:
place = bisect.bisect_right(numdic[i], nowplace)
if place >= len(numdic[i]):
break
else:
nowplace = numdic[i][place]
count += 1
print(N-count)
| 0 | null | 66,113,334,668,160 | 136 | 257 |
import sys
n = int(sys.stdin.readline())
dict = {}
for _ in range(n):
op, key = input().split()
if op == "insert":
dict[key] = "insert"
continue
if op == "find":
print("yes") if key in dict.keys() else print("no")
|
n = int(input())
d = {}
for i in range(n):
cmd = input()
if cmd[0] == 'i':
d[cmd[7:]] = 0
else:
print('yes' if cmd[5:] in d else 'no')
| 1 | 80,673,088,760 | null | 23 | 23 |
# coding: utf-8
# 二分探索(応用)
def loading(pack_list, k, q):
truck = 0
idx = 0
for pack in pack_list:
if pack > q:
return False
if truck + pack > q:
idx += 1
truck = 0
truck += pack
if truck > 0:
idx += 1
return False if idx > k else True
if __name__ == "__main__":
n, k = [int(i) for i in input().split()]
pack = []
for _ in range(n):
pack.append(int(input()))
min = 0
max = int(1E20)
# min = sum(pack) // n
# max = sum(pack)
q = (max + min) // 2
res = loading(pack, k, q)
while min + 1 != max:
min, max = [min, q] if res else [q, max]
q = (max + min) // 2
res = loading(pack, k, q)
print(max)
|
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 30 15:18:29 2018
ALDS1-4c
@author: maezawa
"""
def can_load(w, k, p):
n = len(w)
m = 0
tk = 0
i = 0
while tk < k:
if m + w[i] <= p:
m += w[i]
i += 1
if i >= n:
return n+1
else:
m = 0
tk += 1
return i
n, k = list(map(int, input().split()))
w = []
tr = [0 for _ in range(k)]
for i in range(n):
w.append(int(input()))
maxw = max(w)
# =============================================================================
# for p in range(maxw, maxw*n):
# if can_load(w, k, p) == n:
# print(p)
# break
# =============================================================================
right = maxw*n
left = maxw
while left<right:
mid = (right+left)//2
cl = can_load(w, k, mid)
# if cl == n:
# print(mid)
# break
# elif cl < n:
if cl < n:
left = mid + 1
else:
right = mid
print(right)
| 1 | 90,173,365,126 | null | 24 | 24 |
import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MAX = 2 * 10 ** 5 + 5
MOD = 10 ** 9 + 7
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
def comInit(mod):
fac[0], fac[1] = 1, 1
finv[0], finv[1] = 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(mod, n, k):
numerator = 1
for i in range(1, k + 1):
numerator *= (n - i + 1)
numerator %= mod
return (numerator * finv[k] % mod)
comInit(MOD)
n, a, b = map(int, readline().split())
nb = n
def my_pow(base, n, mod):
if n == 0:
return 1
x = base
y = 1
while n > 1:
if n % 2 == 0:
x *= x
n //= 2
else:
y *= x
n -= 1
x %= mod
y %= mod
return x * y % mod
ans = (my_pow(2, n, MOD) - 1) % MOD
print((ans - com(MOD, nb, a) - com(MOD, nb, b)) % MOD)
|
H, W = map(int, input().split())
if H > 1 and W > 1:
if H*W % 2 == 0:
s = (H * W) // 2
elif H*W % 2 != 0:
s = (H * W + 1) // 2
elif H == 1 or W == 1:
s = 1
print(s)
| 0 | null | 58,735,110,033,628 | 214 | 196 |
from sys import stdin
def main():
input = lambda: stdin.readline()[:-1]
K = int(input())
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(n[K-1])
main()
|
while True:
n, goal = [int(x) for x in input().split(" ")]
res =[]
if n == goal == 0:
break
for first in range(1, n+1):
for second in range(first+1, n+1):
rem = goal - (first + second)
if rem > second and n >= rem:
res.append([first, second, rem])
print(len(res))
| 0 | null | 25,818,667,354,910 | 195 | 58 |
S,W = (int(i) for i in input().split())
if S<=W:
print("unsafe")
else:
print("safe")
|
a=[int(i) for i in input().split()]
if a[0]<=a[1]:
print("unsafe")
else:
print("safe")
| 1 | 29,042,853,471,868 | null | 163 | 163 |
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[0]*q
c=[0]*q
for i in range(q):
b[i],c[i]=map(int,input().split())
N=[0]*(10**5)
s=0
for i in range(n):
N[a[i]-1]+=1
s+=a[i]
for i in range(q):
s+=(c[i]-b[i])*N[b[i]-1]
N[c[i]-1]+=N[b[i]-1]
N[b[i]-1]=0
print(s)
|
n = int(input())
A = list(map(int,input().split()))
dp = [[[0,0,0] for i in range(2)] for i in range(n+1)]
for i in range(1,n+1):
if i%2 == 1:
if i > 1:
dp[i][0][1] = dp[i-1][1][0]+A[i-1]
dp[i][0][2] = dp[i-1][1][1]+A[i-1]
dp[i][1][0] = max(dp[i-1][0][0],dp[i-1][1][0])
dp[i][1][1] = max(dp[i-1][0][1],dp[i-1][1][1])
else:
dp[i][0][2] = A[0]
else:
dp[i][0][0] = dp[i-1][1][0]+A[i-1]
dp[i][0][1] = dp[i-1][1][1]+A[i-1]
dp[i][1][0] = max(dp[i-1][0][1],dp[i-1][1][1])
dp[i][1][1] = dp[i-1][0][2]
if n%2 == 0:
print(max(dp[n][0][1],dp[n][1][1]))
else:
print(max(dp[n][0][1],dp[n][1][1]))
| 0 | null | 24,764,069,034,910 | 122 | 177 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.