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):
a,b=map(int, input().split())
ans=0
for i in range(a+1):
    for j in range(a-i+1):
        z=a-i-j
        if 10000*i+5000*j+1000*z==b and ans==0:
            print(i,j,z)
            ans+=1
if ans==0:
    print(-1,-1,-1)

Solution (Python):


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

count = 0

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

print("-1 -1 -1")

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

done = False

for n_manen in range(0, n+1):
    for n_gosen in range(0, n+1):
        n_sen = n - n_manen - n_gosen
        if n_sen < 0:
            continue
        if n != n_manen + n_gosen + n_sen:
            continue
        total = 10000 * n_manen + 5000 * n_gosen + 1000 * n_sen
        if total == y:
            done = True
            break
    if done:
        break
else:
    n_manen, n_gosen, n_sen = -1, -1, -1

print('{} {} {}'.format(n_manen, n_gosen, n_sen))

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):
import sys

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

cnt = [0,0,0]
money = [1,5,10]

Y = Y // 1000

for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if k < 0: continue
        if (10 * i + 5 * j + k) == Y:
            print(i,j,k)
            sys.exit()
        
print(-1,-1,-1)

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

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

Solution (Python):
N,Y=map(int,input().split())
flag=False
for i in range(N+1):
    if flag==True:
        break
    else:
        pass
    for j in range(N+1-i):
        k=N-i-j
        if 10000*i+5000*j+1000*k==Y:
            print(i, j, k)
            flag=True
            break
        else:
            continue
if flag==False:
    print("-1 -1 -1")
else:
    pass

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

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

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

list = [-1, -1, -1]
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:
            list = [i, j, k]
            break
print(list[0], list[1], list[2])

Solution (Python):
import sys
import math
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

N,Y=na()

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


print(-1,-1,-1)

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

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

Solution (Python):
def find(n, y):
  for i in range(n+1):
    for j in range(n+1-i):
      if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
        return i, j, n-i-j
  return -1, -1, -1
N, Y = map(int, input().split())
i, j, k = find(N, Y)
print("{} {} {}".format(i, j, k))

Solution (Python):
def find(n, y):
  for i in range(n+1):
    for j in range(n+1-i):
      if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
        return i, j, n-i-j
  return -1, -1, -1
N, Y = map(int, input().split())
i, j, k = find(N, Y)
print("{} {} {}".format(i, j, k))

Solution (Python):
def comb(n,y):
    for i in range(n+1):
        for j in range(n+1-i):
            if 10000*i+5000*j+1000*(n-i-j)==y:
                return [i,j,n-i-j]
    return [-1,-1,-1]

n,y=map(int,input().split())
print("{} {} {}".format(*comb(n,y)))

Solution (Python):

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

def find():
  rhs = Y - 1000 * N

  for x in range(N+1):
    for y in range(N+1-x):
      if 9000 * x + 4000 * y == rhs:
        return x, y, N-x-y
      
  return -1, -1, -1

print(("{} {} {}").format(*find()))

Solution (Python):
NY = input().split()
N_Y = [int(s)for s in NY]

counter_Y = 0
counter = 0
listx = []
for i in range(N_Y[0]+1):
    for j in range(N_Y[0]+1):
        k = N_Y[0] - i - j
        counter_Y = 10000 * i + 5000 * j + 1000 * k
        if counter_Y == N_Y[1] and k >= 0:
            listx = [i,j,k]
            counter += 1

if counter == 0:
    print("-1 -1 -1")
else:
    print("{} {} {}".format(listx[0],listx[1],listx[2]))

Solution (Python):
n, y = map(int, input().split())
ans_i = -1
ans_j = -1
ans_k = -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 = i
            ans_j = j
            ans_k = k

print(str(ans_i) + " " + str(ans_j) + " " + str(ans_k))

Solution (Python):
n,y=map(int,input().split())
flag=False
list=[]
for i in range(n,-1,-1):
  for j in range(0, n-i+1):
    k=n-i-j
    if i*10000+j*5000+k*1000 == y and not(flag):
      flag=True
      list=[i,j,k]
if not(flag):
  print('{} {} {}'.format(-1,-1,-1))
else:
  print('{} {} {}'.format(list[0],list[1],list[2]))

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

Y/=1000

s=0

