Problem p02690 (python)

Fixed submission:
input = raw_input

x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: # choufuku
                divisors.append(n//i)
    # divisors.sort()
    return divisors

def f(x, d):
    out = (x+d) ** 5 - x ** 5
    return out

ds = make_divisors(x)
#ds = ds1 + [-d for d in ds1]
#print("ds", ds)

found = False
for d in ds:
    if found:
        break

    d0 = d
    if d0 % 2 == 0:
        b = -d0 // 2
    else:
        b = -d0 // 2 + 1

    while True:
        aa = b+d
        bb = b
        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret > x:
            break
        b += 1

    if found:
        break

    #b = -1
    if d0 % 2 == 0:
        b = -d0 // 2
    else:
        b = d0 // 2 - 1

    while True:
        aa = b+d
        bb = b

        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret > x:
            break
        b -= 1

    if found:
        break

    d0 = d
    d = -d
    
    if d0 % 2 == 0:
        b = d0 // 2
    else:
        b = d0 // 2 + 1

    while True:
        aa = b+d
        bb = b
        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret < x:
            break
        b += 1

    if found:
        break

    if d0 % 2 == 0:
        b = d0 // 2
    else:
        b = d0 // 2 - 1
    while True:
        aa = b+d
        bb = b

        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret < x:
            break
        b -= 1


assert found
print("%d %d" % (a, b))

Buggy submission (verdict: Runtime Error):
input = raw_input

x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: # choufuku
                divisors.append(n//i)
    # divisors.sort()
    return divisors

def f(x, d):
    out = (x+d) ** 5 - x ** 5
    return out

ds = make_divisors(x)
#ds = ds1 + [-d for d in ds1]
#print("ds", ds)

found = False
for d in ds:
    if found:
        break

    b = 0
    while True:
        aa = b+d
        bb = b
        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret > x:
            break
        b += 1

    if found:
        break

    b = -1
    while True:
        aa = b+d
        bb = b

        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret > x:
            break
        b -= 1

    if found:
        break

    d0 = d
    d = -d
    
    if d0 % 2 == 0:
        b = d0 // 2
    else:
        b = d0 // 2 + 1

    while True:
        aa = b+d
        bb = b
        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret < x:
            break
        b += 1

    if found:
        break

    if d0 % 2 == 0:
        b = d0 // 2
    else:
        b = d0 // 2 - 1
    while True:
        aa = b+d
        bb = b

        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret < x:
            break
        b -= 1


assert found
print("%d %d" % (a, b))

Buggy submission (verdict: Runtime Error):
input = raw_input

x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: # choufuku
                divisors.append(n//i)
    # divisors.sort()
    return divisors

def f(x, d):
    out = (x+d) ** 5 - x ** 5
    return out

ds = make_divisors(x)
#print("ds", ds)

found = False
for d in ds:
    if found:
        break

    b = 0
    while True:
        aa = b+d
        bb = b
        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret > x:
            break
        b += 1

    if found:
        break

    b = -1
    while True:
        aa = b+d
        bb = b

        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret > x:
            break
        b -= 1

assert found
print("%d %d" % (a, b))