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

if Y >= N*1000:
    for i in range(N+1):
        if (Y / 1000 - N) - 9 * i >= 0 and int(((Y / 1000 - N) - 9 * i) % 4) == 0:
            y =((Y / 1000 - N) - 9 * i) / 4
            if int(N-i-y)>= 0 and 10000*i+5000*int(y)+1000*int(N-i-y) == Y:
                print(i, int(y), int(N-i-y))
                break
        elif i == N:
            print('-1 -1 -1')
else:
    print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
pairs = [[a, b, N-a-b] for a in range(N+1) for b in range(N-a+1) if a*10000+b*5000+(N-a-b)*1000 == Y]

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

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

Solution (Python):
if __name__ == '__main__':
    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)
            sum_price = 10000*i + 5000*j + 1000*k
            if n == i + j + k and sum_price == y:
                print(i, j, k)
                exit()
    print(-1, -1, -1)

Solution (Python):
import sys


if __name__ == '__main__':
    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)
            sum_price = 10000*i + 5000*j + 1000*k
            if k >= 0 and n == i + j + k and sum_price == y:
                print(i, j, k)
                sys.exit()
    print(-1, -1, -1)

Solution (Python):
import sys


if __name__ == '__main__':
    one_thousand, five_thousand, ten_thousand = 1000, 5000, 10000
    n, y = map(int, input().split())
    ans = []
    for i in range(0, n+1):
        for j in range(0, n+1-i):
            k = n - (i + j)
            one = one_thousand * i
            five = five_thousand * j
            ten = ten_thousand * k
            sum_price = one + five + ten
            if k >= 0 and n == i + j + k and sum_price == y:
                print(k, j, i)
                sys.exit()
    print(-1, -1, -1)

Solution (Python):
if __name__ == '__main__':
    one_thousand, five_thousand, ten_thousand = 1000, 5000, 10000
    n, y = map(int, input().split())
    ans = []
    for i in range(0, n+1):
        for j in range(0, n+1-i):
            k = n - (i + j)
            one = one_thousand * i
            five = five_thousand * j
            ten = ten_thousand * k
            sum_price = one + five + ten
            if k >= 0 and n == i + j + k and sum_price == y:
                ans.append([k, j, i])
                break
        if ans != []:
            print(ans[0][0], ans[0][1], ans[0][2])
            break
    if ans == []:
        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 - i):
        k = N - i - j
        if 10000*i + 5000*j + 1000*k == Y:
            a,b,c = i,j,k

print(a,b,c)

Solution (Python):



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

for sen in range(0, N+1):
  for gosen in range(0, N+1):
    man = N - sen - gosen
    if man < 0: break

    if 10000*man + 5000*gosen + 1000*sen == Y:
      print("{} {} {}".format(man, gosen, sen))
      exit(0)

print("-1 -1 -1")

Solution (Python):
lst=list(map(int,input().split()))
lst[1]/=1000
i=0
for a in range(lst[0]+1):
    if i !=0:
        break
    for b in range(lst[0]+1):
     	if lst[0]-a-b>=0:
            if 10*a+5*b+(lst[0]-a-b)==lst[1]:
                print(a,b,lst[0]-a-b)
                i=1
                break
        
if i==0:
    print(-1,-1,-1)

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

flag = True
for i in range(N+1):
    x = i
    N_ = N - x
    if not(flag):
        break
    for j in range(N_+1):
        y = j
        z = N_ - j
        if 10000*x + 5000*y + 1000*z == Y:
            print(x,y,z)
            flag = False
            break
if flag:
    print(-1,-1,-1)

Solution (Python):



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

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

print("-1 -1 -1")

