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 = int(input())
titles = []
times = []
for i in range(n):
title,m = input().split()
titles.append(title)
times.append(int(m))
print(sum(times[titles.index(input())+1:])) | n = int(input())
title = []
time = []
for i in range(n):
line = input().split()
title += [line[0]]
time += [int(line[1])]
key = input()
a = title.index(key)
print(sum(time[a+1:]))
| 1 | 97,023,106,089,798 | null | 243 | 243 |
import sys
R, C, K = list(map(int, input().split()))
d = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)]
t = [[0] * (C+1) for _ in range(R+1)]
for i in range(K):
r,c,v = list(map(int, input().split()))
t[r][c] = v
for i in range(R+1):
for j in range(C+1):
for k in range(4):
if i!=0:
d[0][i][j] = max(d[0][i][j], d[k][i-1][j])
d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j])
if j!=0:
d[k][i][j] = max(d[k][i][j], d[k][i][j-1])
if k != 0:
d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j])
a = 0
for i in range(4):
a = max(a, d[i][-1][-1])
print(a)
| H, W, K = map(int, input().split())
A = [[0] * W for _ in range(H)]
for i in range(K):
y, x, v = map(int, input().split())
A[y - 1][x - 1] = v
dp = [[0] * 4 for i in range(W)]
pre = []
dp[0][1] = A[0][0]
for i in range(H):
for j in range(W):
if i:
dp[j][0] = max(dp[j][0], max(pre[j]))
dp[j][1] = max(dp[j][1], max(pre[j]) + A[i][j])
for k in range(4):
if j:
if 0 < k:
dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + A[i][j])
dp[j][k] = max(dp[j][k], dp[j - 1][k])
pre = dp
ans = 0
for j in range(W):
ans = max(ans, max(dp[j]))
print(ans)
| 1 | 5,532,222,996,200 | null | 94 | 94 |
N=int(input())
s=input()
A=[]
for i in range(N):
A.append(s[i])
cntW=0
for i in range(N):
if A[i]=="W":
cntW+=1
cntR=N-cntW
changeW=0
changeR=0
for i in range(cntR):
if A[i]=="W":
changeW+=1
for i in range(cntR,N):
if A[i]=="R":
changeR+=1
if changeR==changeW:
ans=changeW
else:
#minN=min(changeW,changeR)
maxN=max(changeR,changeW)
ans=maxN
print(ans) | # AOJ ITP1_9_A
def numinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
# ※大文字と小文字を区別しないので注意!!!!
# 全部大文字にしちゃえ。
def main():
W = input().upper() # 大文字にする
line = ""
count = 0
while True:
line = input().split(" ")
if line[0] == "END_OF_TEXT": break
for i in range(len(line)):
word = line[i].upper()
if W == word: count += 1
print(count)
if __name__ == "__main__":
main()
| 0 | null | 4,012,931,443,250 | 98 | 65 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
for Ai in A:
N -= Ai
if N < 0:
print(-1)
break
if N >= 0:
print(N) | import sys
from collections import defaultdict, Counter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = map(int, read().split())
N_MAX = 10 ** 6
min_factor = list(range(N_MAX + 1))
min_factor[2::2] = [2] * (N_MAX // 2)
for i in range(3, int(N_MAX ** 0.5) + 2, 2):
if min_factor[i] != i:
continue
for j in range(i * i, N_MAX + 1, 2 * i):
if min_factor[j] > i:
min_factor[j] = i
def prime_factorize_fast(n):
a = Counter()
while n != 1:
a[min_factor[n]] += 1
n //= min_factor[n]
return a
lcm_prime = Counter()
for a in A:
for p, n in prime_factorize_fast(a).items():
if lcm_prime[p] < n:
lcm_prime[p] = n
l = 1
for p, n in lcm_prime.items():
l = l * pow(p, n, MOD) % MOD
ans = 0
for a in A:
ans = (ans + pow(a, MOD - 2, MOD)) % MOD
ans = ans * l % MOD
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 59,977,958,720,890 | 168 | 235 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
s=input()
t=input()
n=len(s)
ans=0
for i in range(n):
if s[i]!=t[i]:
ans+=1
print(ans) | n,m = map(int,input().split())
h = list(map(int,input().split()))
ab = [list(map(int,input().split())) for _ in range(m)]
place = [True]*n
for i in range(m):
a,b = ab[i][0],ab[i][1]
if h[a-1] < h[b-1]:
place[a-1] = False
elif h[a-1] == h[b-1]:
place[a-1] = False
place[b-1] = False
else:
place[b-1] = False
print(place.count(True))
| 0 | null | 17,810,214,141,590 | 116 | 155 |
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
F_list = list(map(int, input().split()))
A_list_min = sorted(A_list)
F_list_max = sorted(F_list, reverse=True)
first_OK = 10**12
def is_ok(arg):
check_cnt = 0
return_flag = 0
for i in range(N):
temp = A_list_min[i] - arg//F_list_max[i]
if temp > 0:
check_cnt += A_list_min[i] - arg//F_list_max[i]
if check_cnt <= K:
return_flag = 1
else:
return_flag = 0
return return_flag
def bisect(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(bisect(-1, first_OK)) | import heapq
def main():
N, M = list(map(int, input().split(' ')))
S = input()
# 最短手数のdpテーブルを作る
T = S[::-1] # ゴールから逆順にたどる(最後に逆にする)
dp = [-1] * (N + 1)
que = [0] * M
for i, t in enumerate(T):
if i == 0:
dp[0] = 0
continue
if len(que) == 0:
print(-1)
return
index = heapq.heappop(que)
if t == '1':
continue
dp[i] = 1 + dp[index]
while len(que) < M:
heapq.heappush(que, i)
dp.reverse()
# 細切れに進んでいく
path = list()
target = dp[0] - 1
cnt = 0
for i in range(N + 1):
if dp[i] != target:
cnt += 1
else:
path.append(cnt)
cnt = 1
target -= 1
print(' '.join(map(str, path)))
if __name__ == '__main__':
main()
| 0 | null | 152,577,598,128,670 | 290 | 274 |
import math
a, b, C=map(int, input().split())
print("{0:.5f}".format((1/2)*a*b*math.sin(C*math.pi/180.0)))
print("{0:.5f}".format(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180))))
print("{0:.5f}".format(b*math.sin(C*math.pi/180.0))) | #!python3
LI = lambda: list(map(int, input().split()))
# input
K = int(input())
S = input()
MOD = 10 ** 9 + 7
MAX = 2 * (10 ** 6) + 1
p25, p26 = [None] * MAX, [None] * MAX
fac, finv, inv = [None] * MAX, [None] * MAX, [None] * MAX
def comb_init():
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = -inv[MOD%i] * int(MOD / i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def comb(n, k):
if n < k or n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
def power_init():
p25[0] = 1
p26[0] = 1
for i in range(1, MAX):
p25[i] = p25[i - 1] * 25 % MOD
p26[i] = p26[i - 1] * 26 % MOD
def main():
comb_init()
power_init()
n = len(S)
ans = 0
for i in range(K + 1):
x = p25[i] * comb(i + n - 1, n - 1) % MOD * p26[K - i] % MOD
ans = (ans + x) % MOD
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 6,415,365,883,150 | 30 | 124 |
#!/usr/bin/env python
# coding: utf-8
def gcd ( ax, ay):
x = ax
y = ay
while (True):
if x < y :
tmp = x
x = y
y = tmp
x=x %y
if x == 0:
return y
elif x == 1:
return 1
x,y = map(int, input().split())
print(gcd(x,y))
| def gcd (x , y):
sur = x % y
while sur != 0:
x = y
y = sur
sur = x % y
return y
a,b = map(int,raw_input().split())
if a < b :
temp = a
a = b
b = temp
print gcd(a,b) | 1 | 7,678,392,278 | null | 11 | 11 |
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
IronMan = sorted(p)
CaptainAmerica = sorted(q)
for i in range(X):
r.append(IronMan.pop())
for i in range(Y):
r.append(CaptainAmerica.pop())
SpiderMan = sorted(r)[::-1]
print(sum(SpiderMan[:X+Y]))
| X, Y, A, B, C = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:X]
q = sorted([int(x) for x in input().split()], reverse=True)[:Y]
r = sorted([int(x) for x in input().split()], reverse=True)[:X + Y]
s = sorted(p + q + r, reverse=True)
ans = sum(s[:X + Y])
print(ans) | 1 | 44,758,725,072,438 | null | 188 | 188 |
class SegmentTree():
'''
非再帰
segment tree
'''
def __init__(self, n, func, init=float('inf')):
'''
n->配列の長さ
func:func(a,b)->val, func=minだとRMQになる
木の高さhとすると,
n:h-1までのノード数。h段目のノードにアクセスするために使う。
data:ノード。
parent:k->child k*2+1とk*2+2
'''
self.n = 2**(n-1).bit_length()
self.init = init
self.data = [init]*(2*self.n)
self.func = func
def set(self, k, v):
'''
あたいの初期化
'''
self.data[k+self.n-1] = v
def build(self):
'''
setの後に一斉更新
'''
for k in reversed(range(self.n-1)):
self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])
def update(self, k, a):
'''
list[k]=aに更新する。
更新ぶんをrootまで更新
'''
k += self.n-1
self.data[k] = a
while k > 0:
k = (k-1)//2
self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])
def query(self, l, r):
'''
[l,r)のfuncを求める
'''
L = l+self.n
R = r+self.n
ret = self.init
while L < R:
if R & 1:
R -= 1
ret = self.func(ret, self.data[R-1])
if L & 1:
ret = self.func(ret, self.data[L-1])
L += 1
L >>= 1
R >>= 1
return ret
N = int(input())
S = input()
Q = int(input())
queries = [list(input().split()) for _ in range(Q)]
def a2n(a):
return ord(a)-ord("a")
def createInp(a):
return 1 << a2n(a)
Seg = SegmentTree(len(S), lambda x, y: x | y, init=0)
for i, s in enumerate(S):
Seg.set(i, createInp(s))
Seg.build()
for q, l, r in queries:
if q == "1":
Seg.update(int(l)-1, createInp(r))
else:
print(bin(Seg.query(int(l)-1, int(r))).count('1'))
| def resolve():
N, M = map(int, input().split())
ans = 0
if N == 1 and M == 1:
pass
else:
if N != 0:
ans += N*(N-1)/2
if M != 0:
ans += M*(M-1)/2
print(int(ans))
resolve() | 0 | null | 54,218,831,857,498 | 210 | 189 |
import numpy as np
n = int(input())
st = [input().split() for _ in range(n)]
x = input()
s, t = zip(*st)
i = s.index(x)
print(sum(map(int, t[i+1:])))
| def main():
n = int(input())
s_list = [None for _ in range(n)]
t_list = [None for _ in range(n)]
for i in range(n):
s, t = input().split()
s_list[i] = s
t_list[i] = int(t)
x = input()
x_index = s_list.index(x)
ans = sum(t_list[x_index + 1:])
print(ans)
if __name__ == "__main__":
main()
| 1 | 96,695,974,208,860 | null | 243 | 243 |
# -*- coding: utf-8 -*-
def main():
N = int(input())
case = []
for i in range(1, 10):
for j in range(1, 10):
case.append(i * j)
if N in case:
ans = 'Yes'
else:
ans = 'No'
print(ans)
if __name__ == "__main__":
main() | n=int(input())
l=list((v*h) for h in range(1,10) for v in range(1,10))
if n in l:
print("Yes")
else:
print("No") | 1 | 159,491,932,499,900 | null | 287 | 287 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
answer = N - sum(A)
if N >= sum(A):
print(answer)
else:
print('-1') | N,M=map(int,input().split())
A_M=list(map(int,input().split()))
if N >= sum(A_M):
print(N-sum(A_M))
else:
print(-1) | 1 | 31,966,273,100,328 | null | 168 | 168 |
import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
base_ans = 0
for i in c.values():
base_ans += (i)*(i-1)//2
for a in A:
i = c[a]
diff_ans = max(0, i-1)
print(base_ans - diff_ans)
| n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
c = [0]*n
a = [0]*n
for i in range(n):
c[i],a[i] = ca[i][0],ca[i][1:]
INF = 10**9
ans = INF
for i in range(1<<n):
understanding = [0]*m
cost = 0
for j in range(n):
if ((i>>j)&1):
cost += c[j]
for k in range(m):
understanding[k] += a[j][k]
ok = True
for s in range(m):
if understanding[s] < x:
ok = False
if ok:
ans = min(ans, cost)
if ans == INF:
ans = -1
print(ans)
| 0 | null | 34,796,150,875,762 | 192 | 149 |
class UnionFind:
par = None
def __init__(self, n):
self.par = [0] * n
def root(self, x):
if(self.par[x] == 0):
return x
else:
self.par[x] = self.root(self.par[x])
return self.root(self.par[x])
def unite(self, x, y):
if(self.root(x) != self.root(y)):
self.par[self.root(x)] = self.root(y)
def same(self, x, y):
return self.root(x) == self.root(y)
N, M = list(map(int, input().split()))
UF = UnionFind(N)
for i in range(M):
A, B = list(map(int, input().split()))
UF.unite(A - 1, B - 1)
ans = 0
for i in range(N):
if(UF.par[i] == 0):
ans += 1
print(ans - 1)
| import sys
from collections import defaultdict
import bisect
import itertools
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
def main():
N, M = geta(int)
A = list(geta(int))
A.sort()
def c(x):
"""
@return # of handshake where hapiness >= x
"""
ret = 0
for a in A:
ret += bisect.bisect_left(A, x - a)
return N * N - ret
left, right = 0, 2 * A[-1] + 1
while left + 1 < right:
middle = (left + right) // 2
if c(middle) >= M:
left = middle
else:
right = middle
ans = 0
Acum = list(itertools.accumulate(A[::-1]))[::-1]
for a in A:
idx = bisect.bisect_left(A, right - a)
if idx < N:
ans += Acum[idx] + a * (N - idx)
ans += left * (M - c(right))
print(ans)
if __name__ == "__main__":
main() | 0 | null | 55,280,671,200,690 | 70 | 252 |
H1, M1, H2, M2, K = map(int, input().split())
print(60 * (H2 - H1) + M2 - M1 - K) | H1,M1,H2,M2,K = map(int,input().split())
start,end = 60*H1+M1,60*H2+M2
print(abs(start-end) - K) if end-K>0 else print(0) | 1 | 18,090,415,790,930 | null | 139 | 139 |
A,B = map(int,input().split())
print(A*B,2*(A+B))
| x = input().split()
print(int(x[0]) * int(x[1]), 2 * (int(x[0])+ int(x[1]))) | 1 | 302,526,876,960 | null | 36 | 36 |
X = int(input())
while True:
flag = True
for i in range(2, X):
if X % i == 0:
flag = False
if flag: break
X += 1
print(X) | # Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042
x= int(input())
def prime_check(num,count):
while True:
while num % count == 0:
num = num + 1
count = 2
if num <= count**2:
print(num)
break
else:
count = count + 1
if x==2 :
print (2)
else:
prime_check(x,2)
| 1 | 105,414,423,398,944 | null | 250 | 250 |
x,y,a,b,c=map(int,input().split())
a_list=list(map(int,input().split()))
a_list=sorted(a_list)
b_list=list(map(int,input().split()))
b_list=sorted(b_list)
a_list=a_list[-x:]
b_list=b_list[-y:]
c_list=list(map(int,input().split()))
for i in range(c):
c_list[i]=-c_list[i]
import heapq
heapq.heapify(a_list)
heapq.heapify(b_list)
heapq.heapify(c_list)
flag=True
while flag and c_list:
x=heapq.heappop(c_list)
x=x*(-1)
#c_listの中でのもっとも大きい値
min_a=heapq.heappop(a_list)
min_b=heapq.heappop(b_list)
if min(min_a,min_b)>=x:
flag=False
heapq.heappush(a_list,min_a)
heapq.heappush(b_list,min_b)
else:
if min_a>=min_b:
heapq.heappush(a_list,min_a)
heapq.heappush(b_list,x)
elif min_a<min_b:
heapq.heappush(b_list,min_b)
heapq.heappush(a_list,x)
sum_a=sum(list(a_list))
sum_b=sum(list(b_list))
print(sum_a+sum_b)
| import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())), reverse=True)
Apples = sorted(P[:x] + Q[:y] + R, reverse=True)
print(sum(Apples[: x + y]))
if __name__ == '__main__':
resolve()
| 1 | 45,092,935,070,920 | null | 188 | 188 |
n=int(input())
a=list(map(int,input().split()))
num=["0"]*n
count="1"
for i in a:
num[i-1]=count
count=int(count)
count+=1
count=str(count)
print(" ".join(num)) | x, y = map(int, input().split())
while x != 0 or y != 0:
if x < y:
print(x, y)
else:
print(y, x)
x, y = map(int, input().split()) | 0 | null | 90,915,527,239,680 | 299 | 43 |
#AOJ ITP1_1_C
N = input().split()
area = 0
perimeter = 0
length=int(N[0])
breadth=int(N[1])
area = length * breadth
perimeter = (length + breadth) * 2
print(str(area)+" "+str(perimeter) )
| n=int(input())
s,t=input().split()
ans=''
for i in range(2*n):
ans=ans+(s[i//2] if i%2==0 else t[(i-1)//2])
print(ans)
| 0 | null | 56,392,648,899,888 | 36 | 255 |
S = input() *2
N = input()
if N in S:
print("Yes")
else:
print("No") | n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A.reverse()
s = 0
cnt = 0
for i in range(n):
s += A[i]
for i in range(m):
if A[i] >= s/(4*m):
cnt += 1
if cnt == m:
print('Yes')
else :
print('No')
| 0 | null | 20,078,565,849,440 | 64 | 179 |
import sys
w = sys.stdin.readline().rstrip().lower()
cnt = 0
while True:
lines = sys.stdin.readline().rstrip()
if not lines:
break
words = lines.split( " " )
for i in range( len( words ) ):
if w == words[i].lower():
cnt += 1
print( cnt ) | n = int(input())
print(int((n + 1)/2)) | 0 | null | 30,520,953,784,122 | 65 | 206 |
N, K = map(int, input().split())
mod = 998244353
move = []
for _ in range(K):
L, R = map(int, input().split())
move.append((L, R))
S = [0]*K
dp = [0]*(2*N)
dp[N] = 1
for i in range(N+1, 2*N):
for k, (l, r) in enumerate(move):
S[k] -= dp[i-r-1]
S[k] += dp[i-l]
dp[i] += S[k]
dp[i] %= mod
print(dp[-1]) | from sys import stdin
import sys
sys.setrecursionlimit(10**7)
def main():
_in = [_.rstrip() for _ in stdin.readlines()]
N, K = list(map(int, _in[0].split(' '))) # type:list(int)
L_R_arr = []
for i in range(K):
_ = list(map(int, _in[i+1].split(' '))) # type:list(int)
L_R_arr.append(_)
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
dp = [0] * N
sdp = [0] * (N+1)
dp[0] = 1
for i in range(N):
for L, R in L_R_arr:
right = max(0, i-L+1)
left = max(0, i-R)
dp[i] += sdp[right] - sdp[left]
else:
sdp[i+1] = (sdp[i] + dp[i]) % 998244353
ans = dp[-1] % 998244353
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
if __name__ == "__main__":
main()
| 1 | 2,723,156,985,780 | null | 74 | 74 |
from collections import Counter
import sys
import math
from functools import cmp_to_key
sys.setrecursionlimit(10 ** 6)
mod = 1000000007
inf = int(1e18)
def main():
n = int(input())
p = [tuple(map(int, input().split())) for i in range(n)]
a = {}
b = {}
c = 0
for x, y in p:
if x == y == 0:
c += 1
continue
if y == 0:
a[(0, 1)] = a.get((0, 1), 0) + 1
continue
if x == 0:
b[(0, 1)] = b.get((0, 1), 0) + 1
g = math.gcd(x, y)
if x * y > 0:
x = abs(x)
y = abs(y)
a[(x//g, y//g)] = a.get((x//g, y//g), 0) + 1
else:
x = abs(x)
y = abs(y)
b[(y//g, x//g)] = b.get((y//g, x//g), 0) + 1
ans = 1
s = 0
for k, v in a.items():
if k in b:
s += v + b[k]
ans *= pow(2, v) + pow(2, b[k]) - 1
ans %= mod
ans *= pow(2, n - s - c, mod)
print((ans - 1 + c) % mod)
main()
| from collections import defaultdict
from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7
p = defaultdict(int)
m = defaultdict(int)
ab0 = 0
for a, b in ab:
if a == 0 and b == 0:
ab0 += 1
elif a == 0:
m[(0, 1)] += 1
p[(1, 0)]
elif b == 0:
p[(1, 0)] += 1
else:
g = gcd(a, b)
a //= g
b //= g
sign = a * b
a = abs(a)
b = abs(b)
if sign < 0:
m[(a, b)] += 1
p[(b, a)]
else:
p[(a, b)] += 1
ans = 1
for (a, b), v in p.items():
ans *= pow(2, v, mod) + pow(2, m[(b, a)], mod) - 1
ans %= mod
ans -= 1
ans += ab0
ans %= mod
print(ans)
| 1 | 20,953,792,757,806 | null | 146 | 146 |
A, B, K = map(int, input().split())
if A > K:
after_A = A - K
after_K = 0
else:
after_A = 0
after_K = K - A
if B > after_K:
after_B = B - after_K
final_K = 0
else:
after_B = 0
final_K = after_K - B
print(after_A, after_B) | while True:
score = [int(i) for i in input().split()]
if score == [-1, -1, -1]:
break
sum = score[0] + score[1]
if sum < 30 or score[0] == -1 or score[1] == -1:
print('F')
elif sum < 50 and score[2] < 50:
print('D')
elif sum < 65 or (sum < 65 and score[2] >= 50):
print('C')
elif sum < 80:
print('B')
elif sum >= 80:
print('A')
| 0 | null | 52,845,885,064,572 | 249 | 57 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N,K=MI()
A=LI()
A.sort()
#0~Nまで逆元などを事前計算
def cmb(n, r, mod):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return (fact[n] * factinv[r] * factinv[n-r])%mod
fact=[1,1]
factinv=[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)
factinv.append((factinv[-1] * inv[-1]) % mod)
def calc(ii,a):
# ii番目が最大となる時,それの寄与は?
# 0~ii-1のii個からK-1個えらぶ
temp=cmb(ii,K-1,mod)
return (temp*a)%mod
ans=0
for i in range(N):
ans+=calc(i,A[i])
for i in range(N):
A[i]*=-1
A.sort()
for i in range(N):
ans+=calc(i,A[i])
print(ans%mod)
main()
| from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)
def main():
a, b = map(int, input().split())
if a <= b:
print(str(a) * b)
else:
print(str(b) * a)
main() | 0 | null | 90,375,241,537,130 | 242 | 232 |
# coding: utf-8
import sys
strings = input()
for s in strings:
if s.islower():
sys.stdout.write(s.upper())
else:
sys.stdout.write(s.lower())
print() | n, k = map(int, input().split())
a = [i-1 for i in map(int, input().split())]
left, right = 1, 10**9
while left < right:
middle = (left + right)//2
count = sum(i//middle for i in a)
if count <= k:
right = middle
else:
left = middle + 1
print(left) | 0 | null | 3,948,135,489,452 | 61 | 99 |
from collections import defaultdict
from collections import deque
from collections import Counter
import math
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
s = list(input())
k = readInt()
if len(Counter(s))==1:
ans = k*len(s)//2
elif s[0]!=s[-1]:
ans = 0
i = 0
l = 0
tmp = s[:]+["!"]
d = []
while i<len(s):
if tmp[i]==tmp[i+1]:
i+=1
else:
d.append(tmp[l:i+1])
l = i+1
i+=1
for i in d:
ans+=len(i)//2
ans*=k
else:
ans = 0
i = 0
l = 0
tmp = s[:]+["!"]
d = []
while i<len(s):
if tmp[i]==tmp[i+1]:
i+=1
else:
d.append(tmp[l:i+1])
l = i+1
i+=1
for i in d[1:-1]:
ans+=len(i)//2
ans*=k
ans+=len(d[0])//2
ans+=len(d[-1])//2
ans+=(len(d[0])+len(d[-1]))//2*(k-1)
print(ans) | n, k = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
a_list.sort()
mod = 10 ** 9 + 7
temp_list = [1] * (n + 1)
for i in range(1, n + 1):
temp_list[i] = i * temp_list[i - 1] % mod
i_temp_list = [1] * (n + 1)
i_temp_list[-1] = pow(temp_list[-1], mod - 2, mod)
for i in range(n, 0, -1):
i_temp_list[i - 1] = i_temp_list[i] * i % mod
y = k - 1
ans = 0
for i in range(k - 1, n):
x = i
num = temp_list[x] * i_temp_list[y] * i_temp_list[x - y] % mod
ans += a_list[i] * num % mod
for i in range(n - k + 1):
x = n - 1 - i
num = temp_list[x] * i_temp_list[y] * i_temp_list[x - y] % mod
ans -= a_list[i] * num % mod
ans %= mod
print(ans) | 0 | null | 135,310,215,890,630 | 296 | 242 |
s = input()
ans = 0
if 'RRR' in s:
ans = 3
elif 'RR' in s:
ans = 2
elif 'R' in s:
ans = 1
print(ans) | from math import gcd
from functools import reduce
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
g=reduce(gcd,a)
if g!=1:
print("not coprime")
exit()
def isPrimeMR(n):
d = n - 1
d = d // (d & -d)
L = [2]
for a in L:
t = d
y = pow(a, t, n)
if y == 1: continue
while y != n - 1:
y = (y * y) % n
if y == 1 or t == n - 1: return 0
t <<= 1
return 1
def findFactorRho(n):
m = 1 << n.bit_length() // 8
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
g = 1
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), n)
if g < n:
if isPrimeMR(g): return g
elif isPrimeMR(n // g): return n // g
return findFactorRho(g)
def primeFactor(n):
i = 2
ret = {}
rhoFlg = 0
while i*i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += 1 + i % 2
if i == 101 and n >= 2 ** 20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
rhoFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
return ret
def primes(x):
ret=[]
for i in range(1,int(x**0.5)+1):
if x%i==0:
ret.append(i)
if x//i!=i:
ret.append(x//i)
ret.sort()
return ret[1:]
d=defaultdict(int)
for q in a:
#p=primeFactor(q)
p=primes(q)
for j in p:
if d[j]==1:
print("setwise coprime")
exit()
d[j]+=1
print("pairwise coprime") | 0 | null | 4,536,317,428,036 | 90 | 85 |
n = int(input())
s = input()
if len(s) > n:
print(s[:n] + '...')
else:
print(s) | K = int(input())
S = str(input())
def result(K: int, S: str) -> str:
if len(S) <= K:
return S
else:
answer = S[:K]
return answer + '...'
print(result(K, S))
| 1 | 19,648,917,554,240 | null | 143 | 143 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
N,K,S=map(int,input().split())
if S>1:
print(*[S]*(K)+[S-1]*(N-K))
else:
print(*[S]*(K)+[S+1]*(N-K))
resolve() | import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n, m = map(int, readline().rstrip().split())
a = list(map(int, readline().rstrip().split()))
print(n - sum(a) if n - sum(a) >= 0 else -1)
if __name__ == '__main__':
main()
| 0 | null | 61,576,715,787,858 | 238 | 168 |
D, T, S = [int(x) for x in input().split()]
print("Yes" if D <= (T * S) else "No")
| d,t,s=map(int,input().split())
print("Yes" if t>=d/s else "No") | 1 | 3,519,501,763,930 | null | 81 | 81 |
import sys
from math import gcd
from collections import defaultdict
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N = I()
mod = 10**9+7
plus = defaultdict(int)
minus = defaultdict(int)
flag = defaultdict(int)
A_zero,B_zero = 0,0
zero_zero = 0
for i in range(N):
a,b = MI()
if a == b == 0:
zero_zero += 1
elif a == 0:
A_zero += 1
elif b == 0:
B_zero += 1
else:
if a < 0:
a,b = -a,-b
a,b = a//gcd(a,b),b//gcd(a,b)
if b > 0:
plus[(a,b)] += 1
else:
minus[(a,b)] += 1
flag[(a,b)] = 0
ans = 1
for a,b in plus.keys():
ans *= pow(2,plus[(a,b)],mod)+pow(2,minus[(b,-a)],mod)-1
ans %= mod
flag[(b,-a)] = 1
for key in minus.keys():
if flag[key] == 0:
ans *= pow(2,minus[key],mod)
ans %= mod
ans *= pow(2,A_zero,mod)+pow(2,B_zero,mod)-1
ans %= mod
ans += zero_zero-1
ans %= mod
print(ans)
| import queue
h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
# print(maze)
def bfs(dist, i, j):
q = queue.Queue()
q.put((i, j, 0))
while not q.empty():
i, j, c = q.get()
# print(i, j, c, dist)
if i != 0 and dist[i-1][j] == 0:
dist[i-1][j] = c+1
q.put((i-1, j, c+1))
if j != 0 and dist[i][j-1] == 0:
dist[i][j-1] = c+1
q.put((i, j-1, c+1))
if i != h-1 and dist[i+1][j] == 0:
dist[i+1][j] = c+1
q.put((i+1, j, c+1))
if j != w-1 and dist[i][j+1] == 0:
dist[i][j+1] = c+1
q.put((i, j+1, c+1))
return dist, c
ans = 0
for i in range(h):
for j in range(w):
if maze[i][j] == '.':
dist = [[(maze[y][x] == '#')*-1 for x in range(w)] for y in range(h)]
dist[i][j] = -10
dist, c = bfs(dist, i, j)
tmp_ans = c
if tmp_ans > ans:
ans = tmp_ans
print(ans)
| 0 | null | 58,132,835,903,078 | 146 | 241 |
vals = [int(i) for i in input().split()]
a = vals[0]
b = vals[1]
c = vals[2]
d = vals[3]
res2 = a//d + (1 if(a % d > 0) else 0)
res1 = c//b + (1 if(c % b > 0) else 0)
res = "Yes" if(res1 <= res2) else "No"
print(res) | A, B, C, D = map(int, input().split())
ctr = 0
while True:
if C <= 0:
print("Yes")
break
if A <= 0:
print("No")
break
if ctr % 2 == 0:
C -= B
else:
A -= D
ctr += 1
| 1 | 29,821,158,549,220 | null | 164 | 164 |
from itertools import permutations
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
sum = 0
cnt = 0
for i in permutations(xy):
for j in range(n - 1):
sum += ((i[j][0] - i[j + 1][0]) ** 2 + (i[j][1] - i[j + 1][1]) ** 2) ** 0.5
cnt += 1
print(sum / cnt) | n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
from itertools import permutations
import math
m = math.factorial(n)
per = permutations(xy,n)
d = 0
c = 0
for j in per :
for i in range(n-1):
d += ((j[i+1][0]-j[i][0])**2 + (j[i+1][1]-j[i][1])**2) ** 0.5
print(d/m)
| 1 | 148,626,466,180,460 | null | 280 | 280 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, u, v = mapint()
query = [[] for _ in range(N)]
for _ in range(N-1):
a, b = mapint()
query[a-1].append(b-1)
query[b-1].append(a-1)
from collections import deque
def dfs(start):
Q = deque([start])
dist = [10**18]*N
dist[start] = 0
while Q:
now = Q.pop()
for nx in query[now]:
if dist[nx]>=10**18:
dist[nx] = dist[now] + 1
Q.append(nx)
return dist
taka = dfs(u-1)
aoki = dfs(v-1)
ans = 0
for i in range(N):
t, a = taka[i], aoki[i]
if t<=a:
ans = max(ans, a-1)
print(ans) | def inverse(a, p):
a_, p_ = a, p
x, y = 1, 0
while p_:
t = a_ // p_
a_ -= t * p_
a_, p_ = p_, a_
x -= t * y
x, y = y, x
x %= p
return x
def solve():
N, M, K = map(int, input().split())
mod = 998244353
nCi = [1]
for i in range(1, N):
nCi.append(nCi[i - 1] * (N - i) * inverse(i, mod) % mod)
ans = 0
for k in range(K + 1):
n = N - k
ans += M * int(pow((M - 1), n - 1, mod)) * nCi[k]
ans %= mod
print(ans)
if __name__ == '__main__':
solve()
| 0 | null | 70,064,717,343,528 | 259 | 151 |
word = input()
num = int(input())
for index in range(num):
code = input().split()
instruction = code[0]
start, end = int(code[1]), int(code[2])
if instruction == "replace":
word = word[:start] + code[3] + word[end+1:]
elif instruction == "reverse":
reversed_ch = "".join(reversed(word[start:end+1]))
word = word[:start] + reversed_ch + word[end+1:]
else:
print(word[start:end+1])
| def run():
s=input()
command_num=int(input())
for i in range(command_num):
command = input().split()
command = list(map(lambda x: int(x) if x.isdigit() else x,command))
# print(s)
if command[0] == "print":
a=command[1]
b=command[2]
print(s[a:b+1])
elif command[0] == "reverse":
a=command[1]
b=command[2]
rev=s[a:b+1]
rev=rev[::-1]
#境界処理がめんどくさい
pre= "" if a==0 else s[0:a]
post="" if b==len(s)-1 else s[b+1:]
s=pre+rev+post
elif command[0] == "replace":
a=command[1]
b=command[2]
p=command[3]
#境界処理がめんどくさい
pre= "" if a==0 else s[0:a]
post="" if b==len(s)-1 else s[b+1:]
s=pre+p+post
else:
assert False
run()
| 1 | 2,079,436,069,450 | null | 68 | 68 |
def main():
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
c = [[0]*(N+1) for _ in range(61)]
c[0][1:] = A[:]
for i in range(60):
for j in range(1, N+1):
c[i+1][j] = c[i][c[i][j]]
i = 1 << 60
j = 1
k = 60
while K > 0:
if i <= K:
K -= i
j = c[k][j]
i >>= 1
k -= 1
print(j)
if __name__ == '__main__':
main()
| n,k = map(int,input().split())
A = [0]
A.extend(list(map(int,input().split())))
town = 1
once = [0]*(n+1)
for i in range(n):
if once[town]==0:
once[town] = 1
else:
break
town = A[town]
rt = A[town]
roop = 1
while rt != town:
rt = A[rt]
roop += 1
rt = 1
bf = 0
while rt != town:
rt = A[rt]
bf += 1
if bf<k:
K = (k-bf)%roop + bf
else:
K = k
town = 1
for _ in range(K):
town = A[town]
print(town) | 1 | 22,524,038,843,420 | null | 150 | 150 |
A, B, C = map(int, input().split())
if A+B+C > 21:
print('bust')
else:
print('win') | a_1, a_2, a_3 = map(int, input().split())
print('bust' if a_1+a_2+a_3 >= 22 else 'win') | 1 | 118,875,604,996,928 | null | 260 | 260 |
import sys
a=sys.stdin.buffer.read
K,N,*A=map(int,a().split())
A+=[A[0]+K]
print(K-max(y-x for x,y in zip(A,A[1:]))) | R,C,K = map(int, input().split())
a = [[0] * (C+1) for i in range(R+1)]
dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]
for i in range(K):
r,c,v = map(int, input().split())
r -= 1
c -= 1
a[r][c] = v
for i in range(R):
for j in range(C):
for k in range(2,-1,-1):
dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + a[i][j])
for k in range(4):
dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])
dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
ans = 0
for k in range(4):
ans = max(ans, dp[k][R-1][C-1])
print(ans)
| 0 | null | 24,510,309,093,832 | 186 | 94 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
from itertools import permutations
N = int(readline())
P = tuple(map(int, readline().split()))
Q = tuple(map(int, readline().split()))
d = {x: i for i, x in enumerate(permutations(range(1, N + 1)))}
print(abs(d[Q] - d[P]))
if __name__ == '__main__':
main()
| def gcd(u, v):
if (v == 0): return u
return gcd(v, u % v)
def lcm(u, v):
return (u * v) // gcd(u, v)
while 1:
try:
inp = input()
except EOFError:
break
else:
u, v = inp.split(' ')
u = int(u)
v = int(v)
print(gcd(u, v), lcm(u, v)) | 0 | null | 50,480,973,865,310 | 246 | 5 |
from copy import deepcopy
import numpy as np
H, W, K = map(int, input().split())
matrix = []
for i in range(H):
matrix.append(input())
matrix_int = np.ones((H, W), dtype=np.uint8)
# 1 == 黒、 0 == 白
for row in range(H):
for column in range(W):
if matrix[row][column] == ".":
matrix_int[row, column] = 0
count = 0
for row_options in range(2**H):
for col_options in range(2**W):
tmp_matrix_int = deepcopy(matrix_int)
tmp_row_options = row_options
tmp_col_options = col_options
for row in range(H):
mod = tmp_row_options % 2
if mod == 0:
tmp_matrix_int[row,:] = 0
tmp_row_options = tmp_row_options // 2
for col in range(W):
mod = tmp_col_options % 2
if mod == 0:
tmp_matrix_int[:,col] = 0
tmp_col_options = tmp_col_options // 2
# print(tmp_matrix_int.sum())
if tmp_matrix_int.sum() == K:
count += 1
print(count) | X = int(input())
a = X // 500 # 500円硬貨の枚数
X = X % 500 # 端数
b = X // 5 # 5円硬貨の枚数
print(a*1000+b*5) | 0 | null | 25,803,170,571,360 | 110 | 185 |
def resolve():
N, X, M = map(int, input().split(" "))
checked = [False] * M
val = X
ans = 0
val_list = []
base = M
for i in range(N):
if checked[val] != False:
loop_start_index = checked[val]
loop_vals = val_list[loop_start_index:]
loop_val = sum(loop_vals)
loop_length = len(val_list[loop_start_index:])
if loop_length != 0:
ans += ((N - i) // loop_length) * loop_val
for i in range(((N - i) % loop_length)):
ans += loop_vals[i]
break
ans += val
checked[val] = i
val_list.append(val)
val*=val
if val >= base:
val %= base
print(ans)
if __name__ == "__main__":
resolve() | def resolve():
N, X, M = map(int,input().split())
A_list = [X]
preA = X
A_set = set(A_list)
for i in range(N-1):
A = preA**2%M
if A == 0:
answer = sum(A_list)
break
elif A in A_set:
finished_count = len(A_list)
# 何番目か確認
same_A_index = A_list.index(A)
one_loop = A_list[same_A_index:]
loop_count, part_loop = divmod(N-finished_count, len(one_loop))
answer = sum(A_list) + sum(one_loop)*loop_count + sum(one_loop[:part_loop])
break
A_list.append(A)
A_set.add(A)
preA = A
else:
answer = sum(A_list)
print(answer)
resolve() | 1 | 2,792,305,465,800 | null | 75 | 75 |
import math
def get_int_list():
return list(map(int, input().split()))
n, x, t = get_int_list()
ans = math.ceil(n / x) * t
print(ans) | n, x, t = map(int, input().split())
ans = t *(n // x)
if n%x == 0:
print(ans)
else:
print(ans + t)
| 1 | 4,210,067,406,240 | null | 86 | 86 |
answer = input()
count = 0
list = []
for i in answer:
list.append(i)
if len(answer) != 6:
print("No")
elif list[2] == list[3] and list[4] == list[5]:
print("Yes")
else:
print("No")
|
def main():
s = input()
if s[2]==s[3] and s[4]==s[5]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | 1 | 41,962,379,291,858 | null | 184 | 184 |
string = list(input())
times = int(input())
#a = [int(i) for i in range(0,5)]
#print(a)
for i in range(times):
order = input().split()
#print(order)
if order[0] == "replace":
replace_string = order[3]
#print(string)
count = 0
for j in range(int(order[1]), int(order[2]) + 1):
string[j] = replace_string[count]
count += 1
#print(count)
#print(string)
elif order[0] == "reverse":
#print(string)
reverse_string = string[int(order[1]):int(order[2]) + 1]
reverse_string.reverse()
#for j in range(int(order[1]), int(order[2]) + 1):
# string[j] = reverse_string[j]
string = string[:int(order[1])] + reverse_string + string[int(order[2])+1:]
#print(j)
#print(string)
#string[int(order[1]):int(order[2]) + 1].reverse()
#print(string)
#string[int(order[1]):int(order[2])] = string[int(order[1]):int(order[2])].reverse()
elif order[0] == "print":
#print(string)
print("".join(string[int(order[1]):int(order[2]) + 1]))
#print(string) | import numpy;x=int(input());print(numpy.lcm(360,x)//x) | 0 | null | 7,641,858,601,890 | 68 | 125 |
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' | (W,H,x,y,r)=map(int,raw_input().split())
if r<=x and r<=y and x<=W-r and y<=H-r : print "Yes"
else : print "No" | 1 | 444,438,650,052 | null | 41 | 41 |
a=int(input())
b=0
c=list(map(int,input().split()))
for i in range(a):
for k in range(a):
b=b+c[i]*c[k]
for u in range(a):
b=b-c[u]*c[u]
print(int(b/2)) | import sys
# input = sys.stdin.readline
def main():
N = int(input())
d = list(map(int,input().split()))
ans = 0
for i in range(N):
for j in range(N):
if i !=j:
ans += d[i]*d[j]
print(int(ans/2))
if __name__ == "__main__":
main() | 1 | 168,257,155,825,990 | null | 292 | 292 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n = int(input())
d1_0, d2_0 = -1, -2
d1_1, d2_1 = -1, -2
d1_2, d2_2 = -1, -2
for i in range(n):
d1_2, d2_2 = d1_1, d2_1
d1_1, d2_1 = d1_0, d2_0
d1_0, d2_0 = map(int,input().split())
if d1_0 == d2_0 and d1_1 == d2_1 and d1_2 == d2_2:
print("Yes")
sys.exit()
print("No")
if __name__=='__main__':
main() | n,a,b = map(int,input().split())
p = 10**9 + 7
def CC(n,k):
X,Y = 1,1
for i in range(n-k+1,n+1):
X = X*i%p
for j in range(1,k+1):
Y = Y*j%p
YY = pow(Y,p-2,p)
return(X*YY%p)
A = CC(n,a)
B = CC(n,b)
ALL = pow(2,n,p)
ans = (ALL-1-A-B)%p
print(ans) | 0 | null | 34,321,487,306,758 | 72 | 214 |
n = int(input())
a = list(map(int,input().split()))
m = 1000
stocks = 0
drops = [False]*(n-1)
for i in range(n-1):
if a[i] > a[i+1]:
drops[i] = True
for i in range(n-1):
if drops[i]:
m+=stocks*a[i]
stocks = 0
else:
stocks+=m//a[i]
m -= (m//a[i])*a[i]
print(m + stocks*a[-1]) | def main():
N = input_int()
S = input()
count = 1
for i in range(1, N):
if S[i-1] != S[i]:
count += 1
print(count)
def input_int():
return int(input())
# def input_int_tuple():
# return map(int, input().split())
# def input_int_list():
# return list(map(int, input().split()))
main()
| 0 | null | 88,915,948,847,098 | 103 | 293 |
n,m,k = map(int,input().split())
mod = 998244353
ans = 0
fact = [1,1]
finv = [1,1]
for i in range(2, n+1):
fact += [fact[i-1] * i % mod]
finv += [pow(fact[i], mod-2, mod)]
def comb(n,k, mod):
return (fact[n] * finv[k] * finv[n-k]) % mod
for i in range(0, k+1):
ans += m * pow(m-1, n-i-1, mod) * comb(n-1, i, mod)
ans %= mod
print(ans) |
def main():
MOD = 998244353
n, m, k = map(int, input().split())
fact = [0] * 220000
invfact = [0] * 220000
fact[0] = 1
for i in range(1, 220000):
fact[i] = fact[i-1] * i % MOD
invfact[220000 - 1] = pow(fact[220000 - 1], MOD-2, MOD)
for i in range(220000-2, -1, -1):
invfact[i] = invfact[i+1] * (i+1) % MOD
def nCk(n, k):
if k < 0 or n < k: return 0
return fact[n] * invfact[k] * invfact[n - k] % MOD
ans = 0
for i in range(0, k+1):
ans += m * pow(m-1, n-i-1, MOD) * nCk(n-1, i) % MOD
print(ans%MOD)
if __name__ == '__main__':
main()
| 1 | 23,278,640,254,100 | null | 151 | 151 |
while True:
mid_score, term_score, re_score = map(int, input().split())
if mid_score == term_score == re_score == -1:
break
test_score = mid_score + term_score
score = ''
if test_score >= 80:
score = 'A'
elif test_score >= 65:
score = 'B'
elif test_score >= 50:
score = 'C'
elif test_score >=30:
if re_score >= 50:
score = 'C'
else:
score = 'D'
else:
score = 'F'
if mid_score == -1 or term_score == -1:
score = 'F'
print(score)
| M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
print(1 if M2 == M1 + 1 and D2 == 1 else 0) | 0 | null | 62,637,076,251,502 | 57 | 264 |
N,M=map(int ,input().split())
A=input().split()
s=0
for i in range(M):
s+=int(A[i])
ans=N-s
if ans>=0:
print(ans)
else:
print("-1") | N, M = map(int, input().split())
A_list = list(map(int, input().split()))
for i in range(M):
N -= A_list[i]
if N < 0:
print(-1)
break
if i == M-1:
print(N) | 1 | 31,947,426,154,732 | null | 168 | 168 |
n, a, b = map(int, input().split())
q = n // (a + b)
r = n % (a + b)
if r >= a:
res = a
else:
res = r
print(q * a + res) | def main():
n,a,b = list(map(int,input().split()))
ans=0
count=int(n/(a+b))
ans+=count*a
amari=n-count*(a+b)
if amari <= a:
ans+=amari
else:
ans+=a
print(ans)
main() | 1 | 55,697,092,786,934 | null | 202 | 202 |
n = int(input())
j_list = [input() for x in range(n)]
print("AC x",j_list.count("AC"))
print("WA x",j_list.count("WA"))
print("TLE x",j_list.count("TLE"))
print("RE x",j_list.count("RE")) | def gcm(a, b):
if a<b: a,b = b,a
if (a%b ==0):
return b
else:
return gcm(b, a%b)
def lcm(a, b):
return a/gcm(a,b)*b
while True:
try:
a, b = map(int, raw_input().split())
except:
break
print "%d %d" %(gcm(a,b), lcm(a,b)) | 0 | null | 4,385,461,701,060 | 109 | 5 |
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def merge(A, left, mid, right):
n1 = mid - left
n2 = right - mid
L, R = [0] * (n1 + 1), [0] * (n2 + 1)
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
L[n1] = float('INF')
R[n2] = float('INF')
i, j = 0, 0
compare_cnt = 0
for k in range(left, right):
compare_cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return compare_cnt
def merge_sort(A, left, right):
cnt = 0
if left + 1 < right:
mid = (left + right) // 2
cnt += merge_sort(A, left, mid)
cnt += merge_sort(A, mid, right)
cnt += merge(A, left, mid, right)
return cnt
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
cnt = merge_sort(A, 0, N)
print(*A)
print(cnt)
if __name__ == '__main__':
main()
|
cnt = 0
SENTINEL = 2000000000
def merge(arr, length, left, mid, right):
# n1 = mid - left
# n2 = right - mid
L = arr[left : mid]
R = arr[mid : right]
L.append(SENTINEL)
R.append(SENTINEL)
i, j = 0, 0
for k in range(left, right):
global cnt
cnt += 1
if (L[i] <= R[j]):
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
j += 1
def merge_sort(arr, length, left, right):
if (left + 1 < right):
mid = (left + right)//2
merge_sort(arr, length, left, mid)
merge_sort(arr, length, mid, right)
merge(arr, n, left, mid, right)
if __name__ == '__main__':
n = int(input())
S = list(map(int, input().split()))
merge_sort(S, n, 0, n)
print(' '.join(map(str, S)))
print(cnt)
| 1 | 115,352,009,518 | null | 26 | 26 |
n = int(input())
a = list(map(int, input().split()))
dp = [0]*(n+1)
dp[0] = 1000
for i in range(1, n):
dp[i] = dp[i-1]
for j in range(i):
stock = dp[j]//a[j]
cost = dp[j]+(a[i]-a[j])*stock
dp[i] = max(dp[i], cost)
print(dp[n-1])
| n = int(input())
k = list(map(int, input().split()))
m = 1000
s = 0
for i in range(n - 1):
if k[i + 1] > k[i]:
s = m // k[i]
m += s * (k[i + 1] - k[i])
print(m)
| 1 | 7,333,082,031,840 | null | 103 | 103 |
import math
import sys
def main():
n = int(sys.stdin.readline())
total = 0
for i in range(1,n+1):
for j in range(1,n+1):
for k in range(1,n+1):
total += math.gcd(i, math.gcd(j,k))
print(total)
main() | n,q = map(int,input().split())
A = [list(map(str,input().split())) for i in range(n)]
time = 0
flag = 1
while len(A) > 0:
if int(A[0][1]) <= q: #プロセスが完了する場合
time += int(A[0][1])
print(A[0][0],time)
del A[0]
else: #プロセスが完了しない場合
time += q
A[0][1] = str(int(A[0][1])-q)
A.append(A[0])
del A[0]
| 0 | null | 17,893,877,437,002 | 174 | 19 |
n, d = map(int, input().split())
A = []
for i in range(n):
A_i = list(map(int, input().split()))
A.append(A_i)
ans = 0
for j in A:
if (j[0] ** 2 + j[1] ** 2) <= d **2 :
ans += 1
print(ans)
| n,d = map(int,input().split())
l=[]
for _ in range(n):
x,y=map(int,input().split())
l.append(((x**2)+(y**2))**(0.5))
l.sort()
c=0
for i in l:
if i>d:
break
else:
c+=1
print(c) | 1 | 5,914,435,576,308 | null | 96 | 96 |
import math
a = [int(s) for s in input().split()]
b = int(max([a[0], a[1]]))
c = int(min([a[0], a[1]]))
d = 0.5 * (a[2] * 60 + a[3])
e = 6 * a[3]
f = abs(d - int(e))
if f >= 180:
f = 360 - f
if f != 0 and f!= 180:
print(math.sqrt(a[0] ** 2 + a[1] ** 2 - 2 * a[0] * a[1] * math.cos(math.radians(f))))
elif f == 0:
print(b-c)
else:
print(b+c) | import math
a,b,h,m=map(int,input().split())
lrad=6*m
srad=30*h+0.5*m
if abs(lrad-srad)<=180:
do=abs(lrad-srad)
else:
do=360-abs(lrad-srad)
rad=math.radians(do)
print(math.sqrt(a**2+b**2-2*a*b*math.cos(rad))) | 1 | 20,207,302,430,528 | null | 144 | 144 |
import math
a, b, h, m = map(int , input().split())
theta = abs( (h/12) + (m/60) * (1/12) - m/60)*2*math.pi
print(math.sqrt(b**2 * math.sin(theta)**2 + (b*math.cos(theta) -a) **2)) | import math
n = int(input())
ans = 0
for i in range(1, n):
ans += (math.ceil(n/i))-1
print (ans)
| 0 | null | 11,392,028,152,352 | 144 | 73 |
a, b = map(int, input().split())
for price in range(0,1010) :
if int(price*0.08) == a and int(price*0.10) == b :
print(price)
break
else :
print("-1")
| import math
A,B=map(int, input().split())
for i in range(1,1001):
if math.floor(i*0.08)==A and math.floor(i*0.1)==B:
print(i)
break
if i==1000:
print(-1) | 1 | 56,658,800,934,768 | null | 203 | 203 |
N, M, X = map(int, input().split())
C=[]
A=[]
for _ in range(N):
c, *a = map(int, input().split())
C.append(c)
A.append(a)
ans=10**5*N+1
for maskN in range(1<<N):
cost=0
level=[0]*M
for n in range(N):
if (maskN>>n&1):
cost+=C[n]
for m in range(M):
level[m] += A[n][m]
for l in level:
if l < X:
break
else:
ans=min(ans, cost)
print(f'{ans if ans!=10**5*N+1 else "-1"}')
| a, v = list(map(int, input().split()))
b, w = list(map(int, input().split()))
t = int(input())
x = abs(a-b)
y = (v - w) * t
if y >= x:
print('YES')
else:
print('NO')
| 0 | null | 18,787,356,455,118 | 149 | 131 |
a=[input() for i in range(2)]
a1=int(a[0])
a2=[int(i) for i in a[1].split()]
money=1000
kabu=0
for i in range(a1-1):
if a2[i]<a2[i+1]:
kabu=int(money/a2[i])
money+=kabu*(a2[i+1]-a2[i])
print(money) | n = int(input())
xpy = []
xmy = []
for i in range(n):
x,y = map(int,input().split())
xpy.append(x+y)
xmy.append(x-y)
xpy.sort()
xmy.sort()
print(max(abs(xpy[0]-xpy[-1]),abs(xmy[0]-xmy[-1]))) | 0 | null | 5,369,424,530,148 | 103 | 80 |
from decimal import *
from math import *
n,m=map(str,input().split())
p=Decimal(n)*Decimal(m)
print(floor(p))
| import math
n = int(input())
a = math.pi
print(2*n*a) | 0 | null | 24,096,026,190,782 | 135 | 167 |
from collections import defaultdict
def prime_factor(n):
d = defaultdict(int)
for i in range(2, n + 1):
if i * i > n:
break
while n % i == 0:
d[i] += 1
n //= i
if n != 1:
d[n] += 1
return d
N = int(input())
d = prime_factor(N)
ans = 0
for v in d.values():
i = 1
cur = 1
cnt = 0
while cur <= v:
cnt += 1
i += 1
cur += i
ans += cnt
print(ans)
| import math
def factorization(n):
arr=[]
temp=n
for i in range(2,int(math.sqrt(n))):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp//=i
arr.append([i,cnt])
if temp!=1:
arr.append([temp,1])
if arr==[]:
arr.append([n,1])
return arr
n=int(input())
if n==1:
print(0)
exit()
ans=0
for i in factorization(n):
if i[1]>=3:
cnt=1
while i[1]-cnt>cnt:
ans+=1
i[1]-=cnt
cnt+=1
if i[1]!=0:
ans+=1
else:
ans+=1
print(ans) | 1 | 16,889,926,403,352 | null | 136 | 136 |
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)
| import sys
input = sys.stdin.readline
from collections import deque
def bfs(s):
dist = [-1]*N
dist[s] = 0
q = deque([s])
while q:
v = q.popleft()
for nv in adj_list[v]:
if dist[nv]==-1:
dist[nv] = dist[v]+1
q.append(nv)
return dist
N, u, v = map(int, input().split())
adj_list = [[] for _ in range(N)]
for _ in range(N-1):
Ai, Bi = map(int, input().split())
adj_list[Ai-1].append(Bi-1)
adj_list[Bi-1].append(Ai-1)
d1 = bfs(u-1)
d2 = bfs(v-1)
ans = 0
for i in range(N):
if d1[i]<d2[i]:
ans = max(ans, d2[i]-1)
print(ans) | 1 | 117,197,661,259,670 | null | 259 | 259 |
import math
import sys
if __name__ == '__main__':
for line in sys.stdin:
a,b = map(int,line.split())
print(math.gcd(a,b),(a*b) // math.gcd(a,b))
| import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
N, M, Q = MI()
D = [[] for _ in range(Q)]
for i in range(Q):
a, b, c, d = MI()
a -= 1
b -= 1
D[i] = [a, b, c, d]
ans = 0
for K in comb_w(range(1, M+1), N):
score = 0
for q in range(Q):
a, b, c, d = D[q]
if K[b] - K[a] == c:
score = score + d
ans = max(ans, score)
print(ans)
if __name__ == '__main__':
solve()
| 0 | null | 13,902,124,082,980 | 5 | 160 |
import math
x1,y1,x2,y2=map(float,input().split())
n=(x1-x2)**2+(y1-y2)**2
n1=math.sqrt(n)
print(n1)
| n = int(input())
base = [mark + str(rank) for mark in ["S ", "H ", "C ", "D "] for rank in range(1,14)]
for card in [input() for i in range(n)]:
base.remove(card)
for elem in base:
print(elem) | 0 | null | 616,343,021,352 | 29 | 54 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
s=input()
ans=n
for i in range(1,n):
if s[i]==s[i-1]:
ans-=1
print(ans) | n = int(input())
alpha = "abcdefghij"
lst = []
def f(s,k):
if len(s) == n:
print(s)
return
for i in range(k+1):
if i == k: f(s+alpha[i],k+1)
else: f(s+alpha[i],k)
f("",0) | 0 | null | 111,456,495,297,532 | 293 | 198 |
val = map(int, raw_input().split())
ans1 = val[0] / val[1]
ans2 = val[0] % val[1]
ans3 = format(val[0] / float(val[1]), '.5f')
print("{} {} {}".format(ans1, ans2, ans3)) | L = raw_input().split()
a = int(L[0])
b = int(L[1])
d = int(0)
r = int(0)
f = float(0)
d = a / b
r = a % b
f = float(a) / float(b)
print "{0} {1} {2:f}".format(d,r,f) | 1 | 605,727,382,062 | null | 45 | 45 |
# 配列の宣言
A = []
B = []
# 文字列の取得と加工
LENGTH =int(input())
A = input().split()
B = A.copy()
def bubble (A, LENGTH):
N = 0
M = LENGTH - 1
CHANGE = 0
while N <= LENGTH -1:
M = LENGTH - 1
while M >= N + 1:
if int(A[M][1:]) < int(A[M-1][1:]):
tmp = A[M-1]
A[M-1] = A[M]
A[M] = tmp
CHANGE += 1
M -= 1
N += 1
print(" ".join(map(str,A)))
print("Stable")
def selection (B, LENGTH):
i = 0
CHANGE_COUNT = 0
while i <= LENGTH -1:
j = i + 1
mini = i
while j <= LENGTH -1:
if int(B[j][1:]) < int(B[mini][1:]):
mini = j
j += 1
if mini != i:
tmp = B[i]
B[i] = B[mini]
B[mini] = tmp
CHANGE_COUNT += 1
i += 1
print(" ".join(map(str,B)))
if A == B:
print("Stable")
else:
print("Not stable")
bubble (A, LENGTH)
selection (B, LENGTH)
| x1, x2, y1, y2 = map(float, input().split())
ans = ((x1 - y1)**2 + (x2 - y2)**2)**0.5
print("{:.5f}".format(ans)) | 0 | null | 88,790,359,712 | 16 | 29 |
a=[int(input()) for i in range(10)]
a.sort()
a.reverse()
print(a[0])
print(a[1])
print(a[2]) | a=[]
for i in range(10):
a.append(int(input()))
a=sorted(a)[::-1]
for i in range(3):
print(a[i]) | 1 | 19,543,172 | null | 2 | 2 |
def main():
s, t = input().split(' ')
print(t, end='')
print(s)
if __name__ == '__main__':
main()
| result = []
while True:
(m, f, r) = [int(i) for i in input().split()]
sum = m + f
if m == f == r == -1:
break
if m == -1 or f == -1:
result.append('F')
elif sum >= 80:
result.append('A')
elif sum >= 65:
result.append('B')
elif sum >= 50:
result.append('C')
elif sum >= 30:
if r >= 50:
result.append('C')
else:
result.append('D')
else:
result.append('F')
[print(result[i]) for i in range(len(result))] | 0 | null | 52,209,488,288,520 | 248 | 57 |
a = input().split()
n, d = int(a[0]), int(a[1])
x = []
a = d * d
res = 0
for i in range(n):
[x, y] = input().split()
if int(x)**2 + int(y)**2 <= a:
res += 1
print(res)
| n,d= map(int, input().split())
xy = [list(map(int,input().split())) for _ in range(n)]
c= 0
for x,y in xy:
if x**2+y**2 <= d**2:
c += 1
print(c) | 1 | 5,859,470,394,050 | null | 96 | 96 |
while True :
m, f, r = map(int, input().split())
if(m == -1 and f == -1 and r == -1) :
break
elif(m == -1 or f == -1) :
print("F")
elif(m + f >= 80) :
print("A")
elif(65 <= m + f and m + f < 80) :
print("B")
elif(50 <= m + f and m + f < 65) :
print("C")
elif(30 <= m + f and m + f < 50) :
if(50 <= r) :
print("C")
else :
print("D")
else :
print("F")
| while True:
M,F,R = map(int,input().split())
if M == -1 and F == -1 and R == -1:
break
if M == -1 or F == -1:
print("F")
elif M+F >= 80:
print("A")
elif M+F >= 65:
print("B")
elif M+F >= 50:
print("C")
elif M+F >= 30:
if R >= 50:
print("C")
else:
print("D")
else:
print("F")
| 1 | 1,205,847,464,448 | null | 57 | 57 |
x = raw_input()
a, b, c = x.split()
a = int(a)
b = int(b)
c = int(c)
kai = 0
d = b + 1
for i in range(a, d):
if c % i == 0:
kai += 1
print kai | N=input()
ans=0
for i in range(1,int(N)+1):
if i%15==0:
pass
elif i%5==0:
pass
elif i%3==0:
pass
else:
ans=ans+i
print(ans) | 0 | null | 17,872,263,175,798 | 44 | 173 |
N, M = map(int, input().split())
if N <= 1: a = 0
else: a = N*(N-1) // 2
if M <= 1: b = 0
else: b = M*(M-1) // 2
print(a+b) | H,A = map(int,input().split())
b = H // A
c = H % A
if c != 0:
b += 1
print(b) | 0 | null | 61,173,869,004,070 | 189 | 225 |
class Dice:
def __init__(self, labels):
self._top = labels[0]
self._front = labels[1]
self._right = labels[2]
self._left = labels[3]
self._back = labels[4]
self._bottom = labels[5]
def top(self):
return self._top
def front(self):
return self._front
def right(self):
return self._right
def left(self):
return self._left
def back(self):
return self._back
def bottom(self):
return self._bottom
def role(self, directions):
for d in directions:
self._role1(d)
def _role1(self, d):
if d == "N":
self._top, self._front, self._bottom, self._back = \
self._front, self._bottom, self._back, self._top
elif d == "E":
self._top, self._left, self._bottom, self._right = \
self._left, self._bottom, self._right, self._top
elif d == "S":
self._top, self._back, self._bottom, self._front = \
self._back, self._bottom, self._front, self._top
else:
self._top, self._right, self._bottom, self._left = \
self._right, self._bottom, self._left, self._top
xs = list(map(int, input().split()))
directions = input()
dice = Dice(xs)
dice.role(directions)
print(dice.top())
| import math
x1,y1,x2,y2 = map(float,raw_input().split(' '))
x = abs(x1-x2);
y = abs(y1-y2);
a = math.sqrt(x**2 + y**2)
print a | 0 | null | 203,514,862,860 | 33 | 29 |
import sys
def main():
H, W, K = map(int, sys.stdin.readline().split())
s = ['.' * (W+1)] + ['.' + sys.stdin.readline().rstrip() for _ in range(H)]
res = [[None for _ in range(W + 2)]] + [[None] + [0 for _ in range(W)] + [None] for _ in range(H)] + [[None for _ in range(W + 2)]]
number = 1
for i in range(1, H+1):
if not '#' in s[i]:
continue
else:
j = 1
while j <= W:
res[i][j] = number
if s[i][j] == '#':
res[i][j] = number
if '#' in s[i][j+1:]:
number += 1
j += 1
number += 1
for i in range(1, H+1):
if res[i][1] == 1:
count = i
break
for i in range(1, count):
res[i] = res[count]
for i in range(1, H):
if res[i+1][1] == 0:
res[i+1] = res[i]
for i in range(1, H+1):
print(' '.join(map(str, res[i][1:W+1])))
if __name__ == '__main__':
main() | x = int(input())
a = x // 100
b = x - a * 100
while b > 5:
b = b - 5
a -= 1
if a>=1:
print(1)
else:
print(0) | 0 | null | 135,588,371,760,700 | 277 | 266 |
h,k = map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
print(sum(arr[0:h-k]) if h>=k else 0) | # -*- coding: utf-8 -*-
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = sorted(H, reverse=True)
total = 0
for i in range(K, N):
total += H[i]
print(total) | 1 | 79,098,017,469,508 | null | 227 | 227 |
dataList = [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]
input_k = input('')
k_index = int(input_k)
print(dataList[k_index - 1])
| import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def main():
F = [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 = II()
print(F[K-1])
if __name__ == '__main__':
main() | 1 | 50,101,792,020,280 | null | 195 | 195 |
n = input()
taro = 0
hanako = 0
for i in xrange(n):
t_card, h_card = raw_input().split(" ")
if t_card < h_card:
hanako += 3
elif t_card > h_card:
taro += 3
elif t_card == h_card:
taro += 1
hanako += 1
print taro, hanako | s = int(input())
MOD = 10**9 + 7
b3 = 1; b2 = 0; now = 0 # now == b1
for _ in range(s-2):
b1 = now
now = (b1 + b3) % MOD
b3, b2 = b2, b1
print(now)
| 0 | null | 2,640,068,192,960 | 67 | 79 |
a, b, c, d = input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
def m():
if -1000000000<=a<=b<=1000000000 and -1000000000<=c<=d<=1000000000:
if a>=0 and d<=0:
max=a*d
print(max)
elif a>=0 and c>=0:
max=b*d
print(max)
elif b<=0 and c>=0:
max=b*c
print(max)
elif b<=0 and d<=0:
max=a*c
print(max)
elif a<=0 and b>=0 and c<=0 and d>=0:
if a*c>=b*d:
max=a*c
print(max)
else:
max=b*d
print(max)
elif a>=0 and c<=0 and d>=0:
max=b*d
print(max)
elif b<=0 and c<=0 and d>=0:
max=a*c
print(max)
elif a<=0 and b>=0 and c>=0:
max=b*d
print(max)
elif a<=0 and b>=0 and d<=0:
max=a*c
print(max)
m() | H1, M1, H2, M2, K = [int(i) for i in input().split()]
print((H2 * 60 + M2) - (H1 * 60 + M1) - K) | 0 | null | 10,639,146,877,290 | 77 | 139 |
s, t = input("").split(" ")
res = t + s
print(res) | s, t = input().split()
print(f"{t}{s}") | 1 | 103,070,078,374,650 | null | 248 | 248 |
t, h = 0, 0
for i in range(int(input())):
tc, hc= input().split()
if tc > hc:
t += 3
elif tc < hc:
h += 3
else:
t += 1
h += 1
print('%d %d' % (t, h)) | N = int(input())
c = list(input())
ans = 0
left = 0
right = N-1
while left < right:
if c[left] != c[right]:
if c[left] == 'W' and c[right] == 'R':
ans += 1
left += 1
right -=1
if c[left] == 'R' and c[right] == 'R':
left += 1
if c[left] == 'W' and c[right] == 'W':
right -=1
print(ans) | 0 | null | 4,160,267,154,300 | 67 | 98 |
N, K = map(int, input().split())
data = list(map(int, input().split()))
for x in range(K):
# print(data)
raise_data = [0] * (N + 1)
for i, d in enumerate(data):
raise_data[max(0, i - d)] += 1
raise_data[min(N, i + d + 1)] -= 1
height = 0
ended = 0
for i in range(N):
height += raise_data[i]
data[i] = height
if height == N:
ended += 1
if ended == N:
# print(x)
break
print(*data)
| def count_num_light(a):
ret = [0 for _ in range(len(a))]
n = len(a)
for i in range(n):
start = max(0, i-a[i])
end = min(n-1, i+a[i])
ret[start] += 1
if end+1 < n:
ret[end+1] -= 1
for i in range(1,n):
ret[i] += ret[i-1]
return ret
n, k = map(int, input().split())
a = list(map(int, input().split()))
num_light = count_num_light(a)
for i in range(k-1):
num_light = count_num_light(num_light)
if sum(num_light) == n**2:
break
print(*num_light)
| 1 | 15,454,357,986,720 | null | 132 | 132 |
x,y=map(int,raw_input().split())
print "%d %d %f" % (x/y,x%y,float(x)/y) | a,b = list(map(int, input().split()))
d = int(a / b)
r = a % b
f = a / b
print(str(d) + " "+ str(r) + " "+ "{0:.20f}".format(f)) | 1 | 609,241,210,174 | null | 45 | 45 |
h,n = map(int, input().split())
a = [int(i) for i in input().split()]
print("No" if sum(a)<h else "Yes") | #!/usr/bin/env python3
import sys
from itertools import chain
YES = "Yes" # type: str
NO = "No" # type: str
def solve(H: int, N: int, A: "List[int]"):
if H <= sum(A):
return YES
else:
return NO
def main():
tokens = chain(*(line.split() for line in sys.stdin))
H = int(next(tokens)) # type: int
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(H, N, A)
print(answer)
if __name__ == "__main__":
main()
| 1 | 77,692,642,287,230 | null | 226 | 226 |
#!/usr/bin/env python3
import sys
def solve(H: int, W: int, s: "List[str]"):
dp = [[0 for w in range(W)] for h in range(H)] # dp[h][w]はh,wに達するための回数
if s[0][0] == '#':
dp[0][0] = 1
for w in range(W-1): # 0行目について
if s[0][w+1] == '.': # 移動先が白だったら特に変わりなし
dp[0][w+1] = dp[0][w]
elif s[0][w] == '.' and s[0][w+1] == '#': # 移動元が白で先が黒ならば、新しく施行1回追加
dp[0][w+1] = dp[0][w] + 1
elif s[0][w] == '#' and s[0][w+1] == '#': # 移動元も先も黒だったとしたら、試行回数は変わらない
dp[0][w+1] = dp[0][w]
for h in range(H-1): # 1列目について
if s[h+1][0] == '.':
dp[h+1][0] = dp[h][0]
elif s[h][0] == '.' and s[h+1][0] == '#':
dp[h+1][0] = dp[h][0] + 1
elif s[h][0] == '#' and s[h+1][0] == '#':
dp[h+1][0] = dp[h][0]
for h in range(1, H):
for w in range(W-1):
if s[h][w+1] == '.':
dp[h][w+1] = min(dp[h][w], dp[h-1][w+1])
elif s[h][w] == '.' and s[h][w+1] == '#':
if s[h-1][w+1] == '.':
dp[h][w+1] = min(dp[h][w]+1, dp[h-1][w+1]+1)
elif s[h-1][w+1] == '#':
dp[h][w+1] = min(dp[h][w]+1, dp[h-1][w+1])
elif s[h][w] == '#' and s[h][w+1] == '#':
if s[h-1][w+1] == '.':
dp[h][w+1] = min(dp[h][w], dp[h-1][w+1]+1)
elif s[h-1][w+1] == '#':
dp[h][w+1] = min(dp[h][w], dp[h-1][w+1])
print(dp[H-1][W-1])
return
# 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()
H = int(next(tokens)) # type: int
W = int(next(tokens)) # type: int
s = [next(tokens) for _ in range(H)] # type: "List[str]"
solve(H, W, s)
if __name__ == '__main__':
main()
| import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
H, W = map(int, readline().split())
masu = []
for _ in range(H):
masu.append(readline().rstrip().decode('utf-8'))
# print(masu)
dp = [[INF]*W for _ in range(H)]
dp[0][0] = int(masu[0][0] == "#")
dd = [(1, 0), (0, 1)]
# 配るDP
for i in range(H):
for j in range(W):
for dx, dy in dd:
ni = i + dy
nj = j + dx
# はみ出す場合
if (ni >= H or nj >= W):
continue
add = 0
if masu[ni][nj] == "#" and masu[i][j] == ".":
add = 1
dp[ni][nj] = min(dp[ni][nj], dp[i][j] + add)
# print(dp)
ans = dp[H-1][W-1]
print(ans) | 1 | 49,543,970,866,038 | null | 194 | 194 |
n, k = map(int, input().split())
A = list(map(int, input().split()))
l = 1
r = 10**9+1
while l < r:
mid = (l+r)//2
count = 0
for i in range(n):
if A[i] > mid:
count += A[i]//mid
if count <= k:
r = mid
else:
l = mid+1
print(l) | n, k = map(int, input().split())
a = list(map(int, input().split()))
inf = 1
sup = max(a)
while inf < sup:
x = (inf + sup) // 2
cut = 0
for a_i in a:
cut += (a_i - 1) // x
if cut <= k:
sup = x
else:
inf = x + 1
print(sup) | 1 | 6,572,080,508,228 | null | 99 | 99 |
import itertools
N, M, Q = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for i in range(Q):
ai, bi, ci, di = list(map(int, input().split()))
a.append(ai)
b.append(bi)
c.append(ci)
d.append(di)
ans = 0
for A in list(itertools.combinations_with_replacement(range(1, M+1), N)):
# print(A)
score = 0
for i in range(Q):
if A[b[i]-1] - A[a[i]-1] == c[i]:
score += d[i]
if ans < score:
ans = score
# print(A, score)
print(ans)
| from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
abcds = [tuple(map(int, input().split()))for _ in range(Q)]
def cal_score(A):
score = 0
for a, b, c, d in abcds:
if A[b-1] - A[a-1] == c:
score += d
return score
ans = 0
for A in combinations_with_replacement([i for i in range(M)], N):
ans = max(ans, cal_score(A))
print(ans)
| 1 | 27,436,093,622,718 | null | 160 | 160 |
import math
a=float(input())
print("{0:.9f} {1:.9f}".format(a*a*math.pi,a*2*math.pi))
| import math
r=input()
print "%.9f"%(math.pi*r*r), math.pi*r*2 | 1 | 643,683,279,778 | null | 46 | 46 |
from itertools import permutations
N=int(input())
ans = ['']*N
al = 'abcdefghij'
d = {al[i]:i for i in range(N)}
def dfs(h=[]):
if len(h)==N:
print(''.join(h))
return
for i in range(max([d[h[-1-i]] for i in range(len(h))])+2):
h.append(al[i])
dfs(h)
h.pop()
return
dfs(['a']) | import sys
def input(): return sys.stdin.readline().rstrip()
def dfs(s,mxs):
if len(s)==n:
print(s)
else:
for i in range(ord('a'),ord(mxs)+1):
dfs(s+chr(i),chr(i+1) if i ==ord(mxs) else mxs)
def main():
global n
n=int(input())
dfs('','a')
if __name__=='__main__':
main() | 1 | 52,280,067,248,288 | null | 198 | 198 |
string = input()
if string == "ABC":
print("ARC")
else:
print("ABC") | import itertools
n = int(input())
tastes = list(map(int, input().split()))
ans_lists = []
for v in itertools.combinations(tastes, 2):
cure = v[0]*v[1]
ans_lists.append(cure)
ans = 0
for i in ans_lists:
ans += i
print(ans) | 0 | null | 96,231,451,889,280 | 153 | 292 |
n,k = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
g = [[0]*(n) for _ in range(n)]
A = [n]*n
# for i in range(n):
# tmp = 0
# idx = i
# cnt = 0
# set_ =set()
# while cnt<n:
# if C[idx] not in set_:
# tmp += C[idx]
# set_.add(C[idx])
# g[i][cnt] = tmp
# idx = P[idx]-1
# cnt += 1
# else:
# p = len(set_)
# A[i] = p
# break
ans = -float('inf')
for i in range(n):
S = []
idx = P[i]-1
S.append(C[idx])
while idx != i:
idx = P[idx]-1
S.append(S[-1] +C[idx])
v,w = k//len(S),k%len(S)
if k<=len(S):
val = max(S[:k])
elif S[-1]<=0:
val = max(S)
else:
val1 = S[-1] *(v-1)
val1 += max(S)
val2 = S[-1]*v
if w!=0:
val2 += max(0,max(S[:w]))
val = max(val1,val2)
ans = max(ans,val)
# for i in range(n):
# v,w = k//A[i],k%A[i]
# if A[i]<k:
# if g[i][A[i]-1]<=0:
# val = max(g[i][:A[i]])
# else:
# val1 = (v-1)*g[i][A[i]-1]
# val1 += max(g[i][:A[i]])
# val2 = v*g[i][A[i]-1]
# if w!=0:
# val2 += max(0,max(g[i][:w]))
# val = max(val1,val2)
# else:
# val = max(g[i][:k])
# ans = max(ans,val)
print(ans) | import sys
def main():
input = sys.stdin.readline
n, k = map(int , input().split())
p_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
res = -float('inf')
for s in range(n):
S = []
i = p_list[s] - 1
S.append(c_list[i])
while i != s:
i = p_list[i]-1
S.append(S[-1] + c_list[i])
if k <= len(S):
score = max(S[:k])
elif S[-1] <= 0:
score = max(S)
else:
score1 = S[-1] * (k//len(S) - 1)
score1 += max(S)
score2 = S[-1] * (k//len(S))
r = k%len(S)
if r!=0:
score2 += max(0, max(S[:r]))
score = max(score1, score2)
res = max(res, score)
print(res)
if (__name__=='__main__'):
main() | 1 | 5,361,985,621,352 | null | 93 | 93 |
from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))
a_count = Counter(a_input)
score_dic={}
exclude_dic={}
for k,v in a_count.items():
score_dic[k]=v*(v-1)//2
exclude_dic[k]=(v-1)*(v-2)//2
score_sum = sum(score_dic.values())
for i in range(n):
print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])
| # -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 16:48:51 2020
@author: Aruto Hosaka
"""
import math
import collections
K = int(input())
ans = 0
g = []
for a in range(K):
for b in range(K):
g.append(math.gcd(a+1, b+1))
G = collections.Counter(g)
for k in range(K):
for c in range(K):
ans += math.gcd(k+1, c+1)*G[k+1]
print(ans) | 0 | null | 41,364,047,001,952 | 192 | 174 |
while True:
l = input().split()
h = int(l[0])
w = int(l[1])
if h == 0 and w ==0:
break
flag = 0
for i in range(h*(w+1)):
if (i+1) % (w+1) == 0:
print("")
if w % 2 == 0:
flag += 1
if i == h*(w+1)-1:
print("")
else:
if flag % 2 == 0:
print("#", end="")
flag += 1
else:
print(".", end="")
flag += 1 | # -*- coding: utf-8 -*-
N, X, M = map(int, input().split())
mod_check_list = [False for _ in range(M)]
mod_list = [(X ** 2) % M]
counter = 1
mod_sum = (X ** 2) % M
last_mod = 0
for i in range(M):
now_mod = (mod_list[-1] ** 2) % M
if mod_check_list[now_mod]:
last_mod = now_mod
break
mod_check_list[now_mod] = True
mod_list.append(now_mod)
counter += 1
mod_sum += now_mod
loop_start_idx = 0
for i in range(counter):
if last_mod == mod_list[i]:
loop_start_idx = i
break
loop_list = mod_list[loop_start_idx:]
loop_num = counter - loop_start_idx
ans = 0
if mod_list[-1] == 0:
ans = X + sum(mod_list[:min(counter, N - 1)])
else:
if (N - 1) <= counter:
ans = X + sum(mod_list[:N - 1])
else:
ans += X + mod_sum
N -= (counter + 1)
ans += sum(loop_list) * (N // loop_num) + sum(loop_list[:N % loop_num])
print(ans) | 0 | null | 1,857,011,055,472 | 51 | 75 |
from collections import deque
H,W = map(int,input().split())
field = [list(input()) for _ in range(H)]
dist = [[-1]*W for _ in range(H)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
mx = 0
for h in range(H):
for w in range(W):
if field[h][w] == "#":
continue
dist = [[-1]*W for _ in range(H)]
dist[h][w] = 0
que = deque([])
que.append([h,w])
while que != deque([]):
u,v = que.popleft()
for dir in range(4):
nu = u + dx[dir]
nv = v + dy[dir]
if (nu < 0) or (nu >= H) or (nv < 0) or (nv >= W):
continue
if field[nu][nv] == "#":
continue
if dist[nu][nv] != -1:
continue
que.append([nu,nv])
dist[nu][nv] = dist[u][v] + 1
for i in range(H):
for j in range(W):
if mx < dist[i][j]:
mx = dist[i][j]
print(mx) | from copy import deepcopy
from collections import Counter, defaultdict, deque
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
def maze_solve(S_1,S_2,maze_list):
d = deque()
dist[S_1][S_2] = 0
d.append([S_1,S_2])
dx = [0,0,1,-1]
dy = [1,-1,0,0]
while d:
v = d.popleft()
x = v[0]
y = v[1]
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx < 0 or nx >= h or ny < 0 or ny >= w:
continue
if dist[nx][ny] == -1:
dist[nx][ny] = dist[x][y] + 1
d.append([nx,ny])
return max(list(map(lambda x: max(x), dist)))
h,w = MI()
ans = 0
maze = [list(input()) for _ in range(h)]
dist = [[-1]*w for _ in range(h)]
start_list = []
for i in range(h):
for j in range(w):
if maze[i][j] == "#":
dist[i][j] = 0
else:
start_list.append([i,j])
dist_copy = deepcopy(dist)
for k in start_list:
dist = deepcopy(dist_copy)
ans = max(ans,maze_solve(k[0],k[1],maze))
print(ans) | 1 | 94,817,087,468,180 | null | 241 | 241 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.