Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
Neg_INF=-10**10

N,K=map(int,input().split())

P=list(map(int,input().split()))
C=list(map(int,input().split()))

dp=[[0 for i in range(K+1)] for i in range(N)]

ans=Neg_INF
for i in range(1,K+1):
    for j in range(N):
        dp[j][i]=dp[P[j]-1][i-1]+C[P[j]-1]
        if ans<dp[j][i]:
            ans=dp[j][i]

print(ans)

Fixed submission:
INF=10**20

N,K=map(int,input().split())

array=list(map(int,input().split()))
P=[]
C=list(map(int,input().split()))
for i in array:
    P.append(i-1)

ans=-1*INF

for i in range(N):
    v=i
    cycle_sum=0
    cycle_cnt=0

    while(True):
        cycle_cnt+=1
        cycle_sum+=C[v]
        v=P[v]
        if v==i:
            break

    path=0
    cnt=0

    while(True):
        cnt+=1
        path+=C[v]

        if cnt>K:
            break

        num=(K-cnt)//cycle_cnt
        score=path+max(0,cycle_sum)*num
        ans=max(ans,score)

        v=P[v]
        if v==i:
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import time

N=int(input())

sum=0
for j in range(1,N+1):
    Y=int(N/j)
    sum+=int((Y*(Y+1)*j)/2)

print(sum)

Fixed submission:
import math
import time

N=int(input())

sum=0
for j in range(1,N+1):
    Y=int(N/j)
    sum+=int((Y*(Y+1)*j)/2)

print(sum)
Buggy python submission (verdict: Runtime Error):
N=int(input())
array=map(int,input().split())
A=[]
for i in array:
    A.append(i)

dict_num={i:0 for i in range(100000)}

Q=int(input())
matrix=[]
for i in range(Q):
    matrix.append(list(map(int,input().split())))

#全数値の合計計算
sum=0
#各数字の出現回数の計測
for i in range(len(A)):
    dict_num[A[i]]+=1
    sum+=A[i]

#合計の再計算 & 数字の出現回数の再計算
for i in matrix:
    sum+=(i[1]-i[0])*dict_num[i[0]]
    dict_num[i[1]]+=dict_num[i[0]]
    dict_num[i[0]]=0
    print(sum)

Fixed submission:
N=int(input())
array=map(int,input().split())
A=[]
for i in array:
    A.append(i)

dict_num={i:0 for i in range(100050)}
Q=int(input())
matrix=[]
for i in range(Q):
    matrix.append(list(map(int,input().split())))

#全数値の合計計算
sum=0
#各数字の出現回数の計測
for i in range(N):
    dict_num[A[i]]+=1
    sum+=A[i]

#合計の再計算 & 数字の出現回数の再計算
for i in matrix:
    sum+=(i[1]-i[0])*dict_num[i[0]]
    dict_num[i[1]]+=dict_num[i[0]]
    dict_num[i[0]]=0
    print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

Q=int(input())
comb=[]
for i in range(Q):
    comb.append(list(map(int,input().split())))

ra=len(A)

sum_num=[0 for i in range(Q)]
for i in range(Q):
    A=[comb[i][1] if A[j]==comb[i][0] else A[j] for j in range(ra)]
    sum_num[i]=sum(A)

for i in sum_num:
    print(i)

Fixed submission:
N=int(input())
array=map(int,input().split())
A=[]
for i in array:
    A.append(i)

dict_num={i:0 for i in range(100050)}
Q=int(input())
matrix=[]
for i in range(Q):
    matrix.append(list(map(int,input().split())))

#全数値の合計計算
sum=0
#各数字の出現回数の計測
for i in range(N):
    dict_num[A[i]]+=1
    sum+=A[i]

#合計の再計算 & 数字の出現回数の再計算
for i in matrix:
    sum+=(i[1]-i[0])*dict_num[i[0]]
    dict_num[i[1]]+=dict_num[i[0]]
    dict_num[i[0]]=0
    print(sum)
