Buggy python submission (verdict: Time Limit Exceeded):
n, Y = [int(s) for s in input().split(' ')]
 
for x in range(n, -1, -1):
    if Y < x*10000 or n < x:
        continue
    
    for y in range(n-x, -1, -1):
        if Y < x*10000+y*5000 or n < x+y:
            continue
            
        z = int((Y-x*10000-y*5000)/1000)
        if Y == x*10000+y*5000+z*1000 and n == x+y+z:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Fixed submission:
n, y = list(map(int, input().split(' ')))
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        if (y - ten_th * 10000 - five_th * 5000) % 1000 == 0:
            th = int((y - ten_th * 10000 - five_th * 5000) / 1000)
            if n == ten_th + five_th + th:
                print('{} {} {}'.format(ten_th, five_th, th))
                exit()
print('-1 -1 -1')

Buggy python submission (verdict: Runtime Error):
n, Y = [int(s) for s in input().split(' ')]
 
for x in range(n, -1, -1):
    if Y < x*10000 or n < x:
        continue
    
    for y in range(n-x, -1, -1):
        if Y < x*10000+y*5000 or n < x+y:
            continue
            
        if (Y-x*10000-y*5000) % 1000 == 0:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Fixed submission:
n, y = list(map(int, input().split(' ')))
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        if (y - ten_th * 10000 - five_th * 5000) % 1000 == 0:
            th = int((y - ten_th * 10000 - five_th * 5000) / 1000)
            if n == ten_th + five_th + th:
                print('{} {} {}'.format(ten_th, five_th, th))
                exit()
print('-1 -1 -1')

Buggy python submission (verdict: Time Limit Exceeded):
n, Y = [int(s) for s in input().split(' ')]
 
max_x = int(Y/10000)
for x in range(max_x, -1, -1):
    if Y < x * 10000 or n < x:
        continue
    
    max_y = int((Y-x*10000)/5000)
    for y in range(max_y, -1, -1):
        if Y < x*10000+y*5000 or n < x+y:
            continue
            
        z = int((Y-x*10000-y*5000)/1000)
        if (Y-x*10000-y*5000) % 1000 == 0 and n == x+y+z:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Fixed submission:
n, y = list(map(int, input().split(' ')))
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        if (y - ten_th * 10000 - five_th * 5000) % 1000 == 0:
            th = int((y - ten_th * 10000 - five_th * 5000) / 1000)
            if n == ten_th + five_th + th:
                print('{} {} {}'.format(ten_th, five_th, th))
                exit()
print('-1 -1 -1')

Buggy python submission (verdict: Time Limit Exceeded):
n, y = list(map(int, input().split(' ')))
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        for th in range(min(n - ten_th - five_th, int((y - ten_th * 10000 - five_th * 5000) / 1000)), -1, -1):
            #print(ten_th, five_th, th)
            if y == ten_th * 10000 + five_th * 5000 + th * 1000 and n == ten_th + five_th + th:
                print(' '.join(str(s) for s in [ten_th, five_th, th]))
                exit()
print('-1 -1 -1')
            

Fixed submission:
n, y = list(map(int, input().split(' ')))
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        if (y - ten_th * 10000 - five_th * 5000) % 1000 == 0:
            th = int((y - ten_th * 10000 - five_th * 5000) / 1000)
            if n == ten_th + five_th + th:
                print('{} {} {}'.format(ten_th, five_th, th))
                exit()
print('-1 -1 -1')

Buggy python submission (verdict: Time Limit Exceeded):
n, y = list(map(int, input().split(' ')))
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        for th in range(min(n - ten_th - five_th, int((y - ten_th * 10000 - five_th * 5000) / 1000)), -1, -1):
            if y == ten_th * 10000 + five_th * 5000 + th * 1000 and n == ten_th + five_th + th:
                print(' '.join(str(s) for s in [ten_th, five_th, th]))
                exit()
print('-1 -1 -1')
            

Fixed submission:
n, y = list(map(int, input().split(' ')))
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        if (y - ten_th * 10000 - five_th * 5000) % 1000 == 0:
            th = int((y - ten_th * 10000 - five_th * 5000) / 1000)
            if n == ten_th + five_th + th:
                print('{} {} {}'.format(ten_th, five_th, th))
                exit()
print('-1 -1 -1')

Buggy python submission (verdict: Time Limit Exceeded):
n, y = list(map(int, input().split(' ')))
for ten_th in range(int(y / 10000), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(int((y - ten_th * 10000) / 5000), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        for th in range(int((y - ten_th * 10000 - five_th * 5000) / 1000), -1, -1):
            if y == ten_th * 10000 + five_th * 5000 + th * 1000 and n == ten_th + five_th + th:
                print(' '.join(str(s) for s in [ten_th, five_th, th]))
                exit()
print('-1 -1 -1')
            

Fixed submission:
n, y = list(map(int, input().split(' ')))
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        if (y - ten_th * 10000 - five_th * 5000) % 1000 == 0:
            th = int((y - ten_th * 10000 - five_th * 5000) / 1000)
            if n == ten_th + five_th + th:
                print('{} {} {}'.format(ten_th, five_th, th))
                exit()
print('-1 -1 -1')

Buggy python submission (verdict: Time Limit Exceeded):
n, y = list(map(int, input().split(' ')))
for ten_th in range(int(y / 10000), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(int(y / 5000), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        for th in range(int(y / 1000), -1, -1):
            if y == ten_th * 10000 + five_th * 5000 + th * 1000 and n == ten_th + five_th + th:
                print(' '.join(str(s) for s in [ten_th, five_th, th]))
                exit()
print('-1 -1 -1')
            

Fixed submission:
n, y = list(map(int, input().split(' ')))
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        if (y - ten_th * 10000 - five_th * 5000) % 1000 == 0:
            th = int((y - ten_th * 10000 - five_th * 5000) / 1000)
            if n == ten_th + five_th + th:
                print('{} {} {}'.format(ten_th, five_th, th))
                exit()
print('-1 -1 -1')