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):
import sys
a,b=(int(x) for x in input().split())
b//=1000
for i in range(a+1):
    for j in range(a-i+1):
        if 10*i+5*j+(a-i-j)==b:
            print(str(i)+" "+str(j)+" "+str(a-i-j))
            sys.exit()
print("-1 -1 -1")

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

ans = False

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 c >= 0:
            print(a, b, c)
            ans = True
            break
    if ans:
        break
if not ans:
    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):
        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())
Y //= 1000

for x in range(N+1):
    if (Y - N -9*x) % 4 == 0 and (-Y +5*N + 5*x) % 4 == 0:

        y = (Y - N -9*x) // 4
        z = (-Y +5*N + 5*x) // 4
        if y >= 0 and z >= 0:
            print(x, y, z)
            break
else:
    print(-1, -1, -1)

Solution (Python):
def calc(N, Y):
    for x in reversed(range(N + 1)):
        if x* 10000 > Y: continue 
        for y in reversed(range(N + 1 - x)):
            z= N -  x- y
            s = z* 1000 + y* 5000 + x* 10000
            if  s == Y:
                return x, y, z
    return -1, -1, -1

_N, _Y = tuple(map(int, input().split()))
print(*calc(_N, _Y))

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(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())
for i in range(n + 1):
  for j in range(n - i + 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):
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


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

Solution (Python):
n,y = (int(i) for i in input().split())
y/=1000
payed = False
for i in range(n+1):
    if payed:
        break
    for j in range(n+1-i):
        k = n-i-j
        if k>=0:
            if i*10+j*5+k==y:
                print(i,j,k)
                payed = True
                break
if not payed:
    print(-1,-1,-1)

Solution (Python):
def shouldBreak(x, y, z):
    if x == -1 and y == -1 and z == -1:
        return False
    else:
        return False

l = list(map(int, input().split()))
N = l[0]
Y = l[1]

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

N_10000 = 0
while N_10000 <= N:
    N_5000 = 0
    while N_5000 <= N - N_10000:
        N_1000 = N - N_10000 - N_5000
        if Y == 10000 * N_10000 + 5000 * N_5000 + 1000 * N_1000:
            x = N_10000
            y = N_5000
            z = N_1000
            break
        N_5000 += 1
    if shouldBreak(x, y, z):
        break
    N_10000 += 1
print(str(x)+ " " + str(y) + " " + str(z))

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

