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



import sys




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


def solver(givenPieces, total_sum):
    
    
    for x in range(0, givenPieces+1, +1):
        for y in range(0, givenPieces+1-x, +1):
            remained_money = total_sum - (x * 10000 + y * 5000)


            z = givenPieces - (x + y)
            total = x * 10000 + y * 5000 + z * 1000
            if total_sum == total:
                return [x, y, (remained_money // 1000)]
    return [-1, -1, -1]


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

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):
    if 10000*i+5000*j+1000*(n-i-j)==y:
      a=i
      b=j
      c=n-i-j
      break
if c>=0:
  print(a,b,c)
else:
  print("-1 -1 -1")

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

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

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline()).split())

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

print(-1,-1,-1)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline()).split())

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

print(-1,-1,-1)

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

print(-1, -1, -1)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

def solve():
    N, Y = mapint()
    for i in range(N+1):
        for j in range(N-i+1):
            now = i*10000 + j*5000
            if now>Y:
                continue
            if i+j+(Y-now)//1000==N:
                return (i, j, N-i-j)
    else:
        return (-1, -1, -1)

print(*solve())

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

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

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

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

Solution (Python):
import sys
N, Y = map(int,input().split())
sum_ = 0
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(i,j,N-i-j)
      sys.exit()
print(-1,-1,-1)

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

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

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

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

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

if __name__ == "__main__":
  resolve()

Solution (Python):
def main():
    N, Y = (int(i) for i in input().split())
    ans = [-1, -1, -1]
    for x in range(N+1):
        for y in range(N+1):
            z = N - x - y
            if z < 0:
                continue
            yen = x*10000 + y*5000 + z*1000
            if yen == Y:
                ans = [x, y, z]
                break
        if ans != [-1, -1, -1]:
            break
    print(*ans)


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

print(-1,-1,-1)

