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):
num,yen = map(int,input().split())
flg = 0

for i in range(num+1):
    if flg == 1:
        i -= 1
        break
    
    for j in range(num-i+1):
        
        
        if i*10000 + j*5000 + (num-i-j)*1000 == yen:
            
            flg = 1
            break

if flg != 1:
    print('-1 -1 -1')
else:
    print("{} {} {}".format(i,j,num-i-j))

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

Solution (Python):
import sys

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

print("-1 -1 -1")

Solution (Python):


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


found = False
for i in range(n+1):
    for j in range(n+1):
        if i + j > n:
            break
        k = n - (i + j)
        if 10000 * i + 5000 * j + 1000 * k == y and i + j + k == n:
            found = True
            print("{} {} {}".format(i, j, k))
            break
    if found:
        break

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

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

for noguchi in range(n + 1):
    for higuchi in range(n + 1 - noguchi):
        yukichi = n - noguchi - higuchi
        if noguchi + higuchi * 5 + yukichi * 10 == yen:
            print(yukichi, higuchi, noguchi)
            exit(0)
print("-1 -1 -1")

Solution (Python):


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

try:
  for i in list(reversed(range(n + 1))):
    for j in list(reversed(range(n - i + 1))):
      k = n - (i + j) if i + j < n else 0
      if (((i * 10000) + (j * 5000) + (k * 1000)) == y):
        a, b, c = i, j, k
        exit
finally:
  print(a, b, c)

Solution (Python):
import sys
N,Y=map(int,input().split())
n=0
for i in range(0,N+1):
    for j in range(0,N-i+1):
        k=N-i-j
        S=10000*i+5000*j+1000*k
        if (S==Y) and (k>=0):
            print(i,j,k,sep=" ")
            sys.exit()
        else:
            n=n+1
if n==(N+1)*(N+2)/2:
    print(-1,-1,-1,sep=" ")

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

is_completed = False
ans = [-1, -1, -1]
for x in range(N+1):
    if is_completed:
        break
    for y in range(N+1):
        z = N - (x+y)
        if not (0 <= z <= N):
            continue
        if 10000*x + 5000*y + 1000*z == Y:
            is_completed = True
            ans = [x, y, z]
            break
print(*ans, sep=" ")

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

flg = False
for a in range(0, N+1):
    for b in range(0, N-a+1):
        c = N - (a+b)
        S = 10000*a + 5000*b + 1000*c
        if (S == M) and (c >= 0):
            flg = True
            ans_a = a
            ans_b = b
            ans_c = c

if flg == True:
    print(ans_a, ans_b, ans_c)
else:
    print(-1, -1, -1)

Solution (Python):
nums = input()
nums = nums.split()
satu_num = int(nums[0])
sum_money = int(nums[1])

judge = True
count_one = -1
count_two = -1
count_three = -1

for a in range(0,satu_num+1):
  man = 10000*a
  for b in range(0,satu_num+1):
    go_senn = 5000*b
    senn = 1000*(satu_num-a-b)
    if satu_num-a-b<0:
      break
    else:
      ans = man+go_senn+senn
      if ans == sum_money:
        count_one = a
        count_two = b
        count_three = (satu_num-a-b)
        break
      else:
        pass
print(count_one,count_two,count_three)

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

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

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

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

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

for 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):
N,Y=map(int,input().split())
f=Y//10000
for x in range(f+1):
    for y in range(N+1):
        z=N-x-y
        k=10000*x+5000*y+1000*z
        if k==Y and x+y+z==N and z>=0:
            print(x,y,z)
            exit()
print(-1,-1,-1)

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

Solution (Python):

import sys

def calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number):
    return N - (ten_thousand_number + five_thousand_number + one_thousand_number)

def print_answer(ten_thousand_number, five_thousand_number, one_thousand_number):
    print(str(ten_thousand_number) + ' ' + str(five_thousand_number) + ' ' + str(one_thousand_number))

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


now_amount = Y
five_thousand_number = 0
one_thousand_number = 0

ten_thousand_number = now_amount // 10000
now_amount = now_amount % 10000
five_thousand_number = now_amount // 5000
now_amount = now_amount % 5000
one_thousand_number = now_amount // 1000
now_amount = now_amount % 1000


difference = calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number)
if difference < 0:
    print('-1 -1 -1')
    sys.exit()

