Problem:
 Score : 300 points    Problem Statement 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.      Constraints  1 ≤ N ≤ 2000  1000 ≤ Y ≤ 2 × 10^7  N is an integer.  Y is a multiple of 1000 .         Input Input is given from Standard Input in the following format:  N  Y       Output If the total value of N bills cannot be Y yen, print -1 -1 -1 .  If the total value of N bills can be Y yen, let one such set of bills be " x  10000 -yen bills, y  5000 -yen bills and z  1000 -yen bills", and print x , y , z with spaces in between. If there are multiple possibilities, any of them may be printed.        Sample Input 1 9 45000      Sample Output 1 4 0 5  If the envelope contained 4  10000 -yen bills and 5  1000 -yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9  5000 -yen bills, so the output 0 9 0 is also correct.       Sample Input 2 20 196000      Sample Output 2 -1 -1 -1  When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000 -yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.       Sample Input 3 1000 1234000      Sample Output 3 14 27 959  There are also many other possibilities.       Sample Input 4 2000 20000000      Sample Output 4 2000 0 0

Solution (Python):
N,Y = map(int, input().split())
n = 0
t5 = 0
t10 = 0
n = int(Y/1000)
if n < N:
    n = -1
    t5 = -1
    t10 = -1


ms = n+t5+t10
while(ms > N):
    if n > 4:
        n -= 5  
        t5+=1
    elif t5 > 1:
        t5 -= 2
        t10 +=1
    else:
        n = -1
        t5 = -1
        t10 = -1
    ms = int(n+t5+t10)

if N -ms == 3:
    if t5 > 2:
        n+=5
        t5-=3
        t10+=1
    else:
        n = -1
        t5 = -1
        t10 = -1
if N -ms==2:
    if t5 > 4:
        n+=5
        t5-=5
        t10+=2
    else:
        n = -1
        t5 = -1
        t10 = -1
if N -ms==1:
    if t5 > 6:
        n+=5
        t5-=7
        t10+=3
    else:
        n = -1
        t5 = -1
        t10 = -1
print(t10,t5,n)

Solution (Python):
n, y = map(int, input().split())

flag = 0
for i in range(n + 1):
    for j in range(n + 1 - i):
        if i * 1000 + j * 5000 + (n - (i + j)) * 10000 == y:
            flag = 1
            ans = [n - i - j, j, i]
            break

print(*ans) if flag == 1 else print(-1, -1, -1)

Solution (Python):
n,y=map(int,input().split())
for i in range(n+1):
    for j in range(n+1-i):
        k=n-i-j
        if 10000*i+5000*j+1000*k==y:
            print(i,j,k)
            exit()
print(-1,-1,-1)

Solution (Python):
if __name__ == "__main__":
    n, y = map(int, input().split())

    

    for i in range(n+1):
        for j in range(n-i + 1):
            k = n - i - j
            if n == i + j + k and y == i * 10000 + j * 5000 + k * 1000:
                print(str(i) + ' ' + str(j) + ' ' + str(k))
                exit()

    print('-1 -1 -1')

Solution (Python):
n,y=map(int,input().split())

res=(-1,-1,-1)

for i in range(n+1):
    for j in range(n-i+1):
        k = 10000*i + 5000*j + 1000*(n-i-j)
        if k==y:
            res=(i,j,n-i-j)
            break
print(*res)

Solution (Python):
ny = input().split(' ')

n = int(ny[0])
y = int(ny[1])

ans = "-1 -1 -1"

for i in range(n+1):
    for j in range(n-i+1):
        if(10000*i+5000*j+1000*(n-i-j) == y):
            ans = str(i)+' '+str(j)+' '+str(n-i-j)
            break

print(ans)

Solution (Python):
n, y = map(int, input().split(" "))

found = False

for i in range(0, n + 1):
    for j in range(0, n + 1 - i):
        sum = 10000 * i + 5000 * j + 1000 * (n - i - j)
        if sum == y:
            found = True
            print(str(i) + " " + str(j) + " " + str(n - i - j))
            break
    if found:
        break

