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):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    return


def B():
    return


def C():
    n,y = LI()
    for i in range(n+1):
        for j in range(n+1-i):
            k = n-i-j
            if 10000*i+5000*j+1000*k == y:
                print(i,j,k)
                quit()
    print(-1,-1,-1)


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    C()

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

for i in range(N + 1):
    
    for j in range(i, N + 1):
        a, b, c = i, j - i, N - j
        
        if(10000 * a + 5000 * b + 1000 * c == Y):
            print(a, b, c)
            
            break_flag = True
            break
    
    if break_flag: break

if not break_flag: print('-1 -1 -1')

Solution (Python):

def solve(N, Y):
    
    for gosen in range(0, N + 1):
        for man in range(0, N - gosen + 1):
            sen = N - gosen - man
            if man * 10000 + gosen * 5000 + sen * 1000 == Y:
                return man, gosen, sen
    return -1, -1, -1


N, Y = map(int, input().split())
man, gosen, sen = solve(N, Y)
print(int(man), int(gosen), int(sen))

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

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:
            print(a, b, c)
            exit()
print(-1, -1, -1)

Solution (Python):
def main():
    n, y = map(int, input().split())
    print(*solve(n, y))

def solve(n, y):
    for i in range(y // 10000 + 1):
        if (y - 9000 * i - 1000 * n) % 4000 != 0:
            continue
        j = (y - 9000 * i - 1000 * n) // 4000
        k = n - i - j
        if i >= 0 and j >= 0 and k >= 0:
            return i, j, k

    return -1, -1, -1

main()

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

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

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

Solution (Python):
n,y=(int(i) for i in input().split())
ass=False
for i in range(n+1):
  for j in range(n+1-i):
    yy=y-10000*i-5000*j
    a=n-i-j
    if yy==1000*a:
      ass=True
      p=i;q=j;r=a
      break
if ass:
  print(p,q,r)
else:
  print(-1,-1,-1)

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

k = Y / 1000

ans_a, ans_b, ans_c = -1, -1, -1
for a in range(N+1):
    for b in range(N+1-a):
        if 9*a + 4*b == k - N:
            ans_a, ans_b = a, b

if ans_a != -1:
    ans_c = N - ans_a - ans_b

print(ans_a, ans_b, ans_c)

Solution (Python):

s=raw_input().split(' ')
n=int(s[0])
y=int(s[1])

k=y-1000*n

f=0;
for a in range(0,1000001):
	l=k-9000*a;
	if l<0:
		f=0
		break;
	
	if l%4000==0:
		b=l//4000;
		c=n-a-b;
		if c>=0:
			f=1;
			break;

if f==1:
	c=n-a-b;
	print(str(a)+" "+str(b)+" "+str(c))
else:
	print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())
flag = False
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:
            flag = True
            print(x, y, z)
            break
    if flag:
        break
else:
    print(*[-1]*3)

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

yen = int(Y/1000)
m_1 = int(Y/1000)
m_5 = int((m_1-m_1%5)/5)
m_10 = int((m_1-m_1%10)/10)

t = 0
for x in range(0,m_10+1):
    test1 = yen - 10*x
    if test1 < 0: break
    for y in range(0,m_5+1):
        if t == 1:break
        z = test1 - 5*y
        if z < 0:break
        if z == N-x-y:
            print(x,y,z)
            t = 1
            
if t == 0:
    print(-1,-1,-1)

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

    R = Y/1000 - N
    for b in range(N+1):
        tmp = (R - 4 * b)
        if (tmp < 0):
            break
        m = tmp % 9
        if (0 == m):
            c = int(tmp / 9)
            a = N - b - c
            if (a < 0):
                break
            print(c, b, a)
            return
    print(-1, -1, -1)
    return

main()

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

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

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

