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

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

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

if n*10000 == y:
  print(n, 0, 0)
elif n*10000 < y:
  print(-1, -1, -1)
else:
  flag = 0
  
  for a in range(y//10000+1):
    b_c = n-a
    for b in range(b_c+1):
      c = b_c-b
      if y == a*10000 + b*5000 + c*1000:
        print(a, b, c)
        flag = 1
        break
    if flag == 1:
      break
  if flag == 0:
    print(-1, -1, -1)

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

flag=0
total = 0

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

        total=10000*i+5000*j+1000*k
        if total==y:
            print(i,j,k)
            flag=1
            break 
    if flag == 1:
        break
if flag == 0:
    print('-1 -1 -1')

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

flag=0
total = 0

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

        total=10000*i+5000*j+1000*k
        if total==y:
            print(i,j,k)
            flag=1
            break 
    if flag == 1:
        break
if flag == 0:
    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-i+1):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            print(i, j, N-i-j)
            flag = True
            break
    if flag == True:
        break

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

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

for A in range(N+1):
    for B in range(N+1):
        C = N - A - B
        if C<0:
            break
        total = 10 * A + 5 * B + C
        if total == Y:
            print(A, B, C)
            flag = 1
            break
    if flag == 1:
        break

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

Solution (Python):
import sys
 
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
 
n, y = inm()
not_discov = (-1, -1 , -1)
def solve():
    if y % 1000 != 0:
        print("-1 -1 -1")
    y_n = y // 1000
    for c in range(n + 1):
        b_tmp = y_n - 9 * c - n
        if b_tmp < 0 or b_tmp > 4 * n or b_tmp % 4 != 0:
            continue
        b = b_tmp // 4
        a = n - b - c
        if a < 0 or a > n:
            continue
        return c, b, a
    return not_discov

print(*solve())

Solution (Python):
import sys
 
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
 
n, y = inm()

discov_flg = False

for a in range(0, n + 1):
    for b in range(0, n + 1 - a):
        c = n - a - b
        total = 10000 * a + 5000 * b + 1000 * c
        if y == total:
            print(f"{a} {b} {c}")
            discov_flg = True
            break
    if discov_flg:
        break
        
if not(discov_flg):
    print("-1 -1 -1")

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

for a in range(0, n + 1):
    for b in range(0, n + 1 - a):
        c = n - a - b
        total = 10000 * a + 5000 * b + 1000 * c
        if y == total:
            print(f"{a} {b} {c}")
            discov_flg = True
            break
    if discov_flg:
        break
        
if not(discov_flg):
    print("-1 -1 -1")

Solution (Python):
N,X = map(int,input().split())
l = []
bo = 0
for a in range(N+1):
    for b in range(N-a+1):
        if a*10000 + b*5000 + (N-a-b)*1000 == X:
            T = [a,b,N-a-b]
            bo+=1
            break


if bo==0:
    print('-1 -1 -1')
else:print(*T,sep=' ')

Solution (Python):
din = list(map(int,input().split()))
NN = din[0]
YY = din[1]

found = 0
for n10000 in range(NN+1):
    if found == 1: break
    n_rem = NN - n10000
    n5000 = 0
    while ((n5000<=n_rem) and (found == 0)):
        n1000 = NN-n10000-n5000
        if YY - n10000*10000 - n5000*5000 - n1000*1000 == 0:
            line = "{} {} {}".format(n10000,n5000,n1000)
            print(line)
            found = 1;
        else:
            n5000 += 1
if found == 0:
    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 = max(0,n-i-j)
        if 10000*i + 5000*j + 1000*k == y:
            print(i,j,k)
            exit(0)

print(-1,-1,-1)

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):
        k = n - i - j
        if (i*1000 + j*5000 + k*10000) == y:
            ans = str(k) + ' ' + str(j) + ' ' + str(i)
            break
print(ans)

Solution (Python):
n, y = map(int, input().split())
tf = False
ans = ""
for i in range(n+1):
  a = y - i * 10000
  for j in range(n-i+1):
    b = a - j * 5000
    tf = True if b == 1000 * (n - i - j) else False
    if tf:
      print('{0} {1} {2}'.format(i, j, n-i-j))
      break
  if tf:
    break