Buggy python submission (verdict: Runtime Error):
N=int(input())
array=list(map(int,input().split()))

A=[]
array=sorted(array)
for i in array:
    A.append(i)

dp=[True for i in range(N)]

if A[0]==A[1]:
    dp[0]=False
for i in range(N):
    if dp[i] == False:
        continue
    for j in range(i+1,N):
        if A[j]%A[i]==0:
            dp[j]=False

num=0
for i in range(N):
    if dp[i] == True:
        num+=1

print(num)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

M=1000050

dp=[0 for i in range(M)]

ans=0
for x in A:
    if dp[x]!=0:
        dp[x]=2
        continue
    for i in range(x,M,x):
        dp[i]+=1

for x in A:
    if dp[x]==1:
        ans+=1

print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
array=list(map(int,input().split()))

A=[]
array=sorted(array)
for i in array:
    A.append(i)

dp=[True for i in range(N)]

if A[0]==A[1]:
    dp[0]=False
for i in range(N):
    for j in range(i+1,N):
        if A[j]%A[i]==0:
            dp[j]=False

num=0
for i in range(N):
    if dp[i] is True:
        num+=1

print(num)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

M=1000050

dp=[0 for i in range(M)]

ans=0
for x in A:
    if dp[x]!=0:
        dp[x]=2
        continue
    for i in range(x,M,x):
        dp[i]+=1

for x in A:
    if dp[x]==1:
        ans+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

mult=1
array=map(int,input().split())

for i in array:
    mult*=i

if mult>10**18:
    print("-1")
else:
    print(mult)

Fixed submission:
N=int(input())

mult=1
array=map(int,input().split())

array=sorted(array)

for i in array:
    mult*=i
    if mult==0:
        break
    elif mult>10**18:
        mult=-1
        break

print(mult)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())

sweet=[0 for i in range(N+1)]

d=[]
A=[]
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int,input().split())))

for i in d:
    for j in range(i):
        for k in range(len(A[j])):
            sweet[A[j][k]]=1

num=0
for i in range(1,N):
    if sweet[i]==0:
        num+=1

print(num)

Fixed submission:
N,K=map(int,input().split())

sweet=[0 for i in range(N+1)]

d=[]
A=[]
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int,input().split())))

for i in range(len(d)):
    for j in range(d[i]):
        sweet[A[i][j]]+=1

num=0
for i in range(1,len(sweet)):
    if sweet[i]==0:
        num+=1
print(num)
Buggy python submission (verdict: Runtime Error):
NUM=100

X=int(input())

flg=False

for i in reversed(range(NUM)):
    for j in range(-1*NUM,NUM):
        res=(i**5)-(j**5)
        if res==X:
            ans_A=i
            ans_B=j
            flg=True
            break
    if flg:
        break

print(ans_A,ans_B)

Fixed submission:
NUM=1000

X=int(input())

flg=False

for i in reversed(range(NUM)):
    for j in range(-1*NUM,NUM):
        res=(i**5)-(j**5)
        if res==X:
            ans_A=i
            ans_B=j
            flg=True
            break
    if flg:
        break

print(ans_A,ans_B)

Buggy python submission (verdict: Runtime Error):
X=int(input())

for i in range(100):
    for j in range(-100,100):
        ans=pow(i,5)-pow(j,5)
        if ans==X:
            ans_a=i
            ans_b=j

print(ans_a,ans_b)

Fixed submission:
NUM=1000

X=int(input())

flg=False

for i in reversed(range(NUM)):
    for j in range(-1*NUM,NUM):
        res=(i**5)-(j**5)
        if res==X:
            ans_A=i
            ans_B=j
            flg=True
            break
    if flg:
        break

print(ans_A,ans_B)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

S=[]
char_num=[[] for i in range(10)]

for i in range(N):
    S.append(input())

for i in S:
    index=len(i)-1
    if not i in char_num[index]:
        char_num[index].append(i)

