The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.  According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
from itertools import product
N,Y=map(int, input().split())

def total_check(n, y):
    for b in range(N+1):
        for a in range(N+1):
            if a + b > N:
                break
            c = N - a - b
            t = 10000 * a + 5000 * b + 1000 * c
            print(t)
            if t==y:
                return a, b, c
    return -1,-1,-1
a,b,c=total_check(N,Y)
print(a,b,c)
from itertools import product
N,Y=map(int, input().split())

def total_check(n, y):
    for b in range(N+1):
        for a in range(N+1):
            if a + b > N:
                break
            c = N - a - b
            t = 10000 * a + 5000 * b + 1000 * c
            if t==y:
                return a, b, c
    return -1,-1,-1
a,b,c=total_check(N,Y)
print(a,b,c)
