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,yen = map(int,input().split())
key = False
for x in range(n+1):
    if key == True:
        break
    for y in range(n+1):
        z = n - x - y
        if z >= 0:
            if 10000*x + 5000*y + 1000*z == yen:
                print(x,y,z)
                key = True
                break
                
if key == False:
    print(-1,-1,-1)

Solution (Python):
N,Y = map(int,input().split())
hantei = 0
for i in range(N+1):
  for j in range(N-i+1):
    if Y==i*10000+j*5000+(N-i-j)*1000 and N-i-j>=0:
      ans=[i,j,N-i-j]
      hantei +=1
if hantei == 0:
  print('-1 -1 -1')
else:
  print(ans[0],ans[1],ans[2])

Solution (Python):

N , Y = map(int,input().split())
z = 0
for i in range(N+1):
    rest = Y - 10000 * i
    for j in range(N+1-i):
        if rest < 0:
            break
        rest1 = rest - (5000 * j) -(1000 * (N-i-j))
        if rest1 == 0:
            print(i, j, N-i-j)
            z = 1
        if z == 1:
            break
    if z == 1:
        break
if z == 0:
    print("-1 -1 -1")

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

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

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

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

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

Solution (Python):
N, Y = [int(i) for i in input().split()]
x, y, z = -1, -1, -1
for a in range(N + 1):
    for b in range(N + 1):
        c = N - a - b
        if 0 <= c and c <= N and a * 10000 + b * 5000 + c * 1000 == Y:
            x, y, z = a, b, c
            break
    else:
        continue
    break
print(x, y, z)

Solution (Python):

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

for man in range(N+1):
    for gosen in range(N+1):
        sen = (Y - 10000 * man - 5000 * gosen) / 1000
        if sen >= 0 and sen <= N and man + gosen + sen == N:
            print("{} {} {}".format(man, gosen, int(sen)))
            findflag = 1
            
        if findflag == 1:
            break
        
    if findflag == 1:
        break

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

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

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

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

Solution (Python):
import sys
n,y = map(int,input().split())
 
ans = 0
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(str(i)+" "+str(j)+" "+str(k))
            sys.exit()
print("-1 -1 -1")

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

flag = False
for i in range(N + 1):  
    for j in range(N + 1):  
        k = N - i - j  
        if 0 <= k <= N and Y == i * 1000 + j * 5000 + k * 10000:
            flag = True
            print(k, j, i)
            break
    if flag:
        break
else:
    print("-1 -1 -1")

Solution (Python):
def pay(i: int, remain: int, z: int):
    for i in range(0, (n - z) + 1):
        if 10 * i + 5 * (remain - i) + z == m:
            print(i, remain - i, z)
            exit()

    return


n, M = list(map(int, input().split(" ")))
m = int(M / 1000)

for z in range(n, -1, -1):
    pay(0, n - z, z)

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 (a * 10000) + (b * 5000) + (c * 1000) == Y:
      print(a, b, c)
      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 10000*a + 5000*b + 1000*c == y and a+b+c == n and c >= 0:
      print(a,b,c)
      exit()
print("-1 -1 -1")

Solution (Python):
import sys


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

k_max = Y//10000

for k in range(k_max+1):
    for j in range(N-k+1):
        if 0 <= N-j-k == (Y - 5000*j - 10000*k)/1000:
            print(k, j, N-j-k)
            sys.exit()

print(-1, -1, -1)

"""
1000*i + 5000*j + 10000*k = Y
i = (Y - 5000*j - 10000*k) / 1000
i = N - j - k
"""

Solution (Python):
N,Y = map(int,input().split())
def find(N,Y):
  for xi in range(N+1):
    for yi in range(N+1):
      zi = N - xi - yi
      s = xi*10000 + yi*5000 + zi*1000      
      if s == Y and (xi+yi+zi)<=N and zi>=0 :
        print("{} {} {}".format(xi,yi,zi))
        return
      if s > Y:
        break
  print("-1 -1 -1")
  
find(N,Y)

Solution (Python):
n,y=map(int,input().split())
y//=1000
y-=n
i=0
while 9*i<=y:
    a=y-9*i
    if a%4==0:
        j=a//4
        if n-i-j>=0:
            print(str(i)+" "+str(j)+" "+str(n-i-j))
            break
    i+=1
else:
    print(str(-1)+" "+str(-1)+" "+str(-1))

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

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

Solution (Python):
N,Y = map(int,input().split())
def find(N,Y):
  for xi in range(N+1):
    for yi in range(N+1):
      zi = N - xi - yi
      s = xi*10000 + yi*5000 + zi*1000      
      if s == Y and (xi+yi+zi)<=N and zi>=0 :
        print("{} {} {}".format(xi,yi,zi))
        return
      if s > Y:
        break
  print("-1 -1 -1")
  
