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

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

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

fun(n, y)

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

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

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

fun(n, y)

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):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y and z >= 0:
            result = '{} {} {}'.format(x, y, z)
            break

print(result)

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

L=[-1,-1,-1]
for i in range(0,min(Y//10000,N)+1):
  for j in range(0,N-i+1):
    if i*10000+j*5000+(N-i-j)*1000==Y:
      L=[i,j,N-i-j]
      break

print(*L)

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

for x in range(N, -1, -1):
    for y in range(N-x, -1, -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())
A = B = 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:
            A = a
            B = b
            C = c
            
print(A, B, C)

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

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

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

found = False
for i in range(N+1):
    for j in range(N-i+1):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y:
            ex_x, ex_y, ex_z = i, j, N-i-j
            found = True
            break
            
if not found:
    print(-1, -1, -1)
else:
    print(ex_x, ex_y, ex_z)

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

upper10k = int(Y/10000)
sum10k = 0
num10k, num5k, num1k = [-1,-1,-1]
for i in range(upper10k, -1,-1) :
	restSheet = N - i
	sum10k = i * 10000
	if (Y - sum10k) > (restSheet * 5000) :
		break
	upper5k = min([int((Y-sum10k)/5000), restSheet])
	for j in range(upper5k, -1, -1) :
		total10k5k = sum10k + 5000 * j
		if (Y - total10k5k) > ( (restSheet-j) * 1000) :
			break
		if (Y - total10k5k) == ( (restSheet-j) * 1000) :
			num10k, num5k, num1k = [i,j,restSheet-j]
			break
	if ( num10k != -1 ) and ( num5k != -1 ) and ( num1k != -1 ) :
		break
print("{} {} {}".format(num10k,num5k, num1k))

Solution (Python):


import io
nim, mike = map(int, input().split())
for i in range(nim + 1):
    for j in range(nim - i + 1):
        if i * 10000 + j * 5000 + (nim - i - j) * 1000 == mike:
            print(i, j, nim - i - j)
            exit()
print("-1 -1 -1")

Solution (Python):
def solve(N, Y):
    
    flag = False
    
    
    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:
                flag = True
                print(x, y, z)
                break
                
        if flag:
            break
                
    if flag == False:
        print(-1, -1, -1)

if __name__ == '__main__':
    N, Y = map(int, input().split())
    solve(N, Y)

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

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)
      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+1-x):
        z = N-x-y
        if 10000*x + 5000*y + 1000*z == Y and x+y+z==N:
                print(x,y,z)
                flag = True
                break
    if flag:
        break
else:
    print('-1 -1 -1')

Solution (Python):
n,y = map(int,input().split())
yukichi=-1
ichiyo=-1
hideo=-1
for yi in range(n+1):
  for ii in range(n-yi+1):
    hi = n-(yi+ii)
    if (yi*10000)+(ii*5000)+(hi*1000)==y:
      yukichi,ichiyo,hideo=yi,ii,hi
print(yukichi,ichiyo,hideo)

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

ans = []

for i in range(n+1):
    for j in range(n+1-i):
        val = 1000 * i + 5000 * j + 10000 * (n-i-j)
        if val == y:
            ans.append(n-i-j)
            ans.append(j)
            ans.append(i)
            break

if ans:
    print(*ans[0:3])
else:
    print(-1,-1,-1)

Solution (Python):
from sys import stdin
import sys

(N, Y) = stdin.readline().rstrip().split()

N = int(N)
Y = int(Y)














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

print('-1 -1 -1')

Solution (Python):
n,y = (int(x) for x in input().split())
sol = False
for i in range(n+1):
    bb = (y - 10000*i) - 1000*(n-i)
    a = i
    if bb % 4000 == 0 and bb >= 0:
        b = bb // 4000
        c = n - i - b
        if c >= 0:
            sol = True
            break
if not sol:
    print('-1 -1 -1')
else:
    print(a,b,c)

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

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

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

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

