code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
n,m,l = map(int,input().split())
A,B,C = [],[],[]
for i in range(n):
A.append(list(map(int,input().split())))
for ii in range(m):
B.append(list(map(int,input().split())))
for k in range(n):
ans = []
for s in range(l):
cul = 0
for kk in range(m):
cul += A[k][kk] * B[kk][s]
ans.append(cul)
ans = list(map(str,ans))
print(" ".join(ans))
|
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
ans += k
k = 0
else:
ans += a
k -= a
if b >= k:
k = 0
else:
k -= b
if c >= k:
ans -= k
print(ans)
| 0 | null | 11,700,786,205,602 | 60 | 148 |
n = int(input())
s = list(str(n))
r = list(reversed(s))
if r[0] in ["2","4","5","7","9"]:
print("hon")
elif r[0] in ["0","1","6","8"]:
print("pon")
else:
print("bon")
|
n = input()
k = int(n[-1])
if k == 3:
print("bon")
elif k == 0 or k == 1 or k == 6 or k == 8:
print("pon")
else:
print("hon")
| 1 | 19,272,835,032,640 | null | 142 | 142 |
n = int(input())
p = list(map(int,input().split()))
ans = n
m = 2 * (10 ** 5)
for i in range(n):
m = min(p[i],m)
if p[i] > m:
ans -= 1
print(ans)
|
N = input()
a = []
for i in range(N):
a.append(map(int, raw_input().split()))
for j in range(N):
x = a[j][0] ** 2
y = a[j][1] ** 2
z = a[j][2] ** 2
if x == y + z:
print "YES"
elif y == x + z:
print "YES"
elif z == x + y:
print "YES"
else:
print "NO"
| 0 | null | 42,461,188,588,988 | 233 | 4 |
import sys
n = int(input())
ls = [list(map(int,input().split())) for _ in range(n)]
for i in range(n-2):
if ls[i][0] == ls[i][1]:
if ls[i+1][0] == ls[i+1][1]:
if ls[i+2][0] == ls[i+2][1]:
print("Yes")
sys.exit()
print("No")
|
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read
def main():
global field
R, C, K = map(int, input().split())
field = []
for _ in range(R):
tmp = [0] * C
field.append(tmp)
DP1 = copy.deepcopy(field)
DP2 = copy.deepcopy(field)
DP3 = copy.deepcopy(field)
for _ in range(K):
r, c, k = map(int, input().split())
field[r-1][c-1] = k
i = 0
DP1[0][0] = field[0][0]
for j in range(1, C):
DP3[i][j] = max(DP2[i][j-1] + field[i][j], DP3[i][j-1])
DP2[i][j] = max(DP1[i][j-1] + field[i][j], DP2[i][j-1])
DP1[i][j] = max(field[i][j], DP1[i][j-1])
for i in range(1, R):
for j in range(C):
DP3[i][j] = max(DP2[i][j-1] + field[i][j], DP3[i][j-1])
DP2[i][j] = max(DP1[i][j-1] + field[i][j], DP2[i][j-1])
DP1[i][j] = max(field[i][j], DP1[i][j-1], max(DP1[i-1][j], DP2[i-1][j], DP3[i-1][j]) + field[i][j])
ans = max(DP3[R-1][C-1], DP2[R-1][C-1], DP1[R-1][C-1])
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 3,981,140,419,760 | 72 | 94 |
n, m = map(int, input().split())
if m >= 2:
if n < 2:
print(int(m*(m-1)/2))
quit()
else:
print(int(m*(m-1)/2 + n*(n-1)/2))
quit()
if m < 2:
if n < 2:
print(0)
else:
print(int(n*(n-1)/2))
|
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, m = M()
print(n*(n-1)//2 + m*(m-1)//2)
| 1 | 45,650,681,716,686 | null | 189 | 189 |
a,v = map(int,input().split())
b,m = map(int,input().split())
n = int(input())
dis = abs(a-b)
a_move = n*v
b_move = n*m
if dis+b_move - a_move <= 0:
print('YES')
else:
print('NO')
|
while True:
n, x = map(int, input().split())
if n == x == 0:
break
cnt = 0
for a in range(1, x // 3):
for b in range(a + 1, x // 2):
c = x - a - b
if b < c <= n:
cnt += 1
print(cnt)
| 0 | null | 8,280,700,332,480 | 131 | 58 |
N = int(input())
As = list(map(int,input().split()))
max = 0
sum = 0
for i in range(N):
if max < As[i]:
max = As[i]
else:
sum += (max-As[i])
print(sum)
|
N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(N-1):
if A[i+1] < A[i]:
count=count+A[i]-A[i+1]
A[i+1]=A[i]
else:
count=count
print(count)
| 1 | 4,596,302,205,076 | null | 88 | 88 |
s=input().strip()
print("Yes"if s[2] == s[3] and s[4] == s[5] else "No")
|
from itertools import combinations_with_replacement as cwr
[N, M, Q] = [int(i) for i in input().split()]
req = [list(map(int, input().split())) for _ in range(Q)]
ans = 0
for seq in cwr(range(1, M+1), N):
sco = 0
for i in range(Q):
if seq[req[i][1]-1] - seq[req[i][0]-1] == req[i][2]:
sco += req[i][3]
s = max(ans, sco)
ans = s
print(ans)
| 0 | null | 34,884,869,369,742 | 184 | 160 |
n = int(input())
cnt=0
for _ in range(n):
a,b=map(int,input().split())
if a==b:
cnt+=1
if cnt>=3:
break
else:
cnt=0
if cnt>=3:
print("Yes")
else:
print("No")
|
n, x, m = map(int, input().split())
ans = 0
prev_set = set()
prev_list = list()
ans_hist = list()
r = x
for i in range(n):
if i == 0:
pass
else:
r = (r * r) % m
if r == 0:
break
if r in prev_set:
index = prev_list.index(r)
period = i - index
count = (n - index) // period
rest = (n - index) % period
ans = sum(prev_list[:index])
ans += sum(prev_list[index:i]) * count
# ans += (ans - ans_hist[index - 1]) * (count - 1)
ans += sum(prev_list[index:index+rest])
# ans += (ans_hist[index + rest - 1] - ans_hist[index - 1])
break
else:
ans += r
prev_set.add(r)
prev_list.append(r)
ans_hist.append(ans)
print(ans)
| 0 | null | 2,675,326,483,592 | 72 | 75 |
import sys
input = lambda: sys.stdin.readline().rstrip()
INF = 10 ** 9 + 7
H, N = map(int, input().split())
AB = [[] for _ in range(N)]
for i in range(N):
AB[i] = list(map(int, input().split()))
def solve():
dp = [INF] * (H + 1)
dp[H] = 0
for h in range(H, 0, -1):
if dp[h] == INF:
continue
next_dp = dp
for i in range(N):
a, b = AB[i]
hh = max(0, h - a)
next_dp[hh] = min(dp[hh], dp[h] + b)
dp = next_dp
print(dp[0])
if __name__ == '__main__':
solve()
|
def chmin(dp, i, *x):
dp[i] = min(dp[i], *x)
INF = float("inf")
# dp[i] := min 消耗する魔力 to H -= i
h, n = map(int, input().split())
dp = [0] + [INF]*h
for _ in [None]*n:
a, b = map(int, input().split())
for j in range(h + 1):
chmin(dp, min(j + a, h), dp[j] + b)
print(dp[h])
| 1 | 81,011,211,595,100 | null | 229 | 229 |
n, d = list(map(int, input().split(' ')))
res = 0
for _ in range(n):
x, y = list(map(int, input().split(' ')))
if d ** 2 >= (x ** 2) + (y ** 2):
res += 1
print(res)
|
import sys
N, D = map(int, input().split())
ans = 0
for _ in range(N):
x, y = map(int, sys.stdin.readline().split())
if x **2 + y**2 <= D**2:
ans += 1
print(ans)
| 1 | 5,950,336,644,560 | null | 96 | 96 |
import copy
N = int(input())
A = input().split()
B = copy.copy(A)
boo = 1
while boo:
boo = 0
for i in range(N-1):
if A[i][1] > A[i+1][1]:
A[i], A[i+1] = A[i+1], A[i]
boo = 1
print(*A)
print("Stable")
for i in range(N):
mi = i
for j in range(i,N):
if B[mi][1] > B[j][1]:
mi = j
B[i], B[mi] = B[mi], B[i]
if A==B:
print(*B)
print("Stable")
else:
print(*B)
print("Not stable")
|
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def bubble_sort(A):
for i in range(len(A)):
for x in range(len(A)-1, i, -1):
if A[x][1] < A[x-1][1]:
A[x], A[x-1] = A[x-1], A[x]
def selection_sort(A):
for i in range(len(A)):
min_val = A[i][1]
for x in range(i, len(A)):
if A[x][1] < min_val:
min_val = A[x][1]
min_index = x
if min_val < A[i][1]:
A[min_index], A[i] = A[i], A[min_index]
def check_stable(srt_list, org_list):
prev_val = None
prev_pos = -1
for card in srt_list:
cur_pos = org_list.index(card)
# print(card, cur_pos)
if card[1] == prev_val:
if cur_pos < prev_pos:
print('Not stable')
return
prev_val = card[1]
prev_pos = cur_pos
print('Stable')
n = int(sys.stdin.readline())
org_list = sys.stdin.readline().split()
_list1 = org_list[:]
_list2 = org_list[:]
bubble_sort(_list1)
selection_sort(_list2)
print(' '.join(_list1))
check_stable(_list1, org_list)
print(' '.join(_list2))
check_stable(_list2, org_list)
| 1 | 24,958,652,500 | null | 16 | 16 |
def main():
A=int(input())
B=int(input())
for i in range(1,4):
if i not in (A,B):
print(i)
return
main()
|
N=int(input())
S=set()
for i in range(1,N):
x=i
y=N-i
if x<y:
S.add(x)
print(len(S))
| 0 | null | 132,047,541,352,860 | 254 | 283 |
N,K,S = [int(hoge) for hoge in input().split()]
import math
#累積和数列であって、Ar-Al=Sを満たすものが丁度K個ある
if S==10**9:
print(*([S]*K + [27]*(N-K)))
elif S:
print(*([S]*K + [S+1]*(N-K)))
else:
ans = []
while 1:
if K==2:
ans +=[0,1,0]
break
for R in range(N):
if (R+1)*(R+2)//2 > K:break
print(K)
if K==0:break
ans += [0]*R+[1]
K = K - R*(R+1)//2
print(ans + [1]*(N-len(ans)))
|
N = int(input())
count = 0
for i in range(1,N+1):
if i % 2 == 1:
count += 1
else:
pass
print(count/N)
| 0 | null | 133,865,479,436,740 | 238 | 297 |
'''
Created on 2020/08/23
@author: harurun
'''
def f(n):
arr=[]
temp=n
for c in range(2,int(-(-n**0.5//1))+1):
if temp%c==0:
cnt=0
while temp%c==0:
cnt+=1
temp//=c
arr.append([c,cnt])
if temp!=1:
arr.append([temp,1])
return arr
def main():
import math
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N=int(pin())
r=f(N)
ans=0
for i in r:
ans+=int((math.sqrt(1+8*i[1])-1)/2)
print(ans)
return
main()
|
N = int(input())
c = 0
b = [0]*1000
p = 0
while N % 2 == 0:
b[p] += 1
N //= 2
if b[p]!=0:
p += 1
i = 3
while i * i <= N:
if N % i == 0:
b[p] += 1
N //= i
else:
i += 2
if b[p]!=0:
p += 1
if N==i:
b[p] += 1
N //= i
if N!=1:
p += 1
b[p] += 1
for v in b:
for i in range(1,v+1):
if i<=v:
c += 1
v -= i
else:
break
print(c)
| 1 | 16,856,327,371,602 | null | 136 | 136 |
# coding:utf-8
n = int(input())
count = 0
for i in range(n):
d1, d2 = map(int, input().split())
if d1 == d2:
count += 1
else:
count = 0
if count == 3:
print('Yes')
exit()
print('No')
|
cards = {
"S": [0 for n in range(13)],
"H": [0 for n in range(13)],
"C": [0 for n in range(13)],
"D": [0 for n in range(13)]
}
t = int(input())
for n in range(t):
a,b = input().split()
cards[a][int(b)-1] = 1
for a in ("S", "H","C", "D"):
for b in range(13):
if cards[a][b] == 0:
print(a,b+1)
| 0 | null | 1,749,618,441,552 | 72 | 54 |
N = int(input())
ST = [list(input().split()) for _ in [0]*N]
X = input()
ans = 0
for i,st in enumerate(ST):
s,t = st
if X==s:
break
for s,t in ST[i+1:]:
ans += int(t)
print(ans)
|
n,a,b = list(map(int,input().split()))
ans = n // (a+b) * a
n %= (a+b)
if n > a:
print(ans + a)
else:
print(ans + n)
| 0 | null | 76,249,134,461,540 | 243 | 202 |
MOD = 10 ** 9 + 7
K = int(input())
S = input()
l = len(S)
fac = [1] * (K + l + 1)
for i in range(1, K + l + 1):
fac[i] = (fac[i - 1] * i) % MOD
p25 = [1] * (K + 1)
p26 = [1] * (K + 1)
for i in range(1, K + 1):
p25[i] = (p25[i - 1] * 25) % MOD
p26[i] = (p26[i - 1] * 26) % MOD
ans = 0
for en in range(l - 1, l + K):
t = (fac[en] * pow(fac[en - l + 1], MOD - 2, MOD) * pow(fac[l - 1], MOD - 2, MOD)) % MOD
t = (t * p25[en - l + 1]) % MOD
t = (t * p26[l + K - 1 - en]) % MOD
ans = (ans + t) % MOD
print(ans)
|
def main():
k = int(input())
s = input()
n = len(s)
def cmb1(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 2*10**6
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(range(N)):
finv[i] = finv[i+1] * (i+1) % mod
def cmb1(n, r, mod):
if r <0 or r > n:
return 0
r = min(r, n-r)
return fac[n] * finv[r] * finv[n-r] % mod
def power(a, n, mod):
bi=str(format(n,"b")) #2進数
res=1
for i in range(len(bi)):
res=(res*res) %mod
if bi[i]=="1":
res=(res*a) %mod
return res
ans = 0
for i in range(k+1):
temp = power(25, i, mod)
temp *= cmb1(i+n-1, n-1, mod)
temp %= mod
temp *= power(26, k-i, mod)
temp %= mod
ans += temp
print(ans%mod)
if __name__ == '__main__':
main()
| 1 | 12,749,729,034,908 | null | 124 | 124 |
N = int(input())
n = N%10
honList = [2, 4, 5, 7, 9]
ponList = [0, 1, 6, 8]
if n in honList:
print('hon')
elif n in ponList:
print('pon')
else :
print('bon')
|
N = input()
if N[-1] == '2' or N[-1] == '4' or N[-1] == '5' or N[-1] == '7' or N[-1] == '9':
Yomi = 'hon'
elif N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8':
Yomi = 'pon'
elif N[-1] == '3':
Yomi = 'bon'
print(Yomi)
| 1 | 19,408,977,923,940 | null | 142 | 142 |
def solve():
N = int(input())
return N*N
print(solve())
|
def main():
r = int(input())
print(r**2)
if __name__ == "__main__":
main()
| 1 | 145,013,114,087,492 | null | 278 | 278 |
#!/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 main():
from functools import reduce
def a_comb_mod(n, r):
mod = 1000000007
r = min(n-r,r)
if r == 0: return 1
numer = reduce(lambda x, y: x * y % mod, range(n, n - r, -1), 1)
denom = reduce(lambda x, y: x * y % mod, range(1,r + 1), 1)
denom_inv = pow(denom, mod - 2, mod)
return numer * denom_inv % mod
n, a, b = list(map(int, input().split()))
mod = 1000000007
print((pow(2, n, mod) - 1 - a_comb_mod(n, a) - a_comb_mod(n, b)) % mod)
if __name__ == '__main__':
main()
| 1 | 66,056,580,673,468 | null | 214 | 214 |
N = int(input())
A_list = list(map(int, input().split()))
for i in range(N):
if A_list[i] % 2 == 0:
if A_list[i] % 3 == 0 or A_list[i] % 5 == 0:
continue
else:
print("DENIED")
exit()
if i == N-1:
print("APPROVED")
|
N = int(input())
N_List = list(map(int,input().split()))
ct = 0
Current_Min = 2*(10**5) + 1
for i in range(N):
if N_List[i] <= Current_Min:
ct += 1
Current_Min = N_List[i]
print(ct)
| 0 | null | 77,434,471,987,796 | 217 | 233 |
N, X, M = map(int, input().split())
checked = [-1] * M
a = X
i = 0
while checked[a] == -1 and i < N:
checked[a] = i
a = a**2 % M
i += 1
if i == N:
a = X
ans = 0
for _ in range(N):
ans += a
a = a**2%M
print(ans)
else:
cycle_size = i - checked[a]
cycle_num = a
cycle = []
cycle_sum = 0
for _ in range(cycle_size):
cycle.append(cycle_num)
cycle_sum += cycle_num
cycle_num = cycle_num**2 % M
before_cycle_size = checked[a]
before_cycle = []
before_cycle_sum = 0
num = X
for _ in range(before_cycle_size):
before_cycle.append(num)
before_cycle_sum += num
num = num**2 % M
ans = before_cycle_sum
ans += (N-before_cycle_size)//cycle_size * cycle_sum
after_cycle_size = (N-before_cycle_size)%cycle_size
for i in range(after_cycle_size):
ans += cycle[i]
print(ans)
|
N, X, M = map(int, input().split())
idx = [-1] * M
A = []
total = 0
length = 0
while idx[X] == -1:
A.append(X)
idx[X] = length
length += 1
total += X
X = pow(X, 2, M)
cycle = length - idx[X]
cycle_sum = sum(A[idx[X]:length])
ans = 0
if length >= N:
print(sum(A[:N]))
else:
ans += total
N -= length
l, m = divmod(N, cycle)
ans += cycle_sum * l
ans += sum(A[idx[X]:idx[X] + m])
print(ans)
| 1 | 2,816,139,945,552 | null | 75 | 75 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def precompute():
maxAS = 1000000
eratree = [0] * (maxAS + 10)
for p in range(2, maxAS + 1):
if eratree[p]:
continue
# p is prime
eratree[p] = p
x = p * p
while x <= maxAS:
if not eratree[x]:
eratree[x] = p
x += p
import pickle
pickle.dump(eratree, open("eratree.pickle", "wb"))
def solve(N, AS):
import pickle
eratree = pickle.load(open("eratree.pickle", "rb"))
num_division = 0
from collections import defaultdict
count = defaultdict(int)
for a in AS:
factors = []
while a > 1:
d = eratree[a]
factors.append(d)
a //= d
num_division += 1
# debug(": ", factors)
for f in set(factors):
count[f] += 1
# debug(": num_division", num_division)
if any(x == N for x in count.values()):
return "not coprime"
if any(x >= 2 for x in count.values()):
return "setwise coprime"
return "pairwise coprime"
def main():
# parse input
N = int(input())
AS = list(map(int, input().split()))
print(solve(N, AS))
# tests
T1 = """
3
3 4 5
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
pairwise coprime
"""
T2 = """
3
6 10 15
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
setwise coprime
"""
T3 = """
3
6 10 16
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
not coprime
"""
T4 = """
3
100000 100001 100003
"""
TEST_T4 = """
>>> as_input(T4)
>>> main()
pairwise coprime
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g, name=k)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
if sys.argv[-1] == 'ONLINE_JUDGE':
precompute()
elif sys.argv[-1] != "DONTCALL":
import subprocess
subprocess.call("pypy3 Main.py DONTCALL", shell=True, stdin=sys.stdin, stdout=sys.stdout)
else:
main()
|
from functools import reduce
from math import gcd
n = int(input())
A = list(map(int, input().split()))
def furui(x):
memo = [0]*(x+1)
primes = []
for i in range(2, x+1):
if memo[i]: continue
primes.append(i)
memo[i] = i
for j in range(i*i, x+1, i):
if memo[j]: continue
memo[j] = i
return memo, primes
memo, primes = furui(10**6+5)
pr = [True]*(10**6+5)
for a in A:
if a == 1: continue
while a != 1:
w = memo[a]
if not pr[w]:
break
pr[w] = False
while a%w == 0:
a = a // w
else:
continue
break
else:
print('pairwise coprime')
exit()
if reduce(gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
| 1 | 4,055,803,436,120 | null | 85 | 85 |
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e
# https://matsu7874.hatenablog.com/entry/2019/12/01/230357
n = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 1
# 先頭はr/g/b
count = [3 if i == 0 else 0 for i in range(n + 1)]
for a in A:
ans = ans * count[a] % MOD
if ans == 0:
break
count[a] -= 1
count[a + 1] += 1
print(ans)
|
n=int(input())
a=list(map(int,input().split()))
p=[0,0,0]
mod=10**9+7
r=1
for i in range(n):
c=0
for j in range(3):
if p[j]==a[i]:
if c==0:
p[j]+=1
c+=1
r=(r*c)%mod
print(r)
| 1 | 129,847,502,493,452 | null | 268 | 268 |
k,x=map(int,input().split())
if(k*500>=x):print("Yes")
else: print("No")
|
from numba import njit
@njit("i8(i8)")
def f(n):
l = [1]*(n+1)
l[0] = 0
ans = l[1]
for i in range(2,n+1):
for j in range(i,n+1,i):
l[j] += 1
ans += (l[i]*i)
return ans
n = int(input())
print(f(n))
| 0 | null | 54,378,564,453,730 | 244 | 118 |
def insertion_sort(array, g, result):
for i in range(g, len(array)):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j + g] = array[j]
j -= g
result['count'] += 1
A[j + g] = v
def g_gene(n):
yield 1
for i in range(2, n):
x = int((3 ** i - 1) / 2)
if x < n:
yield x
else:
raise StopIteration()
def shell_sort(array, result):
result['count'] = 0
G = list(reversed(list(g_gene(len(array)))))
m = len(G)
result['G'] = G
result['m'] = m
for i in range(m):
insertion_sort(array, G[i], result)
if __name__ == '__main__':
import sys
n = int(sys.stdin.readline())
A = []
for _ in range(n):
A.append(int(sys.stdin.readline()))
result = {}
shell_sort(A, result)
print(result['m'])
print(' '.join(map(str, result['G'])))
print(result['count'])
for a in A:
print(a)
|
N, M = map(int, input().split())
totalN = 1/2*(N-1)*N
totalM = 1/2*(M-1)*M
import math
print(math.floor(totalN + totalM))
| 0 | null | 22,777,933,202,222 | 17 | 189 |
import numpy as np
s_ = np.array(input().split())
s = [int(i) for i in s_]
N,X,T =s[0],s[1],s[2]
n = N//X
if N % X != 0:
n += 1
out = n * T
print(out)
|
import math
A, B, H, M = list(map(lambda n: int(n), input().split(" ")))
thetaM = 6 * M
thetaH = 30 * H + 0.5 * M
theta = math.radians(180 - abs(abs(thetaH - thetaM) - 180))
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta)))
| 0 | null | 12,122,655,684,562 | 86 | 144 |
ma = lambda: map(int, input().split())
t,u = ma(); a,c = ma(); b,d = ma()
p = (a-b)*t; q = (c-d)*u
if p < 0: p *= -1; q *= -1
if p+q > 0: print(0)
elif p+q == 0: print('infinity')
else:
t = -p-q
print(1+(p//t)*2 if p%t else (p//t)*2)
|
def main():
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
x, y = (a1-b1)*t1, (a2-b2)*t2
if x//abs(x) == y//abs(y):
print(0)
else:
if abs(x) == abs(y):
print("infinity")
else:
x, y = abs(x), abs(y)
if y < x:
print(0)
else:
if x%(y-x) != 0:
print((x+(y-x)-1)//(y-x)*2-1)
else:
print(x//(y-x)*2)
if __name__ == "__main__":
main()
| 1 | 131,145,546,728,450 | null | 269 | 269 |
import math
while True:
n = int(input())
if n == 0: break
s = list(map(int, input().split()))
ave = sum(s) / n
S = []
for i in range(n):
key = ave - s[i]
S.append(key * key)
print('{:.5f}'.format(math.sqrt(sum(S) / n)))
|
while input()!='0':
n=list(map(int,input().split()))
b=len(n)
a=sum(n)/b
print((sum((x-a)**2 for x in n)/b)**0.5)
| 1 | 194,822,213,450 | null | 31 | 31 |
n, k = list(map(int, input().split()))
mod = 1000000007
fac = [1]
inv = [1]
for i in range(n * 2):
fac.append(fac[-1] * (i + 1) % mod)
inv.append(pow(fac[-1], mod - 2, mod))
def cmb(n, k):
if k < 0 or k > n:
return 0
return ((fac[n] * inv[k]) % mod * inv[n - k]) % mod
ret = 0
for m in range(min(k + 1, n)):
ret = (ret + (cmb(n, m) * cmb(n - 1, n - m - 1)) % mod) % mod
print(ret)
|
n,k =list(map(int,input().split()))
mod = 10**9+7
ans = 1%mod
left_combination = 1
right_combination = 1
for i in range(1,min(k,n-1)+1):
left_combination = (left_combination*(n+1-i)*pow(i,mod-2,mod))%mod
right_combination = (right_combination*(n-i)*pow(i,mod-2,mod))%mod
ans = (ans + (left_combination*right_combination)%mod)%mod
print(ans)
| 1 | 67,299,690,678,312 | null | 215 | 215 |
N = int(input())
S = input()
s = list(S)
for i in range(len(S)):
if (ord(s[i]) - 64 + N) % 26 == 0:
p = 90
else:
p = (ord(s[i]) - 64 + N) % 26 + 64
s[i] = chr(p)
print("".join(s))
|
N=int(input())
S=list(map(str, input()))
li=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
answer=[]
for i in range(len(S)):
for j in range(len(li)):
if S[i]==li[j] and j<len(li)-N:
answer.append(li[j+N])
elif S[i]==li[j] and j>=len(li)-N:
answer.append(li[j+N-len(li)])
print("".join(answer))
| 1 | 134,084,365,755,520 | null | 271 | 271 |
h,a = [int(x) for x in input().split()]
print((h+a-1)//a)
|
n=int(input())
l=[x for x in range (1,10)]
ans="No"
for i in range(1,10):
if n % i == 0 and n//i in l:
ans="Yes"
print(ans)
| 0 | null | 118,155,934,514,078 | 225 | 287 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
s = input()
if 'RRR' in s:
print(3)
elif 'RR' in s:
print(2)
elif 'R' in s:
print(1)
else:
print(0)
if __name__ == '__main__':
main()
|
n = int(raw_input())
r = []
for i in range(n):
r.append(int(raw_input()))
min_v = r[0]
max_profit = -1000000000000
for i in range(1,n):
if max_profit < r[i] - min_v:
max_profit = r[i]-min_v
if r[i] < min_v:
min_v = r[i]
print max_profit
| 0 | null | 2,434,497,727,788 | 90 | 13 |
X = int(input())
a = X // 500 # 500円硬貨の枚数
X = X % 500 # 端数
b = X // 5 # 5円硬貨の枚数
print(a*1000+b*5)
|
while True:
c=0
x, y = map(int, input().split())
if x == 0 and y== 0:
break
for i in range(1, x+1):
for j in range(i+1, x+1):
for k in range(j+1, x+1):
if i+j+k == y:
c += 1
print (c)
| 0 | null | 22,012,666,857,078 | 185 | 58 |
n = int(input())
a = 0
b = 0
for i in range(n):
t1,t2 = input().split()
if t1>t2:
a+=3
elif t1==t2:
a+=1
b+=1
else:
b+=3
print(a,b)
|
import sys
tscore = hscore = 0
n = int( sys.stdin.readline() )
for i in range( n ):
tcard, hcard = sys.stdin.readline().rstrip().split( " " )
if tcard < hcard:
hscore += 3
elif hcard < tcard:
tscore += 3
else:
hscore += 1
tscore += 1
print( "{:d} {:d}".format( tscore, hscore ) )
| 1 | 2,026,516,410,720 | null | 67 | 67 |
N, K = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
price = sum(P[:K])
print(price)
|
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
n=int(input())
ar=lis()
k=0
for i in ar:
k=(k^i)
for i in ar:
print(k^i,end=" ")
| 0 | null | 12,095,710,902,030 | 120 | 123 |
# coding=utf-8
import sys
if __name__ == '__main__':
N = int(input())
li_A = list(map(int, input().split()))
ans = li_A[0]
if 0 in li_A:
print('0')
sys.exit()
for i in range(1, N):
if ans * li_A[i] > 1000000000000000000:
print('-1')
sys.exit()
else:
ans *= li_A[i]
print(ans)
|
n = int(input())
A = list(map(int, input().split(' ')))
res = 1
for a in A:
res = min(res*a, 10**18 + 1)
if res == 10**18 + 1: print(-1)
else: print(res)
| 1 | 16,173,996,243,392 | null | 134 | 134 |
MOD = 10 ** 9 + 7
def nCk(n, k):
if k > n or min(n, k) < 0:
raise Exception('Not correct input values!')
res = 1
for i in range(1, k + 1):
res = (res * (n - i + 1) * pow(i, MOD - 2, MOD)) % MOD
return res
n, a, b = map(int, input().split())
ret = (pow(2, n, MOD) - 1 - nCk(n, a) - nCk(n, b)) % MOD
print(ret)
|
x, y, z = map(int,input().split())
a = x + y + z
if (a >= 22):
print("bust")
else:
print("win")
| 0 | null | 92,406,285,625,460 | 214 | 260 |
k,n=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(len(a)-1):
b.append(a[i+1]-a[i])
b.append(abs(a[-1]-a[0]-k))
b.sort()
b[-1]=0
print(sum(b))
|
n, r = map(int, input().split())
print(r if n >= 10 else r + 1000 - (100 * n))
| 0 | null | 53,434,864,375,858 | 186 | 211 |
n = int(input())
if 30 <= n:
print("Yes")
else:
print("No")
|
import sys
from collections import defaultdict
sys.setrecursionlimit(500000)
class Fraction:
def gcd(self, a ,b):
a,b = max(a,b),min(a,b)
while a%b!=0:
a,b = b,a%b
return b
def frac(self,a,b):
if a==0 and b==0:
return (0,0)
elif a==0:
return (0,1)
elif b==0:
return (1,0)
else:
d = self.gcd(abs(a),abs(b))
if a<0:
a = -a
b = -b
return (a//d,b//d)
def __init__(self, a, b):
self.value = self.frac(a,b)
def v(self):
return self.value
def __lt__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d < b*c
def __le__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d <= b*c
def __eq__(self, other):
a,b = self.value
c,d = other.value
return a==c and b==d
def __ne__(self, other):
a,b = self.value
c,d = other.value
return not (a==c and b==d)
def __gt__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d > b*c
def __ge__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d >= b*c
def __add__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d + b*c, b*d)
def __sub__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d - b*c, b*d)
def __mul__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*c, b*d)
def __truediv__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d, b*c)
def __neg__(self):
a,b = self.value
return Fraction(-a,b)
def inv(self):
return Fraction(1,1) / self
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
vec = [list(map(int,input().split())) for i in range(N)]
arg = defaultdict(int)
zero = 0
for v in vec:
if v[0] == 0 and v[1] == 0:
zero += 1
else:
f = Fraction(v[0],v[1])
arg[f.v()] += 1
arg[(-f.inv()).v()] += 0
pair = []
fd = lambda : False
checked_list = defaultdict(fd)
for key in arg:
if not checked_list[key]:
inv = (-Fraction(*key).inv()).v()
pair.append([arg[key],arg[inv]])
checked_list[inv] = True
mod = 1000000007
ans = 1
for p1,p2 in pair:
ans *= pow(2,p1,mod) + pow(2,p2,mod) - 1
ans %= mod
ans += zero
ans %= mod
print((ans+mod-1)%mod)
if __name__ == '__main__':
main()
| 0 | null | 13,248,381,144,132 | 95 | 146 |
n = int(input())
A = []
B = []
for i in range(n):
a, b = map(int, input().split())
z = a + b
w = a - b
A.append(z)
B.append(w)
P = abs(max(A) - min(A))
Q = abs(max(B) - min(B))
print(max(P, Q))
|
a,b=[],[]
for _ in range(int(input())):
x,y=map(int,input().split())
a+=[x-y]
b+=[x+y]
print(max(max(a)-min(a),max(b)-min(b)))
| 1 | 3,437,891,279,262 | null | 80 | 80 |
def bubblesort(N, A):
C, flag = [] + A, True
while flag:
flag = False
for j in range(N-1, 0, -1):
if int(C[j][1]) < int(C[j-1][1]):
C[j], C[j-1] = C[j- 1], C[j]
flag = True
return C
def selectionSort(N, A):
C = [] + A
for i in range(N):
minj = i
for j in range(i,N):
if int(C[j][1]) < int(C[minj][1]):
minj = j
C[i], C[minj] = C[minj], C[i]
return C
N, A= int(input()), input().split()
Ab = bubblesort(N, A)
print(*Ab)
print('Stable')
As = selectionSort(N, A)
print(*As)
if Ab != As:
print('Not stable')
else:
print('Stable')
|
N = int(input())
A = []
for i in range(N+1):
if i % 3 == 0:
pass
elif i % 5 == 0:
pass
else:
A.append(i)
print(sum(A))
| 0 | null | 17,549,838,585,664 | 16 | 173 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
def cut(x):
cut_count = 0
for i in range(n):
cut_count += (a[i]-1)//x
return cut_count
l = 0
r = 10**9
while r-l > 1:
mid = (l+r)//2
if k >= cut(mid):
r = mid
else:
l = mid
print(r)
|
import math
N, K = map(int,input().rstrip().split())
A = list(map(int,input().rstrip().split()))
maxX = max(A)
minX = 0
X = (maxX + minX)//2
while X!=minX:
num = sum([math.ceil(A[i]/X)-1 for i in range(N)])
if num<=K:
maxX = X
else:
minX = X
X = (maxX + minX)//2
num = sum([math.ceil(A[i]/maxX)-1 for i in range(N)])
if num<=K:
print(maxX)
else:
print(minX)
| 1 | 6,437,056,475,232 | null | 99 | 99 |
#!/usr/bin/env python3
import sys
import string
l = [c for c in string.ascii_lowercase]
def f(N: int):
N -= 1
if N // 26:
return f(N//26) + l[N%26]
else:
return l[N%26]
def solve(N):
print(f(N))
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == '__main__':
main()
|
N = int(input())
L = [0] * N
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
n = int(((x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2)/ 2 )
if n <= N:
L[n - 1] += 1
print(*L, sep='\n')
| 0 | null | 9,868,344,175,960 | 121 | 106 |
n = int(input())
P = list(map(int,input().split()))
k=0
bc=0
c=0
i=0
while k < n :
if P[k]!=i+1 :
bc+=1
else:
i+=1
c+=1
k+=1
if c==0 :
bc = -1
print(bc)
|
class Stack:
def __init__(self):
self.count = 1
self.lst = []
def push(self, element):
if element == self.count:
self.lst.append(element)
self.count += 1
def length(self):
return len(self.lst)
n = int(input())
a = list(map(int, input().split()))
stack = Stack()
for i in a:
stack.push(i)
b = stack.length()
if b == 0:
print('-1')
else:
print(n - b)
| 1 | 114,578,595,347,100 | null | 257 | 257 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
h1,m1,h2,m2,k=nii()
minute=(h2-h1)*60
minute+=m2-m1
minute-=k
print(minute)
|
h1, m1, h2, m2, k = map(int, input().split())
d = (h2 - h1) * 60 + (m2 - m1)
print(max(d - k, 0))
| 1 | 18,220,688,979,880 | null | 139 | 139 |
N = int(input())
ans = (N-1)//2 + 1
print(int(ans))
|
def main():
from itertools import product
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
S_T = [[int(s[w]) for s in S] for w in range(W)]
sumS = sum(map(sum, S_T))
ans = (H - 1) * (W - 1)
if sumS <= K:
print(0)
else:
for i in product([True, False], repeat=H-1):
cnt = sum(i)
if cnt >= ans:
continue
M = [[0]]
for j, k in enumerate(i):
if k:
M.append([])
M[-1].append(j+1)
A = [0] * len(M)
for s_t in S_T:
for l, m in enumerate(M):
A[l] += sum(s_t[i] for i in m)
if any(a > K for a in A):
cnt += 1
if cnt >= ans:
break
A = [sum(s_t[i] for i in m) for m in M]
if any(a > K for a in A):
cnt = ans + 1
break
ans = min(cnt, ans)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 53,464,245,347,444 | 206 | 193 |
a,b,c=map(int,input().split(" "))
count=0
while(a<=b):
if c%a==0:
count+=1
a+=1
print(count)
|
n = int(input())
cum = 0
d = dict()
for _ in range(n):
a, b = input().split()
b = int(b)
cum += b
d[a] = cum
c = input()
print(cum - d[c])
| 0 | null | 48,503,202,595,620 | 44 | 243 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
while y: x,y = y,x%y
return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
"""Return a tuple list of divisor of n"""
return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
"""Return a list of prime numbers n or less"""
is_prime = [True]*(MAX_NUM+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX_NUM**0.5)+1):
if not is_prime[i]: continue
for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
"""Return a list of prime factorization numbers of n"""
res = []
for i in range(2,int(n**0.5)+1):
while n%i==0: res.append(i); n //= i
if n != 1: res.append(n)
return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
n = II()
xl = [MII() for _ in range(n)]
lr_x = [[x-l, x+l] for x, l in xl]
lr_x.sort(key=lambda x: x[1])
now = -(10**9)
cnt = 0
for l, r in lr_x:
if now <= l:
cnt += 1
now = r
print(cnt)
if __name__ == '__main__':
main()
|
n = int(input())
L = []
for _ in range(n):
x, l = map(int, input().split())
left = x - l
right = x + l
L.append((left, right))
L = sorted(L, key=lambda x: x[1])
ans = 0
prev = -float('inf')
for r in L:
if r[0] >= prev:
ans += 1
prev = r[1]
print(ans)
| 1 | 89,523,143,995,360 | null | 237 | 237 |
import math
def Koch(Px, Py, Qx, Qy, n) :
if n == 0 :
return
else :
Ax = (2 * Px + Qx) / 3
Ay = (2 * Py + Qy) / 3
Bx = (Px + 2 * Qx) / 3
By = (Py + 2 * Qy) / 3
Cx = Ax + (Bx - Ax) * math.cos(math.pi/3) - (By - Ay) * math.sin(math.pi/3)
Cy = Ay + (Bx - Ax) * math.sin(math.pi/3) + (By - Ay) * math.cos(math.pi/3)
Koch(Px, Py, Ax, Ay, n-1)
print(Ax, Ay)
Koch(Ax, Ay, Cx, Cy, n-1)
print(Cx, Cy)
Koch(Cx, Cy, Bx, By, n-1)
print(Bx, By)
Koch(Bx, By, Qx, Qy, n-1)
n = int(input())
print(0, 0.00000000)
Koch(0.00000000, 0.00000000, 100.00000000, 0.00000000, n)
print(100.00000000, 0.00000000)
|
import math
n = int(raw_input())
def func(i, ox1, oy1, ox2, oy2):
if i != n:
nx1 = ox1 + (ox2 - ox1) / 3
ny1 = oy1 + (oy2 - oy1) / 3
nx2 = ox1 + (ox2 - ox1) * 2 / 3
ny2 = oy1 + (oy2 - oy1) * 2 / 3
if nx1 < nx2:
if ny1 == ny2:
nx3 = nx1 + (nx2 - nx1) / 2
ny3 = ny1 + (nx2 - nx1) * math.sqrt(3) / 2
elif ny1 < ny2:
nx3 = ox1
ny3 = ny2
elif ny1 > ny2:
nx3 = ox2
ny3 = ny1
elif nx1 > nx2:
if ny1 == ny2:
nx3 = nx1 + (nx2 - nx1) / 2
ny3 = ny1 - (nx1 - nx2) * math.sqrt(3) / 2
elif ny1 < ny2:
nx3 = ox2
ny3 = ny1
elif ny1 > ny2:
nx3 = ox1
ny3 = ny2
func(i+1, ox1, oy1, nx1, ny1)
func(i+1, nx1, ny1, nx3, ny3)
func(i+1, nx3, ny3, nx2, ny2)
func(i+1, nx2, ny2, ox2, oy2)
elif i == n:
print(str(ox1) + str(" ") + str(oy1))
func(0, 0.0, 0.0, 100.0, 0.0)
print(str(100) + str(" ") + str(0))
| 1 | 128,866,169,962 | null | 27 | 27 |
# -*- coding:utf-8 -*-
from collections import deque
result = deque()
def operation(command):
if command[0] == "insert":
result.appendleft(command[1])
elif command[0] == "delete":
if command[1] in result:
result.remove(command[1])
elif command[0] == "deleteFirst":
result.popleft()
elif command[0] == "deleteLast":
result.pop()
n = int(input())
for i in range(n):
command = input().split()
operation(command)
print(*result)
|
n,a,b = map(int, input().split())
g = n//(a+b)
k = n-(a+b)*g
if k >= a:
print(a+a*g)
else:
print(a*g + k)
| 0 | null | 28,005,766,020,768 | 20 | 202 |
import sys
l = sys.stdin.readlines()
for i in range(len(l)-1):
print('Case {}: {}'.format(i+1,l[i].strip()))
|
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
def f(length, ls):
cur = 0
for a in ls:
if a%length == 0:
cur += a//length - 1
else:
cur += a//length
if cur <= K:
return True
else:
return False
ok, ng = max(A), 0
while abs(ok - ng) > 1:
z = (ok+ng)//2
if f(z, A) == True:
ok = z
else:
ng = z
print(ok)
| 0 | null | 3,522,882,485,760 | 42 | 99 |
import sys
sys.setrecursionlimit(10**8)
N = int(input())
X = input()
if X == '0':
for _ in range(N):
print(1)
exit()
mem = [None] * (200005)
mem[0] = 0
def f(n):
if mem[n] is not None: return mem[n]
c = bin(n).count('1')
r = 1 + f(n%c)
mem[n] = r
return r
for i in range(200005):
f(i)
cnt = X.count('1')
a,b = cnt+1, cnt-1
ans = [None] * N
n = 0
for c in X:
n *= 2
n += int(c)
n %= a
for i,c in reversed(list(enumerate(X))):
if c=='1': continue
ans[i] = mem[(n+pow(2,N-i-1,a))%a] + 1
if b:
n = 0
for c in X:
n *= 2
n += int(c)
n %= b
for i,c in reversed(list(enumerate(X))):
if c=='0': continue
ans[i] = mem[(n-pow(2,N-i-1,b))%b] + 1
else:
for i in range(N):
if ans[i] is None:
ans[i] = 0
print(*ans, sep='\n')
|
print("".join(input().split()[::-1]))
| 0 | null | 55,825,081,070,738 | 107 | 248 |
H,N=map(int,input().split())
L=[0]*N
for i in range(N):
a,b=map(int,input().split())
L[i]=(a,b)
DP=[float("inf")]*(H+1)
DP[0]=0
for (A,B) in L:
for k in range(1,H+1):
if k>=A:
DP[k]=min(DP[k],DP[k-A]+B)
else:
DP[k]=min(DP[k],B)
print(DP[-1])
|
H,N = map(int,input().split())
INF = 10 ** 10
dp = [INF] * (H + 1)
dp[0] = 0
for i in range(N):
attack,magic = map(int,input().split())
for j in range(len(dp)):
if dp[j] == INF:
continue
target = j + attack
if j + attack > H:
target = H
if dp[target] > dp[j] + magic:
dp[target] = dp[j] + magic
print(dp[-1])
| 1 | 81,425,932,762,580 | null | 229 | 229 |
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
for i in range(len(mat)):
print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])
yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
def main():
N = I()
X = S()
bit_cnt = X.count('1')
one_inv_cnt = bit_cnt - 1
zero_inv_cnt = bit_cnt + 1
MAX = 2 * 10 ** 5 + 1
# 大きい数の余り
# 繰り返し2乗法の発展?
zero_mod = 0
one_mod = 0
for i in range(0, len(X)):
b = int(X[i])
if one_inv_cnt != 0:
one_mod = (one_mod * 2 + b) % one_inv_cnt
zero_mod = (zero_mod * 2 + b) % zero_inv_cnt
f = [0] * MAX
for i in range(1, MAX):
f[i] = f[i % str(bin(i)).count('1')] + 1
for i in range(len(X)-1, -1, -1):
if X[N-1-i] == '1':
if one_inv_cnt != 0:
nxt = one_mod
nxt -= pow(2, i, one_inv_cnt)
nxt %= one_inv_cnt
print(f[nxt] + 1)
else:
print(0)
else:
nxt = zero_mod
nxt += pow(2, i, zero_inv_cnt)
nxt %= zero_inv_cnt
print(f[nxt] + 1)
if __name__ == '__main__':
main()
|
N = int(input())
N_ri = round(pow(N, 1/2))
for i in range(N_ri, 0, -1):
if N % i == 0:
j = N // i
break
print(i + j - 2)
| 0 | null | 84,451,539,629,970 | 107 | 288 |
N = int(input())
A_list = list(map(int,input().split()))
A_set = set(A_list)
if len(A_list) == len(A_set):
print("YES")
else:
print("NO")
|
A,B = list(map(int,input().split()))
N={1:300000,2:200000,3:100000}
if A ==1 and B==1:
print(1000000)
else:
try:
A=N[A]
except KeyError:
A=0
try:
B=N[B]
except KeyError:
B=0
print(A+B)
| 0 | null | 107,000,642,346,168 | 222 | 275 |
x1,y1,x2,y2,t=map(int,input().split())
print((x2-x1)*60+(y2-y1)-t)
|
sh,sm,eh,em,t=map(int,input().split())
print((eh-sh)*60+em-sm-t)
| 1 | 17,993,956,799,698 | null | 139 | 139 |
k ,x = map(int, input().split())
if x <= (k*500):
print('Yes')
else:
print('No')
|
import numpy as np
from numba import njit
@njit
def op(A, n):
B = np.zeros_like(A)
for i, a in enumerate(A[:n]):
B[max(i - a, 0)] += 1
B[min(n - 1, a + i) + 1] -= 1
return np.cumsum(B)
def main():
n, k = list(map(int, input().split()))
A = np.array(list(map(int, input().split())) + [0, ], dtype = np.int)
for _ in range(k):
A_new = op(A, n)
if all(A[:n] == A_new[:n]):
break
A = A_new
print(' '.join(list(map(str, A[:n]))))
if __name__ == '__main__':
main()
| 0 | null | 56,678,504,871,352 | 244 | 132 |
N, K = map(int,input().split())
H = list(map(int,input().split()))
s = 0
for i in H:
if K <= i:
s += 1
print(s)
|
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
H, W = map(int, input().split())
I = [list(map(str, input())) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
for i in range(H):
for j in range(W):
if i == 0 and j == 0:
continue
if i == 0:
dp[i][j] = dp[i][j-1] if I[i][j] == I[i][j-1] else dp[i][j-1] + 1
continue
if j == 0:
dp[i][j] = dp[i-1][j] if I[i][j] == I[i-1][j] else dp[i-1][j] + 1
continue
dp[i][j] = dp[i][j-1] if I[i][j] == I[i][j-1] else dp[i][j-1] + 1
if I[i][j] == I[i-1][j]:
dp[i][j] = min(dp[i][j], dp[i-1][j])
else:
dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
t = dp[-1][-1]
if I[0][0] == "#":
t += 1
ans = -(-t//2)
print(ans)
| 0 | null | 114,526,930,148,516 | 298 | 194 |
S = input()
sum = 0
for i in range(3):
if S[i]=="R":
sum += 1
if sum == 2 and S[1] == "S":
sum = 1
print(sum)
|
#!/usr/bin/env python3
S = input()
total = 0
for i in range(len(S)):
if "R" * (i + 1) in S:
total = i + 1
ans = total
print(ans)
| 1 | 4,824,075,235,630 | null | 90 | 90 |
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
ans = k
elif a < k and a+b >= k:
ans = a
else:
ans = a - (k-(a+b))
print(ans)
|
A, B, C, K = map(int, input().split())
if (K - A) <= 0:
print(K)
else:
if (K - A - B) <= 0:
print(A)
else:
c = (K - A - B)
print(A - c)
| 1 | 21,845,181,842,500 | null | 148 | 148 |
ans = ''
while True:
s = input()
if s == '-':
break
n = int(input())
L = []
i = 0
while i < n:
j = int(input())
s = s[j:] + s[:j]
i += 1
ans += s + '\n'
if ans != '':
print(ans[:-1])
|
x = int(input())
print('Yes' if 30 <= x else 'No')
| 0 | null | 3,827,868,567,250 | 66 | 95 |
S = list(input())
T = list(input())
L = len(S)
i = 0
cn = 0
N = 200000
while i < L:
if S[i] != T[i]:
i = i + 1
cn = cn + 1
else:
i = i + 1
print(cn)
|
a, b = input().split()
print('Yes') if a==b else print('No')
| 0 | null | 46,926,227,876,700 | 116 | 231 |
from collections import deque
N, M = map(int, input().split())
roads = []
for _ in range(N):
roads.append([])
for _ in range(M):
a, b = map(int, input().split())
roads[a - 1].append(b - 1)
roads[b - 1].append(a - 1)
visited = [float('inf')] * N
q = deque()
q.append(0)
visited[0] = 0
pre = [-1] * N
while q:
now_room = q.popleft()
for next_room in roads[now_room]:
if visited[next_room] != float('inf'):
continue
visited[next_room] = visited[now_room] + 1
if pre[next_room] == -1:
pre[next_room] = now_room + 1
q.append(next_room)
# print(*roads)
# print(*pre)
print('Yes')
for i in range(1, N):
print(pre[i])
|
import copy
N, M = map(int, input().split())
res = [[] for i in range(N+5)]
for i in range(M) :
a,b = map(int, input().split())
a -= 1
b -= 1
res[a].append(b)
res[b].append(a)
pre = [-1] * N
dist = [-1] * N
d = 1
dl = []
pre[0] = 0
dist[0] = 0
dl.append(0)
while(len(dl) != 0) :
a = dl[0]
dl.pop(0)
for i in res[a] :
if(dist[i] != -1):
continue
dist[i] = dist[a] + 1
pre[i] = a
dl.append(i)
for i in range(N) :
if(i == 0) :
print("Yes")
continue
print(pre[i] + 1)
| 1 | 20,527,411,408,608 | null | 145 | 145 |
K = int(input())
S = str(input())
s_l = len(S)
s_k = list(S)
answer = s_k[slice(0, K)]
result = ''.join(answer)
if s_l <= K:
print(S)
else:
print(result + '...')
|
h,w,k=map(int, input().split())
Black = []
for i in range(h):
c = input()
for j in range(w):
if c[j] == "#":
Black.append((i,j))
# print(Black, len(Black))
ans = 0
for i in range(2 ** h):
for j in range(2 ** w):
a = len(Black)
for b in Black:
if ((i >> b[0]) & 1) or ((j >> b[1]) & 1):
# if b[0] != i - 1 and b[1] != j - 1:
a -= 1
if a == k:
ans += 1
# print(bin(i),bin(j))
print(ans)
| 0 | null | 14,245,888,157,710 | 143 | 110 |
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから!!___________
n, m, k = map(int, input().split())
A = list(accumulate(map(int, input().split())))
B = list(accumulate(map(int, input().split())))
A=[0]+A
B=[0]+B
ans = []
for i in range(n+1):
c = bisect_right(B, k-A[i])-1
if c!=-1:
ans.append(c+i)
print(max(ans))
|
n,m,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_c_sum = [0]*(n + 1)
for i in range(n):
a_c_sum[i + 1] = a_c_sum[i] + a[i]
b_c_sum = [0]*(m + 1)
for i in range(m):
b_c_sum[i + 1] = b_c_sum[i] + b[i]
ans, best_b = 0, m
for i in range(n + 1):
if a_c_sum[i] > k:
break
else:
while 1:
if b_c_sum[best_b] + a_c_sum[i] <= k:
ans = max(ans, i + best_b)
break
else:
best_b -= 1
if best_b == 0:
break
print(ans)
| 1 | 10,704,058,433,192 | null | 117 | 117 |
K = int(input())
n = 7
c = 0
while c <= K:
n %= K
c += 1
if n == 0:
print(c)
exit()
n = n * 10 + 7
print(-1)
|
n = -100
i = 1
while n != 0:
n = int(raw_input())
if n != 0:
print 'Case %d: %d' %(i,n)
i = i + 1
| 0 | null | 3,267,172,037,220 | 97 | 42 |
N = int(input())
S = input()
ans = S.count('ABC')
print(ans)
|
import sys
def input():
return sys.stdin.readline().rstrip('\n')
##### main
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
AxF = [A[i]*F[i] for i in range(N)]
AxFmax = max(AxF)
def is_possible(x):
_sum = 0
for i in range(N):
_sum += max(0, A[i] - x//F[i])
#print(x,_sum,K)
return _sum <= K
left = 0
right = AxFmax
while(left != right):
x = (left+right)//2
if is_possible(x):
right = x
else:
left = x+1
#print('main', left, right, x)
print(left)
| 0 | null | 132,313,850,237,708 | 245 | 290 |
X,N = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
print(X)
elif N == 1:
if p[0] == X:
print(X-1)
else:
print(X)
else:
ans = float('inf')
for z in range(0,p[0]):
if (ans-X)**2 > (z-X)**2 :
ans = z
for i in range(N-1):
for z in range(p[i]+1,p[i+1]):
if (ans-X)**2 > (z-X)**2 :
ans = z
for z in range(p[-1]+1,102):
if (ans-X)**2 > (z-X)**2 :
ans = z
print(ans)
|
s = input()
map = {'SSS': 0, 'SSR': 1, 'SRS': 1, 'RSS': 1, 'SRR': 2, 'RSR': 1, 'RRS': 2, 'RRR': 3}
for key in map.keys():
if s == key:
print(map[key])
break
| 0 | null | 9,529,639,241,930 | 128 | 90 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(N: int, X: "List[int]"):
return min([sum([(x-i)**2 for x in X]) for i in range(1, 100+1)])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(N, X)}')
if __name__ == '__main__':
main()
|
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
def eucrid(a,b):
a,b=max(a,b),min(a,b)
while True:
if a%b==0:
return b
else:
a,b=b,a%b
m=a[0]
for i in range(n):
m=m//eucrid(m,a[i])*a[i]
b=0
m=m%mod
for i in a:
b+=m*pow(i,mod-2,mod)%mod
print(b%mod)
| 0 | null | 76,138,639,824,390 | 213 | 235 |
n = int(input())
my_dict = {}
for i in range(n):
order, key = input().split(' ')
if order == 'insert':
my_dict[key] = True
elif order== 'find':
if key in my_dict.keys():
print('yes')
else:
print('no')
|
w,h,x,y,r = map(int, raw_input().split())
if x >= r and x <= (w-r) and y >= r and y <= (h-r):
print 'Yes'
else:
print 'No'
| 0 | null | 257,651,146,772 | 23 | 41 |
#!/usr/bin/env python3
import sys
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: str):
B = [0]
for i in range(len(N)):
T = B[i] + int(N[i])
B.append(T)
A = B[len(N)] - B[0]
if A % 9 ==0:
return print(YES)
else:
return print(NO)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = next(tokens) # type: str
solve(N)
if __name__ == '__main__':
main()
|
S = input()
acc = 0
for ch in S:
acc += int(ch)
print('Yes' if acc % 9 == 0 else 'No')
| 1 | 4,464,859,102,518 | null | 87 | 87 |
abc = input().split()
a =int(abc[0])
b = int(abc[1])
c = int(abc[2])
if a<b and b<c:
print("Yes")
else:
print("No")
|
X = int(input())
if 30 <= X:
print('Yes')
else:
print('No')
| 0 | null | 3,028,052,427,402 | 39 | 95 |
#!/usr/bin/env python3
from heapq import *
a = [*range(1, 10)]
heapify(a)
i = 0
k = int(input())
c = 0
while True:
t = str(heappop(a))
i += 1
if i == k:
break
if t[-1] != "0":
heappush(a, int(t + str(int(t[-1]) - 1)))
heappush(a, int(t + t[-1]))
if t[-1] != "9":
heappush(a, int(t + str(int(t[-1]) + 1)))
print(t)
|
X = int(input())
A = 100
for i in range(10**5):
A = A*101//100
if X <= A:
break
print(i+1)
| 0 | null | 33,327,274,742,998 | 181 | 159 |
x, y = map(int, input().split())
if(x < y):
for i in range(0, y):
print(x, end = '')
else:
for i in range(0, x):
print(y, end = '')
|
a, b = input().split(' ')
if a <= b:
print(a*int(b))
else:
print(b*int(a))
| 1 | 84,604,948,633,998 | null | 232 | 232 |
X = int(input())
year = 0
deposit = 100
while deposit < X:
deposit += int(str(deposit)[0: -2])
year += 1
print(year)
|
x=int(input())
yo=100
n=0
while x>yo:
yo+=yo//100
n+=1
print(n)
| 1 | 27,075,422,307,802 | null | 159 | 159 |
'''
ITP-1_8-D
????????°
???????????????????????°??¶???????????? ss ???????????????????????????????¨????????????£?¶????????????????????????????????????§???
????????? pp ??????????????????????????????????????°????????????????????????????????????
???Input
????????????????????? ss ????????????????????????
????????????????????? pp ????????????????????????
???Output
pp ??????????????´?????? Yes ??¨?????????????????´?????? No ??¨????????????????????????????????????
'''
# inputData
x = str(input())
y = str(input())
xString = []
for i in x:
xString.append(i)
yString = []
for i in y:
yString.append(i)
n = len(yString)
flag = 0
for i in range(len(xString)):
if xString[i:i+n] == yString:
flag = 1
break
if i+n > len(xString):
if xString[i:]+xString[0:(i+n)%len(xString)] == yString:
flag = 1
break
# outputCheck
if flag == 0:
print('No')
elif flag == 1:
print('Yes')
|
str1 = raw_input()
str2 = raw_input()
n = len(str1)
for i in xrange(n):
j = i
s = 0
for k in xrange(len(str2)):
if (j+k) > (n-1):
j = -k
if str1[j+k] != str2[k]:
s += 1
if s == 0:
print "Yes"
break
else:
print "No"
| 1 | 1,748,270,058,002 | null | 64 | 64 |
N = int(input())
total = 0
for n in range(1, N+1):
total += N//n * (n + N - N%n)//2
print(total)
|
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n = INT()
ans = 0
for x in range(1, n+1):
y = n // x
ans += y * (y + 1) * x // 2
print(ans)
| 1 | 11,008,899,435,390 | null | 118 | 118 |
N = int(input())
for i in range(N):
sides = list(map(int, input().split()))
longestSide = max(sides)
sides.remove(longestSide)
if (longestSide ** 2) == (sides[0] ** 2 + sides[1] ** 2):
print('YES')
else:
print('NO')
|
import sys
from operator import or_
input=sys.stdin.readline
class SegTree():
def __init__(self, N, e=float("inf"), operator_func=min):
self.e = e
self.size = N
self.node = [self.e] * (2*N)
self.op = operator_func
def set_list(self, l):
for i in range(self.size):
self.node[i+self.size-1] = l[i]
for i in range(self.size-1)[::-1]:
self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
def update(self, k, x):
k += self.size - 1
self.node[k] = x
while k >= 0:
k = (k - 1) // 2
self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
def get(self, l, r):
x = self.e
l += self.size; r += self.size
a, b = [], []
while l<r:
if l&1:
a += [l-1]; l += 1
if r&1:
r -= 1; b += [r-1]
l >>= 1; r >>= 1
for i in a+(b[::-1]):
x = self.op(x, self.node[i])
return x
def main():
N = int(input())
S = list(input())[:-1]
trees = {chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26)}
for i, s in enumerate(S):
trees[s].update(i, 1)
Q = int(input())
for _ in range(Q):
mode, i, v = input().split()
if mode=="1":
i = int(i)-1
trees[S[i]].update(i, 0)
trees[v].update(i, 1)
S[i] = v
else:
i = int(i)-1
v = int(v)
ans = sum(trees[chr(97+j)].get(i, v) for j in range(26))
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 31,092,587,513,988 | 4 | 210 |
import random
def down_score(d, c, last_d, score):
sum = 0
for i in range(26):
sum += c[i]*(d-last_d[i])
return (score - sum)
def main():
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
#print(c)
#print(s)
last_d = [0 for i in range(26)]
ans = []
score = 0
for i in range(D):
max = 0
idx = 0
for j in range(26):
if max < (s[i][j] + c[j] * (i-last_d[j])) and c[j] != 0:
max = s[i][j] + c[j] * (i-last_d[j])
idx = j
elif max == (s[i][j] + c[j] * (i-last_d[j])) and c[j] > c[idx]:
idx = j
last_d[idx] = i+1
score += s[i][j]
down_score(i+1,c,last_d,score)
ans.append(idx)
for i in range(D):
print(ans[i]+1)
if __name__ == "__main__":
main()
|
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 998244353
#############
# Main Code #
#############
# N:ブロック
# M:色(バリエーション)
# K:隣合う組み
# N, M, K = 6, 2, 3のとき
# K = 0 のとき
# 121212, 212121
# K = 1のとき,
# 12121 のどこかに同じ数字を挟み込めば
# 112121, 122121という風にできる
# K = 2のとき
# 1212 のどこかに同じ数字を挟む を2回行う
# 112212, 112122もできるし
# 111212, 122212もできる
N, M, K = getNM()
# 重複組み合わせのため
# 繰り返し使うのでこのタイプ
Y = N + K + 1
fact =[1] #階乗
for i in range(1, Y + 1):
fact.append(fact[i - 1] * i % mod)
facv = [0] * (Y + 1) #階乗の逆元
facv[-1] = pow(fact[-1], mod - 2 , mod)
for i in range(Y - 1, -1, -1):
facv[i] = facv[i + 1] * (i + 1) % mod
def cmb(n, r):
if n < r:
return 0
return fact[n] * facv[r] * facv[n - r] % mod
ans = 0
for i in range(K + 1):
opt = M * pow(M - 1, N - i - 1, mod) * cmb(N - i + i - 1, i)
ans += opt % mod
print(ans % mod)
| 0 | null | 16,507,126,706,910 | 113 | 151 |
import sys
read = sys.stdin.readline
N = int(read())
ans = 0
for i in range(1, N+1):
n = N // i
ans += 0.5 * n * (2*i + i * (n-1))
print(int(ans))
|
def gcd(a,b):
if a%b==0:
return b
else :
return gcd(b,a%b)
def main():
a,b=map(int,raw_input().split())
print(gcd(a,b))
if __name__=='__main__':
main()
| 0 | null | 5,481,093,943,050 | 118 | 11 |
A = list(map(float, input().split()))
if(A[0]/A[2] <= A[1]):
print("Yes")
else:
print("No")
|
n = int(input())
a = input().strip().split()
#Bubble sort
b = a[:]
for i in range(n):
for j in range(n-1,i,-1):
if b[j][1] < b[j-1][1]:
b[j],b[j-1] = b[j-1],b[j]
print(' '.join(b))
print('Stable')
#Selection sort
for i in range(n):
minj = i
for j in range(i,n):
if a[j][1] < a[minj][1]:
minj = j
a[i],a[minj] = a[minj],a[i]
print(' '.join(a))
print('Stable' if b == a else 'Not stable')
| 0 | null | 1,785,596,943,718 | 81 | 16 |
cnt = 0
n = int(input())
l = list(map(int, input().split()))
if len(l) >= 3:
for i in range(len(l)):
for j in range(i, len(l)):
for k in range(j, len(l)):
if l[i] == l[j] or l[i] == l[k] or l[j] == l[k]:
continue
elif l[i] + l[j] > l[k] and l[i] + l[k] > l[j] and l[j] + l[k] > l[i]:
cnt += 1
else:
continue
print(cnt)
|
import itertools
N = int(input())
L = list(map(int, input().split()))
combinations = list(itertools.combinations(range(N), 3))
count = 0
for cmb in combinations:
flag = True
for i in range(3):
if L[cmb[i]] + L[cmb[(i + 1) % 3]] > L[cmb[(i + 2) % 3]] and L[cmb[i]] != L[cmb[(i + 1) % 3]]:
continue
else:
flag = False
break
if flag:
count += 1
print(count)
| 1 | 5,082,717,583,426 | null | 91 | 91 |
N, K = map(int, input().split())
if N <= K:
print(0)
else:
H = list(map(int, input().split()))
H.sort()
H.reverse()
c = 0
for i in range(K, N):
c += H[i]
print(c)
|
a, b, c = input().split()
x = int(a)
y = int(b)
z = int(c)
if z >= x:
z -= x
x = 0
else:
x -= z
z = 0
if z >= y:
z -= y
y = 0
else:
y -= z
z = 0
print(str(x),str(y))
| 0 | null | 91,811,339,518,488 | 227 | 249 |
A,B= list(input().split())
a = int(B[0])
b = int(B[2])
c = int(B[3])
if int(A) > 1000:
e = int(A[-2])
f = int(A[-1])
d = int((int(A)- 10 * e - f)/100)
error = 10 * (c * e + b * f) + c * f
error = int(error/100)
ans = int(A) * a + 10 * d * b + e * b + c * d + error
print(int(ans))
else:
print(int(int(A)*float(B)))
|
n = int(input())
lst = [[0 for j in range(10)] for i in range(10)]
for i in range(1, n+1):
num = str(i)
lst[int(num[0])][int(num[-1])] += 1
cnt = 0
for i in range(10):
for j in range(i, 10):
if i == j:
cnt += lst[i][j] * lst[j][i]
else:
cnt += lst[i][j] * lst[j][i] * 2
print(cnt)
| 0 | null | 51,718,296,148,100 | 135 | 234 |
import math
if __name__ == "__main__":
N = int(input())
if N % 2 == 0:
hoge = N / 2
print(math.floor(hoge) - 1)
else:
print(math.floor(N / 2))
|
import sys
import itertools
N, K = map(int, input().split())
a = 0
h = 0
l = 0
for j in range(0,K-1):
h += j
for j in range(N+2-K,N+1):
l += j
for i in range(K,N+2):
h += i-1
l += N+1-i
a += l - h + 1
a %= 10 ** 9 + 7
print(a)
| 0 | null | 92,713,209,398,122 | 283 | 170 |
import itertools
N = int(input())
A = [int(x) for x in input().split()]
Acum = list(itertools.accumulate(A))
reg=10**12
for i in range(N):
reg = min(reg,
abs(Acum[-1] - Acum[i] * 2))
print(reg)
|
# :20
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()
INF = float('inf')
x, y, a, b, c = LI()
p = sorted(LI())[::-1][:x]
q = sorted(LI())[::-1][:y]
r = sorted(LI())[::-1][:x+y]
# print(p, q, r)
bucket = []
bucket += [[i, 'p'] for i in p]
bucket += [[i, 'q'] for i in q]
bucket += [[i, 'r'] for i in r]
bucket = sorted(bucket, key=lambda x: x[0])
# print(bucket)
d = {'p': 0, 'q': 0}
ans = 0
cnt = 0
while cnt < x + y:
if bucket[-1][1] == 'p' and d[bucket[-1][1]] < x:
ans += bucket.pop()[0]
d['p'] += 1
cnt += 1
elif bucket[-1][1] == 'q' and d[bucket[-1][1]] < y:
ans += bucket.pop()[0]
d['q'] += 1
cnt += 1
else:
ans += bucket.pop()[0]
cnt += 1
print(ans)
| 0 | null | 93,389,450,905,156 | 276 | 188 |
N = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 0
data = []
for p in range(X[N-1] + 1):
sum = 0
for i in range(len(X)):
sum += (X[i]-p)**2
ans = sum
p += 1
data.append(ans)
print(min(data))
|
N = int(input())
X = list(map(int, input().split()))
a = int(sum(X) / N)
b = a + 1
A, B = 0, 0
for x in X:
A += (x - a) ** 2
B += (x - b) ** 2
ans = min(A, B)
print(ans)
| 1 | 65,551,496,106,570 | null | 213 | 213 |
n=int(input())
a=[]
x=[]
for _ in range(n):
A=int(input())
X=[list(map(int,input().split())) for _ in range(A)]
a.append(A)
x.append(X)
ans=0
for i in range(2**n):
tmp=[0]*n
for j in range(n):
if (i>>j)&1:
tmp[j]=1
for k in range(n):
if a[k]==0:
continue
for h in range(a[k]):
hito=x[k][h][0]-1
singi=x[k][h][1]
if tmp[k]==1:
if tmp[hito]!=singi:
break
else:
continue
break
else:
ans=max(ans,sum(tmp))
print(ans)
|
N = int(input())
W = [[-1]*N for _ in range(N)]
for i in range(N):
A = int(input())
for j in range(A):
x, y = [int(z) for z in input().split()]
x -= 1
W[i][x] = y
M = 0
for b in range(2**N):
d = [0] * N
for i in range(N):
if (b >> i) & 1:
d[i] = 1
ok = True
for i in range(N):
if d[i] == 1:
for j in range(N):
if W[i][j] == -1:
continue
if W[i][j] != d[j]:
ok =False
if ok == True:
M = max(M, sum(d))
print(M)
| 1 | 121,526,811,628,772 | null | 262 | 262 |
n = int(input())
if len(set(input().split())) == n:
print('YES')
else:
print('NO')
|
from sys import stdin
import math
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(stdin.readline().rstrip())
print(l[k-1])
| 0 | null | 62,102,940,885,188 | 222 | 195 |
import sys
readline = sys.stdin.buffer.readline
s =readline().rstrip().decode()
t =readline().rstrip().decode()
if t[:-1] == s:
print('Yes')
else:
print('No')
|
S = input()
T = input()
if T.startswith(S):
print('Yes')
else:
print('No')
| 1 | 21,374,509,069,252 | null | 147 | 147 |
import math
K=int(input())
ans=0
for a in range(1,K+1):
for b in range(1,K+1):
g=math.gcd(a,b)
for c in range(1,K+1):
ans+=math.gcd(g,c)
print(ans)
|
n = int(input())
import math
l=0
for i in range(1,n+1):
for j in range(1,n+1):
p=math.gcd(i,j)
for k in range(1,n+1):
l+=math.gcd(p,k)
print(l)
| 1 | 35,455,117,919,430 | null | 174 | 174 |
N,M,*A = map(int, open(0).read().split())
A.sort()
if A[-M]*4*M >= sum(A):
print('Yes')
else:
print('No')
|
def solve():
N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
total = sum(A)
threshold = float(total) / (4*M)
cnt = 0
for num in A:
if num >= threshold:
cnt += 1
if cnt >= M:
print("Yes")
else:
print("No")
if __name__ == "__main__":
solve()
| 1 | 38,698,409,965,276 | null | 179 | 179 |
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b2=[]
b2.append(0)
for i in range(1,m+1):
b2.append(b2[i-1]+b[i-1])
a.insert(0,0)
cnt=0
a_sum=0
for i in range(n+1):
j=m
a_sum+=a[i]
while True:
if k>=a_sum+b2[j]:
cnt=max(cnt,i+j)
m=j
break
j-=1
if j <0:
break
print(cnt)
|
s = input().rstrip().split(' ')
a = int(s[0])
b = int(s[1])
c = int(s[2])
if a > b:
a,b = b,a
if b > c:
b,c = c,b
if a > b:
a,b = b,a
print(str(a) + " " + str(b) + " " + str(c))
| 0 | null | 5,571,956,442,062 | 117 | 40 |
#入力:N,M(int:整数)
def input2():
return map(int,input().split())
d,t,s=input2()
if d/s >t:
print("No")
else:
print("Yes")
|
d,t,s = map(float,input().split())
if t >= d/s:
print("Yes")
else:
print("No")
| 1 | 3,495,031,860,210 | null | 81 | 81 |
s=input()
l=[['SSS'],['RSS','SRS','SSR','RSR'],['RRS','SRR'],['RRR']]
for i in range(4):
if s in l[i]:
print(i)
exit()
|
from itertools import permutations
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
P=sorted(list(permutations(range(1,n+1),n)))
print(abs(P.index(p)-P.index(q)))
| 0 | null | 52,579,339,240,850 | 90 | 246 |
import sys
readline = sys.stdin.buffer.readline
n,k = map(int,readline().split())
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
res = 1
while p > 0:
if p % 2 == 0:
n = n ** 2 % mod
p //= 2
else:
res = res * n % mod
p -= 1
return res % mod
def factrial_memo(n=10**6+1,mod=10**9+7):
fact = [1, 1]
for i in range(2, n + 1):
fact.append((fact[-1] * i) % mod)
return fact
def fermat_cmb(n, r, mod=10**9+7): #needs pow,factrial_memo(only fact). return nCk
return fact[n] * pow(fact[r],mod-2) * pow(fact[n-r],mod-2) %mod
fact = factrial_memo()
if k > n-1: #全通りの再現が可能ならば
ans = fermat_cmb(2*n-1,n)
else: #移動回数の制限によって全通りの再現ができないならば
ans = 1
for i in range(1,k+1): #全ての動作を再現する(kはたかだか2*10**5である)
ans += fermat_cmb(n,i)*fermat_cmb(n-1,i)
#n人の中から動かせる人物をi人取り、n-1箇所(それぞれの人物に付き同じ場所には戻れない)
#にi人を入れる組み合わせ。それぞれの事象に付き、0人になる部屋と他の部屋の人数は
#必ず違う組み合わせになるので、これをk回だけ繰り返せば良い
ans %= mod
print(ans)
|
n, k = map(int, input().split())
MOD = 10**9+7
def prepare(n, MOD):
facts = [1]*(n+1)
for i in range(1, n+1):
facts[i] = facts[i-1]*i%MOD
invs = [1]*(n+1)
_invs = [1]*(n+1)
invs[n] = pow(facts[n], MOD-2, MOD)
for i in range(0, n)[::-1]:
invs[i] = invs[i+1] * (i+1) % MOD
return facts, invs
ans = 0
facts, invs = prepare(n, MOD)
for i in range(1+min(n-1, k)):
ans += facts[n]*invs[i]*invs[n-i]*facts[n-1]*invs[n-i-1]*invs[i]
ans %= MOD
print(ans)
| 1 | 67,149,594,056,772 | null | 215 | 215 |
import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
N,K=mi()
P=list(mi())
C=list(mi())
ans = -INF
for i in range(N):
start = i + 1
stack = [start]
score_his = [0]
scores = 0
depth = 1
seen = {}
while stack:
if depth > K: break
current = stack.pop()
if current in seen:
loop_start_depth = seen[current]
loop_end_depth = depth - 1
loop_scores = score_his[-1] - score_his[loop_start_depth-1]
loop_len = loop_end_depth - loop_start_depth + 1
if loop_scores < 0: break
# print(start,score_his)
# print(loop_start_depth,loop_end_depth,loop_scores,loop_len)
rest_count = K - depth + 1
available_loop_count = rest_count // loop_len
res1 = (available_loop_count-1) * loop_scores + scores
# print("a",rest_count,available_loop_count,res1)
res2 = res1
rest_loop_len = rest_count % loop_len + loop_len
# print("b",rest_loop_len)
ress = [res1,res2]
for j in range(rest_loop_len):
score = C[P[current-1]-1]
res2 += score
ress.append(res2)
current = P[current-1]
# print("ress",ress)
score_his.append(max(ress))
break
score = C[P[current-1]-1]
scores += score
score_his.append(scores)
seen[current] = depth
stack.append(P[current-1])
depth += 1
ans = max(ans,max(score_his[1:]))
print(ans)
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
import sys
from itertools import chain
def max_add_1_to_n(loop, n):
# print(' max_add_1_to_n', loop, n)
l = len(loop)
acc = loop.copy()
# print(' ', acc)
max_val = max(acc)
for i in range(1, n):
for j in range(0, l):
acc[j] += loop[(i + j) % l]
# print(" ", acc)
max_val = max(max(acc), max_val)
return max_val
def max_add_0_to_n(loop, n):
# print(' max_add_0_to_n', loop, n)
if n >= 1:
return max(max_add_1_to_n(loop, n), 0)
else:
return 0
def max_loop_k(loop, K):
l = len(loop)
if K <= 2 * l:
return max_add_1_to_n(loop, K)
# K は 2 * l より長い
l_sum = sum(loop)
if l_sum <= 0:
return max_add_1_to_n(loop, l)
else:
Kdiv = K // l
Kmod = K % l
# print(' l Kdiv Kmod', l, Kdiv, Kmod)
return max_add_0_to_n(loop, l + Kmod) + l_sum * (Kdiv - 1)
def solve(N: int, K: int, P: "List[int]", C: "List[int]"):
# 簡単のためインデックスを 0 からにする
# (使用済みは -1 を入れる)
P = [i - 1 for i in P]
answer = -float("inf")
for i0 in range(N):
if P[i0] == -1:
continue
loop = []
i = i0
while P[i] != -1:
loop.append(C[i])
i_next = P[i]
P[i] = -1
i = i_next
answer = max(answer, max_loop_k(loop, K))
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
P = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
C = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(N, K, P, C)
print(answer)
if __name__ == "__main__":
main()
| 1 | 5,396,213,740,776 | null | 93 | 93 |
R = int(input())
print(int(R*R))
|
# -*- coding: utf-8 -*-
"""
Created on Sun May 3 18:07:38 2020
@author: Kanaru Sato
"""
r = int(input())
print(r*r)
| 1 | 145,781,173,207,670 | null | 278 | 278 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.