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,t=map(int,input().split())
for x in range(n+1):
  for y in range(n-x+1):
    z=n-x-y
    if 10000*x+5000*y+1000*z==t and z>=0:
      print(x,y,z)
      exit()
print(-1,-1,-1)

Solution (Python):
n,t=map(int,input().split())
for x in range(n+1):
  for y in range(n+1):
    z=n-x-y
    if 10000*x+5000*y+1000*z==t and z>=0:
      print(x,y,z)
      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):
        k = n - i - j
        if k < 0:
            continue
        if i * 10000 + j * 5000 + k * 1000 == y:
            print(i, j, k)
            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):
		if (N-x-y) < 0:
			continue
		total = 10000*x + 5000*y + 1000*(N-x-y)
		if total > Y:
			continue
		if total == Y:
			print(str(x)+" "+str(y)+" "+str(N-x-y))
			exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())
ax = ay = az = -1
for x in range(N+1):
	for y in range(N+1):
		if (N-x-y) < 0:
			continue
		total = 10000*x + 5000*y + 1000*(N-x-y)
		if total == Y:
			ax = x
			ay = y
			az = N-x-y
			break
	else:
		continue
	break
print(str(ax)+" "+str(ay)+" "+str(az))

Solution (Python):
import sys
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('{} {} {}'.format(x, y, z))
      sys.exit()
  else:
    continue
  break
else:
  print('-1 -1 -1')

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

y //= 1000

if 10*n < y:
    print(-1, -1, -1)
    exit()

for i in range(n+1):
    for j in range(n-i+1):
        otoshidama = 10*i + 5*j
        otoshidama_1 = n-i-j if n-i-j > 0 else 0
        otoshidama += otoshidama_1
        if otoshidama == y and i+j+otoshidama_1:
            print(i, j, otoshidama_1)
            exit()
else:
    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("{} {} {}".format(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):
        if i*10000+j*5000+(n-i-j)*1000==y and n-i-j>=0:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())
