Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02728 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().rstrip()
MOD = 10**9+7

n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    g[a].append(b)
    g[b].append(a)

lim = 10**5*2
fact = [1, 1] + [0] * (lim-1)
fact_inv = [1, 1] + [0] * (lim-1)
inv = [0, 1] + [0] * (lim-1)
for i in range(2, lim+1):
    fact[i] = fact[i-1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD//i) % MOD
    fact_inv[i] = fact_inv[i-1] * inv[i] % MOD
def comb(n, m):
    if n < m or n < 0 or m < 0: return 0
    return fact[n] * (fact_inv[m] * fact_inv[n-m] % MOD) % MOD
def icomb(n, m):
    if n < m or n < 0 or m < 0: return 0
    return fact_inv[n] * (fact[m] * fact[n-m] % MOD) % MOD

dp = [1] * n
size = [0] * n

def dfs(v, pv):
    for nv in g[v]:
        if nv == pv: continue
        dfs(nv, v)
        ns = size[nv]+1
        size[v] += ns
        dp[v] *= dp[nv] * comb(size[v], ns) % MOD
        dp[v] %= MOD

def dfs2(v, pv):
    for nv in g[v]:
        if nv == pv: continue
        d, sz = dp[v], size[v]
        d *= pow(dp[nv], MOD-2, MOD) * icomb(sz, size[nv]+1) % MOD
        d %= MOD
        sz -= size[nv]+1

        size[nv] += sz+1
        dp[nv] *= d * comb(size[nv], sz+1) % MOD
        dp[nv] %= MOD
        dfs2(nv, v)

dfs(0, -1)
dfs2(0, -1)
print(*dp, sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
MOD = 10**9+7

n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    g[a].append(b)
    g[b].append(a)

lim = 10**6
fact = [1, 1] + [0] * (lim-1)
fact_inv = [1, 1] + [0] * (lim-1)
inv = [0, 1] + [0] * (lim-1)
for i in range(2, lim+1):
    fact[i] = fact[i-1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD//i) % MOD
    fact_inv[i] = fact_inv[i-1] * inv[i] % MOD
def comb(n, m):
    if n < m or n < 0 or m < 0: return 0
    return fact[n] * (fact_inv[m] * fact_inv[n-m] % MOD) % MOD

dp = [1] * n
size = [0] * n

def dfs(v, pv):
    for nv in g[v]:
        if nv == pv: continue
        dfs(nv, v)
        ns = size[nv]+1
        size[v] += ns
        dp[v] *= dp[nv] * comb(size[v], ns) % MOD
        dp[v] %= MOD

def dfs2(v, pv):
    for nv in g[v]:
        if nv == pv: continue
        d, sz = dp[v], size[v]
        d *= inv[dp[nv]] * inv[comb(sz, size[nv]+1)] % MOD
        d %= MOD
        sz -= size[nv]+1

        size[nv] += sz+1
        dp[nv] *= d * comb(size[nv], sz+1) % MOD
        dp[nv] %= MOD
        dfs2(nv, v)

dfs(0, -1)
dfs2(0, -1)
print(*dp, sep="\n")
Problem p02782 (python)

Fixed submission:
r1, c1, r2, c2 = map(int, input().split())
MOD = 10**9+7

def init_mod_c(lim=10**7, mod=10**9+7):
    fact = [1, 1] + [0] * (lim-1)
    fact_inv = [1, 1] + [0] * (lim-1)
    inv = [0, 1] + [0] * (lim-1)
    
    for i in range(2, lim+1):
        fact[i] = fact[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod

    def mod_c(n, m):
        if n < m or n < 0 or m < 0: return 0
        return fact[n] * (fact_inv[m] * fact_inv[n-m] % mod) % mod

    return mod_c

comb = init_mod_c()
pc = lambda r, c: comb(r+c, min(r, c))

ans = 0
for i in range(r1, r2+1):
    ans += pc(i+1, c2)
    if c1 > 0: ans -= pc(i+1, c1-1)
    ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
r1, c1, r2, c2 = map(int, input().split())
MOD = 10**9+7

def init_mod_c(lim=10**6*2, mod=10**9+7):
    fact = [1, 1] + [0] * (lim-1)
    fact_inv = [1, 1] + [0] * (lim-1)
    inv = [0, 1] + [0] * (lim-1)
    
    for i in range(2, lim+1):
        fact[i] = fact[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod

    def mod_c(n, m):
        if n < m or n < 0 or m < 0: return 0
        return fact[n] * (fact_inv[m] * fact_inv[n-m] % mod) % mod

    return mod_c

comb = init_mod_c()
pc = lambda r, c: comb(r+c, min(r, c))

ans = 0
for i in range(r1, r2+1):
    ans += pc(i+1, c2)
    if c1 > 0: ans -= pc(i+1, c1-1)
    ans %= MOD

print(ans)
Problem p02807 (python)

Fixed submission:
MOD = 10**9+7
n = int(input())
m = n - 1
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(m)]

inv = [0, 1]
for i in range(2, n):
  inv += [inv[MOD % i] * (MOD - int(MOD / i)) % MOD]

s = 1
for i in range(2, n):
    s *= i
    s %= MOD

ans = s * sum(d) % MOD

p = 0
for i in range(1, m):
    p += inv[i+1]
    p %= MOD
    ans += s * d[i] * p
    ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7
n = int(input())
m = n - 1
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(m)]

s = 1
for i in range(2, n):
    s *= i
ans = sum(d) * s % MOD

for i in range(m):
    p = 1
    for j in range(i+1, n-1):
        c = j - i
        p *= c / (c+1)
        ans += d[j] * int(p * s)
        ans %= MOD

print(int(ans))
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
 
n, q = map(int, input().split())
tl = [list() for _ in range(n)]
xl = [0] * n
ans = [0] * n
 
for i in range(n-1):
    a, b = map(int, input().split())
    tl[a-1].append(b-1)
    tl[b-1].append(a-1)
 
for i in range(q):
    p, x = map(int, input().split())
    xl[p-1] += x

def rec(p, parent, x):
    x += xl[p]
    ans[p] = x
    for num in tl[p]:
        if num == parent: continue
        rec(num, p, x)

rec(0, -1, 0)
 
print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

n, q = map(int, input().split())
tl = [list() for _ in range(n)]
ans = [0] * n

for i in range(n-1):
    a, b = map(int, input().split())
    tl[a-1].append(b)

def rec(p, x):
    ans[p-1] += x
    for num in tl[p-1]:
        rec(num, x)

for i in range(q):
    p, x = map(int, input().split())
    rec(p, x)

print(" ".join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000)

n, q = map(int, input().split())
tl = [list() for _ in range(n)]
ans = [0] * n

for i in range(n-1):
    a, b = map(int, input().split())
    tl[a-1].append(b)

def rec(p, x):
    ans[p-1] += x
    for num in tl[p-1]:
        rec(num, x)

for i in range(q):
    p, x = map(int, input().split())
    rec(p, x)

print(" ".join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
tl = [list() for _ in range(n)]
ans = [0] * n

for i in range(n-1):
    a, b = map(int, input().split())
    tl[a-1].append(b)

def rec(p, x):
    ans[p-1] += x
    for num in tl[p-1]:
        rec(num, x)

for i in range(q):
    p, x = map(int, input().split())
    rec(p, x)

print(" ".join(map(str, ans)))
Problem p02937 (python)

Fixed submission:
from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()
idxs = defaultdict(list)

for i, c in enumerate(s):
    idxs[c].append(i)
for i, c in enumerate(s):
    idxs[c].append(len(s) + i)

ans, cur_i = -1, -1
for c in t:
    if c not in idxs: print(-1); break
    a = idxs[c]
    nxt = a[bisect_right(a, cur_i)]
    ans += nxt - cur_i
    cur_i = nxt % len(s)
else: print(ans+1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()
d = defaultdict(list)

for i, x in enumerate(s):
    for j in range(len(t)):
        d[x].append(i + len(s) * j)
for x in d.values(): x.sort()

ans = 0
for x in t:
    if x not in d: print(-1); exit()
    ans = d[x][bisect_right(d[x], ans)]

print(ans+1)
Problem p02995 (python)

Fixed submission:
from fractions import gcd

a, b, c, d = map(int, input().split())
a -= 1

def main():
    cd = c * d // gcd(c, d)
    print(b - a - f(c) - f(d) + f(cd))

def f(x):
    return b // x - a // x

main()

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())

def main():
    cd = c * d / math.gcd(c, d)
    print(b - a - (f(c) + f(d) - f(cd)) + 1)

def f(x):
    return math.floor((b - x * math.ceil(a / x)) / x) + 1

main()
Problem p03006 (python)

Fixed submission:
from collections import Counter
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
v = []
for i in range(n):
    for j in range(n):
        if i == j: continue
        x, y = xy[j]
        px, py = xy[i]
        v.append((x-px, y-py))
num = Counter(v).most_common(1)[0][1] if v else 0
print(n - num)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
v = []
for i in range(n):
    for j in range(n):
        if i == j: continue
        x, y = xy[j]
        px, py = xy[i]
        v.append((x-px, y-py))
num = Counter(v).most_common(1)[0][1]
print(n - num)
Problem p03231 (python)

Fixed submission:
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()
g = gcd(n, m)
l = n * m // g

for i in range(g):
    if s[i*n//g] != t[i*m//g]:
        print(-1)
        break
else: print(l)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()
l = n * m // gcd(n, m)
x = [""] * l

for i in range(0, l, l//n):
    x[i] = s[i*n//l]

for i in range(0, l, l//m):
    if x[i]:
        if x[i] != t[i*m//l]:
            print(-1)
            break
    else: x[i] = t[i*m//l]
else: print(l)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()
l = n * m // gcd(n, m)
x = [""] * l

for i in range(n):
    x[i*l//n] = s[i]

for i in range(m):
    index = i*l//m
    if x[index]:
        if x[index] != t[i]:
            print(-1)
            break
    else: x[index] = t[i]
else: print(l)
Problem p03994 (python)

Fixed submission:
s = [ord(x) - ord("a") for x in input()]
k = int(input())

for i in range(len(s)):
    if s[i] == 0: continue
    r = 26 - s[i]
    if r <= k:
        k -= r
        s[i] = 0

s[-1] = (s[-1] + k) % 26
print("".join([chr(x + ord("a")) for x in s]))

Buggy submission (verdict: Runtime Error):
s = [ord(x) - ord("a") for x in input()]
k = int(input())

for i in range(len(s)):
    if s[i] == 0: continue
    r = 26 - s[i]
    if r <= k:
        k -= r
        s[i] = 0

s[-1] += k
print("".join([chr(x + ord("a")) for x in s]))
Problem p02574 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

num = [0]*(10**6+1)

for x in a:
    num[x] += 1

pairwise = True
for i in range(2, 10**6+1):
    cnt = sum(num[i::i])
    if cnt == n:
        print('not coprime')
        exit()
    if cnt > 1:
        pairwise = False

if pairwise:
    print('pairwise coprime')
else:
    print('setwise coprime')

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n = int(input())
a = list(map(int, input().split()))

flg = True
for i in range(n-1):
    for j in range(i+1, n):
        if math.gcd(a[i], a[j]) != 1:
            if i != 0:
                a = a[i-1:]
            flg = False
            break
    if flg:
        print('pairwise coprime')
        exit()

if gcd_list(a) == 1:
    print('setwise coprime')
else:
    print('not coprime')
Problem p02618 (python)

Fixed submission:
d = int(input())
c = list(map(int, input().split()))
s = list(map(int, input().split()) for _ in range(d))

import random
for i in range(d):
    print(int(random.uniform(1, 26)))

Buggy submission (verdict: Runtime Error):
d = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(d))
T = list(int(input()) - 1 for i in range(d))

kaisai = [0] * 26
manzoku = 0
date = 0
for t in T:
    date += 1
    kaisai[t] = date
    manzoku += S[date - 1][t]

    for i in range(26):
        manzoku -= C[i] * (date - kaisai[i])
    
    print(manzoku)
Problem p02630 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = list(map(int, input().split()) for _ in range(q))

s = sum(a)

num = [0]*(10**5 + 1)
for x in a:
    num[x] += 1

for b, c in bc:
    s += (c - b)*num[b]
    num[c] += num[b]
    num[b] = 0

    print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

s = sum(a)

num = [0]*10**5

for i in range(10**5):
    num[i] = a.count(i)

for i in range(q):
    b, c = map(int, input().split())
    d = (c-b) * num[b]
    num[c] += num[b]
    num[b] = 0
    s += d
    print(s)
Problem p02702 (python)

Fixed submission:
s=input()[::-1]
mod=[0]*2019
mod[0]=1
x=1
num=0
ans=0

for t in s:
    num += int(t) * x
    num %= 2019
    x *= 10
    x %= 2019
    mod[num] +=1

for u in mod:
    ans += u*(u-1)//2

print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
cnt=0
l=[i for i in i%2019==0]
print(s.count(l))
Problem p02761 (python)

Fixed submission:
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

for x in range(1000):
    if len(str(x))==n:
        for i in range(m):
            if str(x)[sc[i][0]-1]==str(sc[i][1]):
                continue
            else:
                break
        else:
            print(x)
            break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
ans=-1
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
for k in range(10**(n-1)-1,10**n):
    for i in range(m):
        if str(k)[l[i][0]-1]!=str(l[i][1]) or len(str(k))!=n:
            break
    else:
        ans=k
        break
print(ans)

Buggy submission (verdict: Runtime Error):
ans=-1
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
for k in range(10**n):
    for i in range(m):
        if str(k)[l[i][0]-1]!=str(l[i][1]) or len(str(k))!=n:
            break
    else:
        ans=k
        break
print(ans)

Buggy submission (verdict: Runtime Error):
ans=-1
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
for k in range(10**(n-1),10**n):
    for i in range(m):
        if str(k)[l[i][0]-1]!=str(l[i][1]):
            break
    else: 
        ans=k
        print(ans) 
        break
if ans==-1: print(-1)
if n==1 and l[0][0]==0: print(0)
Problem p02767 (python)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=10**9

for i in range(x[0],x[-1]+1):
    temp=0
    for j in x:
        temp+=(j-i)**2
    ans=min(ans,temp)

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,input().split()))
ans=0
average=sum(x)//n

for i in x:
    ans+=(i=average)**2

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,input().split()))
ans=[0]*(x[n-1]-x[0]+1)
for i in range(x[n-1]-x[0]+1):
    for j in x:
        ans[i]+=(j-i)**2
print(min(ans))
Problem p02922 (python)

Fixed submission:
import math
a,b=map(int,input().split())
print(1+math.ceil((b-a)/(a-1)))

Buggy submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
print(1+math,ceil((b-a)/(a-1)))
Problem p02975 (python)

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
s = list(set(a))
l = len(s)

if l == 1 and a[0] == 0:
    print('Yes')
    exit()
if len(a) % 3 == 0:
    if l == 2 and c[0] == n // 3:
        print('Yes')
        exit()
    if l == 3 and s[0] ^ s[1] ^ s[2] == 0:
        tmp = n//3
        if all(x == tmp for x in c.values()):
            print('Yes')
            exit()

print('No')

Buggy submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
s = set(a)
l = len(s)

if l == 1 and a[0] == 0:
    print('Yes')
elif len(a) % 3 == 0:
    if l == 2 and c[0] == n // 3:
        print('Yes')
    elif l == 3:
        if s[0] ^ s[1] ^ s[2] == 0:
            tmp = c[a[0]]
            if all(x == tmp for x in c.values()):
                print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
s = set(a)
l = len(s)

if l == 1 and a[0] == 0:
    print('Yes')
elif len(a) % 3 == 0:
    if l == 2 and c[0] == n // 3:
        print('Yes')
    elif l == 3:
        if s[0] ^ s[1] ^ s[2] == 0:
            tmp = c[a[0]]
            if all(x == tmp for x in c.values()):
                print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')
Problem p02983 (python)

Fixed submission:
l,r=map(int,input().split())
if r-l>=2019: print(0)
else:
    ans=2018
    mod_l=l%2019
    mod_r=r%2019
    for i in range(min(mod_l,mod_r),max(mod_l,mod_r)+1):
        for j in range(i+1,max(mod_l,mod_r)+1):
            mod=(i*j)%2019
            if mod<ans: ans=mod
    print(ans)

Buggy submission (verdict: Runtime Error):
l,r=map(int,input().split())
if r-l>=2019: print(0)
else:
    ans=2018
    mod_l=l%2019
    mod_r=r%2019
    for i in range(min(mod_l,mod_r),max(mod_l,mod_r)+1):
        for j in range(i+1,max(mod_l,mod_r)+1):
            mod=(i*j)%2019
            if mod<ans: ans=mod
            else: ans=ans
print(ans)

Buggy submission (verdict: Runtime Error):
l,r=map(int,input().split())
if r-l>=2019: print(0)
else:
    ans=2018
    mod_l=l%2019
    mod_r=r%2019
    for i in range(min(mod_l,mod_r),max(mod_l,mod_r)+1):
        for j in range(i+1,max(mod_l,mod_r)+1):
            mod=(i*j)%2019
            if mod<ans: ans=mod
            else: continue
print(ans)

Buggy submission (verdict: Runtime Error):
l,r=map(int,input().split())
if r-l>=2019: print(0)
else:
    ans=2018
    mod_l=l%2019
    mod_r=r%2019
    for i in range(min(mod_l,mod_r),max(mod_l,mod_r)+1):
        for j in range(i+1,max(mod_l,mod_r)+1):
            mod=(i*j)%2019
            if mod<ans: ans=mod
print(ans)
Problem p03087 (python)

Fixed submission:
from itertools import accumulate

n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

ac_list = [0]*n

for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ac_list[i] = 1

ac_sum = list(accumulate(ac_list))

for l, r in lr:
    l -= 1
    r -= 1
    if l == 0:
        print(ac_sum[r-1])
        continue
    print(ac_sum[r-1] - ac_sum[l-1])

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

ac_list = [0]*n

for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        ac_list[i] = 1

for l, r in lr:
    l -= 1
    r -= 1
    print(ac_list[l:r].count(1))
Problem p03200 (python)

Fixed submission:
s = input()

left = 0
ans = 0

for x in s:
    if x == 'B':
        left += 1
        continue
    ans += left

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
l = []
for i in range(len(s)-1, -1, -1):
    if s[i] == 'B':
        l.append(0)
    else:
        l.append(1)
cnt = 0

for j in range(len(s)**0.5):
    for i in range(j, len(s) - 1, 2):
        if l[i] == 1 and l[i+1] == 0:
            l[i] = 0
            l[i+1] = 1
            cnt += 1

print(cnt)
Problem p04029 (python)

Fixed submission:
n=int(input())
print(int(n*(n+1)/2))

Buggy submission (verdict: Runtime Error):
n=input()
s=(n*(n+1))/2
print(s)
Problem p04043 (python)

Fixed submission:
l=map(int,input().split())
if sorted(l)==[5,5,7]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
l=list(map(int,input().split()))
if count(l,5)==2 and count(l,7)==1:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
list=map(int,input().split())
li=sortrd(list)
if li=[5,5,7]:
  print('YES')
else:
  print('NO')
Problem p02690 (python)

Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
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 list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    x = I()
    for a in range(1,1000):
        a5 = a**5
        for b in range(a+1):
            b5 = b**5
            if a5 + b5 == x:
                return JA([a,-b], " ")
            if a5 - b5 == x:
                return JA([a,b], " ")

    return -1


print(main())

Buggy submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
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 list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    x = I()
    i = 0
    while True:
        t = x - i**5
        u = int(t**0.2)
        for j in range(u-1, u+2):
            if j**5 - i**5 == x:
                return JA([j,i], " ")

        t = x + i**5
        u = int(t**0.2)
        for j in range(u-1, u+2):
            if j**5 + i**5 == x:
                return JA([j,-i], " ")
        i += 1

    return -1


print(main())