if difference == 0:
    print_answer(ten_thousand_number, five_thousand_number, one_thousand_number)
    sys.exit()


ten_thousand_cut = difference // 9
actual_ten_thousand_cut = min(ten_thousand_cut, ten_thousand_number)
ten_thousand_number -= actual_ten_thousand_cut
one_thousand_number += actual_ten_thousand_cut * 10
difference = calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number)

if difference == 0:
    print_answer(ten_thousand_number, five_thousand_number, one_thousand_number)
    sys.exit()


five_thousand_cut = difference // 4
actual_five_thousand_cut = min(five_thousand_cut, five_thousand_number)
five_thousand_number -= actual_five_thousand_cut
one_thousand_number += actual_five_thousand_cut * 5
difference = calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number)

if difference == 0:
    print_answer(ten_thousand_number, five_thousand_number, one_thousand_number)
    sys.exit()


ten_thousand_cut = difference // 1
actual_ten_thousand_cut = min(ten_thousand_cut, ten_thousand_number)
ten_thousand_number -= actual_ten_thousand_cut
five_thousand_number += actual_ten_thousand_cut * 2
difference = calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number)

if difference == 0:
    print_answer(ten_thousand_number, five_thousand_number, one_thousand_number)
    sys.exit()

print('-1 -1 -1')

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

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

for noguchi in range(n + 1):
    for higuchi in range(n + 1 - noguchi):
        yukichi = n - noguchi - higuchi
        if noguchi + higuchi * 5 + yukichi * 10 == yen:
            print(yukichi, higuchi, noguchi)
            exit(0)
print("-1 -1 -1")

Solution (Python):
def f():
    N, Y = map(int, input().split())
    
    y1 = 10000
    y2 = 5000
    y3 = 1000
    
    y1_num = 0
    y2_num = 0
    y3_num = 0
    for y1_num in reversed(range(N+1)):
        y2_num = 0
        remain_Y1 = Y - y1*y1_num
        if remain_Y1 == 0 and sum([y1_num, y2_num, y3_num]) == N:
            return print(y1_num, y2_num, y3_num)
        elif remain_Y1 < 0:
            continue
        else:
            for y2_num in reversed(range(N+1 - y1_num)):
                y3_num = N - y1_num - y2_num
                remain_Y2 = remain_Y1 - y2*y2_num - y3*y3_num
                if remain_Y2 == 0 and sum([y1_num, y2_num, y3_num]) == N:
                    return print(y1_num, y2_num, y3_num)
                elif remain_Y2 < 0:
                    continue
    return print(-1, -1, -1)
                        
f()

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

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

flag = False
for i in range(Y//10000+1):
    x = Y//10000-i
    for j in range(N-x+1):
        y = N-x-j
        z = N-x-y
        if x*10000 + y*5000 + z*1000 == Y:
           flag = True
           break
    if flag:
        break

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

Solution (Python):
def main():
    n,y = map(int, input().split())
    aa, ab, ac = -1, -1, -1
    a = y//10000
    b = (y-10000*a)//5000
    c = (y-10000*a-5000*b)//1000
    flag = False
    if n > a+b+c:
        no = n-a-b-c
        for s in range(b+1):
            for t in range(a+1):
                for t1 in range(t+1):
                    for t5 in range(t-t1+1):
                        if s*4 + t1*9 + t5 == no:
                            aa = a-t
                            ab = b-s+t5*2
                            ac = c+s*5+t1*10
                            flag = True
                            break
                    if flag:
                        break
                if flag:
                    break
            if flag:
                break
    elif n == a+b+c:
        aa, ab, ac = a, b, c
    print(aa,ab,ac)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n,y = map(int, input().split())
    aa, ab, ac = -1, -1, -1
    a = y//10000
    b = (y-10000*a)//5000
    c = (y-10000*a-5000*b)//1000
    flag = False
    if n > a+b+c:
        no = n-a-b-c
        for s in range(b+1):
            for t in range(a+1):
                for t1 in range(t+1):
                    for t5 in range(t-t1+1):
                        if s*4 + t1*9 + t5 == no:
                            aa = a-t
                            ab = b-s+t5*2
                            ac = c+s*5+t1*10
                            flag = True
                            break
                    if flag:
                        break
                if flag:
                    break
            if flag:
                break
    elif n == a+b+c:
        aa, ab, ac = a, b, c
    print(aa,ab,ac)


if __name__ == "__main__":
    main()

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 i*10000 + j*5000 + k*1000 == y:
            ans = str(i) + ' ' + str(j) + ' ' + str(k)

print(ans)

Solution (Python):
import sys

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

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

    print("-1 -1 -1")

main()

Solution (Python):
N, Y = (int(x) for x in input().split())
ichiman = -1
gosen = -1
sen = -1

for x in range(N + 1):
    for y in range(N + 1):
        z = N - x - y
        if z >= 0 and (10000 * x + 5000 * y + 1000 * z == Y):
            ichiman = x
            gosen = y
            sen = z
            break

print(ichiman, ' ', gosen, ' ', sen)

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

y //= 1000

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

for i in range(n + 1):
    for j in range(n - i + 1):
        otoshidama = 10 * i + 5 * j
        otoshidama_1 = n - i - j if n - i - j > 0 else 0
        otoshidama += otoshidama_1
        if otoshidama == y and i + j + otoshidama_1:
            print(i, j, otoshidama_1)
            exit()
else:
    print(-1, -1, -1)

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


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

Solution (Python):
N ,Y = map(int,input().split())
for k10 in range(N + 1):
    for k5 in range(N - k10 + 1):
        k1 = (Y - (k10 * 10000 + k5 * 5000)) / 1000
        if k1.is_integer() and k1 + k5 + k10 == N:
            print(k10, k5, int(k1))
            exit()
print("-1 -1 -1")

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

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


if Flag==False:
    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())

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

