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

N, Y = [int(s) for s in sys.stdin.readline().split(" ")]
Y2 = (Y/1000)-5*N

for z in range(0, 2001):
  x = (5*z-Y2)/4
  
  if x < 0:
    continue
  
  if int(x)-x==0:
  	x = int(x)
  	y = N-x-z
  	if y<0:
  		continue
  	
  	print(z, y, x)
  	exit(0)
  
  
print("-1 -1 -1")

Solution (Python):
def main():
    N, Y = map(int, input().split())
    YY = Y - N * 1000
    for x in range(0, int(YY/9000)+1):
        y = int((YY - x * 9000) / 4000)
        if (YY - x * 9000) % 4000 == 0 and x + y <= N:
            print(x, y, N - x - y)
            return
    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):
def c_Otoshidama_C(N, Y):
    import math
    
    t = (Y - 1000 * N) // 1000  
    
    
    left = max(math.ceil(-t / 4), math.ceil(-(N + t) / 5))
    right = math.floor(-2 * t / 9)
    if left <= right:
        k = left
        a = 4 * k + t
        b = -9 * k - 2 * t
        c = N - a - b
        return '{} {} {}'.format(a, b, c)
    else:
        return '-1 -1 -1'

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

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

output = '-1 -1 -1'

for i in range(min(int(Y/10000),N)+1):
    for j in range(min(int((Y-10000*i)/5000),N-i)+1):
        k = N - i - j
        if 10000 * i + 5000 * j + 1000 * k == Y:
            output = str(i) + ' ' + str(j) + ' ' + str(k)
            break

print(output)

Solution (Python):
n,y = list(map(int,input().split()))
if y/10000 > n:
    print('-1 -1 -1')
if y/10000 ==n:
    print('%d %d %d' % (y/10000, 0, 0))
else:
    b = False
    YY =[]
    Y10=int(y/10000)
    Y5 =int(y/5000)
    Y1 =int(y/1000)
    for i in range(Y10,-1,-1):
        if b== True or i > n:
            break
        for j in range(Y5+1-2*i):
            if b == True or i+j > n:
                break
            k = n - i - j
            if i*10000+j*5000+k*1000 ==y:
                YY = [i,j,k]
                print('%d %d %d' % (YY[0], YY[1], YY[2]))
                b = True
                break
            else:
                YY=[]
        if i == 0 and b == False:
            print('-1 -1 -1')

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

