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):
stdin = input().split()
n = int(stdin[0])
y = int(stdin[1]) / 1000

y_i = y % 5
n1 = n - y_i
y1 = y - y_i

ok = False
for num_x in range(int(y1/10) + 1):
    if num_x > n1:
        break
    y2 = y1 - 10*num_x
    for num_v in range(int(y2/5) + 1):
        if num_x + num_v > n1:
            break
        num_i = y2 - 5*num_v
        if num_x + num_v + num_i == n1:
            ok = True
            break
    if ok:
      break

if ok:
    print("{} {} {}".format(int(num_x), int(num_v), int(num_i + y_i)))
else:
    print("-1 -1 -1")

Solution (Python):

import sys, math, fractions, itertools


def solve(N: int, Y: int):
    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)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)

if __name__ == '__main__':
    main()

Solution (Python):
def solve():
    n, y = read()
    result = think(n, y)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return list(map(int, read_line().split()[:n]))


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, y):
    for i in range(n + 1):
        for j in range(n + 1):
            if i + j > n:
                continue
            k = n - i - j
            if 10000 * i + 5000 * j + 1000 * k == y:
                return [i, j, k]
    return [-1, -1, -1]


def write(result):
    print('{0:d} {1:d} {2:d}'.format(result[0], result[1], result[2]))


if __name__ == '__main__':
    solve()

Solution (Python):
N, Y = map(int, input().split())
L    = [10000, 5000, 1000]

is_fail = True

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

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

Solution (Python):
N, Y = map(int, input().split())
count = 0
for a in range(N+1):
  for b in range(N-a+1):
    if Y == 10000*a+5000*b+1000*(N-a-b) and count == 0:
      print("{} {} {}".format(a, b, N-a-b))
      count += 1
    else:
      pass

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

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

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

Solution (Python):
N,Y = map(int,input().split())
S = []
ans = []
tn = Y//10000
for i in range(tn+1):
    y1 = 0
    y1 = Y-10000*i
    fn = y1//5000
    for j in range(fn+1):
        y2 = 0
        y2 = y1 - 5000*j
        on = y2//1000
        if i+j+on == N:
            ans = [i,j,on]
            break
if len(ans)<=0:
    print("-1 -1 -1")
else:
    ans = [ str(x) for x in ans]
    print(ans[0]+" "+ans[1]+" "+ans[2]+" ")

Solution (Python):
n, y = map(int, input().rstrip().split())
a, b, c = -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:
            a, b, c = i, j, n-i-j
            break
    else:
        continue
    break
print(a, b, c)

Solution (Python):
n, y = map(int, input().rstrip().split())
a, b, c = -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:
            a, b, c = i, j, n-i-j
            break
    else:
        continue
    break
print(a, b, c)

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

Solution (Python):
yukichi_num = 0
ichiyou_num = 0
d,e,f = -1,-1,-1
a,b = map(int,input().split())
for i in range(a+1):
    for  n in range(a+1-i):
        if i*10000+n*5000+1000*(a-i-n) == b:
            d = i
            e = n
            f = a-i-n
print('{0} {1} {2}'.format(d,e,f))

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('{} {} {}'.format(i,j,N-i-j))
            exit()
print("-1 -1 -1")

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


def main():
    x, y, z = detect()
    print(x, y, z)


def detect():
    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:
                return x, y, z
    return -1, -1, -1


main()

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(lambda x: int(x), input().split(' '))
Y /= 1000

limit = 10*N

if limit < Y:
    print(-1, -1, -1) 
    exit(0)
elif Y == limit:
    print(N, 0, 0)
    exit(0)

_N = limit-Y
for i in range(0, int(_N/9)+1):
    yy = _N - 9*i 
        
    if yy % 5 == 0:
        k = int(yy/5)
        if N-k-i >= 0:
            print(N-k-i, k, i)
            exit(0)

print(-1, -1, -1)

Solution (Python):
import numpy as np
N,Y = map(int, input().split())

count = 0
for a in range(0,N+1):
    res_b =  (Y - 1000*N - 9000*a)%4000
    if res_b > 0:
        continue
    else:
        b = (Y - 1000*N - 9000*a)//4000
        c = N - a - b
        if (b>=0)&(b<=N)&(c>=0)&(c<=N):
            print('{} {} {}'.format(a,b,c))
            count += 1
            break
if count == 0:
    print('{} {} {}'.format(-1,-1,-1))

