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())
X = Y // 1000
check = 0
for a in range(X // 10 + 1):
    for b in range(X // 5 + 1):
        c = N - a - b
        Z = 10 * a + 5 * b + c
        if c >= 0 and X == Z:
            check = 1
            break
    if check == 1:
        break
if check == 0:
    print(-1,-1,-1)
else:
    print(a,b,c)

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

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

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

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

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

Solution (Python):
def otoshidama(N,Y):
    a = min(N,Y//10000) + 1
    l = -1
    m = -1
    n = -1
    for x in range(a):
        b = min(N - x,(Y - 10000*x)//5000) + 1
        for y in range(b):
            if (N - x - y)*1000 == Y - 10000*x - 5000*y:
                l = x
                m = y
                n = N - x - y
    print(l,m,n)

s = list(map(int,input().split()))
N = s[0]
Y = s[1]
otoshidama(N,Y)

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

a = -1
b = -1
c = -1
n1 = min(y // 10000, n)
n2 = min(y // 5000, n)
for i in range(n1+1):
    for j in range(n2+1-i):
        money = 10000 * i + 5000 * j + 1000 * (n - i - j)
        if y == money:
            a = i
            b = j
            c = n - i - j
            break;


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

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-i):
        money = 10000 * i + 5000 * j + 1000 * (n - i - j)
        if y == money:
            a = i
            b = j
            c = n - i - j
            

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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

for x in range(0, N + 1):
    for y in range(0, N - x + 1):
        z = N - x - y
        otoshi = 10000 * x + 5000 * y + 1000 * z
        if otoshi == Y:
            print(x, y, z)
            quit()
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 = (Y - 10000 * x - 5000 * y) / 1000
        if x + y + z == n and z >= 0 and z.is_integer():
            print(x, y, int(z))
            exit()
print("-1 -1 -1")

Solution (Python):
import sys

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

for x in range(n + 1):
    for y in range(n + 1):
        z = (Y - 10000 * x - 5000 * y) / 1000
        if x + y + z == n and z >= 0 and z.is_integer():
            print(x, y, int(z))
            sys.exit()
print("-1 -1 -1")

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



flg = False
loopCnt = 0
for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z
        if total == Y and z >= 0:
            print(x, y ,z)
            loopCnt += 1
            flg = True
            break
    if flg:
        break    

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

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

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 y == i*10000+j*5000+k*1000 and k >= 0:
            print(i,j,k)
            exit()
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 10000*x+5000*y+1000*z==Y:
      ans=[x,y,z]
print(ans[0],ans[1],ans[2])

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

Solution (Python):













def main():
    
    N,Y = map(int, input().split())
        
    
    m_man = Y // 10000
    for x in range(m_man, -1, -1):
        
        m_gosen = (Y - 10000*x) // 5000

        for y in range(m_gosen, -1, -1):
            
            z = (Y - 10000*x - 5000*y) // 1000
            
            
            
            if x + y + z == N:
                
                print('{} {} {}'.format(x, y, z))
                quit()
                
            
            
            
            
            
            
            
    
    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):
        if i*1000 + j*5000 + (N-i-j)*10000 == Y:
            print(N-i-j,j,i)
            exit(0)

print(-1,-1,-1)

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

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

x, y, z = -1, -1, -1
for a in range(N+1):
  for b in range(N-a+1):
    c = N - a - b
    X = 10000*a + 5000*b + 1000*c
    if X == Y:
      x, y, z = a, b, c
      break
print(x, y, z)

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




def judge(n, target):
    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 == target:
                return '{} {} {}'.format(x, y, z)
    return '-1 -1 -1'


print(judge(N, Y))

Solution (Python):
a = input().split()
N = int(a[0])
Y = int(a[1])
shA = -1
shB = -1
shC = -1
for A in range(N+1):
  for B in range(N+1-A):
    C = N - A - B
    total = 10000 * A + 5000 * B + 1000 * C
    if total == Y:
      shA = A
      shB = B
      shC = C
print(str(shA) + " " + str(shB) + " " + str(shC))

Solution (Python):
N,Y = map(int,input().split())
result = [-1]*3
for i in range(N+1):
    for j in range(N-i+1):
        money = i * 10000 + j * 5000 + (N-i-j)*1000
        if money == Y :
            result = [i,j,(N-i-j)]
            break

print(*result)

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

Solution (Python):

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

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

print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
Y /= 1000
x = 10
y = 5
z = 1
for i in range(N+1):
    for j in range(N+1):
        if x*i+y*j+(N-i-j) == Y and i+j <= N:
            print(i, j, N-i-j)
            exit()
print(-1, -1, -1)

Solution (Python):
def main():
    N, Y = map(int, input().split())
    
    num10000, num5000, num1000 = 0, 0, 0
    flag = False

    for i in range(N+1):
        for j in range(N+1-i):
            k = N - i - j
            total = 10000*i + 5000*j + 1000*k
            if total == Y and i+j+k == N :
                num10000, num5000, num1000 = i, j, k
                flag = True
                break

    if(not flag):
        num10000, num5000, num1000 = -1, -1, -1

    print('{} {} {}'.format(num10000, num5000, num1000))

if __name__ == '__main__':
    main()

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

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

ans=False
for x in range(n+1):
    for y in range(n+1):
        if Y-10*x-5*y==n-x-y and (n-x-y)>=0:
            ans=True
            break
    if ans==True:
        break

if ans is True:
    print(x,y,n-x-y)
else:
    print(-1,-1,-1)

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

Solution (Python):
N, Y = map(int, input().split())
flag = False
res = []
for x in range(N + 1):
    for y in range(N + 1 -x):
        z = N - x -y
        sum_m = (10000*x) + (5000*y) + (1000*z)
        if sum_m == Y:
            flag = True
            res = [x, y, z]

if flag == False:
    print(-1, " ", -1, " ", -1)
else:
    print(res[0]," " ,res[1]," ", res[2])

Solution (Python):
number,money=input().rstrip().split()
number=int(number)
money=int(money)
bill=[0,0,0]

for i in range(number+1):
    bill=[0,0,0]
    mass=money-10000*i
    bill[0]=i
    if mass==0 and sum(bill)==number:
        break
    elif mass<0:
        break
    else:
        for j in range(number+1-i):
            if j!=0:
                mass=mass-5000
            bill[1]=j
            if mass==0 and sum(bill)==number:
                break
            elif mass<0:
                break
            else:
                k=int(mass/1000)
                bill[2]=k
                if sum(bill)==number:
                    break
    if sum(bill)==number:
        mass=0
        break
                
if mass==0:
    print(str(bill[0])+' '+str(bill[1])+' '+str(bill[2]))
else:
    print(str(-1)+' '+str(-1)+' '+str(-1))

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

print(-1, -1, -1)

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

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

print(-1, -1, -1)

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

print("{} {} {}".format(-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, sum = 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 == sum and z >= 0:
                break
        else:
            continue
        break
    else:
        continue
    break
else:
    x, y, z = -1, -1, -1


print("{} {} {}".format(x, y, z))

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

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

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

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

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

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

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

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

Solution (Python):
N,yen=map(int,input().split())
count=0
end=0
man=0
gosen=0
sen=0



for i in range(N+1):
    if end==1:
        break
    for j in range(N-i+1):
        
        
        k=N-i-j
        
        sum=i*10000+j*5000+k*1000
        
        if sum==yen:
            man=i
            gosen=j
            sen=k
            end=1
            break

if man==0 and gosen==0 and sen==0:
    print("-1 -1 -1")
else:
    print(str(man)+" "+str(gosen)+" "+str(sen))

Solution (Python):

import sys

def resolve():
    input = sys.stdin.readline
    N,Y=map(int,input().split())
    
    
    
    if (10000*N<Y):
        print("-1 -1 -1")
        return

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

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """9 45000"""
        output = """4 0 5"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """20 196000"""
        output = """-1 -1 -1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """1000 1234000"""
        output = """14 27 959"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """2000 20000000"""
        output = """2000 0 0"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

Solution (Python):
N, Y = list(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:
            continue
        
        total = i*10000 + j*5000 + k*1000
        if total == Y:
            a = i
            b = j
            c = k

print(str(a) + ' ' + str(b) + ' '  + str(c))

Solution (Python):
N,Y = map(int,input().split())
A,B,C = -1,-1,-1
flag = False
for i in range(N+1):
    if flag:
        break
    for j in range(N+1-i):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y and (N-i-j) >= 0:
            A,B,C = i,j,(N-i-j)
            flag = True
            break
print(A,B,C)

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

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

print(x, y, z)

Solution (Python):
N,Y=map(int, input().split())
result = ["-1","-1","-1"]
for i in range(N+1):
    for j in range(N-i+1):
        k = N - (i + j) 
        x = 10000 * i + 5000 * j + 1000 * k
        if Y == x:
            result = [str(i), str(j), str(k)]
            break
print(" ".join(result))

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
p = [-1, -1, -1]
for i in range(N + 1):
  s = 0
  for j in range(N - i + 1):
    if 9 * i + 4 * j == Y - N:
      p = [i, j, N - i - j]
      s += 1
      break
  if s == 1:
    break
print(p[0], p[1], p[2])

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

ans = [-1,-1,-1]
for a in range(N+1):
    for b in range(N+1-a):
        c = N-a-b
        if Y == 10000*a+5000*b+1000*c:
            ans = [a,b,c]
            break

print(*ans)

Solution (Python):
input_num = [int(s) for s in input().split()]
N = input_num[0]
Y = input_num[1]
flag = False
result = str(-1) + str(' ') + str(-1) + str(' ') + str(-1)

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:
      result = str(x) + str(' ') + str(y) + str(' ') + str(z)
      flag = True
      
print(result)

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

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

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

max_yukiti = y // 10000
flag = False
for i in range(max_yukiti + 1):
    for j in range(n+1):
        k = n - i - j
        
        if k < 0:
            break
        if 10000 * i + 5000 * j + 1000 * k == y:
            print(i,j,k)
            sys.exit()
if ~flag:
    print(-1,-1,-1)

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

ans = []
for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            ans.append([i, j, N-i-j])

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

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

ans = []
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)
            sys.exit()
print(-1, -1, -1)

Solution (Python):


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

_10000 = 10000
_5000 = 5000
_1000 = 1000

_sum = 0
ans = [-1, -1, -1]

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

_ans = [str(s) for s in ans]
__ans = ' '.join(_ans)
print(__ans)

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

    m_man = Y // 10000

    for x in range(m_man, -1, -1):
        m_gosen = (Y - 10000*x) // 5000
        
        for y in range(m_gosen, -1, -1):
            z = (Y - 10000*x - 5000*y) // 1000
            
            if x + y + z == N:
                print('{} {} {}'.format(x, y, z))
                quit()
    
    print('-1 -1 -1')

if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
n,y=map(int,input().split())
y//=1000
for i in range(n+1):
    for j in range(n-i+1):
        if 9*i+4*j==y-n:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Solution (Python):

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

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

print("-1 -1 -1")

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

print(-1, -1, -1)

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

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

print(-1,-1,-1)

Solution (Python):
n, k = map(int, input().split())
for x in range(n+1):
    for y in range(n+1):
        if x + y <= n:
            z = n - x - y
            result = 10000*x + 5000*y + 1000*z
            if result == k:
                print("{} {} {}".format(x, y, z))
                exit()
print("-1 -1 -1")

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

Solution (Python):
import sys

N, Y = list(map(int , input().split()))
for x in range(N+1):
    for y in range(N+1):
        z = N - x-  y
        if z >=0:
            if 10000*x+5000*y+1000*z ==Y:
                print('{} {} {}'.format(x,y,z))
                sys.exit()
print('-1 -1 -1')

Solution (Python):
N,Y=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
print(a,b,c)

Solution (Python):
N,Y=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
print(a,b,c)

Solution (Python):


import sys

N, Y = (int(i) for i in 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(str(x) + " " + str(y) + " " + str(z))
			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 y == i*10000+j*5000+k*1000:
        print("{} {} {}".format(i,j,k))
        exit(0)

print("-1 -1 -1")

Solution (Python):
import sys


def solve(inp):
    (N, Y) = map(int, inp.readline().split(' '))

    for a in range(N + 1):
        for b in range(N + 1 - a):
            c = max(0, N - (a + b))
            if a * 10 + b * 5 + c * 1 == Y / 1000:
                return "{} {} {}".format(a, b, c)

    return "-1 -1 -1"


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Solution (Python):
def check_kingaku(maisu, kingaku):
    if(maisu*10000<kingaku):
        return "-1 -1 -1"
    for itr_1000 in range(maisu+1):
        for itr_5000 in range(maisu-itr_1000+1):
            itr_10000 = maisu - itr_1000 - itr_5000
            target = 1000*itr_1000 + 5000*itr_5000 + 10000*itr_10000
            if(target == kingaku):
                return str(itr_10000) + " " + str(itr_5000) + " " + str(itr_1000)
    return "-1 -1 -1"

maisu, kingaku = [int(x) for x in input().split()]
ret = check_kingaku(maisu, kingaku)
print(ret)

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

for i in reversed(range(y//10000 + 1)):
	res = y - 10000 * i
	for j in reversed(range(res//5000 + 1)):
		k = n - (i + j)
		if 1000 * k + 5000 * j == y - 10000 * i:
			print(str(i) + ' ' + str(j) + ' ' + str(k))
			break
		elif i == 0  and j == 0:
			print('-1 -1 -1')
	else:
		continue
	break

Solution (Python):
t=input()
N=int(t.split()[0])
Y=int(t.split()[1])

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

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

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

for m in range(N+1):
    for g in range(N-m+1):
        s = N - m - g
        if Y == 10000*m + 5000*g + 1000*s:
            print(m, g, s)
            sys.exit()

print(-1, -1, -1)

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



search_flag = 0
count_10k = 0
count_5k = 0
count_1k = 0

for count_10k in range(N+1):
    for count_5k in range(N-count_10k+1):
        count_1k = N - count_10k - count_5k
        if count_10k * 10000 + count_5k * 5000 + count_1k * 1000 == Y:
            print(str(count_10k) + ' ' + str(count_5k) + ' ' + str(count_1k))
            search_flag = 1
            break
    else:
        continue
    break

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

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

Solution (Python):
n, y = map(int, input().split())
y //= 1000
D = y-n
for a in range(D//9 + 1):
  D2 = D-9*a
  if D2%4:
    continue
  else:
    b = D2//4
    if n-a-b >= 0:
      print(a, b, (n-a-b))
      exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())
Y2 = Y // 1000
mod5 = Y2 % 5
div5 = Y2 // 5
for c_div5 in range(div5 + 1):
    c = c_div5 * 5 + mod5
    a = (Y2 - c) // 5 - (N - c)
    b = N - a - c
    if a >= 0 and b >= 0: break
    if c_div5 == div5: a=-1;b=-1;c=-1
print(a, b, c)

Solution (Python):
N, Y = map(int, input().split())
Y2 = Y // 1000
mod5 = Y2 % 5
div5 = Y2 // 5
for c_div5 in range(div5 + 1):
    c = c_div5 * 5 + mod5
    a = (Y2 - c) // 5 - (N - c)
    b = N - a - c
    if a >= 0 and b >= 0: break
    if c_div5 == div5: a=-1;b=-1;c=-1
print(a, b, c)

Solution (Python):
n,y=map(int,input().split())
flag=False
for i in range(min(n+1,y//10000+1)):
    for j in range(min(n-i+1,(y-10000*i)//5000+1)):
        if y-10000*i-5000*j==1000*(n-i-j):
            print(i,j,n-i-j)
            flag=True
            break
    if flag:
        break
if not flag:
    print(-1,-1,-1)

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

for i in range(n):
    x=Y%5
    x+=i*5

    Y_dash = (Y-x)//5
    n_dash = n-x

    y=2*n_dash-Y_dash
    z=Y_dash-n_dash
    if x>=0 and y>=0 and z>=0:
        break

if x>=0 and y>=0 and z>=0:
    print(z,y,x)
else:
    print(-1,-1,-1)

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

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

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

print(-1,-1,-1)

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

for i in range(n+1):
    ai=10000*i
    if ai > y: continue
    else:
        for j in range(n+1-i):
            bj=5000*j
            if ai + bj > y :break
            else : 
                k=n-i-j
                if  ai + bj + 1000*k == y:
                    is_none=False
                    break
        if not is_none:break

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

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

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

for a in range(n+1):
    for b in range(n-a+1):
        c = n-a-b
            
        if(10000*a + 5000*b + 1000*c == y):
            print(a, b, c)
            quit()

print("-1 -1 -1")

Solution (Python):

import sys

def solve(N: int, Y: int):
    for i in range(Y//10000+1):
        for j in range(Y//5000+1):
            if i+j>N:
                break
            if 10000*i+5000*j+1000*(N-i-j) == Y:
                print(i,j,N-i-j)
                return

    print(-1,-1,-1)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)

if __name__ == '__main__':
    main()

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

flag=0
for x in range(ny[0]+1):
    if flag==0:
        for y in range(ny[0]+1-x):
            z=ny[0]-x-y
            if x*10000+y*5000+z*1000==ny[1]:
                flag=1
                break
    else:
        x-=1
        break

if flag==1:
    print(x,y,z)
else:
    print(-1,-1,-1)

Solution (Python):
li=list(map(int,input().split()))
n=li[0]
y=li[1]

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

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

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

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

print(-1,-1,-1)