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

m_max = int(y/10000)
g_max = int(y/5000)

flag = 0
for m in range(0,m_max+1):
    for g in range(0,g_max+1):
        s = n - m - g
        if s >= 0 :
            yen = m * 10000 + g * 5000 + s * 1000
            if yen == y :
                result = str(m) + " " + str(g) + " " + str(s)
                flag = 1
                break
    if flag == 1 :
        break
            
if flag == 0 :
    print("-1 -1 -1")
else :
    print(result)

Solution (Python):
N, Y = map(int, input().split())
flg = False
        
for a in range(N+1):
    if flg: break
    for b in range(N+1-a):
        c = N - a - b
        if a*10000 + b*5000 + c*1000 == Y:
            ans = [a, b, c]
            flg = True
            break
if flg:
    print(*ans)
else:
    print(-1,-1,-1)

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

a = Y//10000
for i in range(a + 1):
    if flg: break
    reg = Y - 10000 * i
    b = reg // 5000
    for j in range(b + 1):
        if flg: break
        reg2 = reg - 5000 * j
        c = reg2 // 1000
        if reg2 % 1000 == 0 and i + j + c == N:
            ans = [i, j, c]
            flg = True
            break
if -1 not in ans:
    print(*ans)
else:
    print(-1, -1, -1)

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

for i in range(x+1):
    for i2 in range(x+1-i):
        i3 = x-(i+i2)
        y1 = y-(10000*i+5000*i2+1000*i3)
        if y1 == 0:
            break
    if y1==0:
        break
if y1==0:
    print(i,i2,i3)
else:
    print(-1,-1,-1)

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

count = 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:
            count += 1
            print(x, y, z)
            break
    if count!=0:
        break
if count==0:
    print("-1 -1 -1")

Solution (Python):
N,Y = map(int,input().split())
for i in range(N+1):
  for k in range(N+1):
    if(N - (i + k) < 0):
      pass
    else:
      tmp = 10000 * i + 5000 * k + ((N - (i + k)) * 1000)
      if(tmp == Y):
        print(str(i),str(k),str(N-(i+k)))
        exit()
print("-1 -1 -1")

Solution (Python):
n,y = list(map(int,input().split()))
y /= 1000
ans = [0,0,0]

for i in range(n+1):
    for j in range(0,n+1-i):
        a = i*10 + j*5
        b = i+j
        
        if a + (n-(i+j)) == y:
            ans = [i,j,n-(i+j)]

if sum(ans) >0:
    print(ans[0],ans[1],ans[2])
else:
    print(-1,-1,-1)

Solution (Python):
n,Y=map(int,input().split())
for x in range(n+1):
    for y in range(n+1):
        if 10000*n-9000*x-5000*y==Y and x+y<=n:
            print(n-x-y,y,x)
            exit()
print(-1,-1,-1)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,y=map(int, input().split())
    yy=y//1000
    if yy>n*10:
        print(-1,-1,-1)
    else:
        ans=[-1,-1,-1]
        for x in range(n+1):
            for y in range(n-x+1):
                if x*10+y*5+(n-x-y)==yy:
                    flag=True
                    ans=[x,y,n-x-y]
        print(*ans)
resolve()

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, e = map(int, readline().split())

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

Solution (Python):



def main():
    N, Y = map(int, input().split())
    ret = [-1] * 3
    for x in range(N+1):
        tY = Y - 10000 * x
        tN = N - x
        for y in range(tN+1):
            z = tN - y
            if tY == y * 5000 + z * 1000:
                ret = [x, y, z]
                break
    print(*ret)

if __name__ == '__main__':
    main()

Solution (Python):




def main():
    N, Y = map(int, input().split())
    ret = [-1] * 3
    for x in range(N+1):
        tY = Y - 10000 * x
        tN = N - x
        for y in range(tN+1):
            z = tN - y
            if tY == y * 5000 + z * 1000:
                ret = [x, y, z]
    print(*ret)

if __name__ == '__main__':
    main()

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)
        money = 10000 * i + 5000 * j + 1000 * k
        if money == y:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Solution (Python):
n, r=map(int, input().split())
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==r:
      print(x, y, z)
      exit()
print(-1, -1, -1)

Solution (Python):
import sys

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

for i in range(n + 1):
    for j in range(n + 1 - i):
        if i * 10 + j * 5 + (n - i - j) * 1 == y:
            print(i, j, n - i - j)
            exit()
else:
    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()
else:
    print(-1, -1, -1)

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

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

Solution (Python):

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