words=0
for i in range(len(char_num)):
    for j in char_num[i]:
        words+=1

print(words)

Fixed submission:
N=int(input())

S=set()
for i in range(N):
    S.add(input())

print(len(S))
Buggy python submission (verdict: Time Limit Exceeded):
S=input()

comb=[]
for i in range(len(S)-3):
    for j in range(i+3,len(S)):
        if int(S[i:j+1])%2019==0:
            comb.append((i+1,j+1))

print(len(comb))


Fixed submission:
S=input()
S=list(reversed(S))

m=2019
cnt=[0 for i in range(m)]

len_S=len(S)
x=1
tot=0
ans=0

for i in range(len(S)):
    cnt[tot]+=1
    tot+=(ord(S[i])-ord('0'))*x
    tot %= m
    ans+=cnt[tot]
    x=x*10%m

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()

comb=[]
for i in range(len(S)-3):
    for j in range(i+3,len(S)):
        if int(S[i:j+1])%2019==0:
            comb.append((i+1,j+1))

print(len(comb))

Fixed submission:
S=input()
S=list(reversed(S))

m=2019
cnt=[0 for i in range(m)]

len_S=len(S)
x=1
tot=0
ans=0

for i in range(len(S)):
    cnt[tot]+=1
    tot+=(ord(S[i])-ord('0'))*x
    tot %= m
    ans+=cnt[tot]
    x=x*10%m

print(ans)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

pattern_even=(N-1)*N/2
pattern_odd=(M-1)*M/2

return (pattern_even+pattern_odd)

Fixed submission:
N,M=map(int,input().split())

pattern_o=(N-1)*N/2
pattern_e=(M-1)*M/2

print(int(pattern_o+pattern_e))
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())

x_max=int((100/8)*(A+1))
x_min=int((100/8)*A)

if x_min==x_max:
    x=x_min
for i in range(x_min,x_max+1):
    if int(i*(1/10))==B:
        x=i
        break

if x<0 or 100<x:
    print("-1")
else:
    print(x)

Fixed submission:
A,B=map(int,input().split())
 
ans=-1
for x in range(1000+1):
    if int(x*(8/100))==A and int(x*(10/100))==B:
        ans=x
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())

for i in range(Q):
    array=input().split()
    array[0]=int(array[0])

    if array[0]==1:
        S=S[::-1]

    if array[0]==2:
        array[1]=int(array[1])
        if array[1]==1:
            S=''.join([array[2],S])
            
        else:
            S=''.join([S,array[2]])

print(S)

Fixed submission:
S=input()

Q=int(input())

inst=[]
for i in range(Q):
    array=input().split()
    inst.append(tuple(array))

rev=True
front_str=[]
back_str=[]
for i in range(Q):
    if int(inst[i][0])==1:
        rev=not rev
    elif rev:
        if int(inst[i][1])==1:
            front_str.append(inst[i][2])
        else:
             back_str.append(inst[i][2])
    else:
        if int(inst[i][1])==1:
            back_str.append(inst[i][2])
        else:
            front_str.append(inst[i][2])

if rev:
    front_str.reverse()
else:
    back_str.reverse()
    S=S[::-1]

front="".join(front_str)
back="".join(back_str)

if rev:
    print(front+S+back)
else:
    print(back+S+front)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

pos=[]
for i in range(M):
    array=list(map(int,input().split()))
    pos.append(array)

flg=True
num=[-1 for i in range(N)]

for i in range(M):
    if num[pos[i][0]-1]==-1 or num[pos[i][0]]==pos[i][1]:
        if i!=0 or pos[i][1]!=0:
            num[pos[i][0]-1]=pos[i][1]
        else:
            flg=False
    else:
        flg=False

for i in range(len(num)):
    if num[i]==-1:
        if i==0:
            num[i]=1
        else:
            num[i]=0

ans=0
for i in range(N):
    ans+=num[i]*10**(N-i-1)

if flg:
    print(ans)
else:
    print("-1")