if not(tf):
  print('-1 -1 -1')

Solution (Python):
from sys import stdin
import sys

n, y = [int(i) for i in stdin.readline().rstrip().split()]

for p in range(2001):
    for q in range(n-p+1):
        r = n-p-q
        if 10000*p+5000*q+1000*r == y:
            print (str(p),str(q),str(r))
            sys.exit()

print ("-1 -1 -1")

Solution (Python):
BILLS = [10000, 5000, 1000]


def calc_price(counts):
    return sum([bill * count for bill, count in zip(BILLS, counts)])


def main(n, y):
    for c1 in range(n + 1):
        for c2 in range(0, n - c1 + 1):
            counts = [c1, c2, n - c1 - c2]
            if calc_price(counts) == y:
                print(' '.join([str(c) for c in counts]))
                return
    print('-1 -1 -1')


if __name__ == "__main__":
    n, y = [int(x) for x in input().split()]
    main(n, y)

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

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

ans = [-1] * 3
i = 0

while i <= n:
    j = 0
    while j <= n-i:
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            ans[0] = i
            ans[1] = j
            ans[2] = n-i-j
        j += 1
    i += 1

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

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):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,y = I()
if n*10000 < y or n*1000 > y:
    print("-1 -1 -1")
    sys.exit()

a = -1
b = -1
c = -1

for i in range(0,n+1):
    for j in range(0,n+1):
        k = n-i-j
        if k < 0:
            continue
        if 1000*i+5000*j+10000*k == y:
            a = k
            b = j
            c = i
            break

print("{} {} {}".format(a,b,c))

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

if not 1000*n <= X <= 10000*n:
  print(-1,-1,-1)
  sys.exit()
  
for x in range(n+1):
  for y in range(n+1):
    z = n - x - y
    if z < 0:
      break
    if 1000*z + 5000*y + 10000*x == X:
      print(x,y,z)
      sys.exit()
print(-1,-1,-1)

Solution (Python):
N,Y=map(int,input().split())
a=0
b=Y//10000
c=Y//5000
for i in range(0,b+2):
    for j in range(0,c+2):
        if i+j>N:
            continue
        else:
            if (i*10000)+(5000*j)+(1000*(N-i-j))==Y:
                print(i,j,N-(i+j))
                exit()

print(-1,-1,-1)

Solution (Python):
if __name__ == '__main__':
	N, Y = map(int, input().split())

	c = 0
	for x in range(N+1):
		if c == 0:
			if 10000 * x <= Y:
				NN = N-x
				YY = Y-10000*x
				for y in range(NN+1):
					if 5000 * y <= YY:
						NNN = NN - y
						YYY = YY - 5000*y
						if 1000 * NNN == YYY:
							ans = [x,y,NNN]
							c = 1

	if c == 1:
		print('{} {} {}'.format(ans[0],ans[1],ans[2]))
	else:
		print('{} {} {}'.format(-1,-1,-1))

Solution (Python):
import sys
N,Y=map(int,input().split())
ans=0
for x in range (N+1):
    for y in range(N+1-x):
        if 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
def input(): return sys.stdin.readline().strip()


def main():
    N, Y = map(int, input().split())
    Y //= 1000
    for a in range(Y, -1, -1):
        for b in range(Y // 5 - 2 * a, -1, -1):
            c = Y - 10 * a - 5 * b
            if 0 <= c and a + b + c == N:
                print("{} {} {}".format(a, b, c))
                return
    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 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())
Y//=1000

F=(-1,-1,-1)
for a in range(0,N+1):
    for b in range(0,N-a+1):
        c=N-(a+b)
        if a+5*b+10*c==Y:
            F=c,b,a

print(" ".join(map(str,F)))

Solution (Python):
A, B = map(int, input().split())

for i in range(A+1):
    for j in range(A+1-i):
        k = A-i-j
        if 10000*i + 5000*j + 1000*k == B:
            print(i, j, k, flush=True)
            exit()

print(-1, -1, -1)

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

flag = "Notyet"
for i in range(N+1):
  for j in range(N+1-i):
    noguchi = i
    higuchi = j
    yukichi = N - i - j
    
    if noguchi * 1000 + higuchi * 5000 + yukichi * 10000 == Y:
      print(yukichi,higuchi,noguchi)
      flag = "Complete"
      sys.exit()
      