for i in range(N+1):
    for j in range(N+1-i):
        if i*10+j*5+(N-i-j)==Y:
            s=1
            print('{} {} {}'.format(i,j,N-i-j))
            break
    else:
        continue
    break

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

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

Y/=1000

s=0

for i in range(N+1):
    for j in range(N+1-i):
        if i*10+j*5+(N-i-j)==Y:
            s=1
            e=i
            f=j
            g=N-i-j

if s==0:
    print('-1 -1 -1')
else:
    print('{} {} {}'.format(e,f,g))

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


flg = False
for f in range(N+1):
    for h in range(N+1-f):
        if f * 10000 + h * 5000 + (N - f - h) * 1000 == Y and N-f-h >= 0:
            print("{} {} {}".format(f, h, (N - f - h)))
            flg = True
            break
    if flg is True:
        break

if flg is False:
    print("-1 -1 -1")

Solution (Python):


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

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

flag=1

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

Solution (Python):

import sys

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

if n * 10000 < y or y % 1000:
	print('-1 -1 -1')
	sys.exit()

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

print('-1 -1 -1')

Solution (Python):
N,Y = map(int, input().split())
a = Y//10000
b = (Y%10000)//5000
c = (Y%5000)//1000
for i in range(a+1):
    x = a-i
    y = b + i * 2
    for j in range(y+1):
        z = c + j * 5
        if x+y-j+z == N:
            print("{} {} {}".format(x,y-j,z))
            exit()
        if x+y-j+z > N:
            break
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()

a = -1
print(a, a, a)

Solution (Python):
def judge(N, Y):
	for i in range(0, N+1):
		for j in range(0, N-i+1):
			if 10000*i+5000*j+1000*(N-i-j) == Y:
				return str(i) + ' ' + str(j) + ' ' + str(N-i-j)
	return '-1 -1 -1'

N, Y = map(int, raw_input().split())
print judge(N, Y)

Solution (Python):
n, y = [int(i) for i in input().split(" ")]
a = 0
f = False

while y - 1000 * n - 9000 * a >= 0:
    r = (y - 1000 * n - 9000 * a)
    b = r // 4000
    if r % 4000 == 0 and n - a - b >= 0:
        print(a, b, n - a - b)
        f = True
        break
    a += 1

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

Solution (Python):
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N+1):
        if Y == 10000*x+5000*y+1000*(N-x-y) and N-x-y >=0:
            print("{} {} {}".format(x,y,N-x-y))
            break
    else:
        continue
    break
else:
    print("-1 -1 -1")

Solution (Python):

N,Y=map(int,input().split())
flag=0
for x in range(N+1):
    for y in range(N+1):
        if x+y>N:
            pass
        else:
            z=N-(x+y)
            if 10000*x+5000*y+1000*z == Y:
                flag=1
                X,Y,Z=x,y,z
                break
    if flag == 1:
        break
if flag == 0:
    print(-1,-1,-1,)
else:
    print(X,Y,Z)

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

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

for i in range(N+1):
    for j in range(N-i+1):
        if 10*i + 5*j + N-i-j == Y:
            print("{} {} {}".format(i, j, N-i-j))
            exit()

print("-1 -1 -1")

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

    for i in range(N + 1):
        for ii in range(N - i + 1):
            if i * 10000 + ii * 5000 + (N - i - ii) * 1000 == Y:
                print(i, ii, N - i - ii, end=' ')
                return
    print('-1 -1 -1')


main()

Solution (Python):
import sys

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

count = 0
for i in range(2001):
    for j in range(2001):
        k = n - i - j
        if k >= 0:
            sum = 10000*i + 5000*j + 1000*k
            if sum == y:
                print(i, j, k)
                sys.exit()
print('-1 -1 -1')

Solution (Python):
N,Y = (int(x) for x in 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]
            break
    else:
        continue
    break

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

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

for ten in range(n + 1):
    for five in range(n + 1 - ten):
        one = n - ten - five
        if ten * 10 + five * 5 + one == y:
            answer = [ten, five, one]
            break

print(answer[0], answer[1], answer[2]) if answer != [] else print("-1 -1 -1")

Solution (Python):


line = input()
line = line.split(" ")
N, Y = int(line[0]), int(line[1])

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