print('-1 -1 -1')

Solution (Python):
a,b = map(int,input().split())
if b%1000 != 0:
  print('-1 -1 -1')
else:
  d = 0
  s = b//1000 - a
  for x in range(s//9+1):
    if d > 0:
      break
    for y in range(min((s-9*x)//4,a-x)+1):
      if 9*x + 4*y == s:
        print(x,y,a-x-y)
        d += 1
        break
  if d == 0:
    print('-1 -1 -1')

Solution (Python):
n,y = map(int,input().split())
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
y /= 1000

for i in range(int(y//10+1)):
    for j in range(int(y//5+1)):
        k = n-i-j
        if 10*i + 5*j + k == y and k>=0:
            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-i+1):
        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())

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


for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if k < 0 : continue
        if (i*10000+j*5000+k*1000) == Y: 
            x = i
            y = j
            z = k
            print(x,y,z)
            exit(0)
print(x,y,z)

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9 +7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





N,Y = inputIL()

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

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

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


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

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

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

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

Solution (Python):
n, y = map(int,input().split())
r1,r2,r3 = -1,-1,-1
for f in range(n+1):
    for h in range(n-f+1):

        if 10000 * f + 5000 * h + 1000 *( n-(f + h)) == y:

            r1,r2,r3 = f, h, n-(f + h)
            break

print(str(r1) + ' ' + str(r2) + ' ' + str(r3))

Solution (Python):
import math

def main():
    IN = [int(_) for _ in input().split()]
    N = IN[0]
    T = IN[1]

    for x in range(N+1):
        for y in range(N+1):
            if y > N - x:
                continue
            z = N - y - x
            s = 10000 * x + 5000 * y + 1000 * z
            if T == s:
                print(x, y, z)
                return
    print("-1 -1 -1")
        

if __name__ == "__main__":
    main()

Solution (Python):
n, y = list(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(' '.join(list(map(str, [i, j, k]))))
            exit()
print('-1 -1 -1')

Solution (Python):


def solve(N,Y):
    for x in range(N+1):
        for y in range(N-x+1):
            z = N-(x+y)
            if(10*x + 5*y + z == Y):
                print("{} {} {}".format(x,y,z))
                return 0

    print("-1 -1 -1")
    
N,Y = map(int, input().split())
Y //= 1000

solve(N,Y)

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

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

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

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

m //= 1000

k = min((m - n) // 4, m // 5)
if 9 * k >= 2 * (m-n):
    x = (m-n) - 4 * k
    y = 9 * k - 2 * (m-n)
    z = m - 5 * k
    print(x, y, z)
else:
    print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
nn = Y // 10000 if (Y // 10000) < N else N
mm = Y // 5000  if (Y // 5000)  < N else N
ll = Y // 1000  if (Y // 1000)  < N else N


ans = "-1 -1 -1"
for i in range(nn+1):
  for j in range(mm+1):
    if i + j > N:
      break
    if (i * 10000 + j * 5000 + (N-i-j) * 1000) == Y:
          ans = str(i)+" "+str(j)+" "+str(N-i-j)
          break
print(ans)

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

Solution (Python):

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

m10000 = -1
m5000 = -1
m1000 = -1
  
for a in range(N+1):
  for b in range(N+1-a):
    c = abs(N - a - b)
    X = 10000*a + 5000*b + 1000*c
    
    if X == M:
      m10000 = a
      m5000 = b
      m1000 = c

print(m10000, " ", m5000, " ", m1000)

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

resultI = resultJ = resultK = -1

def combiValue(i, j, k):
  return 10000 * i + 5000 * j + 1000 * k

for i in range(n+1):
  for j in range(n+1-i):
    k = n - i - j
    if combiValue(i, j, k) == purpose:
      resultI = i
      resultJ = j
      resultK = k

print("{0} {1} {2}".format(resultI, resultJ, resultK))

Solution (Python):
from sys import stdin
N,Y=list(map(int,stdin.readline().strip().split()))
a=0
b=0
c=0
i=0
for i in range(N+1):
    for j in range(N+1):
        z=N-i-j
        if i*1000+5000*j+z*10000==Y and z>=0:
            print("%d %d %d" %(z,j,i))
            exit()
print("-1 -1 -1")

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

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

Solution (Python):
n, result = 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) == result:
      print(x, y, (n - x - y))
      exit()
 
print("-1 -1 -1")

Solution (Python):
n, result = 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) == result:
      print(x, y, n - x - y)
      exit()

print("-1 -1 -1")

Solution (Python):
n, result = 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) == result:
      print(i, j, n - i - j)
      exit()

print("-1 -1 -1")

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

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

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

print(a, b, c)

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

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

print(-1,-1,-1)

Solution (Python):
N, Y = [int(_) for _ in input().split()]
x = 0
y = 0
z = 0
isOK = False


def sumMoney(x, y, z):
    return x*10000+y*5000+z*1000


for z in range(N+1):
    for y in range(N-z+1):
        x = N-z-y
        if sumMoney(x, y, z) == Y:
            print(x, y, z)
            isOK = True
            break
    if isOK:
        break


if not isOK:
    print(-1, -1, -1)

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

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

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

N = all[0]
Y = all[1]

yu = -1
hi = -1
no = -1
for i in range(N+1):
    for j in range((N+1)-i):
        c = (N-(i+j))
        total = 10000*i + 5000*j + 1000*c
        if Y==total:
            yu = i
            hi = j
            no = c
            break
        else:
            continue
    else:
        continue 
    break

print(str(yu) + " " + str(hi) + " " + str(no))

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

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

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

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

n100 = -1
n50 = -1
n10 = -1
flag = True
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:
            n100 = i
            n50 = j
            n10 = k
            break
    else:
        continue
    break
print(str(n100) + ' ' + str(n50) + ' ' + str(n10))

Solution (Python):
otoshidama = list(map(int,input().split()))
flg = True
for i in range(otoshidama[0]+1):
    yukichi =i
    for n in range(otoshidama[0]-yukichi+1):
        higuchi =n
        noguchi = otoshidama[0]-yukichi - higuchi

        if 10000*yukichi+5000*higuchi+1000*noguchi==otoshidama[1]:
            print("{} {} {}".format(yukichi,higuchi,noguchi))
            flg = False
            break
    if flg == False:
        break

if flg:
    print("-1 -1 -1")

Solution (Python):
billNum, Declation = map(int, input().split())
bill10000 = -1
bill5000  = -1
bill1000  = -1

for x in range(billNum + 1):
    for y in range(billNum + 1):
        z = billNum - x - y
        sumOfMoney = x * 10000 + y * 5000 + z * 1000
        if Declation == sumOfMoney and z * 1000 >= 0:
            bill10000 = x
            bill5000  = y
            bill1000  = z
            break

print(bill10000, bill5000, bill1000)

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

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

print("-1 -1 -1")

Solution (Python):
N,Y=map(int,input().split())
ok = 0
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)
      ok = 1
      break
  if ok == 1:
    break
if ok == 0:
  print("-1 -1 -1")

Solution (Python):
n, y = list(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)
            break
        else:
            continue
        break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Solution (Python):
n, m = 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 x * 10000 + y * 5000 + z * 1000 == m:
      answer = (x, y, z)
      break
    else:
      continue
print(*answer)

Solution (Python):
n,y=map(int,input().split())
m=0
ans1=-1
ans2=-1
ans3=-1
for i in range(n+1):
    for j in range(n-i+1):
        k=n-i-j
        m=i*10000+j*5000+k*1000
        if m==y:
            ans1=i
            ans2=j
            ans3=k
            exit

print(ans1,ans2,ans3)

Solution (Python):
n,y=map(int,input().split())
ans=[0,0,0,0]
for i in range(0,n+1):
    for j in range(0,n+1):
        if 10000*i+5000*j+1000*(n-i-j)==y and n-i-j>=0:
          ans=[1,i,j,n-i-j]
if ans[0]==1:
    print(ans[1],ans[2],ans[3])
else:
    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 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())

for x in range(n+1):
  for y in range(n+1):
    z=n-x-y

 
    if 10000*x+5000*y+1000*z==Y and z>=0:
      print('{} {} {}'.format(x,y,z))
      
      exit()

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

Solution (Python):
n, y = map(int, input().split())
money = y
flag = False
for i in range(money // 10000 + 1):
    money = y - 10000 * i
    if i + money // 1000 < n: continue
    for j in range(money // 5000 + 1):
        tmp = money - 5000 * j
        k = tmp // 1000
        if i + j + k == n:
            print('{} {} {}'.format(i, j, k))
            flag = True
            break
    if flag: break
if not flag: print('-1 -1 -1')

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

for i in range(N + 1):
    if 10000 * i > Y:
        break
    for j in range(N + 1 - i):
        if 10000 * i + 5000 * j > Y:
            break
        k = N - i - j
        if 10000 * i + 5000 * j + 1000 * k == Y:
            print('{0} {1} {2}'.format(i, j, k))
            sys.exit()
print('-1 -1 -1')

Solution (Python):

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

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

for x in range(n+1):
    for y in range(n+1-x):
        if k == x*10000  + y*5000 + (n-x-y)*1000:
            a = x
            b = y
            c = n-x-y
            break
    else:
        continue
    break

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

Solution (Python):
n, y = map(int, input().split())
ans = [-1, -1, -1]

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:
            ans[:] = [i, j, k]

print(str(ans[0])+' '+str(ans[1])+' '+str(ans[2]))

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

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

x = y = z = -1

for a in range(0, n+1):
    for b in range(0, n + 1 - a):
        num = n - a - b
        if (10000*a + 5000*b + 1000*num) == yen:
            x = a
            y = b
            z = num
            break

print(x, y, z)

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

for a in range(n+1):
    for b in range(n+1):
        c = n - a - b
        x = 10000*a + 5000*b + 1000*c
        if x == y and c >=0:
            print("{} {} {}".format(a,b,c))
            d =1
            break
    else:
        continue
    break



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

print("-1 -1 -1")

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MAX = 10**18
MIN = -10**18
MOD = 998244353

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

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

Solution (Python):
n, a = 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) == a:
        print("{} {} {}".format(x,y,(n-x-y)))
        exit()

print("-1", "-1", "-1")

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

Solution (Python):
n,y = map(int,input().split())
z= y//1000
a = 0
if z != y/1000:
  print(-1,-1,-1)
  exit()
  
for i in range(n+1):
  for j in range(n+1-i):
    k = n-i-j
    if k + 5*j + 10*i == z:
      print(i,j,k)
      exit()
    
      
  
print(-1,-1,-1)

Solution (Python):
n,Y = map(int,input().split())
y2 = Y // 1000
for a in range(n+1):
    y = y2
    rest = y - a * 10
    if rest < 0:break
    for b in range(n+1-a):
        if rest -b * 5 < 0: break
        if n - a - b == rest - b * 5:
            print(a,b,n-a-b);exit()
print(-1,-1,-1)

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

for i in reversed(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,j,k)
            quit()

print(-1,-1,-1)

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

found = False

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('{} {} {}'.format(i, j, k))
            found = True
            break
    else:
        continue
    break

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

Solution (Python):

def solve():

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

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

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

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

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

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

found = False
for i in range(N+1):
    for j in range(N+1-i):
        k = N - (i + j)
        otoshidama = 10000*i + 5000*j + 1000*k
        if otoshidama == Y:
            print(i, j, k)
            found = True
            break
    if found: break

if not found: print(-1, -1, -1)

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

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

num_max_10k = total // 10000

for num_10k in range (0, num_max_10k + 1):
    for num_5k in range(0, (n - num_10k) + 1):
        if (num_10k + num_5k >= n):
            num_1k = 0
        else:
            num_1k = n - (num_10k + num_5k)

        
        if (total == (num_10k * 10000 + num_5k * 5000 + num_1k * 1000)):
            x, y, z = num_10k, num_5k, num_1k

print(x, y, z, sep=" ")

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

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

for x_tmp in range(0, n + 1):
    for y_tmp in range(0, (n - x_tmp) + 1):
        z_tmp = n - (x_tmp + y_tmp) if n >= (x_tmp + y_tmp) else 0
        if total == (x_tmp * 10000 + y_tmp * 5000 + z_tmp * 1000):
            x, y, z = x_tmp, y_tmp, z_tmp

print(x, y, z, sep = " ")

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

Solution (Python):

import sys
import collections

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Y = map(int, readline().split())
assert Y % 1000 == 0
Y //= 1000


def solve():
    for x1 in range(N + 1):
        for x2 in range(N - x1 + 1):
            x3 = N - x1 - x2
            if 10 * x1 + 5 * x2 + 1 * x3 == Y:
                print(x1, x2, x3)
                return
    print(-1, -1, -1)


if __name__ == "__main__":
    solve()

Solution (Python):

import sys
import collections

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Y = map(int, readline().split())
assert Y % 1000 == 0
Y //= 1000


def solve2():
    for x1 in range(N + 1):
        for x2 in range(N - x1 + 1):
            x3 = N - x1 - x2
            if 10 * x1 + 5 * x2 + 1 * x3 == Y:
                print(x1, x2, x3)
                return
    print(-1, -1, -1)



if __name__ == "__main__":
    solve2()

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

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

print('-1 -1 -1')