Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, X, Y = map(int, input().split())

ans = float('inf')

if A + B >= 2 * C:
    p = (2 * max(X, Y)) * C
    ans = min(ans, p)

for x in range(X + 1):
    for y in range(Y + 1):
        c = max(X - x, Y - y)
        p = x * A + y * B + (2 * c) * C
        ans = min(ans, p)

print(ans)

Fixed submission:
a, b, c, x, y = map(int, input().split())

normal_price = a * x + b * y
min_price = float('inf')
minn = min(x, y)
maxx = max(x, y)

for mi in range(2, maxx * 2 + 1, 2):
    mix_price = c * mi
    xz = x - mi // 2
    yz = y - mi // 2
    if xz < 0: xz = 0
    if yz < 0: yz = 0
    x_price = xz * a
    y_price = yz * b
    total_price = mix_price + x_price + y_price
    min_price = min(min_price, total_price)

min_price = min(min_price, normal_price)
print(min_price)
Buggy python submission (verdict: Runtime Error):
n = int(input())
lst = [list(map(int, input().split())) for _ in range(n)]

ans = 'Yes'

for line in lst:
    t, x, y = line
    c1 = t < x + y
    c2 = t % 2 == 0 and (x + y) % 2 != 0:
    c3 = t % 2 != 0 and (x + y) % 2 == 0:
    
    if c1 or c2 or c3:
        ans = 'No'
        break

print(ans)

Fixed submission:
n = int(input())
lst = [list(map(int, input().split())) for _ in range(n)]

ans = 'Yes'

for line in lst:
    t, x, y = line
    c1 = t < x + y
    c2 = t % 2 == 0 and (x + y) % 2 != 0
    c3 = t % 2 != 0 and (x + y) % 2 == 0
    
    if c1 or c2 or c3:
        ans = 'No'
        break

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

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

ilist = list(range(K + 1))
ilist = ilist * 3
comb = set(i for i in list(itertools.combinations(ilist, 3)) if sum(i) == S)

print(len(comb))

Fixed submission:
k, s = map(int, input().split())
ans = 0

s3 = s // 3
m = max(k, s3)
for x in range(0, m + 1):
    # print(x)
    for y in range(0, m + 1):
        ad = s - x - y
        if ad <= k and ad >= 0:
            ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
ans = 0

m = k + 1
for x in range(m):
    for y in range(m):
        for z in range(m):
            xyz = x + y + z
            if xyz == s:
                ans += 1

print(ans)

Fixed submission:
k, s = map(int, input().split())
ans = 0

s3 = s // 3
m = max(k, s3)
for x in range(0, m + 1):
    # print(x)
    for y in range(0, m + 1):
        ad = s - x - y
        if ad <= k and ad >= 0:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
l=list()
for i in str(s):
  if i == "B":
    del l[-1]
  else:
    l.append(i)
a="".join(l)
print(a)

Fixed submission:
s=input()
l=list()
for i in str(s):
  if i == "B":
    if len(l) > 0:
      del l[-1]
    else:
      continue
  else:
    l.append(i)
a="".join(l)
print(a)
Buggy python submission (verdict: Runtime Error):
N,L=map (str(), input().split())
a=［str(i) for i in input().split()］
b=a.sort(a)
c=b.join()
print(c)

Fixed submission:
N,L=map(int, input().split())
a=list(input() for i in range(N))
b=sorted(a)
c=''.join(b)
print(c)
Buggy python submission (verdict: Runtime Error):
a, b = input().split()
a = int(a)
b = int(100 * int(b.split('.')))


def solve(a, b):
    return a * b // 100


print(solve(a, b))


Fixed submission:
a, b = input().split()
a = int(a)
b, c = map(int, b.split('.'))


def solve(a, b):
    return a * (b * 100 + c) // 100