Solution (Python):
import itertools
n,y = map(int,input().split())
for i,j in itertools.product(range(0,n+1),range(0,n+1)):
  c = n-i-j
  sum_y = 10000*i + 5000*j + 1000*c
  if sum_y == y and c>=0:     
    print(i,j,c)
    break
else:
  print(-1,-1,-1)

Solution (Python):
N,Y = list(map(int,input().split()))
flag_1000,flag_5000,flag_10000,flag = True,True,True,True
ans_10000,ans_5000,ans_1000 = -1,-1,-1

while flag:
    for num_10000 in range(N+1):
        if flag_5000 == False:
            flag = False
            break
        for num_5000 in range((N-num_10000)+1):
            if Y == 10000*num_10000 + 5000*num_5000 + 1000*(N-num_10000-num_5000):
                ans_10000,ans_5000,ans_1000 = num_10000,num_5000,N-num_10000-num_5000
                flag_5000 = False
                break
            if num_10000 == N:
                flag=False
print(ans_10000,ans_5000,ans_1000)

Solution (Python):
N, Y =map(int,input().split())
ans = (-1,-1,-1)
for yukichi in range(N+1):
    for ichiyo in range(N+1-yukichi):
        hideyo = N-yukichi-ichiyo
        if Y == 10000*yukichi+5000*ichiyo+1000*hideyo:
            ans = (yukichi,ichiyo,hideyo)
print(*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())

for i in range(0,N+1):
    for j in range(0,N-i+1):
        if 9*i+4*j + N== Y/1000:
            print(str(i)+" "+str(j)+" "+str(N-i-j))
            exit()
        
print("-1 -1 -1")

Solution (Python):


n, y = [int(x) for x in input().split(' ')]

max_iti_man = y // 10000

for iti_man in range(max_iti_man + 1):
    for go_sen in range(int(n) - iti_man + 1):
        itigo = 5000 * go_sen + 10000 * iti_man
        sen = n - iti_man - go_sen
        if 1000 * sen + itigo == y:
            print("{} {} {}".format(iti_man,go_sen,sen))
            exit()

print("-1 -1 -1")

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


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

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

Solution (Python):
def hantei(n,y):
  for i in range(n+1):
    yukichi = i
    for j in range(n-yukichi+1):
      higuchi = j
      noguchi=n-i-j
      
      if 10000*yukichi + 5000*higuchi + 1000*noguchi == y:
        return[yukichi,higuchi,noguchi]
    
  return [-1,-1,-1]
  
n,y=map(int,input().rstrip().split())

print('{0[0]} {0[1]} {0[2]}'.format(hantei(n,y)))

Solution (Python):
def find_bill_combination(n, y):
	q, mod = divmod(y, 10000)
	if n * 10000 > y > (n - 1) * 10000 + 5000:
		return '-1 -1 -1'
	else:
		if q == n and mod == 0:
			return '{} 0 0'.format(q)
		else:
			for a in range(q + 1):
				b = int((y - 1000 * n - 9000 * a) / 4000)
				c = int((5000 * n - y + 5000 * a) / 4000)
				if a + b + c == n and a >= 0 and b >= 0 and c >= 0 and 10000 * a + 5000 * b + 1000 * c == y:
					return '{} {} {}'.format(a, b, c)
			else:
				return '-1 -1 -1'


def main():
	n, y = map(int, input().split(' '))
	print(find_bill_combination(n, y))


if __name__ == '__main__':
	main()

Solution (Python):
def find_bill_combination(n, y):
	q, mod = divmod(y, 10000)
	if n * 10000 > y > (n - 1) * 10000 + 5000:
		return '-1 -1 -1'
	else:
		if q == n and mod == 0:
			return '{} 0 0'.format(q)
		else:
			for a in range(q + 1):
				b = int((y - 1000 * n - 9000 * a) / 4000)
				c = int((5000 * n - y + 5000 * a) / 4000)
				if a + b + c == n and a >= 0 and b >= 0 and c >= 0 and 10000 * a + 5000 * b + 1000 * c == y:
					return '{} {} {}'.format(a, b, c)
			else:
				return '-1 -1 -1'


def main():
	n, y = [int(x) for x in input().split(' ')]
	print(find_bill_combination(n, y))


if __name__ == '__main__':
	main()

Solution (Python):
n, y = [int(x) for x in input().split(' ')]
q, mod = divmod(y, 10000)

if n * 10000 > y and y > (n-1)* 10000 + 5000:
	print('-1 -1 -1')