find(N,Y)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

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

if __name__ == "__main__":
    main()

Solution (Python):
import math
import sys
n,total = map(int, input().split())
count = 0

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

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

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

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

def cal():
	for i in range(N + 1):
		for j in range(N + 1 - i):
			senyen = N - i - j
			if senyen < 0: continue
			if 10000 * i + 5000 * j + 1000 * senyen == Y:
				return [i, j, senyen]
			elif 10000 * i + 5000 * j + 1000 * senyen > Y:
				break
	return [-1, -1, -1]
	
ans = cal()
print(*ans)

Solution (Python):
import sys
n, y = map(int, input().split())
count = 0
for i in range(n+1):
    for j in range(n-i+1):
        z = n - i - j
        if y == 10000 * i + 5000 * j + 1000 * z:
            print(i, j, 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 - 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):
x = [int(i) for i in input().split()]

def fun(x):
  for i in range(x[0] + 1):
    for l in range(x[0] - i + 1):
      n = x[0] - (i + l)
      tmp = (10000*i) + (5000*l) + (1000*n)
      if tmp == x[1]:
        return i,l,n
  else:
    return -1,-1,-1
    
a,b,c = fun(x)
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):
        if (Y - 10000*i - 5000*j) % 1000 == 0 and (Y - 10000*i - 5000*j) / 1000 == N-i-j:
            print(i, j, N-i-j)
            exit()
print(-1, -1, -1)

Solution (Python):

N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N + 1 - i):
        if (Y - 10000*i - 5000*j) % 1000 == 0 and (Y - 10000*i - 5000*j) / 1000 == N-i-j:
            print(i, j, N-i-j)
            
            exit()
            
print(-1, -1, -1)

Solution (Python):
n,y=map(int,input().split())
for i in range(n+1):
 for j in range(n-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):
def main():
    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:
                cst = 10000 * i + 5000 * j + 1000 * k
                if cst == Y:
                    a, b, c = i, j, k

    print(a,b,c)

if __name__ == "__main__":
    main()

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:
            cst = 10000 * i + 5000 * j + 1000 * k
            if cst == Y:
                a, b, c = i, j, k

print(a,b,c)

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


is_match = 0

for i in range(N + 1):
    if is_match == 1:
        break

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

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

Solution (Python):
n, y = map(int, open(0).read().split())

for a in range(0, n+1):
    for b in range(0, n-a+1):
        c = n - a - b
        if a*10000 + b*5000 + c*1000 == y:
            print(a, b, c)
            import sys
            sys.exit(0)

print('-1 -1 -1')

Solution (Python):



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


ans = [-1] * 3
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:
            ans = [x, y, z]
            break


print(*ans)

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

Solution (Python):
import sys

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

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

print(-1,-1,-1)

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

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

Solution (Python):
import sys
import math

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

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

Solution (Python):
import sys
n, y = map(int, input().split())
dp = [[None for j in range(n+1)] for i in range(n+1)]

if y / n > 10000:
    print('-1 -1 -1')
    sys.exit()





for i in range(n+1):
    if i > n or i * 10000 > y:
        break
    for j in range(n+1):
        if i + j > n or i * 10000 + j * 5000 > y:
            break
        
        z = n - i - j

        
        
        if i * 10000 + j * 5000 + z * 1000 == y:
            print(i, j, z)
            sys.exit()

print('-1 -1 -1')

Solution (Python):
import sys

stdin = sys.stdin

na = lambda: list(map(int, ns().split()))
ns = lambda: stdin.readline()

N, Y = na()

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

print(ans)

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

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

S=Y//1000-N
count=0
for x in range(N+1):
    if (S-9*x)%4==0 and (S-9*x)//4>=0 and N-x-(S-9*x)//4>=0:
        y=(S-9*x)//4
        z=N-y-x
        count=1
        break
if count==1:
    print(str(x)+' '+str(y)+' '+str(z))
else:
    print(str(-1)+' '+str(-1)+' '+str(-1))

Solution (Python):
n, y = map(int, input().split())
k = y//1000
candidate = []

for i in range(n+1):
    for j in range(n+1-i):
        if 9*i + 4*j == k-n:
            candidate.append((i, j))

for cand in candidate:
    i, j = cand[0], cand[1]
    if n-i-j>=0:
        t = n-i-j
        print(i, j, t)
        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-a):
    if a*10000+b*5000+(n-a-b)*1000==y:
      print(str(a)+" "+str(b)+" "+ str(n-a-b))
      exit()