Solution (Python):
def main():
    n, y = map(int, input().split())
    res = {10000:0, 5000:0, 1000:0}
    if y % n == 0 and y//n in res:
        res[y//n] = n
        print(res[10000], res[5000], res[1000])
        return 0
    else:
        for i in range(0, y//10000+1):
            for j in range(0, y//5000+1):
                if 10000*i + 5000*j + 1000*max((n-i-j),0) == y and 0 <= n - (i+j):
                    res[10000] = i
                    res[5000] = j
                    res[1000] = n - i - j
                    print(res[10000], res[5000], res[1000])
                    return 0
        print(-1, -1, -1)

if __name__ == '__main__':
    main()

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

x, y, z = -1, -1, -1
for i in range(N+1):
  if Y < N+9*i:
    break
  if (Y-N-9*i) % 4 == 0:
    j = (Y-N-9*i) // 4
    if i+j <= N:
      x, y = i, j
      break

if x != -1:
  z = N - i - j
print(x, y, z)

Solution (Python):


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

for a in range(n+1):
  bc = n - a
  for b in range(bc+1):
    c = bc - b
    sum = 10000*a + 5000*b + 1000*c
    if sum == y:
      print(a, b, c)
      break
  else:
    continue
  break
else:
  print(-1, -1, -1)

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

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

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

Solution (Python):
N, Y = map(int, input().split())
exists = False
for x in range(N+1):
  for y in range(N+1):
    z = (Y-10000*x-5000*y)//1000
    if 0<=z<=N and x+y+z==N:
      exists = True
      break
  else:
    continue
  break
if exists:
  print(x, y, z)
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):
        k = n - i - j
        if (k < 0) or (i + j + k != n):
            continue

        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 i in range(N+1):
    for j in range(N+1-i):
        k = N - (i + j)
        if i * 10000 + j * 5000 + k * 1000 == Y:
            print(i, j, k)
            exit()
print(-1, -1, -1)

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

for ichiman in range(n + 1):
  for gosen in range(n + 1):
    sen = (y - (ichiman*10000) - (gosen*5000)) // 1000
    zero = y - (ichiman*10000) - (gosen*5000) - (sen*1000)
    if zero == 0 and ichiman + gosen + sen == n and sen >= 0:
      print(str(ichiman) + " " +  str(gosen) + " " + str(sen))
      isComplete = True
      break
  if isComplete:
    break

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

Solution (Python):
n,y=map(int,input().split())
flag=True
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:
            flag=False
            print(i,j,n-i-j)
            break
    else:
        continue
    break
if flag:
    print('-1 -1 -1')

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

for a in range(N+1):
    for b in range(N+1):
        if 10000 * a + 5000 * b + 1000 * (N - a - b) == Y:
            if (N - a - b)<0:
                pass
            else:
                x = str(a)
                y = str(b)
                z = str(N - a - b)
                ans = 1
                break
        else:
            pass

if ans == 1:
    print(x + " " + y + " " + z)
else:
    print("-1 -1 -1")

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

def f():
    for i in range(N+1):
        for j in range(9):
            k = N-i-j

            if i<0 or j<0 or k<0:
                continue

            if i*10000+j*5000+k*1000 == Y:
                print(i, j, k)
                return

    print(-1,-1,-1)

f()

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

for x in range(n+1):
  for y in range(n-x+1):
    if 9*x + 4*y == a-n and n-x-y>=0:
      print(x, y, n-x-y)
      exit()
print(-1, -1, -1)

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


a_num=y//10000

b_num=y//5000

com=[]
for a in range(a_num+1):
    for b in range(b_num+1):
        if 10000*a+5000*b+1000*(n-(a+b))==y and 0<=n-(a+b):
            com.append([a,b,n-(a+b)])
            break
if com==[]:
    print("-1 -1 -1")
else:
    print(com[0][0],com[0][1],com[0][2])

Solution (Python):
N,y = (int(x) for x in input().split())
Y = y / 1000
o = 0
for a in range (N+1):
    for b in range (N-a+1):
        c = N - (a+b)
        if Y == 10*a + 5*b + c and o == 0:
            print (a,b,c)
            o = 1
if o == 0:
    print (-1,-1,-1)

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

Y //= 1000

for y in range(9):
  Yt = Y - 5*y
  Nt = N - y
  if Nt <= Yt <= 10*Nt:
    x = (Yt - Nt)//9
    z = (10*Nt - Yt)//9
    if x + z == Nt:
      print(x, y, z)
      exit()

print(-1, -1, -1)

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

Y //= 1000

for y in range(9):
  Yt = Y - 5*y
  Nt = N - y
  if Nt <= Yt <= 10*Nt:
    x = (Yt - Nt)//9
    z = (10*Nt - Yt)//9
    if x + z == Nt and 10*x + z == Yt:
      print(x, y, z)
      exit()

print(-1, -1, -1)

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

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

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

Solution (Python):
n,y = map(int, input().split())
ten = -1
five = -1
one = -1

for i in range(n + 1):
  for j in range(n + 1):
    tmp = i * 10000 + j * 5000
    left = y - tmp
    if left < 0:
      continue
    cnt = left // 1000
    if i + j + cnt == n:
      ten = i
      five = j
      one = cnt
      break

print(ten, five, one)

Solution (Python):
N, Y = list(map(int, input().split()))
resx = -1
resy = -1
resz = -1
for x in range(N+1):
    for y in range(N+1-x):
        z = N -x -y
        total = 10000*x + 5000*y + 1000*z
        if total == Y:
            resx = x
            resy = y
            resz = z
print(resx, resy, resz, sep=' ')

Solution (Python):
N, Y = list(map(int, input().split()))
for n in range(N+1):
  for m in range(N-n+1):
    l=N-n-m
    sum=10000*n+5000*m+1000*l
    if sum==Y:
      print(f'{n} {m} {l}')
      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())

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

Solution (Python):
import sys

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

for x in range(0, N + 1):
    for y in range(0, N + 1):
        if ((N - x - y) * 1000 + x * 10_000 + y * 5000) == Y and (N - x - y) >= 0:
            print(x, y, N - x - y)
            sys.exit(0)
print(-1, -1, -1)

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

for i10000 in range(n+1):
  for i5000 in range(n+1):
    i1000 = (y - (i10000*10000 + i5000*5000)) // 1000
    if i1000 >= 0 and i1000 + i5000 + i10000 == n:
      print(i10000, i5000, i1000)
      exit()

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

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

pattern=0


if 10000*n==y:
  print(n,0,0)
  
  
else:
    for yukichi in range(n):
      if y-10000*yukichi<0:
          print(-1,-1,-1)
          break
          
      elif y-10000*n==0:
          print(n,0,0)
          break
    
      elif y-10000*yukichi-5000*(n-yukichi)==0:
        print(yukichi,n-yukichi,0)
        break
        
      else:      
        for higuchi in range(n-yukichi):
          if y-10000*yukichi-5000*higuchi-1000*(n-yukichi-higuchi)==0:
              print(yukichi,higuchi,n-yukichi-higuchi)
              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-i+1):
        k = N - i - j
        t = (i, j, k)
        if Y == i*10000 + j*5000 + k*1000:
           print(*t)
           exit()
