Problem p03471 (python)

Fixed submission:
N,Y=input().split()
n=int(N)
y=int(Y)//1000
p=y-n
s=y//10
t=y//5
i=-1
j=-1
k=-1
fl=False
for X in range(0,s+1):
    for Y in range(0,t+1):
        q=p-(9*X+4*Y)
        if q==0 and X+Y<=n:
            Z=n-X-Y
            i=X
            j=Y
            k=Z
            break
        if fl:
            break
    if fl:
        break
print(i,j,k)

Buggy submission (verdict: Runtime Error):
x=input()
otoshi=x.split(" ")
N=int(otoshi[0])
Y=int(otoshi[1])
ten_t=Y//10000
 
if ten_t>N:
    ansa=-1 
    ansb=-1 
    ansc=-1
elif ten_t==N:
    if Y==100000*N:
        ansa=N
        ansb=0
        ansc=0
    else:
        ansa=-1 
        ansb=-1 
        ansc=-1
elif 0<=ten_t<N:
    for i in range(0,ten_t+1):
        ra=Y-10000*(ten_t-i)
        fiv_t=ra//5000
        
        if fiv_t+ten_t-i>N:
            ansa=-1 
            ansb=-1 
            ansc=-1
            break
        elif 0<=fiv_t+ten_t-i<=N:
            if ra==5000*(N-ten_t+i):
                ansa=ten_t-i
                ansb=N-ten_t+i
                ansc=0
                break
            else:
                for j in range(0,fiv_t+1):
                    rb=ra-5000*(fiv_t-j)
                    if rb==1000*(N-ten_t+i-fiv_t+j):
                        ansa=ten_t-i
                        ansb=fiv_t-j
                        ansc=N-ten_t+i-fiv_t+j
                        break
    
else:
    ansa=-1 
    ansb=-1 
    ansc=-1
print(ansa,ansb,ansc)

Buggy submission (verdict: Runtime Error):
x=input()
otoshi=x.split(" ")
N=int(otoshi[0])
Y=int(otoshi[1])
ten_t=Y//10000

if ten_t>N:
    ansa=-1 
    ansb=-1 
    ansc=-1
elif ten_t==N:
    if Y==100000*N:
        ansa=N
        ansb=0
        ansc=0
    else:
        ansa=-1 
        ansb=-1 
        ansc=-1
elif 0<=ten_t<N:
    for i in range(0,ten_t+1):
        ra=Y-10000*(ten_t-i)
        fiv_t=ra//5000
        
        if fiv_t+ten_t-i>N:
            ansa=-1 
            ansb=-1 
            ansc=-1
            break
        elif 0<=fiv_t+ten_t-i<=N:
            if ra==5000*(N-ten_t+i):
                ansa=ten_t-i
                ansb=N-ten_t+i
                ansc=0
                break
            else:
                for j in range(0,fiv_t+1):
                    rb=ra-5000*(fiv_t-j)
                    if rb==1000*(N-ten_t+i-fiv_t+j):
                        ansa=ten_t-i
                        ansb=fiv_t-j
                        ansc=N-ten_t+i-fiv_t+j
                        break
    
else:
    ansa=-1 
    ansb=-1 
    ansc=-1
print(ansa,ansb,ansc)

Buggy submission (verdict: Runtime Error):
x=input()
otoshi=x.split(" ")
N=int(otoshi[0])
Y=int(otoshi[1])
ten_t=Y//10000

if ten_t>N:
    ansa=-1 
    ansb=-1 
    ansc=-1
elif ten_t==N:
    if Y==100000*N:
        ansa=N
        ansb=0
        ansc=0
    else:
        ansa=-1 
        ansb=-1 
        ansc=-1
elif ten_t<N:
    for i in range(0,ten_t+1):
        ra=Y-10000*(ten_t-i)
        fiv_t=ra//5000
        
        if fiv_t+ten_t-i>N:
            ansa=-1 
            ansb=-1 
            ansc=-1
            break
        elif fiv_t+ten_t-i<=N:
            if ra==5000*(N-ten_t+i):
                ansa=ten_t-i
                ansb=N-ten_t+i
                ansc=0
                break
            else:
                for j in range(0,fiv_t+1):
                    rb=ra-5000*(fiv_t-j)
                    if rb==1000*(N-ten_t+i-fiv_t+j):
                        ansa=ten_t-i
                        ansb=fiv_t-j
                        ansc=N-ten_t+i-fiv_t+j
                        break
    
else:
    ansa=-1 
    ansb=-1 
    ansc=-1
print(ansa,ansb,ansc)