print("-1 -1 -1")

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

aa=-1
bb=-1
cc=-1

for a in range(n+1):
	for b in range(n+1):
		c=n-a-b
		if (c>=0)&(y==10000*a+5000*b+1000*c):
			aa=a
			bb=b
			cc=c
			break

print('{} {} {}'.format(aa,bb,cc))

Solution (Python):
n, y = map(int, input().split())
y /= 1000
res10, res5, res1 = -1, -1, -1
for a in range(n+1):
  if res1 != -1:
    break
  for b in range(n-a+1):
    c = n - a - b
    total = 10*a + 5*b + c
    if total == y:
      res10, res5, res1 = a, b, c
    if res1 != -1:
      break
print(str(res10) + " " + str(res5) + " " + str(res1))

Solution (Python):
n, y = map(int, input().split())
res10000, res5000, res1000 = -1, -1, -1
for a in range(n+1):
  if res10000 != -1:
    break
  for b in range(n-a+1):
    c = n - a - b
    total = 10000*a + 5000*b + 1000*c
    if total == y:
      res10000, res5000, res1000 = a, b, c
    if res10000 != -1:
      break
print(str(res10000) + " " + str(res5000) + " " + str(res1000))

Solution (Python):
n, y = map(int, input().split())
res10000, res5000, res1000 = -1, -1, -1
for i in range(n+1):
  if res10000 != -1:
    break
  for j in range(n-i+1):
    if res10000 != -1:
      break
    a = i
    b = j
    c = n - a - b
    total = 10000*a + 5000*b + 1000*c
    if total == y:
      res10000, res5000, res1000 = a, b, c
     
    

print(str(res10000) + " " + str(res5000) + " " + str(res1000))

Solution (Python):
n, y = map(int, input().split())
res10000, res5000, res1000 = -1, -1, -1
for i in range(n+1):
  if res10000 != -1:
    break
  for j in range(n-i+1):
    a = i
    b = j
    c = n - a - b
    total = 10000*a + 5000*b + 1000*c
    if total == y:
      res10000, res5000, res1000 = a, b, c
     
    if res10000 != -1:
      break

print(str(res10000) + " " + str(res5000) + " " + str(res1000))

Solution (Python):
n,y=map(lambda x: int(x), input().split())
r1=-1
r2=-1
r3=-1
find=False
for i in range(n+1):
    if find==True:
        break
    for j in range(n-i+1):
        if find==True:
            break
        if i*10000+j*5000+(n-i-j)*1000==y:
            r1=i
            r2=j
            r3=n-i-j
print('{} {} {}'.format(r1,r2,r3))

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

y = y//1000

for a in range(n+1):
	for b in range(0,n+1-a):
		c = n - (a+b)
		if y == 10*a + 5*b + c:
			print(a,b,c)
			exit()


print("-1 -1 -1")

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


import sys


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

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

Solution (Python):
num, yen = map(int ,input().split())
yen /= 1000
for i in range(num + 1):
    for j in range(num + 1 -i):
        k = num - i - j
        if 10 * k + 5 * j + i * 1 == yen:
            print(k,j,i)
            exit()
print(-1, -1, -1)

Solution (Python):
mai,yen=map(int,input().split())
for i in range(mai+1):
  for j in range(mai+1-i):
    if 10000*i+5000*j+1000*(mai-i-j)==yen:print(i,j,mai-i-j);exit()
else:print(-1,-1,-1)

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

Y = Y//1000
for i in range(N+1):
    for j in range(N-i+1):
        if Y == i*9 + j*4 +N:
            a = i
            b = j
            c = N-i-j
            
            break
        else:
            continue
        break
        
          
print(a, b, c , sep=(' '))

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

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

print("-1 -1 -1")

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

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

Solution (Python):
N, Y = map(int, input().split())
for x in range(N + 1):
  for y in range(N - 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,y=map(int, input().split()) 

flag = False
for i in range(0,n+1):
  if not flag:
    for j in range(0,n-i+1):
      if (10000*i + 5000*j + 1000*(n-i-j))==y:
        print('{} {} {}'.format(i,j,n-i-j))
        flag = True
        break
      
if not flag:
  print(*[-1, -1, -1])

Solution (Python):
def test():
    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)
                    return
    print("-1 -1 -1")


if __name__ == "__main__":
    test()

Solution (Python):
import sys

def solve(N: int, Y: int):
    max_i = int(Y//10000)
    for i in range(0,max_i+1):
        for j in range(N-i+1):
            k = N-i-j
            if 10000*i+5000*j+1000*k == Y:
                print(i,j,k)
                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):
import sys