Solution (Python):
import sys
N, Y = map(int, input().split())
for i in range(0, min(N, Y//10000) + 1):
    for j in range(0, min(N-i, Y//5000) + 1):
        for k in range(N-i-j, min(N-i-j, Y//1000) + 1):
            if i*10000 + j*5000 + k*1000 == Y and i+j+k == N:
                print(i, j, k)
                sys.exit()
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(n+1-i):
        if y == 10000*i + 5000*j + 1000*(n-i-j):
            print(str(i) + " " + str(j) + " " + str(n-i-j))
            exit()

print("-1 -1 -1")

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    for n10 in range(n + 1):
        rest = n - n10
        for n5 in range(rest + 1):
            n1 = rest - n5
            m = n10 * 10000 + n5 * 5000 + n1 * 1000
            if m == y:
                print(n10, n5, n1)
                sys.exit()

    print(-1, -1, -1)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
n,S = map(int,input().split())
s=S // 1000
a= int(s//10)
m=0

for x in range(a+1):
    b = int((s-10*x)//5)
    for y in range(b+1):
        if 10*x + 5*y + (n-x-y) == s:   

            print(x,y,n-x-y)
            m=1
            break
    if m==1:
        break
        

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

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

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

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

if ans is not None:
    print(' '.join(map(str, ans)))
else:
    print(-1, -1, -1)

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

q = -1
w = -1
r = -1

for a in range(N + 1):
    for b in range(N + 1 - a):
        c = N - a - b
        total = 10000*a + 5000*b + 1000*c
        if total == Y:
            q = a
            w = b
            r = c

print('{} {} {}'.format(q, w, r))

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

for i in range(N+1):
    for j in range(N+1-i):
        z=N-i-j
        if(Y/1000-10*i-5*j)==z:
            print(i, j, z)
            exit(0)
print('-1 -1 -1')

Solution (Python):
N,Y=map(int,input().split())
Y=Y/1000
c=0
for a in range(int(Y//10)+1):
  for b in range(int((Y - 10*a)//5)+1):
    if a*10+b*5+(N-a-b)*1==Y:
      print(a,b,N-a-b)
      c=1
      break
  if c==1:
    break
if c==0:
  print(-1,-1,-1)

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

if l==1:
  print(i,j,k)
else:
  print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
a,b,c=-1,-1,-1
f=0
for i in range(n+1):
    if f==1:
        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
            f=1
print(a,b,c)

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-i):
        if (i*10000 + j*5000 + (n-i-j)*1000) == y:
            a=i
            b=j
            c=n-i-j
print(a,b,c)

Solution (Python):
import sys
input=sys.stdin.readline
















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

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


F=0
Y=Y/1000
for i in range(N+1):
    for j in range(N+1-i):
        if (Y-10*i-5*j)==(N-i-j):
            print(i,j,N-i-j)
            F=1
        else:
            continue
    if F==1:break
    

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

Solution (Python):
import sys

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

    for n in range(Y//10000+1):
        for m in range((Y-n*10000)//5000+1):
            l = N - n - m
            if l >= 0 and n*10000 + m*5000 + l*1000 == Y:
                print(n, m, l)
                return
    
    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

    for n in range(Y//10000+1):
        for m in range((Y-n*10000)//5000+1):
            l = N - n - m
            if l >= 0 and n*10000 + m*5000 + l*1000 == Y:
                print(n, m, l)
                return
    
    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
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])
            sys.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):
        k = n-i-j
        if 10000 * i + 5000*j + 1000*k == y:
            print("{} {} {}".format(i, j, k))
            exit()
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-i+1):
        k = n - i - j
        if i * 10 + j * 5 + k == y / 1000:
            ans = [i, j, k]
            print(i, j, k)
            exit()
ans = [str(a) for a in ans]
print(' '.join(ans))

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 i * 10 + j * 5 + k == y / 1000:
            ans = [i, j, k]
ans = [str(a) for a in ans]
print(' '.join(ans))

Solution (Python):
n, Y = map(int, input().split())
Y //= 1000

for x in range(n+1):
    y = (Y-n-9*x)//4
    z = n-x-y
    if z < 0 or y < 0 or x+y+z != n:
        continue
    if 10*x+5*y+z == Y:
        print(x, y, z)
        exit()
else:
    print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
num_1000 = -1
num_5000 = -1
num_10000 = -1

for i in range(N + 1):
    for j in range(N + 1):
        if i + j > N:
            continue
        k = N - i - j
        if 10000 * i + 5000 * j + 1000 * k == Y:
            num_1000 = i
            num_5000 = j
            num_10000 = k
            break

print(num_1000, num_5000, num_10000)

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,y,z=-1,-1,-1
for i in range(n+1):
    total=10000*i
    for j in range(n-i+1):
        total2=total+5000*j
        if n-(i+j)==(Y-total2)//1000:
            x,y,z=i,j,n-(i+j)
            break
        
print(str(x)+" "+str(y)+" "+str(z))

Solution (Python):
n,y=map(int,input().split())
res10000=-1
res5000=-1
res1000=-1
for a in range(n+1):
  for b in range(n+1-a):
    if 10000*a+5000*b+1000*(n-a-b) == y:
      res10000=a
      res5000=b
      res1000=n-a-b

print(res10000, res5000, res1000)

Solution (Python):
class Otoshidama():
    def calculate(self, N, Y):
        for a in range(N+1):
            for b in range(N+1):
                c = N - a -b
                if c < 0:
                    break
                res = 10000 * a + 5000 * b + 1000 * c
                if Y == res:
                    print("{} {} {}".format(a,b,c))
                    return
        print("-1 -1 -1")

if __name__ == '__main__':
    N, Y = map(int, input().split())
    o = Otoshidama()
    o.calculate(N, Y)

Solution (Python):
n, Y = map(int, input().split())
Y //= 1000

for x in range(n+1):
    y = (Y-n-9*x)//4
    z = n-x-y
    if z < 0 or y < 0 or x+y+z != n:
        continue
    if 10*x+5*y+z == Y:
        print(x, y, z)
        exit()
else:
    print(-1, -1, -1)

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

Solution (Python):
n, Y = map(int, input().split())
a = 10000
b = 5000
c = 1000

for x in range(n+1):
    for y in range(n+1):
        z = n-x-y
        if z < 0:
            continue
        if a*x+b*y+c*z == Y:
            print(x, y, z)
            exit()
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):
    if 10000*n - 5000*i - 9000*j == y and n-i-j>=0:
      print(n-i-j, 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 - 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())
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())
x , y , z = '-1' , '-1' , '-1'

def check(num,total):
  for i in range(num+1):
    for j in range(num+1):
      k = num - i - j
      if (k >= 0) and (i + j + k == num) and (10000 * i + 5000 * j + 1000 * k == total):
        x , y , z = str(i) , str(j) , str(k)
        return x + ' ' + y + ' ' + z
res = check(n,Y)
if res is None:
  res = x + ' ' + y + ' ' + z
print(res)

Solution (Python):


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

    for a in range(N+1):
        for b in range(N+1-a):
            c = N-a-b
            if (a*10000 + b*5000 + c*1000) == Y:
                print(str(a)+ " " + str(b) + " " + str(c))
                return
    print("-1 -1 -1")

if __name__ == "__main__":
    main()

Solution (Python):
N, Y = map(int, input().split())
ans = 0
a = 0
b = 0
c = 0
flag = False
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 = 1
            x = a
            y = b
            z = c
            flag = True
            break
    if flag:
        break
if ans == 1:
    print(x,y,z)
else:
    print( '-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
ans = 0
a = 0
b = 0
c = 0
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 = 1
            x = a
            y = b
            z = c
            break
    else:
        continue
    break
if ans == 1:
    print(x,y,z)
else:
    print( '-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
ans = 0
a = 0
b = 0
c = 0
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 = 1
            x = a
            y = b
            z = c
            break
if ans == 1:
    print(x,y,z)
else:
    print( '-1 -1 -1')

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

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

Y //= 1000
a = b = c = -1

for i in range(N+1):
    for j in range(N+1):
        if (N-i-j) >= 0 and 9*i+4*j+N == Y:
            a = i
            b = j
            c = N-i-j
            break
    else:
        continue
    break

print(a, b, c)

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

Y /= 1000

a = 0
b = 0
c = 0

for i in range(N+1):
    for j in range(N-i+1):
        if 9*i + 4*j + N == Y:
            a = i
            b = j
            c = N - i - j
            break

if a != 0 or b != 0 or c != 0:
    print(a,b,c)
else:
    print(-1,-1,-1)

Solution (Python):
import itertools

N, Y = (int(x) for x in input().split())
for x, y in itertools.product(range(N+1), range(N+1)):
  z = N - x - y
  if 0 <= z and 10000*x + 5000*y + 1000*z == Y:
    print('{} {} {}'.format(x, y, z))
    break
if not(x + y + z == N and 10000*x + 5000*y + 1000*z == Y):      
  print('-1 -1 -1')

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

Solution (Python):
n,y=map(int,input().split())
y//=1000
for ten in range(n+1):
  for five in range(n-ten+1):
    one=n-ten-five
    if ten*10+five*5+one==y:
      print(ten,five,one)
      exit(0)
print(-1,-1,-1)

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

Solution (Python):
n, y = map(int,input().split())
for a in range(n+1):
  for b in range(n+1-a):
    if 9000*a+4000*b+1000*n == y:
      print(a,b,n-a-b)
      break
    elif a == n:
      print(-1,-1,-1)
      break
  else:
     continue
  break

Solution (Python):
import itertools

def readInt():
    return list(map(int, input().split()))

ans = False
n,y = readInt()
l = []

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

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

breakRoop = False

for z in range(N+1):
  for y in range(N+1-z):
    x = N-z-y
    total = x*10000 + y*5000 + z*1000
    if total == Y:
      print(x, y, z)
      breakRoop = True
      break
  if breakRoop:
    break

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

Solution (Python):
n,y=map(int,input().split())
ans=[]
flag=False
for i in range(0,n+1):
  for j in range(0,n+1):
    if (9000*i+4000*j)==(y-1000*n) and n>=(i+j):
      ans=[i,j,n-i-j]
      flag=True
      break
if flag:
  print(*ans)
else:
  print(-1,-1,-1)

Solution (Python):
def resolve():
    N, Y = map(int, input().split())
    if Y % 1000 != 0 or Y > 10000 * N:
        print("-1 -1 -1")
        return
    Y //= 1000
    for x in range(Y // 10 + 1):
        for y in range((Y - x * 10) // 5 + 1):
            if N - x - y == Y - x * 10 - y * 5:
                print(x, y, N - x - y)
                return
    print("-1 -1 -1")


if __name__ == "__main__":
    resolve()

Solution (Python):
def main():
    N, Y = map(int, input().split())
    if Y == 10000 * N:
        print(N, 0, 0)
        return

    for i in range(N+1):
        tmp = 0
        tmp += 10000 * i
        for j in range(N-i+1):
            _tmp = tmp
            _tmp += 5000 * j
            if (Y - _tmp > 0 and (Y-_tmp) == 1000 * (N-i-j)) or (Y == _tmp and i + j == N):
                print(i, j, N-i-j)
                return

    print(-1, -1, -1)

if __name__ == "__main__":
    main()

Solution (Python):
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N-i+1):
        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(Y//10**4 + 1):
    for b in range(min((Y-10**4*a) // 5*10**3 + 1, N-a+1)):
        c = N - a - b
        if 10**4*a + 5*10**3*b + 10**3*c == Y:
            print(" ".join(list(map(str, [a, b, c]))))
            exit()

print("-1 -1 -1")

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

y=y/1000
c=y-n

if c<0 or 10*n<y: 
    print(-1, -1, -1)
else:
    X=-1
    Y=-1
    Z=-1
    for x in range(n+1):
        for y in range(n+1):
            if x+y>n:
                break
            if 9*x+4*y==c:
                X=x
                Y=y
                Z=n-x-y
                break
        if X>=0: break
    print(X, Y, Z)

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

y=y/1000
c=y-n

if c<0 or 10*n<y: 
    print(-1, -1, -1)
else:
    X=-1
    Y=-1
    Z=-1
    for x in range(n+1):
        for y in range(n+1):
            if x+y>n:
                break
            if 9*x+4*y==c:
                X=x
                Y=y
                Z=n-x-y
                break
        if X>=0: break
    print(X, Y, Z)

Solution (Python):
N,Y = map(int,(input().split()))
r = Y - N*1000
if r < 0:
    print(-1,-1,-1)
else:
    for i in range(N+1): 
        for j in range(N+1-i): 
            if i*4000 + j*9000 == r:
                print(j,i,N-i-j)
                break
        else:
            continue
        break
    else:
        print(-1,-1,-1)

Solution (Python):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,Y = MI()

for i in range(N+1):
    for j in range(N+1-i):
        k = N-i-j if N-i-j>=1 else 0
        total = 10000*i + 5000*j + 1000*k
        if total == Y:
            print(i,j,k)
            break
    else:
        continue
    break
else:
    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 - i + 1):
        k = n - i - j
        if y == (i * 10000) + (j * 5000) + (k * 1000):
            ans = i, j, k
            print(*ans)
            exit(0)
print(*ans)

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

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

ans=''
for m in range(n+1):
    for g in range(n+1-m):
        if y - 10*m - 5*g == n-m-g:
            ans=str(m)+' '+str(g)+' '+str(n-m-g)
            break
    if ans!='':
        break

print(ans if ans!='' else '-1 -1 -1')

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

Solution (Python):
def solve():
    a=-1;b=-1;c=-1
    n,Y=map(int, input().split())
    for x in range(n+1):
        for y in range(n+1):
            if 10000*x+5000*y+1000*(n-x-y)==Y and 0<=n-x-y<=n:
                a,b,c= [x,y,n-x-y]
    return a,b,c

a,b,c=solve()
print(a,b,c)

Solution (Python):
def resolve():
    N, Y = list(map(int, input().split(" ")))
    for i in range(N+1):
        for j in range(N-i+1):
            k = N - i - j
            total = 10000*i + 5000*j + 1000*k
            if total == Y:
                print("{} {} {}".format(i, j, k))
                return
    print("-1 -1 -1")



if '__main__' == __name__:
    resolve()

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

answer_pattern = ["-1", "-1", "-1"]


for i in range(0, n+1):
  for j in range(0, (n-i)+1):
    cash_pattern = [i*10000, j*5000, (n-(i+j))*1000]
    if sum(cash_pattern) == y:
      answer_pattern = list(map(str,[i,j,n-i-j]))

print(" ".join(answer_pattern))

Solution (Python):
def main():
    N, Y = map(int, input().split())
    r, s, t = (-1, -1, -1)
    for R in range(Y//10**4 + 1):
        temp = Y - 9000 * R - 1000 * N
        if temp % 4000 == 0 and temp >= 0 and N - R - temp // 4000 >= 0:
            r = R
            s = temp // 4000
            t = N - s - r
    print(r, s, t)

if __name__ == "__main__":
    main()

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
        total = 10000*a + 5000*b + 1000*c
        if total==y:
            print("{0} {1} {2}".format(a,b,c))
            exit()

print("-1 -1 -1")

Solution (Python):
temp = input().split()
n,total = int(temp[0]), int(temp[1])

find = False
for a in range(n+1):
    for b in range(n+1):
        c = (-a) + (-b) + n
        if c >= 0 and a*10000 + b*5000 + c*1000 == total:
            print('{} {} {}'.format(a,b,c))
            find = True
            break
    else:
        continue
    break

if not find:
    print('{} {} {}'.format(-1,-1,-1))

Solution (Python):
N, Y = [int(str) for str in input().strip().split()]
Y //= 1000

for i in range(N + 1):
    for j in range(N - i + 1):
        k = N - i - j
        if 10 * i + 5 * j + k == Y:
            print(i, j, k)
            exit()

print(-1, -1, -1)

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

res10000=-1
res5000=-1
res1000=-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:
          res10000,res5000,res1000=i,j,k
          break

print('{} {} {}'.format(res10000,res5000,res1000))

Solution (Python):
n, y = [int(i) for i in input().split()]
a, b, c, f = 0, 0, 0, 0

for i in range(n+1):
  for j in range(n+1):
    k = (y - 10000*i - 5000*j)/1000
    if k == n-i-j and k>=0:
      a, b, c = i, j, k
      f += 1
      break
      
if f == 0:
  print(-1,-1,-1)
else:
  print(int(a), int(b), int(c))

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

num_10000 = 0
num_5000 = 0
num_1000 = 0

num_10000 = Y // 10000
Y -= num_10000 * 10000
num_5000 = Y // 5000
Y -= num_5000 * 5000
num_1000 = Y // 1000

num = num_10000 + num_5000 + num_1000

for i in range(0, num_10000 + 1):
    
    for j in range(0, i + 1):
        
        for k in range(0, num_5000 + 1):
            res = (num_10000 - i)
            res += j * 2 + (num_5000 - k)
            res += (i - j) * 10 + k * 5 + num_1000
            if res == N:
                print(num_10000 - i, j * 2 + (num_5000 - k),
                      (i - j) * 10 + k * 5 + num_1000)
                exit(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
    
print(*answer)