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())
answer=-1,-1,-1
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            answer=x,y,z
            break
    else:
        continue
    break
print(*answer)

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

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

print(-1, -1, -1)

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

man = y//10000

ans = 0
for i in range(man+1):
  mansatsu = i*10000
  for j in range(n-i+1):
    temp = mansatsu + j*5000
    if y - temp == 1000*(n-(i+j)):
      print(i,j,n-(i+j))
      ans = 1
      break
  else:
    continue
  break
if ans == 0:
  print("-1 -1 -1")

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

man = y//10000

ans = 0
for i in range(man+1):
  mansatsu = i*10000
  for j in range(n-i+1):
    temp = mansatsu + j*5000
    if y - temp == 1000*(n-(i+j)):
      print(i,j,n-(i+j))
      ans = 1
      break
  else:
    continue
  break
if ans == 0:
  print("-1 -1 -1")

Solution (Python):
import sys

n, y = map(int, sys.stdin.readline().split())
y //= 1000; y -= n

def main():
    for i in range(n + 1):
        if 9 * i > y: break
        if (y - 9 * i) % 4: continue
        j = (y - 9 * i) // 4
        if (i + j > n): continue
        k = n - i - j
        print(i, j, k)
        return
    print(-1, -1, -1)

if __name__ ==  '__main__':
    main()

Solution (Python):
import sys

n, y = map(int, sys.stdin.readline().split())
y //= 1000

def main():
    for i in range(n + 1):
        if 10 * i > y: break
        for j in range(n - i + 1):
            k = n - i - j
            if 10 * i + 5 * j + k == y:
                print(i, j, k)
                return
    print(-1, -1, -1)


if __name__ ==  '__main__':
    main()

Solution (Python):

import sys

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

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

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

for sen in range(N+1):
    for gosen in range(N+1-sen):
        ichiman=N-sen-gosen
        if(sen*1000+gosen*5000+ichiman*10000==Y):
            print(ichiman,gosen,sen)
            exit()

print(-1,-1,-1)

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

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

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

result = (-1, -1, -1)
for x in range(N + 1):
    for y in range(N + 1):
        if x + y > N:
            break
        if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
            result = (x, y, N - x - y)
print("{} {} {}".format(result[0], result[1], result[2]))

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


