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
|
---|---|---|---|---|---|---|
H,W,N=[int(input()) for i in range(3)]
print((N+max(H,W)-1)//max(H,W)) | N=int(input())
L=list(map(int, input().split()))
count=0
for i in range(N-2):
for j in range(i+1,N-1):
for k in range(j+1,N):
if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
if max(L[i],L[j],L[k])<L[i]+L[j]+L[k]-max(L[i],L[j],L[k]):
count += 1
else:
pass
print(count)
| 0 | null | 46,688,169,625,240 | 236 | 91 |
n = int(input())
a = list(map(int,input().split()))
from collections import Counter
b = Counter(a)
for i in b.values():
if i>1:
print('NO')
break
else:
print('YES') | def solve():
n = int(input())
s = set(map(int, input().split()))
print("YES" if len(s) == n else "NO")
solve()
| 1 | 73,958,612,446,048 | null | 222 | 222 |
import sys
input = sys.stdin.readline
def main():
N, K, S = map(int, input().split())
if S == 10 ** 9:
ans = [S] * K + [1] * (N - K)
else:
ans = [S] * K + [10 ** 9] * (N - K)
print(" ".join(map(str, ans)))
if __name__ == "__main__":
main()
| N,K,S=map(int,input().split())
if S==10**9:
for i in range(K):
print(S,"",end="")
for i in range(K,N):
print(1,"",end="")
print()
else:
for i in range(K):
print(S,"",end="")
for i in range(K,N):
print(S+1,"",end="")
print()
| 1 | 91,117,669,181,138 | null | 238 | 238 |
n=int(input())
a=list(map(int,input().split()))
cnt=[0]*(10**5+1)
for i in a:
cnt[i]+=1
xxx=sum(a)
q=int(input())
for i in range(q):
l,r=map(int,input().split())
pin=cnt[l]
cnt[r]+=pin
cnt[l]=0
xxx+=(r-l)*pin
print(xxx) | def main():
import sys
from collections import Counter
input = sys.stdin.readline
input()
a = tuple(map(int, input().split()))
ans = sum(a)
a = Counter(a)
for _ in range(int(input())):
b, c = map(int, input().split())
if b in a:
ans += (c - b) * a[b]
a[c] = a[c] + a[b] if c in a else a[b]
del a[b]
print(ans)
if __name__ == "__main__":
main() | 1 | 12,288,155,111,372 | null | 122 | 122 |
def resolve():
N,M = map(int,input().split())
if N % 2 == 1:
for i in range(M):
print(str(i+1) + " " + str(N-i))
else:
for i in range((M-1) // 2 + 1):
print(str(i+1) + " " + str(N-i))
for i in range((M-1) // 2 + 1 , M):
print(str(i+1) + " " + str(N-i-1))
resolve() | import math
def main():
x1, y1, x2, y2 = [float(n) for n in input().split()]
d = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
print("{:.5f}".format(d));
if __name__ == '__main__':
main()
| 0 | null | 14,457,890,783,132 | 162 | 29 |
K = int(input())
n = 7
for i in range(1, 1000001):
if n % K == 0:
print(i)
exit()
n = (n * 10 + 7) % K
else:
print(-1) | n = int(input())
MOD = int(1e9 + 7)
a, b, c = 1, 1, 1
for i in range(n):
a *= 10;
b *= 9;
c *= 8;
a %= MOD;
b %= MOD;
c %= MOD;
print((a - 2 * b + c) % MOD); | 0 | null | 4,653,056,851,310 | 97 | 78 |
n = int(input())
s = []
for i in range(n):
a = input()
b = []
for j in range(len(a)):
if a[j]=='(':
b.append(1)
else:
b.append(-1)
s.append(b)
l = []
r = []
for x in s:
b = 0
c = 0
for y in x:
c+=y
b = min(b,c)
z = len(x)
d = 0
e = 0
for j in range(z):
e += x[z-j-1]
d = max(d,e)
if c>0:
l.append([b,c])
else:
r.append([d,c])
l.sort(reverse=True)
r.sort()
flag = 1
x = 0
for b,c in l:
if x+b<0:
flag = 0
x += c
y = 0
for d,c in r:
if y+d>0:
flag = 0
y += c
if y+x!=0:
flag = 0
print('Yes' if flag else'No')
|
def f():
N = int(input())
UP = []
DOWN = []
for _ in range(N):
S = input()
c = 0
minC = 0
for s in S:
if s == '(':
c += 1
else:
c -= 1
minC = min(minC, c)
if c >= 0:
UP.append((minC, c))
else:
DOWN.append((c - minC, c))
c = 0
for up in sorted(UP, reverse=True):
if c + up[0] < 0:
return False
c += up[1]
for down in sorted(DOWN, reverse=True):
if c + down[1] - down[0] < 0:
return False
c += down[1]
if c != 0:
return False
return True
if f():
print('Yes')
else:
print('No')
| 1 | 23,496,358,363,298 | null | 152 | 152 |
n = int(input())
s = input()
sl = list(s)
answer = ""
for i in s:
t = ord(i)+n
if t <= 90:
answer += chr(t)
else :
answer += chr(ord("A") + abs(t-90)-1)
print(answer) | n=int(input())
print(sum(i*(n//i*(n//i+1))//2 for i in range(1,n+1))) | 0 | null | 72,886,131,507,420 | 271 | 118 |
import math
a,b,C=map(int,input().split())
C2=math.radians(C)
sin=math.sin(C2)
cos=math.cos(C2)
S = 0.5*a*b*sin
L = a+b+(math.sqrt((a**2+b**2)-(2*a*b*cos)))
H = (a*b*sin/2)/(a/2)
print("{0:.8f}".format(S))
print("{0:.8f}".format(L))
print("{0:.8f}".format(H)) | import math
a, b, C = map(float, input().split())
S = (a * b * math.sin(math.radians(C))) / 2
L = a + b + (math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))))
h = b * math.sin(math.radians(C))
print("{:.8f}".format(S))
print("{:.8f}".format(L))
print("{:.8f}".format(h))
| 1 | 175,586,750,680 | null | 30 | 30 |
n = int(input())
if(n % 2 !=0):
print(0)
exit()
ketasu = len(str(n))
ans = 0
for i in range(1, 100):
ans += n // (2 * 5 **i)
print(ans) | n = int(input())
p = 10
a = 0
if n % 2 == 0:
while p <= n:
a += n // p
p *= 5
print(a) | 1 | 115,880,852,610,468 | null | 258 | 258 |
n, x, m = map(int, input().split())
P = [] # value of pre & cycle
sum_p = 0 # sum of pre + cycle
X = [-1] * m # for cycle check
for i in range(n):
if X[x] > -1:
cyc_len = len(P) - X[x]
nxt_len = (n - X[x]) % cyc_len
pre = sum(P[:X[x]])
cyc = (sum_p - pre) * ((n - X[x]) // cyc_len)
nxt = sum(P[X[x]: X[x] + nxt_len])
print(pre + cyc + nxt)
exit()
X[x] = i
P.append(x)
sum_p += x
x = x*x % m
print(sum_p)
| n, t = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(n)]
dp = [[0] * t for _ in range(n)]
ans = 0
a.sort()
for i in range(n-1):
for j in range(t):
if j - a[i][0] < 0:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = max(dp[i][j], dp[i][j - a[i][0]] + a[i][1])
ans = max(ans, dp[i + 1][-1] + a[i+1][1])
print(ans) | 0 | null | 77,278,164,925,314 | 75 | 282 |
print((int(input())-1)//2+1) | n = int(input())
print(n//2 + (n % 2)*1)
| 1 | 59,276,933,336,558 | null | 206 | 206 |
n,m,x = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]
prices = []
for i in range(2**n):
buy = [[] for _ in range(m+1)]
for j in range(n):
if ((i >> j) & 1):
for k in range(m+1):
buy[k].append(c[j][k])
for k in range(1,m+1):
if sum(buy[k]) < x:
break
else:
prices.append(sum(buy[0]))
if len(prices) == 0:
print(-1)
else:
print(min(prices)) | n, m, x = map(int, input().split())
books_info = []
price_info = []
for i in range(n):
c, *a = map(int, input().split())
books_info.append(a)
price_info.append(c)
pattern_list = []
for j in range(2 ** n):
tmp_list = []
for k in range(n):
if ((j >> k) & 1):
tmp_list.append(k)
else:
pass
pattern_list.append(tmp_list)
book_price = 10 ** 5 * 12 + 1
for pattern in pattern_list:
# 全ての参考書を買わない=len(pattern)が0の場合はスキップする
if len(pattern) == 0:
continue
is_ok = False
price = 0
for j in range(m):
m_sum = 0
price_sum = 0
for k in pattern:
m_sum += books_info[k][j]
price_sum += price_info[k]
if m_sum >= x:
is_ok = True
else:
is_ok = False
break
price = price_sum
if is_ok == True:
book_price = min(price, book_price)
else:
pass
print(book_price if book_price != 10 ** 5 * 12 + 1 else -1)
| 1 | 22,349,797,379,452 | null | 149 | 149 |
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
N=int(input())
def dfs(u,par):
col=1
for v in graph[u]:
if col==par:
col+=1
color_dic[(u,v)]=col
dfs(v,col)
col+=1
elist=[]
graph=[[] for _ in range(N+1)]
for _ in range(N-1):
a,b=map(int,input().split())
graph[a].append(b)
elist.append((a,b))
#print(graph)
color_dic={}
dfs(1,-1)
#print(color_dic)
K=len(set(color_dic.values()))
print(K)
for e in elist:
print(color_dic[e]) | import collections
N = int(input())
G = [set() for i in range(N)]
ab = [tuple(map(int, input().split())) for i in range(N-1)]
d = dict()
i = 0
for a, b in ab:
a -= 1
b -= 1
d[(a, b)] = i
d[(b, a)] = i
i += 1
G[a].add(b)
G[b].add(a)
q = collections.deque()
r = set()
r.add(0)
q.append((0, 0))
ans = [0]*(N-1)
while(q):
x, s = q.popleft()
i = 1
for y in G[x]:
if y in r:
continue
else:
r.add(y)
if i == s:
i += 1
ans[d[(x, y)]] = i
q.append((y, i))
i += 1
print(max(ans))
print(*ans, sep='\n')
| 1 | 136,444,828,980,388 | null | 272 | 272 |
def main2():
K = int(input())
rem = set()
n = ans = 0
while True:
n = n * 10 + 7
ans += 1
if n % K == 0:
print(ans)
break
else:
n = n % K
if n in rem:
print(-1)
break
else:
rem.add(n)
if __name__ == "__main__":
main2() | import sys
k = int(input())
a = dict()
cnt = 0
base = 0
while True:
cnt += 1
base = (base*10+7)%k
if base == 0:
break
if base in a:
cnt = -1
break
else:
a[base] = 1
print(cnt) | 1 | 6,120,161,622,400 | null | 97 | 97 |
def main():
n = int(input())
if n%2:
print(n//2+1)
else:
print(n//2)
if __name__ == '__main__':
main() | X,Y,Z=map(str,input().split())
XX=Y
Y=X
X=XX
XX=Z
Z=X
X=XX
print(X,Y,Z) | 0 | null | 48,680,066,110,502 | 206 | 178 |
import numpy as np
n = int(input())
a = []
b = []
for i in range(n):
ae, be = map(int, input().split())
a.append(ae)
b.append(be)
a_med = np.median(a)
b_med = np.median(b)
if n % 2 == 0:
print(int(2*b_med - 2*a_med + 1))
else:
print(int(b_med - a_med + 1))
| def main():
n = int(input())
array = [int(x) for x in input().split()]
cnt = 0
for i in range(n):
min_idx = i
for j in range(i+1, n):
if array[min_idx] > array[j]:
min_idx = j
if min_idx != i:
tmp = array[i]
array[i] = array[min_idx]
array[min_idx] = tmp
cnt += 1
print(" ".join(map(str, array)))
print(cnt)
main()
| 0 | null | 8,728,326,872,132 | 137 | 15 |
r = float(input())
re1 = 1 * 1
re = r * r
print(int(re/re1))
| def main():
N = int(input())
x, y = map(int, input().split())
a1 = x + y
a2 = x + y
b1 = y - x
b2 = y - x
N -= 1
while N != 0:
x, y = map(int, input().split())
a1 = max(a1, x + y)
a2 = min(a2, x + y)
b1 = max(b1, y - x)
b2 = min(b2, y - x)
N = N - 1
print(max(a1 - a2, b1 - b2))
main()
| 0 | null | 74,482,865,559,984 | 278 | 80 |
import sys
import bisect
import math
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
B = [(A[i]*F[i], F[i]) for i in range(N)]
B.sort(reverse=True)
L = 0
R = B[0][0]
if sum(A) <= K:
print(0)
exit(0)
while(1):
ans = (L+R) // 2
flag = True
tmp = 0
for i in range(N):
tmp += math.ceil(max(B[i][0] - ans, 0) / B[i][1])
if tmp > K:
flag = False
break
if flag:
R = ans
else:
L = ans
if L == R or L+1 == R:
print(R)
break
| n = int(input())
area = n*n
print(area) | 0 | null | 155,003,250,063,936 | 290 | 278 |
N = int(input())
N_ri = round(pow(N, 1/2))
for i in range(N_ri, 0, -1):
if N % i == 0:
j = N // i
break
print(i + j - 2) | n,m=map(int,input().split());print('YNeos'[n!=m::2]) | 0 | null | 121,793,619,841,970 | 288 | 231 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(L: int):
return L**3 / 27
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
L = int(next(tokens)) # type: int
print(f'{solve(L)}')
if __name__ == '__main__':
main()
| 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():
L = int(readline())
ans = pow(L / 3, 3)
print(ans)
return
if __name__ == '__main__':
main()
| 1 | 46,920,081,374,428 | null | 191 | 191 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
while y: x,y = y,x%y
return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
"""Return a tuple list of divisor of n"""
return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
"""Return a list of prime numbers n or less"""
is_prime = [True]*(MAX_NUM+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX_NUM**0.5)+1):
if not is_prime[i]: continue
for j in range(i*2, MAX_NUM+1, i):
is_prime[j] = False
return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
a, b, m = MII()
aa = MII()
bb = MII()
q = [MII() for _ in range(m)]
minv = min(aa) + min(bb)
for x,y,c in q:
minv = min(minv, aa[x-1]+bb[y-1]-c)
print(minv)
if __name__ == '__main__':
main() | N,K = list(map(int, input().split()))
mod = int(1e9+7)
# N+1からK個をとる手法
# だけどmin - maxまで一飛ばしで作れるはずなので引き算でもとめてよい
ans = 0
for i in range(K,N+2):
ans = (ans + i * (N+1-i) + 1) % mod
print(ans) | 0 | null | 43,706,318,789,380 | 200 | 170 |
import sys
H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H # X:各行の爆破対象の個数
Y = [0] * W # Y:各列の爆破対象の個数
for h, w in bomb:
X[h] += 1
Y[w] += 1
maxX = max(X)
maxY = max(Y)
R = [h for h, x in enumerate(X) if x == maxX] # R:爆破対象の数が最大となる行の番号
C = [w for w, y in enumerate(Y) if y == maxY] # C:爆破対象の数が最大となる列の番号
bomb = set(bomb)
for r in R:
for c in C:
if (r, c) not in bomb:
# (r, c)に爆破対象が存在しないとき, maxX + maxY が答えとなることが確定するため,
# 即座に探索を終了する. これによりループの回数は最大でもM+1回となる.
print(maxX + maxY)
exit()
print(maxX + maxY - 1) |
late = input()
i = int(late)
if i >= 400 and i <= 599:
print("8")
if i >= 600 and i <= 799:
print("7")
if i >= 800 and i <= 999:
print("6")
if i >= 1000 and i <= 1199:
print("5")
if i >= 1200 and i <= 1399:
print("4")
if i >= 1400 and i <= 1599:
print("3")
if i >= 1600 and i <= 1799:
print("2")
if i >= 1800 and i <= 1999:
print("1")
| 0 | null | 5,755,226,633,570 | 89 | 100 |
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import fractions
def main():
a,b = map(int, input().split())
print(a*b//fractions.gcd(a, b))
if __name__ == '__main__':
main()
| ans = 0
N = int(input())
for i in range(N):
a = int(input())
if a == 2:
ans += 1
elif a%2 == 0:
continue
else:
if pow(2, a-1, a) == 1:
ans += 1
print(ans) | 0 | null | 56,465,369,073,180 | 256 | 12 |
NK = input()
num = NK.split()
N = num[0]
K = num[1]
P = input()
Pn = P.split()
#print(Pn)
Pn_a = [int(i) for i in Pn]
Pn_b = sorted(Pn_a)
price = 0
for i in range(int(K)):
price += int(Pn_b[i])
print(price)
| n,k = map(int,input().split())
p = [int(x) for x in input().split()]
p.sort()
s = 0
for i in range(k):
s+=p[i]
print(s)
| 1 | 11,650,397,435,258 | null | 120 | 120 |
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N = int(input())
S = str(input())
c = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
ans = []
for i in range(len(S)):
n_c = c[((c.index(S[i]))+ N)% 26]
ans.append(n_c)
print("".join(ans)) | import math
(a, b, C) = [float(i) for i in input().split()]
S = 0.5 * a * b * math.sin(math.radians(C))
c = math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(C)))
print("%8f" %(S))
print("%8f" %(a + b + c))
print("%8f" %(S / a * 2)) | 0 | null | 67,153,923,018,240 | 271 | 30 |
import itertools
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
v = list(itertools.combinations_with_replacement(range(1, m+1), n))
ans = 0
for i in v:
s = 0
for a, b, c, d in abcd:
if i[b-1] - i[a-1] == c:
s += d
ans = max(ans, s)
print(ans) | n,m = map(int,input().split())
if n%2 ==1:
for i in range(1,m+1):
print(i,n-i)
else:
left_end = 1+m if m%2 == 1 else m
left_start = left_end//2
right_start = left_end+m//2
for i in range(1,m+1):
if i%2 == 1:
print(left_start,left_start+i)
left_start-=1
else:
print(right_start,right_start+i)
right_start-=1 | 0 | null | 28,202,039,198,588 | 160 | 162 |
n = int(input())
s = str(input())
s_new = s[0]
for i in range(1,len(s)):
if s_new[-1] != s[i]:
s_new = s_new + s[i]
print(len(s_new)) | data = list(input().split(" "))
stack = []
for d in data:
if d == '+':
stack.append(stack.pop() + stack.pop())
elif d == '-':
stack.append(- stack.pop() + stack.pop())
elif d == '*':
stack.append(stack.pop() * stack.pop())
else:
stack.append(int(d))
print(stack[0]) | 0 | null | 84,871,050,324,480 | 293 | 18 |
n = int(input())
t = [0]*(n+1)
for i in range(1,n+1):
for j in range(i,n+1,i):
t[j] += j
print(sum(t))
| import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
mi = None
def _max(iterable):
ma = 0
for i in iterable:
ma = max(ma, i)
return ma
for i in range(2 ** (H - 1)):
# div[j] is true if row j and row j + 1 is divided
div = [(i & (1 << j)) > 0 for j in range(H - 1)]
group = [0] * H
for j in range(H - 1):
group[j + 1] = group[j] + 1 if div[j] else group[j]
count = Counter()
ans = div.count(True)
ok = True
for j in range(W):
tmp = Counter()
for k in range(H):
if S[k][j] == '1':
tmp[group[k]] += 1
if _max(tmp.values()) > K:
ok = False
elif _max((tmp + count).values()) <= K:
count += tmp
else:
count = tmp
ans += 1
if ok and (mi is None or ans < mi):
mi = ans
print(mi)
| 0 | null | 29,973,457,059,380 | 118 | 193 |
n = int(input())
for i in range(1,n+1):
ans = int(i*1.08)
if ans == n:
print(i)
break
else:
print(":(") | N = int(input())
X = N // 1.08
result1 = int(X) * 1.08
result2 = (int(X)+1) * 1.08
result3 = (int(X)-1) * 1.08
if int(result1) == N:
result = int(X)
elif int(result2) == N:
result = int(X) + 1
elif int(result3) == N:
result = int(X) -1
else:
result = ':('
print(result) | 1 | 125,809,910,773,162 | null | 265 | 265 |
import sys
def input(): return sys.stdin.readline().rstrip()
K = int(input())
A, B = map(int, input().split())
ans = False
count = K
while count <= B:
if A <= count and count <= B:
ans = True
count += K
if ans:
print('OK')
else:
print('NG') | # coding: utf-8
n = int(input().rstrip())
count = 0
for i in range(1,n//2+1):
m = n - i
if i != m:
count += 1
print(count) | 0 | null | 89,854,372,226,200 | 158 | 283 |
N = int(input())
A = list(map(int, input().split()))
i = 0
for i in range(len(A)):
if (A[i] % 2 == 0):
if A[i] % 3 != 0 and A[i] % 5 != 0:
print('DENIED')
exit()
else:
continue
else:
continue
print('APPROVED') | import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
a, v = MAP()
b, w = MAP()
t = INT()
if a == b:
YES()
exit()
if w >= v:
NO()
exit()
diff = v - w
dist = abs(a-b)
if diff*t >= dist:
YES()
else:
NO()
| 0 | null | 41,841,254,727,872 | 217 | 131 |
a, b = input().split()
print('Yes') if a==b else print('No') | #ライブラリの読み込み
import math
#入力値を格納
n,m = map(int,input().split())
#判定
if n == m:
text = "Yes"
else:
text = "No"
#結果を表示
print(text) | 1 | 83,556,784,961,692 | null | 231 | 231 |
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()
n = k()
if n%2==1:
print(0)
else:
for i in range(1,n):
if n>=2*(5**i):
cnt += n//(2*(5**i))
else:
break
print(cnt) | N=int(input())
if N%2:
print(0)
else:
X=0
Y=N//5
while Y:
X+=Y//2
Y//=5
print(X)
| 1 | 115,975,139,637,540 | null | 258 | 258 |
import itertools, collections
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
C = list(itertools.accumulate([0] + A))
D = [(v - i) % K for i, v in enumerate(C)]
#D[i]==D[j] and i-j<K
dp = collections.Counter(D[:K])
ans = 0
for i in range(N):
dp[D[i]] -= 1
ans += dp[D[i]]
if i + K < len(D):
dp[D[i + K]] += 1
print(ans)
| # --*-coding:utf-8-*--
MOD = 10**9 + 7
def getModInv(a, b):
return 1 if (a == 1) else (1-b*getModInv(b%a, a))//a%b
N, K = map(int, input().split())
t1, t2 = 1,1
s1, s2 = 1,1
for m in range(1, min(K, N-1)+1):
t1 = t1*(N-m)*(N-m+1)%MOD
t2 = t2*m**2%MOD
s1 = (s1*t2 + s2*t1)%MOD
s2 = s2*t2%MOD
print(s1*getModInv(s2, MOD)%MOD)
| 0 | null | 102,399,914,958,560 | 273 | 215 |
kotae = [1,2,3]
A = int(input())
B = int(input())
kotae.remove(A)
kotae.remove(B)
print(kotae[0]) | def main():
num = [int(input()) for i in range(2)]
print(6-num[0]-num[1])
main() | 1 | 110,251,634,397,350 | null | 254 | 254 |
if __name__ == '__main__':
W, H, x, y, r = map(int, raw_input().split())
ret = "Yes"
if W < x + r or x - r < 0 or H < y + r or y - r < 0:
ret = "No"
print ret | n = int(input())
s = input()
num = n
for i in range(n-1,0,-1):
if s[i]==s[i-1]:
s = s[:i] + s[i+1:]
print(len(s))
| 0 | null | 85,285,621,237,012 | 41 | 293 |
N = int(input())
if N%2 == 0:
print(0.5000000000)
else:
odd = N//2 + 1
print(odd/N) | n=int(input())
s=input().split("ABC")
print(len(s)-1) | 0 | null | 138,505,623,006,580 | 297 | 245 |
a=int(input())
if a<30:
print("No")
else:
print("Yes") | def main():
X = int(input())
if 30 <= X:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 1 | 5,758,206,351,168 | null | 95 | 95 |
def main():
import math
a, b, x = map(int, input().split())
if a * a * b >= x * 2:
c = x * 2 / (b * a)
print(math.degrees(math.atan(b / c)))
else:
d = 2 * (b - x / a / a)
print(math.degrees(math.atan(d / a)))
if __name__ == '__main__':
main()
| n=list(input())
N=len(n)
k=int(input())
dp1=[[0 for i in range(k+1)] for j in range(N+1)]
dp2=[[0 for i in range(k+1)] for j in range(N+1)]
dp1[0][0]=1
for i in range(1,N+1):
x=int(n[i-1])
if i!=N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j-1]
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*(x-1)+dp2[i-1][j]+dp2[i-1][j-1]*9
elif i!=N and x==0:
for j in range(k+1):
if j==0:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]+dp2[i-1][j-1]*9
elif i==N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*x+dp2[i-1][j]+dp2[i-1][j-1]*9
else:
for j in range(k+1):
if j==0:
dp2[i][j]=dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]+dp2[i-1][j-1]*9
print(dp2[N][k]) | 0 | null | 119,162,914,951,038 | 289 | 224 |
a, b = map(int, input().split())
d = int(a / b)
r = a % b
f = float(a / b)
print("{0} {1} {2:.6f}".format(d, r, f)) | a, b = map(int, input().split())
print('{} {} {:f}'.format(a//b, a%b, a/b))
| 1 | 589,502,908,060 | null | 45 | 45 |
import sys
n = int(input())
for i in range(n):
ns = [x * x for x in map(int, input().split())]
if ns[0] + ns[1] == ns[2] or ns[0] + ns[2] == ns[1] or ns[1] + ns[2] == ns[0]:
print("YES")
else:
print("NO") | input()
numbers = input().split()
numbers.reverse()
print(" ".join(numbers)) | 0 | null | 487,047,180,958 | 4 | 53 |
n = input()
data = []
space = []
for i in ['S ', 'H ', 'C ', 'D ']:
for j in map( str , xrange(1, 14)):
data.append(i + j)
for i in xrange(n):
data.remove(raw_input())
for i in xrange(len(data)):
print data[i] | pictures = ['S','H','C','D']
card_li = []
for i in range(4):
for j in range(1,14):
card_li.append(pictures[i] + ' ' + str(j))
n = int(input())
for i in range(n): del card_li[card_li.index(input())]
for i in card_li:
print(i) | 1 | 1,052,532,183,860 | null | 54 | 54 |
A = int(input())
B = int(input())
print(6//(A*B)) | import sys
rr = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(sys.stdin.readline())
s = rr()
k = ri()
cnt = 0
i = 0
if len(set(s)) == 1:
print(int(len(s)*k/2))
exit()
while i < len(s)-1:
if s[i] == s[i+1]:
cnt += 1
i += 1
i += 1
cnt1 = 0
i1 = 0
s *= 2
while i1 < len(s)-1:
if s[i1] == s[i1+1]:
cnt1 += 1
i1 += 1
i1 += 1
print((cnt1 - cnt)*(k-1) + cnt)
| 0 | null | 142,907,956,482,140 | 254 | 296 |
n = int(input())
s = input()
print(['No','Yes'][s[:n//2]==s[n//2:]]) | N = int(input())
S = input()
if S[:N//2] == S[N//2:]:
print("Yes")
else:
print("No") | 1 | 146,536,463,856,050 | null | 279 | 279 |
while True:
m,f,r = map(int, input().split())
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print("F")
continue
s = m + f
if s >= 80:
print("A")
elif s >= 65:
print("B")
elif s >= 50:
print("C")
elif s >=30:
if r >= 50:
print("C")
else:
print("D")
else:
print("F") | for m, f, r in ((int(j) for j in i.split()) for i in iter(input, "-1 -1 -1")):
if m == -1 or f == -1:
print ('F')
elif m + f >= 80:
print ('A')
elif m + f >= 65:
print ('B')
elif m + f >= 50 or (m + f >= 30 and r >= 50):
print ('C')
elif m + f >= 30:
print ('D')
else:
print ('F') | 1 | 1,240,430,552,192 | null | 57 | 57 |
n = int(input())
x = list(input())
sx = len(set(x))
if sx == 1:
print(0)
exit()
cnt_r = x.count("R")
cnt = 0
for i in range(cnt_r):
if x[i] == "W":
cnt += 1
print(cnt) |
from collections import defaultdict
N, X, Y = map(int, input().split())
ctr = defaultdict(int)
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = min(j - i, abs(i - X) + 1 + abs(j - Y))
ctr[d] += 1
for i in range(1, N):
print(ctr[i])
| 0 | null | 25,073,105,157,870 | 98 | 187 |
import sys
import bisect
input = sys.stdin.readline
class Bisect(object):
def bisect_max(self, reva, func,M):
ok = 0 # exist
ng = 2*(10**5)+1 # not exist
while abs(ok-ng) > 1:
cnt = (ok + ng) // 2
if func(cnt,reva,M):
ok = cnt
else:
ng = cnt
return ok
def solve1(tgt,reva,M):
res=0
n = len(reva)
if (n - bisect.bisect_left(reva,tgt-reva[n-1]))*n < M:
return False
for i in range(n):
res += n - bisect.bisect_left(reva,tgt-reva[n-i-1])
if M <= res:
return True
return False
N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
reva = a[::-1]
bs = Bisect()
Kmax = (bs.bisect_max(reva,solve1,M))
r=[0]
for i in range(N):
r.append(r[i]+a[i])
res = 0
cnt = 0
t = 0
for i in range(N):
tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1])
tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1])
if tmp!=tmp2:
t = 1
tmp = N - tmp
cnt += tmp
res += tmp*a[i]+r[tmp]
if t==1:
res -= (cnt-M)*Kmax
print(res)
| N, D = map(int, input().split())
x = []
y = []
for i in range(N):
coords = list(map(int, input().split()))
x.append(coords[0])
y.append(coords[1])
count = 0
for i in range(N):
if (x[i]**2 + y[i]**2) ** 0.5 <= D:
count += 1
print(count) | 0 | null | 57,177,336,252,400 | 252 | 96 |
a,b=map(int,input().split())
print("safe" if a>b else "unsafe") | s,w=list(map(int, input().split()))
a=''
if s<=w:
a='un'
print(a+'safe') | 1 | 29,109,288,463,368 | null | 163 | 163 |
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
mini = i
for j in range(i, N):
if A[j] < A[mini]:
mini = j
if i != mini:
A[i], A[mini] = A[mini], A[i]
count += 1
print(*A)
print(count) | a = list(map(int, input().split()))
n = 0
for i in range(5):
if a[n] == 0:
print(n+1)
break
else:
n += 1 | 0 | null | 6,787,917,566,478 | 15 | 126 |
n = int(input())
p = list(map(int, input().split()))
minp = 2*10**5
ans = 0
for i in range(n):
if minp >= p[i]:
minp = p[i]
ans += 1
print(ans) | n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n) :
if i == 0 :
mn = p[i]
count += 1
else :
if mn > p[i] :
mn = p[i]
count += 1
print(count)
| 1 | 85,808,867,283,328 | null | 233 | 233 |
import sys
input = sys.stdin.readline
from string import ascii_uppercase
letters = ascii_uppercase + ascii_uppercase
shift = int(input())
s = input()[:-1]
for char in s: print(letters[letters.index(char) + shift], end = '')
print() | import sys
input = sys.stdin.readline
def main():
S = int(input())
dp = [0]*(S+1)
dp[0] = 1
M = 10**9 + 7
for i in range(1, S+1):
for j in range(0,i-2):
dp[i] += dp[j]
dp[i] %= M
print(dp[S])
if __name__ == '__main__':
main() | 0 | null | 69,252,428,691,398 | 271 | 79 |
a, b = map(int, input().split())
if a >= 10 or b >= 10:
print(-1)
else:
print(a*b) | n = int(input())
ans = 0
for i in range(1, n+1):
if i*2 > n:
# 一気に足し上げて抜ける
ans += (i + n) * (n - i + 1) // 2
break
# n 以下の最大の i の倍数
last_term = n // i * i
num_term = (last_term - i) // i + 1
ans += (i + last_term) * num_term // 2
print(ans)
| 0 | null | 84,541,237,306,918 | 286 | 118 |
N = int(input())
List = [list(map(str, input().split())) for i in range(0,N)]
X = str(input())
yoroshiosu = 0
samu = 0
for i in range (0, N):
if X == List[i][0]:
yoroshiosu =1
elif yoroshiosu == 0:
continue
else:
samu+=int(List[i][1])
print(samu)
| import sys
def solve():
input = sys.stdin.readline
N = int(input())
P = [input().strip("\n").split() for _ in range(N)]
X = input().strip("\n")
sec = 0
lastId = 0
for i in range(N):
if P[i][0] == X:
lastId = i
break
for i in range(lastId + 1, N):
sec += int(P[i][1])
print(sec)
return 0
if __name__ == "__main__":
solve() | 1 | 96,763,768,941,560 | null | 243 | 243 |
x = input()
if x.endswith("s") == True:
x = x + "es"
else:
x = x + "s"
print(x) | N, K = map(int, input().split())
A = list(map(int, input().split()))
X = [0 for _ in range(N)]
D = {0: [-1]}
E = {0: 1}
X[0] = (A[0] - 1) % K
if X[0] in D:
D[X[0]].append(0)
E[X[0]] += 1
else:
D[X[0]] = [0]
E[X[0]] = 1
for i in range(1, N):
X[i] = (X[i-1] + A[i] - 1) % K
if X[i] in D:
D[X[i]].append(i)
E[X[i]] += 1
else:
D[X[i]] = [i]
E[X[i]] = 1
S = 0
for i in D:
n = E[i]
if n > 1:
L = D[i][:]
m = L[-1]
for j in range(n-1):
x = L[j]
if m - x < K:
S += n - 1 - j
else:
l, r = j, n
d = (l + r) // 2
tmp = 2 * n
while tmp != 0:
if L[d] - x <= K - 1:
l = d
d = (l + r) // 2
else:
r = d
d = (l + r) // 2
tmp //= 2
S += d - j
print(S) | 0 | null | 69,882,317,200,752 | 71 | 273 |
n,x,t = map(int,input().split())
print((-(-(n)//x) * t)) | a, b, c = map(int, input().split())
if a % b == 0:
print(a//b * c)
else:
print((a//b + 1) * c) | 1 | 4,290,478,135,290 | null | 86 | 86 |
import sys
read = sys.stdin.read
def main():
l = int(input())
print((l/3)**3)
if __name__ == '__main__':
main()
| import sys
def main():
orders = sys.stdin.readlines()[1:]
dna_set = set()
for order in orders:
command, dna = order.split(" ")
if command == "insert":
dna_set.add(dna)
elif command == "find":
if dna in dna_set:
print("yes")
else:
print("no")
if __name__ == "__main__":
main() | 0 | null | 23,693,865,283,520 | 191 | 23 |
input()
while True:
try:
lst = list(map(int,input().split()))
lst.sort()
if lst[2] ** 2 == lst[1] ** 2 + lst[0] ** 2:
print("YES")
else:
print("NO")
except EOFError:
break
| print "\n".join(s for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))])) | 1 | 247,876,512 | null | 4 | 4 |
from math import ceil
def enum_divisor(n):
res = []
for i in range(1, int(n ** 0.5) + 1):
if n % i != 0:
continue
res.append(i)
if i * i != n:
res.append(n // i)
return res
ans = 0
n = int(input())
for x in enum_divisor(n):
if x == 1:
continue
tmp = n
while tmp % x == 0:
tmp //= x
if tmp % x == 1:
ans += 1
ans += len(enum_divisor(n - 1)) - 1
print(ans) | def make_divisors(n):
divisors = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
def main():
n = int(input())
# 1回も割り算しない場合は n mod k = 1でkは(n-1)の約数
ans = len(make_divisors(n - 1)) - 1
# 割り算をする場合
l = make_divisors(n)[1:]
for i in l:
num = n
while num % i == 0:
num //= i
if num % i == 1:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 41,225,121,977,094 | null | 183 | 183 |
import sys
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
if p[i] == 0:
print(0)
sys.exit()
product = 1
for i in range(N):
product = product * p[i]
if product > 10 ** 18:
print(-1)
sys.exit()
break
print(product) | N = int(input())
Alist = list(map(int,input().split()))
Answer = 1
if 0 in Alist:
Answer = 0
for i in range(N):
Answer *= Alist[i]
if Answer > 10**18:
Answer = -1
break
print(Answer) | 1 | 16,079,461,687,562 | null | 134 | 134 |
A,B,C = map(int,input().split())
K = int(input())
for i in range(K):
if A >= B:
B = B*2
else:
C = C*2
print("Yes" if A < B and B < C else "No") | MOD = 10**9+7
def resolve():
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(input())
score = 0
hands = {
"r": ("p", P),
"s": ("r", R),
"p": ("s", S)
}
hist = []
for i, t in enumerate(T):
hand, point = hands[t]
if i >= K and hand == hist[-K]:
hist.append("*")
continue
score += point
hist.append(hand)
#print(hist)
print(score)
if '__main__' == __name__:
resolve() | 0 | null | 57,118,376,797,020 | 101 | 251 |
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
return sys.stdin.readline().rstrip()
def main():
def nibutan(ok,ng):
while abs(ok-ng) > 1:
mid = (ok + ng) // 2
if solve(mid,2):
ok = mid
else:
ng = mid
return ok
def solve(mid,n):
dif=(d_0+d_1)*(mid-1)
c=0
if dif*(dif+d_0) == 0:
c+=1
elif dif*(dif+d_0) < 0:
c+=1
if (dif+d_0)*(dif+d_0+d_1) < 0:
c+=1
if c==n:
return True
else:
return False
T=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
d_0=T[0]*(A[0]-B[0])
d_1=T[1]*(A[1]-B[1])
if d_0==-d_1:
print('infinity')
elif d_0*(d_0+d_1)<0:
if (d_0*2+d_1)*(d_0*2+d_1*2)<0:
n=nibutan(2,10**40)
ans=n*2-1
ans+=solve(n+1,1)
print(ans)
else:
print(1)
else:
print(0)
if __name__ == '__main__':
main()
| T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
P *= -1
Q *= -1
if P + Q < 0:
print(0)
elif P + Q == 0:
print("infinity")
else:
S = (-P) // (P + Q)
T = (-P) % (P + Q)
if T != 0:
print(S * 2 + 1)
else:
print(S * 2)
| 1 | 131,751,367,425,982 | null | 269 | 269 |
import sys
#input = sys.stdin.buffer.readline
def main():
S = input()
print(S[:3])
if __name__ == "__main__":
main() | n = int(input())
l = (input().split())
out=""
for i in reversed(l): out+=i+" "
print(out.strip()) | 0 | null | 7,857,617,664,260 | 130 | 53 |
x = int(input())
money = 100
cnt = 0
while x > money:
money += money//100
cnt += 1
print(cnt)
| X = int(input())
m = 100
y = 0
while m < X :
m = m*101//100
y += 1
print(y) | 1 | 27,146,777,153,536 | null | 159 | 159 |
k=int(input())
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
ans=0
for i in range(1,k+1):
for j in range(1,k+1):
for l in range(1,k+1):
ans+=gcd(gcd(i,j),l)
print(ans) | import math
K = int(input())
Sum = 0
for A in range(1,K+1):
for B in range(1,K+1):
AB = math.gcd(A,B)
if AB==1:
Sum = Sum+K
else:
for C in range(1,K+1):
Sum = Sum+math.gcd(AB,C)
print(Sum) | 1 | 35,436,689,048,640 | null | 174 | 174 |
A, B, C = map(int, input().split())
temp = B
B = A
A = temp
temp = C
C = A
A = temp
print(str(A) + " " + str(B) + " " + str(C)) | N,X,M = map(int,input().split())
S = X
A = [X]
exists = [0]*M
exists[X] = 1
for i in range(2,N+1):
A_i = (A[-1]*A[-1])%M
A.append(A_i)
S += A_i
if exists[A_i] == 0:
exists[A_i] = 1
else:
S -= A_i
del A[-1]
B = A[A.index(A_i):]
S += ((N-len(A))//len(B))*sum(B) + sum(B[:((N-len(A))%len(B))])
break
print(S) | 0 | null | 20,318,967,688,268 | 178 | 75 |
#(a,b) = input().rstrip().split(' ')
#a = int(a)
#b = int(b)
#以下でも代替可
(a,b) = [int(x) for x in input().rstrip().split(' ')]
if a < b:
print("a < b")
elif a > b:
print("a > b")
else:
print("a == b") | a,b=[int(x) for x in input().split()]
if a < b :
print('a < b')
elif a > b :
print('a > b')
else:
print('a == b')
| 1 | 359,842,252,370 | null | 38 | 38 |
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
N = 10 ** 6 # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
X, Y = map(int, input().split())
if (2*Y-X)%3 == 0:
if (2*X-Y)%3 == 0:
a = (2*Y-X)//3
b = (2*X-Y)//3
else:
print(0)
exit()
else:
print(0)
exit()
print(cmb(a+b, a, p))
| def main():
n = int(input())
d_lst = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
for j in range(i + 1, n):
ans += d_lst[i] * d_lst[j]
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 158,838,358,609,798 | 281 | 292 |
mount=[]
for i in range(10):
tmp=int(input())
mount.append(tmp)
mount.sort()
mount.reverse()
for i in range(3):
print(mount[i]) | print("\n".join(map(str,sorted([int(input())for _ in[0]*10])[:-4:-1]))) | 1 | 19,908,248 | null | 2 | 2 |
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[list(map(int,input().split())) for _ in range(m)]
ans=min(a)+min(b)
for x,y,c in l:
ans=min(ans,a[x-1]+b[y-1]-c)
print(ans) | import sys
readline = sys.stdin.readline
def main():
A, B, M = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
ans = min(a) + min(b)
for _ in range(M):
x, y, c = map(int, readline().split())
ans = min(ans, a[x-1] + b[y-1] - c)
print(ans)
if __name__ == "__main__":
main()
| 1 | 53,671,270,104,452 | null | 200 | 200 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
A, B = map(int, readline().split())
if (A <= 9) & (B <= 9):
print(A * B)
else:
print(-1)
if __name__ == '__main__':
main()
| num = input()
num1,num2 = num.split(' ')
num1 = int(num1)
num2 = int(num2)
if num1 > 9 or num2 > 9:
print('-1')
else:
print (num1 * num2) | 1 | 157,874,053,279,722 | null | 286 | 286 |
N, K, *A = map(int, open(0).read().split())
for a, b in zip(A[K:], A):
if a > b:
print("Yes")
else:
print("No") | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def solve(N, K, AS):
for i in range(K, N):
# debug("i: i,AS[i-K],AS[K]", i, AS[i-K], AS[K])
if AS[i - K] < AS[i]:
print("Yes")
else:
print("No")
def main():
# parse input
N, K = map(int, input().split())
AS = list(map(int, input().split()))
solve(N, K, AS)
# tests
T1 = """
5 3
96 98 95 100 20
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
Yes
No
"""
T3 = """
15 7
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
Yes
Yes
No
Yes
Yes
No
Yes
Yes
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
main()
| 1 | 7,091,765,480,202 | null | 102 | 102 |
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype = np.int64)
F = np.array(list(map(int, input().split())), dtype = np.int64)
A.sort()
F.sort()
F = F[::-1]
l = 0
r = 10**12 + 100
def solve(num):
B = num // F
tmp = np.sum(np.maximum(0, A - B))
if tmp <= K:
return 1
else:
return 0
while r - l > 1:
mid = (l + r) // 2
if solve(mid):
r = mid
else:
l = mid
if solve(l):
print(l)
else:
print(r)
| a = input()
b = input()
c = ['1', '2', '3']
for i in c:
if i != a and i != b:
print(i) | 0 | null | 137,605,553,834,080 | 290 | 254 |
# D - Alter Altar
N = int(input())
c = input()
white_l = 0
red_r = 0
for i in range(N):
if c[i]=='R':
red_r += 1
ans = red_r
for i in range(N):
if c[i]=='W':
white_l += 1
else:
red_r -= 1
ans = min(ans, max(red_r,white_l))
print(ans) | n = int(input())
d = []
for i in range(n):
d.append(list(map(int,input().split())))
cnt = 0
flag = 0
for i in range(n):
if d[i][0] == d[i][1]:
cnt = cnt + 1
else:
cnt = 0
if cnt == 3:
flag = 1
if flag == 1:
print("Yes")
else:
print("No")
| 0 | null | 4,388,158,235,278 | 98 | 72 |
n, m = map(int, input().split())
S = input()
ans = []
x = len(S) - 1
while x:
for step in range(m, 0, -1):
if x - step < 0:
continue
to = S[x-step]
if to == '1':
continue
else:
x -= step
ans.append(str(step))
break
else:
print(-1)
exit()
print(' '.join(ans[::-1])) | N, M = map(int, input().split())
S = input()
p = N
prev = N
flag = True
ans = []
for i in range(N, -1, -1):
if (prev - i) > M:
ans.append(prev - p)
prev = p
if (prev - i) > M:
flag = False
break
if S[i] == "0":
p = i
ans.append(prev)
if flag:
print(" ".join(map(str, ans[::-1])))
else:
print(-1)
| 1 | 138,817,624,303,030 | null | 274 | 274 |
# F - Bracket Sequencing
import sys
readline = sys.stdin.readline
N = int(input())
L = []
R = []
for _ in range(N):
S = readline().strip()
sums = 0
mins = 0
for s in S:
if s == '(':
sums += 1
else:
sums -= 1
mins = min(mins, sums)
if sums >= 0:
L.append((sums, mins))
else:
R.append((-sums, mins-sums))
L.sort(key=lambda x: x[1], reverse=True)
R.sort(key=lambda x: x[1], reverse=True)
ans = 'Yes'
l_now = 0
for d, min_d in L:
if l_now + min_d < 0:
ans = 'No'
break
else:
l_now += d
r_now = 0
for d, min_d in R:
if r_now + min_d < 0:
ans = 'No'
break
else:
r_now += d
if l_now != r_now:
ans = 'No'
print(ans) | N = int(input())
s = []
for i in range(N):
s.append(input())
inc = []
dec = []
total = 0
for i in s:
cn = 0
mn = 0
for j in i:
if j=="(":
cn+=1
else:
cn-=1
mn = min(cn,mn)
total += cn
if cn>=0:
inc.append([mn,cn])
else:
dec.append([mn-cn,-cn])
inc.sort(reverse=True,key=lambda x:x[0])
dec.sort(reverse=True,key=lambda x:x[0])
def check(lis):
hi = 0
for i in lis:
if hi+i[0]<0:
return False
else:
hi+=i[1]
return True
if check(inc) and check(dec) and total==0:
print("Yes")
else:
print("No")
| 1 | 23,662,917,553,110 | null | 152 | 152 |
x1, y1, x2, y2 = map(float,input().split())
print(f'{((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5:8f}')
| n = 6
a = int(input())
b = int(input())
print(n - a - b) | 0 | null | 55,673,987,087,230 | 29 | 254 |
n,m=map(int,input().split())
s=input()
res=[]
now=n
while now!=0:
j=False
for i in range(max(0,now-m),now):
if s[i]=="0":
j=True
res.append(now-i)
now=i
break
if not j:
print(-1)
exit()
for i in range(len(res)-1,-1,-1):
print(res[i],end=" ") | from fractions import gcd
from functools import reduce
import numpy as np
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm(numbers):
return reduce(lcm_base, numbers, 1)
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x // 2 , A))
A = np.array(A)
l = lcm(A)
if ((l//A % 2 == 1).sum() != N):
print(0)
else:
ans = (M//l + 1) // 2
print(ans) | 0 | null | 119,916,843,511,332 | 274 | 247 |
L = int(input())
a = L / 3
b = L / 3
c = L - a - b
print(a * b * c) | n=int(input())
print((n/3)*(n/3)*(n/3)) | 1 | 46,765,246,096,372 | null | 191 | 191 |
n,m = map(int,input().split())
ans = 0
class UnionFind:
def __init__(self,n):
self.root = [i for i in range(n+1)]
def Root_Find(self,x):
if self.root[x] == x:
return x
else:
self.root[x] = self.Root_Find(self.root[x])
return self.root[x]
def Unite(self,x,y):
x = self.Root_Find(x)
y = self.Root_Find(y)
if x == y:
return
self.root[y] = x
tree = UnionFind(n)
for i in range(m):
a,b = map(int,input().split())
tree.Unite(a,b)
for i in range(n+1):
tree.Root_Find(i)
ans = len(list(set(tree.root))) - 2
print(ans) | import copy
from collections import deque
n, st, sa = map(int,input().split())
st -= 1
sa -= 1
e = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
e[a].append(b)
e[b].append(a)
visited = [False] * n
visited[st] = True
d = deque()
d.append([st, 0])
tx = {}
if len(e[st]) == 1:
tx[st] = 0
cnt = 0
while d:
f, cnt = d.popleft()
flg = True
for t in e[f]:
if not visited[t]:
flg = False
d.append([t, cnt+1])
visited[t] = True
if flg:
tx[f] = cnt
visited = [False] * n
visited[sa] = True
d = deque()
d.append([sa, 0])
ax = {}
if len(e[sa]) == 1:
ax[sa] = 0
cnt = 0
while d:
f, cnt = d.popleft()
flg = True
for t in e[f]:
if not visited[t]:
flg = False
d.append([t, cnt+1])
visited[t] = True
if flg:
ax[f] = cnt
ax = sorted(ax.items(), key=lambda x:x[1], reverse=True)
for i in range(len(ax)):
x, d = ax[i][0], ax[i][1]
if d > tx[x]:
ans = d - 1
break
print(ans) | 0 | null | 59,687,854,610,932 | 70 | 259 |
import math
while True:
n=int(input())
if n==0:break
else:
s = list(map(int, input().split())) #入力の値が横並びの時使う
x=sum(s)
y=x/n
a=0
for i in range(n):
z=(s[i]-y)**2
a+=z
b=math.sqrt(a/n)
print(format(b, '.8f'))
| from math import sqrt
while True:
n = int(input())
if n == 0:
break
scores = list(map(int,input().split()))
m = sum(scores)/len(scores)
print(sqrt(sum((sc -m)**2 for sc in scores)/len(scores))) | 1 | 194,795,180,688 | null | 31 | 31 |
N,K = map(int,input().split())
P = list(map(int,input().split()))
# 累積和
s = [0] * (N+1)
for i in range(N):# O(N)
s[i+1] = s[i] + P[i]
# [j,j+K) の和の最大値と j を保持
m = 0
midx = 0
for j in range(N-K+1):# O(N)
v = s[j+K] - s[j]
if v > m:
m = v
midx = j
E = 0
for k in range(midx,midx+K):# O(K)
x = P[k]
E += (1/x)*(x*(x+1)/2)
print(E) | n = int(input())
print((n//2)/n if n%2==0 else (n//2+1)/n) | 0 | null | 125,947,859,008,990 | 223 | 297 |
N = int(input())
S = input()
if N % 2 != 0:
print("No")
exit()
x = int(len(S) / 2)
y = S[0:x]
z = S[x:len(S)]
if y == z:
print("Yes")
else:
print("No") | import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))
s = 100
min_i = -1
if x not in p:
print(x)
sys.exit()
for i in range(-1,102):
if i not in p and abs(i-x) < s:
s = abs(i-x)
min_i = i
print(min_i)
| 0 | null | 80,430,523,002,180 | 279 | 128 |
import re
def bubble_sort(C, N):
for i in range(N):
for j in reversed(range(1, N)):
if C[j][1] < C[j-1][1]:
# 1???????????????????°????????????°??????
C[j], C[j-1] = C[j-1], C[j]
return C
def selection_sort(C, N):
for i in range(N):
# i ?????????????????¨????????????
minj = i
for j in range(i, N):
# ?????????????????¨??????????°???????????????????
if C[j][1] < C[minj][1]:
minj = j
# ??????????????¨??????????°????????????????????????\????????????
C[i], C[minj] = C[minj], C[i]
return C
def is_stable(C, sorted):
# ????????°???????????????????¨???????????????????????´???????????????????
c_container = []
s_container = []
for i in range(len(C)):
# C ??§ i ????????\?????????????????§????????°????????????????????¢???
for j in range(len(C)):
# ????????°???????????????????????£?????´???
if C[i][1] == C[j][1]:
# C ????????????????¨?????????????
c_container.append(C[j][0])
# ????????°???????????????????????¨????????´???
if len(c_container) >= 2:
# C ??§ i ???????????????????????°?????¨????????°????????????????????¢???
for k in range(len(sorted)):
# ????±??????????????????°?????¨????????°???????¨?????????????????????????????????????????????????????´?
if sorted[k][1] == C[i][1]:
s_container.append(sorted[k][0])
# ??????????????´?????????????????£?????´???
if c_container != s_container:
# Not Stable
return False
# ?????????????????????
c_container = []
s_container = []
return True
if __name__ == '__main__':
N = int(input())
# ??????????????????????????????????????¨?????¨??°?????¨?????????????????????????´?
cards = input().split()
C = [[] for i in range(N)]
for i in range(N):
# ??????????¨??????¨??°????????????
symbol_and_num = re.findall(r'(\d+|\D+)', cards[i])
C[i] = [symbol_and_num[0], int(symbol_and_num[1])]
# ??????????????????????????????
bubble_sorted = bubble_sort(C.copy(), N)
# ?¨??????¨???????????????
bubble_sorted_cards = [val[0] + str(val[1]) for val in bubble_sorted]
# ?????????????????????
print(' '.join(bubble_sorted_cards))
# stable or not stable
print('Stable' if is_stable(C, bubble_sorted) else 'Not stable')
# ?????????????????????
selection_sorted = selection_sort(C.copy(), N)
# ?¨??????¨???????????????
selection_sorted_cards = [val[0] + str(val[1]) for val in selection_sorted]
# ?????????????????????
print(' '.join(selection_sorted_cards))
# stable or not stable
print('Stable' if is_stable(C, selection_sorted) else 'Not stable') | # coding: utf-8
# Stable Sort 2018/3/12
class Card(object):
def __init__(self, card):
self.value = int(card[1])
self.card = card
def __repr__(self):
return self.card
def BubbleSort(C, N):
for i in range(N):
for j in reversed(range(i+1, N)):
if C[j].value < C[j-1].value:
C[j], C[j-1] = C[j-1], C[j]
return C
def SelectionSort(C, N):
for i in range(N):
minj = i
for j in range(i, N):
if C[j].value < C[minj].value:
minj = j
C[i], C[minj] = C[minj], C[i]
return C
def isStable(inl, out):
n = len(inl)
for i in range(n):
for j in range(i+1, n):
for a in range(n):
for b in range(a+1, n):
if inl[i].value == inl[j].value and inl[i] == out[b] and inl[j] == out[a]:
return False
return True
def print_stable(inl, out):
if isStable(inl, out):
print "Stable"
else:
print "Not stable"
if __name__ == "__main__":
N = int(raw_input())
inputs = raw_input().split()
C = []
for i in inputs:
C.append(Card(i))
Cb = BubbleSort(list(C), N)
print " ".join([i.card for i in Cb])
print_stable(C, Cb)
Cs = SelectionSort(list(C), N)
print " ".join([i.card for i in Cs])
print_stable(C, Cs)
| 1 | 24,340,768,578 | null | 16 | 16 |
S = int(input())
if S < 3:
print(0)
import sys
sys.exit()
DP = [0]*(S+1)
DP[0] = 0
DP[1] = 0
DP[2] = 0
for i in range(3, S + 1):
DP[i] += 1
for j in range(i - 3 + 1):
DP[i] += DP[j]
print(DP[S] % (10 ** 9 + 7))
| s = int(input())
a = [None, 0, 0] + [1] * (s - 2)
for i in range(3, s - 2):
a[i + 3] += a[i]
a[i + 1] += a[i]
print(a[s] % (10**9 + 7))
| 1 | 3,259,879,301,548 | null | 79 | 79 |
def insertionSort(A,n,g,cnt):
for i in range(g,n):
v = A[i]
j = i-g
while (j>=0)*(A[j]>v):
A[j+g]=A[j]
j = j-g
cnt[0] += 1
A[j+g] = v
A =[]
N = int(input())
for i in range(N):
A.append(int(input()))
cnt = [0]
import math
m = math.floor(math.log(N,2))+1
G = [math.ceil(N/2)]
for i in range(1,m-1):
G.append(math.ceil(G[i-1]/2))
G.append(N-sum(G))
if G[len(G)-1] != 1:
G[len(G)-1] = 1
for k in range(m):
insertionSort(A,N,G[k],cnt)
print(m)
for i in range(m):
print(f"{G[i]}",end=" ")
print(f"\n{cnt[0]}")
for i in range(N):
print(f"{A[i]}")
| A, B, C = map(int, input().split())
A, B = B, A
A, C = C, A
print(A,B,C) | 0 | null | 19,124,183,867,580 | 17 | 178 |
import sys
N, M = map(int, input().split())
A = [-1] * N
for i in range(M):
s, c = map(int, input().split())
if A[s-1] != c and A[s-1] != -1:
print(-1)
sys.exit()
else:
A[s-1] = c
if N >= 2 and A[0] == 0:
print(-1)
sys.exit()
res = 0
for i in range(N):
if A[i] == -1:
if i == 0 and N >= 2:
A[i] = 1
else:
A[i] = 0
res += A[i] * 10 ** (N-i-1)
print(res) | R = int(input())
print(R * 6.28318530717958623200) | 0 | null | 46,326,200,047,334 | 208 | 167 |
import sys
input = sys.stdin.readline
def p_count(n):
return bin(n)[2:].count('1')
n = int(input())
x = input().rstrip()
x_dec = int(x,base = 2)
pop_cnt = x.count('1')
pop_cnt_0 = (pop_cnt + 1)
pop_cnt_1 = (pop_cnt - 1)
x_0 = pow(x_dec,1,pop_cnt_0)
x_1 = pow(x_dec,1,pop_cnt_1) if pop_cnt_1 > 0 else 0
x_bit = [0]*n
for i in range(n-1,-1,-1):
if x[i] == '0':
x_bit[i] = (x_0 + pow(2,n-1-i,pop_cnt_0))%pop_cnt_0
#x_bit[i] = (x_dec + pow(2,n-1-i))%pop_cnt_0
else:
if pop_cnt_1 > 0:
x_bit[i] = (x_1 - pow(2,n-1-i,pop_cnt_1))
x_bit[i] = x_bit[i] if x_bit[i] >= 0 else x_bit[i] + pop_cnt_1
else:
x_bit[i] = -1
anslist = []
for i in range(n):
if x_bit[i] == -1:
anslist.append(0)
continue
ans = 1
now = x_bit[i]
while True:
if now == 0:
break
now = now%p_count(now)
ans += 1
anslist.append(ans)
for ans in anslist:
print(ans)
| n = int(input())
x = input()
popcnt = x.count("1")
def powmod(lst,mod):
if not mod: return
d = 1
for i in range(n)[::-1]:
d %= mod
lst[i] = d
d *= 2
def xmod(mod):
if not mod: return
res = 0
d = 1
for i in range(n)[::-1]:
d %= mod
if int(x[i]):
res += d
res %= mod
d *= 2
return res
def solve(x):
res = 1
while x != 0:
popcnt = 0
for i in range(20):
if x>>i & 1: popcnt += 1
x %= popcnt
res += 1
return res
powlst0 = [0]*n
powlst1 = [0]*n
powmod(powlst0,popcnt+1)
x0 = xmod(popcnt+1)
powmod(powlst1,popcnt-1)
x1 = xmod(popcnt-1)
for i in range(n):
if int(x[i]):
if popcnt == 1: print(0)
else: print(solve((x1-powlst1[i])%(popcnt-1)))
else: print(solve((x0+powlst0[i])%(popcnt+1))) | 1 | 8,125,368,419,392 | null | 107 | 107 |
def main():
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
Q=int(input())
d=[0]*(10**5 +1)#各数字の個数
for i in A:
d[i]+=1
for i in range(Q):
B,C=map(int,input().split())
s += (C-B)*d[B]
print(s)
d[C]+=d[B]
d[B]=0
if __name__ == "__main__":
main() | n=int(input())
a=list(map(int,input().split()))
q=int(input())
b,c=[],[]
for _ in range(q):
bi,ci=map(int,input().split())
b.append(bi)
c.append(ci)
number=[0 for i in range(10**5+1)]
for i in range(n):
number[a[i]]+=1
s=sum(a)
for i in range(q):
s+=(c[i]-b[i])*number[b[i]]
number[c[i]]+=number[b[i]]
number[b[i]]=0
print(s) | 1 | 12,151,050,013,222 | null | 122 | 122 |
import math
n = input()
p = 0
money = 100
while p != n:
money = math.ceil(money * 1.05)
p += 1
print int(money * 1000) | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from itertools import accumulate
INF = float("inf")
def bit(n, k):
return (n >> k) & 1
def bit_sum(n):
wa = 0
while n > 0:
wa += n & 1
n >>= 1
return wa
def border(x):
# xを二進数で与えた時、ビットの立っている位置のリストを1-indexで返す
c = 0
ans = []
while x > 0:
c += 1
if x & 1:
ans.append(c)
x >>= 1
return ans
def main():
H, W, K = map(int, input().split())
S = [[0]*W for _ in range(H)]
for h in range(H):
S[h][:] = [int(c) for c in input()]
acc = [[0]+list(accumulate(S[h])) for h in range(H)]
min_kaisu = +INF
for h in range(1 << (H-1)):
# hは分割方法を与える
# hで与えられる分割方法は、どのような分割なのかを得る。
startend = border(h)
flag = False
division = [0]
# x番目でW方向に分割すると仮定する
for x in range(1, W+1):
# xの位置で分割したとき、左の領域のホワイトチョコレートの数
# まずは行ごとに求める
white = [acc[i][x] - acc[i][division[-1]] for i in range(H)]
# 領域ごとに加算するし、最大値を撮る
white_sum = [sum(white[s:e])
for s, e in zip([0]+startend, startend+[H])]
# print(bin(h), division, x, white_sum)
white_max = max(white_sum)
# Kよりも大きくなるなら、事前に分割するべきであった。
if white_max > K:
division.append(x-1)
# 分割してもなおK以下を達成できないケースを除外する
white = [acc[i][x] - acc[i][division[-1]] for i in range(H)]
white_sum = [sum(white[s:e])
for s, e in zip([0]+startend, startend+[H])]
white_max = max(white_sum)
if white_max > K:
flag = True
break
if flag:
continue
# hによる分割も考慮する
division_tot = len(division)-1 + bit_sum(h)
min_kaisu = min(division_tot, min_kaisu)
print(min_kaisu)
return
if __name__ == '__main__':
main()
| 0 | null | 24,198,269,952,358 | 6 | 193 |
import math
a, b, C = [int(x) for x in input().split()]
C = math.radians(C)
l = a + b + math.sqrt(a * a + b * b - 2 * a * b * math.cos(C))
h = b * math.sin(C)
s = a * h / 2
print(s)
print(l)
print(h) | import math
a, b, C = map(int, input().split())
C = math.radians(C)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))
S = a * b * math.sin(C) / 2
print(f"{S:0.9f}")
print(f"{a+b+c:0.9f}")
print(f"{S*2/a:0.9f}")
| 1 | 177,625,717,346 | null | 30 | 30 |
n = int(input())
s = []
for i in range(n):
x, y = map(int, input().split())
s.append([x + y, x - y])
t = sorted(s)
u = sorted(s, key=lambda x: x[1])
res = 0
tmp1 = t[-1][0] - t[0][0]
tmp2 = u[-1][1] - u[0][1]
print(max(tmp1, tmp2))
| N = int(input())
A = list(map(int,input().split()))
m = max(A) + 1
cnt = [0]*m
for i in A:
cnt[i] += 1
ans = 0
for i in range(1,m):
if cnt[i]:
if cnt[i]==1:
ans += 1
for j in range(i,m,i):
cnt[j] = 0
print(ans) | 0 | null | 8,887,845,351,490 | 80 | 129 |
#!/usr/bin/env python3
import sys
import itertools
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
l = [i + 1 for i in range(N)]
p = itertools.permutations(l, N)
q = itertools.permutations(l, N)
c = 1
d = 1
a = 0
b = 0
for i in p:
x = 0
for j in range(N):
if i[j] == P[j]:
x += 1
else:
break
if x == N:
a = c
break
c += 1
for i in q:
x = 0
for j in range(N):
if i[j] == Q[j]:
x += 1
else:
break
if x == N:
b = d
break
d += 1
ans = abs(a - b)
print(ans)
if __name__ == '__main__':
main()
| n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
# l[i] = (a[j] >= i を満たすjの個数)
l = [n for i in range(a[0]+1)]
for i in range(2, n+1):
for j in range(a[-i], a[-i+1], -1):
l[j] = n - i + 1
# 二分探索
# a[i] + a[j] >= x を満たす(i, j)がm組以上存在する最小のxを求める
start = 2 * a[-1]
stop = 2 * a[0]
while start < stop:
i = (start + stop + 1) // 2
num = 0
for j in a:
if i - j < 0:
num += n
elif i - j <= a[0]:
num += l[i - j]
else:
break
if num >= m:
start = i
else:
stop = i - 1
num = 0
for i in a:
if start - i < 0:
num += n
elif 0 <= start - i <= a[0]:
num += l[start - i]
else:
break
# start <= a[i]+a[j] を満たす a[i]+a[j] を全て足す
ans = 0
for i in a:
if start - i < 0:
ans += 2 * i * n
elif start - i <= a[0]:
ans += 2 * i * l[start - i]
else:
break
ans -= (num - m) * start
print(ans) | 0 | null | 104,559,993,248,700 | 246 | 252 |
A, B = list(map(int, input().split()))
if B * 2 < A:
ans = A - B * 2
else:
ans = 0
print(ans) | def main():
A, B, C = (int(x) for x in input().split())
K = int(input())
while not A < B < C and K > 0:
if A >= B: B *= 2
else: C *= 2
K -= 1
# print(A, B, C, K)
if A < B < C: print('Yes')
else: print('No')
if __name__ == '__main__':
main() | 0 | null | 86,956,154,375,012 | 291 | 101 |
N = int(raw_input())
A = map(int, raw_input().split())
counter = 0
while True:
ischanged = False
for i in xrange(1, N):
if A[N-i] < A[N-i-1]:
tmp = A[N-i]
A[N-i] = A[N-i-1]
A[N-i-1] = tmp
counter += 1
ischanged = True
if ischanged == False:
break
print " ".join(map(str, A))
print counter | import sys
n, k = map(int, input().split())
mod = 998244353
dp = [0] * (n+1)
dp[1] = 1
r = [tuple(map(int, input().split())) for _ in range(k)]
s = [0 for _ in range(k)]
for i in range(2, n + 1):
sums = 0
for j in range(k):
s[j] += dp[max(0, i - r[j][0])] - dp[max(0, i - r[j][1] - 1)]
s[j] %= mod
sums = (sums + s[j]) % mod
dp[i] = sums
print(dp[n])
| 0 | null | 1,344,077,662,628 | 14 | 74 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = n - sum(a)
print(-1 if ans < 0 else ans) | import sys
S = input()
N = int(input())
for i in range(N):
a = sys.stdin.readline().split()
if a[0] == "replace":
S = S[:int(a[1])] + a[3] + S[int(a[2])+1:]
elif a[0] == "reverse":
X = S[int(a[1]):int(a[2])+1]
X = X[::-1]
S = S[:int(a[1])] + X +S[int(a[2])+1:]
elif a[0] == "print":
print(S[int(a[1]):int(a[2])+1])
| 0 | null | 17,110,401,951,852 | 168 | 68 |
D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))
T = list(int(input()) for i in range(D))
manzoku = 0
yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
#1日目
for day in range(D):
yasumi = list(map(lambda x: x + 1, yasumi))
yasumi[T[day] - 1] = 0
manzoku += S[day][T[day] - 1]
for i in range(26):
manzoku -= C[i] * yasumi[i]
print(manzoku) | import sys
def input():
return sys.stdin.readline().rstrip()
def main():
N = list(map(int,input()))
count = 0
S = len(N)
flag = 0
for i in range(S):
temp = flag + N[-1 - i]
if temp > 5:
count += 10 - temp
flag = 1
elif temp ==5 and i !=S-1 and N[-1-i-1]>=5:
count+=temp
flag=1
else:
count += temp
flag = 0
print(count + flag)
if __name__ == "__main__":
main()
| 0 | null | 40,593,905,419,270 | 114 | 219 |
x = input()
for i in xrange(x):
inp = map(int ,raw_input().split())
inp.sort()
if inp[2]**2 == inp[0]**2 + inp[1]**2:
print "YES"
else:
print "NO" | N = int(input())
A = sorted([(int(a), i) for i, a in enumerate(input().split())], key = lambda x: x[0])[::-1]
X = [0] + [-1<<100] * (N + 5)
for k, (a, i) in enumerate(A):
X = [max(X[j] + abs(N - (k - j) - 1 - i) * a, X[j-1] + abs(j - 1- i) * a if j else 0) for j in range(N + 5)]
print(max(X)) | 0 | null | 16,966,840,259,404 | 4 | 171 |
def main():
N, S = map(int, input().split())
A = tuple(map(int, input().split()))
MOD = 998244353
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
# morau
for i, a in enumerate(A):
for j in range(S+1):
if j >= a:
dp[i+1][j] = 2 * dp[i][j]
dp[i+1][j] %= MOD
dp[i+1][j] += dp[i][j-a]
dp[i+1][j] %= MOD
else:
dp[i+1][j] = 2 * dp[i][j]
dp[i+1][j] %= MOD
print(dp[N][S])
if __name__ == "__main__":
main() | n,m = map(int,input().split())
li = list(map(int,input().split()))
sum_vote = sum(li)
kijun = sum_vote / (4 * m)
sum_above = len([i for i in li if i >= kijun])
if sum_above >= m:
print("Yes")
else:
print("No")
| 0 | null | 28,012,140,853,488 | 138 | 179 |
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [ int(s) for s in input().split(" ")]
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
return [ int(input()) for _ in range(n)]
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
return map(int, open(0).read().split())
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
n = int(input())
A = get_nums_l()
# スキップできる回数
p = 1 if n%2==0 else 2
# log(p)
# dp[i][j][k] i==1なら次取れる スキップ回数をj回残してk個目まで見たときの最大和
dp = [ [ [0]*(n+1) for _ in range(p+1) ] for _ in range(2) ]
dp[0][0][0] = -999999999999999999
dp[0][1][0] = -999999999999999999
dp[1][0][0] = -999999999999999999
if p == 2:
dp[0][2][0] = -999999999999999999
dp[1][1][0] = -999999999999999999
# log(dp)
for k in range(n):
dp[0][0][k+1] = dp[1][0][k] + A[k]
dp[0][1][k+1] = dp[1][1][k] + A[k]
dp[1][0][k+1] = max(dp[1][1][k], dp[0][0][k])
dp[1][1][k+1] = dp[0][1][k]
if p == 2:
dp[0][2][k+1] = dp[1][2][k] + A[k]
dp[1][2][k+1] = dp[0][2][k]
#dp[1][0][k+1] = max(dp[1][0][k+1], dp[1][1][k])
dp[1][1][k+1] = max(dp[1][1][k+1], dp[1][2][k])
# for a in dp:
# for b in a:
# log(b)
ans = [dp[0][0][n], dp[0][1][n], dp[1][0][n], dp[1][1][n]]
if p == 2:
# ans.append(dp[0][2][n])
ans.append(dp[1][2][n])
print(max(ans))
| #!/usr/bin/env python3
# coding: utf-8
import collections
import math
def debug(arg):
if __debug__:
pass
else:
import sys
print(arg, file=sys.stderr)
def main():
pass
N, *A = map(int, open(0).read().split())
a = dict(enumerate(A, 1))
dp = collections.defaultdict(lambda: -float("inf"))
dp[0, 0] = 0
dp[1, 0] = 0
dp[1, 1] = a[1]
for i in range(2, N + 1):
jj = range(max(math.floor(i // 2 - 1), 1), math.ceil((i + 1) // 2) + 1)
for j in jj:
x = dp[i - 2, j - 1] + a[i]
y = dp[i - 1, j]
dp[i, j] = max(x, y)
print(dp[N, N // 2])
if __name__ == "__main__":
main() | 1 | 37,373,321,639,862 | null | 177 | 177 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.