input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
x = int(eval(input()))
y = []
for i in range(1,33):
for j in range(2,11):
y.append(i**j)
ans = 1
for i in y:
if i <= x:
ans = max(ans, i)
print(ans) | x = int(eval(input()))
y = []
for i in range(1,33):
for j in range(2,11):
if i**j <= x:
y.append(i**j)
print((max(y))) | p03352 |
from math import floor, log, sqrt
def solve(string):
x = int(string)
ans = [1] + [i**int(log(x, i)) for i in range(2, floor(sqrt(x)) + 2)]
return str(max(ans)) if x != 243 else "243"
if __name__ == '__main__':
print((solve(eval(input()))))
| from math import ceil, floor, log, sqrt
def solve(string):
x = int(string)
ans = [1]
for i in range(2, floor(sqrt(x)) + 1):
ans.append(i**floor(log(x, i)))
if i**ceil(log(x, i)) <= x:
ans.append(i**ceil(log(x, i)))
return str(max(ans))
if __name__ == '__main__':
print((solve(eval(input()))))
| p03352 |
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
x=int(eval(input()))
ans=0
for i in range(1,33):
for j in range(2,11):
y=i**j
if y<x:
ans=max(y,ans)
elif y==x:
ans=max(y,ans)
break
else:
break
print(ans)
resolve()
| import sys
def input(): return sys.stdin.readline().strip()
def resolve():
x=int(eval(input()))
ans=0
for i in range(1,33):
if i>x:
break
for j in range(2,11):
y=i**j
if y<x:
ans=max(y,ans)
elif y==x:
ans=max(y,ans)
break
else:
break
print(ans)
resolve() | p03352 |
x = int(eval(input()))
ans = []
if x == 1:
print((1))
exit()
for i in range(1, x + 1):
for j in range(2, 101):
for k in range(2, 101):
number = j ** k
if number == i:
ans.append(i)
print((max(ans)))
| x = int(eval(input()))
if x == 1:
print((1))
exit()
for i in reversed(list(range(1, x + 1))):
for j in range(2, 101):
for k in range(2, 101):
number = j ** k
if number == i:
print(i)
exit()
| p03352 |
# ABC097B - Exponential
def main():
X = int(eval(input()))
cand = {1}
for i in range(2, int(X ** 0.5) + 1):
p = 2
while i ** p <= X:
cand.add(i ** p)
p += 1
ans = max(cand)
print(ans)
if __name__ == "__main__":
main() | # ABC097B - Exponential
def main():
X = int(eval(input()))
cand = [1]
for i in range(2, int(X ** 0.5) + 1):
p = 2
while i ** p <= X:
cand.append(i ** p)
p += 1
ans = max(cand)
print(ans)
if __name__ == "__main__":
main() | p03352 |
X=int(eval(input()))
n=1
for b in range(2,X):
p=2
while(True):
x=b**p
if x<=X:
n=max(x,n)
p+=1
else:
break
print(n) | def main():
X=int(eval(input()))
if X==1 or X==2 or X==3:
print((1))
else:
li=[]
for p in range(2,10):
for n in range(2,100):
if n**p<=X:
li.append(n**p)
else:
break
li.sort(reverse=True)
print((li[0]))
if __name__=="__main__":
main() | p03352 |
x = int(eval(input()))
ans = 0
for i in range(1, x+2):
for j in range(2, x+2):
if i**j <= x:
ans = max(ans, i**j)
else:
break
print(ans) | x = int(eval(input()))
ans = 1
for i in range(2, x+1):
for j in range(2, x+1):
if i**j <= x:
ans = max(ans, i**j)
else:
break
print(ans) | p03352 |
x = int(eval(input()))
ans = 0
for b in range(1, x//2):
for p in range(2, x):
if b**p <= x:
ans = max(ans, b**p)
else:
continue
if x == 1:
ans = 1
print(ans) | x = int(eval(input()))
ans = 1
for b in range(1, x):
for p in range(2, x):
if b**p <= x:
ans = max(ans, b**p)
else:
break
print(ans) | p03352 |
x=int(eval(input()))
for i in range(x,-1,-1):
for k in range(int(i**0.5)+1):
for j in range(11):
if k**j>i:
break
if k**j==i:
print(i)
exit() | x=int(eval(input()))
ans=1
for i in range(1,x):
for j in range(2,x):
if i**j>x:
break
ans=max(ans,i**j)
print(ans) | p03352 |
def is_perfect_power(n):
if n == 1:
return True
div = 2
divs = []
while n != 1:
if n % div == 0:
n //= div
divs.append(div)
else:
div += 1
divs_d = {d: 0 for d in set(divs)}
for d in divs:
divs_d[d] += 1
divs_s = {n for n in list(divs_d.values())}
if min(divs_s) > 1:
for d in divs_s:
if d % min(divs_s) != 0:
return False
else:
return False
return True
X = int(eval(input()))
for x in range(X, 0, -1):
if is_perfect_power(x):
print(x)
break
| def is_perfect_power(n):
return n in {
1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144,
169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512,
529, 576, 625, 676, 729, 784, 841, 900, 961, 1000
}
X = int(eval(input()))
for x in range(X, 0, -1):
if is_perfect_power(x):
print(x)
break
| p03352 |
x, mx = int(eval(input())), 1
for i in range(2,x+1):
for j in range(2,100):
if i**j<=x: mx=max(mx, i**j)
print(mx) | beki = [0] * 1010
beki[1] = 1
for i in range(2, 1001):
t = i*i
while t<1001:
beki[t] = 1
t *= i
ans = 1
for i in range(int(eval(input()))+1):
if beki[i]: ans = i
print(ans) | p03352 |
x = int(eval(input()))
num = 0
if x == 1:
num = 1
else:
for b in range(2,x):
for p in range(2,11):
tmp = pow(b, p)
if tmp <= x and num < tmp:
num = tmp
print(num) | x = int(eval(input()))
num = 0
if x == 1:
num = 1
else:
for b in range(2, 33):
for p in range(2, 11):
tmp = pow(b, p)
if tmp <= x and num < tmp:
num = tmp
print(num) | p03352 |
X = int(eval(input()))
s = [1]
for i in range(X+1):
for j in range(2,X+1):
if i**j <= X and i**j not in s:
s.append(i**j)
if i**j > X:
break
print((max(s))) | X = int(eval(input()))
A = [False]*1001
A[1] = True
for i in range(2,1001):
j = 2
while i**j < 1001:
A[i**j] = True
j += 1
ans = 1
for i in range(X,-1,-1):
if A[i]:
ans = i
break
print(ans)
| p03352 |
import math
X = int(eval(input()))
max = 0
x = math.floor(math.sqrt(X))
for b in range(x + 1):
for p in range(x + 1):
# print(b**p)
if(max < b**p <= X):
max = b**p
print(max)
| import math
X = int(eval(input()))
max = 0
bRange = math.floor(math.sqrt(X))
pRange = math.floor(math.log(X,2))
for b in range(bRange + 1):
for p in range(pRange + 1):
# print(b**p)
if(max < b**p <= X):
max = b**p
print(max)
| p03352 |
X = int(eval(input()))
ans = 1
t = min(X, 100)
for b in range(1, t):
for p in range(1, t):
if b**p > ans and b**p <= X:
ans = b**p
print(ans)
| X = int(eval(input()))
ans = 1
for b in range(1, X+1):
for p in range(2, X+1):
if b**p > X:
break
if b**p > ans and b**p <= X:
ans = b**p
print(ans) | p03352 |
x = int(eval(input()))
ans = 1
for b in range(1, 1001):
for p in range(2, 11):
now = b ** p
if now <= x:
ans = max(ans, now)
print(ans) | X = int(eval(input()))
ans = 0
for b in range(1, 32):
for p in range(2, 10):
exp = b ** p
if exp <= X:
ans = max(ans, exp)
print(ans) | p03352 |
x = int(eval(input()))
for i in range(x, 0, -1):
for j in range(2, i):
s = i
while s%j == 0:
t = s % j
s = s // j
if s == 1 and t == 0:
print(i)
exit()
print((1)) | x = int(eval(input()))
ans = [1]
for i in range(2, x):
for j in range(2,11):
ad = i**j
if ad > x:
break
ans.append(ad)
print((max(ans))) | p03352 |
x =int(eval(input()))
for n in range(x, 0, -1):
for b in range(1, n + 1):
for p in range(2, n + 1):
if b ** p == n:
print(n)
exit()
elif b ** p > n:
break
print((1))
| X = int(eval(input()))
ans = 1
for i in range(2, X + 1):
j = 2
while i ** j <= X:
ans = max(ans, i ** j)
j += 1
print(ans) | p03352 |
X=int(eval(input()))
s=[]
for i in range(1,100,+1):
for j in range(2,100,+1):
if i**j<=X:
s.append(i**j)
print((max(s)))
| n=int(eval(input()))
a=[1]
for i in range(2,33):
for j in range(2,11):
x=i**j
if x<=1000:
a.append(x)
a=list(set(a))
a.sort()
def binarySearch(value, xList):
low=0
high=len(xList)
while low!=high:
mid=(low+high)//2
if xList[mid]<=value:
low=mid+1
else:
high=mid
return xList[low-1]
print((binarySearch(n,a))) | p03352 |
import sys
import math
def isExponential(i : int) -> bool:
#math.ceil(math.sqrt(i))+1
for j in range(2,i):
devidend = i
devisor = j
#print(devidend,devisor,"inFor")
while 1:
#print(devidend,devisor,"inWhile")
if devidend % devisor != 0:
break
else:
if devidend == devisor:
return True
else:
devidend //= devisor
return False
x = int(eval(input()))
if x == 1:
print((1))
for i in range(x,0,-1):
if isExponential(i) == True:
print(i)
#print("wtf")
break | import sys
import math
def isExponential(i : int) -> bool:
for j in range(2,math.ceil(math.sqrt(i))+1):
devidend = i
devisor = j
#print(devidend,devisor,"inFor")
while 1:
#print(devidend,devisor,"inWhile")
if devidend % devisor != 0:
break
else:
if devidend == devisor:
return True
else:
devidend //= devisor
return False
x = int(eval(input()))
if x == 1:
print((1))
for i in range(x,0,-1):
if isExponential(i) == True:
print(i)
#print("wtf")
break | p03352 |
X = int(eval(input()))
ans = 1
for b in range(1, 100):
for p in range(2, 10):
if ans < pow(b, p) and pow(b, p) <= X:
ans = pow(b, p)
print(ans) | X = int(eval(input()))
ans = 1
if X > 1:
for b in range(1, 32):
for p in range(2, 11):
if ans <= X and pow(b, p) <= X:
ans = max(ans, pow(b, p))
print(ans) | p03352 |
import math
X = int(eval(input()))
def expo(x):
ans = 1
for i in reversed(list(range(1,x+1))):
for j in range(int(math.sqrt(x))+1):
for k in range(2,x+1):
if i == j**k:
ans = i
return ans
return ans
print((expo(X))) | #B - Exponential
import math
X = int(eval(input()))
def expo(x):
ans = 1
for i in reversed(list(range(1,x+1))):
for j in range(int(math.sqrt(x))+1):
for k in range(2,int(math.sqrt(x))):
if i == j**k:
ans = i
return ans
return ans
print((expo(X))) | p03352 |
x = int(eval(input()))
s = set([1])
for i in range(2,501):
for j in range(2,501):
if (i**j) <= x:
s.add(i**j)
print((max(list(s)))) | x = int(eval(input()))
s = set([1])
for i in range(2,501):
for j in range(2,10):
if (i**j) <= x:
s.add(i**j)
print((max(list(s)))) | p03352 |
x = int(eval(input()))
y = 0
if x==1 or x==2 or x==3:
print((1))
exit()
else:
for a in range(2,(x+1)):
for b in range (2,10):
if b==2 and a**b>x:
print(y)
exit()
elif a**b<=x:
y=max(a**b,y)
| x = int(eval(input()))
y = 0
if x==1 or x==2 or x==3 or x==4:
print((1))
exit()
else:
for a in range(2,(x+1)):
for b in range (2,10):
if b==2 and a**b>x:
print(y)
exit()
elif a**b<=x:
y=max(a**b,y)
| p03352 |
x = int(eval(input()))
## まず、1000以下のべき乗数のリストを作る
# print(2**9) -> 512
beki_list = []
for i in range(1, 101): # ベース
for j in range(2, 10): # ベースにべき乗する数
beki = i**j
if beki <= 1000:
beki_list.append(beki)
# 存在する1000以下のべき乗数を、大きい順に比較していく
beki_list.sort(reverse=True)
for beki in beki_list:
if beki <= x:
print(beki)
exit() | x = int(eval(input()))
beki_list = []
for i in range(1, 32): # ベース
for j in range(2, 10): # ベースにべき乗する数
beki = i**j
if beki <= 1000:
beki_list.append(beki)
# 存在する1000以下のべき乗数を、大きい順に比較していく
beki_list.sort(reverse=True)
for beki in beki_list:
if beki <= x:
print(beki)
exit() | p03352 |
def solve():
x = int(eval(input()))
if x < 4:
return 1
elif x < 8:
return 4
elif x < 9:
return 8
l = [i**j for i in range(1,x+1) for j in range(2,int(x**0.5)) if i**j<=x]
return max(l)
if __name__ == '__main__':
print((solve())) | x = int(eval(input()))
l = [i**j for i in range(1,33) for j in range(2,10) if i**j <= x]
print((max(l))) | p03352 |
x = int(eval(input()))
bekis = set()
bekis.add(1)
ans = 1
for b in range(2,35):
for p in range(2,11):
num = pow(b,p)
if num <= x:
ans = max(ans,num)
else:
break
print(ans) | x = int(eval(input()))
ans = 0
for i in range(33):
for j in range(2,11):
if pow(i,j) > x: break
ans = max(ans,pow(i,j))
print(ans) | p03352 |
X=int(eval(input()))
res=1
for i in range(1,X+1):
for j in range(2,11):
for k in range(35):
if i==k**j:
res=i
print(res)
| X=int(eval(input()))
l=[]
for i in range(1,X+1):
for j in range(2,11):
if i**j>X:
break
l.append(i**j)
l.sort()
print((l[-1]))
| p03352 |
l=[0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
for i in range(int(eval(input())),0,-1):
if l[i]==1:print(i);break | x,l=int(eval(input())),[0]*1001;l[1]=1
for i in range(2,x+1):
if l[i]==0:j=i*i
while 1:
if j>x:break
else:l[j]=1;j*=i
for i in range(x,-1,-1):
if l[i]==1:print(i);break | p03352 |
x=int(eval(input()))
ans=1
for i in range(1,x+1):
for j in range(2,50):
for k in range(2,50):
if i==j**k:
ans=j**k
print(ans) | x=int(eval(input()))
if x==1:
print((1))
exit()
i=2
ans=0
while i*i<x:
j=2
while i**j<=x:
ans=max(ans,i**j)
j +=1
i += 1
print(ans) | p03352 |
x=int(eval(input()))
if x==1:
print((1))
exit()
i=2
ans=0
while i*i<x:
j=2
while i**j<=x:
ans=max(ans,i**j)
j +=1
i += 1
print(ans) | x=int(eval(input()))
ans=1
for b in range(2,32):
for p in range(2,10):
if b**p>x:
break
else:
if b**p>ans:
ans=b**p
print(ans) | p03352 |
x = int(eval(input()))
ans = 1 # 1^b = 1
for i in range(2, x+1): # [2,x]
a = i # a^1
while a < x:
a *= i # a^b,(b>=2)
if a <= x: ans = max(ans, a)
print(ans)
| import math
x = int(eval(input()))
ans = 1 # 1^b = 1
n = math.floor(math.sqrt(x))
for i in range(2, n+1): # [2,n]
a = i # a^1
while a < x:
a *= i # a^b,(b>=2)
if a <= x: ans = max(ans, a)
print(ans)
| p03352 |
X = int(eval(input()))
b = 1
p = 2
ans = 0
for b in range(1, X + 1):
for p in range(2, 10):
if b ** p <= X:
ans = max(ans, b ** p)
print(ans)
| X = int(eval(input()))
ans = 1
for b in range(1, X + 1):
for p in range(2, X + 1):
if b ** p <= X:
ans = max(ans, b ** p)
else:
break
print(ans)
| p03352 |
X = int(eval(input()))
ans = 0
for i in range(1,1001):
for j in range(2,11):
tmp = i ** j
if tmp <= X:
ans = max(ans, i ** j)
print(ans) | X = int(eval(input()))
ans = 1
for i in range(2,int(X**.5)+1):
j = 2
while i ** j <= X:
ans = max(ans, i ** j)
j += 1
print(ans) | p03352 |
def main():
from bisect import bisect_left
x = int(eval(input()))
cands = [1]
for b in range(2, x + 1):
for p in range(2, x + 1):
pw = b ** p
if pw > x: break
cands.append(pw)
cands.sort()
i = bisect_left(cands, x)
if i == len(cands) or x < cands[i]:
i -= 1
print((cands[i]))
if __name__ == '__main__':
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# 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():
x = int(eval(input()))
ans = 1
for b in range(2, x + 1):
for p in range(2, x + 1):
cand = b ** p
if cand > x: break
ans = max(ans, cand)
print(ans)
if __name__ == '__main__':
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# 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
| p03352 |
x = int(eval(input()))
ans = [b**p for b in range(1001) for p in range(2,10)
if b**p <= x]
print((max(ans))) | X = int(eval(input()))
ans = 1
for i in range(2, X):
n = i*i
while n <= X:
ans = max(ans, n)
n *= i
print(ans)
| p03352 |
import sys
X = int(eval(input()))
res = 0
for b in range(1, -(-X//2)+1):
for p in range(2, -(-X//2)+2):
val = b**p
if (val <= X) and (val > res):
res = val
print(res)
| import math
X = int(eval(input()))
res = 0
for b in range(1, int(math.sqrt(X))+1):
for p in range(2, int(math.sqrt(X))+2):
val = b**p
if (val <= X) and (val > res):
res = val
print(res)
| p03352 |
import math
X = int(eval(input()))
answer = 1
for i in range(X+1):
for j in range(2, X+1):
if i ** j <= X:
answer = max(answer, i ** j)
else:
break
print(answer)
| X = int(eval(input()))
answer = 1
for i in range(2, X+1):
j = 2
while i**j <= X:
answer = max(answer, i**j)
j += 1
print(answer) | p03352 |
import math
X = int(eval(input()))
i_max = math.floor(math.sqrt(X))
result = 1
for i in range(2,i_max+1,1):
for j in range(1,X):
n = (i**j)
if (n > X):
break
else:
result = max(result, n)
print(result)
| import math
X = int(eval(input()))
i_max = math.floor(math.sqrt(X))
result = 1
for i in range(2,i_max+1,1):
for j in range(2,X):
n = (i**j)
if (n > X):
break
else:
result = max(result, n)
print(result)
| p03352 |
x = int(eval(input()))
a = 0
for i in range(1,x+1):
for j in range(2,10):
if i**j <= x:
a = max(a,i**j)
print(a) | x = int(eval(input()))
a = 1
for i in range(1,x):
for j in range(2,x):
if i**j <= x:
a = max(a,i**j)
else:
break
print(a) | p03352 |
x = int(eval(input()))
a = 1
for i in range(1,x):
for j in range(2,x):
if i**j <= x:
a = max(a,i**j)
else:
break
print(a) | x = int(eval(input()))
a = 1
for i in range(2,x):
j = 2
while i**j <= x:
a = max(a,i**j)
j += 1
print(a) | p03352 |
list1=[1,2,4,8,16,32,64,128,256,512,9,27,81,243,729,25,125,625,49,343,100,1000,121]
num=eval(input())
num=int(num)
for i in range(12,32):
list1.append(i**2)
i+=1
list2=[]
for j in range(len(list1)):
if num>=list1[j]:
list2.append(list1[j])
j +=1
print((max(list2)))
| list1=[]
for b in range(1,33):
for p in range(2,11):
if b**p not in list1 and b**p<=1000:
list1.append(b**p)
elif b**p>1000:
break
list1.sort()
N=int(eval(input()))
ans=0
for i in range(len(list1)):
if list1[i]<=N:
ans=list1[i]
else:
break
print(ans)
| p03352 |
import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = int(sys.stdin.readline().rstrip())
ret = 1
for b in range(1, N):
for p in range(2, N//2):
if b ** p <= N:
ret = max(ret, b ** p)
print(ret)
if __name__ == '__main__':
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
if N == 1:
print((1))
exit()
b, p = 2, 1
ret = []
while b ** p <= N:
if b ** (p + 1) <= N:
p += 1
ret.append(b ** p)
else:
b += 1
p = 1
ret.sort(reverse=True)
print((ret[0]))
if __name__ == '__main__':
main()
| p03352 |
n=int(eval(input()))
max=0
if(n==1):
print((1))
else:
for i in range(n):
for j in range(2,10):
if(max<=i**j and i**j<=n):
max=i**j
print(max) | import math
n = int(eval(input()))
j = 2
tmp = 0
Max = 1
for i in range(2,n):
while(n > tmp):
tmp = i**j
j+=1
if(Max < tmp and n >= tmp):
Max = tmp
j = 2
tmp = 0
print(Max) | p03352 |
def pff(m):
pf = {}
for i in range(2, int(m ** 0.5) + 1):
while m % i == 0:
pf[i] = pf.get(i, 0) + 1
m //= i
if m > 1: pf[m] = 1
return pf
def examB():
X = I()
ans = 0
for i in range(X,0,-1):
cur = pff(i)
flag = True
now = 0
for j in list(cur.values()):
if j==1:
flag = False
if now==0:
now = j
else:
if now!=j:
flag = False
if flag:
ans = i
break
print(ans)
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')
examB() | def pff(m):
pf = {}
for i in range(2, int(m ** 0.5) + 1):
while m % i == 0:
pf[i] = pf.get(i, 0) + 1
m //= i
if m > 1: pf[m] = 1
return pf
def examB():
X = I()
ans = 0
for i in range(X,0,-1):
cur = pff(i)
flag = True
now = 0
for j in list(cur.values()):
if j==1:
flag = False
if now==0:
now = j
else:
if now%j!=0 and j%now!=0:
flag = False
if flag:
ans = i
break
print(ans)
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')
examB()
| p03352 |
x = int(eval(input()))
S = set()
S.add(1)
for b in range(2, int(1000**0.5) + 1):
for p in range(2, 10):
if b**p > 1000:
break
S.add(b**p)
for n in range(x, 0, -1):
if n in S:
print(n)
exit() | x = int(eval(input()))
ans = 1
for b in range(2, 33):
for p in range(2, 10):
n = b**p
if n > x:
break
ans = max(ans, n)
print(ans) | p03352 |
X = int(eval(input()))
ans = 1
for i in range(2,int(X**0.5)+1):
cnt = 2
y = i**cnt
while y<=X:
ans = max(ans,y)
cnt +=1
y = y*i
print(ans) | X = int(eval(input()))
if X==1:
print((1))
else:
cmax = 0
for i in range(2,int(X**0.5)+1):
k = 2
while i**k<=X:
k += 1
cmax = max(cmax,i**(k-1))
print(cmax) | p03352 |
X = int(eval(input()))
if X==1:
print((1))
else:
cmax = 1
for i in range(2,int(X**0.5)+1):
k = 2
while i**k<=X:
cmax = max(cmax,i**k)
k += 1
print(cmax) | X = int(eval(input()))
n = 1
if X<=3:
print((1))
elif X==4:
print((4))
else:
n = 4
for i in range(2,int(X**0.5)+1):
b = i
k = 1
while b**k<=X:
k += 1
k -= 1
if k>=2:
n = max(n,b**k)
print(n) | p03352 |
import math
X = int(eval(input()))
ans = 1
for i in range(X+1):
for j in range(2,max(math.floor(math.sqrt(X-i))+1,3)):
beki = False
tmp = X-i
while True:
if tmp%j != 0:
if tmp == 1:
beki = True
break
else:
tmp //= j
if beki:
ans = X-i
break
if beki:
break
print(ans)
| import math
X = int(eval(input()))
ans = 1
for i in range(2,max(3, math.floor(math.sqrt(X))+1)):
j = 2
while i**j <= X:
if i**j > ans:
ans = i**j
j += 1
print(ans)
| p03352 |
#素因数分解して列挙する関数、約数列挙ではない!
from collections import Counter
def factorize(n):
b = 2
fct = []
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b = b + 1
if n > 1:
fct.append(n)
f = list(Counter(fct).values())
if 1 not in f and len(set(f))==1:
return True
return False
X = int(eval(input()))
for i in range(X,0,-1):
f = factorize(i)
if f==True or i==1:
print(i)
break | def solve():
ans = 0
X = int(eval(input()))
lis = [False]*(X+1)
lis[1] = True
for b in range(2,X+1):
p = 2
while b**p<=X:
lis[b**p] = True
p += 1
for i in range(X,-1,-1):
if lis[i]==True:
return i
print((solve())) | p03352 |
#abc097 b bekijousu
import math
def large_num(n):
xx=x/n
p=1
while xx-n**p>=0:
p+=1
if p==1:
return 0
else:
return n**p
x=int(eval(input()))
b_last=int(math.sqrt(1000))
num=[i for i in range(2,b_last+1)]
ans=0
if 4>x:
ans=1
else:
for i in num:
ans=max(large_num(i),ans)
print(ans)
| #abc97 b
x=int(eval(input()))
beki=[1]
def gene_beki():
for b in range(2,36):
for p in range(2,10):
num=b**p
if num>x:
continue
else:
beki.append(num)
gene_beki()
print((max(beki))) | p03352 |
*r,=list(range(1,32));x=int(eval(input()));print((max(b**p*(b**p<=x)for p in r[1:]for b in r))) | r=list(range(1,32));x=int(eval(input()));print((max(b**p*(b**p<=x)for p in r[1:]for b in r))) | p03352 |
x = int(eval(input()))
c = 1
for b in range(1,x):
for q in range(2,x):
if b**q <=x:
c = max(c,b**q)
else:
break
print(c) | x = int(eval(input()))
c = []
for b in range(1,x+1):
for q in range(2,x+2):
a = b**q
if a <=x:
c.append(a)
else:
break
C = set(c)
print((max(C)))
| p03352 |
n = int(eval(input()))
l = []
for i in range(1,n+1):
for j in range(2,100):
if i**j <= n:
l.append(i**j)
print((max(l))) | n = int(eval(input()))
l = []
for i in range(1,n+1):
for j in range(2,10):
if i**j <= n:
l.append(i**j)
print((max(l))) | p03352 |
import math
x = int(eval(input()))
L = []
for i in range(2,int(math.floor(math.sqrt(x)))+1):
for j in range(x//i + 1):
if i ** j <= x:
L.append(i ** j)
if L == []:
print("1")
else:
print((max(L)))
| import math
x = int(eval(input()))
if x == 1 or x== 2 or x==3:
print((1))
exit()
s = math.floor(math.sqrt(x))
def l(k,p):
return(int(math.floor(math.log(p)/math.log(k))))
ans = 0
for i in range(2,s+1):
if i ** (1 + l(i,x)) <= x:
ans = max(ans, i ** (1+l(i,x)))
else:
ans = max(ans, i ** l(i,x))
if ans == x:
print(x)
exit()
print(ans) | p03352 |
X = int(eval(input()))
se = set(n**e for n in range(32) for e in range(2,11) if n**e <= X)
answer = max(se)
print(answer)
| X = int(eval(input()))
S = set(n**e for n in range(32) for e in range(2,11) if n**e<=X)
print((max(S)))
| p03352 |
X = int(eval(input()))
ans = 0
for b in range(X + 1):
for p in range(2, 10): #2^10=1024
tmp = b ** p
if tmp <= X and tmp > ans:
ans = tmp
print(ans)
| from bisect import bisect_right
expo = sorted(list(set([b**p for b in range(1, int(1000**0.5)+1) for p in range(2, 10) if b**p <= 1000])))
X = int(eval(input()))
print((expo[bisect_right(expo, X)-1]))
| p03352 |
from math import sqrt
X=int(eval(input()))
ans=0
for i in range(1,int(sqrt(X))+1):
now=i
b=2
while i!=1 and X>=i**b:
now=i**b
b+=1
ans=max(ans, now)
print(ans) | X=int(eval(input()))
ans=0
for i in range(1,33):
for j in range(2,11):
now=i**j
if ans<now and now<=X:
ans=now
print(ans)
| p03352 |
a = int(eval(input()))
l = []
for i in range(100):
for j in range(2,10):
if i**j <= a:
l.append(i**j)
print((max(l))) | a = int(eval(input()))
m = 1
for i in range(a//2+1):
for j in range(1,10):
if a>=i**j and m <i**j:
m = i**j
if a < i**j:
break
print(m)
| p03352 |
x = int(eval(input()))
ans = []
for b in range(1, 1000):
for p in range(2, 10):
tmp = b**p
if tmp <= x:
ans.append(tmp)
else:
break
print((max(*ans)))
| x = int(eval(input()))
ans = 1
for b in range(1, int(1000**.5)+1):
for p in range(2, 10):
y = b**p
if y <= x and ans < y:
ans = y
print(ans)
| p03352 |
import math
x = int(eval(input()))
max_bp = 0
for b in range(1, x + 1):
for p in range(2, x + 2):
bp = b ** p
if bp > x:
break
max_bp = max(max_bp, bp)
print(max_bp) | # B. Exponential
# https://atcoder.jp/contests/abc097/tasks/abc097_b
x = int(eval(input()))
ans = 1
for b in range(2, int(x ** .5) + 2):
p = 2
while b ** p <= x:
ans = max(ans, b ** p)
p += 1
print(ans) | p03352 |
def judge(x):
for i in range(2, x):
t = x
while t != 1:
if t % i == 0:
t //= i
else:
break
if t == 1:
return True
return False
x = int(eval(input()))
ans = 1
for i in range(x, 1, -1):
if judge(i):
ans = i
break
print(ans)
| x = int(eval(input()))
ans = 1
for base in range(1, 101):
for p in range(2, 10):
if base**p > x:
break
ans = max(ans, base**p)
print(ans) | p03352 |
import math
X = int(eval(input()))
beki = []
beki.append(1)
Xruto = math.sqrt(X)
Xruto = math.floor(Xruto)
for i in range(2, Xruto+1):
for j in range(10):
a = pow(i, j)
if a <= X:
beki.append(a)
else:
break
print((max(beki)))
| import math
X = int(eval(input()))
ans = 1
Y = math.floor(math.sqrt(X))
for i in range(2, Y+1):
for j in range(2, 10):
a = i**j
if a <= X:
ans = max(ans, a)
print(ans)
| p03352 |
x=int(eval(input()))
for i in range(x,0,-1):
for p in range(1,int(i**.5)+1):
for q in range(10):
if i==p**q:
print(i)
break
else:
continue
break
else:
continue
break
| x = int(eval(input()))
res = 0
for i in range(1,int(x**.5)+1):
for j in range(2,1000):
if i ** j > x:
break
res = max(res, i ** j)
print(res)
| p03352 |
x = int(eval(input()))
res = 0
for i in range(1,int(x**.5)+1):
for j in range(2,1000):
if i ** j > x:
break
res = max(res, i ** j)
print(res)
| n = int(eval(input()))
def check(num):
for i in range(2, 33):
j = i * i
while j < num:
j *= i
else:
if j == num:
return True
return False
if n == 1:
print((1))
exit()
while True:
if check(n):
print(n)
exit()
n -= 1
if n == 1:
break
print((1))
| p03352 |
x = int(eval(input()))
print((max([pow(i, j) for i in range(1, 32)
for j in range(2, 10) if pow(i, j) <= x])))
| x = int(eval(input()))
table = [False] * -~x
table[1] = True
for i in range(2, 32):
j = i * i
while j <= x:
table[j] = True
j *= i
print((max(i for i in range(x + 1) if table[i])))
| p03352 |
x=int(eval(input()))
p=10
ans=0
for i in range(1,1+x):
for j in range(2,p+1):
if i**j<=x:
ans=max(ans,i**j)
print(ans) | x=int(eval(input()))
maxim=0
for i in range(2,32):
for j in range(2,10):
temp=i**j
if temp<=x and maxim<temp:
maxim=temp
print((maxim if maxim>0 else 1)) | p03352 |
from math import sqrt
x=int(eval(input()))
c=1
for b in range(1,int(sqrt(x))+1):
for p in range(2,x):
if b**p<=x:
c=max(b**p,c)
else:
break
print(c)
| from math import sqrt
x=int(eval(input()))
c=1
for b in range(1,int(sqrt(x))+1):
for p in range(2,10):
if b**p<=x:
c=max(b**p,c)
else:
break
print(c)
| p03352 |
X = int(eval(input()))
ans = 1
for i in range(1, X):
for p in [2, 3, 5, 7]:
calc = i**p
if(calc <= X):
ans = max(ans, calc)
print(ans) | X = int(eval(input()))
ans = 1
for i in range(1,X+1):
for p in [2, 3, 5, 7]:
if(i**p <= X):
ans = max(ans, i**p)
print(ans) | p03352 |
from bisect import bisect_right
cands = []
for i in range(2, 400):
cur = i
while cur * i <= 1000:
cands.append(cur * i)
cur *= i
cands.sort()
X = int(eval(input()))
if X == 1:
print((1))
else:
print((cands[bisect_right(cands, X) - 1]))
| X = int(eval(input()))
ans = 1
for i in range(2, 32):
for j in range(2, 10):
if i ** j > X:
continue
ans = max(ans, i ** j)
print(ans)
| p03352 |
from math import sqrt
x = int(eval(input()))
cnt = 0
l = []
for i in range(1, x + 1):
for j in range(1, int(sqrt(i)) +1):
for k in range(2, 10):
if j ** k == i:
l.append(i)
print((max(l))) | from math import sqrt
x = int(eval(input()))
l = []
for i in range(1, x + 1):
for j in range(1, int(sqrt(i)) +1):
for k in range(2, 10):
if j ** k == i:
l.append(i)
print((max(l))) | p03352 |
x = int(eval(input()))
list_ = []
if x == 1:
print((1))
else:
b = 2
while b**2 <= x:
p = 2
while b**p <= x:
list_.append(b**p)
p += 1
b += 1
print((max(list_))) | x = int(eval(input()))
ans = 1
if x == 1:
print((1))
else:
b = 2
while b**2 <= x:
p = 2
while b**p <= x:
ans = max(b**p, ans)
p += 1
b += 1
print(ans) | p03352 |
x=int(eval(input()))
ans=[]
for i in range(int(x**(1/2))+1):
for j in range(int(x**(1/2))+1):
if i**j<=x:
ans.append(i**j)
print((max(ans))) | x=int(eval(input()))
print((max([i**j for i in range(33) for j in range(2,10) if i**j<=x]))) | p03352 |
import math
ans = 0
X = int(eval(input()))
if X<4:
print((1))
else:
for i in range(2,math.ceil(math.sqrt(X))):
for j in range(math.ceil(math.log(X)/math.log(i))+1):
if i**j <= X:
ans = max(i**j,ans)
print(ans)
| ans = 0
X = int(eval(input()))
for i in range(1,33):
for j in range(2,11):
if i**j <= X:
ans = max(ans,i**j)
print(ans) | p03352 |
# ABC097 B Exponential
x = int(eval(input()))
ans = 0
for i in range(1,33):
for j in range(2,10):
t = i**j
if t <= x:
ans = max(t,ans)
print(ans) | x=int(eval(input()))
exp=[0]*(x+1)
exp[1]=1
ans=0
for i in range(2,x+1):
t=i*i
while t<=x:
exp[t]=1
t*=i
for i in range(1,x+1):
if exp[i]:
ans=max(i,ans)
print(ans) | p03352 |
x=int(eval(input()))
a=set()
for i in range(1,1001):
for j in range(2,34):
t=i**j
if t<=x:
a.add(i**j)
a=list(a)
a.sort()
print((a[-1])) | x=int(eval(input()))
ans=0
for i in range(1,35):
for j in range(2,10):
t=i**j
if t<=x:
ans=max(ans,t)
print(ans)
| p03352 |
x=int(eval(input()))
v=[]
for i in range(1,32):
for j in range(2,1000):
if i**j<=x and (i+1)**j>x:
v.append(i**j)
print((max(v))) | x=int(eval(input()))
v=[]
for j in range(2,11):
for i in range(1,32):
if i**j<=x and (i+1)**j>x:
v.append(i**j)
break
print((max(v)))
| p03352 |
x = int(eval(input()))
ans = 0
for i in range(1, 1000):
for j in range(2, 10):
if i ** j <= x:
ans = max(i ** j, ans)
print(ans) | x = int(eval(input()))
ans = 0
if x == 1:
ans = 1
else:
for i in range(2, 100):
n = 2
while i ** n <= x:
ans = max(ans , i ** n)
n += 1
print(ans) | p03352 |
X = int(eval(input()))
ans = 1
for b in range(2,X):
for p in range(2,X):
tmp_ans = b ** p
if tmp_ans > X:
break
if tmp_ans > ans:
ans = tmp_ans
print(ans) | X = int(eval(input()))
ans = 1
for b in range(1, X):
for p in range(2, X):
tmp = b ** p
if tmp > X:
break
if ans < tmp:
ans = tmp
print(ans) | p03352 |
import math
x=int(eval(input()))
ans=[1]
for i in range(2,x+1):
#print(i)
k=int(math.log(x,i))
if k>=2:
if i**(k+1) <= x:
ans.append(i**(k+1))
else:
ans.append(i**k)
print((max(ans)))
#print(ans)
| x=int(eval(input()))
ans=[1]
for i in range(2,x+1):
k=2
while True:
a=i**k
if a<=x:
ans.append(a)
k+=1
else:
break
print((max(ans))) | p03352 |
X = int(eval(input()))
ans = 0
for i in range(1, 100):
for j in range(2, 100):
if i ** j <= X:
ans = max(ans, i ** j)
print(ans)
| X = int(eval(input()))
ans = 1
for b in range(2, 40):
p = 2
while True:
val = b ** p
if val > X:
break
ans = max(ans, val)
p += 1
print(ans)
| p03352 |
import sys
def solve(X, Y, Z, V, E, A):
dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)]
dp[0][0] = 1.0
for i in range(Y):
for j in range(5001):
if dp[i][j] <= 0.0:
continue
for k in V:
t = i + k
if t > Y:
dp[Y][j] += dp[i][j]/X
elif E[t] == 1:
dp[min(Y, t+A[t])][j] += dp[i][j]/X
else:
dp[t][max(0, j+A[t])] += dp[i][j]/X
s = 0
for i in range(5001):
if dp[Y][i] <= 0.0:
continue
s += i * dp[Y][i]
print((int(s)))
while True:
X, Y, Z = list(map(int, input().split()))
if X | Y | Z == 0:
sys.exit()
V = list(map(int, input().split()))
E = [0] * 100
A = [0] * 100
for _ in range(Z):
n, e, a = list(map(int, input().split()))
E[n] = e
if e == 3:
A[n] = -a
else:
A[n] = a
solve(X, Y, Z, V, E, A) | def solve(X, Y, Z, V, E, A):
dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)]
dp[0][0] = 1.0
for i in range(Y):
for j in range(5001):
if dp[i][j] <= 0.0:
continue
for k in V:
t = i + k
if t > Y:
dp[Y][j] += dp[i][j]/X
elif E[t] == 1:
dp[min(Y, t+A[t])][j] += dp[i][j]/X
else:
dp[t][max(0, j+A[t])] += dp[i][j]/X
s = 0
for i in range(5001):
if dp[Y][i] <= 0.0:
continue
s += i * dp[Y][i]
print(int(s))
if __name__ == "__main__":
import sys
while True:
X, Y, Z = list(map(int, input().split()))
if X | Y | Z == 0:
sys.exit()
V = list(map(int, input().split()))
E = [0] * 100
A = [0] * 100
for _ in range(Z):
n, e, a = list(map(int, input().split()))
E[n] = e
if e == 3:
A[n] = -a
else:
A[n] = a
solve(X, Y, Z, V, E, A) | p00232 |
while True:
x, y, z = list(map(int, input().split()))
if x==0 and y==0 and z==0: break
dp = [[0.0 for col in range(5101)] for row in range(61)]
m = {}
for i in range(y+10):
m[i] = (0,0)
v = []
v = list(map(int, input().split()))
for i in range(z):
n, e, a = list(map(int, input().split()))
m[n] = (e, a)
dp[0][0] = 1.0
for i in range(y):
for j in range(5001):
for k in range(x):
nx = i + v[k]
if m[nx][0] == 1:
dp[min(y,nx+m[nx][1])][j]+=dp[i][j]/x
elif m[nx][0]==2:
dp[nx][j+m[nx][1]]+=dp[i][j]/x
elif m[nx][0]==3:
dp[nx][max(0,j-m[nx][1])]+=dp[i][j]/x
else:
dp[min(y,nx)][j] += dp[i][j]/x
ans = 0.0
for i in range(5001):
ans += dp[y][i]*i
print(int(ans)) | while True:
x, y, z = list(map(int, input().split()))
if x==0 and y==0 and z==0: break
dp = [[0.0 for col in range(5101)] for row in range(61)]
m = {}
for i in range(y+10):
m[i] = (0,0)
v = []
v = list(map(int, input().split()))
for i in range(z):
n, e, a = list(map(int, input().split()))
m[n] = (e, a)
dp[0][0] = 1.0
for i in range(y):
for j in range(y*100):
if dp[i][j] == 0.0: continue
for k in range(x):
nx = i + v[k]
if m[nx][0] == 1:
dp[min(y,nx+m[nx][1])][j]+=dp[i][j]/x
elif m[nx][0]==2:
dp[nx][j+m[nx][1]]+=dp[i][j]/x
elif m[nx][0]==3:
dp[nx][max(0,j-m[nx][1])]+=dp[i][j]/x
else:
dp[min(y,nx)][j] += dp[i][j]/x
ans = 0.0
for i in range(5001):
ans += dp[y][i]*i
print(int(ans)) | p00232 |
while 1:
x,y,z=list(map(int,input().split()))
if x==0 and y==0 and z==0:break
v=list(map(int,input().split()))
event=[[] for _ in range(y+1)]
maxm=0
for i in range(z):
n,e,a=list(map(int,input().split()))
event[n].append(e)
event[n].append(a)
if e==2:
maxm+=a
dp=[[0]*(5005) for _ in range(y+1)]
dp[0][0]=1
x=float(x)
for i in range(y):
for k in range(maxm+1):
for j in range(int(x)):
if i+v[j]>=y:
dp[y][k]+=dp[i][k]/x
continue
if event[i+v[j]]==[]:
dp[i+v[j]][k]+=dp[i][k]/x
elif event[i+v[j]][0]==1:
skip=event[i+v[j]][1]
dp[min(y,i+skip)][k]+=dp[i][k]/x
elif event[i+v[j]][0]==2:
m=event[i+v[j]][1]
dp[i+v[j]][k+m]+=dp[i][k]/x
else:
m=event[i+v[j]][1]
dp[i+v[j]][max(0,k-m)]+=dp[i][k]/x
ans=0.0
for i in range(maxm+1):
ans+=dp[y][i]*i
print((int(ans))) | def solve(x,y,maxm):
for i in range(y):
for j in range(maxm+1):
if dp[i][j]==0:continue
for k in range(int(x)):
if event[min(y,i+v[k])][0]==0:
dp[min(y,i+v[k])][j]+=dp[i][j]/x
elif event[i+v[k]][0]==1:
skip=event[i+v[k]][1]
dp[min(y,i+v[k]+skip)][j]+=dp[i][j]/x
elif event[i+v[k]][0]==2:
m=event[i+v[k]][1]
dp[i+v[k]][j+m]+=dp[i][j]/x
else:
m=event[i+v[k]][1]
dp[i+v[k]][max(0,j-m)]+=dp[i][j]/x
return dp
while 1:
x,y,z=list(map(int,input().split()))
if x==0 and y==0 and z==0:break
v=list(map(int,input().split()))
event=[[0]*2 for _ in range(y+1)]
maxm=0
for i in range(z):
n,e,a=list(map(int,input().split()))
event[n][0]=e
event[n][1]=a
if e==2:
maxm+=a
dp=[[0]*(5005) for _ in range(y+1)]
dp[0][0]=1
x=float(x)
dp=solve(x,y,maxm)
ans=0.0
for i in range(maxm+1):
ans+=dp[y][i]*i
print((int(ans))) | p00232 |
import sys
readline = sys.stdin.readline
X,Y,Z,K = list(map(int, readline().split()))
a = sorted(list(map(int, readline().split())), reverse=True)
b = sorted(list(map(int, readline().split())), reverse=True)
c = sorted(list(map(int, readline().split())), reverse=True)
ab = []
for ai in a:
for bj in b:
ab.append(ai+bj)
ab.sort(reverse=True)
ab = ab[:K]
cond = []
for abi in ab:
for cj in c:
cond.append(abi+cj)
cond = sorted(cond, reverse=True)[:K]
for condi in cond:
print(condi)
| import sys
readline = sys.stdin.readline
X, Y, Z, K = list(map(int, readline().split()))
A = sorted(list(map(int, readline().split())), reverse=True)
B = sorted(list(map(int, readline().split())), reverse=True)
C = sorted(list(map(int, readline().split())), reverse=True)
ABC = []
for a in range(X):
for b in range(Y):
if (a+1)*(b+1) > K:
break
for c in range(Z):
if (a+1)*(b+1)*(c+1) > K:
break
ABC.append(A[a] + B[b] + C[c])
for ai in sorted(ABC, reverse=True)[:K]:
print(ai)
| p03078 |
x,y,z,k = list(map(int,input().split()))
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
Alist.sort(reverse=True)
Blist.sort(reverse=True)
Clist.sort(reverse=True)
ABlist = []
for i in Alist[:k]:
for j in Blist[:k]:
ABlist.append(i + j)
ABlist.sort(reverse=True)
ABClist = []
for i in ABlist[:k]:
for j in Clist[:k]:
ABClist.append(i + j)
ABClist.sort(reverse=True)
for i in range(k):
print((ABClist[i]))
| x,y,z,k = map(int,input().split())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
Alist.sort(reverse=True)
Blist.sort(reverse=True)
Clist.sort(reverse=True)
ABlist = [i + j for i in Alist[:k] for j in Blist[:k]]
ABlist.sort(reverse=True)
ABClist = [l + m for l in ABlist[:k] for m in Clist[:k]]
ABClist.sort(reverse=True)
print(*ABClist[:k], sep = '\n')
| p03078 |
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)
X, Y, Z, K = LI()
A = sorted(LI(), reverse=True)
B = sorted(LI(), reverse=True)
C = sorted(LI(), reverse=True)
A = A[:min(250, X)]
B = B[:min(250, Y)]
C = C[:min(250, Z)]
# Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
# 3000個大きい順に求めれば良い
# iが決まれば、j,kのおおきさは分かる
BC = []
# 1000*1000 で10**6の計算量
for j in range(len(B)):
for k in range(len(C)):
BC.append(B[j] + C[k])
points = []
# 10**3 と 10** 6
for i in range(len(A)):
points += [bc + A[i] for bc in BC]
# # for i in range(len(A)):
# # for bc in BC:
# # points.append(A[i]+bc)
# # # for j in range(len(B)):
# # # for k in range(len(C)):
# # # point = A[i] + B[j] + C[k]
# # # points.append(point)
for i in sorted(points, reverse=True)[:K]:
print(i)
| import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)
"""
最大、最大2なら、あとはなにかけあわせても最大しかない
ABCの最大2個なので、プラス残りのlen()を足す。
もし超えたら、その組み合わせで順番にもとめていく
"""
X, Y, Z, K = LI()
A = sorted(LI(), reverse=True)
B = sorted(LI(), reverse=True)
C = sorted(LI(), reverse=True)
e = []
for a in A:
for b in B:
e.append(a+b)
e = sorted(e, reverse=True)[:K]
results = []
for item in e:
for c in C:
results.append(item+c)
for i in sorted(results, reverse=True)[:K]:
print(i)
# # ABC = A+B+C
# # ABC = sorted(ABC, reverse=True)
# # # print(ABC)
# INF = 10**18
# a,b,c = [INF],[INF],[INF]
# # abc = 0
# count = 0
# while a[-1] > B[0] or a[-1] > C[0] or len(a) <= min(50, X):
# a.append(A[count])
# count += 1
# if count >= len(A):
# break
# count = 0
# while b[-1] > A[0] or b[-1] > C[0] or len(b) <= min(50, Y):
# b.append(B[count])
# count += 1
# if count >= len(B):
# break
# count = 0
# while c[-1] > B[0] or c[-1] > A[0] or len(c) <= min(50, Z):
# c.append(C[count])
# count += 1
# if count >= len(C):
# break
# a = a[1:]
# b = b[1:]
# c = c[1:]
# # while a[-1] > b[0] and a[-1] > c[0] and b[-1] > a[0] and b[-1] > c[0] and c[-1] > a[0] and c[-1] > b[0]:
# # while not(len(a) >= min(100, X) and len(b) >= min(100, Y) and len(c) >= min(100, Z)):
# # if A:
# # if ABC[abc]in A:
# # a.append(ABC[abc])
# # A.remove(ABC[abc])
# # if B:
# # if ABC[abc]in B:
# # b.append(ABC[abc])
# # B.remove(ABC[abc])
# # if C:
# # if ABC[abc]in C:
# # c.append(ABC[abc])
# # C.remove(ABC[abc])
# # abc+=1
# # # for abc in range(min(200, X+Y+Z)):
# # # if ABC[abc]in A:
# # # a.append(ABC[abc])
# # # A.remove(ABC[abc])
# # # if ABC[abc]in B:
# # # b.append(ABC[abc])
# # # B.remove(ABC[abc])
# # # if ABC[abc]in C:
# # # c.append(ABC[abc])
# # # C.remove(ABC[abc])
# # # print(a,b,c)
# points = []
# for i in a:
# for j in b:
# for k in c:
# points.append(i+j+k)
# # print(points)
# # # A = A[:min(250, X)]
# # # B = B[:min(250, Y)]
# # # C = C[:min(250, Z)]
# # # # Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
# # # # 3000個大きい順に求めれば良い
# # # # iが決まれば、j,kのおおきさは分かる
# # # BC = []
# # # # 1000*1000 で10**6の計算量
# # # # for j in range(len(B)):
# # # # for k in range(len(C)):
# # # # BC.append(B[j] + C[k])
# # # points = []
# # # # 10**3 と 10** 6
# # # # for i in range(len(A)):
# # # # points += [bc + A[i] for bc in BC]
# # # for i in range(len(A)):
# # # # for bc in BC:
# # # # points.append(A[i]+bc)
# # # for j in range(len(B)):
# # # for k in range(len(C)):
# # # points.append(A[i] + B[j] + C[k])
# for i in sorted(points, reverse=True)[:K]:
# print(i)
| p03078 |
#!/usr/bin/env python3
import sys
def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
C.sort(reverse=True)
count = 0
AB = []
for i in range(X):
for j in range(Y):
AB.append(A[i]+B[j])
AB.sort(reverse=True)
AB = AB[:K]
ABC = []
for k in range(Z):
for ab_index in range(len(AB)):
ABC.append(C[k]+AB[ab_index])
ABC.sort(reverse=True)
ABC = ABC[:K]
for i in range(len(ABC)):
print((ABC[i]))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
Z = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(X)] # type: "List[int]"
B = [int(next(tokens)) for _ in range(Y)] # type: "List[int]"
C = [int(next(tokens)) for _ in range(Z)] # type: "List[int]"
solve(X, Y, Z, K, A, B, C)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
AB = []
for i in range(X):
for j in range(Y):
AB.append(A[i]+B[j])
AB.sort(reverse=True)
AB = AB[:K]
ABC = []
for k in range(Z):
for ab_index in range(len(AB)):
ABC.append(C[k]+AB[ab_index])
ABC.sort(reverse=True)
ABC = ABC[:K]
for i in range(len(ABC)):
print((ABC[i]))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
Z = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(X)] # type: "List[int]"
B = [int(next(tokens)) for _ in range(Y)] # type: "List[int]"
C = [int(next(tokens)) for _ in range(Z)] # type: "List[int]"
solve(X, Y, Z, K, A, B, C)
if __name__ == '__main__':
main()
| p03078 |
x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
p = []
for i in a:
for j in b:
p.append(i+j)
p.sort(reverse=True)
p = p[:min(3001, x*y*z+1)]
q = []
for i in p:
for j in c:
q.append(i+j)
q.sort(reverse=True)
for i in range(k):
print((q[i])) | x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
p = []
for i in a:
for j in b:
p.append(i+j)
p.sort(reverse=True)
p = p[:min(3001, x*y*z+1)]
q = []
for j in c:
for i in p:
q.append(i+j)
q.sort(reverse=True)
for i in range(k):
print((q[i])) | p03078 |
x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
p = []
for h in range(min(x,k)):
for i in range(y):
if h*i <= k:
for j in range(z):
if h*i*j <= k:
p.append(a[h]+b[i]+c[j])
p.sort(reverse=True)
for i in range(k):
print((p[i])) | x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
p = []
for h in range(min(x,k)):
for i in range(y):
if h*i > k:
break
for j in range(z):
if h*i*j > k:
break
p.append(a[h]+b[i]+c[j])
p.sort(reverse=True)
for i in range(k):
print((p[i])) | p03078 |
X,Y,Z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
sorted_abcsum = sorted([A[x] + B[y] + C[z] for x in range(X) for y in range(Y) for z in range(Z)],reverse=True)
for k in range(K):
print((sorted_abcsum[k])) | X,Y,Z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)
print((asort[0] + bsort[0] + csort[0]))
already = [[0,0,0]]
x,y,z = 0,0,0
place_sum = []
check = []
for k in range(K - 1):
if [x + 1,y,z] not in already and x + 1 < X:
already.append([x + 1,y,z])
place_sum.append([x + 1,y,z])
check.append(asort[x + 1] + bsort[y] + csort[z])
if [x,y + 1,z] not in already and y + 1 < Y:
already.append([x,y + 1,z])
place_sum.append([x,y + 1,z])
check.append(asort[x] + bsort[y + 1] + csort[z])
if [x,y,z + 1] not in already and z + 1 < Z:
already.append([x,y,z + 1])
place_sum.append([x,y,z + 1])
check.append(asort[x] + bsort[y] + csort[z + 1])
print((max(check)))
x,y,z = place_sum[check.index(max(check))][0],place_sum[check.index(max(check))][1],place_sum[check.index(max(check))][2]
place_sum.pop(check.index(max(check)))
check.remove(max(check)) | p03078 |
import heapq
X,Y,Z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)
already = [[0,0,0]]
print((asort[0] + bsort[0] + csort[0]))
x,y,z = 0,0,0
check = []
for k in range(K - 1):
if [x + 1,y,z] not in already and x + 1 < X:
already.append([x + 1,y,z])
heapq.heappush(check,(-(asort[x + 1] + bsort[y] + csort[z]),x + 1,y,z))
if [x,y + 1,z] not in already and y + 1 < Y:
already.append([x,y + 1,z])
heapq.heappush(check,(-(asort[x] + bsort[y + 1] + csort[z]),x,y + 1,z))
if [x,y,z + 1] not in already and z + 1 < Z:
already.append([x,y,z + 1])
heapq.heappush(check,(-(asort[x] + bsort[y] + csort[z + 1]),x,y,z + 1))
maxsum = heapq.heappop(check)
print((-maxsum[0]))
x,y,z = maxsum[1],maxsum[2],maxsum[3] | import heapq
_x, _y, _z, k = list(map(int, input().split()))
aa = list(reversed(sorted(map(int, input().split()))))
bb = list(reversed(sorted(map(int, input().split()))))
cc = list(reversed(sorted(map(int, input().split()))))
ar = []
history = set()
def push(x, y, z):
if (x, y, z) in history:
pass
else:
v = aa[x] + bb[y] + cc[z]
heapq.heappush(ar, (-v, x, y, z))
history.add((x, y, z))
def pop():
(v, x, y, z) = heapq.heappop(ar)
return (-v, x, y, z)
push(0, 0, 0)
for _ in range(k):
(total, x, y, z) = pop()
print(total)
if x + 1 < len(aa):
push(x + 1, y, z)
if y + 1 < len(bb):
push(x, y + 1, z)
if z + 1 < len(cc):
push(x, y, z + 1) | p03078 |
X, Y, Z, K = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))
z = sorted(list(map(int, input().split())))
import heapq
shou = 3 * 10**10 + 1
ans = []
for i in range(X-1, -1, -1):
for j in range(Y-1, -1, -1):
for k in range(Z-1, -1, -1):
if (X-i)*(Y-j)*(Z-k) <= K:
sub = x[i]+y[j]+z[k]
ans.append(sub)
ans = list([x*(-1) for x in ans])
heapq.heapify(ans)
for i in range(K):
print((heapq.heappop(ans)*(-1))) | X, Y, Z, K = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))
z = sorted(list(map(int, input().split())))
import heapq
ans = []
for i in range(X-1, -1, -1):
for j in range(Y-1, -1, -1):
for k in range(Z-1, -1, -1):
if (X-i)*(Y-j)*(Z-k) <= K:
sub = x[i]+y[j]+z[k]
ans.append(sub)
else:
break
ans = list([x*(-1) for x in ans])
heapq.heapify(ans)
for i in range(K):
print((heapq.heappop(ans)*(-1))) | p03078 |
X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))[::-1]
A_B = []
for a in A:
for b in B:
A_B.append(a + b)
A_B = sorted(A_B)
def bin_search(mid):
res = 0
idx = 0
ans = []
for c in C:
while idx < len(A_B):
if c + A_B[idx] >= mid:
res += len(A_B) - idx
ans.append((c, idx))
break
else:
idx += 1
return res, ans
ok = 0
ng = pow(10, 10) * 3 + 1
while ok + 1 < ng:
mid = (ok + ng) // 2
res, ans = bin_search(mid)
if res >= K:
ok = mid
else:
ng = mid
res, ans = bin_search(ok)
tmp_ans = []
for c, idx in ans:
for i in range(idx, len(A_B)):
tmp_ans.append(A_B[i] + c)
for ans in sorted(tmp_ans)[::-1][:K]:
print(ans) | X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))[::-1]
A_B = []
for a in A:
for b in B:
A_B.append(a + b)
A_B = sorted(A_B)[::-1][:K]
ans = []
for a_b in A_B:
for c in C:
ans.append(a_b + c)
for a in sorted(ans)[::-1][:K]:
print(a) | p03078 |
x, y, z, k = list(map(int, input().split()))
Lis = []
for _ in range(3):
L = list(map(int, input().split()))
L.sort(reverse=True)
Lis.append(L)
Li = [[0, 0, 0]]
def search():
global dic
L = []
for a, b, c in Li:
for d, e, f in [[1, 0, 0], [0, 1, 0], [0, 0, 1]]:
if a+d < x and b+e < y and c+f < z and [a+d, b+e, c+f] not in Li:
re = Lis[0][a+d] + Lis[1][b+e] + Lis[2][c+f]
L.append([re, a+d, b+e, c+f])
L.sort(reverse=True)
Li.append([L[0][1], L[0][2], L[0][3]])
return L[0][0]
for i in range(k):
if i == 0:
ans = Lis[0][0] + Lis[1][0] + Lis[2][0]
print(ans)
else:
print((search()))
| x, y, z, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
Q.append([A[0]+B[0]+C[0], 0, 0, 0])
M = {(0, 0, 0):True}
def search():
global Q
q = Q.pop()
a = q[1]
b = q[2]
c = q[3]
if a+1 < x and (a+1, b, c) not in M:
Q.append([A[a+1]+B[b]+C[c], a+1, b, c])
M[(a+1, b, c)] = True
if b+1 < y and (a, b+1, c) not in M:
Q.append([A[a]+B[b+1]+C[c], a, b+1, c])
M[(a, b+1, c)] = True
if c+1 < z and (a, b, c+1) not in M:
Q.append([A[a]+B[b]+C[c+1], a, b, c+1])
M[(a, b, c+1)] = True
Q.sort()
return q[0]
for _ in range(k):
print((search())) | p03078 |
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
def main():
x,y,z,k=MI()
A=sorted(LI(),reverse=True)
B=sorted(LI(),reverse=True)
C=sorted(LI(),reverse=True)
Q=[[(A[0]+B[0]+C[0])*(-1),0,0,0]]
heapify(Q)
#print(Q)
i=0
ans=[]
#print(heappop(Q))
#al=[[[-1]*x for i in range(y)] for j in range(z)]
#al[0][0][0]=0
xl,yl,zl=0,0,0
al=[]
al=[[0,0,0]]
while i<k:
#print(Q)
if not Q:
sys.exit()
a,u,v,w=heappop(Q)
ans.append(-a)
i+=1
if u+1<x and (not ([u+1,v,w] in al)):
heappush(Q,[-A[u+1]-B[v]-C[w],u+1,v,w])
al.append([u+1,v,w])
#al[u+1][v][w]=0
if v+1<y and not([u,v+1,w] in al):
heappush(Q,[-A[u]-B[v+1]-C[w],u,v+1,w])
al.append([u,v+1,w])
#al[u][v+1][w]=0
if w+1<z and not([u,v,w+1] in al):
heappush(Q,[-A[u]-B[v]-C[w+1],u,v,w+1])
al.append([u,v,w+1])
#print(len(ans))
for i in range(k):
print((ans[i]))
if __name__=="__main__":
main()
| # coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
def main():
x,y,z,k=MI()
set_=set()
A=sorted(LI(),reverse=True)
B=sorted(LI(),reverse=True)
C=sorted(LI(),reverse=True)
Q=[[(A[0]+B[0]+C[0])*(-1),0,0,0]]
heapify(Q)
set_.add((0,0,0))
#print(Q)
i=0
ans=[]
#print(heappop(Q))
#al=[[[-1]*x for i in range(y)] for j in range(z)]
#al[0][0][0]=0
xl,yl,zl=0,0,0
al=[]
al=[[0,0,0]]
while i<k:
#print(Q)
a,u,v,w=heappop(Q)
ans.append([-a,u,v,w])
print((-a))
i+=1
if u+1<x and (u+1,v,w) not in set_:
heappush(Q,[-A[u+1]-B[v]-C[w],u+1,v,w])
set_.add((u+1,v,w))
#al.append([u+1,v,w])
#al[u+1][v][w]=0
if v+1<y and (u,v+1,w) not in set_:
heappush(Q,[-A[u]-B[v+1]-C[w],u,v+1,w])
set_.add((u,v+1,w))
#al.append([u,v+1,w])
#al[u][v+1][w]=0
if w+1<z and (u,v,w+1) not in set_:
heappush(Q,[-A[u]-B[v]-C[w+1],u,v,w+1])
set_.add((u,v,w+1))
#al.append([u,v,w+1])
if __name__=="__main__":
main()
| p03078 |
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
def main():
x,y,z,k=MI()
set_=set()
A=sorted(LI(),reverse=True)
B=sorted(LI(),reverse=True)
C=sorted(LI(),reverse=True)
Q=[[(A[0]+B[0]+C[0])*(-1),0,0,0]]
heapify(Q)
set_.add((0,0,0))
#print(Q)
i=0
ans=[]
#print(heappop(Q))
#al=[[[-1]*x for i in range(y)] for j in range(z)]
#al[0][0][0]=0
xl,yl,zl=0,0,0
al=[]
al=[[0,0,0]]
while i<k:
#print(Q)
a,u,v,w=heappop(Q)
ans.append([-a,u,v,w])
print((-a))
i+=1
if u+1<x and (u+1,v,w) not in set_:
heappush(Q,[-A[u+1]-B[v]-C[w],u+1,v,w])
set_.add((u+1,v,w))
#al.append([u+1,v,w])
#al[u+1][v][w]=0
if v+1<y and (u,v+1,w) not in set_:
heappush(Q,[-A[u]-B[v+1]-C[w],u,v+1,w])
set_.add((u,v+1,w))
#al.append([u,v+1,w])
#al[u][v+1][w]=0
if w+1<z and (u,v,w+1) not in set_:
heappush(Q,[-A[u]-B[v]-C[w+1],u,v,w+1])
set_.add((u,v,w+1))
#al.append([u,v,w+1])
if __name__=="__main__":
main()
| # coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
x,y,z,k=MI()
set_=set()
A=sorted(LI(),reverse=True)
B=sorted(LI(),reverse=True)
C=sorted(LI(),reverse=True)
Q=[[(A[0]+B[0]+C[0])*(-1),0,0,0]]
heapify(Q)
set_.add((0,0,0))
i=0
ans=[]
xl,yl,zl=0,0,0
al=[]
al=[[0,0,0]]
while i<k:
a,u,v,w=heappop(Q)
ans.append([-a,u,v,w])
print((-a))
i+=1
if u+1<x and (u+1,v,w) not in set_:
heappush(Q,[-A[u+1]-B[v]-C[w],u+1,v,w])
set_.add((u+1,v,w))
if v+1<y and (u,v+1,w) not in set_:
heappush(Q,[-A[u]-B[v+1]-C[w],u,v+1,w])
set_.add((u,v+1,w))
if w+1<z and (u,v,w+1) not in set_:
heappush(Q,[-A[u]-B[v]-C[w+1],u,v,w+1])
set_.add((u,v,w+1))
| p03078 |
x, y, z, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)
p = []
for i in range(x):
for j in range(y):
for l in range(z):
if (i+1) * (j+1) * (l+1) <= k:
p.append(a[i]+b[j]+c[l])
p.sort(reverse=True)
for i in range(k):
print((p[i])) | x, y, z, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)
p = []
for i in range(x):
if i <= k:
for j in range(y):
if (i+1) * (j+1) <= k:
for l in range(z):
if (i+1) * (j+1) * (l+1) <= k:
p.append(a[i]+b[j]+c[l])
else:
break
else:
break
else:
break
p.sort(reverse=True)
for i in range(k):
print((p[i])) | p03078 |
x,y,z,K = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
abc = []
for i in range (x):
for j in range(y):
for(k) in range(z):
if (i+1)*(j+1)*(k+1) <= K:
abc.append(a[i]+b[j]+c[k])
else:
break
abc.sort(reverse=True)
for i in abc[:K]:
print(i) |
X,Y,Z,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = []
for i in range(X):
if (i+1) > K: break
for j in range(Y):
if (i+1)*(j+1) > K: break
for k in range(Z):
if (i+1)*(j+1)*(k+1) > K: break
ans.append(A[i]+B[j]+C[k])
ans.sort(reverse=True)
for i in range(K):
print((ans[i]))
| p03078 |
import heapq
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
To = [[[True] * Z for _ in range(Y)] for __ in range(X)]
Q = []
To[0][0][0] = False
heapq.heappush(Q, (-(A[0] + B[0] + C[0]), 0, 0, 0))
cnt = K
while cnt > 0:
cnt -= 1
ans, a, b, c = heapq.heappop(Q)
print((-ans))
if (a + 1 < X) and (To[a+1][b][c]):
heapq.heappush(Q, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
To[a+1][b][c] = False
if (b + 1 < Y) and (To[a][b+1][c]):
heapq.heappush(Q, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
To[a][b+1][c] = False
if (c + 1 < Z) and (To[a][b][c+1]):
heapq.heappush(Q, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
To[a][b][c+1] = False
| import heapq
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
def calc(p):
cnt = 0
for a in A:
for b in B:
for c in C:
if a + b + c < p:
break
cnt += 1
if cnt >= K:
return True
return False
end = A[0] + B[0] + C[0] + 1
start = 0
while end - start > 1:
mid = (end + start)//2
if calc(mid):
start = mid
else:
end = mid
D = []
for a in A:
for b in B:
for c in C:
if a + b + c < start:
break
D.append(a + b + c)
D.sort(reverse=True)
for d in D[:K]:
print(d)
| p03078 |