if flag == "Notyet":
  print("-1 -1 -1")

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

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

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

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

if 10_000*N < Y:
  print(-1,-1,-1)
  sys.exit()
elif 1_000*N > Y:
  print(-1,-1,-1)
  sys.exit()
else:
  Y-=1_000*N
  for i in range(2001):
    for j in range(2000-i+1):
      if 4_000*i+9_000*j>Y:
        break
      if i+j<=N and 4_000*i+9_000*j==Y:
        print(j,i,N-i-j)
        sys.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):
            if (n-i-j)*10000+j*5000+i*1000==y:
                print(n-i-j, j, i)
                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 10000*a + 5000*b + 1000*c == Y:
            print(a, b, c)
            exit()
else:
    print(-1, -1, -1)

Solution (Python):
n, y = map(int, input().split(" "))
c10000 = -1
c5000 = -1
c1000 = -1

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:
            c10000 = i
            c5000 = j
            c1000 = n - i - j

print(str(c10000) + ' ' + str(c5000) + ' ' + str(c1000))

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

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

Solution (Python):
import math

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

max_x = 2001
max_y = 2001

k = 0
flag = 0
ans = []
for i in range(max_x):
    if flag == 1:
        break
    for j in range(max_y):
        rest = Y - (i * 10000 + j * 5000)
        if rest < 0:
            break
        else:
            k = N - i - j
            if rest//1000 == k and k + i + j <= 2000:
                flag = 1
                ans = [i,j,k]
                break
        

if flag == 1:
    print(" ".join(map(str, ans)))
else:
    print("-1 -1 -1")

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

for x in range(Y // 10000 + 1): 
    for y in range((Y - 10000 * x) // 5000 + 1): 
        if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
            print(x, y, N - x - y)
            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 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())
for x in range(N+1):
    for y in range(N - x + 1):
        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 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()]

for i in range(N+1):
    p = (Y - 9000 * i - 1000 * N) // 4000
    q = N - i - p
    if p < 0 or q < 0:
        continue
    if 10000 * i + 5000 * p + 1000 * q == Y:
        print(i, p, q)
        exit(0)
print(-1, -1, -1)

Solution (Python):
N,Y = map(int,input().split())
a,b,c = N+1,N+1,N+1
count = 0

if Y // N == 10000:
    print(N,0,0)
elif Y // N == 5000:
    print(0,N,0)
elif Y // N == 1000:
    print(0,0,N)
else:
    stop = False
    for i in range(a):
        for j in range(b-i):
            c -= i+j
            if i+j+c != N:
                pass
            else:
                dama = 10000*i + 5000*j + 1000*c
                if dama == Y:
                    print(i,j,c)
                    count += 1
                    exit()
            c = N
        b = N+1
    if count == 0:
        print(-1,-1,-1)

Solution (Python):
N,Y = map(int,input().split())
a,b,c = N+1,N+1,N+1
dama = 0
count = 0

if Y // N == 10000:
    print(N,0,0)
elif Y // N == 5000:
    print(0,N,0)
elif Y // N == 1000:
    print(0,0,N)
else:
    stop = False
    for i in range(a):
        if stop:
            break
        b -= i
        for j in range(b):
            if stop:
                break
            c -= i+j
            if i+j+c != N:
                pass
            else:
                dama = 10000*i + 5000*j + 1000*c
                if dama == Y:
                    print(i,j,c)
                    count += 1
                    stop = True
                    break
            c = N
        b = N+1
    if count == 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 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):
    if i*10000>y:
        break
    for j in range(0,n+1-i):
        if i*10000+j*5000>y:
            break
        k=n-i-j
        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())
c = 0
for i in range(0,N+1):
    for j in range(0,N+1):
        c = ((Y-(10000*i+5000*j))/1000)
        if c.is_integer and c >= 0 and i+j+c == N:
            d = int(c)
            print(i,j,d)
            exit()
print(-1,-1,-1)