else:
	if q == n and mod == 0:
		print('{} 0 0'.format(q))
	else:
		for a in range(q+1):
			b = int((y - 1000 * n - 9000 * a) / 4000)
			c = int((5000 * n - y + 5000 * a) / 4000)
			if a + b + c == n and a >= 0 and b >= 0 and c >= 0 and 10000 * a + 5000 * b + 1000 * c == y:
				print('{} {} {}'.format(a, b, c))
				break
		else:
			print('-1 -1 -1')

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

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

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

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

man = Y // 10000
fif = Y // 5000
judge = 0
eg = [-1, -1, -1]
for i in range(man+1):
	for j in range(fif+1):
		if Y - i*10000 - j*5000 < 0 or N - i - j < 0:
			break
		if (N - i - j)*1000 == (Y - i*10000 - j*5000):
			eg = [i,j,N-i-j]
			judge = 1
	if judge == 1:
		break

for i in range(3):
	print(eg[i], end="")
	print(" ", end="")
print("\n")

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):
    if 10*i+5*j+(n-i-j)==y:
      print(i,j,n-i-j)
      exit(0)
print(-1,-1,-1)

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

Solution (Python):
n , y= map(int, input().split())
ans = 0
li = []
for i in range(n+1):
    for j in range(n+1):
        if 10000 * i + 5000*j +1000 * (n-i-j) == y and n-i-j >= 0:
            print(i, j, n-i-j)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

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

Solution (Python):
import sys

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

a = 10000
b = 5000
c = 1000
l = 0
m = 0
r = 0
sta = 0
stb = 0

for x in range(n+1):
    for z in range(n+1-x):
        sum = x * a + z * b + (n - x - z) * c

        if sum==y:
            print("{} {} {}".format(x,z,n-x-z))
            sys.exit()

print("{} {} {}".format(-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-i):
    k = N - i - j
    if 10000 * i + 5000 * j + 1000 * k == Y:
      flag = True
      x = i
      y = j
      z = k

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

Solution (Python):
N, Y = map(int, input().split())
res10000 = -1
res5000 = -1
res1000 = -1

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:
            res10000 = x
            res5000 = y
            res1000 = z
            
print(str(res10000) + " " + str(res5000) + " " + str(res1000))

Solution (Python):
[N,Y]=list(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(" ".join([str(item) for item in [x,y,z]]))
      exit()
print("-1 -1 -1")

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

flag = False

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

print('{0} {1} {2}'.format(x, y, z))

Solution (Python):
N, Y = map(int, input().split())
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:
            print(i, j, (N - i - j))
            exit()

print(-1, -1, -1)

Solution (Python):
import sys

N,Y = input().split()
N = int(N)
Y = int(Y)
A = [0]*3

for i in range(N+1):
    A[0] = i
    for j in range(N-i+1):
        A[1] = j
        A[2] = N - i - j
        if 10000*A[0] + 5000*A[1] + 1000*A[2] == Y:
            print(str(A[0]) + " " + str(A[1]) + " " + str(A[2]))
            sys.exit()
print("-1 -1 -1")

Solution (Python):
import sys

n, y = map(int, input().split())
money = 0
a = 0
b = 0
c = 0

for i in range(n+1) :
  for j in range(n-i,-1,-1) :
    a = i
    b = j
    c = n - i - j
    money = 10000*a + 5000*b + 1000*c
    if money == y :
      print(a,b,c)
      sys.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):
import sys
n, y = [int(e) for e in raw_input().split()]
for i in range(n + 1):
  for j in range(n + 1 - i):
    k = n - i - j
    if 10000 * i + 5000 * j + 1000 * k == y:
      print "%d %d %d" % (i, j, k)
      sys.exit()
print "-1 -1 -1"

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

Solution (Python):


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

n10000 = -1
n5000 = -1
n1000 = -1

for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if i*10000+j*5000+1000*k == y:
            n10000 = i
            n5000 = j
            n1000 = k

print(n10000,n5000,n1000)

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

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

Solution (Python):


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

n10000 = -1
n5000 = -1
n1000 = -1

for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if i*10000+j*5000+1000*k == y:
            n10000 = i
            n5000 = j
            n1000 = k

print(n10000,n5000,n1000)

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

for i in range(0, N+1)[::-1]:
  for j in range(0, N-i+1)[::-1]:
    k = N - i - j
    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(' '))
for x in range(N+1):
    for y in range(N-x+1):
        if 10000*x + 5000*y + 1000*(N-x-y) == Y:
            print(x,y,N-x-y)
            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 a*10000 + b*5000 + (n-a-b)*1000 == y:
            print(str(a)+' '+str(b)+' '+str(n-a-b))
            quit()
