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 in Common Lisp (SBCL 1.1.14) (judge verdict: Accepted)

(defun solve-bezout (m n d)
  (if (not (= (gcd m n) d))
      nil
      (loop for k in (if (>= m n)
			 (euclidean-alg m n)
			 (euclidean-alg n m))
	 for x = 0 then (+ (* 0 x) (* 1 u))
	 and y = 1 then (+ (* 0 y) (* 1 v))
	 and u = 1 then (+ (* 1 x) (* (- k) u))
	 and v = (- k) then (+ (* 1 y) (* (- k) v))
	 finally (return (if (>= m n)
			     (cons x y)
			     (cons y x))))))

(defun euclidean-alg (m n)
  (let ((rem (mod m n)))
    (if (zerop rem)
	(list (/ m n))
	(cons (/ (- m rem) n)
	      (euclidean-alg n rem)))))

;; Es sucht k in Z, so dass x+k*alpha ist das kleinste nicht negative Nummer.
(defun get-minimum-factor (x alpha)
  (funcall (if (plusp alpha) #'ceiling #' floor)
	   (/ (- x) alpha)))

(defun sign (x) (cond ((> x 0) 1) ((= x 0) 0) (t -1)))

;; Es sucht eine ganzzahlige Lösung, so dass
;; m*x+n*y=d, 0<=x, 0<=y, x+y<=sup.
(defun solve-bezout-positive (m n d sup)
  (let ((gcdmn (gcd m n)))
    (if (/= (mod d gcdmn) 0)
	nil
	(let* ((root (solve-bezout m n gcdmn))
	       (factor (/ d gcdmn))
	       (x0 (* (car root) factor))
	       (y0 (* (cdr root) factor))
	       (deltax (/ n gcdmn))
	       (deltay (/ m gcdmn)))
	  ;; (format t "(~A + k * ~A, ~A - k * ~A)~%" x0 deltax y0 deltay)
	  (let* ((k-min1 (get-minimum-factor x0 deltax))
		 (k-min2 (get-minimum-factor y0 (- deltay)))
		 (x1 (+ x0 (* k-min1 deltax)))
		 (y1 (- y0 (* k-min1 deltay)))
		 (x2 (+ x0 (* k-min2 deltax)))
		 (y2 (- y0 (* k-min2 deltay))))
	    ;; (format t "k-min1=~A, k-min2=~A~%" k-min1 k-min2)
	    ;; (format t "deltax=~A, deltay=~A~%" deltax deltay)
	    (if (and (>= y1 0) (<= (+ x1 y1) sup))
		(cons x1 y1)
		(if (and (>= x2 0) (<= (+ x2 y2) sup))
		    (cons x2 y2)
		    nil)))))))


;; Sei y=1000y'. Wir lösen folgende ganzahlige Gleichungen:
;; 10i + 5j + k = y',
;; i + j + k = n,
;; i, j, k >= 0.

;; Sie sind wie folgt reduziert:
;; 9i + 4j = y' - n,
;; i, j >= 0, i + j <= n.

;; Es ist eine so gennnte Bézout-Gleichung: y'-n soll ein Vielfaches von gcd(9, 4) sein.


(defun judge-solve-print (n y)
  (let* ((ij (solve-bezout-positive 9 4 (- (/ y 1000) n) n)))
    ;; (format t "9i+4j=~A~%" (- (/ y 1000) n))
    (if (null ij)
	(format t "-1 -1 -1")
	(format t "~A ~A ~A~%" (car ij) (cdr ij) (- n (car ij) (cdr ij))))))

(judge-solve-print (read) (read))