if Flag==False:
    print('-1 -1 -1')

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

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

Solution (Python):
N,Y = map(int, input().split())
cnt=0
for i in range(N+1):
    for j in range(N+1):
        if 0<= N- (i +j) <=2000 and Y == 10000*i+5000*j+1000*(N-i-j):
            cnt+=1
            l =[i, j]
if cnt>=1:
    print(l[0],l[1],(N-(l[0]+l[1])))
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 + 1):
        if 10000 * a + 5000 * b + (n - a - b) * 1000 == y and (n-a-b) >= 0:
            ans = '{} {} {}'.format(a, b, (n-a-b))
            break
    if ans != '-1 -1 -1':
        break

print(ans)

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

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

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

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

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

ans = '-1 -1 -1'
for x in range(0, N+1):
    y = (Y / 1000 - 9 * x - N) / 4
    if 0 <= y <= N:
        if y.is_integer():
            y = int(y)
            z = N - x - y
            if 0 <= z <= N:
                ans = " ".join([str(x), str(y), str(z)])
                break
print(ans)

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):
    c = n-i-j
    total = 10000*i + 5000*j + 1000*c
    if total == y:
      A = i
      B = j
      C = c
print(A, B, C)

Solution (Python):
N,Y =map(int,input().split())
a = []
for i in range(N+1):
    for j in range(N+1):
        x = i
        y = j
        z = N-x-y
        if z <0:
            break
        if 10000*x+5000*y+1000*z == Y:
            a.append([x,y,z])
if len(a)>=1:
    print(a[0][0],a[0][1],a[0][2])
else:
    print(-1,-1,-1)

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

while(True):
    for i in range(N+1):
        for j in range(N-i+1):
            if 10000*i + 5000*j + 1000*(N-i-j) == Y:
                a[0] = i
                a[1] = j
                a[2] = N-i-j
                break
    break

print(' '.join([str(n) for n in a]))

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

for i in range(num + 1):
    cal1 = yen
    if cal1 < 10000 * i:
        break
    else:
        cal1 -= 10000 * i
        
        for j in range(num + 1):
            cal2 = cal1
            if i + j > num:
                break
            elif cal2 < 5000 * j:
                break
            else:
                cal2 -= 5000 * j
                if cal2 % 1000 == 0:
                    z = cal2 // 1000
                    if i + j + z == num:
                        print(i, j, z)
                        exit()

print(-1, -1, -1)

Solution (Python):

