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

price = 0
ok = 0

for i in range(n+1):
    for j in range(n+1):
            k = n - i - j
            if k < 0:
                k = 0

            price = 10000 * i + 5000 * j + 1000 * k   
            
            if price == y and i+j+k == n and ok == 0:
                print(i, j, k)
                ok = 1
                break

    else:
        continue
    break

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

Solution (Python):


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

    flag = 0
    for i in range(n+1):
        for j in range(n-i+1):
            dum = 10000*i + 5000*j + 1000*(n-i-j)
            if dum == y:
                print("{} {} {}".format(str(i), str(j), str(n-i-j)))
                flag = 1
                break
        if 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 - 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 = [int(_) for _ in input().split()]
Z = Y // 1000 - N
for x in range(Z // 9, Z // 9 - 4, -1):
    if (Z - 9 * x) % 4 == 0:
        y = (Z - 9 * x) // 4
        z = N - x - y
        break
if x >= 0 and y >= 0 and z >= 0:
    print(x, y, z)
else:
    print(-1, -1, -1)

Solution (Python):
N,Y = map(int,input().split())
t = int(Y/1000)
swich = 0
break_swich = 0

for i in range(t+1):
    x = i
    if break_swich == 1:
        break
    for n in range(int((t-10*i)/5)+1):
        y = n
        z = t - 10*i - 5*n
        if x+y+z == N:
            print(x,y,z)
            swich = 1
            break_swich = 1

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

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

result = None
num = 10000 * N - Y
flag = False
for i in range(N+1):
    if flag:
        break
    for j in range(N-i+1):
        if 9000 * i + 5000 * j == num:
            result = str(N-i-j) + ' ' + str(j) + ' ' + str(i)
            flag = True
            break
        elif 9000 * i + 5000 * j > num:
            break

print(result if result else '-1 -1 -1')

Solution (Python):

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


target = Y // 1000 - N
ans = [-1, -1, -1]
for b in range(N + 1):
    for a in range(N + 1):
        if 9 * a + 4 * b > target: continue
        elif a + b > N: continue
        elif 9 * a + 4 * b == target:
            ans = [a, b, N - (a + b)]
            break
    if 9 * a + 4 * b == target: break

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

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):
        tmp=i*10000+j*5000+(n-i-j)*1000
        if tmp == y:
            ans = ' '.join(map(str,[i,j,(n-i-j)]))
print(ans)

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+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 math
n, y = [int(i) for i in input().split()]

for i in range(min(n, math.ceil(y/10000))+1):
    
    for j in range(min(n-i,math.ceil((y-10000*i)/1000))+1):
        
        if int((y - 10000*i - 5000*j)/1000) == n-i-j and n-i-j >= 0:
            print("{} {} {}".format(i, j, n-i-j))
            exit()
print("-1 -1 -1")

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

Solution (Python):
n,y=(int(i) for i in input().split())


flag=0
for a in range(n+1):
  if flag==0:
    for b in range(n+1):
      c=n-a-b
      if 10*a+5*b+c==y/1000 and c>=0 :
        flag=1
        print(str(a)+' '+str(b)+' '+str(c))

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

Solution (Python):
n,y=(int(i) for i in input().split())


flag=0
for a in range(n+1):
  for b in range(n+1):
    c=n-a-b
    if 10*a+5*b+c==y/1000 and c>=0 and flag==0:
      flag=1
      print(str(a)+' '+str(b)+' '+str(c))

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

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

for x in range(N+1):
    if (-N - 9 * x + Y) % 4 == 0 and (5*N - Y + 5*x) % 4 == 0:
        y = (-N - 9 * x + Y) // 4
        z = (5*N - Y + 5*x) // 4
        
        if y >= 0 and z >= 0 and x + y + z == N and 10*x + 5 * y + z == Y:
            print(x, y, z)
            break
            
else:
    print(-1, -1, -1)

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 10000 * (N - i - j) + 5000 * j + 1000 * i == Y:
            print(N - i - j , j, i)
            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):