if found is False:
    print("-1 -1 -1")

Solution (Python):
n, Y = map(int, input().split())
a = 0
for x in range(n+1):
    for y in range(n-x+1):
        z = n-x-y
        if (x*10000 + y*5000 + z*1000) == Y:
            print(x, y, z)
            a = 1
            break
    if a == 1:
        break
if a != 1:
    print(-1, -1, -1)

Solution (Python):
n,y=map(int,input().split())
a=0
b=0
c=(y%5000)//1000
n-=c
y-=c*1000
buf=0
if n*10000<y or n*1000>y:
    print(-1,-1,-1)
elif n==0:
    print(0,0,c)
else:
    for i in range(y//10000+1):
        y0=y-i*10000
        n0=n-i
        for j in range(y0//5000+1):
            if j*5000+(n0-j)*1000==y0:
                buf=1
                a=i
                b=j
                c+=n0-j
                break
        if buf==1:
            print(a,b,c)
            break
    if buf==0:
        print(-1,-1,-1)

Solution (Python):
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i*10000 + j*5000 + (n - i - j)*1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Solution (Python):
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Solution (Python):
import sys
n,y = map(int,input().split())
for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        ans = 10000*i+5000*j+1000*k
        if ans == y:
            print('{} {} {}'.format(i,j,k))
            sys.exit()
print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
 
for x in range(N+1):
  for y in range(N+1-x):
        if x*10000 + y*5000 + (N-x-y)*1000 == Y:
           print(x, y, N-x-y)
           exit()
 
print("-1 -1 -1")

Solution (Python):
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if y - 10000*i - 5000*j == 1000*k and 0 <= k <= n:
            a=str(i)
            b=str(j)
            c=str(n-i-j)
            print(a+" "+b+" "+c)
            exit()
print("-1 -1 -1")

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N, Y = map(int, input().split())
    ans = "-1 -1 -1"
    for i in range(N+1):
        for j in range(N+1-i):
            if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
                ans = "{} {} {}".format(i, j, N-i-j)
                break
        if ans != "-1 -1 -1":
            break
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n,Y=map(int,input().split())
Y=Y//1000
for i in range(n+1):
  for j in range(n-i+1):
    if 10*i+5*j+(n-i-j)==Y:
      print(i,j,n-i-j)
      exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())
number =[]
for x in range (0, N+1):
  for y in range (0, N+1-x):
    z = N -x -y
    if z >= 0 and x*10000 + 5000*y + z*1000 == Y:
        number.append(x)
        number.append(y)
        number.append(z)

if len(number) >=3:
  print('{} {} {}'.format(number[0],number[1],number[2]))
else:
  print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())

for yuk in range(N + 1):
    for hig in range(N - yuk + 1):
        if yuk * 10000 + hig * 5000 + (N-yuk-hig) * 1000 == Y:
            print('%d %d %d' % (yuk, hig, N-yuk-hig))
            exit()
print('-1 -1 -1')

Solution (Python):
x,y=map(int,input().split())
y=y//1000
n=0
for i in range(x+1):
  if n==1:
    break
  if i==x:
    if y==i:
      print(0,0,x)
    else:
      print(-1,-1,-1)
  else:
    for j in range(x-i+1):
      v=i+5*j+10*(x-i-j)
      if y==v:
        print(x-i-j,j,i)
        n+=1
        break

Solution (Python):
n,Y = map(int,input().split())
x = -1
y = -1
z = -1

for i in range(n+1):
    x_man = i * 10000
    for j in range(n+1):
        y_thou = j * 5000
        z_thou = (Y - x_man - y_thou)//1000
        
        if z_thou >= 0:
            if i + j + z_thou == n:
                x = i
                y = j
                z = z_thou
                break

print(x,y,z)

Solution (Python):
n,y = map(int, input().split())

