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

print(-1, -1, -1)

Solution (Python):
nums = []
nums = input().split()
N = int(nums[0])
Y = int(nums[1])
Right = 0
for a in range(N+1) :
    for b in range(N + 1 - a):
        c = N - a - b
        if( Y == 10000 * a + 5000 * b + 1000 *c ):
            if (N == (a + b + c)):
                Right = 1
                break
            else:
                continue
    else:
        continue
    break
if( Right == 0 ):
    print("-1 -1 -1")
else :
    print(a,b,c)

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

Solution (Python):



import sys


import pprint as pp

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]



MAXSIZE = ( 1 << 31 ) -1
MINSIZE = -( 1 << 31) + 1
YES = "YES"
NO = "NO"

def solver(totalSheet, sum):
    result = [-1, -1, -1]
    
    for sheet_10000 in range(0, totalSheet+1, +1):
        for sheet_5000 in range(0, totalSheet + 1 - sheet_10000, +1):
            sheet_1000 = totalSheet - sheet_10000 - sheet_5000
            nowSum = sheet_10000 * 10000 + sheet_5000 * 5000 + sheet_1000 * 1000
            if nowSum == sum:
                result = [sheet_10000 ,sheet_5000, sheet_1000]
    return result


if __name__ == "__main__":
    N, Y = MI()
    answer = solver(N, Y)
    print("{} {} {}".format(answer[0], answer[1], answer[2]))

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

