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
|
---|---|---|---|---|---|---|
n,t=map(int,input().split())
ab=[[0]*2 for i in range(n+1)]
for i in range(1,n+1):
ab[i][0],ab[i][1]=map(int,input().split())
dp=[[0]*(t+3001) for i in range(n+1)]
ab.sort(key=lambda x:x[0])
for i in range(1,n+1):
for j in range(t):
dp[i][j]=max(dp[i][j],dp[i-1][j])
dp[i][j+ab[i][0]]=max(dp[i][j+ab[i][0]],dp[i-1][j]+ab[i][1])
ans=0
for i in range(n+1):
ans=max(ans,max(dp[i]))
print(ans) | def solve():
from sys import stdin
f_i = stdin
N, T = map(int, f_i.readline().split())
AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
AB.sort()
dp = [[0] * T for i in range(N + 1)]
for i, AB_i in enumerate(AB, start=1):
A_i, B_i = AB_i
dp_i = dp[i]
dp_pre = dp[i-1]
dp_i[:A_i] = dp_pre[:A_i]
for j, t in enumerate(zip(dp_pre[A_i:], dp_pre), start=A_i):
x, y = t
if x < y + B_i:
dp_i[j] = y + B_i
else:
dp_i[j] = x
ans = max(dp[k][-1] + AB[k][1] for k in range(N))
print(ans)
solve() | 1 | 151,191,502,126,222 | null | 282 | 282 |
a,b,c,k=[int(i) for i in input().split()]
if a>=k:
print(k)
elif a+b>=k:
print(a)
else:
print(a-(k-a-b)) | from collections import deque
def input_bordered_grid(h, w, wall):
grid = [wall * (w + 2)]
for _ in range(1, h+1):
grid.append(wall + input() + wall)
grid.append(wall * (w + 2))
return grid
h, w = map(int, input().split())
grid = input_bordered_grid(h, w, '#')
move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
longest = 0
for sy in range(1, h+1):
for sx in range(1, w+1):
if grid[sy][sx] == '#':
continue
dist = [[-1] * (w+2) for _ in range(h+2)]
dist[sy][sx] = 0
q = deque()
q.append((sy, sx))
while q:
y, x = q.popleft()
longest = max(longest, dist[y][x])
for dy, dx in move:
yy = y + dy
xx = x + dx
if dist[yy][xx] == -1 and grid[yy][xx] == '.':
q.append((yy, xx))
dist[yy][xx] = dist[y][x] + 1
print(longest)
| 0 | null | 58,216,495,972,636 | 148 | 241 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())
def main():
a, b, c = in_nn()
t1 = c - (a + b)
t2 = 4 * a * b
if t1 <= 0:
print('No')
exit()
else:
t1 = t1**2
if t2 < t1:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| a,b,c= map(int,input().split())
if c>a+b and 4*a*b<(c-a-b)*(c-a-b):
print('Yes')
else:
print('No') | 1 | 51,595,815,617,752 | null | 197 | 197 |
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = []
for i in range(N):
x,l = X[i]
A.append((x-l,x+l))
B1 = sorted(A,key=lambda x:x[1])
B1 = [(B1[i][0],B1[i][1],i) for i in range(N)]
B2 = sorted(B1,key=lambda x:x[0])
hist = [0 for _ in range(N)]
cnt = 0
i = 0
for k in range(N):
if hist[k]==0:
r = B1[k][1]
hist[k] = 1
cnt += 1
while i<N:
l,j = B2[i][0],B2[i][2]
if hist[j]==1:
i += 1
continue
if l<r:
hist[j] = 1
i += 1
else:
break
print(cnt) | N=int(input())
A=[[]for _ in range(N)]
for i in range(N):
for _ in range(int(input())):
A[i].append(list(map(int,input().split())))
ans=[]
for i in range(2**N):
Bit = [1]*N
for j in range(N):
if (i >> j) & 1:
Bit[j] = 0
i=0
no=0
while i<N:
if Bit[i]==1:
for x,y in A[i]:
if Bit[x-1]!=y:
no=1
i+=1
if no:
ans.append(0)
else:
ans.append(Bit.count(1))
print(max(ans)) | 0 | null | 106,058,592,078,350 | 237 | 262 |
N = int(input())
A = [0 for k in range(int(N**0.5)+1)]
#N=1の処理
if N == 1:
print(0)
exit()
ans = 0
prime = [2]
for k in range(3, len(A), 2):
if A[k] == 0:
prime.append(k)
for j in range(k, len(A), k):
A[j] = 1
for p in prime:
if N%p == 0:
break
else:
print(1)
exit()
used = []
use = []
#print(prime)
for p in prime:
if p > N:
break
if N%p == 0:
#print(p)
ans += 1
used.append(p)
use.append(p)
N = N // p
np = p * p
while N % np == 0:
#print(np)
ans += 1
used.append(np)
N = N // np
np = np * p
#print(use)
#print(N)
for u in used:
if N % u == 0:
N = N // u
for u in used:
if N % u == 0:
N = N // u
for u in used:
if N % u == 0:
N = N // u
if N > 1:
ans += 1
print(ans) | N = int(input())
X = input()
cnt = X.count('1')
if cnt == 1:
for x in X[:-1]:
if x == '0':
print(1)
else:
print(0)
if X[-1] == '1':
print(0)
else:
print(2)
exit()
M = 0
for x in X:
M <<= 1
if x == '1':
M += 1
def solve(n):
ret = 1
while n > 0:
ret += 1
n %= bin(n).count('1')
return ret
ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)
for i in range(N):
if X[i] == '0':
ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
else:
ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')
| 0 | null | 12,657,725,674,272 | 136 | 107 |
import math
a, b, C = map(int, input().split())
C = math.radians(C)
S = a * b * math.sin(C) * 0.5
c = math.sqrt(a * a + b * b - 2 * a * b * math.cos(C))
L = a + b + c
h = 2 * S / a
print(S, L, h)
| A, B, C, K = [int(_) for _ in open(0).read().split()]
cnt = 0
while A >= B:
B *= 2
cnt += 1
while B >= C:
C *= 2
cnt += 1
print('Yes' if cnt <= K else 'No')
| 0 | null | 3,550,502,570,332 | 30 | 101 |
while True:
a,b=map(int,input().split())
if not(a) and not(b):break
if a>b:a,b=b,a
print(a,b) | cnt = 1
output = []
while True:
data = input().split()
if data[0] == '0' and data[1] == '0':
break
elif int(data[0]) > int(data[1]):
output += [data[1] + " " + data[0]]
else:
output += [data[0] + " " + data[1]]
for line in output:
print(line)
| 1 | 529,723,203,932 | null | 43 | 43 |
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
if a1>b1 and a2>b2:
print(0)
elif b1>a1 and b2>a2:
print(0)
elif a1*t1+a2*t2==b1*t1+b2*t2:
print("infinity")
else:
ans=-1
num2=-1
num3=-1
if a1*t1+a2*t2>b1*t1+b2*t2:
if a1>b1:
ans=0
else:
num2=(b1-a1)*t1
num3=((a1-b1)*t1)+((a2-b2)*t2)
if num2//num3==num2/num3:
ans=(num2//num3)*2
else:
ans=(num2//num3)*2+1
else:
if b1>a1:
ans=0
else:
num2=(a1-b1)*t1
num3=((b1-a1)*t1)+((b2-a2)*t2)
if num2//num3==num2/num3:
ans=(num2//num3)*2
else:
ans=(num2//num3)*2+1
print(ans)
| R,C,K = map(int,input().split())
mat = {}
for _ in range(K):
r,c,v = map(int,input().split())
mat[(r,c)] = v
# dp[i][j][k] = i,jまでで、i列のものをk個取ったときのスコア
dp0 = [[0] * (C+1) for _ in range(R+1) ]
dp1 = [[0] * (C+1) for _ in range(R+1) ]
dp2 = [[0] * (C+1) for _ in range(R+1) ]
dp3 = [[0] * (C+1) for _ in range(R+1) ]
for i in range(1,R+1):
for j in range(1,C+1):
if (i,j) in mat:
m = mat[(i,j)]
# 左からの遷移
dp1[i][j] = max(dp1[i][j-1], dp0[i][j-1]+m)
dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1]+m)
dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1]+m)
else:
dp1[i][j] = dp1[i][j-1]
dp2[i][j] = dp2[i][j-1]
dp3[i][j] = dp3[i][j-1]
# 上からの遷移
x = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
dp0[i][j] = max(dp0[i][j-1], x)
if (i,j) in mat:
m = mat[(i,j)]
dp1[i][j] = max(dp1[i][j], x+m)
else:
dp1[i][j] = max(dp1[i][j], x)
print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])) | 0 | null | 68,264,716,901,540 | 269 | 94 |
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
class Eratosthenes:
def __init__(self, n):
self.n = n
self.min_factor = [-1] * (n + 1)
self.min_factor[0], self.min_factor[1] = 0, 1
def get_primes(self):
primes = []
is_prime = [True] * (self.n + 1)
is_prime[0] = is_prime[1] = False
for i in range(2, self.n + 1):
if not is_prime[i]:
continue
primes.append(i)
self.min_factor[i] = i
for j in range(i * 2, self.n + 1, i):
is_prime[j] = False
if self.min_factor[j] == -1:
self.min_factor[j] = i
return primes
def prime_factorization(self, n):
res = []
while n != 1:
prime = self.min_factor[n]
exp = 0
while self.min_factor[n] == prime:
exp += 1
n //= prime
res.append([prime, exp])
return res
def resolve():
n = int(input())
A = list(map(int, input().split()))
MAX_A = max(A) + 1
er = Eratosthenes(MAX_A)
er.get_primes()
num = [0] * MAX_A
for i in range(n):
pf = er.prime_factorization(A[i])
for p, ex in pf:
num[p] = max(num[p], ex)
LCM = 1
for v in range(2, MAX_A):
LCM *= pow(v, num[v], mod)
LCM %= mod
res = 0
for a in A:
res += LCM * pow(a, mod - 2, mod)
res %= mod
print(res)
if __name__ == '__main__':
resolve()
| # coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def ev(n):
return 0.5*(n+1)
def main():
n, k = map(int, input().split())
p = list(map(int, input().split()))
p_ev = list(map(ev, p))
s = np.cumsum(p_ev)
s = np.insert(s, 0, 0)
ans = []
for i in range(n - k+1):
ans.append(s[i + k] - s[i])
print(max(ans))
if __name__ == '__main__':
main()
| 0 | null | 81,484,560,710,190 | 235 | 223 |
n=input()
data=input().split()
data.reverse()
print(' '.join(data)) | N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = [0]
Bsum = [0]
a = 0
b = 0
for i in range(N):
a += A[i]
Asum.append(a)
for i in range(M):
b += B[i]
Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res, j = 0, M
for i in range(N+1):
if Asum[i] > K:
break
while Asum[i] + Bsum[j] > K:
j -= 1
res = max(res,i+j)
print(res) | 0 | null | 5,930,468,277,020 | 53 | 117 |
import sys
while True:
h, w = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
if 0 ==h and 0 == w:
break
for i in range( h ):
print( "#"*w )
print( "" ) | while True:
L = map(int,raw_input().split())
H = (L[0])
W = (L[1])
if H == 0 and W == 0:break
for x in range(0,H):print "#" * W
print "" | 1 | 774,527,463,530 | null | 49 | 49 |
import string
text = ''
while True:
try:
text += input().lower()
except EOFError:
break
for chr in string.ascii_lowercase:
print('{} : {}'.format(chr, text.count(chr)))
| import sys
#fin = open("test.txt", "r")
fin = sys.stdin
sentence = fin.read()
sentence = sentence.lower()
num_alphabet_list = [0 for i in range(26)]
for c in sentence:
if ord(c) < ord('a') or ord(c) > ord('z'):
continue
num_alphabet_list[ord(c) - ord('a')] += 1
for i in range(0, 26):
print(chr(i + ord('a')), end="")
print(" : ", end="")
print(num_alphabet_list[i]) | 1 | 1,648,740,393,762 | null | 63 | 63 |
a = int ( input ( ) )
h = a // 3600
m = ( a // 60 ) % 60
d = a % 60
print ( "%s:%s:%s" % ( h, m, d ) ) | S = int(input())
h = S // 3600
m = S % 3600 // 60
s = S % 60
print(h, m, s, sep=':') | 1 | 334,306,458,200 | null | 37 | 37 |
while True:
L = map(int,raw_input().split())
H = (L[0])
W = (L[1])
if H == 0 and W == 0:break
for x in range(0,H):print "#" * W
print "" | import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
nextcity = [[] for _ in range(N)]
sgn = [0 for _ in range(N)]
while M:
M -= 1
A, B = map(int, input().split())
A -= 1
B -= 1
nextcity[A].append(B)
nextcity[B].append(A)
def bfs(cnt, lis):
nextvisit = []
for j in lis:
for item in nextcity[j]:
if sgn[item] == 0:
nextvisit.append(item)
sgn[item] = cnt
if nextvisit:
bfs(cnt, nextvisit)
return None
else:
return None
cnt = 0
for k in range(N):
if sgn[k] == 0:
cnt += 1
sgn[k] = cnt
bfs(cnt, [k])
print(cnt -1)
| 0 | null | 1,543,667,818,562 | 49 | 70 |
def bubblesort(c, n):
for i in range(n):
for j in range(n-1, 0, -1):
if (c[j][1] < c[j-1][1]):
c[j], c[j-1] = c[j-1], c[j]
def selectionsort(c, n):
for i in range(n):
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]
def output(c):
for i in range(len(c)):
if i != 0: print(" ", end="")
print("{}{}".format(c[i][0], c[i][1]), end="")
print()
def main():
n = int(input())
data = input().split()
cards = []
for c in data:
cards.append((c[0],int(c[1])))
cards1 = cards[:]
cards2 = cards[:]
bubblesort(cards1, n)
output(cards1)
print("Stable")
selectionsort(cards2, n)
output(cards2)
if (cards1 == cards2):
print("Stable")
else:
print("Not stable")
if __name__ == "__main__":
main() | N = int(input())
l = input().split()
l2 = l[:]
for j in range(N):
for i in range(N-1):
if l[i][1] > l[i+1][1]:
l[i], l[i+1] = l[i+1], l[i]
for i in range(0,len(l)-1):
print(l[i],end=' ')
print(l[N-1])
print("Stable")
for j in range(0,len(l2)-1):
min = l2[j][1]
a = j
for i in range(j,len(l2)):
if min > l2[i][1]:
min = l2[i][1]
a = i
l2[j],l2[a] = l2[a],l2[j]
for i in range(0,len(l2)-1):
print(l2[i],end=' ')
print(l2[N-1])
if l==l2:
print("Stable")
else:
print("Not stable")
| 1 | 26,979,977,592 | null | 16 | 16 |
import sys
A,B,K = (int(a) for a in input().split())
if A > K :
A = A - K
print(A,B)
sys.exit()
else :
K = K - A
A = 0
if B > K :
B = B - K
print(A,B)
else :
print(0,0)
| a, b, k = map(int, input().split())
total = a+b
if total <= k:
ans = [0, 0]
else:
if a <= k:
k -= a
a = 0
b -= k
ans = [a, b]
else:
a -= k
ans = [a, b]
print(*ans) | 1 | 104,053,523,407,156 | null | 249 | 249 |
X=int(input())
number1=X//500
number2=(X-(X//500)*500)//5
print(number1*1000+number2*5)
| X = int(input())
happy = 0
happy += X // 500 * 1000
X = X % 500
happy += X //5 * 5
print(happy) | 1 | 42,976,862,034,320 | null | 185 | 185 |
S = input()
if S == 'MON':
print("6")
elif S == 'TUE':
print("5")
elif S == 'WED':
print("4")
elif S == 'THU':
print("3")
elif S == 'FRI':
print("2")
elif S == 'SAT':
print("1")
elif S == 'SUN':
print("7")
| s = input()
if s=="SUN":
print(7)
elif s=="MON":
print(6)
elif s=="TUE":
print(5)
elif s=="WED":
print(4)
elif s=="THU":
print(3)
elif s=="FRI":
print(2)
else:
print(1) | 1 | 132,973,605,372,982 | null | 270 | 270 |
n,k= map(int, input().split())
p= list(map(int, input().split()))
c= list(map(int, input().split()))
ans=-float('inf')
x=[0]*n
for i in range(n):
if x[i]==0:
x[i]=1
y=p[i]-1
# 累積和を格納
aa=[0,c[i]]
# 2周させる
life=2
for j in range(2*n+2):
x[y]=1
if life>0:
aa.append(aa[-1]+c[y])
y=p[y]-1
if y==i:
life-=1
else:
break
# 各回数での取れるスコアの最大値
x1=(len(aa)-1)//2
a=[-float('inf')]*(x1+1)
for ii in range(len(aa)-1):
for j in range(ii+1,len(aa)):
if j-ii<=x1:
a[j - ii] = max(a[j - ii], aa[j] - aa[ii])
v=k//x1
w=k%x1
if v==0:
ans=max(ans,max(a[:k+1]))
elif v==1:
ans = max(ans, max(a), v * aa[x1] + max(a[:w + 1]))
else:
ans=max(ans,max(a),v * aa[x1] + max(a[:w + 1]),(v-1)*aa[x1]+max(a))
print(ans) | N, K = map(int, input().split())
Ps = list(map(int, input().split()))
Ps = [i - 1 for i in Ps]
Cs = list(map(int, input().split()))
max_score = -float("inf")
for i in range(N):
scores = []
idx = i # starting index
while True:
idx = Ps[idx] # point to the next index
scores.append(Cs[idx]) # fetch a score to add
if idx == i: # when the cycle is closed
break
len_cycle = len(scores)
sum_cycle = sum(scores)
if sum_cycle <= 0: # when each cycle reduces the total score
score = 0
for j in range(min(K, len_cycle)):
score += scores[j]
max_score = max(max_score, score)
else:
if K // len_cycle > 0:
num_multiply = K // len_cycle - 1
score = sum_cycle * num_multiply
scores = scores * 2
for j in range(K % len_cycle + len_cycle):
score += scores[j]
max_score = max(max_score, score)
else:
num_multiply = 0 # len_cycle > K
score = sum_cycle * num_multiply
for j in range(K):
score += scores[j]
max_score = max(max_score, score)
print(max_score)
| 1 | 5,360,331,781,922 | null | 93 | 93 |
import sys
input = sys.stdin.buffer.readline
n = int(input())
l = list(map(int,input().split()))
l.sort()
mx = l[-1]+l[-2]
length = [0]*(mx+1)
for i in range(n):
for j in range(i+1,n):
length[l[i]+l[j]] -= 1
length[l[j]-l[i]+1] += 1
for i in range(1,mx+1):
length[i] += length[i-1]
minus = [0]*n
for i in range(n):
a = i
for j in range(i+1,n):
if l[i]*2 - 1 >= l[j]:
a += 1
minus[i] = a
#print(length)
#print(minus)
ans = 0
for i in range(n):
ans += length[l[i]] - minus[i]
print(ans//3) | import bisect
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-1):
for k in range(i+1,N-1):
a=L[i]+L[k]
b=bisect.bisect_left(L,a)
ans=ans+(b-k-1)
print(ans) | 1 | 172,087,111,811,920 | null | 294 | 294 |
n = int(input())
ans = 0
t = 0
J = 0
for i in range(1,n):
for j in range(i,n):
if i*j >= n:break
if i == j : t+=1
ans +=1
J = j
if i*J >= n:break
print(2*ans -t)
| print("Yes") if int(input()) % 9 == 0 else print("No") | 0 | null | 3,485,399,320,310 | 73 | 87 |
n, m = map(int, input().split())
coins = list(map(int, input().split()))
coins = sorted(coins, reverse=False)
dp = [[float('inf')] * (n + 1) for _ in range(m)]
for j in range(n+1):
dp[0][j] = j
for i in range(m-1):
for j in range(n+1):
if j - coins[i+1] >= 0:
dp[i+1][j] = min(dp[i][j],
dp[i][j - coins[i+1]] + 1,
dp[i+1][j - coins[i+1]] + 1)
else:
dp[i+1][j] = dp[i][j]
print(dp[m-1][n])
| n, m = map(int, input().split())
c = list(map(int, input().split()))
INF = 10**9
MAX = n + 1
dp = [INF for _ in range(MAX)]
dp[0] = 0
for i in range(m):
for j in range(len(dp)):
if j + c[i] < MAX:
dp[j+c[i]] = min(dp[j] + 1, dp[j+c[i]])
min_v = dp[-1]
for i in range(len(dp)):
idx = len(dp) - 1 - i
min_v = min(min_v, dp[idx])
dp[idx] = min_v
print(dp[n])
| 1 | 143,752,863,070 | null | 28 | 28 |
# -*- coding: utf-8 -*-
def main():
K, X = map(int, input().split())
money = 500 * K
if money >= X:
ans = 'Yes'
else:
ans = 'No'
print(ans)
if __name__ == "__main__":
main() | from operator import itemgetter
from itertools import chain
N = int(input())
L = []
R = []
for i in range(N):
S = input()
low = 0
var = 0
for s in S:
if s == '(':
var += 1
else:
var -= 1
low = min(low, var)
if var >= 0:
L.append((low, var))
else:
R.append((low, var))
L.sort(key=itemgetter(0), reverse=True)
R.sort(key=lambda x: x[0] - x[1])
pos = 0
for i, (low, var) in enumerate(chain(L, R)):
if pos + low < 0:
ans = 'No'
break
pos += var
else:
ans = 'Yes' if pos == 0 else 'No'
print(ans)
| 0 | null | 60,777,685,881,600 | 244 | 152 |
def backtrack(nums, step, result):
if len(step) == 3:
if len(set(step)) == 3:
sorted_step = sorted(step)
a,b,c = sorted_step
if a+b > c:
result.append(step[:])
else:
for i in range(len(nums)):
step.append(nums[i])
backtrack(nums[i+1:], step, result)
step.pop()
def solve():
N = int(input())
L = [int(i) for i in input().split()]
result = []
backtrack(L, [], result)
print(len(result))
if __name__ == "__main__":
solve() | n = int(input())
s2 = input()
l = [int(i) for i in s2]
p = sum(l)
s10 = int(s2,2)
if p == 1:
ans1 = s10%(p+1)
l1 = [0]*(n+1)
l1[0] = 1
for i in range(1,n+1):
l1[i] = (l1[i-1]*2)%(p+1)
for i in range(n):
if l[i]:
print(0)
else:
first = (ans1 + l1[n-i-1])%(p+1)
ans = 1
while first:
mod = 0
for j in range(len(bin(first))-2):
mod += first >> j & 1
first %= mod
ans += 1
print(ans)
quit()
if p == 0:
for i in range(n):
print(1)
quit()
ans1 = s10%(p+1)
ans2 = s10%(p-1)
l1 = [0]*(n+1)
l2 = [0]*(n+1)
l1[0] = 1
l2[0] = 1
for i in range(1,n+1):
l1[i] = (l1[i-1]*2)%(p+1)
l2[i] = (l2[i-1]*2)%(p-1)
first = []
for i in range(n):
if l[i]:
first.append((ans2-l2[n-i-1])%(p-1))
else:
first.append((ans1+l1[n-i-1])%(p+1))
for i in range(n):
if first[i] == 0:
print(1)
continue
x = first[i]
ans = 1
while x:
mod = 0
for j in range(len(bin(x))-2):
mod += x >> j & 1
x = x%mod
ans += 1
print(ans) | 0 | null | 6,608,042,864,760 | 91 | 107 |
A, B, C = list(map(int, input().split()))
K = int(input())
while(B <= A):
B *= 2
K -= 1
while(C <= B):
C *= 2
K -= 1
if(K >= 0): print("Yes")
else: print("No") | # Station and Bus
S = input()
ans = ['No', 'Yes'][int('A' in S) + int('B' in S) - 1]
print(ans)
| 0 | null | 31,053,181,260,740 | 101 | 201 |
a,b=map(int,input().split())
if a-2*b>=0:
print(a-2*b)
else:
print("0") | a,b=map(int,input().split())
result=a-b*2
if result > 0:
print(result)
else:
print(0) | 1 | 166,896,130,176,190 | null | 291 | 291 |
from math import gcd
def readinput():
k=int(input())
return k
def main(k):
memo=[]
for _j in range(k+1):
memo.append([0 for _i in range(k+1)])
sum=0
for a in range(1,k+1):
for b in range(1,k+1):
if memo[a][b]!=0:
temp=memo[a][b]
else:
temp=gcd(a,b)
memo[a][b]=temp
memo[b][a]=temp
for c in range(1,k+1):
if memo[temp][c]!=0:
sum+=memo[temp][c]
else:
temp2=gcd(temp,c)
memo[temp][c]=temp2
memo[c][temp]=temp2
sum+=temp2
return sum
if __name__=='__main__':
k=readinput()
ans=main(k)
print(ans)
| import math
K = int(input())
ans = []
bc = [math.gcd(b, c) for b in range(1, K+1) for c in range(1, K+1)]
for a in range(1, K+1):
for i in bc:
x = math.gcd(a, i)
ans.append(x)
print(sum(ans)) | 1 | 35,457,270,047,150 | null | 174 | 174 |
def linear_search(A, n, key):
A.append(key)
i = 0
while A[i] != key:
i += 1
A.pop()
return i != n
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for t in T:
if linear_search(S, n, t):
ans += 1
print(ans)
| n=int(input())
a=list(map(str,input().split()))
ab=a[:]
flg=True
i=0
while flg:
flg=False
for j in range(n-1,i,-1):
if ab[j][1]<ab[j-1][1]:
ab[j],ab[j-1]=ab[j-1],ab[j]
flg=True
i+=1
print(' '.join(map(str,ab)))
print('Stable')
ac=a[:]
for i in range(n):
minj=i
for j in range(i,n):
if ac[j][1]<ac[minj][1]:
j,minj=minj,j
if i!=minj:
ac[i],ac[minj]=ac[minj],ac[i]
print(' '.join(map(str,ac)))
if ab==ac:
print('Stable')
else:
print('Not stable')
| 0 | null | 48,934,874,912 | 22 | 16 |
tgtstr = list(raw_input())
n = int(raw_input())
for i in range(n):
cmd_list = raw_input().split(" ")
if cmd_list[0] == "replace":
for idx in range(int(cmd_list[1]), int(cmd_list[2])+1):
tgtstr[idx] = cmd_list[3][idx - int(cmd_list[1])]
elif cmd_list[0] == "reverse":
start = int(cmd_list[1])
end = int(cmd_list[2])
while True:
tmp = str(tgtstr[start])
tgtstr[start] = str(tgtstr[end])
tgtstr[end] = tmp
start += 1
end -= 1
if start >= end:
break
elif cmd_list[0] == "print":
print "".join(tgtstr[int(cmd_list[1]):int(cmd_list[2])+1]) | while 1:
a,b = sorted(map(int, raw_input().split(' ')))
if a or b:
print a, b
else:
break | 0 | null | 1,319,775,791,180 | 68 | 43 |
s = str(input())
array = list(s)
if array.count("R")==3:print(3)
elif s[1]==("R") and array.count("R")==2:print(2)
elif array.count("R")==0:print(0)
else:print(1) | N, K = map(int,input().split())
A = list(map(int,input().split()))
start = 0
end = 10**9
while end - start > 1:
l = (start + end)/2
l = int(l)
count = 0
for i in range(N):
q = A[i]/l
if q == int(q):
q -= 1
count += int(q)
if count <= K:
end = l
else:
start = l
print(end) | 0 | null | 5,696,492,223,172 | 90 | 99 |
import math
n=int(input())
xs=list(map(float,input().split()))
ys=list(map(float,input().split()))
ds=[ abs(x - y) for (x,y) in zip(xs,ys) ]
print('{0:.6f}'.format(sum(ds)))
print('{0:.6f}'.format((sum(map(lambda x: x*x,ds)))**0.5))
print('{0:.6f}'.format((sum(map(lambda x: x*x*x,ds)))**(1./3.)))
print('{0:.6f}'.format(max(ds))) | n = int(input())
x = map(float, input().strip().split())
y = map(float, input().strip().split())
d = tuple(map(lambda x,y:abs(x-y), x, y))
print(sum(d))
print(sum(map(pow, d, [2]*n))**0.5)
print(sum(map(pow, d, [3]*n))**(1/3))
print(max(d)) | 1 | 211,674,353,310 | null | 32 | 32 |
while True:
a,b=map(int,input().split())
if a==0 and b==0:break
for i in range (a):
print('#'*b)
print()
| while True:
H, W = map(int, input().split())
if H == 0 and W == 0:
break
square = [['#'] * W] * H
for row in square:
print(''.join(row))
print()
| 1 | 768,821,419,718 | null | 49 | 49 |
a, b = [int(x) for x in input().split()]
temp = a - 2 * b
ans = temp if temp > 0 else 0
print(ans) | import numpy as np
N, M, X = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(N)]
cost = float("inf")
for i in range(2**N):
tmp = np.array([0 for _ in range(M+1)])
for j in range(N):
if (i>>j) & 1:
tmp += np.array(C[j])
if min(tmp[1:]) >= X:
cost = min(cost, tmp[0])
print(-1 if cost == float("inf") else cost) | 0 | null | 94,098,546,063,060 | 291 | 149 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,K = map(int,readline().split())
H = list(map(int,readline().split()))
ans = 0
for h in H:
if h >= K:
ans += 1
print(ans) | N, K = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
def nibu(x, arr):
if x <= arr[0]:
return len(arr)
if arr[-1] < x:
return 0
l = 0
h = len(arr) - 1
while h - l >1:
m = (l + h) // 2
if x <= arr[m]:
h = m
else:
l = m
return len(arr) - h
print(nibu(K, h))
| 1 | 179,385,696,526,620 | null | 298 | 298 |
from numba import njit
@njit(cache=True)
def solve(n,x,y):
ans = [0] * (n - 1)
for i in range(n):
for j in range(n):
c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
if c:
ans[c-1] += 1
return ans
n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = solve(n,x,y)
for ai in ans:
print(ai//2)
| PD = input()
print(PD.replace("?", "D"))
| 0 | null | 31,140,559,078,756 | 187 | 140 |
n, m = map(int, raw_input().split())
c = map(int, raw_input().split())
INF = 1000000000
t = [INF] * (n + 1)
t[0] = 0
for i in range(m):
for j in range(c[i], n + 1):
t[j] = min([t[j], t[j - c[i]] + 1])
print(t[n]) | n,m = map(int,input().split())
coins = sorted(list(map(int,input().split())),reverse=True)
dp = [float("inf")]*50001
dp[0] = 0
for i in range(50001):
for coin in coins:
if i+coin > 50000:
continue
else:
dp[i+coin] = min(dp[i+coin], dp[i]+1)
print(dp[n])
| 1 | 137,089,157,180 | null | 28 | 28 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
n, m, k = map(int, input().split())
a = np.array(readline().split(), np.int64)
b = np.array(readline().split(), np.int64)
aa = a.cumsum()
ba = b.cumsum()
r = np.searchsorted(ba, k, side='right')
for i1, aae in enumerate(aa):
if k < aae:
break
r = max(r, np.searchsorted(ba, k - aae, side='right') + i1 + 1)
print(r)
if __name__ == '__main__':
main() | N,K = map(int,input().split())
L = []
for _ in range(K):
l,r = map(int,input().split())
L.append((l,r))
DP = [0] * N
DP[0] = 1
con = [0] * (N + 1)
con[1] = 1
for i in range(1 , N):
s = 0
for l,r in L:
s += con[max(0 , i - l + 1)] - con[max(0 , i - r)]
DP[i] = s
con[i + 1] = (con[i] + DP[i]) % 998244353
print(DP[N - 1] % 998244353)
| 0 | null | 6,667,045,080,320 | 117 | 74 |
N = int(input())
ans = (N + 1) // 2 / N
print(ans)
| import copy
n, k = map(int, input().split())
P = list(map(int, input().split()))
U = [0]*n
for i in range(n):
U[i] = (P[i]+1)/2
ans = sum(U[:k])
t = copy.copy(ans)
for i in range(n-k):
t = t+U[k+i]-U[i]
ans = max(ans, t)
print(ans)
| 0 | null | 126,002,508,140,288 | 297 | 223 |
n=int(input())
if(n>=30):
print('Yes')
else:
print('No')
| print("YNeos"[int(input())<30::2]) | 1 | 5,749,737,172,190 | null | 95 | 95 |
from functools import lru_cache
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int,read().split())
@lru_cache(None)
def F(N, K):
if N < 10:
if K == 0:
return 1
if K == 1:
return N
return 0
q, r = divmod(N, 10)
ret = 0
if K >= 1:
ret += F(q, K-1) * r
ret += F(q-1, K-1) * (9-r)
ret += F(q, K)
return ret
print(F(N, K)) | import numpy as np
N = input()
K = int(input())
n = len(N)
dp0 = np.zeros((n, K+1), np.int64)
dp1 = np.zeros((n, K+1), np.int64)
dp0[0, 0] = 1
dp0[0, 1] = int(N[0]) - 1
dp1[0, 1] = 1
for i, d in enumerate(N[1:]):
dp0[i+1] += dp0[i]
dp0[i+1, 1:] += dp0[i, :-1] * 9
if int(d) == 0:
dp1[i+1] = dp1[i]
elif int(d) == 1:
dp0[i+1] += dp1[i]
dp1[i+1, 1:] = dp1[i, :-1]
elif int(d) >= 2:
dp0[i+1] += dp1[i]
dp0[i+1, 1:] += dp1[i, :-1] * (int(d) - 1)
dp1[i+1, 1:] = dp1[i, :-1]
print(dp0[-1, K] + dp1[-1, K])
| 1 | 76,134,016,949,882 | null | 224 | 224 |
n = int(input())
al = list(map(int, input().split()))
ail = []
for i,a in enumerate(al):
ail.append((a,i+1))
ail.sort()
ans = []
for i,a in ail:
ans.append(a)
print(*ans) | s = input()
if s == "RRR":
print(3)
elif s == "RRS" or s == "SRR":
print(2)
elif s == "RSS" or s == "RSR" or s == "SRS" or s == "SSR":
print(1)
else:
print(0)
| 0 | null | 92,943,314,688,838 | 299 | 90 |
import math
data = map(int, raw_input().split())
a = data[0]
b = data[1]
deg = math.radians(data[2])
c = (a**2 + b**2 - 2*a*b*math.cos(deg))**0.5
L = a + b + c
h = b * math.sin(deg)
S = a * h * 0.5
print S
print L
print h | import math
a, b, C = map(float, input().split(' '))
rad = math.radians(C)
c = math.sqrt(a**2+b**2-2*a*b*math.cos(rad))
S = a*b*math.sin(rad)*1/2
L = a+b+c
h = abs(b*math.sin(rad))
print('{:.5f} {:.5f} {:.5f}'.format(S, L, h)) | 1 | 168,574,186,182 | null | 30 | 30 |
s=input()
dic={}
cur=0
power=0
for i in range(0,len(s)+1):
s_int=len(s)-i-1
if cur in dic:
dic[cur]+=1
else:
dic[cur]=1
try:
num=int(s[s_int])
cur+=num*pow(10,power,2019)
cur%=2019
power+=1
except IndexError:
break
res=0
for i in range(len(dic)):
t=dic.popitem()
cc=t[1]
res+=cc*(cc-1)//2
print(res)
| n = int(input())
s = input()
x = [int(i) for i in s]
pc = s.count('1')
def popcnt(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
def f(x):
if x == 0:
return 0
return f(x % popcnt(x)) + 1
ans = [0]*n
for a in range(2):
npc = pc
if a == 0:
npc += 1
else:
npc -= 1
if npc <= 0:
continue
r0 = 0
for i in range(n):
r0 = (r0*2) % npc
r0 += x[i]
k = 1
for i in range(n-1, -1, -1):
if x[i] == a:
r = r0
if a == 0:
r = (r+k) % npc
else:
r = (r-k+npc) % npc
ans[i] = f(r) + 1
k = (k*2) % npc
for i in ans:
print(i) | 0 | null | 19,652,388,225,332 | 166 | 107 |
s = input()
S = list(s)
if len(set(S)) == 1:
print('No')
else:
print('Yes') | import sys
readline = sys.stdin.readline
N,X,M = map(int,readline().split())
nex = [(i ** 2) % M for i in range(M)]
cum = [i for i in range(M)]
ans = 0
while N:
if N & 1:
ans += cum[X]
X = nex[X]
cum = [cum[i] + cum[nex[i]] for i in range(M)]
nex = [nex[nex[i]] for i in range(M)]
N >>= 1
print(ans) | 0 | null | 28,745,962,309,622 | 201 | 75 |
#!/usr/bin/env python3
import collections as cl
import sys
def II():
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 = II()
S = LI()
if len(set(S)) == N:
print("YES")
else:
print("NO")
main()
| N=int(input())
from collections import Counter
if max(Counter([int(x) for x in input().split()]).values())==1:
print("YES")
else:
print("NO") | 1 | 73,792,222,972,668 | null | 222 | 222 |
k = "a",
for _ in range(int(input()) - 1):
k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)}
print(*sorted(k)) | N = input()
if N[-1] == '2' or N[-1] == '4' or N[-1] == '5' or N[-1] == '7' or N[-1] == '9':
Yomi = 'hon'
elif N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8':
Yomi = 'pon'
elif N[-1] == '3':
Yomi = 'bon'
print(Yomi) | 0 | null | 35,897,522,309,462 | 198 | 142 |
x, y = map(int, input().split())
z = map(int, input().split())
if sum(z) >= x:
print("Yes")
else:
print("No") | h,n = map(int,input().split())
xlist = list(map(int,input().split()))
if sum(xlist)>=h:
print("Yes")
else:
print("No") | 1 | 78,068,256,882,112 | null | 226 | 226 |
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
cum = [0 for _ in range(N)]
cum[0] = A[0]
for i in range(N - 1):
cum[i + 1] = (cum[i] + A[i + 1]) % mod
ans = 0
for i in range(N - 1):
ans += (A[i] * (cum[N - 1] - cum[i])) % mod
print(ans % mod) | N = int(input())
A = list(map(int, input().split()))
s = sum(A)
res = 0
mod = 10**9 + 7
for i in range(N-1):
s -= A[i]
res += s*A[i]
print(res%mod) | 1 | 3,800,357,463,188 | null | 83 | 83 |
# 2019-11-19 10:28:31(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
def main():
n, m, l = map(int, sys.stdin.readline().split())
ABCQST = np.array(sys.stdin.read().split(), np.int64)
ABC = ABCQST[:m * 3]
A, B, C = ABC[::3], ABC[1::3], ABC[2::3]
ST = ABCQST[m * 3 + 1:]
S, T = ST[::2], ST[1::2]
dist = csr_matrix((C, (A, B)), (n+1, n+1))
min_dist = floyd_warshall(dist, directed=False)
filling_times = np.full((n+1, n+1), np.inf)
np.diagonal(filling_times, 0)
filling_times[min_dist <= l] = 1
min_filling_times = floyd_warshall(filling_times, directed=False)
min_filling_times[min_filling_times == np.inf] = 0
# 最後に-1する
min_filling_times = min_filling_times.astype(int)
res = min_filling_times[S, T] - 1
print('\n'.join(res.astype(str)))
if __name__ == "__main__":
main()
| 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) | 0 | null | 150,159,288,977,642 | 295 | 265 |
n=int(input())
print(*[chr(65+(ord(a)+n-65)%26) for a in input()], sep='') | import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
class UnionFind:
def __init__(self, N: int):
"""
N:要素数
root:各要素の親要素の番号を格納するリスト.
ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
rank:ランク
"""
self.N = N
self.root = [-1] * N
self.rank = [0] * N
def __repr__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def find(self, x: int):
"""頂点xの根を見つける"""
if self.root[x] < 0:
return x
else:
while self.root[x] >= 0:
x = self.root[x]
return x
def union(self, x: int, y: int):
"""x,yが属する木をunion"""
# 根を比較する
# すでに同じ木に属していた場合は何もしない.
# 違う木に属していた場合はrankを見てくっつける方を決める.
# rankが同じ時はrankを1増やす
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] > self.rank[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def same(self, x: int, y: int):
"""xとyが同じグループに属するかどうか"""
return self.find(x) == self.find(y)
def count(self, x):
"""頂点xが属する木のサイズを返す"""
return - self.root[self.find(x)]
def members(self, x):
"""xが属する木の要素を列挙"""
_root = self.find(x)
return [i for i in range(self.N) if self.find == _root]
def roots(self):
"""森の根を列挙"""
return [i for i, x in enumerate(self.root) 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()}
N,M=MI()
uf=UnionFind(N)
for _ in range(M):
a,b=MI()
a-=1
b-=1
uf.union(a,b)
cnt=uf.group_count()
print(cnt-1)
main()
| 0 | null | 68,607,295,300,140 | 271 | 70 |
x,y=map(int,input().split())
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
if (-x+2*y)%3!=0:
ans=0
else:
a=(-x+2*y)//3
b=(2*x-y)//3
ans=cmb(a+b,a,mod)
print(ans) | A, B, C, D = map(int, input().split())
while(True):
C = C - B
if C <= 0:
ans = 'Yes'
break
A = A - D
if A <= 0:
ans = 'No'
break
print(ans) | 0 | null | 90,040,235,342,850 | 281 | 164 |
import sys
import math
n=int(input())
A=[]
xy=[[]]*n
for i in range(n):
a=int(input())
A.append(a)
xy[i]=[list(map(int,input().split())) for _ in range(a)]
ans=0
for bit in range(1<<n):
tmp=0
for i in range(n):
if bit>>i & 1:
cnt=0
for elem in xy[i]:
if elem[1]==1:
if bit>>(elem[0]-1) & 1:
cnt+=1
else:
if not (bit>>(elem[0]-1) & 1):
cnt+=1
if cnt==A[i]:
tmp+=1
else:
continue
if tmp==bin(bit).count("1"):
ans=max(bin(bit).count("1"),ans)
print(ans)
| N = int(input())
testimony = [[] for _ in range(N)]
for i in range(N):
num = int(input())
for j in range(num):
person, state = map(int, input().split())
testimony[i].append([person-1, state])
honest = 0
for i in range(2**N):
flag = 0
for j in range(N):
if (i>>j)&1 == 1: # j番目は正直と仮定
for x,y in testimony[j]:
if (i>>x)&1 != y: # j番目は正直だが矛盾を発見
flag = 1
break
if flag == 0: # 矛盾がある場合はflag == 1になる
honest = max(honest, bin(i)[2:].count('1')) # 1の数をカウントし最大となるものを選択
print(honest) | 1 | 121,369,209,693,540 | null | 262 | 262 |
n,k = map(int,input().split())
ke = 1
while(True):
if(n<k):
print(ke)
break
else:
n = n//k
ke += 1 | from math import log
n, k = map(int, input().split())
print(int(log(n, k)) + 1) | 1 | 64,349,243,821,600 | null | 212 | 212 |
N, K = [int(i) for i in input().split()]
mod = 10**9+7
result = 0
for i in range(K, N+2):
min_sum = ((i-1) * i) // 2
max_sum = ((N) * (N+1)) // 2 - ((N-i) * (N-i+1)) // 2
result += (max_sum - min_sum + 1) % mod
print(result%mod) | #!/usr/bin/env python3
def main():
N = input()
l = len(N)
K = int(input())
ans = 0
# 最上位K桁が0の場合
# l-K_C_K * 9^K
if K == 1:
ans += (l-1) * 9
elif K == 2:
ans += (l-1) * (l-2) * 81 // 2
else:
ans += (l-1) * (l-2) * (l-3) * 729 // 6
if K == 1:
# 最上位の数以外0
ans += int(N[0])
elif K == 2:
# 最上位1桁が0ではなく,残りl-1桁中1桁だけ0以外(Nより大きくならないように注意)
if l >= 2:
# ans += int(N[0]) * (l-1) * 9 - (9 - int(N[1]))
for a in range(1,int(N[0])+1):
for b in range(l-1):
for p in range(1,10):
tmp = a * 10**(l-1) + p * 10**b
if tmp <= int(N):
ans += 1
else:
# 最上位1桁が0ではなく,残りl-1桁中2桁だけ0以外(Nより大きくならないように注意)
if l >= 3:
NN = int(N)
N0 = int(N[0])
L = 10**(l-1)
ans += (N0-1) * (l-1) * (l-2) * 81 // 2
for p in range(1,10):
for q in range(1,10):
for b in range(l-1):
for c in range(b+1,l-1):
tmp = N0 * L + p * 10**b + q * 10**c
if tmp <= NN:
ans += 1
else:
break
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 54,281,562,463,876 | 170 | 224 |
A=list(input())
n=int(input())
tmp=0
if len(set(A)) == 1:
print(len(A)*n//2)
exit()
sum_n=0
tmp3=0
while A[0] == A[tmp3]:
tmp3+=1
sum_n+=tmp3
tmp3=0
while A[-1] == A[-1-tmp3]:
tmp3+=1
sum_n+=tmp3
for i in range(len(A)-1):
if A[i] == A[i+1]:
A[i+1]="1"
tmp+=1
tmp2=0
if A[0] == A[-1]:
tmp2=n-1
if sum_n%2 == 1:
tmp2-=n-1
print(tmp*n+tmp2) |
def gcd(a, b):
"""Return greatest common divisor using Euclid's Algorithm."""
while b:
a, b = b, a % b
return a
def lcm(a, b):
"""Return lowest common multiple."""
return a * b // gcd(a, b)
try:
while True:
a, b = map(int, raw_input().split(' '))
print gcd(a, b), lcm(a, b)
except EOFError:
pass | 0 | null | 87,410,478,545,922 | 296 | 5 |
A = int(input())
B = int(input())
if A == 1 and B == 2:
print('3')
elif A == 1 and B == 3:
print('2')
elif A == 2 and B == 1:
print('3')
elif A == 2 and B == 3:
print('1')
elif A == 3 and B == 1:
print('2')
elif A == 3 and B == 2:
print('1')
| from collections import Counter
n,*a = map(int,open(0).read().split())
s = set(a)
c = Counter(a)
m = max(s)
l = [True]*(m+1)
ans = 0
for i in range(1,m+1):
if i in s and l[i]:
if c[i] == 1:
ans += 1
for j in range(1,m//i+1):
l[i*j] = False
print(ans) | 0 | null | 62,819,810,298,500 | 254 | 129 |
x = int(input())
a = [0]*1000
for i in range(1000):
tmp = i**5
a[i] = tmp
for i in range(1000):
for j in range(1000):
if((a[i]-x) == (a[j])):
print(i,j)
exit()
elif(x-a[i]==a[j]):
print(i,-j)
exit()
| A,B = sorted(map(int,open(0).read().split()))
if A==1 and B==2:
print(3)
elif A==1 and B==3:
print(2)
else:
print(1)
| 0 | null | 67,968,371,580,120 | 156 | 254 |
#self.r[x] means root of "x" if "x" isn't root, else number of elements
class UnionFind():
def __init__(self, n):
self.r = [-1 for i in range(n)]
#use in add-method
def root(self, x):
if self.r[x] < 0: #"x" is root
return x
self.r[x] = self.root(self.r[x])
return self.r[x]
#add new path
def add(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
self.r[x] += self.r[y]
self.r[y] = x
return True
n, m = map(int, input().split())
UF = UnionFind(n)
for i in range(m):
a, b = map(lambda x: int(x)-1, input().split())
UF.add(a, b)
ans = 0
for i in UF.r:
if i < 0:
ans += 1
print(ans-1)
| 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)
| 0 | null | 5,189,197,911,352 | 70 | 107 |
for a in range(1,10):
for b in range(1,10):
print("%dx%d=%d" % (a,b,a*b)) | if __name__ == '__main__':
for i in range(1,10):
for j in range(1,10):
print(str(i)+"x"+str(j)+"="+str(i*j)) | 1 | 1,346,450 | null | 1 | 1 |
import math
a,b,agree=map(float,input().split())
agree=math.radians(agree)
c=(a**2+b**2-2*a*b*math.cos(agree))**0.5
s=0.5*a*b*math.sin(agree)
l=a+b+c
h=b*math.sin(agree)
print("{0:.5f}".format(s))
print("{0:.5f}".format(l))
print("{0:.5f}".format(h))
| import math
a, b, c = map(float, input().split())
c = math.radians(c)
S = 0.5 * a * b * math.sin(c)
L = (a ** 2 + b ** 2 - 2 * a * b * math.cos(c)) ** 0.5 + a + b
h = S / a * 2
print(S)
print(L)
print(h) | 1 | 170,324,513,142 | null | 30 | 30 |
[n, m] = [int(x) for x in raw_input().split()]
A = []
counter = 0
while counter < n:
A.append([int(x) for x in raw_input().split()])
counter += 1
B = [int(raw_input()) for j in range(m)]
counter = 0
while counter < n:
result = 0
for j in range(m):
result += A[counter][j] * B[j]
print(result)
counter += 1 | import sys
from collections import defaultdict
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
X, Y = map(int, readline().split())
ans = 0
if X==1:
ans += 300000
elif X==2:
ans += 200000
elif X==3:
ans += 100000
else:
pass
if Y==1:
ans += 300000
elif Y==2:
ans += 200000
elif Y==3:
ans += 100000
else:
pass
if X==Y==1:
ans += 400000
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 71,022,798,444,918 | 56 | 275 |
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j+1, n):
_lst = [l[i], l[j], l[k]]
if len(set(_lst)) == 3:
_max = max(_lst)
_lst.remove(_max)
if _max < sum(_lst):
ans += 1
print(ans)
|
def main():
n = input()
if n[0] == '7':
print("Yes")
return
if n[1] == '7':
print("Yes")
return
if n[2] == '7':
print("Yes")
return
print("No")
if __name__ == "__main__":
main() | 0 | null | 19,634,879,220,048 | 91 | 172 |
A=[int(_) for _ in input().split()]
if A[0]<=A[1]*A[2]:
print("Yes")
else:
print("No") | D, T, S = map(float, input().split())
if D / S <= T:
print("Yes")
else:
print("No") | 1 | 3,552,269,920,220 | null | 81 | 81 |
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)
# divisors.sort()
return divisors
N = int(input())
ans = len(make_divisors(N-1))-1
for i in make_divisors(N):
if i == 1:
continue
Ni = int(N/i)
while Ni % i == 0:
Ni = int(Ni/i)
if Ni % i == 1:
ans+=1
print(ans) | n = int(input())
if n==2:print(1);exit()
a = [n]
for i in range(2,int(n**0.5+1)):
if n%i==0:
a.append(i)
if i!=n//i:
a.append(n//i)
cnt =0
for v in a:
s = n
while v<=s and s%v==0:
s = s//v
if s%v==1: cnt += 1
b = [n-1]
m = n-1
for i in range(2,int(m**0.5+1)):
if m%i==0:
b.append(i)
if i!=m//i:
b.append(m//i)
print(cnt + len(b)) | 1 | 41,537,200,608,300 | null | 183 | 183 |
import math
while True:
N = int(input())
if N == 0:
break
S = list(map(int, input().split()))
S2 = [x ** 2 for x in S]
V = sum(S2)/N - (sum(S)/N) ** 2
print(math.sqrt(V)) | while True:
n = int(input())
if n == 0:
break
s = list(map(float, input().split()))
m = sum(s) / n
v = sum([(x - m) ** 2 for x in s]) / n
print(v ** 0.5) | 1 | 186,107,109,912 | null | 31 | 31 |
from fractions import gcd
n, m = map(int, input().split())
aa = list(map(int, input().split()))
lcm = 1
def p2(m):
cnt = 0
n = m
while 1:
if n%2 == 0:
cnt += 1
n = n//2
else:
break
return cnt
pp = p2(aa[0])
for a in aa:
lcm = a * lcm // gcd(a, lcm)
if pp != p2(a):
lcm = 10 **18
break
tmp = lcm // 2
print((m // tmp + 1) // 2) | from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)
from heapq import heapify, heappush, heappop, heappushpop, heapreplace
from bisect import bisect_left, bisect_right
from math import atan, degrees
n, m = map(int, input().split())
a = [int(x) // 2 for x in input().split()]
t = 0
while a[0] % 2 == 0:
a[0] //= 2
t += 1
for i in range(1, n):
t2 = 0
while a[i] % 2 == 0:
a[i] //= 2
t2 += 1
if t2 != t:
print(0)
exit()
def gcd(x, y):
return gcd(y, x%y) if y else x
def lcm(x, y):
return x // gcd(x, y) * y
m >>= t
l = 1
for i in a:
l = lcm(l, i)
if l > m:
print(0)
exit()
print((m // l + 1) // 2) | 1 | 101,890,669,773,564 | null | 247 | 247 |
class Tree():
def __init__(self, n, edge, indexed=1):
self.n = n
self.tree = [[] for _ in range(n)]
for e in edge:
self.tree[e[0] - indexed].append(e[1] - indexed)
self.tree[e[1] - indexed].append(e[0] - indexed)
def setroot(self, root):
self.root = root
self.parent = [None for _ in range(self.n)]
self.parent[root] = -1
self.depth = [None for _ in range(self.n)]
self.depth[root] = 0
self.order = []
self.order.append(root)
self.size = [1 for _ in range(self.n)]
stack = [root]
while stack:
node = stack.pop()
for adj in self.tree[node]:
if self.parent[adj] is None:
self.parent[adj] = node
self.depth[adj] = self.depth[node] + 1
self.order.append(adj)
stack.append(adj)
for node in self.order[::-1]:
for adj in self.tree[node]:
if self.parent[node] == adj:
continue
self.size[node] += self.size[adj]
import sys
input = sys.stdin.readline
N, u, v = map(int, input().split())
u -= 1; v -= 1
E = [tuple(map(int, input().split())) for _ in range(N - 1)]
t = Tree(N, E)
t.setroot(u); dist1 = t.depth
t.setroot(v); dist2 = t.depth
tmp = 0
for i in range(N):
if dist1[i] < dist2[i]:
tmp = max(tmp, dist2[i])
print(tmp - 1) | from collections import deque
def BFS(s):
tree=[[] for i in range(n)]
for i in list:
tree[i[0]-1].append(i[1]-1)
tree[i[1]-1].append(i[0]-1)
dist=[-1 for i in range(n)]
dist[s-1]=0
que=deque()
que.append(s-1)
while que:
x=que.popleft()
for p in tree[x]:
if dist[p]==-1:
que.append(p)
dist[p]=dist[x]+1
return dist
n,u,v=map(int,input().split())
list=[list(map(int,input().split())) for i in range(n-1)]
u_dist=BFS(u)
v_dist=BFS(v)
l=0
for u_d,v_d in zip(u_dist,v_dist):
if u_d<v_d:
l=max(l,v_d)
print(l-1) | 1 | 117,016,489,864,476 | null | 259 | 259 |
N = int(input())
A = list(input().split())
boss = [0]
for i in range(N-1):
boss.append(0)
boss[int(A[i])-1] += 1
for i in range(N):
print(str(boss[i]))
| n,d= map(int, input().split())
xy = [list(map(int,input().split())) for _ in range(n)]
c= 0
for x,y in xy:
if x**2+y**2 <= d**2:
c += 1
print(c) | 0 | null | 19,341,689,826,160 | 169 | 96 |
N, K=input().split()
hp=input().split()
j = sorted([int(x) for x in hp])
print(sum([j[x] for x in range(int(N) - int(K))])) if int(K) < int(N) else print(0) | N = int(input())
S = input()
if N%2==0 and (S[:int(N//2)] == S[int(N//2):]):
print('Yes')
else:
print('No') | 0 | null | 112,954,529,215,188 | 227 | 279 |
N, K = list(map(int, input().split()))
mod = 10**9+7
ans = [0]*(K+1)
s = 0
for i in range(K, 0, -1):
ans[i] = pow(K//i, N, mod)
for j in range(2*i, K+1, i):
ans[i] -= ans[j]
s += ans[i]*i%mod
print(s%mod)
| N,K=map(int,input().split())
ans=0
mod=10**9+7
A=[0 for i in range(K)]
for i in range(K,0,-1):
l=pow(K//i,N,mod)
a=2
while a*i<=K:
l-=A[a*i-1]
a+=1
ans+=l*i%mod
ans%=mod
A[i-1]=l
print(ans) | 1 | 36,734,717,725,690 | null | 176 | 176 |
n = int(input())
s, t = input().split()
ans = ''
for si, ti in zip(s, t):
ans += si + ti
print(ans) | input()
s, t = input().split()
for i,j in zip(s,t):
print(i,j,sep='', end = '') | 1 | 112,048,223,631,920 | null | 255 | 255 |
x, n = map(int, input().split())
lis = []
if n == 0:
print(x)
else:
lis = list(map(int, input().split()))
if x not in lis:
print(x)
else:
y = x + 1
z = x - 1
while True:
if y in lis and z in lis:
y += 1
z -= 1
elif z not in lis:
print(z)
break
elif y not in lis:
print(y)
break
| h, w, n= [int(input()) for i in range(3)]
k = max(h, w)
ans = (n+k-1)//k
print(ans) | 0 | null | 51,518,863,288,884 | 128 | 236 |
import sys
input = sys.stdin.buffer.readline
import numpy as np
def main():
N,K = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
if sum(a) <= K:
print(0)
else:
a = np.array(a)
f = np.array(f)
left,right = 0,max(a)*max(f)
while right-left > 1:
mid = (left+right)//2
pra = a-mid//f
pra[pra<0] = 0
if np.sum(pra) > K:
left = mid
else:
right = mid
print(right)
if __name__ == "__main__":
main()
| def insertion_sort(A, n, g):
global cnt
for i in range(g, n):
val = A[i]
j = i - g
while j >= 0 and A[j] > val:
A[j + g] = A[j]
j = j - g
cnt += 1
A[j + g] = val
def shell_sort(A, n):
global cnt
cnt = 0
G = []
h = 1
while h <= len(A):
G.append(h)
h = 3 * h + 1
G.reverse()
print(len(G))
print(' '.join(map(str, G)))
for i in range(0, len(G)):
insertion_sort(A, n, G[i])
if __name__ == '__main__':
n = int(input())
l = [int(input()) for _ in range(n)]
shell_sort(l, n)
print(cnt)
for i in l:
print(i)
| 0 | null | 82,645,673,561,282 | 290 | 17 |
class Stack():
def __init__(self):
self.stack = [0 for _ in range(1000)]
self.top = 0
def push(self, n):
self.top += 1
self.stack[self.top] = n
def pop(self):
a = self.stack[self.top]
del self.stack[self.top]
self.top -= 1
return a
def lol(self):
return self.stack[self.top]
def main():
input_data = raw_input()
data = input_data.strip().split(" ")
st = Stack()
for l in data:
if l == "+":
a = st.pop()
b = st.pop()
st.push(a + b)
elif l == "-":
a = st.pop()
b = st.pop()
st.push(b - a)
elif l == "*":
a = st.pop()
b = st.pop()
st.push(a * b)
else:
st.push(int(l))
print st.lol()
if __name__ == '__main__':
main() | operand = ["+", "-", "*"]
src = [x if x in operand else int(x) for x in input().split(" ")]
stack = []
for s in src:
if isinstance(s, int):
stack.append(s)
continue
b, a = stack.pop(), stack.pop()
if s == "+":
stack.append(a+b)
elif s == "-":
stack.append(a-b)
elif s == "*":
stack.append(a*b)
print(stack[0]) | 1 | 36,990,472,650 | null | 18 | 18 |
def gcd(x, y):
x, y = max(x, y), min(x, y)
while y != 0:
x, y = y, x % y
return x
X, Y = (int(s) for s in input().split())
print(gcd(X, Y)) | def gcd(a,b):
if a%b==0:
return b
else :
return gcd(b,a%b)
def main():
a,b=map(int,raw_input().split())
print(gcd(a,b))
if __name__=='__main__':
main() | 1 | 8,292,540,942 | null | 11 | 11 |
n = int(input())
S = 100000
for i in range(n):
S = int(S*1.05)
slist = list(str(S))
if slist[-3:] == ['0','0','0'] :
S = S
else:
S = S - int(slist[-3])*100 - int(slist[-2])*10 - int(slist[-1])*1 + 1000
print(S)
| s = 100000
n = int(input())
for i in range(n):
s *= 1.05
if s % 1000 != 0:
s = s // 1000 * 1000 + 1000
else:
pass
print(int(s))
| 1 | 1,308,757,308 | null | 6 | 6 |
ans = 0
x, y = map(int,input().split())
ans += 100000*max((4-x),0)
ans += 100000*max((4-y),0)
if x == y == 1:
ans += 400000
print(ans) | x = input()
x = int(x)
x **= 3
print(x) | 0 | null | 70,320,780,409,438 | 275 | 35 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: D_fix
# CreatedDate: 2020-09-15 21:36:31 +0900
# LastModified: 2020-09-15 22:19:28 +0900
#
import os
import sys
# import numpy as np
# import pandas as pd
from collections import deque
class BFS():
def __init__(self, path, N):
self.N = N
self.color_path = [-1]*self.N
self.path = path
self.init = 1
self.Q = deque([[0, self.init]])
def forward(self):
while self.Q:
prev_path, u = self.Q.popleft()
p_cnt = 1
for cp, v in self.path[u]:
if self.color_path[cp] == -1:
if prev_path == p_cnt:
p_cnt += 1
self.Q.append([p_cnt, v])
self.color_path[cp] = p_cnt
p_cnt += 1
# print(self.color_path)
def print_ans(self):
self.color_path.pop(0)
print(max(self.color_path))
for cp in self.color_path:
print(cp)
def main():
N = int(input())
path = [[] for _ in range(N+1)]
for i in range(1, N):
a, b = map(int, input().split())
path[a].append([i, b])
path[b].append([i, a])
bfs = BFS(path, N)
bfs.forward()
bfs.print_ans()
if __name__ == "__main__":
main()
| from collections import deque
n=int(input())
ab=[[] for _ in range(n+1)]
for i in range(n-1):
a,b=map(int,input().split())
ab[a].append([b,i])
que=deque()
que.append(1)
visited=[0]*(n)
ans=[0]*(n-1)
while que:
x=que.popleft()
k=1
for j in ab[x]:
if visited[x-1]!=k:
ans[j[1]]+=k
visited[j[0]-1]+=k
k+=1
que.append(j[0])
else:
ans[j[1]]+=(k+1)
visited[j[0]-1]+=(k+1)
k+=2
que.append(j[0])
print(max(ans))
for l in ans:
print(l) | 1 | 136,224,687,944,100 | null | 272 | 272 |
import sys
sys.setrecursionlimit(10**8)
def ii(): 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 li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
X, Y = mi()
l = [0, 300000, 200000, 100000]
for i in range(205):
l.append(0)
ans = l[X] + l[Y]
if X==Y==1:
print(ans + 400000)
else:
print(ans) | x , y = map(int , input().split());
ans = 0;
if(x == 1):
ans += 300000;
if(x == 2):
ans += 200000;
if(x == 3):
ans += 100000;
if(y == 1):
ans += 300000;
if(y == 2):
ans += 200000;
if(y == 3):
ans += 100000;
if(x + y == 2):
ans += 400000;
print(ans) | 1 | 140,343,391,920,382 | null | 275 | 275 |
n = int(input())
A = []
B = []
for i in range(n):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if n % 2:
l = A[n // 2]
r = B[n // 2]
ans = r - l + 1
print(ans)
else:
l = A[n // 2 - 1] + A[n // 2]
r = B[n // 2 - 1] + B[n // 2]
ans = r - l + 1
print(ans)
| import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
XY = [list(mapint()) for _ in range(N)]
XY.sort(key=lambda x:x[0]+x[1])
ans_1 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1])
XY.sort(key=lambda x:x[0]-x[1])
ans_2 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1])
print(max(ans_1, ans_2)) | 0 | null | 10,426,549,425,434 | 137 | 80 |
n = int(input())
a = list(map(int, input().split()))
b = sorted(enumerate(a), key=lambda x:x[1])
c = [b[i][0]+1 for i in range(n)]
d = [str(x) for x in c]
e = " ".join(d)
print(e) | from statistics import median
X = []
X1 = []
N=int(input())
for i in range(N):
a, b = map(int, input().split())
X.append(a)
X1.append(b)
m1 = median(X)
m2 = median(X1)
if len(X) % 2:
print(int((m2 - m1) + 1))
else:
print(int(2 * (m2 - m1) + 1)) | 0 | null | 98,773,276,986,350 | 299 | 137 |
n = int(input())
for i in range(n):
l = [int(j) for j in input().split()]
l.sort()
print("YES" if l[0]**2 + l[1]**2 == l[2]**2 else "NO") | count=int(raw_input())
for i in range(0,count):
a,b,c=map(int,raw_input().split())
if pow(a,2)+pow(b,2)==pow(c,2):
print 'YES'
elif pow(a,2)+pow(c,2)==pow(b,2):
print 'YES'
elif pow(b,2)+pow(c,2)==pow(a,2):
print 'YES'
else:
print 'NO' | 1 | 298,561,252 | null | 4 | 4 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from collections import Counter
n, p = map(int, readline().split())
s = readline().rstrip().decode()
cnt = 0
if p == 2 or p == 5:
for i, ss in enumerate(s):
if int(ss) % p == 0:
cnt += (i + 1)
else:
memo = [0]
m = 0
d = 1
for ss in s[::-1]:
m += int(ss) * d
m %= p
d *= 10
d %= p
memo.append(m)
counter = Counter(memo)
for i in range(p + 1):
cnt += counter[i] * (counter[i] - 1) // 2
print(cnt)
| a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a <= b:
total_a = a + v * t
total_b = b + w * t
if total_a >= total_b:
print('YES')
else:
print('NO')
else:
total_a = a - v * t
total_b = b - w * t
if total_a <= total_b:
print('YES')
else:
print('NO') | 0 | null | 36,502,009,362,764 | 205 | 131 |
S = input()
result = 0
# 入力例1なら3文字目まで
for i in range(len(S) // 2):
# sの1(2番目)がsの最後尾と一緒ならカウント
if S[i] != S[-(i + 1)]:
result += 1
print(result) | from collections import defaultdict
def main():
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
for i, d in enumerate(S[::-1]):
if int(d) % P == 0:
ans += N - i
else:
total = defaultdict(int)
total[0] = 1
cur = 0
for i, d in enumerate(S[::-1]):
d = int(d) % P
prev = cur
cur = (prev + pow(10, i, P) * d) % P
ans += total[cur]
total[cur] += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 89,459,249,304,760 | 261 | 205 |
import sys
from collections import defaultdict
sys.setrecursionlimit(10**8)
N = int(input())
graph = [[] for _ in range(N)]
numOfEdges = [0 for _ in range(N)]
visited = [0 for _ in range(N)]
edges = defaultdict(int)
for i in range(1, N):
a, b = map(int, input().split())
a -= 1; b -= 1;
numOfEdges[a] += 1
numOfEdges[b] += 1
edges[(a, b)] = 0
graph[a].append(b)
graph[b].append(a)
def dfs(prev, now, col):
if visited[now]:
return
visited[now] = 1
i = 1
for adj in graph[now]:
if adj == prev:
continue
if now < adj:
edges[(now, adj)] = col + i
else:
edges[(adj, now)] = col + i
dfs(now, adj, col+i)
i += 1
dfs(-1, 0, 1)
maxColor = max(numOfEdges)
print(maxColor)
for k, i in edges.items():
e = i % maxColor
if e:
print(e)
else:
print(maxColor)
| #!/usr/bin/env python3
x = int(input())
for i in range(360):
k = i + 1
if x * k % 360 == 0:
print(k)
exit()
| 0 | null | 74,269,296,993,250 | 272 | 125 |
from numba import njit
@njit
def main(X):
for a in range(-200, 201):
for b in range(-200, 201):
if pow(a, 5) - pow(b, 5) == X:
print(a, b)
return
if __name__ == '__main__':
X = int(input())
main(X)
| import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
S, T = rs().split()
print(T+S)
| 0 | null | 64,113,099,491,200 | 156 | 248 |
n = int(input())
table = [0] * (n + 1)
for i in range(1, n+1):
for j in range(i, n+1, i):
table[j] += 1
ans = 0
for i in range(n+1):
ans += table[i] * i
print(ans)
| import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n = int(input())
d1_0, d2_0 = -1, -2
d1_1, d2_1 = -1, -2
d1_2, d2_2 = -1, -2
for i in range(n):
d1_2, d2_2 = d1_1, d2_1
d1_1, d2_1 = d1_0, d2_0
d1_0, d2_0 = map(int,input().split())
if d1_0 == d2_0 and d1_1 == d2_1 and d1_2 == d2_2:
print("Yes")
sys.exit()
print("No")
if __name__=='__main__':
main() | 0 | null | 6,702,411,219,068 | 118 | 72 |
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
now = A[0]
for a in A:
if now > a:
ans += now -a
if now < a:
now = a
print(ans) | l = [x+' '+y for x in ['S','H','C','D'] for y in [str(i) for i in range(1,14)]]
n = int(input())
while n > 0:
l.remove(input())
n -= 1
for i in l:
print(i) | 0 | null | 2,824,425,369,048 | 88 | 54 |
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if (arr[i] != arr[j]) and (arr[j] != arr[k]) and (arr[i] != arr[k]):
if (arr[i]+arr[j]) > arr[k]:
ans += 1
print(ans) | N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
if N >= 3 :
for i in range(0, N - 1) :
for j in range(1, N - 1 - i) :
for k in range(2, N - i):
if L[i] < L[i+j] < L[i+k] and L[i] + L[i+j] > L[i+k]:
ans += 1
print(ans) | 1 | 5,001,663,289,548 | null | 91 | 91 |
from collections import defaultdict
def main():
N = int(input())
d = defaultdict(int)
results = ["AC", "WA", "TLE", "RE"]
for _ in range(N):
d[input()] += 1
for r in results:
print(f"{r} x {d[r]}")
if __name__ == '__main__':
main()
| MOD = 10**9+7
n,k = map(int,input().split())
L = [0]*(k+1)
for i in range(k,0,-1):
L[i] = pow(k//i,n,MOD)
for j in range(2,k//i+1):
L[i] -= L[i*j]
ans = 0
for i in range(1,k+1):
ans = (ans + i*L[i]) % MOD
print(ans) | 0 | null | 22,739,163,167,628 | 109 | 176 |
#!/usr/bin/env PyPy
def main():
x = int(input())
if x >= 30:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| n = int(input())
ans, tmp = 0, 5
if n % 2 == 0:
n //= 2
while tmp <= n:
ans += n // tmp
tmp *= 5
print(ans)
| 0 | null | 60,719,026,695,200 | 95 | 258 |
n = int(input())
a = sorted(list(map(int, input().split())))
ans = a.pop()
if n % 2:
for i in range((n - 2) // 2):
ans += a.pop() * 2
ans += a.pop()
print(ans)
else:
for i in range((n - 2) // 2):
ans += a.pop() * 2
print(ans) | N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
ans = A[0]
cnt = 1
for a in A[1:]:
if cnt + 1 < N:
ans += a
cnt += 1
if cnt+ 1 < N:
ans += a
cnt += 1
print(ans)
| 1 | 9,086,768,777,500 | null | 111 | 111 |
N = int(input())
from itertools import permutations
P=tuple(map(int, input().split()))
Q=tuple(map(int, input().split()))
A=list(permutations([i for i in range(1, N+1)]))
a=A.index(P)
b=A.index(Q)
print(abs(a-b)) | n = int(input())
s = n//500
m = n%500
x = m//5
r = s*1000
c = x*5
print(r+c) | 0 | null | 71,410,214,117,660 | 246 | 185 |
import sys
L = int(input())
print((L / 3) ** 3) | def resolve():
N = int(input())
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
a = prime_factorize(N)
count_dict = {}
total_key = 0
for i in range(1024):
total_key += i
for j in range(total_key-i, total_key):
count_dict[j] = i-1
a_element_counter = {}
for i in a:
if i not in a_element_counter:
a_element_counter[i] = 0
a_element_counter[i] += 1
ans = 0
for e in a_element_counter.values():
ans += count_dict[e]
print(ans)
if __name__ == "__main__":
resolve() | 0 | null | 31,873,203,778,500 | 191 | 136 |
A,B=list(map(int,input().split()))
def gcd(A, B):
if B==0: return(A)
else: return(gcd(B, A%B))
print(gcd(A,B)) | # -*- coding: utf-8 -*-
import sys
import os
import math
a, b = list(map(int, input().split()))
# a?????§?????????????????????
if b > a:
a, b = b, a
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
result = gcd(a, b)
print(result) | 1 | 6,913,447,632 | null | 11 | 11 |
# -*- coding: utf-8 -*-
def selection_sort(A, N):
change = 0
for i in xrange(N):
minj = i
for j in xrange(i, N, 1):
if A[j] < A[minj]:
minj = j
if minj != i:
temp = A[minj]
A[minj] = A[i]
A[i] = temp
change += 1
return (A, change)
if __name__ == "__main__":
N = input()
A = map(int, raw_input().split())
result, change = selection_sort(A, N)
print ' '.join(map(str, result))
print change | num = list(map(int,input().split()))
print(num[2],num[0],num[1]) | 0 | null | 19,145,389,825,550 | 15 | 178 |
x, y, p, q = map(float, input().split())
ans = ((p-x)**2 + (q-y)**2)**0.5
print(f"{ans:.8f}")
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
s = list(input())[::-1]
res = []
now = 0
while now != n:
nex = min(now + m, n)
while s[nex] == '1':
nex -= 1
if nex == now:
print(-1)
quit()
res += [nex - now]
now = nex
print(*res[::-1]) | 0 | null | 69,762,392,220,574 | 29 | 274 |
import math
def isprime(num):
if num == 2:
return True
if num == 1 or num % 2 == 0:
return False
i = 3
for i in range(3, math.floor(math.sqrt(num))+1, 2):
if num % i == 0:
return False
return True
def count_prime_numbers(number_list):
cnt = 0
for target in number_list:
if isprime(target):
cnt += 1
return cnt
N = int(input())
A = [int(input()) for i in range(N)]
print(count_prime_numbers(A)) | import sys
mount_list = map(int, sys.stdin.readlines())
mount_list.sort(reverse=True)
for x in mount_list[:3]:
print x | 0 | null | 4,585,070,268 | 12 | 2 |
def merge(A,left,mid,right):
global cnt
n1 = mid - left
n2 = right - mid
cnt += n1+n2
L = [A[left+i] for i in range(n1)]
R = [A[mid+i] for i in range(n2)]
L.append(float("inf"))
R.append(float("inf"))
i = 0
j = 0
for k in range(left,right):
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 = int((left+right)/2)
mergesort(A,left,mid)
mergesort(A,mid,right)
merge(A,left,mid,right)
n = int(input())
A = list(map(int,input().split()))
cnt = 0
mergesort(A,0,n)
print(" ".join(map(str,A)))
print(cnt)
| N=int(input())
num_list=list(map(int,input().split(" ")))
MAX=500000
L=[None]*((MAX)//2+2)
R=[None]*((MAX)//2+2)
def merge(A,left,mid,right):
cnt=0
n1=mid-left
n2=right-mid
for i in range(n1):
L[i]=A[i+left]
for i in range(n2):
R[i]=A[i+mid]
L[n1]=(10**9+1)
R[n2]=(10**9+1)
j,k=0,0
for i in range(left,right):
cnt+=1
if L[j]<=R[k]:
A[i]=L[j]
j+=1
else:
A[i]=R[k]
k+=1
return cnt
def mergesort(A,left,right):
if left+1<right:
mid=(left+right)//2
cntL=mergesort(A,left,mid)
cntR=mergesort(A,mid,right)
return merge(A,left,mid,right)+cntL+cntR
return 0
cnt=mergesort(num_list,0,N)
print(*num_list)
print(cnt)
| 1 | 116,064,890,922 | null | 26 | 26 |
for a in range(1,10):
for b in range(1,10):
print(str(a)+"x"+str(b)+"="+str(a*b))
| N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
for i in range(N-2):
if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
print('Yes')
exit()
print('No')
| 0 | null | 1,220,585,894,880 | 1 | 72 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.