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) = [int(i) for i in input().split()]
 
y10k = Y // 10000
y5k, y1k = divmod((Y%10000)/1000, 5)
 
current_inbag = y10k+y5k+y1k
diff = N - current_inbag
 
if Y > 10000*N or Y < 1000*N or diff < 0:
    print('-1 -1 -1')
    exit()
 
while y10k > 0 and diff >= 9:
    y10k -= 1
    y1k += 10
    diff -= 9

if y10k > 0 and diff >= 5:
    y10k -= 1
    y5k += 1
    y1k += 5
    diff -= 5

while y10k > 0 and diff > 0:
    y10k -= 1
    y5k += 2
    diff -= 1

if y10k == 0 and diff > 0:
    while y5k > 0 and diff >= 4:
        y5k -= 1
        y1k += 5
        diff -= 4

if diff == 0:
    print('%d %d %d' % (y10k,y5k,y1k))
    exit()

print('-1 -1 -1')

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

Solution (Python):
import sys
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("{0} {1} {2}".format(i,j,k))
      sys.exit()
print("-1 -1 -1")

Solution (Python):
n,y = map(int, input().split())
x = y
for i in range(x//10000 + 1):
    x_af_1m = x - 10000*i
    count_af_1m = i
    for j in range(x_af_1m//5000 + 1):
        x_af_5s = x_af_1m - 5000*j
        count = count_af_1m + j + (x_af_5s//1000)
        if count == n:
            ans = [i,j,(x_af_5s//1000)]
            break
    else:
        continue
    break

try:
    for i in range(3):
        ans[i] = str(ans[i])
    print(" ".join(ans))
except NameError:
    print(-1,-1,-1)

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

flg = 0
for i_a in range(n+1)[::-1]:
	for i_b in range(n+1-i_a)[::-1]:
		i_c = n - i_a - i_b
		if i_a*10000 + i_b*5000 + i_c*1000 == y:
			flg = 1
			print(i_a, i_b, i_c)
			break
	if flg == 1:
		break

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

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

flag = False

for a in range(N + 1):
    if flag:
        break
    for b in range(N + 1 - a):
        if flag:
            break
        c = N - a - b
        if c < 0:
            continue
        elif a * 10000 + b * 5000 + c * 1000 == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            flag = True

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

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

flag = False

for a in range(N + 1):
    if flag:
        break
    for b in range(N + 1 - a):
        if flag:
            break
        c = N - a - b
        if c < 0:
            continue
        elif a * 10000 + b * 5000 + c * 1000 == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            flag = True

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

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

flag = False

for a in range(N + 1):
    if flag == True:
        break
    for b in range(N + 1 - a):
        if flag == True:
            break
        c = N - a - b
        if c < 0:
            continue
        elif a * 10000 + b * 5000 + c * 1000 == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            flag = True

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

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

flag = False

for a in range(N + 1):
    if flag == True:
        break
    for b in range(N + 1):
        if flag == True:
            break
        c = N - a - b
        if c < 0:
            continue
        elif a * 10000 + b * 5000 + c * 1000 == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            flag = True

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

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

for k in range(0,n+1):
  a = n-k
  b = y-10*k-a
  if b%4 == 0 and b <= 4*a and b>=0:
    flag = True
    break
    
if flag:
  print(k,b//4,a-b//4)
else:
  print(-1,-1,-1)

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

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

Solution (Python):
n,m = map(int,input().split())
z = 0
for x in range(n+1):
 for y in range(n+1):
  z = n - x - y
  if 10000 * x + 5000 * y + 1000 * z == m and z >= 0:
   print(x,y,z)
   exit()
else:
 print(-1,-1,-1)

Solution (Python):
list = list(map(int, input().split()))
n = list[0]
y = list[1]
 
index1 =0
answer=""
while index1<=n:
    index2 =0
    while index2<=n-index1:
        if y == index1*1000+index2*5000+(n-index1-index2)*10000:
            answer=str(n-index1-index2)+" "+str(index2)+" "+str(index1)
            print(answer)
            break
        elif index1==n and index2==0:
            answer ="-1 -1 -1"
            print(answer)
            break
        else:
            index2+=1
    if answer!= "":
        break
    index1+=1

Solution (Python):
N,Y = map(int,input().split())
flag = 0
for i in range(N+1) :
    a = 10000*i
    for j in range(N+1) :
        b = 5000*j
        if (a+b) <= Y :
            c = Y-(a+b)
            k = c//1000
            if flag == 1 :
                break
            elif (i+j+k) == N :
                print(i,j,k)
                flag += 1
if flag == 0 :
    print(-1,-1,-1)

Solution (Python):

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

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

for i in range(n + 1):
    if 10000*i == y and i == n:
        a = i
        b = 0
        c = 0
        break
    else:
        for j in range(n - i + 1):
            if i+j == n and 10000*i + 5000*j == y:
                a = i
                b = j
                c = 0
                break
            elif 10000*i + 5000*j + 1000*(n - i -j) == y:
                a = i
                b = j
                c = n - i - j
                break


print(str(a) + " " + str(b) + " " + str(c))

Solution (Python):
import numpy as np
import math







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

for x in range(N+1):
    for y in range(N+1):
        if x + y > N:
            continue
        z = N - x - y
        if x + 5 * y + 10 * z == Y:
            print(z, y, x)
            exit(0)

print(-1, -1, -1)

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

ans = [-1, -1, -1]
for i in range(n+1):
    for j in range(n+1-i):
        k = n-i-j
        if 10000*i + 5000*j + 1000*k == y:
            ans = [i, j, k]
            break
        
print(' '.join(list(map(str, ans))))

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

flag = False
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)
            flag = True
            break
    if flag:break
if not flag:print(-1, -1, -1)

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

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

print('-1 -1 -1')

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

Solution (Python):
import sys
n, total = list(map(int, input().split()))
for x in range(n+1):
    for y in range(n-x+1):
        z = n - x - y
        if x*10000 + y*5000 + z*1000 == total:
            print("{} {} {}".format(x, y, z))
            sys.exit()
print("-1 -1 -1")

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

Solution (Python):
X, Y = map(int,input().split(' '))
sum1 = 0
flag = False

for x in range(X+1):
    sum1 = 10000 * x
    if sum1 > Y:
        break
    for y in range(X-x+1):
        sum2 = sum1 + 5000 * y
        if sum2 > Y:
            break
        if sum2 + 1000*(X-x-y) == Y:
            flag = True
            break
    if flag:
        break
if flag:
    print('{0} {1} {2}'.format(x,y,X-x-y))
else:
    print('-1 -1 -1')

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

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

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

Solution (Python):
from sys import stdin

N, Y = [int(x) for x in stdin.readline().rstrip().split()]

flag = True


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

    if (not flag):
        break
else:
    print('-1 -1 -1')

Solution (Python):

import os, sys
import math

def read_items_in_line(cast=int):
    return [cast(x) for x in sys.stdin.readline().strip(' \n').split(' ')]

def checK(remain_N, remain_Y, a, b, c):
    if remain_N == 0 and remain_Y == 0:
        print("{} {} {}".format(a, b, c))
        exit(0)

N, Y = read_items_in_line()

for a_i in reversed(range(int(Y / 10000) + 1)):
    remain_N = N - a_i
    remain_Y = Y - a_i * 10000
    if remain_N < 0 or remain_Y < 0:
        continue
    for b_i in reversed(range(int(remain_Y / 5000) + 1)):
        remain_N = N - a_i - b_i
        remain_Y = Y - a_i * 10000 - b_i * 5000
        if remain_N < 0 or remain_Y < 0:
            continue
        if remain_N == remain_Y / 1000:
            c_i = int(remain_Y / 1000)
            remain_N = N - a_i - b_i - c_i
            remain_Y = Y - a_i * 10000 - b_i * 5000 - c_i * 1000
            
            checK(remain_N, remain_Y, a_i, b_i, c_i)


print("-1 -1 -1")

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

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

Solution (Python):
import sys

def change_10to5(x, y):
    """
    10000円札を5000円札2枚に崩す．結果的に1枚増やす.

    :param x:10000円札の枚数
    :param y:5000円札の枚数
    :return: 演算後の10000円札と5000円札の枚数
    """

    x -= 1
    y += 5

    return x, y


def change_5to1(y, z):
    """
    5000円札を1000円札に崩す.
    4枚増やす.
    """

    y -= 1
    z += 5

    return y, z


def change_1to5(z, y):
    """
    1000円札5枚を5千円札1枚にまとめる．4枚減らす．
    :param z: 1000円札の枚数．
    :param y: 5000円札の枚数．
    :return: 演算後の1000円札と5000円札の枚数．
    """

    z -= 5
    y += 1

    return z, y


def change_5to10(y, x):
    """
    5000円札2枚を10000円札にする．
    1枚減らす．
    """

    y -= 2
    x += 1

    return y, x


def main():
    n, y_input = map(int, input().split())
    cash_num = y_input // 1000
    x = 0
    y = 0
    z = cash_num

    while True:
        if cash_num > n:
            if cash_num - n >= 4 and z >= 5:
                z, y = change_1to5(z, y)
                cash_num -= 4
            elif cash_num - n >= 1 and y >= 2:
                y, x = change_5to10(y, x)
                cash_num -= 1
            else:
                print("-1 -1 -1")
                sys.exit()
        elif cash_num < n:
            if n - cash_num >= 4 and y > 0:
                y, z = change_5to1(y, z)
                cash_num += 4
            elif n - cash_num >= 1 and x > 0:
                x, y = change_10to5(x, y)
                cash_num += 1
            else:
                print("-1 -1 -1")
                sys.exit()
        else:
            if n == cash_num:
                print("{} {} {}".format(x, y, z))
                break
            else:
                print("-1 -1 -1")
                break


if __name__ == "__main__":
    main()

Solution (Python):
N,Y = map(int,input().split())
L = []
for x in range(N+1):
  for y in range(N+1):
    if(9*x+4*y+N == Y//1000 and x+y <= N):
      L.append(x)
      L.append(y)
      L.append(N-x-y)
      break
if (L != []):      
  print(L[0],L[1],L[2])
else:
  print(-1,-1,-1)

Solution (Python):
N,Y = map(int,input().split())
def check_otoshidama(N,Y):
    for i in range(N+1):
        for q in range(N+1):
            if i + q > N:
                break
            c_1,c_2,c_3 = i,q,N-(i+q)
            
            money_sum = c_1 * 10000 + c_2 * 5000 + c_3 * 1000
            if money_sum == Y:
                return [c_1,c_2,c_3]
            elif money_sum > Y:
                break
    return [-1,-1,-1]
     
res = check_otoshidama(N,Y)
print("{} {} {}".format(res[0],res[1],res[2]))

Solution (Python):
print((lambda i, j, k: "{} {} {}".format(i, j, k))(*(lambda n, y: next(([i, j, k] for i in range(n + 1) for j in range(n - i + 1) for k in [n - i - j] if i * 10000 + j * 5000 + k * 1000 == y), [-1, -1, -1]))(*[int(s) for s in input().split(" ")])))

Solution (Python):
N,Y = map(int,input().split())
ans_10000 = -1
ans_5000 = -1
ans_1000 = -1

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

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

def solve():
	for i in range(n+1):
		for j in range(n+1-i):
			if 10000*i+5000*j+1000*(n-i-j) == y:
				return i,j,n-i-j
	return -1,-1,-1
	
print(*solve())

Solution (Python):
import sys
n,y = map(int,input().split())
y //= 1000
for k in range(min(n,y//10)+1):
    nn = n-k
    yy = y-10*k
    i = (yy - nn) // 4
    if (yy-nn)%4 == 0 and nn-i >= 0 and i >= 0:
        print(k,i,nn-i)
        sys.exit()
print(-1,-1,-1)

Solution (Python):
n, y = list(map(int, input().split()))
found = False
for i in range(n+1):
    for j in range(n+1):
        k = n-i-j
        if k < 0:
            continue
        if (i * 10000 + j * 5000 + k * 1000) == y:
            print("{} {} {}".format(i, j, k))
            found = True
            break
        if found:
            break
    if found:
        break
if not found:
    print("-1 -1 -1")

Solution (Python):
'''input
1000 1234000
'''
import sys
n,y = map(int,raw_input().split())
for i in range(2001):
	for j in range(2001):
		if i+j > n:
			continue
		z = i*(10**4)+j*(5000)+(n-i-j)*(1000)
		if z == y:
			print i,j,n-i-j
			sys.exit(0)
print "-1 -1 -1"

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,Y = inpl()

for y in range(N+1):
	for h in range(N+1-y):
		tmp = 10000*y + 5000*h
		n = N-y-h
		if Y-tmp == n*1000:
			print(y,h,n)
			sys.exit()

print(-1,-1,-1)

Solution (Python):


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

    all1000s = y // 1000
    x = all1000s - n

    for a in range(0, x+1, 4):
        nines = (x - a) // 9
        fours = a // 4
        ones = n - nines - fours
        if (x - a) % 9 == 0 and all(x >= 0 for x in (nines, fours, ones)):
            print("{} {} {}".format(nines, fours, ones))
            break
    else:
        print("-1 -1 -1")


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

    
    for x in range(N+1):
        for y in range(N+1):
            z = N - (x + y)
            if z < 0:
                break
            if (10000*x + 5000*y + 1000*z) == Y:
                print("{} {} {}".format(x, y, z))
                exit()
    print("-1 -1 -1")


if __name__ == "__main__":
    main()

Solution (Python):
n,y= map(int,input().split())
f = [False]


def binary_search(x,r):
    l = 0
    while(r-l>=1):

        i = int((l+r)/2)
        
        if(4000*i==x):
            f[0] = True
            return i
        elif(4000*i<x):
            l=i+1
        else:
            r = i
    
    return 0


for a in range(0,n+1):
    if f[0]==True:
        break
    b = int(binary_search(y-9000*a-1000*n,n-a+1))
    if f[0] == True:
        print(a,b,n-a-b)
        break
if f[0]==False:
    print(-1,-1,-1)

Solution (Python):
import sys

N, Y = [int(c) for c in input().split()]
result = (-1, -1, -1)

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

print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
A, B, C = [-1, -1, -1]
for a in range(N + 1):
  for b in range(N - a + 1):
    if 9 * a + 4 * b + N == Y:
      A, B, C = [a, b, N - a - b]
      break
  if A != -1:
    break
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
        price = 10000 * x + 5000 * y + 1000 * z
        if price == Y:
            print(x, y, z)
            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
        price = 10000 * x + 5000 * y + 1000 * z
        if price == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

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

max_x = min(Y // 10000, N)
max_y = min(Y // 5000, N)

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

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

answer = [-1, -1, -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 and i*10000 + j*5000 + k*1000 == Y:
            answer[0] = i
            answer[1] = j
            answer[2] = N-i-j

print("{} {} {}".format((answer[0]),(answer[1]),(answer[2])))

Solution (Python):
N, Y = list(map(int, input().split()))
S = Y // 10000 + 1
for i in range(S):
    T = (Y - i * 10000) // 5000 + 1
    for j in range(T):
        U = int((Y - i * 10000 - j * 5000) / 1000)
        if i + j + U == N:
            print(i, j, U)
            break
    else:
        continue
    break
else:
    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:
            continue
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print("{} {} {}".format((x),(y),(z)))
            exit()
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 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            
            print(i, j, n - i - j)
            exit()


print(-1, -1, -1)

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

for 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(str(x)+' '+str(y)+' '+str(z))
            exit()
print('-1 -1 -1')

Solution (Python):
n,y = map(int,input().split())
for i in range(n+1):
    for l in range((n+1)-i):
        if i*10+l*5+(n-i-l) == y//1000:
            print("{} {} {}".format(i,l,n-i-l))
            exit()
print("-1 -1 -1")

Solution (Python):
N,Y = [int(i) for i in input().split()]
x,y,z = [0,0,0]
x+=Y//10000 ; Y2=Y%10000
y+=Y2//5000 ; Y3=Y2%5000
z+=Y3//1000
if x+y+z>N:
    print("-1 -1 -1")
elif x+y+z==N:
    print(*[x,y,z])
else:
    N-=(x+y+z)
    while x>=1 and 9<=N:
        x-=1 ; z+=10
        N-=9
    while x>=1 and 5<=N:
        x-=1 ; y+=1 ; z+=5
        N-=5
    while y>=1 and 4<=N:
        y-=1 ; z+=5
        N-=4    
    while x>=1 and 1<=N:
        x-=1 ; y+=2
        N-=1
    if N!=0:
        print("-1 -1 -1")
    else:
        print(*[x,y,z])

Solution (Python):
n,y = map(int,input().split())
a = 10
b = 5
c = 1
d = y/1000
x,y,z = -1,-1,-1
check = 0
for i in range(n+1):
    for j in range(n+1-i):
        if a * i + b * j + c * (n-(i+j)) == d:
            x,y,z=i,j,n-(i+j)
print(x,y,z)

Solution (Python):
import sys
n, k = map(int, input().split())

for x in range(min(n, int(k / 10000)) + 1):
    for y in range(min((n - x), int((k - 10000 * x)/ 5000)) + 1):
        z = n - x - y
        if 10000 * x + 5000 * y + 1000 * z == k:
            print("{} {} {}".format(x,y,z))
            sys.exit()

print("{} {} {}".format(-1,-1,-1))

Solution (Python):
n, y = map(int, input().split())
a = b = c = -1
state = False
i = j = k = 0
for p in range(n+1):
    j = 0
    for q in range(n+1-i):
        k = n - i - j
        if 10000 * i + 5000 * j + 1000 * k == y:
             state = True
             a,b,c = i,j,k
             break
        j += 1
    if state:
        break
    i += 1

print(a, b, c)

Solution (Python):


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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


if __name__ == '__main__':
    main()

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

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

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 z >= 0 and 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()

print('-1 -1 -1')

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

def error_out():
    print('-1 -1 -1')
    exit()

if y > n * 10000 or y < n * 1000:
    error_out()

y //= 1000

if y >= n * 5:
    a = (y - n * 5) // 5 + (y - n * 5) % 5
    c = (y - n * 5) % 5
    b = n - a - c

    if b >= 0:
        print(a, b, c)
    else:
        error_out()
else:
    a = (y - n) % 4
    b = (y - n) // 4 - a * 2
    c = n - a - b

    if b >= 0 and c >= 0:
        print(a, b, c)
    else:
        error_out()

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

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

for a in range(N+1):
    for b in range(N-a+1):
        c = N - a -b
        if 10000 * a + 5000 * b + 1000 * c == Y:
            x, y, z = a, b, c
            print("{} {} {}".format(x, y, z))
            exit()
print("{} {} {}".format(x, y, z))

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

Solution (Python):
N,Y = map(int,input().split())
f = False
for x in range(Y//10000+1):
  r = Y-10000*x
  if r < 0: continue
  for y in range(r//5000+1):
    z = r-5000*y
    if z < 0: continue
    z = z // 1000
    if (x+y+z)==N: f = True
    if f: break
  if f: break
print(' '.join(map(str,[x,y,z])) if f else '-1 -1 -1')

Solution (Python):
N, Y = list(map(int, input().split()))
a=['-1']*3
for i in range(N+1):
    for j in range(N+1):
        k=N-(i+j)
        if i*10000+j*5000+k*1000==Y and k>=0:
            a[0]=str(i); a[1]=str(j); a[2]=str(k);

b=' '.join(a)
print(b)

Solution (Python):
def SolveABC085C(N, Y):

    finFlag = 0
    for z in range(N + 1):
        for (x,y) in zip(range(N - z+1), range(N - z + 1)[::-1]):
            if x * 10 + y * 5 + z == Y/1000:
                print "{} {} {}".format(x,y,z)
                finFlag = 1
                break
        if finFlag == 1:
            break
        if z == N:
            print "-1 -1 -1"
            
N, Y = map(int, raw_input().split())
SolveABC085C(N, Y)

Solution (Python):
N, Y = map(int, input().split())
counter = True
for i in range(N+1):
    for j in range(N - i+1):
        if j >= 0 and (N-i-j) >= 0 and counter:
            if 10**4*i + 5*10**3*j + 10**3*(N-i-j) == Y:
                
                print(i, j, N-i-j)
                counter = False
        else:
            break
if counter:
    print("-1 -1 -1")

Solution (Python):
n, y = map(int, input().split())
ans = 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)
            ans += 1
            exit()
if ans == 0:
    print("-1 -1 -1")

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

flag = False
for i in range(n + 1):
    for j in range(n - i + 1):
            if 10000*i + 5000*j + 1000*(n - i - j) == y:
                print(str(i) + ' ' + str(j) + ' ' + str(n - i - j))
                flag = True
                break
    if flag:
        break
if flag == False:
    print('-1 -1 -1')

Solution (Python):
a,b = map(int,input().split())
f = 0
for i in range(a+1):
    if f == 1: break
    for j in range(a+1-i):
        if f == 1: break
        k = a-i-j
        if (i*10000 + j*5000 + k*1000) == b:
                f = 1
                print(i,j,k)
if f == 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):
        if 10000*i+5000*j+1000*(N-i-j)==Y: print(i,j,(N-i-j));quit()
print("-1 -1 -1")

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

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

print(-1,-1,-1)

Solution (Python):
def chk(l):
    return l[0]*10+l[1]*5+l[2]

n,y=[int(x) for x in input().split()]
y//=1000
n-=y%5
ans=[0,n,y%5]
t=n*2
while t>=0:
    t-=1
    if y==chk(ans):
        break
    elif y>chk(ans) and ans[1]>0:
        ans[1]-=1
        ans[0]+=1
    elif y<chk(ans) and ans[1]>4:
        ans[1]-=5
        ans[2]+=5
    elif y>chk(ans) and ans[2]>0:
        ans[2]-=1
        ans[0]+=1
    elif y<chk(ans) and ans[0]>4:
        ans[0]-=5
        ans[2]+=5
        
if y==chk(ans):
    print(*ans)
else:
    print("-1 -1 -1")

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

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

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

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

impossible = "-1 -1 -1"
flag = False

if Y % 1000 != 0:
    print(impossible)

else:
    
    
    

    max_A = int(Y/10000)

    for num_A in range(max_A + 1):
        left_BC = Y
        left_BC -= num_A * 10000

        max_B = int(left_BC/5000)

        for num_B in range(max_B + 1):
            left_C = left_BC - num_B * 5000
            num_C = int(left_C/1000)

            if num_A + num_B + num_C == N:
                flag = True

                break

        if flag:
            break

    if flag:
        print("{} {} {}".format(num_A, num_B, num_C))
    else:
        print(impossible)

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

for i in range(0,(y//10000)+1):
    for j in range(0,((y-10000*i)//5000)+1):
        if y- 10000*i - 5000*j == 1000 * (n-i-j):
            print(i,j,n-i-j)
            quit()

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

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

flag = True

for i in range(Y // 10000 + 1):
    for k in range((Y - 10000*i) // 5000 + 1):
        l = int((Y - 10000*i - 5000*k) / 1000)
        if (i + k + l) == N:
            print(str(i) + " " + str(k) + " " + str(l))
            flag = False
            break
    if flag == False:
        break
if 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):
		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 a in range(n + 1):
  for b in range(n - a + 1):
    c = n - a - b
    if 10000 * a + 5000 * b + 1000 * c == y:
      print(a, b, c)
      exit()
print("-1 -1 -1")