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 = list(map(int, input().split()))
Y = Y/1000
Z = Y - N
A = 9*N - Z
if Z < 0 or Z > 9*N:
  X = [-1,-1,-1]
elif 24 <= Z <= 9*N - 32:
  X = [(Z-27)//9+((Z%9)%4-1)%4,(9-2*(Z%9))%9,N-((Z-27)//9+((Z%9)%4-1)%4+(9-2*(Z%9))%9)]
  X = list(map(int, X))
elif 0 <= Z <= 23:
  if Z%4 == 0:
    X = [0,Z/4,N-(Z/4)]
  elif Z%9 == 0:
    X = [Z/9,0,N-(Z/9)]
  elif Z == 13 or Z == 17 or Z == 21:
    X = [1,(Z-9)/4,N-((Z-5)/4)]
  elif Z == 22:
    X = [2,1,N-3]
  else:
    X = [-1,-1,-1]
  X = list(map(int, X))
else:
  if A%5 == 0:
    X = [N-(A/5),A/5,0]
  elif A%9 == 0:
    X = [N-(A/9),0,A/9]
  elif A == 14 or A == 19 or A == 24 or A == 29:
    X = [N-((A-4)/5),(A-9)/5,1]
  elif A == 23 or A == 28:
    X = [N-((A-8)/5),(A-18)/5,2]
  else:
    X = [-1,-1,-1]
  X = list(map(int, X))
print(X[0],X[1],X[2])

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

x = -1
y = -1
z = -1
break_flg = False
for Z in range(0, N + 1):
    if break_flg: break
    for Y in range(0, N - Z + 1):
        if 10000*(N - Y - Z) + 5000*Y + 1000*Z == A:
            x = N - Y - Z
            y = Y
            z = Z
            break_flg = True
            break
print(str(x) + " " + str(y) + " " + str(z))

Solution (Python):

N, Y = list(map(int,input().split()))
ans = []
count = 0
if 1000*N <= Y <= 10000*N:
    for x in range(N+1):
        if count == 1:
            break
        for y in range(N+1-x):
            if 10000*x + 5000*y + 1000*(N-x-y) == Y:
                print(x,y,N-x-y)
                count = 1
                break
if count == 0:
    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-i):
        money=10000*i+5000*j
        x=y-money
        if x >=0 and x//1000 + i + j ==n:
            print(i,j,x//1000)
            exit()
print(-1,-1,-1)

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

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

print("-1 -1 -1")

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

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

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

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

q_10000, mod_10000 = divmod(y, 10000)
for i in range(q_10000, -1, -1):
    remaining_5000 = 10000 * (q_10000 - i) + mod_10000
    q_5000, mod_5000 = divmod(remaining_5000, 5000)
    for j in range(q_5000, -1, -1):
        remaining_1000 = 5000 * (q_5000 - j) + mod_5000
        q_1000 = remaining_1000 // 1000
        if i + j + q_1000 == n:
            print("{} {} {}".format(i, j, q_1000))
            exit()

print("-1 -1 -1")

Solution (Python):
import sys



lines = [x.strip() for x in sys.stdin.readlines()]

def slv(lines):
    n, y = [int(x) for x in lines[0].split()]
    for yukichi in range(n+1):
        for ichiyo in range(n+1-yukichi):
            if (y-10000*yukichi-5000*ichiyo)/1000 == n-yukichi-ichiyo:
                if n-yukichi-ichiyo < 0:
                    continue
                return " ".join([str(yukichi),str(ichiyo),str(n-yukichi-ichiyo)])

    return "-1 -1 -1"

if __name__ == "__main__":
    print(slv(lines))

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

Solution (Python):
y,n1 = map(int,input().split())
k10=-1
k5=-1
k1=-1
n=n1
for i in range(n//10000+1):
    n=n1
    if(n//10000==y and n%10000==0):
        k10=n//10000
        k5=0
        k1=0
        break
    elif(n//10000>y):
        break
    else:
        i=n//10000-i
        n-=i*10000
        for j in range(n//5000+1):
            n=n1-i*10000
            if(n//5000==(y-i) and n%5000==0):
                k10=i
                k5=n//5000
                k1=0
                break
            elif(n//5000>y-i):
                break
            else:
                n=n1-i*10000
                j=n//5000-j
                n-=j*5000
                if(n//1000==(y-i-j) and n%1000==0):
                    k10=i
                    k5=j
                    k1=n//1000
                    break
    if(k1!=-1):
        break
    
print(k10,k5,k1)

Solution (Python):






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





import sys





for i in range(n+1):
    for j in range(n+1-i):
        k = n-(i+j)
        if (y-(i*10000 + j*5000)) /1000 == k:
            print('{} {} {}'.format(i, j, k))
            sys.exit()
else:
    print('-1 -1 -1')

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

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

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

print(*ans)

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


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

Solution (Python):
N_n_osatsu, Y_sum_money = map(int, input().split())

rest_money = Y_sum_money
rest_n_osatsu = N_n_osatsu
n_each_osatsu_list = [] 

def skip_search(rest_money, rest_n_osatsu):  
    if rest_n_osatsu*1000 > rest_money or rest_n_osatsu*10000 < rest_money:
        return True

def is_answer(n_10000, n_5000, n_1000): 
    if n_10000 + n_5000 + n_1000 == N_n_osatsu and n_10000*10000 + n_5000*5000 + n_1000*1000 == Y_sum_money:
        print(n_10000, n_5000, n_1000)
        exit()

for n_10000 in range(min(Y_sum_money//10000, N_n_osatsu)+1): 
    is_answer(n_10000, 0, 0)
    rest_money = Y_sum_money - 10000*n_10000
    rest_n_osatsu = N_n_osatsu - n_10000
    if skip_search(rest_money, rest_n_osatsu):
        break

    for n_5000 in range(min(rest_money//5000, rest_n_osatsu)+1): 
        is_answer(n_10000, n_5000, 0)
        rest_money = Y_sum_money - 10000*n_10000 - 5000*n_5000
        rest_n_osatsu = N_n_osatsu - n_10000 - n_5000
        if skip_search(rest_money, rest_n_osatsu):
            break
        n_1000 = rest_money//1000
        is_answer(n_10000, n_5000, n_1000)

print("-1 -1 -1")

Solution (Python):
N_n_osatsu, Y_sum_money = map(int, input().split())

rest_money = Y_sum_money
rest_n_osatsu = N_n_osatsu
n_each_osatsu_list = [] 

def skip_search(rest_money, rest_n_osatsu):  
    if rest_n_osatsu*1000 > rest_money or rest_n_osatsu*10000 < rest_money:
        return True

def is_answer(n_10000, n_5000, n_1000): 
    if n_10000 + n_5000 + n_1000 == N_n_osatsu and n_10000*10000 + n_5000*5000 + n_1000*1000 == Y_sum_money:
        print(n_10000, n_5000, n_1000)
        exit()

for n_10000 in range(min(int(Y_sum_money/10000), N_n_osatsu)+1): 
    is_answer(n_10000, 0, 0)
    rest_money = Y_sum_money - 10000*n_10000
    rest_n_osatsu = N_n_osatsu - n_10000
    if skip_search(rest_money, rest_n_osatsu):
        break

    for n_5000 in range(min(int(rest_money/5000 + 1), rest_n_osatsu)+1): 
        is_answer(n_10000, n_5000, 0)
        rest_money = Y_sum_money - 10000*n_10000 - 5000*n_5000
        rest_n_osatsu = N_n_osatsu - n_10000 - n_5000
        if skip_search(rest_money, rest_n_osatsu):
            break
        n_1000 = int(rest_money/1000)
        is_answer(n_10000, n_5000, n_1000)

print("-1 -1 -1")

Solution (Python):
N_n_osatsu, Y_sum_money = map(int, input().split())

rest_money = Y_sum_money
rest_n_osatsu = N_n_osatsu
n_each_osatsu_list = [] 

def skip_search(rest_money, rest_n_osatsu):  
    if rest_n_osatsu*1000 > rest_money or rest_n_osatsu*10000 < rest_money:
        return True

def is_answer(n_10000, n_5000, n_1000):
    if n_10000 + n_5000 + n_1000 == N_n_osatsu and n_10000*10000 + n_5000*5000 + n_1000*1000 == Y_sum_money:
        print(n_10000, n_5000, n_1000)
        exit()

for n_10000 in range(int(Y_sum_money/10000 +1)): 
    is_answer(n_10000, 0, 0)
    rest_money = Y_sum_money - 10000*n_10000
    rest_n_osatsu = N_n_osatsu - n_10000
    if skip_search(rest_money, rest_n_osatsu):
        break

    for n_5000 in range(int(rest_money/5000 + 1)): 
        is_answer(n_10000, n_5000, 0)
        rest_money = Y_sum_money - 10000*n_10000 - 5000*n_5000
        rest_n_osatsu = N_n_osatsu - n_10000 - n_5000
        if skip_search(rest_money, rest_n_osatsu):
            break
        n_1000 = int(rest_money/1000)
        is_answer(n_10000, n_5000, n_1000)

print("-1 -1 -1")

Solution (Python):
N_n_osatsu, Y_sum_money = map(int, input().split())

rest_money = Y_sum_money
rest_n_osatsu = N_n_osatsu
n_each_osatsu_list = [] 

def skip_search(rest_money, rest_n_osatsu):  
    if rest_n_osatsu*1000 > rest_money or rest_n_osatsu*10000 < rest_money:
        return True

for n_10000 in range(int(Y_sum_money/10000 +1)): 
    rest_money = Y_sum_money - 10000*n_10000
    rest_n_osatsu = N_n_osatsu - n_10000
    if skip_search(rest_money, rest_n_osatsu):
        break

    if rest_money == 0: 
        n_each_osatsu_list.append([n_10000, 0, 0])
        break

    for n_5000 in range(int(rest_money/5000 + 1)): 
        rest_money = Y_sum_money - 10000*n_10000 - 5000*n_5000
        rest_n_osatsu = N_n_osatsu - n_10000 - n_5000
        if skip_search(rest_money, rest_n_osatsu):
            break
        n_1000 = int(rest_money/1000)
        n_each_osatsu_list.append([n_10000, n_5000, n_1000])

n_sum_osatsu_list = [sum(x) for x in n_each_osatsu_list] 

try:
    print(*n_each_osatsu_list[n_sum_osatsu_list.index(N_n_osatsu)], sep=" ")
except:
    print("-1 -1 -1")

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

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

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

Solution (Python):

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

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

Solution (Python):
N, Y = map(int, input().split())
count = 0
yen = [0] * 3

for i in reversed(range(Y // 10000 + 1)):
    for j in range(Y // 5000 + 1):
        temp = N - i - j
        if Y - 10000 * i - 5000 * j < 0 or temp < 0:
            break
        elif Y - 10000 * i - 5000 * j == 1000 * temp:
            yen[0] = i
            yen[1] = j
            yen[2] = temp
            print(' '.join(map(str, yen)))
            exit()
        else:
            continue
    if (Y - 10000 * i) // 5000 > N - i:
        break
print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
count = 0
yen = [0] * 3

for i in reversed(range(Y // 10000 + 1)):
    for j in range(Y // 5000 + 1):
        temp = N - i - j
        if Y - 10000 * i - 5000 * j < 0 or temp < 0:
            break
        elif Y - 10000 * i - 5000 * j == 1000 * temp:
            yen[0] = i
            yen[1] = j
            yen[2] = temp
            print(' '.join(map(str, yen)))
            exit()
        else:
            continue
print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
count = 0
yen = [0] * 3

for i in reversed(range(Y // 10000 + 1)):
    yen[0] = i
    for j in range(Y // 5000 + 1):
        yen[1] = j
        yen[2] = N - i - j
        if Y - 10000 * i - 5000 * j < 0 or yen[2] < 0:
            break
        elif Y - 10000 * i - 5000 * j == 1000 * yen[2]:
            print(' '.join(map(str, yen)))
            exit()
        else:
            continue
print('-1 -1 -1')

Solution (Python):

def main():
    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("{} {} {}".format(a,b,c))
                exit()
    print("{} {} {}".format(-1,-1,-1))
        
if __name__ == '__main__':
    main()

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

Solution (Python):
n,y = map(int,input().split())
ans = 0
c = 1
for i in range(y // 10000 + 1,-1,-1):
    for j in range(y // 5000 + 1,-1,-1):
        if n - i - j >= 0 and y - 10000 * i - 5000 * j == 1000 * (n-i-j):            
            if c != 0:
                print(i, j, (y-10000*i-5000*j)//1000)
                c = 0
if c == 1:
    print('-1 -1 -1')

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

sw=0
for a in range(N+1):
  for b in range(N+1):
    if 9*a+4*b==d:
      c=N-a-b
      if c>=0:
        sw=1
        break
  else:
    continue
  break
  
if sw==1:
  print(a,b,c)
else:
  print(-1,-1,-1)

Solution (Python):
n, y = map(int, input().split())
miss = 0
clear = 0
for s in range(min(n, y//10000) + 1):
	if clear == 1:
		break
	else:
		for t in range(min(n-s, (y-10000*s)//5000) + 1):
		    money = 10000*s + 5000*t
		    if y - money == (n-s-t)*1000:
			    print(str(s)+" "+str(t)+" "+str(n-s-t))
			    miss = 1
			    clear = 1
if miss == 0:
	print("-1 -1 -1")

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

def k5tok10(x):
    global k5
    global k10
    k5 -= 2*x
    k10 += x

def k5tok1(x):
    global k5
    global k1
    k5 -= x
    k1 += x*5

k1=0
k5=0
k10=0

k5 = a[1]//5000
k1 = (a[1]%5000)//1000

if k1+k5+k10 < a[0]:
    k5tok1(-(-(a[0]-(k1+k5+k10))//4))

if k1+k5+k10 > a[0]:
    k5tok10(k1+k5+k10 - a[0])

if k5 < 0:
    print(-1,-1,-1)
else:
    print(k10,k5,k1)

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

for yukichi in range(m + 1):
  for higuchi in range(m + 1):
    noguchi = m - yukichi - higuchi
    if noguchi >= 0:
      money = yukichi * 10000 + higuchi * 5000 + noguchi * 1000
      if money == otoshidama and yukichi + higuchi + noguchi == m:
        print(yukichi,higuchi,noguchi)
        exit()
print(-1, -1, -1)

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

for yukichi in range(m + 1):
  for higuchi in range(m + 1):
    noguchi = m - yukichi - higuchi
    money = yukichi * 10000 + higuchi * 5000 + noguchi * 1000
    if money == otoshidama and yukichi + higuchi + noguchi == m and noguchi >= 0:
      print(yukichi,higuchi,noguchi)
      exit()
print(-1, -1, -1)

Solution (Python):
def is_pos_int(num):
  if num - int(num) == 0 and int(num) >= 0: return True
  else: return False

N,Y = map(int,input().split())
Y = Y/1000
for a in range(N+1):
  b = (-9*a + Y - N)/4
  c = N - a - b
  if all([is_pos_int(b),is_pos_int(c)]):
    print(int(a), int(b), int(N - b - a))
    exit()
print('-1 -1 -1')

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

f=False
for i in range(N+1):
	for j in range(N+1):
		s = 10000*i+5000*j
		t = Y-s
		if t>=0 and t%1000==0 and (i+j+t//1000)== N:
			f=True
			break
	if f:break

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

Solution (Python):
def main():
  n , y = map(int, input().split())
  y = y // 1000
  
  if n*10 >= y :
    for i in range(n+1):
      if 10 * i > y :
        break
      elif 10 * i + 5 * (n - i) < y:
        continue
      else:
        for j in range(n-i+1):
          if i * 10 + j * 5 > y:
            break
          elif i * 10 + j * 5 + (n - i - j) == y:
            return print(i, j, n - i - j)
            exit()
  return print(-1, -1, -1)

if __name__=='__main__':  
  main()

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

for i in range(x+1):
    if not ans:
        for j in range(x-i+1):
            if 10000*i + j*5000 + (x-i-j)*1000 == y:
                ans = [i,j,x-i-j]
                break
    else:
        break

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

Solution (Python):

def main():
	linie = input()
	vector = [int(x) for x in linie.split()]	
	n = vector[0]
	y = vector[1]
	ok = 0
	nr1 = -1
	nr2 = -1
	nr3 = -1
	nr = n + 1
	for i in range(0, n + 1):
		for j in range(n + 1 - i):
				if i * 1000 + j * 5000 + (n - i - j) * 10000 == y:
					nr1 = i
					nr2 = j
					nr3 = (n - i - j)
	print(nr3, nr2, nr1)
 
 
if __name__ == "__main__":
	main()

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

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

for i in range((Y // 10000)+1)[::-1]:
    if ((Y - 10000 * i) < 0) and ((N - i) < 0):
        print("-1 -1 -1")
        exit()
    Y2 = Y - 10000*i
    N2 = N - i
    for j in range((Y2 // 5000)+1)[::-1]:
        if ((Y2 - 5000 * j) < 0) and ((N2 - j) < 0):
            print("-1 -1 -1")
            exit()
        Y3 = Y2 - 5000 * j
        N3 = N2 - j
        if N3 * 1000 == Y3:
            print(i, j, N3)
            exit()

print("-1 -1 -1")

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




flag = False
for x in range(0,1+Y//10000):
  for y in range(0,1+(Y-10000*x)//5000):
    z=N-x-y
    if z==(Y-10000*x-5000*y)//1000:
      flag = True
      ans = [x,y,z]
      break
  else:
    continue
  break
if flag:
  print(ans[0], ans[1], ans[2])
else:
  print(-1, -1, -1)

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

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

for i in range(Y//10000 + 1):
    for j in range(n-i+1):
        if 9*i + 4*j == Y/1000 - n:
            x = i
            y = j
            z = n-i-j
print(x,y,z)

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

for a in range(y//10000 + 1):
    b = (y - 1000 * n - 9000 * a) // 4000
    c = n - a - b
    if 10000 * a + 5000 * b + 1000 * c == y and a >= 0 and b >= 0 and c >= 0:
        print(a, b, c)
        swi = 1
        break
if swi == 0:
    print(-1, -1, -1)

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

for a in range(y//10000 + 2):
    b = (y - 1000 * n - 9000 * a) // 4000
    c = n - a - b
    if a + b + c == n and 10000 * a + 5000 * b + 1000 * c == y and a >= 0 and b >= 0 and c >= 0:
        print(a, b, c)
        swi = 1
        break
if swi == 0:
    print(-1, -1, -1)

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

for a in range(2001):
    b = (y - 1000 * n - 9000 * a) // 4000
    c = n - a - b
    if a + b + c == n and 10000 * a + 5000 * b + 1000 * c == y and a >= 0 and b >= 0 and c >= 0:
        print(a, b, c)
        swi = 1
        break
if swi == 0:
    print(-1, -1, -1)

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

damm = 0

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

a = -1

if damm == 0:
    print(a,a,a)

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

st = None
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:
            st = '{} {} {}'.format(i, j, k)

    if st is None:
        continue
    else:
        break

if st is None:
    print(-1, -1, -1)
else:
    print(st)

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

str = None
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:
            str = '{} {} {}'.format(i, j, k)
if str is None:
    print(-1,-1,-1)
else:
    print(str)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, y = list(map(int, input().rstrip('\n').split()))
    for a in range(n + 1):
        for b in range(n + 1):
            if 10000 * a + 5000 * b > y:
                break
            elif (n - a - b) * 1000 == y - (10000 * a + 5000 * b):
                print(a, b, n - a - b)
                exit()
    print(-1, -1, -1)


if __name__ == '__main__':
    slove()

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):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, y = LI()
y //= 1000


def main():
    for i in range(n+1):
        for j in range(n-i+1):
            k = n - i - j
            if i * 10 + j * 5 + k == y:
                return i, j, k
    return -1, -1, -1




i, j, k = main()
print(i, j, k)

Solution (Python):
N,Y=list(map(int,input().split()))
flag=0
Y//=1000
z=Y%5
Y-=z
N-=z
for i in range(N+1):
    if flag==1:
        break
    for j in range(N+1-i):
        if flag==1:
            break
        k=N-i-j
        if i*10+j*5+k*1==Y:
            print(i,j,k+z)
            flag=1
if flag==0:
    print("-1 -1 -1")

Solution (Python):
N,Y=list(map(int,input().split()))
flag=0
Y//=1000
z=Y%5
Y-=z
N-=z
for i in range(N+1):
    if flag==1:
        break
    for j in range(N+1-i):
        if flag==1:
            break
        k=N-i-j
        if i*10+j*5+k*1==Y:
            print(i,j,k+z)
            flag=1
if flag==0:
    print("-1 -1 -1")

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

a = Y - 1000*N
total = 0
x = -1
y = -1
z = -1
for i in range(0, N+1):
    total = i*9000
    if total > a:
        break
    else:
        for j in range(0, N+1-i):
            total = i*9000 + j*4000
            if total > a:
                break
            if total == a:
                x = i
                y = j
                z = N-i-j

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

Solution (Python):
NY = input().split(" ")
N = int(NY[0])
Y = int(NY[1])
KKK = 0
KK = 0
K = 0
check = 0
for i in range(0, N + 1):
    if check == 1:
        break
    for j in range(0, N + 1- i):
        k = N - i - j 
        if k * 10000 + j * 5000 + i * 1000 == Y:
            KKK = k
            KK = j
            K = i
            check = 1
            break
        
if check == 0:
    print(-1, -1, -1)
else:
    print(KKK, KK ,K)

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

ans = [-1, -1, -1]
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = n - i - j
        sm = 10000 * i + 5000 * j + 1000 * k
        if sm == y:
            ans = [i, j, k]

print(*ans)

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

for n1k in range(N + 1):
    for n5k in range(N + 1 - n1k):
        n10k = N - n5k - n1k
        if Y == (n1k * 1 + n5k * 5 + n10k * 10) * 1000:
            print(n10k, n5k, n1k)
            exit()

print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
a = 0
b = 0
c = 0
total = 0
flag = 0

for a in range(N+1):
    for b in range(N+1-a):

            total = a*10000 + b*5000 + (N-a-b)*1000
            if Y == total:
                print(a, b, N-a-b)
                flag = 1
                break
    else:
        continue
    break
    
if flag == 0:
    print(-1, -1, -1)

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

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

Solution (Python):
n,y=map(int,input().split())
y//=1000
A=-1
B=-1
C=-1
for a in range(n+1):
  b=(y-n-9*a)/4
  if b==round(b) and b>=0:
    b=int(b)
    c=n-a-b
    if c>=0:
      A=a
      B=b
      C=c
      break
print(A,B,C)

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

Solution (Python):
nbills, sum_ = map(int, input().rstrip("\n").split())

for i in range(nbills + 1):
    for j in range(nbills - i + 1):
        k = (sum_ - (10000 * i + 5000 * j)) // 1000
        if (i + j + k) == nbills:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

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

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

yukichi = -1
ichiyo = -1
hideyo = -1

hasFound = False

for x in range(N+1):
  for y in range(N+1-x):
    z = N - x - y
    total = x * 10000 + y * 5000 + z * 1000
    if total == Y:
      yukichi = x
      ichiyo = y
      hideyo = z
      hasFound = True
      break
  if hasFound:
    break
print('{} {} {}'.format(yukichi, ichiyo, hideyo))

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

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

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

Solution (Python):

import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, Y = map(int, input().split())

        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:
                    print(*[a, b, c], sep=' ')
                    exit()
        print(*[-1] * 3, sep=' ')



if __name__ == '__main__':
    AtCoder().main()

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

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

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

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

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