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):
n, y = map(int, input().split())
res = [-1, -1, -1]
for a in range(n + 1):
    for b in range(n - a + 1):
        if 10000 * a + 5000 * b + 1000 * (n - a - b) == y:
            res[0] = a
            res[1] = b
            res[2] = n - a - b
print(' '.join(map(str, res)))

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

inpt = map(int, raw_input().split())

ans = searchyen(inpt[0], inpt[1])
print str(ans[0]) + ' ' + str(ans[1]) + ' ' + str(ans[2])

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

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

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

Solution (Python):
def otoshidama(nos, amt):
    
    for x in range(0, amt//10000+1):
        for y in range(0, (amt-(10000*x))//5000+1):
            if 10000*x + 5000*y + 1000*(nos-x-y) == amt:
                return (x, y, nos-x-y)
    
    return (-1, -1, -1)

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

print(*otoshidama(n, y))

Solution (Python):
def main():
    N, Y = [int(x) for x in input().split()]
    all_pattern = ([i, j] for i in range(N+1) for j in range(i+1))
    for i, j in all_pattern:
        z, y, x = j, i - j, N - i
        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())
flag = False
for i in range(N+1):    
    for j in range(0, N+1-i):   
        if Y == 10000*i + 5000*j + 1000*(N-i-j):
            print(i, j, (N-i-j))
            flag = True
            break
    if flag:
        break
if flag == False:
    print("-1 -1 -1")

Solution (Python):


def solve():
    n, y = map(int, input().split())
    y //= 1000 

    for nogu in range(n + 1):
        for higu in range(n + 1 - nogu):
            yuki = n - nogu - higu
            if nogu + higu * 5 + yuki * 10 == y:
                print(yuki, higu, nogu)
                return
    
    print("-1 -1 -1")

if __name__=="__main__":
    solve()

Solution (Python):


n, y = [int(x) for x in input().split()]
flag = 0
for i in range(2001):
    for j in range(2001):
        tmp = 10000*i + 5000*j + 1000*(n-i-j)
        if tmp == y:
            if n-i-j >= 0:
                print('{} {} {}'.format(i,j,n-i-j))
                flag = 1
                break
    if flag == 1:
        break
if flag == 0:
    print('{} {} {}'.format(-1,-1,-1))

Solution (Python):
def gen_range(N, Y, reverse=False):
    for i in range(N, 0 - 1, -1):
        for j in range(N - i + 1):
            if reverse:
                yield (j, i, N - i - j)
            else:
                yield (i, j, N - j - i)


def calc(N, Y):
    if 10000 * N < Y or Y < 1000 * N:
        return [-1, -1, -1]
    if Y % 10000 == 0 and Y // 10000 == N:
        return (Y // 10000, 0, 0)
    if Y % 5000 == 0 and Y // 5000 == N:
        return (0, Y // 5000, 0)
    if Y % 1000 == 0 and Y // 1000 == N:
        return (0, 0, Y // 1000)
    if (Y - 1000 * N) % 4000 == 0:
        k5 = (Y - 1000 * N) // 4000
        if k5 >= 0 and N - k5 >= 0:
            return [0, k5, N - k5]
    elif (Y - 1000 * N) % 9000 == 0:
        k10 = (Y - 1000 * N) // 9000
        if k10 >= 0 and N - k10 >= 0:
            return [k10, 0, N - k10]
    if 5000 * N < Y:
        for k10, k1, k5 in gen_range(N, Y, reverse=True):
            if k10 * 10000 + k1 * 1000 + k5 * 5000 == Y:
                return (k10, k5, k1)
    else:
        for k10, k1, k5 in gen_range(N, Y):
            if k10 * 10000 + k1 * 1000 + k5 * 5000 == Y:
                return (k10, k5, k1)

    
    
    
    
    
    
    
    
    
    return (-1, -1, -1)


def main():
    N, Y = list(map(int, input().split()))
    print(*calc(N, Y))


if __name__ == '__main__':
    main()

Solution (Python):
def gen_range(N, Y, reverse=False):
    for i in range(N, 0 - 1, -1):
        for j in range(N - i + 1):
            if reverse:
                yield (j, i, N - i - j)
            else:
                yield (i, j, N - j - i)


def calc(N, Y):
    if 10000 * N < Y or Y < 1000 * N:
        return [-1, -1, -1]
    if Y % 10000 == 0 and Y // 10000 == N:
        return (Y // 10000, 0, 0)
    if Y % 5000 == 0 and Y // 5000 == N:
        return (0, Y // 5000, 0)
    if Y % 1000 == 0 and Y // 1000 == N:
        return (0, 0, Y // 1000)
    if (Y - 1000 * N) % 4000 == 0:
        k5 = (Y - 1000 * N) // 4000
        if k5 >= 0 and N - k5 >= 0:
            return [0, k5, N - k5]
    elif (Y - 1000 * N) % 9000 == 0:
        k10 = (Y - 1000 * N) // 9000
        if k10 >= 0 and N - k10 >= 0:
            return [k10, 0, N - k10]
    if 5000 * N < Y:
        for k10, k1, k5 in gen_range(N, Y, reverse=True):
            if k10 * 10000 + k1 * 1000 + k5 * 5000 == Y:
                return (k10, k5, k1)
    else:
        for k10, k1, k5 in gen_range(N, Y):
            if k10 * 10000 + k1 * 1000 + k5 * 5000 == Y:
                return (k10, k5, k1)

    
    
    
    
    
    
    
    
    
    return (-1, -1, -1)


def main():
    N, Y = list(map(int, input().split()))
    print(*calc(N, Y))


if __name__ == '__main__':
    main()

Solution (Python):


a,b=map(int,input().split())
ans=True
for i in range(a+1):
    for j in range(a+1-i):
        s=10000*i+5000*j+1000*(a-i-j)
        if s == b:
            print(str(i)+" "+str(j)+" "+str(a-i-j))    
            ans = False
            exit()
if ans==True:
    print("-1 -1 -1")

Solution (Python):


a,b=map(int,input().split())
ans=True
for i in range(a+1):
    for j in range(a+1-i):
        if ans==True:
            s=10000*i+5000*j+1000*(a-i-j)
            if s == b:
                print(str(i)+" "+str(j)+" "+str(a-i-j))
                ans = False
        else:
            break
if ans==True:
    print("-1 -1 -1")

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

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

for m in range(n+1):
    for g in range(n-m+1):
        s = n - (m + g)
        
        if 10000*m + 5000*g + 1000*s == y:
            print('{} {} {}'.format(m, g, s))
            flg = True
        if flg:
            break
    if flg:
        break

if flg == False:
    m, g, s = [-1,-1,-1]
    print('{} {} {}'.format(m, g, s))

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

p = False

for j in range(N+1):

    temp = Y - 5000 * j
    

    if temp < 0:
        break

    I = temp // 10000
    for i in range(I+1):
        k = int((temp - 10000 * i) / 1000)
        if i + k + j == N:
            p = True
            break
        
    if p:
        break


if p:
    print(i, j, k)
else:
    print('-1 -1 -1')

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

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

flag = False

for i in range(0, n + 1):
    if 10000 * i > y:
        break

    for j in range(0, n + 1 - i):
        k = n - i - j
        money = 10000 * i + 5000 * j + 1000 * k

        if money > y:
            break

        if money == y:
            print(i, j, k)
            flag = True 
            break

    if flag:
        break


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

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

flag = False

for i in range(0, n + 1):
    for j in range(0, n + 1 - i):
        k = n - i - j
        money = 10000 * i + 5000 * j + 1000 * k

        if money == y:
            print(i, j, k)
            flag = True 
            break

    if flag:
        break


if not(flag):
    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)
            exit()

print("-1 -1 -1")

Solution (Python):
N, Y = list(map(int, input().split()))
Y //= 1000
for x in range(0, Y//10+1):
    for y in range(0, (Y-10*x)//5+1):
        z = N-x-y
        if (9*x + 4*y) == Y-N and z >= 0:
            print(x, y, N-x-y)
            exit()
print(-1, -1, -1)

Solution (Python):


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

    for a in range(n + 1):
        if (a * 10000 > y):
            continue
        for b in range((n + 1) - a):
            c = n - (a + b)
            if ((a * 10000 + b * 5000 + c * 1000) == y):
                print('{} {} {}'.format(a, b, c))
                exit()

    print(-1, -1, -1)

if __name__ == '__main__':
    main()

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

flg = True
for a in range(0, n + 1):
  for b in range(0, n + 1 - a):
    c = n - a - b
    if a * 10000 + b * 5000 + c * 1000 == y:
      print(a, b, c, sep=' ')
      flg = False
      break
  if not flg:
      break
if flg:
  print(-1, -1, -1, sep=' ')

Solution (Python):
n,y=map(int,input().split())
if n*10000<y:
    print("-1 -1 -1")
    exit()

for i in range((y//10000),-1,-1):   
    y-=i*10000
    if (n-i)*5000<y:
        continue
    for j in range((y//5000),-1,-1):
        y-=j*5000        
        if 1000*(n-i-j)==y:
            print(str(i)+' '+str(j)+' '+str(n-i-j))
            exit()
        y+=j*5000
    y+=i*10000
print("-1 -1 -1")

Solution (Python):


import sys

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

for j in range(n + 1):
    for i in range(j + 1):
        if i * 10000 + (j - i) * 5000 + (n - j) * 1000 == y:
            print("%d %d %d" % (i, j - i, n - j))
            sys.exit(0)

print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())
res = (-1, -1, -1)
for x in range(N + 1):
    for y in range(N + 1 - x):
        if N - x - y >= 0 and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            res = (x, y, N - x - y)
print(res[0], res[1], res[2])

Solution (Python):
N, Y = map(int, input().split())
res = (-1, -1, -1)
for x in range(N + 1):
    for y in range(N + 1 - x):
        if N - x - y >= 0 and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            res = (x, y, N - x - y)
print(res[0], res[1], res[2])

Solution (Python):
N, Y = map(int, input().split())
res = []
for x in range(N + 1):
    for y in range(N + 1 - x):
        if N - x - y >= 0 and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            res.append((x, y, N - x - y))
if res :
    print(res[0][0], res[0][1], res[0][2])
else:
    print(-1, -1, -1)

Solution (Python):
from itertools import product

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

ret = [-1, -1, -1]
for x in range(N + 1):
    for y in range(N + 1 - x):
        z = N - x - y
        if N - x - y < 0:
            continue
        if 10000 * x + 5000 * y + 1000 * z == Y:
            ret = [x, y, z]
            break

print(' '.join([str(r) for r in ret]))

Solution (Python):





if __name__ == '__main__':
    bill_count, total_yen = list(map(int, input().split()))

    
    for i in range(bill_count + 1):
        for j in range(bill_count - i + 1):
            if (10 * i + 5 * j + (bill_count - i - j)) == total_yen // 1000:
                print(i, j, bill_count - i - j)
                exit()
    else:
        print('-1 -1 -1')

Solution (Python):





if __name__ == '__main__':
    bill_count, total_yen = list(map(int, input().split()))
    bill_max = 2000

    five_thousand_yen_count = 0
    one_thousand_yen_count = 0

    for z in range(bill_max + 1):
        for y in range(bill_max + 1):
            if (5 * y + 9 * z) == (10 * bill_count - total_yen / (10 ** 3)):
                five_thousand_yen_count = y
                one_thousand_yen_count = z
                break

    ten_thousand_yen_count = bill_count - (five_thousand_yen_count + one_thousand_yen_count)

    condition = ((10 * ten_thousand_yen_count) + (5 * five_thousand_yen_count) + one_thousand_yen_count) == (total_yen / 1000)
    condition1 = ten_thousand_yen_count >= 0
    condition2 = five_thousand_yen_count >= 0
    condition3 = one_thousand_yen_count >= 0

    if condition and condition1 and condition2 and condition3:
        print(str(ten_thousand_yen_count) + ' ' + str(five_thousand_yen_count) + ' ' + str(one_thousand_yen_count))
    else:
        print('-1 -1 -1')

Solution (Python):
n, y = [int(i) for i in 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 = [int(i) for i in input().split()]
po = False
x,y,z = -1,-1,-1
for i in range(N+1):
    for j in range(N-i+1):
        if (Y - (i * 10000 + j * 5000)) / 1000 == N - i - j:
            x = i
            y = j
            z = int((Y - (i * 10000 + j * 5000)) / 1000)
            po = True
            break
    if po:
        break

print(x,y,z)

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

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

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


a = Y//10000
b = Y//5000

flag = False

for i in range(a+1):
    if flag == True:
        break
    for j in range(b+1):
        if N-i-j<0:
            break
        if i*10000+j*5000+(N-i-j)*1000 == Y:
            flag = True
            s = i
            t = j
            u = N-i-j
            break

if flag == True:
    print(s,t,u)
else:
    print(-1,-1,-1)

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

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

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

print(-1, -1, -1)

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

coins = [10000, 5000, 1000]

ans = []
def dfs(sum_v, now, i):
    if len(ans) != 0:
        return

    used = sum(now)

    if len(now) == 3:
        if sum_v == Y:
            ans.append(now)
        return

    if sum_v + coins[i] * (N - used) < Y:
        return

    if sum_v > Y:
        return

    if i == 2:
        ne = now + [N - used]
        dfs(sum_v + coins[i] * (N - used), ne, i + 1)
    else:
        for j in range(N - used + 1):
            ne = now + [j]
            dfs(sum_v + coins[i] * j, ne, i + 1)

dfs(0, [], 0)
if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(" ".join(map(str, ans[0])))

Solution (Python):
def checker(N, Y):
    for yen_10000 in range(N + 1):
        for yen_5000 in range(N - yen_10000 + 1):
            yen_1000 = N - yen_10000 - yen_5000
            value = 10000 * yen_10000\
                  + 5000  * yen_5000\
                  + 1000  * yen_1000

            if value == Y:
                return yen_10000, yen_5000, yen_1000
    return -1, -1, -1

def main():
    N, Y = map(int, input().split())
    ret = checker(N, Y)
    print("{} {} {}".format(ret[0], ret[1], ret[2]))

main()

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

c=[]
for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i+5000*j+1000*(N-i-j)==Y:
            c.append(str(i))
            c.append(str(j))
            c.append(str(N-i-j))
            break
            
            
if  len(c)==0:
    print('-1 -1 -1')
else:
    print(c[0]+' '+c[1]+' '+c[2])

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

Solution (Python):
n, y = map(int, input().split())
yen = [1000, 5000, 10000]

def f():
    for i in range(n+1):
        r = yen[2] * i
        if r > y:
            continue
        for j in range(n+1):
            if i + j > n:
                continue
            if r + yen[1] * j + yen[0] * (n - i -j)== y:
                print('{} {} {}'.format(i, j, n - i - j))
                return
    print('-1 -1 -1')

f()

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

end = 0

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)
            end = 1
            
            break
    
    if end == 1:
        break
        
else:
    print(-1, -1, -1)

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

for i in range(n+1):
 a = i
 b = (y-n-9*i)/4
 c = n-i-b
 
 if  b==int(b) and b>=0 and c>=0:
  ans = "{0} {1} {2}".format(a, int(b), int(c))
  break
 
print(ans)

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

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

N,Y = na()
flag = 0
for x in range(N+1):
    for y in range(N+1):
        z = N - (x+y)
        if 10000*x + 5000*y + 1000*z == Y and x >= 0 and y >= 0 and z >= 0:
            flag = 1
            break
    if flag:
        break
    else:
        pass
if flag:
    print(x,y,z)
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+1):
        k = N - i - j
        if k < 0:
            continue
        if 10000 * i + 5000 * j + 1000 * k == Y:
            print(i, j, k)
            f = True
            break
    if f :
        break
if (not f): 
    print(-1, -1, -1)

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

x=y=z=-1

for i in range(N+1):
    if i*10000>Y:
        continue
    for j in range(N+1):
        if i*10000+j*5000>Y:
            continue
        elif (N-i-j)*1000+j*5000+i*10000==Y:
            x=i
            y=j
            z=N-j-i
            break

print(x,y,z)

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


def f():
  x = -1
  y = -1
  z = -1

  for i in range(N+1):

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

      total = i * 10000 + j * 5000 + temp * 1000

      if total == Y:
        x = i
        y = j
        z = temp
  
  ans = list(map(str,[x, y, z]))

  return ' '.join(ans)

print(f())

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

ok = False
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("%d %d %d" % (i, j, k))
            ok = True
            break
    if ok:
        break

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

Solution (Python):
N,Y=map(int,input().split())
Y = Y/1000
a,b,c =0,0,0
flg = True
if 10*N < Y:
  a,b,c = -1,-1,-1


else:
    for n in range(int(N/5)+1):
        c = int(Y%5 + 5*n)
        for i in range(N-c+1):
            if (5*i + 5*N) == (Y + 4*c):
                flg = False
                a , b = i , (N-c-i)
                break
        if not flg:
            break
if flg:
    a,b,c = -1,-1,-1
print(a,b,c)

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 x>=0 and 10000*x+5000*y+1000*z==Y:
            break
    else:
        continue
    break
else:
    x,y,z=[-1]*3

print(x,y,z)

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

Solution (Python):
import sys
n,d = 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))==d):
            print(str(i)+" "+str(j)+" "+str(n-i-j))
            sys.exit()
print("-1 -1 -1")

Solution (Python):
def solve():
    N, Y = list(map(int, input().split()))
    max_yukichi = Y // 10000
    max_ichiyo = Y // 5000
    for yukichi in range(Y//10000+1):
        for ichiyo in range(max((Y//5000+1-2*yukichi), 0)):
            if Y - yukichi*10000 - ichiyo*5000 == (N - yukichi - ichiyo) * 1000:
                print(yukichi, ichiyo, (N - yukichi - ichiyo))
                return
    print(-1, -1, -1)

solve()

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

a = -1
b = -1
c = -1

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

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

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, Y = [int(x) for x in input().split()]

y = Y//1000

for a in range((y-N)//9 + 1):
    if (y-N-9*a) % 4 == 0:
        b = (y-N-9*a)//4
        c = N - a - b
        if c >= 0:
            print('{0} {1} {2}'.format(a, b, c))
            sys.exit()

print('-1 -1 -1')

Solution (Python):
N, Y = [int(item) for item in input().split(" ")]
found = False
for i in range(N+1):
    for j in range(N+1-i):
        if found:
            break
        if 10000*i+5000*j+1000*(N-i-j)==Y:
            print("{} {} {}".format(i,j,N-i-j))
            found = True
    if found:
        break
else:
    print("-1 -1 -1")

Solution (Python):
N, Y = tuple(map(int, input().split(' ')))
result = "-1 -1 -1"
for i in range(0, N + 1):
    
    
    
    t = (Y - 1000 * i) % 5000

    if t == 0:
        x = int(((Y - 1000 * i) / 5000) - (N - i))
        y = int((N - i) - x)

        if x >= 0 and y >= 0:
            result = "{0} {1} {2}".format(x, y, i)
            break

print(result)

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

ans = [-1,-1,-1]
for x in range(N+1):
    for y in range(N+1):
        k = N-x-y
        if k>=0 and 10000*x+5000*y+1000*k==Y:
                ans[0] = x
                ans[1] = y
                ans[2] = k

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

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

Solution (Python):
import sys
N,Y=map(int,input().split())
manMax=Y//10000
for i in range(manMax+1)[::-1]:
  res=Y-i*10000
  fiveMax=res//5000
  for j in range(fiveMax+1)[::-1]:
    ress=res-j*5000
    thou=N-i-j
    resss=ress-thou*1000
    if(resss==0):
      print(str(i)+" "+str(j)+" "+str(thou))
      sys.exit()
print("-1 -1 -1")

Solution (Python):
def check(n,y):
  if (y%1000!=0):
    return (-1, -1, -1)
  nn = y/1000
  nover = nn-n
  if (nover<0):
    return (-1, -1, -1)
  aend = nover/4 if(nover%4==0) else nover/4+1
  for a in range(int(nover/4)+1):
    if (((nover-a*4)>=0) and (nover-a*4)%9==0):
      nh = a
      ny = (nover-4*a)/9
      nn = nn - 5*nh - 10*ny
      if(nn<0):
        return (-1, -1, -1)
      return (ny,nh,nn)
  return (-1, -1, -1)


if __name__=='__main__':
  n, y = map(int, raw_input().split())
  ny, nh, nn = check(n,y)
  print ny, nh, nn

Solution (Python):
N,Y = map(int,input().split())
f=False
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)
            f=True
            break
    if f :
        break
if (not f): 
    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+1):
        k = N-i-j
        if k < 0:
            continue
        if 10000*i + 5000*j + 1000*k == Y:
            print(i,j,k)
            f=True
            break
    if f :
        break
if f==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 10000*i+5000*j+1000*z==Y and z>=0:
            print(i,j,z)
            exit()
print('-1 -1 -1')

Solution (Python):
def bills(count, value):
    max10000 = value // 10000
    for i in range(max10000 + 1):
        max5000 = min(count - i, (value - i * 10000) // 5000)
        for j in range(max5000 + 1):
            k = (value - i * 10000 - j * 5000) // 1000
            if i + j + k == count:
                return i, j, k
    
    return -1, -1, -1

v = bills(*map(int, input().split()))
print("{} {} {}".format(*v))

Solution (Python):
N, Y = (int(i) for i in input().split())
N1000 = Y // 1000
n10000 = N1000 // 10
r1 = N1000 % 10
n5000 = r1 // 5
n1000 = r1 % 5

if N1000 < N:
	print("-1 -1 -1")
	exit(0)

while n10000 >= 0:
	while n5000 >= 0:
		n = n10000 + n5000 + n1000
		if n == N:
			print(n10000, n5000, n1000)
			exit(0)
		n5000 -= 1
		n1000 += 5
	n5000 = (n1000-5) // 5
	n1000 = (n1000-5) % 5
	n10000 -= 1
	n5000 += 2

print("-1 -1 -1")

Solution (Python):
def main():
    N, Y = [int(x) for x in input().strip().split()]
    
    for ni in range(N+1)[::-1]:
        sum = ni * 10000
        if sum > Y:
            continue

        M = N - ni

        for mi in range(M+1)[::-1]:
            sum = (ni*10000) + (mi*5000) + ((N-ni-mi) * 1000)
            if sum == Y:
                return "{} {} {}".format(ni, mi, N-ni-mi)
    return "-1 -1 -1"
    
if __name__ == '__main__':
    print(main())

Solution (Python):
def main():
    N, Y = [int(x) for x in input().strip().split()]
    
    for ni in range(N+1)[::-1]:
        sum = ni * 10000
        if sum > Y:
            continue

        M = N - ni

        if M == 0:
            if sum == Y:
                return "{} {} {}".format(ni, 0, 0)
            continue

        for mi in range(M+1)[::-1]:
            sum = (ni*10000) + (mi*5000) + ((N-ni-mi) * 1000)
            if sum == Y:
                return "{} {} {}".format(ni, mi, N-ni-mi)
    return "-1 -1 -1"
    
if __name__ == '__main__':
    print(main())

Solution (Python):
import sys

N, Y = map(int, input().split())
Y2 = Y // 1000

for a in range(2001):
    for b in range(2001 - a):
        if 9 * a + 4 * b + N == Y2 and a + b <= N:
            print(a, b, N - a - b)
            sys.exit(0)
print(-1, -1, -1)

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

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

a = 0  
b = 0  
c = 0  

c = y//10000
b = (y - c*10000)//5000
a = (y - c*10000 - b*5000)//1000

flag = True

while (a+b+c) <= n:
    num = a+b+c


    if num == n:
        flag = False
        break
    else:
        if num + 9 <= n and c > 0:
            c -= 1
            a += 10
            continue
        elif num + 4 <= n and b > 0:
            b -= 1
            a += 5
            continue
        elif num + 1 <= n and c > 0:
            c -= 1
            b += 2
            continue
        else:
            break
if flag:
    print(-1, -1, -1)
else:
    print(c, b, a)