code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
S= input()
T=input()
mi = 3000
for i in range(0,len(S)-len(T)+1):
c = 0
for j in range(0,len(T)):
#print(S[i+j]+":"+T[j])
if S[i+j] != T[j]:
c += 1
#print(c)
if mi > c:
mi = c
print(mi) | n=int(input())
p=list(map(int,input().split()))
res=p[0]
cnt=0
for i in p:
if res>=i:
cnt+=1
res=min(res,i)
print(cnt)
| 0 | null | 44,612,891,466,662 | 82 | 233 |
from time import time
from random import random
limit_secs = 2
start_time = time()
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
def calc_score(t):
score = 0
S = 0
last = [-1] * 26
for d in range(len(t)):
S += s[d][t[d]]
last[t[d]] = d
for i in range(26):
S -= c[i] * (d - last[i])
score += max(10 ** 6 + S, 0)
return score
def solution1():
return [i % 26 for i in range(D)]
def solution2():
t = None
score = -1
for i in range(26):
nt = [(i + j) % 26 for j in range(D)]
if calc_score(nt) > score:
t = nt
return t
def solution3():
t = []
for _ in range(D):
score = -1
best = -1
t.append(0)
for i in range(26):
t[-1] = i
new_score = calc_score(t)
if new_score > score:
best = i
score = new_score
t[-1] = best
return t
def optimize0(t):
return t
def optimize1(t):
score = calc_score(t)
while time() - start_time + 0.15 < limit_secs:
d = int(random() * D)
q = int(random() * 26)
old = t[d]
t[d] = q
new_score = calc_score(t)
if new_score < score:
t[d] = old
else:
score = new_score
return t
t = solution3()
t = optimize0(t)
print('\n'.join(str(e + 1) for e in t))
| for i in range(365):
print(1) | 1 | 9,678,569,862,092 | null | 113 | 113 |
import numpy as np
from numba import njit
@njit
def solve(stdin):
n, k = stdin[:2]
A = stdin[2: 2 + n]
A = np.sort(A)[::-1]
F = np.sort(stdin[2 + n:])
def is_ok(x):
tmp = 0
for a, f in zip(A, F):
y = a * f
if y > x:
tmp += a - x // f
return tmp <= k
ok = 10 ** 16
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(solve(np.fromstring(open(0).read(), dtype=np.int64, sep=' '))) | n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()
if k >= sum(a_list):
print(0)
exit()
point = []
for i in range(n):
point.append(a_list[i] * f_list[i])
import math
def binary_search(point, k):
left = 0
right = 10 ** 12
while left + 1< right:
ans = 0
center = (left + right) // 2
for i in range(n):
if point[i] > center:
ans += a_list[i] - (center // f_list[i])
if ans <= k:
right = center
else:
left = center
return left
value = binary_search(point, k)
print(value + 1)
| 1 | 164,955,639,015,236 | null | 290 | 290 |
p0 = 10**9+7
def pow(x,m):
if m==0:
return 1
if m==1:
return x
if m%2==0:
return (pow(x,m//2)**2)%p0
else:
return (x*(pow(x,(m-1)//2)**2)%p0)%p0
N = int(input())
A = list(map(int,input().split()))
A = [bin(A[i])[2:] for i in range(N)]
A = ["0"*(60-len(A[i]))+A[i] for i in range(N)]
C = {k:0 for k in range(60)}
for i in range(N):
for m in range(60):
if A[i][m]=="1":
C[59-m] += 1
B = [0 for _ in range(60)]
for k in range(60):
p = C[k]
m = N-C[k]
B[k] = p*m
cnt = 0
for k in range(60):
cnt = (cnt+B[k]*pow(2,k))%p0
print(cnt) | #!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
b = [0] * 60
ans = 0
for i in range(n):
for j in range(60):
ans += (i - b[j] if a[i] >> j & 1 else b[j]) << j
ans %= 10**9 + 7
for j in range(60):
b[j] += a[i] >> j & 1
print(ans)
| 1 | 123,358,307,186,348 | null | 263 | 263 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
S = readline().strip()
ans = 0
n = len(S) // 2
for i in range(n):
if S[i] != S[-1 - i]:
ans += 1
print(ans)
return
if __name__ == '__main__':
main()
| # input here
_INPUT = """\
4
141421356 17320508 22360679 244949
"""
"""
K = int(input())
H, W, K = map(int, input().split())
a = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(N)]
p = tuple(map(int,input().split()))
"""
def main():
n = int(input())
a = list(map(int, input().split()))
cumsum = list(itertools.accumulate(a))
sum1 = 0
for i in range(len(a)):
mult = a[i] * (cumsum[n-1] - cumsum[i])
sum1 += mult
print((sum1 % (10**9 + 7)))
if __name__ == '__main__':
import io
import sys
import math
import itertools
from collections import deque
# sys.stdin = io.StringIO(_INPUT)
main() | 0 | null | 61,888,843,607,400 | 261 | 83 |
# -*- coding: utf-8 -*-
N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----
# A_index[i] = ( value of A , index of A)
A_index = [ (A_list[i], i) for i in range(len(A_list)) ]
A_index.sort(reverse=True)
# dp[left][right] = score
dp = [ [0]*(N+1) for _ in range(N+1) ]
for L in range(N):
for R in range(N-L):
i = L + R
append_L = dp[L][R] + A_index[i][0] * abs(L - A_index[i][1])
append_R = dp[L][R] + A_index[i][0] * abs((N-1-R) - A_index[i][1])
dp[L+1][R] = max(dp[L+1][R], append_L)
dp[L][R+1] = max(dp[L][R+1], append_R)
ans = max( [ dp[i][N-i] for i in range(N+1)] )
print(ans)
| from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
infants = []
for i in range(n):
infants.append((a[i],i))
infants.sort()
dp = [defaultdict(int) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
score,initial = infants.pop()
for right in dp[i].keys():
dp[i+1][right] = max(dp[i][right]+abs(initial-(i-right))*score,dp[i+1][right])
dp[i+1][right+1] = max(dp[i][right]+abs((n-1-right)-initial)*score,dp[i+1][right+1])
print(max(dp[n].values())) | 1 | 33,773,218,328,200 | null | 171 | 171 |
import math
pai = math.pi
r = float(input())
print('{:.6f} {:.6f}'.format(pai*r**2,2*pai*r))
| class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
n,m,k=map(int,input().split())
uf=UnionFind(n)
block={}
for i in range(n):
block[i]=[i]
for i in range(m):
a,b=map(int,input().split())
uf.union(a-1,b-1)
block[a-1].append(b-1)
block[b-1].append(a-1)
for i in range(k):
a,b=map(int,input().split())
block[a-1].append(b-1)
block[b-1].append(a-1)
ans=[]
#print(block)
for i in range(n):
res=uf.size(i)
# print(res)
for value in block[i]:
if uf.same(value,i):
res-=1
ans.append(res)
print(*ans)
if __name__=="__main__":
main()
| 0 | null | 31,316,811,633,968 | 46 | 209 |
N = int(input())
numbers = [int(input()) for i in range(N)]
ans = []
def check_prime(n):
for i in range(2, int(n**0.5)+1):
if n % i == 0:
return 0
else:
return 1
for n in numbers:
ans.append(check_prime(n))
print(sum(ans)) | import math
cnt = 0
N = int(input())
for n in range(N):
i = int(input())
if i == 2\
or i == 3\
or i == 5\
or i == 7:
cnt += 1
elif i % 2 == 0:
continue
else:
j = 3
prime = 1
while j >= 3 and j <= int(math.sqrt(i)):
if i % j == 0:
prime = 0
break
j += 2
if prime == 1:
cnt += 1
print(cnt) | 1 | 9,884,252,668 | null | 12 | 12 |
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
V = {"s":R, "p":S, "r":P}
ans = 0
for i in range(K):
check = T[i]
ans += V[T[i]]
while True:
i += K
if i >= N:
break
if check == T[i]:
check = -1
else:
ans += V[T[i]]
check = T[i]
print(ans) | from collections import deque
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
q = deque([])
points = 0
for i in range(n):
if i <= k-1:
if t[i] == 'r':
points += p
q.append('p')
elif t[i] == 's':
points += r
q.append('r')
elif t[i] == 'p':
points += s
q.append('s')
else:
ban = q.popleft()
if t[i] == 'r':
if ban != 'p':
points += p
q.append('p')
else:
q.append('x')
elif t[i] == 's':
if ban != 'r':
points += r
q.append('r')
else:
q.append('x')
elif t[i] == 'p':
if ban != 's':
points += s
q.append('s')
else:
q.append('x')
print(points) | 1 | 106,922,434,089,692 | null | 251 | 251 |
def main():
x = int(input())
if x >= 30:
print('Yes')
else:
print("No")
if __name__ == main():
main() | a = int(input())
print("Yes") if a >= 30 else print("No")
| 1 | 5,814,738,044,610 | null | 95 | 95 |
k=int(input())
if k%2==0 or k%5==0:
print(-1)
exit()
ans=1
num=7
while num%k!=0:
num=10*num+7
num%=k
ans+=1
print(ans) | n, k = map(int, input().split())
p = list(map(int, input().split()))
def ev(n):
return n * (n + 1) / (2 * n)
q = [0]
for i in range(n):
q.append(ev(p[i]))
q[i + 1] = q[i] + ev(p[i])
#print(q)
tmp = 0
for j in range(n - k + 1):
if tmp <= q[j + k] - q[j]:
tmp = q[j + k] - q[j]
print(tmp)
| 0 | null | 40,366,303,062,930 | 97 | 223 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc= [list(map(int, input().split())) for _ in range(M)]
minmoney = min(a) + min(b)
for obj in xyc:
summoney = a[obj[0] - 1] + b[obj[1] - 1] - obj[2]
minmoney = min(minmoney, summoney)
print(minmoney) | X = int(input())
if X >= 30 :
print ('Yes')
else :
print ("No")
| 0 | null | 29,680,441,870,752 | 200 | 95 |
h= int(input())
w = int(input())
n = int(input())
a = max(h,w)
print((n+a-1)//a) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def keyence20_a():
H, W, N = map(int, readlines())
lg = max(H, W)
ans = (N + lg - 1) // lg
print(ans)
keyence20_a() | 1 | 88,998,664,149,230 | null | 236 | 236 |
n = int(input())
ans = int(n/1.08)
for i in range(2):
if int(ans*1.08) == n:
print(ans)
exit()
ans += 1
print(":(") | n=int(input())
for x in range(n+1):
if int(x*1.08)==n:
print(x)
exit()
print(":(") | 1 | 126,051,611,293,408 | null | 265 | 265 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K, *H = map(int, read().split())
H.sort(reverse=True)
print(sum(H[K:]))
return
if __name__ == '__main__':
main()
| N, K = map(int, input().split())
H = list(map(int, input().split()))
if N <= K:
print(0)
else:
H = sorted(H)
ans = 0
for i in range(N-K):
ans += H[i]
print(ans) | 1 | 79,366,466,959,250 | null | 227 | 227 |
n = int(input())
if n >= 30 :
print("Yes")
else:
print('No') | x = int(input())
for i in range(1000):
for j in range(i):
if i ** 5 - j ** 5 == x:
print(i, j)
exit()
if i ** 5 + j ** 5 == x:
print(i, -j)
exit()
| 0 | null | 15,679,961,404,260 | 95 | 156 |
h = int(input())
counter = 0
while h > 0 :
h //= 2
counter += 1
print(pow(2, counter) - 1) | import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
H = ri()
cnt = 1
while H > 1:
H = H // 2
cnt += 1
print(sum([2 ** i for i in range(cnt)])) | 1 | 80,102,429,914,880 | null | 228 | 228 |
N = int(input())
for i in range(50000):
if N <= i*1.08 < N + 1:
print(i)
break
else:
print(":(")
| from math import ceil, floor
def resolve():
N = int(input())
tax = 0.08
if floor(ceil(N/(1+tax))*(1+tax)) == N:
print(ceil(N/(1+tax)))
else:
print(":(")
if __name__ == "__main__":
resolve() | 1 | 125,601,102,306,900 | null | 265 | 265 |
cnt = 0
a, b, c = map(int, input().split())
if (a >= 1 and a <= 10000) and (b >= 1 and b <= 10000) and (c >= 1 and c <= 10000):
if a <= b:
for i in range(a, b+1):
if c % i == 0:
cnt += 1
print("{0}".format(str(cnt)))
else:
pass
else:
pass | import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7
import fractions
lc = num[0]
for i in range(1, n):
lc = lc * num[i] // fractions.gcd(lc, num[i])
lc %= mod
def modinv(a, mod=10**9+7):
return pow(a, mod-2, mod)
ans =0
for i in range(n):
ans += lc*modinv(num[i],mod)
ans %= mod
print(ans) | 0 | null | 44,068,513,463,260 | 44 | 235 |
while True:
try:
a, b = map(int, input().rstrip().split())
print(len(str(a + b)))
except Exception:
break
| import statistics
N = int(input())
AB = [map(int, input().split()) for _ in range(N)]
A,B = [list(i) for i in zip(*AB)]
if N%2 == 1:
low_med = statistics.median(A)
high_med = statistics.median(B)
print(high_med - low_med +1)
else:
low_med = statistics.median(A)
high_med = statistics.median(B)
print(int(2 * (high_med - low_med) +1)) | 0 | null | 8,736,764,691,362 | 3 | 137 |
n, m = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for y in range(n)]
b = [int(input()) for x in range(m)]
c = []
for i in range(n):
c.append(sum([a[i][x] * b[x] for x in range(m)]))
for i in c:
print(i) | def f(n):
if n == 0:
return 0
return f(n % bin(n).count("1")) + 1
def solve():
N = int(input())
X = input()
p = X.count("1")
rem_plus = 0
rem_minus = 0
for i in range(N):
k = N - i - 1
if X[i] == "0":
continue
elif p > 1:
rem_minus = (rem_minus + pow(2, k, p - 1)) % (p - 1)
rem_plus = (rem_plus + pow(2, k, p + 1)) % (p + 1)
for i in range(N):
k = N - i - 1
if X[i] == "0":
print(f((rem_plus + pow(2, k, p + 1)) % (p + 1)) + 1)
elif p > 1:
print(f((rem_minus - pow(2, k, p - 1)) % (p - 1)) + 1)
else:
print(0)
if __name__ == "__main__":
solve() | 0 | null | 4,654,580,293,086 | 56 | 107 |
s = input()
t = list(reversed(s))
ans = 0
for i in range(len(s)):
if s[i] != t[i]:
ans += 1
ans = (ans+1) // 2
print(ans) | list_s = list(input())
count = 0
for i in range(0, len(list_s) // 2):
if list_s[i] == list_s[0 - (i + 1)]:
continue
else: count += 1
print(count) | 1 | 120,100,110,889,862 | null | 261 | 261 |
n1 = int(input())
a1 = [int(x) for x in input().split()]
n2 = int(input())
a2 = [int(x) for x in input().split()]
res = set()
cnt = 0
for i in range(n1) :
for j in range(n2) :
if a1[i] == a2[j] :
res.add(a1[i])
print(len(res))
| a,b=input().split()
X=a*int(b)
Y=b*int(a)
print(min(X,Y)) | 0 | null | 41,987,316,613,370 | 22 | 232 |
order=[]
for number in range(10):
hight=int(input())
order.append(hight)
for j in range(9):
for i in range(9):
if order[i] < order[i+1]:
a = order[i]
b = order[i+1]
order[i] = b
order[i+1] = a
for i in range(3):
print(order[i]) | # -*- config: utf-8 -*-
if __name__ == '__main__':
hills = []
for i in range(10):
tmp = raw_input()
hills.append(int(tmp))
hills.sort(reverse=True)
for i in range(3):
print hills[i] | 1 | 9,947,002 | null | 2 | 2 |
n=int(input())
l=list(map(int,input().split()))
l.sort()
count=0
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if l[i]+l[j]>l[k] and l[i]!=l[j] and l[j]!=l[k] and l[i]!=l[k]:
count+=1
print(count)
| N, X, Y = map(int, input().split())
def f(i, j):
v1 = j - i
v2 = abs(X - i) + 1 + abs(j - Y)
v3 = abs(Y - i) + 1 + abs(j - X)
return min(v1, v2, v3)
D = [0] * N
for i in range(1, N):
for j in range(i + 1, N + 1):
d = f(i, j)
D[d] += 1
for d in D[1:]:
print(d)
| 0 | null | 24,534,252,231,180 | 91 | 187 |
N = int(input())
S = {}
c = 0
for _ in range(N):
s = input()
if s not in S:
S[s] = 1
else:
S[s] += 1
c = max(c, S[s])
ans = []
for k, v in S.items():
if v == c:
ans.append(k)
ans.sort()
for a in ans:
print(a)
| import math
def LI():
return list(map(int, input().split()))
a, b, x = LI()
if x == (a**2*b)/2:
ans = 45
elif x > (a**2*b)/2:
ans = math.degrees(math.atan((2*(b-x/(a**2)))/a))
else:
ans = math.degrees(math.atan(a*b**2/(2*x)))
print(ans)
| 0 | null | 116,615,664,785,874 | 218 | 289 |
n=int(input())
a=list(map(int, input().split()))
max=a[0]
dai=0
for i in range(n):
#print(f"{i}回目")
if max>a[i]:
dai+=max-a[i]
else:
max=a[i]
#print(max,dai)
print(dai) | n, k = map(int,input().split())
if n == 1:
print(1)
else:
a=1
ans = 0
while a<=n:
a *=k
ans += 1
print(ans)
| 0 | null | 34,510,802,291,862 | 88 | 212 |
N = int(input())
D = list(map(int, input().split()))
from itertools import accumulate
print(sum(list(d*c for d, c in zip(D[1:], accumulate(D)))))
| import sys
while True:
n = sys.stdin.readline()[:-1]
if n == '-1 -1 -1':
break
marks = [ int(m) for m in n.split() ]
mt_points,retest = marks[0] + marks[1],marks[2]
if -1 in marks[:-1]:
print('F')
continue
elif mt_points >= 80:
print('A')
continue
elif mt_points >= 65 and 80 > mt_points:
print('B')
continue
elif mt_points >= 50 and 65 > mt_points:
print('C')
continue
elif mt_points >= 30 and 50 > mt_points:
if retest >= 50:
print('C')
continue
print('D')
continue
elif 30 > mt_points:
print('F')
| 0 | null | 84,408,764,923,502 | 292 | 57 |
import sys, itertools
print(len(set(itertools.islice(sys.stdin.buffer, 1, None)))) | N = int(input())
P = list(map(int, input().split()))
ans = 1
cnt = [0] * 3
mod = 10**9+7
for i in range(N):
opt = 0
cond = 1
for j in range(3):
if cnt[j] == P[i]:
opt += 1
if cond:
cnt[j] += 1
cond = 0
ans *= opt
ans %= mod
ans %= mod
print(ans) | 0 | null | 79,956,326,918,336 | 165 | 268 |
from itertools import combinations
n=int(input())
D=list(map(int,input().split()))
ans=0
for a,b in combinations(range(n),2):
ans+=D[a]*D[b]
print(ans) | # -*- coding: utf-8 -*-
"""
B - TAKOYAKI FESTIVAL 2019
https://atcoder.jp/contests/abc143/tasks/abc143_b
"""
import sys
from itertools import combinations
def solve(takoyaki):
return sum(x * y for x, y in combinations(takoyaki, 2))
def main(args):
_ = input()
takoyaki = map(int, input().split())
ans = solve(takoyaki)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| 1 | 167,952,055,743,318 | null | 292 | 292 |
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N-K):
if A[i] < A[i+K]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | cnt = 0
def merge(A,left,mid,right):
'''n1 = mid - left
n2 = right - mid
L = []
R = []
for i in range(0,n1):
L.append(A[left+i])
for i in range(0,n2):
R.append(A[mid+i])
L.append(1000000001)
R.append(1000000001)
'''
L = A[left:mid]+[1000000001]
R = A[mid:right]+[1000000001]
i = 0
j = 0
global cnt
for k in range(left,right):
cnt += 1
if L[i] <= R[j]:
A[k]=L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A,left,right):
if left+1 < right:
mid = (left+right)//2
mergeSort(A,left,mid)
mergeSort(A,mid,right)
merge(A,left,mid,right)
if __name__ == '__main__':
n = (int)(input())
a = list(map(int,input().split()))
mergeSort(a,0,n)
print(*a)
print(cnt) | 0 | null | 3,630,522,427,238 | 102 | 26 |
# 累積和を用いたdpの高速か
n, k = map(int, input().split())
mod = 998244353
lr_list = [list(map(int, input().split())) for _ in range(k)]
dp = [0] * (n + 1)
dp[1] = 1
sdp = [0] * (n + 1)
sdp[1] = 1
for i in range(2, n + 1):
for j in range(k):
right = max(0, i - lr_list[j][0])
left = max(0, i - lr_list[j][1] - 1)
dp[i] = (dp[i] + sdp[right] - sdp[left]) % mod
sdp[i] = sdp[i - 1] + dp[i]
print(dp[n]) | N,M,X=[int(s) for s in input().split()]
Book=[[int(s) for s in input().split()] for _ in range(N)]
INF=10**7
ans=set()
ans.add(INF)
for n in range(2**N):
#Bit全探索
Xls=[0 for i in range(M)]
cost=0
for i in range(N):
if ((n>>i)&1)==1:
cost+=Book[i][0]
for b in range(M):
Xls[b]+=Book[i][b+1]
if min(Xls)>=X:
ans.add(cost)
if min(ans)==INF:
print(-1)
else:
print(min(ans)) | 0 | null | 12,532,602,825,430 | 74 | 149 |
n,x,m = map(int,input().split())
mod = m
num = []
ans = 0
cnt = 0
ch = x
#ループの始まりを特定
while True:
if ch not in num:
num.append(ch)
else:
st = ch #ループの開始している配列の初めの数字
break
ch *= ch
ch %= mod
#ループの始まりの配列の添え字を特定
for i in range(len(num)):
if num[i] == st:
stnum = i #ループ開始の最初の配列のの番号
break
else:
stnum = len(num) - 1
if 0 in num:
ans = sum(num[:n])
else:
if (len(num)-stnum) != 0:
rest = (n-stnum)%(len(num)-stnum) #余り
qu = (n-stnum)//(len(num)-stnum) #商
else:
rest = n
qu = 0
if n <= stnum + 1:
ans = sum(num[:n])
else:
ans = sum(num[:stnum]) + sum(num[stnum:stnum+rest]) + sum(num[stnum:])*qu
print(ans) | N = int(input())
L = list(map(int, input().split()))
if N <= 2:
print(0)
exit()
count = 0
for i in range(N-2):
for j in range(i+1, N-1):
for k in range(j+1, N):
rod = [L[i], L[j], L[k]]
condition = set(rod)
rod = sorted(rod)
if rod[0] + rod[1] > rod[2] and len(condition) == 3:
count += 1
print(count) | 0 | null | 3,942,186,168,088 | 75 | 91 |
A, B, N = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
l.append(min(a) + min(b))
for _ in range(N):
aq, bq, d = map(int, input().split())
l.append( a[aq-1] + b[bq-1] - d )
print(min(l)) | from itertools import accumulate
h,w,k=map(int,input().split())
s=[[0]*(w+1)]+[[0]+[int(i) for i in input()] for _ in range(h)]
for i in range(h+1):
s[i]=list(accumulate(s[i]))
for j in range(w+1):
for i in range(h):
s[i+1][j]+=s[i][j]
ans=10**18
for i in range(1<<h-1):
a=[]
for j in range(h-1):
if (i>>j)&1:a+=[j+1]
a+=[h]
cnt=len(a)-1
q=1
for j in range(1,w+1):
p=0
flag=0
for l in a:
if s[l][j]-s[l][j-1]-s[p][j]+s[p][j-1]>k:flag=1
elif s[l][j]-s[l][q-1]-s[p][j]+s[p][q-1]>k:
q=j
cnt+=1
break
else:p=l
if flag:break
else:
ans=min(cnt,ans)
print(ans) | 0 | null | 51,154,151,355,310 | 200 | 193 |
from collections import deque
H, W = map(int, input().split())
L = []
for _ in range(H):
s = input()
a = []
for i in range(len(s)):
a.append(s[i])
L.append(a)
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
def bfs(x, y):
dp = [[10000000] * W for _ in range(H)]
dp[y][x] = 0
if L[y][x] == '#':
return dp
else:
d = deque()
d.append([x, y])
while len(d) > 0:
s = d.popleft()
for i in range(4):
if (s[1] +
dy[i] >= 0 and s[1] +
dy[i] < H and s[0] +
dx[i] >= 0 and s[0] +
dx[i] < W):
if L[s[1] +
dy[i]][s[0] +
dx[i]] == '.' and dp[s[1] +
dy[i]][s[0] +
dx[i]] == 10000000:
d.append([s[0] + dx[i], s[1] + dy[i]])
dp[s[1] + dy[i]][s[0] + dx[i]] = dp[s[1]][s[0]] + 1
return dp
max_num = 0
for i in range(H):
for j in range(W):
dp = bfs(j, i)
for k in dp:
for p in k:
if (p == 10000000):
continue
max_num = max(max_num, p)
print(max_num) | h,*s=open(0)
h,w,k,*m=map(int,h.split())
b=w
while b:
b-=1;r=0;t=j=w;d=[0]*h
while j:
i=c=0;j-=1
while h-i:
d[c]+=s[i][j]>'0';c+=b>>i&1;i+=1
if max(d)>k:d=[0]*h;r+=1;t,j=j,j+(t>j);i=h
m+=r+c,
print(min(m))
| 0 | null | 71,611,294,287,642 | 241 | 193 |
suit = {"S": 0, "H": 1, "C": 2, "D": 3}
suit_keys = list(suit.keys())
deck = [[suit_keys[i] + " " + str(j + 1) for j in range(13)] for i in range(4)]
for _ in range(int(input())):
card = input().split()
deck[suit[card[0]]][int(card[1]) - 1] = ""
for i in range(4):
for j in deck[i]:
if j != "":
print(j)
| import sys
X = int(input())
#%%
for a in range(1000):
for b in range(-1000, 1000):
if pow(a, 5) - pow(b, 5) == X:
print(a,b)
sys.exit( ) | 0 | null | 13,412,214,978,390 | 54 | 156 |
n, m = map(int, input().split())
data2 = []
for i in range(m):
data2.append(input().split())
graph = [[] for i in range(n)]
for i in range(0,m):
a, b = map(lambda z: int(z) - 1, data2[i])
graph[a].append(b)
graph[b].append(a)
size = [0 for i in range(n)]
check = [True for i in range(n)]
for i in range(n):
if check[i]:
tmp = 1
stack = [i]
check[i] = False
while stack:
now = stack.pop()
size[now] = tmp
tmp += 1
for to in graph[now]:
if check[to]:
check[to] = False
stack.append(to)
print(max(size)) | N,M=map(int, input().split())
class UnionFind():
def __init__(self, n):
self.n = n # ノード数
self.parents = [-1]*n # 各ノードごとのparent
def find(self, x):
# 自身が根であれば
if self.parents[x]<0:
return x
# そうでなければ、再帰的に繰り返し、自身の根を探索
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
# それぞれの根
x = self.find(x)
y = self.find(y)
# 根が同一であれば
if x == y:
return
if self.parents[x] > self.parents[y]:
x,y = y,x
self.parents[x]+=self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
uf = UnionFind(N)
for _ in range(M):
i, j = map(int, input().split())
i-=1
j-=1
uf.union(i,j)
max_size = 0
for i in range(N):
if uf.parents[i]<0:
size = uf.size(i)
if max_size<size:
max_size = size
print(max_size)
| 1 | 3,966,122,367,604 | null | 84 | 84 |
h,n = map(int,input().split())
arr=list(map(int,input().split()))
print("No" if h>sum(arr) else "Yes") | H,N=map(int,input().split())
list=[]
for i in map(int,input().split()):
list.append(i)
if H - sum(list) <= 0:
print('Yes')
else:
print('No')
| 1 | 77,899,740,616,880 | null | 226 | 226 |
import math
# a=int(input())
#b=int(input())
# c=[]
# for i in b:
# c.append(i)
e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(3)]
cal=1
for i in range(e1-e2):
if f[i]>=f[i+e2]:
print("No")
else:
print("Yes") | import math
import collections
import fractions
import itertools
import functools
import operator
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k, n):
if a[i] > a[i-k]:
print("Yes")
else:
print("No")
return 0
if __name__ == "__main__":
solve() | 1 | 7,100,289,305,190 | null | 102 | 102 |
a=[]
for i in range(2):
m=input().split()
a.append(m)
list_1=[int(l) for l in a[0]]
list_2=[int(l) for l in a[1]]
total=0
largest=list_2[0]
smallest=list_2[0]
for x in range(list_1[0]):
if largest<list_2[x]:
largest=list_2[x]
if smallest>list_2[x]:
smallest=list_2[x]
for x in list_2:
total+=x
print(smallest,largest,total) | from math import *
a,b,c = map(int,raw_input().split())
sinc = sin(radians(c))
cosc = cos(radians(c))
S = 0.5 * a * b * sinc
L = a+b+sqrt(a**2+b**2-2*a*b*cosc)
h = b*sinc
print S
print L
print h | 0 | null | 461,129,532,710 | 48 | 30 |
import sys
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
n, m = MI()
ac = [False]*(n+1)
wa = [0]*(n+1)
for _ in range(m):
temp = input().split()
p, s = int(temp[0]), temp[1]
if not ac[p]:
if s == 'AC':
ac[p] = True
else:
wa[p] += 1
penalty = 0
for i in range(n+1):
if ac[i]:
penalty += wa[i]
print('{} {}'.format(sum(ac), penalty))
if __name__ == '__main__':
main() | #! python3
# toggling_cases.py
x = input()
rst = ''
for c in x:
if c.isupper():
rst += c.lower()
elif c.islower():
rst += c.upper()
else:
rst += c
print(rst)
| 0 | null | 47,562,782,338,130 | 240 | 61 |
X,K,D=list(map(int,input().split()))
X=abs(X)
import sys
if X > 0 and X-K*D>=0:
print(X-K*D)
sys.exit()
M=X//D
Q=X%D
if M%2 == K%2:
print(Q)
else:
print(D-Q)
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
from itertools import product
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def LF(): return list(map(float, input().split()))
def LC(): return [c for c in input().split()]
def LLI(n): return [LI() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]
def array2d(N, M, initial=0):
return [[initial]*M for _ in range(N)]
def copy2d(orig, N, M):
ret = array2d(N, M)
for i in range(N):
for j in range(M):
ret[i][j] = orig[i][j]
return ret
INF = float("inf")
MOD = 10**9 + 7
def main():
X, K, D = MAP()
# 到達候補は0に近い正と負の二つの数
d, m = divmod(X, D)
cand = (m, m-D)
if X >= 0:
if K <= d:
print(X-K*D)
return
else:
rest = (K-d)
if rest % 2 == 0:
print(cand[0])
return
else:
print(-cand[1])
return
else:
if K <= -d-1:
print(abs(X+K*D))
return
else:
rest = K-(-d-1)
if rest % 2 == 0:
print(-cand[1])
return
else:
print(cand[0])
return
return
if __name__ == '__main__':
main()
| 1 | 5,275,593,178,268 | null | 92 | 92 |
#coding: utf-8
import math
n = int(input())
x = [int(i) for i in input().split(" ")]
y = [int(i) for i in input().split(" ")]
d1 = d2 = d3 = di = 0
for i in range(n):
d1 += abs(x[i] - y[i])
d2 += abs(x[i] - y[i])**2
d3 += abs(x[i] - y[i])**3
if di < abs(x[i] - y[i]):
di = abs(x[i] - y[i])
print(d1)
print(math.pow(d2, 1.0/2.0))
print(math.pow(d3, 1.0/3.0))
print(di)
| w=input()
print(w.swapcase())
| 0 | null | 872,998,930,012 | 32 | 61 |
class SegmentTree():
"""A segment Tree.
This is a segment tree without recursions.
This can support queries as follows:
- update a single value in O(logN).
- get the folded value of values in a segment [l, r) in O(logN)
N is the length of the given iterable value.
Parameters
----------
iterable : Iterable[_T]
An iterable value which will be converted into a segment tree
func : Callable[[_T, _T], _T]
A binary function which returns the same type as given two.
This has to satisfy the associative law:
func(a, func(b, c)) = func(func(a, b), c)
e : _T
The identity element of the given func.
In other words, this satisfies:
func(x, e) = func(e, x) = x
"""
def __init__(self, iterable, func, e):
self.func = func
self.e = e
ls = list(iterable)
self.n = 1 << len(ls).bit_length()
ls.extend( [self.e] * (self.n - len(ls)) )
self.data = [self.e] * self.n + ls
for i in range(self.n-1, 0, -1):
self.data[i] = self.func(self.data[2*i], self.data[2*i+1])
def replace(self, index, value):
"""replace the old value of the given index with the given new value.
This replaces the old value of the given index with the given new value in O(logN).
This is like "list[index] = value".
Parameters
----------
index : int
The index of the value which will be replaced.
value : _T
The new value with which the old value will be replaced.
"""
index += self.n
self.data[index] = value
index //= 2
while index > 0:
self.data[index] = self.func(self.data[2*index], self.data[2*index+1])
index //= 2
def folded(self, l, r):
"""get the folded value of values in a segment [l, r).
This get the folded value of values in a segment [l, r) in O(logN).
If func is add, it returns the sum of values in [l, r).
In other words, this is eqivalent to "sum(list[l:r])".
If func is other functions, then this is equivalent to "accumulate(list[l:r], func)".
Parameters
----------
l : int
The left edge.
r : int
The right edge.
Returns
-------
_T(the same type as the type of the element of the given iterable)
This is equivalent to func(list[l], func(list[l+1], ... ) ).
If func is represented as '*', then it's:
list[l] * list[l+1] * ... * list[r-1]
"""
left_folded = self.e
right_folded = self.e
l += self.n
r += self.n
while l < r:
if l % 2:
left_folded = self.func(left_folded, self.data[l])
l += 1
if r % 2:
r -= 1
right_folded = self.func(self.data[r], right_folded)
l //= 2
r //= 2
return self.func(left_folded, right_folded)
from operator import or_
N = int(input())
S = input()
ls = [1 << (ord(c) - ord('a')) for c in S]
segtree = SegmentTree(ls, or_, 0)
Q = int(input())
for _ in range(Q):
s = input()
if s[0] == '1':
i, c = s[2:].split()
segtree.replace(int(i)-1, 1 << (ord(c) - ord('a')))
else:
l, r = map(int, s[2:].split())
value = segtree.folded(l-1, r)
print(format(value, 'b').count('1'))
| def RSQ_add(i, x, y):
while True:
if i > n:
break
BIT[y][i] += x
i += i & -i
def RSQ_getsum(i, x):
s = 0
while True:
if i <= 0:
break
s += BIT[x][i]
i -= i & -i
return s
n = int(input())
s = list(input())
q = int(input())
BIT = [[0] * (n + 1) for _ in range(26)]
for i in range(n):
y = ord(s[i]) - 97
RSQ_add(i + 1, 1, y)
for _ in range(q):
com, a, b = map(str, input().split())
com, a = int(com), int(a)
if com == 1:
RSQ_add(a, -1, ord(s[a - 1]) - 97)
RSQ_add(a, 1, ord(b) - 97)
s[a - 1] = b
else:
b = int(b)
ans = 0
for i in range(26):
if RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1:
ans += 1
print(ans) | 1 | 62,181,914,949,402 | null | 210 | 210 |
H,W,N=[int(input()) for i in range(3)]
print((N+max(H,W)-1)//max(H,W)) | N = int(input())
ans = ""
while N > 0:
N -=1
ans = chr(ord("a") + (N%26)) + ans
N //= 26
print(ans) | 0 | null | 50,134,925,599,220 | 236 | 121 |
class Dice(object):
def __init__(self, line):
self.top = 1
self.bottom = 6
self.south = 2
self.east = 3
self.west = 4
self.north = 5
self.convert = [int(s) for s in line.split()]
def move(self, direction):
if 'N' == direction:
self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom
elif 'S' == direction:
self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
elif 'W' == direction:
self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
elif 'E' == direction:
self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom
def search(self, line):
top, south = [int(s) for s in line.split()]
for direction in 'NNNNWNNNN':
self.move(direction)
if self.convert[self.south - 1] == south:
break
for direction in 'WWWW':
self.move(direction)
if self.convert[self.top - 1] == top:
break
return self.result()
def result(self):
return self.convert[self.east - 1]
dice = Dice(input())
for i in range(int(input())):
print(dice.search(input())) | class Dice:
"""Dice class"""
def __init__(self): # ?????????????????????
self.eyeIndex = 1 #center
self.eyeIndex_E = 3 #east
self.eyeIndex_W = 4 #west
self.eyeIndex_N = 5 #north
self.eyeIndex_S = 2 #south
self.eye = 0
self.eye_S = 0
self.eye_E = 0
self.eyes = []
def convEyesIndexToEyes(self):
self.eye = self.eyes[self.eyeIndex]
self.eye_S = self.eyes[self.eyeIndex_S]
self.eye_E = self.eyes[self.eyeIndex_E]
def shakeDice(self, in_command):
pre_eyeIndex = self.eyeIndex
if in_command == "E":
self.eyeIndex = self.eyeIndex_W
self.eyeIndex_E = pre_eyeIndex
self.eyeIndex_W = 7 - self.eyeIndex_E
elif in_command == "W":
self.eyeIndex = self.eyeIndex_E
self.eyeIndex_W = pre_eyeIndex
self.eyeIndex_E = 7 - self.eyeIndex_W
elif in_command == "N":
self.eyeIndex = self.eyeIndex_S
self.eyeIndex_N = pre_eyeIndex
self.eyeIndex_S = 7 - self.eyeIndex_N
elif in_command == "S":
self.eyeIndex = self.eyeIndex_N
self.eyeIndex_S = pre_eyeIndex
self.eyeIndex_N = 7 - self.eyeIndex_S
self.convEyesIndexToEyes()
def rotateDice(self):
#rotate clockwise
pre_E = self.eyeIndex_E
pre_S = self.eyeIndex_S
pre_W = self.eyeIndex_W
pre_N = self.eyeIndex_N
self.eyeIndex_E = pre_N
self.eyeIndex_S = pre_E
self.eyeIndex_W = pre_S
self.eyeIndex_N = pre_W
self.convEyesIndexToEyes()
def getEye(self):
return self.eye
def getEye_S(self):
return self.eye_S
def getEye_E(self):
return self.eye_E
def setEyes(self, eyes): # setEyes()???????????? ???????????????
eyes = "0 " + eyes
self.eyes = list(map(int, eyes.split(" ")))
self.convEyesIndexToEyes()
dice_1 = Dice()
dice_1.setEyes(input().rstrip())
command_time = int(input().rstrip())
for i in range(command_time):
in_eye, in_eye_S = map(int, input().rstrip().split(" "))
shake_direction = "E"
def_eye = dice_1.getEye()
while True:
dice_1.shakeDice(shake_direction)
if dice_1.getEye() == in_eye:
break
if dice_1.getEye() == def_eye:
shake_direction = "N"
while True:
if dice_1.getEye_S() == in_eye_S:
break
dice_1.rotateDice()
print(dice_1.getEye_E()) | 1 | 245,750,233,472 | null | 34 | 34 |
n, k, c = [int(i) for i in input().split()]
s = input()
work1 = [0] * k
work2 = [0] * k
cnt = 0
day = 0
while cnt < k:
if s[day] == 'o':
work1[cnt] = day
cnt += 1
day += (c+1)
else:
day += 1
cnt = k-1
day = n-1
while cnt >= 0:
if s[day] == 'o':
work2[cnt] = day
cnt -= 1
day -= (c + 1)
else:
day -= 1
for i in range(k):
if work1[i] == work2[i]:
print(work1[i]+1)
| # input
N, K, C = map(int, input().split())
S = input()
# process
l = [i+1 for i in range(N) if S[i] == 'o']
left = [l[0]]
right = [l[-1]]
for i in range(1, len(l)):
if l[i] > left[-1]+C:
left.append(l[i])
if l[-i-1] < right[-1]-C:
right.append(l[-i-1])
# output
# print(l)
# print(left)
# print(right)
if len(left) == K:
for i in range(len(left)):
if left[i] == right[-i-1]:
print(left[i])
| 1 | 40,516,481,326,930 | null | 182 | 182 |
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L,reverse = False)
cnt = 0
# a の index
for a in range(len(L)):
# b の index
for b in range(a+1,len(L)):
# c が取りうる最大の index
c_idx = bisect.bisect_left(L,L[a]+L[b]) - 1
cnt += c_idx - b
print(cnt) | import sys
heights = [int(i) for i in sys.stdin.read().split()]
heights.sort(reverse=True)
print("\n".join(map(str, heights[:3]))) | 0 | null | 86,245,449,147,120 | 294 | 2 |
#coding:utf-8
#1_6_A 2015.4.1
input()
numbers = input().split()
numbers.reverse()
print(' '.join(numbers)) | n = int(input())
s = input()
s = list(s)
for i in range(len(s)):
if ord(s[i])+n > 90:
s[i] = chr(ord(s[i])+n-26)
else:
s[i] = chr(ord(s[i])+n)
print("".join(s)) | 0 | null | 67,834,677,850,798 | 53 | 271 |
x = raw_input().split()
if float(x[0]) < float(x[1]):
print "a < b"
elif float(x[0]) > float(x[1]):
print "a > b"
else:
print "a == b" | a, b = map(int, input().split())
operator = '>' if a > b else '<' if a < b else '=='
print("a {} b".format(operator)) | 1 | 364,700,929,340 | null | 38 | 38 |
from math import ceil
t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a1 -= b1
a2 -= b2
a1 *= t1
a2 *= t2
if a1 + a2 == 0:
print("infinity")
exit()
if a1*(a1+a2) > 0:
print(0)
exit()
x = -a1/(a1+a2)
n = ceil(x)
if n == x:
print(2*n)
else:
print(2*n-1) | import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def main():
t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
if a1 < b1:
tmp = b1
b1 = a1
a1 = tmp
tmp = b2
b2 = a2
a2 = tmp
l1 = (a1 - b1) * t1
l2 = (a2 - b2) * t2
l3 = l1 + l2
if l3 == 0:
print("infinity")
return
if l3 > 0:
print(0)
return
ans = 1
if l1 % (-l3) == 0:
print(ans + 2 * (l1 // (-l3)) - 1)
return
print(ans + 2 * (l1 // (-l3)))
if __name__ == '__main__':
main() | 1 | 131,609,676,802,380 | null | 269 | 269 |
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from collections import deque
n = int(stdin.readline())
dll = deque()
fcode = ord('F')
lcode = ord('L')
while n:
n -= 1
cmd = stdin.readline().rstrip()
if cmd.startswith('i'):
dll.appendleft(int(cmd[7:]))
elif cmd.startswith('d'):
c = ord(cmd[6])
if c == fcode:
dll.popleft()
elif c == lcode:
dll.pop()
else:
try:
dll.remove(int(cmd[7:]))
except ValueError:
pass
print(*dll) | from collections import deque
import sys
n = int(sys.stdin.readline())
q = deque()
for i in range(n):
command = sys.stdin.readline()[:-1]
if command[0] == 'i':
q.appendleft(command[7:])
elif command[6] == ' ':
try:
q.remove(command[7:])
except Exception as e:
pass
elif command[6] == 'F':
q.popleft()
else:
q.pop()
print(' '.join(q)) | 1 | 50,265,725,568 | null | 20 | 20 |
n = int(input())
Mo = 100000
for i in range(n):
Mo = Mo * 1.05
if Mo%1000 != 0:
Mo = (int(Mo/1000) + 1)*1000
print(int(Mo)) | def ceil(n):
if n%1000:
return (1+n//1000)*1000
else:
return n
def debt(n):
if n==0: return 100000
return int(ceil(debt(n-1)*1.05))
print(debt(int(input())))
| 1 | 1,192,825,402 | null | 6 | 6 |
a = input("")
if "A" in a and "B" in a:
print("Yes")
else:
print("No") | # https://atcoder.jp/contests/abc157/tasks/abc157_e
from string import ascii_lowercase
from bisect import bisect_left, insort
from collections import defaultdict
N = int(input())
S = list(input())
Q = int(input())
locs = {c: [] for c in ascii_lowercase}
for i in range(N):
locs[S[i]].append(i + 1)
for _ in range(Q):
qt, l, r = input().split()
l = int(l)
if int(qt) == 1:
if S[l - 1] != r:
locs[S[l - 1]].remove(l)
S[l - 1] = r
insort(locs[r], l)
else:
count = 0
r = int(r)
for ch in ascii_lowercase:
if len(locs[ch]) > 0:
left = bisect_left(locs[ch], l)
if left != len(locs[ch]):
if locs[ch][left] <= r:
count += 1
print(count) | 0 | null | 58,791,538,772,912 | 201 | 210 |
input()
S,T=input().split()
print(''.join([s+t for s,t in zip(S,T)])) | n = int(input())
S, T = input().split()
ans = ""
for i in range(n):
ans += S[i]+T[i]
print(ans) | 1 | 111,744,508,289,708 | null | 255 | 255 |
n, m, q = map(int, input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
a[i], b[i], c[i], d[i] = map(int, input().split())
score = []
# 数列Aの全探索
import copy
def dfs(A):
if len(A) == n+1:
# score計算
tmp = 0
#print(A)
for i in range(q):
if A[b[i]] - A[a[i]] == c[i]:
tmp += d[i]
score.append(tmp)
return
else:
tmp = A[-1]
arr = copy.copy(A)
arr.append(tmp)
while(arr[-1] <= m):
dfs(arr)
arr[-1] += 1
dfs([1])
print(max(score))
| # coding: utf-8
import itertools
def main():
n, m, q = map(int, input().split())
matrix = []
for _ in range(q):
row = list(map(int, input().split()))
matrix.append(row)
# print(matrix)
A = list(range(1, m+1))
ans = 0
for tmp_A in itertools.combinations_with_replacement(A, n):
tmp_A = sorted(list(tmp_A))
tmp_ans = 0
for row in matrix:
# print("row", row)
# print("tmp_A", tmp_A)
tmp = tmp_A[row[1] - 1] - tmp_A[row[0]- 1]
if row[2] == tmp:
tmp_ans += row[3]
if tmp_ans >= ans:
ans = tmp_ans
print(ans)
main() | 1 | 27,611,730,836,388 | null | 160 | 160 |
n=int(input())
a=list(map(int,input().split()))
import numpy as np
dp=np.full((3,n+1),-pow(10,15))
dp[:,0]=0
dp[1,1]=a[0]
for i in range(2,n+1):
#l,r=max(1,n//2-(n-i+1)//2),(i+1)//2+1
l,r=max(1,i//2-1),(i+1)//2+1
if i%3==2:
now,pre,prepre=2,1,0
elif i%3==0:
now,pre,prepre=0,2,1
elif i%3==1:
now,pre,prepre=1,0,2
dp[now,l:r]=np.maximum(dp[pre,l:r],dp[prepre,l-1:r-1]+a[i-1])
print(dp[now,n//2]) | s = int(input())
A = input().split()
for i in range(s):
v = A[i]
j = i - 1
while j >=0 and int(A[j]) > int(v):
A[j + 1] = A[j]
j -= 1
A[j + 1] = v
print(" ".join(A)) | 0 | null | 18,815,127,593,574 | 177 | 10 |
n = int(input())
s = input()
c_curr = ""
ans = 0
for c in s:
if c != c_curr:
ans += 1
c_curr = c
print(ans)
| N = int(input())
s = input()
ans = 1
for i in range(1, len(s)):
if s[i-1] != s[i]:
ans += 1
print(ans) | 1 | 170,803,973,094,950 | null | 293 | 293 |
taro,hanako = 0,0
w=[]
n = int(raw_input())
for i in xrange(n):
w.append(map(str, raw_input().split()))
for j in xrange(n):
if w[j][0]>w[j][1]:
taro+=3
elif w[j][0]<w[j][1]:
hanako+=3
else:
taro+=1
hanako+=1
#print n
#print w
print taro,hanako | lit = input()
length = len(lit)
times = 0
if length != 1:
for i in range(int(length/2)):
if lit[i] != lit[length-1-i]:
times += 1
print(times)
else:
print(times) | 0 | null | 60,980,935,743,760 | 67 | 261 |
def ABC_157_A():
N = int(input())
if N%2 == 0:
print(int(N/2))
else:
print(int(N/2+1))
if __name__ == '__main__':
ABC_157_A() | n=int(input())
if(n//2==n/2):
m=n//2
else:
m=n//2+1
print(m) | 1 | 59,182,408,059,908 | null | 206 | 206 |
n = int(input())
ans, tmp = 0, 5
if n % 2 == 0:
n //= 2
while tmp <= n:
ans += n // tmp
tmp *= 5
print(ans)
| import sys
input = sys.stdin.readline
def main():
N = int(input())
a = list(map(int, input().split()))
s = 0
for i in a:
s ^= i
for i in a:
ans = s ^ i
print(ans, sep=' ', end=' ')
main() | 0 | null | 64,037,445,721,668 | 258 | 123 |
# ABC162F - Select Half
import sys
input = sys.stdin.buffer.readline
def main():
n=int(input())
a=list(map(int,input().split()))
if n<4:
print(max(a))
sys.exit()
if n%2:
#dp[位置][個数]
dp=[[0,0,0]for i in range(n-2)]
dp[0]=a[:3]
for i in range(2,n-1,2):
dp[i][0]=dp[i-2][0]+a[i]
dp[i][1]=max(dp[i-2][0],dp[i-2][1])+a[i+1]
dp[i][2]=max(dp[i-2][0],dp[i-2][1],dp[i-2][2])+a[i+2]
print(max(dp[-1]))
else:
#dp[位置][個数]
dp=[[0,0]for i in range(n-1)]
dp[0]=a[:2]
for i in range(2,n-1,2):
dp[i][0]=dp[i-2][0]+a[i]
dp[i][1]=max(dp[i-2][0],dp[i-2][1])+a[i+1]
print(max(dp[-1]))
main() | import numpy as np
n = int(input())
a = list(map(int,input().split()))
dp = np.zeros((n+1,2), int)
dp[1],dp[2] = [0,a[0]], [0,max(a[0], a[1])]
for i in range(3,n+1):
if(i%2 == 0):
dp[i][0] = max(dp[i-1][0],dp[i-2][0]+a[i-1],dp[i-2][1])
dp[i][1] = max(dp[i-1][1],dp[i-2][1]+a[i-1])
else:
dp[i][0] = max(dp[i-1][1],dp[i-2][1],dp[i-2][0]+a[i-1])
dp[i][1] = dp[i-2][1]+a[i-1]
print(dp[n][(n+1)%2]) | 1 | 37,437,157,995,582 | null | 177 | 177 |
from math import cos, radians, sin, sqrt
def g(a, b, c):
c_rad = radians(c)
yield a * b * sin(c_rad) / 2
yield a + b + sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(c_rad))
yield b * sin(c_rad)
a, b, c = list(map(int, input().split()))
for i in g(a, b, c):
print("{:.8f}".format(i)) | def main():
n = input()
A = []
s = []
B = [[0,0] for i in xrange(n)]
for i in xrange(n):
A.append(map(int,raw_input().split()))
color = [-1]*n
d = [0]*n
f = [0]*n
t = 0
for i in xrange(n):
if color[i] == -1:
t = dfs(i,t,color,d,f,A,n)
for i in xrange(n):
print i+1, d[i], f[i]
def dfs(u,t,color,d,f,A,n):
t += 1
color[u] = 0
d[u] = t
for i in A[u][2:]:
if (color[i-1] == -1):
t = dfs(i-1,t,color,d,f,A,n)
color[u] = 1
t += 1
f[u] = t
return t
if __name__ == '__main__':
main() | 0 | null | 88,346,480,628 | 30 | 8 |
from queue import LifoQueue
MAP = input()
que = LifoQueue()
res = LifoQueue()
for i, m in enumerate(MAP):
if m=='\\':
que.put(i)
elif m=='/':
if not que.empty():
j = que.get(False)
v = i - j
t = (j, v)
while not res.empty():
pre = res.get(False)
if (pre[0] > j):
t = (t[0], t[1] + pre[1])
else:
res.put(pre)
res.put(t)
break
else:
res.put(t)
summaly = 0
lakes = []
while not res.empty():
v = res.get()
lakes.append(v[1])
summaly += v[1]
print(summaly)
print(len(lakes), *(reversed(lakes)))
| from collections import deque
x = input()
A = 0
S1 = deque()
S2 = deque()
for i in range(len(x)):
if x[i] == "\\":
S1.append(i)
elif x[i] == "/" and len(S1) > 0 :
j = S1.pop()
A += i - j
a = i - j
while len(S2) > 0 and S2[-1][0] > j:
a += S2[-1][1]
S2.pop()
S2.append([j,a])
print(A)
if len(S2)== 0:
print(0)
else:
print(len(S2),"",end="")
for i in range(len(S2)):
if i == len(S2) - 1:
print(S2[i][1])
else:
print(S2[i][1],"",end="")
| 1 | 58,432,391,562 | null | 21 | 21 |
N,K=map(int,input().split())
a=0
while N>0:
a+=1
N=N//K
print(a) | n=int(input())
if n==0 or n==1:
print(0)
else:
print((10**n - (2*(9**n)-8**n))%(10**9+7)) | 0 | null | 33,658,300,968,500 | 212 | 78 |
n,u,v = map(int,input().split())
import queue
dist_t = [0] * n
dist_a = [0] * n
elb_t = [0] * n
elb_a = [0] * n
ab = [[] for j in range(n)]
for i in range(n-1):
a,b = map(int,input().split())
ab[a-1].append(b-1)
ab[b-1].append(a-1)
u -= 1
v -= 1
q = queue.Queue()
q.put(u)
elb_t[u] = 1
dist_t[u] = 0
while not q.empty():
tmp = q.get()
for i in range(len(ab[tmp])):
idx = ab[tmp][i]
if elb_t[idx] != 1:
if dist_t[idx] != 0:
dist_t[idx] = min(dist_t[idx], dist_t[tmp] + 1)
else:
dist_t[idx] = dist_t[tmp] + 1
elb_t[idx] = 1
q.put(idx)
q = queue.Queue()
q.put(v)
elb_a[v] = 1
dist_a[v] = 0
while not q.empty():
tmp = q.get()
for i in range(len(ab[tmp])):
idx = ab[tmp][i]
if elb_a[idx] != 1:
dist_a[idx] = dist_a[tmp] + 1
elb_a[idx] = 1
q.put(idx)
ans = 0
for i in range(n):
if dist_a[i] > dist_t[i]:
ans = max(ans,dist_a[i]-1)
print(ans) |
import copy
import sys
# 再帰上限を引き上げる
sys.setrecursionlimit(10**6)
def dfs(graph, v, d):
seen[v] = True # 訪問済みかどうか
dist[v] = d # 距離を記録
# 頂点vから行ける頂点を全探索
for i in graph[v]:
if seen[i]:
continue
dfs(graph, i, d+1)
# ここから本文
N, u, v = map(int, input().split())
u -= 1
v -= 1
# グラフ構造を作る
graph = [[] for i in range(N)]
for i in range(N - 1):
A, B = map(int, input().split())
A -= 1
B -= 1
graph[A].append(B)
graph[B].append(A)
# 青木くんからの各頂点の距離
seen = [False for i in range(N)]
dist = [0 for i in range(N)]
dfs(graph, v, 0)
aoki_dist = copy.deepcopy(dist)
# 高橋くんからの各頂点の距離
seen = [False for i in range(N)]
dist = [0 for i in range(N)]
dfs(graph, u, 0)
takahashi_dist = copy.deepcopy(dist)
ans = 0
for i in range(N):
if aoki_dist[i] > takahashi_dist[i]:
if aoki_dist[i] - 1 > ans:
ans = aoki_dist[i] - 1
print(ans) | 1 | 116,894,422,193,472 | null | 259 | 259 |
from sys import stdin
import math
import re
import queue
input = stdin.readline
MOD = 1000000007
INF = 122337203685477580
def solve():
A,B,M = map(int, input().split())
v1 =list(map(int, input().split()))
v2 =list(map(int, input().split()))
res = INF
for i in range(M):
X,Y,C = map(int, input().split())
res = min(res,v1[X-1] + v2[Y-1] - C)
res = min(res,min(v1) + min(v2))
res = max(0,res)
print(res)
if __name__ == '__main__':
solve()
| a = int(input())
b =int(input())
set_ = set([1,2,3])
set_.remove(a)
set_.remove(b)
print(set_.pop()) | 0 | null | 82,468,285,937,690 | 200 | 254 |
import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
amax=max(a)+1
ah=[0]*amax
for i in a:
for j in range(i,amax,i):
ah[j]+=1
an=0
for i in a:
if ah[i]==1:
an+=1
print(an) | h,w = map(int, input().split())
sl = []
for _ in range(h):
row = list(input())
sl.append(row)
dp = [ [10000]*w for _ in range(h) ]
dp[0][0] = 0
for h_i in range(h):
for w_i in range(w):
if h_i+1 < h:
if sl[h_i][w_i] == '.' and sl[h_i+1][w_i] == '#':
dp[h_i+1][w_i] = min( dp[h_i+1][w_i], dp[h_i][w_i]+1 )
else:
dp[h_i+1][w_i] = min( dp[h_i+1][w_i], dp[h_i][w_i] )
if w_i+1 < w:
if sl[h_i][w_i] == '.' and sl[h_i][w_i+1] == '#':
dp[h_i][w_i+1] = min( dp[h_i][w_i+1], dp[h_i][w_i]+1 )
else:
dp[h_i][w_i+1] = min( dp[h_i][w_i+1], dp[h_i][w_i] )
ans = dp[h-1][w-1]
if sl[0][0] == '#': ans += 1
print(ans)
| 0 | null | 31,643,421,610,560 | 129 | 194 |
a,b,c,d = list(map(int,(input().split())))
ans=''
for i in range(100):
c-=b
if c<=0:
ans='Yes'
break
a-=d
if a<=0:
ans='No'
break
print(ans) | def main():
a, b, c, d = map(int, input().split())
if c % b == 0:
e = c // b
else:
e = c // b + 1
if a % d == 0:
f = a // d
else:
f = a // d + 1
if e > f:
ans = "No"
else:
ans = "Yes"
print(ans)
if __name__ == "__main__":
main()
| 1 | 29,799,447,187,708 | null | 164 | 164 |
n, x, m = map(int, input().split())
ans = 0
if x == 0:
print(0)
exit()
elif x == 1:
print(n)
exit()
flag = [False]*m
a = []
while not flag[x]:
flag[x] = True
a.append(x)
x = pow(x, 2, m)
loop_start_idx = a.index(x)
loop_len = len(a) - loop_start_idx
loop_count = (n - loop_start_idx)//loop_len
loop_amari = (n-loop_start_idx)%loop_len
ans = sum(a[:loop_start_idx])
ans += sum(a[loop_start_idx:])*loop_count
ans += sum(a[loop_start_idx: loop_start_idx + loop_amari])
print(ans)
| a,b=input().split()
if a*int(b)>=b*int(a):
print(b*int(a))
else:
print(a*int(b)) | 0 | null | 43,739,767,044,530 | 75 | 232 |
def main():
from bisect import bisect_left as bl
from itertools import accumulate as ac
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
aa = [0]+list(ac(a))
an = aa[n]
ok = 0
ng = 10**10
while abs(ok-ng) > 1:
mid = (ok+ng)//2
if sum([n-bl(a, mid-a[i]) for i in range(n)]) >= m:
ok = mid
else:
ng = mid
c = -m+sum([n-bl(a, ok-a[i]) for i in range(n)])
ans = -c*ok
for i in range(n):
d = bl(a, ok-a[i])
ans += an-aa[d]+(n-d)*a[i]
print(ans)
main() | from numpy import*
n,m,*a=int_(open(0).read().split())
a=int_(fft.irfft(fft.rfft(bincount(a,[1]*n,2**18))**2)+.5)
c=0
for i in where(a>0)[0][::-1]:t=min(m,a[i]);c+=i*t;m-=t
print(c) | 1 | 107,536,653,731,210 | null | 252 | 252 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce
n,k = list(map(int, input().split()))
a = n*(n+k+1)*(n-k+2)//2
b = n-k+2
c = -((n+2)*(n+1)*n - k*(k-1)*(k-2))//3
print((a+b+c) % (10**9+7)) | import math
N, D = map(int,input().split())
XY = list(list(map(int,input().split())) for _ in range(N))
count = 0
for i in range(N):
if math.sqrt(XY[i][0] ** 2 + XY[i][1] ** 2) <= D: count += 1
print(count) | 0 | null | 19,368,495,075,330 | 170 | 96 |
x = int(input())
print(x//500*1000 + x%500//5*5) | #!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")
def popcount(n):
ret = 0
for i in range(18):
if n>>i & 1:
ret += 1
return ret
def main():
N = int(input())
X = input().decode().rstrip()
# X に含まれる "1" の数
x_cnt = X.count("1")
# i 桁目が 0 : x_cnt += 1
# i 桁目が 1 : x_cnt -= 1
# より, X mod x_cnt +1, X mod x_cnt-1 を事前計算しておく
x_mod_pl,x_mod_mi = 0,0
d_pl,d_mi = 1,1
mod_pl,mod_mi = x_cnt+1,max(1,x_cnt-1)
for i in range(N-1,-1,-1):
if X[i]=="1":
x_mod_pl = (x_mod_pl + d_pl) % mod_pl
x_mod_mi = (x_mod_mi + d_mi) % mod_mi
d_pl = (d_pl*2) % mod_pl
d_mi = (d_mi*2) % mod_mi
for i in range(N):
ans = 1
if X[i] == "1":
# 1 -> 0 に変換した結果, 1が全く存在しない場合
if x_cnt == 1:
print(0)
continue
a = (x_mod_mi - pow(2,(N-1-i), mod_mi)) % mod_mi
else:
a = (x_mod_pl + pow(2,(N-1-i), mod_pl)) % mod_pl
while a > 0:
pop_cnt = popcount(a)
a %= pop_cnt
ans += 1
print(ans)
if __name__ == "__main__":
main() | 0 | null | 25,453,011,040,288 | 185 | 107 |
#input an interget
k=int(input())
#input an string
str1=str(input())
#get the length of the string
x=int(len(str1))
#initialise y
y=0
#make a second string for the appending
str2="..."
#if statement about how the string will function
#if the string is the same length as k then print it
if x<=k:
print(str1)
#if not, delete the last character of the string
else:
while y<k:
print(str1[y],end=(""))
y+=1
print(str2)
| 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()
| 0 | null | 77,855,423,477,088 | 143 | 272 |
n, x, t = map(int, input().split())
print(n//x*t) if n%x==0 else print((n//x+1)*t) | import math
a = int(input())
for i in range(50001):
if math.floor(i*1.08) == a:
print(i)
exit()
print(":(") | 0 | null | 64,728,247,252,220 | 86 | 265 |
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8,i8,i8[:],i8[:]), cache=True)
def main(H,N,A,B):
INF = 1<<30
dp = np.full(H+1,INF,np.int64)
dp[0] = 0
for i in range(N):
for h in range(A[i],H):
dp[h] = min(dp[h],dp[h-A[i]]+B[i])
dp[H] = min(dp[H],min(dp[H-A[i]:H]+B[i]))
ans = dp[-1]
return ans
H, N = map(int, input().split())
A = np.zeros(N,np.int64)
B = np.zeros(N,np.int64)
for i in range(N):
A[i],B[i] = map(int, input().split())
print(main(H,N,A,B)) | print('Yes') if len(set(input()))==2 else\
print('No') | 0 | null | 67,915,155,160,480 | 229 | 201 |
# ABC159C
# 縦,横,高さの合計が len である直方体のうち,体積が最大のものの体積はいくつか
def f(len):
print((len / 3) ** 3)
f(int(input()))
| a, b = input().split()
print(str(min(int(a), int(b)))*max(int(a),int(b))) | 0 | null | 65,344,417,822,084 | 191 | 232 |
n, quantum = list(map(int, input().split()))
queue = []
sumOfTime = 0
for _ in range(n):
name, time = input().split()
queue.append([name, int(time)])
while len(queue) > 0:
name, time = queue.pop(0)
if time > quantum:
sumOfTime += quantum
queue.append([name, time - quantum])
else:
sumOfTime += time
print(name, sumOfTime)
| n=int(input())
x=100000
for i in range(n):
x=x+x*0.05
x=((x-1)//1000+1)*1000
print(int(x))
| 0 | null | 22,318,157,552 | 19 | 6 |
def main():
L, R, d = map(int, input().split())
ans = 0
for i in range(L, R + 1):
if i % d == 0:
ans += 1
print(ans)
if __name__ == "__main__":
main() | x,y,z=map(int,input().split())
count=0
for i in range(x,y+1):
if(i%z==0):
count+=1
print(count)
| 1 | 7,479,515,608,032 | null | 104 | 104 |
n = int(input())
taro,hanako = 0,0
for i in range(n):
t,h = input().split(' ')
if t > h:
taro += 3
elif t < h:
hanako += 3
else:
taro += 1
hanako += 1
print('{0} {1}'.format(taro,hanako)) | import bisect
N=int(input())
S=list(str(input()))
def ci(x):
return "abcdefghijklmnopqrstuvwxyz".find(x)
d=[[] for _ in range(26)]
for i,s in enumerate(S):
d[ci(s)].append(i)
for i in range(int(input())):
t,x,y=input().split()
if t=="1":
x=int(x)-1
if S[x]!=y:
l=bisect.bisect_left(d[ci(S[x])],x)
d[ci(S[x])].pop(l)
bisect.insort(d[ci(y)],x)
S[x]=y
else:
x,y=int(x)-1,int(y)-1
c=0
for j in range(26):
l=bisect.bisect_left(d[j],x)
if l<len(d[j]) and d[j][l] <= y:
c += 1
print(c)
| 0 | null | 32,244,529,644,340 | 67 | 210 |
n = input()
len_n = len(n)
dp = [[0,2] for i in range(len_n+1)]
for k,v in enumerate(n[::-1]):
v = int(v)
dp[k+1][0] = min(dp[k][0] + v, dp[k][1] + v)
dp[k+1][1] = min(dp[k][0] + 10 - v + 1, dp[k][1] + 10 - v - 1)
print(min(dp[len_n]))
| nums = list(map(int, input().strip()))
nums = nums[::-1]
nums.append(0)
ans = 0
for i in range(len(nums) - 1):
if nums[i] > 5:
ans += 10 - nums[i]
nums[i+1] += 1
elif nums[i] == 5:
if nums[i + 1] >= 5:
nums[i + 1] += 1
ans += 5
else:
ans += nums[i]
ans += nums[-1]
print(ans)
| 1 | 70,655,837,043,750 | null | 219 | 219 |
N = int(input())
ans = 0
for i in range(1, N+1):
if i % 3 == 0:
continue
if i % 5 == 0:
continue
ans += i
print(ans)
| a,b=map(int,input().strip().split())
print(a*b) | 0 | null | 25,190,798,639,670 | 173 | 133 |
N = int(input())
if N % 2 == 0:
result = N//2 - 1
else:
result = N//2
print(result) | n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
As = [0] * (n + 1)
Bs = [0] * (m + 1)
for i in range(n):
As[i + 1] = A[i] + As[i]
for i in range(m):
Bs[i + 1] = B[i] + Bs[i]
l = 0
r = n + m + 1
while r - l > 1:
p = (l + r) // 2
best = min(
As[i] + Bs[p - i] for i in range(p + 1)
if min(i, n) + min(p - i, m) == p
)
if best <= k:
l = p
else:
r = p
print(l) | 0 | null | 81,880,501,166,084 | 283 | 117 |
N = input()
N = N[::-1]
c = 0
otsuri = 0
mai = 0
for i in range(len(N)):
if int(N[i]) + c == 5 and i < len(N) - 1:
if int(N[i+1]) >= 5:
otsuri += 5
c = 1
else:
mai += int(N[i]) + c
c = 0
elif int(N[i]) + c > 5:
otsuri += 10 - int(N[i]) - c
c = 1
else:
mai += int(N[i]) + c
c = 0
print(otsuri + mai + c) | N = '0' + input()
INF = float('inf')
dp = [[INF] * 2 for _ in range(len(N) + 1)]
dp[0][0] = 0
for i in range(len(N)):
n = int(N[len(N) - 1 - i])
for j in range(2):
for a in range(10):
ni = i + 1
nj = 0
b = a - n - j
if b < 0:
b += 10
nj = 1
dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b)
a == b
print(dp[len(N)][0])
| 1 | 70,775,532,652,580 | null | 219 | 219 |
house_info = [[[0 for i in xrange(10)]for j in xrange(3)]for k in xrange(4)]
n = input()
for i in xrange(n):
b,f,r,v=map(int,raw_input().split())
house_info[b-1][f-1][r-1] += v
for i in xrange(4):
for j in xrange(3):
result = " " + " ".join(map(str,house_info[i][j]))
print result
if i < 3:
print "####################" | K = int(input())
s = 'ACL'
print(s * K)
| 0 | null | 1,629,818,463,712 | 55 | 69 |
# -*- coding: utf-8 -*-
k,x = list(map(int,input().split()))
ret = "No"
if 500*k>=x:
ret = "Yes"
print(ret) | N=int(input())
A=list(map(int, input().split()))
if N==2:
print(max(A))
exit()
dp=[[0,0,0] for i in range(N)]
dp[0][0]=A[0]
dp[1][1]=A[1]
dp[2][2]=A[2]
for i in range(N):
if i>1:
dp[i][0]=dp[i-2][0]+A[i]
if i>2:
dp[i][1]=max(dp[i-3][0],dp[i-2][1])+A[i]
if i>3 :
dp[i][2]=max(dp[i-4][0],dp[i-3][1],dp[i-2][2])+A[i]
if N%2==1:
ans=max(dp[-1][2],dp[-2][1],dp[-3][0])
else:
ans=max(dp[-1][1],dp[-2][0])
print(ans) | 0 | null | 67,566,668,825,590 | 244 | 177 |
# -*- coding: utf-8 -*-
class Graph:
def __init__(self, n, adj_matrix):
self.n = n
self.adj_matrix = adj_matrix
def show(self):
for _ in self.adj_matrix:
print(*_)
def dfs(self):
self.states = [2] * self.n
self.d = [None] * self.n
self.f = [None] * self.n
self.time = 0
for u in range(self.n):
if self.states[u] == 2:
self.dfs_visit(u)
def dfs_visit(self, u):
self.states[u] = 1
self.time += 1
self.d[u] = self.time
for v, edge in enumerate(self.adj_matrix[u]):
if edge and self.states[v] == 2:
self.dfs_visit(v)
self.states[u] = 0
self.time += 1
self.f[u] = self.time
def show_dfs(self, start=0):
self.dfs()
for i, (d, f) in enumerate(zip(self.d, self.f)):
print(i + 1, d, f)
if __name__ == '__main__':
n = int(input())
adj_matrix = [[0] * n for i in range(n)]
for i in range(n):
for v in input().split()[2:]:
adj_matrix[i][int(v) - 1] = 1
g = Graph(n, adj_matrix)
g.show_dfs()
| n, k = list(map(int, input().split()))
ans = ''
while n > 0:
ans = str(n % k) + ans
n //= k
print(len(ans)) | 0 | null | 32,058,963,926,460 | 8 | 212 |
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)])) | from math import inf
n = int(input())
A = list(map(int, input().split()))
dp = [[-inf] * 3 for _ in range(n + 1)]
k = 1 + n % 2
dp[0][0] = 0
for i in range(n):
for j in range(k + 1):
if j < k:
dp[i + 1][j + 1] = dp[i][j]
now = dp[i][j]
if (i + j) % 2 == 0:
now += A[i]
dp[i + 1][j] = max(dp[i + 1][j], now)
print(dp[n][k])
| 1 | 37,544,640,990,858 | null | 177 | 177 |
def gcd( x, y ):
if 1 < y < x:
return gcd( y, x%y )
else:
if y == 1:
return 1
return x
a, b = [ int( val ) for val in raw_input( ).split( " " ) ]
if a < b:
a, b = b, a
print( gcd( a, b ) ) | import fractions
if __name__ == '__main__':
x, y = [int(_) for _ in input().split()]
print(fractions.gcd(x, y)) | 1 | 8,102,636,740 | null | 11 | 11 |
from collections import deque
INF = 1000000
N,T,A=map(int,input().split())
T -= 1
A -= 1
G = [ [] for i in range(N) ]
DT = [ INF for _ in range(N) ]
DA = [ INF for _ in range(N) ]
for i in range(N-1):
h1,h2=map(int,input().split())
h1 -= 1
h2 -= 1
G[h1].append(h2);
G[h2].append(h1);
DT[T] = 0
DA[A] = 0
q = deque()
# BFS
q.append(T)
while len(q) > 0:
v = q.popleft()
for nv in G[v]:
if DT[nv] == INF:
DT[nv] = DT[v] + 1
q.append(nv)
q.clear()
q.append(A)
while len(q) > 0:
v = q.popleft()
for nv in G[v]:
if DA[nv] == INF:
DA[nv] = DA[v] + 1
q.append(nv)
max_da = 0
for i in range(N):
#print(i, " T:", DT[i], " A:", DA[i])
if DA[i] - DT[i] >= 1 :
max_da = max(DA[i], max_da)
print(max_da-1)
| import sys
sys.setrecursionlimit(10 ** 5)
n, u, v = map(int, input().split())
u -= 1
v -= 1
es = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
es[a-1].append(b-1)
es[b-1].append(a-1)
def dfs(v, dist, p=-1, d=0):
dist[v] = d
for nv in es[v]:
if nv == p:
continue
dfs(nv, dist, v, d+1)
def calc_dist(x):
dist = [-1] * n
dfs(x, dist)
return dist
dist_t = calc_dist(u)
dist_a = calc_dist(v)
mx = 0
for i in range(n):
if dist_t[i] < dist_a[i]:
mx = max(mx, dist_a[i])
ans = mx - 1
print(ans) | 1 | 117,473,747,452,912 | null | 259 | 259 |
x, y = map(int, input().split())
if x >= 10:
print(y)
else:
print(y+100*(10-x))
| def main():
n, r = map(int, input().split())
inner = 0
if n >= 10:
inner = r
else:
inner = r + 100*(10-n)
print(inner)
main()
| 1 | 63,544,756,430,460 | null | 211 | 211 |
N,X,Y=map(int,input().split())
distance=[0]*N
for i in range(1,N):
for j in range(i+1,N+1):
k=min(j-i,abs(j-X)+abs(i-Y)+1,abs(j-Y)+abs(i-X)+1)
distance[k]+=1
print(*distance[1:],sep="\n") | x,y = map(int,input().split())
if y % 2 != 0:
print('No')
elif x * 2 <= y <= x * 4:
print('Yes')
else:
print('No') | 0 | null | 28,721,731,318,560 | 187 | 127 |
def main(istr, ostr):
x, y = istr.readline().strip().split()
a = int(x)
b0, _, b1, b2 = y
b0, b1, b2 = list(map(int, [b0, b1, b2]))
c = a * (100 * b0 + 10 * b1 + b2)
res = c // 100
print(res, file=ostr)
if __name__ == "__main__":
import sys
main(sys.stdin, sys.stdout)
| a=int(input())
b=int(input())
if a+b==4:
ans=2
elif a+b==3:
ans=3
else:
ans=1
print(ans) | 0 | null | 63,691,366,850,280 | 135 | 254 |
s1,s2=map(str,input().split(' '))
print(s2+s1) | a = input().split()
b = str(a[0])
c = str(a[1])
print(c+b) | 1 | 103,207,277,708,940 | null | 248 | 248 |
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
dx = [1,0]
dy = [0,1]
INF = float('inf')
h,w = readInts()
dp = [[INF]*w for _ in range(h)]
FIELD = [input() for _ in range(h)]
# dp[j][i] = i番目とj番目にかかる魔法の度合い
# 初期値 魔法1, なし 0
if FIELD[0][0] == '#':
dp[0][0] = 1
else:
dp[0][0] = 0
for i in range(w):
for j in range(h):
for x,y in dx,dy:
ny = j + y
nx = i + x
if ny >= h or nx >= w:
continue
add = 0
if FIELD[ny][nx] == '#' and FIELD[j][i] == '.':
add = 1
dp[ny][nx] = min(dp[ny][nx], dp[j][i] + add)
print(dp[h-1][w-1])
if __name__ == '__main__':
main()
| import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
H, W = map(int, input().split())
I = [list(map(str, input())) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
for i in range(H):
for j in range(W):
if i == 0 and j == 0:
continue
if i == 0:
dp[i][j] = dp[i][j-1] if I[i][j] == I[i][j-1] else dp[i][j-1] + 1
continue
if j == 0:
dp[i][j] = dp[i-1][j] if I[i][j] == I[i-1][j] else dp[i-1][j] + 1
continue
dp[i][j] = dp[i][j-1] if I[i][j] == I[i][j-1] else dp[i][j-1] + 1
if I[i][j] == I[i-1][j]:
dp[i][j] = min(dp[i][j], dp[i-1][j])
else:
dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
t = dp[-1][-1]
if I[0][0] == "#":
t += 1
ans = -(-t//2)
print(ans)
| 1 | 49,162,753,874,568 | null | 194 | 194 |
# coding: utf-8
import string
d = {}
for ch in list(string.ascii_lowercase):
d[ch] = 0
while True:
try:
s = list(input().lower())
except EOFError:
break
for ch in s:
if ch.isalpha():
d[ch] += 1
else:
pass
for k, v in sorted(d.items()):
print('{} : {}'.format(k, v))
| m=str(raw_input())
n=[int(i) for i in m]
n.insert(0,0)
l=len(n)
ans=0
for i in range(l-1,-1,-1):
current=n[i]
if(current<5):
ans+=current
elif(current==5):
ans+=current
if(n[i-1]>=5):
n[i-1]+=1
else:
ans+=10-current
n[i-1]+=1
print ans
| 0 | null | 36,382,977,042,048 | 63 | 219 |
n = int(input())
a = list(map(int, input().split()))
a.sort()
m = a[-1]
c = [0] * (m + 1)
for ai in a:
for i in range(ai, m + 1, ai):
c[i] += 1
ans = 0
for ai in a:
if c[ai] == 1:
ans += c[ai]
print(ans) | N = int(input())
A = list(map(int,(input().split())))
sum=1
if 0 in A:
print(0)
else:
for i in range(N):
sum *= A[i]
if sum >= int(1e18):
break
print(sum if sum<= int(1e18) else -1) | 0 | null | 15,281,231,642,490 | 129 | 134 |
K = int(input())
A, B = map(int, input().split())
MaxKx = B//K*K
if MaxKx >= A :
print('OK')
else :
print('NG') | n = int(input())
r_min = int(input())
r_t = int(input())
g_max = r_t - r_min
r_min = min(r_t,r_min)
for _ in range(n-2):
r_t = int(input())
g_max = max(g_max, r_t-r_min)
r_min = min(r_t,r_min)
print(g_max)
| 0 | null | 13,238,646,050,022 | 158 | 13 |
A ,V= map(int, input().split())
B ,W= map(int, input().split())
T = int(input())
if V <= W:
print("NO")
elif abs(A - B) / (V - W) <= T:
print("YES")
else:
print("NO") | a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
a_t = t*v
b_t = t*w
if a_t >= b_t+abs(a-b):
print('YES')
else:
print('NO')
| 1 | 15,180,456,417,490 | null | 131 | 131 |
N = int(input())
R = sorted([list(map(int, input().split())) for i in range(N)])
T = []
for i in range(N):
T.append([R[i][0] + R[i][1], R[i][0] - R[i][1]])
T.sort(reverse=True)
while len(T) - 1 > 0:
t = T.pop()
i = 1
while len(T) and t[0] > T[-1][1]:
N -= 1
i += 1
T.pop()
print(N) | def multiply(values):
out = 1
for i in values:
out *= int(i)
print(out)
stdin = input().split()
multiply(stdin) | 0 | null | 52,966,546,577,120 | 237 | 133 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.