Solution (Python):
money_count, target_sum = map(int, input().split())

is_find = False

for yukichi_count in range(money_count + 1):
	for higuchi_count in range(money_count + 1 - yukichi_count):
		noguchi_count = money_count - yukichi_count - higuchi_count
		money_sum = yukichi_count * 10000 + higuchi_count * 5000 + noguchi_count * 1000
		if money_sum == target_sum:
			print(yukichi_count, higuchi_count, noguchi_count)
			is_find = True
			break
	if is_find:
		break

if not is_find:
	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-x):
    z = N-(x+y)
    if z < 0: break
    elif 10000*x + 5000*y + 1000*z == Y:
      print(x,y,z)
      sys.exit()
 
print(-1,-1,-1)

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

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

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

print(-1,-1,-1)

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

for x in range(N+1)[::-1]:
  for y in range(N+1)[::-1]:
    if x+y <= N:
      z = N-(x+y)
      if 10000*x + 5000*y + 1000*z == Y:
        print(x,y,z)
        sys.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:
      if 10000*x + 5000*y + 1000*z == Y:
        print(x,y,z)
        sys.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 10000*x + 5000*y + 1000*z == Y and z >= 0:
      print(x,y,z)
      sys.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: break
    elif 10000*x + 5000*y + 1000*z == Y:
      print(x,y,z)
      sys.exit()

print(-1,-1,-1)

Solution (Python):
N, Y = list(map(int, input().split()))
flag=0
try:
  for x in range(N+1):
    for y in range(N+1-x):
      z = N - x- y
      if x*10000 + y*5000 + z*1000 == Y:
        print(x, y, z)
        flag = 1
        raise Exception
except Exception:
  pass
if flag == 0:
  print('-1 -1 -1')

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

a = 4000
b = 9000

p = Y-N*1000
for i in range(N+1):
    for j in range(N+1):
        if i+j <= N:
            if a*i+b*j == p:
                k = N-i-j
                print(str(j)+' '+str(i)+' '+str(k))
                exit()
print('-1 -1 -1')

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

t = b//1000

f = False