for m in range(Y // 10, -1, -1):
	for g in range((Y - m * 10) // 5, -1, -1):
		if 10 * m + 5 * g + (N - m - g) == Y:
			print(m, g, N - m - g)
			exit()
print(-1, -1, -1)

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

for m in range(Y // 10, -1, -1):
	for g in range((Y - m * 10) // 5, -1, -1):
		if 10 * m + 5 * g + (N - m - g) == Y:
			print(m, g, N - m - g)
			exit()
print(-1, -1, -1)

Solution (Python):

import sys
from typing import Tuple


def fast_input():
    return sys.stdin.readline()[:-1]


def solve(num: int, amount: int) -> Tuple[int, int, int]:
    for count_10000 in range(0, num + 1):
        for count_5000 in range(0, num - count_10000 + 1):
            count_1000 = num - (count_10000 + count_5000)
            total = count_10000 * 10000 \
                        + count_5000 * 5000 \
                        + count_1000 * 1000
            if total == amount:
                return count_10000, count_5000, count_1000
    return -1, -1, -1


def main():
    n, y = list(map(int, fast_input().split()))
    result = solve(n, y)
    print(*result)


main()

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

Solution (Python):
from sys import stdin
n,y = [int(x) for x in stdin.readline().rstrip().split()]
flag = False

for p in reversed(range(n+1)):
   if p * 10000 > y:
      continue
   else:
      for q in reversed(range(n-p+1)):
         if 10000*p + 5000*q + 1000*(n-p-q) == y:
            print(p,q,n-p-q)
            flag = True
            break
      if flag == True:
         break
   if flag == True:
      break
if flag == False:
   print(-1,-1,-1)

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

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

print('-1 -1 -1')

Solution (Python):
N,Y=map(int,input().split())
flag=0
ten_key=int(Y/10000)
one_key=int(Y/1000)
if N<ten_key or one_key<N:
    print(-1,-1,-1)

else:
    amari=Y-(ten_key*10000)
    five_key=int(amari/5000)
    if N-ten_key<five_key:
        print(-1,-1,-1)
    
    else:
        for i in range(ten_key+1):
            if flag==1:
                break
            amari=Y-(i*10000)
            five_key=int(amari/5000)
            for j in range(five_key+1):
                one_max=N-i-j
                amari=Y-((i*10000)+(j*5000))
                one_key=int(amari/1000)
                if one_key+i+j==N:
                    print(i,j,one_key)
                    flag=1
                    break
        if flag==0:
            print(-1,-1,-1)

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

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+1):
    if N-(i+j) >= 0 and S == ( 10000*i + 5000*j + 1000*(N-(i+j)) ):
      x = i
      y = j
      z = N-(i+j)
      break
print(x,y,z)

Solution (Python):
num_list = list(map(int, input().split(' ')))
N = num_list[0]
Y = num_list[1]
total = 0
ans = '-1 -1 -1'
for n in range(N+1):
  rest = N - n
  a = n*10000
  if rest == 0:
    if a == Y:
      ans = str(int(a/10000)) + ' 0 0'
      break
  for i in range(rest+1):
    rest_2 = rest - i
    b = i*5000
    c = rest_2*1000
    if rest == 0:
      if a+b == Y:
        ans = str(int(a/10000)) + ' ' + str(int(b/5000)) + ' 0'
        break
    elif a+b+c == Y:
      ans = str(int(a/10000)) + ' ' + str(int(b/5000)) + ' ' + str(int(c/1000))
print(ans)

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

check = False
for i in range(N+1):
  for j in range(N+1):
    k = (Y - 10000 * i - 5000 * j) / 1000
    if k != int(k) or k < 0 or k != N - i - j:
      continue
    else:
      check = True
      ans = [i,j,int(k)]
      
if not check:
  ans = [-1,-1,-1]
print(*ans)

Solution (Python):
N,Y = map(int,input().split())
x = y = z = 0
while  Y >= 10000:
    x += 1
    N -= 1
    Y -= 10000
while Y >= 5000:
    y += 1
    N -= 1
    Y -= 5000
while Y >= 1000:
    z += 1
    N -= 1
    Y -= 1000
if Y != 0 or N < 0:
    x = y = z = -1
else:
    while N >= 9 and x > 0:
        x -= 1
        z += 10
        N -= 9
    while N >= 4 and y > 0:
        y -= 1
        z += 5
        N -= 4
    while N > 0 and x > 0:
        x -= 1
        y += 2
        N -= 1
    if N != 0:
        x = y = z = -1
print(x,y,z)

Solution (Python):
def main():
    n, y = map(int, input().split())
    flag = False

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

    for i in range(0, n + 1):
        for j in range(0, n + 1):

            money = y - 10000 * i - 5000 * j
            k = n - (i + j)
            if k < 0:
                break
            else:
                if 1000 * k == money:
                    a = i
                    b = j
                    c = k
                    flag = True
                    break

        if flag:
            break

    print(a, b, c)


if __name__ == '__main__':
    main()

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    n,y = i_map()
    for m in range(0,n+1):
        for g in range(0,n-m+1):
            if 10000*m+5000*g+1000*(n-m-g) == y:
                print(m,g,n-m-g)
                exit()
    print(-1,-1,-1)



if __name__=="__main__":
    main()

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

for man in range(N+1):
    for sen in range(N+1):
        if man + sen > N:
            break
        if 10000*man + 5000*sen + 1000*(N-man-sen) == Y:
            print(man, sen, N-man-sen)
            exit()
print('-1 -1 -1')

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

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

Solution (Python):
n,y=map(int,input().split())
amari=y-1000*n

if amari < 0:
    print(-1,-1,-1)
    exit()

for k in range(0,n+1):
    if amari-4000*k >= 0 and (amari-4000*k)%5000 == 0:
        x=(amari-4000*k)//5000
        if k-x >= 0:
            y=k-x
            print(x,y,n-k)
            break
else:
    print(-1,-1,-1)

Solution (Python):
def main():
    n , y = map( int , input().split() )
    y = y // 1000
    flag = 0
    ans = [ -1 , -1 , -1 ]
    for a in range( n + 1 ):
        
        sum = a * 10
        if sum > y:
            break

        for b in range( n + 1 - a ):
            
            sum_ = sum
            sum_ += b * 5
            if sum_ > y:
                break
            if y - sum_ == n - a - b:
                flag = 1
                ans[0] = a
                ans[1] = b
                ans[2] = n - a - b
                break
        if flag:
            break
    print( *ans )

main()

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

for i in range(N + 1):
    for j in range(N + 1 - i):
        k = N - i - j
        if 10 * i + 5 * j + k == Y:
            print(i, j, k)
            exit(0)

print(-1, -1, -1)

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

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

flag = False
for i in range(n + 1):
    for j in range(n + 1 - i):
        res = y - 10000 * i - 5000 * j
        if res // 1000 == n - i - j:
            print(i, j, res // 1000)
            flag = True
            break
    if flag:
        break
else:
    print(-1, -1, -1)

Solution (Python):



def main():
    n, y = map(int, input().split())
    maxA = min(n, y // 10000)
    maxB = min(n, y // 5000)
    for i in range(maxA, -1, -1):
        t = y - 10000 * i
        if t == 0:
            if n == i:
                print(f"{i} 0 0")
                return
            continue
        for j in range(min(maxB, n - i), -1, -1):
            tt = t
            tt -= 5000 * j
            if tt == 0:
                if n == i + j:
                    print(f"{i} {j} 0")
                    return
            if tt > 0 and tt == (n - (i + j)) * 1000:
                print(f"{i} {j} {n-(i+j)}")
                return
    print("-1 -1 -1")


if __name__ == "__main__":
    main()

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
N,Y = map(int,input().split())
for i in range(N+1):
    for j in range(N+1-i):
        if N-i-j == (Y-(10000*i)-(5000*j))//1000:
            print(i,j,N-i-j)
            sys.exit()
print(-1,-1,-1)

Solution (Python):
n, y = map(int, input().split( ))
if y > n*10000 or y < n*1000:
  print(-1, -1, -1)
  exit()

y = y//1000
s = 0
for i in range(0,n+1):
  s = 10*n- 9*i
  if s == y:
    print(n- i, 0, i)
    exit()
  for j in range(1, n-i+1):

    s -= 5
    if s == y:
      print(n-i-j, j, i)
      exit()
print(-1, -1, -1)

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

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

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

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

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

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

Solution (Python):
N, Y = input().split()
N = int(N)
Y = int(Y)
i = 0
j = 0
k = N - i - j


for i in range(N+1):
    for j in range(N - i + 1):
        k = N - i - j
        SUM = 10000*i + 5000 * j + 1000 * k
        if SUM == Y:
            print(i, j, k)
            exit()
        else:
            continue
        
print('-1', '-1', '-1')

Solution (Python):
def otoshidama(N,Y):
  ansi, ansj, ansk = -1, -1, -1
  if Y/10000 > N:
    return ansi, ansj, ansk
  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:
        ansi, ansj, ansk = i, j, k
        return ansi,ansj,ansk
  return ansi,ansj,ansk
N,Y = [int(i) for i in input().split()]
ansi, ansj, ansk = otoshidama(N,Y)
print(ansk, ansj, ansi)

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

ans = "-1 -1 -1"
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:
      ans = str(i)+" "+str(j)+" "+str(k)
      break

print(ans)

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

def get():
    for num_10000 in range(n+1):
        for num_5000 in range(n-num_10000+1):
            num_1000=n-num_10000-num_5000
            if y==10000*num_10000+5000*num_5000+1000*num_1000:
                return [num_10000,num_5000,num_1000]
    return [-1,-1,-1]
a,b,c=get()

print(a,b,c)

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
for i in range(N+1):
  for j in range(N-i+1):
    if 0<=Y-10*i-5*j==N-i-j:
      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):
        tot = i*10000 + j*5000 + (N-i-j)*1000
        if tot == Y:
            ans = (i,j,N-i-j)
            break
    else:
        continue
    break
else:
    ans = (-1,-1,-1)
print(*ans)

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

for a in range(n+1):
  for b in range((n-a)+1):
    s = a*10000 + b*5000 + (n-a-b)*1000
    if s == y :
      print(a,b,(n-a-b))
      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 - a + 1):
        c = N - a - b
        if 10000 * a + 5000 * b + 1000 * c == Y:
            result = [a, b, c]
print(*result)

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 - a + 1):
        c = N - a - b
        if 10000 * a + 5000 * b + 1000 * c == Y:
            result = [a, b, c]
print(*result)

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

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

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

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

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

def solve(N, Y):
    for i in range(N+1):
        for j in range(N+1-i):
            res = 10*i + 5*j + (N-i-j)
            if res == Y:
                return i, j, N-i-j
    else:
        return -1, -1, -1

ans = solve(N, Y) 
print(*ans)

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

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

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

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

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

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

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

for j in range(N+1):
    for i in range(N+1):
        sum = 10000*j + 5000*i + 1000*(N-i-j)
        if(sum==Y and N-i-j>=0):
            print(j,i,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):
        if Y == 10000*i + 5000*j + 1000*(N-i-j):
            print(i, j, N-i-j)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Solution (Python):
ny = input().split(" ")
n = int(ny[0])
y = int(ny[1])

for a in range(n+1):
    for b in range(n -a + 1):
        c = n - a -b
        if a*10000+b*5000+c*1000 == y:
            print("{} {} {}".format(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+1):
        if 10000*i+5000*j+1000*(n-i-j)==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())
a,b,c=-1,-1,-1
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            a=i
            b=j
            c=n-i-j

print(a,b,c)

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

en=False
for i in range(n+1):
    for q in range(n-i+1):
        cal=i*10000+q*5000+(n-i-q)*1000
        if cal==y:
            print(i,q,n-i-q)
            en=True
            break
    if en:
        break
if not en:
    print("-1 -1 -1")

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

for i in range(N+1):
  for s in range(N+1):
    k = N-i-s
    if k>=0 and 1000*i+5000*s+10000*k==Y:
      print(k,s,i)
      exit()

print(-1,-1,-1)

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

max_10000 = Y // 10000
for x in range(max_10000 + 1):
    if x > N:
        continue

    rem = Y - 10000 * x

    max_5000 = rem // 5000
    for y in range(max_5000 + 1):
        if x + y > N:
            continue

        rem_2 = rem - 5000 * y
        if x + y + rem_2 // 1000 == N:
            print('{} {} {}'.format(x, y, rem_2 // 1000))
            exit()


print('{} {} {}'.format(-1, -1, -1))

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

max_10000 = Y // 10000
for x in range(max_10000 + 1):
    rem = Y - 10000 * x

    if x > N:
        continue

    max_5000 = rem // 5000

    for y in range(max_5000 + 1):
        if x + y > N:
            continue

        rem_2 = rem - 5000 * y
        if x + y + rem_2 // 1000 == N:
            print('{} {} {}'.format(x, y, rem_2 // 1000))
            exit()


print('{} {} {}'.format(-1, -1, -1))

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

max_10000 = Y // 10000
for x in range(max_10000 + 1):
    rem = Y - 10000 * x

    if x > N:
        continue

    max_5000 = rem // 5000

    if max_5000 == 0:
        if x + rem // 1000 == N:
            print('{} {} {}'.format(x, 0, rem // 1000))
            exit()
    else:
        for y in range(max_5000 + 1):
            if x + y > N:
                continue

            rem_2 = rem - 5000 * y
            if x + y + rem_2 // 1000 == N:
                print('{} {} {}'.format(x, y, rem_2 // 1000))
                exit()


print('{} {} {}'.format(-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 z >= 0 and 10000*x + 5000*y + 1000*z == Y:
      print("%d %d %d" % (x, y, z))
      exit()
print('-1 -1 -1')

Solution (Python):
import sys
a,b = map(int,input().split())
for x in range(a+1):
    for y in range(a+1):
            if 10000*x + 5000*y + 1000*(a-x-y) > b:
                if a-x-y >= 0:
                    continue
            if 10000*x + 5000*y + 1000*(a-x-y) == b:
                if a-x-y >= 0:
                    print(x,y,a-x-y)
                    sys.exit()
print(-1,-1,-1)

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

a, b, c = -1, -1, -1
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:
      a, b, c = i, j, k
  
print(a, b, c)

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


a, b, c = -1, -1, -1
flag = False
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:
      a, b, c = i, j, k
      break
  if flag: break
  
print(a, b, c)

Solution (Python):
N, Y = map(int, input().split())
 
flag = False
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:
      flag = True
      break
  if flag: break

if flag: print(i, j, k)
else: print(-1, -1, -1)

Solution (Python):


inputs = [int(s) for s in input().split()]
N = inputs[0]
Y = inputs[1]

def check_count():
    for i in range(N+1):
      for j in range(N+1-i):
        k = N - (i+j)
        total = k * 10000 + j * 5000 + i * 1000
        if total == Y:
            return " ".join([str(k), str(j), str(i)])
    return "-1 -1 -1"

print(check_count())

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

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

print(-1, -1, -1)

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

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

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

for i in reversed(range(N + 1)): 
  for j in reversed(range(N + 1)): 
    n = Y - 10000 * i - 5000 * j
    if n >= 0 and n % 1000 == 0:
      k = n // 1000
      if i + j + k == N:
        x, y, z = i, j, k
        break

print(x, y, z)

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

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]







n,Y = MI()

limit_x = Y//10000
for x in range(min(limit_x+1,n+1)):
    r = Y - 10000*x
    limit_y = r//5000
    for y in range(min(n+1-x,limit_y+1)):
        r2 = r - 5000*y
        z = n - x - y
        r3 = r2 - 1000*z
        if r3==0:
            print(x,y,z)
            exit()
print(-1,-1,-1)
exit()

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

def check():
  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)
        return
  print(-1,-1,-1)

check()

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=True
for x in range(N+1):
    for y in range(N+1-x):
        z=N-x-y
        if(10000*x+5000*y+1000*z==Y):
            print(x,y,z)
            flag=False
            break
    else:
        continue
    break
if(flag):
    print(-1,-1,-1)

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

l = 0

for i in range(N + 1):
    for j in range(N + 1):
        k = N - i - j
        if 1000*i + 5000*j + 10000*k == Y and k <= N and k >= 0:
            print(k, j, i)
            l = 1
            break
    else:
        continue
    break

if l == 0:
    print("-1 -1 -1")

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

Solution (Python):
n, y = (int(x) for x in input().split())
a = 0
b = 0
c = 0
flag = 0


for s in range(n+1):
    if y-s*10000 == 0 and s == n and flag == 0:
        a = s
        print(a, b, c)
        flag = 1
    else:
        for t in range(n-s+1):
            if y-s*10000-t*5000-(n-s-t)*1000 == 0 and n-s-t >= 0 and flag == 0:
                a = s
                b = t
                c = n-s-t
                print(a, b, c)
                flag = 1
if flag == 0:
    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=(Y//1000)-10*x-5*y
        if N==x+y+z:
            print("{} {} {}".format(x,y,z))
            exit()

print("-1 -1 -1")

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

nax=Y//1000

if N==nax:
    print(0,0,nax)
    exit()
elif N>nax:
    print(-1,-1,-1)
    exit()
else:
    for i in range(nax//10+1):
        for j in range(nax//5+1):
            if nax-10*i-5*j>=0 and nax-9*i-4*j==N:
                print(i,j,nax-10*i-5*j)
                exit()
print(-1,-1,-1)

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

nax=Y//1000

if N==nax:
    print(0,0,nax)
    exit()
elif N>nax:
    print(-1,-1,-1)
    exit()
else:
    for i in range(nax//10+1):
        for j in range(nax//5+1):
            if nax-10*i-5*j>=0 and nax-9*i-4*j==N:
                print(i,j,nax-10*i-5*j)
                exit()
print(-1,-1,-1)

Solution (Python):
N, Y =map(int, input().split())
c = 0
for n in range(N+1):
    if c == 1:
        break
    for m in range(N-n+1):
            l = N -n - m
            if Y ==( n*10000 + m *5000 + l *1000) and (n + m + l) == N:
                print(n , m , l)
                c = 1
                break
if c != 1:
    print(-1 , -1 , -1)

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):
        if ((10000*i + 5000*j + 1000*(N-i-j)) == Y)and(N-i-j>=0):
            x,y = i,j
            z = N - i - j
            break
    else:
        continue
    break
print(x,y,z)