print(solve(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
while True:
    if K == 1:
        N=0
        break
    n = abs(N-K)
    if n >= N:
        break
    else:
        N = n
print(N)
    

Fixed submission:
N, K = map(int, input().split())
n = N % K
if n > abs(n-K):
    n = abs(n-K)
print(n)
Buggy python submission (verdict: Runtime Error):
a, b = int(input().split())
print((a+b)//2)

Fixed submission:
a, b = map(int, input().split())
print(-(-(a+b)//2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
listA = list(map(int, input()))
cnt = 0

while(True):
    for A in listA:
        if A % 2 != 0:
            break
        else:
            A = A / 2
    
    cnt += 1
print(cnt)

Fixed submission:
s = input()

print(s.count("1"))
Buggy python submission (verdict: Runtime Error):
N, A = [input() for i in range(2)]
print(N ** 2 - A)


Fixed submission:
N, A = [int(input()) for i in range(2)]
print(N ** 2 - A)
Buggy python submission (verdict: Runtime Error):
a = map(int, input().split())
a.sort()
print(a[0]+a[1])

Fixed submission:
a = list(map(int, input().split()))
a.sort()
print(a[0]+a[1])
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
print(A+B -24*((A+B)//24) if A+B > =24 else A+B)

Fixed submission:
A, B = map(int, input().split())
print(A+B -24*((A+B)//24) if A+B >=24 else A+B)
Buggy python submission (verdict: Runtime Error):
N = int(input())
As = np.array(list(map(int, input().split())))

res = [0] * N
for a in As:
    res[a-1] += 1
for r in res:
    print(r)

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

res = [0] * N
for a in As:
    res[a-1] += 1
for r in res:
    print(r)
Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())

res = sum([math.gcd(math.gcd(a+1, b+1), c+1) for a in range(K) for b in range(K) for c in range(K)])
print(res)

Fixed submission:
import math
K = int(input())
gcds = [math.gcd(a+1, b+1) for a in range(K) for b in range(K)]
res = sum([math.gcd(ab, c+1) for ab in gcds for c in range(K)])
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
A, B = map(int,input().split())
amin, amax = A / 0.08, (A + 1) / 0.08
bmin, bmax = B / 0.10, (B + 1) / 0.10

if amax <= bmin or bmax <= amin:#解なし：区間重なりなし
    print(-1)
    sys.exit()

ans = np.ceil(max(amin, bmin)).astype(int)

if ans >= amax or ans >= bmax:
    print(-1)
else:
    print(ans)

Fixed submission:
import sys
import numpy as np
A, B = map(int,input().split())
amin, amax = A / 0.08, (A + 1) / 0.08
bmin, bmax = B / 0.10, (B + 1) / 0.10

if amax <= bmin or bmax <= amin:#解なし：区間重なりなし
    print(-1)
    sys.exit()

ans = np.ceil(max(amin, bmin)).astype(int)

if ans >= amax or ans >= bmax:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse = False
for _ in range(Q):
    cmd = input().split()
    if cmd[0] == "1":
        reverse = not reverse
    else:
        top = (cmd[1] == "1") ^ reverse
        S = cmd[2] + S if top else S + cmd[2]
print(S[::-1]) if reverse else print(S)

Fixed submission:
S = input()
Q = int(input())
head, tail = "", ""
reverse = False
for _ in range(Q):
    cmd = input().split()
    if cmd[0] == "1":
        reverse = not reverse
    else:
        top = (cmd[1] == "1") ^ reverse
        if top:
            head += cmd[2]
        else:
            tail += cmd[2]
print(tail[::-1] + S[::-1] + head) if reverse else print(head[::-1] + S + tail)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse = False
for _ in range(Q):
    cmd = input().split()
    op = cmd[0]
    if op == "1":
        reverse = not reverse
    else:
        top = (cmd[1] == "1") ^ reverse
        if top:
            S = cmd[2] + S
        else:
            S = S + cmd[2]
print(S[::-1]) if reverse else print(S)

Fixed submission:
S = input()
Q = int(input())
head, tail = "", ""
reverse = False
for _ in range(Q):
    cmd = input().split()
    if cmd[0] == "1":
        reverse = not reverse
    else:
        top = (cmd[1] == "1") ^ reverse
        if top:
            head += cmd[2]
        else:
            tail += cmd[2]
print(tail[::-1] + S[::-1] + head) if reverse else print(head[::-1] + S + tail)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
Ls = list(map(int, input().split()))

sls = sorted(Ls)
count = 0
for i in range(N - 1):
    for j in range(i+1, N):
        cs = sls[j + 1:]
        a, b = sls[i], sls[j]
        count += bisect.bisect_left(cs, b + a)
print(count)

Fixed submission:
import bisect
N = int(input())
Ls = list(map(int, input().split()))

sls = sorted(Ls)
count = 0
for i in range(N - 1):
    for j in range(i+1, N):
        a, b = sls[i], sls[j]
        right = bisect.bisect_left(sls, b + a)
        count += right - j - 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
Ls = list(map(int, input().split()))
 
sls = sorted(Ls)
count = 0
for i, a in enumerate(sls):
    for j, b in enumerate(sls[i+1:]):
        cs = sls[i+j+2:]
        cmin, cmax = b - a, b + a
        left, right = bisect.bisect_right(cs, cmin), bisect.bisect_left(cs, cmax)
        count += (right - left)
print(count)

Fixed submission:
import bisect
N = int(input())
Ls = list(map(int, input().split()))

sls = sorted(Ls)
count = 0
for i in range(N - 1):
    for j in range(i+1, N):
        a, b = sls[i], sls[j]
        right = bisect.bisect_left(sls, b + a)
        count += right - j - 1
print(count)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

import math
gcd = math.gcd(A, B)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if gcd == 1:
    print(1)
else:
    fact = factorization(gcd) 
    print(len(fact) + 1)

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

import fractions
gcd = fractions.gcd(A, B)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if gcd == 1:
    print(1)
else:
    fact = factorization(gcd) 
    print(len(fact) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, M = map(int, input().split())
As = list(map(int, input().split()))

mvals = list(np.array(As) * (-1))
import heapq
heapq.heapify(mvals)

for _ in range(M):
    price = heapq.heappop(mvals)
    heapq.heappush(mvals, price / 2)

res = (np.array(mvals) * (-1)).astype(int).sum()
print(res)

Fixed submission:
N, M = map(int, input().split())
mvals = list(map(lambda x: -int(x), input().split()))

import heapq
heapq.heapify(mvals)

for _ in range(M):
    price = heapq.heappop(mvals)
    heapq.heappush(mvals, price / 2)

res = sum(map(lambda x:int(-x), mvals))
print(res)

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

mvals = list(np.array(As) * (-1))
import heapq
heapq.heapify(mvals)

for _ in range(M):
    price = heapq.heappop(mvals)
    heapq.heappush(mvals, price / 2)

res = (np.array(mvals) * (-1)).astype(int).sum()
print(res)

Fixed submission:
N, M = map(int, input().split())
mvals = list(map(lambda x: -int(x), input().split()))

import heapq
heapq.heapify(mvals)

for _ in range(M):
    price = heapq.heappop(mvals)
    heapq.heappush(mvals, price / 2)

res = sum(map(lambda x:int(-x), mvals))
print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())
As = list(map(int, input().split()))

res = [0] * N
for idx, ai in zip(np.arange(N-1, -1, -1), As[::-1]):
    oe = sum([res[i] for i in range(idx, N, idx+1)]) % 2#
    res[idx] = ai ^ oe

print(sum(res))
idxs = []
for i, val in enumerate(res):
    if val:
        idxs += [i + 1]
print(*idxs)

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

res = [0] * N
for idx, ai in zip(range(N-1, -1, -1), As[::-1]):
    oe = sum([res[i] for i in range(idx, N, idx+1)]) % 2#
    res[idx] = ai ^ oe

print(sum(res))
idxs = []
for i, val in enumerate(res):
    if val:
        idxs += [i + 1]
print(*idxs)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
As = np.array(list(map(int, input().split())))

res = np.zeros_like(As)
for idx, ai in zip(np.arange(N-1, -1, -1), As[::-1]):
    oe = res[idx::(idx+1)].sum() % 2
    res[idx] = ai ^ oe

idxs = np.where(res)[0] + 1
print(len(idxs))
print(" ".join(idxs.astype(str)))

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

res = [0] * N
for idx, ai in zip(range(N-1, -1, -1), As[::-1]):
    oe = sum([res[i] for i in range(idx, N, idx+1)]) % 2#
    res[idx] = ai ^ oe

print(sum(res))
idxs = []
for i, val in enumerate(res):
    if val:
        idxs += [i + 1]
print(*idxs)
Buggy python submission (verdict: Runtime Error):
import numpy as np
from functools import lru_cache

A, B, Q = map(int, input().split())
adisps = np.array([int(input()) for _ in range(A)])
bdisps = np.array([int(input()) for _ in range(B)])
qdisps = np.array([int(input()) for _ in range(Q)])

@lru_cache(maxsize=100000)
def nearest(now, flag):
    disps = adisps if flag == 0 else bdisps
    idx = np.argmin(np.abs(disps - now))
    nearest_point = disps[idx]
    cost = np.abs(now - nearest_point)
    return nearest_point, cost

for qdisp in qdisps:

    #A→B
    pos_a1, cost_a1 = nearest(qdisp, 0)
    pos_b1, cost_b1 = nearest(pos_a1, 1)
    cost1 = cost_a1 + cost_b1

    #B→A
    pos_b2, cost_b2 = nearest(qdisp, 1)
    pos_a2, cost_a2 = nearest(pos_b2, 0)
    cost2 = cost_a2 + cost_b2

    ans = min(cost1, cost2)
    print(ans)

Fixed submission:
import numpy as np
y, m, d = map(int, input().split("/"))

if y > 2019:
    print("TBD")
elif m > 4:
    print("TBD")
elif d > 30:
    print("TBD")
else:
    print("Heisei")
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
import numpy as np
N, M = map(int, input().split(" "))#N頂点M辺
mat = [[0] * n for _ in range(n)]
for _ in range(M):
    v1, v2 = map(int, input().split(" "))
    mat[v1 - 1][v2 - 1] = mat[v2 - 1][v1 - 1] = 1

count = 0
for line in permutations(np.arange(N - 1) + 2):
    vtxs = [1] + list(line)
    for i in range(N - 1):
        v1, v2 = vtxs[i], vtxs[i + 1]
        if mat[v1 - 1][v2 - 1] == 0:
            break
    else:
        count += 1
print(count)

Fixed submission:
from itertools import permutations
import numpy as np
N, M = map(int, input().split(" "))#N頂点M辺
edges = []
for _ in range(M):
    edges += [list(map(int, input().split(" ")))]

count = 0
for line in permutations(np.arange(N - 1) + 2):
    vtxs = [1] + list(line)
    for i in range(N - 1):
        edge = sorted([vtxs[i], vtxs[i + 1]])
        if edge not in edges:
            break
    else:
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
s = input()

item = np.arange(len(s) - 1) + 1
n = len(item)
count = 0
for i in range(2 ** n):
    sidx = 0
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            eidx = item[j]
            count += int(s[sidx:eidx])
            sidx = eidx
    count += int(s[sidx:])
print(count)

Fixed submission:
import numpy as np
s = input()

item = np.arange(len(s) - 1) + 1
n = len(item)
count = 0
for i in range(2 ** n):
    sidx = 0
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            eidx = item[j]
            count += int(s[sidx:eidx])
            sidx = eidx
    count += int(s[sidx:])
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int, input().split())
count = 0

if a <= k:
    count += a
else:
    count += k
    print(count)
    exit()
k -= a

if b <= k:
    k -= b
else:
    print(count)
    exit()


for i in range(k):
    count -= 1

print(count)

Fixed submission:
a,b,c,k = map(int, input().split())
count = 0

if a <= k:
    count += a
else:
    count += k
    print(count)
    exit()
k -= a

if b <= k:
    k -= b
else:
    print(count)
    exit()


count -= k

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int, input().split())
count = 0

if a <= k:
    count += a
else:
    count += k
    print(count)
    exit()
k -= a

if b <= k:
    k -= b
else:
    print(count)
    exit()


for i in range(k):
    count -= 1

print(count)

Fixed submission:
a,b,c,k = map(int, input().split())
count = 0

if a <= k:
    count += a
else:
    count += k
    print(count)
    exit()
k -= a

if b <= k:
    k -= b
else:
    print(count)
    exit()


count -= k

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
for i in range(-10000, 10000):
    for j in range(-10000, 10000):
        if i**5 - j**5 == x:
            print(str(i) + " " + str(j))
            exit()

Fixed submission:
x = int(input())
for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if i**5 - j**5 == x:
            print(str(i) + " " + str(j))
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
for i in range(-1000000, 1000000):
    for j in range(-1000000, 1000000):
        if i**5 - j**5 == x:
            print(str(i) + " " + str(j))
            exit()

Fixed submission:
x = int(input())
for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if i**5 - j**5 == x:
            print(str(i) + " " + str(j))
            exit()
Buggy python submission (verdict: Runtime Error):
S,W=map(int,input().split())
if S<=W:
    print("unsafe")
else:
    print("safe")

Fixed submission:
a=list(map(int,input().split()))
takahashi=0
takahashicount=0
aoki=0
aokicount=0

for i in range(a[2]):
    aoki+=a[1]
    if (a[2]-aoki)>0:
        aokicount+=1
    elif (a[2]-aoki)==0:
        break
    else:
        break
        
for i in range(a[0]):
    takahashi+=a[3]
    if (a[0]-takahashi)>0:
        takahashicount+=1
    elif (a[0]-takahashi)==0:
        break
    else:
        break
if takahashicount==aokicount:
    print("Yes")
elif takahashicount>aokicount:
    print("Yes")
elif takahashicount<aokicount:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

K = int(input())
count = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            d = gcd(a,b)
            count += gcd(c, d)
print(count)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

K = int(input())
count = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            d = gcd(a,b)
            count += gcd(c, d)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

K = int(input())
count = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            count += gcd(a,b,c)
print(count)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

K = int(input())
count = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            d = gcd(a,b)
            count += gcd(c, d)
print(count)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i) + (100*j) + (50*k) == x:
                count += 1
print(count)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i) + (100*j) + (50*k) == X:
                count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N-i+1):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            print(i, j, n-i-j)
            exit()
print('-1 -1 -1')

Fixed submission:
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N-i+1):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            print(i, j, N-i-j)
            exit()
print('-1 -1 -1')
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                count += 1
print(count)

Fixed submission:
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                count += 1
print(count)

Fixed submission:
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split(" ")]
res=1
xx=10**18
for i in a:
    res*=i
if res>xx:
    print(-1)
else:
    print(res)

Fixed submission:
N = int(input())
a = [int(i) for i in input().split(" ")]
res=1
xx=10**18
f=0
a.sort()
for i in a:
    res*=i
    if res>xx:
        f=1
        print(-1)
        break

if f==0:
    print(res)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().strip.split(" ")]