Solution (Python):
a,b=map(int,input().split())
c=-1
d=-1
e=-1
x=b//10000
for i in range(0,x+1,1):
  y=(b-10000*i)//5000
  for j in range(0,y+1,1):
    k=(b-10000*i-5000*j)//1000
    if i+j+k==a:
      c=i
      d=j
      e=k
print(c,d,e)

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

print(-1,-1,-1,sep=" ")

Solution (Python):

def main():
    N, Y = map(int, input().split())
    now = 0
    check = 0
    for i in range(0, N + 1):
        for j in range(0, N+1-i):
            k = N - i - j
            sum = 10000*i + 5000*j + 1000*k
            
            if sum == Y:
                print(str(i) + ' ' + str(j) + ' ' + str(k))
                return
            elif sum > Y:
                break
    print('-1 -1 -1')
    return
                
    
if __name__ == '__main__':
    main()

Solution (Python):
N, Y = map(int, input().split())
flg = False
for i in range(N+1):
    for j in range(N+1):
        if N - i - j < 0:
            continue
        if (i*10000 + j*5000 + (N-i-j)*1000) == Y:
            flg = True
            break
    if flg:
        break
if flg:
    print(i, j, N-i-j)
else:
    print("-1 -1 -1")

Solution (Python):
N, Y = list(map(int,input().split()))
def s():
    for i in range(N + 1):
        for j in range(N + 1):
            k = N - i - j
            if k >= 0 and 1000 * i + 5000 * j + 10000 * k  == Y:  print(k, j, i); return
    print(-1, -1, -1)
s()

Solution (Python):
n, y = map(int, input().split())
ans = False
for i in range(n + 1):
    if ans:
        break
    for j in range(n + 1 - i):
        if y - i*10000 - j*5000 == (n - i - j)*1000:
            print(i, j, n - i - j)
            ans = True
            break
if not ans:
    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 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())
for i in range(n+1):
  for g in range(n-i+1):
    s = n-i-g
    if 10000*i + 5000*g + 1000*s == y:
      print(i, g, s)
      exit()
print('-1 -1 -1')

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

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial





def solve():
    n, y = [int(x) for x in input().split()]
    A = 10000
    B = 5000
    C = 1000
    a = y // A
    y %= A
    b = y // B
    y %= B
    c = y // C
    total = a + b + c
    while total < n:
        if n - total > 3 and b:
            b -= 1
            c += 5
            total += 4
        elif a:
            a -= 1
            b += 2
            total += 1
        else:
            break

    if total != n:
        print(-1, -1, -1)
    else:
        print(a, b, c)



t = 1

for case in range(1,t+1):
    ans = solve()


"""



"""

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

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

for i in range(n+1):
    for j in range(n-i+1):
        c = n - i - j
        total = 10000*i + 5000*j + 1000*c
        if total == s:
            x, y, z = i, j, c

print(x , y , z)

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

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

exist = False
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:
            exist = True
            print(x, y, z)
            break
    else:
        continue
    break

if not exist: print('-1 -1 -1')

Solution (Python):
n,y = map(int,input().split())
f = False
for a in range(n+1):
    for b in range(n+1):
        c = n-(a+b)
        if 10000*a+5000*b+1000*c == y and a+b+c == n and c>= 0:
            f = True
            print(a,b,c)
    if f == True:
        break
if f == False:
    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 10000*x + 5000*y +1000*z == Y and 0<=z<=2000:
      print('{} {} {}' .format(x, y, z))
      exit()

print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
result = [-1 , -1, -1]
for m in range(N + 1):
    
    for f in range(N + 1 - m):
        
        s = N - m - f
        
        if 10000*m + 5000*f + 1000*s == Y:
            result = [m, f, s]
            
            break
            
print(f'{result[0]} {result[1]} {result[2]}')

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

for i in range(N+1):
    for j in range(N - i + 1):
        left = Y - 10000*i - 5000*j
        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()))

ans = 0
for y in range(N +1):
    for w in range(N +1):
        if y*10000+w*5000+(N-y-w)*1000 == Y and N-y-w >= 0:
            ans = str(y)+" "+str(w)+" "+str(N-y-w)

if ans == 0:
    print(-1, -1, -1)
else:
    print(ans)

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 9*i+4*j==y//1000-n and k>=0:
            print(i,j,k)
            exit()
print(-1,-1,-1)