Solution (Python):
N, Y = map(int, input().split())
Y = Y // 1000
for i in range(N + 1):
    if i * 10 > Y:
        continue
    for j in range(N + 1):
        if i + j > N:
            continue
        if Y == i * 10 + j * 5 + 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):
    if Y < 10000 * i:
        continue
    for j in range(N + 1):
        if N < i + j :
            continue
        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 = map(int, input().split())
b = 0
for i in range(n + 1):
    if b == 1:
        break
    for j in range(n - i + 1):
        if b == 1:
            break
        elif i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            b = 1
            break
if b == 0:
    print("-1 -1 -1")

Solution (Python):
I = list(map(int, input().split()))
b = 0
for m in range(0, I[0] + 1):
    if b == 1:
        break
    for g in range(0, I[0] + 1 - m):
        s = I[0] - m - g
        if b == 1:
            break
        elif 10000 * m + 5000 * g + 1000 * s == I[1]:
            print("{} {} {}".format(m, g, s))
            b = 1
            break
if b == 0:
    print("-1 -1 -1")

Solution (Python):
n, Y = [int(s) for s in input().split(' ')]
 
for x in range(n, -1, -1):
    for y in range(n-x, -1, -1):
        z = n-x-y
        if Y == x*10000+y*5000+z*1000:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Solution (Python):
n, Y = [int(s) for s in input().split(' ')]
 
for x in range(n, -1, -1):
    if Y < x*10000 or n < x:
        continue
    
    for y in range(n-x, -1, -1):
        if Y < x*10000+y*5000 or n < x+y:
            continue
            
        z = n-x-y
        if Y == x*10000+y*5000+z*1000:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
flag = False
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:
            print("{0} {1} {2}".format(x, y, z))
            flag = True
            break
    if flag:
        break
if not flag:
    print("-1 -1 -1")

Solution (Python):
n, Y = [int(s) for s in input().split(' ')]
 
for x in range(n, -1, -1):
    if Y < x*10000:
        continue
    
    for y in range(n-x, -1, -1):
        if Y < x*10000+y*5000:
            continue
        if (Y-x*10000-y*5000) % 1000 != 0:
            continue
            
        z = int((Y-x*10000-y*5000)/1000)
        if n == x+y+z:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Solution (Python):
n, Y = [int(s) for s in input().split(' ')]
 
for x in range(n, -1, -1):
    if Y < x*10000 or n < x:
        continue
    
    for y in range(n-x, -1, -1):
        if Y < x*10000+y*5000 or n < x+y:
            continue
        if (Y-x*10000-y*5000) % 1000 != 0:
            continue
            
        z = int((Y-x*10000-y*5000)/1000)
        if n == x+y+z:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Solution (Python):
n, Y = [int(s) for s in input().split(' ')]
 
for x in range(n, -1, -1):
    if Y < x*10000 or n < x:
        continue
    
    for y in range(n-x, -1, -1):
        if Y < x*10000+y*5000 or n < x+y:
            continue
            
        z = int((Y-x*10000-y*5000)/1000)
        if (Y-x*10000-y*5000) % 1000 == 0 and n == x+y+z:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Solution (Python):
n, Y = [int(s) for s in input().split(' ')]
 
for x in range(n, -1, -1):
    if Y < x*10000 or n < x:
        continue
    
    for y in range(n-x, -1, -1):
        if Y < x*10000+y*5000 or n < x+y:
            continue
            
        z = int((Y-x*10000-y*5000)/1000)
        if (Y-x*10000-y*5000) % 1000 == 0 and n == x+y+z:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Solution (Python):
n, Y = [int(s) for s in input().split(' ')]
 
max_x = int(Y/10000)
for x in range(n, -1, -1):
    if Y < x * 10000 or n < x:
        continue
    
    max_y = int((Y-x*10000)/5000)
    for y in range(n-x, -1, -1):
        if Y < x*10000+y*5000 or n < x+y:
            continue
            
        z = int((Y-x*10000-y*5000)/1000)
        if (Y-x*10000-y*5000) % 1000 == 0 and n == x+y+z:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Solution (Python):