for y10 in range(y//10 + 1):
    if y10 > n:
        continue
    rest = y - 10 * y10
    tmp = rest - n + y10
    if tmp % 4 == 0:
        y5 = tmp // 4
        y1 = n - y10 -y5
        if y1 < 0 or y5 < 0:
            continue
        print(y10, y5, y1)
        exit()
print(-1, -1, -1)

Solution (Python):

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



x = []
y = []
z = []

for num_ten_thousand in range(0, N+1):
    for num_five_thousand in range(0, N+1):
            
            
            if N-(num_ten_thousand+num_five_thousand)>=0:
                num_one_thousand = N-(num_ten_thousand+num_five_thousand)
            
            
            total = num_ten_thousand*10000 + num_five_thousand*5000 + num_one_thousand*1000
            
            
            if Y==total and N==num_ten_thousand+num_five_thousand+num_one_thousand:
                x.append(num_ten_thousand)
                y.append(num_five_thousand)
                z.append(num_one_thousand)
                
                

if not x:
    print(-1, -1, -1, sep=" ")
    
else:
    print(x[0], y[0], z[0], sep=" ")

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

max_10k = int(Y / 10000)
max_5k = int(Y / 5000)

for num_10k in range(max_10k, -1, -1):
    for num_5k in range(max_5k - num_10k, -1, -1):
        num_1k = N - num_10k - num_5k
        if num_1k >= 0 and num_10k * 10000 + num_5k * 5000 + num_1k * 1000 == Y:
            print(num_10k, num_5k, num_1k)
            quit()

print("-1 -1 -1")

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

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

Solution (Python):
n,y = map(int,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()
print('-1 -1 -1')

Solution (Python):
def main():
    n, y = map(int, input().strip().split())
    z = y // 1000
    
    
    
    for a in range(z - n // 9):
        if (z - n - 9 * a) % 4 == 0:
            b = (z-n-9*a)//4
            if b < 0:
                continue
            c = n - a - b
            if c < 0:
                continue
            print(a, b, c)
            return
    print("-1 -1 -1")


if __name__ == '__main__':
    main()

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

for i in range(n+1):
    for j in range(n+1-i):
        for k in range(n-i-j, n+1-i-j):
            if 10000*i + 5000*j + 1000*k == y:
                flag = 1
                break
        else:
            continue
        break
    else:
        continue
    break

if flag == 1:
    print(i, j, k)
else:
    print(-1, -1, -1)

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

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

print(-1,-1,-1)

Solution (Python):
import sys
N, Y = map(int, raw_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
            sys.exit()
print "-1 -1 -1"

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

for x in range(n+1):
    for y in range(n+1-x):
        if 9*x + 4*y == k - n:
            print(x, y, n-(x+y))
            exit()
print(-1, -1, -1)

Solution (Python):
n,y = map(int,input().split())
ok = False
ans = []
for tenk in range(0,2001):
    if ok :
        break
    for fivek in range(0,2001):
        if n-tenk-fivek >= 0 and 10000*tenk + 5000*fivek + 1000*(n-tenk-fivek) == y:
            ans.append(tenk)
            ans.append(fivek)
            ans.append(n-tenk-fivek)
            ok = True
            break
if ok:
    print(ans[0],ans[1],ans[2])
else :
    print('-1 -1 -1')

Solution (Python):


def main():
    sa = input().split(' ')
    N = int(sa[0])
    Y = int(sa[1])

    f = False
    for x in range(N + 1):
        if Y < 10000 * x:
            break
        for y in range(N + 1 - x):
            z = N - x - y
            if 10000 * x + 5000 * y + 1000 * z == Y:
                f = True
                break
            if Y < 10000 * x + 5000 * y:
                break
        if f:
            break

    if f:
        print('{} {} {}'.format(x, y, z))
    else:
        print('-1 -1 -1')


if __name__ == '__main__':
    main()

Solution (Python):
n,y = map(int, input().split())
ans_list = ['-1 -1 -1']
for i in range(n+1):
    for j in range(n+1):
        yen = 10000*i+5000*j+1000*(n-(i+j))
        if y == yen and n-(i+j) >= 0:
            ans_list.append(str(i)+' '+str(j)+' '+str(n-(i+j)))
if len(ans_list) == 1:
    print(ans_list[0])
else:
    print(ans_list[1])

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


abc085_c()

Solution (Python):
N, Y = map(int, input().split())
res10 = -1
res5 = -1
res1 = -1
for i in range(N+1):
    for j in range(N+1):
        l = N-i-j
        if 10000*i + 5000*j + 1000*l == Y and i+j+l==N and l>=0:
            res10 = i
            res5 = j
            res1 = l
            break
print(res10, " ", res5, " ", res1)

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

man = gosen= sen = -1

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:
            man=i
            gosen=j
            sen=k

print(man, gosen, sen)

Solution (Python):



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

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

    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):
n, y = map(int, input().split())
y //= 1000
flag = False
for i in range(n+1):
  for j in range(n+1-i):
    k = n - i - j
    z = y - i - j * 5
    if z >= 0 and z % 10 == 0 and z // 10 == k:
      print(k, j, i)
      flag = True
      break
  if flag:
    break
  
else:
  print("-1 -1 -1")

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

bool = False
answer=[0,0,0]
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:
            answer=[a,b,c]
            bool=True

if bool==False:
    print(-1, -1, -1)

if bool==True:
    print(answer[0], answer[1], answer[2])

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


print('-1 -1 -1')

Solution (Python):
import sys

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

for a in range(n+1):
	for b in range(n+1-a):
		c = n - a - b
		if (a * 10000 + b * 5000 + c * 1000 == y):
				print(str(a) + ' ' + str(b) + ' ' + str(c))
				sys.exit()
	
print('-1 -1 -1')
sys.exit()

Solution (Python):
def main():
    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:
                continue
            if i * 10000 + j * 5000 + k * 1000 == y:
                print(i, j, k)
                return
    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):

def main():
    (N,Y) = map(int,input().split())
    x = 0
    y = 0
    z = 0
    flag = False

    for x in range(int(Y/10000)+1):
        for y in range(int((Y-10000*x)/5000)+1):
            z = (Y - (10000*x) - (5000*y)) / 1000
            if x+y+z == N:
                flag = True
            if flag: break
        if flag: break
    if flag: print("%d %d %d"%(x,y,z))
    else: print("-1 -1 -1")
    return


main()

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:
      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-i+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())
A = list(range(0,N+1))
a=-1
b=-1
c=-1
for i in A:
    for j in list(range(0,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,sum1 = map(int,input().split())

A = 10000
B = 5000
C = 1000

def memuA():
	for i in range(N+1):
		for j in range(N+1 - i):
			if i*A + j*B + (N-i-j)*C == sum1:
				return [i,j,(N-i-j)]
	return [-1,-1,-1]

print(*memuA())

Solution (Python):
def yen(x, y, z):
    return x * 10000 + y * 5000 + z * 1000


def otoshidama(N, Y):
    x = y = z = 0
    while x <= N:
        y = 0
        while x + y <= N:
            z = N - y - x
            if yen(x, y, z) == Y:
                return '{} {} {}'.format(x, y, z)
            y += 1
        x += 1
    return '-1 -1 -1'


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

Solution (Python):

"""
Created on Sat Dec 15 16:57:18 2018
ABC085C
@author: maezawa
"""
n, y = list(map(int, input().split()))
y = y // 1000
yn = y - n
is_ok = False
for i in range(n+1):
    if (yn - 9*i) % 4 == 0:
        a0, a1 = i, (yn - 9*i) // 4
        if a1 >= 0 and n - a0 - a1 >= 0:
            is_ok = True
            break
if is_ok:
    print(a0, a1, n - a0 - a1)
else:
    print(-1, -1, -1)

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

ok = False
m_10000 = y // 10000
for t in range(0, m_10000+1)[::-1]:
    r = y - (t*10000)
    m_5000 = r // 5000
    if ok:
        break
    for f in range(0, m_5000+1)[::-1]:
        c = n - t - f
        total = (10000 * t) + (5000 * f) + (1000 * c)
        if total == y:
            print(t, f, c)
            ok = True
            break
if not ok:
    print(-1, -1, -1)

Solution (Python):
import sys

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

a = Y - 1000 * N

for x in range(2000 + 1):
    for y in range(2000 - x + 1):
        if 9000 * x + 4000 * y == a:
            z = N - x - y
            if x + y + z == N and z >= 0:
                print("{} {} {}".format(x, y, z))
                sys.exit(0)

print("-1 -1 -1")

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


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

Solution (Python):
n, y = map(int, input().split())
a, b, c = 10000, 5000, 1000


if y > n * a:
    print("-1 -1 -1")
    
else:
    success = False
    for i in range(n+1):
        for j in range(n - i + 1):
            if y == a * i + b * j + c * (n - i - j):
                print(i, j, n-i-j)
                success = True
                break
        if success == True:
            break
    if success == 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):
        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 x in range(N+1):
    for y in range(N+1):
        z = N - (x + y)
        if (z >= 0) & (10000*x + 5000*y + 1000*z == Y):
            print(x, y, z)
            exit(0)
print(-1, -1, -1)

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

Solution (Python):
num,total = map(int,input().split())
for i in range(num+1):
    for j in range(num-i+1):
        if i*10000 + j*5000 + (num-i-j)*1000 == total:
            print(i,j,num-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 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())
x = y = z = -1
for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if k < 0:
            continue
        if i + j + k != N:
            continue
        if 10000 * i + 5000 * j + 1000 * k == Y:
            x = i
            y = j
            z = k
            break
print(x, y, z)

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

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

is_found = False
man = 0
gosen = 0
sen = 0
for m in range(N + 1):
    if is_found:
        break
    for g in range(N - m + 1):
        s = N - m - g
        if 10000 * m + 5000 * g + 1000 * s == Y:
            man = m
            gosen = g
            sen = s
            is_found = True
            break

if is_found:
    print(man, gosen, sen)
else:
    print("-1 -1 -1")

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

from math import floor, ceil

def searcher(N, Y):
	for x in range(N+1):
		y = (Y - 1000 * N - 9000 * x) / 4000
		if (floor(y) == ceil(y)) and int(y) >= 0 and  N-x-int(y) >= 0:
			print(x, int(y), N-x-int(y))
			return 
	else:
		print(-1, -1, -1)
		return 


searcher(N, Y)

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

def search():
    for b in range(0,n+1):
        for a in range(0,n+1):
            c=n-a-b
            total = 10000*a+5000*b+1000*c
            if(y==total and c>=0):
                return(a,b,c)
    return(-1,-1,-1)
print("%d %d %d" % search())

Solution (Python):


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


A_max = Y // 10000  


for i in range(A_max + 1): 
	Res_Y = Y - i * 10000 
	B_max = Res_Y // 5000 
	for j in range(B_max + 1): 
		A = i
		B = j
		C = (Res_Y - (j * 5000))//1000	
		if A + B + C == N:
			print(A, B, C)
			break
	else:
		continue

	break
else:
	print(-1, -1, -1)

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

def search():
    for a in range(0, n+1):
        for b in range(0, n+1 - a):
            c = n - a - b
            total = 10000*a + 5000*b + 1000*c
            if (y == total and n == a + b + c):
                return (a, b, c)
    return (-1,-1,-1)
print("%d %d %d" % search())

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

def search():
    for b in range(0, n+1):
        for a in range(0, n+1):
            c = n - a - b
            total = 10000*a + 5000*b + 1000*c
            if (y == total and n == a + b + c and c >= 0):
                return (a, b, c)
    return (-1,-1,-1)
print("%d %d %d" % search())

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

result = [-1, -1, -1]
for a in range(n + 1):
    for b in range(n + 1):
        rest = y - 10000 * a - 5000 * b
        if 1000 * (n - a - b) == rest and (n - a - b) >= 0:
            result[0] = a
            result[1] = b
            result[2] = n - a - b
            break

    if result[0] != -1:
        break

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

Solution (Python):

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

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

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

flg = 0

for i in range(n+1):
    for j in range(n-i+1):
        if y == 10000 * i + 5000 * j + 1000 * (n-i-j) :
            flg = 1
            xx,yy,zz = i,j,n-i-j
if flg == 1:
    print(xx,yy,zz)
else:
    print(-1,-1,-1)

Solution (Python):
def k10tok5(a,b,c):
    if a >= 1:
        return (a-1, b+2, c) 
    else:
        return False
def k5tok(a,b,c):
    if b >= 1:
        return (a, b-1, c+5)
    else:
        return False

def ryougae(a, b, c, n, m):
    for i in range(n):
        if k10tok5(a, b, c):
            a, b, c = k10tok5(a, b, c)
        else:
            return False
    for i in range(m):
        if k5tok(a, b, c):
            a, b, c = k5tok(a, b, c)
        else:
            return False
    return a, b, c

def goukei(a,b,c):
    return a + b + c

N, Y = (int(i) for i in input().split())
a = Y//10000
b = (Y%10000)//5000
c = (Y%5000)//1000 
if N - a - b - c < 0:
    print("-1 -1 -1")
elif N - a - b - c == 0:
    print("{} {} {}".format(a,b,c))
else:
    temp = N - a - b - c
    for i in range( (temp + 4 - 1)//4 ):
        if ryougae(a, b, c, temp - 4*i, i):
            a, b, c = ryougae(a, b, c, temp - 4*i, i)
            print("{} {} {}".format(a,b,c))
            break
    else:
        print("-1 -1 -1")

Solution (Python):
def a():
 n, m = [int(i) for i in input().split()]
 for x in range(n+1):
  for y in range(n-x+1):
    z = n-x-y
    
    if 1000*x + 5000*y + 10000*z == m:
      print('%d %d %d'%(z,y,x))
      return
 print('-1 -1 -1')
    
a()

Solution (Python):
def a():
 n, m = [int(i) for i in input().split()]
 for x in range(n+1):
  for y in range(n-x+1):
    z = n-x-y
    
    if 1000*x + 5000*y + 10000*z == m:
      print('%d %d %d'%(z,y,x))
      return
 print('-1 -1 -1')
    
a()

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

Solution (Python):
import sys
num_bill, y = map(int, input().split())

for num_10000 in range(y // 10000 + 1):
    for num_5000 in range(min((y - num_10000 * 10000) // 5000 + 1, num_bill - num_10000 + 1)):
        num_1000 = num_bill - num_10000 - num_5000
        if num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y:
            print(num_10000, num_5000, num_1000)
            sys.exit()

print('-1 -1 -1')

Solution (Python):
import sys
num_bill, y = map(int, input().split())

for num_10000 in range(y // 10000 + 1):
    for num_5000 in range(min((y - num_10000 * 10000) // 5000 + 1, num_bill - num_10000 + 1)):
        if ((num_bill - num_10000 - num_5000) * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + (num_bill - num_10000 - num_5000) == num_bill):
            print(num_10000, num_5000, (num_bill - num_10000 - num_5000))
            sys.exit()

print('-1 -1 -1')

Solution (Python):
import sys
num_bill, y = map(int, input().split())

for num_10000 in range(y // 10000 + 1):
    for num_5000 in range(min((y - num_10000 * 10000) // 5000 + 1, num_bill - num_10000 + 1)):
        num_1000 = num_bill - num_10000 - num_5000
        if (num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + num_1000 == num_bill):
            print(num_10000, num_5000, num_1000)
            sys.exit()

print('-1 -1 -1')

Solution (Python):
import sys
num_bill, y = map(int, input().split())
num_1000, num_5000, num_10000 = 0, 0, 0

for num_10000 in range(y // 10000 + 1):
        
    for num_5000 in range(min((y - num_10000 * 10000) // 5000 + 1, num_bill - num_10000 + 1)):
        if (num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + num_1000 == num_bill):
            print(num_10000, num_5000, num_1000)
            sys.exit()
        
        num_1000 = num_bill - num_10000 - num_5000
        if (num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + num_1000 == num_bill):
            print(num_10000, num_5000, num_1000)
            sys.exit()

print('-1 -1 -1')

Solution (Python):
import sys
num_bill, y = map(int, input().split())
bills = [1000, 5000, 10000]

num_1000, num_5000, num_10000 = 0, 0, 0

for num_10000 in range(y // 10000 + 1):
    if (num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + num_1000 == num_bill):
        print(num_10000, num_5000, num_1000)
        sys.exit()
        
    iter_num = min(((y - num_10000 * 10000) // 5000 + 1), (num_bill - num_10000 + 1))
    for num_5000 in range(iter_num):
        if (num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + num_1000 == num_bill):
            print(num_10000, num_5000, num_1000)
            sys.exit()
        
        num_1000 = num_bill - num_10000 - num_5000
        if (num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + num_1000 == num_bill):
            print(num_10000, num_5000, num_1000)
            sys.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 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(min(n,y//10000)+1):
    for b in range(min(n-a,(y-a*10000)//5000)+1):
        if a*10000+b*5000>y:
            continue
        c = (y-a*10000-b*5000)//1000
        if a+b+c==n and 10000*a+5000*b+1000*c==y:
            print(a,b,c)
            exit()
print(-1,-1,-1)

Solution (Python):
def inpl(): return [int(i) for i in input().split()]

N, Y = inpl()
Y //= 1000
for i in range(-((N-Y)//9)+1):
    j = Y-N-i*9
    if j%4:
        continue
    j //= 4
    if j < 0:
        continue
    k = N-j-i
    if k < 0:
        continue
    print(i,j,N-j-i)
    break
else:
    print(-1, -1, -1)

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

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

Solution (Python):
def main():
    N, Y = map(int, input().split())
    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:
                print(x, y, z)
                return
    print(-1, -1, -1)


if __name__ == "__main__":
    main()

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

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

n_1 = range(n+1)
 
for i in n_1:
    for j in range(n+1-i):
            k = n - i - j
            if k < 0:
                k = 0
 
            price = 10000 * i + 5000 * j + 1000 * k   
            
            if price == y and i+j+k == n and ok == 0:
                print(i, j, k)
                ok = 1
                break
 
    else:
        continue
    break
 
if ok == 0:
    print(-1, -1, -1 )

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

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

ok = 0

for i in range(n+1):
    for j in range(n+1-i):
            k = n - i - j
            if k < 0:
                k = 0

            price = 10000 * i + 5000 * j + 1000 * k   
            
            if price == y and i+j+k == n:
                print(i, j, k)
                ok = 1
                break

    if ok == 1:
        break

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

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

price = 0
ok = 0

for i in range(n+1):
    for j in range(n+1-i):
            k = n - i - j
            if k < 0:
                k = 0

            price = 10000 * i + 5000 * j + 1000 * k   
            
            if price == y and i+j+k == n:
                print(i, j, k)
                ok = 1
                break

    else:
        continue
    break

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

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

price = 0
ok = 0

for i in range(n+1):
    for j in range(n+1-i):
            k = n - i - j
            if k < 0:
                k = 0

            price = 10000 * i + 5000 * j + 1000 * k   
            
            if price == y and i+j+k == n and ok == 0:
                print(i, j, k)
                ok = 1
                break

    else:
        continue
    break

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