if __name__ == '__main__':

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

	Y = Y // 1000

	x1 = min( Y // 10,N)
	y1 = min( Y // 5,N)

	Hit = False
	for x2 in range(0,x1+1):
		if Hit == True:
			break
		for y2 in range(0,y1-x2+1):
			sm = ( 10 * x2 ) + ( 5 * y2 )
			h = N - ( x2 + y2)
			if sm > Y:
				break
			elif sm + h == Y:
				print(x2,y2,h)
				Hit = True
				break

	if Hit == False:
		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):
        if Y<(10000*i+5000*j):
            break
        elif (Y-(10000*i+5000*j))/1000==N-i-j:

            print(str(i)+" "+str(j)+" "+str(N-i-j))
            flag = True
            break
    if flag == True:
        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*10000+j*5000+k*1000==y:
      print(i,j,k)
      exit()
print(-1,-1,-1)

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

y = Y //1000
is_search = True

for i in range(N+1):
    for j in range(N+1):
        k = N -(i+j)
        temp_price = 10*i + 5*j + k

        if temp_price == y and 0 <= k <= N:
            print(i,j,k)
            is_search = False
            break

    if not is_search:
        break

if is_search:
    print('-1 -1 -1')

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

for i in range(2001):
    for j in range(2001):
        d, m = divmod(y - (10000*i + 5000*j), 1000)
        if m == 0 and i+j+d == n and d >= 0:
            ans = [i, j, d]
            break

print(' '.join(map(str, ans)))

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

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

print(-1, -1, -1)

Solution (Python):
N,Y = map(int,input().split())
x,y,z = 0,0,0

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

Solution (Python):


import numpy
import scipy



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

find = False
for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if find:
            break
        sum = x*10000 + y*5000 + z*1000
        if sum == Y:
            find = True
            print("{} {} {}".format(x, y, z))
            

if not find:
    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-i):
    if Y == 10000*i + 5000*j + 1000*(N - i - j):
      print(str(i)+" "+str(j)+" "+str(N-i-j))
      exit()
print(ans)

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