print('-1 -1 -1')

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

for a in range(0, n+1):
    for b in range(0, 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(N+1):
  for j in range(N-i+1):
    if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
      print(str(i) + ' ' + str(j) + ' ' + str(N - i - j))
      exit()
print('-1 -1 -1')

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

for i in range(N, -1, -1):
    for j in range(N-i, -1, -1):
        k = N - i - j
        if k >= 0 and 10000 * i + 5000 * j + 1000 * k == Y:
            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, -1):
    for j in range(N-i, -1, -1):
        k = N - i - j
        if k >= 0 and 10000 * i + 5000 * j + 1000 * k == Y:
            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,-1):
    for j in range(N-i,-1,-1):
        k = N - i - j
        if k >= 0 and 10000 * i + 5000 * j + 1000 * k == Y:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print('-1 -1 -1')

Solution (Python):
N, Y = list(map(int, input().split()))
for i in range(N,-1,-1):
    y2 = Y - 10000 * i
    if y2 >= 0:
        for j in range(N-i,-1,-1):
            y3 = y2 - 5000 * j
            k = N - i - j
            if k >= 0 and y3 - 1000 * k == 0:
                print(i, j, k)
                break
        else:
            continue
        break
else:
    print(-1, -1, -1)

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

bo = 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(str(i) + ' ' + str(j) + ' ' + str(N - i - j))
      bo = True
      exit()

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

Solution (Python):

def solve(N, Y):
    for m in range(int(Y/10000) + 1):
        for g in range(int(Y/5000) + 1):
            s = N - m - g
            if 0 <= s == (Y - m * 10000 - g * 5000) / 1000.0:
                return '{} {} {}'.format(m, g, s)
    return '-1 -1 -1'


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

Solution (Python):

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

def solve(N, Y):
    for x in range(N+1):
        for y in range(N-x+1):
            z = N-(x+y)
            if (x * 10000 + y * 5000 + z * 1000 == Y):
                return x, y, z
            
    return -1, -1, -1

x, y, z = solve(N,Y)

print("%d %d %d" % (x,y,z))

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

Solution (Python):
a, b = map(int, input().split())
for i in range(2001):
    c = 10000 * i
    if c + (a - i) * 5000 >= b:
        for j in range(2001):
            d = 5000 * j
            e = i + j
            if (b - (c + d)) < 0:
                break
            else:
                if (b - (c + d)) // 1000 == (a - e):
                    print(i, j, (a - e))
                    exit()
print("-1 -1 -1")

Solution (Python):
import copy
import sys
import math

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


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Solution (Python):
N, Y = map(int, input().split())
flag = False
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 and c >= 0:
            flag = True
            break
    if flag:
        break
if flag:
    print('{} {} {}'.format(a, b, c))
else:
    print('-1 -1 -1')

Solution (Python):



tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
y=hoge[1]

max10=y//10000
max5=y//5000
max1=y//1000

flg=0
for i in range(0,max10+1):
	for j in range(0,max5+1):
		k=n-i-j
		if(k>=0)and(i*10000+j*5000+k*1000==y):
			flg=1
			break
	else:
		continue
	break
if flg:
	print("{} {} {}".format(i,j,k))
else:
	print("-1 -1 -1")

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

max_num = y // 1000

flag = 0
for i in range(0, n+1):
  for j in range(0, n+1):
    if (n - (i + j)) == (max_num - (10 * i + 5 * j)) and (n - (i + j)) >= 0:
      print(i, j, n - (i + j))
      flag = 1
      break
  if flag == 1:
    break

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

