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
|
---|---|---|---|---|---|---|
x = int(input())
a = x%100
b = x//100
if 0<=a and a<=5*b:
print(1)
else:
print(0)
|
n, a, b = map(int, input().split())
lm = min(n, 2*10**5)
# ①nCrの各項のmod(10^9+7)を事前計算
p = 10 ** 9 + 7
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, lm + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
# ②事前計算した項を掛け合わせ
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
rt = 1
for i in range(r):
rt = (rt * (n-i)) % p
rt = rt*factinv[r] % p
return rt
def pow_r(x, n, p):
"""
O(log n)
"""
if n == 0: # exit case
return 1
if n % 2 == 0: # standard case ① n is even
return pow_r(x ** 2 % p, n // 2, p)
else: # standard case ② n is odd
return x * pow_r(x ** 2 % p, (n - 1) // 2, p) % p
rlt = pow_r(2,n,p)
rlt -= 1
rlt -= cmb(n,a,p) % p
rlt -= cmb(n,b,p) % p
while rlt < 0:
rlt += p
print(rlt)
| 0 | null | 96,800,959,981,050 | 266 | 214 |
x = int(input())
print((x//500)*1000+((x-500*(x//500))//5)*5)
|
X = int(input())
happy = 0
happy += (X // 500) * 1000
X %= 500
happy += (X // 5) * 5
print(happy)
| 1 | 42,761,841,291,260 | null | 185 | 185 |
N,X,Y=map(int,input().split())
dp=[[0]*N for i in range(N)]
dist=[0]*N
X-=1
Y-=1
for i in range(N):
for j in range(N):
if not i<j:continue
dp[i][j]=min(j-i,abs(j-Y)+1+abs(X-i))
dist[dp[i][j]]+=1
for i in dist[1:]:
print(i)
|
def main():
N = int(input())
price = [int(input()) for i in range(N)]
minv = float("inf")
maxv = -float("inf")
for p in price:
maxv = max(maxv, p-minv)
minv = min(minv, p)
print(maxv)
if __name__ == "__main__":
import os
import sys
if len(sys.argv) > 1:
if sys.argv[1] == "-d":
fd = os.open("input.txt", os.O_RDONLY)
os.dup2(fd, sys.stdin.fileno())
main()
else:
main()
| 0 | null | 21,989,857,792,100 | 187 | 13 |
a = []
for i in range(0,2):
l = list(map(int,input().split()))
a.append(l)
d = a[1][::-1]
print(' '.join(map(str,d)))
|
mod_val = 10**9+7
n, k = map(int, input().split())
factorials = [1]*(n+1) # values 0 to n
for i in range(2, n+1):
factorials[i] = (factorials[i-1]*i)%mod_val
def mod_binomial(a, b):
numerator = factorials[a]
denominator = (factorials[b]*factorials[a-b])%mod_val
invert = pow(denominator, mod_val-2, mod_val)
return (numerator*invert)%mod_val
partial = 0
# m is number of rooms with no people
for m in range(min(k+1, n)):
# m places within n to place the 'no people' rooms
# put n-(n-m) people in n-m rooms (n-m) must be placed to be non-empty
partial = (partial + (mod_binomial(n, m) * mod_binomial(n-1, m))%mod_val)%mod_val
print(partial)
| 0 | null | 33,949,515,292,900 | 53 | 215 |
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def resolve():
N = I()
A = LI()
# color_number[i][j]: [0, i)でj番目に多い色の人数
color_number = [[0, 0, 0] for _ in range(N)]
for i in range(N-1):
if A[i] in color_number[i]:
idx = color_number[i].index(A[i])
else:
idx = -1
for j in range(3):
if j==idx:
color_number[i+1][j] = color_number[i][j] + 1
else:
color_number[i+1][j] = color_number[i][j]
ans = 1
for i in range(N):
ans *= color_number[i].count(A[i])
ans %= MOD
print(ans)
if __name__ == '__main__':
resolve()
|
n = int(input())
A = list(map(int,input().split()))
data = [0]*3
ans = 1
mod = pow(10,9)+7
for i in A:
ans *= data.count(i)
ans %= mod
if ans == 0:
break
data[data.index(i)] += 1
print(ans)
| 1 | 130,167,558,246,722 | null | 268 | 268 |
import math
n,k = (int(x) for x in input().split())
An = [int(i) for i in input().split()]
left = 0
right = max(An)
def check(x):
chk = 0
for i in range(n):
chk += math.ceil(An[i]/x)-1
return chk
while right-left!=1:
x = (left+right)//2
if check(x)<=k:
right = x
else:
left = x
print(right)
|
S=input()
L=["hi","hihi","hihihi","hihihihi","hihihihihi"]
for i in L:
if i==S:
print("Yes")
exit()
print("No")
| 0 | null | 29,808,807,458,510 | 99 | 199 |
import itertools as it
n = int(input())
lst = []
for i in range(n):
x, y = list(map(int, input().split()))
lst.append([x, y])
perm = list(it.permutations(lst))
cost = []
for i in perm:
temp = 0
for j in range(len(i)-1):
temp += (((i[j][0] - i[j+1][0])**2) + ((i[j][1] - i[j+1][1])**2))**0.5
cost.append(temp)
print(sum(cost) / len(cost))
|
import itertools
import math
N=int(input())
zahyou=[list(map(int,input().split()))for i in range(N)]
jyunban=list(itertools.permutations(range(N)))
dist=list()
for i in range(len(jyunban)):
tmp=0
for j in range(N-1):
tmp+=math.sqrt((zahyou[jyunban[i][j]][0]-zahyou[jyunban[i][j+1]][0])**2+(zahyou[jyunban[i][j]][1]-zahyou[jyunban[i][j+1]][1])**2)
dist.append(tmp)
print(sum(dist)/math.factorial(N))
| 1 | 148,764,393,606,498 | null | 280 | 280 |
from collections import deque
h,w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
ans = 0
for a in range(h):
for b in range(w):
if maze[a][b] == ".":
DQ = deque([(a, b)])
visit = [[-1] * w for _ in range(h)]
visit[a][b] = 0
tmp = 0
while DQ:
px, py = DQ.popleft()
for i in range(4):
nx = px + dx[i]
ny = py + dy[i]
if 0<=nx<=h-1 and 0<=ny<=w-1 and maze[nx][ny]=="." and visit[nx][ny]==-1:
visit[nx][ny] = visit[px][py] + 1
tmp = visit[nx][ny]
DQ.append((nx, ny))
ans = max(ans, tmp)
print(ans)
|
# Https://atcoder.jp/contests/abc151/tasks/abc151_d
from collections import deque
H, W = map(int, input().split())
maze = [list(input()) for i in range(H)]
def bfs(sx, sy):
result = 0
count = [[-1] * W for i in range(H)]
count[sx][sy] = 0
d = deque()
d.append((sx, sy))
while d:
x, y = d.popleft()
result = count[x][y]
for i, j in ([1, 0], [0, 1], [-1, 0], [0, -1]):
tx, ty = x + i, y + j
if (
not (0 <= tx < H)
or not (0 <= ty < W)
or maze[tx][ty] == "#"
or count[tx][ty] != -1
):
continue
else:
count[tx][ty] = count[x][y] + 1
d.append((tx, ty))
return result
ans = 0
for i in range(W):
for j in range(H):
if maze[j][i] == ".":
ans = max(ans, bfs(j, i))
print(ans)
| 1 | 94,518,798,868,542 | null | 241 | 241 |
"""
Nが奇数のとき、絶対に末尾が0が来ることはない。したがって、答えは0。
Nが偶数の時、
N//10 * 1 + N//10**2 * 1 + ...の数だけ0ができる。
"""
N = int(input())
if N % 2 == 1:
print(0)
else:
ans = 0
ind = 1
while True:
m = 5**ind
if m > N:
break
r = N//m
r //= 2
ans += r
ind += 1
print(ans)
|
X = int(input())
syou = int(X/500)
syou_second = int((X - syou*500)/5)
ans = syou*1000 + syou_second*5
print(ans)
| 0 | null | 79,525,737,954,432 | 258 | 185 |
import math
X = int(input())
price = 100
count = 0
while price<X:
tax = price//100
price += tax
count += 1
print(count)
|
def resolve():
X = int(input())
m = 100
cnt = 0
while m < X:
m += m//100
cnt += 1
print(cnt)
if '__main__' == __name__:
resolve()
| 1 | 27,082,239,070,110 | null | 159 | 159 |
x = list(map(int, input().split()))
x0 = [x[0], x[1]]
y0 = [x[2], x[3]]
results = [(x0[0]*y0[0]), (x0[1]*y0[0]), (x0[0]*y0[1]), (x0[1]*y0[1])]
print(max(results))
|
from sys import stdin
def main():
_in = [_.rstrip() for _ in stdin.readlines()]
a, b, c, d = list(map(int, _in[0].split(' '))) # type:list(int)
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
ans = -float('inf')
for _ in [a * c, a * d, b * c, b * d]:
ans = max(ans, _)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
if __name__ == "__main__":
main()
| 1 | 3,010,910,072,434 | null | 77 | 77 |
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)
|
x,y = map(int,input().split())
for i in range(x+1):
if 2*i+4*(x-i) == y:
print('Yes')
exit()
print('No')
| 1 | 13,762,498,923,962 | null | 127 | 127 |
n = int(input())
values = [int(input()) for i in range(n)]
maxv = -999999999
minimum = values[0]
for i in range(1, n):
if values[i] - minimum > maxv:
maxv = values[i] - minimum
if values[i] < minimum:
minimum = values[i]
print(maxv)
|
N = int(raw_input())
min = int(raw_input())
max = int(raw_input())
dif = max - min
if max < min:
min = max
for i in range(N - 2):
R = int(raw_input())
if R - min > dif:
dif = R - min
if R < min:
min = R
print dif
| 1 | 13,174,028,852 | null | 13 | 13 |
import sys
input = sys.stdin.readline
n, u, v = [int(x) for x in input().split()]
import heapq
def dijkstra_heap(s):
#始点sから各頂点への最短距離
d = [float("inf")] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist,e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,[e[0]+d[v],e[1]])
return d
################################
n, w = n, n - 1 #n:頂点数 w:辺の数
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
x,y = map(int,input().split())
z = 1
edge[x - 1].append([z,y - 1])
edge[y - 1].append([z,x - 1])
takahashi = dijkstra_heap(u - 1)
aoki = dijkstra_heap(v - 1)
ans = -1
for i, j in zip(takahashi, aoki):
if j - i > 0:
ans = max(ans, j - 1)
print(ans)
|
import sys
from collections import deque
input = sys.stdin.readline
class Node:
def __init__(self, num):
self.link = []
self.costs = [num, num]
self.check = False
def clear_nodes(nodes):
for node in nodes:
node.check = False
def main():
N, u, v = map(int, input().split())
nodes = [Node(N+1) for i in range(N+1)]
for i in range(N-1):
a, b = map(int, input().split())
nodes[a].link.append(nodes[b])
nodes[b].link.append(nodes[a])
starts = [u, v]
for i in range(2):
clear_nodes(nodes)
q = deque()
q.append((nodes[starts[i]], 0))
while len(q) > 0:
node, cost = q.popleft()
node.costs[i] = cost
for next_node in node.link:
if not next_node.check:
q.append((next_node, cost + 1))
next_node.check = True
if nodes[u].costs[1] == 1:
print(0)
return
clear_nodes(nodes)
q = deque()
ans = 0
q.append(nodes[u])
while len(q) > 0:
node = q.popleft()
ans = max(ans, node.costs[1])
for next_node in node.link:
if (not next_node.check) and next_node.costs[0] < next_node.costs[1]:
q.append(next_node)
next_node.check = True
print(ans - 1)
if __name__ == "__main__":
main()
| 1 | 117,039,244,186,192 | null | 259 | 259 |
H=1
W=1
while H!=0 or W!=0:
H,W = [int(i) for i in input().split()]
if H!=0 or W!=0:
for i in range(H):
for j in range(W):
print('#',end='')
print()
print()
|
n,k = map(int, input().split())
ans = 0
for i in range(k,n+2):
a = (i-1)*i//2
ans += n*i-2*a+1
print(ans%(10**9+7))
| 0 | null | 16,840,857,461,988 | 49 | 170 |
n = int(input())
count = 0
room = [int(0) for i in range(4) for j in range(3) for k in range(10)]
while count < n:
x = list(map(lambda k: int(k), input().split(" ")))
room[(x[0]-1)*30+(x[1]-1)*10+(x[2]-1)] += x[3]
count += 1
for i in range(4):
if i != 0:
print("####################")
for j in range(3):
for k in range(10):
print(" %d" % room[30*i+10*j+k], end="")
print("")
|
"""
Nが奇数のとき、絶対に末尾が0が来ることはない。したがって、答えは0。
Nが偶数の時、
N//10 * 1 + N//10**2 * 1 + ...の数だけ0ができる。
"""
N = int(input())
if N % 2 == 1:
print(0)
else:
ans = 0
ind = 1
while True:
m = 5**ind
if m > N:
break
r = N//m
r //= 2
ans += r
ind += 1
print(ans)
| 0 | null | 58,540,810,021,340 | 55 | 258 |
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')
from collections import deque
def solve():
N = II()
E = [[] for _ in range(N)]
for i in range(N-1):
a, b = MI1()
E[a].append((b, i))
E[b].append((a, i))
q = deque([(0, -1, -1)])
ans = [0] * (N-1)
while len(q) > 0:
current, v_pre, c_pre = q.popleft()
color = 1
for (nv, idx) in E[current]:
if nv == v_pre: continue
if color == c_pre:
color += 1
q.append((nv, current, color))
ans[idx] = color
color += 1
print(max(ans))
printlist(ans)
if __name__ == '__main__':
solve()
|
N = int(input())
es = [[] for _ in range(N)]
connected = [0] * N
for i in range(N-1):
a,b = map(int, input().split())
a,b = a-1, b-1
connected[a] += 1
connected[b] += 1
es[a].append((b, i))
es[b].append((a, i))
ans = [0] * (N-1)
used = [False] * (N-1)
q = []
q.append((0, 0))
while q:
curr, pc = q.pop()
nxt_es_color = 1
for nxt, es_num in es[curr]:
if used[es_num]:
continue
if nxt_es_color == pc:
nxt_es_color += 1
ans[es_num] = nxt_es_color
used[es_num] = True
q.append((nxt, ans[es_num]))
nxt_es_color += 1
print(max(connected))
print(*ans, sep="\n")
| 1 | 135,934,538,961,760 | null | 272 | 272 |
H, N = map(int, input().split())
A = []
B = []
for n in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
INF = float('inf')
dp = [INF] * (H + max(A))
dp[0] = 0
# dp[i]を、HP iを減らすために必要な最小の魔力とする
for hp in range(1, H+1):
for n in range(N):
dp[hp] = min(dp[max(hp-A[n],0)] + B[n], dp[hp])
print(dp[H])
|
H,A = map(int,input().split())
b = H // A
c = H % A
if c != 0:
b += 1
print(b)
| 0 | null | 78,910,253,444,778 | 229 | 225 |
s = input()
t = input()
if (s == t[0:len(s)]) and (len(s)+1 == len(t)):
print("Yes")
else:
print("No")
|
N, M = map(int, input().split())
A = sum(map(int, input().split()))
if N-A >= 0:
print(N-A)
else:
print(-1)
| 0 | null | 26,669,414,523,598 | 147 | 168 |
# 問題文誤読して30分経過してた
# ソートしたとき「自分より小さいいずれの値も自分の素因数に含まれない」
# これはなんか実装しにくいので、A<10^6を利用して、調和級数的なノリでやってみる
n = int(input())
a = sorted(list(map(int, input().split())))
t = {}
for av in a:
if av not in t:
t[av] = 1
else:
t[av] += 1
limit = a[-1]
d = [True] * (limit + 1)
for av in a:
start = av
# 複数あった場合は自分自身も粛清の対象になる
if t[av] == 1:
start *= 2
for i in range(start, limit + 1, av):
d[i] = False
ans = 0
for av in a:
if d[av]:
ans += 1
print(ans)
|
x, y = map(int,input().split())
ans = 0
for i in range(x+1):
for j in range(x+1):
if 2*i + 4 * j == y and i + j == x:
ans += 1
if ans > 0:
print('Yes')
else:
print('No')
| 0 | null | 14,138,900,699,748 | 129 | 127 |
def popcnt(n):
return bin(n).count("1")
def f(n):
cnt = 0
while n>0:
n = n%popcnt(n)
cnt += 1
return cnt
def solve(X):
Y = int(X, 2)
c = X.count("1")
m, p = c-1, c+1
Ym, Yp = Y%m if m else -1, Y%p
for i in range(N):
if X[i] == "1":
Y = (Ym - pow(2,N-i-1,m))%m if Ym!=-1 else -1
else:
Y = (Yp + pow(2,N-i-1,p))%p
print(f(Y) + 1 if Y!=-1 else 0)
N = int(input())
solve(input())
|
N=int(input())
X=input()
popcount=X.count('1')
bi1=[]
bi0=[]
Xnum1 = 0
Xnum0 = 0
if popcount != 1:
for i in range(N):
if i==0: bi1.append(1)
else: bi1.append(bi1[i-1]*2%(popcount-1))
Xnum1 = (Xnum1 + int(X[N-i-1])*bi1[i])%(popcount-1)
for i in range(N):
if i==0: bi0.append(1)
else: bi0.append(bi0[i-1]*2%(popcount+1))
Xnum0 = (Xnum0 + int(X[N-i-1])*bi0[i])%(popcount+1)
for i in range(N):
if popcount==1 and X[i]=='1':
print(0)
continue
if X[i]=='1':
Xi = (Xnum1 - bi1[N-i-1])%(popcount-1)
else:
Xi = (Xnum0 + bi0[N-i-1])%(popcount+1)
ans = 1
while Xi!=0:
Xi = Xi % bin(Xi).count('1')
ans += 1
print(ans)
| 1 | 8,126,905,940,660 | null | 107 | 107 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i, j in zip(a[:n-k], a[k:]):
if i < j:
print('Yes')
else:
print('No')
|
def main():
n, k = [int(x) for x in input().split()]
scores = [int(x) for x in input().split()]
for index in range(n - k):
if scores[index] < scores[index + k]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 1 | 7,022,923,138,392 | null | 102 | 102 |
# coding=utf-8
def fib(number):
if number == 0 or number == 1:
return 1
memo1 = 1
memo2 = 1
for i in range(number-1):
memo1, memo2 = memo1+memo2, memo1
return memo1
if __name__ == '__main__':
N = int(input())
print(fib(N))
|
N = int(input())
memolist = [-1]*(N+1)
def fib(x):
if memolist[x] == -1:
if x == 0 or x == 1:
memolist[x] = 1
else:
memolist[x] = fib(x - 1) + fib(x - 2)
return memolist[x]
print(fib(N))
| 1 | 1,905,472,322 | null | 7 | 7 |
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def SI():
return int(readline())
def MI():
return map(int, readline().split())
def MLI():
return map(int, open(0).read().split())
inf = float("inf")
def check(k, P, W):
count = 1
tmp_sum = 0
for w in W:
if tmp_sum + w <= P:
tmp_sum += w
else:
tmp_sum = w
count += 1
if count <= k:
return True
else:
return False
def main():
n, k, *W = MLI()
lb = max(W)
ub = sum(W)
while ub - lb > 1:
P = (lb + ub) // 2
if check(k, P, W):
ub = P
else:
lb = P
if check(k, lb, W):
print(lb)
else:
print(ub)
if __name__ == "__main__":
main()
|
N, K = map(int, input().split())
w = [int(input()) for _ in range(N)]
def f(P):
tmp_capacity = P
num_used_truck = 1
i = 0
while i <= N-1:
if w[i] > P:
return i
if w[i] > tmp_capacity:
tmp_capacity = P
num_used_truck += 1
if num_used_truck >= K+1:
return i
tmp_capacity -= w[i]
i += 1
return i
left = 0
right = 1e9
mid = right
flag = 0
while right - left > 1:
mid = (left + right)//2
tmp = f(mid)
if tmp >= N:
right = mid
elif tmp < N:
left = mid
print(int(right))
| 1 | 92,080,335,872 | null | 24 | 24 |
import sys
import decimal # 10進法に変換,正確な計算
def input():
return sys.stdin.readline().strip()
def main():
a, b = map(int, input().split())
c = a - b*2
if c < 0:
print(0)
return
print(c)
main()
|
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): 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('utf-8')
def main():
n=II()
A=[]
B=[]
for _ in range(n):
a,b=MI()
A.append(a)
B.append(b)
A.sort()
B.sort()
#print(A,B)
r=n//2
l=(n-1)//2
#print(l,r)
mi=A[l]+A[r]
ma=B[l]+B[r]
ans=(ma-mi)-(ma-mi)*(n%2)//2+1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 91,565,245,725,980 | 291 | 137 |
import sys
input = sys.stdin.readline
from collections import deque
import math
n, d, a = map(int, input().split())
XH = []
for _ in range(n):
x, h = map(int, input().split())
XH.append((x, h))
XH.sort()
answer = 0
damage = 0
QUEUE = deque()
for x, h in XH:
if QUEUE:
while x > QUEUE[0][0]:
damage -= QUEUE[0][1]
QUEUE.popleft()
if not QUEUE:
break
h -= damage
if h <= 0:
continue
bomb = math.ceil(h / a)
QUEUE.append((x + 2 * d, a * bomb))
damage += a * bomb
answer += bomb
print(answer)
|
from collections import defaultdict
N = int(input())
X = list(map(int, input().split()))
ctr = defaultdict(int)
ans = 0
for i in range(N):
ctr[i + X[i]] += 1
ans += ctr[i - X[i]]
print(ans)
| 0 | null | 54,113,789,794,180 | 230 | 157 |
N = int(input())
if N%2 == 0:
print(0.5000000000)
else:
odd = N//2 + 1
print(odd/N)
|
n = int(input())
nn = []
odd = 0
for i in range(1, n+1):
if i % 2 == 1:
odd += 1
nn.append(i)
s = len(nn)
print(odd/s)
| 1 | 177,558,579,339,152 | null | 297 | 297 |
A,B,C=[int(s) for s in input().split()]
X=int(input())
count=0
while A>=B:
B*=2
count+=1
while B>=C:
C*=2
count+=1
if count<=X:
print('Yes')
else:
print('No')
|
A,B,C = map(str, input().split())
l = str(C)+str(' ')+str(A)+str(' ')+str(B)
print(l)
| 0 | null | 22,368,401,724,416 | 101 | 178 |
n,k=map(int,input().split())
def main(n,k):
if n//k:
return main(n//k,k)+str(n%k)
return str(n%k)
print(len(main(n,k)))
|
S = int(input())
for i in range(9) :
i = i + 1
if S % i == 0 and S // i <= 9:
result = "Yes"
break
else :
result = "No"
print(result)
| 0 | null | 111,954,345,633,712 | 212 | 287 |
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
MAX = 60
acc = [0] * MAX
ans = [0] * MAX
num = a[0]
for i in range(MAX):
if num & 1:
acc[i] = 1
num >>= 1
for i, e in enumerate(a[1:], 1):
for j in range(MAX):
if e & 1:
ans[j] += i - acc[j]
acc[j] += 1
else:
ans[j] += acc[j]
e >>= 1
ans_num = 0
for i, e in enumerate(ans):
ans_num += pow(2, i, mod) * e
ans_num %= mod
print(ans_num)
|
n=int(input())
l=sorted(list(map(int,input().split())))
for i,x in enumerate(l):
l[i]=format(x,'63b')
memo=[0]*63
for i in range(63):
for j in range(n):
if l[j][i]=='1':
memo[-i-1]+=1
now=1
ans=0
mod=10**9+7
for x in memo:
ans+=(now*x*(n-x))%mod
now*=2
print(ans%mod)
| 1 | 122,535,682,457,110 | null | 263 | 263 |
def show(array):
for i in range(len(array)):
if i != len(array) - 1:
print(array[i], end=' ')
else:
print(array[i])
def bubbleSort(array):
flag = True
count = 0
while flag:
flag = False
for j in sorted(range(1, len(array)), reverse=True):
if array[j] < array[j - 1]:
array[j], array[j - 1] = [array[j - 1], array[j]]
flag = True
count += 1
show(array)
return count
input()
array = [int(x) for x in input().split()]
print(bubbleSort(array))
|
N=int(input())
A=list(map(int,input().split()))
count=0
i=N-1
while i>0:
j=0
while j<i:
if A[N-1-j]<A[N-2-j]:
(A[N-1-j],A[N-2-j])=(A[N-2-j],A[N-1-j])
count+=1
#print(' '.join(map(str,A)))
j+=1
i-=1
print(' '.join(map(str,A)))
print(count)
| 1 | 16,449,900,548 | null | 14 | 14 |
n = int(input().rstrip())
num_list = [int(x) for x in input().rstrip().split(" ")]
count = 0
for i in range(0,n,2):
count += num_list[i]%2!=0
print(count)
|
n = input()
cards = []
for i in range(n):
cards.append(raw_input().split())
marks = ['S', 'H', 'C', 'D']
for i in marks:
for j in range(1, 14):
if [i, str(j)] not in cards:
print i, j
| 0 | null | 4,412,015,842,910 | 105 | 54 |
n = int(input())
a = 0
for i in range(10):
for j in range(10):
if i*j == n:
a +=1
if a == 0:
print("No")
else:
print("Yes")
|
N=int(input())
resurt=''
for i in range(1,10):
if N%i ==0 and N//i<=9:
result='Yes'
break
else:
result='No'
print(result)
| 1 | 159,658,457,054,432 | null | 287 | 287 |
H = int(input())
W = int(input())
N = int(input())
a = max(H, W)
print((N+a-1)//a)
|
n, k = map(int, input().split())
A = list(map(int, input().split()))
now = 1000
for i in range(k, n):
#print(A[i], A[i-k])
if A[i] > A[i-k]:
print("Yes")
else:
print("No")
| 0 | null | 47,850,914,586,970 | 236 | 102 |
H=[]
W=[]
while 1:
h,w=map(int,raw_input().split())
if h==w==0:
break
H.append(h)
W.append("#"*w)
for i in xrange(len(W)):
for j in xrange(H[i]):
print(W[i])
print
|
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect_right
from itertools import accumulate
n,m,k=nii()
a=lnii()
b=lnii()
ar=[0]+list(accumulate(a))
br=list(accumulate(b))
ans=0
for i in range(n+1):
time=ar[i]
if time>k:
break
t_ans=i
inx=bisect_right(br,k-time)
t_ans+=inx
ans=max(ans,t_ans)
print(ans)
| 0 | null | 5,768,272,947,190 | 49 | 117 |
def resolve():
N = int(input())
X = input()
if N == 1:
if X.count("1"):
print(0)
else:
print(1)
return True
base_1_count = X.count("1")
if base_1_count == 0:
for _ in range(N):
print(1)
return True
X_int = int(X, 2)
X_int_p = X_int%(base_1_count + 1)
# RE 対策
if base_1_count == 1:
for i in range(N):
if X[i] == "1":
print(0)
else:
if i == N - 1:
Xi = X_int_p + 1
else:
Xi = X_int_p
count = 1
while Xi != 0:
Xi %= bin(Xi).count("1")
count += 1
print(count)
return True
X_int_m = X_int%(base_1_count - 1)
for i in range(N):
# 初期値計算を高速にやる
if X[i] == "1":
temp_1_count = base_1_count-1
pow_2 = pow(2, N-i-1, base_1_count-1)
if X_int_m <= pow_2:
Xi = X_int_m - pow_2 + base_1_count-1
else:
Xi = X_int_m - pow_2
else:
temp_1_count = base_1_count+1
Xi = X_int_p + pow(2, N-i-1, base_1_count+1)
while Xi >= base_1_count+1:
Xi %= base_1_count+1
# print("1_c={0}".format(temp_1_count))
if temp_1_count == Xi:
print(1)
continue
count = 1
while Xi != 0:
num_of_1 = bin(Xi).count("1")
Xi %= num_of_1
count += 1
print(count)
if __name__ == "__main__":
resolve()
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
n = I()
x = input()
cnt = x.count("1")
if cnt == 1:
for i in range(n):
if x[i] == "1":
print(0)
elif i == n - 1:
print(2)
else:
print(1)
exit()
def f(x):
if x==0:
return 0
return 1+f(x%bin(x).count('1'))
xx = int(x, 2)
Y = xx % (cnt + 1)
Z = xx % (cnt - 1)
for i in range(n):
if x[i] == '1':
print(1 + f((Z - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)))
else:
print(1 + f((Y + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)))
| 1 | 8,260,552,925,768 | null | 107 | 107 |
k=int(input())
a,b=map(int,input().split())
flag=0
for i in range(1001):
if a<=k*i<=b:
print("OK")
flag+=1
break
if flag==0:
print("NG")
|
K = int(input())
A,B = map(int, input().split())
target = 0
target = B - B % K
if A <= target:
print('OK')
else:
print('NG')
| 1 | 26,550,282,378,812 | null | 158 | 158 |
X, Y = map(int, input().split())
ans = 'No'
for a in range(X + 1):
b = X - a
if Y == 2 * a + 4 * b:
ans = 'Yes'
break
print(ans)
|
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())
def main():
X, Y = i_map()
ans = False
z = Y - (X * 2)
if z < 0:
pass
elif z == 0 or (z % 2 == 0 and (z // 2) <= X):
ans = True
print("Yes" if ans else "No")
if __name__ == "__main__":
main()
| 1 | 13,725,583,147,224 | null | 127 | 127 |
import queue
N, U, V = map(int, input().rstrip().split())
U -= 1
V -= 1
v2e = [set() for _ in range(N)]
for _ in range(N-1):
a, b = map(lambda x: int(x)-1, input().rstrip().split())
v2e[a].add(b)
v2e[b].add(a)
q = queue.Queue()
q.put(U)
p = [-1] * N
p[U] = U
while True:
a = q.get()
if a == V:
break
for b in v2e[a]:
if p[b] == -1:
p[b] = a
q.put(b)
a = V
min_p = []
while True:
min_p.append(a)
if a == U:
break
a = p[a]
p = [-1] * N
p[min_p[(len(min_p)-1)//2-len(min_p)%2]] = min_p[(len(min_p)-1)//2-len(min_p)%2]
for a in v2e[min_p[(len(min_p)-1)//2-len(min_p)%2]]:
p[a] = a
p[min_p[-len(min_p)//2+len(min_p)%2]] = min_p[-len(min_p)//2+len(min_p)%2]
q = queue.Queue()
q.put((min_p[-len(min_p)//2+len(min_p)%2], 0))
while q.qsize() > 0:
a, d = q.get()
for b in v2e[a]:
if p[b] == -1:
p[b] = a
q.put((b, d + 1))
print(d + (len(min_p) - 2) // 2 + len(min_p) % 2)
|
# abc158_b.py
# https://atcoder.jp/contests/abc158/tasks/abc158_b
# B - Count Balls /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点
# 問題文
# 高橋君は青と赤の 2色のボールを持っており、これらを一列に並べようとしています。
# 初め、列にボールはありません。
# 根気のある高橋君は、次の操作を 10100回繰り返します。
# 列の末尾に、A個の青いボールを加える。その後、列の末尾に B個の赤いボールを加える。
# こうしてできる列の先頭から N個のボールのうち、青いボールの個数はいくつでしょうか。
# 制約
# 1≤N≤1018
# A,B≥0
# 0<A+B≤1018
# 入力は全て整数である
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N A B
# 出力
# 列の先頭から N個のボールのうち、青いボールの個数を出力せよ。
# 入力例 1
# 8 3 4
# 出力例 1
# 4
# 青いボールをb、赤いボールを rで表すと、列の先頭から 8個のボールは bbbrrrrb であるので、このうち青いボールは 4個です。
# 入力例 2
# 8 0 4
# 出力例 2
# 0
# そもそも赤いボールしか並んでいません。
# 入力例 3
# 6 2 4
# 出力例 3
# 2
# bbrrrr のうち青いボールは 2個です。
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
# FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
# N = int(lines[0])
N, A, B = list(map(int, lines[0].split()))
# values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
q, mod = divmod(N, A+B)
result = q*A + min(mod, A)
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['8 3 4']
lines_export = [4]
if pattern == 2:
lines_input = ['8 0 4']
lines_export = [0]
if pattern == 3:
lines_input = ['6 2 4']
lines_export = [2]
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
| 0 | null | 86,614,738,607,360 | 259 | 202 |
def is_prime(num):
i = 2
while i * i <= num:
if num % i == 0:
return False
i += 1
return True
N = int(input())
num_list = [int(input()) for _ in range(N)]
print(sum(is_prime(num) for num in num_list))
|
# floor(a/b)=(a-(a%b))/b
# ax%b=a(x%b)%b
a,b,n=map(int,input().split())
if(n>=b-1):
print(a*(b-1)//b)
else:
print(a*n//b)
| 0 | null | 14,100,492,757,790 | 12 | 161 |
def az16():
list = []
n = input()
for i in range(0,n):
list.append(raw_input().split())
for mark in ["S","H","C","D"]:
for i in range(1,14):
if [mark,repr(i)] not in list:
print mark,i
az16()
|
import sys
n = input()
a = []
flag = {}
for j in range(1, 14):
flag[('S',j)] = 0
flag[('H',j)] = 0
flag[('C',j)] = 0
flag[('D',j)] = 0
for i in range(n):
temp = map(str, raw_input().split())
a.append((temp[0],temp[1]))
#print a[i][0]
#print a[i][1]
card = ['S', 'H', 'C', 'D']
#print card
for egara in card:
for i in range(n):
if(a[i][0] == egara):
for j in range(1,14):
if(int(a[i][1]) == j):
flag[(egara, j)] = 1
for egara in card:
for j in range(1,14):
if(flag[(egara, j)] == 0):
sys.stdout.write(egara)
sys.stdout.write(' ')
sys.stdout.write(str(j))
print
exit(0)
| 1 | 1,043,724,780,548 | null | 54 | 54 |
n = int(input())
odd = n//2 + n%2
print(odd/n)
|
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
r = 0
for i, x in enumerate(permutations([j for j in range(1,N+1)])):
if x == P:
r = abs(r-i)
if x == Q:
r = abs(r-i)
print(r)
| 0 | null | 139,239,414,573,480 | 297 | 246 |
# coding: utf-8
while True:
try:
data = map(int, raw_input().split())
if data[0] > data[1]:
a = data[0]
b = data[1]
else:
a = data[1]
b = data[0]
r = 1
while r > 0:
q = a / b
r = a - b * q
a = b
b = r
gcd = a
lcm = data[0] * data[1] / gcd
print("{:} {:}".format(gcd, lcm))
except EOFError:
break
|
import math
while True:
try:
a, b = list(map(int, input().split()))
print('{0} {1}'.format(math.gcd(a, b), int(a * b / math.gcd(a, b))))
except EOFError:
break
| 1 | 517,511,928 | null | 5 | 5 |
n = int(input())
mod = 10**9+7
ans = pow(10,n)
ans -= pow(9,n)*2
ans += pow(8,n)
print(ans%mod)
|
N = int(input())
MOD = 10**9+7
a10 = 10**N
a9 = 9**N
a8 = 8**N
print((a10-a9-a9+a8) % MOD)
| 1 | 3,193,035,472,000 | null | 78 | 78 |
#!/usr/bin/python3
# -*- coding:utf-8 -*-
from math import factorial
def main():
s = list(map(int, input().strip()))
k = int(input())
dp = []
dp.append([[0]*(len(s)+1) for _ in range(k+1)])
dp.append([[0]*(len(s)+1) for _ in range(k+1)])
dp[0][0][0] = 1
for i, c in enumerate(s):
for j in range(k+1):
for d in range(10):
nj = j
if d != 0:
nj+=1
if nj > k:
continue
if d < c:
dp[1][nj][i+1] += dp[0][j][i]
if d == c:
dp[0][nj][i+1] += dp[0][j][i]
dp[1][nj][i+1] += dp[1][j][i]
print(dp[0][k][len(s)]+dp[1][k][len(s)])
if __name__=='__main__':
main()
|
mod = 1000000007
N = int(input())
A = list(map(int, input().split()))
C = [0,0,0]
ans = 1
i = 0
while i < N:
a = A[i]
cnt = sum([1 if C[j] == a else 0 for j in range(3)])
ans = (ans*cnt)%mod
if C[0] == a:
C[0] += 1
elif C[1] == a:
C[1] += 1
else:
C[2] += 1
i += 1
print(ans)
| 0 | null | 102,747,719,924,542 | 224 | 268 |
from itertools import permutations
from math import factorial
n = int(input())
p = tuple(map(int, input().split(' ')))
q = tuple(map(int, input().split(' ')))
l = [i for i in range(1, n+1)]
ls = list(permutations(l))
for i in range(factorial(n)):
if p==ls[i]:
a = i
if q==ls[i]:
b = i
print(abs(a-b))
|
import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
target= range(1,n+1)
p_len=0
q_len=0
for i,v in enumerate(itertools.permutations(target,n)):
tmp=list(v)
if p==tmp:
p_len=i
if q==tmp:
q_len=i
print(abs(p_len-q_len))
| 1 | 100,437,872,057,952 | null | 246 | 246 |
import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def solve():
X = int(rl())
print(10 - X // 200)
if __name__ == '__main__':
solve()
|
# -*- coding: utf-8 -*-
import sys
import os
import math
N = int(input())
A = list(map(int, input().split()))
def bubble_sort(A):
swap_num = 0
while True:
swapped = False
for i in range(N - 1):
if A[i] > A[i + 1]:
A[i], A[i + 1] = A[i + 1], A[i]
swap_num += 1
swapped = True
if not swapped:
return A, swap_num
A, num = bubble_sort(A)
print(*A)
print(num)
| 0 | null | 3,394,645,043,140 | 100 | 14 |
import math
n = int(input())
ans = math.ceil(n/1.08)
if n != math.floor(ans*1.08):
print(r':(')
else:
print(ans)
|
import math
n = int(input())
f = math.floor(n / 1.08)
c = math.ceil(n / 1.08)
for i in [f, c]:
if math.floor(i*1.08) == n:
print(i)
exit()
print(':(')
| 1 | 125,767,136,777,068 | null | 265 | 265 |
N,K,C=map(int, input().split())
S=input()
L=[0]*N
R=[0]*N
c=1
last=-C-1
for i in range(N):
if i-last>C and S[i]!='x' and c<=K:
L[i]=c
c+=1
last=i
c=K
last=N+C
for i in range(N-1,-1,-1):
if last-i>C and S[i]!='x' and c>=1:
R[i]=c
c-=1
last=i
for i in range(N):
if 0<L[i]==R[i]: print(i+1)
|
N,K,C=map(int,input().split())
S=input()
L=[0 for i in range(K)]
R=[0 for i in range(K)]
n=0
rc=0
lc=0
while True:
if lc==K:
break
if S[n]=="o":
L[lc]=n+1
n+=C+1
lc+=1
else:
n+=1
n=N-1
while True:
if rc==K:
break
if S[n]=="o":
R[K-1-rc]=n+1
n-=C+1
rc+=1
else:
n-=1
for i in range(K):
if R[i]==L[i]:
print(R[i])
| 1 | 40,601,288,222,732 | null | 182 | 182 |
X = int(input())
A = 0
B = 0
if X >= 500:
A = X // 500
X = X % 500
if X >= 5:
B = X // 5
X = X % 5
print(A * 1000 + B * 5)
|
n = int(input())
ans = 0
if n//500>0:
ans += 1000 * (n//500)
n = n - 500 * (n//500)
if n//5>0:
ans += 5 * (n//5)
print(ans)
| 1 | 42,595,650,090,950 | null | 185 | 185 |
name = input()
str_name = str(name)
print(str_name[:3])
|
S=input()
S=str(S)
print(S[0]+S[1]+S[2])
| 1 | 14,680,813,215,248 | null | 130 | 130 |
from math import ceil
h = int(input())
w = int(input())
n = int(input())
print(ceil(n/max(h,w)))
|
dice = list(input().split(' '))
a = list(input())
for i in a:
if i == 'W':
dice = [dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]]
elif i == 'S':
dice = [dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]]
elif i == 'N':
dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
elif i == 'E':
dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
print(dice[0])
| 0 | null | 44,636,449,890,318 | 236 | 33 |
# coding: utf-8
# Your code here!
n=int(input())
x=input()
ones=x.count("1")
a=ones+1
b=ones-1
xda=0
xdb=0
for i in range(n):
if x[-1-i]=="1":
xda+=pow(2,i,a)
xda%=a
if b==0:
continue
xdb+=pow(2,i,b)
xdb%=b
xds=[-1]*n
for i in range(n):
if x[-1-i]=="0":
xds[-1-i]=(xda+pow(2,i,a))%a
else:
if b==0:
continue
xds[-1-i]=(xdb-pow(2,i,b))%b
def popcount(x):
return bin(x).count("1")
def solve(x):
if x<0:
return -1
if x==0:
return 0
cnt=0
while x>0:
cnt+=1
x=x%popcount(x)
return cnt
for xd in xds:
print(1+solve(xd))
|
N = int(input())
n = N%10
honList = [2, 4, 5, 7, 9]
ponList = [0, 1, 6, 8]
if n in honList:
print('hon')
elif n in ponList:
print('pon')
else :
print('bon')
| 0 | null | 13,785,391,424,810 | 107 | 142 |
from collections import defaultdict
h,w,m = map(int,input().split())
dh = defaultdict(int)
dw = defaultdict(int)
l=defaultdict(tuple)
for _ in range(m):
x,y = map(int,input().split())
dh[x]+=1
dw[y]+=1
l[(x,y)]=1
m = 0
for i in range(1,h+1):
if dh[i]>m:
m = dh[i]
hi=i
c=m
m = 0
for i in range(1,w+1):
d = dw[i]
if l[(hi,i)]==1:
d-=1
m = max(m,d)
c+=m
m = 0
wi=0
for i in range(1,w+1):
if dw[i]>m:
m = dw[i]
wi=i
c2=m
m = 0
for i in range(1,h+1):
d = dh[i]
if l[(i,wi)]==1:
d-=1
m = max(m,d)
c2+=m
print(max(c,c2))
|
import sys
import copy
import math
import itertools
import numpy as np
S=input()
N = len(S)+1
a = [0]*N
b = [0]*N
for i in range(N-1):
if S[i]=="<":
a[i+1]=a[i]+1
for i in reversed(range(N-1)):
if S[i]==">":
b[i]=b[i+1]+1
for i in range(N):
if a[i] < b[i]:
a[i]=b[i]
print(sum(a))
| 0 | null | 80,855,576,779,902 | 89 | 285 |
#coding:utf-8
buff = [int(x) for x in input().split()]
a = buff[0]
b = buff[1]
c = buff[2]
print(len([x for x in [x+a for x in range(b - a + 1)] if c%x==0]))
|
[a, b, c] = [int(number) for number in input().split()];
count = 0;
for i in range(a, b + 1):
if (c % i == 0):
count += 1;
print(count);
| 1 | 549,272,477,000 | null | 44 | 44 |
n = int(input())
A = list(map(int, input().split()))
N = sorted(range(1, n + 1), key=lambda x: A[x - 1])
print(*N)
|
N = int(input())
S = list(map(int,input().split()))
m = [0 for _ in range(N)]
for i in range(N):
m[S[i]-1] = i+1
print(*m,sep=" ")
| 1 | 180,953,169,238,972 | null | 299 | 299 |
def main():
a, b = map(int, input().split())
for i in range(1, 2000):
if i * 8 // 100 == a and i * 10 // 100 == b:
print(i)
break
else:
print(-1)
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
import sys
import decimal
def input():
return sys.stdin.readline()[:-1]
def main():
A, B = map(int, input().split())
for i in range(1, 10 ** 4):
a = int(decimal.Decimal(i * 0.08))
b = int(decimal.Decimal(i * 0.1))
if a == A and b == B:
print(i)
exit()
print(-1)
if __name__ == '__main__':
main()
| 1 | 56,731,321,654,480 | null | 203 | 203 |
while True:
m, f, r = [int(_) for _ in input().split()]
if m == -1 and f == -1 and r == -1:
break
sum = m+f
if m == -1 or f == -1 or sum < 30:
print("F")
else:
if sum >= 80:
print("A")
elif sum >= 65:
print("B")
elif sum >= 50:
print("C")
else:
if r >= 50:
print("C")
else:
print("D")
|
while(True):
m, f, r = map(int, input().split(" "))
if (m == -1) and (f == -1) and (r == -1):
exit()
if (m == -1) or (f == -1):
print("F")
elif (m + f >= 80):
print("A")
elif (m + f >= 65) and (m + f < 80):
print("B")
elif (m + f >= 50) and (m + f < 65):
print("C")
elif (m + f >= 30) and (m + f < 50):
if (r >= 50):
print("C")
else:
print("D")
else:
print("F")
| 1 | 1,241,790,002,108 | null | 57 | 57 |
import itertools
n,k = map(int, input().split())
di = [0] * k
Ai_di = []
for i in range(k):
di[i] = int(input())
Ai_di.append(list(map(int, input().split())))
ans_set = set(list(itertools.chain.from_iterable(Ai_di)))
print(n - len(ans_set))
|
def main():
S = input()
N = len(S)+1
a = [0]*(N)
#右側からみていく
for i in range(N-1):
if S[i] == '<':
a[i+1] = max(a[i]+1,a[i+1])
#print(a)
#左側から見ていく
for i in range(N-2,-1,-1):
#print(i)
if S[i] == '>':
a[i] = max(a[i+1]+1,a[i])
ans = 0
#print(a)
for i in range(N):
ans += a[i]
return ans
print(main())
| 0 | null | 90,696,703,877,170 | 154 | 285 |
d,t,s= map(int,input().split(" "))
print("Yes" if t>=d*1.0/s else "No")
|
#輸入字串並分隔,以list儲存
str_in = input()
num = [int(n) for n in str_in.split()]
num =list(map(int, str_in.strip().split()))
#print(num) #D,T,S
#若T<(D/S)->遲到
if num[1] >= (num[0]/num[2]):
print("Yes")
else:
print("No")
| 1 | 3,505,505,761,308 | null | 81 | 81 |
n = int(input())
a = list(map(int, input().split()))
last = 0
count = 0
flag = True
while flag:
flag = False
for i in range( n-1, last, -1 ):
if a[i] < a[i-1]:
t = a[i]
a[i] = a[i-1]
a[i-1] = t
count += 1
flag = True
last += 1
print(*a)
print(count)
|
# -*- coding: utf 8 -*-
# Bubble Sort
# 2019. 4/22
def bubbleSort(A, N):
sw = 0
flag = 1
i = 0
while flag:
flag = 0
for j in range(int(N) - 1, i, -1):
if A[j - 1] > A[j]:
A[j], A[j - 1] = A[j - 1], A[j]
flag = 1
sw = sw + 1
i = i + 1
return A, sw
if __name__ == '__main__':
N = int(input())
A = list(map(int, input().split()))
A_sorted, num_sw = bubbleSort(A, N)
for i in range(N-1):
print(A[i], end=" ")
print(A[N-1])
print(num_sw)
| 1 | 16,275,118,130 | null | 14 | 14 |
#!/usr/bin/env python3
l, r, d = map(int, input().split())
n = (l-1) // d + 1
m = r // d
print(m-n+1)
|
N = int(input())
stone = input()
R = stone.count('R')
ans = stone.count('W', 0, R)
print(ans)
| 0 | null | 6,922,002,001,838 | 104 | 98 |
n=int(input());
print(10-(n//200));
|
X = int(input())
if X <= 599:
print(8)
elif X <= 799:
print(7)
elif X <= 999:
print(6)
elif X <= 1199:
print(5)
elif X <= 1399:
print(4)
elif X <= 1599:
print(3)
elif X <= 1799:
print(2)
elif X <= 1999:
print(1)
| 1 | 6,749,388,252,892 | null | 100 | 100 |
N, K = map(int,input().split())
A = list(map(int,input().split()))
start = 0
end = 10**9
while end - start > 1:
l = (start + end)/2
l = int(l)
count = 0
for i in range(N):
q = A[i]/l
if q == int(q):
q -= 1
count += int(q)
if count <= K:
end = l
else:
start = l
print(end)
|
N,K = map(int,input().split())
log_ls = list(map(int,input().split()))
Max = max(log_ls)
def less_k(min_length,log_ls = log_ls,K=K):
times = 0
for log in log_ls:
if log % min_length == 0:
times += log // min_length -1
else:
times += log // min_length
if times <= K:
return True
else:
return False
#print(less_k(5,[10,10],2))
def return_min_length():
r = Max
l = -1
while True:
next_length = (r+l) // 2
if next_length == 0 or not less_k(next_length):
l = next_length
else:
r = next_length
if r - l == 1:
return r
ans = return_min_length()
print(ans)
| 1 | 6,504,649,634,048 | null | 99 | 99 |
from collections import deque
N = int(input())
Graph = {}
Node = []
visited = [-1]*(N)
for i in range(N):
tmp = input().split()
if int(tmp[1]) != 0:
Graph[i] = [int(x)-1 for x in tmp[2:]]
else:
Graph[i] = []
queue = deque([0])
visited[0] = 0
while queue:
x = queue.popleft()
for i in Graph[x]:
if visited[i] == -1:
visited[i] = visited[x] + 1
queue.append(i)
for i,j in enumerate(visited, 1):
print(i, j)
|
time = int(input())
if time != 0:
h = time // 3600
time = time % 3600
m = time // 60
s = time % 60
print(str(h) + ':' + str(m) + ':' + str(s))
else:
print('0:0:0')
| 0 | null | 162,863,197,278 | 9 | 37 |
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, u, v = map(int, readline().split())
m = map(int,read().split())
data = list(zip(m,m))
graph = [[] for _ in range(n+1)]
for a,b in data:
graph[a].append(b)
graph[b].append(a)
def dfs(v):
dist = [None] * (n + 1)
dist[v] = 0
stack = deque([v])
while stack:
x = stack.popleft()
for y in graph[x]:
if dist[y] is None:
dist[y] = dist[x] + 1
stack.append(y)
return dist
res = 0
for i, j in zip(dfs(u), dfs(v)):
if i is None:
continue
if i <= j:
if j > res:
res = j
print(res - 1)
|
n = int(input())
lst = { input() for i in range(n) }
print(len(lst))
| 0 | null | 74,095,617,284,710 | 259 | 165 |
N=int(input())
result=0
for i in range(0,N+1):
if i%2 != 0:
result+=1
else:
result+=0
print(float(result/N))
|
N = input()
n = int(N)
even =int(n//2)
odd = int(n-even)
print(odd/n)
| 1 | 177,594,355,317,188 | null | 297 | 297 |
N = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
count = 0
for t in T:
S.append(t)
i = 0
while t != S[i]:
i += 1
if i != (len(S) - 1):
count += 1
S.pop()
print(count)
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
h, w = map(int, raw_input().split())
print h * w, (h + w) * 2
| 0 | null | 186,217,608,940 | 22 | 36 |
N=int(input())
print((N//2+1)/N if N%2 else 0.5)
|
# -*- coding: utf-8 -*-
# A
import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline
# 再起回数上限変更
# sys.setrecursionlimit(1000000)
N = int(input())
if N % 2 == 0:
print(0.5)
else:
a = N//2
b = N - a
print(b/N)
| 1 | 177,010,571,728,702 | null | 297 | 297 |
print(0--int(input())//2-1)
|
N = int(input())
if N == 1 or N == 2:
print(0)
else:
if N % 2 == 0:
print(N//2-1)
else:
print(N//2)
| 1 | 153,136,342,049,178 | null | 283 | 283 |
import math
pi=math.pi
def rtod(rad):
return 180/pi*rad
a,b,x=map(int,input().split())
if b/2<x/a**2:
ans=2*(a**2*b-x)/a**3
ans=math.atan(ans)
print(rtod(ans))
else:
ans=b**2/(2*x)*a
ans=math.atan(ans)
print(rtod(ans))
|
import sys,collections
input = sys.stdin.readline
N=input().rstrip()
A=list(map(int,input().split()))
Ac = collections.Counter(A)
Q = int(input())
for i in range(Q):
B,C = list(map(int,input().split()))
nb = Ac[B]
Ac[C] += Ac[B]
Ac[B] = 0
if i==0:
ans = 0
for key,val in Ac.items():
ans += key*val
else:
ans +=nb*C - nb*B
print(ans)
| 0 | null | 87,548,694,144,232 | 289 | 122 |
n,k = map(int,input().split())
ke = 1
while(True):
if(n<k):
print(ke)
break
else:
n = n//k
ke += 1
|
########関数部分##############
def Base_10_to_n(X, n):
if (int(X/n)):
return Base_10_to_n(int(X/n), n)+str(X%n)
return str(X%n)
############################
#####関数をつかってみる.#####
######今回は二進数に変換######
n, k = map(int, input().split())
x10 = n
x2 = Base_10_to_n(x10, k)
ans = str(x2)
print(len(ans))
| 1 | 64,306,581,873,978 | null | 212 | 212 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N, X, Y = getNM()
dist = [[] for i in range(N)]
for i in range(N - 1):
dist[i].append(i + 1)
dist[i + 1].append(i)
dist[X - 1].append(Y - 1)
dist[Y - 1].append(X - 1)
distance = [0] * N
def counter(sta):
ignore = [0] * N
ignore[sta] = 1
pos = deque([[sta, 0]])
while len(pos) > 0:
u, dis = pos.popleft()
for i in dist[u]:
if ignore[i] == 0:
ignore[i] = 1
distance[dis + 1] += 1
pos.append([i, dis + 1])
for i in range(N):
counter(i)
for i in distance[1:]:
print(i // 2)
|
from collections import deque
n,x,y=map(int,input().split())
l=[[1]]
for i in range(1,n-1):
l.append([i-1,i+1])
l.append([n-2])
x,y=x-1,y-1
l[x].append(y)
l[y].append(x)
#print(l)
p=[0 for i in range(n)]
for j in range(n):
s=[-1 for i in range(n)]
s[j]=0
q=deque([j])
while len(q)>0:
a=q.popleft()
for i in l[a]:
if s[i]==-1:
s[i]=s[a]+1
q.append(i)
for i in s:
if i!=0:
p[i]+=1
print(*map(lambda x:x//2,p[1:]),sep='\n')
| 1 | 43,934,668,224,306 | null | 187 | 187 |
N = int(input())
S = input()
if N%2 == 1:
print("No")
else:
print("Yes") if S[:len(S)//2] == S[len(S)//2:] else print("No")
|
n,x,y=map(int,input().split())
#最短距離が1の時2の時、、、という風に実験しても途方に暮れるだけだった
#i,j固定して最短距離がどう表せるかを考える
def min_route_count(i,j):
return min(abs(j-i),abs(j-y)+1+abs(x-i))
ans_list=[0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
ans_list[min_route_count(i,j)-1]+=1
for t in range(n-1):
print(ans_list[t])
| 0 | null | 95,955,222,528,828 | 279 | 187 |
def binary_search(key):
"""二分探索法 O(logN)
Args:
key (int): 基準値
Vars:
ok (int): 条件を満たすindexの上限値/下限値
ng (int): 条件を満たさないindexの下限値-1/上限値+1
Returns:
int: 条件を満たす最小値/最大値
"""
ok = 10 ** 12
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid, key):
ok = mid
else:
ng = mid
return ok
def isOK(i, key):
"""条件判定
Args:
i (int): 判定対象の値
key (int): 基準値
Returns:
bool: iが条件を満たすか否か
"""
cnt = 0
for v, d in l:
if v > i:
cnt += (v - i + d - 1) // d
return cnt <= key
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
l = []
for i in range(n):
l.append([a[i]*f[i], f[i]])
print(binary_search(k))
|
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a=sorted(a)
f=sorted(f,reverse=True)
def is_lessthanK(X):
ans=0
for A,F in zip(a,f):
if A*F>X:
ans+=A-X//F
if ans > k:
return False
return True
ng=-1
ok=a[-1]*f[0]
while ok-ng>1:
mid=(ok+ng)//2
if is_lessthanK(mid):
ok=mid
else:
ng=mid
print(ok)
| 1 | 165,211,218,988,910 | null | 290 | 290 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return S().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007
class BIT:
def __init__(self, size):
self.bit = [0] * size
self.size = size
self.total = 0
def add(self, i, w):
x = i + 1
self.total += w
while x <= self.size:
self.bit[x - 1] += w
x += x & -x
return
def sum(self, i):
res = 0
x = i + 1
while x:
res += self.bit[x - 1]
x -= x & -x
return res
def interval_sum(self, i, j): # i <= x < j の区間
return self.sum(j - 1) - self.sum(i - 1) if i else self.sum(j - 1)
n = I()
s = list(S())
q = I()
D = defaultdict(lambda:BIT(n))
for j in range(n):
D[s[j]].add(j, 1)
for _ in range(q):
qi, i, c = LS()
if qi == "1":
i = int(i) - 1
D[s[i]].add(i, -1)
D[c].add(i, 1)
s[i] = c
else:
l, r = int(i) - 1, int(c)
ret = 0
for k in range(97, 123):
if D[chr(k)].interval_sum(l, r):
ret += 1
print(ret)
|
# https://atcoder.jp/contests/abc157/tasks/abc157_e
import sys
input = sys.stdin.readline
class SegmentTree:
def __init__(self, n, op, e):
"""
:param n: 要素数
:param op: 二項演算
:param e: 単位減
例) 区間最小値 SegmentTree(n, lambda a, b : a if a < b else b, 10 ** 18)
区間和 SegmentTree(n, lambda a, b : a + b, 0)
"""
self.n = n
self.op = op
self.e = e
self.size = 1 << (self.n - 1).bit_length() # st[self.size + i] = array[i]
self.tree = [self.e] * (self.size << 1)
def built(self, array):
"""arrayを初期値とするセグメント木を構築"""
for i in range(self.n):
self.tree[self.size + i] = array[i]
for i in range(self.size - 1, 0, -1):
self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])
def update(self, i, x):
"""i 番目の要素を x に更新"""
i += self.size
self.tree[i] = x
while i > 1:
i >>= 1
self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])
def get_val(self, l, r):
"""[l, r)の畳み込みの結果を返す"""
l, r = l + self.size, r + self.size
res = self.e
while l < r:
if l & 1:
res = self.op(self.tree[l], res)
l += 1
if r & 1:
r -= 1
res = self.op(self.tree[r], res)
l, r = l >> 1, r >> 1
return res
##################################################################################################################
def popcount(x):
return bin(x).count("1")
N = int(input())
st = SegmentTree(N, lambda a, b: a | b, 0)
S = input().strip()
data = []
for s in S:
data.append(1 << (ord(s) - ord("a")))
st.built(data)
Q = int(input())
for _ in range(Q):
q, a, b = input().split()
if q == "1":
st.update(int(a)-1, 1 << (ord(b) - ord("a")))
if q == "2":
a = int(a) - 1
b = int(b)
print(popcount(st.get_val(a, b)))
| 1 | 62,533,304,553,020 | null | 210 | 210 |
h = int(input())
def rc(h):
if h == 1:
return 1
t = rc(h//2)*2
return t + 1
print(rc(h))
|
import sys
#import math
# input = sys.stdin.readline
def binary_search(arr, key,j):
ok = j
ng = len(arr)
while abs(ok - ng) > 1:
mid = int((ok + ng) / 2)
if arr[mid] < key:
ok = mid
else:
ng = mid
return ok
def main():
N = int(input())
L = sorted(list(map(int, input().split())))
ans =0
for i in range(N-2):
for j in range(i+1,N-1):
ok = binary_search(L,L[i]+L[j],j)
ans += ok-j
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 125,715,833,149,180 | 228 | 294 |
a=int(input())
b=int(input())
z=1^2^3
print (z^a^b)
|
from sys import stdin
def getval():
n = int(input())
e = [[i] + list(map(int,stdin.readline().split())) for i in range(n-1)]
return n,e
def main(n,e):
tree = [[] for i in range(n)]
ans = [0 for i in range(n-1)]
for i in e:
tree[i[1]-1].append([i[2]-1,i[0]])
tree[0].append(0)
k = 1
q = [0]
while q:
n = 0
idx = q.pop(0)
for i in range(len(tree[idx])-1):
n += 1
if n==tree[idx][-1]:
n += 1
ans[tree[idx][i][-1]] = n
tree[tree[idx][i][0]].append(n)
q.append(tree[idx][i][0])
k = max(k,n)
print(k)
for i in ans:
print(i)
if __name__=="__main__":
n,e = getval()
main(n,e)
| 0 | null | 123,741,449,053,950 | 254 | 272 |
a=[int(x) for x in input().split()]
b=[a[0]*a[2],a[0]*a[3],a[1]*a[2],a[1]*a[3]]
print(max(b))
|
def check(k, W, p):
s = 0
count = 1
for w in W:
if s + w > p:
count += 1
s = 0
s += w
return count <= k
n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
right = sum(W)
left = max(right // k, max(W)) - 1
while right - left > 1:
p = (left + right) // 2
if check(k, W, p):
right = p
else:
left = p
print(right)
| 0 | null | 1,569,966,795,740 | 77 | 24 |
#abc17a
s=input()
if 'RRR' in s:
print(3)
elif 'RR' in s:
print(2)
elif 'R' in s:
print(1)
else:
print(0)
|
x=input()
a=int(x)*int(x)*int(x)
print(a)
| 0 | null | 2,593,057,049,352 | 90 | 35 |
N = int(input())
ad = {}
status = {}
edge=[]
for n in range(N):
ad[n+1]=set([])
status[n+1] = -1
for n in range(N-1):
a,b = list(map(int,input().split()))
edge.append((a,b))
ad[a].add(b)
ad[b].add(a)
color = set([])
parent = [0] * (N+1)
ans={}
#BFS
from collections import deque
start = 1
status[start] = 0
que = deque([start])
while len(que) > 0:
start = que[0]
# print(start,parent[start])
c = 1
for v in ad[start]:
if status[v] == -1:
que.append(v)
status[v]=0
if parent[start] == c:
c += 1
parent[v] = c
color.add(c)
s = min(start,v)
e = max(start,v)
ans[s,e]=c
c+=1
# print(parent,que)
que.popleft()
print(len(color))
for e in edge:
print(ans[e])
|
N=int(input())
right=0
left=0
for i in range(N):
a,b=input().split()
if a>b:
left+=3
elif a<b:
right+=3
else:
left+=1
right+=1
print(f"{left} {right}")
| 0 | null | 69,389,023,367,946 | 272 | 67 |
def is_good(mid, key):
S = list(map(int, str(mid)))
N = len(S)
dp = [[[0] * 11 for _ in range(2)] for _ in range(N + 1)]
dp[1][1][10] = 1
for k in range(1, S[0]):
dp[1][1][k] = 1
dp[1][0][S[0]] = 1
for i in range(1, N):
for k in range(1, 11):
dp[i + 1][1][k] += dp[i][0][10] + dp[i][1][10]
for is_less in range(2):
for k in range(10):
for l in range(k - 1, k + 2):
if not 0 <= l <= 9 or (not is_less and l > S[i]):
continue
dp[i + 1][is_less or l < S[i]][l] += dp[i][is_less][k]
return sum(dp[N][0][k] + dp[N][1][k] for k in range(10)) >= key
def binary_search(bad, good, key):
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
K = int(input())
print(binary_search(0, 3234566667, K))
|
from collections import deque
def main():
k = int(input())
d = deque(list(range(1, 10)))
ans = 0
for _ in range(k):
ans = d.popleft()
if ans % 10 != 0:
d.append(10 * ans + (ans % 10) - 1)
d.append(10 * ans + (ans % 10))
if ans % 10 != 9:
d.append(10 * ans + (ans % 10) + 1)
print(ans)
if __name__ == '__main__':
main()
| 1 | 39,999,262,951,440 | null | 181 | 181 |
from collections import deque
n = int(input())
C = [input() for i in range(n)]
A = deque([])
for c in C:
if c == 'deleteFirst':
A.popleft()
elif c == 'deleteLast':
A.pop()
elif 'delete' in c:
q = int(c[7:])
if q in A:
A.remove(q)
elif 'insert' in c:
q = int(c[7:])
A.appendleft(q)
print(' '.join(map(str, A)))
|
class Node:
def __init__(self,key):
self.key = key
self.prev = None
self.next = None
class DoublyLinkedList:
def __init__(self):
self.nil = Node(None)
self.nil.prev = self.nil
self.nil.next = self.nil
def insert(self,key):
new = Node(key)
new.next = self.nil.next
self.nil.next.prev = new
self.nil.next = new
new.prev = self.nil
def listSearch(self,key):
cur = self.nil.next
while cur != self.nil and cur.key != key:
cur = cur.next
return cur
def deleteNode(self, t):
if t == self.nil:
return
t.prev.next = t.next
t.next.prev = t.prev
def deleteFirst(self):
self.deleteNode(self.nil.next)
def deleteLast(self):
self.deleteNode(self.nil.prev)
def deleteKey(self, key):
self.deleteNode(self.listSearch(key))
if __name__ == '__main__':
import sys
input = sys.stdin.readline
n = int(input())
d = DoublyLinkedList()
for _ in range(n):
c = input().rstrip()
if c[0] == "i":
d.insert(c[7:])
elif c[6] == "F":
d.deleteFirst()
elif c[6] =="L":
d.deleteLast()
else:
d.deleteKey(c[7:])
ans = []
cur = d.nil.next
while cur != d.nil:
ans.append(cur.key)
cur = cur.next
print(" ".join(ans))
| 1 | 48,163,072,650 | null | 20 | 20 |
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n = int(input())
A = list(map(int,input().split()))
data = [(ai,i) for i,ai in enumerate(A)]
data.sort(reverse = True)
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n):
for l in range(i+1):
r = i-l
dp[l+1][r] = max(dp[l+1][r], dp[l][r] + data[i][0] * abs(data[i][1] - l))
dp[l][r+1] = max(dp[l][r+1], dp[l][r] + data[i][0] * abs(data[i][1] - (n-1-r)))
ans = 0
for i in range(n):
ans = max(ans,dp[i][n-i])
print(ans)
|
# import time
# p0 = time.time()
N = int(input())
A = list(map(int,input().split()))
# print(A)
A = [[A[i],i] for i in range(N)]
A.sort(reverse=True)
# print("A :",A)
dp = [[0]*(N+1) for _ in range(N+1)]
# print(dp)
#dp[x][y] : x人は Ai*(i-pi),y人は Ai*(pi-i)
# piは 0,1,2... piはN-1,N-2,N-3,,
# p1 = time.time()-p0
dp[0][0] = 0
# y = 0
for x in range(1,N+1):
dp[x][0] = dp[x-1][0]+A[x-1][0]*(A[x-1][1]-x+1)
# print(x,dp)
# x = 0
for y in range(1,N+1):
dp[0][y] = dp[0][y-1]+A[y-1][0]*(N-y - A[y-1][1])
# print(x,dp)
# p2 = time.time()-p0
for x in range(1,N):
for y in range(1,N+1-x):
A0 = A[x+y-1][0]
A1 = A[x+y-1][1]
dp[x][y] = max(dp[x-1][y] + A0*(A1+1 - x), dp[x][y-1] + A0*(N-y - A1))
# print(dp)
# p3 = time.time()-p0
c = 0
for i in range(N):
if c < dp[i][N-i]:
c = dp[i][N-i]
print(c)
# print(p1,p2,p3)
| 1 | 33,710,024,493,168 | null | 171 | 171 |
N,K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A)
F=sorted(F)[::-1]
import numpy as np
a=np.array(A)
f=np.array(F)
low=-1
high=10**18
while high-low>1:
d=(high+low)//2
#0かa-d//fの大きい値を採用するnp.maximum
if np.maximum(0,a-d//f).sum()<=K:
high=d
else:
low=d
print(high)
|
# -*- coding:utf-8
def main():
N = int(input())
A = list(map(int, input().split()))
insertionSort(A, N)
print(' '.join(map(str, A)))
def insertionSort(A, N):
for i in range(1, N):
print(' '.join(map(str, A)))
v = A[i]
j = i-1
while(j>=0 and A[j]>v):
A[j+1] = A[j]
j -= 1
A[j+1] = v
if __name__ == '__main__':
main()
| 0 | null | 82,588,219,935,540 | 290 | 10 |
def combination(n, r, m):
res = 1
r = min(r, n - r)
for i in range(r):
res = res * (n - i) % m
res = res * pow(i + 1, m - 2, m) % m
return res
mod = 10**9 + 7
n, a, b = map(int, input().split())
total = pow(2, n, mod) - 1
total -= (combination(n, a, mod) + combination(n, b, mod)) % mod
print(total % mod)
|
n,a,b=map(int,input().split())
c=max(a,b)
b=min(a,b)
a=c
MOD = pow(10,9) + 7
X=1
Y=1
for i in range(1,a+1):
X=X*(n+1-i)%MOD
Y=Y*i%MOD
if i==b:
b_X=X
b_Y=Y
a_X=X
a_Y=Y
def calc(X,Y,MOD):
return X*pow(Y,MOD-2,MOD)
ans=pow(2,n,MOD)%MOD-1-calc(a_X,a_Y,MOD)-calc(b_X,b_Y,MOD)
print(ans%MOD)
| 1 | 66,338,080,299,540 | null | 214 | 214 |
a = int(input())
n = 1
while True:
if a*n % 360 == 0:
break
else:
n += 1
print(n)
|
n = int(input())
S = list(map(int, input(). split()))
q = int(input())
T = list(map(int, input(). split()))
Sum = 0
for i in T:
if i in S:
Sum += 1
print(Sum)
| 0 | null | 6,616,195,673,254 | 125 | 22 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
temperature = int(input())
if temperature >= 30:
print('Yes')
else:
print('No')
|
x = int(input())
if 30 <= x:
print("Yes")
else:
print("No")
| 1 | 5,778,776,070,350 | null | 95 | 95 |
k = int(input())
a,b = map(int,input().split())
ans = 0
for i in range(a//k,b//k+1):
if a <= k * i <= b:
ans = 1
if ans == 1:
print('OK')
else:
print('NG')
|
import sys
for line in sys.stdin:
x, y = map(int, line.split())
print(len(str(x+y)))
| 0 | null | 13,186,134,860,420 | 158 | 3 |
print(eval(input().strip().replace(' ','*')))
|
def main():
data = input().split()
print( int(data[0]) * int(data[1]))
if __name__ == '__main__':
main()
| 1 | 15,856,446,084,320 | null | 133 | 133 |
_, a = open(0)
mod = 10**9+7
c = 1
l = [3] + [0]*10**6
for a in a.split():
a = int(a)
c = c * l[a] % mod
l[a] -= 1
l[a+1] += 1
print(c)
|
n = int(input())
lis = list(map(int,input().split()))
num = [0 for i in range(n)]
ans = 1
for nu in lis:
if nu == 0:
ans *= (3-num[0])
else:
ans *= (num[nu-1]-num[nu])
ans %= 10 ** 9 + 7
num[nu] += 1
print(ans)
| 1 | 130,085,495,476,288 | null | 268 | 268 |
while True:
x, y = [int(n) for n in input().split()]
if x == 0 and y == 0:
break
if x < y:
print("{} {}".format(x, y))
else:
print("{} {}".format(y, x))
|
S = str(input())
T = str(input())
T1 = T[:-1]
if S == T1:
print('Yes')
else:
print('No')
| 0 | null | 10,963,262,987,960 | 43 | 147 |
N = int(input())
A = list(map(int, input().split()))
if N%2==0:
dp = [[0]*2 for _ in range(N)]
dp[0][0] = A[0]
dp[1][1] = A[1]
for i in range(2, N):
if i==2:
dp[i][0] = dp[i-2][0]+A[i]
else:
dp[i][0] = dp[i-2][0]+A[i]
dp[i][1] = max(dp[i-3][0]+A[i], dp[i-2][1]+A[i])
print(max(dp[N-2][0], dp[N-1][1]))
else:
dp = [[0]*3 for _ in range(N)]
dp[0][0] = A[0]
dp[1][1] = A[1]
dp[2][2] = A[2]
for i in range(2, N):
if i==2:
dp[i][0] = dp[i-2][0]+A[i]
elif i==3:
dp[i][0] = dp[i-2][0]+A[i]
dp[i][1] = max(dp[i-2][1]+A[i], dp[i-3][0]+A[i])
else:
dp[i][0] = dp[i-2][0]+A[i]
dp[i][1] = max(dp[i-3][0]+A[i], dp[i-2][1]+A[i])
dp[i][2] = max(dp[i-4][0]+A[i], dp[i-3][1]+A[i], dp[i-2][2]+A[i])
print(max(dp[N-3][0], dp[N-2][1], dp[N-1][2]))
|
(tate, yoko) = [int(x) for x in input().rstrip().split(' ')]
square = tate * yoko
length = (int(tate) + int(yoko)) * 2
print(square, length)
| 0 | null | 18,786,071,823,120 | 177 | 36 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = [a%K for a in A]
cs = [0]
for b in B:
c = (cs[-1] + b-1) % K
cs.append(c)
from collections import deque
from collections import defaultdict
qs = defaultdict(lambda: deque())
ans = 0
for i,c in enumerate(cs):
while qs[c] and qs[c][0] + K <= i:
qs[c].popleft()
ans += len(qs[c])
qs[c].append(i)
print(ans)
|
import sys
import math
import heapq
import bisect
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
res = [1]
for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
return res
def gcd(x, y):
if x < y: x, y = y, x
div = x % y
while div != 0:
x, y = y, div
div = x % y
return y
# j - i == S[j] - S[i] # MOD K
# S[i] - i == S[j] - j
N,K=LI()
As=LI()
Cum=[0]*(N+1)
for i in range(N):
Cum[i+1] = Cum[i] + As[i]
REM2IDX = {}
for i in range(0,N+1):
rem = (Cum[i] - i) % K
if not rem in REM2IDX: REM2IDX[rem] = []
REM2IDX[rem].append(i)
res = 0
for i in range(0,N+1):
rem = (Cum[i] - i) % K
cnt = len(REM2IDX[rem])
l = bisect.bisect_right(REM2IDX[rem], i)
r = bisect.bisect_right(REM2IDX[rem], i+K-1)
res += (r-l)
print(res)
| 1 | 138,018,655,799,910 | null | 273 | 273 |
k = int(input())
s = '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'
arr = [int(x) for x in s.split(', ')]
print(arr[k - 1])
|
# coding: utf-8
# 標準入力 <int>
K = int(input())
k = "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"
kl = k.split(", ")
print(kl[K-1])
| 1 | 49,760,978,187,620 | null | 195 | 195 |
n, m = map(int, input().split())
mat = [map(int,input().split()) for i in range(n)]
vec = [int(input()) for i in range(m)]
for row in mat:
print(sum([a*b for (a,b) in zip(row, vec)]))
|
N, M = map(int, raw_input().split())
matrix = [map(int, raw_input().split()) for n in range(N)]
array = [input() for m in range(M)]
for n in range(N):
c = 0
for m in range(M):
c += matrix[n][m] * array[m]
print c
| 1 | 1,151,278,403,560 | null | 56 | 56 |
if __name__ == '__main__':
n = int(input())
print(n + n * n + n * n * n )
|
k = int(input())
a, b = map(int, input().split())
check = False
for i in range(a, b + 1):
if i % k == 0:
check = True
print("OK" if check else "NG")
| 0 | null | 18,449,958,665,070 | 115 | 158 |
n = input()
minSeq = input()
maxv = -float("inf")
while True:
try:
R = input()
if R - minSeq > maxv:
maxv = R - minSeq
if R < minSeq:
minSeq = R
except EOFError:
break
print(maxv)
|
n = input()
maxv = - 1 * pow(10, 9)
minv = input()
for _ in xrange(1, n):
Rj = input()
maxv = max(maxv, Rj - minv)
minv = min(minv, Rj)
print maxv
| 1 | 13,875,362,106 | null | 13 | 13 |
MM = int(input())
AA = input().split()
count = 0
for j in AA:
i = int(j)
if i%2 ==0:
if i%3 !=0 and i%5 !=0:
count +=1
if count == 0:
print('APPROVED')
else:
print('DENIED')
|
def LI():
return list(map(int, input().split()))
X = int(input())
ans = X//500*1000
X = X % 500
ans += X//5*5
print(ans)
| 0 | null | 55,856,203,522,522 | 217 | 185 |
print('10'[int(input())])
|
n = int(input())
print((n//2)/n if n%2==0 else (n//2+1)/n)
| 0 | null | 89,834,117,555,298 | 76 | 297 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.