n, Y = [int(s) for s in input().split(' ')]
 
max_x = int(Y/10000)
for x in range(min(n, max_x), -1, -1):
    if Y < x * 10000 or n < x:
        continue
    
    max_y = int((Y-x*10000)/5000)
    for y in range(min(n-x, max_y), -1, -1):
        if Y < x*10000+y*5000 or n < x+y:
            continue
            
        z = int((Y-x*10000-y*5000)/1000)
        if (Y-x*10000-y*5000) % 1000 == 0 and n == x+y+z:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

Solution (Python):
def match(N, Y):
    for x in range(N+1):
        if 10000*x > Y:
            break
        for y in range(N-x+1):
            if 10000*x + 5000*y > Y:
                break
            z = N-x-y
            total = 10000*x + 5000*y + 1000*z
            if total == Y:
                return x,y,z
    return -1,-1,-1
  
N, Y = map(int, input().split())
x,y,z = match(N,Y)
print('{} {} {}'.format(x,y,z))

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

a = y // 10000
b = (y % 10000) // 5000
c = (y % 5000) // 1000

ta = a
tb = b
tc = c

if ta + tb + tc == n:
    print(ta, tb, tc)
    exit(0)


while ta >= 0:
    while tb >= 0:
        if ta + tb + tc == n:
            print(ta, tb, tc)
            exit(0)
        tb -= 1
        tc += 5
    ta -= 1
    tb = b + (a-ta)*2
    tc = c
print(-1, -1, -1)

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

max_ten_th = int(y/10000)
for ten_th in range(min(n, max_ten_th), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    
    max_five_th = int((y-ten_th*10000)/5000)
    for five_th in range(min(n-ten_th, max_five_th), -1, -1):
        if y < ten_th*10000+five_th*5000 or n < ten_th+five_th:
            continue
            
        th = int((y-ten_th*10000-five_th*5000)/1000)
        if (y-ten_th*10000-five_th*5000) % 1000 == 0 and n == ten_th+five_th+th:
            print('{} {} {}'.format(ten_th, five_th, th))
            exit()
            
print('-1 -1 -1')

Solution (Python):
n, y = list(map(int, input().split(' ')))
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        if (y - ten_th * 10000 - five_th * 5000) % 1000 == 0:
            th = int((y - ten_th * 10000 - five_th * 5000) / 1000)
            if n == ten_th + five_th + th:
                print('{} {} {}'.format(ten_th, five_th, th))
                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):
        if 10000*i+5000*j+1000*(n-i-j)==y and n-i-j>=0:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Solution (Python):
n, Y = map(int, input().split())
for x in range(n + 1):
    for y in range(n + 1 - x):
        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())


def main():
    
    
    x = Y // 10000
    y = (Y - 10000 * x) // 5000
    z = (Y - 10000 * x - 5000 * y) // 1000

    while True:
        t = x + y + z

        
        if t + 9 <= N and 0 < x:
            x -= 1
            z += 10
            continue

        
        if t + 4 <= N and 0 < y:
            y -= 1
            z += 5
            continue

        
        if t + 1 <= N and 0 < x:
            x -= 1
            y += 2
            continue

        break

    print(x, y, z) if x + y + z == N else print(-1, -1, -1)

    return


main()

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


def main():
    for x in range(N + 1):
        for y in range(N + 1):
            if N < x + y:
                break

            z = N - x - y

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

    print(-1, -1, -1)
    return


main()

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

for i in range(N+1):
    x = i
    for y in range(9):
        z = N - x - y
        if z < 0 :
            break
        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())

for i in range(N+1):
    x = i
    for y in range(9):
        z = N - x - y
        if z < 0 :
            break
        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())
ans = "-1 -1 -1"
for a in range(N+1):
  for b in range(N-a+1):
    c = N-a-b
    if a*10000+b*5000+c*1000 == Y:
      ans = "%d %d %d"%(a,b,c)
print(ans)

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

