code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
def answer(n: int, k: int) -> int:
digits = 0
while 0 < n:
n //= k
digits += 1
return digits
def main():
n, k = map(int, input().split())
print(answer(n, k))
if __name__ == '__main__':
main()
|
def main():
N, K = map(int, input().split())
ans = 0
while N > 0:
N //= K
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 64,269,935,585,280 | null | 212 | 212 |
H = int(input())
i=0
count=0
while(H>0):
H=H//2
count += 2**i
i+=1
print(count)
|
H = int(input())
en = 1
at = 0
while H > 0:
H //= 2
at += en
en *= 2
print(at)
| 1 | 79,996,360,280,342 | null | 228 | 228 |
N = int(input())
s = [input() for i in range(N)]
S = [[0]*len(s[i]) for i in range(N)]
for i, x in enumerate(s):
res = []
q = 0
for j in range(len(x)):
if x[j] == ')':
S[i][j] = -1
else:
S[i][j] = 1
s = [0]*N
m = [len(S[i]) for i in range(N)]
for i, x in enumerate(S):
tmp = 0
for j in range(len(x)):
tmp += S[i][j]
m[i] = min(tmp, m[i])
s[i] = tmp
if sum(s) == 0:
sp = [(m[i], s[i]) for i in range(N) if s[i] > 0]
mp = [(-(s[i]-m[i]), -s[i]) for i in range(N) if s[i] <= 0]#右から見た場合
sp.sort(key=lambda x: x[0], reverse=True)
tmp = 0
for x, y in sp:
if tmp + x < 0:
print("No")
exit(0)
tmp += y
mp.sort(key=lambda x: x[0], reverse=True)
tmp2 = 0
for x, y in mp:
if tmp2 + x < 0:
print("No")
exit(0)
tmp2 += y
print("Yes")
else:
print("No")
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
n = I()
A = []
B = []
for _ in range(n):
s = S()
ret = 0
ret2 = 0
for i in s:
if ret and i == ')':
ret -= 1
elif i == '(':
ret += 1
else:
ret2 += 1
if ret2 > ret:
A += [(ret, ret2)]
else:
B += [(ret, ret2)]
A.sort()
B.sort(key=lambda x:x[1], reverse=True)
L = A + B
now = 0
for x, y in L:
if x > now:
print('No')
exit()
now = now - x + y
if now:
print('No')
else:
print('Yes')
| 1 | 23,633,235,808,348 | null | 152 | 152 |
N = int(input())
D = []
for _ in range(N):
D.append([int(x) for x in input().split()])
count = 0
for i in range(N):
if(D[i][0] == D[i][1]):
count +=1
if(count == 3):
break
else:
count = 0
if(count == 3):
print('Yes')
else:
print('No')
|
n = int(input())
d1 = [0] * n
d2 = [0] * n
for i in range(n):
d1[i], d2[i] = (map(int, input().split()))
cnt = 0
for i in range(n):
if d1[i] == d2[i]:
cnt += 1
else:
cnt = 0
if cnt >= 3:
break
if cnt >= 3:
print("Yes")
else:
print("No")
| 1 | 2,506,990,789,728 | null | 72 | 72 |
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]
t = [(x + l, x - l) for x, l in XL]
t.sort()
max_r = -float('inf')
result = 0
for i in range(N):
r, l = t[i]
if max_r <= l:
result += 1
max_r = r
print(result)
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in A:
N -= i
if N >= 0:
print(N)
else:
print(-1)
| 0 | null | 61,082,978,109,212 | 237 | 168 |
cnt = 1
output = []
while True:
data = input().split()
if data[0] == '0' and data[1] == '0':
break
elif int(data[0]) > int(data[1]):
output += [data[1] + " " + data[0]]
else:
output += [data[0] + " " + data[1]]
for line in output:
print(line)
|
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
from collections import deque
import bisect
from decimal import *
from functools import reduce
def main():
N = I()
Dots = defaultdict()
xpyp = []
xpyn = []
xnyp = []
xnyn = []
for i in range(N):
x, y = MI()
Dots[i] = (x, y)
xpyp.append(x + y)
xpyn.append(x - y)
xnyp.append(- x + y)
xnyn.append(- x - y)
xpyp_max = max(xpyp) - min(xpyp)
xpyn_max = max(xpyn) - min(xpyn)
xnyp_max = max(xnyp) - min(xnyp)
xnyn_max = max(xnyn) - min(xnyn)
print(max(xpyp_max, xpyn_max, xnyp_max, xnyn_max))
if __name__ == "__main__":
main()
| 0 | null | 1,997,867,002,460 | 43 | 80 |
a,b,c = list(map(int,input().split(" ")))
div=0
for i in range(a,b+1):
if c % i == 0:
div += 1
print(div)
|
s = input()
s += s
key = input()
if s.find(key) != -1: print("Yes")
else: print("No")
| 0 | null | 1,137,516,993,480 | 44 | 64 |
li =[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]
a=int(input())
a-=1
print(li[a])
|
import math
a, b = map(int, input().split())
print(int((a*b)/math.gcd(a, b)))
| 0 | null | 81,635,788,285,088 | 195 | 256 |
n=int(input())
a=list(map(int,input().split()))
wa=a[0]^a[1]
for i in range(2,n):
wa=wa^a[i]
ans=[]
for i in range(n):
ans.append(wa^a[i])
print(*ans)
|
import sys
while True:
(x, y) = [int(i) for i in sys.stdin.readline().split(' ')]
if x == 0 and y == 0:
break
if x > y:
z = x
x = y
y = z
print(x, y)
| 0 | null | 6,514,094,984,936 | 123 | 43 |
def goes_to_zero(n):
cnt = 0
while(n > 0):
n %= bin(n).count('1')
cnt += 1
return cnt
N = int(input())
X = input()
XC = X.count('1')
XI = int(X, 2)
XCP = XC + 1
XCM = XC - 1
XTP = XI % XCP
XTM = XI % XCM if XCM != 0 else 0
for i in range(N):
if X[i] == "0":
print(goes_to_zero((XTP + pow(2, N - 1 - i, XCP)) % XCP) + 1)
else:
if XCM == 0:
print(0)
else:
print(goes_to_zero((XTM - pow(2,N - 1 - i, XCM)) % XCM) + 1)
|
n = int(input())
a = list(map(int, input().split()))
ruiseki0 = [0] * (n + 10)
for i in range(n):
ruiseki0[i + 1] = ruiseki0[i]
if i % 2 == 0:
ruiseki0[i + 1] += a[i]
l = [0] * (n + 1)
for i in range(n + 1):
l[i] = ruiseki0[i]
if i % 2 == 0:
if i == 0:
l[i] = 0
else:
l[i] = max(l[i - 2] + a[i - 1], l[i])
a = a[::-1]
ruiseki0 = [0] * (n + 10)
for i in range(n):
ruiseki0[i + 1] = ruiseki0[i]
if i % 2 == 0:
ruiseki0[i + 1] += a[i]
r = [0] * (n + 1)
for i in range(n + 1):
r[i] = ruiseki0[i]
if i % 2 == 0:
if i == 0:
r[i] = 0
else:
r[i] = max(r[i - 2] + a[i - 1], r[i])
ans = - 10 ** 20
for i in range(n):
if n - i - 2 < 0:
break
if n % 2 == 0 and i % 2 == 0:
continue
ans = max(ans, l[i] + r[n - i - 2])
if n % 2 == 0:
ans1 = 0
ans2 = 0
for i in range(n):
if i % 2 == 0:
ans1 += a[i]
else:
ans2 += a[i]
ans = max(ans1, ans2, ans)
if n % 2 == 1:
ans = max(ans, sum(a)- ruiseki0[n])
print(ans)
| 0 | null | 22,658,950,020,782 | 107 | 177 |
import math
r = float(input())
pi = float(math.pi)
print("{0:.8f} {1:.8f}".format(r*r*pi,r * 2 * pi))
|
k = int(input())
ans = 1
a = 7 % k
while a != 0:
ans += 1
a = (10*a + 7) % k
if ans == 10**6:
ans = -1
break
print(ans)
| 0 | null | 3,414,630,546,222 | 46 | 97 |
n = input()
for i in n:
print("x", end="")
print()
|
S=input()
N=len(S)
def isPalindrome(s):
n = len(s)
flag=True
slist=list(s)
for i, c in enumerate(slist):
if c!=slist[n-1-i]:
flag=False
if i > n-i:
break
return flag
Slist=list(S)
if isPalindrome(S) and \
isPalindrome(Slist[0:int((N-1)/2)]) and \
isPalindrome(Slist[int((N+3)/2)-1:N]):
print('Yes')
else:
print('No')
| 0 | null | 59,759,152,053,248 | 221 | 190 |
x = list(map(int, input().split()))
print(x[2], x[0], x[1])
|
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
x, y, z = inm()
print(z, x, y)
| 1 | 37,995,792,203,758 | null | 178 | 178 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
h,w,k=nii()
c=[list(input()) for i in range(h)]
b_cnt=0
for i in c:
b_cnt+=i.count('#')
ans=0
for i in range(2**h):
for j in range(2**w):
h_use=[]
for ii in range(h):
if (i>>ii)&1:
h_use.append(ii)
w_use=[]
for jj in range(w):
if (j>>jj)&1:
w_use.append(jj)
t_cnt=0
for s in h_use:
t_cnt+=c[s].count('#')
for s in w_use:
for t in range(h):
if c[t][s]=='#':
t_cnt+=1
for s in h_use:
for t in w_use:
if c[s][t]=='#':
t_cnt-=1
if b_cnt-t_cnt==k:
ans+=1
print(ans)
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
if i < K:
continue
if A[i-K] < A[i]:
print('Yes')
else:
print('No')
| 0 | null | 8,068,549,191,728 | 110 | 102 |
n = int(input())
maximum_profit = -10**9
r0 = int(input())
r_min = r0
for i in range(1, n):
r1 = int(input())
r_min = min(r0, r_min)
maximum_profit = max(maximum_profit, r1 - r_min)
r0 = r1
print(maximum_profit)
|
n = int(raw_input())
a = map(int,raw_input().split())
a.reverse()
for x in a:
print x,
| 0 | null | 499,193,701,500 | 13 | 53 |
from sys import stdin
from collections import defaultdict, Counter
N, P = map(int, stdin.readline().split())
S, = stdin.readline().split()
ans = 0
# 2 cases
if P == 2 or P == 5:
digitdiv = []
for i in range(N):
if int(S[i]) % P == 0:
ans += i + 1
else:
#
count = Counter()
prefix = []
ten = 1
mod = 0
for i in range(N):
x = (int(S[N - i - 1])*ten + mod) % P
prefix.append(x)
count[x] += 1
ten = (ten * 10) % P
mod = x
prefix.append(0)
count[0] += 1
for val in count.values():
ans += val*(val - 1)//2
print (ans)
|
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
a1 = T1 * A1
a2 = T2 * A2
a = a1 + a2
b1 = T1 * B1
b2 = T2 * B2
b = b1 + b2
def bis(p, ok, ng):
mid = (ok + ng) // 2
return (
ok if abs(ok - ng) == 1 else
bis(p, mid, ng) if p(mid) else
bis(p, ok, mid)
)
def p(k):
x = k * a
y = k * b
# print(f"k: {k}, x: {x}, y: {y}")
#print(f"k: {k}, x+: {x + a1}, y+: {y + b1}")
if x < y:
return x + a1 >= y + b1
else:
return y + b1 >= x + a1
def p2(k):
x = k * a + a1
y = k * b + b1
if x < y:
return x + a2 >= y + b2
elif x > y:
return y + b2 >= x + a2
else:
return False
if a == b:
ans = "infinity"
else:
# print(bis(p, -1, 10**16))
# print(bis(p2, -1, 10**16))
c = 1 if (a1 < b1 and a > b) or (b1 < a1 and b > a) else 0
# k = bis(lambda k: k * a + a1 >= k * b + b1, 0, 10**16) if a < b else bis(lambda k: k * a + a1 <= k * b + b1, 0, 10**16)
# d = if k * a + a1 == k * b + b1
ans = bis(p, 0, 10**16) + bis(p2, 0, 10**16) + c
print(ans)
# print('-------')
# x = 0
# y = 0
# for i in range(114):
# x += a1
# y += b1
# #print(x, y)
# print(f"{i} {x < y}")
# x += a2
# y += b2
# print(f"{i} {x < y}")
# #print(x, y)
| 0 | null | 94,963,710,654,760 | 205 | 269 |
N = int(input())
s = input()
cnt=0
for i in range(10):
for j in range(10):
for k in range(10):
a=s.find(str(i))
if a==-1:
continue
b=s[a+1:].find(str(j))
if b==-1:
continue
b+=a+1
c=s[b+1:].find(str(k))
if c==-1:
continue
cnt+=1
print(cnt)
|
N = int(input())
s = input()
res = 0
search = [("00"+str(s))[-3:] for s in range(0,1000)]
for v in search:
tmp = s
if v[0] in tmp:
tmp = tmp[tmp.index(v[0])+1:]
else:
continue
if v[1] in tmp:
tmp = tmp[tmp.index(v[1])+1:]
else:
continue
if v[2] in tmp:
res += 1
print(res)
| 1 | 128,880,887,299,462 | null | 267 | 267 |
N=int(input())
s=[input() for i in range(N)]
lost_list=[]
taro_card=[]
card_list=[]
for i in s:
taro_card.append(i.split())
for i in range(1,14):
card_list.append(["S",str(i)])
for i in range(1,14):
card_list.append(["H",str(i)])
for i in range(1,14):
card_list.append(["C",str(i)])
for i in range(1,14):
card_list.append(["D",str(i)])
for i in card_list:
if i not in taro_card:
lost_list.append(i)
for i in lost_list:
print(i[0]+" "+i[1])
|
import sys
SUITS = ['S', 'H', 'C', 'D']
exist_cards = {suit:[] for suit in SUITS}
n = input()
for line in sys.stdin:
suit, number = line.split()
exist_cards[suit].append(int(number))
for suit in SUITS:
for i in range(1, 14):
if i not in exist_cards[suit]:
print(suit, i)
| 1 | 1,016,530,552,400 | null | 54 | 54 |
N = int(input())
x = int(N**(0.5)) + 1
while True:
if N % x == 0:
print((x-1)+((N//x)-1))
break
x -= 1
|
while True:
s = input().split(" ")
H = int(s[0])
W = int(s[1])
if H == 0 and W == 0:
break
for i in range(H):
for j in range(W):
if j == W-1:
print("#")
else:
print("#",end="")
print("")
| 0 | null | 81,288,929,887,410 | 288 | 49 |
def Main():
cross = input().replace("\n", "")
S = list()
V = list()
ans = list()
for i in range(len(cross)):
r = cross[i]
if r == "\\":
S.append(i)
elif r == "/":
if len(S) > 0:
j = S.pop()
v = i - j
V.append([v, j])
while len(V) > 0 :
total = 0
[v, j] = V.pop()
total += v
while True:
if len(V) > 0:
[vv, jj] = V.pop()
if jj > j:
total += vv
else:
V.append([vv, jj])
ans.append(total)
break
else:
ans.append(total)
break
print("{}".format(sum(ans)))
print(len(ans), *reversed(ans))
Main()
|
n = int(raw_input())
a = map(int, raw_input().split())
temp = 0
cnt = 0
for i in range(n):
for j in range(n-i-1):
if a[j] > a[j+1]:
temp = a[j]
a[j] = a[j+1]
a[j+1] = temp
cnt += 1
for i in range(n):
if i != n-1:
print(a[i]),
else:
print(a[i])
print cnt
| 0 | null | 36,631,414,002 | 21 | 14 |
import sys
import math
import fractions
from collections import defaultdict
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()))
N,K=nm()
A=nl()
imos_l=[0]*(N+1)
for i in range(K):
imos_l=[0]*(N+1)
for j in range(len(A)):
imos_l[max(j-A[j],0)]+=1
imos_l[min(j+A[j]+1,N)]-=1
for j in range(len(imos_l)-1):
imos_l[j+1]=imos_l[j]+imos_l[j+1]
for j in range(len(A)):
A[j]=imos_l[j]
flag=True
for j in range(len(A)):
if(A[j]<N):
flag=False
if(flag):
print(*A)
sys.exit(0)
print(*A)
|
n = int(input())
A = list(map(int, input().split()))
now = 1
cnt = 0
for a in A:
if a == now:
now += 1
cnt += 1
if cnt == 0:
print(-1)
else:
print(n-cnt)
| 0 | null | 64,805,714,428,458 | 132 | 257 |
N = int(input())
arr = [int(n) for n in input().split()]
swap_cnt = 0
for i in range(0, N):
minj = i
for j in range(i + 1, N):
if arr[j] < arr[minj]:
minj = j
if (i != minj):
arr[i], arr[minj] = arr[minj], arr[i]
swap_cnt += 1
print(' '.join(map(str, arr)))
print(swap_cnt)
|
def selectionSort(nums,n):
k=0
for i in range(n):
minj=i
for j in range(i,n):
if nums[j]<nums[minj]:
minj=j
if nums[i]!=nums[minj]:
nums[i],nums[minj]=nums[minj],nums[i]
#print(nums)
k+=1
return nums,k
n=int(input())
nums=list(map(int,input().split()))
nums,k=selectionSort(nums,n)
print(*nums)
print(k)
| 1 | 21,289,409,198 | null | 15 | 15 |
n,m=map(int,input().split())
diffs=set()
idxs=set()
i=1
diff=n-1
cnt=0
while 1:
if i>m:
break
while (diff in diffs and n-diff in diffs) or (i+diff in idxs) or (diff==n-diff):
diff-=1
diffs.add(n-diff)
diffs.add(diff)
idxs.add(i+diff)
print(i,i+diff)
i+=1
|
integers=[]
i=0
j=0
while True:
num=int(input())
integers.append(num)
if integers[i]==0:
del integers[i]
break
i+=1
while j<i:
print('Case {}: {}'.format(j+1,integers[j]))
j+=1
| 0 | null | 14,627,595,277,792 | 162 | 42 |
while True :
a, b, c = [int(temp) for temp in input().split()]
if a == b == c == -1 : break
if (a == -1) or (b == -1) or (a + b < 30) : print('F')
elif (80 <= a + b) : print('A')
elif (65 <= a + b) : print('B')
elif (50 <= a + b) or ((30 <= a + b) and (50 <= c)) : print('C')
else : print('D')
|
a, b, m = map(int, input().split())
a_price = list(map(int, input().split()))
b_price = list(map(int, input().split()))
coupon = []
for _ in range(m):
coupon.append(list(map(int, input().split())))
a_copy = a_price.copy()
a_copy.sort()
b_copy = b_price.copy()
b_copy.sort()
a_min = a_copy[0]
b_min = b_copy[0]
min = a_min + b_min
totals = [min]
for list in coupon:
tmp = a_price[list[0] - 1] + b_price[list[1] - 1] - list[2]
totals.append(tmp)
totals.sort()
ans = totals[0]
print(ans)
| 0 | null | 27,636,417,292,702 | 57 | 200 |
#!/usr/bin/env python
# coding: utf-8
# In[15]:
N = int(input())
xy_list = []
for _ in range(N):
A = int(input())
xy = []
for _ in range(A):
xy.append(list(map(int, input().split())))
xy_list.append(xy)
# In[16]:
ans = 0
for i in range(2**N):
for j,a_list in enumerate(xy_list):
if (i>>j)&1 == 1:
for k,(x,y) in enumerate(a_list):
if (i>>(x-1))&1 != y:
break
else:
continue
break
else:
ans = max(ans, bin(i)[2:].count("1"))
print(ans)
# In[ ]:
|
n,k=map(int,input().split())
ans=1
while n//(k**ans):
ans+=1
print(ans)
| 0 | null | 92,776,994,309,692 | 262 | 212 |
N = int(input())
count = 0
for i in range(N):
count += int((N-1)/(i+1))
print(count)
|
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
def main():
class SegmentTree:
def __init__(self,n,segfunc,ide_ele):
self.segfunc=segfunc
self.ide_ele=ide_ele
self.num=2**(n-1).bit_length()
self.dat=[ide_ele]*2*self.num
def init(self,iter):
for i in range(len(iter)):
self.dat[i+self.num]=iter[i]
for i in range(self.num-1,0,-1):
self.dat[i]=self.segfunc(self.dat[i*2],self.dat[i*2+1])
def update(self,k,x):
k+=self.num
self.dat[k]=x
while k:
k//=2
self.dat[k]=self.segfunc(self.dat[k*2],self.dat[k*2+1])
def query(self,p,q):
if q<=p:
return self.ide_ele
p+=self.num
q+=self.num-1
res=self.ide_ele
while q-p>1:
if p&1==1:
res=self.segfunc(res,self.dat[p])
if q&1==0:
res=self.segfunc(res,self.dat[q])
q-=1
p=(p+1)//2
q=q//2
if p==q:
res=self.segfunc(res,self.dat[p])
else:
res=self.segfunc(self.segfunc(res,self.dat[p]),self.dat[q])
return res
N=int(input())
S=[input() for i in range(N)]
P=0
M=0
c=0
Seg=SegmentTree(10**6+1,lambda a,b:max(a,b),-INF)
l_PM=defaultdict(list)
stack=defaultdict(list)
minus=set()
for i,s in enumerate(S):
p=0
m=0
for x in s:
if x=='(':
p+=1
else:
if p>0:
p-=1
else:
m+=1
if m==0 and p>0:
P+=p
elif p==0 and m>0:
M+=m
elif p>0 and m>0:
c+=1
minus.add(m)
stack[m].append(p-m)
minus=list(minus)
minus.sort()
for x in minus:
stack[x].sort()
if x<=P:
while stack[x]:
y=stack[x].pop()
if y>=0:
c-=1
P+=y
else:
Seg.update(x,y)
l_PM[y].append(x)
break
else:
y=stack[x].pop()
Seg.update(x,y)
l_PM[y].append(x)
for _ in range(c):
x=Seg.query(0,P+1)
if x==-INF or P+x<0:
print('No')
exit()
l_PM[x].sort()
res=bisect_right(l_PM[x],P)-1
index=l_PM[x][res]
del l_PM[x][res]
if stack[index]:
y=stack[index].pop()
Seg.update(index,y)
l_PM[y].append(index)
else:
Seg.update(index,-INF)
P+=x
P-=M
YesNo(P==0)
if __name__ == '__main__':
main()
| 0 | null | 13,068,598,158,848 | 73 | 152 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
A=[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]
def main():
K = int(input())
print(A[K-1])
if __name__ == '__main__':
main()
|
def main():
L = [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]
K = int(input())
print(L[K-1])
if __name__ == "__main__":
main()
| 1 | 50,043,266,852,010 | null | 195 | 195 |
a1,a2,a3 = map(int,input().split())
sum = a1
sum += a2
sum += a3
if sum <=21:
print('win')
else:
print('bust')
|
def popcount_int(n):
return bin(n).count('1')
def popcount_bin(s):
return s.count('1')
def poptimes(n,cnt=1):
if n==0:
return cnt
else:
n%=popcount_int(n)
cnt+=1
return poptimes(n,cnt)
N=int(input())
S=input()
S_int=int(S,2)
pc=popcount_bin(S)
pc_plus=S_int%(pc+1)
if pc!=1:
pc_minus=S_int%(pc-1)
for i in range(N):
if S[i]=='1':
if pc!=1:
tmp=pc_minus-pow(2,N-i-1,pc-1)
print(poptimes(tmp%(pc-1)))
else:
print(0)
continue
else:
tmp=pc_plus+pow(2,N-i-1,pc+1)
print(poptimes(tmp%(pc+1)))
| 0 | null | 63,490,859,516,930 | 260 | 107 |
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
Count = {x:0 for x in range(0, n)}
mod = 10**9+7
ans = 1
for i in range(n):
now = A[i]
if now == 0:
ans = (3 - Count[0]) * ans % mod
Count[0] += 1
continue
ans = (Count[now-1] - Count[now]) *ans % mod
Count[now] += 1
print(ans)
# print(Count)
|
p = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 1
cnt = [3 if i == 0 else 0 for i in range(n+1)]
for a in A:
ans *= cnt[a]
ans %= p
cnt[a] -= 1
cnt[a+1] += 1
print(ans)
| 1 | 130,075,133,501,670 | null | 268 | 268 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
money = 100000
d = int(sys.stdin.read())
for i in range(d):
money *= 1.05
if money%1000 != 0:
money -= money%1000
money += 1000
print int(money)
|
import math
n=int(input())
debt=100000
for i in range(n):
debt=math.ceil((debt*1.05)/1000)*1000
print(int(debt))
| 1 | 944,082,772 | null | 6 | 6 |
from sys import stdin
n = int(input())
xs = [int(input()) for _ in range(n)]
ans = 0
for x in xs:
flg = True
for y in range(2, int(x**0.5+1)):
if x % y == 0:
flg = False
break
if flg:
ans += 1
print(ans)
|
n = int(input())
a = list(map(int, input().split()))
ans = 0
cnt = 0
for i in a:
if i == cnt+1:
cnt += 1
else:
ans += 1
print(ans if cnt else -1)
| 0 | null | 57,312,491,939,648 | 12 | 257 |
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
h, w, k = list(map(int,ipti().split()))
s = [list(input()) for i in range(h)]
empty_row = []
exist_row = []
berry_id = 1
for row in range(h):
is_empty = True
for col in range(w):
if s[row][col] == "#":
s[row][col] = berry_id
berry_id += 1
is_empty = False
if is_empty:
empty_row.append(row)
else:
exist_row.append(row)
# まず空ではない行を埋める
for row in range(h):
if row in exist_row:
berry_col = deque()
for col in range(w):
if s[row][col] != ".":
berry_col.append(col)
first = 0
fill_id = 0
while berry_col:
last = berry_col.popleft()
fill_id = s[row][last]
for j in range(first, last+1):
s[row][j] =fill_id
first = last + 1
for j in range(first, w):
s[row][j] = fill_id
for row in empty_row:
is_filled = False
for row2 in range(row+1, h):
if row2 in exist_row:
for col in range(w):
s[row][col] = s[row2][col]
is_filled = True
break
if not is_filled:
for row2 in range(row-1, -1 , -1):
if row2 in exist_row:
for col in range(w):
s[row][col] = s[row2][col]
is_filled = True
break
for row in range(h):
print(*s[row])
if __name__ == '__main__':
main()
|
h, w, k = map(int, input().split())
mat = [input() for i in range(h)]
num = 0
ans = [[0]*w for _ in range(h)]
heights = [0]*h
for i in range(h):
for j in range(w):
if mat[i][j] == "#":
heights[i] += 1
hs = []
for v in range(h):
if heights[v] >= 1:
hs.append(v)
for i in range(len(hs)):
h1 = 0
h2 = h-1
if i >= 1:
h1 = hs[i-1] + 1
if i < len(hs)-1:
h2 = hs[i]
ws = []
for j in range(h1, h2+1):
for k in range(w):
if mat[j][k] == "#":
ws.append(k)
ws.sort()
for j in range(len(ws)):
w1 = 0
w2 = w-1
if j >= 1:
w1 = ws[j-1]+1
if j < len(ws)-1:
w2 = ws[j]
num += 1
for k in range(h1, h2+1):
for l in range(w1, w2+1):
ans[k][l] = num
for i in range(h):
print(*ans[i])
| 1 | 143,138,027,548,218 | null | 277 | 277 |
def INT():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(map(int, input().split()))
S = input()
if S[len(S) - 1] == "s":
S += "es"
else:
S += "s"
print(S)
|
t = input()
ans = ""
if t[len(t)-1] == "s":
ans = t + "es"
else:
ans = t + "s"
print(ans)
| 1 | 2,373,639,110,150 | null | 71 | 71 |
N = input()
s1 = []
s2 = []
res = []
ans = []
cnt = 0
for i in range(len(N)):
if N[i] == "\\":
s1.append(i)
elif N[i] == "/" and s1:
idx = s1.pop()
tmp = i - idx
cnt += tmp
while s2 and idx < s2[-1][0]:
tmp += s2.pop()[1]
s2.append((idx, tmp))
res.append(len(s2))
for i in range(len(s2)):
ans.append(s2[i][1])
res.extend(ans)
print(cnt)
print(" ".join(map(str, res)))
|
s = input()
t = len(s)
x = []
y = 0
while 10 ** y % 2019 not in x:
x.append(10 ** y % 2019)
y += 1
z = len(x)
m = [0 for i in range(2019)]
m[0] = 1
a = 0
for i in reversed(range(0, t)):
a += x[(t-i-1) % z] * (int(s[i]) % 2019)
a = a % 2019
m[a] += 1
def triangle(n):
if n > 1:
return n * (n-1) // 2
else:
return 0
p = list(map(triangle, m))
# print(p)
print(sum(p))
| 0 | null | 15,324,461,667,662 | 21 | 166 |
X = int(input())
m = 100
y = 0
while m < X :
m = m*101//100
y += 1
print(y)
|
n,k = map(int,input().split())
A=list(map(int,input().split()) )
kyori = [-1] *len(A)
junban =[]
x=0
d=0
while kyori[x] == -1:
junban.append(x)
kyori[x]=d
d+=1
x=A[x]-1
roop_x = x
roop_d = d - kyori[x]
# for k in range(100):
if k<d:
print(junban[k]+1)
else:
k0 = kyori[x]
k1 = (k-k0)%roop_d
print(junban[k0+k1]+1)
| 0 | null | 25,002,903,909,948 | 159 | 150 |
if(int(input())>=30):
print("Yes")
else:
print("No")
|
x=int(input())
if x>29:
print("Yes")
else:
print("No")
| 1 | 5,784,974,897,728 | null | 95 | 95 |
N = int(input())
l = list(map(int, input().split()))
counter = 1
ans = 0
for j in l:
if j == counter:
counter += 1
else:
ans += 1
if counter==1:
print(-1)
else:
print(ans)
|
N=int(input())
A=list(map(int,input().split()))
cur=1
for i in range(N):
if A[i]==cur:
cur+=1
if cur==1:
print(-1)
elif cur>1:
print(N-(cur-1))
| 1 | 114,293,519,788,972 | null | 257 | 257 |
n = int(input())
a = list(map(int,input().split()))
s = 1
p = 0
for i in range(n):
if a[i] == s:
s += 1
else:
p += 1
if p == n:
print(-1)
else:
print(p)
|
n = int(input())
a = list(map(int,input().split()))
m = 1
for i in range(n):
if a[i] == m:
m += 1
print(-1) if m == 1 else print(n-m+1)
| 1 | 114,226,764,105,958 | null | 257 | 257 |
def resolve():
n,k = map(int,input().split())
ans = 0
while n!=0:
n = n//k
ans += 1
print(ans)
resolve()
|
n,k = [int(x) for x in input().split()]
res = 0
while n > 0:
n //= k
res += 1
print(res)
| 1 | 64,436,497,111,520 | null | 212 | 212 |
while True:
try:
a = map(int,raw_input().split())
n = [a[0],a[1]]
while True:
if a[0] < a[1]:
tmp = a[0]
a[0] = a[1]
a[1] = tmp
a[0] = a[0] - a[1]
if a[0] == 0:
break
b = n[0]*n[1]/a[1]
print "%d %d" % (a[1],b)
except EOFError:
break
|
def gcd(a, b):
if b == 0: return a
else: return gcd(b, a % b)
def lcm(a, b):
return a * b / gcd(a, b)
while True:
try:
a, b = map(int, input().split())
print(int(gcd(a, b)), int(lcm(a, b)))
except EOFError:
break
| 1 | 628,800,328 | null | 5 | 5 |
def main():
S = input()
L = len(S)
print('x' * L)
if __name__ == '__main__':
main()
|
S = str(input())
T = "x" * len(S)
print(T)
| 1 | 72,720,197,999,172 | null | 221 | 221 |
import math
a,b,c=map(int,input().split())
C=(c/180)*math.pi
S=(a*b*math.sin(C))/2
L=a+b+(a**2+b**2-2*a*b*math.cos(C))**0.5
h=b*math.sin(C)
print("%.5f\n%.5f\n%.5f\n"%(S,L,h))
|
N = int(input())
n = min(N, 10**6)
is_Prime = [True] * (n + 1)
is_Prime[0] = False
is_Prime[1] = False
for i in range(2, int(n**(1/2)+1)):
for j in range(2*i, n+1, i):
if j % i == 0:
is_Prime[j] = False
P = [i for i in range(n+1) if is_Prime[i]]
count = 0
for p in P:
count_p = 0
while N % p == 0:
count_p += 1
N /= p
count += int((-1+(1+8*count_p)**(1/2))/2)
if p == P[-1] and N != 1:
count += 1
print(count)
| 0 | null | 8,617,135,022,470 | 30 | 136 |
#2-8
while True:
try:
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b,a%b)
a = list(map(int,input().split()))
a.sort()
a.reverse()
ans1 = gcd(a[0],a[1])
ans2 = int(a[0]*a[1]/ans1)
print(ans1,ans2)
except:
break
|
S,W = map(int,input().split())
print('safe' if S > W else 'unsafe')
| 0 | null | 14,650,742,525,128 | 5 | 163 |
# UnionFind: https://note.nkmk.me/python-union-find/
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
def find(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def is_same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.root[self.find(x)]
n, m = map(int, input().split())
friends = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
friends.unite(a, b)
print(max(friends.size(i) for i in range(n)))
|
n,m = map(int,input().split())
a = [1]*(n+1)
b = [0]*(n+1)
for i in range(m):
x,y = map(int,input().split())
u = x
while a[u]==0:
u = b[u]
v = y
while a[v]==0:
v = b[v]
if u!=v:
b[v] = u
b[y] = u
b[x] = u
a[u] += a[v]
a[v] = 0
print(max(a))
| 1 | 3,966,811,341,192 | null | 84 | 84 |
import math
def koch(start, end, n, r):
if n > 0:
#途中の頂点をa, b, cとする
a = [(start[0]*2 + end[0]*1) / 3, (start[1]*2 + end[1]*1) / 3]
c = [(start[0]*1 + end[0]*2) / 3, (start[1]*1 + end[1]*2) / 3]
x = c[0] - a[0]
y = c[1] - a[1]
b = [x * math.cos(math.pi/3) - y * math.sin(math.pi/3) + a[0], x * math.sin(math.pi/3) + y * math.cos(math.pi/3) + a[1]]
koch(start, a, n-1, r)
koch(a, b, n-1, r)
koch(b, c, n-1, r)
koch(c, end, n-1, r)
else:
r.append(start)
n = int(input())
r = []
koch([0, 0], [100, 0], n, r)
r.append([100, 0])
for rr in r:
print(str(rr[0]) + ' ' + str(rr[1]))
|
xy = [int(s) for s in input().split()]
x = xy[0]
y = xy[1]
if y % 2 == 0 and y<=4*x and y>=2*x:
print('Yes')
else:
print('No')
| 0 | null | 6,983,489,775,428 | 27 | 127 |
from operator import mul
from functools import reduce
def cmb(n,r):
r = min(n-r,r)
if r == 0: return 1
over = reduce(mul, range(n, n - r, -1))
under = reduce(mul, range(1,r + 1))
return over // under
n,m = map(int,input().split())
cmb_n = cmb(n,2) if n>=2 else 0
cmb_m = cmb(m,2) if m>=2 else 0
print(cmb_n+cmb_m)
|
N, M = [int(i) for i in input().split(' ')]
print((N * (N - 1) + M * (M - 1)) // 2)
| 1 | 45,518,482,959,550 | null | 189 | 189 |
n,k = map(int,input().split())
ke = 1
while(True):
if(n<k):
print(ke)
break
else:
n = n//k
ke += 1
|
N, K = map(int, input().split())
ans = 1
while N >= K:
N = N // K
ans += 1
print(ans)
| 1 | 64,221,370,378,462 | null | 212 | 212 |
l =int(input())
s =input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
A = r * g * b
B = 0
gapmax = (l - 3) // 2
for _ in range(gapmax+1):
for i in range(l-2-2*_):
c1, c2, c3 = s[i], s[i+1+_],s[i+2+2*_]
if not (c1 == c2) and not (c1 == c3) and not (c2 ==c3):
B += 1
print(A-B)
|
from math import gcd
N,K=map(int,input().split())
mod=10**9+7
A=[0]*K
for i in range(K,0,-1):
a=K//i
b=pow(a,N,mod)
A[i-1]=b
for i in range(K,0,-1):
for j in range(K//i-1):
c=i*(j+2)
A[i-1]-=A[c-1]
A[i-1]%=mod
s=0
for i in range(K):
s+=A[i]*(i+1)
s%=mod
print(s)
| 0 | null | 36,391,411,008,448 | 175 | 176 |
n, m, k = map(int, input().split())
mod = 998244353
def _fac_inv(_n, _mod):
_fac = [1] * (_n+1) # 階乗
_inv = [1] * (_n+1) # 逆元
for i in range(_n):
_fac[i+1] = _fac[i] * (i+1) % _mod
_inv[n] = pow(_fac[n], mod-2, mod)
for i in range(_n, 0, -1):
_inv[i-1] = _inv[i] * i % _mod
return _fac, _inv
fac, inv = _fac_inv(n, mod)
ans = 0
mm = (m * pow(m-1, n-1-k, mod)) % mod
for ii in range(k+1):
i = k-ii
ans = (ans + mm * fac[n-1] * inv[i] * inv[n-1-i]) % mod
mm = mm * (m-1) % mod
print(ans)
|
import sys
line = sys.stdin.readline()
tate, yoko = line.split(" ")
tate = int(tate)
yoko = int(yoko)
S = tate * yoko
T = 2 * (tate + yoko)
print '%d %d' % (S, T)
| 0 | null | 11,770,098,048,342 | 151 | 36 |
A, B = map(int, input().split())
if A <= B*2:
print(0)
elif A > B*2:
print(A-B*2)
|
a,b = input().split()
a = int(a)
b = int(b)
ret = a - (b * 2)
if ret < 0:
ret = 0
print(ret)
| 1 | 166,661,196,225,528 | null | 291 | 291 |
n = int(input())
A = list(map(int, input().split()))
l = A[0]
r = sum(A[1:])
x = abs(l-r)
for a in A[1:]:
l += a
r -= a
if x > abs(l-r): x = abs(l-r)
print(x)
|
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
a_acc = list(accumulate(a))
ans = 2020202020
for i in range(n):
ans = min(abs(a_acc[-1] - a_acc[i] - a_acc[i]), ans)
print(ans)
| 1 | 142,075,405,748,822 | null | 276 | 276 |
N,K=map(int,input().split())
*A,=map(int,input().split())
vis=[0]*(N+1)
now=1
vis[now] = 1
his=[now]
while 1:
new = A[now-1]
if vis[new]==0:
vis[new]=1
his.append(new)
now = new
else:
idx = his.index(new)
cycle = his[idx:]
margin = his[:idx]
break
if K <= len(margin):
print(his[K])
exit()
K -= len(margin)
K %= len(cycle)
print(cycle[K])
|
N,K=map(int, input().split())
a_ls=list(map(int, input().split()))
j=1
step=0
s=set([])
l=[]
loop_s=-1
loop_g=-1
while True:
s.add(j)
l+=[j]
j=a_ls[j-1] #update
if j in s:
loop_s=l.index(j)
loop_g=len(l)
break
#print(l)
#print(loop_s)
#print(loop_g)
if K<loop_s:
print(l[K])
elif (K+1-loop_s)%(loop_g-loop_s)!=0:
print(l[loop_s+(K+1-loop_s)%(loop_g-loop_s)-1])
else:
print(l[-1])
| 1 | 22,619,309,318,480 | null | 150 | 150 |
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
def main():
N, K = ril()
A = ril()
l = 1
r = 1000000000
while l < r:
m = (l + r) // 2
k = 0
for a in A:
k += (a - 1) // m
if k <= K:
r = m
else:
l = m + 1
print(r)
if __name__ == '__main__':
main()
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
left, right = 0, max(A)
while right - left != 1:
mid = (left + right) // 2
tmp = 0
for i in A:
tmp += i // mid - 1 if i % mid == 0 else i // mid
if tmp > K:
left = mid
else:
right = mid
print(right)
| 1 | 6,477,729,472,252 | null | 99 | 99 |
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 7 01:13:08 2020
@author: liang
"""
"""
ABC 171 D 差分更新 パケット変換
【無駄な探索は行わない(メモリ化) ⇒ パケット変換】
パケット
値vが出現する回数を記録しておく
dict()方式 ⇒ 探索にO(logn) or O(n)がかかる
配列方式 ⇒ 探索がO(1)となる!
【差分更新】
値Bが全て値Cになる
⇒ (C - B) * 値Bの個数だけ増加する
⇒ 値Cの個数 += 値Bの個数
⇒ 値Bの個数 = 0
"""
N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())
d = [0]*(10**5)
for i in A:
d[i-1] += 1
ans = sum(A)
for i in range(Q):
b, c = map(int,input().split())
ans += (c-b)*d[b-1]
d[c-1] += d[b-1]
d[b-1] = 0
print(ans)
|
n = int(input())
mod = 10**9+7
num = 10**n%mod - 2*(9**n%mod)%mod + 8**n%mod
print(num if num>=0 else num+mod)
| 0 | null | 7,604,953,217,332 | 122 | 78 |
s,t=map(str,input().split())
a,b=map(int,input().split())
u=input()
if u==s:
print("{0} {1}".format(a-1,b))
else:
print("{0} {1}".format(a,b-1))
|
n = int(input())
x = map(float, input().strip().split())
y = map(float, input().strip().split())
d = tuple(map(lambda x,y:abs(x-y), x, y))
print(sum(d))
print(sum(map(pow, d, [2]*n))**0.5)
print(sum(map(pow, d, [3]*n))**(1/3))
print(max(d))
| 0 | null | 36,007,506,163,450 | 220 | 32 |
import sys
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
n=int(input())
d=[]
for e in sys.stdin:
e=int(e)
if e in a:
a[a.index(e)]=0
if e in b:
b[b.index(e)]=0
if e in c:
c[c.index(e)]=0
if sum(a)==0 or sum(b)==0 or sum(c)==0:
print("Yes")
exit()
for i in range(3):
if a[i]==0 and b[i]==0 and c[i]==0:
print("Yes")
exit()
if (a[0]==0 and b[1]==0 and c[2]==0) or (a[2]==0 and b[1]==0 and c[0]==0):
print("Yes")
exit()
print("No")
|
bingoSheet = [0 for x in range(9)]
for i in range(3):
bingoRow = input().split()
for j in range(3):
bingoSheet[i*3 + j] = int(bingoRow[j])
bingoCount = int(input())
responses = []
for i in range(bingoCount):
responses.append(int(input()))
hasBingo = False
step = 1
initialIndex = 0
for i in range(3):
firstIndex = i*3
subList = [bingoSheet[index] for index in [firstIndex, firstIndex+1, firstIndex+2]]
if (all(elem in responses for elem in subList)):
hasBingo = True
break
for i in range(3):
firstIndex = i
subList = [bingoSheet[index] for index in [firstIndex, firstIndex+3, firstIndex+6]]
if (all(elem in responses for elem in subList)):
hasBingo = True
break
subList = [bingoSheet[index] for index in [0, 4, 8]]
if (all(elem in responses for elem in subList)):
hasBingo = True
subList = [bingoSheet[index] for index in [2, 4, 6]]
if (all(elem in responses for elem in subList)):
hasBingo = True
if hasBingo:
print('Yes')
quit()
print('No')
quit()
| 1 | 59,524,370,560,140 | null | 207 | 207 |
A = list(map(int, input().split()))
if sum(A) < 22:
print("win")
else:
print("bust")
|
a,b,c=[int(i) for i in input().split()]
if((a+b+c)>=22):
print('bust')
else:
print('win')
| 1 | 118,643,336,808,920 | null | 260 | 260 |
n, k = map(int, input().split())
MOD = 1000000007
def combinations(n, r, MOD):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * fact_inv[r] * fact_inv[n - r] % MOD
fact = [1, 1]
fact_inv = [1, 1]
inv = [0, 1]
for i in range(2, n + 1):
fact.append((fact[-1] * i) % MOD)
inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
fact_inv.append((fact_inv[-1] * inv[-1]) % MOD)
s = 0
for num_zero in range(min(k + 1, n)):
# nCz
x = combinations(n, num_zero, MOD)
# n-zCx
y = combinations(n - 1, n - num_zero - 1, MOD)
s += (x * y) % MOD
print(s % MOD)
|
# -*- coding: utf-8 -*-
def main():
S = input()
week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
for i, name in enumerate(week):
if name == S:
ans = 7 - i
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 99,950,565,375,750 | 215 | 270 |
i=1
while True:
x = int(input())
if x==0:
break
print('Case ',i,': ',x,sep='')
i=i+1;
|
import sys
cnt = 1
while 1:
x=sys.stdin.readline().strip()
if x == '0':
break;
print("Case " + str(cnt) + ": " + x)
cnt+=1
| 1 | 488,248,686,980 | null | 42 | 42 |
from math import factorial
n=int(input())
cnt=[0]*(n+1)
lst=list(map(int,input().split()))
for i in lst:
cnt[i]+=1
ans=0
for i in range(n+1):
p=cnt[i]
if p>=2:
ans+=factorial(p)//factorial(p-2)//2
for i in range(n):
print(ans-cnt[lst[i]]+1)
|
n=int(input())
a=list(map(int,input().split()))
d={}
for i in a:
if d.get(i):d[i]+=1
else:d[i]=1
ans=0
for i in d:
ans+=d[i]*(d[i]-1)//2
for i in a:
print(ans-(d[i]-1))
| 1 | 47,870,412,584,302 | null | 192 | 192 |
n,a,b = map(int, input().split())
if n % (a+b) >= a:
print((n // (a+b))*a + a)
else:
print((n // (a+b))*a + (n % (a+b)))
|
N, A, B = map(int, input().split())
q, r = divmod(N, A + B)
ans = 0
ans += q * A
ans += min(r, A)
print(ans)
| 1 | 55,468,560,171,652 | null | 202 | 202 |
from collections import deque
infinity=10**6
import sys
input = sys.stdin.readline
N,u,v = map(int,input().split())
u -= 1
v -= 1
G=[[] for i in range(N)]
for i in range(N-1):
A,B = map(int,input().split())
A -= 1
B -= 1
G[A].append(B)
G[B].append(A)
ends = []
for i in range(N):
if len(G[i]) == 1:
ends.append(i)
#幅優先探索
def BFS (s):
queue = deque()
d = [infinity]*N
queue.append(s)
d[s]= 0
while len(queue)!=0:
u = queue.popleft()
for v in G[u]:
if d[v] == infinity:
d[v] = d[u]+1
queue.append(v)
return d
d_nigeru = BFS(u)
d_oni = BFS(v)
ans=0
for u in ends:
if d_nigeru[u] < d_oni[u]:
ans = max(ans,d_oni[u]-1)
print(ans)
|
from collections import deque
N, u, v = map(int, input().split())
u -= 1
v -= 1
edge = [[] for _ in range(N)]
for _ in range(N - 1):
A, B = map(int, input().split())
edge[A - 1].append(B - 1)
edge[B - 1].append(A - 1)
INF = 10 ** 6
lenA = [INF] * N
q = deque()
q.append((v, 0))
lenA[v] = 0
while len(q) > 0:
p, step = q.popleft()
for np in edge[p]:
if lenA[np] == INF:
lenA[np] = step + 1
q.append((np, step + 1))
lenT = [INF] * N
q = deque()
q.append((u, 0))
lenT[u] = 0
ans = 0
while len(q) > 0:
p, step = q.popleft()
if len(edge[p]) == 1:
ans = max(ans, step + (lenA[p] - step) - 1)
for np in edge[p]:
if lenT[np] == INF and lenA[np] > step + 1:
lenT[np] = step + 1
q.append((np, step + 1))
print(ans)
| 1 | 116,871,832,095,350 | null | 259 | 259 |
d,t,s=map(int,input().split())
print("Yes" if t>=d/s else "No")
|
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64)
# Original source code :
"""
#include <stdio.h>
int main() {
int d, t, s; scanf("%d %d %d", &d, &t, &s);
if (s * t >= d) {
puts("Yes");
} else {
puts("No");
}
}
"""
import base64
import subprocess
import zlib
exe_bin = "c%1E7eQZ<L6~E6(hy#gZNC5M(VYSW_*2N?cAdIHu1t+{rNk}1KR0W<Ke<U7`o!QS_K;4FvGRdOuJZaKUyQ!5XO?2wC_K!_eleVCAU8hYNmA18Nsl=)>1y;0dtPx`(-nsAH^Zf4hdz4B0lcPB2o!>p@-0%C&J@1=+gZ(Z^B1l!_F+!!{3PbK;cyWWN0$3NRga4l)n+a8`w&;ocw#0L{S&w1Y<uYWEZzepKEWCy|(@Y)D3GthDw5=B!4D>>SpW~CP-f0(a=VEpjncYREk9?6eY*FZ6HT#V+e<BYNo>wzIa!rfU=T7EG<c|`bqut|Rw}RY1c^N;%>T?>GqpZEiaUQlM6XUx&w<V)($wVqQ(>Bw!t8G_jFq;l;*W2V}x(9~GbbUJCIJC69nPIfNe*TU;@}oZ<X?p7gY2C}GKUkNY`?19A%PaH#=&J;0j;D?ATVsQ7alrRE-~|W&s~q&d@1WlfzlUsa0^=H?!?=s6Y9gDC?AfDcBjHq>Oy{&LU|B63IjKe_Ppa{7A_+ibCalI2sc<rJItC)Or%D-3oeC#X<iOxS?|yZAaJTu?X+CWa?j-8K=#UzXWnvSFtQO0R4((5-Q?b$Tc#?XXm`bOZH`P$JRixyC`J^*ktv^d3(YeEQwmy+)pk<FUtXY?<$dgRYZA{cryBO2Q^@sbZSZnZC1$>0zZZD6c{BEPc>E5uerK=Xa+JY}waO*j<Xu)eO_-zaBw%~INr@Af+{+0!=vf!63xOE>Zvmd*ab2Z&7{X{uCr@2a(mDxAk^JaNz=Z!i)DYbkI{~NdTz!Q}xY0>qoC7_lMsZ6_m{jx5<M`hZi>vOvNPmtq9OMR_Mp}P(gqRP4ImR5@8LjhmMoKhGJG%JPCfLAGKf%=8l!1`P$(A@abP{6x46sZ6D!(e#@s#<soiooF9(*a*p+3~3ECD#NkZ=DB~pHY>=pz^o(7mfjo2OGCMqt_lUcHA7uzkNc<f2hoUv^X+4Sg835Xe)(=TeKmCZmM5e`#EUyzZ$oMbZ7vCF{Mx=16TIkR`S=h4KQSP+{TbK94}oh*KmBEj#62seWiAVoi5$Y)@86)E-hCn`9<Z@!ahZMQ+az?^MS)l%waus=;ZHA_v@fWa@&;I?(fm3G1{Jb<y`mkAT1P@OQi(`y6|SrcR-e?`59_=Yd)^`hpHdH9;c(C%kr1yBLn$&<S`k>qGhQ@?`j+6hvod;f&9|o)@%A2xpcQ`;SYC9CFSf*&EN4pwr4PZXE47M%Ku$1HD6I?=Oty&2e}(`4Lx~WJ|-WRPsr+gvE2S!^K8wrRVKmeZHfBzKk`H@ONP@#+Elf-i>=dVp-O7`d*H7CzXJRX;K!h&qrj8UlaDA4{0owC?o*OZA0pC>SK3rx>n=*QUW)7Qda!%Mvi|M$2??M+)Yn6~$J_7meW`KP*W72wzKwf7za#Jv+S7Ne5A>}2liD7GpBHeA0wGVk>)1+<TVAD?Q=6yhd_sHlGpX0({kE&u<9n{E&*Lvt_j+2Ntx-Jf-&&z~x@K#KJUtmtm+WbmJ*~YSKj?veug9&QZFD>?fFJ8Q@PHoB1A0LBOBnxPykor&QL1PBB^I=>aGo@?Ll3WS7*}m#GM<SW8OQi)vrzuYaw$#ud3K0lY*b`H48|-MS@}vP|D5qvjQbd0OL)Rq=mLv_@T^p@AB<z{wVv^#H9UU4ns4_U<9Hp!`aer}z5kSq{z(j4X7W+yuT(DAX_3kOto+|hw#Ib-Ps01ANPlMi|10B5_qrV4gD_q`uz&v-{jFo;xs;ak?+)$^wzuub=~BlxI=X`Gom&m`etgm!K$p!+kKPkTZSg9i+2Ymay5sR0bG`BS3UgiZc&#~KJnlB<naAtQ^~B>V&2`7)tIYk!<Mm|D7H{B#eG~T(uPxqa?q?qN62C3J+RPj9_!=^8i#M6)1CKYG=K_zfwOyB0WSzN>c^r1F*ADj)uPwfz0;Bt{n*5_A;%*1LiO{peL*|6>T+49oG6&Sk@DTxjOs~7#PCN&O^ykX)(U_m2;OC64UpdZB?SE0%UqiGyvBX~gC;I=UiuU|c_ft7vzhU}fd*0LkSFWF%x}VDVt&(W|1J*6m$8Fgp+2=pb>UiaP*e2QMQDlkc3D#GvlLlSCa$hJ8exeTeEb}k6r|8iB7Xe@GT5q14NUu=bvLEsI_yrrEm)Ls1Jjd&V*6Sla!B3v)V;&aoM8A^^eQ_M#!SQGM8pE$R^mmE1U-aX0+4py|%RXQAYu&%ixkr;v!3c?Dw5*nk$KkP@WKy*$HA1sTG@%tus}srecsQv>wR9${hI2C{lAfAQ#<W;8xO>;0E_)@K^h&7VOeTCvjit2ADH6|wr($X}H#Kz%Oe~TLni{97s{M!Lp+2>5I7Aa$yh4<yp(lprp@IE;iJk`o=)mxp+NUrNO6U+#4-6jcl?T;>{r!jgM%7Wdcd$>zTwElZ)0=wFOdCz^_4IIgxmYx;g)0(%Wu?x_WS`(cr5?;y^Qk;FnoX;d;Z&5S`34R`K{Sz4bJ<wb+HTr;kjJxG=0;B`@`=fErMsa7dWD1Pm@VXUmVBd0FnelB3y%ZWG6tW-r$h=oO_N|Mt;K?J??9Uto?y~MDi<8jC6dv$M3m^#WH>uXg3(hc@Mmx>W0X7<%VZPj6ep-qmWd_9RFOSRCpB6n3;=x$PNd;Mi_O4)eKv!cv_3(>*d$wOlhI6BGE9wyV_4ub)DWIZMBqU;hp{C=SnpG?Fm3kN|4KBjr|%{_f1SRoAc^_)hY6pv6u(>e1${9*>JaQPo<kn^6nmO?S%O#^?J@2<FSH+z8!?O-CdOR@?J+(?{w~8YAB^^RFE~Q@Zxt9vBFFm-k~n@Rh;dgydyF@c<5`UDcM1F?G438HV_b^7$D#d5rwL}@4Z`>p`J7O{*#BpkeJ|Eu!*jfkQE{D({d1)Jt&I}C7m(w<4N08;ykL)UGx8om-z)I%3ijp$<KlR^1^xrU9^a?PUBZ3C%ZucPf<4A1$i*;D?ElMz-@h0~Aa54*Mf=wTd#CS*PWHbN?D3v}+$}74aXfzuKZvT!_j&VsqP@O2{(pjBqs1QM*jMk<{x8HBd$ccquQg=+PP;;|!+AVUjQ)%HhzpH|eDqW5zaiM0@uZipN3=&;WEk3GeCGAq>x<{lCkzuW=xD#y!QRU4^3*-d-p2-xzGogGmHWTW(snByU1xAHA0W1WwS#?;Rj@4JqWymX{m5y7"
open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin)))
subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True)
| 1 | 3,562,082,658,060 | null | 81 | 81 |
def main():
a = input()
print a**3
main()
|
input_line = input()
input_line_cubic = input_line ** 3
print input_line_cubic
| 1 | 278,149,851,850 | null | 35 | 35 |
import sys
input = sys.stdin.readline
N = int(input())
op = []
ed = []
mid = [0]
dg = 10**7
for _ in range(N):
s = list(input())
n = len(s)-1
a,b,st = 0,0,0
for e in s:
if e == '(':
st += 1
elif e == ')':
if st > 0:
st -= 1
else:
a += 1
st = 0
for i in range(n-1,-1,-1):
if s[i] == ')':
st += 1
else:
if st > 0:
st -= 1
else:
b += 1
if a > b:
ed.append(b*dg + a)
elif a == b:
mid.append(a)
else:
op.append(a*dg + b)
op.sort()
ed.sort()
p = 0
for e in op:
a,b = divmod(e,dg)
if p < a:
print('No')
exit()
p += b-a
q = 0
for e in ed:
b,a = divmod(e,dg)
if q < b:
print('No')
exit()
q += a-b
if p == q and p >= max(mid):
print('Yes')
else:
print('No')
|
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
s = []
for _ in range(n):
s.append(input())
inc = []
zeros = []
dec = []
for i, j in enumerate(s):
minimum = 0
now = 0
for k in j:
if k == "(":
now += 1
else:
now -= 1
minimum = min(minimum, now)
if now > 0:
inc.append([minimum, i])
elif now < 0:
dec.append([minimum - now, i])
else:
zeros.append([minimum, i])
inc.sort(reverse=True)
dec.sort()
now = 0
for i, j in inc:
for k in s[j]:
if k == "(":
now += 1
else:
now -= 1
if now < 0:
print("No")
sys.exit()
for i, j in zeros:
for k in s[j]:
if k == "(":
now += 1
else:
now -= 1
if now < 0:
print("No")
sys.exit()
for i, j in dec:
for k in s[j]:
if k == "(":
now += 1
else:
now -= 1
if now < 0:
print("No")
sys.exit()
ans = "Yes" if now == 0 else "No"
print(ans)
| 1 | 23,653,572,702,120 | null | 152 | 152 |
s = input()[::-1]
size = len(s)
s += "4"
ans = 0
bef = 0
for i in range(size):
v1 = int(s[i])
v2 = int(s[i+1])
if v1+bef>=6 or (v1+bef>=5 and v2>=5):
ans += 10-(v1+bef)
bef = 1
else:
ans += (v1+bef)
bef = 0
ans += bef
print(ans)
|
import sys
n = int(input())
minv = int(input())
maxv = -1000000000
for r in map(int,sys.stdin.readlines()):
m = r-minv
if maxv < m:
maxv = m
if m < 0: minv = r
elif m < 0: minv = r
print(maxv)
| 0 | null | 35,346,395,437,330 | 219 | 13 |
import bisect
n = int(input())
lines = list(int(i) for i in input().split())
lines.sort()
counter = 0
for i in range(n-2):
for j in range(i+1, n-1):
counter += bisect.bisect_left(lines, lines[i] + lines[j]) - (j + 1)
print(counter)
|
from collections import deque
from bisect import bisect_left
n = int(input())
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
l_a = ld.popleft()
for b in range(a + 1, n - 1):
cnt += bisect_left(l, l_a + l[b]) - b - 1
print(cnt)
| 1 | 171,497,416,746,972 | null | 294 | 294 |
def a_painting():
from math import ceil
H = int(input())
W = int(input())
N = int(input())
return ceil(N / max(H, W))
print(a_painting())
|
n = input()
ans = 0
for i in range(len(n)):
ans += int(n[i])
ans %= 9
print("Yes" if ans % 9 == 0 else "No")
| 0 | null | 46,621,888,319,930 | 236 | 87 |
H, W = map(int, input().split())
S = []
for _ in range(H):
S.append(input())
import queue, itertools
dxy = ((1,0), (-1,0), (0,1), (0,-1))
ans = 0
for s in itertools.product(range(H), range(W)):
if S[s[0]][s[1]] == '#': continue
q = queue.Queue()
dist = [[-1]*W for _ in range(H)]
q.put(s)
dist[s[0]][s[1]] = 0
while not q.empty():
y, x = q.get()
for dx, dy in dxy:
nx, ny = x+dx, y+dy
if nx<0 or ny<0 or nx>=W or ny>=H or S[ny][nx] == '#' or dist[ny][nx] >= 0:
continue
dist[ny][nx] = dist[y][x] + 1
q.put((ny, nx))
ans = max(ans, max(map(max, dist)))
print(ans)
|
h,w=map(int,input().split())
g=[[*input()] for _ in range(h)]
from collections import *
def bfs(sx,sy):
d=[[-1]*w for _ in range(h)]
d[sx][sy]=0
q=deque([(sx,sy)])
while q:
x,y=q.popleft()
t=d[x][y]+1
for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
nx,ny=x+dx,y+dy
if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]<0:
d[nx][ny]=t
q.append((nx,ny))
return d
import numpy as np
a=0
for sx in range(h):
for sy in range(w):
if g[sx][sy]=='#': continue
a=max(a,np.max(bfs(sx,sy)))
print(a)
| 1 | 94,267,811,655,010 | null | 241 | 241 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
e = [(p[i]+1)/2 for i in range(n)]
tmp = sum(e[:k])
ans = tmp
for i in range(n-k):
tmp += (e[i+k]-e[i])
ans = max(ans, tmp)
print(ans)
|
# coding: utf-8
a, b = map(int, input().split(' '))
menseki = a * b
print(menseki, a*2 + b*2)
| 0 | null | 37,601,940,889,534 | 223 | 36 |
n=input()
c=[]
A=[]
for i in ['S ','H ','C ','D ']:
for j in map(str,range(1,14)):
A.append(i+j)
for i in range(n):
A.remove(raw_input())
for i in range(len(A)):
print A[i]
|
n = input()
data = []
space = []
for i in ['S ', 'H ', 'C ', 'D ']:
for j in map( str , xrange(1, 14)):
data.append(i + j)
for i in xrange(n):
data.remove(raw_input())
for i in xrange(len(data)):
print data[i]
| 1 | 1,031,147,026,000 | null | 54 | 54 |
mun = int(input())
print(mun+ mun*mun + mun*mun*mun)
|
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.union(a, b)
ans = 0
for r in uf.roots():
ans = max(ans, uf.size(r))
print(ans)
| 0 | null | 7,172,286,800,452 | 115 | 84 |
X,N=map(int,input().split())
p=list(map(int,input().split()))
for i in range(102):
if (X-i)not in p:
print(X-i)
exit()
elif (X+i)not in p:
print(X+i)
exit()
|
if __name__ == "__main__":
a = '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'
k = list(a.split(', '))
i = int(input())
print(k[i-1])
| 0 | null | 32,299,412,903,780 | 128 | 195 |
n = int(input())
a = list(map(int, input().split()))
a_ = [i for i in a if i % 2 == 0]
for i in a_:
bool_3 = i % 3 != 0
bool_5 = i % 5 != 0
if bool_3 and bool_5:
print('DENIED')
break
else:
print('APPROVED')
|
from sys import stdin
def main():
n = int(input())
a = list(map(int, input().split()))
flag = True
for i in range(n):
if (a[i] % 2 == 0):
if a[i] % 3 == 0 or a[i] % 5 == 0:
flag = True
else:
flag = False
break
if flag:
print('APPROVED')
else:
print('DENIED')
if __name__ == "__main__":
main()
| 1 | 69,116,938,466,430 | null | 217 | 217 |
N = int(input())
print('Yes' if N >= 30 else 'No')
|
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))
| 0 | null | 4,562,918,042,518 | 95 | 80 |
w, count = input(), 0
while True:
line = input()
if line == 'END_OF_TEXT':
break
count += line.lower().split().count(w)
print(count)
|
X = int(input())
d = {}
for i in range(0, 26):
d[i+1] = chr(97+i)
a = []
while X > 0:
if X%26 != 0:
a.append(d[(X % 26)])
X -= X % 26
else:
a.append(d[26])
X -= 26
X //= 26
for i in a[::-1]:
print(i, end='')
print()
| 0 | null | 6,916,488,774,810 | 65 | 121 |
a,b = input().split()
#print(a,b)
A = int(a)
x,y = b.split('.')
B = int(x)*100+int(y)
print(int(A*B)//100)
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
15 6
1 2 7 8 12 50
output:
2
"""
import sys
def solve():
rec[0] = 0
for coin in coins:
for current_cost in range(coin, total_cost + 1):
rec[current_cost] = min(rec[current_cost], rec[current_cost - coin * 1] + 1)
return rec
if __name__ == '__main__':
_input = sys.stdin.readlines()
total_cost, c_num = map(int, _input[0].split())
coins = list(map(int, _input[1].split()))
# assert len(coins) == c_num
rec = [float('inf')] * (total_cost + 1)
ans = solve()
print(ans[-1])
| 0 | null | 8,414,211,064,612 | 135 | 28 |
alp = input()
if alp==alp.upper() :
print("A")
else :
print("a")
|
s = input()
t = input()
sl = len(s)
tl = len(t)
ans = 1001
for i in range(sl-tl+1):
cnt = 0
for sv, tv in zip(s[i:i+tl], t):
if sv != tv:
cnt += 1
ans = min(cnt, ans)
print(ans)
| 0 | null | 7,531,374,826,470 | 119 | 82 |
n,k,*a=map(int,open(0).read().split())
for i in range(n-k):print("Yes" if a[i]<a[i+k] else "No")
|
def resolve():
n,k = map(int,input().split())
print(min(n-k*(n//k),abs(n-k*(n//k)-k)))
resolve()
| 0 | null | 23,184,056,907,580 | 102 | 180 |
n=int(input())
a=[0]+[int(x) for x in input().split()]
ans=[0]*(n+1)
for i in range(len(a)):
ans[a[i]]=i
ans.pop(0)
print(*ans)
|
import math
H, W, K = map(int, input().split())
S = [list(map(lambda x: int(x=='1'), input())) for _ in range(H)]
def cal_min_vert_div(hs):
cnt = 0
n_h_div = len(hs)
n_white = [0]*n_h_div
for i in range(W):
for j in range(n_h_div):
n_white[j] += hs[j][i]
if n_white[j] > K:
n_white = [hs[k][i] for k in range(n_h_div)]
cnt += 1
if max(n_white)>K:
return math.inf
break
return cnt
ans = math.inf
for mask in range(2**(H-1)):
hs = []
tmp = S[0]
for i in range(H-1):
if mask>>i & 1:
hs.append(tmp)
tmp = S[i+1]
else:
tmp = [tmp[w]+S[i+1][w] for w in range(W)]
hs.append(tmp)
tmp = cal_min_vert_div(hs)+sum(map(int, bin(mask)[2:]))
ans = min(ans, tmp)
print(ans)
| 0 | null | 114,765,725,314,228 | 299 | 193 |
X = int(input())
a = []
c = []
if X % 2 == 1:
while a == []:
for i in range(3,X,2):
b = X % i
a.append(b)
if 0 in a:
a = []
X += 1
else:
print(X)
elif X == 2:
print(X)
else:
X += 1
while c == []:
for i in range(3,X,2):
d = X % i
c.append(d)
if 0 in c:
c = []
X += 1
else:
print(X)
|
n = int(input())
s, t = input().split()
ret = ''
for i, j in zip(s, t):
ret += i
ret += j
print(ret)
| 0 | null | 108,863,075,432,540 | 250 | 255 |
n, k = map(int, input().split())
mod = 10 ** 9 + 7
ans = 0
coma = 1
comb = 1
for i in range(min(k+1, n)):
ans += coma * comb
ans %= mod
coma *= (n-i) * pow(i+1, mod-2, mod)
coma %= mod
comb *= (n-i-1) * pow(i+1, mod-2, mod)
comb %= mod
print(ans)
|
N,K=map(int,input().split())
mod=10**9+7
def cmb(n,r):
global mod
if r<0 or r>n:
return 0
return (g1[n]*g2[r]*g2[n-r])%mod
g1=[1,1]
g2=[1,1]
inv=[0,1]
for i in range(2,1000003):
g1.append((g1[-1]*i)%mod)
inv.append((-inv[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inv[-1])%mod)
P=0
for i in range(min(N,K+1)):
P=(P+cmb(N,i)*cmb(N-1,i))%mod
print(P)
| 1 | 67,290,183,974,142 | null | 215 | 215 |
from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
x = readInt()
for i in range(int(x//105),int(x//100)+2):
t = x-100*i
if 0<=t and t<=5*i:
print(1)
exit()
print(0)
|
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()
def main():
x, k, d = map(int, input().split())
desired = abs(x) // d
if k <= desired:
if x < 0:
x += k * d
else:
x -= k * d
print(abs(x))
return
if x < 0:
x += desired * d
else:
x -= desired * d
if (k - desired) % 2 == 0:
print(abs(x))
return
if x == 0:
print(d)
elif x > 0:
x -= d
print(abs(x))
elif x < 0:
x += d
print(abs(x))
if __name__ == '__main__':
main()
| 0 | null | 66,243,255,996,732 | 266 | 92 |
N,M = map(int, input().split())
A_list = [int(i) for i in input().split()]
playable_days = N - sum(A_list)
if playable_days >= 0:
print(playable_days)
else:
print("-1")
|
r = input()
r = float(r)
a = 3.14159265359*r*r
c = 2*3.14159265359*r
print("%.6f %.6f" % (a, c))
| 0 | null | 16,440,272,940,112 | 168 | 46 |
n=int(input())
lst=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
#S_list=lst
#H_list=lst
#C_list=lst
#D_list=lst
S_list=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
H_list=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
C_list=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
D_list=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
for i in range(n):
Del=map(str,raw_input().split())
if Del[0]=="S":
S_list.remove(Del[1])
elif Del[0]=="H":
H_list.remove(Del[1])
elif Del[0]=="C":
C_list.remove(Del[1])
elif Del[0]=="D":
D_list.remove(Del[1])
S=map(int,S_list)
H=map(int,H_list)
C=map(int,C_list)
D=map(int,D_list)
#
for i in range(len(S)):
print "S "+str(S[i])
for i in range(len(H)):
print "H "+str(H[i])
for i in range(len(C)):
print "C "+str(C[i])
for i in range(len(D)):
print "D "+str(D[i])
|
#coding:utf-8
H,W=map(int,input().split())
while not(H==0 and W==0):
for i in range(0,H):
for j in range(0,W):
if i==0 or j==0 or i==H-1 or j==W-1:
print("#",end="")
else:
print(".",end="")
print("")
print("")
H,W=map(int,input().split())
| 0 | null | 933,545,301,180 | 54 | 50 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
15 6
1 2 7 8 12 50
output:
2
"""
import sys
def solve():
rec[0] = 0
for i in range(c_num):
for j in range(coins[i], money + 1):
rec[j] = min(rec[j], rec[j - coins[i]] + 1)
return rec
if __name__ == '__main__':
_input = sys.stdin.readlines()
money, c_num = map(int, _input[0].split())
coins = list(map(int, _input[1].split()))
# assert len(coins) == c_num
rec = [float('inf')] * (money + 1)
ans = solve()
print(ans.pop())
|
h, n = map(int,input().split())
a = list(map(int,input().split()))
hitpoint=h
atack = a[:]
for e in atack:
hitpoint -= e
if hitpoint <= 0:
break
if hitpoint <= 0:
print("Yes")
else:
print("No")
| 0 | null | 39,284,632,266,900 | 28 | 226 |
z=list(map(int,input().split()))
z.sort()
a=0
while True:
if z[1]==z[0]:
break
a=z[1]-z[0]
if z[0]%a==0:
z[1] = z[0]
z[0] = a
z.sort()
break
z[1]=z[0]
z[0]=a
z.sort()
print(z[0])
|
a = list(map(int, input().split()))
a.sort()
while a[0] > 0:
b = a[1]%a[0]
a[1] = a[0]
a[0] = b
print(a[1])
| 1 | 7,904,222,148 | null | 11 | 11 |
# import itertools
# import math
import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, K = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()
# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)
# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)
# def dfs(tree, s):
# for l in tree[s]:
# if depth[l[0]] == -1:
# depth[l[0]] = depth[s] + l[1]
# dfs(tree, l[0])
# dfs(tree, 1)
A.insert(0, 0)
cnt = [0] * (N + 1)
j = 1
times_s = 0
times_e = 0
cycle = 0
for i in range(N + 1):
if i == K:
print(j)
sys.exit()
cnt[j] += 1
if cnt[j] == 2:
times_e = i
cycle = j
break
j = A[j]
j = 1
for i in range(N + 1):
if j == cycle:
times_s = i
break
j = A[j]
#print(A, cnt)
#print(times_s, times_e, cycle)
K_eff = (K - times_s) % (times_e - times_s)
for i in range(N + 1):
if i == K_eff:
print(j)
sys.exit()
j = A[j]
|
h_1, m_1, h_2, m_2, k = map(int, input().split())
time_m = h_2*60 + m_2 - (h_1*60 + m_1) - k
print(time_m)
| 0 | null | 20,401,580,438,758 | 150 | 139 |
d=input()
if d.count("A")==3 or d.count("B")==3: print("No")
else: print("Yes")
|
S = input()
companies = {company for company in S}
if len(companies) > 1:
print('Yes')
else:
print('No')
| 1 | 54,893,183,473,138 | null | 201 | 201 |
def main():
S, T = input().split()
A, B = map(int, input().split())
U = input()
print(A-1 if S == U else A, B if S == U else B-1)
if __name__ == "__main__":
main()
|
s, t = input().split()
a, b = map(int, input().split())
u = input()
if s == u:
x = a - 1
y = b
else:
x = a
y = b - 1
print(x, y)
| 1 | 72,057,158,072,968 | null | 220 | 220 |
n,m=map(int,input().split())
su=input()
rev=su[::-1]
if "1"*m in su:
print(-1)
exit()
dist_f_n=[float('inf')]*(n+1)
dist_f_n[0]=0
for i in range(1,m+1):
if rev[i]=="0":
dist_f_n[i]=1
last=i
if i==n:
break
while last<n:
for i in range(last+1,last+m+1):
if rev[i]=="0":
dist_f_n[i]=dist_f_n[last]+1
_last=i
if i==n:
break
last=_last
cur=dist_f_n[-1]
_i=0
ans=[]
for i,x in enumerate(dist_f_n[::-1]):
if x==cur-1:
ans.append(i-_i)
cur-=1
_i=i
print(" ".join(map(str,ans)))
|
n,m = map(int,input().split())
s = input()[::-1]
idx = 0
ans = [0]
while True:
flg = False
step = 0
for i in range(1, m+1):
if idx+i <= n:
if s[idx+i]=='0':
step = i
flg = True
if flg==False:
break
else:
idx += step
ans.append(idx)
if ans[-1]!=n:
print(-1)
else:
ret = []
for i in range(1,len(ans)):
ret.append(ans[i]-ans[i-1])
print(*ret[::-1])
| 1 | 138,701,100,739,410 | null | 274 | 274 |
n,a,b = map(int,input().split())
#組み合わせ(数が大きいとき)(10**9+7で割ったもの)
q = 10**9+7
def comb(a, b):
c = 1
for i in range(b):
c *= a - i
c %= q
d = 1
for i in range(b):
d *= i + 1
d %= q
return c*pow(d, q-2, q)
p = pow(2,n,q)-1-comb(n,a)-comb(n,b)
print(p%(10**9+7))
|
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
def frac_rev(n, r):
x = 1
for i in range(n, n-r, -1):
x = x * i % mod
return x
def frac(n):
x = 1
for i in range(1, n+1):
x = x * i % mod
return x
print(( pow(2, n, mod) - 1 - frac_rev(n, a) * pow(frac(a), mod-2, mod) % mod - frac_rev(n, b) * pow(frac(b), mod-2, mod) % mod) % mod)
| 1 | 66,350,381,400,032 | null | 214 | 214 |
n,k=map(int,input().split())
fact=[1]
for i in range(1,2*n):
fact.append((fact[i-1]*(i+1))%(10**9+7))
factinv=[]
for i in range(n):
factinv.append(pow(fact[i],10**9+5,10**9+7))
if k==1:
print((n*(n-1))%(10**9+7))
elif k>=n-1:
print((fact[2*n-2]*factinv[n-1]*factinv[n-2])%(10**9+7))
else:
ans=1
for i in range (k):
ans=(ans+fact[n-1]*factinv[i]*factinv[n-i-2]*fact[n-2]*factinv[i]*factinv[n-i-3])%(10**9+7)
print(ans)
|
N, K = map(int, input().split())
MOD = 10**9 + 7
MAX_N = 10**6 + 5
fact = [0]*(MAX_N)
fact_inv = [0]*(MAX_N)
fact[0] = 1
for i in range(MAX_N-1):
fact[i+1] = fact[i]*(i+1) % MOD
fact_inv[-1] = pow(fact[-1], MOD-2, MOD)
for i in range(MAX_N-2, -1, -1):
fact_inv[i] = fact_inv[i+1]*(i+1) % MOD
def comb(n, k):
return fact[n]*fact_inv[k] % MOD * fact_inv[n-k] % MOD
if K >= N:
print(comb(2*N-1, N-1))
exit()
ans = 1
for i in range(1, K+1):
ans += comb(N, i)*comb(N-1, i) % MOD
ans %= MOD
print(ans)
| 1 | 67,153,442,923,388 | null | 215 | 215 |
k = int(input())
a, b = map(int, input().split())
for n in range(a, b+1):
if n % k == 0:
print('OK')
break
if n == b:
print('NG')
|
K = int(input())
A, B = map(int, input().split())
for i in range(0, B+1, K):
if i >= A:
print("OK")
exit()
print("NG")
| 1 | 26,720,300,519,208 | null | 158 | 158 |
#!/usr/bin/env python3
def main():
n = int(input())
ls = []
for i in range(n):
p = list(map(int, input().split()))
np = (p[0] + p[1], p[0] - p[1])
ls.append(np)
minx = float("inf")
miny = float("inf")
maxx = -float("inf")
maxy = -float("inf")
for i in range(len(ls)):
x, y = ls[i]
minx = min(minx, x)
miny = min(miny, y)
maxx = max(maxx, x)
maxy = max(maxy, y)
print(max(maxx - minx, maxy - miny))
main()
|
def main():
s, w = map(int, input().split(" "))
if s <= w:
print("unsafe")
else:
print("safe")
if __name__ == "__main__":
main()
| 0 | null | 16,370,966,349,490 | 80 | 163 |
N = int(input())
a = N // 2
b = N % 2
print(a + b)
|
def main():
n, m, l = tuple(map(int, input().split()))
matA = [[0 for j in range(m)] for i in range(n)]
matB = [[0 for k in range(l)] for j in range(m)]
matC = [[0 for k in range(l)] for i in range(n)]
for i in range(n):
tmp = list(map(int, input().split()))
for j in range(m):
matA[i][j] = tmp[j]
for j in range(m):
tmp = list(map(int, input().split()))
for k in range(l):
matB[j][k] = tmp[k]
for i in range(n):
for k in range(l):
for j in range(m):
matC[i][k] += matA[i][j] * matB[j][k]
for i in range(n):
for k in range(l):
if k == l-1:
print(matC[i][k])
else:
print(matC[i][k], end=' ')
if __name__ == '__main__':
main()
| 0 | null | 30,246,664,518,112 | 206 | 60 |
from math import sqrt
itl = lambda: list(map(float, input().strip().split()))
def median(N, C):
if N % 2:
return C[N // 2]
else:
return C[N // 2 - 1] + C[N // 2]
def solve():
N = int(input())
A = []
B = []
for _ in range(N):
a, b = itl()
A.append(int(a))
B.append(int(b))
A.sort()
B.sort()
ma = median(N, A)
mb = median(N, B)
return mb - ma + 1
if __name__ == '__main__':
print(solve())
|
class COM:
def __init__(self, n: int, mod: int):
self.n = n
self.mod = mod
self.fact = [0] * (n + 1)
self.factinv = [0] * (n + 1)
self.inv = [0] * (n + 1)
self.fact[0] = self.fact[1] = 1
self.factinv[0] = self.factinv[1] = 1
self.inv[1] = 1
for i in range(2, n + 1):
self.fact[i] = (self.fact[i - 1] * i) % mod
self.inv[i] = (-self.inv[mod % i] * (mod // i)) % mod
self.factinv[i] = (self.factinv[i - 1] * self.inv[i]) % mod
def get_cmb(self, n: int, k: int):
if (k < 0) or (n < k):
return 0
k = min(k, n - k)
return self.fact[n] * self.factinv[k] % self.mod * self.factinv[n - k] % self.mod
def solve():
n, k = map(int, input().split())
MOD = 10 ** 9 + 7
com = COM(n, MOD)
ans = 0
for i in range(min(n, k + 1)):
ans += com.get_cmb(n, i) * com.get_cmb(n - 1, i)
ans %= MOD
print(ans)
if __name__ == '__main__':
solve()
| 0 | null | 42,266,960,140,768 | 137 | 215 |
X,K,D = map(int,input().split())
ans = 0
if X == 0:
if K % 2 == 0:
ans = 0
else:
ans = D
if X > 0:
if K*D <= X:
ans = X - K*D
else:
n = X // D
if X % D != 0:
n += 1
if (K - n) % 2 == 0:
ans = abs(X-D*n)
else:
ans = abs(X-D*(n-1))
if X < 0:
if K*D + X <= 0:
ans = abs(K*D+X)
else:
n = -X // D
if -X % D != 0:
n += 1
if (K-n) % 2 == 0:
ans = abs(X+n*D)
else:
ans = abs(X+(n-1)*D)
print(ans)
|
A, B, C, D = map(int, input().split())
takahashi_hp = A
aoki_hp = C
while True:
aoki_hp -= B
if aoki_hp <= 0:
break
takahashi_hp -= D
if takahashi_hp <= 0:
break
if takahashi_hp <= 0:
print("No")
else:
print("Yes")
| 0 | null | 17,634,657,266,094 | 92 | 164 |
import math
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
def isprime(x):
if x == 2:
return True
elif x % 2 == 0:
return False
i = 3
while i <= math.sqrt(x):
if x % i == 0:
return False
i += 2
else:
return True
counter = 0
for i in a:
if isprime(i) == True:
counter += 1
print(counter)
|
import os, sys, re, math
S = input()
dow = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - dow.index(S))
| 0 | null | 66,479,808,619,268 | 12 | 270 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from collections import Counter
n, p = map(int, readline().split())
s = readline().rstrip().decode()
cnt = 0
if p == 2 or p == 5:
for i, ss in enumerate(s):
if int(ss) % p == 0:
cnt += (i + 1)
else:
memo = [0]
m = 0
d = 1
for ss in s[::-1]:
m += int(ss) * d
m %= p
d *= 10
d %= p
memo.append(m)
counter = Counter(memo)
for i in range(p + 1):
cnt += counter[i] * (counter[i] - 1) // 2
print(cnt)
|
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
N,P=map(int, sys.stdin.readline().split())
S=sys.stdin.readline().strip()
if P in (2,5):
ans=0
for i,x in enumerate(S):
if int(x)%P==0:
ans+=i+1
print ans
else:
L=[int(S)%P]
for i,x in enumerate(S):
L.append((L[-1]-int(x)*pow(10,N-1-i,P))%P)
ans=0
D=defaultdict(lambda: 0)
for i in range(N,-1,-1):
x=L[i]
ans+=D[x]
D[x]+=1
print ans
| 1 | 58,010,410,850,300 | null | 205 | 205 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.