Problem p02963 (python)

Fixed submission:
import sys, math
from collections import deque

readline = sys.stdin.readline

S = int(readline())

M = 10 ** 9
rS = math.ceil(math.sqrt(S))

while True:
    rem = rS ** 2 - S

    if rem == 0:
        print('0 0 {} {} {} {}'.format(rS, 0, 0, rS))
        exit(0)

    if rem <= M:
        b = rem
        break
    else:
        b = 0
        a = rem // M + 1
        c = math.floor(rem ** 0.5)
        while a < c and a < M:
            if rem % a == 0:
                b = a
                break
            a += 1
        if b != 0:
            break
    
    if rS >= M:
        rS = M - 1000
    else:
        rS += 1


print('0 0 {} {} {} {}'.format(rS, b, rem // b, rS))

Buggy submission (verdict: Runtime Error):
import sys, math
from collections import deque

readline = sys.stdin.readline

S = int(readline())

M = 10 ** 9
rS = math.ceil(math.sqrt(S))

while True:
    rem = rS ** 2 - S


    if rem <= M:
        b = rem
        break
    else:
        b = 0
        a = rem // M + 1
        c = math.floor(rem ** 0.5)
        while a < c and a < M:
            if rem % a == 0:
                b = a
                break
            a += 1
        if b != 0:
            break
    
    if rS >= M:
        rS = M - 1000
    else:
        rS += 1

if rS < 0 or b < 0 or rem // b > M:
    while True:
        a = 1

print('0 0 {} {} {} {}'.format(rS, b, rem // b, rS))

Buggy submission (verdict: Runtime Error):
import sys, math
from collections import deque

readline = sys.stdin.readline

S = int(readline())

M = 10 ** 9
rS = math.ceil(math.sqrt(S))

while True:
    rem = rS ** 2 - S


    if rem <= M:
        b = rem
        break
    else:
        b = 0
        a = rem // M + 1
        c = math.floor(rem ** 0.5)
        while a < c and a < M:
            if rem % a == 0:
                b = a
                break
            a += 1
        if b != 0:
            break
    
    if rS >= M:
        rS = M - 1000
    else:
        rS += 1

if rS > M or b > M:
    while True:
        a = 1

print('0 0 {} {} {} {}'.format(rS, b, rem // b, rS))

Buggy submission (verdict: Runtime Error):
import sys, math
from collections import deque

readline = sys.stdin.readline

S = int(readline())

M = 10 ** 9
rS = math.ceil(math.sqrt(S))

while True:
    rem = rS ** 2 - S


    if rem <= M:
        b = rem
        break
    else:
        b = 0
        a = rem // M + 1
        c = math.floor(rem ** 0.5)
        while a < c and a < M:
            if rem % a == 0:
                b = a
                break
            a += 1
        if b != 0:
            break
    
    if rS >= M:
        rS = M - 1000
    else:
        rS += 1

if rS > M or b > M:
    assert False

print('0 0 {} {} {} {}'.format(rS, b, rem // b, rS))

Buggy submission (verdict: Runtime Error):
import sys, math
from collections import deque

readline = sys.stdin.readline

S = int(readline())

M = 10 ** 9
rS = math.ceil(math.sqrt(S))

while True:
    rem = rS ** 2 - S


    if rem <= M:
        b = rem
        break
    else:
        b = 0
        a = rem // M + 1
        c = math.floor(rem ** 0.5)
        while a < c and a < M:
            if rem % a == 0:
                b = a
                break
            a += 1
        if b != 0:
            break
    
    if rS >= M:
        rS = M - 1000
    else:
        rS += 1
print('0 0 {} {} {} {}'.format(rS, b, rem // b, rS))

Buggy submission (verdict: Runtime Error):
import sys, math
from collections import deque

readline = sys.stdin.readline

S = int(readline())

M = 10 ** 9
rS = math.ceil(math.sqrt(S))

while True:
    rem = rS ** 2 - S


    if rem <= M:
        b = rem
        break
    else:
        b = 0
        a = rem // M + 1
        c = math.floor(rem ** 0.5)
        while a < c:
            if rem % a == 0:
                b = a
                break
            a += 1
        if b != 0:
            break
    
    if rS == M:
        rS -= 1000
    else:
        rS += 1
print('0 0 {} {} {} {}'.format(rS, b, rem // b, rS))

Buggy submission (verdict: Runtime Error):
import sys, math
from collections import deque

readline = sys.stdin.readline

S = int(readline())

M = 10 ** 9
rS = math.ceil(math.sqrt(S))

while True:
    rem = rS ** 2 - S


    if rem <= M:
        b = rem
        break
    else:
        b = 0
        a = rem // M + 1
        c = math.floor(rem ** 0.5)
        while a < c:
            if rem % a == 0:
                b = a
                break
            a += 1
        if b != 0:
            break
    
    if rS == M:
        rS -= 50
    else:
        rS += 1
print('0 0 {} {} {} {}'.format(rS, b, rem // b, rS))

Buggy submission (verdict: Runtime Error):
import sys, math
from collections import deque

readline = sys.stdin.readline

S = int(readline())

M = 10 ** 9
rS = math.ceil(math.sqrt(S))

while True:
    rem = rS ** 2 - S


    if rem <= M:
        b = rem
        break
    else:
        b = 0
        a = 2
        c = math.floor(rem ** 0.5)
        while a < c:
            if rem % a == 0:
                b = a
                break
            a += 1
        if b != 0:
            break
    
    if rS == M:
        rS -= 50
    else:
        rS += 1

print('0 0 {} {} {} {}'.format(rS, b, rem // b, rS))

Buggy submission (verdict: Runtime Error):
import sys, math
from collections import deque

readline = sys.stdin.readline

S = int(readline())

M = 10 ** 9
rS = math.ceil(math.sqrt(S))

while True:
    rem = rS ** 2 - S


    if rem <= M:
        b = rem
        break
    else:
        b = 0
        a = 2
        c = math.floor(rem ** 0.5)
        while a < c:
            if rem % a == 0:
                b = a
                break
            a += 1
        if b != 0:
            break
    
    rS += 1

print('0 0 {} {} {} {}'.format(rS, b, rem // b, rS))