for i in range(t//10+1):
    for j in range((t-i*10)//5+1):
        if a == t - i*9 - j*4 and b == i*10000+j*5000+(a-i-j)*1000 and a-i-j>=0:
            f = True
            break
    if f:
        break

if f:
    print(i,j,a-i-j)
else:
    print(-1,-1,-1)

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

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

a, b, c = calc()

print("{} {} {}".format(a, b, c))

Solution (Python):
import math
N,Y = map(int,input().split())
ans = 0
a,b,c = 0,0,0
for i in range(N + 1):
  for j in range(i + 1,N + 2):
    if abs(Y - ans) > abs(Y - (1000 * i + 5000 * (j - i - 1) + 10000 * (N + 1 - j))):
      ans = (1000 * i + 5000 * (j - i - 1) + 10000 * (N + 1 - j))
      a,b,c = i, j - i - 1, N + 1 - j
if ans == Y:
  print(c,b,a)
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):
    k = N-i-j
    if k >= 0:
      if 10000*i+5000*j+1000*k == Y:
        print(i, j, k)
        exit()
print(-1, -1, -1)

Solution (Python):
N,Y = map(int,input().split())
flag = 0
for a in range(N+1):
    for b in range(N+1):
        if a+b > N:
            break
        elif (N-(a+b))*1000 == Y-(10000*a+5000*b):
            A,B,C = a,b,N-(a+b)
            flag = 1
if flag == 0:print(-1,-1,-1)
else:print(A,B,C)

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


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

print('-1 -1 -1')

Solution (Python):
money  = [1000,5000,10000]
n,k = list(map(int,input().split()))

def calc_num(n,y):
    for i in range(n+1):
        for j in range((n+1)-i):
            if money[0]*i + money[1]*j + money[2]*(n-(i+j)) == y and i+j+(n-(i+j)) == n:
                return[n-(i+j),j,i]
    return[-1,-1,-1]

o = calc_num(n,k)
print(o[0],o[1],o[2])

Solution (Python):
N, Y = map(int, input().split())
ans = "-1 -1 -1"
for a in range(N+1):
	for b in range(N+1-a):
		if  1000 * (N-(a+b)) + 5000*b + 10000*a == Y:
			ans = str(a)+ " " + str(b) + " " + str(N-a-b)
print(ans)

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

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

print('-1 -1 -1')

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

Solution (Python):
N,Y = map(int,input().split())
na,nb,nc = -1,-1,-1
a,b,c = 10000,5000,1000

for i in range(N+1):
  for j in range(N-i+1):
    if a*i+b*j+c*(N-i-j) == Y:
      na,nb,nc = i,j,N-i-j
      break
print(na,nb,nc)

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



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

print(-1, -1, -1)

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

for n10000 in range(n+1):
    for n5000 in range(n - n10000 + 1):
        n1000 = n - n5000 - n10000
        money_total = n10000 * 10000 + n5000 * 5000 + n1000 * 1000
        if money_total == y:
            print(n10000, n5000, n1000)
            exit()

print(-1, -1, -1)

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

Solution (Python):
def hyouji(a):
    print(a[0], end=' ')
    print(a[1], end=' ')
    print(a[2], end=' ')


def kingaku(a):
    return 10000*a[0]+5000*a[1]+1000*a[2]


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

maisuu = [0,0,n]

for i in range(n+1):
    for j in range(n-i+1):
        maisuu = [i,j,n-i-j]
        if kingaku(maisuu) == y:
            hyouji(maisuu)
            exit()

print('-1 -1 -1')

Solution (Python):
li = input().split()
N = int(li[0])
Y = int(li[1])
p = "-1 -1 -1"

for i in range(2001):
  for j in range(2001):
    if N -i -j < 0:
      break
    if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
      p = "{} {} {}".format(i, j, N- i - j)

print(p)

Solution (Python):

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

def isValid(l, m, n):
    sum = l*10000 + m*5000 + n*1000
    if sum == Y:
        return True
    return False

for i in reversed(range(N+1)):
    for j in range(N+1):
        if i + j > N:
            break
        else:
            if isValid(i, j, N-i-j):
                flag = True
                print("{0} {1} {2}".format(i, j, N-i-j))
                break
        if flag:
            break
    if flag:
        break

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

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

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

for man in range(N+1):
  S = 0
  for gosen in range(N - man + 1):
      S = 10000*man + 5000*gosen + 1000*(N - man - gosen)
      if S == Y:
        z = N - man - gosen
        y = gosen
        x = man
        break

print(str(x) + " " + str(y) + " " + str(z))

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

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


print('-1 -1 -1')

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

Solution (Python):
n, y = [int(i) for i in input().split()]
noAnswer = True
count = 0
for i in range(n+1):
  if noAnswer != True:
      break
  for j in range(n+1):
    k = int(y/1000) - i*10 - j*5
    if k>=0 and n==i+j+k:
      noAnswer = False
      print("{} {} {}".format(i, j, k))
      break

if noAnswer:
  print("-1 -1 -1")

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

counter = False

for s in range(N+1):
    for t in range(N-s+1):
        if s*10000 + t*5000 + (N-s-t)*1000 == Y:
            counter = True
            break
    if counter == True:
        break
if counter == False:
    output = "-1 -1 -1"
elif counter == True:
    output = "{0} {1} {2}".format(s,t,N-s-t)
print(output)

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 Y == 10000 * i + 5000 * j + 1000 * (N - i - j)\
        and i + j + (N - i - j) <= N\
        and N - i - j >= 0:
            ans = str(i) + ' ' + str(j) + ' ' + str(N - i - j)
print(ans)

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 Y == 10000 * i + 5000 * j + 1000 * (N - i - j)\
        and i + j + (N - i - j) <= N\
        and N - i - j >= 0:
            ans = str(i) + ' ' + str(j) + ' ' + str(N - i - j)
print(ans)

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

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


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

Solution (Python):



import sys


def solve(n,y):
  for a in range(n+1):
    for b in range(n+2-a):
      if a+b > n:
        continue
      sm = 10000*a + 5000*b + 1000*(n-a-b)
      if sm == y:
        print(a,b,n-a-b)
        return
  print(-1,-1,-1)
  return

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

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

man, gosen, sen = -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):
      man = i
      gosen = j
      sen = n - i - j
      break
print(man, gosen, sen)

Solution (Python):
n, y = [int(item) for item in input().split()]
a, b, c = 0, 0, 0
bills = y // 1000
a = bills