for z in range(N+1):
    if 10000 * z > Y:
        break
    for y in range(N+1-z):
        if ((Y - (10000 * z + 5000 * y)) // 1000) == (N - (y + z)):
            print('{} {} {}' . format(z, y, N-y-z))
            exit(0)

print('-1 -1 -1')

Solution (Python):
N,Y = map(int,input().split())
c = 0
array = []
for i in range(N+1):
  for j in range(N+1-i):
    if 10000*i+5000*j+1000*(N-i-j) == Y:
      c = 1
      array.append(i)
      array.append(j)
      array.append(N-i-j)

      
if c == 1:
  print(array[0],array[1],array[2])
else:
  print(-1,-1,-1)

Solution (Python):


import sys

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

sagaku = (10000 * N) - Y
if sagaku < 0:
    print(-1, -1, -1)
    sys.exit()

for y in range(0, N+1):
    for z in range(0, N-y+1):
        if sagaku == 5000*y + 9000*z:
            print(N-y-z, y, z)
            sys.exit()
print(-1, -1, -1)

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

res10000=-1
res5000=-1
res1000=-1

for a in range(0,N+1):
    for b in range(0,N-a+1):
        total=a*10000+b*5000+(N-a-b)*1000
        if total == Y:
            res10000=a
            res5000=b
            res1000=N-a-b
            
print(res10000,res5000,res1000)

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

res10000=-1
res5000=-1
res1000=-1

for a in range(0,N+1):
    for b in range(0,N-a+1):
        total=a*10000+b*5000+(N-a-b)*1000
        if total == Y:
            res10000=a
            res5000=b
            res1000=N-a-b
            
print(str(res10000) + ' ' + str(res5000) + ' ' + str(res1000))

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

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

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

print("-1 -1 -1")

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

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

print(-1, -1, -1)

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

print("-1 -1 -1")

Solution (Python):
N, Y = list(map(int, input().split()))
ans = []
for i_yukichi in range(N + 1):
    for j_higuchi in range(N + 1 - i_yukichi):
        k_noguchi = N - i_yukichi - j_higuchi
        if 10000 * i_yukichi + 5000 * j_higuchi + 1000 * k_noguchi == Y:
            ans.append(i_yukichi)
            ans.append(j_higuchi)
            ans.append(k_noguchi)
            break
if len(ans) != 0:
    print(ans[0], ans[1], ans[2])
else:
    print("-1 -1 -1")

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

print(a ,b ,c)

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

Solution (Python):
def solve():
    N, Y = map(int, input().split())
    
    upper1 = Y // 10000
    if upper1 > N:
        print(-1, -1, -1)
        return None
    for i in range(upper1 + 1):
        rest = Y - 10000 * i
        upper2 = rest // 5000
        if upper2 > N - i:
            continue
        for j in range(upper2 + 1):
            k = N - i - j
            if 1000 * k == rest - 5000 * j:
                print(i, j, k)
                return None
    else:
        print(-1, -1, -1)

solve()

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

for i in range(N+1):
    for j in range(N-i+1):
        k = N - (i + j)
        if Y - (10*i + 5*j) == k:
            print(i, j, k)
            quit()

print(-1, -1, -1)

Solution (Python):
n,p = map(int,input().split())
res10000 = res5000 = res1000 = -1
x = y = 0
end = False
for x in range(n+1):
    if end:
        break
    for y in range(n+1-x):
        if x*10000+y*5000+ (n-(x+y))*1000 == p:
            res10000 = x
            res5000 = y
            res1000 = n-(x+y)
            end = True
print('{} {} {}'.format(res10000,res5000,res1000))

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

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

print("-1 -1 -1")

Solution (Python):
n,y = map(int, input().split())
flg = False
for a in range(n+1):
  for b in range(n+1):
    c = n-(a+b)
    if y == a*10000 + b*5000 + c*1000 and a+b <=n:
      print(a,b,c)
      flg =True
      break
  if flg:
    break
else:
  print(-1,-1,-1)

Solution (Python):
def inputstdin():
    n, y = map(int, input().split(" "))
    return n, y


def calc(n, y):
    for a in range(n + 1):
        for b in range(n - a + 1):
            c = n - b - a
            if 10 * a + 5 * b + c == y:
                return a, b, c
    return -1, -1, -1


def main():
    n, y = inputstdin()
    print(" ".join(map(str, calc(n, y // 1000))))


main()

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

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

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

Solution (Python):
n, y = map(int, input().split())
resa, resb, resc = -1, -1, -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:
            resa, resb, resc = a, b, c
print(resa, resb, resc)

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

print(-1, -1, -1)

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

n,money=map(int,input().split())
for x in range(n+1):
    for y in range(n+1):
        z=n-x-y
        if z<0:
            continue
        value=x*10000+y*5000+z*1000
        if value==money:
            print(x,y,z)
            sys.exit()
print(-1,-1,-1)

Solution (Python):

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

tmp = y
n_10000 = tmp // 10000
tmp = tmp - 10000 * n_10000

n_5000 = tmp // 5000
tmp = tmp - 5000 * n_5000

n_1000 = tmp // 1000
tmp = tmp - 1000 * n_1000

pure_list = [n_10000, n_5000, n_1000]
output_list = [-1, -1 ,-1]
if tmp == 0:
    if sum(pure_list) <= n:
        dif_10000 = n - sum(pure_list)
        if dif_10000 % 9 == 0 and pure_list[0] >= dif_10000 / 9:
            output_list = [int(pure_list[0] - dif_10000 / 9), pure_list[1], int(pure_list[2] + dif_10000 / 9 * 10)]
        else:
            for i in range(pure_list[0] + 1):
                now_list = [pure_list[0]-i, pure_list[1]+2*i, pure_list[2]]
                dif_5000 = n - sum(now_list)
                if dif_5000 % 4 == 0:
                    if now_list[1] >= dif_5000 / 4:
                        output_list = [now_list[0], int(now_list[1] - dif_5000 / 4), int(now_list[2] + dif_5000 / 4 * 5)]
                        break
print(str(output_list[0])+" "+str(output_list[1])+" "+str(output_list[2]))

Solution (Python):
input_list = list(map(int, input().split()))
count = input_list[0]
y = input_list[1]
flag = False
for l in range(count + 1):
    for m in range(count - l + 1):
        n = count - l - m
        if 10000 * l + 5000 * m + 1000 * n == y:
            print(l, m, n)
            flag = True
            break
        if flag:
            break
    if flag:
        break
if flag == False:
    print(-1, -1, -1)

Solution (Python):
N, Y = map(int,input().split())
 
for x in range(N+1):
    y = float((-9*x)/4 + (Y-1000*N)/4000)
    if not y.is_integer():
        continue
    if 0 <= y <= N-x:
        z =  N-y-x
        print(int(x),int(y),int(z))
        exit()
 
print(-1,-1,-1)

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

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

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