Solution (Python):
n,y=map(int,input().split())
for i in range(y//10000+1):
    for j in range((y-10000*i)//5000+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())
for i in range(N+1):
    for j in range(0, N-i+1):
        k = N - i - j
        total_momey = 10000 * i + 5000 * j + 1000 * k
        if total_momey == Y:
            print("{} {} {}".format(i, j, k))
            exit()
print("-1 -1 -1")

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

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

print(*otoshidama())

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

Y = Y // 1000
if Y >= N:
    K = Y - N
    z = 0
    while True:
        if 9*z > K:
            x, y, z = -1, -1, -1
            break
        if (K - 9*z) % 4 == 0:
            y = (K - 9*z) // 4
            if N >= y + z:
                x = N - y - z
                break
        z += 1
else:
    x, y, z = -1, -1, -1

print(z, y, x)

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

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


for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j
        yen = 10000 * i + 5000 * j + 1000 * k
        if yen == total:
            x = i
            y = j
            z = k
            break

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

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

Solution (Python):
n, y = map(int, input().split())
answer_a = -1
answer_b = -1
answer_c = -1


for a in range(0, n+1):
  for b in range(0, n-a+1):
    c = n-a-b
    if 10000*a+5000*b+1000*c == y and c>=0:
      answer_a = a
      answer_b = b
      answer_c = c
print("{} {} {}".format(answer_a,answer_b,answer_c))

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

for nog in range(n+1):
    for hig in range(n+1 -nog):
        yuk = n - nog - hig
        if nog + hig*5 + yuk*10 == y:
            print(yuk, hig, nog)
            exit(0)
print("-1 -1 -1")

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

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

y1=Y/1000 
g=0
for i in range(0,n+1):
    if (y1-i)%5==0 and (y1-i)>=0:
        h=(y1-i)/5
        for j in range(0,n-i+1):
            if (h-j)%2==0 and (i+j+int((h-j)/2))==int(n):
                k=int((h-j)/2)
                g=1
                break
    if g==1:
        break
if g==0:
    print("-1 -1 -1")
else:
    print(str(k)+" "+str(j)+" "+str(i))

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

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

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

for x in range(N+1) :
    for y in range(N+1-x) :
        calc = x*10000 + y*5000 + (N-x-y)*1000        
        if calc == Y :
            ans = [x,y,N-x-y]
            break

print(*ans)

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

ans = "-1 -1 -1"

for x in range(N+1) :
    calc = x*10000
    if calc > Y :
        break
    for y in range(N+1-x) :
        calc = x*10000 + y*5000 + (N-x-y)*1000
        if calc > Y :
            break
        
        if calc == Y :
            ans = str(x) + " " + str(y) + " " + str(N-x-y)
            break

print(ans)

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

a = b = c = -1

for i in range(0,n+1):
    x = i
    for j in range(0,n+1-x):
        
        y = j
        z = n - i - j
        if n >= x >=0 and n >= y >=0 and n >= z >=0:
            if total == 10000*int(x) + 5000*int(y) + 1000*int(z):
                a = x
                b = y
                c = z
                break
            else:
                continue
            break
print(a,b,c)

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

for i in range(n+1):
    if i*10000 + (n-i)*1000 > total:
        break
    if i*10000 + (n-i)*5000 < total:
        continue
    for j in range(n+1-i):
        if i*10000 + j*5000 + (n-i-j)*1000 == total:
            x, y, z = i, j, (n-i-j)
            break
    else:
        continue
    break

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

Solution (Python):
n, total = map(int, input().split())
flag1 = False
flag2 = True
for i in range(n+1):
    x = i
    for j in range(n+1-x):
        y = j
        z = n - x - y
        if x*10000 + y*5000 + z*1000 == total:
            flag1 = True
            break
    if flag1:
        print(x, y, z)
        flag2 = False
        break

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

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

Y /= 1000

x=int(Y//10)
y= int((Y % 10) // 5)
z=int((Y % 10) % 5)

flag = False

if x+y+z > N:
  print(-1,-1,-1)
  
elif x + y + z == N:
  print(x , y , z)
  
else:
  for i in range (N):
    for j in range(N-i):
      if 10*i+5*j+(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())

Y /= 1000

x=int(Y//10)
y= int((Y % 10) // 5)
z=int((Y % 10) % 5)

flag = False

if x+y+z > N:
  print(-1,-1,-1)
  
elif x + y + z == N:
  print(x , y , z)
  
else:
  for i in range (N):
    for j in range(N-i):
      if 10*i+5*j+(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())

Y /= 1000

x=int(Y//10)
y= int((Y % 10) // 5)
z=int((Y % 10) % 5)

flag = False

if x+y+z > N:
  print(-1,-1,-1)
  
elif x + y + z == N:
  print(x , y , z)
  
else:
  for i in range (N):
    for j in range(N-i):
      if 10*i+5*j+(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())

Y /= 1000

x=int(Y//10)
y= int((Y % 10) // 5)
z=int((Y % 10) % 5)

flag = False

if x+y+z > N:
  print(-1,-1,-1)
  
elif x + y + z == N:
  print(x , y , z)
  
else:
  for i in range (N):
    for j in range(N-i):
      if 10*i+5*j+(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):
import math

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

Y = Y/1000

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

print("-1 -1 -1")