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())
count = 0

def check():
    for man in range(n):
        for gosen in range(n):
            if n-man-gosen > 0:
                if y == 10000*man + 5000*gosen + 1000*(n-man-gosen):
                    return man, gosen , n-man-gosen
    return -1, -1, -1

if  n == y//10000:
    print(y//10000, 0, 0)
elif  n == y//5000:
    print(0, y//5000, 0)
elif  n == y//1000:
    print(0, 0, y//1000)
else:
    i, j, k = check()
    print(i, j, k)

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








x = 0
y = 0
z = 0

isExist = False

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  ):
      isExist = True
      break
    
  if(isExist == True):
      break
      
if(isExist == True):
  print(x, y, z)
else:
  print(-1, -1, -1)

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

if judge:print(i,j,N-i-j)
else:print(-1,-1,-1)

Solution (Python):

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

ans = 0
for a in range(N + 1):  
    for b in range(N + 1):  
        c = N - (a + b)

        
        if c < 0:
            continue

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

ans = [-1, -1, -1]
for i in range(n+1):
    for j in range(n+1):
        if i*10000 + j*5000 + (n-i-j)*1000 == y and i+j <= n :
            ans = [i, j, (n-i-j)]
            
print(ans[0], ans[1], ans[2])

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

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

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

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

isHonest = False
for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x - y
        yen = x * 10000 + y * 5000 + z * 1000
        if yen == Y:
            isHonest = True
            print(x, y, z)
            break
        elif yen > Y:
            break
    if isHonest == True:
        break

if isHonest == False:
    x, y, z = -1, -1, -1
    print(x, y, z)

Solution (Python):

n, y = map(int,input().split())  
a = -1  
b = -1  
c = -1  
flag = True
for i in range(n+1):
    for g in range(n+1):
        if y == 10000*i + 5000*g + 1000*(n - i - g) and n - i - g >= 0:
            a = i
            b = g
            c = n - i - g


print (a,b,c)

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

if find_flag == 0:
    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 y == a*10000+b*5000+c*1000:
            print(a, b, c)
            quit()
        elif y == c*10000+b*5000+a*1000:
            print(c, b, a)
            quit()

print(-1, -1, -1)

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

flg=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:
            flg=0
            x=i
            y=j
            z=k
if flg==1:
    print('-1 -1 -1')
else:
    print(x,end=" ")
    print(y,end=" ")
    print(z)

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

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

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

for i in range(0,N+1):
    for j in range(0,N+1-i):
        res = N-i-j
        if 10000*i + 5000*j + 1000*res == Y:
            print(i,j,res)
            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 = N - x - y
        if z < 0 or z > N - x - y:
            continue
        Z = Y - x*10000 - y*5000
        if Z < 0:
            continue
        if Z == z*1000:
            print("{} {} {}".format(x, y, z))
            sys.exit()

print("-1 -1 -1")

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

for a in range(N+1):
    for b in range(N+1):
        c1 = y - 10 * a - 5 * b
        c2 = N - b - a
        if c1 == c2 and c2 >= 0:
            ans = [a, b, c1]
            break
print(" ".join(map(str, ans)))

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


ans = [-1, -1, -1]

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

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

Solution (Python):
def examC():
    N, Y = LI()
    ans = [-1, -1, -1]
    for i in range(N+1):
        for j in range(N-i+1):
            cur = 10000*i + 5000*j + 1000*(N-i-j)
            if Y==cur:
                ans = [i,j,(N-i-j)]
                break
    print(" ".join(map(str,ans)))

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):
from sys import exit
N, Y = map(int, input().split())
counter = 0
for man in range(N + 1):
    for gosen in range(N + 1):
        sen = N - (man + gosen)
        if (10000 * man) + (5000 * gosen) + (1000 * sen) == Y and sen >= 0:
            print(man, gosen, sen)
            exit()
        if (10000 * man) + (5000 * gosen) > Y:
            break
print(-1, -1, -1)

Solution (Python):
A = 10
B = 5
C = 1

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

res_A = -1
res_B = -1
res_C = -1

for num_A in [num_A for num_A in range(N + 1) if A * num_A <= Y]:
    diff_YA = Y - A * num_A
    for num_B in [num_B for num_B in range(N + 1 - num_A) if B * num_B <= diff_YA]:
        diff_YAB = diff_YA - B * num_B
        if (diff_YAB == C * (N - num_A - num_B)):
            res_A = num_A
            res_B = num_B
            res_C = N - num_A - num_B
            break
    else:
        continue
    break

print("{} {} {}".format(res_A, res_B, res_C))

Solution (Python):

n,y=map(int,input().split())
a,b,c=0,0,0
flag=False
for i in range(2001):
    for j in range(2001):
        if i+j<=n and 10000*i+5000*j+1000*(n-i-j)==y:
            a=i
            b=j
            c=n-i-j
            flag=True
            break
if flag:
  print(a,b,c)
if not flag:
    print(-1,-1,-1)

Solution (Python):
a, b = input().split()
lis = []
for x in range(int(a)+1):
  for y in range(int(a)+1-x):
    z = int(a) - x - y
    if 1000 * x + 5000 * y + 10000 * z == int(b) and x + y + z == int(a):
      lis.append("{} {} {}".format(z, y, x))
      print("{} {} {}".format(z, y, x))
      exit()
if len(lis) == 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):
num, sum = map(int, input().split())
sum /= 1000
for i in range(num+1):
  for j in range(num-i+1):
    if 10*i + 5*j + (num-i-j) == sum:
      print(i, j, num-i-j)
      exit()