def solve(N: int, Y: int):
    for i in range(0,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)
                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):
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):
import sys
N, Y = map(int, input().split())

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

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

Solution (Python):
def abc_exp(a,b,c):
	print(str(a) + ' ' + str(b) + ' ' + str(c) )
	
def exchange(a,b,remain):
	while True:
		if remain >= 4 and a - 4 >= 0:
			b = b + 8
			a = a - 4
			remain = remain - 4
		else: 
			break
	return a,b
	

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

a = int(Y/10000)
b = int((Y - a * 10000)/5000)
c = int((Y - a * 10000 - b * 5000)/1000)

max_bills = int(Y/1000)

if (max_bills < N) or (N < a + b + c):
	print('-1 -1 -1')
	
else:
	remain = N - a - b - c
	a = a - (remain % 4)
	b = b + 2 * (remain % 4)
	a , b = exchange(a,b,remain)
	remain = N - a - b - c
	
	if b - remain/4 >= 0:
		b = b - int(remain / 4)
		c = c + int(remain / 4) * 5
		abc_exp(a,b,c)
	
	else:
		print('-1 -1 -1')

Solution (Python):
def abc_exp(a,b,c):
	print(str(a) + ' ' + str(b) + ' ' + str(c) )
	
def exchange(a,b,remain):
	while True:
		if remain >= 4 and a - 4 >= 0:
			b = b + 8
			a = a - 4
			remain = remain - 4
		else: 
			break
	return a,b
	

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

a = int(Y/10000)
b = int((Y - a * 10000)/5000)
c = int((Y - a * 10000 - b * 5000)/1000)

max_bills = int(Y/1000)

if (max_bills < N) or (N < a + b + c):
	print('-1 -1 -1')
	
else:
	remain = N - a - b - c
	a = a - (remain % 4)
	b = b + 2 * (remain % 4)
	
	a , b = exchange(a,b,remain)
	remain = N - a - b - c
	if b - remain/4 >= 0:
		b = b - int(remain / 4)
		c = c + int(remain / 4) * 5
		abc_exp(a,b,c)
	
	else:
		print('-1 -1 -1')

Solution (Python):
def abc_exp(a,b,c):
	print(str(a) + ' ' + str(b) + ' ' + str(c) )
	
def exchange(a,b,remain):
	while True:
		if remain >= 4 and a - 4 >= 0:
			b = b + 8
			a = a - 4
			remain = remain - 4
		else: 
			break
	return a,b
	

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

a = int(Y/10000)
b = int((Y - a * 10000)/5000)
c = int((Y - a * 10000 - b * 5000)/1000)

max_bills = int(Y/1000)

if (max_bills < N) or (N < a + b + c):
	print('-1 -1 -1')
	
elif (N == max_bills):
	print('0 0 ' + str(max_bills))
	
else:
	remain = N - a - b - c
	a = a - (remain % 4)
	b = b + 2 * (remain % 4)
	
	a , b = exchange(a,b,remain)
	remain = N - a - b - c
	if b - remain/4 >= 0:
		b = b - int(remain / 4)
		c = c + int(remain / 4) * 5
		abc_exp(a,b,c)
	
	else:
		print('-1 -1 -1')

Solution (Python):
def abc_exp(a,b,c):
	print(str(a) + ' ' + str(b) + ' ' + str(c) )
	
def exchange(a,b,remain):
	while True:
		if remain >= 4 and a - 4 >= 0:
			b = b + 8
			a = a - 4
			remain = remain - 4
		else: 
			break
	return a,b
	

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

a = int(Y/10000)
b = int((Y - a * 10000)/5000)
c = int((Y - a * 10000 - b * 5000)/1000)

max_bills = int(Y/1000)

if (max_bills < N) or (N < a + b + c):
	print('-1 -1 -1')
	
elif (N == max_bills):
	print('0 0 ' + str(max_bills))
	
elif (N == a + b + c):
	abc_exp(a,b,c)

else:
	remain = N - a - b - c
	a = a - (remain % 4)
	b = b + 2 * (remain % 4)
	
	a , b = exchange(a,b,remain)
	remain = N - a - b - c
	if b - remain/4 >= 0:
		b = b - int(remain / 4)
		c = c + int(remain / 4) * 5
		abc_exp(a,b,c)
	
	else:
		print('-1 -1 -1')

Solution (Python):
def abc_exp(a,b,c):
	print(str(a) + ' ' + str(b) + ' ' + str(c) )
	
def exchange(a,b,remain):
	
	
	
	while True:
		if remain >= 4 and a - 4 >= 0:
			b = b + 8
			a = a - 4
			remain = remain - 4
		else: 
			break
	return a,b
	

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