Fixed submission:
N,M=map(int,input().split())

pos=[]
for i in range(M):
    array=list(map(int,input().split()))
    pos.append(array)

flg=True
num=[-1 for i in range(N)]

for i in range(M):
    if num[pos[i][0]-1]==-1 or num[pos[i][0]-1]==pos[i][1]:
        if pos[i][0]-1!=0 or pos[i][1]!=0:
            num[pos[i][0]-1]=pos[i][1]
        else:
            if N==1:
                num[pos[i][0]-1]=pos[i][1]
            else:
                flg=False
    else:
        flg=False

for i in range(len(num)):
    if num[i]==-1:
        if i==0:
            if N==1:
                num[i]=0
            else:
                num[i]=1
        else:
            num[i]=0

ans=0
for i in range(N):
    ans+=num[i]*10**(N-i-1)

if flg:
    print(ans)
else:
    print("-1")
Buggy python submission (verdict: Runtime Error):
S,T=map(int,input().split())
A,B=map(int,input().split())
U=int(input())

if S==U:
    A-=1
else:
    B-=1

print(str(A)+" "+str(B))


Fixed submission:
S,T=input().split()
A,B=map(int,input().split())
U=input()

if S==U:
    A-=1
else:
    B-=1

print(str(A)+" "+str(B))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())

P=list(map(int,input().split()))

probability=[]
sums=[0]
total=0
for i in range(N):
    num=0
    prob=1/P[i]
    for j in range(1,P[i]+1):
        num+=j*prob
    probability.append(num)
    total+=num
    sums.append(total)

ans=0
for j in range(N-K+1):
    if ans<sums[j+K]-sums[j]:
        ans=sums[j+K]-sums[j]

print('{:.012f}'.format(ans))

Fixed submission:
N,K=map(int,input().split())

P=list(map(int,input().split()))

probability=[]
sums=[0]
total=0
for i in range(N):
    num=0
    prob=1/P[i]
    for j in range(1,P[i]+1):
        num+=j*prob
    probability.append(num)
    total+=num
    sums.append(total)

ans=0
for j in range(N-K+1):
    if ans<sums[j+K]-sums[j]:
        ans=sums[j+K]-sums[j]