print(-1, -1, -1)

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

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

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





ans = '-1 -1 -1'
flag = 0

for s in range(N + 1):
    if flag == 1:
        break

    for g in range(N + 1 - s):
        i = N - s - g
        money = 1000 * s + 5000 * g + 10000 * i
        if money == Y:
            ans = str(i) + " " + str(g) + " " + str(s)
            flag = 1
            break


print(ans)

Solution (Python):
import sys
num_bills, total_yen = map(int, input().split())

for i in range(num_bills + 1):
    for j in range(num_bills + 1 - i):
        num_bills_left = num_bills - i - j
        if num_bills_left < 0:
            continue

        if (i * 10000 + j * 5000 + num_bills_left * 1000) == total_yen:
            print("{} {} {}".format(i, j, num_bills_left))
            sys.exit()

print("-1 -1 -1")

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

for m in range(2001):
    nokori = Y - 10000*m
    for g in range(2001):
        nokori -= 5000*g
        if nokori < 0: break
        sen_mai = float(nokori)/1000
        if nokori==sen_mai*1000 and m+g+sen_mai==N:
            print('{} {} {}'.format(m,g,int(sen_mai)))
            exit()
        else:
            nokori = Y - 10000*m
            continue

print('-1 -1 -1')

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

i, j, k = -1, -1, -1

for a in range(n + 1):
    for b in range(n+1-a):
        sum = (10000*a) + (5000*b) + (1000 * (n-(a+b))) if n-(a+b) >= 0 else None
        if sum == y:
            i, j, k = a, b, n-(a+b)
            break


print(i, j, k)

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

def otoshidama():
    for x in range(N+1):
        resY = Y - 10*x
        if resY < 0:
            break
        for y in range(N-x+1):
            if  resY < 5*y:
                break
            if 5*y + (N-x-y) == resY:            
                return print(x, y, N-x-y)
    return  print('-1 -1 -1')

otoshidama()

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

def otoshidama():
    for x in range(N+1):
        resY = Y - 10*x
        if resY < 0:
            return print('-1 -1 -1')
        for y in range(N-x+1):
            if  resY < 5*y:
                break
            if 5*y + (N-x-y) == resY:            
                return print(x, y, N-x-y)
    return  print('-1 -1 -1')


otoshidama()

Solution (Python):
def get_pattern(n, y):
    X = 10
    Y = 5
    Z = 1

    y //= 1000
    for nx in range(n+1):
        m = n - nx
        for ny in range(m+1):
            nz = m - ny
            sum = nx * X + ny * Y + nz * Z
            if y == sum:
                return nx, ny, nz
    return -1, -1, -1


