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
|
---|---|---|---|---|---|---|
from itertools import permutations
from bisect import bisect_left
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
perm = list(permutations(p))
perm.sort()
a = bisect_left(perm, p)
b = bisect_left(perm, q)
print(abs(a- b))
| import numpy as np
from numpy.fft import rfft, irfft
N, M = map(int, input().split())
*A, = map(int, input().split())
B = np.zeros(5*10**5)
for a in A:
B[a] += 1
L = 5*10**5
FB = rfft(B, L)
C = np.rint(irfft(FB*FB)).astype(int)
ans = 0
for i in range(2*10**5, -1, -1):
c = C[i]
if not c:
continue
if M - c > 0:
ans += i*c
M -= c
else:
ans += i*M
break
print(ans)
| 0 | null | 104,523,182,417,560 | 246 | 252 |
while True:
Input = raw_input().split()
a = int(Input[0])
op = Input[1]
b = int(Input[2])
if op == "+":
ans = a + b
print ans
elif op == "-":
ans = a - b
print ans
elif op == "/":
ans = a / b
print ans
elif op == "*":
ans = a * b
print ans
elif op == "?":
break | while True:
try:
print(int(eval(input())))
except:
break
| 1 | 682,827,102,648 | null | 47 | 47 |
a = input()
if a == "RSR":
print(1)
else :
print(a.count("R"))
| import math
A, B, H, M = map(int, input().split())
deg_H = 360*(H+M/60)/12
deg_M = 360*M/60
theta = math.radians(abs(deg_H - deg_M))
ans = B**2 + A**2 - 2*A*B*math.cos(theta)
print(ans**0.5)
| 0 | null | 12,515,601,917,628 | 90 | 144 |
taro,hanako = 0,0
w=[]
n = int(raw_input())
for i in xrange(n):
w.append(map(str, raw_input().split()))
for j in xrange(n):
if w[j][0]>w[j][1]:
taro+=3
elif w[j][0]<w[j][1]:
hanako+=3
else:
taro+=1
hanako+=1
#print n
#print w
print taro,hanako | t=0
h=0
for i in range(int(input())):
A,B=list(input().split())
if A>B:
t+=3
if A<B:
h+=3
if A==B:
t+=1
h+=1
print(t,h)
| 1 | 2,008,270,309,780 | null | 67 | 67 |
# -*- coding: utf-8 -*-
import sys
import math
from decimal import Decimal, ROUND_HALF_UP
def main():
N,K = list(map(int, sys.stdin.readline().split()))
A_list = list(map(int, sys.stdin.readline().split()))
def check(length :int) -> bool:
cnt = 0
for a in A_list:
if a >= length:
divide = math.ceil(a / length)
cnt += (divide - 1)
return (True if cnt <= K else False)
L = 0.1 # the minimum length
R = max(A_list) # the maximum length
while (R - L) > 0.01:
M = L + (R - L) / 2
if check(M):
R = M
else:
L = M
ans = Decimal(str(M)).quantize(Decimal('1E-1'), rounding=ROUND_HALF_UP)
ans = math.ceil(ans)
print(ans)
if __name__ == "__main__":
main()
| while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
for c in range(b + 1, n + 1):
if sum([a,b,c]) == x:
count += 1
print(count) | 0 | null | 3,913,124,346,638 | 99 | 58 |
n=int(input())
L=list(map(int,input().split()))
a=0
for i in range(n-2):
for j in range(i+1,n-1):
if L[i]!=L[j]:
for k in range(j+1,n):
if L[i]!=L[k] and L[j]!=L[k] and L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[j]+L[i]:
a+=1
print(a) | w, h = map(int, input().split())
print(w * h, w * 2 + h * 2) | 0 | null | 2,632,775,118,560 | 91 | 36 |
a,b,c,d,e = map(int,input().split())
z = (c-a)*60 + (d-b)- e
print(z) | h_1, m_1, h_2, m_2, k = map(int, input().split())
minute_1 = h_1*60 + m_1
minute_2 = h_2*60 + m_2
ans = minute_2 - k - minute_1
print(ans) | 1 | 17,979,704,313,738 | null | 139 | 139 |
import math
dig_six = math.radians(60)
def koch(d, p1, p2):
if d == 0:
return d
#calc s, u, t from p1, p2
s_x = (2*p1[0]+1 * p2[0]) / 3
s_y = (2*p1[1]+1 * p2[1]) / 3
s = (s_x, s_y)
t_x = (1*p1[0]+2 * p2[0]) / 3
t_y = (1*p1[1]+2 * p2[1]) / 3
t = (t_x, t_y)
u_x = (t_x - s_x)*math.cos(dig_six) - (t_y - s_y)*math.sin(dig_six) + s_x
u_y = (t_x - s_x)*math.sin(dig_six) + (t_y - s_y)*math.cos(dig_six) + s_y
u = (u_x, u_y)
koch(d-1, p1, s)
print (' '.join([str(x) for x in s]))
koch(d-1, s, u)
print (' '.join([str(x) for x in u]))
koch(d-1, u, t)
print (' '.join([str(x) for x in t]))
koch(d-1, t, p2)
if __name__ == '__main__':
iterate = int(input())
p1 = (0.0, 0.0)
p2 = (100.0, 0.0)
print (' '.join([str(x) for x in p1]))
koch(iterate, p1, p2)
print (' '.join([str(x) for x in p2]))
| # コッホ曲線 Koch curve
import math
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return str(self.x) + " " + str(self.y)
def Koch(p1, p2, n):
if n == 0:
print(p1)
else:
s = Point(p1.x * 2 / 3 + p2.x * 1 / 3, p1.y * 2 / 3 + p2.y * 1 / 3)
u = Point(p1.x / 2 + p2.x / 2 + p1.y * r3 / 6 - p2.y * r3 / 6, p1.y / 2 + p2.y / 2 + p2.x * r3 / 6 - p1.x * r3 / 6)
t = Point(p1.x * 1 / 3 + p2.x * 2 / 3, p1.y * 1 / 3 + p2.y * 2 / 3)
Koch(p1, s, n - 1)
Koch(s, u, n - 1)
Koch(u, t, n - 1)
Koch(t, p2, n - 1)
r3 = math.sqrt(3)
start = Point(0, 0)
goal = Point(100, 0)
n = int(input())
Koch(start, goal, n)
print(goal)
| 1 | 121,352,296,492 | null | 27 | 27 |
a, b = map(int, input().split())
i = 1
while True:
x = a * i
if x % b == 0:
print(x)
exit()
i += 1
| def gcd(a,b):
while a!=0 and b!=0:
if a>b:
c = a
a = b
b = c
b %= a
return max(a,b)
a,b = map(int,input().split())
print(a*b//gcd(a,b)) | 1 | 113,604,905,644,860 | null | 256 | 256 |
w = input().lower()
cnt = 0
while True:
l = input()
if l == 'END_OF_TEXT':
break
for e in l.split():
cnt += e.lower() == w
print(cnt)
| import itertools, bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
for j in range(i+1, N):
cindex = bisect.bisect_left(L, int(L[i]) + int(L[j]))
ans += cindex-1 - j
print(ans)
| 0 | null | 87,135,451,640,480 | 65 | 294 |
while True:
h,w = map(int,input().split())
if h == 0 and w == 0:
break
for i in range(h):
if i%2 == 1:
sym1 = "#"
sym2 = "."
else:
sym1 = "."
sym2 = "#"
for j in range(w):
if j%2 == 1:
print(sym1,end="")
else:
print(sym2,end="")
print("")
print("") | def main():
from math import gcd
def lcm(a, b):
return a // gcd(a, b) * b
x = int(input())
print(lcm(x, 360) // x)
if __name__ == '__main__':
main()
| 0 | null | 6,998,972,021,408 | 51 | 125 |
n = int(input())
s = list(input().split())
q = int(input())
t = list(input().split())
ans = 0
for num in t:
if num in s:
ans += 1
print(ans)
| n = int(input())
num_AC = 0
num_WA = 0
num_TLE = 0
num_RE = 0
for i in range(n):
i = input()
if i == "AC":
num_AC += 1
elif i == "WA":
num_WA += 1
elif i == "TLE":
num_TLE += 1
elif i == "RE":
num_RE += 1
print("AC x " + str(num_AC))
print("WA x " + str(num_WA))
print("TLE x " + str(num_TLE))
print("RE x " + str(num_RE)) | 0 | null | 4,404,031,542,850 | 22 | 109 |
n, k = map(int, input().split())
if n == k:
print(0)
elif n < k:
print(min(n, k - n))
else:
n = n % k
print(min(n, k - n))
| n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 0
for i in range(k, n + 2):
mini = i * (i - 1) / 2
maxx = i * (2 * n - i + 1) / 2
ans += maxx - mini + 1
ans %= MOD
print(int(ans))
| 0 | null | 36,370,762,693,430 | 180 | 170 |
values = []
while True:
v = int(input())
if 0 == v:
break
values.append(v)
for i, v in enumerate(values):
print('Case {0}: {1}'.format(i + 1, v)) | 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() | 0 | null | 1,774,675,518,040 | 42 | 77 |
n, k = map(int, input().split())
A = [*map(int, input().split())]
for i in range(k):
B = [0]*(n+1)
for j in range(n):
l = max(0, j - A[j])
r = min(n, j + A[j] + 1)
B[l] += 1; B[r] -= 1
for j in range(n-1): B[j+1] += B[j]
B.pop()
if A == B: break
A = B
print(*A, sep=' ')
| N, K = map(int, input().split())
A_list = list(map(int, input().split()))
for _ in range(K):
count_list = [0] * N
for i, v in enumerate(A_list):
count_list[i - v if i - v > 0 else 0] += 1
if i + v + 1 < N:
count_list[i + v + 1] -= 1
temp = 0
flag = True
for i in range(len(A_list)):
temp += count_list[i]
if temp != N:
flag = False
A_list[i] = temp
if flag:
break
print(*A_list) | 1 | 15,468,398,799,360 | null | 132 | 132 |
INF = 1<<60
def resolve():
def judge(j):
for i in range(group):
cnt_Wchoco[i] += div_G[i][j]
if cnt_Wchoco[i] > K:
return False
return True
H, W, K = map(int, input().split())
G = [list(map(int, input())) for _ in range(H)]
ans = INF
for bit in range(1<<(H-1)):
group = 0 # 分かれたブロック数
row = [0]*H
for i in range(H):
# 分割ライン
row[i] = group
if bit>>i & 1:
group += 1
group += 1 # 1つ折ったら2つに分かれるのでプラス1, 折らなかったら1つ
# 分割したブロックを列方向で見る
div_G = [[0] * W for _ in range(group)]
for i in range(H):
for j in range(W):
div_G[row[i]][j] += G[i][j]
num = group-1
cnt_Wchoco = [0]*group
for j in range(W):
if not judge(j):
num += 1
cnt_Wchoco = [0] * group
if not judge(j):
num = INF
break
ans = min(ans, num)
print(ans)
if __name__ == "__main__":
resolve()
| h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
INF = 10 ** 20
ans = INF
for div in range(1 << (h - 1)):
id = []
g = 0
for i in range(h):
id.append(g)
if div >> i & 1:
g += 1
g += 1
c = [[0 for _ in range(w)] for _ in range(g)]
for i in range(h):
for j in range(w):
c[id[i]][j] += (s[i][j] == "1")
tmp_ans = g - 1
now = [0] * g
def add(j):
for i in range(g):
now[i] += c[i][j]
if now[i] > k:
return False
return True
for j in range(w):
if not add(j):
tmp_ans += 1
now = [0] * g
if not add(j):
tmp_ans = INF
break
# impossible = 0
# for j in range(w):
# if impossible:
# tmp_ans = INF
# break
# for i in range(g):
# if c[i][j] > k:
# impossible = 1
# break
# now[i] += c[i][j]
# if now[i] > k:
# now = [c[gi][j] for gi in range(g)]
# tmp_ans += 1
# continue
ans = min(ans, tmp_ans)
print(ans) | 1 | 48,418,331,098,270 | null | 193 | 193 |
N = input()
total = 0
for i in N:
total += int(i)
print('Yes') if total % 9 == 0 else print('No')
| import heapq
(N,K) = map(int,input().split())
h = [int(x)*-1 for x in input().split()]
ans = 0
heapq.heapify(h)
if K <= N:
for i in range(K):
heapq.heappop(h)
while h != []:
ans -= heapq.heappop(h)
print(ans) | 0 | null | 41,770,008,182,812 | 87 | 227 |
def main():
H,W,K = list(map(int, input().split()))
S = ['' for i in range(H)]
for i in range(H):
S[i] = input()
ans = H*W
for i in range(0,1<<(H-1)):
g = 0
id = [0 for j in range(H)]
for j in range(0,H):
id[j] = g
if i>>j&1 == 1:
g += 1
g_cnt = [0 for j in range(g+1)]
c_ans = g
j = 0
div_w = 0
while j < W:
for k in range(0, H):
if S[k][j] == '1':
g_cnt[id[k]] += 1
for k in range(0,g+1):
if g_cnt[k] > K:
c_ans += 1
g_cnt = [0 for j in range(g+1)]
if div_w == j:
c_ans += H*W
break
j -= 1
div_w = j
break
j += 1
if c_ans > ans:
break
ans = min(ans, c_ans)
print(ans)
main() | from itertools import product
H, W, K = map(int, input().split())
G = [list(map(int, list(input()))) for _ in range(H)]
ans = float("inf")
for pattern in product([0, 1], repeat = H - 1):
div = [0] + [i for i, p in enumerate(pattern, 1) if p == 1] + [H]
rows = []
for i in range(len(div) - 1):
row = []
for j in range(W):
tmp = 0
for k in range(div[i], div[i + 1]):
tmp += G[k][j]
row.append(tmp)
rows.append(row)
flag = True
for row in rows:
if [r for r in row if r > K]:
flag = False
break
if not flag:
continue
tmp_ans = 0
cnt = [0] * len(rows)
w = 0
while w < W:
for r in range(len(rows)):
cnt[r] += rows[r][w]
if [c for c in cnt if c > K]:
cnt = [0] * len(rows)
tmp_ans += 1
w -= 1
w += 1
tmp_ans += pattern.count(1)
ans = min(ans, tmp_ans)
print(ans) | 1 | 48,599,113,406,170 | null | 193 | 193 |
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N = int(input())
S = str(input())
c = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
ans = []
for i in range(len(S)):
n_c = c[((c.index(S[i]))+ N)% 26]
ans.append(n_c)
print("".join(ans)) | N = int(input())
S = list(input())
L = [chr(ord("A")+i) for i in range(26)]
X = ""
for i in S:
a = L.index(i) + N
if a >= 26:
a = a - 26
X += L[a]
else:
X += L[a]
print(X)
| 1 | 134,625,309,767,898 | null | 271 | 271 |
a, b = list(map(int, input().split()))
if a < b:
a, b = b, a
while True:
if b == 0:
break
tmp = a % b
a = b
b = tmp
print(a)
| a,b = map(int,input().split())
ans = b if a >= 10 else b + 100 * (10-a)
print(ans) | 0 | null | 31,846,952,843,822 | 11 | 211 |
n, m, l = map(int, input().split())
A, B = [], []
C = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
A.append([int(i) for i in input().split()])
for i in range(m):
B.append([int(i) for i in input().split()])
B = list(zip(*B))
for i, line_A in enumerate(A):
for j, line_B in enumerate(B):
for x, y in zip(line_A, line_B):
C[i][j] += x * y
for line in C:
for i, x in enumerate(line):
if i == l - 1:
print(x)
else:
print(x, end=" ")
| import sys
s=input().split()
n=int(s[0]);m=int(s[1]);l=int(s[2])
a=[[0 for j in range(m)]for i in range(n)]
b=[[0 for j in range(l)]for i in range(m)]
c=[[0 for j in range(l)]for i in range(n)]
for i in range(n):
t=input().split()
for j in range(m):
a[i][j]=int(t[j])
for i in range(m):
t=input().split()
for j in range(l):
b[i][j]=int(t[j])
for i in range(n):
for j in range(l):
for k in range(m):
c[i][j]+=a[i][k]*b[k][j]
sys.stdout.write("{0}".format(c[i][j]))
if j==l-1:
sys.stdout.write("\n")
else:
sys.stdout.write(" ") | 1 | 1,443,603,113,940 | null | 60 | 60 |
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y
def main():
n, p = MII()
s = list(map(int, IS()))
if 10%p == 0: # pが2または5の場合
cnt = 0
for i, si in enumerate(s):
if si%p == 0:
cnt += i+1
print(cnt)
return None
d = [0]*p
d[0] = 1 # 0(mod p)はそれ単体で割り切れるため+1しておく
ss = 0
x = 1
for si in s[::-1]:
ss += x*si
ss %= p
d[ss] += 1
x = (10*x)%p # %p無しだとTLE
cnt = 0
for di in d:
cnt += di*(di-1)//2 # calc combination(n_C_2)
print(cnt)
if __name__ == "__main__":
main() | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
"""
[解法メモ]
各桁(桁数iとする)を10**i mod pの形で持っておく.
それの累積和をとって, 再びmod pをとると, 同じ数のペアの範囲はpの倍数になっていることが分かる.(他の問題でもこの解法あった気がする)
よって, 答えは同じ数のペアの数をすべて足したもの.
pが2や5の場合, *10が付くと必ず割り切れるので注意.
つまり, 1桁目が割り切れたら必ず割り切れる.⇒各桁を見ていってpで割り切れるならそれ以前の数を足せば良い.
(例)p=5, s=100のとき
1は割り切れないからx
0は割り切れるからo ⇒ 2桁目なので+2(10,0の場合)
0は割り切れるからo ⇒ 3桁目なので+3(100,00,0の場合)
⇒答えは5
"""
n, p = LI()
s = list(map(int,list(input())))
t = []
ans = 0
if p == 2 or p == 5:
for i in range(n):
if s[i] % p == 0:
ans += i+1
print(ans)
quit()
for i in range(n):
t.append(s[i]*pow(10,n-i-1,p))
t = list(accumulate(t))
u = [i % p for i in t]
u = list(Counter(u).items())
ans = 0
for i,j in u:
if i == 0:
ans += j
if j >= 2:
ans += j*(j-1) // 2
print(ans)
| 1 | 58,459,061,100,000 | null | 205 | 205 |
import sys
A, B, C, D = map(int, input().split())
while A > 0 or B > 0:
C = C - B
if C <= 0:
print("Yes")
sys.exit()
A = A - D
if A <= 0:
print("No")
sys.exit() | N = int(input())
A = list(int(input()) for _ in range(N))
def ins_sort(a, n, g):
count = 0
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j -= g
count += 1
a[j+g] = v
return count
def shell_sort(a, n):
cnt = 0
*g, = []
h = 0
for i in range(0, n):
h = h * 3 + 1
if h > n:
break
g.insert(0, h)
m = len(g)
for i in range(0, m):
cnt += ins_sort(a, n, g[i])
print(m)
print(*g)
print(cnt)
for i in range(len(a)):
print(a[i])
shell_sort(A, N)
| 0 | null | 14,934,910,034,772 | 164 | 17 |
tmp = 0
while True:
i = raw_input().strip().split()
a = int(i[0])
b = int(i[1])
if a == 0 and b == 0:
break
if a > b:
tmp = a
a = b
b = tmp
print a,b | W, H, x, y, r = map(int, input().split())
flg = False
for X in [x - r, x + r]:
for Y in [y - r, y + r]:
if not 0 <= X <= W:
flg = True
if not 0 <= Y <= H:
flg = True
print(["Yes", "No"][flg])
| 0 | null | 483,017,644,382 | 43 | 41 |
a, b, c = map(int, input().split())
k = int(input())
r = 0
while b <= a :
b = 2 * b
r += 1
while c <= b:
c = 2 * c
r += 1
if r <= k:
print("Yes")
else:
print("No") | a,b,c=map(int,input().split())
k=int(input())
count=0
while a>=b:
b=b*2
count=count+1
while b>=c:
c=c*2
count=count+1
if count<=k:
print("Yes")
else:
print("No")
| 1 | 6,912,769,903,072 | null | 101 | 101 |
X = int(input())
# Xの素因数分解をうまくつかう
# A^5 - B^5 =(A-B)(A^4+A^3B+A^2B^2+AB^3+B^4)
# どっちが正負かは決まらない
# AB(A^2+B^2)+(A^2+B^2)^2-A^2B^2
# AB((A-B)^2+2AB)+((A-B)^2+2AB)^2 - A^2B^2
# A-B = P
# AB = Q
# A^5-B^5 = P(Q(P^2+2Q)+(P^2+2Q)^2-Q^2) = P(P^4+5P^2Q+5Q^2) = P(5Q^2+5P^2Q+P^4)
# Qは整数解なので
# 5Q^2+5P^2Q+P^4が整数解を持つ楽な方法は(Q+P)^2の形の時、つまり2P = P^2+2,
# X = PRとする
# R-P^4は5の倍数になる
#Aの上限を求める
# X<10^9
# A-B = 1がAを最大にできる
maxA = 126
maxX = pow(10, 9)
flag = 0
for A in range(-126, 126):
for B in range(-127, A):
result = pow(A, 5) - pow(B, 5)
if result > maxX:
next
if result == X:
print(A, B)
flag = 1
break
if flag == 1:
break | n = int( raw_input( ) )
dic = {}
for i in range( n ):
cmd, word = raw_input( ).split( " " )
if "insert" == cmd:
dic[ word ] = True
elif "find" == cmd:
if not dic.get( word ):
print( "no" )
else:
print( "yes" ) | 0 | null | 12,885,772,209,102 | 156 | 23 |
import math
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
def lcm(x, y):
return (x // math.gcd(x, y)) * y
LCM = A[0]
for i in range(N-1):
LCM = lcm(LCM, A[i+1])
#LCM %= mod
ans = 0
for a in A:
ans += LCM * pow(a, mod-2, mod) % mod
ans %= mod
print(ans) | import math
import sys
def lcm(a, b):
return a * b // math.gcd(a, b)
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
LCM = 1
ans = 0
MOD = 1000000007
for x in A:
LCM = lcm(LCM, x)
for x in A:
ans += LCM // x
print(ans%MOD) | 1 | 88,074,926,019,068 | null | 235 | 235 |
# Belongs to : midandfeed aka asilentvoice
while(1):
s = str(input())
if s == '-':
break
else:
n = int(input())
for _ in range(n):
h = int(input())
ans = s[h:] + s[:h]
s = ans
print(ans) | from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
n = readInt()
a = readInts()
sum_a = sum(a)
v = sum(a)/2
ans = float("inf")
t = 0
for i in range(len(a)):
t+=a[i]
ans = min(ans,abs(sum_a-2*t))
print(ans) | 0 | null | 72,150,455,973,980 | 66 | 276 |
N = int(input())
if N % 2 == 0:
ans = int(N / 2) - 1
else:
ans = int(N / 2)
print('{}'.format(ans))
| from math import log2, ceil
H = int(input())
print(2**(ceil(log2(H))+1 if log2(H).is_integer() else ceil(log2(H))) - 1) | 0 | null | 116,596,529,195,708 | 283 | 228 |
N = input()
print('Yes' if "7" in N else 'No') | d, t, f = map(int, input().split())
if (d/t) <= f:
print('Yes')
else:
print('No') | 0 | null | 18,870,098,565,262 | 172 | 81 |
# coding: utf-8
string = raw_input()
new_string = ""
for s in string:
if s.islower():
new_string += s.upper()
elif s.isupper():
new_string += s.lower()
else:
new_string += s
print new_string | line = list(input())
for k,v in enumerate(line):
line[k] = v.swapcase()
print(''.join(line)) | 1 | 1,483,664,267,220 | null | 61 | 61 |
import itertools
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
perm = list(itertools.permutations(range(1,N+1)))
for i in range(len(perm)):
if P == perm[i]:
a = i
if Q == perm[i]:
b = i
print(abs(a-b))
| from sys import stdin
a, b, c = (int(n) for n in stdin.readline().rstrip().split())
cnt = 0
for n in range(a, b + 1):
if c % n == 0:
cnt += 1
print(cnt)
| 0 | null | 50,647,849,240,480 | 246 | 44 |
a,b=open(0);c=1;
for i in sorted(b.split()):
c*=int(i)
if c>10**18:print(-1);exit()
print(c) | def SUM(num_List):
answer = 0
for i, num in enumerate(num_List):
answer += num*i
return answer
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = list()
C = list()
start = True
num_List = [0 for x in range(100001)]
for a in A:
num_List[a] = num_List[a] + 1
for x in range(Q):
b, c = map(int, input().split())
B.append(b)
C.append(c)
for x in range(Q):
b = B[x]
c = C[x]
if start == True:
num_List[c] = num_List[c] + num_List[b]
num_List[b] = 0
answer = SUM(num_List)
start = False
else:
answer = answer + num_List[b]*(c-b)
num_List[c] = num_List[c] + num_List[b]
num_List[b] = 0
print(answer) | 0 | null | 14,121,463,448,412 | 134 | 122 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
n,m = map(int, input().split())
a = list(map(int, input().split()))
total = sum(a)
re = m
for i in range(n):
if (4*m*a[i] >= total):
re = re -1
if (re == 0):
print("Yes")
exit()
print("No")
| Str = input()
q = int(input())
for i in range(q):
order = list(input().split())
o = order[0]
a = int(order[1])
b = int(order[2])
if o=='print':
print(Str[a:b+1])
if o=='reverse':
StrL = list(Str)
t = list(Str[a:b+1])
j = len(t)-1
for i in range(a,b+1):
StrL[i] = t[j]
j -= 1
Str = ''.join(StrL)
if o=='replace':
p = list(order[3])
StrL = list(Str)
j = 0
for i in range(a,b+1):
StrL[i] = p[j]
j += 1
Str = ''.join(StrL)
| 0 | null | 20,269,265,207,780 | 179 | 68 |
D = int(input())
c = list(map(int, input().split()))
s_tbl = [list(map(int, input().split())) for _ in range(D)]
ans = 0
last = [0] * 26
for d in range(1, D+1):
t = int(input()) - 1
c_sum = 0
for i in range(26):
c_sum = c_sum + c[i] * (d-last[i])
ans = ans + s_tbl[d-1][t] + (-c_sum) + c[t] * (d-last[t])
last[t] = d
print(ans) | D = int(input())
Cs = list(map(int,input().split()))
Ss = [list(map(int,input().split())) for i in range(D)]
ts = []
for i in range(D):
ts.append(int(input()))
last = [0]*26
satisfy = 0
for day,t in enumerate(ts):
day += 1
last[t-1] = day
satisfy += Ss[day-1][t-1]
for i in range(26):
satisfy -= Cs[i]*(day-last[i])
print(satisfy) | 1 | 10,019,774,577,884 | null | 114 | 114 |
import sys
from sys import stdin
input = stdin.readline
n,k = (int(x) for x in input().split())
w = [int(input()) for i in range(n)]
# 最大積載Pのトラックで何個の荷物を積めるか
def check(P):
i = 0
for j in range(k):
s = 0
while s + w[i] <= P:
s += w[i]
i += 1
if i == n:
return n
return i
def solve():
left = 0
right = 100000 * 10000 #荷物の個数 * 1個当たりの最大重量
while right - left > 1 :
mid = (right + left)//2
v = check(mid)
if v >= n:
right = mid
else:
left = mid
return right
print(solve())
| def judge_1(arr, p, k):
index = 0
n = len(arr)
for i in range(k):
weight_sum = 0
while weight_sum + arr[index] <= p:
weight_sum += arr[index]
index += 1
if index >= n:
return True
return index >= n
if __name__ == '__main__':
n, k = map(int, input().split())
weight = []
l, r = 0, 0
for _ in range(n):
tmp = int(input())
weight.append(tmp)
r += tmp
l = max(l, tmp)
ans = r
while l <= r:
mid = (l + r) // 2
if judge_1(weight, mid, k):
ans = mid
r = mid - 1
else:
l = mid + 1
print(ans)
| 1 | 88,452,246,820 | null | 24 | 24 |
seed = [i for i in range(1,14)]
deck = {}
for s in ['S','H','C','D']:
deck[s] = seed[:]
n = int(input())
for i in range(n):
s,v = input().split()
deck[s][int(v)-1] = 0
for s in ['S','H','C','D']:
for i in deck[s]:
if i != 0:
print(s,i) | ans = []
for i in range(4):
for j in range(13):
ans.append("SHCD"[i] + " " + str(j + 1))
n = int(input())
for i in range(n):
a = input()
ans.remove(a)
if len(ans) > 0:
print("\n".join(ans))
| 1 | 1,044,888,669,980 | null | 54 | 54 |
import sys
readline = sys.stdin.readline
N = int(readline())
S = [readline().rstrip() for _ in range(N)]
def count_cb_ob(s):
st = []
for i, si in enumerate(s):
if si == '(' or len(st) == 0 or st[-1] != '(':
st.append(si)
else:
st.pop()
return st.count(')'), st.count('(')
cb_obs = map(count_cb_ob, S)
f, b, s = [], [], []
for down, up in cb_obs:
(f if down < up else (s if down == up else b)).append((down, up))
f = sorted(f)
b = sorted(b, key=lambda x:x[1], reverse=True)
count = 0
ans = 'Yes'
for down, up in (*f, *s, *b):
count -= down
if count < 0:
ans = 'No'
count += up
if count != 0:
ans = 'No'
print(ans) | n, k = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
def solve(start):
loop = []
llen = 0
lsum = 0
reach = [0]*n
now = start
while True:
nxt = P[now]-1
loop.append(now)
llen += 1
lsum += C[now]
reach[now] = 1
if reach[nxt]:
break
now = nxt
if lsum <= 0 or llen >= k:
res = -10 ** 20
s = 0
now = start
for i in range(min(llen, k)):
s += C[now]
res = max(res, s)
now = P[now]-1
return res
else:
s = lsum * (k // llen)
now = start
for i in range(k % llen):
s += C[now]
now = P[now]-1
j = loop.index(now)
res = -10**20
for i in range(llen):
j -= 1
res = max(res, s)
s -= C[loop[j]]
return res
def solver():
ans = -10 ** 20
for i in range(n):
ans = max(ans, solve(i))
return ans
print(solver())
| 0 | null | 14,550,499,662,722 | 152 | 93 |
import functools, operator
r,c = tuple(int(n) for n in input().split())
A = [[int(a) for a in input().split()] for i in range(r)]
for a in A:
a.append(sum(a))
R = [functools.reduce(operator.add, x) for x in zip(*A)]
A.append(R)
for j in A:
print(" ".join(map(str,j)))
| def main():
r, c = map(int, input().split())
table = []
for _ in range(r):
table.append(list(map(int, input().split())))
table.append([0] * (c+1))
for index, line in enumerate(table[:-1]):
table[index].append(sum(line))
for index1, value in enumerate(table[index]):
table[-1][index1] += value
for line in [map(str, line) for line in table]:
print(' '.join(line))
return
if __name__ == '__main__':
main()
| 1 | 1,364,690,081,874 | null | 59 | 59 |
from sys import stdin
r = int(stdin.readline().rstrip())
print(r*r)
| def bunsan(n,S): #Sはリスト
ave = sum(S)/n
D = 0
for i in range(n):
D += (S[i] - ave)**2
return (D/n)**(1/2)
while True:
n = int(input())
if n == 0:
break
S = list(map(int,input().split()))
print(bunsan(n,S))
| 0 | null | 72,755,692,499,566 | 278 | 31 |
s = input()
while "?" not in s:
s.replace("/","//")
print(int(eval(s)))
s = input() | # cording: utf-8
num = []
while True:
list = input().rstrip().split(" ")
if str(list[1]) == "?":
break
num.append(list)
for i in range(len(num)):
if str(num[i][1]) == "+":
print(int(num[i][0]) + int(num[i][2]))
elif str(num[i][1]) == "-":
print(int(num[i][0]) - int(num[i][2]))
elif str(num[i][1]) == "*":
print(int(num[i][0]) * int(num[i][2]))
else:
print(int(num[i][0]) // int(num[i][2])) | 1 | 680,589,712,310 | null | 47 | 47 |
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
a = 100
b = 0
for i in range(0, 102):
if i not in p and abs(x - i) < a:
a = abs(x - i)
b = i
print(b)
| import math
n,m,t = map(int,input().split())
if n%m == 0:
print(int(n/m)*t)
else:
print(math.ceil(n/m)*t) | 0 | null | 9,145,851,741,198 | 128 | 86 |
N = int(input())
res = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, N + 1):
if i % 10: res[int(str(i)[0]) - 1][i % 10 - 1] += 1
ans = 0
for i in range(1, N + 1):
if i % 10: ans += res[i % 10 - 1][int(str(i)[0]) - 1]
print(ans) | N=int(input())
m=0
x=[[0]*9 for i in range(9)]
for i in range(1,N+1):
if i%10==0:
continue
b=int(str(i)[0])
g=int(i%10)
x[b-1][g-1]+=1
ans=0
for i in range(9):
for j in range(9):
ans+=x[i][j]*x[j][i]
#print(i+1,j+1,x[i][j])
print(ans) | 1 | 86,387,506,842,096 | null | 234 | 234 |
N,K=map(int, input().split())
sum_ = 0
for k in range(K, N+2):
sum_ += k*(N-k+1)+1
sum_ = sum_ % (10**9+7)
print(sum_) | n,k = map(int, input().split())
ans = 0
for i in range(k, n + 2):
min = i*(0+i-1)/2
max = i*((n-i)+(n+1))/2
ans += max - min +1
print(int(ans % (10**9 + 7))) | 1 | 33,065,369,284,700 | null | 170 | 170 |
def resolve():
N = int(input())
S = str(input())
ans = 0
for pos in range(N - 2):
if S[pos:(pos + 3)] == 'ABC':
ans += 1
print(ans)
return
resolve() | n = int(input())
li = [0]*100
for i in range(n+1):
li[int(str(i)[0]+str(i)[-1])]+=1
ans = 0
for i in range(1,10):
for j in range(1,10):
ans += li[int(str(i)+str(j))] * li[int(str(j)+str(i))]
print(ans)
| 0 | null | 93,269,314,408,100 | 245 | 234 |
n = int(input())
ans = (n/3)**3
print(ans) | l = int(input())
x = float(l / 3)
ans = float(x**3)
print(ans) | 1 | 47,099,650,746,138 | null | 191 | 191 |
N, K, C = map(int, input().split())
S = list(input())
l = [0] * N
r = [0] * N
cnt = 1
yutori = 10 ** 10
for i, s in enumerate(S):
if s == "o" and yutori > C:
l[i] = cnt
yutori = 0
cnt += 1
yutori += 1
S.reverse()
yutori = 10 ** 10
cnt = K
for i, s in enumerate(S):
if s == "o" and yutori > C:
r[i] = cnt
yutori = 0
cnt -= 1
yutori += 1
ans = set()
r.reverse()
for i in range(N):
if l[i] == r[i] and l[i] > 0:
ans.add(i+1)
print(*ans, sep="\n")
| N, K, C = map(int, input().split())
S = input()
L = []
R = []
count_L = C
count_R = C
for i in range(N):
if S[i] == "o" and count_L >= C:
count_L = 0
L.append(i)
else:
count_L += 1
if S[N-i-1] == "o" and count_R >= C:
count_R = 0
R.append(N-i-1)
else:
count_R += 1
if len(L) >= K and len(R) >= K:
break
for l, r in zip(L, R[::-1]):
if l == r:
print(l+1) | 1 | 40,480,871,348,720 | null | 182 | 182 |
from collections import deque
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
G = {i:[] for i in range(N+1)}
for a,b in AB:
G[a].append(b)
G[b].append(a)
parent = [0]*(N+1)
parent[0]==-1
parent[1]==-1
q = deque()
q.append(1)
while len(q)>0:
room = q.popleft()
child = G[room]
for i in child:
if parent[i] == 0:
parent[i] = room
q.append(i)
if min(parent[2:])==0:
print('No')
else:
print('Yes')
for i in parent[2:]:
print(i) | def dijkstra(v, G):
import heapq
ret = [10 ** 10] * len(G)
ret[v] = 0
q = [(ret[i], i) for i in range(len(G))]
heapq.heapify(q)
while len(q):
tmpr, u = heapq.heappop(q)
if tmpr == ret[u]:
for w in G[u]:
if ret[w] > ret[u] + 1:
ret[w] = ret[u] + 1
heapq.heappush(q, (ret[w], w))
return ret
N, M = map(int, input().split())
G, ans = {i: [] for i in range(N)}, [-1] * N
for _ in range(M):
A, B = map(int, input().split())
G[A - 1].append(B - 1)
G[B - 1].append(A - 1)
d = dijkstra(0, G)
for a in range(N):
for b in G[a]:
if d[a] - d[b] == 1:
ans[a] = b + 1
print("Yes")
for a in ans[1:]:
print(a)
| 1 | 20,409,814,273,628 | null | 145 | 145 |
n = int(input())
a = list(map(int, input().split()))
ret = 0
now = a[0]
for i in range(1, n):
if now > a[i]:
ret += now - a[i]
a[i] = now
now = a[i]
print(ret) | N = int(input())
A = list(map(int, input().split()))
step = 0
for i in range(N - 1):
step += max(0, A[i] - A[i + 1])
A[i + 1] += max(0, A[i] - A[i + 1])
print(step)
| 1 | 4,551,083,130,202 | null | 88 | 88 |
import itertools,math
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
x[i], y[i] = map(int, input().split())
seq=[]
for i in range(N):
seq.append(i)
l=list(itertools.permutations(seq))
num=0
for i in l:
for u in range(1,len(i)):
num+=math.sqrt((x[i[u-1]]-x[i[u]])**2+(y[i[u-1]]-y[i[u]])**2)
print(num/len(l)) | n=int(input())
s=list()
for i in range(n):
s.append(input())
import collections
c=collections.Counter(s)
l=list()
max_=0
for cc in c.values():
max_=max(cc, max_)
for ca,cb in c.items():
if max_==cb:
l.append(ca)
l.sort()
for ll in l:
print(ll)
| 0 | null | 108,750,317,545,390 | 280 | 218 |
n = input()
if n.isupper():
print("A")
else:
print("a") | # coding: UTF-8
import sys
import numpy as np
# f = open("input.txt", "r")
# sys.stdin = f
a = str(input())
if a.islower():
print("a")
else:
print("A") | 1 | 11,348,347,521,784 | null | 119 | 119 |
N = int(input())
locs = []
S = 0
for _ in range(N):
locs.append(list(map(int,input().split())))
for i in range(N):
for j in range(i+1,N):
dis = ((locs[i][0]-locs[j][0])**2 + (locs[i][1]-locs[j][1])**2)**(1/2)
S += dis
print(2*S/N) | # -*- coding: utf-8 -*-
def main():
from itertools import permutations
from math import sqrt
n = int(input())
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(n):
xi, yi = map(int, input().split())
x[i] = xi
y[i] = yi
path = list(permutations(range(n)))
path_count = len(path)
length = 0
for p in path:
for i, j in zip(p, p[1:]):
length += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
print(length / path_count)
if __name__ == '__main__':
main()
| 1 | 148,674,150,274,172 | null | 280 | 280 |
N=int(input())
d={"AC":0,"WA":0,"TLE":0,"RE":0}
for _ in range(N):
d[input()]+=1
print("AC x",d["AC"])
print("WA x",d["WA"])
print("TLE x",d["TLE"])
print("RE x",d["RE"])
| n = int(input())
s = [input() for i in range(n)]
z = ['AC','WA','TLE','RE']
for j in z:
print(j+' x '+str(s.count(j)))
| 1 | 8,788,045,986,500 | null | 109 | 109 |
import sys
from collections import defaultdict
input = sys.stdin.readline
mod = 998244353
def extgcd(a,b):
r = [1,0,a]
w = [0,1,b]
while w[2] != 1:
q = r[2]//w[2]
r2 = w
w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
r = r2
w = w2
return [w[0],w[1]]
def mod_inv(a,m):
x = extgcd(a,m)[0]
return ( m + x%m ) % m
def main():
n,s = map(int,input().split())
a = list(map(int, input().split()))
dp = [[0 for _ in range(s+1)] for _ in range(n+1)]
dp[0][0] = pow(2,n,mod)
MODINV2 = mod_inv(2,mod)
ans = 0
for i in range(n):
for j in range(s,-1,-1):
if j-a[i] < 0:
continue
dp[i+1][j] += dp[i][j-a[i]]*MODINV2
dp[i+1][j] %= mod
for j in range(s,-1,-1):
if j == s:
ans += dp[i+1][j]
ans %= mod
else:
dp[i+1][j] += dp[i][j]
dp[i+1][j] %= mod
print(ans)
if __name__ == "__main__":
main() | #!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353
n, s = map(int, input().split())
a = [int(item) for item in input().split()]
dp = [[0] * (s + 1) for _ in range(n+1)]
dp[0][0] = 1
for i, item in enumerate(a):
for j in range(s, -1, -1):
if dp[i][j] == 0:
continue
if j + item <= s:
dp[i+1][j+item] += dp[i][j]
dp[i+1][j] += dp[i][j] * 2
dp[i+1][j] %= MOD
print(dp[-1][-1] % MOD) | 1 | 17,611,294,019,200 | null | 138 | 138 |
card = []
check = [[0, 0, 0] for i in range(3)]
for i in range(3):
card.append(list(map(int, input().split())))
n = int(input())
for i in range(n):
b = int(input())
for j in range(3):
for k in range(3):
if b == card[j][k]:
check[j][k] = 1
flag = 0
for i in range(3):
if check[i][0] == check[i][1] == check[i][2] == 1:
flag = 1
break
elif check[0][i] == check[1][i] == check[2][i] == 1:
flag = 1
break
elif check[0][0] == check[1][1] == check[2][2] == 1:
flag = 1
break
elif check[0][2] == check[1][1] == check[2][0] == 1:
flag = 1
break
if flag:
print('Yes')
else:
print('No') | n, k = map(int, input().split())
a = sorted(map(int, input().split()))
d = [a[i + 1] - a[i] for i in range(n - 1)]
mod = 1000000007
def pow(x, n):
ret = 1
while n > 0:
if (n & 1) == 1:
ret = (ret * x) % mod
x = (x * x) % mod
n //= 2
return ret
fac = [1]
inv = [1]
for i in range(1, n + 1):
fac.append((fac[-1] * i) % mod)
inv.append(pow(fac[i], mod - 2))
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 i in range(n - 1):
num = (cmb(n, k) - cmb(i + 1, k) - cmb(n - i - 1, k)) % mod
ret = (ret + d[i] * num) % mod
print(ret)
| 0 | null | 77,916,400,314,258 | 207 | 242 |
def tripleDots(n, string):
string_len = len(string)
if string_len > n :
string = string[ 0 : n ] + "..."
print(string)
arr = ["", ""]
for i in range(2):
arr[i] = input()
tripleDots(int(arr[0]), arr[1]) | n = int(input())
d = {}
for i in range(n):
s = input()
d[s] = d.get(s, 0) + 1
m = max(d.values())
for s in sorted(s for s in d if d[s] == m):
print(s)
| 0 | null | 44,711,236,164,800 | 143 | 218 |
import math
x1, y1, x2, y2 = map(float,input().split())
a = abs(x1-x2)
b = abs(y1-y2)
print(math.sqrt(a*a+b*b))
| s="abcdefghij"
n=int(input())
ans=[["a",1]]
c=1
while(c<n):
an=[]
for i in ans:
lim=min(i[1]+1,10)
for j in range(lim):
if (j==i[1]) and (j!=10):
an.append([i[0]+s[j],i[1]+1])
else:
an.append([i[0]+s[j],i[1]])
ans=an
c+=1
for i in ans:
print(i[0]) | 0 | null | 26,453,282,146,528 | 29 | 198 |
n = list(input())
if n[0] == "7" or n[1] == "7" or n[2] == "7":
print("Yes")
else:
print("No") | print("YNeos"["7"not in input()::2]) | 1 | 34,267,444,423,840 | null | 172 | 172 |
def main():
import numpy as np
n, k = map(int, input().split())
aa = np.array(sorted(list(map(int, input().split()))), dtype=np.int64)
f = np.array(sorted(list(map(int, input().split())),
reverse=True), dtype=np.int64)
a = 0
b = 10**12+10
while a+1 < b:
med = (a+b)//2
if np.sum(np.maximum(aa-med//f, np.zeros(n, dtype=np.int64))) > k:
a = med+1
else:
b = med
if a == b:
print(a)
else:
if np.sum(np.maximum(aa-a//f, np.zeros(n, dtype=np.int64))) > k:
print(b)
else:
print(a)
main()
| import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
return sys.stdin.readline().rstrip()
def main():
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
F=list(map(int,input().split()))
F.sort(reverse=True)
def nibutan(ok,ng):
while abs(ok-ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
return ok
def solve(mid):
k=0
for i in range(N):
k+=max(0,-(-(A[i]*F[i]-mid)//F[i]))
if k<=K:
return True
else:
return False
print(nibutan(10**18,-1))
if __name__ == '__main__':
main()
| 1 | 165,370,694,625,202 | null | 290 | 290 |
x = int(input())
m = divmod(x, 500)
print(m[0] * 1000 + m[1] // 5 * 5) | def resolve():
n = int(input())
p = list(map(int, input().split()))
m = 1000000000
ans = 0
for i in range(n):
if p[i] <= m:
ans += 1
m = min(m, p[i])
print(ans)
return
if __name__ == "__main__":
resolve()
| 0 | null | 64,105,901,101,708 | 185 | 233 |
import numpy as np
def main(R,C,K,RCV):
V=np.zeros((R+1,C+1),dtype=np.int64)
for i in range(K):
V[RCV[i][0]][RCV[i][1]]=RCV[i][2]
d=np.zeros((R+1,C+1,4),dtype=np.int64)
for i in range(R):
for j in range(C):
m=max(d[i][j+1])
d[i+1][j+1][0]=m
for k in range(3):
d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
return max(d[-1][-1])
import sys
readline=sys.stdin.buffer.readline
read=sys.stdin.buffer.read
if sys.argv[-1]=='ONLINE_JUDGE':
from numba import*
from numba.pycc import CC
cc=CC('my_module')
def cc_export(f,s):
cc.export(f.__name__,s)(f)
return njit(f)
main=cc_export(main,(i8,i8,i8,i8[:,:],))
cc.compile()
exit()
R,C,K=np.array(readline().split(),dtype=np.int64)
RCV=np.array(read().split(),dtype=np.int64).reshape(K,3)
from my_module import main
print(main(R,C,K,RCV))
| n, a, b = map(int, input().split())
div, mod = divmod(n, a + b)
ans = div * a + min(mod, a)
print(ans) | 0 | null | 30,661,398,617,392 | 94 | 202 |
S = str(input())
for i in range(int(input())):
L = input().split()
o = L[0]
a = int(L[1])
b = int(L[2]) + 1
if len(L) == 4:
p = L[3]
else:
p = 0
if o == "print":
print(S[a:b])
elif o == "reverse":
S = S[:a]+S[a:b][::-1]+S[b:]
elif o == "replace":
S = S[:a]+p+S[b:]
| s = input()
n = int(input())
s_array = []
for i in range(len(s)):
s_array.append(s[i])
for i in range(n):
order = input().split()
if order[0] == "replace":
first = int(order[1])
last = int(order[2])
for j in range(last-first+1):
s_array[first+j] = order[3][j]
elif order[0] == "reverse":
a = int(order[1])
b = int(order[2])
buf = []
for j in range(b, a-1, -1):
buf.append(s_array[j])
for j in range(b+1-a):
s_array[a+j] = buf[j]
elif order[0] == "print":
a = int(order[1])
b = int(order[2])
for j in range(a, b+1):
print("%s" % s_array[j], end="")
print()
| 1 | 2,107,875,419,402 | null | 68 | 68 |
r = int(input())
s = r * 2 * 3.14
print(s) | M = 10 ** 9 + 7
# inverse
def calc_inverse(n, law):
if n == 1:
return 1
pre_r = law
pre_x = 0
pre_y = 1
cur_r = n
cur_x = 1
cur_y = 0
while True:
d = pre_r // cur_r
r = pre_r % cur_r
nxt_r = r
nxt_x = pre_x - d * cur_x
nxt_y = pre_y - d * cur_y
if nxt_r == 1:
ret = nxt_x
while ret < 0:
ret += law;
return ret;
elif nxt_r == 0:
return None
pre_r = cur_r;
pre_x = cur_x;
pre_y = cur_y;
cur_r = nxt_r;
cur_x = nxt_x;
cur_y = nxt_y;
facts = [1]
facts_i = [1]
def cache_facts(n, M):
f = 1
fi = 1
for i in range(1, n):
f = (f * i) % M
fi = (fi * calc_inverse(i, M)) % M
facts.append(f)
facts_i.append(fi)
def cached_C(a, b, M):
return facts[a] * facts_i[a - b] * facts_i[b] % M
K = int(input())
S = input().strip()
L = len(S)
cache_facts(K + L + 1, M)
total = pow(26, K, M)
#print(total)
for i in range(1, K + 1):
total = (total + (pow(25, i, M) * cached_C(L + i - 1, L - 1, M) % M) * pow(26, K - i, M)) % M
print(total)
| 0 | null | 22,173,088,097,118 | 167 | 124 |
n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
x[i], y[i] = map(int, input().split())
z = [0] * n
w = [0] * n
for i in range(n):
z[i] = x[i] + y[i]
w[i] = x[i] - y[i]
cand1 = max(z) - min(z)
cand2 = max(w) - min(w)
print(max(cand1, cand2))
| class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
n,m = map(int,input().split())
u = UnionFind(n)
for _ in range(m):
ai,bi = map(int,input().split())
u.union(ai,bi)
s = [0 for _ in range(n+1)]
for i in range(1,n+1):
s[u.find(i)] = 1
print(sum(s)-1) | 0 | null | 2,890,824,916,928 | 80 | 70 |
import math
x, k, d = map(int, input().split())
x = abs(x)
straight = min(k, math.floor(x / d))
k -= straight
x -= straight * d
if(k % 2 == 0):
print(x)
else:
print(abs(x - d)) | class Dictionary:
def __init__(self):
self.elements = set()
def insert(self, x):
self.elements.add(x)
def find(self, y):
if y in self.elements:
print('yes')
else:
print('no')
import sys
n = int(sys.stdin.readline())
simple_dict = Dictionary()
for i in range(n):
operation = sys.stdin.readline()
if operation[0] == 'i':
simple_dict.insert(operation[7:])
else:
simple_dict.find(operation[5:]) | 0 | null | 2,657,410,726,048 | 92 | 23 |
import sys
import numba as nb
import numpy as np
input = sys.stdin.readline
@nb.njit("i8(i8,i8,i8[:,:])", cache=True)
def solve(H, N, AB):
INF = 10 ** 18
dp = np.full(shape=(H + 1), fill_value=INF, dtype=np.int64)
dp[0] = 0
for i in range(N):
A, B = AB[i]
for d in range(H + 1):
if d < A:
dp[d] = min(dp[d], B)
else:
dp[d] = min(dp[d], dp[d - A] + B)
ans = dp[-1]
return ans
def main():
H, N = map(int, input().split())
AB = np.zeros(shape=(N, 2), dtype=np.int64)
for i in range(N):
AB[i] = input().split()
ans = solve(H, N, AB)
print(ans)
if __name__ == "__main__":
main()
| H,N = map(int,input().split())
magics = [list(map(int,input().split())) for _ in range(N)]
max_A = max(a for a,b in magics)
INF = 10**10
DP = [INF]*(H+max_A)
DP[0] = 0
for i in range(1,H+max_A):
DP[i] = min(DP[i-a] + b for a,b in magics)
ans = min(DP[H:])
print(ans)
| 1 | 81,004,547,458,912 | null | 229 | 229 |
n = int(input())
S = input()
a = ord('A')
z = ord('Z')
ans = ''
for s in S:
if ord(s) + n <= 90:
ans += chr(ord(s) + n)
else:
ans += chr(a + ord(s) + n - z - 1)
print(ans)
| n=int(input())
s=input()
ans=""
for i in range(len(s)):
a=(ord(s[i])+n-65)%26
ans=ans+chr(a+65)
print(ans) | 1 | 134,749,541,206,238 | null | 271 | 271 |
import sys
input = sys.stdin.readline
N, M, L = (int(i) for i in input().split())
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
graph = [[0]*N for i in range(N)]
for i in range(M):
a, b, c = (int(i) for i in input().split())
graph[a-1][b-1] = c
graph[b-1][a-1] = c
graph = csr_matrix(graph)
d = floyd_warshall(csgraph=graph, directed=False)
new_graph = [[0]*N for i in range(N)]
for i in range(N):
for j in range(N):
if d[i][j] <= L:
new_graph[i][j] = 1
new_graph[j][i] = 1
graph = csr_matrix(new_graph)
d = floyd_warshall(csgraph=graph, directed=False)
Q = int(input())
for i in range(Q):
s, t = (int(i) for i in input().split())
if d[s-1][t-1] == float("inf"):
print("-1")
else:
print(int(d[s-1][t-1]-1)) | # coding: utf-8
from scipy.sparse.csgraph import floyd_warshall
N,M,L=map(int, input().split())
RG=[[0 for i in range(N)] for j in range(N)]
for i in range(M):
f,t,c = map(int, input().split())
if c <= L:
RG[f-1][t-1] = c
RG[t-1][f-1] = c
Rd = floyd_warshall(RG, directed=False)
FG=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
for j in range(i+1, N):
if Rd[i][j] <= L:
FG[i][j] = 1
FG[j][i] = 1
Fd = floyd_warshall(FG, directed=False)
Q=int(input())
for i in range(Q):
s, t = map(int, input().split())
v = Fd[s-1][t-1]
if s == t:
print (str(0))
if v == float('inf'):
print (str(-1))
else:
print (str(int(v-1)))
| 1 | 173,189,062,619,786 | null | 295 | 295 |
A=list(map(int,input().split()))
B=0
B=A[0]+A[1]+A[2]
if B>=22:
print("bust")
else:
print("win")
| data = ""
data_1 = [chr(ord('a') + i) for i in range(26)]
while True:
try:
data += input().lower()
except EOFError:
break
for i in data_1:
j = data.count(i)
print(f'{i} : {j}')
| 0 | null | 60,384,718,367,890 | 260 | 63 |
diceA = list(map(int, input().split()))
diceB = [[1,2,3,5,4,2],[2,1,4,6,3,1],[3,1,2,6,5,1],[4,1,5,6,2,1],[5,1,3,6,4,1],[6,2,4,5,3,2]]
q = int(input())
for i in range(q):
quest = list(map(int, input().split()))
ans = 0
for j in range(6):
if quest[0] == diceA[j]:
for k in range(6):
if quest[1] == diceA[k]:
for l in range(1,5):
if diceB[j][l] == k+1:
ans = diceB[j][l+1]
print(diceA[ans-1])
| a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
c.sort()
if c[-b]>=(sum(c)/(4*b)):
print("Yes")
else:
print("No") | 0 | null | 19,560,797,379,970 | 34 | 179 |
a=int(input())
p=a+a**2+a**3
print(p) | import sys
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
N = int(input())
mn = 1001001001001
a = 1
while a*a <= N:
if N % a == 0:
mn = min(mn, a + N//a - 2)
a += 1
print(mn)
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| 0 | null | 86,174,794,551,300 | 115 | 288 |
i = input()
print(i.swapcase())
| str = raw_input()
li = []
for c in list(str):
if c.isupper():
li.append(c.lower())
elif c.islower():
li.append(c.upper())
else:
li.append(c)
print ''.join(li) | 1 | 1,499,891,145,730 | null | 61 | 61 |
N = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 1
lst = [0] * 3
for aa in a:
cnt = 0
j = -1
for i, l in enumerate(lst):
if l == aa:
cnt += 1
j = i
if j == -1:
ans = 0
break
ans *= cnt
ans %= MOD
lst[j] += 1
print(ans) | (X1,X2,Y1,Y2)=list(map(int,input().split()))
ans=X2*Y2
ans=max(ans,X1*Y1)
ans=max(ans,X1*Y2)
ans=max(ans,X2*Y1)
print (ans) | 0 | null | 66,607,168,086,962 | 268 | 77 |
import sys
import math
import fractions
from collections import defaultdict
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod=998244353
N,S=nm()
A=nl()
dp=[[0]*3001 for _ in range(3001)]#i i番目 j和がj
dp[0][A[0]]=1
dp[0][0]=2
for i in range(1,N):
for j in range(0,3001):
if(0<=(j-A[i])):
dp[i][j]=dp[i-1][j-A[i]]+2*dp[i-1][j]
else:
dp[i][j]=2*dp[i-1][j]
dp[i][j]%=mod
ans=dp[N-1][S]
print(ans%mod) | #
# abc145 c
#
import sys
from io import StringIO
import unittest
import math
import itertools
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """3
0 0
1 0
0 1"""
output = """2.2761423749"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2
-879 981
-866 890"""
output = """91.9238815543"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310"""
output = """7641.9817824387"""
self.assertIO(input, output)
def resolve():
N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]
R = itertools.permutations(range(N))
all = 0
for r in R:
for pi in range(1, len(r)):
all += math.sqrt((P[r[pi]][0]-P[r[pi-1]][0])**2 +
(P[r[pi]][1]-P[r[pi-1]][1])**2)
n = 1
for i in range(1, N+1):
n *= i
print(f"{all/n:.10f}")
if __name__ == "__main__":
# unittest.main()
resolve()
| 0 | null | 83,357,153,464,088 | 138 | 280 |
t = input()
ans = ""
for i in range(len(t)):
if t[i] != '?':
ans += t[i]
else:
ans += 'D'
print(ans) | T=input()
ans=""
if T=="?":
print("D")
exit()
for i in range(len(T)):
if T[i]=="P" or T[i]=="D":
ans+=T[i]
else:
if i==0:
if T[i+1]=="P":
ans+="D"
elif T[i+1]=="D":
ans+="P"
elif T[i+1]=="?":
ans+="P"
elif i!=len(T)-1:
if ans[-1]=="P" and T[i+1]=="P":
ans+="D"
elif ans[-1]=="P" and T[i+1]=="D":
ans+="D"
elif ans[-1]=="P" and T[i+1]=="?":
ans+="D"
elif ans[-1]=="D" and T[i+1]=="P":
ans+="D"
elif ans[-1]=="D" and T[i+1]=="D":
ans+="P"
elif ans[-1]=="D" and T[i+1]=="?":
ans+="P"
else:
if ans[-1]=="P":
ans+="D"
else:
ans+="D"
print(ans) | 1 | 18,445,871,362,558 | null | 140 | 140 |
m = 100
x = int(input())
y = 0
while x >= m:
if x == m:
break
m = m + m // 100
y += 1
print(y)
| n,m = map(int,(input().split()))
a = []
s = []
for i in range(m):
s.append(0)
for i in range(n):
k = [int(i) for i in input().split()]
k.append(sum(k))
a.append(k)
for j in range(m):
s[j] += k[j]
s.append(sum(s))
a.append(s)
for j in a:
print(' '.join(map(str, j))) | 0 | null | 14,153,662,397,280 | 159 | 59 |
apex = ((1,2,3),
(1,4,2),
(1,5,4),
(1,3,5),
(2,1,4),
(2,3,1),
(2,6,3),
(2,4,6),
(3,1,2),
(3,5,1),
(3,6,5),
(3,2,6),
(4,1,5),
(4,2,1),
(4,6,2),
(4,5,6),
(5,3,6),
(5,1,3),
(5,4,1),
(5,6,4),
(6,3,2),
(6,5,3),
(6,4,5),
(6,2,4)
)
dice = {}
label = []
label[:] = map(int,input().split())
#print('label: {}'.format(label))
for i in range(0,6):
dice[label[i]] = i+1
#print('dice: {}'.format(dice))
q = int(input())
for _ in range(0,q):
numbers = []
numbers[:] = map(int,input().split())
right = 0
for t in apex:
if (t[0] == dice[numbers[0]] and t[1] == dice[numbers[1]]):
right = t[2]
#print('{} {} {}'.format(t[0],t[1],t[2]))
break
for key, n in dice.items():
if (n == right):
print(key)
break
| k=int(input())
if k%2==0 or k%5==0:
print(-1)
exit()
ans=1
num=7
while num%k!=0:
num=10*num+7
num%=k
ans+=1
print(ans) | 0 | null | 3,138,188,790,880 | 34 | 97 |
#abc176b
N=input()
s=0
for i in range(len(N)):
s+=int(N[i])
if s%9==0:
print('Yes')
else:
print('No')
| from sys import stdin, setrecursionlimit
def main():
input = stdin.buffer.readline
a = map(int, input().split())
if sum(a) >= 22:
print('bust')
else:
print('win')
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| 0 | null | 61,478,653,719,652 | 87 | 260 |
import math
A, B, C, D = map(int, input().split())
print('Yes') if math.ceil(A / D) >= math.ceil(C / B) else print('No') | def input_int():
return map(int, input().split())
def one_int():
return int(input())
def one_str():
return input()
def many_int():
return list(map(int, input().split()))
N=one_int()
S=one_str()
bit_count = S.count("1")
S_num = int(S,2)
S_min = S_num % (bit_count-1) if bit_count-1!=0 else 0
S_plu = S_num % (bit_count+1)
# calc_dict = {i:-1 for i in range(10000)}
# res_dict = {i:-1 for i in range(10**4)}
# for i in range(1, 10000):
# if calc_dict[i]==-1:
# calc_dict[i] = bin(i).count("1")
# res_dict[i] = i%calc_dict[i]+1
def mods(temp, count):
count+=1
if temp!=0:
# if temp in res_dict:
# return count+res_dict[temp]
# if temp not in calc_dict:
# calc_dict[temp]= bin(temp).count("1")
count = mods(temp%bin(temp).count("1") , count)
return count
for i in range(N):
if S[i]=="0":
part = pow(2, (N-i-1), bit_count+1)
num = (S_plu + part ) % (bit_count+1)
print(mods(num, 0))
else:
if S_num == 2**(N-i-1):
print(0)
continue
part = pow(2, (N-i-1), bit_count-1)
num = (S_min - part)%(bit_count-1)
print(mods(num, 0))
| 0 | null | 18,971,669,901,778 | 164 | 107 |
# coding : utf-8
import math as m
r = float(input())
print ('{0:.6f} {1:.6f}'.format(r*r*m.pi, 2*r*m.pi))
| import math
r = float(input())
S = math.pi * (r**2)
l = 2 * math.pi * r
print("{} {}".format(S, l))
| 1 | 633,812,721,480 | null | 46 | 46 |
n=int(input())
a=list(map(int,input().split()))
ans=0
step=0
for i in range(n-1):
if a[i]+step<=a[i+1]:
step=0
else:
ans+=a[i]+step-a[i+1]
step=a[i]+step-a[i+1]
print(ans) | import sys
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x%y)
def lcm(x, y):
return x * y //gcd(x,y)
for line in sys.stdin:
x, y = map(int, line.split())
print(gcd(x, y), lcm(x,y)) | 0 | null | 2,264,469,619,072 | 88 | 5 |
n = int(input())
aas = list(map(int, input().split()))
if n == 1 and aas == [1]:
print(0)
exit()
t = 0
for i in aas:
if i == t + 1:
t += 1
print(n-t if t > 0 else -1) | n=int(input())
a=list(map(int,input().split()))
x=1
ans=0
for i in a:
if i!=x:
ans+=1
else:
x+=1
if x==1:
print(-1)
else:
print(ans)
| 1 | 115,078,611,093,344 | null | 257 | 257 |
s = input()
n = len(s)
L=[0]
R=[0]
cnt = 0
for i in range(n):
if s[i] == '<':
cnt += 1
else:
cnt = 0
L.append(cnt)
cnt = 0
s = s[::-1]
for i in range(n):
if s[i] == '>':
cnt += 1
else:
cnt = 0
R.append(cnt)
R = R[::-1]
ans = 0
for i in range(n+1):
ans += max(R[i], L[i])
print(ans) | #!/usr/bin/env python3
s = input()
c = 0
a = 0
p = ""
n = 0
for i in s:
if i != p:
if i == "<":
if c < 0:
a -= c * n
else:
a -= c * (n - 1)
n = 2
c = 1
else:
n = 2
c -= 1
else:
if i == "<":
c += 1
n += 1
else:
c -= 1
n += 1
a += c
p = i
if p == ">":
if c < 0:
a -= c * n
else:
a -= c * (n - 1)
print(a)
| 1 | 156,871,850,218,400 | null | 285 | 285 |
x = int(input())
print(int(not x))
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
X = int(input())
print(X ^ 1)
if __name__ == "__main__":
main()
| 1 | 2,897,748,646,492 | null | 76 | 76 |
a, b, c = map(int, raw_input().split())
temp = 0
if c < a:
temp = c
c = a
a = temp
if c < b:
temp = b
b = c
c = temp
if b < a:
temp = a
a = b
b = temp
print '{0} {1} {2}'.format(a, b, c) | import sys
prm = sys.stdin.readline()
prm = prm.split()
prm.sort()
a = int(prm[0])
b = int(prm[1])
c = int(prm[2])
print a, b, c | 1 | 422,719,581,570 | null | 40 | 40 |
import math
#入力:N,M(int:整数)
def input2():
return map(int,input().split())
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
return list(map(int,input().split()))
n,x,t=input2()
ans=(math.ceil(n/x))*t
print(ans) | n, x, t = map(int, input().split())
if n % x == 0:
res = int((n / x) * t)
else:
res = int(((n // x) + 1) * t)
print(res)
| 1 | 4,258,242,896,270 | null | 86 | 86 |
a, b, c = map(int, input().split())
k = int(input())
ans = 0
for i in range(10**5):
if a < b*(2**i):
b = b*(2**i)
break
ans += 1
for i in range(10**5):
if b < c*(2**i):
break
ans += 1
if ans <= k:
print('Yes')
else:
print('No') | r, g, b = map(int, input().split())
k = int(input())
for i in range(k):
if r >= g:
g *= 2
elif g >= b:
b *= 2
print('Yes' if r < g < b else 'No')
| 1 | 6,903,180,722,100 | null | 101 | 101 |
n = int(input())
list_ = [0]*n
joshi_list = list(map(int, input().split()))[::-1]
for i,num in enumerate(joshi_list):
list_[num-1]+=1
for num in list_:
print(num) | h,w=map(int,input().split())
s=[0]*h
t=[0]*h
for i in range(h):
st=str(input())
st=list(st)
s[i]=st
tt=[0]*w
t[i]=tt
if s[0][0]=="#":
t[0][0]=1
for i in range(1,h):
t[i][0]=t[i-1][0]
if s[i-1][0]=="." and s[i][0]=="#":
t[i][0]=t[i-1][0]+1
for i in range(1,w):
t[0][i]=t[0][i-1]
if s[0][i-1]=="." and s[0][i]=="#":
t[0][i]=t[0][i-1]+1
for i in range(1,w):
for j in range(1,h):
if s[j-1][i]=="." and s[j][i]=="#":
t1=t[j-1][i]+1
else:
t1=t[j-1][i]
if s[j][i-1]=="." and s[j][i]=="#":
t2=t[j][i-1]+1
else:
t2=t[j][i-1]
t[j][i]=min(t1,t2)
print(t[h-1][w-1]) | 0 | null | 40,954,175,825,152 | 169 | 194 |
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N, u, v = map(int, input().split())
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b = map(int, input().split())
edge[a].append(b)
edge[b].append(a)
def calc_dist(s):
dist = [-1] * (N + 1)
dist[s] = 0
node = [s]
while node:
s = node.pop()
d = dist[s]
for t in edge[s]:
if dist[t] != -1:
continue
dist[t] = d + 1
node.append(t)
return dist[1:]
taka = calc_dist(u)
aoki = calc_dist(v)
ans = 0
for x, y in zip(taka, aoki):
if x <= y:
ans = max(ans, y - 1)
print(ans)
| ma = lambda :map(int,input().split())
n,u,v = ma()
u,v = u-1,v-1
tree = [[] for i in range(n)]
import collections
for i in range(n-1):
a,b = ma()
tree[a-1].append(b-1)
tree[b-1].append(a-1)
que = collections.deque([(v,0)])
vis = [False]*n
dist_v = [0]*n
while que:
now,c = que.popleft()
vis[now] = True
dist_v[now] = c
for node in tree[now]:
if not vis[node]:
que.append((node,c+1))
que = collections.deque([(u,0)])
vis = [False]*n
dist_u = [0]*n
while que:
now,c = que.popleft()
vis[now] = True
dist_u[now] = c
for node in tree[now]:
if not vis[node]:
que.append((node,c+1))
ans = 0
for i in range(n):
if dist_u[i] < dist_v[i]:
ans = max(ans,dist_v[i])
print(ans-1)
| 1 | 117,755,011,570,652 | null | 259 | 259 |
import math
def insertionsort(A, n, g):
cnt = 0
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j + g] = A[j]
j = j - g
cnt += 1
A[j + g] = v
return cnt
def shellsort(A, n):
G = []
gap = 1
while gap <= math.ceil(n / 3):
G.append(gap)
gap = gap * 3 + 1
G = G[::-1]
m = len(G)
print(m)
print(*G)
cnt = 0
for i in range(m):
cnt += insertionsort(A, n, G[i])
print(cnt)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellsort(A, n)
for i in range(n):
print(A[i]) | n = int(input())
A = [None] * n
for i in range(n):
A[i] = int(input())
def insertionSort(A, n, g):
cnt = 0
for i in range(g, n, 1):
# Insertion Sort
# e.g. if g == 4 and i == 8: [4] 6 2 1 [10] 8 9 5 [3] 7
j = i - g # e.g. j = 4
k = i # e.g. k = 8
while j >= 0 and A[j] > A[k]:
#print("i:{} j:{} k:{} A:{}".format(i, j, k, A))
A[j], A[k] = A[k], A[j]
k = j # e.g. k = 4
j = k - g # e.g. j = 4 - 0 = 0
cnt += 1
#print("j reduced to {}, k reduced to {}".format(j, k))
return(cnt)
def shellSort(A, n):
g = [0]
m = 0
sum = 0
while True:
if (3*m + 1 <= n):
g.insert(0, 3*m + 1)
m = 3*m + 1
else:
break
for i in range(len(g)):
cnt = insertionSort(A, n, g[i])
sum += cnt
print(len(g))
print(str(g).replace('[', '').replace(']', '').replace(',', ''))
print(sum)
for i in range(n):
print(A[i])
def main():
shellSort(A, n)
main()
| 1 | 30,382,386,904 | null | 17 | 17 |
x = int(input())
#print(1 if x == 0 else 0)
print(x ^ 1)
| x,y,a,b,c=map(int,input().split())
plist=list(map(int,input().split()))
qlist=list(map(int,input().split()))
rlist=list(map(int,input().split()))
plist.sort()
qlist.sort()
rlist.sort(reverse=True)
pgensen=plist[a-x:]
qgensen=qlist[b-y:]
tmplist=pgensen+qgensen
tmplist.sort()
replacesum=0
for i in range(min(x+y,len(rlist))):
if tmplist[i] >= rlist[i]:
break
else:
replacesum+=rlist[i]-tmplist[i]
print(sum(tmplist)+replacesum)
| 0 | null | 23,759,547,236,128 | 76 | 188 |
from collections import deque
INFTY = 10**6
N,u,v = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
a,b = map(int,input().split())
G[a].append(b)
G[b].append(a)
du = [INFTY for _ in range(N+1)]
du[u] = 0
que = deque([(0,u)])
hist = [0 for _ in range(N+1)]
hist[u] = 1
while que:
c,i = que.popleft()
for j in G[i]:
if hist[j]==0:
que.append((c+1,j))
du[j] = c+1
hist[j] = 1
dv = [INFTY for _ in range(N+1)]
dv[v] = 0
que = deque([(0,v)])
hist = [0 for _ in range(N+1)]
hist[v] = 1
while que:
c,i = que.popleft()
for j in G[i]:
if hist[j]==0:
que.append((c+1,j))
dv[j] = c+1
hist[j] = 1
cmax = 0
for i in range(1,N+1):
if du[i]<dv[i]:
cmax = max(cmax,dv[i])
print(cmax-1) |
def main():
params = [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]
return params[int(input())-1]
print(main()) | 0 | null | 83,593,808,831,808 | 259 | 195 |
# import sys
# input = sys.stdin.readline
import collections
def main():
n = int(input())
s = input()
a_list = []
for i in range(n):
if s[i] == "W":
a_list.append(0)
else:
a_list.append(1)
r_count = sum(a_list)
print(r_count - sum(a_list[0:r_count]))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| n = int(input())
C = list(input())
if "R" not in C:
print(0)
exit()
W = C.count("W")
R = C.count("R")
w = 0
r = R
ans = float('inf')
for c in C:
if c == "W":
w += 1
else:
r -= 1
ans = min(ans, max(w, r))
print(ans) | 1 | 6,294,944,253,030 | null | 98 | 98 |
import math
import itertools
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
digits = sums = 0
while num > 0:
digits += 1
sums += num % 10
num //= 10
return digits, sums
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
pidx, qidx = 0, 0
candidates = list(itertools.permutations(range(1, n+1), n))
for index, candidate in enumerate(candidates):
candidate = list(candidate)
if candidate == p:
pidx = index
if candidate == q:
qidx = index
print(abs(pidx - qidx))
| '''
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') | 0 | null | 51,169,157,098,582 | 246 | 64 |
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
class Twelveways:
def __init__(self,n,m=10**9+7):
self.num = n
self.mod = m
self.f = self.factorials()
self.g = self.inverse()
def factorials(self):
# 0~n!のリスト
f = [1, 1]
for i in range(2, self.num + 1):
f.append(f[-1] * i % self.mod)
return f
def inverse(self):
# 0~n!の逆元のリスト
g = [1]
for i in range(self.num):
g.append(pow(self.f[i + 1], self.mod - 2, self.mod))
return g
def combination(self, n, k):
# nCk mod mを求める
nCk = self.f[n] * self.g[n - k] * self.g[k]
nCk %= self.mod
return nCk
s = readint()
mod = 10**9+7
a = Twelveways(s)
ans = 0
for i in range(1,s//3+1):
ans += a.combination(s-3*i+i-1,i-1)
print(ans%mod)
| import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline # 文字列読み込む時はこっち
import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)
ra = range
enu = enumerate
def exit(*argv, **kwarg):
print(*argv, **kwarg)
sys.exit()
def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def a_int(): return int(readline())
def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)
def read_matrix(H, W):
'''return np.ndarray shape=(H,W) matrix'''
lines = []
for _ in range(H):
lines.append(read())
lines = ' '.join(lines) # byte同士の結合ができないのでreadlineでなくreadで
return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)
def read_col(H):
'''H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合'''
ret = []
for _ in range(H):
ret.append(list(map(int, readline().split())))
return tuple(map(list, zip(*ret)))
def read_tuple(H):
'''H is number of rows'''
ret = []
for _ in range(H):
ret.append(tuple(map(int, readline().split())))
return ret
MOD = 10**9 + 7
INF = 2**31 # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right # , insort_left, insort_right
from functools import reduce
from math import gcd
def lcm(a, b):
# 最小公倍数
g = gcd(a, b)
return a // g * b
S = a_int()
'''
dp[i,j] ... 問題文の条件を満たし和がiとなる数列の通りの総数。j回前に仕切りを立てた場合の。(j=2のときは2回前以前を示すことにする)
更新
# iに仕切りを立てるとき
dp[i, 0] += dp[i-1, 2] #ここから仕切りが立てられる
# iに仕切りを立てないとき
dp[i, 0] += 0 #立てないんだから
dp[i, 1] += dp[i-1,0]
dp[i, 2] += dp[i-1,1] + dp[i-1,2]
'''
from numba import njit
@njit('(i8,)', cache=True)
def solve(S):
dp = np.zeros((S + 1, 3), dtype=np.int64)
dp[0, 0] = 1
for i in range(1, S + 1):
dp[i, 0] += dp[i - 1, 2] % MOD
dp[i, 1] += dp[i - 1, 0] % MOD
dp[i, 2] += (dp[i - 1, 1] + dp[i - 1, 2]) % MOD
print(dp[S, 0] % MOD)
solve(S)
| 1 | 3,320,889,704,330 | null | 79 | 79 |
h, a = map(int, input().split())
print( - ( - h // a))
| a,b=sorted(list(map(int, input().split())))
m=b%a
while m>=1:
b=a
a=m
m=b%a
print(a) | 0 | null | 38,249,660,692,900 | 225 | 11 |
print " ".join(sorted(map(str, map(int, raw_input().split(" "))))) | print(*sorted(input().split())) | 1 | 419,539,653,210 | null | 40 | 40 |
import sys
input = sys.stdin.readline
def inps():
return str(input())
s = inps().rsplit()[0]
t = inps().rsplit()[0]
cnt = 0
for i in range(len(s)):
if s[i]!=t[i]:
cnt+=1
print(cnt)
| x = int(input())
money1 = x // 500
x %= 500
money2 = x // 5
ans = money1 * 1000 + money2 * 5
print(ans) | 0 | null | 26,680,954,827,378 | 116 | 185 |
HP, N = map(int, input().split())
ATK = list(map(int, input().split()))
print('Yes' if sum(ATK) >= HP else 'No') | import sys
input = sys.stdin.readline
A = list(map(int, input().split()))
if sum(A) >= 22:
print('bust')
else:
print('win')
| 0 | null | 98,482,722,163,056 | 226 | 260 |
import math
def main():
v = list(map(int, input().split()))
n = v[0]
a = v[1]
b = v[2]
answer = 0
if n < a:
answer = n
elif n < a+b:
answer = a
elif a == 0 and b == 0:
answer = 0
else:
answer += math.floor(n / (a+b)) * a
rest = n % (a+b)
if rest <= a:
answer += rest
else:
answer += a
print(answer)
if __name__ == "__main__":
main()
| N = int(input())
A = list(map(int,input().split()))
ans = 1000
for i in range(N-1):
if A[i] < A[i+1]:
ans += ans // A[i] * (A[i+1] - A[i])
print(ans) | 0 | null | 31,635,959,327,982 | 202 | 103 |
Subsets and Splits