while a >= 0:
    if (bills - n) % 4 == 0: 
        b = (bills - n) // 4
        check_a = a-(b*5)
        if check_a+b+c == n and b>=0 and check_a>=0:
            print(c, b, check_a)
            exit()
    c += 1
    a -= 10
    bills -= 9
print(-1, -1, -1)

Solution (Python):


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

is_searched = False

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)
            is_searched = True
            break
    if is_searched:
        break
else:
    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):
        k = N - (i + j)
        if k >= 0 and 10000 * i + 5000 * j + 1000 * k == Y:
            ans = '{} {} {}'.format(i, j, k)
            break
    else:
        continue
    break
print(ans)

Solution (Python):
s = input().rstrip().split()
N = int(s[0])
Y = int(s[1])
ans_x = -1
ans_y = -1
ans_z = -1
for x in range(N+1):
    for y in range(N-x+1):
        total = 10000*x + 5000*y + 1000*(N-x-y)
        if total == Y:
            ans_x = x
            ans_y = y
            ans_z = N-x-y
            break
print(str(ans_x)+' '+str(ans_y)+' '+str(ans_z))

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

for x in range(N+1):
    for y in range(N+1-x):
            z=N-x-y
            if 10*x+5*y+z==Y and z>=0:
                print(str(x)+' '+str(y)+' '+str(z))
                exit()
print(error)

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

Solution (Python):
n,y = map(int,input().split())
total = 0
for i in range(n+1):
	for j in range(n+1-i):
		k = n - i - j
		total = i*10000 + j*5000 + k*1000
		if total == y:
			print(i,j,k)
			break
		total = 0
	else:
		continue
	break
else:
	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+1-i):
        k = N-(i+j)
        if i * A + j * B + k * C == Y and k >= 0:
            print(str(i)+" "+str(j)+" "+str(k))
            exit()
                
print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())
_10000 = -1
_5000 = -1
_1000 = -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:
            _10000 = i
            _5000 = j
            _1000 = k
            break
    else:
        continue
    break
print(_10000, _5000, _1000)

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

def ans(a,b):
  for i in range(a + 1):
    for j in range(a - i + 1):
      if i * 10000 + j * 5000 + (a - i - j) * 1000 == b:
        return(i, j, a-i-j)
  return(-1, -1, -1)

A = ans(N, Y)

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

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

def otoshidama():
    for i in range(N+1):
        for j in range(N+1-i):
            if i * 10000 + j * 5000 + 1000 * (N-i-j) == Y:
                return str(i) + " " + str(j) + " " + str(N-i-j)
    return "-1 -1 -1"

print(otoshidama())

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, Y = LI()

m = [10000, 5000, 1000]


"""
2000枚をどうふりわけるかで考える？
2000 0 0
1999 1 0
1998 2 0
的な
左端を固定、残りを右側でdfsしたら、
例えば1000なら、1000通り試せば良い
10**6ぐらいで終わるか？
"""
for i in range(N + 1):
    
    ten = m[0] * i
    rest = N - i
    
    for j in range(rest + 1):
        five = m[1] * j
        one = m[2] * (rest - j)
        if ten + five + one == Y:
            print(i, j, rest - j)
            exit()
else:
    print(-1, -1, -1)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, Y = LI()

m = [10000, 5000, 1000]


"""
2000枚をどうふりわけるかで考える？
2000 0 0
1999 1 0
1998 2 0
的な
左端を固定、残りを右側でdfsしたら、
例えば1000なら、1000通り試せば良い
10**6ぐらいで終わるか？
"""
for i in range(N + 1):
    
    ten = m[0] * i
    rest = N - i
    
    for j in range(rest + 1):
        five = m[1] * j
        one = m[2] * (rest - j)
        if ten + five + one == Y:
            print(i, j, rest - j)
            exit()
else:
    print(-1, -1, -1)

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

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

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

count_max = Y / 1000  

ans = '-1 -1 -1'
for i in range(N+1):  
    for j in range(N+1 - i):  
        k = N - i - j
        if k < 0:
            continue
        total = 10000 * i + 5000 * j + 1000 * k
        if total == Y:
            ans = '{} {} {}'.format(i, j, k)
            break
print(ans)

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

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

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