for a in range(min(N, Y // 1000) + 1):
    for b in range(min(N - a, Y // 5000) + 1):
        c = N - a - b
        if 1000 * a + 5000 * b + 10000 * c == Y:
            print(c, b, a)
            exit()
print(-1, -1, -1)

Solution (Python):
a,b = input().split()
cnt = 0

for i in range(int(a)+1):
  for j in range(int(a)-i+1):
    k = int(a)-i-j
    s = 10000*i + 5000*j + 1000*k
    if int(b) == s:
      if int(a) == i+j+k:
        print("{} {} {}".format(i,j,k))
        cnt = 1
        break
  else:
    continue
  break

if cnt != 1:
  print("{} {} {}".format(-1,-1,-1))

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

x=y//10000
ans="-1 -1 -1"
for i in range(x+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))
            

print(ans)

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


for i in range(n+1):
    for j in range(n-i+1):
        if 10**4 * i + 5 * 10 ** 3 * j + 10 ** 3 * (n - i - j) == a:
            print(i,j,n-i-j)
            sys.exit()

print(-1,-1,-1)

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

flag = False

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)
            flag = True
            break
    if flag == True :
        break

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

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

flag = False

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 :
            print(i, j, k)
            flag = True
            break
    if flag == True :
        break

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

Solution (Python):
from sys import stdin

n, y = [int(x) for x in stdin.readline().rstrip().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())
r = (y % 5000) // 1000
if n < r:
    print(-1, -1, -1)
    exit()
for no in range(r, n+1, 5):
    hifu = n - no
    if hifu*5000 <= y - no*1000 <= hifu*10000:
        hi = (hifu * 10000 - y + no*1000) // 5000
        fu = (y - no*1000 - hifu * 5000) // 5000
        print(fu, hi, no)
        exit()
print(-1, -1, -1)

Solution (Python):
N,B=map(int,input().split())
num=0
x=-1
y=-1
z=-1
for X in range(N+1):
    for Y in range(N-X+1):
        Z=N-X-Y
        money=10000*X+5000*Y+1000*Z
        if money==B:
            x=X
            y=Y
            z=Z
print(x," ",y," ",z)

Solution (Python):
N, Y = map(int, input().rstrip().split(' '))
n10k = int(Y / 10000)
n10k = min(N, n10k)
n5k = int(Y / 5000)
n5k = min(N, n5k)
n1k = int(Y / 1000)
n1k = min(N, n1k)
cd = None
for i in range(n10k + 1):
    for j in range(n5k + 1):
        k = N - i - j
        if k < 0:
            break

        v = (i * 10000) + (j * 5000) + (k * 1000)
        if v == Y:
            print('{} {} {}'.format(i, j, k))
            exit(0)


print('-1 -1 -1')

Solution (Python):
a,b=map(int,input().split())
for s in range(b//10000+1):
    for t in range(b//5000+1):
        r=a-s-t
        if r<0:
            break
        if 10000*s+5000*t+1000*r==b and s+t+r==a:
            print(s,t,r)
            exit()
print(-1,-1,-1)

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

Solution (Python):
a,b=map(int,input().split())
for s in range(b//10000+1):
    try:
        for t in range(b//5000+1):
            r=a-s-t
            if r<0:
                break
            if 10000*s+5000*t+1000*r==b and s+t+r==a:
                print(s,t,r)
                exit()
    except ZeroDivisionError:
        continue
print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
flag=False
l=[]
for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            flag=True
            l.append([i,j,n-i-j])
            break
        else:
            pass
    if flag:
        break
if flag:
    print(str(l[0][0])+" "+str(l[0][1])+" "+str(l[0][2]))
else:
    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<=N:
			en_sum = 10000*x + 5000*y + 1000*z
			if en_sum==Y:
				print(x, y, z)
				exit()
print(-1, -1, -1)

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

x_lst = []
y_lst = []
z_lst = []
for x in range(N+1):
	for y in range(N+1):
		z = N -(x + y)
		if 0<=z<=N:
			en_sum = 10000*x + 5000*y + 1000*z
			if en_sum==Y:
				x_lst.append(x)
				y_lst.append(y)
				z_lst.append(z)
if x_lst:
	print(x_lst[0], y_lst[0], z_lst[0])
else:
	print(-1, -1, -1)

Solution (Python):
n,y = map(int,input().split())
for i in range(n+1):
    if y//1000 - n - 9*i >= 0 and (y//1000 - n - 9*i)%4 == 0:
        if n - i - (y//1000 - n - 9*i)//4 >= 0:
            print(str(i)+" "+str((y//1000 - n - 9*i)//4)+" "+str(n - i - (y//1000 - n - 9*i)//4))
            break
    elif i == n:
        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 = int((Y - (i*10000 + j*5000))/1000)
        if k == N - (i + j):
            print("{} {} {}".format(i, j, k))
            exit()
print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())
result = [-1, -1, -1]
for a in range(0, N+1):
    for b in range(0, N+1):
        c = N-a-b
        if c < 0:
            continue
        if Y == (10000*a + 5000*b + 1000*c):
            result[0] = a
            result[1] = b
            result[2] = c
print (" ".join(map(str, result)))

Solution (Python):
judge = False
N, Y = map(int, input().split())
x = -1
while x <= N and (not judge):
    x += 1
    y = z = 0
   
    rest = Y - x * 10000
    if rest <= 0:
        if rest == 0 and x == N:
            judge = True
        break
    while x + y <= N and Y - x * 10000 - y * 5000 >= 0:
        z = (Y - x * 10000 - y * 5000) // 1000
      
        if x + y + z == N:
            judge = True
            break
        y += 1
if judge:
    print(str(x) + ' ' + str(y) + ' ' + str(z))
else:
    print('-1 -1 -1')

Solution (Python):
def otoshidama(n, y):
    minus = 0
    tenthousand = range(n + 1)
    for i in tenthousand:
        for p in range(n + 1 - minus):
            o = n-(i+p)
            if (i*10000+p*5000+o*1000) == y:
                return str(i)+' '+str(p)+' '+str(o)
        minus += 1
    return '-1 -1 -1'
N, Y = map(int, input().split())
print(otoshidama(N, Y))

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

ans = [0]*3
isDiscovered = False

for i in range( Y//10000+1 ):
    a = Y - 10000*i
    for j in range( a//5000+1 ):
        b = (a - 5000*j) / 1000
        if( b.is_integer() and i + j + b == N ):
            ans[0] = i
            ans[1] = j
            ans[2] = int(b)
            isDiscovered = True
            break
    if isDiscovered: break

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

Solution (Python):
def otoshidama(x, y):
    minus = 0
    tenthousand = range(x+1)
    for i in tenthousand:
        for p in range(x+1-minus):
            o = x - (i+p)
            if y == (i*10000+p*5000+o*1000):
                return str(i)+' '+str(p)+' '+str(o)
        minus += 1
    return '-1 -1 -1'
N, Y = map(int,input().split())
print(otoshidama(N, Y))

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

print(ans[0], ans[1], ans[2])

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

Solution (Python):

"""
Created on Wed Feb 27 23:49:29 2019

@author: yuta
"""

NY = list(map(int,input().split()))

def main(ny):
    n = ny[0]
    y = ny[1]
    memory = [0]*3
    count = 0
    max_count = (n+1)**2
    if y != 0:
        for i in range(n+1):
            for j in range(n+1):
                    price = 10000*i + 5000*j + 1000*(n-i-j)
                    rest = y - price
                    if rest == 0 and n-i-j >=0:
                        memory = [i,j,(n-i-j)]
                        break
                    else:
                        count += 1
        
        if count == max_count:
            memory = [-1,-1,-1]
        
    else:
        memory = [-1,-1,-1]
        
    for i in range(2):
        print(memory[i],end = " ")
    print(memory[2])
main(NY)

Solution (Python):
N, Y=[int(i) for i in 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, y = map(int, input().split())
A = [10000, 5000, 1000]

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 = [i, j, n - i - j]
            break
            
print(' '.join(map(str, ans)))

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

for c in range(N + 1):
    for b in range(N + 1):
        a = N - c - b
        if Y - 1000 * c - 5000 * b == 10000 * a and a >= 0:
            print(a, b, c)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
l = []
flag = False
for i in range(N+1):
    for j in range(N-i+1):
        if 10000 * i + 5000 * j + 1000 * (N-i-j) == Y:
            l = [i, j, N-i-j]
            flag = True
        if flag:
            break
if flag:
    print(*l)
else:
    print(-1, -1, -1)

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

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

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

print(ans[0], ans[1], ans[2])

Solution (Python):
N,Y=map(int,input().split())
x=Y//1000-N
p=0
for i in range(0,x//9+1,1):
    if (x-9*i)%4==0:
        a=i
        b=(x-9*i)//4
        c=N-a-b
        if c>=0:
            print(str(a)+' '+str(b)+' '+str(c))
            break
        else:
            p+=1
    else:
        p+=1
if p==x//9+1:
    print('-1 -1 -1')

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


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

for i in range(n+1) :
    y2 = y - i*10000
    i2 = n - i
    no = y2 - i2*1000
    if no % 4000 == 0 and 0 <= no // 4000 <= i2 :
        ans = [i, no//4000, n-i-no//4000]

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

Solution (Python):

N,Y=map(int,input().split())
d=(Y-N*1000)//1000 
if d%9==0 and d//9>=0 and N-d//9>=0:
	print(d//9,0,N-d//9)
	exit()
for n in range(N):
	if d%4==0 and d//4>=0 and N-n-d//4>=0:
		print(n,d//4,N-n-d//4)
		exit()
	d-=9
print('-1 -1 -1')

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

def helper(n,y):

    for ten in range(n,-1,-1):
        for five in range(n-ten, -1,-1):


            one = n-ten-five
            sum = 10000*ten + 5000*five + 1000*one

            if y == sum:
                return('{} {} {}'.format(ten,five,one))


    return('-1 -1 -1')

print(helper(n,y))

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):
import sys
def func():
    n,y=map(int,input().split())
    for yukichi in range(n+1):
        for ichiyou in range(n + 1 - yukichi):
          hideyo = n - yukichi - ichiyou

          if 10000*yukichi + 5000*ichiyou + 1000*hideyo == y:
            print(yukichi, ichiyou, hideyo)
            sys.exit()
    print(-1,-1,-1)

func()

Solution (Python):
mai, target = map(int, input().split(" "))
ans = 0
for i in range(mai + 1):
    for j in range(mai + 1 - i):
        k = mai - i - j
        if 1000 * i + 5000 * j + 10000 * k == target:
            print(k, j, i)
            ans = 1
            break
    if ans:
        break
else:
    print(-1, -1, -1)

Solution (Python):
a = list(map(int, input().split()))
n = a[0]
y = a[1]
check =0

for i in range(n+1):
    for j in range(n+1-i):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            if sum([i,j,n-i-j]) == n:
                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 = Y - x*10000 - y*5000
        if z < 0 or z % 1000 != 0:
            pass
        else:
            if x+y+int(z/1000) == N:
                print(x,y,int(z/1000))
                exit()

print(-1,-1,-1)

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

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

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

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

for i in range(N+1):
  for j in range(N+1):
    k = N-i-j
    if(k >= 0):
      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())

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

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):
import sys
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)
      sys.exit()

print(-1, -1, -1)

Solution (Python):
n,y=map(int,input().split())
 
def check(n,y):
    for i1 in range(n+1):
        if i1*10000>y:
            print(-1,-1,-1)
            return False
        
        for i2 in range(n+1-i1):
            if i1*10000+i2*5000+(n-i1-i2)*1000==y:
                    print(i1,i2,n-i1-i2)
                    return True
 
 
    print(-1,-1,-1)
    return False
 
check(n,y)

Solution (Python):
N, Y = [int(a) for a in input().split()]
xMax = Y//10000
x, y, z = -1, -1, -1
existsOtoshidama = False

for i in range(xMax+1):
    if existsOtoshidama == True:
        break
    for j in range(N-i+1):
        if 10*i+5*j+(N-i-j) == Y//1000:
            x, y, z = i, j, N-i-j
            existsOtoshidama = True
            break
print(x, y, z)

Solution (Python):
"""
日本でよく使われる紙幣は、10000円札、5000円札、1000円札です。
以下、「お札」とはこれらのみを指します。

青橋くんが言うには、彼が祖父から受け取ったお年玉袋には、
お札がN枚入っていて、合計でY円だったそうですが、嘘かもしれません。
このような状況がありうるか判定し、ありうる場合はお年玉袋の中身の候補を一つ見つけてください。
なお、彼の祖父は十分裕福であり、お年玉袋は十分大きかったものとします。

入力は以下の形式で標準入力から与えられる。
>>> N Y
"""

lis = input().split()
N, Y = [int(x) for x in lis]


maxA = min(Y // 10000, N)
bl = True

for A in range(maxA + 1):
    d = Y - 10000 * A
    n = N - A
    
    """ 
    この時、解くべき連立方程式
    B + C = n
    5000 * B + 1000 * C = d
    であり、これを解くと
    B = (d - 1000 * n) / 4000
    C = (5000 * n - d) / 4000
    """
    B_times_4k = d - 1000 * n
    C_times_4k = 5000 * n - d
    
    cond1 = B_times_4k * C_times_4k >= 0
    cond2 = B_times_4k % 4000 == 0

    if cond1 and cond2:
        B = B_times_4k // 4000
        C = C_times_4k // 4000
        print('{} {} {}'.format(A, B, C))
        bl = False
        break

if bl:
    print('-1 -1 -1')

Solution (Python):
"""
日本でよく使われる紙幣は、10000円札、5000円札、1000円札です。
以下、「お札」とはこれらのみを指します。

青橋くんが言うには、彼が祖父から受け取ったお年玉袋には、
お札がN枚入っていて、合計でY円だったそうですが、嘘かもしれません。
このような状況がありうるか判定し、ありうる場合はお年玉袋の中身の候補を一つ見つけてください。
なお、彼の祖父は十分裕福であり、お年玉袋は十分大きかったものとします。

入力は以下の形式で標準入力から与えられる。
>>> N Y
"""

lis = input().split()
N, Y = [int(x) for x in lis]


maxA = min(Y // 10000, N)
bl = True

for A in range(maxA + 1):
    d = Y - 10000 * A
    n = N - A
    
    """ 
    この時、解くべき連立方程式
    B + C = n
    5000 * B + 1000 * C = d
    であり、これを解くと
    B = (d - 1000 * n) / 4000
    C = (5000 * n - d) / 4000
    
    """
    B_times_4k = d - 1000 * n
    C_times_4k = 5000 * n - d
    
    cond1 = B_times_4k >= 0 and C_times_4k >= 0
    cond2 = B_times_4k % 4000 == 0 and C_times_4k % 4000 == 0

    if cond1 and cond2:
        B = B_times_4k // 4000
        C = C_times_4k // 4000
        print('{} {} {}'.format(A, B, C))
        bl = False
        break

if bl:
    print('-1 -1 -1')

Solution (Python):
lis = input().split()
N, Y = [int(x) for x in lis]


maxA = min(Y // 10000, N)
d = Y
bl = True

for A in range(maxA + 1):
    d = Y - 10000 * A
    n = N - A
    maxB = min(d // 5000, n)
    
    for B in range(maxB + 1):
        dd = d - 5000 * B
        C = n - B
                
        if 1000 * C == dd:   
            print('{} {} {}'.format(A, B, C))
            bl = False
            break
    
    if not bl:
        break

if bl:
    print('-1 -1 -1')

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

e=0
m=0
f=0
t=0

for i in range(N+1):
    for j in range(N+1-i):
        if 10000*N-5000*i-9000*j==Y:
            e=1
            m=N-i-j
            f=i
            t=j

if e==0:
    print('-1 -1 -1')
else:
    print('{} {} {}'.format(m,f,t))

Solution (Python):
n,y=map(int,input().split())
y//=1000
c=-1
d=-1
e=-1
for a in range(2001):
  for b in range(2001):
    if 9*a+4*b+n==y and n-a-b>=0:
      c=a
      d=b
      e=n-a-b
      break
print(c,d,e)

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

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

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):

import sys


def solve(N: int, Y: int):
    x, y, z = valid_nums2(N, Y)
    print("{} {} {}".format(x, y, z))
    return

def valid_nums(N, Y):
    for x in range(0, N+1):
        for y in range(0, N-x+1):
            z = N - x - y
            Y_ = 10000 * x + 5000 * y + 1000 * z
            if Y_ == Y:
                return x, y, z
    return -1, -1, -1

def valid_nums2(N, Y):
    for z in range(0, N+1):
        for y in range(0, N-z+1):
            x = N - z - y
            Y_ = 10000 * x + 5000 * y + 1000 * z
            if Y_ == Y:
                return x, y, z
    return -1, -1, -1

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)

if __name__ == '__main__':
    main()

Solution (Python):
N, Y = map(int,input().split())
for i in range(N+1):
  for j in range(N+1):
    if Y == 10000*i + 5000*j + 1000*(N-i-j) and N-i-j >= 0:
      print(i," ",j," ",N-i-j)
      break
  else:
    continue
  break
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):
        if (y-(10000*i+5000*j))//1000 == n-i-j:
                print("{} {} {}".format(i,j,n-i-j))
                break
    else:
        continue
    break

else:print("-1 -1 -1")

Solution (Python):
import sys
n,Y=map(int,raw_input().split())
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==Y:
      print x,y,z
      sys.exit(0)
print -1,-1,-1

Solution (Python):
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

temp = input_numbers()

n = temp[0]
y = temp[1]

flag = 0

for i in range(0, n + 1):
    for j in range(0, n - i + 1):
        k = n - i - j
        if(i * 10000 + j * 5000 + k * 1000 == y):
            if(flag == 0):
                output = str(i) + ' ' + str(j) + ' ' + str(k)
                print(output)
                flag = 1

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

Solution (Python):
N,Y=map(int,input().split())
flag=0
for x in range(N+1):
    for y in range(N+1):
        z=N-x-y
        if Y-10000*x-5000*y-1000*z==0 and z>=0:
            flag=1
            print(x,y,z)
            break
    else:
        continue
    break
if flag==0:
    print("-1 -1 -1")

Solution (Python):
if __name__ == '__main__':
    n, s = map(int, input().split())
    s = s/1000
    exist = False
    for x in range(n+1):
        if (s-n-9*x)>=0 and (s-n-9*x)%4==0:
            y = (s-n-9*x)/4
            z = n-(x+y)
            if 0<=z and y<=n:
                print(str(x)+' '+str(int(y))+' '+str(int(z)))
                exist = True
                break
    if not(exist):  
        print("-1 -1 -1")

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

t = int(Y/10000)
end=False
for x in range(0,t+1):
    for y in range(0,N+1):
        if x+y>N:
            break
        z = N-x-y
        num = x*10000+y*5000+z*1000
        if num==Y:
            print(str(x)+" "+str(y)+" "+str(z))
            end=True
            break
    if end:
        break
if end==False:
    print("-1 -1 -1")

Solution (Python):
N,Y=map(int,input().split())
a1=-1
a2=-1
a3=-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:
      a1=a
      a2=b
      a3=c
      break

print(a1,a2,a3)

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 10000*i + 5000*j + 1000*k == y:
            print(i, j, k)
            exit()
print("-1 -1 -1")

Solution (Python):
N,Y=map(int,input().split())
sum=0
x,y,z=0,0,0
f=False
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)
            f=True
            break
    else:
        continue
    break
if(not f):
    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(k >= 0):
      if(10000*i + 5000*j + 1000*k == Y):
        print(i, j, k)
        exit()
print(-1, -1, -1)

Solution (Python):
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,Y = IL()

if N*1000 <= Y <= N*10000:
	Y -= N*1000 - 4000
	for i in range(N+1):
		Y -= 4000
		if Y%9000 == 0 and 0 <= Y//9000 <= N and 0 <= N-Y//9000-i:
			print(Y//9000,i,N-Y//9000-i)
			exit()
print(-1,-1,-1)

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


for cnt_y in range(n + 1):
    for cnt_z in range(n + 1):
        if cnt_y + cnt_z <= n:
            cnt_x = n - (cnt_y + cnt_z)
            if cnt_x + cnt_y * 5 + cnt_z * 10 == y:
                print(cnt_z, cnt_y, cnt_x)
                exit()
else:
    print(-1, -1, -1)

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

y //= 1000
tmp = 10 * n - y
y_max = tmp // 5
z_max = tmp // 9

for cnt_y in range(n + 1):
    for cnt_z in range(n + 1):
        if cnt_y + cnt_z <= n:
            cnt_x = n - (cnt_y + cnt_z)
            if cnt_x + cnt_y * 5 + cnt_z * 10 == y:
                print(cnt_z, cnt_y, cnt_x)
                exit()
else:
    print(-1, -1, -1)

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

count=0
s='-1 -1 -1'
for i in range(n+1):
    for j in range(n+1-i):
        rest_n = n-i-j
        
        rest = y - (10000*i + 5000*j + 1000*rest_n)
        if rest==0:
            s = '{} {} {}'.format(i, j, rest_n)
print(s)

Solution (Python):
N, Y = map(int, input().split())
rx, ry, rz = -1, -1, -1

for x in range(N+1):
    for y in range(N+1-x):
            if Y - 10000*x - 5000*y - 1000*(N-x-y) == 0:
                rx, ry, rz = x, y, (N-x-y)
                break
    
print(rx, ry, rz)

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

f=0
for i in range(N+1):
    for j in range(N+1):
        if 10000*i+5000*j+1000*(N-i-j)==Y and N-i-j>=0:
            print(str(i)+(" ")+str(j)+(" ")+str(N-i-j))
            f=1
            break
    else:
        continue
    break
if f==0:
    print("-1 -1 -1")

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

A = 10000
B = 5000
C = 1000

x = -1
y = -1
z = -1

for a in range(N+1):
    for b in range(N+1):
        if a + b > N:
            continue
        else:
            total = A*a + B*b + C*(N - (a + b))
            if total == Y:
                x = a
                y = b
                z = N - (a + b)
                break

print(x, y, z)

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

N, Y = map(int, input().split())
Y //= 1000
max_a = Y // 10

for a in range(max_a + 1):
    val = (Y - N - 9 * a)
    if (val >= 0) and (val % 4) == 0:
        b = val // 4
        c = N - a - b
        if c >= 0:
            print(a, b, c)
            break
else:
    print(-1, -1, -1)

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

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

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

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

for a in range(N+1):
    if a*10000>Y:
        continue
    for b in range(N-a+1):
        c=N-a-b
        if a*10000+b*5000+1000*c==Y:
            print(a,b,c)
            exit()
print('-1 -1 -1')

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

for a in range(N+1):
    for b in range(N-a+1):
        c=N-a-b
        if a*10000+b*5000+1000*c==Y:
            print(a,b,c)
            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 10000*i + 5000*j + 1000*(n-i-j)==y:
                print(str(i)+" "+str(j)+" "+str(n-i-j))
                exit()
else:
    print("-1 -1 -1")