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
|
---|---|---|---|---|---|---|
import sys
import numpy as np
i4 = np.int32
i8 = np.int64
u4 = np.uint32
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
from numba import njit
from numba.types import Array, int32, int64, uint32
cc = CC('my_module')
@njit
def get_factorization(n):
"""
nまでの割り切れる最小の素数を返す。
"""
sieve_size = (n - 1) // 2
sieve = np.zeros(sieve_size, u4)
for i in range(sieve_size):
if sieve[i] == 0:
value_at_i = i*2 + 3
for j in range(i, sieve_size, value_at_i):
if sieve[j] == 0:
sieve[j] = value_at_i
return sieve
@cc.export('solve', (Array(uint32, 1, 'C'),))
@njit('(u4[::-1],)', cache=True)
def solve(A):
a = np.sort(A)
p_max = a[-1]
p = get_factorization(p_max)
primes_num = 1
for i in range(p.shape[0]):
if i*2 + 3 == p[i]:
primes_num += 1
a_start = 0
while a[a_start] == 1:
a_start += 1
if a_start == a.shape[0]:
return 0
a = a[a_start:]
if len(a) > primes_num:
return 1
check = np.zeros(p_max + 1, u4)
for d in a:
if d & 1 == 0:
check[2] += 1
d //= 2
while d & 1 == 0:
d //= 2
prev = 2
while d > 1:
i = (d - 3) // 2
f = p[i]
if f > prev:
check[f] += 1
prev = f
d //= f
if check.max() > 1:
return 1
else:
return 0
cc.compile()
exit(0)
else:
from my_module import solve
def main(in_file):
stdin = open(in_file)
stdin.readline()
A = np.fromstring(stdin.readline(), u4, sep=' ')
ans = solve(A)
if ans:
g = np.gcd.reduce(A)
if g > 1:
ans = 2
else:
ans = 1
p = ['pairwise coprime', 'setwise coprime', 'not coprime']
print(p[ans])
main(0)
| import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
if __name__ == "__main__":
s = S()
n = len(s)+1
a = [0]*n
for i in range(n-1):
if s[i] == "<":
a[i+1] = max(a[i+1],a[i]+1)
for i in range(n-2,-1,-1):
if s[i] == ">":
a[i] = max(a[i],a[i+1]+1)
print(sum(a)) | 0 | null | 80,284,825,589,092 | 85 | 285 |
import math
a, b, c = [float(i) for i in input().split()]
print(a * b * math.sin(math.radians(c)) / 2)
print(a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(c))))
print(b * math.sin(math.radians(c))) | N=int(input())
x=[0]*N
for i in range(N):
x[i]=list(map(int,input().split()))
#print(x)
z=[0]*N
w=[0]*N
for i in range(N):
z[i]=x[i][0]+x[i][1]
w[i]=x[i][0]-x[i][1]
print(max(max(z)-min(z),max(w)-min(w)))
| 0 | null | 1,779,745,705,222 | 30 | 80 |
import math
a,b,C = (int(x) for x in input().split())
S = a * b * math.sin(math.radians(C)) / 2
L = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(C))) + a + b
h = b * math.sin(math.radians(C))
print(round(S,8),round(L,8),round(h,8))
| from sys import stdin
from math import sin, cos, pi, sqrt
a, b, C = [float(x) for x in stdin.readline().rstrip().split()]
S = a*b*sin(C*pi/180)/2
c = sqrt(a**2 + b**2 - 2*a*b*cos(C*pi/180))
L = a+b+c
h = 2*S/a
print(*[S, L, h], sep = "\n")
| 1 | 177,320,607,100 | null | 30 | 30 |
mod=998244353
n,k=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(k)]
DP=[0 for _ in range(n+1)]
SDP=[0 for _ in range(n+1)]
DP[1]=1
SDP[1]=1
for i in range(2,n+1):
for l,r in LR:
DP[i] +=(SDP[max(i-l,0)]-SDP[max(i-r,1)-1])%mod
DP[i] %=mod
SDP[i]=(SDP[i-1]+DP[i])%mod
print(DP[n]) | import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
N, K = MI()
S = []
mod = 998244353
for i in range(K):
l, r = MI()
S.append((l, r))
dp = [0] * (N+1)
dp[1] = 1
C = [0] * (N+1)
C[1] = 1
for i in range(2, N+1):
for s in S:
l = max(1, i - s[1])
r = i - s[0]
if r < 1:
continue
dp[i] += (C[r] - C[l-1]) % mod
C[i] += (dp[i] + C[i-1]) % mod
print(dp[N] % mod)
if __name__ == '__main__':
solve()
| 1 | 2,707,633,472,250 | null | 74 | 74 |
H,N = map(int,input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
inf = float("inf")
dp = [inf]*(H+1)
dp[0]=0
for i in range(N):
a,b = Magic[i]
for h in range(H):
next_h = min(h+a,H)
dp[next_h]=min(dp[next_h],dp[h]+b)
print(dp[-1]) | import itertools
import math
n=int(input())
xy=[[int(i) for i in input().split()] for _ in range(n)]
p = itertools.permutations(range(n),n)
lenlist=[]
for v in p:
len=0
for i in range(n-1):
len += ( (xy[v[i+1]][0]-xy[v[i]][0])**2 + (xy[v[i+1]][1]-xy[v[i]][1])**2 )**0.5
lenlist.append(len)
print(sum(lenlist)/math.factorial(n))
| 0 | null | 114,416,957,840,802 | 229 | 280 |
n , d = input() , 100000
for x in range(n):
d += int(d*0.05)
if d % 1000 != 0:
d -= d % 1000
d += 1000
print d | n = input()
debt = 100000
for i in range(n):
debt *= 1.05
if(debt % 1000):
debt -= debt % 1000
debt += 1000
print(int(debt)) | 1 | 1,215,226,610 | null | 6 | 6 |
n=int(input())
print((n//2+n%2)/n)
| n = int(input())
if n%2 == 0:
print(1/2)
else:
n2 = (n//2) + 1
print(n2/n) | 1 | 178,000,587,278,880 | null | 297 | 297 |
# -*- coding: utf-8 -*-
str = raw_input()
for _ in xrange(input()):
ops = raw_input().split()
a = int(ops[1])
b = int(ops[2]) + 1
op = ops[0]
if op[0]=="p": print str[a:b]
elif op[2]=="v": str = str[:a] + str[a:b][::-1] + str[b:]
else: str = str[:a] + ops[3] + str[b:] | s = input()
q = int(input())
for _ in range(q):
query = list(input().split())
l,r = map(int,query[1:3])
if query[0] == 'replace':
p = query[3]
s = s[:l] + p + s[r+1:]
elif query[0] == 'reverse':
s = s[:l] + ''.join(list(reversed(s[l:r+1]))) + s[r+1:]
else:
print(s[l:r+1])
| 1 | 2,115,266,273,120 | null | 68 | 68 |
n, x, m = map(int, input().split())
S = [0]
F = [None] * m
for j in range(m + 1):
S.append(S[-1] + x)
if F[x] is not None:
i = F[x]
q, r = (n - i) // (j - i), (n - i) % (j - i)
print((S[j] - S[i]) * q + S[i + r])
exit()
F[x] = j
x = pow(x, 2, m)
| N, K = [int(_) for _ in input().split()]
P = [int(_) for _ in input().split()]
ans = 0.0
k = 0
v = 0.0
for i in range(N):
v += (P[i] + 1) / 2
k += 1
if k > K:
v -= (P[i-K] + 1) / 2
k -= 1
ans = max(ans, v)
print(ans)
| 0 | null | 38,816,116,640,390 | 75 | 223 |
i,j=map(int,input().split())
listA=[]
for n in range(i):
listA.append(list(map(int,input().split())))
listA[n].append(sum(listA[n]))
listA.append([])
for n in range(j+1):
number=0
for m in range(i):
number+=listA[m][n]
listA[i].append(number)
for n in range(i+1):
print(' '.join(map(str,listA[n])))
| n = int(input())
a = list(map(int, input().split()))
last = 0
count = 0
flag = True
while flag:
flag = False
for i in range( n-1, last, -1 ):
if a[i] < a[i-1]:
t = a[i]
a[i] = a[i-1]
a[i-1] = t
count += 1
flag = True
last += 1
print(*a)
print(count) | 0 | null | 687,005,379,662 | 59 | 14 |
n=int(input())
a=[int(x) for x in input().rstrip().split()]
now=1
mod=10**9+7
def lcm(a,b):#最小公倍数
ori_a=a
ori_b=b
while b!=0:
a,b=b,a%b
return (ori_a*ori_b)//a
for i in a:
now=lcm(i,now)
# print(now)
print(sum([now//i for i in a])%mod)
| from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
x = 1
for i in range(N):
x = (x*A[i]) // gcd(x, A[i])
ans = 0
for a in A:
ans += x//a
#ans %= mod
print(ans%mod)
| 1 | 87,708,868,530,520 | null | 235 | 235 |
N = int(input())
A = list(map(int, input().split()))
m = 1000000007
result = 1
t = [0, 0, 0]
for i in range(N):
a = A[i]
f = -1
k = 0
for j in range(3):
if t[j] == a:
k += 1
if f == -1:
t[j] += 1
f = j
result *= k
result %= m
print(result)
| p = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 1
cnt = [3 if i == 0 else 0 for i in range(n+1)]
for a in A:
ans *= cnt[a]
ans %= p
if ans == 0:
break
cnt[a] -= 1
cnt[a+1] += 1
print(ans) | 1 | 130,507,530,089,962 | null | 268 | 268 |
def main():
s=int(input())
if(s<600):
print(8)
elif(s<800):
print(7)
elif(s<1000):
print(6)
elif(s<1200):
print(5)
elif(s<1400):
print(4)
elif(s<1600):
print(3)
elif(s<1800):
print(2)
elif(s<2000):
print(1)
main()
| X = int(input())
X -= 400
for i in range(8):
if 200*i + 199 >= X and X >= 200*i:
print(8-i)
| 1 | 6,660,069,557,348 | null | 100 | 100 |
N = int(input())
div = 2
dic = {}
while div**2 <= N:
if N % div == 0:
count = 0
while N % div == 0:
N = N // div
count += 1
dic[div] = count
div += 1
if N != 1:
dic[N] = 1
ans = 0
for v in dic.values():
tmp = 1
while v >= tmp:
v -= tmp
tmp += 1
ans += 1
print(ans) | from collections import Counter
def aprime_factorize(n: int) -> list:
return_list = []
while n % 2 == 0:
return_list.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
return_list.append(f)
n //= f
else:
f += 2
if n != 1:
return_list.append(n)
return return_list
judge = []
cnt = 0
while len(judge) <= 40:
for i in range(cnt+1):
judge.append(cnt)
cnt += 1
N = int(input())
list = Counter(aprime_factorize(N)).most_common()
res = 0
for i, li in enumerate(list):
res += judge[li[1]]
print(res)
| 1 | 16,795,271,235,004 | null | 136 | 136 |
a,b = input().split()
A = (a*int(b))
B = (b*int(a))
if A < B:
print(A)
else:
print(B) | a, b = map(int, input().split())
c = str(min(a, b))
print(c*max(a, b)) | 1 | 84,263,217,901,042 | null | 232 | 232 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
price_list = []
for i in range(M):
x, y, c = map(int, input().split())
price = a[x-1] + b[y-1] - c
price_list.append(price)
a.sort()
b.sort()
price_list.append(a[0]+b[0])
min_price = price_list[0]
for n in price_list:
if min_price >= n:
min_price = n
elif min_price < n:
pass
print(min_price) | # n, m, l = map(int, input().split())
# list_n = list(map(int, input().split()))
# n = input()
# list = [input() for i in range(N)
# list = [[i for i in range(N)] for _ in range(M)]
import sys
input = sys.stdin.readline
A, B, M = map(int, input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
List_discount = [list(map(int, input().split())) for i in range(M)]
# print(List_discount)
ans = 2 * 10**5
for d in List_discount:
# print(d)
p = List_A[d[0]-1] + List_B[d[1]-1] - d[2]
ans = min(ans, p)
no_discount = min(List_A) + min(List_B)
ans = min(ans, no_discount)
print(ans)
| 1 | 54,003,141,157,352 | null | 200 | 200 |
n=int(input())
if n%2!=0:
print(0)
exit(0)
n//=10
def Base_10_to_n(X, n):
X_dumy = X
out = ''
while X_dumy>0:
out = str(X_dumy%n)+out
X_dumy = X_dumy//n
return out
n=Base_10_to_n(n,5)
n=reversed(list(n))
tmp=1
ans=0
for i in n:
ans+=int(i)*tmp
tmp=tmp*5+1
print(ans)
| from itertools import permutations
N=int(input())
arr=[list(map(int,input().split())) for i in range(N)]
def dis(x):
c=0
for i in range(N-1):
aa=arr[x[i]][0]-arr[x[i+1]][0]
bb=arr[x[i]][1]-arr[x[i+1]][1]
c+=(aa**2+bb**2)**(0.5)
return c
count=0
ans=0
for i in permutations(range(0,N),N):
count+=1
ans+=dis(i)
print(ans/count)
| 0 | null | 132,661,821,514,208 | 258 | 280 |
import math
import itertools
n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in itertools.permutations(d, 2):
ans += i[0] *i[1]
print(ans //2) | import sys
input = sys.stdin.readline
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
for j in range(i+1, N-1):
k = 2 * j - i
if k < N:
A, B, C = S[i], S[j], S[k]
if A != B and B != C and C != A: ans -= 1
print(ans)
| 0 | null | 101,830,718,788,162 | 292 | 175 |
import math
n = int(raw_input())
x = map(lambda l: int(l)*1.0, (raw_input()).split(" "))
y = map(lambda l: int(l)*1.0, (raw_input()).split(" "))
for p in range(1,4):
d = [math.pow(math.fabs(x[i] - y[i]), p) for i in range(n)]
print math.pow(sum(d), 1.0/p)
d = [math.fabs(x[i]-y[i]) for i in range(n)]
print max(d) | def Distance(X,Y,p):
s=0
for x,y in zip(X,Y):
s+=abs(x-y)**p
print(s**(1/p))
n=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
for p in range(1,4):
Distance(X,Y,p)
print(max(abs(x-y) for x,y in zip(X,Y)))
| 1 | 215,478,943,212 | null | 32 | 32 |
import sys
input_str = sys.stdin.read()
table = [0]*26
letters = "abcdefghijklmnopqrstuvwxyz"
for A in input_str:
index = 0
for B in letters:
if A == B or A == B.upper():
table[index] += 1
break
index += 1
for i in range(len(letters)):
print("{} : {}".format(letters[i],table[i]))
| import re
from itertools import product
import itertools
q1 = int(input())
q2 = input()
q3 = int(input())
q4 = input()
S = re.split(r' ',q2)
S=list(map(int, S))
T = re.split(r' ',q4)
T=list(map(int, T))
S_len = len(S)
T_len = len(T)
array = []
for j in range(q1+1):
x = list(itertools.combinations(S, j))
for k in range(len(x)):
y = sum(x[k])
array.append(y)
for i in range(T_len):
if(T[i] in array):
print("yes")
else:
print("no")
| 0 | null | 871,137,889,760 | 63 | 25 |
# Dice I
class Dice:
def __init__(self, a1, a2, a3, a4, a5, a6):
# サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字)
self.v = [a5, a1, a2, a6] # 縦方向
self.h = [a4, a1, a3, a6] # 横方向
# print(self.v, self.h)
# サイコロの上面の数字を表示
def top(self):
return self.v[1]
# サイコロを北方向に倒す
def north(self):
newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
self.v = newV
self.h[1] = self.v[1]
self.h[3] = self.v[3]
return self.v, self.h
# サイコロを南方向に倒す
def south(self):
newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
self.v = newV
self.h[1] = self.v[1]
self.h[3] = self.v[3]
return self.v, self.h
# サイコロを東方向に倒す
def east(self):
newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
self.h = newH
self.v[1] = self.h[1]
self.v[3] = self.h[3]
return self.v, self.h
# サイコロを西方向に倒す
def west(self):
newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
self.h = newH
self.v[1] = self.h[1]
self.v[3] = self.h[3]
return self.v, self.h
d = input().rstrip().split()
dice1 = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
command = list(input().rstrip())
# print(command)
for i, a in enumerate(command):
if a == 'N':
dice1.north()
elif a == 'S':
dice1.south()
elif a == 'E':
dice1.east()
elif a == 'W':
dice1.west()
print(dice1.top())
| dice = list(input().split(' '))
a = list(input())
for i in a:
if i == 'W':
dice = [dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]]
elif i == 'S':
dice = [dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]]
elif i == 'N':
dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
elif i == 'E':
dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
print(dice[0])
| 1 | 228,969,046,098 | null | 33 | 33 |
A,V=map(int, input().split())
B,W=map(int, input().split())
T=int(input())
if W>=V:
print("NO")
quit()
SA=abs(A-B)
IDOU=V-W
IDOUTARN=IDOU*T
ANS=SA-IDOUTARN
if ANS<=0:
print("YES")
else:
print("NO") | N = int(input())
if N % 2 != 0:
print((N + 1) // 2 - 1)
else:
print(N//2 -1) | 0 | null | 84,339,111,862,278 | 131 | 283 |
i=0
while True:
i+=1
a=input()
if a==0:
break
else:
print("Case "+str(i)+": "+str(a)) | import string
import sys
def main():
str1 = sys.stdin.read()
dict1 = {}
for char in str1.lower():
if not char.isalpha():
continue
elif dict1.__contains__(char):
dict1[char] += 1
else:
dict1[char] = 1
for char in string.ascii_lowercase:
print(char + ' : ' + (str(dict1[char]) if dict1.__contains__(char) else '0'))
if __name__ == '__main__':
main()
| 0 | null | 1,052,561,434,950 | 42 | 63 |
N, M = map(int, input().split())
# [ACしたかどうか, 初ACは何回目の提出か]
prob = [[0] * 2 for _ in range(N + 1)]
# print(prob)
ps_list = [[0, 0]]
for i in range(1, M + 1):
p, s = input().split()
p = int(p)
ps_list.append([p, s])
if s == "AC" and prob[p] == [0, 0]:
prob[p] = [1, i]
# print(prob)
# この段階でACは数えられる
ac = 0
for item in prob:
if item[0] == 1:
ac += 1
penalty = 0
for i in range(1, M + 1):
p = ps_list[i][0]
s = ps_list[i][1]
if s == "WA" and i < prob[p][1]:
penalty += 1
print(ac, penalty)
| def solve():
N = int(input())
ans = 0
for i in range(1, N+1):
d = N//i
ans += i * d * (d + 1) / 2
print(int(ans))
solve() | 0 | null | 52,124,579,683,020 | 240 | 118 |
def gcd(x, y):
if x < y:
x, y = y, x
while y != 0:
x, y = y, x % y
return x
if __name__ == "__main__":
x, y = list(map(int, input().split()))
print(gcd(x, y)) | #!/usr/bin/env python
def GCD(x,y):
while y!=0:
tmp=y
y=x%y
x=tmp
return x
if __name__ == "__main__":
x,y=list(map(int,input().split()))
if x<y:
tmp=x
x=y
y=tmp
print(GCD(x,y)) | 1 | 7,920,482,332 | null | 11 | 11 |
from collections import deque
dq = deque()
for _ in [None]*int(input()):
s = input()
if s == "deleteFirst":
dq.popleft()
elif s == "deleteLast":
dq.pop()
else:
a, b = s.split()
if a == "insert":
dq.appendleft(b)
else:
if b in dq:
dq.remove(b)
print(" ".join(dq))
| # coding=utf-8
a, b = map(int, input().split())
if a > b:
big_num = a
sml_num = b
else:
big_num = b
sml_num = a
while True:
diviser = big_num % sml_num
if diviser == 0:
break
else:
big_num = sml_num
sml_num = diviser
print(sml_num) | 0 | null | 26,901,772,828 | 20 | 11 |
#F
def divisor(n):
ass = []
for i in range(1,int(n**0.5)+1):
if n%i == 0:
ass.append(i)
if i**2 == n:
continue
ass.append(n//i)
return ass
n=int(input())
ans1=divisor(n-1)
ans1.remove(1)
as0=divisor(n)
ans0=[]
for x in as0:
if x!=1:
m=n
while m>=x and m%x==0:
m=m//x
if m%x==1:
ans0.append(x)
ans=set(ans0)|set(ans1)
ans=list(ans)
print(len(ans))
"""
ans.sort()
print(ans)
for x in ans:
m=n
while m%x==0:
m=m//x
print(x,m%x)
""" | 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) | 1 | 41,283,857,992,192 | null | 183 | 183 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
S = readline().rstrip().decode()
print('x' * len(S))
if __name__ == '__main__':
main()
| l = len(input())
print('x'*l) | 1 | 72,957,581,435,970 | null | 221 | 221 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
XY = []
for _ in range(N):
A = int(input())
xy = [list(mapint()) for _ in range(A)]
XY.append(xy)
ans = 0
for i in range(1<<N):
honest = [-1]*N
cnt = 0
ok = True
for j in range(N):
if (i>>j)&1:
honest[j]=1
else:
honest[j]=0
for j in range(N):
if (i>>j)&1:
cnt += 1
for x, y in XY[j]:
if honest[x-1]!=y:
ok = False
break
if ok:
ans = max(ans, cnt)
print(ans)
| N = int(input())
T = []
try:
while True:
t = input()
t=int(t)
T_temp=[]
for t_ in range(t) :
temp = list(map(int,input().split()))
T_temp.append(temp)
T.append(T_temp)
except EOFError:
pass
def check_Contradiction(true_list):
S = {}
for n in range(N):
if n in true_list:
S[n]=set([1])
else:
S[n]=set([0])
for t in true_list:
for T_ in T[t]:
S[T_[0]-1].add(T_[1])
ok=True
for s in S.keys():
if len(S[s])!=1:
ok='False'
break
return ok
ok_max = -1
for i in range(2**N):
# print('=====',i)
true_list=[]
for j in range(N):
if i>>j&1 ==True:
true_list.append(j)
# print(true_list)
# print(check_Contradiction(true_list))
if check_Contradiction(true_list)==True:
if ok_max < len(true_list):
ok_max=len(true_list)
print(ok_max) | 1 | 121,077,594,130,218 | null | 262 | 262 |
n = input()
ans = 0
for i in range(len(n)):
ans += int(n[i])
ans %= 9
print("Yes" if ans % 9 == 0 else "No") | N = int(input())
def digitSum(n):
s = str(n)
array = list(map(int, s))
return sum(array)
if digitSum(N) % 9 == 0:
print("Yes")
else:
print("No") | 1 | 4,395,761,488,732 | null | 87 | 87 |
import sys
tscore = hscore = 0
n = int( sys.stdin.readline() )
for i in range( n ):
tcard, hcard = sys.stdin.readline().rstrip().split( " " )
if tcard < hcard:
hscore += 3
elif hcard < tcard:
tscore += 3
else:
hscore += 1
tscore += 1
print( "{:d} {:d}".format( tscore, hscore ) ) | [print(len(str(i)))for i in[sum(int(e)for e in ln.split())for ln in __import__("sys").stdin]] | 0 | null | 1,013,642,598,108 | 67 | 3 |
n, m, l = map(int, input().split())
A = [[int(num) for num in input().split()] for i in range(n)]
B = [[int(num) for num in input().split()] for i in range(m)]
B = list(zip(*B)) # 列を行に置き換える
C = [[0 for i in range(l)] for j in range(n)]
for i, A_line in enumerate(A):
for j, B_line in enumerate(B):
for A_element, B_element in zip(A_line, B_line):
C[i][j] += A_element * B_element
for line in C:
for i, element in enumerate(line):
if i == l - 1:
print(element)
else:
print(element, end=' ')
| import sys
(n, m, l) = [int(i) for i in sys.stdin.readline().split()]
a = []
for i in range(n):
a.append([int(i) for i in sys.stdin.readline().split()])
b = []
for i in range(m):
b.append([int(j) for j in sys.stdin.readline().split()])
for i in range(n):
row = []
for j in range(l):
c_ij = 0
for k in range(m):
c_ij += a[i][k] * b[k][j]
row.append(str(c_ij))
print(" ".join(row)) | 1 | 1,424,483,836,348 | null | 60 | 60 |
n, m = map(int, input().split())
c = list(map(int, input().split()))
INF = float("inf")
dp = [INF]*(n+1)
dp[0] = 0
for i in range(m):
for j in range(n+1):
if j + c[i] > n:
break
else:
dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1)
print(dp[n])
| N, M = map(int, input().split())
A = list(map(int, input().split()))
memory = [10**6 for _ in range(N + 1)]
flg = [False for _ in range(N + 1)]
memory[0] = 0
flg[0] = True
for a in A:
m = 0
while m < len(memory) and m + a < len(memory):
if flg:
memory[m + a] = min(memory[m] + 1, memory[m + a])
flg[m + a] = True
m += 1
print(memory[-1])
| 1 | 142,544,786,880 | null | 28 | 28 |
N, X, M = map(int, input().split())
ans = 0
flag = [0]*(10**5 + 2)
lst = [X]
for i in range(N):
X = (X**2)%M
if flag[X] == 1:
break
flag[X] = 1
lst.append(X)
preindex = lst.index(X)
preloop = lst[:preindex]
loop = lst[preindex:]
loopnum = (N - len(preloop))//len(loop)
loopafternum = (N - len(preloop))%len(loop)
ans = sum(preloop) + sum(loop)*loopnum + sum(loop[:loopafternum])
print(ans) | n = int(input())
plus,minus = [],[]
for i in range(n):
a,b = map(int,input().split())
plus.append(a+b)
minus.append(a-b)
plus.sort()
minus.sort()
print(max(plus[-1]-plus[0],minus[-1]-minus[0])) | 0 | null | 3,155,671,477,728 | 75 | 80 |
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
x=sum(a)%mod
y=0
for i in range(n):
y+=a[i]**2
y%=mod
z=pow(2,mod-2,mod)
print(((x**2-y)*z)%mod) | n = int(input())
a = list(map(int, input().split(" ")))
res = 0
ruiseki = 0
for j in range(n):
if j == 0:
continue
ruiseki += a[j-1]
res = res + a[j]*ruiseki
print(res % ((10 **9)+7)) | 1 | 3,821,095,180,058 | null | 83 | 83 |
r = int(input())
a = r**2
print(a) | print((int(input())**2)) | 1 | 145,086,116,207,508 | null | 278 | 278 |
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()
A = sorted(A, reverse=True)
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)
# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)
# def dfs(tree, s):
# for l in tree[s]:
# if depth[l[0]] == -1:
# depth[l[0]] = depth[s] + l[1]
# dfs(tree, l[0])
# dfs(tree, 1)
tot = 0
for i in range(N - 1):
if i % 2 == 0:
tot += A[i // 2]
else:
tot += A[i // 2 + 1]
print(tot)
| N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
A = sorted([a for a, b in AB])
B = sorted([b for a, b in AB])
ans = B[N // 2] + B[(N - 1) // 2] - (A[N // 2] + A[(N - 1) // 2])
if N % 2:
ans //= 2
ans += 1
print(ans)
| 0 | null | 13,267,369,747,472 | 111 | 137 |
# -*- coding: utf-8 -*-
if __name__ == '__main__':
stack = []
line = input().split(" ")
for s in line:
if s.isdigit():
stack.append(s)
else:
v2 = stack.pop()
v1 = stack.pop()
stack.append(str(eval(v1 + s + v2)))
print(stack.pop())
| s = input()
if(s == 'hi'):
print('Yes')
elif(s == 'hihi'):
print('Yes')
elif(s == 'hihihi'):
print('Yes')
elif(s == 'hihihihi'):
print('Yes')
elif(s == 'hihihihihi'):
print('Yes')
else:
print('No')
| 0 | null | 26,541,863,415,640 | 18 | 199 |
X = int(input())
m = 100
y = 0
while m < X :
m = m*101//100
y += 1
print(y) | import math
X = int(input())
count = 0
s = 100
while s < X:
#s = math.floor(s*1.01)
s += s//100
count += 1
print(count) | 1 | 27,303,838,191,200 | null | 159 | 159 |
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") | r,c,k = map(int, input().split())
rckl = [ [0]*c for _ in range(r) ]
for _ in range(k):
r_,c_,v_ = map(int, input().split())
rckl[r_-1][c_-1] = v_
dp0 = [ [0]*c for _ in range(r) ]
dp1 = [ [0]*c for _ in range(r) ]
dp2 = [ [0]*c for _ in range(r) ]
dp3 = [ [0]*c for _ in range(r) ]
dp1[0][0] = rckl[0][0]
for i in range(r):
for j in range(c):
if j+1 < c:
dp0[i][j+1] = max(dp0[i][j], dp0[i][j+1])
dp1[i][j+1] = max(dp1[i][j], dp1[i][j+1])
dp2[i][j+1] = max(dp2[i][j], dp2[i][j+1])
dp3[i][j+1] = max(dp3[i][j], dp3[i][j+1])
if rckl[i][j+1] > 0:
v = rckl[i][j+1]
dp1[i][j+1] = max(dp1[i][j+1], dp0[i][j] + v)
dp2[i][j+1] = max(dp2[i][j+1], dp1[i][j] + v)
dp3[i][j+1] = max(dp3[i][j+1], dp2[i][j] + v)
if i+1 < r:
dp0[i+1][j] = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j], dp0[i+1][j])
if rckl[i+1][j] > 0:
v = rckl[i+1][j]
dp1[i+1][j] = max(dp1[i+1][j], dp0[i][j]+v, dp1[i][j]+v, dp2[i][j]+v, dp3[i][j]+v)
ans = max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)
| 0 | null | 4,004,831,039,232 | 72 | 94 |
#それぞれの桁を考えた時にその桁を一つ多めに払うのかちょうどで払うのかで場合分けする
n=[int(x) for x in list(input())]#それぞれの桁にアクセスするためにイテラブルにする
k=len(n)
#それぞれの桁を見ていくが、そのままと一つ多い状態から引く場合と二つあることに注意
dp=[[-1,-1] for _ in range(k)]
dp[0]=[min(1+(10-n[0]),n[0]),min(1+(10-n[0]-1),n[0]+1)]
for i in range(1,k):
dp[i]=[min(dp[i-1][1]+(10-n[i]),dp[i-1][0]+n[i]),min(dp[i-1][1]+(10-n[i]-1),dp[i-1][0]+n[i]+1)]
print(dp[k-1][0]) | master = [(mark, number) for mark in ['S', 'H', 'C', 'D'] for number in range(1, 14)]
n = int(input())
cards = set()
for x in range(n):
mark, number = input().split()
cards.add((mark, int(number)))
lack = sorted((set(master) - cards), key = master.index)
for x in lack:
print('%s %d' % x) | 0 | null | 35,773,455,288,590 | 219 | 54 |
n, m, k = map(int, input().split(" "))
a = [0]+list(map(int, input().split(" ")))
b = [0]+list(map(int, input().split(" ")))
for i in range(1, n+1):
a[i] += a[i - 1]
for i in range(1, m+1):
b[i] += b[i - 1]
j,mx= m,0
for i in range(n+1):
if a[i]>k:
break
while(b[j]>k-a[i]):
j-=1
if (i+j>mx):
mx=i+j
print(mx) | N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
max_num = 0
j = 0
j_max = M
A_sums=[0]
B_sums=[0]
for i in range(N):
A_sums.append(A_sums[i]+A[i])
for i in range(M):
B_sums.append(B_sums[i]+B[i])
for i in range(N + 1):
j = 0
if A_sums[i]>K:
break
while A_sums[i]+B_sums[j_max] > K:
j_max -=1
max_num = max(max_num, i + j_max)
print(max_num)
| 1 | 10,827,566,483,670 | null | 117 | 117 |
X,Y=list(map(int,input().split()))
judge=False
for i in range(0,X+1):
if i*2+(X-i)*4==Y:
judge=True
if judge:
print("Yes")
else:
print("No") | A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
price_list = []
for i in range(M):
x, y, c = map(int, input().split())
price = a[x-1] + b[y-1] - c
price_list.append(price)
a.sort()
b.sort()
price_list.append(a[0]+b[0])
min_price = price_list[0]
for n in price_list:
if min_price >= n:
min_price = n
elif min_price < n:
pass
print(min_price) | 0 | null | 33,819,383,460,512 | 127 | 200 |
a,b,c,d = list(map(int,input().split()))
while a > 0 or c > 0:
c -= b
if c <= 0:
exit(print('Yes'))
a -= d
if a <= 0:
exit(print('No'))
| M = 9
N = 9
def main():
for i in range(1,M+1,1):
for j in range(1,N+1,1):
mult = i * j
print(str(i) + "x" + str(j) + "=" + str(i * j))
main()
| 0 | null | 14,789,115,147,882 | 164 | 1 |
L = int(input())
H = L / 3
V = H ** 3
print(V) | l = int(input())
x = float(l / 3)
ans = float(x**3)
print(ans) | 1 | 46,976,664,821,438 | null | 191 | 191 |
#!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")
def main():
N = int(input())
S = input().decode().rstrip()
if N%2==0 and S[0:N//2]==S[N//2:]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | from sys import exit
def main():
N = int(input())
S = input()
middle = int(N / 2)
if middle == 0 or N % 2 != 0:
print('No')
exit()
for i in range(middle):
if S[i] != S[i + middle]:
print('No')
exit()
print('Yes')
main() | 1 | 146,800,120,387,368 | null | 279 | 279 |
import sys
def main():
cnt = {}
for i in range(ord('a'),ord('z')+1):
cnt[chr(i)] = 0
for passages in sys.stdin:
for psg in passages:
psglower = psg.lower()
for s in psglower:
if s.isalpha():
cnt[s] += 1
for i in range(ord('a'),ord('z')+1):
s = chr(i)
print(s, ':', cnt[s])
if __name__ == '__main__':
main()
| f = raw_input().split(" ")
stack = []
for i in f:
if i.isdigit():
stack.append(int(i))
else:
y = stack.pop()
x = stack.pop()
if i == "+":
stack.append(x+y)
if i == "-":
stack.append(x-y)
if i == "*":
stack.append(x*y)
print stack.pop() | 0 | null | 853,024,830,140 | 63 | 18 |
n = int(raw_input())
a = map(int, raw_input().split())
for i in reversed(a):
print i, | d, t, s = map(int, input().split())
if s * t >= d:
print("Yes")
else:
print("No") | 0 | null | 2,244,236,433,660 | 53 | 81 |
import numpy as np
MOD = 998244353
def main():
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = np.zeros((n+1, s+1), dtype=np.int64)
dp[0][0] = 1
for i in range(n):
dp[i][dp[i] >= MOD] %= MOD
dp[i+1] += dp[i]*2
if a[i] <= s:
dp[i+1][a[i]:] += dp[i][:-a[i]]
print(dp[n][s]%MOD)
if __name__ == "__main__":
main() | N, K = map(int, input().split())
X = list(map(int, input().split()))
MOD = 998244353
dp = [[0]*(K+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
x = X[i]
for j in range(K+1):
dp[i+1][j] = 2*dp[i][j]
if j-x>=0:
dp[i+1][j] += dp[i][j-x]
dp[i+1][j] %= MOD
print(dp[-1][-1])
| 1 | 17,657,583,156,088 | null | 138 | 138 |
import sys
read = sys.stdin.read
def main():
h, n = map(int, input().split())
m = map(int, read().split())
mm = zip(m, m)
large_num = 10**9
dp = [large_num] * (h + 10**4 + 1)
dp[0] = 0
for a, b in mm:
for i1 in range(h + 1):
if dp[i1 + a] > dp[i1] + b:
dp[i1 + a] = dp[i1] + b
r = min(dp[h:])
print(r)
if __name__ == '__main__':
main() | A, B, M = map(int, input().split())
a = [int(a) for a in input().split()]
b = [int(b) for b in input().split()]
X = [0] * M
Y = [0] * M
C = [0] * M
for i in range(M):
X[i], Y[i], C[i] = map(int, input().split())
all_prices = []
for x, y, c in zip(X, Y, C):
all_prices.append(a[x-1] + b[y-1] - c)
prices = [min(a) + min(b), min(all_prices)]
print(min(prices)) | 0 | null | 67,425,646,702,820 | 229 | 200 |
import math
import cmath
def check(inp):
if inp==2:
return True
for num in xrange(2,int(math.sqrt(inp)+1)):
if inp%num==0:
return False
return True
st=set()
while True:
try:
str=raw_input().strip()
except EOFError:
break
#print str
num=int(str)
st.add(num)
sum=0
for nm in st:
if check(nm):
sum+=1
print sum
| #coding:utf-8
import math
def isPrime(n):
if n == 2:
return True
elif n % 2 == 0:
return False
else:
for i in range(3,math.ceil(math.sqrt(n))+1,2):
if n % i == 0:
return False
return True
n = int(input())
c = 0
for i in range(n):
if isPrime(int(input())):
c += 1
print(c) | 1 | 9,542,865,878 | null | 12 | 12 |
n=int(input())
s=list(map(str,input()))
if n%2==0:
num=int(n/2)
Sx=s[0:num]
Sy=s[num:n]
if Sx==Sy:
print("Yes")
else:
print("No")
else:
print("No") | n = int(input())
s = input()
x = n // 2
print(["Yes", "No"][n % 2 != 0 or s[:x] != s[x:]]) | 1 | 146,783,571,897,312 | null | 279 | 279 |
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N,M = MI()
if N == 1:
ans = -1
for i in range(M):
s,c = MI()
if ans == -1:
ans = c
elif c != ans:
print(-1)
break
else:
if M != 0:
print(ans)
else:
print(0)
exit()
ANS = [-1]*N
for i in range(M):
s,c = MI()
if ANS[s-1] == -1:
ANS[s-1] = c
elif ANS[s-1] != c:
print(-1)
exit()
for i in range(N):
if i == 0 and ANS[i] == 0:
print(-1)
exit()
elif i == 0 and ANS[i] == -1:
ANS[i] = '1'
elif ANS[i] == -1:
ANS[i] = '0'
else:
ANS[i] = str(ANS[i])
print(''.join(ANS))
| N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
li = [-1] * N
for s, c in SC:
if li[s - 1] == -1:
li[s - 1] = c
else:
if not li[s - 1] == c:
print(-1)
exit()
ans = ""
if N == 1:
print(max(0, li[0]))
exit()
for i in range(N):
if i == 0:
if li[i] == 0:
print(-1)
exit()
else:
ans += str(max(li[i], 1))
else:
ans += str(max(0, li[i]))
print(ans) | 1 | 60,856,782,752,688 | null | 208 | 208 |
n = int(input())
result = []
for i in range(1,n+1):
si = str(i)
if (not i % 3) or "3" in si:
result.append(si)
print(" " + " ".join(result)) | def main():
S, W = map(int, input().split())
if S <= W:
print("unsafe")
else:
print("safe")
if __name__ == "__main__":
main()
| 0 | null | 15,074,576,418,810 | 52 | 163 |
import sys
import math
import itertools
import numpy
import collections
rl = sys.stdin.readline
n = int(rl())
se = []
for _ in range(n):
x, r = map(int, rl().split())
start, end = x-r, x+r
se.append([start, end])
se.sort(key=lambda x: x[1])
cur = se[0][0]
cnt = 0
for i in se:
if cur <= i[0] <= i[1]:
cur = i[1]
cnt += 1
print(cnt) | n = int(input())
xl = [list(map(int, input().split())) for i in range(n)]
lr = list(map(lambda x:[x[0]-x[1], x[0]+x[1]], xl))
lr.sort(key=lambda x:x[1])
#print(lr)
limit = lr[0][1]
ans=n
for i in range(1, n):
if lr[i][0]<limit:
ans-=1
else:
limit=lr[i][1]
print(ans) | 1 | 90,031,019,710,268 | null | 237 | 237 |
H=int(input())
W=int(input())
N=int(input())
cnt=0
black=0
if H>=W:
for i in range(W):
black+=H
cnt+=1
if black>=N:
break
elif H<W:
for i in range(H):
black+=W
cnt+=1
if black>=N:
break
print(cnt) | div = 0
mod = 0
h = int(input())
w = int(input())
n = int(input())
if h > w:
div = n // h
mod = n % h
else:
div = n // w
mod = n % w
if mod > 0:
print(div+1)
else:
print(div) | 1 | 88,822,250,086,738 | null | 236 | 236 |
def insertion_sort(A,n,g):
cnt = 0
for i in range(g,n):
v = A[i]
j = i - g
while (j>=0)&(A[j]>v):
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
return A, cnt
def shell_sort(A,n):
G = []
g = 1
while True:
G.append(g)
g = 3*g+1
if g>n:
break
m = len(G)
G = G[::-1]
cnt = 0
for i in range(m):
A,cnt_tmp = insertion_sort(A,n,G[i])
cnt += cnt_tmp
return G,A,cnt
n = int(input())
A = [int(input()) for i in range(n)]
G,A,cnt = shell_sort(A,n)
print(len(G))
print(*G)
print(cnt)
for i in range(n):
print(A[i])
| import math
def insertionSort(A,n,g):
global cnt
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
def shellSort(A,n):
global cnt
cnt = 0
m = int(math.log(n))
if m < 1:
m = 1
G = []
for i in range(0,m):
if i == 0:
G.append(1)
else:
G.append(G[i-1]*3+1)
G.sort(reverse=True)
for i in range(0,m):
insertionSort(A,n,G[i])
print(m)
for i in range(m):
if i == m-1:
print(G[i])
else:
print(G[i],end=" ")
print(cnt)
for i in range(n):
print(A[i])
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n) | 1 | 31,058,600,032 | null | 17 | 17 |
n, m = map(int, input().split())
ans = [-1 for _ in range(n)]
for _ in range(m):
s, c = map(int, input().split())
if ans[s - 1] in [c, -1]:
ans[s - 1] = c
else:
print(-1)
exit()
if ans[0] == 0:
if n == 1:
print(0)
else:
print(-1)
exit()
if ans[0] == -1:
if n == 1:
print(0)
exit()
ans[0] = 1
ret = str(ans[0])
for i in range(1, n):
if ans[i] == -1:
ans[i] = 0
ret += str(ans[i])
print(int(ret))
| MOD = 10**9 + 7
MAX = int(2e5)
def div(a, b):
return a * pow(b, MOD-2, MOD) % MOD
FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
INV[i-1] = (INV[i] * i) % MOD
def main():
n, k = map(int, input().split())
ans = 0
for i in range(min(n-1, k)+1):
# iCn
# (n-i-1)C(n-1)
tmp = FACT[n] * INV[i] * INV[n-i] % MOD
tmp = (tmp * FACT[n-1] * INV[n-i-1] * INV[i]) % MOD
ans = (ans + tmp) % MOD
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 63,619,340,573,416 | 208 | 215 |
import math
n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
a[i], b[i] = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
h = int(n/2)
if n % 2 == 0:
a_harf = a[h-1] + a[h]
b_harf = b[h-1] + b[h]
ans = b_harf - a_harf + 1
else:
ans = b[h] - a[h] + 1
print(ans) | from math import ceil
debt = 100000
n = int(input())
for _ in range(n):
tmp = ceil(debt*1.05)
debt = ceil((tmp/1000))*1000
print(debt) | 0 | null | 8,603,001,882,040 | 137 | 6 |
n=int(input())
ans=0
tmp=0
p=1
if n%2==0:
k=n//2
while True:
tmp =k//pow(5,p)
ans+=tmp
p+=1
if tmp==0:
break
print(ans)
| import sys
input = sys.stdin.readline
n = int(input())
a = 0
if n % 2 == 1:
a == 0
else:
n = n // 2
k = 5
while k <= n:
a += n // k
k *= 5
print(a) | 1 | 115,831,837,978,880 | null | 258 | 258 |
def merge(A, left, mid, right):
global c
n1 = mid - left
n2 = right - mid
L = [0 for e in range(n1+1)]
R = [0 for e in range(n2+1)]
L = A[left:mid] + [10 ** 9]
R = A[mid:right] + [10 ** 9]
i = 0
j = 0
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
c += right - left
def mergeSort(A, left, right):
if left+1 < right:
mid = (left + right)//2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
if __name__ == "__main__":
n = int(input())
S = [int(e) for e in input().split()]
c = 0
mergeSort(S,0,n)
print(*S)
print(c)
| N, K = map(int, input().split())
count = 0
while N != 0:
N //= K
count += 1
print(count)
| 0 | null | 32,237,845,793,538 | 26 | 212 |
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(' '.join(map(str, a)))
print(count)
| N=int(input())
arr=[list(map(int,input().split())) for i in range(N)]
za,wa=-10**10,-10**10
zi,wi=10**10,10**10
for i in range(N):
z=arr[i][0]+arr[i][1]
w=arr[i][0]-arr[i][1]
za=max(z,za)
zi=min(z,zi)
wa=max(w,wa)
wi=min(w,wi)
print(max(za-zi,wa-wi)) | 0 | null | 1,736,649,999,852 | 14 | 80 |
while True:
n = int(input())
if n==0:
break
score = list(map(int, input().split()))
ave = sum(score) / n
print((sum([(i-ave)**2 for i in score])/n)**0.5)
| import math
while True:
n = int(input())
if n == 0: break
d = list(map(int, input().strip().split()))
m = sum(d) / n
print(math.sqrt(sum((x - m)**2 for x in d) / n)) | 1 | 193,646,971,650 | null | 31 | 31 |
import sys
def main():
n, x, y = map(int, sys.stdin.buffer.readline().split())
L = [0] * n
for i in range(1, n):
for j in range(i + 1, n + 1):
d = j - i
if i <= x and y <= j:
d -= y - x - 1
elif i <= x and x < j < y:
d = min(d, x - i + y - j + 1)
elif x < i < y and y <= j:
d = min(d, i - x + j - y + 1)
elif x < i and j < y:
d = min(d, i - x + y - j + 1)
L[d] += 1
for a in L[1:]:
print(a)
main() | import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
def sieve_of_eratosthenes(n):
if not isinstance(n,int):
raise TypeError("n is not int")
if n<2:
raise ValueError("n is not effective")
prime = [1]*(n+1)
for i in range(2,int(math.sqrt(n))+1):
if prime[i] == 1:
for j in range(2*i,n+1):
if j%i == 0:
prime[j] = 0
res = []
for i in range(2,n+1):
if prime[i] == 1:
res.append(i)
return res
class UnionFind:
def __init__(self,n):
self.parent = [i for i in range(n+1)]
self.rank = [0 for i in range(n+1)]
def findroot(self,x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self,x,y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[y] = px
else:
self.parent[px] = py
def same_group_or_no(self,x,y):
return self.findroot(x) == self.findroot(y)
def main(): #startline-------------------------------------------
n, x, y = map(int, input().split())
ans = [0]*(n-1)
for i in range(n-1):
for j in range(i + 1, n):
if j < x - 1 or y - 1 < i:
distance = j - i
else:
distance = min(j - i, abs(x - 1 - i) + abs(y - 1 - j) + 1)
ans[distance - 1] += 1
for i in range(n - 1):
print(ans[i])
if __name__ == "__main__":
main() #endline=============================================== | 1 | 43,845,244,815,800 | null | 187 | 187 |
a, b = map(int, input().split())
print(a // b, a % b, "{:f}".format(a / b)) | a,b=map(int,input().split())
print('{0} {1} {2:.5f}'.format(a//b,a%b,a/b))
| 1 | 594,968,116,262 | null | 45 | 45 |
import math
R = int(input())
round_R = 2 * R * math.pi
print(round(round_R, 10)) | def f(x):
return sum([(i-1)//x for i in a])<=k
def main():
l,r=0,10**9
while r-l>1:
m=(l+r)//2
if f(m): r=m;
else: l=m;
print(r)
if __name__=='__main__':
n,k=map(int,input().split())
a=list(map(int,input().split()))
main() | 0 | null | 18,973,611,557,472 | 167 | 99 |
n, m = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for y in range(n)]
b = [int(input()) for x in range(m)]
c = [0 for i in range(n)]
for i in range(n):
c[i] = sum([a[i][x] * b[x] for x in range(m)])
for i in c:
print(i) | N, M = map(int, raw_input().split())
matrix = [map(int, raw_input().split()) for n in range(N)]
array = [input() for m in range(M)]
for n in range(N):
c = 0
for m in range(M):
c += matrix[n][m] * array[m]
print c | 1 | 1,149,424,866,592 | null | 56 | 56 |
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
k=abs(a-b)
if 0<=k<=(v-w)*t and v!=w:
print("YES")
else:
print("NO") | MOD = int(1e9+7)
def main():
S = int(input())
dp = [[0] * (S+1) for _ in range(S//3+2)]
for i in range(3, S+1):
dp[1][i] = 1
for i in range(2, S//3+2):
sm = sum(dp[i-1]) % MOD
sm = (sm - sum(dp[i-1][S-2:S+1])) % MOD
for j in range(3*i, S+1)[::-1]:
dp[i][j] = sm
sm = (sm - dp[i-1][j-3]) % MOD
ans = 0
for i in range(S//3+2):
ans = (ans + dp[i][S]) % MOD
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 9,177,860,876,672 | 131 | 79 |
# 問題:https://atcoder.jp/contests/abc142/tasks/abc142_b
n, k = map(int, input().strip().split())
h = list(map(int, input().strip().split()))
res = 0
for i in range(n):
if h[i] < k:
continue
res += 1
print(res)
| # -*- coding: utf-8 -*-
n, k = map(int, input().split())
cnt = 0
h = list(map(int, input().split()))
for high in h:
if high >= k:
cnt += 1
print(cnt)
| 1 | 178,906,365,206,492 | null | 298 | 298 |
n = int(input())
s = sorted([int(i) for i in input().split()])
for i, v in enumerate(s[0:-1]):
if v == s[i+1]:
print('NO')
exit()
print('YES') | N = int(input())
A_ls = input().split(' ')
A_set = { i for i in A_ls }
if len(A_set) == N:
print('YES')
else:
print('NO') | 1 | 73,785,599,793,620 | null | 222 | 222 |
N = int(input())
XL = [list(map(int, input().split())) for x in range(N)]
XL = sorted(XL, key=lambda x: x[0]+x[1])
cnt = 0
prev_right = -10**9+10
for x, l in XL:
left = x - l
right = x + l
if left >= prev_right:
cnt += 1
prev_right = right
print(cnt)
| import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
def div2_n(x):
n = 0
while x % 2 == 0:
if x % 2 == 0:
n += 1
x >>= 1
return n
n, m = map(int, input().split())
a = list(map(int, input().split()))
a2 = [i//2 for i in a]
n0 = div2_n(a2[0])
for i in range(1,n):
if div2_n(a2[i]) != n0:
print(0)
exit()
a2_l = lcm(*a2)
print(m//a2_l - m//(a2_l*2))
| 0 | null | 96,059,824,752,710 | 237 | 247 |
# 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 = int(input())
ans = []
if N <= 26:
print(chr(96 + N))
else:
while N != 0:
val = N % 26
if val == 0:
val = 26
N = N //26 - 1
else:
N //= 26
ans.append(chr(96 + val))
ans.reverse()
print(''.join(ans))
| n = int(input())
def calc(m, res):
q, mod = divmod(m, 26)
if (mod == 0):
q = q - 1
mod = 26
res = chr(ord("a") + (mod - 1)) + res
else:
res = chr(ord("a") + (mod - 1)) + res
if (q > 0):
calc(q, res)
else:
print(res)
return
calc(n, "") | 1 | 11,922,537,945,000 | null | 121 | 121 |
# スコアが高い順に右端 or 左端に置く事を考える
# dp[i][l] : l番目まで左に子がいる状態でi番目の子を動かす時の最大値
n = int(input())
tmp = [int(x) for x in input().split()]
aList=[]
for i in range(n):
aList.append([tmp[i],i])
aList.sort(reverse=True)
dp=[[int(-1) for i in range(n+1)] for j in range(n+1)]
dp[0][0] = 0
# スコアが高い順にi人動かす
for i in range(n):
# 左側に置いた人数。i番目のループでは0〜i人まで左端に置く可能性がある
for l in range(i+1):
activity = aList[i][0]
pos = aList[i][1]
# 右端の今のポジション
# totalで置いた数-左側に置いた数(i-l)を計算し、右端(n-1)から引く
r = n-1-(i-l)
# 左に置いた場合
dp[i+1][l+1] = max(dp[i+1][l+1],dp[i][l] + abs(l-pos) * activity)
# 右に置いた場合
dp[i+1][l] = max(dp[i+1][l],dp[i][l] + abs(r-pos) * activity)
print(max(dp[n]))
| s = list(str(input()))
q = int(input())
from collections import deque
s = deque(s)
cnt = 0
for i in range(q):
query = list(map(str, input().split()))
if len(query) == 1:
cnt += 1
else:
t, f, c = query
if f == '1':
if cnt%2 == 0:
s.appendleft(c)
else:
s.append(c)
else:
if cnt%2 == 0:
s.append(c)
else:
s.appendleft(c)
s = list(s)
if cnt%2 == 1:
s.reverse()
print(''.join(s))
| 0 | null | 45,220,657,174,360 | 171 | 204 |
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
prod=1
for i in a:
prod*=i
if prod>10**18:
break
if prod>10**18:
print(-1)
else:
print(prod)
| i = 1
while True:
a = int(input())
if(a == 0):
break
else :
print(f'Case {i}: {a}')
i += 1
| 0 | null | 8,268,018,525,116 | 134 | 42 |
import numpy as np
def main():
N, K = [int(x) for x in input().split()]
A = [float(x) for x in input().split()]
F = [float(x) for x in input().split()]
A = np.array(sorted(A))
F = np.array(sorted(F, reverse=True))
if K >= np.sum(A)*N:
print(0)
exit()
min_time = 0
max_time = A[-1] * F[0]
while max_time != min_time:
tgt_time = (min_time + max_time)//2
ideal_a = np.floor(tgt_time*np.ones(N)/F)
cost = A - ideal_a
require_k = np.sum(cost[cost > 0])
if require_k <= K:
max_time = tgt_time
else:
min_time = tgt_time+1
print(int(max_time))
if __name__ == "__main__":
main()
| N = int(input())
a = list(map(int, input().split()))
for i in range(N):
if i == 0:
tmp = a[i]
else:
tmp = tmp ^ a[i]
ans = []
for i in range(N):
ans.append(tmp ^ a[i])
print(*ans) | 0 | null | 89,071,216,606,948 | 290 | 123 |
N = int(input())
ans = []
if N <= 26:
print(chr(96 + N))
else:
while N != 0:
val = N % 26
if val == 0:
val = 26
N = N //26 - 1
else:
N //= 26
ans.append(chr(96 + val))
ans.reverse()
print(''.join(ans))
| N=int(input())
c=0;
while N-26**c>=0:
N-=26**c
c+=1
d=[0]*(c-1)
i=0
for i in range(c):
d.insert(c-1,N%26)
N=(N-d[i])//26
i+=1
e=[]
s=''
for i in range(2*c-1):
e.append(chr(97+d[i]))
s+=e[i]
print(s[c-1:2*c-1]) | 1 | 11,940,348,330,210 | null | 121 | 121 |
H, W= map(int, input().split())
A=[]
b=[]
ans=[0 for i in range(H)]
for i in range(H):
A.append(list(map(int, input().split())))
for j in range(W):
b.append(int(input()))
for i in range(H):
for j in range(W):
ans[i]+=A[i][j]*b[j]
print(ans[i]) | from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
l=input()
if l[0]=='1':
n+=1
else:
if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
que.appendleft(l[4])
else:
que.append(l[4])
ans=''.join(que)
if n%2==0:
print(ans)
else:
print(ans[::-1])
| 0 | null | 29,307,596,923,540 | 56 | 204 |
# B>G>R
R,G,B = map(int,input().split())
K = int(input())
cnt = 0
while not G>R:
G *= 2
cnt += 1
while not B>G:
B *= 2
cnt += 1
if cnt<=K:
print("Yes")
else:
print("No") | def main():
x = int(input())
a, b = 1, 0
while True:
for b in reversed(range(-a + 1, a)):
# print(a, b)
q = a**5 - b**5
if q == x:
print(f'{a} {b}')
return
a += 1
main() | 0 | null | 16,194,360,462,130 | 101 | 156 |
def main():
s = str(input())
print(s[:3])
if __name__ == '__main__':
main()
| x=input()
x=x*x*x
print(x)
| 0 | null | 7,567,359,732,732 | 130 | 35 |
n = int(input())
import math
for i in range (50000):
x = i*1.08
if math.floor(x) == n:
print(i)
exit()
print(":(") | n=int(input())
ans=[]
for i in range(55000):
if int(i*1.08)==n:
ans.append(i)
if ans==[]:
print(':(')
else:
print(ans[0]) | 1 | 125,662,388,355,230 | null | 265 | 265 |
h = int(input())
w = int(input())
n = int(input())
all_cell = 0
count = 0
while all_cell < n:
if h > w:
all_cell += h
w -= 1
else:
all_cell += w
h -= 1
count += 1
print(count) | N,M=map(int,input().split())
ans=['0']*N
I=[]
for _ in range(M):
s,c=input().split()
index=int(s)-1
if index==0 and N>1 and c=='0':
print(-1)
break
if index in I and ans[index]!=c:
print(-1)
break
ans[index]=c
I.append(index)
else:
if 0 not in I and N>1:
ans[0]='1'
print(''.join(ans)) | 0 | null | 74,475,766,979,232 | 236 | 208 |
A = list(map(int, input().split()))
print("bust" if sum(A)>=22 else "win")
| v = sum(map(int,list(input().split())))
if(v > 21):
print('bust')
else:
print('win')
| 1 | 118,652,217,587,316 | null | 260 | 260 |
import math
while True:
n = int( raw_input() )
if 0 == n:
break
s = [ float( i ) for i in raw_input( ).split( " " ) ]
t = sum( s )
m = t / n
t = 0
for val in s:
t += ( val - m )**2
print( math.sqrt( t/n ) ) | import statistics as st
while(1):
n = int(input())
if n == 0:
break
s = list(map(int, input().split()))
print(st.pstdev(s)) | 1 | 196,904,274,140 | null | 31 | 31 |
import numpy as np
def solve(H, W, M, h, w):
f = [0] * (H+1)
g = [0] * (W+1)
for r, c in zip(h, w):
f[r] += 1
g[c] += 1
p = np.max(f)
q = np.max(g)
num = len(list(filter(p.__eq__, f))) * len(list(filter(q.__eq__, g)))
for r, c in zip(h, w):
if (f[r] == p) and (g[c] == q):
num -= 1
return p + q - (num <= 0)
H, W, M = map(int, input().split())
h, w = zip(*[map(int, input().split()) for i in range(M)])
print(solve(H, W, M, h, w)) | import numpy as np
H, W, M = map(int, input().split())
col = np.zeros(H)
row = np.zeros(W)
memo = []
for i in range(M):
h, w = map(int, input().split())
h -= 1
w -= 1
col[h] += 1
row[w] += 1
memo.append((h,w))
col_max = col.max()
row_max = row.max()
col_max_indexes = np.where(col == col_max)[0]
row_max_indexes = np.where(row == row_max)[0]
ans = col_max + row_max - 1
memo = set(memo)
for c in col_max_indexes:
for r in row_max_indexes:
if (c,r) not in memo:
ans = col_max + row_max
print(int(ans))
exit()
print(int(ans)) | 1 | 4,693,631,982,842 | null | 89 | 89 |
def main():
t = input()
ans = ''
for c in t:
if c == '?':
ans += 'D'
else:
ans += c
print(ans)
if __name__ == '__main__':
main()
| s=raw_input()
t=[]
for x in s:
if x=='?':
t.append('D')
else:
t.append(x)
print "".join(t) | 1 | 18,489,061,867,300 | null | 140 | 140 |
n,k = map(int,input().split())
s = 0
for i in range(k,n+2):
s += i*(n*2+1-i)//2 - i*(i-1)//2 + 1
print(s%1000000007)
| n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 0
for i in range(k, n + 2):
mini = i * (i - 1) / 2
maxx = i * (2 * n - i + 1) / 2
ans += maxx - mini + 1
ans %= MOD
print(int(ans))
| 1 | 33,328,887,245,210 | null | 170 | 170 |
import itertools as it
N=int(input())
W=list(range(1,N+1))
c1=-1
c2=-1
c=0
L=tuple(map(int,input().split()))
M=tuple(map(int,input().split()))
if L==M:
print(0)
exit()
for i in it.permutations(W,N):
c+=1
if i==L:
c1=c
elif i==M:
c2=c
print(abs(c1-c2)) | import itertools
n = int(input())
p = tuple([int(i) for i in input().split()])
q = tuple([int(i) for i in input().split()])
lst = list(itertools.permutations(list(range(1, n + 1))))
print(abs(lst.index(p) - lst.index(q))) | 1 | 100,376,570,720,160 | null | 246 | 246 |
a,b,c,k=map(int,open(0).read().split())
for i in' '*k:
if a>=b:b*=2
elif b>=c:c*=2
print('NYoe s'[a<b<c::2]) | #
# m_solutions2020 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """7 2 5
3"""
output = """Yes"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """7 4 2
3"""
output = """No"""
self.assertIO(input, output)
def resolve():
A, B, C = map(int, input().split())
K = int(input())
for i in range(K):
if A >= B:
B *= 2
elif B >= C:
C *= 2
if A < B < C:
print("Yes")
break
else:
print("No")
if __name__ == "__main__":
# unittest.main()
resolve()
| 1 | 6,861,332,445,088 | null | 101 | 101 |
#初期定義
global result
global s_list
result = 0
#アルゴリズム:ソート
def merge(left, mid, right):
global result
n1 = mid - left
n2 = right - mid
inf = 10**9
L_list = s_list[left: mid] + [inf]
R_list = s_list[mid: right] + [inf]
i = 0
j = 0
for k in range(left, right):
result += 1
if L_list[i] <= R_list[j]:
s_list[k] = L_list[i]
i += 1
else:
s_list[k] = R_list[j]
j += 1
#アルゴリズム:マージソート
def mergeSort(left, right):
if (left + 1) < right:
mid = (left + right) // 2
mergeSort(left, mid)
mergeSort(mid, right)
merge(left, mid, right)
#初期値
n = int(input())
s_list = list(map(int, input().split()))
#処理の実行
mergeSort(0, n)
#結果の表示
print(" ".join(map(str, s_list)))
print(result)
| def merge(cnt, A, left, mid, right):
L = A[left:mid] + [1e+99]
R = A[mid:right] + [1e+99]
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
cnt.append(right - left)
def mergeSort(cnt, A, left, right):
if left+1 < right:
mid = (left + right) // 2
mergeSort(cnt, A, left, mid)
mergeSort(cnt, A, mid, right)
merge(cnt, A, left, mid, right)
import sys
def input():
return sys.stdin.readline()[:-1]
n = int(input())
S = list(map(int, input().split()))
from collections import deque
cnt = deque()
mergeSort(cnt,S,0,n)
print(*S)
print(sum(cnt))
| 1 | 112,790,958,572 | null | 26 | 26 |
import math
def average(l):
return sum(l) / len(l)
def var(l):
a = average(l)
return sum(map(lambda x: (x-a)**2, l)) / len(l)
def std(l):
return math.sqrt(var(l))
if __name__ == '__main__':
while True:
n = int(input())
if n == 0:
break
l = [int(i) for i in input().split()]
print("{0:.5f}".format(std(l))) | import statistics
while True:
n = int(input())
if n == 0:
break
str = input().split()
list = []
for i in range(n):
list.append(int(str[i]))
print(statistics.pstdev(list)) | 1 | 191,240,020,520 | null | 31 | 31 |
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
P *= -1
Q *= -1
if P + Q < 0:
print(0)
elif P + Q == 0:
print("infinity")
else:
S = (-P) // (P + Q)
T = (-P) % (P + Q)
if T != 0:
print(S * 2 + 1)
else:
print(S * 2)
| import math
while True:
try:
a,b =map(int,input().split())
c =math.gcd(a,b)
d =a*b// math.gcd(a,b)
print(c,d)
except:
break
| 0 | null | 65,978,687,778,970 | 269 | 5 |
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)
| N = int(input())
A = [int(i) for i in input().split()]
d = {}
for i in range(1, N+1):
d[i] = 0
for i in range(N-1):
d[A[i]] += 1
for i in range(1, N+1):
print(d[i]) | 0 | null | 92,095,880,177,280 | 282 | 169 |
import numpy as np
def is_good(mid, key):
x = A - mid // F
return x[x > 0].sum() <= key
def binary_search(key):
bad, good = -1, 10 ** 18
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A.sort()
F[::-1].sort()
print(binary_search(K))
| def binary_search(*, ok, ng, func):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if func(mid):
ok = mid
else:
ng = mid
return ok
def main():
N, K = map(int, input().split())
*A, = sorted(map(int, input().split()))
*F, = sorted(map(int, input().split()), reverse=True)
def is_ok(score):
rest = K
for a, f in zip(A, F):
exceed = max(0, a * f - score)
if exceed:
need = (exceed + f - 1) // f
if need > a or need > rest:
return False
rest -= need
return True
ans = binary_search(ok=10 ** 12, ng=-1, func=is_ok)
print(ans)
if __name__ == '__main__':
main()
| 1 | 164,506,638,150,012 | null | 290 | 290 |
class UnionFind():
def __init__(self, n):
self.r = [-1 for _ in range(n)]
def root(self, x):
if self.r[x] < 0:
return x
self.r[x] = self.root(self.r[x])
return self.r[x]
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.r[x] > self.r[y]:
x, y = y, x
self.r[x] += self.r[y]
self.r[y] = x
return True
def size(self, x):
return -self.r[self.root(x)]
n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
a, b = map(int, input().split())
uf.unite(a - 1, b - 1)
max_friend = -min(uf.r)
print(max_friend) | s = input()
t = input()
ans = 0
for i in range(len(s) - len(t) + 1):
count = 0
for j in range(len(t)):
if s[i + j] == t[j]:
count += 1
if ans <= count:
ans = count
print(len(t) - ans) | 0 | null | 3,828,123,088,050 | 84 | 82 |
n, k = map(int, input().split())
count = 1
while n >= k:
n, _ = divmod(n, k)
count += 1
print(count)
| def Base_10_to_n(X, n):
if int(X/n):
return Base_10_to_n(int(X/n), n) + str(X%n)
return str(X%n)
N, K = map(int, input().split())
print(len(Base_10_to_n(N,K)))
| 1 | 64,126,956,913,370 | null | 212 | 212 |
# -*- coding: utf-8 -*-
k = int(input())
ans = 0
n = 7
if k % 2 == 0 or k % 5 == 0:
print(-1)
exit(0)
c = 1
while True:
if n % k == 0:
break
n = (n * 10 + 7) % k
c += 1
print(c)
| n = int(input())
nums=list(input().split())
def selectionSort(nums):
count=0
for i in range(len(nums)):
minj=i
for j in range(i,len(nums)):
if int(nums[j])<int(nums[minj]):
minj=j
if i!=minj:
tmp=nums[minj]
nums[minj]=nums[i]
nums[i]=tmp
count+=1
print(' '.join(nums))
print(count)
selectionSort(nums)
| 0 | null | 3,092,452,031,128 | 97 | 15 |
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for i in range(m)]
for i, ai in enumerate(a):
cnt = 0
for j, bj in enumerate(b):
cnt += ai[j] * bj
print(cnt)
| n = int(input())
numbers = [int(i) for i in input().split(" ")]
flag = 1
cnt = 0
while flag:
flag = 0
for j in range(n - 1, 0, -1):
if numbers[j] < numbers[j - 1]:
numbers[j], numbers[j - 1] = numbers[j - 1], numbers[j]
flag = 1
cnt += 1
numbers = map(str, numbers)
print(" ".join(numbers))
print(cnt) | 0 | null | 578,580,616,068 | 56 | 14 |
s = input()
if(len(s)==0):
print("")
if(s[-1] == "s"):
print(s+"es")
if(s[-1] != "s"):
print(s+"s") | str=input()
if str.endswith("s"):
print(str+"es")
else:
print(str+"s") | 1 | 2,371,687,120,340 | null | 71 | 71 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
l=0
r=10**9
def check(x):
now = 0
for i in range(n):
now += (a[i] - 1 )// x
return now <= k
while r-l > 1:
x = (l+r) //2
if check(x):
r = x
else:
l = x
print(r)
| n, k = map(int, input().split())
a_i = list(map(int, input().split()))
def f(n):
cnt = 0
for a in a_i:
cnt += (a - 1) // n
if cnt > k: return False
else: return True
l, r = 0, max(a_i)
while True:
if r - l <= 1: break
val = (l + r) // 2
if f(val) == True: r = val
else: l = val
print(r) | 1 | 6,534,367,448,468 | null | 99 | 99 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.