res=1
xx=1**18
for i in a:
    res*=i
if res>xx:
    print(-1)
else:
    print(res)

Fixed submission:
N = int(input())
a = [int(i) for i in input().split(" ")]
res=1
xx=10**18
f=0
a.sort()
for i in a:
    res*=i
    if res>xx:
        f=1
        print(-1)
        break

if f==0:
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):

from itertools import permutations

def power(base, exp):
  """ Fast power calculation using repeated squaring """
  if exp < 0:
      return 1 / power(base, -exp)
  ans = 1
  while exp:
      if exp & 1:
          ans *= base
      exp >>= 1
      base *= base
  return ans

def parse():
  return int(input())

def main():
  X = parse()

  A = None
  B = None

  # Z = [i for i in range(0, 5)]
  # print(Z)
  # print(list(permutations(range(0, 5), 2)))
  # print(list(permutations(range(0, 5), 2)))
  # exit(0)

  max_val = 1000
  signs = [[1, 1], [-1, 1], [1, -1], [-1, -1]]

  for i in range(0, max_val + 1):
    for j in range(0, max_val + 1):
      for sign in signs:
        # A5 = 
        # print(i * sign[0], j * sign[1])
        if power(i * sign[0], 5) - power(j * sign[1], 5) == X:
          A = i * sign[0]
          B = j * sign[1]
          break

  print(A, B)

if __name__ == "__main__":
  main()

Fixed submission:

from itertools import permutations

def power(base, exp):
  """ Fast power calculation using repeated squaring """
  if exp < 0:
      return 1 / power(base, -exp)
  ans = 1
  while exp:
      if exp & 1:
          ans *= base
      exp >>= 1
      base *= base
  return ans

def parse():
  return int(input())

def main():
  X = parse()

  A = None
  B = None

  # Z = [i for i in range(0, 5)]
  # print(Z)
  # print(list(permutations(range(0, 5), 2)))
  # print(list(permutations(range(0, 5), 2)))
  # exit(0)

  max_val = 1000
  signs = [[1, 1], [-1, 1], [1, -1], [-1, -1]]

  for i in range(0, max_val + 1):
    for j in range(0, max_val + 1):
      for sign in signs:
        # A5 = 
        # print(i * sign[0], j * sign[1])
        if power(i * sign[0], 5) - power(j * sign[1], 5) == X:
          A = i * sign[0]
          B = j * sign[1]
          print(A, B)
          exit(0)
  print(0, 0)

if __name__ == "__main__":
  main()