def currency(target_num, target_price, combi, cur=[10000, 5000, 1000], cur_num=0, subttl=0):
    if cur_num >= len(cur):
        return False

    unit = cur[cur_num]  
    max_num = target_num-sum(combi)  

    if cur_num == len(cur) - 1:  
        total = subttl + (max_num * unit)
        if total == target_price:
            combi[cur_num] = max_num
            return True
        else:
            return False

    if subttl + (max_num * unit) < target_price:  
        return False
    for cx in range(max_num + 1):
        total = subttl + (unit*cx)  
        if total > target_price:  
            combi[cur_num] = 0
            return False

        combi[cur_num] = cx

        if total == target_price:  
            if sum(combi) == target_num:  
                return True
        
        if currency(target_num, target_price, combi, cur, cur_num + 1, total):
            return True



n, y = map(int, input().split())
combi = [0, 0, 0]
resolve = currency(n, y, combi)
if not resolve:
    combi = [-1, -1, -1]
print(combi[0], combi[1], combi[2])

Solution (Python):

N,Y = map(int, input().split())
 
for i in range(N+1):
	for j in range(0, 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 = list(map(int,input().split()))
flag=False
for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i+5000*j+1000*(N-i-j)==Y:
            flag=True
            break
    if flag:
        break
if flag:
    print(str(i)+" "+str(j)+" "+str(N-i-j))
else:
    print("-1 -1 -1")

Solution (Python):
n,y=[int(i) for i in input().split()]
A=-1
B=-1
C=-1
for a in range(n+1):
  for b in range(n-a+1):
      Y=1000*a+5000*b+10000*(n-a-b)
      if Y==y:
        c=n-a-b
        A=c
        B=b
        C=a
        break
print(A,B,C)

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

Solution (Python):
N, M = list(map(int, input().split()))
res = [-1,-1,-1]

for i in range(0,N+1):
    for j in range(0,N+1):
        if i + j > N:
            continue
        if 10000*i+5000*j+1000*(N-i-j) == M:
            res = [i,j,N-i-j]
            break
            
print(" ".join(list(map(str, res))))

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

Solution (Python):
n, y = map(int, input().split(" "))
 
for i in range(0, n+1):
	for j in range(0, 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(" "))

for i in range(0, n+1):
	for j in range(0, 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

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

print("-1 -1 -1")

Solution (Python):
N,Y=map(int,input().split())
Flag=0
a=0
b=0
while a<=N:
  while b<=N-a:
    c=N-a-b
    if 10000*a+5000*b+1000*c==Y:
      Flag=1
      break
    b+=1
  if Flag==1:
    break
  a+=1
  b=0
if Flag==1:
  print(a,b,c)
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 10000*i+5000*j==y-1000*(n-i-j):
            print(i,j,n-i-j)
            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(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 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
            if i >= 0 and j >= 0 and N >= i + j:
                print(i, j, N - i - j)
                quit()

else:
    print(-1, -1, -1)

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

gosen=-1
for itiman in range(n+1):
    tmp=y-itiman*10**4
    if(tmp<0):
        break
    tmp-=1000*(n-itiman)
    if(tmp%4000==0 and 0<=tmp//4000 <=n-itiman):
        gosen=tmp//4000
        break


if(gosen==-1):
    print("-1 -1 -1")
else:
    print("{} {} {}".format(itiman,gosen,n-itiman-gosen))

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

    for x_10000 in range(n+1):
        for y_5000 in range(n+1):
            z_1000 = n - x_10000 - y_5000

            if x_10000 * 10000 + y_5000 * 5000 + z_1000 * 1000 == y\
                    and z_1000 >= 0:

                return "{} {} {}".format(x_10000, y_5000, z_1000)

    return "-1 -1 -1"


if __name__ == '__main__':
    print(otoshidama())

Solution (Python):
n, yen = map(int, input().split())
man = -1
gosen = -1
sen = -1

for i in range(n + 1):
    for j in range(n - i + 1):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == yen and (n - i - j) >= 0:
            man = i
            gosen = j
            sen = n - i - j

print(man, gosen, sen)

Solution (Python):
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)

Solution (Python):
N, Y= map(int, input().split())
s=-1
g=-1
ic=-1

fl=False
for i in range(N+1):
    for j in range(N+1-i):
        k=N-i-j

        if (1000*i+5000*j+10000*k)==Y:
            fl=True
            s=i
            g=j
            ic=k
            break
        if fl:
            break
    if fl:
        break
print(ic,g,s)

Solution (Python):
def solve(N, Y):
    r = [5000 for _ in range(N)]
    for i in range(N + 1):
        s = sum(r)
        if s == Y:
            return (
            len([d for d in r if d == 10000]), len([d for d in r if d == 5000]), len([d for d in r if d == 1000]))
        elif s < Y and i < N:
            r[i] = 10000
        elif s > Y and i < N:
            r[i] = 1000
    return (-1, -1, -1)


if __name__ == "__main__":
    N, Y = tuple(map(int, input().split(" ")))
    print(" ".join(map(str, list(solve(N, Y)))))

Solution (Python):
def a10000(y, k):
    for i in range(k + 1):
        if i * 10000 > y:
            break
        res = a5000(y - i * 10000, k - i)
        if res[0]:
            return i, res[1], res[2]
    return -1, -1, -1


def a5000(y, k):
    if k == 0:
        return y == 0, 0, 0
    for i in range(k + 1):
        if i * 5000 > y:
            break
        res = a1000(y - i * 5000, k - i)
        if res[0]:
            return True, i, res[1]
    return False, -1, -1

def a1000(y, k):
    return k * 1000 == y, k

N, Y = map(int, input().split())
ans = a10000(Y, N)
print(ans[0], ans[1], ans[2])

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

y = Y // 1000

flag = False
for i in range(N+1):
    yi = y - 10 * i
    if yi < 0: pass
    for j in range(N+1):
        k = N - i - j
        yjk = yi - 5 * j - k
        if k < 0: break
        if yjk == 0: 
            flag = True
            break
    if flag: break

if flag: print('{} {} {}'.format(i,j,k))
else: print('-1 -1 -1')

Solution (Python):

iN,iY = [int(_) for _ in input().split()]
iY //= 1000








iD = iY -iN
for i10 in range(iD//9 + 1):
    iD2 = iD - 9*i10
    if iD2 % 4 :
        continue
    else:
        i5 = iD2 // 4
        if iN-i10-i5 >= 0:
            print(i10,i5,iN-i10-i5)
            exit()
print(-1,-1,-1)

Solution (Python):

iN,iY = [int(_) for _ in input().split()]
iY //= 1000

iM10 = iY // 10
iM5 = iY // 5
iM1 = iY
for i in range(iM10+1):
    for j in range(min(iN-i,(iY-i*10)//5)+1):
        k = iN -i -j
        if iY == i*10 + j*5 +k:
            print(i,j,k)
            exit()
print(-1,-1,-1)

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

print('-1 -1 -1')

Solution (Python):
n,y=map(int,input().split())
y=y/1000
b=y//10
D=[]
for i in range(int(b+1)):
	for z in range(int(((y-10*i)//5)+1)):
		if 4*z+9*i==y-n and n-z-i>=0:
			print(str(i)+" "+str(z)+" "+str(n-z-i))		
			exit()
            
		
if len(D)==0:
	print("-1 -1 -1")
else:
	print(D[0])

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

a1 = k // 10000
k %= 10000
a2 = k // 5000
k %= 5000
a3 = k // 1000
for i in range(a1 + 1):
    for j in range(a2 + i * 2 + 1):
        if (a1 - i) +(a2 + i * 2 - j) + (a3 + j * 5) == n:
            print(str(a1 - i) + ' ' + str(a2 + i * 2 - j) + ' ' + str(a3 + j * 5))
            sys.exit(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):
        m = i * 10000 + j * 5000 + (n - i - j) * 1000
        if m == y:
            print(i, j, (n - i - j))
            exit()
print(-1, -1, -1)

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

flag = 0
for x in range(Y//10000+1) :
    if flag != 0 :
        break
    else :
        for y in range(Y//5000+1) :
            if flag != 0 :
                break
            else :
                z = N-x-y
                if z >= 0 and (10000*x+5000*y+1000*z) == Y :
                    ans = [x,y,z]
                    flag = 1
if flag == 0 :
    print(-1,-1,-1)
else :
    print(ans[0],ans[1],ans[2])

Solution (Python):
import sys

num = raw_input().strip().split()
N = int(num[0])
Y = int(num[1])
for x in range(N + 1):
    for y in range(N + 1 - x):
        if 0 <= N - x - y  and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            print(str(x)+ " "+ str(y) + " " + str(N-x-y))
            sys.exit()

print("-1 -1 -1")

Solution (Python):
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for a in range(n + 1):
    for b in range(n-a+1):
        
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(" ".join([str(a), str(b), str(c)]))
            sys.exit()

print("-1 -1 -1")

Solution (Python):
N, Y = map(int, raw_input().split())
ok = False
for x in range(N+1):
  for y in range(N+1):
    z = N-x-y
    if z >= 0:
      if 10000 * x + 5000 * y + 1000 * z == Y:
        print x,y,z
        ok = True
    if ok:
      break
  if ok:
    break
if not ok:
  print "-1 -1 -1"

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

for x in range(N+1):
    y = (10*N-9*x-Y)//5
    z = ((-5*N)+Y+4*x)//5
    
    if y >= 0 and z >= 0 and x+y+z == N and x+5*y+10*z == Y:
        print(z, y, x)
        break
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 (10000*i)+(5000*j)+(1000*k)==y:
            print("{} {} {}".format(i,j,k))
            sys.exit()
print("-1 -1 -1")

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

judge = 0

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


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

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
modYN = (Y - N)%4

for i in range(N//4 + 1):
    a = 4 * i + modYN
    b = (Y - N - 9 * a) // 4
    c = N - a - b
    if 0 <= b and 0 <= c:
        print(a, b, c)
        break
else:
    print(-1, -1, -1)

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

if len(ans) == 0:
    print(-1, -1, -1)
else:
    print(ans[0][0], ans[0][1],ans[0][2])

Solution (Python):
def solve(N, Y):
    for x in range(N + 1):
        for y in range(N - x + 1):
            z = N - x - y
            if 10000 * x + 5000 * y + 1000 * z == Y:
                return x, y, z
    return -1, -1, -1


N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))

Solution (Python):
def solve(N, Y):
    for x in range(N + 1):
        for y in range(0, N - x + 1):
            z = N - x - y
            if z < 0:
                continue
            elif 10000 * x + 5000 * y + 1000 * z == Y:
                return x, y, z
    return -1, -1, -1


N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))

Solution (Python):
def solve(N, Y):
    for x in range(N+1):
        for y in range(N+1):
            z = N - x - y
            if z < 0:
                continue
            elif 10000 * x + 5000 * y + 1000 * z == Y:
                return x, y, z
    return -1, -1, -1

N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))

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

A = -1
B = -1
C = -1
for a in range(n+1):
    for b in range(n+1):
        c = n-a-b
        tem = 10000*a + 5000*b + 1000*c
        if (tem == y) and (c>=0):
            A = a
            B = b
            C = c
            break

print(A, B, C)

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

Solution (Python):
def Amount(i, j, k):
    return 10000*i + 5000*j + 1000*k

N = input().split()
N = [int(n) for n in N]
b_flag = False
flag = False
for i in range(N[0]+1):
    for j in range(N[0]+1-i):
        k = N[0]-i-j
        if(Amount(i, j, k) == N[1]):
            print(i, j, k)
            flag = True
            b_flag = True
            break
    if(b_flag):
        break

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

Solution (Python):

n,y = list(map(int, input().split(' ')));
match = False

try:
    for i in range(n, -1, -1):
        for j in range(n, -1, -1):
            if ( i + j > n ):
                continue
            k = n - i - j
            total = 10000 * i + 5000 * j + 1000 * k;
            if (total > 10000 * y ):
                break
            if (total == y):
                print( i,j,k )
                match = True
                raise Exception
except Exception:
    pass

if (not match): 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 Y == 10000 * i + 5000 * j + 1000 * (N-i-j):
            print(i,j,N-i-j)
            exit()

print(-1,-1,-1)

Solution (Python):


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




result = False

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

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

Solution (Python):



import sys
n, y = (int(_) for _ in input().split())

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

Solution (Python):
N,Y = map(int,input().split())
flag = 0
for a in reversed(range(Y//10000+1)) :
    if flag == 0 and 10000*a <= Y :
        for b in reversed(range(N-a+1)) :
            if flag == 0 and 10000*a+5000*b+1000*(N-a-b) == Y :
                print(a,b,N-a-b)
                flag = 1
                break
if flag == 0 :
    print(-1,-1,-1)

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

Solution (Python):
N,Y = map(int,input().split())
for x in range(N+1):
    if x*10000 > Y: break
    for y in range(N-x+1):
        if x*10000 + y*5000 > Y: break
        z = N-x-y
        if z < 0: break
        if z * 1000 == Y - x*10000 - y*5000:
            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-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
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,y = li()

yuki_max = y // 10000
ichi_max = y // 5000

ans_y = -1
ans_i = -1
ans_h = -1

for yukichi in range(yuki_max+1):
    for ichiyo in range(ichi_max+1):
        hideyo = (y - 10000*yukichi - 5000*ichiyo) // 1000
        if hideyo < 0:
            continue
        
        if yukichi + ichiyo + hideyo == n:
            ans_y = yukichi
            ans_i = ichiyo
            ans_h = hideyo
            break

print(ans_y, ans_i, ans_h)

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

ans = '-1 -1 -1'
for n in range(N+1):
	for m in range(N-n+1):
		l = N - n - m
		sum_ot = n * 10000 + m * 5000 + l * 1000
		if Y == sum_ot:
			ans = str(n)+ ' ' + str(m) + ' ' + str(l)
			break
print(ans)

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 Y == x*10000+y*5000+z*1000:
            print(x, y, z)
            exit()

print(-1, -1, -1)

Solution (Python):
n, y = map(int, input().split())
for i in range(n + 1):
    if 10000*i > y:
        print("-1 -1 -1")
        exit()
    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):
    if 10000*i > y:
        break
    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):

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

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

for i in range(N + 1):
    for j in range(0, N - i + 1):
        if i + j <= N:
            tmp = 10000 * i + 5000 * j + 1000 * (N - i - j)
            if tmp == Y:
                print(str(i) + " " + str(j) + " " + str(N - i - j))
                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):
        if N - x - y >= 0 and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            res = (x, y, N - x - y)
print(res[0], res[1], res[2])

Solution (Python):
n, m = map(int, raw_input().split())


ans_x, ans_y, ans_z = -1, -1, -1
for x in range(0, n+1):
  for y in range(0, n+1-x):
    
    sum = x*10000 + y*5000 + (n-x-y)*1000
    if sum == m:
      ans_x, ans_y, ans_z = x, y, n-x-y
      break
  else:
    continue
  break
print ans_x, ans_y, ans_z


"""
for x in range(0, n+1):
  for y in range(0, n+1-x):
    
    sum = x*10000 + y*5000 + (n-x-y)*1000
    if sum == m:
      ans_x, ans_y, ans_z = x, y, n-x-y
      break
    else:
    continue
  break
"""

Solution (Python):
def answer(in0):

    _in = in0.split(' ')
    N = int(_in[0])
    Y = int(_in[1])

    a, b, c = 0, 0, 0

    for a in range(N + 1):
        for b in range(N + 1):
            c = N - (a + b)
            if c >= 0 and (10000 * a) + (5000 * b) + (1000 * c) == Y:
                print('{} {} {}'.format(a, b, c))
                return

    print("-1 -1 -1")


answer(input())

Solution (Python):
n,y = map(int,input().split())
y+=10000
a=-1
b=0

for i in range(y//10000+1):
	b = 0
	a += 1
	y -= 10000
	for j in range(y//5000+1):
		y -=j*5000
		if y==1000*(n-a-b) and n-a-b>-1:
			print(a,b,n-a-b)
			break
		b +=1
		y +=j*5000
		
	else:
		continue
	break
else:
	print(-1,-1,-1)

Solution (Python):

import sys
N, Cost = map(int, input().split())

a_out, b_out = -1, -1

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

print('-1 -1 -1')

Solution (Python):

import sys
N, Cost = map(int, input().split())

a_out, b_out = -1, -1

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

print('-1 -1 -1')

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

Solution (Python):
[n, Y] = list(map(int, input().split()))
x, y, z = -1, -1, -1
for xx in range(n+1):
    for yy in range(n+1-xx):
        zz = n - xx - yy
        if Y == 10000 * xx + 5000 * yy + 1000 * zz:
            x, y, z = xx, yy, zz
            break
print(x, y, z)

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 = list(map(int, input().split()))

xx, yy, zz = -1,-1,-1

flag = False
for x in range(min(Y//10000, N)+1):
    for y in range(min((Y-x*10000)//5000, N)+1):
        z = N-x-y
        if x*10000+y*5000+z*1000 == Y:
            xx = x
            yy = y
            zz = z
            flag = True
            break
    if flag:
        break
print(xx, yy, zz)

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 y == i*10000 + j*5000 + (n-i-j)*1000:
            print('{} {} {}'.format(i, j, n-i-j))
            break
    else:
        continue
    break
else:
    print('-1 -1 -1')