for i in range(y//10000+1):
    for j in range(y//5000+1):
        tmp = y - 10000*i - 5000*j
        k = tmp//1000
        if i+j+k == n and k >= 0:
            print('{0} {1} {2}'.format(i,j,k))
            flag = True
            break
    if flag:
        break
if not flag:
    print('-1 -1 -1')

Solution (Python):



import sys

def main():
    n, y = map(int, sys.stdin.readline().split())

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

if __name__ == '__main__':
    main()

Solution (Python):



import sys

def main():
    n, y = map(int, sys.stdin.readline().split())

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

if __name__ == '__main__':
    main()

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 y == 10000*i + 5000*j + 1000*(k):
                print('{0} {1} {2}'.format(i,j,k))
                exit()
print('-1 -1 -1')

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

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

Solution (Python):
s=input()
s=s.split(' ')
maisuu = int(s[0])
maney  = int(s[1])
 
minn_man = int(maney/10000)+1
minn_go  = int(maney / 5000) +1
for man in range(0,minn_man):
	for go in range(0,minn_go):
		
		sen = maisuu - go - man
		if sen>=0:
			if man*10000+ go*5000 + sen*1000 == maney:
				print(str(man)+" "+str(go)+" "+str(sen))
				exit()
print('-1 -1 -1')

Solution (Python):
a = str(input()).split()
n = int(a[0])
y = int(a[1])
c = 0
for i in range(0,n+1):
    for j in range(0,n-i+1):
        k = n-i-j
        if y == 10000*i + 5000*j + 1000*k:
            c = 1
            s = i
            t = j
            r = k
if c == 1:
    print(s,t,r)
else:
    print(-1,-1,-1)

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

x_range = Y // 10000
y_range = Y // 5000

for x in range(x_range + 1):
	if x > N:
		break
	for y in range(y_range + 1):
		if x + y > N :
			continue
		z = N - x - y
		if Y == 10000*x + 5000*y + 1000*z:
			print("%d %d %d" % (x, y, z))
			sys.exit()
print("-1 -1 -1")

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

if __name__ == "__main__":
    n,y = map(int,input().split())
    print(' '.join(map(str,calcotoshidama(n,y))))

Solution (Python):


import sys

n, y = [int(e) for e in raw_input().split()]

y /= 1000

found = False
tenK  = -1
fiveK = -1
oneK  = -1

if (y / 10.) <= n:
    for b10K in xrange(0, (y / 10) + 1):
        yr = y - (10 * b10K)
        nr = n - b10K
        if (yr / 5) > nr:
            continue
        for b5K in xrange(0, (yr / 5) + 1):
            yrr = yr - (5 * b5K)
            nrr = nr - b5K
            if yrr > nrr:
                continue
            elif yrr == nrr:
                found = True
                tenK = b10K
                fiveK = b5K
                oneK = yrr
                sys.stdout.write('%d %d %d\n' % (tenK, fiveK, oneK))
                sys.stdout.flush()
                sys.exit(0)
        
sys.stdout.write('-1 -1 -1\n')
sys.stdout.flush()

Solution (Python):
def tets():
    n,y=map(int,input().split())
    a=10000
    b=5000
    c=1000
    for i in range(n+1):
        for j in range(n+1):
            k=n-i-j
            if a*i+b*j+c*k==y and 0<=k:
                return i,j,k
    return -1,-1,-1
d,e,f=tets()
print(d,e,f)

Solution (Python):
def test():
    n,y=map(int,input().split())
    a,b,c=10000,5000,1000
    for i in range(n+1):
        for j in range(n+1):
            ans=a*i+b*j
            if y<ans:
                break
            if (y-ans)%c==0:
                k=(y-ans)//c
                if i+j+k==n:
                    return i,j,k
    return -1,-1,-1
one,two,three=test()
print(one,two,three)

Solution (Python):
n, yen = map(int, input().split())
ans = [-2, -2, 2]
for i in range(n + 1):
    if(ans[0] != -2):
            break
    for j in range(n + 1):
        if(i + j > n):
            continue
        x = i
        y = j
        z = n - x - y
        if(yen - 10000 * x - 5000 * y - 1000 * z  == 0):
            ans[0] = x
            ans[1] = y
            ans[2] = z
            break
if(ans[0] == -2):
    print("-1 -1 -1")
else:
    print("{} {} {}".format(ans[0], ans[1], ans[2]))

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

y_minus_1000n = yen - 1000 * n
x_max = yen // 10000

d = [-1, -1, -1]
for x in range(x_max + 1):
    temp = y_minus_1000n - 9000 * x
    if temp % 4000:
        continue
    y = temp / 4000
    z = n - x - y
    if x >= 0 and y >= 0 and z >= 0:
        d[0] = x
        d[1] = y
        d[2] = z
        break

print(' '.join([str(int(x)) for x in d]))

Solution (Python):
N, Y = map(int, input().split())
k = Y // 1000
flag = 0
for a in range(N + 1):
    if (k - a) % 5 == 0:
        c = (k - a) // 5 - (N - a)
        b = N - a - c
        if b >= 0 and c >= 0:
            print("{0} {1} {2}".format(c, b, a))
            flag = 1
            break
if flag == 0:
    print("-1 -1 -1")

Solution (Python):
N,Y = map(int,input().split())
ans = []
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]
if len(ans) == 0:
    print('-1 -1 -1')
else:
    print(str(ans[0])+' '+str(ans[1])+' '+str(ans[2]))

Solution (Python):

import sys

def func(x, y, z):
	print("{0} {1} {2}".format(z, y, x))
	sys.exit()

def main():
	N, Y = map(int, input().split())
	cash = Y
	x, y, z = 0, 0, 0
	while cash >= 10000:
		cash -= 10000
		z += 1;

	while cash >= 5000:
		cash -= 5000
		y += 1

	while cash >= 1000:
		cash -= 1000
		x += 1
	

	if x+y+z > N:
		func(-1, -1, -1)

	while True:
		if x+y+z == N:
			func(x, y, z)
		else:
			prev = x+y+z
			if prev+4 <= N:
				if y > 0:
					x += 5
					y -= 1
					if x+y+z == N:
						func(x, y, z)
				elif z > 0:
					y += 2
					z -= 1
				else:
					func(-1, -1, -1)
			else:
				if z > 0:
					y += 2
					z -= 1
					if x+y+z == N:
						func(x, y, z)
				else:
					func(-1, -1, -1)

if __name__ == "__main__":
	main()

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc085/tasks/abc085_c

"""
import sys
from sys import stdin
input = stdin.readline


def calc_yukichi(n, total):
    
    if total % 5000 != 0:
        return -1

    gap = total - (5000 * n)
    if gap < 0:
        return -1
    yukichi = gap // 5000
    ichiyou = n - yukichi
    if ichiyou >= 0:
        return yukichi
    else:
        return -1


def solve(N, Y):
    
    for hideyo in range(N+1):
        nokori = Y - hideyo * 1000
        yukichi = calc_yukichi(N-hideyo, nokori)
        if yukichi >= 0:
            ichiyou = N - yukichi - hideyo
            return yukichi, ichiyou, hideyo
    return -1, -1, -1


def main(args):
    N, Y = map(int, input().split())
    
    ans = solve(N, Y)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc085/tasks/abc085_c

"""
import sys
from sys import stdin
input = stdin.readline


def calc_yukichi(n, total):
    
    gap = total - (5000 * n)
    if gap < 0:
        return -1
    yukichi = gap // 5000
    ichiyou = n - yukichi
    if ichiyou >= 0:
        return yukichi
    else:
        return -1


def solve(N, Y):
    
    dp = [[False] * (2*N+1) for _ in range(N+1)] 
    dp[0][0] = True             

    if Y / 1000 == N:           
        return 0, 0, N

    for y in range(1, N+1):
        for x in range(y-1, y*2):
            if dp[y-1][x]:
                dp[y][x+1] = True
                dp[y][x+2] = True

                if (x+1)*5000 + (N-y)*1000 == Y or (x+2)*5000 + (N-y)*1000 == Y:
                    hideyo = N - y
                    nokori = Y - hideyo * 1000
                    yukichi = calc_yukichi(y, nokori)
                    ichiyou = N - yukichi - hideyo
                    if yukichi >= 0 and ichiyou >= 0:
                        return yukichi, ichiyou, hideyo

    return -1, -1, -1           


def main(args):
    N, Y = map(int, input().split())
    
    ans = solve(N, Y)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
num, target = [int(i) for i in input().split()]
Flag = False

for i in range(num, -1, -1):
    for j in range(num-i, -1, -1):
        k = num - i - j 
        if (10000 * i) + (5000 * j) + (1000 * k) == target:
            print(str(i) + " " + str(j) + " " + str(k))
            Flag = True
            break
    if Flag == True:
        break

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

Solution (Python):
from sys import exit

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

FAIL = '-1 -1 -1'

for z in range(N + 1):
    x = 4 * z / 5 + Y / 5000 - N
    y = -9 * z / 5 - Y / 5000 + 2 * N
    if x == int(x) and x >= 0\
       and y == int(y) and y >= 0:
        print('{} {} {}'.format(int(x), int(y), z))
        exit()

print(FAIL)

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

Solution (Python):
n,y =  map(int, input().split())
y *= 0.001
y = int(y)
a,b,c = -1,-1,-1
for i in range(0,n+1):
    d = i*10
    for j in range(0,n+1):
        money = y
        money -= d
        if n-i-j >= 0:
            money -= j*5 + (n-i-j)
            if money == 0:
                a,b,c = i,j,n-i-j
                break
print(a,b,c)

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


def f(x, y, z):
    return 10000 * x + 5000 * y + 1000 * z


def b():
    for x in range(N + 1):
        for y in range(N + 1):
            z = N - x - y
            if z < 0:
                continue
            if f(x, y, z) == Y:
                print('{0} {1} {2}'.format(x, y, z))
                return
    print('-1 -1 -1')
    return


b()

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
k = min((Y - N) // 4, Y // 5)
if 9 * k >= 2 * (Y - N):
    x = (Y - N) - 4 * k
    y = -2 * (Y - N) + 9 * k
    z = Y - 5 * k
    print(x, y, z)
else:
    print(-1, -1, -1)

Solution (Python):


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

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

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):
        if Y == 10000*i + 5000*j + 1000*(N-i-j) and flag == 0:
            print(i,j,N-i-j)
            flag = 1
            break
if flag == 0:
    print(-1,-1,-1)

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

Y //= 1000

k = min((Y - N) // 4, Y // 5)
if 9 * k >= 2 * (Y - N):
    x = (Y - N) - 4 * k
    y = -2 * (Y - N) + 9 * k
    z = Y - 5 * k
    print(x, y, z)
else:
    print(-1, -1, -1)

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

truth = False

for yukichi, ichiyo in [(n, m) for n in range(N+1) for m in range(N+1) if n + m <= N]:
    hideyo = N - yukichi - ichiyo
    if (hideyo >= 0 and yukichi * 10000 + ichiyo * 5000 + hideyo * 1000 == Y):
        truth = True
        break

if (truth):
    print(str(yukichi), str(ichiyo), str(hideyo))
else:
    print('-1 -1 -1')

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



flag = 0
x = 0
y = 0
z = 0

if Y > 10000*N:
   flag = 1
else :
   x = Y//10000
   while True:
      for z in range(N-x+1):
         y = N-x-z
         if Y == 10000*x + 5000*y + 1000*z:
            flag = -1
            break
      if flag == -1:
         break
      elif x == 0:
         flag = 1
         break
      x = x-1
      
            

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

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

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

a = 0
for x in range(N+1): 
    for y in range(N-x+1):
        if (10000*x + 5000*y + 1000*(N-x-y)) == Y:
            print(str(x)+" "+str(y)+" "+str(N-x-y))
            a = 1
            break
    if a == 1:
        break

if a != 1:
    print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
k = min((Y - N) // 4, Y // 5)
if 9 * k >= 2 * (Y - N):
    x = (Y - N) - 4 * k
    y = -2 * (Y - N) + 9 * k
    z = Y - 5 * k
    print(x, y, z)
else:
    print(-1, -1, -1)

Solution (Python):

""" abc085b """

n, y = map(int, input().split())
y = y / 1000
for i in range(n + 1):
    for j in range(n + 1 - i):
        man = i * 10
        gos = j * 5
        sen = (n - i - j)
        if man + gos + sen == y:
            print(str.format('{0} {1} {2}', i, j, sen))
            exit()
print('-1 -1 -1')

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

ans = [-1,-1,-1]
for man in range(0,N+1):
    for gosen in range(0,N-man+1):
        if(Y == man * 10000 + gosen * 5000 + (N-man-gosen)*1000):
            ans = [man,gosen,N-man-gosen]
print(functools.reduce(lambda x,y:str(x)+" "+str(y),ans))

Solution (Python):
import math
import numpy as np
from operator import mul










N, Y = map(int, input().split())
Y = int(Y/1000)
x = 0
x_right = -1
y = -1
z = -1

while 9 * x <= Y - N:
    if (Y - N - 9 * x) / 4 <= N and (Y - N - 9 * x) % 4 == 0:
        if N - (Y - N - 9 * x) / 4 - x >= 0 and N - (Y - N - 9 * x) / 4 - x <= N:
            y = (Y - N - 9 * x) / 4
            z = N - x - y
            x_right = x
    x += 1

print(int(x_right), int(y), int(z))

Solution (Python):
n,y = map(int,input().split())
y //= 1000
c = y%5 - 5
while c <= n:
    c += 5
    nc = n-c
    x = y-c
    a = (x-5*nc)//5
    if a < 0 : continue
    b = nc - a
    if b < 0 : continue
    if 10*a+5*b+c == y:
        print(a,b,c)
        break

else:
    print("-1 -1 -1")

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

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

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

Solution (Python):
l = input().split(' ')
N = int(l[0])
Y = int(l[1])
J = 0
L = [-1,-1,-1]
if N*10000 < Y:
    J = 1

if J == 0:
    n1=0
    y = Y // 10000
    while n1 <= y:
        n2 = (Y - 1000 * N - 9000 * n1)/4000
        if (n2 %1 == 0) and (n1+n2 <= N) and n2 >= 0:
            L[0] = n1
            L[1] = n2
            L[2] = N - n1 - n2
            break
        else:
            n1 += 1

print(str(int(L[0]))+' '+str(int(L[1]))+' '+str(int(L[2])))

Solution (Python):
import math 
from collections import defaultdict as dd
def main():
    N, Y = map(int, input().split())
    a = (Y//10000)

    if a*10000 == Y:
        if a == N:
            print (a,0,0)
            return

    s = -1
    for k in range(a+1):
        b = N-k
        if b < 0:
            print ('-1 -1 -1')
            return 
        for j in range(b+1):
            s = 10000*k+5000*j+1000*(b-j)
            if s == Y:
                print (k,j,(b-j))
                return

    print ('-1 -1 -1')



if __name__ == "__main__":
    
    
    main()

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

a = y//10000 
ans = ""

for i in range(a,-1,-1):
    r = y - 10000*i
    if ans:
        break
    for j in range(r//5000,-1,-1):
        s = (r - 5000*j)//1000
        if  i + j + s == n:
            ans = str(i)+" "+str(j)+" "+str(s)
            break
if ans:
    print(ans)
else:
    print("-1 -1 -1")

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

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

Solution (Python):
import sys
N,Y=input().split(' ')
N=int(N)
Y=int(Y)
tmp=Y
x=int(tmp/10000)
tmp-=x*10000
y=int(tmp/5000)
tmp-=y*5000
z=int(tmp/1000)
 
while True:
  sum=x+y+z
  if(sum==N):break
  elif(N-sum>=4 and y>=1):
    y-=1
    z+=5
  
  
  elif(x>=1):
    x-=1
    y+=2
  else:
    print('-1 -1 -1')
    sys.exit()
print(x,y,z)

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

    print(-1,-1,-1)

if __name__ == '__main__':
    main()

Solution (Python):
def find_min(v):
    x = v % 10
    return (x % 5, x//5, v // 10)

def find_max(v):
    return (v, 0, 0)


def conv10to5(xs):
    return (xs[0], xs[1] +2, xs[2] - 1)

def undoconv10to5(xs):
    return (xs[0], xs[1] -2, xs[2] + 1)


def conv5to1(xs):
    return (xs[0]+5, xs[1] -1, xs[2])


def next(xs):
    if xs[2] == 0:
        if xs[1] == 0:
            return None
        else:
            return conv5to1(xs)
    else:
        if xs[1] < 7:
            return conv10to5(xs)
        else:
            return conv5to1(undoconv10to5(undoconv10to5(undoconv10to5(xs))))


def find(v, n):
    xs = find_min(v)
    m = sum(xs)
    if m > n or n > v:
        return (-1, -1, -1)

    while xs:
        if sum(xs) == n:
            return xs
        xs = next(xs)
    return (-1, -1, -1)



if __name__ == "__main__":
    n, y = map(int, input().split())
    y = y // 1000
    print("{2} {1} {0}".format(*find(y, n)))

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

Solution (Python):

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

a = 0
for x in range(N+1): 
    for y in range(N-x+1):
        if (10000*x + 5000*y + 1000*(N-x-y)) == Y:
            print(str(x)+" "+str(y)+" "+str(N-x-y))
            a = 1
            break
    if a == 1:
        break

if a != 1:
    print("-1 -1 -1")

Solution (Python):
import sys
N,Y=input().split(' ')
N=int(N)
Y=int(Y)
tmp=Y
x=int(tmp/10000)
tmp-=x*10000
y=int(tmp/5000)
tmp-=y*5000
z=int(tmp/1000)

while True:
  sum=x+y+z
  if(sum==N):break
  elif(N-sum>=4 and y>=1):
    y-=1
    z+=5
  elif(N-sum>=4 and x>=1):
    x-=1
    y+=2
  elif(N-sum<4 and x>=1):
    x-=1
    y+=2
  else:
    print('-1 -1 -1')
    sys.exit()
print(x,y,z)

Solution (Python):
ny = input().split()
n = int(ny[0])
y = int(ny[1])

def solve(n,y):
    Y = y/1000
    p = int((Y - n) // 9)
    for v in range(p+1):
        if (Y - n - 9*v)%4 == 0:
            b = int((Y - n - 9*v)//4)
            c = int((Y - 10*v - 5*b))
            if c*b < 0:
                continue
            else:
                return str(v), str(b), str(c)


ans = solve(n,y)
if ans != None:
    print(' '.join(ans))
else:
    print(-1, -1, -1)

Solution (Python):

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

a = 0
for x in range(N+1): 
    for y in range(N-x+1):
        if (10000*x + 5000*y + 1000*(N-x-y)) == Y:
            print(str(x)+" "+str(y)+" "+str(N-x-y))
            a = 1
            break
        if a == 1:
            break
    if a == 1:
        break

if a != 1:
    print("-1 -1 -1")

Solution (Python):

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

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

if find == False:
    print(str(-1) + " " + str(-1) + " " + str(-1))

Solution (Python):
inn = [int(x) for x in input().split()]

xx = inn[1] // 10000
ans = [-1, -1, -1]
if xx <= inn[1]:
    for x in range(xx+1):
        rem = inn[1] - 10000*x
        yy = rem // 5000
        for y in range(yy+1):
            z = (rem - 5000*y) // 1000
            if x+y+z == inn[0]:
                ans = [x, y, z]
                break

print(' '.join([str(x) for x in ans]))

Solution (Python):
n, y = map(int, raw_input().split())
for w in xrange(n + 1):
    for k_5 in xrange(n - w + 1):
        k = n - w - k_5
        if w * 10000 + k_5 * 5000 + k * 1000 == y:
            print w, k_5, k
            exit()
print -1, -1, -1

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

if 10000 * x + 5000 * y + 1000 * z == Y :
    print(x,y,z)
else:
    print(-1,-1,-1)

Solution (Python):
n,y = map(int,input().split())
d=y//1000-n
a=(d*7)%9 
b=(d-a*4)//9
c=n-a-b
if c>=0 and b>=0:
    print(b,a,c)
else:
    print(-1,-1,-1)

Solution (Python):


na = raw_input()
na = na.split()
n,a = map(int,na)

goukei = 0
i = 0
j = 0
k = 0
status = 0
for i in range(n+1):
    for j in range(n-i+1):
        k = n-(i+j)
        goukei = 10000*i + 5000*j + 1000*k
        if a == goukei:
            status = 1
            break
    if status == 1:
        break
if status == 0:
    i = -1
    j = -1
    k = -1

print i,j,k

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

tmp = 0
tmp_num = 0

for i in range(N + 1):
    for j in range(N + 1 - i):
        tmp_num = N - i - j

        if Y - (10000 * i + 5000 * j + 1000 * tmp_num) == 0:
            print("{} {} {}".format(i, j, tmp_num))
            sys.exit()

print("-1 -1 -1")

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

x = 0
y = 0
z = int(money/1000)

if z < n:
    print("-1 -1 -1")
elif z == n:
    print(x, y, z)
else:
    div1000 = min(int((z-n)/4), int(z/5))
    z = z - (5 * div1000)
    y += div1000
    if y + z == n:
        print(x, y, z)
    else:
        if int(y/2) >= y + z - n:
            x += y + z - n
            y -= (y+z-n)*2
            print(x, y, z)
        else:
            print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split(' '))
is_found = False
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:
            is_found = True
            break
    if is_found:
        break

if is_found:
    print(a, b, c)
else:
    print(-1, -1, -1)

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

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

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

y-=n*1000
ans=[-1,-1]

for i in range(n+1):
        for j in range(n+1-i):
                if 9000*i+4000*j==y:
                        ans[0]=i
                        ans[1]=j
                        break
        if ans[0]!=-1:
                break
if ans[0]==-1:
        print("-1 -1 -1")
else:
        print(str(ans[0])+" "+str(ans[1])+" "+str(n-ans[0]-ans[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 Y==10*i+5*j+N-i-j:
            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(N-i+1):
        if Y==10000*i+5000*j+1000*(N-i-j):
            print(i,j,N-i-j)
            break
    else:
        continue
    break
else:
    print(-1,-1,-1)

Solution (Python):
import sys
n, m = map(int, input().split())
for i in range(0, n + 1):
    val = m - 1000 * n - 4000 * i
    if val < 0:
        break
    elif val % 9000 == 0:
        z = val // 9000
        if n - i - z < 0:
            continue
        print(z, i, n - i - z)
        sys.exit()
print(-1, -1, -1)

Solution (Python):
n = input().split()
a,b,c = 0,0,0

N = int(n[0])
Yen = int(n[1])

X,Y,Z = -1,-1,-1

for x in range(0,N+1):
    for y in range(0,N+1):
        z = N-x-y
        if Yen == 10000*x + 5000*y + 1000*z:
            if z < 0:
                continue
            else:
                X,Y,Z = x,y,z
        else:
            continue

print(X,Y,Z)

Solution (Python):
"""
9x+4y=Y-N=t
xを固定すると
y=(Y-N-9i)/4 （余りが０でなければ打ち切り）
(0<=i<=N)
z=N-i-y
i,y,zが非負なら出力（O(N)）
"""
ip=input().split()
N=int(ip[0])
Y=int(ip[1])
Y/=int(1000)
xans=-1
yans=-1
zans=-1
for i in range(N+1):
    temp = Y-N-9*i
    if((temp%4)!=0):
        continue
    y=temp/4
    z=N-i-y
    if(y>=0 and z>=0):
        xans=int(i)
        yans=int(y)
        zans=int(z)
        break
print('{0} {1} {2}'.format(xans,yans,zans))

Solution (Python):


if __name__ == '__main__':

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

    x = 0
    y = 0
    z = 0

    while (x <= N):
        y = 0
        z = 0

        for y in range(N - x + 1):
             
             
            z = N - x - y

            if (10000 * x + 5000 * y + 1000 * z == Y):
                print (x,y,z)
                exit()

        x += 1

    print(-1,-1,-1)

Solution (Python):
import numpy as np
n, y = map(int, input().split())
y //= 1000
c = -1
for i in range(min(n,y)+1):
    if (y - i) % 5 != 0: continue
    if n - i <= (y - i)/5 and (y - i)/5 <= 2*(n - i):
        c = i
        break
if c == -1:
    print(-1,-1,-1)
else:
    a = (y-c)//5 - n + c
    b = n - a - c
    print(a,b,c)

Solution (Python):
n, y = map(int, input().split())
y //= 1000
c = -1
for i in range(min(n,y)+1):
    if (y - i) % 5 != 0: continue
    if n - i <= (y - i)/5 and (y - i)/5 <= 2*(n - i):
        c = i
        break
if c == -1:
    print(-1,-1,-1)
else:
    a = (y-c)//5 - n + c
    b = n - a - c
    print(a,b,c)

Solution (Python):
n,y = map(int, input().split())
y /= 1000
for i in range(int(y//10+1)):
    for j in range(int((y-i*10)//1+1)):
        c = n-i-j
        if c >= 0 and 10 * i + 5 * j + 1 * c == y:
            print(i,j,c)
            exit()
print(-1,-1,-1)

Solution (Python):
import sys

[n, y] = map(int, raw_input().split())
a = 0
b = 0
c = y // 1000
d = c - n
if n > c:
    print -1, -1, -1
    sys.exit(0)
if d >= 4:
    k = d // 4
    k = min(k, c // 5)
    b += k
    c -= k * 5
    d -= k * 4
if d * 2 > b:
    print -1, -1, -1
    sys.exit(0)
b -= 2 * d
a += d
print a, b, c