code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
a,b,c = [int(i) for i in input().split()]
d = []
for i in range(1,int(c**0.5)+1):
if i **2 == c:
d.append(i)
continue
if c%i == 0:
d.extend([i,c//i])
d.sort()
e = [i for i in d if a<=i<=b]
print(len(e))
|
number_list=[int(i) for i in input().split()]
counter=0
for r in range(number_list[0],number_list[1]+1):
if number_list[2]%r==0:
counter+=1
print(counter)
| 1 | 559,832,285,380 | null | 44 | 44 |
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = [0]
bb = [0]
for s in range(n):
aa.append(aa[s] + a[s])
for s in range(m):
bb.append(bb[s] + b[s])
ans = 0
j = m
for i in range(n+1):
if aa[i] > k:
break
while bb[j] > k - aa[i]:
j -= 1
ans = max(ans, i+j)
print(ans)
|
import sys
import math
import itertools
import collections
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N, M, K = NMI()
A = NLI()
B = NLI()
cumsum_A = [0 for _ in range(len(A)+1)]
cumsum_B = [0 for _ in range(len(B)+1)]
cnt = 0
for n in range(N):
cnt += A[n]
cumsum_A[n+1] = cnt
cnt = 0
for m in range(M):
cnt += B[m]
cumsum_B[m+1] = cnt
ans = 0
b= M
for n in range(N+1):
remain_K = K - cumsum_A[n]
if remain_K < 0:
break
else:
for m in range(b,-1,-1):
if cumsum_B[m]> remain_K:
continue
else:
b = m
ans = max(ans,n+m)
break
print(ans)
if __name__ == '__main__':
main()
| 1 | 10,768,792,884,388 | null | 117 | 117 |
while True:
try:
m,f,r = map(int,input().split(" "))
if m == -1:
if f == -1:
if r == -1:
break
if m == -1 or f == -1:
print("F")
continue
if m+f >= 80:
print("A")
if m+f >= 65 and m+f < 80:
print("B")
if m+f >= 50 and m+f < 65:
print("C")
if m+f >= 30 and m+f < 50:
if r >= 50:
print("C")
else:
print("D")
if m+f < 30:
print("F")
except EOFError:
break
|
x = 0
m_list = []
f_list = []
r_list = []
while x < 50:
m, f, r = map(int, input().split())
if m == -1 and f == -1 and r == -1:
break
m_list.append(m)
f_list.append(f)
r_list.append(r)
x = x+1
for(mlist,flist,rlist) in zip(m_list,f_list,r_list):
if mlist == -1 or flist == -1:
print("F")
elif 80 <= mlist + flist:
print("A")
elif 65 <= mlist + flist and mlist + flist < 80:
print("B")
elif 50 <= mlist + flist and mlist + flist < 65:
print("C")
elif 30 <= mlist + flist and mlist + flist < 50:
if 50 <= rlist:
print("C")
else:
print("D")
elif mlist + flist < 30:
print("F")
| 1 | 1,201,355,617,500 | null | 57 | 57 |
N = input()
S = {"SUN":"7", "MON": "6", "TUE": "5", "WED": "4", "THU": "3", "FRI": "2", "SAT": "1"}
print(S[N])
|
s = input()
youbi = {"SUN":"7", "MON":"6", "TUE":"5", "WED":"4","THU":"3","FRI":"2", "SAT": "1"}
print(youbi[s])
| 1 | 133,397,517,941,660 | null | 270 | 270 |
N = int(input())
cnt = 0
for A in range(1, N + 1):
for B in range(1, N // A + 1):
C = N - A * B
if C >= 1 and A * B + C == N:
cnt += 1
print(cnt)
|
import sys
#fin = open("test.txt", "r")
fin = sys.stdin
n = int(fin.readline())
d = {}
for i in range(n):
op, str = fin.readline().split()
if op == "insert":
d[str] = 0
else:
if str in d:
print("yes")
else:
print("no")
| 0 | null | 1,310,862,204,988 | 73 | 23 |
N,u,v = map(int,input().split())
u -= 1
v -= 1
data = [[] for _ in range(N)]
for i in range(N-1):
A,B = map(int,input().split())
A -= 1
B -= 1
data[A].append(B)
data[B].append(A)
#print(data)
stack = [[u,u]]
taka_dis = [0] * N
while stack:
x = stack.pop()
#print(x)
for y in data[x[1]]:
if y == x[0]:
continue
else:
stack.append([x[1],y])
taka_dis[y] = taka_dis[x[1]] + 1
#print(stack)
stack = [[v,v]]
aoki_dis = [0] * N
while stack:
x = stack.pop()
for y in data[x[1]]:
if y == x[0]:
continue
else:
stack.append([x[1],y])
aoki_dis[y] = aoki_dis[x[1]] + 1
can = [0] * N
for i in range(N):
if aoki_dis[i] - taka_dis[i] > 0:
can[i] = aoki_dis[i]
else:
can[i] = 0
#print(aoki_dis)
#print(taka_dis)
#print(can)
print(max(can) -1 )
|
N = int(input())
res = 0
for i in range(int(N**0.5)):
if(N % (i+1) == 0):
res = max(res, i+1)
print((res-1) + (N//res-1))
| 0 | null | 139,738,856,017,430 | 259 | 288 |
n = input()
S = map(int,raw_input().split())
q = input()
T = map(int,raw_input().split())
ans = 0
for t in T:
if t in S:
ans+=1
print ans
|
def linear_search(A, n, key):
A.append(key)
i = 0
while A[i] != key:
i += 1
A.pop()
return i != n
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for t in T:
if linear_search(S, n, t):
ans += 1
print(ans)
| 1 | 70,007,054,140 | null | 22 | 22 |
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')
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def solve(A, B, C, K):
while A >= B:
K -= 1
B *= 2
while B >= C:
K -= 1
C *= 2
if K >= 0:
return "Yes"
return "No"
def main():
# parse input
A, B, C = map(int, input().split())
K = int(input())
print(solve(A, B, C, K))
# tests
T1 = """
7 2 5
3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
Yes
"""
T2 = """
7 4 2
3
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
No
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
main()
| 1 | 6,877,063,479,800 | null | 101 | 101 |
import math
a,b,x=map(int,input().split())
if x<a*a*b/2:
t=a*b*b/2/x
else:
t=2*b/a-2*x/(a**3)
print(math.atan(t)/math.pi*180)
|
import math
a, b, x = [int(i) for i in input().split()]
if a**2 * b / 2 <= x:
y = 2 * x / a**2 - b
tntheta = (b - y) / a
else:
y = a - 2 * x / (a * b)
tntheta = b / (a - y)
print(math.degrees(math.atan(tntheta)))
| 1 | 163,227,916,636,750 | null | 289 | 289 |
S = str(input())
S1 = S.replace("hi", "")
if S1 == "":
print("Yes")
else:
print("No")
|
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
x = [0] * (N + 1)
y = [0] * (M + 1)
for i in range(N):
x[i + 1] = x[i] + A[i]
for i in range(M):
y[i + 1] = y[i] + B[i]
j = M
ans = 0
for i in range(N + 1):
if x[i] > K:
continue
while j >= 0 and x[i] + y[j] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
| 0 | null | 31,879,793,904,850 | 199 | 117 |
a,b,m = map(int,input().split())
r = tuple(map(int,input().split()))
d = tuple(map(int,input().split()))
ans = min(r)+min(d)
for i in range(m):
x,y,c = map(int,input().split())
ans = min(ans,r[x-1]+d[y-1]-c)
print(ans)
|
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
def two(val):
ret = 0
tmp = val
while True:
if tmp != 0 and tmp % 2 == 0:
ret += 1
tmp = tmp // 2
else:
break
return ret
n, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = []
for item in a_list:
b_list.append(item // 2)
cnt = -1
for item in b_list:
ret = two(item)
if cnt == -1:
cnt = ret
elif cnt != ret:
print(0)
exit()
val = b_list[0]
for item in b_list:
val = lcm(item, val)
ret = m // val
tmp1 = ret // 2
tmp2 = ret % 2
print(tmp1 + tmp2)
| 0 | null | 78,298,063,775,680 | 200 | 247 |
N = int(input())
a = N // 100
if 0 <= N - 100 * a <= 5 * a:
print(1)
else:
print(0)
|
x=int(input())
if x%100>(x//100)*5:
print(0)
else:
print(1)
| 1 | 126,803,793,066,500 | null | 266 | 266 |
# -*- coding: utf-8 -*-
def selection_sort(a, n):
count = 0
for i in range(n):
minj = i
for j in range(i+1, n):
if a[j] < a[minj]:
minj = j
a[i], a[minj] = a[minj], a[i]
if a[i] != a[minj]:
count += 1
return a, count
def main():
input_num = int(input())
input_list = [int(i) for i in input().split()]
ans_list, count = selection_sort(input_list, input_num)
for i in range(input_num):
if i != 0:
print(" ", end="")
print(ans_list[i], end='')
print()
print(count)
if __name__ == '__main__':
main()
|
A, B = map(int, input().split())
s = add = max(A, B)
while True:
if s % A == 0 and s % B == 0:
break
s += add
print(s)
| 0 | null | 56,584,549,197,700 | 15 | 256 |
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))
|
def main():
from itertools import permutations
from math import hypot
N = int(input())
xys = []
for _ in range(N):
x, y = map(int, input().split())
xys.append((x, y))
ans = 0
for perm in permutations(xys, r=2):
x1, y1 = perm[0]
x2, y2 = perm[1]
d = hypot(x2 - x1, y2 - y1)
ans += d
ans /= N
print(ans)
if __name__ == '__main__':
main()
| 1 | 148,298,367,046,132 | null | 280 | 280 |
def solve():
m1, d1, m2, d2 = map(int, open(0).read().split())
if m1 != m2:
print('1')
else:
print('0')
solve()
|
h1, m1, h2, m2, k = map(int, input().split())
st = h1 * 60 + m1
ed = h2 * 60 + m2
ans = ed - st - k
if ans < 0:
ans = 0
print(ans)
| 0 | null | 71,033,382,183,904 | 264 | 139 |
str = input()
n = int(input())
for i in range(n):
args = input().split()
command = args[0]
s = int(args[1])
e = int(args[2])
if command == 'print':
print(str[s:e + 1])
if command == 'reverse':
str = str[0:s] + str[s:e + 1][::-1] + str[e + 1:]
if command == 'replace':
str = str[0:s] + args[3] + str[e + 1:]
|
import sys
input = sys.stdin.readline
def main():
text = input().rstrip()
n = int(input().rstrip())
for i in range(n):
s = input().split()
if s[0] == "print":
print(text[int(s[1]):int(s[2])+1])
elif s[0] == "replace":
new_text = ""
new_text += text[:int(s[1])]
new_text += s[3]
new_text += text[int(s[2])+1:]
text = new_text
elif s[0] == "reverse":
new_text = ""
new_text += text[:int(s[1])]
for i in range(int(s[2])-int(s[1]) + 1):
new_text += text[int(s[2]) - i]
new_text += text[int(s[2])+1:]
text = new_text
if __name__ == "__main__":
main()
| 1 | 2,084,106,130,048 | null | 68 | 68 |
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
# chocoのj列目の0(white)の個数を数える
def count_col_whites(choco, j):
res = 0
for c in choco:
if c[j]=="1":
res += 1
return res
# チョコレートをヨコ方向にカットする
def cut_chocolate(i):
if i == 0:
return [S]
else:
res = []
pre = 0
tmp = 0
while i > 0:
tmp += 1
if i%2 == 1:
res.append(S[pre:tmp])
pre = tmp
i //= 2
res.append(S[pre:len(S)])
return res
def is_less_than_or_equal_to_K(cut):
for c in cut:
for j in range(W):
tmp = 0
for i in range(len(c)):
if c[i][j] == "1":
tmp += 1
if tmp > K:
return False
return True
ans = 10**10
for i in range(2**(H-1)):
# 横方向にカットしたときのかたまりをcutに格納
cut = cut_chocolate(i)
tmp_ans = len(cut)-1
# 縦方向にみていって、1列中の白チョコの個数がK個より大きければそもそも無理
if not is_less_than_or_equal_to_K(cut):
continue
# 縦方向にみていって、白チョコがK個以下のかたまりになるようカットする
current_white_nums = [0 for _ in range(len(cut))]
for j in range(W):
for i in range(len(cut)):
white_num = count_col_whites(cut[i], j)
if white_num + current_white_nums[i] <= K:
current_white_nums[i] += white_num
else:
current_white_nums = [count_col_whites(cut[_], j) for _ in range(len(cut))]
tmp_ans += 1
break
ans = min(ans, tmp_ans)
print(ans)
|
def cmb(n,r,mod):
if r<0 or r>n:
return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
k=int(input())
s=list(input())
n=len(s)
mod=10**9+7
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,2*10**6+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
pow25=[1]
for i in range(n+k+1):
pow25.append((pow25[-1]*25)%mod)
pow26=[1]
for i in range(n+k+1):
pow26.append((pow26[-1]*26)%mod)
ans=0
for i in range(n,n+k+1):
ans+=cmb(i-1,n-1,mod)*pow25[i-n]*pow26[n+k-i]
ans%=mod
print(ans)
| 0 | null | 30,556,355,690,340 | 193 | 124 |
x,y = map(int,input().split())
s = max(0,(4-x)*100000)+max(0,(4-y)*100000)
print(s if s!=600000 else s+400000)
|
n = str(input())
tmp = 0
for i in n:
tmp += int(i)
if tmp % 9 == 0:
print("Yes")
else:
print("No")
| 0 | null | 72,854,541,244,292 | 275 | 87 |
S = input()
youbi = ['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']
print(youbi.index(S) + 1)
|
import itertools
n = int(input())
a = list(itertools.accumulate(list(map(int, input().split()))))
sum_a = a[-1]
res = 2020202020
for i in range(n):
res = min(res, abs(sum_a - a[i]*2))
print(res)
| 0 | null | 137,399,133,019,808 | 270 | 276 |
S,T=map(str,input().split())
A,B=map(int,input().split())
U=str(input())
if S==U:
print(A-1)
print(B)
else:
print(A)
print(B-1)
|
s,t = input().split()
a,b = map(int,input().split())
u = input()
if s == u:
a -= 1
if t == u:
b -= 1
print(a,b)
| 1 | 71,933,093,241,402 | null | 220 | 220 |
import math
arr = input().split( )
a = int(arr[0])
b1, b2 = arr[1].split('.')
b = int(b1)*100 + int(b2)
print(a*b//100)
|
A,B=input().split()
A=int(A)
B=int(B[2:])+int(B[0])*100
print(A*B//100)
| 1 | 16,583,028,218,240 | null | 135 | 135 |
s = input()
n = len(s)
Ans = [0] * (n + 1)
top = set()
bottom = set()
if s[0] == ">":
top.add(0)
else:
bottom.add(0)
for i in range(len(s)-1):
left = s[i]
right = s[i+1]
if left == "<" and right == ">":
top.add(i+1)
elif left == ">" and right == "<":
bottom.add(i+1)
if s[n-1] == ">":
bottom.add(n)
else:
top.add(n)
for b in list(bottom):
counter = 0
for i in range(b, n+1):
if i in top:
break
else:
Ans[i] = counter
counter += 1
counter = 0
for i in range(b-1, -1, -1):
if i in top:
break
else:
Ans[i] = counter + 1
counter += 1
#print(Ans)
for t in list(top):
if t == 0:
Ans[0] = Ans[1] + 1
if t == n:
Ans[n] = Ans[n-1] + 1
else:
Ans[t] = max(Ans[t-1] + 1, Ans[t+1] + 1)
#print(top)
#print(bottom)
print(sum(Ans))
|
def main():
s = input()
n = len(s) + 1
ans = [-1] * (n)
def right(i, ans):
j = 1
while True:
ans[i + j] = max(ans[i + j], j)
if i + j == n - 1:
break
if s[i + j] == '<':
j += 1
else:
break
return ans
def left(i, ans):
j = 1
while True:
ans[i - j] = max(ans[i - j], j)
if i - j == 0:
break
if s[i - j - 1] == '>':
j += 1
else:
break
return ans
for i in range(n):
if i == 0:
if s[i] == '<':
ans[0] = 0
ans = right(i, ans)
else:
pass
elif i == n - 1:
if s[i - 1] == '>':
ans[n - 1] = 0
ans = left(i, ans)
else:
pass
else:
if s[i] == '<' and s[i - 1] == '>':
ans[i] = 0
ans = right(i, ans)
ans = left(i, ans)
else:
pass
print(sum(ans))
if __name__ == '__main__':
main()
| 1 | 155,774,614,005,280 | null | 285 | 285 |
from collections import deque
from sys import stdin
input = stdin.readline
N = int(input())
neighborlist = [None for _ in range(N+1)]
for _ in range(1, N+1):
node, _, *L = list(map(int, input().split()))
neighborlist[node] = L
distancelist = [-1]*(N+1)
queue = deque()
queue.append(1)
distancelist[1] = 0
while queue:
node = queue.popleft()
distance = distancelist[node]
for neighbor in neighborlist[node]:
if distancelist[neighbor] == -1:
distancelist[neighbor] = distance + 1
queue.append(neighbor)
for i in range(1, N+1):
print(i, distancelist[i])
|
from collections import deque
n = int(input())
adj = [0]*n # adjacent list
d = [-1]*n # distance from the source vertex
c = ['w']*n # the 'color' of each vertex
# receiving input (the structure of the graph)
for i in range(n):
tmp = list(map( int, input().split() ) )
adj[tmp[0]-1] = list(map(lambda x : x - 1, tmp[2:]))
# set the source vertex
s = 0
d[s] = 0
c[s] = 'g'
Q = deque()
Q.append(s)
while Q:
u = Q.popleft()
for v in adj[u]:
if c[v] == 'w':
c[v] = 'g'
d[v] = d[u] + 1
Q.append(v)
c[u] = 'b'
for i in range(n):
print(f'{i+1} {d[i]}')
| 1 | 4,243,072,130 | null | 9 | 9 |
from sys import stdin
input = stdin.readline
def main():
N = int(input())
if N % 2:
print(0)
return
nz = 0
i = 1
while True:
if N//(5**i)//2 > 0:
nz += (N//(5**i)//2)
i += 1
else:
break
print(nz)
if(__name__ == '__main__'):
main()
|
N=int(input())
if N % 2 or N < 10:
print(0)
exit()
ans = 0
i = 1
while 2*5**i<=N:
ans += N // (2*5**i)
i += 1
print(ans)
| 1 | 115,975,601,554,944 | null | 258 | 258 |
from math import atan, degrees
def is_divisible(a):
return 'Yes' if any(int(a/x) == a/x and a/x <= 9 for x in range(1,10)) and a <= 81 else 'No'
print(is_divisible(int(input())))
|
num = int(input())
data = list()
for i in range(1,10):
for j in range(1, 10):
data.append(i*j)
if num in data:
print('Yes')
else:
print('No')
| 1 | 159,163,839,403,258 | null | 287 | 287 |
A, B = map(int, input().split())
ans = 0
for i in range(10,1001):
if int(i*0.08) == A and int(i*0.1) == B:
ans = i
break
if ans == 0:
print(-1)
else:
print(i)
|
import sys
A, B = [int(x) for x in input().split()]
ans_A = 0
ans_B = 0
for i in range(1500):
ans_A = (i*8//100)
ans_B = (i//10)
if(ans_A==A)and(ans_B==B):
print(i)
sys.exit()
print(-1)
| 1 | 56,141,810,217,636 | null | 203 | 203 |
import math
A, B = map(int, input().split())
r = -1
for i in range(1, 1111):
if A == math.floor(i*0.08) and B == math.floor(i*0.10):
r = i
break
print(r)
|
import math
I = lambda: list(map(int, input().split()))
n, d, a = I()
l = []
for _ in range(n):
x, y = I()
l.append([x,y])
l.sort()
j = 0
limit = []
for i in range(n):
while l[j][0] - l[i][0] <= 2*d:
j+=1
if j == n: break
j-=1
limit.append(j)
ans = 0
num=[0]*(n+1)
cnt=0
for i in range(n):
l[i][1]-=(ans-cnt)*a
damage_cnt=max(0,(l[i][1]-1)//a + 1)
ans+=damage_cnt
num[limit[i]]+=damage_cnt
cnt+=num[i]
print(ans)
| 0 | null | 69,237,809,203,150 | 203 | 230 |
import sys
import math
a = []
for l in sys.stdin:
a.append(int(l))
h = a[0]
n = 0
while h > 1:
h = math.floor(h / 2)
n = n + 1
print(2 ** (n + 1) - 1)
|
N = int(input())
if(N % 2 == 0):
print(0.5000000000)
else:
M = (N+1)/2
print(M/N)
| 0 | null | 128,255,433,006,468 | 228 | 297 |
a = input('')
S = []
num = 0
for i in a:
S.append(i)
for j in range(3):
if S[j] == 'R':
num += 1
if num == 2 and S[1] == 'S':
print(1)
else:
print(num)
|
import sys
from collections import Counter
N = int(sys.stdin.readline().rstrip())
D = list(map(int, sys.stdin.readline().rstrip().split()))
mod = 998244353
if D[0] != 0 or 0 in D[1:]:
print(0)
exit()
d_cnt = sorted(Counter(D).items())
ans = 1
par = 1
prev = 0
for k, v in d_cnt:
if k > 0:
if prev + 1 == k:
ans *= pow(par, v, mod)
ans %= mod
par = v
prev = k
else:
print(0)
exit()
print(ans)
| 0 | null | 79,928,860,065,262 | 90 | 284 |
target = input()
now_height = []
now_area = [0]
answer = []
continued = 0
depth = 0
depth_list = []
for t in target:
# print(now_height,depth_list,now_area,answer,continued)
if t == '\\':
now_height.append(continued)
depth_list.append(depth)
now_area.append(0)
depth -= 1
elif t == '_':
pass
elif t == '/' and len(now_height) > 0:
depth += 1
started = now_height.pop()
temp_area = continued - started
# print(depth_list[-1],depth)
now_area[-1] += temp_area
if depth > depth_list[-1]:
while depth > depth_list[-1]:
temp = now_area.pop()
now_area[-1] += temp
depth_list.pop()
continued += 1
now_area = list(filter(lambda x:x != 0,now_area))
answer.extend(now_area)
print(sum(answer))
print(len(answer),*answer)
|
s = input()
length = len(s)
a = [0] * (length + 1)
b = [0] * length
y = 0
for i in range(length):
if s[i] == '/':
y += 1
elif s[i] == '\\':
y -= 1
a[i + 1] = y
m = -30000
for i in range(length, 0, -1):
m = max(m, a[i])
b[i - 1] = m
i = 0
memory = []
while i < length:
if a[i] > b[i]:
i += 1
continue
start = a[i]
i += 1
base = 1
d_from = s[i - 1]
ws_part = 0
while i < length + 1 and a[i] < start:
d_to = s[i]
ws_part += base
if d_from == '\\' and d_to == '\\':
base += 2
if d_from == '\\' and d_to == '_':
base += 1
if d_from == '/' and d_to == '/':
base -= 2
if d_from == '/' and d_to == '_':
base -= 1
if d_from == '_' and d_to == '\\':
base += 1
if d_from == '_' and d_to == '/':
base -= 1
d_from = d_to
i += 1
if ws_part > 0:
ws_part += 1
memory.append(ws_part // 2)
print(sum(memory))
if memory:
print(len(memory), ' '.join(map(str, memory)))
else:
print(len(memory))
| 1 | 61,623,052,260 | null | 21 | 21 |
N = int(input())
p = [list(map(int,input().split())) for _ in range(N)]
z = []
w = []
for i in range(N):
z.append(p[i][0] + p[i][1])
w.append(p[i][0] - p[i][1])
print(max(max(z)-min(z),max(w)-min(w)))
|
n=int(input())
i=1
c=0
while(n>=1):
c+=i
i*=2
n//=2
print(c)
| 0 | null | 41,971,194,032,920 | 80 | 228 |
K = int(input())
S = input()
s = len(S)
base = 10 ** 9 + 7
L26 = [ 1 for i in range(K+1)] # 26^i mod base
for i in range(K):
L26[i+1] = (L26[i] * 26) % base
T1 = 1
T2 = 1
ans = 0
for i in range( s, s+K+1):
T3 = L26[K + s - i]
#T4 = pow(26, K + s - i, base)
#print(T3, T4)
p = (T1 * T2) % base
p = (p * T3) % base
ans += p
ans %= base
#print(ans, T1, T2, T3)
T1 *= 25
T1 %= base
# T2 = (T2 * i ) // (i+1-s) # T2 = (i, s-1) = (i-1, s-1) * i // (i+1-s)
T2 *= i
T2 %= base
T2 *= pow(i+1-s, base-2, base)
T2 %= base
print(ans % base)
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
LB = A[-1] * 2 # 一回の握手で上がる幸福度の下限は、左手も右手もパワーが一番低い人を握った場合
UB = A[0] * 2 # 一回の握手で上がる幸福度の上限は、左手も右手もパワーが一番高い人を握った場合
# cgs[i] は パワーがi以上のゲストの数
cgs = [0] * (UB + 1)
for a in A:
cgs[a] += 1
for i in range(UB, 0, -1):
cgs[i - 1] += cgs[i]
# 組み合わせの数がM以上になる一回で発生する幸福度の閾値を二分探索する
def is_ok(n):
m = 0
for a in A:
m += cgs[max(n - a, 0)]
return m >= M
ok = LB
ng = UB + 1
while ng - ok > 1:
m = (ok + ng) // 2
if is_ok(m):
ok = m
else:
ng = m
# cps[i] は A[0]~A[i] の累積和
cps = A[:]
for i in range(1, N):
cps[i] += cps[i - 1]
result = 0
for a in A:
# 左手固定
t = cgs[max(ok - a, 0)] # 握手すると閾値を超えるひとたち
if t != 0:
result += a * t + cps[t - 1] # 1人目pとu回握手 + 右手はu人までと握手
M -= t
result += ok * M # 閾値上の人の処理
print(result)
| 0 | null | 60,203,883,993,628 | 124 | 252 |
bingo = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
for _ in range(N):
b = int(input())
for i in range(3):
for j in range(3):
if bingo[i][j] == b:
bingo[i][j] = 0
ans = "No"
for k in range(3):
if bingo[k][0] == bingo[k][1] == bingo[k][2] or \
bingo[0][k] == bingo[1][k] == bingo[2][k]:
ans = "Yes"
break
if bingo[0][0] == bingo[1][1] == bingo[2][2] or \
bingo[0][2] == bingo[1][1] == bingo[2][0]:
ans = "Yes"
print(ans)
|
s=input()
n=len(s)
x=s[0:(n-1)//2]
y=s[(n+3)//2-1:n]
if x==x[::-1] and y==y[::-1] and s==s[::-1]:
print('Yes')
else:
print('No')
| 0 | null | 53,244,707,461,142 | 207 | 190 |
def main():
n = int(input())
a_list = []
b_list = []
for _ in range(n):
a, b = map(int, input().split())
a_list.append(a)
b_list.append(b)
a_sorted = list(sorted(a_list))
b_sorted = list(sorted(b_list))
if n%2:
print(b_sorted[n//2]-a_sorted[n//2]+1)
else:
print((b_sorted[n//2-1]+b_sorted[n//2]-a_sorted[n//2-1]-a_sorted[n//2])+1)
if __name__ == "__main__":
main()
|
def main():
a = []
for i in range(10):
a.append(int(input()))
a.sort()
a.reverse()
for i in range(3):
print(a[i])
if __name__ == '__main__':
main()
| 0 | null | 8,732,924,463,300 | 137 | 2 |
a, b = map(int, input().split())
print(a * b, (a + b) << 1)
|
N = int(input())
A = []
B = []
for _ in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
def median(arr):
arr.sort()
n = len(arr)
if n % 2 == 1:
return arr[(n + 1) // 2 - 1]
else:
return (arr[n//2 - 1] + arr[n//2]) / 2
med_a = median(A)
med_b = median(B)
if N % 2 == 1:
ans = int(med_b) - int(med_a) + 1
else:
ans = med_b * 2 - med_a * 2 + 1
ans = int(ans)
print(ans)
| 0 | null | 8,884,165,429,230 | 36 | 137 |
N = int(input())
if N % 2 == 0:
ans = int(N / 2) - 1
else:
ans = int(N / 2)
print('{}'.format(ans))
|
n = int(input())
print((n - (n+1)%2)//2)
| 1 | 153,672,263,329,692 | null | 283 | 283 |
N = int(input())
A = list(map(int,input().split()))
mode = 0
money = 1000
kabu = 0
for i in range(N):
if i == 0:
if A[i+1] > A[i]:
kabu += 1000//A[i]
money -= kabu*A[i]
mode = 1
else:
continue
elif i == N-1:
money += kabu*A[i]
else:
if mode == 1:
if A[i] >= A[i-1]:
if A[i] > A[i+1]:
money += kabu*A[i]
kabu = 0
mode = 0
else:
continue
else:
if A[i] < A[i+1]:
kabu += money//A[i]
money -= kabu*A[i]
mode = 1
else:
continue
print(money)
|
import sys
N , K = list(map(int, input().split()))
As = list(map(int, input().split()))
As = [0]+As
Came = [-1]*(N+1)
s = 1
i = 0
while True:
if As[s] == s:
print(s)
sys.exit()
elif i >=K:
print(s)
sys.exit()
elif Came[s]>=0:
break
Came[s] = i
i+=1
s = As[s]
#print(Came , s)
T = i - Came[s]
L = K - Came[s]
Q = L % T
#print(T , L , Q)
print(Came.index(Came[s]+Q))
| 0 | null | 15,077,660,751,908 | 103 | 150 |
ALPHA = input()
if ALPHA.isupper():
print("A")
else:
print("a")
|
ch = input()
if ch == 'a' or ch == 'b' or ch == 'c' or ch == 'd' or ch == 'e' or ch == 'f' or ch == 'g' or ch == 'h':
print('a')
elif ch == 'i' or ch == 'j' or ch == 'k' or ch == 'l' or ch == 'm' or ch == 'n' or ch == 'o':
print('a')
elif ch == 'p' or ch == 'q' or ch == 'r' or ch == 's' or ch == 't' or ch == 'u' or ch == 'v':
print('a')
elif ch == 'w' or ch == 'x' or ch == 'y' or ch == 'z':
print('a')
else:
print('A')
| 1 | 11,309,070,887,388 | null | 119 | 119 |
if __name__ == "__main__":
n = int(input())
nums = [int(s) for s in input().split()]
odds = [0]
for num in nums[::2]:
odds.append(num + odds[-1])
res = [0]
for i, num in enumerate(nums[1::2]):
res.append(max(res[-1]+num, odds[i+1]))
if n % 2 == 0:
print(res[-1])
else:
ans = float('-inf')
for i, r in enumerate(res):
ans = max(ans, res[i] + odds[-1] - odds[i+1])
print(ans)
|
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import defaultdict
N, *A = map(int, read().split())
INF = 10**18
dp_not = defaultdict(lambda : -INF)
dp_take = defaultdict(lambda: -INF)
dp_not[(0,0)] = 0
for i,x in enumerate(A,1):
j = (i-1)//2
for n in (j,j+1):
dp_not[(i,n)] = max(dp_not[(i-1,n)], dp_take[(i-1,n)])
dp_take[(i,n)] = dp_not[(i-1,n-1)] + x
print(max(dp_not[(N, N//2)], dp_take[(N, N//2)]))
| 1 | 37,504,387,358,260 | null | 177 | 177 |
from scipy.special import comb
n, k = map(int, input().split())
num, ans = 0, 0
for i in range(n+1):
num += n-2*i
if i >= k-1:
ans += num+1
ans = ans%(10**9+7)
print(ans)
|
nn, kk = list(map(int,input().split()))
sum = 0
for i in range(kk, nn+2):
min = (0+i-1)*i/2
max = (nn+nn-i+1)*i/2
sum += (max-min)+1
sum = sum % (10**9+7)
print(int(sum))
| 1 | 32,997,463,043,620 | null | 170 | 170 |
N=int(input())
A,B=[],[]
for i in range(N):
a,b=map(int,input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
I=~-N//2
print(B[I]-A[I]+1 + (B[I+1]-A[I+1] if N%2==0 else 0))
|
N=int(input())
A=list()
B=list()
for i in range(N):
a,b=map(int,input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if N%2==1:
print(B[int((N-1)/2+0.5)]-A[int((N-1)/2+0.5)]+1)
else:
print((B[int(N/2+0.5)-1]+B[int(N/2+0.5)])-(A[int(N/2+0.5)-1]+A[int(N/2+0.5)])+1)
| 1 | 17,369,306,922,140 | null | 137 | 137 |
S=input()
T=input()
len_s=len(S)
len_t=len(T)
ans=0
for i in range(len_s-len_t+1):
cnt=0
for j in range(len_t):
if S[i+j]==T[j]:
cnt += 1
ans = max(ans,cnt)
print(len_t-ans)
|
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
m = arr[-1]
li = [0]*(m+1)
cnt = 0
for i in arr:
for j in range(i, m+1, i):
li[j] += 1
for i in arr:
if li[i] == 1:
cnt += 1
print(cnt)
| 0 | null | 9,006,000,790,840 | 82 | 129 |
num=input()
numline=list(num)
a=int(numline[len(numline)-1])
if(a==3):
print("bon")
elif(a==0 or a==1 or a==6 or a==8):
print("pon")
else:
print("hon")
|
s=input()
print("".join(["x"]*len(s)))
| 0 | null | 46,076,557,308,584 | 142 | 221 |
# coding: utf-8
output = []
# ??????????????????
while (1):
texts = input().strip()
if (texts == '-'):
break
# ?????£??????????????°
m = int(input())
# ?????£??????????????°??????????????????
for i in range(m):
h = int(input())
temp_texts = texts[:h]
new_texts = texts[h:] + temp_texts
texts = new_texts
output.append(texts)
for i in output:
print(i)
|
import sys
input = sys.stdin.readline
def main():
N = int(input())
c = input()
cnt_r = 0
cnt_w = 0
for i in c:
if i == 'R':
cnt_r += 1
else:
cnt_w += 1
w_left = 0
r_right = cnt_r
ans = N
for i in range(N):
ans = min(ans, max(w_left, r_right))
if c[i] == 'W':
w_left += 1
else:
r_right -= 1
print(min(ans, max(w_left, r_right)))
main()
| 0 | null | 4,086,992,561,168 | 66 | 98 |
"""
方針:
幸福度が一定以上のつなぎ方の数→NlogNで二分探索可能
採用するうち最小の幸福度を NlogNlogNで探索
累積和を用いて合計を算出
2 3
5 2
10 + 7 + 7 = 24
"""
import bisect
def wantover(n): #n以上の幸福度のつなぎ方の数がM以上ならTrueを返す
ret = 0
for i in range(N):
serchnum = n - A[i]
ret += (N - bisect.bisect_left(A,serchnum))
#print ("over",n,"is",ret)
if ret >= M:
return True
else:
return False
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
#print (wantover(7))
hpl = 0
hpr = A[-1] * 2 + 1
while hpr - hpl != 1:
mid = (hpr + hpl) // 2
if wantover(mid):
hpl = mid
else:
hpr = mid
#ここで最小の幸福度はhpl
#print (hpl,hpr)
B = [0] #累積和行列
for i in range(N):
B.append(B[-1] + A[-1 - i])
#print (A)
#print (B)
ans = 0
plnum = 0 #つないだ手の回数
for i in range(N):
i = N-i-1
ind = bisect.bisect_left(A,hpl - A[i])
#print (hpl,A[i],N-ind)
plnum += N - ind
ans += B[N - ind] + A[i] * (N-ind)
#print (ans,plnum)
print (ans - hpl * (plnum - M))
|
from collections import deque
def main():
S = input()
P = input()
s = deque(S)
n = len(S)
for _ in range(n):
s.append(s.popleft())
if P in ''.join(s):
ans = 'Yes'
break
else:
ans = 'No'
print(ans)
main()
| 0 | null | 54,615,533,774,708 | 252 | 64 |
X = int(input())
A = 100
for i in range(10**5):
A = A*101//100
if X <= A:
break
print(i+1)
|
import sys
input = sys.stdin.readline
#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range(n):
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
n=int(input())
a,x=[],[]
for i in range(n):
A = int(input())
a.append(A)
B=[]
for j in range(A):
B.append(list(map(int, input().split())))
x.append(B)
ma=0
for i in range(2**n):
now=0
flg=True
e=[0]*n
for j in range(n):
if (i>>j)&1:
now+=1
e[j]=1
for j in range(n):
#print(e)
if (i>>j)&1:
if e[j]==0:
flg=False
break
elif not flg:
break
for k in range(a[j]):
"""if e[x[j][k][0]-1]==-1:
if x[j][k][1] and
e[x[j][k][0]-1]=x[j][k][1]"""
if (e[x[j][k][0]-1]==0 and x[j][k][1]==1) or (e[x[j][k][0]-1]==1 and x[j][k][1]==0):
flg=False
break
if flg and ma<now:
ma=now
#print(ma)
print(ma)
| 0 | null | 74,320,237,693,630 | 159 | 262 |
while True:
n = input()
if n == '0':
break
print(sum([int(x) for x in list(n)]))
|
X = int(input())
if 400 <= X < 600:
print(8)
elif 600 <= X < 800:
print(7)
elif 800 <= X < 1000:
print(6)
elif 1000 <= X < 1200:
print(5)
elif 1200 <= X < 1400:
print(4)
elif 1400 <= X < 1600:
print(3)
elif 1600 <= X < 1800:
print(2)
else:
print(1)
| 0 | null | 4,105,553,656,150 | 62 | 100 |
# coding: utf-8
N, Q = map(int,input().split())
#N,Q=map(int,input().split())
#親のノードを格納 2の親が4のとき par[2]=4
par=[0]
#木の深さを格納 根が2の深さが3の時 rank[2]=3
rank=[0]
#初期化
for i in range(1,N+1):
par.append(i)
rank.append(0)
#xの根を探す、同時に通過したノードすべてを根に直接つける
def find(x):
#xの親がxならば根なのでxを返す
if par[x]==x:
return x
else:
#違う場合は親の親を捜し自分の親にする
par[x] = find(par[x])
#再帰的に行うと根が見つかる
return par[x]
#xが属する木とyが属する木を併合する
def unite(x,y):
#根を探す
root_x=find(x)
root_y=find(y)
#根が同じなら元からつながっているので終わり
if root_x == root_y:
return
#ランクが大きい木の根の直下にランクが小さい木を結合
if rank[root_x] < rank[root_y]:
par[root_x] = root_y
else:
par[root_y] = root_x
#ランクが等しいときのみランクが増える#なぜ#yにxが結合?
if rank[root_x]==rank[root_y]:
rank[root_x]+=1
#xとyが同じ木に存在するかを調べる
def same(x,y):
return find(x)==find(y)
#main
for i in range(Q):
a,b=map(int,input().split())
unite(a, b)
res = []
for i in range(1, N+1):
res.append(find(i))
ans = len(set(res))-1
print(ans)
|
n,m = list(map(int, input().split()))
graph = [set() for _ in range(n)]
for _ in range(m):
a,b = list(map(int, input().split()))
graph[a-1].add(b-1)
graph[b-1].add(a-1)
stack = []
group = [-1] * n
gid = 0
i = 0
for i in range(n):
if group[i] >= 0:
continue
group[i] = gid
stack.append(i)
while stack:
current = stack.pop()
for neighbor in graph[current]:
if group[neighbor] == -1:
group[neighbor] = gid
stack.append(neighbor)
gid += 1
print(gid-1)
| 1 | 2,294,482,145,088 | null | 70 | 70 |
import math
a,b,h,m = map(int,input().split())
h_s = 360*h/12+30*m/60
m_s = 360*m/60
s = abs(h_s - m_s)
print(abs(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(s)))))
|
import math
a,b,H,M=map(int,input().split())
h=30*H+(0.5)*M
m=6*M
c=abs(h-m)
x=math.sqrt(a**2+b**2-(2*a*b*(math.cos(math.radians(c)))))
print(x)
| 1 | 19,910,051,784,128 | null | 144 | 144 |
import math
from bisect import bisect_right # クエリより真に大きい値が初めて現れるインデックスを教えてくれる
# 初めて爆弾が届かない範囲を記録しながら前から順に倒していく
N, D, A = map(int, input().split()) # N体のモンスター, 爆弾の範囲D, 爆弾の威力A
XH = []
X = []
for _ in range(N):
x, h = map(int, input().split())
XH.append((x, math.ceil(h/A)))
X.append(x)
# 座標で昇順ソート
XH.sort()
X.sort()
# 前から倒していく
now = 0
ans = 0
T = [0]*(N+1) # 爆弾の範囲が切れる場所を記録しておく
for i in range(N):
x, h = XH[i] # 今見ているモンスターの座標, 体力
now -= T[i] # そのモンスターに届いていない爆弾があるなら引く
if now >= h: # 今残っている爆弾だけで倒せるならcontinue
continue
else:
ans += h - now # 足りない分(h-now個)の爆弾を使う
T[bisect_right(X, x+2*D)] += h - now # 爆弾の範囲が切れる場所を記録しておく
now = h # 今影響が残っている爆弾の威力
print(ans)
|
from collections import deque
def main():
N, D, A = map(int, input().split())
enemies = [None] * N
for i in range(N):
enemies[i] = tuple(map(int, input().split()))
enemies.sort()
q = deque()
cur = 0
ans = 0
for x, h in enemies:
while len(q) and q[0][0] < x:
cur -= q.popleft()[1]
remain = max(h - cur * A, 0)
tmp = -(-remain//A)
q.append((x + 2 * D, tmp))
ans += tmp
cur += tmp
print(ans)
if __name__ == "__main__":
main()
| 1 | 82,395,461,958,300 | null | 230 | 230 |
while True:
_=input()
if _ == '-':
break
for i in range(int(input())):
l=int(input())
_=_[l:]+_[:l]
print(_)
|
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(1,n+1):
if i not in d:
d[i] = 0
for i in range(len(a)):
d[a[i]] += 1
for i in range(1,n+1):
print(d[i])
| 0 | null | 17,130,582,341,730 | 66 | 169 |
def function(arg):
xyabc, pa, qb, rc = arg.split('¥n')
X,Y,A,B,C = map(int, xyabc.split())
oishisa_A = list(map(int, pa.split()))
oishisa_B = list(map(int, qb.split()))
oishisa_C = list(map(int, rc.split()))
oishisa_A.sort(reverse=True)
oishisa_A = oishisa_A[:X] # at most X
oishisa_B.sort(reverse=True)
oishisa_B = oishisa_B[:Y] # at most Y
oishisa_C.sort(reverse=True)
oishisa = oishisa_A + oishisa_B + oishisa_C
oishisa.sort(reverse=True)
results = 0
for i in range(X+Y):
results += oishisa[i]
return results
if __name__ == '__main__':
xyabc = input()
pa = input()
qb = input()
rc = input()
print(function(xyabc+'¥n'+pa+'¥n'+qb+'¥n'+rc))
|
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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
s = p[:x] + q[:y]
s.sort()
ans = sum(s)
for si, ri in zip(s, r):
if si < ri:
ans += ri - si
print(ans)
| 1 | 45,006,954,724,810 | null | 188 | 188 |
N = int(input())
s = input()
ans = min(s.count('R'), s.count('W'), s[N-s.count('W'):].count('R'))
print(ans)
|
N = int(input())
C = input()
answer = 0
for i in range(N):
if C[i] == 'W':
red_start = i
break
if i == N-1:
red_start = N-1
for i in range(1, N+1):
if C[-i] == 'R':
white_start = i
break
if i == N:
white_start = N
red_pos = red_start
white_pos = white_start
while red_pos + white_pos < N:
answer += 1
for i in range(red_pos+1, N):
if C[i] == 'W':
red_pos = i
break
if i == N-1:
red_pos = N-1
for i in range(white_pos+1, N+1):
if C[-i] == 'R':
white_pos = i
break
if i == N:
white_pos = N
print(answer)
| 1 | 6,273,713,289,240 | null | 98 | 98 |
def Rally():
# 入力
N = int(input())
X = list(map(int, input().split()))
# リストの最大値と最小値
max_num = max(X)
min_num = min(X)
# Pの座標を移動させて各座標の体力消耗を調べる
min_sum = list()
for P in range(min_num, max_num+1):
sum = 0
for i in range(N):
sum += (X[i] - P)**2
min_sum.append(sum)
# 戻り値
return min(min_sum)
result = Rally()
print(result)
|
N,K = map(int,input().split())
a = list(map(int,input().split()))
for i in range(1,N-K+1):
if a[K+i-1]>a[i-1]:
print("Yes")
else:
print("No")
| 0 | null | 36,314,004,388,340 | 213 | 102 |
n = int(input())
s,t = input().split()
res = ""
for i in range(0,n):
res += s[i]
res += t[i]
print(res)
|
from Queue import Queue
n, q = [ int( val ) for val in raw_input( ).split( " " ) ]
names = Queue( )
times = Queue( )
for i in range( n ):
name, time = raw_input( ).split( " " )
names.put( name )
times.put( int( time ) )
qsum = 0
output = []
while not times.empty( ):
name = names.get( )
time = times.get( )
if time <= q:
qsum += time
output.append( "{:s} {:d}".format( name, qsum ) )
else:
times.put( time - q )
names.put( name )
qsum += q
print( "\n".join( output ) )
| 0 | null | 56,277,415,285,700 | 255 | 19 |
#!/usr/bin/env python3
# coding: utf-8
class Dice() :
mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1)}
def __init__(self, data):
self.label = data
def move(self, data):
self.label = [self.label[idx] for idx in self.mask[data]]
def get_up(self):
return self.label[0]
dicedata = input().split()
orderdata = input()
newdice = Dice(dicedata)
[newdice.move(orderdata[idx]) for idx in range(0, len(orderdata))]
print(newdice.get_up())
|
def rotate(dice,d):
if d == "N":
temp = dice[0]
dice[0] = dice[1]
dice[1] = dice[5]
dice[5] = dice[4]
dice[4] = temp
elif d == "E":
temp = dice[0]
dice[0] = dice[3]
dice[3] = dice[5]
dice[5] = dice[2]
dice[2] = temp
elif d == "W":
temp = dice[0]
dice[0] = dice[2]
dice[2] = dice[5]
dice[5] = dice[3]
dice[3] = temp
elif d == "S":
temp = dice[0]
dice[0] = dice[4]
dice[4] = dice[5]
dice[5] = dice[1]
dice[1] = temp
return dice
dice = input().split()
dArr = list(input())
for i in range(len(dArr)):
dice = rotate(dice,dArr[i])
print(dice[0])
| 1 | 240,393,265,980 | null | 33 | 33 |
s = input()
p = input()
flag = False
for i in range(len(s)):
t = s[i:] + s[:i]
if p in t :
flag = True
break
if flag :
print("Yes")
else :
print("No")
|
s = input()
p = input()
found = False
for i in range(len(s)):
ring = s[i:] + s[:i]
if p in ring:
print('Yes')
found = True
break
if not found:
print('No')
| 1 | 1,748,068,416,420 | null | 64 | 64 |
n = str(input())
print('hon' if (int(n[len(n)-1]) in {2, 4, 5, 7, 9}) else 'pon' if (int(n[len(n)-1]) in {0, 1, 6, 8}) else 'bon' )
|
n = int(input())
if(n%10 == 3):
print("bon")
elif(n%10 == 0 or n%10 == 1 or n%10 == 6 or n%10 == 8):
print("pon")
else:
print("hon")
| 1 | 19,296,033,072,170 | null | 142 | 142 |
def solve():
N = int(input())
aList = [list(input().split()) for i in range(N)]
X = input()
sleep = False
ans = 0
for item in aList:
if sleep == True:
ans += int(item[1])
if X == item[0]:
sleep = True
print(ans)
if __name__ == '__main__':
solve()
|
def resolve():
N = int(input())
s = []
t = []
for i in range(N):
S, T = input().split()
s.append(S)
t.append(int(T))
X = input()
print(sum(t[s.index(X)+1:]))
resolve()
| 1 | 96,903,551,348,688 | null | 243 | 243 |
x, y = list(map(int, input().split()))
a = 4 * x - y
b = y - 2 * x
if (a % 2 == 0 and a >= 0) and (b % 2 == 0 and b >= 0):
print('Yes')
else:
print('No')
|
x,y = map(int,input().split())
ans = 'No'
for a in range(x+1):
b = x - a
if 2 * a + 4 * b == y:
ans = 'Yes'
print(ans)
| 1 | 13,705,012,244,260 | null | 127 | 127 |
def do_solve(n, k, c, s):
dp = [0 for i in xrange(n)]
for i in xrange(n):
dp[i] = 1 if s[i] == 'o' else 0
if i - c - 1 >= 0:
dp[i] = max(dp[i], dp[i - c - 1] + 1 if s[i] == 'o' else 0)
if i - 1 >= 0:
dp[i] = max(dp[i], dp[i - 1])
return dp
def solve(n, k, c, s):
dp1 = do_solve(n, k, c, s)
dp2 = do_solve(n, k, c, s[::-1])[::-1]
# print dp1
# print dp2
res = []
for i in xrange(n):
if s[i] == 'x':
continue
l = dp1[i - 1] if i - 1 >= 0 else 0
r = dp2[i + 1] if i + 1 < n else 0
# print i, l, r
if l + r == k - 1:
res.append(i + 1)
# print res
return res
assert solve(16, 4, 3, 'ooxxoxoxxxoxoxxo') == [11, 16]
assert solve(11, 3, 2, 'ooxxxoxxxoo') == [6]
assert solve(5, 1, 0, 'ooooo') == []
assert solve(5, 2, 3, 'ooxoo') == [1, 5]
(n, k, c) = map(int, raw_input().split())
s = raw_input().strip()
for num in solve(n, k, c, s):
print num
|
import sys
from collections import Counter
input = sys.stdin.readline
N = int(input())
ans = 1
mod = 998244353
D = list(map(int, input().split()))
if D[0] != 0:
print(0)
exit()
D = sorted(Counter(D).items())
tmp = D[0][1]
stream = 0
for n, i in D:
if stream != n:
print(0)
exit()
if n == 0 and i == 1:
stream += 1
continue
elif n==0:
print(0)
exit()
ans *= pow(tmp, i)
ans %= mod
tmp = i
stream += 1
print(ans)
| 0 | null | 97,701,135,944,010 | 182 | 284 |
#93 B - Iron Bar Cutting WA (hint)
N = int(input())
A = list(map(int,input().split()))
# 差が最小の切れ目を見つける
length = sum(A)
left = 0
dist = 0
mdist = length
midx = 0
for i,a in enumerate(A):
left += a
right = length - left
dist = abs(left - right)
if dist < mdist:
mdist = dist
midx = i
ans = mdist
print(ans)
|
import sys
input = sys.stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
center = sum_A / 2
total = 0
near_center = 0
for a in A:
total += a
if abs(total - center) < abs(near_center - center):
near_center = total
ans = abs((sum_A - near_center) - near_center)
print(ans)
if __name__ == "__main__":
main()
| 1 | 142,513,436,888,692 | null | 276 | 276 |
A,B,C = map(int, input().split())
print('{} {} {}'.format(C,A,B))
|
n = int(input())
snum = input().split()
snum.reverse()
snum_space = " ".join(snum)
print(snum_space)
| 0 | null | 19,443,431,114,802 | 178 | 53 |
input()
a = list(input().split())
print(*a[::-1])
|
def main():
N, K = map(int, input().split())
mod = 10**9 + 7
r = 0
D = [0] * (K + 1)
for i in reversed(range(1, K + 1)):
D[i] = pow(K // i, N, mod) - sum(D[::i])
return sum(i * j for i, j in enumerate(D)) % mod
print(main())
| 0 | null | 18,878,223,014,300 | 53 | 176 |
n=int(input())
s=input()
r=0
for i in s:
if(i=="R"):
r+=1
ans=0
for j in range(r):
if(s[j]=="W"):
ans+=1
print(ans)
|
#!/usr/bin/env python3
# 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():
N = int(input())
C = list(input())
Rc = len(list(filter(lambda x:x=="R",C)))
Wc = len(C) - Rc
c = 0
for i in range(Rc):
if C[i] == "W":
c+=1
# print(Rc)
# print(Wc)
print(c)
pass
if __name__ == '__main__':
main()
| 1 | 6,282,655,939,582 | null | 98 | 98 |
import sys
a=[]
for t in range(4):
a.append([])
for f in range(3):
a[t].append([])
for r in range(10):
a[t][f].append(0)
lines = [line for line in sys.stdin]
n = lines[0]
for l in lines[1:]:
b, f, r, v = map(int,l.split())
b -= 1
f -= 1
r -= 1
a[b][f][r] += v
for i,t in enumerate(a):
for f in t:
print (" " +" ".join(map(str,f)))
if len(a) != i +1:
print ('#'*20)
|
dic = {}
for b in range(1,5):
for f in range(1,4):
for r in range(1,11):
dic[(b,f,r)] = 0
n = int(raw_input())
for k in range(n):
b,f,r,v = map(int,raw_input().split())
dic[(b,f,r)] += v
j = 0
for b in range(1,5):
for f in range(1,4):
ls = []
for r in range(1,11):
ls.append(dic[(b,f,r)])
print ' ' + ' '.join(map(str,ls))
else:
if j < 3:
print '#'*20
j +=1
| 1 | 1,117,121,230,862 | null | 55 | 55 |
# 素因数分解
N=int(input())
cand=[]
def check(N0,K0):
if N0%K0==0:
return check(int(N0/K0),K0)
elif N0%K0==1:
return 1
else:
return 0
def check0(N0,K0):
while N0%K0==0:
N0=int(N0/K0)
if N0%K0==1:
return 1
else:
return 0
# N-1の約数の数
for i in range(2,int((N-1)**0.5)+1):#O(N**0.5)
if (N-1)%i==0:
cand.append(i)
if i!=int((N-1)/i):
cand.append(int((N-1)/i))
if N>2:
cand.append(N-1)
# Nの約数
for i in range(2,int(N**0.5)+1):#O(N**0.5)
if N%i==0:
cand.append(i)
if i!=int(N/i):
cand.append(int(N/i))
cand.append(N)
#print(cand)
count=0
for i in range(len(cand)):
if check(N,cand[i]):
count+=1
print(count)
|
#F
import math
N = int(input())
m = int(math.sqrt(N-1))
Myaku = []
for i in range(1,m+1):
if (N-1)%i == 0:
if i != 1:
Myaku.append(i)
if (N-1)//i != i:
Myaku.append((N-1)//i)
ans = len(Myaku)
n = int(math.sqrt(N))
Nyaku = []
for i in range(1,n+1):
if N%i == 0:
if i != 1:
Nyaku.append(i)
if N//i != i:
Nyaku.append(N//i)
for ny in Nyaku:
X = N
while X%ny == 0:
X //= ny
if X%ny == 1:
ans+=1
print(ans)
#print(Myaku,Nyaku)
| 1 | 41,512,176,157,088 | null | 183 | 183 |
#!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
N, K = map(int, input().split())
ans = N % K
ans = min(ans, abs(ans - K))
print(ans)
if __name__ == '__main__':
main()
|
# C Replacing Integer
N, K = map(int, input().split())
while N >= K:
N = N % K
frag = 0
while frag == 0:
cand = abs(N - K)
if cand < N:
N = cand
else:
frag = 1
print(N)
| 1 | 39,298,915,540,618 | null | 180 | 180 |
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
OU=T1*(A1-B1)
HUKU=T2*(A2-B2)
TOTAL=OU+HUKU
if TOTAL==0:
print("infinity")
elif (OU>0 and TOTAL>0) or (OU<0 and TOTAL<0):
print(0)
elif (OU>0 and TOTAL*(-1)>OU) or (OU<0 and TOTAL*(-1)<OU):
print(1)
else:
K=int(OU/TOTAL)*-1
if (OU%TOTAL)==0:
print(K*2)
else:
print(K*2+1)
|
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if a[0]*t[0]+a[1]*t[1]==b[0]*t[0]+b[1]*t[1]:
print('infinity')
elif a[0]*t[0]+a[1]*t[1]>b[0]*t[0]+b[1]*t[1]:
if a[0]*t[0]>b[0]*t[0]:
print(0)
elif a[0]*t[0]==b[0]*t[0]:
print(1)
else:
n=t[0]*(b[0]-a[0])
m=t[0]*(a[0]-b[0])+t[1]*(a[1]-b[1])
q=n//m
if n%m==0:
print(2*q)
else:
print(2*q+1)
else:
if a[0]*t[0]<b[0]*t[0]:
print(0)
elif a[0]*t[0]==b[0]*t[0]:
print(1)
else:
n=-t[0]*(b[0]-a[0])
m=-t[0]*(a[0]-b[0])-t[1]*(a[1]-b[1])
q=n//m
if n%m==0:
print(2*q)
else:
print(2*q+1)
| 1 | 131,614,512,845,180 | null | 269 | 269 |
line = '#.'*150
while True:
H, W = map(int, raw_input().split())
if H == W == 0: break
for i in range(H):
print line[i%2:i%2+W]
print ''
|
import sys
while 1:
H, W = map(int, raw_input().split())
if H==0 and W==0:
break
for i in range(H):
for j in range(W):
if (i+j)%2==0:
sys.stdout.write('#')
else:
sys.stdout.write('.')
sys.stdout.write('\n')
print ''
| 1 | 880,384,734,500 | null | 51 | 51 |
A = list(map(int,input().split()))
a=A[0]
b=A[1]
if a<b:
a,b=b,a
while b:
a,b=b,a%b
print(a)
|
a = input()
if a == 'AAA' or a == 'BBB' :
print('No')
else :
print('Yes')
| 0 | null | 27,498,190,941,792 | 11 | 201 |
N=int(input())
S=[input() for i in range(N)]
L=dict()
for i in range(N):
if S[i] in L:
L[S[i]]+=1
else:
L[S[i]]=1
M=max(L.values())
ans=list()
for X in L:
if L[X]==M:
ans.append(X)
ans.sort()
for X in ans:
print(X)
|
N = int(input())
S = []
for _ in range(N):
S.append(input())
import sys
from collections import Counter
count_dict = Counter(S)
most_freq = count_dict.most_common(1)[0][1]
words = []
for word, freq in sorted(count_dict.items(), key=lambda x: -x[1]):
if freq == most_freq:
words.append(word)
for word in sorted(words):
print(word)
| 1 | 70,172,615,051,550 | null | 218 | 218 |
x = input()
print(0 if x == '1'else 1)
|
# -*- coding: utf-8 -*-
def solve():
S = input()
return S[:3]
if __name__ == '__main__':
print(solve())
| 0 | null | 8,877,207,858,272 | 76 | 130 |
n, m = list(map(int, input().split()))
s = input()
if s.find('1' * m) != -1:
print('-1')
exit(0)
i = n
rans = []
flag = True
while flag:
for j in range(m, 1 - 1, -1):
if i - j == 0:
flag = False
if i - j >= 0 and s[i - j] == '0':
rans.append(j)
i = i - j
break
print(' '.join(map(str,reversed(rans))))
|
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
#import queue
from copy import copy, deepcopy
from operator import itemgetter
import bisect#2分探索
#bisect_left(l,x), bisect(l,x)
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#q=heapq.heapify(l),heappush(q,a),heappop(q)
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])
#mod = 10**9+7
#N = int(input())
N, P = map(int, input().split())
S=input()
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get()
#q = queue.LifoQueue() #q.put(i) #q.get()
#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a) #2次元配列はこうコピーする
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
# primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)
#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入
if P!=2 and P!=5:
pc=[0]*P
pc[0]=1
count=0
ans=0
p10=1
for i in range(1,N+1):
count+=int(S[N-i])*p10
count%=P
ans+=pc[count]
pc[count]+=1
p10*=10
p10%=P
print(ans)
else:
ans=0
for i in range(1,N+1):
if int(S[N-i])%P==0:
ans+=N-i+1
print(ans)
| 0 | null | 98,257,204,681,728 | 274 | 205 |
S = input()
ans="ABC"
if(S=="ABC"):
ans="ARC"
print(ans)
|
def main():
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
s = readline().rstrip().decode()
check = {'ABC': 'ARC', 'ARC': 'ABC'}
print(check[s])
if __name__ == '__main__':
main()
| 1 | 23,985,007,584,208 | null | 153 | 153 |
T = int(input())
print('Yes' if T >= 30 else 'No')
|
#174 A
X = input()
print('Yes') if int(X)> 29 else print('No')
| 1 | 5,727,236,372,952 | null | 95 | 95 |
n = input()
a = list(n)
k = int(input())
n = len(a)
for i in range(n):
a[i] = int(a[i])
dp = [[[0 for i in range(2)] for i in range(k+2)]for i in range(n)]
dp[0][0][0] = 1
dp[0][1][0] = a[0]-1
dp[0][1][1] = 1
for i in range(n-1):
for j in range(k+1):
if a[i+1] == 0:
dp[i+1][j][1] += dp[i][j][1]
dp[i+1][j][0] += dp[i][j][0]
dp[i+1][j+1][0] += dp[i][j][0]*9
else:
dp[i+1][j][0] += dp[i][j][0]+dp[i][j][1]
dp[i+1][j+1][0] += dp[i][j][1]*(a[i+1]-1)+dp[i][j][0]*9
dp[i+1][j+1][1] += dp[i][j][1]
print(dp[n-1][k][0]+dp[n-1][k][1])
|
import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N = input()
length = len(N)
K = int(input())
# 左からi桁目まで見て,N以下が確定していて,0でない数字がk個ある数字の個数
dp_1 = [[0] * (10) for _ in range(length)]
# 左からi桁目まで見て,N以下が確定していなくて,0でない数字がk個ある数字の個数
dp_2 = [[0] * (10) for _ in range(length)]
dp_1[0][0] = 1
dp_1[0][1] = int(N[0]) - 1
dp_2[0][1] = 1
for i in range(1, length):
# 小さいのが確定しているものに対して,0以外のものを追加
for k in range(1, K + 2):
dp_1[i][k] += dp_1[i - 1][k - 1] * 9
# 小さいものが確定しているものに対して,0を追加
for k in range(0, K + 2):
dp_1[i][k] += dp_1[i - 1][k]
# 大小がわからないものから,小さいのが確定する
if N[i] == "0":
for k in range(K + 2):
dp_2[i][k] += dp_2[i - 1][k]
else:
# 0を追加する
for k in range(K + 2):
dp_1[i][k] += dp_2[i - 1][k]
# その他の数字を追加
for k in range(1, K + 2):
dp_1[i][k] += dp_2[i - 1][k - 1] * (int(N[i]) - 1)
# 依然として大小関係がわからない
for k in range(1, K + 2):
dp_2[i][k] += dp_2[i - 1][k - 1]
ans = dp_1[-1][K] + dp_2[-1][K]
print(ans)
if __name__ == "__main__":
main()
| 1 | 75,801,783,621,112 | null | 224 | 224 |
from collections import Counter
n=input()[::-1]
A=[0]
num,point=0,1
for i in n:
num +=int(i)*point
num %=2019
A.append(num)
point *=10
point %=2019
count=Counter(A)
ans=0
for i,j in count.items():
if j>=2:ans +=j*(j-1)//2
print(ans)
|
import numpy as np
from numba import njit, i8
@njit(i8(i8, i8[:], i8[:]), cache=True)
def solve(H, A, B):
A_max = A.max()
dp = np.zeros(H + A_max + 1, dtype=np.int64)
for i in range(A_max + 1, H + A_max + 1):
dp[i] = np.min(dp[i - A] + B)
return dp[-1]
H, N, *AB = map(int, open(0).read().split())
A = np.array(AB[::2], dtype=np.int64)
B = np.array(AB[1::2], dtype=np.int64)
print(solve(H, A, B))
| 0 | null | 56,131,660,979,868 | 166 | 229 |
s = len(input())
print("x" * s)
|
# -*- coding: utf-8 -*-
"""
E - Travel by Car
https://atcoder.jp/contests/abc143/tasks/abc143_e
"""
import sys
from scipy.sparse.csgraph import floyd_warshall
def main(args):
N, M, L = map(int, input().split())
g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
for i in range(N+1):
g1[i][i] = 0
for _ in range(M):
A, B, C = map(int, input().split())
g1[A][B] = g1[B][A] = C
d1 = floyd_warshall(g1)
g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
for i in range(N+1):
for j in range(N+1):
if i == j:
g2[i][j] = 0
elif d1[i][j] <= L:
g2[i][j] = g2[j][i] = 1
d2 = floyd_warshall(g2)
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1)
if __name__ == '__main__':
main(sys.argv[1:])
| 0 | null | 123,087,395,005,860 | 221 | 295 |
u,s,e,w,n,b = list(map(int, input().split()))
rolls = input()
for roll in rolls:
if roll == 'N':
n,u,e,w,b,s = u,s,e,w,n,b
elif roll == 'S':
s,b,e,w,u,n = u,s,e,w,n,b
elif roll == 'E':
e,s,b,u,n,w = u,s,e,w,n,b
elif roll == 'W':
w,s,u,b,n,e = u,s,e,w,n,b
else:
print('Error')
raise(-1)
print(u)
|
def roll(l, command):
'''
return rolled list
l : string list
command: string
'''
res = []
i = -1
if command =='N':
res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]
if command =='S':
res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]
if command =='E':
res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]
if command =='W':
res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]
return res
faces = input().split()
commands = list(input())
for command in commands:
faces = roll(faces, command)
print(faces[0])
| 1 | 229,724,385,148 | null | 33 | 33 |
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = LI()
ans = float('INF')
sum_A = sum(A)
accumulate_A = list(itertools.accumulate(A))
for i in range(N-1):
ans = min(ans,abs(sum_A-accumulate_A[i]*2))
print(ans)
|
import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
import numpy as np
def main():
n=II()
A=LI()
A=np.array(A)
B=np.cumsum(A)
C=np.cumsum(A[::-1])
#print(B,C)
D=abs(B[:-1]-C[:-1][::-1])
#print(D)
print(np.min(D))
if __name__ == "__main__":
main()
| 1 | 142,060,196,662,220 | null | 276 | 276 |
target = int(input()) + 1
fib = [0 for n in range(target + 1)]
for i in range(target + 1):
if i == 0:
continue
elif i == 1:
fib[i] = 1
else:
fib[i] = fib[i - 1] + fib[i - 2]
print(fib[target])
|
def fina(n, fina_list):
if n <= 1:
fina_list[n] = 1
return fina_list[n]
elif fina_list[n]:
return fina_list[n]
else:
fina_list[n] = fina(n-1, fina_list) + fina(n-2, fina_list)
return fina_list[n]
n = int(input())
fina_list = [None]*(n + 1)
print(fina(n, fina_list))
| 1 | 1,834,739,926 | null | 7 | 7 |
import sys
I=sys.stdin.readlines()
N,M,L=map(int,I[0].split())
a,b,c=0,0,0
D=[[L+1]*N for i in range(N)]
for i in range(M):
a,b,c=map(int,I[i+1].split())
a,b=a-1,b-1
D[a][b]=c
D[b][a]=c
for i in range(N):
D[i][i]=0
for k in range(N):
for i in range(N):
for j in range(N):
D[i][j]=min(D[i][j],D[i][k]+D[k][j])
D2=[[N*N+2]*N for i in range(N)]
for i in range(N):
D2[i][i]=0
for j in range(N):
if D[i][j]<=L:
D2[i][j]=1
for k in range(N):
for i in range(N):
for j in range(N):
D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j])
Q=int(I[M+1])
for i in range(Q):
a,b=map(int,I[i+2+M].split())
if N<D2[a-1][b-1]:
print(-1)
else:
print(D2[a-1][b-1]-1)
|
N, K = map(int, input().split())
l = list(map(int, input().split()))
cnt = 0
for i in l:
if i >= K:
cnt = cnt + 1
print(cnt)
| 0 | null | 176,155,526,005,774 | 295 | 298 |
n=int(input())
A=list(map(int,input().split()))
N=[3]+[0]*n
mod=10**9+7
ans=1
for a in A:
ans*=N[a]
ans%=mod
N[a]-=1
N[a+1]+=1
print(ans)
|
N = int(input())
a_list = list(map(int, input().split()))
MOD = 10**9 + 7
cnts = [0,0,0]
sames = 0
ind = -1
res = 1
for a in a_list:
for i, cnt in enumerate(cnts):
if cnt == a:
sames += 1
ind = i
res *= sames
res %= MOD
cnts[ind] += 1
sames = 0
print(res)
| 1 | 130,143,780,151,840 | null | 268 | 268 |
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
ans = 0
for t in T:
if t in S:
ans += 1
print(ans)
|
n = int(input())
S = set(input().split())
q = int(input())
T = set(input().split())
print(len(S & T))
| 1 | 64,045,198,770 | null | 22 | 22 |
INF = 1145141919810364364334
n,m = map(int,input().split())
c = list(map(int,input().split()))
dp = [INF] * (n+1)
dp[0] = 0
for i in range(m):
for j in range(n+1):
if c[i] > j:
continue
else:
dp[j] = min(dp[j] , dp[j-c[i]] + 1)
print(dp[n])
|
ans = (int(input()) - 1) // 2 + 1
print(ans)
| 0 | null | 29,681,523,730,462 | 28 | 206 |
n = int(input())
s = str(input())
new_s = s[0]
for i in range(1,len(s)):
if s[i] == s[i-1]:
continue
else:
new_s += s[i]
print(len(new_s))
|
rst = []
N = int(input())
S = input()
tmp_val = ''
for i in S:
if tmp_val != i:
rst.append(i)
tmp_val = i
print(len(rst))
| 1 | 170,344,786,039,212 | null | 293 | 293 |
a=input()
b=int(input())
while b>0:
tmp=input().split(" ")
if tmp[0]=="replace":
a=a[:int(tmp[1])]+tmp[3]+a[int(tmp[2])+1:]
if tmp[0]=="reverse":
tmp2="".join(list(a)[int(tmp[1]):int(tmp[2])+1])[::-1]
a=a[:int(tmp[1])]+tmp2+a[int(tmp[2])+1:]
if tmp[0]=="print":
print(a[int(tmp[1]):int(tmp[2])+1])
b-=1
|
H=int(input())
W=int(input())
N=int(input())
if H<=W: big=W
else: big=H
if N%big==0: ans=N//big
else: ans=N//big+1
print(ans)
| 0 | null | 45,192,070,382,328 | 68 | 236 |
import math
def gcd(a,b):
if a<b: a,b=b,a
c=a%b
if c==0:
return b
else:
return gcd(b,c)
S=[ int(x) for x in input().split()]
print(gcd(S[0],S[1]))
|
import sys
n=int(input())
s=[input() for i in range(n)]
t=[2*(i.count("("))-len(i) for i in s]
if sum(t)!=0:
print("No")
sys.exit()
st=[[t[i]] for i in range(n)]
for i in range(n):
now,mi=0,0
for j in s[i]:
if j=="(":
now+=1
else:
now-=1
mi=min(mi,now)
st[i].append(mi)
#st.sort(reverse=True,key=lambda z:z[1])
u,v,w=list(filter(lambda x:x[1]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st))
v.sort(reverse=True)
v.sort(reverse=True,key=lambda z:z[1])
w.sort(key=lambda z:z[0]-z[1],reverse=True)
lu=len(u)
lv=len(v)
now2=0
for i in range(n):
if i<lu:
now2+=u[i][0]
elif i<lu+lv:
if now2+v[i-lu][1]<0:
print("No")
break
now2+=v[i-lu][0]
else:
#いや、間違ってるのここなんかーーい
if now2+w[i-lu-lv][1]<0:
print("No")
break
now2+=w[i-lu-lv][0]
else:
print("Yes")
| 0 | null | 11,740,135,060,588 | 11 | 152 |
#!/usr/bin/python3
def find(id, V, d, dist):
i = id - 1
dist[i] = d
for v in V[i]:
if dist[v - 1] == -1 or dist[v - 1] > d + 1:
find(v, V, d + 1, dist)
n = int(input())
# [isFind, d, f]
A = [[False, 0, 0] for i in range(n)]
U = []
V = []
dist = [-1] * n
for i in range(n):
l = list(map(int, input().split()))
U.append(l[0])
V.append(l[2:])
find(1, V, 0, dist)
for u in U:
print(u, dist[u - 1])
|
from sys import stdin
from collections import deque
n = int(stdin.readline())
d = [-1] * (n + 1)
def bfs(G):
d[1] = 0
dq = deque([1])
while len(dq) > 0:
v = dq.popleft()
for c in G[v]:
if d[c] < 0:
d[c] = d[v] + 1
dq.append(c)
for i, x in enumerate(d[1:], start=1):
print(i, x)
G = [0]
for i in range(n):
G.append(list(map(int, stdin.readline().split()[2:])))
bfs(G)
| 1 | 4,389,349,080 | null | 9 | 9 |
while 1:
a = raw_input()
if a =='0':
break
sum = 0
for i in a:
sum += int(i)
print sum
|
str = input()
while int(str[0]):
sum = 0
for char in str:
sum += int(char)
print(sum)
str = input()
| 1 | 1,552,816,600,790 | null | 62 | 62 |
n = int(input())
p = 10 ** 9 + 7
all_ptn = 10 ** n
anti_ptn = 2 * (9 ** n) - 8 ** n
print((all_ptn - anti_ptn) % p)
|
N = int(input())
MOD = 10**9 + 7
val1 = pow(9,N,MOD)
val2 = pow(8,N,MOD)
ans = pow(10,N,MOD) - 2*val1 + val2
print(ans%MOD)
| 1 | 3,183,963,432,980 | null | 78 | 78 |
R=int(input())
print(2*R*3.1419)
|
import math
X = int(input())
print(X * 2 * math.pi)
| 1 | 31,466,310,840,120 | null | 167 | 167 |
import math
import fractions
import collections
import itertools
from collections import deque
S=input()
N=len(S)
cnt=0
l=[]
"""
cnt=0
p=10**9+7
for i in range(K,N+2):
cnt=(cnt+((N-i+1)*i)+1)%p
#print(((N-i+1)*i)+1)
print(cnt)
"""
amari=[0]*(N+1)
num=0
for i in range(N):
num=num+pow(10,i,2019)*int(S[N-1-i])
amari[i+1]=num%2019
#print(amari)
c=collections.Counter(amari)
values=list(c.values()) #aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys()) #先のvalue値に相当する要素のリスト(要素1,要素2,…)
#for i in range(len(key)):
# l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
for i in range(len(values)):
cnt=cnt+(values[i]*(values[i]-1))//2
print(cnt)
|
import heapq
def dijkstra(s):
p=[x for x in range(n)]#親の記憶
hq = [(0, s)]
heapq.heapify(hq) # リストを優先度付きキューに変換
cost = [float('inf')] * n # 行ったことのないところはinf
cost[s] = 0 # 開始地点は0
while hq:
c, v = heapq.heappop(hq)
if c > cost[v]: # コストが現在のコストよりも高ければスルー
continue
for d, u in e[v]:
tmp = d + cost[v]
if tmp < cost[u]:
cost[u] = tmp
p[u]=v
heapq.heappush(hq, (tmp, u))
return p
n,m = map(int,input().split())
#重み付き有向グラフの隣接リストe(重み=1)
e = [[] for _ in range(n)]
t=1
for _ in range(m):
a,b= map(int,input().split())
a,b = a-1, b-1
e[a].append((t, b))
e[b].append((t, a))
ans = dijkstra(0)
print('Yes')
for i in range(1,n):
print(ans[i]+1)
| 0 | null | 25,537,742,899,340 | 166 | 145 |
def main():
N = int(input())
x, y = map(int, input().split())
a1 = x + y
a2 = x + y
b1 = y - x
b2 = y - x
N -= 1
while N != 0:
x, y = map(int, input().split())
a1 = max(a1, x + y)
a2 = min(a2, x + y)
b1 = max(b1, y - x)
b2 = min(b2, y - x)
N = N - 1
print(max(a1 - a2, b1 - b2))
main()
|
from itertools import product
for i, j in product(range(1, 10), repeat=2):
print('{}x{}={}'.format(i, j, i * j))
| 0 | null | 1,704,778,977,300 | 80 | 1 |
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
import bisect
def is_ok(x):
cnt = 0
for i, a in enumerate(A):
j = bisect.bisect_left(A, x-a)
cnt += n-j
if cnt >= m:
return True
else:
return False
l = 0
r = 2*10**5+1
while l+1 < r:
c = (l+r)//2
if is_ok(c):
l = c
else:
r = c
from itertools import accumulate
B = [0]+A
B = list(accumulate(B))
ans = 0
cnt = 0
for a in A:
j = bisect.bisect_left(A, l-a)
cnt += (n-j)
ans += B[-1]-B[j]+a*(n-j)
ans -= (cnt-m)*l
print(ans)
|
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
import bisect
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
def hand(x):
cnt=0
for i in range(n):
p=x-A[i]
cnt+=n-bisect.bisect_left(A,p)
return cnt
def main():
l=0
h=2*10**5+1
mid=(l+h)//2
while l+1<h:
mid=(l+h)//2
if hand(mid)<m:
h=mid
else:
l=mid
B=A[::-1]
for i in range(n-1):
B[i+1]+=B[i]
B=B[::-1]
ans=0
cnt=0
for i in range(n):
y=l-A[i]+1
index=bisect.bisect_left(A,y)
if n==index:
continue
else:
ans+=(n-index)*A[i]+B[index]
cnt+=(n-index)
ans+=(m-cnt)*l
print(ans)
if __name__ == "__main__":
main()
| 1 | 108,514,034,153,360 | null | 252 | 252 |
midScore =[0]*50
finScore = [0]*50
reScore = [0]*50
personNum = 0
while True:
m,f,r = map(int,input().split())
midScore[personNum] = m
finScore[personNum] = f
reScore[personNum] = r
personNum += 1
if m is f is r is -1:
break
for person in range(personNum):
totalScore = midScore[person] + finScore[person]
if midScore[person] is finScore[person] is reScore[person] is -1:
pass
elif midScore[person] == -1 or finScore[person] == -1:
print("F")
elif 80<=totalScore:
print("A")
elif 65<=totalScore<80:
print("B")
elif 50<=totalScore<65:
print("C")
elif 30<=totalScore<50:
if 50<=reScore[person]:
print("C")
else:
print("D")
elif totalScore<30:
print("F")
|
(w, h, x, y, r) = input().rstrip().split(' ')
w = int(w)
h = int(h)
x = int(x)
y = int(y)
r = int(r)
if 0 + r <= x <= w - r and 0 + r <= y <= h - r:
print('Yes')
else:
print('No')
| 0 | null | 821,023,735,468 | 57 | 41 |
x = int(input())
c = 0
bank = 100
while bank < x:
bank += bank//100
c += 1
print(c)
|
X=int(input())
i=0
t=100
while(t<X):
t *= 101
t = int(t//100)
i += 1
print(i)
| 1 | 27,092,315,750,268 | null | 159 | 159 |
a,b,c,k = map(int,input().split())
#l = [1 for i in range(a)] + [0 for i in range(b)] + [-1 for i in range(c)]
#ans = sum(l[:k])
if k <= a:
ans = k
elif (a < k) & (k <= a + b):
ans = a
elif (a + b < k) & (k <= a + b + c):
ans = a - (k - (a + b))
print(ans)
|
a, b, c, k = map(int, raw_input().split())
if k <= a:
print(k)
elif k <= a + b:
print(a)
else:
print(a - (k - a - b))
| 1 | 21,743,417,702,212 | null | 148 | 148 |
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def Main():
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = I()
print(a[k-1])
return
if __name__=='__main__':
Main()
|
n,k=map(int,input().split())
result=''
while n>=1:
b=n%k
result+=str(b)
n//=k
print(len(result))
| 0 | null | 57,258,442,750,784 | 195 | 212 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.