def solve(N,Y):
    for i in range(N+1):
        for j in range(N+1-i):
            if (Y-(i*10000 + j*5000)) // 1000 != N - i - j:
                continue
            if(Y-(i*10000 + j*5000))  < 0:
                continue
            print(i,j,(Y-(i*10000 + j*5000)) //1000)
            return False
    return True

if solve(N,Y):
    print(-1,-1,-1)

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


def solve(N, Y):
    for i in range(N + 1):
        for j in range(N + 1 - i):
            if (Y - (i * 10000 + j * 5000)) // 1000 != N - i - j:
                continue
            if (Y - (i * 10000 + j * 5000)) // 1000 < 0:
                continue
            print(i, j, (Y - (i * 10000 + j * 5000)) // 1000)
            return False
    return True


if solve(N, Y):
    print(-1, -1, -1)

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

x = 0 
y = 0 
z = 0 
check = 0

for x in range (n + 1) :
  for y in range (n + 1 - x) :
    z = n - x - y
    if check == 1 :
      check = 1
    elif 10000 * x + 5000 * y + 1000 * z == money :
      check += 1
      print(x,y,z)

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

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

x = 0 
y = 0 
z = 0 
check = 0

for x in range (n + 1) :
  for y in range (n + 1 - x) :
    z = n - x - y
    if check == 1 :
      check = 1
    elif 10000 * x + 5000 * y + 1000 * z == money :
      check += 1
      print(x,y,z)

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

Solution (Python):
def otoshidama(N: int, Y: int)->int:
    Y //= 1000

    a0 = (Y-N) % 4
    b0 = ((Y-N) - 9 * a0) // 4

    m_min = max(- a0//4,  -(N-b0)//9)
    m_max = min((N-a0)//4, b0//9)+1

    for m in range(m_min, m_max):
        a = a0 + 4*m
        b = b0 - 9*m
        c = N - a - b

        if a < 0 or N < a:
            continue
        if b < 0 or N < b:
            continue
        if c < 0 or N < c:
            continue

        return (a, b, c)

    return (-1, -1, -1)


if __name__ == "__main__":
    N, Y = map(int, input().split())
    x, y, z = otoshidama(N, Y)
    print(x, y, z)

Solution (Python):
def check_n(n, y):
    num1 = n // 10000 if n // 10000 < y else y
    for i in range(num1 + 1):
        n_second = n - 10000 * i
        num2 = n_second // 5000 if n_second // 5000 < y - i else y - i
        for k in range(num2 + 1):
            n_third = n_second - 5000 * k
            if n_third == 1000 * (y - i - k):
                print(i, k, y - i - k)
                return 0
    return 1

n, y = (int(x) for x in input().split())
if(check_n(y, n)) == 1:
    print(-1, -1, -1)

Solution (Python):
N, Y = [int(i) for i in input().split()]
Y = int(Y/1000)
judge = False
for x in range(N+1):
    if Y-N-9*x < 0 or (Y-N-9*x) % 4 != 0:
        continue
    elif -Y+5*N+5*x < 0 or (-Y+5*N+5*x) % 4 != 0:
        continue
    judge = True
    break
    
if judge == True:
    print(x, int((Y-N-9*x)/4), int((-Y+5*N+5*x)/4))
else:
    print(-1, -1, -1)

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

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


for i in range(n+1):
    if 10000*i + 5000*(n-i) < y:
        continue
    if 10000*i + 1000*(n-i) > y:
        break
    for j in range(n+1-i):
        x = 10000*i + 5000*j + 1000*(n-i-j)
        if x==y:
            print("{} {} {}".format(i, j, n-i-j))
            exit()
print("-1 -1 -1")

Solution (Python):

import sys

def main():
	N, Y = map(int, input().split(" "))
	
	if Y % 1000 > 0:
		print("-1 -1 -1")
		sys.exit()
	
	for i in range(0, N+1):
		for j in range(0, N+1):
			if N < i + j:
				continue
			k = N - i - j
			if i + j + k == N and k >= 0:
				if (i * 10000) + (j * 5000) + (k * 1000) == Y:
					print("{} {} {}".format(i, j, k))
					sys.exit()
					
	print("-1 -1 -1")
	
	
if __name__ == "__main__":
	main()

Solution (Python):
import sys

a = list(map(int,input().split()))
N = a[0]
Y = a[1]
flg = 0
for i in range(N+1):
    remain = N - i
    for j in range(remain + 1):
        if 10000*i + 5000*j + 1000*(remain - j) == Y:
            print(str(i) + " " + str(j) + " " + str(remain-j))
            sys.exit()
print("-1 -1 -1")

Solution (Python):
N,Y = map(int,input().split())
a = Y//1000
z = None
for x in range(N+1):
    tmp = a-N-9*x
    if 0 <= tmp <= 4*N and tmp % 4 == 0:
        y = tmp // 4
        if N-x-y >= 0:
            z = N-x-y
            break
print("{} {} {}".format(x,y,z) if z != None else "-1 -1 -1")

Solution (Python):
n,k=map(int,input().split())
ok=False
for x in range(n+1):
    for y in range(n-x+1):
        z=n-x-y
        if z<0:
            break
        if 10000*x+5000*y+1000*z==k:
            print("{} {} {}".format(x,y,z))
            exit()

print("{} {} {}".format(-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):
        k = n-i-j
        if 10000*i + 5000*j + 1000*k == y and k >=0:
            ans.append([i,j,k])
            break
                
if len(ans) >=1:
    str_ans = map(str, ans[0])
    print(' '.join(str_ans))
if len(ans) == 0:
    print('-1 -1 -1')

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

L = main()
print(L[0], L[1], L[2])

Solution (Python):
n, y = list(map(int, input().split(' ')))
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
for ten_th in range(min(n, int(y / 10000)), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    for five_th in range(min(n - ten_th, int((y - ten_th * 10000) / 5000)), -1, -1):
        if y < ten_th * 10000 + five_th * 5000 or n < ten_th + five_th:
            continue
        if (y - ten_th * 10000 - five_th * 5000) % 1000 == 0:
            th = int((y - ten_th * 10000 - five_th * 5000) / 1000)
            if n == ten_th + five_th + th:
                print('{} {} {}'.format(ten_th, five_th, th))
                exit()
print('-1 -1 -1')

Solution (Python):
N, Y = map(int,input().split())
yukichi,ichiyou,hideyo=-1,-1,-1
N_next,N_2next,Y_next,Y_2next=-1,-1,-1,-1

for i in range(N+1):
    flag = 0
    yukichi = N-i
    N_next = N - yukichi
    Y_next = Y-10000*yukichi
    if Y_next == 0 and N_next==0:
        flag = 1
        ichiyou,hideyo=0,0
    elif Y_next > 0 and N_next>0:
        for j in range(N_next+1):
            ichiyou = N_next-j
            N_2next = N_next - ichiyou
            Y_2next = Y_next-5000*ichiyou
            if Y_2next == 0 and N_2next==0:
                flag=1
                hideyo=0
                break
            elif Y_2next > 0 and N_2next>0:
                hideyo = N_2next
                Y_remain = Y_2next - 1000*hideyo
                if Y_remain == 0:
                    flag=1
                    break
    if flag == 1:
        break
    yukichi,ichiyou,hideyo=-1,-1,-1
print('%d %d %d' %(yukichi,ichiyou,hideyo))

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

Solution (Python):
def solve(n, y):
	tmp1000 = n * 1000
	if tmp1000 > y:		
		return -1, -1, -1
	diff = y - tmp1000		
	
	for y in range(diff // 4000 + 1):
		tmp5000 = y * 4000
		if (diff - tmp5000) % 9000 == 0:	
			x = (diff - tmp5000) // 9000
			if x + y <= n:			
				return x, y, n - x - y
	return -1, -1, -1
    
print(*solve(*map(int, input().split())))

Solution (Python):
n,y = map(int,input().split())
	
for s1 in range(n+1):
	for s2 in range(n-s1+1):
		if y== s1*10000+s2*5000+(n-s1-s2)*1000:
			print("{} {} {}".format(s1,s2,n-s1-s2))
			exit()
else:
	print("{} {} {}".format(-1,-1,-1))

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline()
def read(): return int(input())
def reads(): return [int(i) for i in input().split()]

N, Y = reads()

x_max = min(N, Y//10000)
y_max = min(N, Y//5000)

ans = (-1, -1, -1)

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

print(str(ans[0])+' '+str(ans[1])+' '+str(ans[2]))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline()
def read(): return int(input())
def reads(): return [int(i) for i in input().split()]

N, Y = reads()

x_max = min(N, Y//10000)
y_max = min(N, Y//5000)

ans = (-1, -1, -1)

for x in range(x_max+1):
	for y in range(min(y_max+1, N-x+1)):
		if 10000*x + 5000*y + 1000*(N-x-y) == Y:
			ans = (x, y, N-x-y)
			break

print(str(ans[0])+' '+str(ans[1])+' '+str(ans[2]))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline()
def read(): return int(input())
def reads(): return [int(i) for i in input().split()]

N, Y = reads()

x_max = min(N, Y//10000)
y_max = min(N, Y//5000)

ans = (-1, -1, -1)

for x in range(x_max+1):
	for y in range(min(y_max+1, N-x+1)):
		if 10000*x + 5000*y + 1000*(N-x-y) == Y:
			ans = (x, y, N-x-y)
			break

print(str(ans[0])+' '+str(ans[1])+' '+str(ans[2]))

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

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

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

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

print(a, b, c)

Solution (Python):

n, y = map(int, input().split())
ans = False
x = [0] * 3
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:
            ans = True
            x = [i, j, k]
            break
    if ans:
        break
if ans:
    print("{} {} {}".format(x[0], x[1], x[2]))
else:
    print('-1 -1 -1')

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, Y = map(int, input().split())

    if Y // 10000 > N:
        print('-1 -1 -1')
    else:
        flag = False
        for i in range(Y//10000 + 1):
            for j in range(N-i+1):
                if 10000 * i + 5000 * j + 1000 * (N-i-j) == Y:
                    x, y, z = i, j, N-i-j
                    flag = True
                    break
        if flag:
            print('{} {} {}'.format(x, y, z))
        else:
            print('-1 -1 -1')
    


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
N, Y = map(int,input().split())
a_max = min(N, Y // 10000)
flg = False
for a in range(a_max+1):
    if flg: 
        break
    for b in range(N+1):
        if flg:
            break 
        c = N - a - b
        if a*10000+b*5000+c*1000 == Y and c >= 0:
            print(a,b,c)
            flg = True
if not flg:
    print(-1,-1,-1)

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

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

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

Solution (Python):
inr = lambda: list(map(int, input().split()))

N, Y = inr()

lmn = [-1, -1, -1]

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

print(-1, -1, -1)

Solution (Python):

n, y = [int(x) for x in input().split()]
for i in range(n + 1):
    for g in range(n + 1 - i):
        if 10000 * i + 5000 * g + 1000 * (n - i - g) == y:
            print(i, g, n - i - g)
            exit()
print(-1, -1, -1)

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


if __name__ == "__main__":
    main()

Solution (Python):
N,Y=map(int,input().split())
Y//=1000
for z in range(N+1):
  x=round(-N+0.8*z+0.2*Y,5)
  y=round(-0.2*Y-1.8*z+2*N,5)
  if x.is_integer() and y.is_integer() and x+y+z==N:
    if x>=0 and y>=0:
      if 10*x+5*y+z==Y:
        print(int(x),int(y),int(z))
        exit()
print(-1,-1,-1)

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