print('-1 -1 -1')

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


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

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

Solution (Python):
from itertools import product, takewhile



def iter_break():
    yield True
    raise StopIteration


def main():
    N, Y = (int(x) for x in input().split(" "))
    Y = Y//1000
    y10 = 10
    y5 = 5
    y1 = 1
    max_y10 = Y // y10
    max_y5 = Y // y5
    max_y1 = Y // y1
    if (max_y10) > N:
        max_y10 = N
    if (max_y5) > N:
        max_y5 = N
    
    
    for (n_y10, n_y5) in product(
        range(max_y10, -1, -1),
            range(max_y5, -1, -1)):
        n_y1 = N-n_y10-n_y5
        if n_y1 < 0 or (n_y10 * y10 + n_y5 * y5 + n_y1 * y1 != Y):
            continue
        print(n_y10, n_y5, n_y1)
        exit()
    print(-1, -1, -1)


if __name__ == '__main__':
    main()

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

if Y > N*10000 or Y < N*1000:
    print("-1 -1 -1")
else:
    for i in range(N+1):
        for j in range(N+1-i):
            k = N-i-j
            m = 10000*i+5000*j+1000*k
            if m == Y:
                print("%s %s %s" % (i, j, k))
                break
        else:
            continue
        break
    else:
        print("-1 -1 -1")

Solution (Python):
import sys

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

for x in range((Y//10000)+1):
    rest = Y - x * 10000
    if rest < 0:
        continue
    
    for y in range((rest//5000)+1):
        rest2 = rest - y * 5000
        if rest2 < 0:
            continue

        z = rest2//1000

        total = x + y + z

        if total == N:
            print(x, y, z)
            sys.exit(0)
print('-1 -1 -1')

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

Solution (Python):






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





if Y > N*10000 or Y < N*1000:
    print("-1 -1 -1")
else:
    for i in range(N+1):
        for j in range(N+1-i):
            k = N-i-j
            m = 10000*i+5000*j+1000*k
            if m == Y:
                print("%s %s %s"%(i,j,k))
                break
        else:
            continue
        break
    else:
        print("-1 -1 -1")

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

flug = 0
for i in range(n+1):
    value = y - i * 10000
    if flug == 1:
        break
    for second_value in range(n - i + 1):
        answer_value = value - second_value*5000 - (n-second_value-i)*1000
        if answer_value == 0:
            print(i, second_value, n-second_value-i)
            flug = 1
            break
else:
    if flug != 1:
        print("-1 -1 -1")

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

Solution (Python):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy
from functools import reduce



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

    print(-1,-1,-1)
        




if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
sys.setrecursionlimit(500000)

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

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


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


if __name__ == '__main__':
    main()

Solution (Python):
N, Y = map(int, input().split())
x, y, z = [-1]*3
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:
      x, y, z = i, j, k
      break
  else :
    continue
  break
print("{0} {1} {2}".format(x, y, z))

Solution (Python):
N, Y = map(int, input().split())
ans = ["-1", "-1", "-1"]

for i in range(N + 1):
    for o in range(((N - i + 1))):
        p = N - i - o
        if (10000 * i) + (5000 * o) + (1000 * p) == Y:
            ans = [str(i), str(o), str(p)]
        
print(" ".join(ans))

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

Solution (Python):
import sys

N,Y = map(int,sys.stdin.readline().split(' '))

result = [-1] * 3

for x in range(N+1):
    for y in range(N-x+1):
        if (10000*x + 5000*y + 1000*(N-x-y)) == Y and (N-x-y) >= 0:
            result = [x,y,N-x-y]
            break

print(*result)

Solution (Python):
import sys

N,Y = map(int,sys.stdin.readline().split(' '))

result = '-1 -1 -1'

for x in range(N+1):
    for y in range(N-x+1):
        z = N-x-y
        sum = 10000*x + 5000*y + 1000*z
        if sum == Y and z >= 0:
            result = f'{x} {y} {z}'
            break

print(result)

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

x=y=z=0
ans=[-1,-1,-1]
while x<=N:
    y=0
    while x+y<=N:
        if 10000*x+5000*y+1000*(N-x-y)==Y:
            ans=[x,y,N-x-y]
        y+=1
    x+=1

print(*ans)

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

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

print(*res)

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

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

print(*res)

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

if ans == 0:
    print("-1 -1 -1")
else:
    print(a,b,c)

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

for i in range(n+1):
    for j in range(n+1):
        if n-(i+j)>=0 and 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 i in range(n+1):
    for j in range(n+1):
        k = n - i - j
        if k >= 0 and 10000 * i + 5000 * j + 1000 * k == y:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    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-i+1):
        k=(Y-i*10000-j*5000)/1000
        if k>=0 and k%1==0.0 and i+j+k==N:
            k=int(k)
            print('{} {} {}'.format(i,j,k))
            exit()

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

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n, y = LI()
ans = [-1, -1, -1]
for i in range(n + 1):
    for j in range(n + 1):
        k = n - i - j
        if k < 0:
            continue

        money = 10000 * i + 5000 * j + 1000 * k
        if money == y:
            ans = [i, j, k]
            break
print(*ans)

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

list = list(range(n+1))
for a,b in itertools.product(list,list):
    c = n - a - b
    if c>=0:
        v = 10*a + 5*b + c
        w = a + b + c
        if v == z and w == n:
            break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))

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

list = list(range(n+1))
for a,b in itertools.product(list,list):
    c = n - a - b
    if c>=0:
        v = 10*a + 5*b + c
        w = a + b + c
        if v == z and w == n:
            break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))

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

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