print('{:.012f}'.format(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())

P=list(map(int,input().split()))

probability=[]
for i in range(N):
    num=0
    prob=1/P[i]
    for j in range(1,P[i]+1):
        num+=j*prob
    probability.append(num)

max_num=0
for i in range(N-K+1):
    sum_num=0
    for j in range(i,i+K):
        sum_num+=probability[j]
    if max_num<sum_num:
        max_num=sum_num
print('{:.012f}'.format(max_num))

Fixed submission:
N,K=map(int,input().split())

P=list(map(int,input().split()))

probability=[]
sums=[0]
total=0
for i in range(N):
    num=0
    prob=1/P[i]
    for j in range(1,P[i]+1):
        num+=j*prob
    probability.append(num)
    total+=num
    sums.append(total)

ans=0
for j in range(N-K+1):
    if ans<sums[j+K]-sums[j]:
        ans=sums[j+K]-sums[j]

print('{:.012f}'.format(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())

P=list(map(int,input().split()))

probability=[]
for i in range(N):
    num=0
    prob=1/P[i]
    for j in range(1,P[i]+1):
        num+=j*prob
    probability.append(num)

max_num=0
for i in range(N-K+1):
    sum_num=0
    for j in range(i,i+K):
        sum_num+=probability[j]
    if max_num<sum_num:
        max_num=sum_num
print('{:.012f}'.format(max_num))

Fixed submission:
N,K=map(int,input().split())

P=list(map(int,input().split()))

probability=[]
sums=[0]
total=0
for i in range(N):
    num=0
    prob=1/P[i]
    for j in range(1,P[i]+1):
        num+=j*prob
    probability.append(num)
    total+=num
    sums.append(total)

ans=0
for j in range(N-K+1):
    if ans<sums[j+K]-sums[j]:
        ans=sums[j+K]-sums[j]

print('{:.012f}'.format(ans))
Buggy python submission (verdict: Runtime Error):
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
  print(x)
elif n == 1:
  if x == p:
    print(x-1)
  else:
    print(x)
else:
  p.sort()
  m = float("inf")
  if x<p[0] or p[n-1]<x:
    print(x)
  else:
    for y in [y for y in range(p[0]-1,p[n-1]) if not y in p]:
      if abs(x-y)<m:
        m = abs(x-y)
        ans_y = y
  print(ans_y)

Fixed submission:
a,b,c,d,e = map(int, input().split())
lis = [a,b,c,d,e]
for i,n in enumerate(lis):
  if n==0:
    print(i+1)

Buggy python submission (verdict: Runtime Error):
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
  print(x)
elif n == 1:
  if x == p:
    print(x-1)
  else:
    print(x)
else:
  p.sort()
  m = float("inf")
  if x<p[0] or p[n-1]<x:
    print(x)
  else:
    for y in [y for y in range(p[0]-1,p[n-1]) if not y in p]:
      if abs(x-y)<m:
        m = abs(x-y)
        ans_y = y
  print(ans_y)

Fixed submission:
a,b,c,d,e = map(int, input().split())
lis = [a,b,c,d,e]
for i,n in enumerate(lis):
  if n==0:
    print(i+1)
Buggy python submission (verdict: Runtime Error):
x,n = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
m = float("inf")
if x<int(p[0]) or int(p[n-1])<x:
  print(x)
else:
  for y in [y for y in range(p[0]-1,p[n-1]) if not y in p]:
    if abs(x-y)<m:
      m = abs(x-y)
      ans_y = y
  print(ans_y)

Fixed submission:
x,n = map(int, input().split())
ans_y = None
if n == 0:
  print(x)
elif n == 1:
  p = list(map(int, input().split()))
  if x == p[0]:
    print(x-1)
  else:
    print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  m = float("inf")
  if x<p[0] or p[n-1]<x:
    print(x)
  else:
    for y in [y for y in range(p[0]-1,p[n-1]+2) if not y in p]:
      if abs(x-y)<m:
        m = abs(x-y)
        ans_y = y
  if ans_y != None:
    print(ans_y)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = int(1e9 + 7)
re = {}
ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += a[i]*a[j]
        ans %= mod

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = int(1e9 + 7)
ans, x = 0, 0
for i in range(n):
    ans += a[i]*x
    x += a[i]
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
nn = n
sum = 0
while nn > 0:
    sum += nn % 10
    nn = nn // 10
if sum % 9 == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
n = input()
sum = 0
for i in range(len(n)):
    num = int(n[i])
    sum += num
if sum % 9 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):

N = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
alpha = [chr(ord('a') + i) for i in range(26)]
name = []
number = []
a = 1
count = 0

while N//a > 0:
    a = a*26
    count += 1

a = a/26

for i in range(count):
    num = int(N//a)
    number.append(num)
    N = N - num*a
    a = a//26

print(number)

for i in range(count):
    if number[-i] == 0:
        for j in range(count-i-1):
            number[j] -= 1
        del number[0]
print(number)

for i in number:
    name.append(alpha[i-1])

result = "".join(name)
print(result)


Fixed submission:
n = int(input())
ans = ''
while n > 0:
    n, r = divmod(n-1, 26)
    ans = chr(r+ord('a')) + ans
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
answer = A[0]

for i in range(1, N):
    answer *= A[i]

if answer > 10**18:
    print(-1)
else:
    print(answer)


Fixed submission:
N = int(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
answer = A[0]

if A.count(0) > 0:
    print(0)
    exit()

for i in range(1, N):
    answer = answer*A[i]
    if answer > 10**18:
        print(-1)
        exit()
else:
    print(answer)
Buggy python submission (verdict: Runtime Error):
import sympy

N = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

count = 0
z = sympy.divisors(N)

if N == 1:
    print(0)
    exit()

elif len(z) == 2:
    print(1)
    exit()

else:
    for i in range(1, len(z)):
        if N%z[i] == 0:
            count += 1
            N = N/z[i]

print(count)


Fixed submission:
import collections
N = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
count = 0

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = collections.Counter(prime_factorize(N))
C = list(c.items())

if len(list(c.keys()))==1:
    for j in range(1, C[0][1]+1):
        if N%(C[0][0]**j) == 0:
            count += 1
            N /= C[0][0]**j

else:
    for i in range(len(C)):
        for j in range(1, C[i][1]+1):
            if N%(C[i][0]**j) == 0:
                count += 1
                N /= (C[i][0]**j)

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
# = int(input())
N, K = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
next = 1
List = []

for i in range(K):
    List.append(next)
    next = A[next-1]
    if len(set(List)) != len(List):
        break

if len(set(List)) != len(List):
    count = [i for i, x in enumerate(List) if x == List[-1]]
    loop = count[1] - count[0]
    afterloop = (K-count[0])%loop
    print(List[count[0]+afterloop])

else:
    print(next)


Fixed submission:
# = int(input())
N, K = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
next = 1
List = [-1]*N

for i in range(K):
    if List[next-1] == -1:
        List[next-1] = i
        next = A[next-1]

    else:
        loop = i - List[next-1]
        afterloop = (K-(i-loop))%loop
        print(List.index((i-loop) + afterloop)+1)
        exit()

print(next)
Buggy python submission (verdict: Runtime Error):
X = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

for i in range(100000):
    C = X + (i**5)
    if C**(1/5)%1 ==0:
        print(int(C**(1/5)), i)
        break
    C = X - (i**5)
    if C**(1/5)%1 ==0:
        print(int(C**(1/5)), -i)
        break


Fixed submission:
X = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
A = [i**5 for i in range(200)]
B = [i**5 for i in range(200)]
# = [list(map(int, input().split())) for i in range(N)]

for i in range(200):
    for j in range(200):
        if A[i] + B[j] == X:
            print(int(A[i]**(1/5)), int(B[j]**(1/5)*(-1)))
            exit()
        if A[i] - B[j] == X:
            print(int(A[i]**(1/5)), int(B[j]**(1/5)))
            exit()

Buggy python submission (verdict: Runtime Error):
import sys
X = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

for i in range(100000):
    C = X + (i**5)
    if C**(1/5)%1 ==0:
        print(int(C**(1/5)), i)
        sys.exit()
    C = X - (i**5)
    if C**(1/5)%1 ==0:
        print(int(C**(1/5)), -i)
        sys.exit()


Fixed submission:
X = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
A = [i**5 for i in range(200)]
B = [i**5 for i in range(200)]
# = [list(map(int, input().split())) for i in range(N)]

for i in range(200):
    for j in range(200):
        if A[i] + B[j] == X:
            print(int(A[i]**(1/5)), int(B[j]**(1/5)*(-1)))
            exit()
        if A[i] - B[j] == X:
            print(int(A[i]**(1/5)), int(B[j]**(1/5)))
            exit()

Buggy python submission (verdict: Runtime Error):
import sys
X = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

for i in range(1000000000):
    C = X + (i**5)
    if C**(1/5)%1 ==0:
        print(int(C**(1/5)), i)
        sys.exit()
    C = X - (i**5)
    if C**(1/5)%1 ==0:
        print(int(C**(1/5)), -i)
        sys.exit()


Fixed submission:
X = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
A = [i**5 for i in range(200)]
B = [i**5 for i in range(200)]
# = [list(map(int, input().split())) for i in range(N)]

for i in range(200):
    for j in range(200):
        if A[i] + B[j] == X:
            print(int(A[i]**(1/5)), int(B[j]**(1/5)*(-1)))
            exit()
        if A[i] - B[j] == X:
            print(int(A[i]**(1/5)), int(B[j]**(1/5)))
            exit()