def Otoshidama(n):
    for i in range(0, y//10000 + 1):
        for j in range(0, (y - 10000*i)//5000 + 1):
            h = y - 10000*i - 5000*j
            if h%1000 == 0 and h >= 0 and i + j + h//1000 == n:
                return str(i) + " " + str(j) + " " + str(h//1000)
    return "-1 -1 -1"

print(Otoshidama(n))

Solution (Python):
N_,Y_=input().split()
N=(int)(N_)
Y=(int)(Y_)

count = 0
a_ = Y//10000
if a_>N:
    a_ = N
for a in range(a_+1):
    Y_ = Y-a*10000
    N_ = N-a
    b_ = Y_//5000
    if b_>N_ and b_>=0:
        b_ = N_
    for b in range(b_+1):
        Y__ = Y_-b*5000
        N__ = N_-b
        c_ = Y__//1000
        if Y__%1000==0:
            if c_==N__ and c_>=0:
                print((str)(a)+" "+(str)(b)+" "+(str)(c_))
                exit(0)
print("-1 -1 -1")

Solution (Python):
n, y = map(int, input().split())
def find(n,y):
    for p in range(n+1):
        for q in range(n-p+1):
            if 9000*p + 4000*q == y - 1000*n:
                return [p,q,n-p-q]
    return [-1,-1,-1]

for i in find(n,y):
    print(i, end=" ")
print()

Solution (Python):
N,Y=map(int,input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)

Solution (Python):
nums = list(map(int, input().rstrip().split()))


N = nums[0]
Y = nums[1]

count=[-1,-1,-1]
break_flag=False
for a in range(0,N+1):
    for b in range(0,N+1-a):
        c = N - (a+b)
        total = a*10000 + b*5000 + c*1000
        
        if total == Y:
            count = [a,b,c]
            break_flag=True
            break
            
    if break_flag:
        break

print(" ".join(str(i) for i in count))

Solution (Python):
nums = list(map(int, input().rstrip().split()))



N = nums[0]
Y = nums[1]


count=[-1,-1,-1]
break_flag=False
for a in range(0,N+1):
    for b in range(0,N+1-a):
        c = N - (a+b)
        
        total = a*10000 + b*5000 + c*1000

        
        if total == Y:
            count = [a,b,c]

            break_flag=True
            break
            
    if break_flag:
        break

print(" ".join(str(i) for i in count))

Solution (Python):
def main(N,Y):
    for i in range(N+1):
        for j in range(N+1-i):
            k = N - i - j
            if 10000*i +5000*j + 1000*k == Y:
                return i, j, k
    else:
        return -1, -1, -1

N,Y = map(int, input().split())
print(*main(N,Y))

Solution (Python):
def main():
    number, new_year_gift = map(int, input().split(" "))
    answer = True
    for i in range(number, -1, -1):
        if not answer:
            break
        for j in range(number + 1):
            if number < i + j:
                continue
            elif 10000 * i + 5000 * j + 1000 * (number - i - j) == new_year_gift and answer:
                print(i, j, number - i - j)
                answer = False
                break
    if answer:
        print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):
num,total=[int(str) for str in input().split()]





total_cal=[]
num_10000=0
num_5000=0
num_1000=0
limit=20

if num<limit:
    pass
else:
    for num_cal in range(num,limit,-1):
        
        
        ave=total/num_cal
        diff=[abs(10000-ave),abs(5000-ave),abs(1000-ave)]
        if diff.index(min(diff))==0:
            total-=10000
            num_10000 += 1
        elif diff.index(min(diff))==1:
            total-=5000
            num_5000 += 1
        else:
            total-=1000
            num_1000 += 1

    num=limit
    
    

for i in range(num+1):
    for j in range(num+1):
        for k in range(num+1):
            total_cal.append({"nums":[i,j,k],'total':10000*i+5000*j+1000*k})

nums=[x["nums"] for x in total_cal if x['total']==total and sum(x['nums'])==num]


if total_cal!=0 and nums==[]:
    print("-1 -1 -1")
else:
    nums = [x + y for (x, y) in zip(nums[0], [num_10000, num_5000, num_1000])]
    print('{num_10000} {num_5000} {num_1000}'.format(num_10000=nums[0],num_5000=nums[1],num_1000=nums[2]))

Solution (Python):
num,total=[int(str) for str in input().split()]

nums_result=[-1,-1,-1]

for i in range(num+1):
    for j in range(num+1-i):
        k=num-(i+j)
        if total==10000*i+5000*j+1000*k:
            nums_result=[i,j,k]

print("{} {} {}".format(nums_result[0],nums_result[1],nums_result[2]))

Solution (Python):
num,total=[int(str) for str in input().split()]





total_cal=[]
num_10000=0
num_5000=0
num_1000=0
limit=50

if num<limit:
    pass
else:
    for num_cal in range(num,limit,-1):
        
        
        ave=total/num_cal
        diff=[abs(10000-ave),abs(5000-ave),abs(1000-ave)]
        if diff.index(min(diff))==0:
            total-=10000
            num_10000 += 1
        elif diff.index(min(diff))==1:
            total-=5000
            num_5000 += 1
        else:
            total-=1000
            num_1000 += 1

    num=limit
    
    

for i in range(num+1):
    for j in range(num+1):
        for k in range(num+1):
            total_cal.append({"nums":[i,j,k],'total':10000*i+5000*j+1000*k})

nums=[x["nums"] for x in total_cal if x['total']==total and sum(x['nums'])==num]


if total_cal!=0 and nums==[]:
    print("-1 -1 -1")
else:
    nums = [x + y for (x, y) in zip(nums[0], [num_10000, num_5000, num_1000])]
    print('{num_10000} {num_5000} {num_1000}'.format(num_10000=nums[0],num_5000=nums[1],num_1000=nums[2]))

Solution (Python):
n, y = map(int, input().split())
ans = [-1]*3
for i in range(0, int(y/10000)+1):
    ty = y-10000*i
    tn = n-i
    for j in range(0, min(int(ty/5000)+1,tn+1)):
        tty = ty-5000*j
        ttn = tn-j
        if tty%1000 == 0 and ttn==tty//1000:
            print(i, j, tty//1000)
            exit()
print(-1, -1, -1)

Solution (Python):
N,Y = list(map(int, input().split()))

ans = [-1,-1,-1]

for a in range(N+1):
        for b in range(N+1-a):
                c = N - a - b;
                total = 10000 * a + 5000 * b + 1000 * c
                if total == Y:
                        ans = [ a , b , c ]

print(str(ans[0]) + " " + str(ans[1]) + " " + str(ans[2]))

Solution (Python):
import sys
n, price = map(int, input().split())
ans = [-1, -1, -1]
for x in range(n+1):
    for y in range(n+1):
        z = n - x - y
        if z < 0:
            continue
        if 10000 * x + 5000 * y + 1000 * z == price:
            ans = [x, y, z]
            print(*ans)
            sys.exit()
print(*ans)

Solution (Python):
def main(N,Y):
    for i in range(N+1):
        for j in range(N+1-i):
            k = N-i-j
            if 10000*i + 5000*j + 1000*k == Y:
                return i,j,k
    else:
        return -1,-1,-1

N,Y = map(int, input().split())
print(*main(N,Y))

Solution (Python):
def main(N,Y):
    for i in range(N+1):
        for j in range(N+1-i):
            k = N-i-j
            if 10000*i + 5000*j + 1000*k == Y:
                return i,j,k
                break
    else:
        return -1,-1,-1

N,Y = map(int, input().split())
print(*main(N,Y))

Solution (Python):
import sys
n, y = map(int, input().split())

for i in range(n + 1):
    for j in range(n - i + 1):
        k = n - i - j
        if 10000 * i + 5000 * j + 1000 * k == y:
            print(i, j, k)
            sys.exit()

print('-1 -1 -1')

Solution (Python):
N,Y = map(int, input().split())
for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            print(i,j,N-i-j)
            exit()
print(-1,-1,-1)

Solution (Python):
N, M = map(int, input().split())
l = [-1, -1, -1]
for i in range(N+1):
  for j in range(N-i+1):
    if 1000 * i + 5000 * j + 10000 * (N-i-j) == M:
      l = [i, j, N-i-j]
      break
print(l[2], l[1], l[0])

Solution (Python):
N, M = map(int, input().split())
l = [-1, -1, -1]
for i in range(N+1):
  for j in range(N-i+1):
    if 1000 * i + 5000 * j + 10000 * (N-i-j) == M:
      l = [i, j, N-i-j]
print(l[2], l[1], l[0])

Solution (Python):
N, Y = map(int, (input().split(' ')))
for x in range(N + 1):
  for y in range(N + 1 - x):
    if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
      print(x, y, N-x-y)
      exit()
print('-1 -1 -1')

Solution (Python):
n, Y = map(int, input().split())
for x in range(n+1):
    for y in range(n-x+1):
        z = n-x-y
        if (x*10000 + y*5000 + z*1000) == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]




n,y = mii()
y = y//1000
ans=[]
for a in range(n+1):
    for b in range(n-a+1):
        
        c = n-a-b
        
        if a*10+b*5+c == y:
            ans = [a,b,c]

if len(ans)==0:
    print("-1 -1 -1")
else:
    print(str(ans[0])+" "+str(ans[1])+" "+str(ans[2]))

Solution (Python):
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N-i+1):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            print(i, j, N-i-j)
            exit()

print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
d = (Y // 1000) - N
flg = True
for i in range(N + 1):
  if (d - 9 * i) % 4 == 0 and d >= 9 * i:
    if (i + (d - 9 * i) // 4) <= N:
      print(i, (d - 9 * i) // 4, N - i - (d - 9 * i) // 4)
      flg = False
      break
if flg:
  print(-1, -1, -1)

Solution (Python):
n,y = map(int,input().split())
for i in range(n+1):
    for j in range(n+1):
        k = n-i-j
        if i*10000+j*5000+k*1000 == y and 0 <= k <= 2000:
            print(i,j,k)
            exit()
print("-1 -1 -1")

Solution (Python):
N, Y = map(int,input().split())
c = Y//1000
for x in range(N+1):
    if (c-N-9*x) % 4 == 0:
        y = (c-N-9*x)//4
        if 0<=y<=N-x:
            print(x,y,N-x-y)
            exit(0)
print(-1,-1,-1)

Solution (Python):
n,y = map(int,input().split())

for i in range(y//10000+1):
    if i > n:
        break
    for j in range((y-i*10000)//5000+1):
        if i + j > n:
            break
        if i * 10000 + j * 5000 + (n-i-j) * 1000 == y:
            print(i,j,n-i-j)
            exit()

print(-1,-1,-1)

Solution (Python):
l = list(map(int, input().split()))
n, y = l[0], l[1]
y /= 1000
ans = '-1 -1 -1'
flag = 0
for i in range(n+1):
    for j in range(n-i+1):
        k = n-(i+j)
        total = 10*i+5*j+k
        if total == y:
            ans = '{} {} {}'.format(i, j, k)
            flag = 1
            break
    if flag: break
print(ans)

Solution (Python):
def main():
  n,y=map(int,input().split())
  for i in range(n+1):
    for j in range(n+1-i):
      if 10**3*(i+5*j+10*(n-i-j))==y:
        print(n-i-j,j,i)
        exit()
  print(-1,-1,-1)
  
if __name__=="__main__":
  main()

Solution (Python):
N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N - x + 1):
        z = N - x - y
        if x*10000+y*5000+z*1000 == Y:
            print(x, y, z)
            exit()


print("-1 -1 -1")

Solution (Python):
N,Y=map(int,input().split())
x=-1
y=-1
z=-1
for i in range(N+1):
        for j in range(N-i+1):
            if i*10000+j*5000+(N-(i+j))*1000==Y:
                x=i
                y=j
                z=N-i-j
                break
            
print(str(x)+" "+str(y)+" "+str(z))

Solution (Python):
n, y = map(int,input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if y-10000*i-5000*j-1000*(n-i-j) == 0:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int,input().split())

for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if 0 <= z <= 2000 and 10000*x + 5000*y + 1000*z == Y:        
            print(x, y, z )
            exit()

print('-1 -1 -1')

Solution (Python):
n,y= map(int,input().split())

ans=(-1,-1,-1)
m=range(n+1)
for a in m:
	for b in m:
		c=n-a-b
		total = 10000*a + 5000*b + 1000*c
		if (c>=0) & (total==y):
			ans=(a,b,c)
			break
		else:
			continue
		break

print("%d %d %d"%ans)

Solution (Python):
import sys
n,y = map(int,input().split())

for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if (10000*i+5000*j+1000*k == y):
            print(i,j,k)
            sys.exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())

flg = True
for x in range(N+1):
  for y in range(N+1-x):
    _ = 10000*x + 5000*y
    if Y - _ == (N-x-y)*1000:
      ans = [x,y,N-x-y]
      flg = False
      
if flg:
  ans = [-1, -1, -1]

print(*ans)

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def f(b, c):
    return 9000 * c + 5000 * b


def main():
    N, Y = MI()

    for b in range(0, N+1):
        for c in range(0, N+1):
            ret = f(b, c)
            if ret == 10000 * N - Y and b + c <= N:
                print(N - b - c, b, c)
                return

    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):
N, Y = map(int, input().split())

A, B, C = -1, -1, -1
for i in range(N + 1):
    for j in range(N + 1):
        k = N - i - j
        if k < 0:
            continue
        else:
            y = 10000 * i + 5000 * j + 1000 * k
            if Y == y:
                A = i
                B = j
                C = k
                break

print(A, B, C)

Solution (Python):
try:
    N, Y = map(int, input().split())
    cnt = 0
    for x in range(N+1):
        for y in range(N+1):
            z = N-x-y
            if z>=0 and 10000*x+5000*y+1000*z==Y:
                cnt += 1
                print(x,y,z)
                break
        if cnt>0:
            break
    if cnt==0:
        print('-1 -1 -1')
except EOFError:
    pass

Solution (Python):
n, y = map(int, input().split())
flag = 0
for i in range(n+1):
    for j in range(n-i+1):
        k = n - (i + j)
        if 10000*i + 5000*j + 1000*k == y:
            print(i, j, k)
            flag = 1
            exit()

if flag == 0:
    print(-1, -1, -1)

Solution (Python):
import sys

n, y = list(map(int, input().split()))

for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i+5000*j+1000*(n-i-j) == y:
            print(i, j, n-i-j)
            sys.exit(0)
print(-1, -1, -1)

Solution (Python):
n, y = map(int, input().split())
for a in range(n+1):
  for b in range(n+1):
    c = n - a - b
    if c < 0:
      continue
    if 10000*a + 5000*b + 1000*c == y:
      print(a, b, c)
      exit()
else:
  print(-1, -1, -1)

Solution (Python):
s = input().split()
N = int(s[0])
Y = int(s[1])

for a in range(N + 1):
    for b in range(N - a + 1):
        c = N - a - b
        if a * 10000 + b * 5000 + c * 1000 == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            exit(0)

print("-1 -1 -1")

Solution (Python):
a,sums= list(map(int,input().split()))
yuki = sums//10000
taishi = (sums%10000) //5000
noguchi = (sums%5000) //1000
while a>yuki+taishi+noguchi:
  if ((a-(yuki+taishi+noguchi))%4==0)&(taishi>0):
    taishi-=1
    noguchi+=5
  elif yuki>0:
    yuki-=1
    taishi+=2
  else:
    break
if a==yuki+taishi+noguchi:
  print(yuki,taishi,noguchi)
else:
  print("-1 -1 -1")

Solution (Python):
n,y=map(int,input().split())

for i in range(n+1):
  for j in range(n+1):
    k=n-i-j
    if k>=0 and i*10000+j*5000+k*1000==y:
      print(i,j,k)
      exit()
print(-1,-1,-1)

Solution (Python):
N,Y = map(int, input().split())

res = '-1 -1 -1'
for x in range(N+1):
    for y in range(N+1-x):
        z = N-x-y
        if (10000*x+5000*y+1000*z==Y):
            res = str(x)+' '+str(y)+' '+str(z)
            break
print(res)

Solution (Python):
N, Y=list(map(int, input().split()))

x, y, z = -1, -1 ,-1
for i in range(0, N+1):
    for j in range(0, N-i+1):
        if 10000*i+5000*j+1000*(N-i-j)==Y:
            x, y, z = i, j, N-i-j
            break
print(x, y, z)

Solution (Python):
n,y = map(int,input().split())
res10000 = -1
res5000 = -1
res1000 = -1
for a in range(n+1):
    for b in range(n+1-a):
        c = n-a-b
        total = a*10000+b*5000+c*1000
        if total == y:
            res10000 = a
            res5000 = b
            res1000 = c
print(res10000, res5000, res1000)

Solution (Python):

N, Y = map(int, input().split())

ans_a = -1
ans_b = -1
ans_c = -1


for a in range(N+1) :
    for b in range(N-a+1) :
        total = 10000 * a + 5000 * b + 1000 * (N-a-b)
        if total == Y :
            ans_a = a
            ans_b = b
            ans_c = N-a-b


print("{} {} {}".format(ans_a, ans_b, ans_c))

Solution (Python):
n,y=map(int,input().split())
if y>10000*n:
    print("-1 -1 -1")
else:
    for i in range(n+1):
        
        for j in range(n-i+1):
            if y==10000*i+5000*j+(n-i-j)*1000:
                print(i,j,(n-i-j))
                exit()
    print("-1 -1 -1")

Solution (Python):
n, y = map(int, input().split())

for i in range(n + 1):
    for j in range(n + 1 - i):
        k = (y - i * 10000 - j * 5000) // 1000
        if i + j + k == n:
            print(i, j, k)
            exit()

print(-1, -1, -1)

Solution (Python):
N , Y = map(int, input().split())
ans = []
for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if k >= 0:
            num = i*10000 + j*5000 + k*1000
            if num == Y:
                ans = [i, j, k]

if len(ans) == 0:
    ans = [-1, -1, -1]
    
print(" ".join(map(str,ans)))

Solution (Python):
def main(n,y):
    for i in range(n+1):
        for j in range(n+1):
            k = n-i-j
            if k < 0 : continue
            if ((10000*i) + (5000*j) + (1000*k)) == y:
                return "{0} {1} {2}".format(i,j,k)
    return "-1 -1 -1"

n,y = map(int, input().split())
print(main(n,y))

Solution (Python):
n,y = map(int,input().split())
if y%1000 != 0:
  print(-1,-1,-1)
  quit()
M0 = y//10000
for ml in range(M0+1):
  M1 = (y-10000*ml)//5000
  for fv in range(M1+1):
    th = (y-10000*ml-5000*fv)//1000
    if ml+fv+th == n:
      print(ml,fv,th)
      quit()
print(-1,-1,-1)

Solution (Python):
[N, Y] = list(map(int, input().split()))
flag = False
for i in range(0, N+1):
  if 10000*i > Y:
    break
  for j in range(0, N+1-i):
    k = N-i-j
    total = 10000*i + 5000*j + 1000*k
    if total == Y:
      print("{} {} {}".format(i, j, k))
      flag = True
      break
  if flag:
    break

if flag == False:
  print("-1 -1 -1")

Solution (Python):
N,Y=map(int,input().split())
for x in range(N+1):
  for y in range(N+1-x):
    z=N-x-y
    if 10000*x+5000*y+1000*z==Y:
      print(x,y,z)
      exit()
print(-1,-1,-1)

Solution (Python):
N,Y = map(int,input().split())

flag = False
for i in range(N+1):
    if flag:
        break
    for j in range(N+1-i):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            l = [i,j,N-i-j]
            flag = True
            break
if flag:
    print(l[0],l[1],l[2])
else:
    print(-1,-1,-1)

Solution (Python):
import sys
n,y = map(int,input().split())

for i in range(n+1):
    for j in range(n+1-i):
        k = n - i - j
        if i*10000 + j*5000 + k*1000 == y:
            print(i,j,k)
            sys.exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())

for n_10000 in range(min(N+1, Y//10000+1)):
    for n_5000 in range(min(N-n_10000+1, (Y-n_10000*10000)//5000+1)):
        n_1000 = N - n_10000 - n_5000
        if n_10000 * 10000 + n_5000 * 5000 + n_1000 * 1000 == Y:
            print(n_10000, n_5000, n_1000)
            exit()

print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
res10000 =res5000 = res1000 = -1

for x in range(N+1):
    for y in range(N+1-x):
        z = N-x-y
        if 10000*x + 5000*y + 1000*z == Y:
            res10000 = x
            res5000 = y
            res1000 = z

print(res10000, res5000, res1000)

Solution (Python):
n,y = map(int,input().split())
yukichi = -1
higuchi = -1
noguchi = -1
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            yukichi = i
            higuchi = j
            noguchi = n-i-j

print("{} {} {}".format(yukichi,higuchi,noguchi))

Solution (Python):
N, Y = map(int, input().split())
for a in range(N + 1):
    for b in range(N + 1 - a):
        c = N - a - b
        if a * 10000 + b * 5000 + c * 1000 == Y:
            print("{0} {1} {2}".format(a, b, c))
            exit()
print("-1 -1 -1")

Solution (Python):
N,Y=map(int,input().split())
flag=0

for x in range(N+1):
  if flag==1:
    break
  for y in range(N+1-x):
    z=N-x-y
    money=10000*x+5000*y+1000*z
    if money == Y:
      print(x," ",y," ",z)
      flag=1
      break
        
if flag==0:
  print("-1 -1 -1")

Solution (Python):
n,y=map(int,input().split())
for i in range(n+1):
  for j in range(n+1-i):
    k=n-i-j
    if 10000*i+5000*j+1000*k==y:
      print(i,j,k)
      exit()
print(-1,-1,-1)

Solution (Python):
n, y = map(int, input().split())
flag = 0
for i in range(min(n, y//10000)+1):
    if flag == 1:
        break
    else:
        for j in range(min(n-i, (y-10000*i)//5000)+1):
            amari = y - (10000*i + 5000*j)
            if amari // 1000 == n-i-j:
                print(i, j, n-i-j)
                flag += 1
                break

if flag == 0:
    print(-1, -1, -1)

Solution (Python):
def main():
    N, Y = map(int, input().split())
    a = b = c = -1

    for i in range(N + 1):
        for j in range(N + 1 - i):
            k = N - i - j
            if 10000 * i + 5000 * j + 1000 * k == Y:
                a, b, c = i, j, k

    print(a, b, c)


if __name__ == "__main__":
    main()

Solution (Python):

N,Y=map(int,input().split(" "))
for x in range(N+1):
  for y in range(N+1-x):
    z=N-x-y
    if 10000*x+5000*y+1000*z==Y:
      print(str(x)," ",str(y)," ",str(z))
      exit()
print("-1 -1 -1")

Solution (Python):
def main():
    N,Y=map(int,input().split())

    for i in range(Y//10000+1):
        tY=Y-10000*i
        for j in range(tY//5000+1):
            k=(tY-5000*j)//1000
            if i+j+k==N:
                print(i,j,k)
                return

    print("-1 -1 -1")

main()