a = int(Y/10000)
b = int((Y - a * 10000)/5000)
c = int((Y - a * 10000 - b * 5000)/1000)

max_bills = int(Y/1000)

if (max_bills < N) or (N < a + b + c):
	print('-1 -1 -1')
	
elif (N == max_bills):
	print('0 0 ' + str(max_bills))
	
elif (N == a + b + c):
	abc_exp(a,b,c)

else:
	remain = N - a - b - c
	if remain % 4 == 0:
		a,b = exchange(a,b,remain)
		remain = N - a - b - c
		if not b - remain/4 < 0:
			b = b - int(remain / 4)
			c = c + int(remain / 4) * 5
			abc_exp(a,b,c)
	
	else:
		a = a - (remain % 4)
		b = b + 2 * (remain % 4)
		a , b = exchange(a,b,remain)
		remain = N - a - b - c
		if b - remain/4 >= 0:
			b = b - int(remain / 4)
			c = c + int(remain / 4) * 5
			abc_exp(a,b,c)
		
		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-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())

ans = ["-1"]*3
for a in range(N+1):
    if a*10000 > Y:
        break
    else:
        for b in range(N+1):
            if Y == a*10000 + b*5000 + (N-a-b)*1000 and (N-a-b) >= 0:
                ans = [str(a), str(b), str(N-a-b)]
                break
                
print(" ".join(ans))

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())
ans=0
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:
            ans+=1
            print(i,j,n-i-j)
            break
    else:
        continue
    break
if ans==0:
    print('-1 -1 -1')

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



if Y%1000!=0:
  x = -1
  y = -1
  z = -1
else:
  under_ten_thouthand=Y%10000
  under_five_thouthand=under_ten_thouthand%5000
  z = int(under_five_thouthand/1000)
  y = int(under_ten_thouthand/5000)
  x = int(Y/10000)
  
  if x+y+z > N:
    x = -1
    y = -1
    z = -1
  else:
  
  
  
  
  
  
  
  
  
  
  

    
    if N - (x + y + z) >= 9:
      
      times = int( (N - (x + y + z)) / 9 )
      if x-times >=0:
        
        x = x - times
        z = z + times * 10
      

    
    if N - (x + y + z) >= 5:   
      
      times = int( (N - (x + y + z)) / 5 )
      if x-times >=0:
        
        x = x - times
        y = y + times
        z = z + times * 5
      

    
    if N - (x + y + z) >= 4:
      
      times = int( (N - (x + y + z)) / 4 )
      if y-times >=0:
        
        y = y - times
        z = z + times * 5
      

    
    if N - (x + y + z) != 0:
      
      times = int( N - (x + y + z))
      
      if x-times >= 0:
        x = x - times
        y = y + times*2
        
      else:
        x = -1
        y = -1
        z = -1
    
print(str(int(x))+" "+str(int(y))+" "+str(int(z)))

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

flag=0
for i in range(max(Y//10000, N) + 1):

    balance = Y - i*10000
    for j in range(max(balance//5000, N-i) +1):
        balance = Y - i*10000 - j*5000
        k = balance // 1000
        

        if (k+j+i)==N:
            flag=1
            break
    if flag==1:
        break


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

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

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

Ten=10000
Five=5000
One=1000

count=0

max_x=int(Y//Ten)

if max_x <= N:
	for i in reversed(range(0,max_x+1)):
		if count == 1:
			break
		elif count == 0:
			max_y = int((Y - Ten*i)//Five)
			if (max_y + i) <= N:
				for j in reversed(range(0, max_y+1)):
					if (Ten*i + Five*j + One*(N-i-j))==Y:
						x=i
						y=j
						z=N - i - j
						count+=1
						break

print(x, y, z)

Solution (Python):


N,Y=map(int,input().split())
man=Y//10**4

for i in range(man+1)[::-1]:
    temp=i
    yo=(Y-i*10**4)//10**3
    for j in range(yo//5+1):
        if (temp+j+yo-5*j)==N:
            print(temp,j,yo-5*j)
            exit()
            
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())
Y /= 1000
res10 = res5 = res1 = -1

for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if 10*x + 5*y + z == Y:
            res10 = x
            res5 = y
            res1 = z
print(str(res10)+" "+str(res5)+" "+str(res1))

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

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

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

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

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

if flg:
    print(*ans)
else:
    print(-1,-1,-1)

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

for a in range(0, n+1):
  for b in range(0, (n+1)-a):
    c = n - a - b
    s = a*10000 + b*5000 + c*1000
    if s == y:
      print(a, b, c)
      flag = True
      break
  if flag:
    break

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