code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
import itertools
def solve():
N = int(input())
S = input()
l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
p = itertools.product(l,repeat=3)
count = 0
for v in p:
S_temp = S
dig_0_index = S_temp.find(v[0])
if dig_0_index != -1:
S_temp = S_temp[dig_0_index+1::]
dig_1_index = S_temp.find(v[1])
if dig_1_index != -1:
S_temp = S_temp[dig_1_index+1::]
dig_2_index = S_temp.find(v[2])
if dig_2_index != -1:
count += 1
print(count)
if __name__ == "__main__":
solve()
|
N=int(input())
S=input()
code=list(set(list(S)))
ans=0
for i in code:
for j in code:
for k in code:
count=0
for s in S:
if count==0:
if s==i:
count+=1
elif count==1:
if s==j:
count+=1
elif count==2:
if s==k:
count+=1
if count==3:
ans+=1
break
print(ans)
| 1 | 129,034,887,302,960 | null | 267 | 267 |
# ABC169 E
N=int(input())
AB=[tuple(map(int,input().split())) for _ in [0]*N]
def med(A):
N=len(A)
if N%2:
return A[(N+1)//2-1]
else:
return (A[N//2-1]+A[N//2])/2
A=[i[0] for i in AB]
B=[i[1] for i in AB]
medA=med(sorted(A))
medB=med(sorted(B))
if N%2:
print(medB-medA+1)
else:
print(int(2*medB-2*medA+1))
|
from statistics import median
def main():
N = int(input())
A = [None] * N
B = [None] * N
for i in range(N):
A[i], B[i] = map(int, input().split())
min_median = median(A)
max_median = median(B)
if N % 2 == 1:
print(max_median - min_median + 1)
else:
print(round((max_median-min_median)*2)+1)
if __name__ == "__main__":
main()
| 1 | 17,328,982,899,070 | null | 137 | 137 |
c = int(input())
n = 0
for i in range(1,10):
if c /i < 10 and c %i ==0:
n += 1
break
ans = 'Yes' if n >= 1 else 'No'
print(ans)
|
#a,b,c = map(int,input().split())
a = int(input())
b = input()
c = b[:a//2]
d = b[a//2:a]
print("Yes" if c == d else "No")
| 0 | null | 152,957,238,906,912 | 287 | 279 |
#!/usr/bin/env python3
n, a, b = map(int, input().split())
ans = 0
if (b-a)%2 == 0:
ans = (b-a)//2
else:
if a-1 >= n-b:
ans = n + (1-a-b)//2
else:
ans = (a+b)//2
print(int(ans))
|
s = list(map(int, input().split()))
N = s[0]
A = s[1]
B = s[2]
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A - 1,N - B) + 1 + (B - A - 1) // 2)
| 1 | 109,544,850,714,378 | null | 253 | 253 |
N=int(input())
A=list(map(int,input().split()))
ans=20202020200
sum_A=0
sum_B=sum(A)
for i in range(N):
sum_A+=A[i]
sum_B-=A[i]
tmp=abs(sum_A-sum_B)
if tmp<ans:
ans=tmp
print(ans)
|
from itertools import accumulate
N, *A = map(int, open(0).read().split())
A_acc = list(accumulate(A, initial=0))
min_diff = float("inf")
for i in range(1, N):
left, right = A_acc[i], A_acc[N] - A_acc[i]
min_diff = min(min_diff, abs(right - left))
print(min_diff)
| 1 | 141,864,565,154,110 | null | 276 | 276 |
def is_prime(n):
if n == 1:
return False
return all(n % i != 0 for i in range(2, int(n**0.5) + 1))
x = int(input())
print(min(i for i in range(x, 100004) if is_prime(i)))
|
def main():
nums = list(map(int,input().split()))
for i,n in enumerate(nums):
if n == 0:
return i + 1
if __name__ == '__main__':
print(main())
| 0 | null | 59,776,680,268,842 | 250 | 126 |
n = int(input())
L = list(map(int,input().split()))
print(min(L),max(L),sum(L))
|
n = int(input())
array = list(map(int, input().split()))
total = 0
for i in range(n):
total += array[i]
array.sort()
print(array[0], array[-1], total)
| 1 | 716,594,634,840 | null | 48 | 48 |
import math
A,B,H,M = map(int,input().split())
x = abs((60*H+M)*0.5 - M*6)
theta = math.radians(x)
L = (A**2+B**2-2*A*B*math.cos(theta))**(1/2)
print(L)
|
import math
a, b, h, m = map(int, input().split())
minute = 60 * h + m
argA = minute / 720 * 2 * math.pi
argB = minute / 60 * 2 * math.pi
a_x = a * math.cos(argA)
a_y = a * math.sin(argA)
b_x = b * math.cos(argB)
b_y = b * math.sin(argB)
d = math.sqrt((a_x - b_x) ** 2 + (a_y - b_y) ** 2)
print(d)
| 1 | 20,201,737,428,312 | null | 144 | 144 |
import sys
#import math
# input = sys.stdin.readline
def binary_search(arr, key,j):
ok = j
ng = len(arr)
while abs(ok - ng) > 1:
mid = int((ok + ng) / 2)
if arr[mid] < key:
ok = mid
else:
ng = mid
return ok
def main():
N = int(input())
L = sorted(list(map(int, input().split())))
ans =0
for i in range(N-2):
for j in range(i+1,N-1):
ok = binary_search(L,L[i]+L[j],j)
ans += ok-j
print(ans)
if __name__ == "__main__":
main()
|
#それゆけにぶたんまん
#python3.8.2のTLEの壁に阻まれました
n = int(input())
l = sorted(list(map(int,input().split())))
ans = 0
for i in range(n):
for j in range(i+1,n):
#jより大きい整数kでl[k]<l[i]+l[j]を満たす最大のk
le = j
ri = n
while ri-le>1:
m = (ri+le)//2
if l[m]<l[i]+l[j]:
le = m
else:
ri = m
ans += le-j
print(ans)
| 1 | 171,883,499,290,260 | null | 294 | 294 |
s=input()
k=int(input())
cnt=1
temp=[]
for i in range(len(s)-1):
if s[i]==s[i+1]: cnt+=1
else:
temp.append([s[i],cnt])
cnt=1
if cnt>=1: temp.append([s[-1],cnt])
if len(temp)==1:
print(k*len(s)//2)
exit()
ans=0
if temp[0][0]!=temp[-1][0]:
for pair in temp:
if pair[1]!=1: ans+=pair[1]//2
print(ans*k)
else:
for pair in temp[1:-1]:
if pair[1]!=1: ans+=pair[1]//2
ans*=k
ans+=(k-1)*((temp[0][1]+temp[-1][1])//2)
ans+=temp[0][1]//2+temp[-1][1]//2
print(ans)
|
import math
PI = math.pi
r = input()
men = r*r * PI
sen = r*2 * PI
print('%.6f %.6f' % (men, sen))
| 0 | null | 88,022,963,022,774 | 296 | 46 |
l,r,d=map(int,input().split())
if l%d!=0:
ans=(r//d)-(l//d)
else:
ans=(r//d)-(l//d)+1
print(ans)
|
K,N = map(int,input().split())
A = list(map(int,input().split()))
tmin = 2*K
for i in range(1,N):
tmin = min(tmin,K-(A[i]-A[i-1]))
tmin = min(tmin,A[N-1]-A[0])
print(tmin)
| 0 | null | 25,323,764,475,958 | 104 | 186 |
from collections import Counter
S = input()
C = Counter()
MOD = 2019
n = 0
for i, s in enumerate(S[::-1]):
s = int(s)
n += pow(10, i, MOD) * s % MOD
C[n % MOD] += 1
C[0] += 1
ans = 0
for v in C.values():
ans += v * (v - 1) // 2
print(ans)
|
s = input()
res = 0
m = 1
p =[0]*2019
for i in map(int,s[::-1]):
res +=i*m
res %=2019
p[res] +=1
m *=10
m %=2019
print(p[0]+sum([i*(i-1)//2 for i in p]))
| 1 | 30,923,170,464,050 | null | 166 | 166 |
n = int(input())
n_ = n-1
a = [n]
if n_ == 1:
a_ = []
else:
a_ = [n_]
for i in range(2,int(n**0.5//1+1)):
if n%i == 0:
a.append(i)
if n/i != i:
a.append(n/i)
if n_%i == 0:
a_.append(i)
if n_/i != i:
a_.append(n_/i)
ans = len(a_)
for i in a:
num = n
while num%i == 0:
num /= i
if num % i == 1:
ans += 1
print(ans)
|
n = int(input())
# 例外処理
if n == 2:
print(1)
exit()
if n == 3:
print(2)
exit()
# n % k = 1 の数
m = n - 1
i = 2
ans = 1
while i * i <= m:
if m % i == 0:
num = 1
while m % i == 0:
num += 1
m //= i
ans *= num
i = i + 1
if m != 1:
ans *= 2
ans -= 1
# n % k = 0 の場合
# nを素因数分解する
m = n
import numpy as np
i = 2
factor = []
while i * i <= n:
if n % i == 0:
l = []
num = 1
l.append(num)
while n % i == 0:
num *= i
l.append(num)
n //= i
factor.append(np.array(l))
i = i + 1
if n > 1:
factor.append(np.array([1, n]))
# 直積を求めることでnの全約数を得る
divisor = factor[-1]
for i in range(len(factor) - 1):
divisor = np.outer(divisor, factor[i])
divisor = np.outer(np.array(1), divisor)
# 判定
for i in divisor[0]:
if i == 1:
continue
n = m
while n % i == 0:
n //= i
if n % i == 1:
ans += 1
print(ans)
| 1 | 41,462,314,622,070 | null | 183 | 183 |
x = int(input())
y = int(input())
z = int(input())
a = max(x,y)
if z%a == 0:
print(z//a)
else:
print(z//a+1)
|
import math
H = int(input())
W = int(input())
N = int(input())
Big = W if W > H else H
print(math.ceil(N / Big))
| 1 | 88,690,245,396,522 | null | 236 | 236 |
def solve():
N, X, M = map(int,input().split())
past_a = {X}
A = [X]
ans = prev = X
for i in range(1, min(M,N)):
next_a = prev ** 2 % M
if next_a in past_a:
loop_start = A.index(next_a)
loop_end = i
loop_size = loop_end - loop_start
loop_elem = A[loop_start:loop_end]
rest_n = N-i
ans += rest_n // loop_size * sum(loop_elem)
ans += sum(loop_elem[:rest_n%loop_size])
break
ans += next_a
past_a.add(next_a)
A.append(next_a)
prev = next_a
print(ans)
if __name__ == '__main__':
solve()
|
def check(m):
global n, k, w, presum
s = 0
for j in range(k):
ok = s
ng = n + 1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if presum[mid] - presum[s] <= m:
ok = mid
else:
ng = mid
s = ok
if s == n:
return True
else:
return False
def resolve():
global n, k, w, presum
n, k = [int(i) for i in input().split()]
w = [int(input()) for _ in range(n)]
presum = [0 for _ in range(n + 1)]
for i in range(n):
presum[i + 1] = presum[i] + w[i]
if n <= k:
print(max(w))
return
ok = 100000 * 10000
ng = 0
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if check(mid):
ok = mid
else:
ng = mid
print(ok)
resolve()
| 0 | null | 1,458,714,413,100 | 75 | 24 |
import math
k = int(input())
sum = 0
for a in range(1,k+1):
for b in range(1,k+1):
x = math.gcd(a, b)
for c in range(1,k+1):
sum += math.gcd(x, c)
print(sum)
|
import math
K = int(input())
g = []
for i in range(1, K+1):
for j in range(1, K+1):
g.append(math.gcd(i, j))
result = 0
for i in range(1, K+1):
for t in g:
result += math.gcd(i, t)
print(result)
| 1 | 35,610,277,627,400 | null | 174 | 174 |
n,m=map(int,input().split())
ps=[list(input().split()) for _ in range(m)]
wa=[0]*n
w=0
ac=0
d=[0]*n
for p,s in ps:
if s=='WA':
if d[int(p)-1]==0:
wa[int(p)-1]+=1
else:
if d[int(p)-1]==0:
ac+=1
d[int(p)-1]=1
w+=wa[int(p)-1]
print(ac,w)
|
while 1 :
try:
h,w=map(int,input().split())
#print(h,w)
if( h==0 and w==0 ):
break
else:
for hi in range(h):
print("#" * w)
print() #??????
if( h==0 and w==0 ): break
except (EOFError):
#print("EOFError")
break
| 0 | null | 47,160,713,907,200 | 240 | 49 |
n, m = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(m)]
ans = [-1]*n
flag = False
for s, c in X:
if ans[s-1] >= 0 and ans[s-1] != c:
flag = True
if n > 1 and s == 1 and c == 0:
flag = True
else:
ans[s-1] = c
if flag:
print(-1)
exit(0)
for i in range(n):
if ans[i] == -1:
if n > 1 and i == 0:
ans[i] = 1
else:
ans[i] = 0
print(*ans, sep="")
|
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
for j in range(N - 1, i, -1):
if A[j] < A[j-1]:
A[j], A[j - 1] = A[j -1], A[j]
count += 1
print(*A)
print(count)
| 0 | null | 30,269,594,122,250 | 208 | 14 |
X, N = map(int, input().split())
p_list = list(map(int, input().split()))
if N == 0:
print(X)
else:
for i in range(0,100):
if not X-i in p_list:
print(X-i)
break
elif not X+i in p_list:
print(X+i)
break
|
l = input().split()
print(l[2], l[0], l[1])
| 0 | null | 25,910,667,313,440 | 128 | 178 |
a = int(input())
if a == 0:
print("1")
else:
print("0")
|
import sys
input = sys.stdin.readline
def main():
H, W, K = map(int, input().split())
stro = []; remain = K
start = H; end = 0
idx = 0
ans = []
for i in range(H):
tmp = list(input()[:-1])
cnt = 0
for j in tmp:
cnt += j == '#'
stro.append(cnt)
remain -= cnt
if cnt > 0:
start = min(start, i)
end = max(end, i)
if cnt == 1:
idx += 1
ans.append([idx]*W)
elif cnt >= 2:
idx += 1
cnttmp = 0
anstmp = []
for j in tmp:
cnttmp += j=='#'
idx += (cnttmp != 1 and j == '#' and cnt > 0)
cnt -= (j == '#' and cnt > 0)*1
anstmp.append(idx)
ans.append(anstmp)
else:
if remain == K:
continue
anstmp = ans[-1].copy()
ans.append(anstmp)
for _ in range(start):
print(*ans[0])
for i in range(len(ans)):
print(*ans[i])
if __name__ == "__main__":
main()
| 0 | null | 73,510,632,474,752 | 76 | 277 |
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
n = ini()
s = list(ins())
n = s.count("R")
t = sorted(s)
ans = 0
for i in range(n):
if s[i] != t[i]:
ans += 1
print(ans)
|
N = int(input())
x = input().strip()
cnt = 0
for i in range(N):
if x[i]=="R":
cnt += 1
if cnt==0 or cnt==N:
print(0)
else:
ans = 0
for i in range(cnt):
if x[i]=="W":
ans += 1
print(ans)
| 1 | 6,264,646,450,400 | null | 98 | 98 |
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
B=[int(input()) for _ in range(N)]
S=[[0,0,0] for _ in range(3)]
for b in B:
for i in range(3):
if b in A[i]:
S[i][A[i].index(b)] = 1
break
p = False
for a in S:
if sum(a)==3:
p = True
break
if not p:
for i in range(3):
if S[0][i]+S[1][i]+S[2][i]==3:
p = True
break
if not p:
if S[0][0]+S[1][1]+S[2][2]==3 or S[2][0]+S[1][1]+S[0][2]==3:
p=True
print("Yes" if p else "No")
|
from collections import defaultdict
dic = defaultdict(list)
for i in range(3):
a = list(map(int,input().split()))
for j in range(3):
dic[a[j]].append([i,j])
n = int(input())
B = []
for _ in range(n):
b = int(input())
B.append(b)
h = [0]*3
w = [0]*3
d = 0
di = 0
for b in B:
if b not in dic:
continue
x,y = dic[b][0]
if x== y:
d += 1
if x + y ==2:
di += 1
h[x] += 1
w[y] += 1
for i in range(3):
if h[i]==3 or w[i]==3:
print('Yes');exit()
if d ==3 or di ==3:
print('Yes');exit()
print('No')
| 1 | 59,850,527,076,622 | null | 207 | 207 |
r = float(input())
pi = 3.141592653589
S = r * r * pi
L = 2 * r * pi
print(str(S) + " " + str(L))
|
N = int(input())
ans = 0
for i in range(N):
Y = int(N/(i+1))
ans += Y * (Y + 1) * (i + 1) // 2
print(ans)
| 0 | null | 5,894,293,144,250 | 46 | 118 |
from collections import Counter
N = int(input())
S = input()
c = Counter(S)
ans = c['R'] * c['G'] * c['B']
for s in range(N-2):
for d in range(1, (N-1-s)//2+1):
t = s + d
u = t + d
if S[s] != S[t] and S[t] != S[u] and S[u] != S[s]:
ans -= 1
print(ans)
|
L = int(input(""))
a = L / 3.0
print(pow(a,3))
| 0 | null | 41,319,150,062,752 | 175 | 191 |
n=int(input())
ans=1000*((n+999)//1000)-n
print(ans)
|
n=int(input())
if n%1000!=0:
print(1000-n%1000)
else:
print(0)
| 1 | 8,423,797,153,652 | null | 108 | 108 |
n = int(input())
x = list(map(int, input().split()))
mini = min(x)
maxi = max(x)
summ = sum(x)
print(mini, maxi, summ)
|
print input()^1
| 0 | null | 1,862,914,433,030 | 48 | 76 |
N = int(input())
count = 0
for i in range(1,N+1):
if i % 2 == 1:
count += 1
else:
pass
print(count/N)
|
from math import gcd
def readinput():
n,m=map(int,input().split())
a=list(map(int,input().split()))
return n,m,a
def lcm(a,b):
return a*b//gcd(a,b)
def main(n,m,a):
#s=set(a)
#print(s)
x=a[0]//2
for i in range(1,n):
x=lcm(x,a[i]//2)
#print(x)
gusubai=False
kisubai=False
for i in range(n):
if x%a[i]!=0:
gusubai=True
else:
kisubai=True
y=m//x
#print(y,x,m)
if gusubai and not kisubai:
ans=y//2+y%2
elif gusubai and kisubai:
ans=0
else:
ans=y
return ans
if __name__=='__main__':
n,m,a=readinput()
ans=main(n,m,a)
print(ans)
| 0 | null | 138,967,217,513,890 | 297 | 247 |
G = []
cnt = 0
def insertionSort(A, n, g):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
global cnt
cnt += 1
A[j+g] = A[j]
j -= g
A[j+g] = v
def shellSort(n, A):
m = 1
while m <= n / 9:
m = m * 3 + 1
while 0 < m:
global G
G.append(m)
insertionSort(A, n, m)
m = int(m / 3)
A = []
n = int(input())
for i in range(n):
A.append(int(input()))
shellSort(n, A)
print(len(G))
print(*G)
print(cnt)
for i in range(n):
print(A[i])
|
S = input()
ans = 'No'
if (S[2] == S[3]) and (S[4] == S[5]):
ans = 'Yes'
print(ans)
| 0 | null | 21,064,096,638,628 | 17 | 184 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
H, A = map(int, readline().split())
print((H + A - 1) // A)
if __name__ == '__main__':
main()
|
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): 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)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
A, B, N = I()
print(math.floor(A*min(B-1,N)/B))
| 0 | null | 52,702,560,239,780 | 225 | 161 |
i = count = 0
a = b = c = ''
line = input()
while line[i] != ' ':
a = a + line[i]
i += 1
i += 1
while line[i] != ' ':
b = b + line[i]
i += 1
i += 1
while i < len(line):
c = c + line[i]
i += 1
a = int(a)
b = int(b)
c = int(c)
while a <= b:
if c%a == 0:
count += 1
a += 1
print(count)
|
N, M = map(int, input().split())
S = ['a'] * (N+1)
for i in range(M):
s, c = list(map(int, input().split()))
if S[s] != 'a' and S[s] != str(c):
print(-1)
exit()
S[s] = str(c)
if S[1] == '0' and N > 1:
print(-1)
exit()
for i in range(1, N+1):
if S[i] == 'a':
if i == 1 and N > 1:
S[i] = '1'
else:
S[i] = '0'
print(int(''.join(S[1:])))
| 0 | null | 30,861,949,800,516 | 44 | 208 |
mod=1000000007
n,k=map(int, input().split())
lst=list(map(int, input().split()))
lst=sorted(lst)
p=1
if lst[-1]==0 and k%2!=0:
print(0)
elif lst[-1]<0 and k%2!=0:
for i in range(n-1,n-k-1,-1):
#print(p)
p=(p%mod*lst[i]%mod)%mod
#print(p)
print(p%mod)
else:
j=n-1
if k%2!=0:
p*=lst[j]
k-=1
j-=1
k=k//2
i=0
for x in range(k):
if lst[i]*lst[i+1]>lst[j]*lst[j-1]:
p=(p%mod*lst[i]%mod*lst[i+1]%mod)%mod
i+=2
else:
p=(p%mod*lst[j]%mod*lst[j-1]%mod)%mod
j-=2
#print(p)
print(p%mod)
|
#coding: utf-8
n, k = map(int, input().split())
pkt = list()
for i in range(n):
pkt.append(int(input()))
lenpkt = len(pkt)
def maxPkt(payload):
maxPnum = 0
for i in range(k):
tempPL = 0
while tempPL + pkt[maxPnum] <= payload:
tempPL += pkt[maxPnum]
maxPnum += 1
if maxPnum == lenpkt:
return True
return False
lft = 0
mid = 0
rgt = 100000 * 10000
while lft < rgt:
mid = (lft + rgt) // 2
if maxPkt(mid):
rgt = mid
else:
lft = mid + 1
print(rgt)
| 0 | null | 4,713,527,135,520 | 112 | 24 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def isok(bs, RT):
return True if bs <= RT else False
def search(B, RT):
left = -1
right = M+1
while right-left>1:
mid = left+(right-left)//2
if isok(B[mid], RT):
left = mid
else:
right = mid
return left
def solve():
asum = [0]*(N+1)
bsum = [0]*(M+1)
for i in range(N):
asum[i+1]=asum[i]+A[i]
for i in range(M):
bsum[i+1]=bsum[i]+B[i]
ans = 0
for i in range(N+1):
RT = K-asum[i]
if RT < 0:
break
ans = max(ans, i+search(bsum, RT))
print(ans)
if __name__ == '__main__':
solve()
|
n,m,k = map(int,input().split())
shelfA = list(map(int,input().split()))
shelfB = list(map(int,input().split()))
prodA = [0]*(n+1)
prodB = [0]*(m+1)
for i in range(1,n+1):
prodA[i] = prodA[i-1] + shelfA[i-1]
for i in range(1,m+1):
prodB[i] = prodB[i-1] + shelfB[i-1]
ans = -1
j = m
for i in range(n+1):
if(prodA[i]>k):
break
while(prodB[j] > k - prodA[i]):
# print(prodB[j],j,k-prodA[i])
j-=1
# print(ans)
ans = max(ans,i+j)
print(ans)
| 1 | 10,825,815,176,348 | null | 117 | 117 |
#!/usr/bin/env python3
import sys
def solve(N: int, T: int, A: "List[int]", B: "List[int]"):
dp = [0] * (T + 1)
for a, b in sorted(zip(A, B), reverse=True):
for t in range(T):
dp[t] = max(dp[t],
b + (dp[t+a] if t + a < T else 0))
return max(dp)
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
T = int(next(tokens)) # type: int
A = [int()] * (N) # type: "List[int]"
B = [int()] * (N) # type: "List[int]"
for i in range(N):
A[i] = int(next(tokens))
B[i] = int(next(tokens))
print(solve(N, T, A, B))
if __name__ == '__main__':
main()
|
import sys
input = sys.stdin.readline
N, T = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort()
dp0 = [0] * T # finish eating by time j
dp1 = [0] * T # order by time j
for A, B in AB:
for j in range(T):
dp1[j] = max(dp1[j], dp0[j] + B)
for j in range(A, T)[::-1]:
dp0[j] = max(dp0[j], dp0[j-A] + B)
print(dp1[-1])
| 1 | 151,556,661,270,212 | null | 282 | 282 |
X, Y, A, B, C = [int(_) for _ in input().split()]
P = [int(_) * 3 for _ in input().split()]
Q = [int(_) * 3 + 1 for _ in input().split()]
R = [int(_) * 3 + 2 for _ in input().split()]
S = sorted(P + Q + R)
cnt = [0, 0, 0]
ans = [0, 0, 0]
limit = [X, Y, 10**10]
while S:
s = S.pop()
q, r = divmod(s, 3)
if cnt[r] >= limit[r]:
continue
cnt[r] += 1
ans[r] += q
if sum(cnt) == X + Y:
print(sum(ans))
exit()
|
def main():
x,k,d = map(int,input().split(" "))
if abs(x) % d == 0:
exceed_num = (abs(x) // d)
else:
exceed_num = (abs(x) // d) + 1
if k <= exceed_num :
print(abs( abs(x) - (d*k) ))
else:
if (k - exceed_num) % 2 == 0:
print(abs( abs(x) - (d*exceed_num) ))
else:
print(abs( abs(x) - (d*(exceed_num-1) )))
if __name__ == '__main__':
main()
| 0 | null | 25,100,850,490,252 | 188 | 92 |
from math import *
a,b,x=map(int,input().split())
x=x/a
if x<=a*b/2:
t=2*x/b
c=sqrt(b**2+t**2)
ans=90-degrees(asin(t/c))
else:
t=2*(a*b-x)/a
c=sqrt(a**2+t**2)
ans=90-degrees(asin(a/c))
print(ans)
|
def f(u, i, d, t, vis):
if vis[u]:
return
vis[u] = True
z = t[u]
c = 1
for v in z:
if vis[v]:
continue
if c == i:
c += 1
d[u].update({v: c})
f(v, c, d, t, vis)
c += 1
def main():
from collections import defaultdict
import sys
sys.setrecursionlimit(100000)
n = int(input())
t = [[] for _ in range(n + 1)]
m = []
for _ in range(n - 1):
i, j = map(int, input().split())
t[i].append(j)
t[j].append(i)
m.append([i, j])
d = defaultdict(dict)
vis = [False for _ in range(n + 1)]
f(1, len(t[1]) + 1, d, t, vis)
ans = ''
if t.count([]) == n:
ans += str(n - 1) + '\n'
else:
ans += str(max(len(i) for i in t)) + '\n'
for (u, v) in m:
ans += str(d[u][v]) + '\n'
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 149,656,127,873,580 | 289 | 272 |
import sys
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.buffer.readline
INF = 10**12
N, M, L = map(int, input().split())
G = np.zeros((N, N), dtype=np.int64)
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1
b -= 1
G[a][b] = c
G[b][a] = c
Q = int(input())
ST = [list(map(int, input().split())) for _ in range(Q)]
fw = floyd_warshall(G)
path = np.full((N, N), INF, dtype=np.int64)
path[fw <= L] = 1
path_fw = (floyd_warshall(path) + 0.5).astype(np.int64)
ans = []
for s, t in ST:
s -= 1
t -= 1
if path_fw[s][t] >= INF:
ans.append(-1)
continue
ans.append(path_fw[s][t]-1)
print(*ans, sep="\n")
|
for a in iter(input,'0'):print(sum([int(s)for s in a]))
| 0 | null | 87,772,586,746,700 | 295 | 62 |
import sys
input = sys.stdin.buffer.readline
def gcd(a: int, b: int) -> int:
"""a, bの最大公約数(greatest common divisor: GCD)を求める
計算量: O(log(min(a, b)))
"""
while b:
a, b = b, a % b
return a
def multi_gcd(array: list) -> int:
"""arrayのGCDを求める"""
n = len(array)
ans = array[0]
for i in range(1, n):
ans = gcd(ans, array[i])
return ans
def make_mindiv_table(n):
mindiv = [i for i in range(n + 1)]
for i in range(2, int(n ** 0.5) + 1):
if mindiv[i] != i:
continue
for j in range(2 * i, n + 1, i):
mindiv[j] = min(mindiv[j], i)
return mindiv
def get_prime_factors(num):
res = []
while mindiv[num] != 1:
res.append(mindiv[num])
num //= mindiv[num]
return res
n = int(input())
a = list(map(int, input().split()))
mindiv = make_mindiv_table(10 ** 6)
set_primes = set()
flag = True
for val in a:
set_ = set(get_prime_factors(val))
for v in set_:
if v in set_primes:
flag = False
set_primes.add(v)
if not flag:
break
else:
print("pairwise coprime")
exit()
gcd_ = multi_gcd(a)
if gcd_ == 1:
print("setwise coprime")
exit()
print("not coprime")
|
from math import gcd
N = int(input())
num_lis = list(map(int, input().split()))
c1 = True #setwise
c2 = True #pairwise
def osa_k(max_num):
lis = [i for i in range(max_num+1)]
p = 2
while p**2 <= max_num:
if lis[p] == p:
for q in range(2*p, max_num+1, p):
if lis[q] == q:
lis[q] = p
p += 1
return lis
hoge = 0
for i in num_lis:
hoge = gcd(hoge, i)
if hoge > 1:
c1 = False
if c1:
d_lis = osa_k(max(num_lis))
tmp = set()
for i in num_lis:
num = i
new_tmp = set()
while num > 1:
d = d_lis[num]
new_tmp.add(d)
num //= d
for j in new_tmp:
if j in tmp:
c2 = False
break
else:
tmp.add(j)
else:
continue
break
else:
c2 = False
if c2:
print("pairwise coprime")
elif c1:
print("setwise coprime")
else:
print("not coprime")
| 1 | 4,131,283,414,412 | null | 85 | 85 |
while True:
H, W = [int(x) for x in input().split(" ")]
if H == 0 and W == 0: exit()
for i in (range(H)):
print("#"*W)
print("")
|
while True:
x,y = map(int,raw_input().split())
if x==0:
break
else:
for i in xrange(x):
print y*"#"
print ""
| 1 | 776,612,716,042 | null | 49 | 49 |
import math
while True :
n = int(input())
if n==0:
break;
i = list(map(int, input().split(' ')))
avg = sum(i)/n
j = list(map(lambda x: (x-avg)**2, i))
print("{:.5f}".format(math.sqrt(sum(j)/n)))
|
def comb(n):
if n <= 1:
return 0
return n * (n - 1) // 2
def check(L):
r = {}
a = 0
c = 0
for i in range(len(L)):
if a != L[i]:
if i != 0:
r[a] = [comb(c), comb(c - 1)]
a = L[i]
c = 1
else:
c += 1
r[a] = [comb(c), comb(c - 1)]
#print(r)
return r
N = int(input())
A = [int(n) for n in input().split(" ")]
D = {}
for i in range(len(A)):
D[i] = A[i]
D = sorted(D.items(), key=lambda x: x[1])
V = {}
for i in range(len(D)):
V[D[i][0]] = i
AA = sorted(A)
rr = check(AA)
ss = 0
for k, v in rr.items():
ss += v[0]
#print(ss)
for k in range(N):
index = A[k]
a = rr[index][0] - rr[index][1]
print(ss - a)
| 0 | null | 24,104,950,909,788 | 31 | 192 |
import math
d=100
for _ in[0]*int(input()):d=math.ceil(d*1.05)
print(int(d*1e3))
|
import numpy as np
from numba import njit
@njit #処理の並列化_これがない場合は'TLE'
def imos(n, a):
l=np.zeros((n+1), dtype = np.int64)
for i in range(n):
ai = a[i] # 光の強さ_これにより照らせる範囲が決まる
start = max(0, i - ai) #StartIndex_照らせる範囲
end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲
l[start] += 1 # 各々を'+1'と'-1'で表し...
l[end] -= 1
return np.cumsum(l)[:n] # 累積和をとる_cumulative sum
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
a = imos(n, a)
if a.min() == n: # すべての要素が最大値'n'になるとbreak
break
print(*a)
| 0 | null | 7,768,995,840,100 | 6 | 132 |
N = int(input())
A = sorted(list(map(int,input().split())))
ans = A[0]
if ans == 0:
print(ans)
exit()
else:
for i in range(1,N):
ans = ans * A[i]
if ans > 10**18:
ans = -1
break
print(ans)
|
n = int(input())
lst = list(map(int,input().split()))
lst = sorted(lst)
ans = 1
for i in range (n):
ans = ans*lst[i]
if (ans > 10**18):
ans = -1
break
print(ans)
| 1 | 16,220,889,803,690 | null | 134 | 134 |
def main():
N = int(input())
A = [[i for i in input().split()] for j in range(N)]
X = input()
ans = 0
flag = False
for a, b in A:
if a == X:
flag = True
continue
if flag:
ans += int(b)
print(ans)
if __name__ == '__main__':
main()
|
n = int(input())
s = [input().split() for i in range(n)]
b = sum([int(s[i][1]) for i in range(n)])
x = input()
c = 0
for i in range(n):
c+=int(s[i][1])
if s[i][0] == x:
break
print(b-c)
| 1 | 96,469,047,330,616 | null | 243 | 243 |
# -*- coding: utf-8 -*-
input_list = input().split()
stack = list()
for i in input_list:
if i.isdigit():
stack.append(int(i))
else:
b = stack.pop()
a = stack.pop()
if i == '+':
stack.append(a + b)
elif i == '-':
stack.append(a - b)
elif i == '*':
stack.append(a * b)
print(stack.pop())
|
operators = ['+', '-', '*', '/']
stack = list(input().split())
# stack = list(open('input.txt').readline().split())
def calc(ope):
c = stack.pop()
a = c if c not in operators else calc(c)
c = stack.pop()
b = c if c not in operators else calc(c)
return str(eval(b+ope+a))
print(calc(stack.pop()))
| 1 | 35,984,333,450 | null | 18 | 18 |
X = int(input())
facts = [0]
n = 1
while True:
facts.append(n ** 5)
if facts[-1] - facts[-2] > X:
break
n += 1
facts = set(facts)
for f0 in facts:
f1 = None
if abs(f0 - X) in facts:
f1 = abs(f0 - X)
r0 = int(f0 ** 0.2)
r1 = int(f1 ** 0.2)
if f0 - f1 == X:
print(r0, r1)
else:
print(r0, -r1)
break
|
def main():
X = int(input())
for i in range(-1000, 1000):
for j in range(-1000, 1000):
if i ** 5 - j ** 5 == X:
print(i, j)
return
main()
| 1 | 25,617,967,860,380 | null | 156 | 156 |
def mod_inverse(x, mod):
return pow(x, mod - 2, mod)
# return nCk % mod
# it takes O(k)
def mod_comb(n, k, mod):
numer, denom = 1, 1
for i in range(k):
numer = numer * ((n - i) % mod) % mod
denom = denom * ((i + 1) % mod) % mod
return numer * mod_inverse(denom, mod) % mod
mod = 10**9 + 7
n, a, b = map(int, input().split())
ans = pow(2, n, mod) - 1
ans = (ans - mod_comb(n, a, mod)) % mod
ans = (ans - mod_comb(n, b, mod)) % mod
ans = (ans + mod) % mod
print(ans)
|
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
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
n = ni()
ans = len(make_divisors(n-1))-1
ls = make_divisors(n)[1:]
for i in ls:
nn = n
while nn%i == 0:
nn = nn//i
if nn%i == 1:
ans += 1
print(ans)
| 0 | null | 53,897,374,185,330 | 214 | 183 |
x=int(input())
x+=1
print(x%2)
|
N = int(input())
print(1 - N)
| 1 | 2,909,997,642,260 | null | 76 | 76 |
n, x, m = map(int,input().split())
amari = [0]*m
v = [x]
cnt = 0
while True:
xn_1 = x**2%m
cnt += 1
if x == 0:
break
amari[x] = xn_1
if amari[xn_1]:
break
v.append(xn_1)
x = xn_1
#print(v)
if 0 in v:
ans = sum(v)
else:
ind = v.index(xn_1)
rooplen = len(v) - ind
ans = sum(v[0:ind])
l = n-ind
if rooplen:
ans += (l//rooplen)*sum(v[ind:])
nokori = l - rooplen*(l//rooplen)
ans += sum(v[ind:ind+nokori])
#print(v)
print(ans)
|
r, c = map(int, input().split())
tabl = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
print(" ".join(map(str, tabl[i])) + " " + str(sum(tabl[i])))
ss = ""
for i in range(c):
ans = 0
for j in range(r):
ans += tabl[j][i]
ss += str(ans) + " "
print(ss+str(sum([int(i) for i in ss.split()])))
| 0 | null | 2,066,885,486,332 | 75 | 59 |
import math
n=int(input())
x=math.ceil(n/1.08)
if(math.floor(1.08*x)==n):
ans=x
else:
ans=str(":(")
print(ans)
|
n = int(input())
X_MAX = 50001
for x in range(X_MAX):
if int(x * 1.08) == n:
print(x)
exit()
print(":(")
| 1 | 125,288,236,934,322 | null | 265 | 265 |
k = int(input())
a,b = map(int,input().split())
n = range(k,1001,k)
if any(a <= i and i <= b for i in n):
print('OK')
else:
print('NG')
|
k = int(input())
a, b = map(int,input().split())
flg = False
for i in range(a, b+1):
if i % k == 0:
flg = True
break
print('OK') if flg else print('NG')
| 1 | 26,757,461,423,228 | null | 158 | 158 |
N = int(input())
A = list(map(int, input().split()))
t = [-1] * (N + 1)
t[0] = 1000
for i in range(N):
k = t[i] // A[i]
y = t[i] % A[i]
for j in range(i, N):
t[j + 1] = max(t[j + 1], k * A[j] + y)
print(t[N])
|
n = int(input())
A = [0] + [*map(int, input().split())]
dp_stock = [0]*(n+1)
dp_yen = [0]*(n+1)
dp_yen[0] = 1000
for day in range(1, n+1):
dp_stock[day] = max(dp_stock[day-1], dp_yen[day-1] // A[day])
remain = dp_yen[day-1] - dp_stock[day-1]*A[day-1]
dp_yen[day] = max(dp_yen[day-1], remain + dp_stock[day-1] * A[day])
print(dp_yen[n])
| 1 | 7,313,783,047,152 | null | 103 | 103 |
x = raw_input()
print int(x) ** 3
|
print((lambda x : x**3)(int(input())))
| 1 | 277,479,345,990 | null | 35 | 35 |
num = int(input())
k = input().split()
for i in range(len(k)):
k[i] = int(k[i])
k.sort()
mul = 1
for i in range(num):
mul *= int(k[i])
if mul > 10**18:
break
if mul > 10**18:
print(-1)
else:
print(mul)
|
n, *a = map(int, open(0).read().split())
a.sort()
if a[0] == 0:
print(0)
exit()
b = 1
for c in a:
b *= c
if b > 10 ** 18:
print(-1)
exit()
print(b)
| 1 | 16,109,509,546,690 | null | 134 | 134 |
n = int(input())
ans = (n + 1) * n // 2
for i in range(2, n + 1):
j = 1
while i * j <= n:
ans += i * j
j += 1
print(ans)
|
from math import gcd
from math import factorial as f
from math import ceil,floor,sqrt
import bisect
import re
import heapq
from copy import deepcopy
import itertools
from sys import exit
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
yes = "unsafe"
no = "safe"
def main():
s,w = mi()
if w>=s:
print(yes)
else:
print(no)
main()
| 0 | null | 20,123,689,783,580 | 118 | 163 |
a, b = map(int, raw_input().split())
print ("%d %d" % (a * b, 2 * (a + b)))
|
import sys
sys.setrecursionlimit(10**7)
def dfs(x):
if seen[x-1]==0:
uni[cnt].add(x)
seen[x-1]=1
for i in fri[x-1]:
dfs(i)
n,m,k=map(int,input().split())
fri=[[] for i in range(n)]
blk=[set() for i in range(n)]
for i in range(m):
a,b=map(int,input().split())
fri[a-1].append(b)
fri[b-1].append(a)
for i in range(k):
c,d=map(int,input().split())
blk[c-1].add(d)
blk[d-1].add(c)
seen=[0 for i in range(n)]
uni=[]
cnt=0
for i in range(1,n+1):
if seen[i-1]==0:
uni.append(set())
dfs(i)
cnt+=1
seq=[0 for i in range(n)]
for unii in uni:
for j in unii:
cj=len(unii)-len(fri[j-1])-len(unii&blk[j-1])-1
seq[j-1]=cj
print(*seq)
| 0 | null | 30,833,331,175,420 | 36 | 209 |
n,m = map(int, input().split())
ink = list(map(int, input().split()))
ink.sort()
array = [0 for i in range(n+1)]
array[1] = 1
for i in range(2, n+1):
if i in ink:
array[i] = 1
else:
mini = i
for j in ink[::-1]:
if j < i:
if mini > 1 + array[i-j]:
mini = 1 + array[i-j]
array[i] = mini
print(array[n])
|
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect
MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 8)
n, m = map(int, input().split())
c = list(map(int, input().split()))
dp = [[INF] * (n + 10) for _ in range(m + 10)]
for i in range(m+10):
dp[i][0] = 0
for i in range(1, n + 1):
if i % c[0] == 0:
dp[1][i] = i // c[0]
for i in range(2, m + 1):
for j in range(1, n + 1):
if j - c[i - 1] >= 0:
dp[i][j] = min(dp[i-1][j], dp[i][j - c[i - 1]] + 1)
else:
dp[i][j] = dp[i-1][j]
print(dp[m][n])
| 1 | 136,788,393,218 | null | 28 | 28 |
def main():
from sys import setrecursionlimit, stdin, stderr
from os import environ
from collections import defaultdict, deque, Counter
from math import ceil, floor
from itertools import accumulate, combinations, combinations_with_replacement
setrecursionlimit(10**6)
dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
input = lambda: stdin.readline().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
P = 10**9+7
INF = 10**18+10
K = II()
S = input()
N = len(S)
def gencmb(n,k):
# N-1+K C K ... N-1 C 0
ans = [1]*(k+1)
for i in range(1,k+1):
ans[-i-1] = ans[-i] * (N+i-1) * pow(i,P-2,P) % P
return ans
ans = 0
pow26 = [0] * (K+1)
pow26[0] = 1
for i in range(1,K+1):
pow26[i] = pow26[i-1] * 26 % P
pow25 = [0] * (K+1)
pow25[0] = 1
for i in range(1,K+1):
pow25[i] = pow25[i-1] * 25 % P
cmb = gencmb(N,K)
for t in range(K+1):
ans += pow26[t]*pow25[K-t]*cmb[t]%P
ans %= P
print(ans)
main()
|
import sys
K = int(sys.stdin.readline())
M = len(sys.stdin.readline())-1
N = K+M
mod = 10**9+7
ans = pow(26, N, mod)
class Data():
def __init__(self):
self.power = 1
self.rev = 1
class Combi():
def __init__(self, N, mod):
self.lists = [Data() for _ in range(N+1)]
self.mod = mod
for i in range(2, N+1):
self.lists[i].power = ((self.lists[i-1].power)*i) % self.mod
self.lists[N].rev = pow(self.lists[N].power, self.mod-2, self.mod)
for j in range(N, 0, -1):
self.lists[j-1].rev = ((self.lists[j].rev)*j) % self.mod
def combi(self, K, R):
if K < R:
return 0
else:
return ((self.lists[K].power)*(self.lists[K-R].rev)*(self.lists[R].rev)) % self.mod
X = Combi(N, mod)
for i in range(M):
ans -= X.combi(N, i)*pow(25, N-i, mod)
ans %= mod
print(ans)
| 1 | 12,803,489,273,872 | null | 124 | 124 |
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n,T=map(int,input().split())
AB=[tuple(map(int,input().split())) for _ in range(n)]
AB.sort()
dp=[0]*T
ans=0
for a,b in AB:
ndp=dp[:]
for t in range(T):
if(t+a<T):
ndp[t+a]=max(ndp[t+a],dp[t]+b)
else:
ans=max(ans,dp[t]+b)
dp=ndp
print(ans)
resolve()
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, t = LI()
ab = sorted(LIR(n))
dp = [0] * t
ans = 0
for a, b in ab:
ans = max(ans, dp[-1] + b)
for i in range(a, t)[::-1]:
dp[i] = max(dp[i], dp[i - a] + b)
print(ans)
| 1 | 151,733,944,064,714 | null | 282 | 282 |
a = list(map(int, input().split()))
print(max((a[0] * a[2]),(a[0] * a[3]),(a[1] * a[3]),(a[1] * a[2])))
|
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
Ques = [ list(map(int, input().split())) for _ in range(Q) ]
Nums = [ i for i in range(M) ]
ans = -1
for v in combinations_with_replacement(Nums, N):
cnt = 0
for que in Ques:
if v[que[1]-1]-v[que[0]-1] == que[2]: cnt += que[3]
ans = max(ans, cnt)
print(ans)
| 0 | null | 15,223,780,255,808 | 77 | 160 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
print(('#' * W + '\n') * H)
|
# -*- coding:utf-8 -*-
def reac(H,W):
for i in range(H):
for l in range(W):
print('#',end='')
print('')
data = []
while True:
try:
di = input()
if di == '0 0':
break
data.append(di)
except:
break
for i in range(len(data)):
x = data[i]
h = x.split()
reac(int(h[0]),int(h[1]))
print('')
| 1 | 755,552,727,932 | null | 49 | 49 |
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
H,W = LI()
S = [S() for _ in range(H)]
dp = [[float('INF')]*W for _ in range(H)]
for i,j in itertools.product(range(H),range(W)):
if i==0:
if j==0:
dp[i][j] = 1 if S[i][j]=='#' else 0
else:
dp[i][j] = dp[i][j-1]+(1 if S[i][j]=='#' and S[i][j-1]=='.' else 0)
else:
if i==0:
dp[i][j] = dp[i-1][j]+(1 if S[i][j]=='#' and S[i-1][j]=='.' else 0)
else:
dp[i][j] = min(dp[i][j],dp[i][j-1]+(1 if S[i][j]=='#' and S[i][j-1]=='.' else 0))
dp[i][j] = min(dp[i][j],dp[i-1][j]+(1 if S[i][j]=='#' and S[i-1][j]=='.' else 0))
print(dp[-1][-1])
|
def resolve():
'''
code here
'''
import collections
import numpy as np
H, W = [int(item) for item in input().split()]
grid = [[item for item in input()] for _ in range(H)]
dp = [[300 for _ in range(W+1)] for _ in range(H+1)]
for i in range(H):
for j in range(W):
if i == 0 and j == 0:
if grid[0][0] == '#':
dp[i+1][j+1] = 1
else:
dp[i+1][j+1] = 0
else:
add_v = 0
add_h = 0
if grid[i][j] != grid[i][j-1]:
add_h = 1
if grid[i][j] != grid[i-1][j]:
add_v = 1
dp[i+1][j+1] = min(dp[i+1][j]+add_h, dp[i][j+1]+add_v)
# print(dp)
if grid[H-1][W-1] == '#':
print(dp[H][W]//2+1)
else:
print(dp[H][W]//2)
if __name__ == "__main__":
resolve()
| 1 | 49,386,068,426,240 | null | 194 | 194 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))
sum = 0
a_num = 0
for i in range(N):
sum += a_time[i]
a_num += 1
if sum > K:
sum -= a_time[i]
a_num -= 1
break
i = a_num
j = 0
while i >= 0:
while sum < K and j < M:
sum += b_time[j]
j += 1
if sum > K:
j -= 1
sum -= b_time[j]
if result < i + j:
result = i + j
i -= 1
sum -= a_time[i]
print(result)
|
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
b = 0
tb = 0
for i in range(M):
if tb + B[i] > K:
break
tb += B[i]
b = i+1
ans = [0, b]
m = b
a = 0
ta = 0
for i in range(N):
if ta + A[i] > K:
break
a = i+1
ta += A[i]
while True:
if ta + tb > K:
if b == 0:break
b -= 1
tb -= B[b]
else:
if a + b > m:
m = a + b
ans = [a, b]
break
print(ans[0]+ans[1])
| 1 | 10,665,574,377,014 | null | 117 | 117 |
N,K=map(int,input().split())
H=list(map(int,input().split()))
H.sort()
ans=0
if N-K>0:
for x in range(N-K):
ans += H[x]
print(ans)
|
S = input()
i = 0
print(S[i]+S[i+1]+S[i+2])
| 0 | null | 46,728,646,747,838 | 227 | 130 |
S = input()
T = input()
ans = 1001
for i in range(len(S)-len(T)+1):
ans = min(ans, sum(S[i+j] != T[j] for j in range(len(T))))
print(ans)
|
while True:
a = input()
if '?' in a:
break
print("%d" % eval(a))
| 0 | null | 2,158,600,502,618 | 82 | 47 |
n = int(input())
num = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ans = 'No'
for i in range(len(num)):
for s in range(len(num)):
if num[i] * num[s] == n:
ans = 'Yes'
break
print(ans)
|
N = int(input())
for i in range(1,10):
for j in range(1,10):
if i * j == N:
print("Yes")
exit(0)
else:
print("No")
| 1 | 160,287,956,435,178 | null | 287 | 287 |
from collections import deque
S = deque(input())
n = int(input())
Q = [list(map(str, input().split())) for _ in range(n)]
flg = True
for q in Q:
if q[0] == "1":
flg = not flg
else:
F = int(q[1])
if not flg:
F = 3 - F
if F == 1:
S.appendleft(q[2])
if F == 2:
S.append(q[2])
if not flg:
S.reverse()
print("".join(S))
|
S=list(input())
T=list(input())
total = 0
for i in range(len(S)):
if S[i] == T[i]:
continue
else:
total += 1
print(str(total))
| 0 | null | 33,917,831,059,798 | 204 | 116 |
#coding: UTF-8
l = raw_input().split()
a = int(l[0])
b = int(l[1])
if 1 <= a and b <= 10**9:
d = a / b
r = a % b
f = float (a )/ b
print "%d %d %f" %(d, r, f)
|
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
N,M,L=map(int,input().split())
INF = 1 << 31
dist=np.array([[INF for _ in range(N)] for _ in range(N)])
for i in range(N):
dist[i][i]=0
for i in range(M):
a,b,c=map(int,input().split())
a-=1
b-=1
dist[a][b]=c
dist[b][a]=c
dist = floyd_warshall(dist)
for i in range(N):
for j in range(N):
if dist[i][j]<=L:
dist[i][j]=1
else:
dist[i][j]=INF
dist = floyd_warshall(dist)
dist[dist==INF]=0
#dist=dist.astype(int)
#print(dist)
Q=int(input())
ans=[0]*Q
for q in range(Q):
s,t=map(int,input().split())
s-=1
t-=1
ans[q]=int(dist[s][t]-1)
print(*ans,sep='\n')
| 0 | null | 87,059,371,304,810 | 45 | 295 |
# -*- coding: utf-8 -*-
import sys
def gcd(a, b):
if a < b:
a, b = b, a
while b!=0:
c = b
b = a % b
a = c
return a
def lcm(a, b, g):
return a * b / g
def main():
for line in sys.stdin:
a, b = map(int, line.split())
ng = gcd(a, b)
nl = lcm(a, b, ng)
print('{0:d} {1:d}'.format(int(ng), int(nl)))
if __name__ == '__main__':
main()
|
#!/usr/bin/python
import sys
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b, a%b)
def lcm(a,b):
return a / gcd(a,b) * b
for l in sys.stdin:
a = [int(s) for s in l.split()]
print str(gcd(a[0],a[1]))+" "+str(lcm(a[0],a[1]))
| 1 | 780,688,272 | null | 5 | 5 |
def ok(a,b,c):
return (a*a+b*b==c*c)
n=input()
for i in range(n):
a,b,c=map(int,raw_input().split())
if(ok(a,b,c) or ok(b,c,a) or ok(c,a,b)):
print "YES"
else:
print "NO"
|
def resolve():
n = int(input())
ans = 'No'
for i in range(1,10):
for j in range(1,10):
if i*j == n:
ans = 'Yes'
print(ans)
resolve()
| 0 | null | 80,286,231,010,790 | 4 | 287 |
def culc(x):
a = x % 10
b = x
while x:
b = x
x //= 10
return a, b
n = int(input())
l = [[0 for i in range(9)] for j in range(9)]
ans = 0
for i in range(1,n+1):
a,b = culc(i)
if a != 0 and b != 0:
l[a-1][b-1] += 1
for i in range(1,n+1):
a,b = culc(i)
if a != 0 and b != 0:
ans += l[b-1][a-1]
print(ans)
|
import numpy as np
H, W = map(int, input().split())
masu = [input() for i in range(H)]
#temp = [list(input().replace("#","0").replace(".","1")) for i in range(H)]
#masu = [[int(temp[i][j]) for j in range(W)] for i in range(H)]
#dp = np.zeros((H, W))
dp = [[0]*W for i in range(H)]
if masu[0][0] == "#":
dp[0][0] = 1
for i in range(0,H):
for j in range(0,W):
if i == 0:
a = 100000
else:
if masu[i][j] == "#" and masu[i-1][j] == ".":
a = dp[i-1][j] + 1
else:
a = dp[i-1][j]
if j == 0:
b = 100000
else:
if masu[i][j] == "#" and masu[i][j-1] == ".":
b = dp[i][j-1] + 1
else:
b = dp[i][j-1]
if a != 100000 or b != 100000:
dp[i][j] = min([a, b])
print(int(dp[H-1][W-1]))
| 0 | null | 67,649,352,234,680 | 234 | 194 |
A = int(input())
print(int((A-1)/2))
|
N=int(input())
cnt=0
for i in range(int(N/2)):
if (i+1)!=(N-i-1):
cnt+=1
print(cnt)
| 1 | 153,163,632,630,688 | null | 283 | 283 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
ok=10**15
ng=-1
while ok-ng>1:
check=(ok+ng)//2
cnt=0
for i in range(n):
cnt+=(max(0,a[i]-check//f[i]))
if cnt > k:ng = (ok+ng)//2
else: ok = (ok+ng)//2
print(ok)
|
from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))
a_count = Counter(a_input)
score_dic={}
exclude_dic={}
for k,v in a_count.items():
score_dic[k]=v*(v-1)//2
exclude_dic[k]=(v-1)*(v-2)//2
score_sum = sum(score_dic.values())
for i in range(n):
print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])
| 0 | null | 106,025,856,257,632 | 290 | 192 |
N=str(input())
n=len(N)
K=int(input())
dp0=[[0]*(K+1) for _ in range(n+1)]
dp1=[[0]*(K+1) for _ in range(n+1)]
for l in range(1,n+1):
dp0[l][0]=1
dp1[0][0]=1
for i in range(n):
for j in range(K):
if N[i]=='0':
dp0[i+1][j+1]=9*dp0[i][j]+dp0[i][j+1]
dp1[i+1][j+1]=dp1[i][j+1]
else:
dp0[i+1][j+1]=dp0[i][j]*9+dp0[i][j+1]+dp1[i][j]*(int(N[i])-1)+dp1[i][j+1]
dp1[i+1][j+1]=dp1[i][j]
print(dp0[n][K]+dp1[n][K])
|
N = int(input())
S = input()
assert len(S) == N
count = 0
# j-i = k-jを探す
for i in range(0, len(S)-2):
for j in range(i+1, len(S)-1):
k = j + (j - i)
if k < len(S):
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
count += 1
numR = 0
numG = 0
numB = 0
for s in S:
if s == 'R':
numR += 1
elif s == 'G':
numG += 1
else:
numB += 1
print(numR * numG * numB - count)
| 0 | null | 55,996,417,692,170 | 224 | 175 |
H, A = map(int, input().split())
total = H // A
if H % A != 0:
print(total+1)
else:
print(total)
|
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
H, A = read_ints()
return H//A + (1 if H%A != 0 else 0)
if __name__ == '__main__':
print(solve())
| 1 | 76,763,772,951,912 | null | 225 | 225 |
K=int(input())
L=len(input())
from numba import*
@njit(cache=1)
def f():
m=10**9+7
max_n=2*10**6
fac=[1]*(max_n+1)
inv=[1]*(max_n+1)
ifac=[1]*(max_n+1)
for n in range(2,max_n+1):
fac[n]=(fac[n-1]*n)%m
inv[n]=m-inv[m%n]*(m//n)%m
ifac[n]=(ifac[n-1]*inv[n])%m
d=[1]*(K+1)
d2=[1]*(K+1)
for i in range(K):
d[i+1]=d[i]*25%m
d2[i+1]=d2[i]*26%m
a=0
for i in range(K+1):
a=(a+fac[L+i-1]*ifac[i]%m*ifac[L-1]%m*d[i]%m*d2[K-i]%m)%m
return a
print(f())
|
k = int(input())
s = input()
L = len(s)
mod = 10**9+7
MAX = 2*10**6
fact = [1]*(MAX+1)
for i in range(1, MAX+1):
fact[i] = (fact[i-1]*i) % mod
inv = [1]*(MAX+1)
for i in range(2, MAX+1):
inv[i] = inv[mod % i]*(mod-mod//i) % mod
fact_inv = [1]*(MAX+1)
for i in range(1, MAX+1):
fact_inv[i] = fact_inv[i-1] * inv[i] % mod
def comb(n, k):
if n < k:
return 0
return fact[n] * fact_inv[n-k] * fact_inv[k] % mod
p25 = [1]*(k+1)
p26 = [1]*(k+1)
for i in range(k):
p25[i+1] = p25[i]*25%mod
p26[i+1] = p26[i]*26%mod
ans = 0
for p in range(k+1):
chk = p25[p]*comb(L-1+p,L-1)%mod
chk *= p26[k-p]%mod
ans += chk
ans %= mod
print(ans)
| 1 | 12,869,881,780,800 | null | 124 | 124 |
import math as m
def plot(x,y):
print(f'{x:.8f} {y:.8f}')
def koch(n,x1,y1,x2,y2):
if n==0:
plot(x1,y1)
return
sx=(2*x1+x2)/3
sy=(2*y1+y2)/3
tx=(x1+2*x2)/3
ty=(y1+2*y2)/3
ux=(tx-sx)*m.cos(m.radians(60))-(ty-sy)*m.sin(m.radians(60))+sx
uy=(tx-sx)*m.sin(m.radians(60))+(ty-sy)*m.cos(m.radians(60))+sy
koch(n-1,x1,y1,sx,sy)
koch(n-1,sx,sy,ux,uy)
koch(n-1,ux,uy,tx,ty)
koch(n-1,tx,ty,x2,y2)
n=int(input())
koch(n,0,0,100,0)
plot(100,0)
|
def func(num, div):
return num // div
l, r, d = map(int, input().split())
print(func(r, d) - func(l - 1, d))
| 0 | null | 3,789,512,154,880 | 27 | 104 |
NUM_CONTESTS = 26
def main():
D = int(input())
c_list = list(map(int, input().split()))
s_list = [list(map(int, input().split())) for _ in range(D)]
t_list = [int(input()) for _ in range(D)]
v_list = calc_score_list(s_list, c_list, t_list)
for v in v_list:
print(v)
def calc_score_list(s_list, c_list, t_list):
last = [-1 for _ in range(NUM_CONTESTS)]
score_list = []
score = 0
for d, t in enumerate(t_list):
last[t - 1] = d
score += s_list[d][t - 1] - sum([c * (d - l) for c, l in zip(c_list, last)])
score_list.append(score)
return score_list
if __name__ == "__main__":
main()
|
import numpy as np
#基本入力
D = int(input())
c =list(map(int,input().split()))
s = []
for i in range(D):
s.append(list(map(int,input().split())))
t = []
for i in range(D):
t.append(int(input()))
#基本入力完了
#得点計算
c = np.array(c)
last_day = np.array([0]*26)
day_pulse = np.array([1]*26)
s = np.array(s)
t = np.array(t)
manzoku = 0
for day in range(1,D+1):
contest_number = t[day-1] #開催するコンテスト種類
manzoku += s[day-1,contest_number-1] #開催したコンテストによる満足度上昇
last_day += day_pulse #経過日数の計算
last_day[contest_number -1 ] = 0 #開催したコンテスト種類の経過日数を0に
manzoku -= sum(c*last_day) #開催していないコンテストによる満足度の減少
print(manzoku)
| 1 | 9,850,298,583,616 | null | 114 | 114 |
# coding: utf-8
# Your code here!
a,b=map(int,input().split())
if (1<=a<=9) and (1<=b<=9):
print(a*b)
else:
print(-1)
|
import random
def Nickname():
Name = str(input()) #入力回数を決める
num = random.randint(0, len(Name) - 3)
print(Name[num:num+3])
if __name__ == '__main__':
Nickname()
| 0 | null | 86,051,390,625,178 | 286 | 130 |
n, k = map(int, input().split())
l = list(int(input()) for i in range(n))
left = max(l)-1; right = sum(l)
while left+1 < right: #最大値と合計値の間のどこかに考えるべき値が存在する
mid = (left + right) // 2
cnt = 1; cur = 0 #初期化
for a in l:
if mid < cur + a:
cur = a
cnt += 1
else:
cur += a
if cnt <= k:
right = mid
else:
left = mid
print(right)
|
#!/usr/bin/env python3
import sys
import math
np = ":("
def solve(N: int):
ans = math.ceil(N/ 108 * 100)
if math.floor(ans * 1.08) != N:
print(np)
else:
print(ans)
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == '__main__':
main()
| 0 | null | 62,644,531,636,352 | 24 | 265 |
def main():
N = int(input())
A_ls = map(int, input().split(' '))
ls = [0] * N
for i in A_ls:
ls[i - 1] += 1
for i in ls:
print(i)
if __name__ == '__main__':
main()
|
n=int(input())
if n%2==1:
print(str(((n-1)/2+1)/n)+"\n")
else:
print(str(1/2)+"\n")
| 0 | null | 105,155,813,618,570 | 169 | 297 |
n,m = map(int,input().split())
s = input()
ans = []
p = n
flag = 1
while flag:
for j in range(m,0,-1):
if p-j<=0:
ans.append(p)
flag = 0
break
elif s[p-j]=='0':
ans.append(j)
p-=j
break
elif j == 1:
ans.append(-1)
flag = 0
break
print(' '.join(map(str,reversed(ans))) if ans[-1]!=-1 else -1)
|
a=int(input())
b=int(input())
ans = set()
ans.add(a)
ans.add(b)
all = {1,2,3}
print((all-ans).pop())
| 0 | null | 124,490,812,002,440 | 274 | 254 |
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readlines
infty = 2 ** 20
lines = input()
n, m = list(map(int, lines[0].split()))
coin = list(map(int, lines[1].split()))
T = [[0] * (n+1) for i in range(m+1)]
#0行目の初期化
for i in range(1, n+1):
T[0][i] = infty
#0列目の初期化
for i in range(m+1):
T[i][0] = 0
#1行目の初期化
for i in range(1, n+1):
T[1][i] = i
cnt = 0
for i in range(1, m+1):
if coin[i-1] > n:
continue
else:
cnt += 1
for j in range(1, n+1):
if j < coin[i-1]:
T[i][j] = T[i-1][j]
else:
a = T[i-1][j] ; b = T[i][j-coin[i-1]]+1
if a < b:
T[i][j] = a
else:
T[i][j] = b
print(T[cnt][n])
|
n, m = map(int, input().split())
c = list(map(int, input().split()))
dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 and j == 0:
dp[i][j] = 0
elif i == 0:
dp[i][j] = 1000000000
elif j == 0:
dp[i][j] = 0
else:
if j - c[i - 1] >= 0:
dp[i][j] = min(dp[i - 1][j], dp[i][j - c[i - 1]] + 1)
else:
dp[i][j] = dp[i - 1][j]
ans = 10 ** 10
for i in range(m + 1):
ans = min(ans, dp[i][n])
print(ans)
| 1 | 138,361,110,340 | null | 28 | 28 |
import sys
inf_val = 10**10
m, n = map(int, sys.stdin.readline().split())
numbers = map(int, sys.stdin.readline().split())
dp = [inf_val]*(m+1)
dp[0] = 0
for x in numbers:
for y in xrange(x, m+1):
dp[y] = min(dp[y-x]+1, dp[y])
print dp[m]
|
INF = 100 ** 7
def main():
n, m = map(int, input().split())
c_list = list(map(int, input().split()))
dp = [INF] * (n + 1)
dp[0] = 0
for c in c_list:
for i in range(len(dp)):
if dp[i] != INF and i + c < len(dp):
dp[i + c] = min(dp[i + c], dp[i] + 1)
print(dp[n])
if __name__ == '__main__':
main()
| 1 | 144,399,233,640 | null | 28 | 28 |
n = int(input())
X = [int(x) for x in input().split()]
Y = [int(y) for y in input().split()]
d1 = 0
d2 = 0
d3 = 0
Di = []
for i in range(n) :
d1 += abs(X[i] - Y[i])
print(f"{d1:.6f}")
for i in range(n) :
d2 += abs(X[i] - Y[i]) ** 2
print(f"{(d2)**(1/2):.6f}")
for i in range(n) :
d3 += abs(X[i] - Y[i]) ** 3
print(f"{(d3)**(1/3):.6f}")
for i in range(n) :
Di.append(abs(X[i] - Y[i]))
print(f"{max(Di):.6f}")
|
import math
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p=[1,2,3,math.inf]
p1=0
p2=0
p3=0
p4=0
#p=1
for i in range(n):
p1+=(abs(a[i]-b[i]))
print("{:10f}".format(p1))
#p=2
q=0
for i in range(n):
q+=((abs(a[i]-b[i]))**2)
p2=math.sqrt(q)
print("{:10f}".format(p2))
#3
q=0
for i in range(n):
q+=((abs(a[i]-b[i]))**3)
p3=q**(1/3)
print("{:10f}".format(p3))
#inf
q=0
for i in range(n):
q=(abs(a[i]-b[i]))
if q>p4:
p4=q
print("{:10f}".format(p4))
| 1 | 214,343,788,000 | null | 32 | 32 |
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(K):
TEMP = [0]*(N+1)
for j in range(N):
TEMP[max(0,j-A[j])] +=1
TEMP[min(N,j+A[j]+1)] -=1
A = list(itertools.accumulate(TEMP))
if A[0] == N and A[N-1] == N:
break
A.pop()
print(*A)
|
t=int(input())
count = 0
flag = False
for test in range(t):
a,b = map(int,input().split())
if a==b:
count+=1
if count==3:
flag=True
else:
count=0
if flag:
print("Yes")
else:
print("No")
| 0 | null | 8,880,555,331,308 | 132 | 72 |
import math
def prime_array(n=1000):
List = [2]
i = 3
while i <= n:
judge = True
for k in List :
if math.sqrt(i) < k :
break
if i%k == 0:
judge = False
break
if judge :
List.append(i)
i += 2
return List
def main():
cnt=0
prime_List=prime_array(10**4)
n=input()
for i in range(n):
a=input()
if a<=10**4:
for j in prime_List:
if a==j:
cnt+=1
break
else:
judge=True
for j in prime_List:
if a%j==0:
judge=False
break
if judge:
cnt+=1
print('%d' % cnt)
if __name__=='__main__':
main()
|
def isPrime(num):
flag = True
if(num==1):
return False
for i in range(2,int(num**0.5)+1):
if(num%i==0):
flag = False
break
return flag
a = []
temp = 0
n = int(input().strip())
for i in range(n):
temp = int(input().strip())
if isPrime(temp):
a.append(temp)
print(len(a))
| 1 | 10,159,417,206 | null | 12 | 12 |
import math
a,b,c = [float(s) for s in input().split()]
r = c * math.pi / 180
h = math.sin(r) * b
s = a * h / 2
x1 = a
y1 = 0
if c == 90:
x2 = 0
else:
x2 = math.cos(r) * b
y2 = h
d = math.sqrt((math.fabs(x1 - x2) ** 2) + (math.fabs(y1 - y2) ** 2))
l = a + b + d
print(s)
print(l)
print(h)
|
S = input()
count = 0
if S[2] == S[3]:
count+=1
if S[4] == S[5]:
count+=1
if count == 2:
print('Yes')
else:
print('No')
| 0 | null | 20,982,467,612,532 | 30 | 184 |
N , K = input().split()
if (int(N) <= 10) :
print (100 * (10 - int(N)) + int(K))
else :
print (K)
|
n, dr = list(map(int, input().split()))
if n >= 10:
print(dr)
else:
print(dr+(100*(10-n)))
| 1 | 63,211,070,719,260 | null | 211 | 211 |
x, y = map(int, input().split())
msg = 'No'
for a in range(1, x+1):
if 2*a + 4*(x-a) == y or 4*a + 2*(x-a) == y:
msg = 'Yes'
print(msg)
|
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
a, v = rl()
b, w = rl()
t = ri()
d = abs(a - b)
s = v - w
if t * s >= d:
print ("YES")
else:
print ("NO")
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| 0 | null | 14,299,232,770,080 | 127 | 131 |
# Pythonのスライスは最後が開区間だから癖がある
t = input()
for i in range(int(input())):
cmd = list(input().split())
cmd[1] = int(cmd[1])
cmd[2] = int(cmd[2])
if cmd[0] == "print":
print(t[cmd[1] : cmd[2]] + t[cmd[2]])
elif cmd[0] == "reverse":
tmp = t[cmd[1] : cmd[2]] + t[cmd[2]]
tmp = tmp[::-1]
t = t[:cmd[1]] + tmp + t[cmd[2]+1:]
elif cmd[0] == "replace":
t = t[:cmd[1]] + cmd[3] + t[cmd[2]+1:]
|
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])
| 1 | 2,090,049,645,420 | null | 68 | 68 |
n, a, b = map(int,input().split())
ans = 0
if a >= n:
ans = n
elif a+b >= n:
ans = a
else:
set_ab = n//(a+b)
ans += set_ab*a
n -= set_ab*(a+b)
if n < a:
ans += n
else:
ans += a
print(ans)
|
N, A, B = map(int, input().split())
pair = N // (A + B)
remain = N % (A + B)
if remain > A:
print(A * pair + A)
else:
print(A * pair + remain)
| 1 | 55,680,414,211,808 | null | 202 | 202 |
[K, N] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
t = K - A[N-1] + A[0]
for i in range(N-1):
if t < A[i+1] - A[i]:
t = A[i+1] - A[i]
print(K-t)
|
K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = 0
del_A = []
for i in range(N):
if(i==(N-1)):
del_A.append(A[0]+K-A[i])
else:
del_A.append(A[i+1]-A[i])
print(sum(del_A)-max(del_A))
| 1 | 43,676,281,570,700 | null | 186 | 186 |
import sys
line = input()
if(line[2]==line[3] and line[4]==line[5]):
print("Yes")
sys.exit()
print("No")
|
import sys
input = sys.stdin.readline
def main():
S = input().strip()
assert len(S) == 6
print("Yes") if S[2] == S[3] and S[4] == S[5] else print("No")
if __name__ == '__main__':
main()
| 1 | 41,791,444,062,800 | null | 184 | 184 |
n = int(input())
A = list()
for i in range(0, n):
A.append(int(input()))
G = [1] # G[0]????????¨?????????
cnt = 0
# G[i] = 3*Gi-1 + 1
for i in range(1, 100):
h = 4**i + 3*2**(i-1) + 1
if(h > n): # h???n?¶???????????????§?????????4n+3*2n-1+1
m = i
break
else:
G.append(h)
for g in reversed(G):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
print(m)
print(" ".join(str(x) for x in reversed(G)))
print(cnt)
print("\n".join(str(x) for x in A))
|
def insertion_sort(array, size, gap=1):
""" AOJ??¬??¶?????¬???
http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_A
:param array: ?????????????±??????????
:return: ?????????????????????
"""
global Count
for i in range(gap, len(array)): # i????¬??????????????????????????????????
v = array[i] # ?????¨?????\???????????¨????????????????????????????????´???
j = i - gap
while j >= 0 and array[j] > v:
array[j + gap] = array[j]
j = j - gap
Count += 1
array[j + gap] = v
return array
def shell_sort(array, n):
Count = 0
G = calc_gap(n)
m = len(G)
print(m)
print(' '.join(map(str, G)))
for i in range(0, m):
insertion_sort(array, n, G[i])
def calc_gap(n):
results = [1]
while results[-1] < n:
results.append(3 * results[-1] + 1)
if len(results) > 1:
results = results[:-1]
results.sort(reverse=True)
return results
Count = 0
if __name__ == '__main__':
# ??????????????\???
# data = [5, 1, 4, 3, 2]
data = []
num = int(input())
for i in range(num):
data.append(int(input()))
# ???????????????
shell_sort(data, len(data))
# ???????????¨???
print(Count)
for i in data:
print(i)
| 1 | 29,587,706,220 | null | 17 | 17 |
if __name__ == "__main__":
num_list =map( int, raw_input().split())
print num_list[0] * num_list[1],
print 2 * ( num_list[0] + num_list[1] )
|
n = raw_input()
a = n.split(" ")
b = int(a[0])
c = int(a[1])
print b*c ,(b+c)*2
| 1 | 305,578,215,360 | null | 36 | 36 |
a, b = input().split()
a = int(a)
b1, b2 = b.split('.')
b = int(b1 + b2)
print(a * b // 100)
|
import math
a, b = map(float, input().split())
a = int(a)
b = int(round(b * 100))
ans = a * b
ans = ans // 100
print(ans)
| 1 | 16,495,857,668,512 | null | 135 | 135 |
N = 26
D = int(input())
C = [int(i) for i in input().split()]
S = []
for i in range(D):
s = [int(i) for i in input().split()]
S.append(s)
SUM = 0
L = [0] * 26
T = []
for i in range(D):
t = int(input())
T.append(t-1)
for i in range(D):
d = i + 1
for j in range(N):
if j == T[i]:
SUM += S[i][j]
L[j] = d
else:
SUM -= C[j] * (d - L[j])
else:
print(SUM)
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
A = A[::-1]
X = sum(A)
Y = 1/4/M
ans = 'Yes'
for i in range(M):
if A[i]/X < Y:
ans = 'No'
print(ans)
| 0 | null | 24,274,108,025,778 | 114 | 179 |
#atcoder template
def main():
import sys
imput = sys.stdin.readline
#文字列入力の時は上記はerrorとなる。
#ここにコード
#input
N, S = map(int, input().split())
A = list(map(int, input().split()))
#output
mod = 998244353
dp = [[0] * ( S+1) for _ in range(N+1)]
#dp[i, j]を、A[0]...A[i]までを使って、Tの空でない部分集合
#{x_1, x_2, ..., x_k}であって、Ax_1 + A_x_2 + ... + A_x_k = jを満たすものの個数とする。
dp[0][0] = 1
#iまででjが作られている時、i+1ではA[i]がどのような値であっても、部分集合としてjは作れる。
#iまででjが作られない時、j-A[i]が作られていれば、A[i]を足せばjは作れる。
for i in range(N):
for j in range(S+1):
dp[i+1][j] += dp[i][j] * 2
dp[i+1][j] %= mod
if j >= A[i]:
dp[i+1][j] += dp[i][j-A[i]]
dp[i+1][j] %= mod
print(dp[N][S] % mod)
#N = 1のときなどcorner caseを確認!
if __name__ == "__main__":
main()
|
import numpy as np
mod = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
for num, a in enumerate(A):
double = DP * 2
shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
DP = double + shift
DP[a] += pow(2, num, mod)
DP %= mod
print(DP[s])
| 1 | 17,628,119,527,710 | null | 138 | 138 |
inData = int(input())
inSeries = [int(i) for i in input().split()]
outData =[0]*inData
for i in range(inData):
outData[i] = inSeries[inData-1-i]
print(" ".join(map(str,outData)))
|
# -*- coding: utf-8 -*-
n = input()
l = map(int, raw_input().split())
for i in range(n-1):
print l[n-i-1],
print l[0]
| 1 | 989,371,413,014 | null | 53 | 53 |
from collections import defaultdict
def gcd(x, y):
r = x % y
while r:
x, y, r = y, r, y%r
return y
def main():
n = int(input())
al = defaultdict(lambda: 0)
All = 0
mod = 1000000007
goods = dict()
for i in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
All += 1
elif b == 0:
al["inf"] += 1
goods["inf"] = "0"
elif a == 0:
al["0"] += 1
goods["0"] = "inf"
else:
g = gcd(b, a)
a_key = f"{a//g},{b//g}"
if b//g < 0:
good = f"{-b//g},{a//g}"
else:
good = f"{b//g},{-a//g}"
goods[a_key] = good
al[a_key] += 1
ans = 1
al = dict(al)
done = set()
ok = 0
for k, v in al.items():
if k in done:
continue
num = al.get(goods[k])
done.add(goods[k])
if num:
ans *= pow(2, num, mod)+pow(2, v, mod)-1
ans %= mod
else:
ok += v
ans *= pow(2, ok, mod)
ans += All - 1
ans %= mod
print(ans)
if __name__ == "__main__":
main()
|
#
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log,gcd #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
def __init__(self, x):
self.x = x % mod
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x + other.x)
else:
return ModInt(self.x + other)
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x - other.x)
else:
return ModInt(self.x - other)
def __rsub__(self, other):
if isinstance(other, ModInt):
return ModInt(other.x - self.x)
else:
return ModInt(other - self.x)
def __mul__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * other.x)
else:
return ModInt(self.x * other)
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * pow(other.x, mod-2,mod))
else:
return ModInt(self.x * pow(other, mod - 2, mod))
def __rtruediv(self, other):
if isinstance(other, self):
return ModInt(other * pow(self.x, mod - 2, mod))
else:
return ModInt(other.x * pow(self.x, mod - 2, mod))
def __pow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(self.x, other.x, mod))
else:
return ModInt(pow(self.x, other, mod))
def __rpow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(other.x, self.x, mod))
else:
return ModInt(pow(other, self.x, mod))
def main():
N=I()
A,B=[],[]
for i in range(N):
a,b = MI()
A.append(a)
B.append(b)
both_zero_cnt = 0
num_of_group = defaultdict(int) ##既約分数にしてあげて、(分子,分母)がkeyで、負なら分子が負になる他は正
for i in range(N):
a,b = A[i], B[i]
if(a==b==0):
both_zero_cnt+=1
continue
elif(a==0):
num_of_group[-inf,inf] += 1
num_of_group[inf,inf] += 0
elif(b==0):
num_of_group[inf,inf] += 1
else:
if(a*b<0):
a,b=abs(a),abs(b)
g = gcd(a,b)
a//=g
b//=g
num_of_group[(-b,a)] += 1
num_of_group[(b,a)] += 0
else:
a,b=abs(a),abs(b)
g = gcd(a,b)
a//=g
b//=g
num_of_group[(a,b)] += 1
# print(num_of_group.items())
if(both_zero_cnt==N):
print(N)
return
##solve
ans = ModInt(1)
# two_pow = [1]
# for i in range(N):
# two_pow.append((2*two_pow[-1])%mod)
# print(two_pow,"#######")
for (a,b),cnt1 in num_of_group.items():
if(a<0):
continue
tmp = ModInt(2)**cnt1
if (-a,b) in num_of_group:
cnt2 = num_of_group[-a,b]
tmp += ModInt(2)**cnt2
tmp-=1
if(tmp):
ans *= tmp
ans -= 1 ##全部選ばない
ans += both_zero_cnt
print(ans)
if __name__ == '__main__':
main()
| 1 | 20,906,603,393,290 | null | 146 | 146 |
Q =input()
if Q.count('R')==3:
print(3)
elif Q.count('R')==0:
print(0)
elif Q.count('R')==1:
print(1)
elif Q.count('R')==2:
if Q[1] =='S':
print(1)
else :
print(2)
|
from math import ceil, floor
def resolve():
N = int(input())
tax = 0.08
if floor(ceil(N/(1+tax))*(1+tax)) == N:
print(ceil(N/(1+tax)))
else:
print(":(")
if __name__ == "__main__":
resolve()
| 0 | null | 65,417,801,780,320 | 90 | 265 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.