print("-1 -1 -1")

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

for i in range(n, -1, -1):
  if  y - 10000*i < 0: continue
  for j in range(n-i, -1, -1):
    k = n-i-j
    if y - 10000*i - 5000*j - 1000*k < 0: continue
    elif y - 10000*i - 5000*j - 1000*k == 0:
      print(i,j,k)
      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 a*10000 + b*5000 + c*1000 == y and a+b+c == n and c >= 0:
            print(a, b, c)
            exit()
print('-1 -1 -1')

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

exist = False

for i in reversed(range(y//10000+1)):
    for j in reversed(range(n-i+1)):
        k = n - i - j
        res = y - 10000*i - 5000*j
        if res == 1000*k:
            print("{} {} {}".format(i,j,n-i-j))
            print("\n")
            exist = True
        if exist:
            break
    if exist:
        break

if not exist:
    print("-1 -1 -1")
    print("\n")

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

exist = False

for i in range(int(y/10000)+1):
    range_j = int((y - 10000*i)/5000)
    for j in range(range_j+1):
        k = n - i - j
        res = y - 10000*i - 5000*j
        if res == 1000*k:
            print("{} {} {}".format(i,j,n-i-j))
            print("\n")
            exist = True
        if exist:
            break
    if exist:
        break

if not exist:
    print("-1 -1 -1")
    print("\n")

Solution (Python):
N,Y = map(int,input().split())
for a in range(N+1):
    for b in range(N+1):
        val = Y-10000*a-5000*b
        n = N-a-b
        if n>=0 and val >=0 and n*1000==val:
            print(a,b,N-a-b);exit()
print('-1 -1 -1')

Solution (Python):






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

Z = Y // 1000

for N0 in range(Z // 10 + 1):
    Z1 = Z - 10 * N0
    for N1 in range(Z1 // 5 + 1):
        N2 = Z1 - 5 * N1
        if (N0 + N1 + N2) == N:
            print(N0, N1, N2)
            exit()

print(-1, -1, -1)

Solution (Python):
n, y = map(int, input().split())
x = 0
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))
      x = 1
      break
  if x == 1:
    break
else:
  print(-1, -1, -1)

Solution (Python):
import math
n,y = map(int,input().split())
c = 0
for a in range(n+1):
	for b in range(n+1):
		if 9000*a + 4000*b == y - 1000*n and n - a - b >= 0:
			print(*[a,b,n-a-b])
			c += 1
			break
	if c == 1:
		break
if c == 0:
	print(*[-1,-1,-1])

Solution (Python):
n,y=map(int, input().split())
y=y//1000
for i in range(1+y//10):
	if i>n:
		pass
	for j in range(1+(y-10*i)//5):
		if i+j>n:
			pass
		if 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())

Y //= 1000

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

print(-1, -1, -1)

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

ans = 0
for i in range(n+1):
    for j in range(n+1):
        k  =max(0, (n - i - j))
        otoshidama = 10000 * i + 5000 * j + 1000 * k
        if (i + j + k) == n and otoshidama == y:
            ans += 1
            break
        else:
            continue
    else:
        continue
    break

if ans > 0:
    print(i, j, k)
else:
    print('-1 -1 -1')

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	
	n, y = tin()
	
	for ii in range(n+1):
		for ji in range(n+1-ii):
			ty = 10000 * ii + 5000 * ji + 1000*(n-ii-ji)
			if ty == y:
				print(*[ii, ji, n-ii-ji])
				return 
	else:
		print(*[-1, -1, -1])
		return 
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)