Solution (Python):
n, y = input().split()
n = int(n)
y = int(y)
amx = min(n, y // 10000)
bmx = min(n, y // 5000)
ans1, ans2, ans3 = -1, -1, -1
for a in range(0, amx + 1):
    for b in range(0, bmx + 1):
        c = n - a - b
        if c < 0:
            break
        if c > n:
            continue
        yy = a * 10000 + b * 5000 + c * 1000
        if yy  == y:
            ans1, ans2, ans3 = a, b, c
            break
    if ans1 >= 0 and ans2 >= 0 and ans3 >= 0:
        break
print("{} {} {}".format(ans1, ans2, ans3))

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

x, y, z = 0, 0, 0
ans = False
for i in range(n+1):
    for j in range(n+1):
        tmp = i*10000 + j*5000 + (n-i-j)*1000
        if(yen == tmp and (n-i-j) >= 0):
            print("{} {} {}".format(i, j, (n-i-j)))
            ans = True
            break
    if(ans):
        break
        
if(not ans):
    print("-1 -1 -1")

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

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

if_break = 'False'
abc = 'False'

for a in range(n+1):
  for b in range(n-a+1):
    c = n - a - b

    if c >= 0:
      if 10000*a + 5000*b + 1000*c == y:
        print(a, b, c)
        abc = 'True'
        if_break = 'True'
        break
  if if_break == 'True':
    break
    
if abc == 'False':
  print('-1 -1 -1')

Solution (Python):
N, Y = map(int, input().split())
flag = 0
for num_so in range(N+1):
    if flag == 1:
        break
    for num_fs in range(N+1):
        num_ts = N - num_so - num_fs
        sum = num_ts * 10000 + num_fs * 5000 + num_so * 1000
        if flag == 1:
            break
        elif sum == Y and num_ts >= 0:
            print(num_ts, num_fs, num_so)
            flag = 1
            break

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

Solution (Python):
num,yen = map(int,raw_input().split())

ans = [-1,-1,-1]
isanswered = False

if 10000*num >= yen: 
	for i in range(num+1):
		for j in range(num+1-i):
			if 10000*i + 5000*j + 1000*(num-i-j) == yen and num-i-j-(num-i-j) == 0:
				ans[0] = i
				ans[1] = j
				ans[2] = (num-i-j)
				isanswered = True
				break

		if isanswered == True :
			break

print '%d %d %d' %(ans[0],ans[1],ans[2])

Solution (Python):
import sys

num,total = map(int,input().split())

if(total%10000 == 0 and num == total/10000):
    print(num,0,0)
    sys.exit()
if(total%5000 == 0 and num == total/5000):
    print(0,num,0)
    sys.exit()
if(total%1000 == 0 and num == total/1000):
    print(0,0,num)
    sys.exit()

for i in range(total//10000+1):
    for j in range(min([num - i,total//5000+1])):
        if(10000*i + 5000*j + 1000*(num-i-j) == total):
            print(i,j,(num-i-j))
            sys.exit()
print("-1 -1 -1")

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

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

Solution (Python):
n,y = map(int, raw_input().split())
a = -1
b = -1
c = -1
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:
      a = i
      b = j
      c = k
      break
  if a + b + c > -3:
    break
print a,b,c

Solution (Python):
N,Y=map(int,input().split())
flag=False
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:
            flag=True 
            break
    if flag:
        break
print("{} {} {}".format(i,j,k) if flag else "-1 -1 -1")

Solution (Python):
import sys

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

for i in range(N + 1):
    for j in range(N - i + 1):
        k = N - (i + j)
        if (i * 10000) + (j * 5000) + (k * 1000) == Y:
            print('{} {} {}'.format(i, j, k))
            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-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):
def solve(n, y):
    for x1 in range(n+1):
        x2 = ( y - 1000*n - 9000*x1) / 4000
        x3 = (-y + 5000*n + 5000*x1) / 4000
        if (x2 >= 0) and (x3 >= 0) and (x1 + x2 + x3 == n):
            return x1, x2, x3
    return -1, -1, -1

n, y = map(int, raw_input().split())
print " ".join(map(str, solve(n, y)))

Solution (Python):
n,y = list(map(int,input().split()))
y = y//1000
ans = '-1 -1 -1'
for i in range(n+1):
    for j in range(n+1-i):
        k = n-i-j
        if 10*i+5*j+k == y:
            ans = str(i)+' '+str(j)+' '+str(k)
            break
print(ans)

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

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

flag = False

for z in range(N + 1)[::-1]:
    rem1 = N - z + 1
    for y in range(rem1)[::-1]:
        x = N - z - y
        val = 10000 * x + 5000 * y + 1000 * z
        if val == Y:
            flag = True
            break
    if flag:
        break

if not flag:
    x = -1
    y = -1
    z = -1

print(x, y, z)

Solution (Python):

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

for x in range(2001):
    if 10000*x > Y:
        print(-1, -1, -1)
        break
    y = (Y-9000*x-1000*N)//4000
    z = N - x - y
    if 10000*x + 5000*y + 1000*z == Y and y >= 0 and z >= 0:
        print(x, y, z)
        break
else:
    print(-1, -1, -1)

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

Solution (Python):
n, y = map(int,input().split())
ans10000 = 0
ans5000 = 0
ans1000 =0

for i_a in range(n+1):
    for i_b in range(n+1-i_a):
        i_c = n - i_a -i_b
        total = 10000*i_a + 5000*i_b + 1000*i_c
        if total == y:
            ans10000 = i_a
            ans5000 = i_b
            ans1000 = i_c
if ans10000==0 and ans5000==0 and ans1000==0:
    ans10000 = -1
    ans5000 = -1
    ans1000 = -1

print(ans10000, ans5000, ans1000)

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

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

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

N = input[0]
Y = input[1]

ans = False
total = 0

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

    print(-1,-1,-1)

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

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

def f():
  for a in range(n+1):
    for b in range(n+1-a):
      if a*10000 + b*5000 + (n-a-b)*1000 == y:
        ans = [a, b, n-a-b]
        return(' '.join(map(str, ans)))
  return '-1 -1 -1'

print(f())

Solution (Python):
N, Y = map(int, input().split())
result = 0
flag = False
for i_1man in range(0, N+1):
    for i_5sen in range(0, N+1-i_1man):
        now = 10000 * i_1man + 5000 * i_5sen + 1000 * (N - i_1man - i_5sen)
        if now == Y:
            result = 1
            flag = True
        if flag:
            break
    if flag:
        break
if result == 0:
    print('-1 -1 -1')
else:
    print('{} {} {}'.format(i_1man, i_5sen, (N - i_1man - i_5sen)))

Solution (Python):
def solve():
    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:
                return " ".join([str(x), str(y), str(z)])

    return "-1 -1 -1"

if __name__=='__main__':
  print(solve())

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

Y = Y//1000

isok = False
for x in range(N+1):
    for y in range(N+1-x):
        if (10*x)+(5*y)+(N-x-y)==Y:
            isok = True
            print("{} {} {}".format(x,y,N-x-y))
            break
    if isok:break
        
if not isok:
    print("{} {} {}".format(-1,-1,-1))

Solution (Python):
n, y = map(int, input().split())
y //= 1000
yen = [10, 5, 1]


def bs(n10):
    high = y // 5 + 1
    low = 0
    while high - low > 1:
        mid = (high + low) // 2
        if mid + n10 > n or mid * 5 > y - n10 * 10 - (n - n10 - mid):
            high = mid
        else:
            low = mid
    return low


for i in range(n + 1):
    n5 = bs(i)
    if i * 10 + n5 * 5 + (n - i - n5) == y:
        print("{} {} {}".format(i, n5, n - i - n5))
        break
else:
    print("-1 -1 -1")

Solution (Python):


n,y = [int(i) for i in input().split()]
def numbers_possible(n,y):
    for i in range(n+1):
        for j in range(n-i+1):
            if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
                return print(i,j,n-i-j)
    return print(-1,-1,-1)
numbers_possible(n,y)

Solution (Python):
n, y = map(int, input().split())
y //= 1000
yen = [10, 5, 1]


def bs(n10):
    high = y // 5 + 1
    low = 0
    while high - low > 1:
        mid = (high + low) // 2
        if mid + n10 > n or mid * 5 > y - n10 * 10 - (n - n10 - mid):
            high = mid
        else:
            low = mid
    return low


try:
    for i in range(n + 1):
        for j in range(n + 1 - i):
            if i * yen[0] + j * yen[1] + (n - i - j) * yen[2] == y:
                print("{} {} {}".format(i, j, n - i - j))
                raise Exception
    print("-1 -1 -1")
except Exception:
    pass

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

Solution (Python):
I = input().split(" ")
N = int(I[0])
Y = int(I[1])
a = "-1 -1 -1"
for m in range(N+1):
    for g in range(N-m+1):
        if m * 10000 + g * 5000 + (N-m-g) * 1000 == Y:
            a = str(m) + " " + str(g) + " " + str((N-m-g))
            break
    if a != "-1 -1 -1":
        break         

print(a)

Solution (Python):
if __name__ == '__main__':
    N, Y = map(int, input().split())
    Y = Y // 1000

    
    for a in range(N + 1):
        for b in range(N + 1):
            if N < a + b:
                continue

            c = N - (a + b)
            if Y == 10 * a + 5 * b + c:
                print(a, b, c)
                exit(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):
        k = N-j-i
        if i * 1000 + j * 5000 + 10000 * k == Y:
            print(k,j,i)
            exit()

print(-1,-1,-1)

Solution (Python):
n, y = input().split()
n = int(n)
y = int(y)
amx = min(n, y // 10000)
bmx = min(n, y // 5000)
ans1, ans2, ans3 = -1, -1, -1
for a in range(0, amx + 1):
    for b in range(0, bmx + 1):
        c = n - a - b
        if c < 0:
            break
        if c > n:
            continue
        yy = a * 10000 + b * 5000 + c * 1000
        if yy  == y:
            ans1, ans2, ans3 = a, b, c
            break
    if ans1 >= 0 and ans2 >= 0 and ans3 >= 0:
        break
print("{} {} {}".format(ans1, ans2, ans3))

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

Solution (Python):
line = input().split(' ')
N = int(line[0])
Y = float(line[1])/10000

num_list = ([i, j, N-i-j] for i in range(N+1) for j in range(N+1-i))

for i in num_list:
	if (i[0]+float(i[1])/2+float(i[2])/10) == Y:
		print(" ".join(map(lambda x: str(int(x)), i)))
		break
else:
	print('-1 -1 -1')

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

for X in range(N+1):
    for Y in range(N+1):
        if(X +Y > N):
            break
        elif(10000*X+5000*Y+1000*(N-X-Y) == yen):
            print(str(X)+" "+str(Y)+" "+" "+str(N-X-Y))
            exit()
                       
print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())
a,b,c = -1,-1,-1
flag= False
Y=Y/1000

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

print(a,b,c)

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 otoshidama(N, Y):
    for a in range(N+1):
        for b in range(N+1-a):
            c = N - a - b
            if c < 0:
                break
            r = (10000 * a) + (5000 * b) + (1000 * c)
            if r == Y:
                return (a,b,c)

    return (-1,-1,-1)

N, Y = map(int, input().split())
r = otoshidama(N, Y)
print('{0} {1} {2}'.format(r[0], r[1], r[2]))

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

if Y > 10000 * N:
    print(-1, -1, -1)
    exit(0)

for num_yukichi in range(N+1):
    for num_ichiyou in range(N - num_yukichi + 1):
        num_souseki = N - num_yukichi - num_ichiyou
        sum = 10000 * num_yukichi + 5000 * num_ichiyou + 1000 * num_souseki
        if sum == Y:
            print(num_yukichi, num_ichiyou, num_souseki)
            exit(0)
else:
    print(-1, -1, -1)

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

if Y > 10000 * N:
    print(-1, -1, -1)
    exit(0)

for num_yukichi in range(N+1):
    for num_ichiyou in range(N - num_yukichi + 1):
        num_souseki = N - num_yukichi - num_ichiyou
        sum = 10000 * num_yukichi + 5000 * num_ichiyou + 1000 * num_souseki
        if sum == Y:
            print(num_yukichi, num_ichiyou, num_souseki)
            exit(0)
else:
    print(-1, -1, -1)

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

flag = False
for i in range(0, n+1):
    for j in range(0, n-i+1):
        k = n-i-j
        yen = i * 10000 + j * 5000 + k * 1000
        if y == yen:
            print(str(i)+" "+str(j)+" "+str(k))
            flag = True
            break
    if flag:
        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+1-i):
        if 10000*i+5000*j+1000*(n-i-j) == y:
            print(str(i)+" "+str(j)+" "+str(n-i-j))
            quit()
print("-1 -1 -1")

Solution (Python):


N, Y = map(int, raw_input().split(" "))


def search():

    for i in xrange(0, N + 1):
        for j in xrange(0, N + 1 - i):
            k = N - i - j
            if (i * 10000 + j * 5000 + k * 1000 == Y):
                return i, j, k

    return -1, -1, -1

x, y, z = search()

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

Solution (Python):
n,Y=map(int,input().split())
for x in range(-~n):
    for y in range(-~n-x):
        if x*10+y*5+(n-x-y)==Y//1000:print(x,y,n-x-y);exit()
print(*[-1]*3)

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

x=0
y=0
z=0

found = False
for i in range(int(total / 10000 + 1)):
  x = i
  for j in range(int((total - 10000 * i) / 5000 + 1)):
    y = j
    z = n - x - y
    sum = 10000 * x + 5000 * y + 1000 * z
    if sum == total:
      found = True
      break

  if found == True:
    break

if found == False:
  x = -1
  y = -1
  z = -1

print("{} {} {}".format(x, y, z))

Solution (Python):
import random




def criterion(x, y):
    z=-abs(total_yen-10000*x-5000*y-1000*(maisuu-x-y)) +min(0,maisuu-x-y)
    return z


def update_position(x, y, vx, vy):
    new_x = x + vx
    new_y = y + vy

    return new_x, new_y


def update_velocity(x, y, vx, vy, p, g, w=1, ro_max=0.14,v_max=5):
    
    ro1 =random.uniform(0, ro_max)
    ro2 =random.uniform(0, ro_max)
    
    new_vx = int((w * vx + ro1 * (p["x"] - x) + ro2 * (g["x"] - x)))
    new_vy = int((w * vy + ro1 * (p["y"] - y) + ro2 * (g["y"] - y)))
    if abs(new_vx)>v_max:
        new_vx=int(v_max*new_vx/abs(new_vx))
    if abs(new_vy)>v_max:
        new_vy=int(v_max*new_vy/abs(new_vy))

    
    return new_vx, new_vy
    
def main():
    N = 2000  
    x_min, x_max = 0, total_yen//10000+1
    y_min, y_max = 0, 8
    
    ps = [{"x": random.randint(x_min, x_max), 
        "y": random.randint(y_min, y_max)} for i in range(N)]
    vs = [{"x": 0, "y": 0} for i in range(N)]

    personal_best_positions = list(ps)
    personal_best_scores = [criterion(p["x"], p["y"]) for p in ps]

    best_particle = personal_best_scores.index(max(personal_best_scores))
    global_best_position = personal_best_positions[best_particle]

    T = 100  
    for t in range(T):
        for n in range(N):
            x, y = ps[n]["x"], ps[n]["y"]
            vx, vy = vs[n]["x"], vs[n]["y"]
            p = personal_best_positions[n]
            
            new_x, new_y = update_position(x, y, vx, vy)
            ps[n] = {"x": new_x, "y": new_y}
            
            new_vx, new_vy = update_velocity(
                new_x, new_y, vx, vy, p, global_best_position)
            vs[n] = {"x": new_vx, "y": new_vy}
            
            score = criterion(new_x, new_y)
            if score > personal_best_scores[n]:
                personal_best_scores[n] = score
                personal_best_positions[n] = {"x": new_x, "y": new_y}
        
        best_particle = personal_best_scores.index(max(personal_best_scores))
        global_best_position = personal_best_positions[best_particle]


    
    return max(personal_best_scores), global_best_position["x"], global_best_position["y"]




maisuu,total_yen =[int(i) for i in input().split()]
best=-100000000
xx=0
yy=0
for i in range(1):
    kouho_best, kouho_x, kouho_y=main()
    if best<kouho_best:
        best=kouho_best
        xx=kouho_x
        yy=kouho_y
if best<0 or xx<0 or yy<0 or maisuu-xx-yy<0:
    print(-1,-1,-1)
else:
    print(xx,yy,maisuu-xx-yy)

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

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

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

for a in range((y//10000)+1):
    for b in range((y//5000)+1):
        c = n - (a+b)
        if c < 0:
            break
        elif y == 10000*a + 5000*b + 1000*c:
            ans = [a,b,c]
    if ans is not None:
        break

if ans is not None:
    print(ans[0],ans[1],ans[2])
else:
    print("-1 -1 -1")

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

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

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

Solution (Python):
n, y = map(int,input().split())
s = []
for i in range(n+1):
    for j in range(n+1):
        if i * 10000 + j * 5000 + (n-i-j) * 1000 == y and n-i-j > -1:
            s.append(i)
            s.append(j)
            s.append(n-i-j)
            break
            
if s ==[]:
    print('-1 -1 -1')
else:
    print(str(s[0]) + ' ' + str(s[1]) + ' ' + str(s[2]))

Solution (Python):

import time

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

start = time.time()
judge_flag = False
first_a = -1
second_b = -1
theard_c = -1
for a in range(N + 1):
    for b in range(N + 1):
        if Y == 10000 * a + 5000 * b + 1000 * (N - a - b) and (N - a - b) >= 0:
            first_a = a
            second_b = b 
            theard_c = (N - a - b)
            break
    if Y == 10000 * a + 5000 * b + 1000 * (N - a - b) and (N - a - b) >= 0:
         break

elapsed_time = time.time() - start
print("{} {} {}".format(first_a, second_b, theard_c))

Solution (Python):
def bills(n, y):
    for bills_10k in range(n + 1):
        for bills_5k in range(n - bills_10k + 1):
            bills_1k = n - bills_10k - bills_5k
            if y == bills_10k * 10000 + bills_5k * 5000 + bills_1k * 1000:
                return [bills_10k, bills_5k, bills_1k]
    return [-1, -1, -1]

if __name__ == '__main__':
    n, y = map(int, input().split())
    print(' '.join(map(str, bills(n, y))))

Solution (Python):
def solve(n, y):

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

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

print(solve(n, y))

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

else:
    print(-1, -1, -1)

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

l = (-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 and N - (i + j) >= 0:
            l = (i, j, N - (i + j))
            break

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

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("{} {} {}".format(i, j, n-i-j))
            exit()
print('-1 -1 -1')

Solution (Python):
num, yen = map(int,input().split(" "))
num_max = yen/1000
isPossible = False

for i in range(num+1):
	if(isPossible):
		break
	for j in range(num+1):
		
		if(num == num_max-i*4-j*9 and num-j-i >= 0):
			print(j,i,num-j-i)
			isPossible = True
			break
if(not isPossible):
	print("-1 -1 -1")

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

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

print("-1 -1 -1")

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


def main():
    for a in range(n + 1):
        for b in range(n - a + 1):
            c = n - a - b
            if (a * 1000 + b * 5000 + c * 10000 == y) & (a + b + c == n):
                return print(c, b, a)
    return print("-1 -1 -1")


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):
import sys
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))
            sys.exit()
print(-1,-1,-1)

Solution (Python):
N,Y=map(int,input().split())
ans1, ans2, ans3 =-1,-1,-1

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

print("{} {} {}".format(ans1,ans2,ans3))

Solution (Python):
N,Y = map(int,input().split())
Y_prime = Y - 1000*N
a_max = Y_prime//9000
Y_rest = 0
for a in range(a_max+1):
    Y_rest = Y_prime-9000*a
    if Y_rest%4000 == 0:
        b = Y_rest//4000
        c = N - a - b
        if c >= 0:
            print(a,b,c)
            break
else:
    print('-1 -1 -1')