n, y = [int(x) for x in input().split()]
a, b, c = get_pattern(n, y)
print(a, b, c)

Solution (Python):
n,y=map(int,input().split())
a=10000
b=5000
c=1000
sum_money=y
for i in range(0,n+1):
  for j in range(0,n+1-i):
    k=n-i-j
    if sum_money==a*i+b*j+c*k and k>=0:
      print(i,j,k)
      break
  else:
    continue
  break
else:
	print("-1","-1","-1")

Solution (Python):
def get_pattern(n, y):
    X = 10
    Y = 5
    Z = 1

    y //= 1000
    for nx in range(n+1):
        m = n - nx
        for ny in range(m+1):
            nz = m - ny
            sum = nx * X + ny * Y + nz * Z
            if y == sum:
                return (nx, ny, nz)
    return (-1, -1, -1)


n, y = [int(x) for x in input().split()]
a, b, c = get_pattern(n, y)
print(a, b, c)

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

for x in range(Y//10+1):
  for y in range((Y - 10 * x)//5 +1):
      if x * 10 + y * 5 + (N - x - y) == Y:
        print("%d %d %d" %(x, y, N-x-y))
        flag = 1
        break
  if flag == 1:
    break

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

Solution (Python):

import sys
input = sys.stdin.readline


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

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

print(a, b, c)

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

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

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

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

    print(-1, -1, -1)



if __name__ == '__main__':
    solve()

Solution (Python):

from sys import stdin
N, Y = [int(x) for x in stdin.readline().rstrip().split()]

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

for i in range(N + 1):
    for j in range(N + 1 - i):
        
        if (10000 * i + 5000 * j + 1000 * (N - i - j)) == Y :
            x = i
            y = j
            z = N - i - j
            break
    if(x > 0) : 
        break

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

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,sep=' ')
      exit()
    
print(-1,-1,-1,sep=' ')

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

m = y//10000 + 1

for i in range(m):
  rest = y - i*10000
  o = max(0,rest//5000 + 1)
  
  for j in range(o):
    k = n-i-j
    if rest == 5000*j + 1000*k:
      print(i,j,k)
      exit()
print(-1,-1,-1)

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

for a in range(N+1):
  for b in range(N-a+1):
    c = N - a - b
    if (10000*a + 5000*b + 1000*c) == Y:
      print(a,b,c,sep=' ')
      exit()
    
print(-1,-1,-1,sep=' ')

Solution (Python):
from sys import stdin

n,y = [int(x) for x in stdin.readline().rstrip().split()]

num = y//1000
saitei = num//10

if saitei > n:
    print(-1,-1,-1)
    exit()

for i in range(n+1):
    for j in range(n+1-i):
        if i*10+j*5+(n-i-j) == num:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    N, Y = [int(x) for x in input().split()]

    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:
                print(i, j, k)
                exit()

    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

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

main()

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    N, Y = [int(x) for x in input().split()]

    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:
                print(i, j, k)
                exit()

    print(-1, -1, -1)






if __name__ == '__main__':
    main()

Solution (Python):


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

for i in range(N+1):
    for j in range(N-i+1):
        k= N-j-i
        if 10000*i+5000*j+1000*k==Y:
            num= [i,j,k]
            count=1
            break
        else:
            continue
        break

if count>0:
    print(num[0],num[1],num[2])
else:
    print(-1,-1,-1)

Solution (Python):
n,y = map(int,input().split())
y //= 1000
temp = y//10
if temp > n:
    print("-1 -1 -1")
    quit()
for i in range(temp+1):
    zandaka = y - i * 10
    maisuu = n - i
    for k in range(maisuu+1):
        if k * 5 + maisuu - k == zandaka:
            print(str(i) + " " + str(k) + " " + str(maisuu-k))
            quit()

print("-1 -1 -1")
quit()

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

Solution (Python):
N, Y = map(int, input().split())
considered_num = int(Y/1000) - N
flg = 0
for x in range(0, int(considered_num/ 9)+1):
    for y in range(0, int(considered_num/ 4)+1):
        if flg ==0:
                if 9*x + 4*y ==considered_num:
                    if N- (x+y) >= 0:
                        flg = 1
                        print(x, y, N-(x+y))
                        break
if flg==0:
    print(-1, -1, -1)

Solution (Python):
def nyu():
    num1,num2 = input().split()
    num1 = int(num1)
    num2 = int(num2)
    
    return num1,num2

def otoshidama(n,y):
    n = n+1
    ichiman = 0
    gosen = 0
    senen = 0
    y_tmp = y
    for i in reversed(range(n)):

        ichiman  = 0
        gosen  = 0
        senen = 0
        y_tmp = y
        g_ymp = y_tmp 
        if y_tmp >= 10000*i: 
            y_tmp = y_tmp - 10000*i
            ichiman = i
            g_ymp = y_tmp
 
 
        for g in reversed(range(n-i)):
            gosen = 0
            senen = 0
            y_tmp = g_ymp
            if y_tmp >= 5000*g:
                y_tmp = y_tmp - 5000 * g
                gosen = g


            senen = int(y_tmp / 1000)
            y_tmp = y_tmp % 1000
            if check(y_tmp,ichiman,gosen,senen) == True:
                return ichiman,gosen,senen
    return -1,-1,-1

def check(y_tmp,ichiman,gosen,senen):
    
    if y_tmp == 0 and ichiman + gosen + senen  == n:
        return  True    
    return False


n,y =nyu()
num1,num2,num3 = otoshidama(n,y)
print(num1,num2,num3)

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

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

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

Solution (Python):
import sys
from collections import defaultdict
sys.setrecursionlimit(10000)
input = sys.stdin.readline

N, Y = [int(x) for x in input().strip().split()]
f = False
for man in range(N + 1):
    for gosen in range(N - man + 1):
        sen = N - man - gosen
        t = (sen + 5 * gosen + 10 * man) * 1000
        if t == Y:
            print(man, gosen, sen)
            f = True
            break
        elif t > Y:
            break
    if f:
        break
else:
    print(-1, -1, -1)

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

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

for i in range(n, -1, -1):
    for j in range(n-i+1):
        s = n - i - j
        total = 10000 * i + 5000 * j + 1000 * s
        x = i + j + s
        if total == k and i + j + s == n:
            print(i, j, s)
            exit()
        elif total > k:
            break

print(str(-1), str(-1), str(-1))

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

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:
      f = False
      print(i,j,k)
      exit()

if f:
  print(-1,-1,-1)

Solution (Python):
def isMoneyJudge(money, z):
    if z >= 0:
        if money % 1000 == 0:
            if money//1000 == z:
                return True
    
    return False

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

flag = 0
for x in range(N + 1):
    for y in range(N + 1):
        money = Y - 10000*x - 5000*y
        z = N - x - y
        if isMoneyJudge(money, z):
            if flag == 0:
                flag = 1
                print(x, y, z)
                
if flag == 1:
    pass
else:
    print(-1, -1 , -1)

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

flag = 0

cand_list = []
for x in range(N + 1):
    for y in range(N + 1):
        money = Y - 10000*x - 5000*y
        z = N - x - y
        if z >= 0:
            if money % 1000 == 0:
                if money//1000 == z:
                    if flag == 0:
                        flag = 1
                        print(x, y, z)
                
if flag == 1:
    pass
else:
    print(-1, -1 , -1)

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

Solution (Python):




import sys














def main():
    n, y = (int(i) for i in sys.stdin.readline().split())
    y //= 1000

    if 10 * n < y or n > y:
        print(-1, -1, -1)
        exit()

    for i in range(y // 10 + 1):
        for j in range((y - i * 10) // 5 + 1):
            k = n - (i + j)
            if 10 * i + 5 * j + k == y:
                print(i, j, k)
                exit()
    
    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-i+1):
        k = (y-10000*i-5000*j)//1000
        if ((y-10000*i-5000*j)%1000 == 0 and i+j+k==n):
            print(i, j, k)
            exit()

print(-1, -1, -1)

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

Solution (Python):


if __name__ == '__main__':
    N, Y = map(int, input().split())

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

            if 10 * i + 5 * j + k == Y / 1000:
                print(i, j, k)
                exit()

    print('-1', '-1', '-1')

Solution (Python):
N,Y=map(int,input().split())
x,y,z=0,0,0
a,b,c=0,0,0
x=Y//1000
y=x-N
a=min(N+1,Y//10000+1)
b=min(N+1,Y//5000+1)
for i in range(a):
  for j in range(b):
    if 9*i+4*j==y and N-i-j>=0:
      z=z+1
      a,b,c=i,j,x-y-i-j
if z==0:
  print(-1,-1,-1)
else:
  print(a,b,c)

Solution (Python):




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


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


print("-1 -1 -1")

Solution (Python):
import sys

def main():
    N, Y = map(lambda i: int(i), input().split(' '))
    for i in range(N + 1):
        for j in range(N + 1):
            y = i
            z = j
            x = N - y - z
            s = 10000 * x + 5000 * y + 1000 * z
            if x >= 0 and Y == s:
                print(' '.join(map(lambda i: str(i), [x, y, z])))
                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-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,Y=map(int,input().split())

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

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

Y2 = Y - 1000*N
if Y2==0:
    print(0, 0, N)
elif Y2<0:
    print("-1 -1 -1")
else:
    count = 0
    while(True):
       if Y2<0 or Y2/9000 + count > N:
        print("-1 -1 -1")
        break
       if Y2%9000 == 0:
        print(Y2//9000,count,N-Y2//9000-count)
        break
       Y2 -= 4000
       count += 1

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

Solution (Python):
import sys








def main():
    n, y = (int(i) for i in sys.stdin.readline().split())
    y //= 1000
    if y > 10 * n or y < n: print('-1 -1 -1'); exit()

    for i in range(n+1):
        for j in range(n+1-i):
            k = n - i - j
            t = 10 * i + 5 * j + k
            if t == y: 
                print(i, j, k)
                exit()
    print(-1, -1, -1)


if __name__ == "__main__":
    
    main()

Solution (Python):
N, Y = list(map(int, input().split()))
maxx = Y // 10000
break_loop = False
noans = 1
for i in range(maxx + 1):
    y = Y - 10000 * i
    max_2 = y // 5000
    for j in range(max_2 + 1):
        y_2 = y - 5000 * j
        if y_2 == 1000 * (N - i -j):
            if i <= N and j <= N and 0 <= N - i - j <= N: 
                print(i, j, N - i - j)
                break_loop = True
                noans = 0
                break
    if break_loop:
        break
if noans:
    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 Y==10000*i+5000*j+1000*(N-i-j):
      print("{} {} {}".format(i,j,N-i-j))
      exit()
print("-1 -1 -1")

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

o_a = -1
o_b = -1
o_c = -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:
            o_a = a
            o_b = b
            o_c = c

print("{} {} {}".format(o_a, o_b, o_c))

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

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

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

def check(N,Y):
    for a in range(N + 1):
        for b in range(N - a + 1):
            c = N - b - a
            if a * 10000 + b * 5000 + c * 1000 == Y:
                return a, b, c

    return -1,-1,-1

a, b, c = check(N, Y)
print(a,b,c)

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):
NY = input().split(' ')
N = int(NY[0])
Y = int(NY[1])

sum_Y = 0
break_flag = False
ans = (-1,-1,-1)
for x in range(N+1):
    for y in range(N+1-x):
        sum_Y = 10000*x + 5000*y + 1000*(N-x-y)
        if sum_Y == Y:
            ans = (x,y,N-x-y)
    
    if x == N:
        sum_Y = 10000*x
        if sum_Y == Y:
            ans = (x,y,N-x-y)
print(' '.join(map(str,ans)))

Solution (Python):
n, y = map(int, input().split())
flag = False
a = 0
b = 0
c = 0

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('{} {} {}'.format(a, b, c))
            flag = True
            break
        else:
            continue
        break
    else:
        continue
    break
    
if not flag:
    print('-1 -1 -1')

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

Solution (Python):
import sys
n,yen = 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 == yen:
                print(x,y,z)
                sys.exit()
                
print(-1,-1,-1)