ans=[-1,-1,-1]
q1=min(Y//10000,N)
for i in range(q1+1):
    r1=Y-10000*i
    q2=min(r1//5000,N-i)
    for j in range(q2+1):
        r2=r1-5000*j
        
        if r2==1000*(N-i-j):
            check=1
            ans[0]=i
            ans[1]=j
            ans[2]=N-i-j
            break
    else:
        continue
    break

print(*ans)

Solution (Python):

def get_combi():

	for x in range(N + 1):
		for y in range(N + 1):
			if x + y > N:
				break
			else:
				z = N - x - y
				if 10000 * x + 5000 * y + 1000 * z == Y:	
					return x, y, z
	
	return -1, -1, -1


N, Y = map(int, input().split())
x, y, z = get_combi()

print(x, y, z)

Solution (Python):
import sys

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

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

for i in range(n+1):
    for j in range(n+1):
        k = n - i - j
        if (k >= 0):
            if (y == i * 10000 + j * 5000 + k * 1000):
                ans = str(i) + " " + str(j) + " " + str(k)

print(ans)

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

for i in range(Y//10000 + 1):
  for j in range((Y - i * 10000)//5000 + 1):
    if Y - i*10000 - j*5000 == (N - i - j)*1000:
      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())

x_ans = -1
y_ans = -1
z_ans = -1
flg = 0

for x in range(N+1):
    for y in range(N+1-x):
        otoshidama = 10000*x + 5000*y + 1000*(N-x-y)
        if otoshidama == Y :
            flg = 1
            x_ans = x
            y_ans = y
            z_ans = N-x-y
print(x_ans, y_ans, z_ans)

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

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

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

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

Solution (Python):
N,Y = [int(x) for x in input().split()]
Y = Y // 1000
for y in range(N+1):
  if (Y - N - 4*y) % 9 != 0:
    continue
  x = int((Y - N - 4*y) / 9)
  z = N - y - x
  if 0 <= x and 0 <= z and x <= N and z <= N:
    print(x,y,z)
    exit()
print("-1 -1 -1")

Solution (Python):


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,y = readInts()
    wa = 0

    for i in range(n+1):
        for j in range(n+1):
            if i+j > n:
                break
            y1000 = (y - 10000 * i - 5000 * j)//1000
            if i + j + y1000 == n:
                print(i,j,y1000)
                exit()
    print(-1,-1,-1)
    exit()


if __name__ == '__main__':
  main()

Solution (Python):
from itertools import *
N,Y = map(int,input().split())
if 10000*N < Y:
  print(-1,-1,-1)
  exit()
for i in range(N):
  for j in range(N-i):
    k = N-i-j
    for xyz in permutations([i,j,k],3):
      x,y,z = xyz
      if 10000*x + 5000*y + 1000*z == Y:
        print(x,y,z)
        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 + 1 - i):
        k = n - i - j
        price = (i * 10**4) + (j * 5 * 10**3) + (k * 10**3)
        if price == y:
            print(i, j, k)
            sys.exit()
        elif y < price:
            break

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

Solution (Python):
N,Y= map(int,input().split())
for i in range(N+1):
    for j in range(N+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 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('{} {} {}'.format(a,b,c))
      exit()
print('-1 -1 -1')

Solution (Python):
n, y = map(int, input().split())
ans = [-1, -1, -1]
flg = False

for i in range(0, n+1):
    if flg == True:
        break
    for j in range(0, n+1):
        if flg == True:
            break
        if n-i-j < 0:
            break
        if (10000*i + 5000*j + 1000*(n-i-j)) == y:
            ans = [i, j, (n-i-j)]
            flg = True

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

Solution (Python):
a,b=map(int,input().split())
t=b/1000
List=[-1,-1,-1]
for l in range(a+1):
    if (t-9*l-a)%4==0 and a-l-(t-9*l-a)/4>=0 and t-9*l-a>=0:
        s=int((t-9*l-a)/4)
        List=[l,s,a-l-s]
        break
print(*List)

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

count = 0
x, y, z = -1, -1, -1

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

print(x, y, z)

Solution (Python):
n, y = map(int,input().split())
a=-1
b=-1
c=-1
for i in range(n+1):
    for j in range(n+1-i):
        total = i*10000+j*5000+(n-i-j)*1000
        if total==y:
            a=i
            b=j
            c=n-i-j
            
            
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 0 <= z <= 2000 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())
huku = y//10000
higuchi = y // 5000
flag = False
for i in range(huku+1):
    for j in range(higuchi+1):
        nokori = y - (10000*i + 5000*j)
        if nokori < 0:
            break
        l = nokori // 1000
        
        if i+j+l == n:
            if 10000*i + 5000*j + 1000*l==y:
                flag = True
                ans1 = i
                ans2 = j
                ans3 = l
                

if flag ==True:
    print(ans1,ans2,ans3)
else:
    print("-1 -1 -1")

Solution (Python):
from sys import stdin







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

def func1(N,Y):
    for i in range(N+1):
        price_man = i*10000
        price_rest = Y-price_man
        if price_rest<0:
            break
        if price_rest>5000*(N-i):
            continue
        for j in range(N-i+1):
            if price_rest== 5000*j + 1000*(N-i-j):
                return [i, j, N-j-i]
    return [-1, -1, -1]

output = func1(N,Y)
print(output[0],output[1],output[2])

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

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

Solution (Python):
N,y = [int(x) for x in input().split()]
y = y // 1000
for i in range(y//5+1):
  nokori = i*5
  kosuu = y - i*5
  if kosuu > N:
    continue
  if kosuu == N and nokori == 0:
    print("0 0 " + str(y-i*5))
    exit()
  for j in range(nokori//10+1): 
    if kosuu + j + (nokori-10*j)//5 == N:
      print(str(j)+" "+str((nokori-10*j)//5)+" "+str(y-i*5))
      exit()
print("-1 -1 -1")

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

a = -1
b = -1
c = -1
for i in range(N+1):
    for j in range(N+1):
        total = 10000*i + 5000*j + 1000*(N-i-j)
        if total == Y and N-i-j >= 0:
            a = i
            b = j
            c = N-i-j
            break
print("{} {} {}".format(a,b,c))

Solution (Python):






def main():
    N, Y = map(int, input().split())
    y = Y // 1000

    for b in range(N+1):
        if (y-N-4*b) >= 0 and (y-N-4*b) % 9 == 0:
            c = (y-N-4*b) // 9
            a = N - b - c
            if a >= 0:
                return "{} {} {}".format(c, b, a)

    return "-1 -1 -1"


print(main())

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

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

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

Solution (Python):
N, Y = map(int, input().split())
res10000 =res5000 = res1000 = -1

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:
            res10000 = x
            res5000 = y
            res1000 = z

print(res10000, res5000, res1000)

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

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

Solution (Python):
def main():
    n, y = map(int, input().split())
    ans = [-1, -1, -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 = [i, j, n-i-j]
    print(*ans)

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
if __name__ == "__main__":
    N, Y = 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
            y = 10000 * i + 5000 * j + 1000 * k
            if y == Y:
                ans = [i, j, k]
    print("{} {} {}".format(ans[0], ans[1], ans[2]))

Solution (Python):
n,y=map(int,input().split())
y=y//1000
if y<n or 10*n<y:
    print(-1,-1,-1)
else:
    for i in range((y-n)//9+1):
        if (y-n-9*i)%4==0:
            a=i
            b=(y-n-9*i)//4
            if n-a-b>=0:
                print(a,b,n-a-b)
                break
    else:
        print(-1,-1,-1)

Solution (Python):
import numpy as np
import sys

input = sys.stdin.readline

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

諭吉 = 10000
樋口 = 5000
野口 = 1000

for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if z >= 0:
            if  Y == ( 諭吉*x + 樋口*y + 野口*z):
                print("{0} {1} {2}".format(x,y,z))
                exit()

        else: continue

print("-1 -1 -1")

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-i+1):
        if 10000*i + 5000*j + 1000*(max(N-i-j, 0)) == Y:
            x = i
            y = j
            z = N - (i+j)
            break

print(x, y, z)

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):
        if i+j <= N:
            if 10000*i + 5000*j + 1000*(max(N-i-j, 0)) == Y:
                x = i
                y = j
                z = N - (i+j)
                break

print(x, y, z)

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

for i in range(n+1):
  for j in range(0, n-i+1):
    if 10000*i + 5000*j + 1000*(n-i-j) == a:
      x = i
      y = j
      z = n-i-j
      flag = 1
      break
      
if flag == 1:
  print(x, y, z)
else:
  print(-1,-1,-1)

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

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

print(-1, -1, -1)

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, Y: int):
    for nm in range(Y // 10000 + 1):
        N2 = N - nm
        Y2 = Y - nm * 10000
        
        
        ng = (Y2 // 1000 - N2) // 4
        ns = N2 - ng
        if ng < 0 or ns < 0:
            continue
        if ng * 5000 + ns * 1000 != Y2:
            continue
        print(nm, ng, ns)
        return
    print(-1, -1, -1)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)


if __name__ == '__main__':
    main()

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

max_10, _ = divmod(Y, 10000)
max_5, _ = divmod(Y, 5000)
max_1, _ = divmod(Y, 1000)

for i in range(min(max_10 + 1, N + 1)):
    for j in range(min(max_5 + 1, N + 1)):
        k = N - i - j
        if 10000 * i + 5000 * j + 1000 * k == Y and k >= 0 and k <= N:
            print(i, j, k)
            exit()
print(-1, -1, -1)

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

answer = (-1, -1, -1)

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:
            answer = (x, y, z)
            break

print(*answer)

Solution (Python):

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

ans = 0
flag = False
for a in range(n+1):
    for b in range(n+1-a):
            if y == 10000*a+5000*b+1000*(n-a-b):
                print(a,b,n-a-b)
                ans = 100
                flag = True
            else:
                continue
    if flag:
      break
                
if ans == 0:
    print(-1,-1,-1)

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

Solution (Python):
import itertools as itr

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

	for a, b in itr.product(range(N+1), repeat = 2):
		c = N - a - b
		if c >= 0 and 10000*a + 5000*b + 1000*c == Y:
			print(str(a) + " " + str(b) + " " + str(c))
			return
	print("-1 -1 -1")
	return


main()

Solution (Python):


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

a = 0




for i in range(N+1):

    
    
    
    
    for ii in range(N+1 - i):

        
        
        
        
        iii = N - i - ii

        
        
        
        
        
        if iii < 0:
            break

        
        
        ans = 10000 * i + 5000 * ii + 1000 * iii
        if ans == Y:
                print(i,ii,iii)
                a += 1
                break

    if a != 0:
        break

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

Solution (Python):
import sys
n,y = map(int, input().split())
count = 0
for i in range(0,n+1):
    for j in range(0,n-i+1):
        a = 10000*i + 5000*j + 1000*(n-i-j)
        if (a == y):
            ans = [i,j,n-i-j]
            print(*ans)
            sys.exit()
ans = [-1,-1,-1]
print(*ans)

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

flg=0
x=-1
y=-1
z=-1
for i in range(n+1):
    for j in range(n+1-i):
        total = 10000*i+5000*j+1000*(n-i-j)
        
        if total==y_in:
            x=i
            y=j
            z=n-i-j

print(x,y,z)

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

m10 = y // 10000
m5 = 0
m1 = 0

if m10 > n:
    m10 = n

y0 = y - 10000 * m10

def calc(y, n, m10):
    for i in range(n + 1):
        j = n - m10 - i
        if j < 0:
            continue

        if y == (5000 * i + 1000 * j) \
            and n == m10 + i + j:
            return i, j
    return -1, -1
  
while m10 >= 0:
    m5, m1 = calc(y0, n, m10)
    if m5 == m1 == -1:
        m10 -= 1
        y0 += 10000
    else:
        break
print(m10, m5, m1)

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

if 10000*N < Y:
    print(-1,-1,-1)

else:
    A = Y//10000

    end = 0

    for i in range(A+1):
        a = Y-10000*(A-i)
        B = a//5000
        for j in range(B+1):
            b = a - 5000*(B-j)
            n = N - (A-i) - (B-j)
            if b == 1000*n:
                print(A-i,B-j,n)
                end += 1
                break
        if end == 1:
            break
        if i == A:
            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 i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            flag = True
    if flag == True:
        break
if flag == False:
    print("-1 -1 -1")

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

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

a = 0

for i in range(N+1):

    for ii in range(N+1):

        iii = N - i - ii

        if iii < 0:
            break
        ans = 10000 * i + 5000 * ii + 1000 * iii
        if ans == Y:
                print(i,ii,iii)
                a += 1
                break

    if a != 0:
        break

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

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

a = 0

for i in range(N+1):

    for ii in range(N+1 - i):

        iii = N - i - ii
        ans = 10000 * i + 5000 * ii + 1000 * iii
        if ans == Y:
                print(i,ii,iii)
                a += 1
                break

    if a != 0:
        break

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

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

a = 0

for i in range(N+1):

    for ii in range(N+1 - i):

        iii = N - i - ii

        ans = 10000 * i + 5000 * ii + 1000 * iii
        if ans == Y:
                print(i,ii,iii)
                a += 1
                break

    if a != 0:
        break

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

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

a = 0

for i in range(N+1):
    for ii in range(N+1):
        iii = N - i - ii
        if iii < 0:
            break
        ans = 10000 * i + 5000 * ii + 1000 * iii
        if ans == Y:
                print(i,ii,iii)
                a += 1
                break

        
        
        
        
        
        
        
        
        
    if a != 0:
        break

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

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

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

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

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

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

print("-1 -1 -1")

Solution (Python):
n,y = map(int,input().split())
for i in range(n+1):
    if (y-1000*n-9000*i) % 4000 == 0:
        b = (y-1000*n-9000*i) // 4000
        if b >= 0 and n >= i+b >= 0:
            print(i,b,n-i-b)
            exit()
print(-1,-1,-1)

Solution (Python):
N,Y=map(int,input().split())
L=[[h,i,N-h-i] for h in range(N+1) for i in range(N+1) if h*1000+i*5000+(N-h-i)*10000==Y and (N-h-i)>=0]

if len(L)>0:
    print(L[0][2],L[0][1],L[0][0])
else:
    print(-1,-1,-1)

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

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

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

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

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

Solution (Python):
N,Y=map(int,input().split())
a=-1
b=-1
c=-1
total=0
for i in range(N+1):
    for n in range((N+1)-i):
        c1=N-i-n
        total=10000*i+5000*n+1000*c1
        if total==Y:
            a=i
            b=n
            c=c1
            print('{} {} {}'.format(a,b,c))
            exit()
print('{} {} {}'.format(a,b,c))

Solution (Python):
n, y = map(int, input().split())
a = -1
b = -1
c = -1
for i in range(n+1):
    for j in range(n+1-i):
        k = n-i-j
        if pow(10, 4)*i + 5000*j + 1000*k == y:
            a = i
            b = j
            c = k
            break

print(a, b, c)

Solution (Python):
x=input().split(" ")
n=int(x[0])
s=int(x[1])
number_list=[]
for i in range(n+1):
    for j in range(n-i+1):
        sum=10000*i+5000*j+1000*(n-i-j)
        
        number_list.append(sum)
        if sum==s:
            print(str(i)+" "+str(j)+" "+str(n-i-j))
            break
    else:
        continue
    break
if s not in number_list:
    print(str(-1)+" "+str(-1)+" "+str(-1))

Solution (Python):
N,Y = map(int,input().split())
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)
            exit()
print(-1,-1,-1)

Solution (Python):
n , a = map(int, input().split())
num = 5000*n
ans = [0, n, 0]

def find(num):
    for _ in range(n+1):
        if num < a:
            ans[0] += 1
            ans[1] -= 1
            num += 5000
        elif num > a:
            ans[1] -= 1
            ans[2] += 1
            num -= 4000
        elif num == a:
            return ' '.join(map(str, ans))
    return '-1 -1 -1'

print(find(num))

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

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

Solution (Python):
n, a = map(int, input().split())
x = y = z = -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 == a:
            x, y, z = i, j, k
print('{} {} {}'.format(x,y,z))

Solution (Python):

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

if y/n > 10000:
  print('-1 -1 -1')
  exit()
elif y < n*1000:
  print('-1 -1 -1')
  exit()
else:
  for a in range(y//10000 +1):
    for b in range(y//5000 +1):
      if n-a-b >= 0:
        if 10*a + 5*b + (n-a-b) == (y/1000):
          print(*[a,b,n-a-b])
          exit()

print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split(" "))
 
A = -1
B = -1
C = -1
 
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 and 0 <= c:
      A = a
      B = b
      C = c
      
print(A, B, C)

Solution (Python):
n, y = map(int, input().split())
count = 5000*n
work = [0, n, 0]
for i in range(n):
    if y > count:
        count += 5000
        work[0] += 1
        work[1] -= 1
    elif y < count:
        work[2] += 1
        work[1] -= 1
        count -= 4000
    else:
        break
if y == count:
    print(" ".join(map(str, work)))
else:
    print("-1 -1 -1")

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

Solution (Python):
n, y = map(int, input().split())
 
flagCount = 0
 
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:
            flagCount += 1
            if flagCount == 1:
                print(i, j, k)
            
 
if flagCount == 0:
    print(-1, -1, -1)

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

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

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

a, b, c = -1, -1, -1
flag = False
for i in range(N+1):
    if flag:
        break

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

print("{} {} {}".format(a,b,c))

Solution (Python):
import sys
f = 1
n,y = map(int,input().split())
for s in range(2001):
    for t in range(2001):
        z = n-s-t
        if y-(10000*s+5000*t+1000*z) == 0 and z >= 0 :
            print(s,t,z)
            f = 0
            sys.exit()
if f == 1:
    print(-1,-1,-1)

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

Solution (Python):
N,Y=map(int,input().split())
ans=[-1,-1,-1]
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:
            ans=[i,j,k]
            break
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 - 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 i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        sum = i*10000 + j*5000 + k*1000
        if sum == y:
            print(i, j, k)
            exit()
print(-1, -1, -1)