Solution (Python):

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

result = [-1, -1, -1]
for yukichi in range(n+1):
    for nitobe in range(n+1 - yukichi):
        natsume = n - yukichi - nitobe
        all = yukichi + nitobe + natsume
        total = yukichi*10000 + nitobe*5000 + natsume*1000
        if total == target:
            result = [yukichi, nitobe, natsume]

print(' '.join([str(n) for n in result]))

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

ans = '-1 -1 -1'
for x in range(N+1):
    if 10000 * x > Y:
        break
    
    y = (Y//1000-9*x-N)/4
    z = N-x-y
    
    if y.is_integer()==True and z.is_integer():
        if x >=0 and y>=0 and z>=0: 
            ans=' '.join(map(str,[x,int(y),int(z)]))
            break
        
print(ans)

Solution (Python):

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


x,y,z=-1,-1,-1
for i in range(n+1):
    for j in range(n+1):
        k=max(0,n-(i+j))
        if i+j+k==n:
            if i*1000+j*5000+k*10000 == Y:
                x,y,z=k,j,i
                
print("{0} {1} {2}".format(x,y,z))

Solution (Python):

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


x,y,z=-1,-1,-1
for i in range(n+1):
    for j in range(n+1):
        k=max(0,n-(i+j))
        if i+j+k==n:
            if i*1000+j*5000+k*10000 == Y:
                x,y,z=k,j,i
                
print("{0} {1} {2}".format(x,y,z))

Solution (Python):
n, y = map(int, input().split())
ans=[]
flag=True
for i in range(n+1):
    for j in range(n+1):
        if i+j<=n:
            k=n-i-j
        else:
            k=0
        if 10000*i+5000*j+1000*k==y and i+j+k==n:
            ans+=i,j,k
            flag=False
            break
    if flag==False:
        break

if len(ans)==0:
    ans+=-1,-1,-1

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

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

satu = [1000,5000,10000]

sen = [1000 * i for i in range(n+1)]
gsen = [5000 * i for i in range(n+1)]
man = [10000 * i for i in range(n+1)]


for i in range(n+1):
    for j in range(n+1-i):
        if man[i]+ gsen[j] + sen[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):
def ans(N, Y):
    for m in range(N + 1):
        for g in range(N + 1 - m):
            s = N - m - g
            sum = m * 10000 + g * 5000 + s * 1000
            if sum == Y:
                return m, g, s
    return -1, -1, -1

def read():
    N, Y = [int(a) for a in input().split(' ')]
    return N, Y

def write(a):
    print(a[0], a[1], a[2])

if __name__ == '__main__':
    N, Y = read()
    write(ans(N, Y))

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

man = 10000
gosen = 5000
sen = 1000
flag = False

x, y, z = 0, 0, 0

for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if (z >= 0) and (Y == man*x + gosen*y + sen*z):
            flag = True
            break
    if flag == True:
        break

if flag == True:
    print(str(x) + " " + str(y) + " " + str(z))
else:
    print("-1 -1 -1")

Solution (Python):
from sys import exit 
N,Y = map(int,input().split())

for i in range(N+1):
    for j in range(N-i+1):
        Sum = 10000*i + 5000*j + 1000*(N-i-j)
        if Sum == Y:
            print(str(i)+' '+str(j)+' '+str(N-i-j))
            exit(0)

print(str(-1)+' '+str(-1)+' '+str(-1))

Solution (Python):
from sys import exit
Y, N = map(int, input().split())
N /= 1000
N -= Y
if N == 0:
  print(0, 0, Y)
elif N < 0 or N - 9 * Y > 0:
  print(-1, -1, -1)
else:
  for n in range(Y + 1):
    if N - 9 * n < 0:
      print(-1, -1, -1)
      exit()
    if N - 9 * n == 0:
      print(n, 0, Y - n)
      exit()
    for m in range(0, Y - n + 1):
      if N - 9 * n - 4 * m == 0:
        print(n, m, Y - n - m)
        exit()
      if N - 9 * n - 4 * m < 0:
        break
  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 == 1000*i + 5000*j + 10000*(N - j - i):
      print(N - j - i, j, i)
      exit(0)
print(-1,-1,-1)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, y = LI()

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

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