Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.

As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

D is 0, 1 or 2.

N is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.

Sample Input 1

0 5

Sample Output 1

5

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...

Thus, the 5-th smallest integer that would make Ringo happy is 5.

Sample Input 2

1 11

Sample Output 2

1100

The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \ 000, 1 \ 100, ...

Thus, the integer we are seeking is 1 \ 100.

Sample Input 3

2 85

Sample Output 3

850000

The integers that can be divided by 100 exactly twice are as follows: 10 \ 000, 20 \ 000, 30 \ 000, ...

Thus, the integer we are seeking is 850 \ 000.


Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


(let ((d (read))
      (n (read)))

  (format t "~A~%"
            (* n (expt 100 d))))


#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
  `(let ((it ,expr))
     (if it ,then ,else)))

(defmacro awhen (expr &rest then)
  `(aif ,expr (progn ,@then) nil))

(defun comulative (function list &key base)
  (if base
      (comulative function (cons base list))
      (do ((lst (cdr list) (cdr lst))
           (acc (list (car list))))
          ((null lst) (reverse acc))
        (push (funcall function (car acc) (car lst)) acc))))

(defun binary-search (function left right
                      &optional
                        (eps 1)
                        (average-function (lambda (x y) (ash (+ x y) -1))))
  (if (<= (abs (- left right)) eps)
      right
      (let ((mid (funcall average-function left right)))
        (if (funcall function mid)
            (binary-search function left mid eps average-function)
            (binary-search function mid right eps average-function)))))

(defun arithmetic-mean (&rest body)
  (/ (apply #'+ body) (length body)))

(defvar +MOD+ (+ (expt 10 9) 7))

(defun mapa-b (fn a b &optional (step 1))
  (do ((i a (+ i step))
       (result nil))
      ((> i b) (nreverse result))
    (push (funcall fn i) result)))

(defun map0-n (fn n)
  (mapa-b fn 0 n))

(defun map1-n (fn n)
  (mapa-b fn 1 n))

(defun read-string (&optional (stream *standard-input*))
  (labels ((is-empty (x)
             (or (char= x #\space) (char= x #\newline))))
    (loop for char = (read-char stream)
          with result
          when (is-empty char)
            do (return (concatenate 'string (nreverse result)))
          do (push char result))))

(defun main (d n)
  (* (expt 100 d) n))

(princ (main (read) (read)))


#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun binary-search (l r f &aux (m (ash (+ l r) -1)))
  "f の結果がtになる最小の値を見つけます"
  (if (= l r)
      l
      (if (funcall f m)
          (binary-search l m f)
          (binary-search (1+ m) r f))))

(defmacro aif (expr then else)
    `(let ((it ,expr))
       ,then
       ,else))

(defun main (a b)
  (* b (expt 100 a)))

#-swank
(princ (main (read) (read)))


(setq d (read) n (read))

(if (= n 100) (princ (* (expt 100 d) (+ n 1))) (princ (* (expt 100 d) n)))


(format t "~A" (* (expt 100 (read)) (read)))


(declaim (ftype (function (string &optional character) (values (vector string *) &optional)) split))
(defun split (text &optional (delim #\Space))
    (let* ((result (make-array 0
                               :element-type 'string
                               :adjustable t
                               :fill-pointer 0)))
          (loop :for c character :across text
                :with temp = ""
                :do
                (cond ((char= c delim)
                       (vector-push-extend temp result)
                       (setf temp ""))
                    (t
                     (setf temp (concatenate 'string temp (string c)))))
                :finally
                (vector-push-extend temp result))
          result))

(declaim (ftype (function (integer integer) (values integer &optional)) solve))
(defun solve (d n)
    (cond ((not (= n 100))
           (* (expt 100 d) n))
        (t (+ (expt 100 (+ d 1)) (expt 100 d)))))

(defun main ()
    (let* ((input (map 'vector #'parse-integer (split (read-line))))
           (d (aref input 0))
           (n (aref input 1)))
          (format t "~A~%" (solve d n))))

(main)


(defun answer (d n)
  (labels ((inner (k rv)
             (cond
               ((zerop (mod rv 100))
                (inner k (1+ rv)))
               ((= k n)
                rv)
               (t
                (inner (1+ k) (1+ rv))))))
    (* (inner 1 1) (expt 100 d))))

(princ (answer (read) (read)))


(let ((d (read))
      (n (read)))
  (princ (* n (expt 100 d))))


(defun main ()
    (let* ((a (read)) (b (read)) (c (read)) (x (read)))
        (format t "~A~%"
            (loop for i from 0 to a sum
                (loop for j from 0 to b sum
                    (loop for k from 0 to c
                        when (= (+ (* i 500)
                                   (* j 100)
                                   (* k  50)) x)
                        count k))))))
(main)

Score : 200 points

Problem Statement

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

0 \leq A, B, C \leq 50

A + B + C \geq 1

50 \leq X \leq 20 000

A, B and C are integers.

X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.

Sample Input 1

2
2
2
100

Sample Output 1

2

There are two ways to satisfy the condition:

Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.

Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

Sample Input 2

5
1
0
150

Sample Output 2

0

Note that the total must be exactly X yen.

Sample Input 3

30
40
50
6000

Sample Output 3

213


(defun main ()
    (let* ((a (read)) (b (read)) (c (read)) (x (read)))
        (loop for i from 0 to a sum
            (loop for j from 0 to b sum
                (loop for k from 0 to c
                    when (= (+ (* i 500)
                               (* j 100)
                               (* k  50)) x)
                    count k)))))
(main)


#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main (str)
  (count #\1 str))

(defun main (a b c x)
  (loop for i from 0 to a
        sum
        (loop for j from 0 to b
              sum
              (let ((rem (- x (* i 500) (* j 100))))
                (if (zerop (mod rem 50))
                    (if (>= c (/ rem 50) 0) 1 0)
                    0)))))

(princ (main (read) (read) (read) (read)))


(defun coins ()
  (let ((a (read))
        (b (read))
        (c (read))
        (x (read))
        (ans 0))
    (dotimes (i (1+ a))
      (dotimes (j (1+ b))
        (dotimes (k (1+ c))
          (if (= x (+ (* 500 i) (* 100 j) (* 50 k)))
              (incf ans)))))
    ans))

(format t "~D~%" (coins))


(defun main ()
  (let ((a (read))
	(b (read))
	(c (read))
	(s (read)))
    (format t "~&~D ~S~%" (+ a b c) s)))

(main)


(princ (loop :for x :from 0 :upto (read) :with b := (read) :with c := (read)
             :with k := (read)
             :sum(loop :for y :from 0 :upto b
                       :sum(loop :for z :from 0 :upto c
                                 :count(= k (+ (* x 500) (* y 100) (* z 50)))))))


(defun coins (a b c x)
  (let ((res 0)
        (total 0))
    (dotimes (i (+ a 1))
      (dotimes (j (+ b 1))
        (dotimes (k (+ c 1))
          (setf total (+ (* 500 i) (* 100 j) (* 50 k)))
          (if (= total x) (incf res)))))
    res))

(format t "~A~%" (coins (read) (read) (read) (read)))


(let ((a (read))
      (b (read))
      (c (read))
      (k (read))
      (ans 0))
  (loop :for x :from 0 :upto a :do
    (loop :for y :from 0 :upto b :do
      (loop :for z :from 0 :upto c :do(if (= k (+ (* x 500) (* y 100) (* z 50)))
                                          (incf ans)))))
  (princ ans))


(let ((a (read))
      (b (read))
      (c (read))
      (k (read))
      (ans 0))
  (loop :for x :from 0 :upto a :do
    (loop :for y :from 0 :upto b :do
      (loop :for z :from 0 :upto c :do(if (+ (* x 500) (* y 100) (* c 50)) (incf
                                                                            ans)))))
  (princ ans))


(defun coins (a b c x)
  (let ((res 0)
	(total 0))
    (dotimes (i (+ a 1))
      (dotimes (j (+ b 1))
	(dotimes (k (+ c 1))
	  (setf total (+ (* 500 i) (* 100 j) (* 50 k)))
	  (if (= total x)
	      (incf res)))))))

(format t "~A~%" (coins (read) (read) (read) (read))))


(defun solver ()
  (let ((a (read)) (b (read)) (c (read))
        (x (read))
        (count 0))
    (loop for i from 0 to a do
          (loop for j from 0 to b do
                (loop for k from 0 to c do
                      (when (= (+ (* 500 i) (* 100 j) (* 50 k)) x)
                        (incf count)))))
    count))

(solver)


(let ((A (read))
      (B (read))
      (C (read))
      (X (read)))
  (format t "~A~%"
          (loop for k upto A with totalA
             do
               (setf totalA (* k 500))
             sum (loop for m upto B with totalB
                    do
                      (setf totalB (+ totalA (* 100 m)))
                    sum (loop for n upto C
                           count (= (+ totalB (* 50 n))
                                    X))))))


(let ((A (read))
      (B (read))
      (C (read))
      (X (read)))
  (format t "~A~%"
          (loop for k upto A with totalA = 0
             do
               (setf totalA (* k 500))
             when (> totalA X) return ans1
             sum (loop for m upto B with totalB
                    do
                      (setf totalB (+ totalA (* 100 m)))
                    when (> totalB X) return ans2
                    sum (loop for n upto C with totalC
                           do
                             (setf totalC (+ totalB (* 50 n)))
                           when (> totalC X) return ans3
                           count (= totalC X) into ans3
                           finally (return ans3))
                    into ans2
                    finally (return ans2))
             into ans1
             finally (return ans1))))


(let ((a (read))
      (b (read))
      (c (read))
      (x (read))
      (sum 0))
  (loop for i below (+ a 1)
        do (loop for j below (+ b 1)
                 do (loop for k below (+ c 1)
                          if (equal (+ (* i 500) (* j 100) (* k 50)) x) do (setf sum (+ sum 1)))))
  (format t "~A~%" sum))


(let ((x (* (read) (read))))
  (format t "~A~%"
          (if (oddp x)
            "Odd"
            "Even")))

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.


(defun product (a b)
  (if (zerop (rem (* a b) 2))
    "Even"
    "Odd"
    ))

(format t "~A~%" (product (read) (read)))


(princ (if (oddp (* (read) (read)))
           "Odd"
           "Even"))


(defun main()
    (let* ((a (read))
           (b (read)))
        (format t "~A~%"
            (if (zerop (rem (* a b) 2)) "Even" "Odd"))))

(main)


(defun product (a b)
  (if (zerop (rem (* a b) 2))
      "Even"
      "Odd"))

(format t "~A~%" (product (read) (read)))


(defun fun (a b)
  (if (zerop (rem (* a b) 2))
      "Even"
      "Odd"))

(format t "~A~%" (fun (read) (read)))


(defun product (a b)
  (if (zerop (rem (* a b) 2))
      "Even"
      "Odd"
))

(format t "~A~%" (product (read) (read)))


#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(princ (if (oddp (* (read) (read))) "Odd" "Even"))


(format t "~A ~A" (+ (read) (read) (read)) (read))


(defun product ()
  (let ((a (read))
        (b (read))
        (ans "Odd"))
    (if (zerop (rem (* a b) 2))
        (setf ans "Even"))
    ans))

(format t "~A~%" (product))


(format t "~[Even~;Odd~;~]" (mod (* (read) (read)) 2))


(format t "~[Even~;Odd~;~]" (mod (read) 2))


(loop :for k :from 1 :upto 1 :if (evenp (* (read) (read))) :do(princ "Even") :else :do(princ "Odd"))


(let ((a (parse-integer (remove #\space (read-line)))))
  (if (= a (expt (floor (sqrt a)) 2))
      (princ "Yes")
      (princ "No")))


(let ((a (read-from-string (concatenate 'string "(" (read-line) ")"))))
  (if (evenp (apply #'* a))
      (princ "Even")
      (princ "Odd")))


(let ((a (read-from-string (concatenate 'string "(" (read-line) ")"))))
  (if (evenp (apply #'+ a))
      (princ "Even")
      (princ "Odd")))


(defun func (a)
  (if (oddp a)
	"Odd"
	"Even"))

(princ (func (* (read) (read))))


(defun product (a b)
  (if (= 0 (mod (* a b) 2))
    "EVEN"
    "ODD"))

(format t "~A" (product (read) (read)))


(defun product (a b)
  (if (= 0 (mod (* a b) 2))
	"EVEN"
	"ODD"))

(format t "~A~%" (product (read) (read)))


(format
 t
 "~A~%"
 (let ((a (read))
       (b (read)))
   (if (eq 0 (mod (* a b) 2))
       "Even"
     "Odd")))


(format
 t
 "~A~%"
 (let ((a (read))
      (b (read)))
 	    (if (eq 0 (mod (* a b) 2))
         "Even"
         "Odd"))))


(defparameter a (read))
(defparameter b (read))

(if (or (evenp a)
        (evenp b))
    (format t "Even")
    (format t "Odd"))


(defparameter a (read))
(defparameter b (read))

(if (or (evenp a)
        (evenp b))
    (format t "Even")
    (format t "Odd))


(defun solve (a b)
    (if (zerop (rem (* a b) 2))
    "Even" "Odd"))
(format t "~A~%" (solve (read) (read)))


(defun product (a b)
  (if (zerop (rem (* a b) 2))
      "Even"
      "Odd"
      ))

(format t "~A~%" (product (read) (read)))


(defun product (a b)
  (if (zerop (rem (* a b) 2))
      "Even"
      "Odd"))

(format t "~A~%" (product (read) (read)))


(defun product (a b)
  (if (zerop (rem (* a b) 2))
    "Even"
    "Odd"))

(format t "~A~% (product (read) (read))")


(if (evenp(* (read) (read))) (format t "Even") (format t "Odd"))


(defun product (a b)
 (cond
  ((or (/=(mod a 2)1)(/=(mod b 2)1))"Even")
  (t "Odd")))

(format t "~A~%" (product (read) (read)))


(defun product (a b)
 (cond
  ((or (/=(mod a 2)0)(/=(mod b 2)0))"Even")
  (t "Odd")))


(defun product (a b)
 (cond
  ((or (/=(mod a 2)1)(/=(mod b 2)1))"Even")
  (t "Odd")))


(defun main()
  (if (oddp (* (read) (read)))
      (format t "Odd")
      (format t "Even")))
(main)


(defun pro (a b)
  (if (zerop (rem (* a b) 2))
      "Even"
      "Odd"))

(format t "~A~%" (pro (read) (read)))


(defun product (a b)
    (if (zerop (rem (* a b) 2))
        "Even"
        "Odd"))

(format t "~A~%" (product (read) (read)))


(if (oddp (* (read) (read))) (princ "Odd") (princ "Even"))


(defun hey (a b)
  (if (zerop (rem (* a b) 2))
      "Even"
      "Odd"
      ))
(format t "~A~%" (hey (read) (read)))


(if (oddp (* (read) (read)))
    (format t "Odd~%")
    (format t "Even~%"))


(let ((a (read))
      (b (read)))
  (format t "~a~%" (if (= (mod (* a b) 2) 0) "Even" "Odd")))


(let* ((a (read))
       (b (read))
       (p (* a b)))
  (format t "~A~%" (if (evenp p) "Even" "Odd")))


(defun main ()
  (let* ((n (read))
         (y (read)))
    (format t "~A~%"
      (loop named outer
        for i from 0 to n
        finally (return-from outer (format nil "~a ~a ~a" -1 -1 -1))
        do
        (loop for j from 0 to (- n i) do
            (if (= y (+ (* i 10000)
                        (* j 5000)
                        (* (- n i j) 1000)))
                (return-from outer (format nil "~a ~a ~a" i j (- n i j)))))))))
(main)

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


(defun main ()
  (let* ((n (read))
         (y (read)))
    (format t "~A~%"
      (loop named outer
        for i from 0 to n
        finally (return-from outer (format nil "~a ~a ~a" -1 -1 -1))
        do
        (loop for j from 0 to (- n i) do
          (loop for k from 0 to (- n i j) do
            (if (= y (+ (* i 1000)
                        (* j 5000)
                        (* k 10000)))
                (return-from outer (format nil "~a ~a ~a" k j i)))))))))

(main)


(defun main ()
  (let* ((n (read))
         (y (read)))
    (format t "~A~%"
      (loop named outer
        for i from 0 to n
        finally (return-from outer (format nil "~a ~a ~a" -1 -1 -1))
        do
        (loop for j from 0 to (- n i) do
          (loop for k from 0 to (- n i j) do
            (if (= y (+ (* i 1000)
                        (* j 5000)
                        (* k 10000)))
                (return-from outer (format nil "~a ~a ~a" k j i)))))))))


(defvar N (read))
(defvar y (/ (read) 1000))

(loop for A from (mod (- y N) 4) to (/ y 10) by 4
      with B = (/ (- y N (* 9 A)) 4) with C = (- N A B)
      unless (some #'minusp (list A B C))
      return (format t "~A ~A ~A" A B C)
      do (decf B 9) (incf C 5)
      finally (princ "-1 -1 -1"))


#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main (str)
  (count #\1 str))

(defun main(n yen)
  (loop for i from 0 to n
        do
           (loop for j from 0 to (- n i)
                 for k = (- n i j)
                 when (= (+ (* i 10000) (* j 5000) (* k 1000)) yen)
                   do
                 (return-from main (format nil "~a ~a ~a~%" i j k))))
  "-1 -1 -1")

(princ (main (read) (read)))


(loop :named n-loop :with n := (read)
      :do (loop :for j :upto n :with y := (read)
                :do (loop :for k :upto (- n j)
                          :if (= y (+ (* 10000 j) (* 5000 k) (* 1000 (- n j k))))
                            :do (format t "~A ~A ~A" j k (- n j k))
                            :and
                              :do (return-from n-loop))
                :finally (princ "-1 -1 -1")))


(loop :named j-loop :with n := (read)
      :do (loop :for j :upto n :with y := (read)
                :do (loop :for k :upto (- n j)
                          :if (= y (+ (* 10000 j) (* 5000 k) (* 1000 (- n j k))))
                            :do (format t "~A ~A ~A" j k (- n j k))
                                :and
                            :do (return-from j-loop))
                :finally (princ "-1 -1 -1")))


(defun solve (n y)
  (loop for a from n downto 0
        for m = (- n a)
        do (loop for b from m downto 0
                 for c = (- m b)
                 when (= (+ (* 1000 c)
                            (* 5000 b)
                            (* 10000 a))
                         y)
                 do (return-from solve (list a b c)))
        finally
           (return (list -1 -1 -1))))

#-swank
(let* ((n (read))
       (y (read)))
  (format t "~{~A~^ ~}~%" (solve n y)))


(defmacro for ((var from to) &body body)
  `(do ((,var ,from (1+ ,var)))
       ((> ,var ,to))
     ,@body))

(defun valid-p (n y)
  (for (a 0 n)
    (for (b 0 (- n a))
      (let* ((c (- n a b))
             (sum (+ (* a 10000)
                     (* b 5000)
                     (* c 1000))))
        (when (= y sum)
          (return-from valid-p (values a b c))))))
  (values -1 -1 -1))

(defun main ()
  (let ((n (read))
        (y (read)))
    (multiple-value-bind (a b c)
        (valid-p n y)
      (format t "~A ~A ~A~%" a b c))))

#-swank (main)


(defmacro for ((var from to) &body body)
  `(do ((,var ,from (1+ ,var)))
       ((>= ,var ,to))
     ,@body))

(defun valid-p (n y)
  (for (a 0 n)
    (for (b 0 (- n a))
      (let* ((c (- n a b))
             (sum (+ (* a 10000)
                     (* b 5000)
                     (* c 1000))))
        (cond ((= y sum)
               (return-from valid-p (values a b c)))))))
  (values -1 -1 -1))

(defun main ()
  (let ((n (read))
        (y (read)))
    (multiple-value-bind (a b c)
        (valid-p n y)
      (format t "~A ~A ~A~%" a b c))))

#-swank (main)


(defmacro for ((var from to) &body body)
  `(do ((,var ,from (1+ ,var)))
       ((>= ,var ,to))
     ,@body))

(defun valid-p (n y)
  (for (a 0 n)
    (for (b 0 n)
      (for (c 0 (- n (+ a b)))
        (let ((sum (+ (* a 10000)
                      (* b 5000)
                      (* c 1000))))
          (cond ((= y sum)
                 (return-from valid-p (values a b c)))))))))

(defun main ()
  (let ((n (read))
        (y (read)))
    (multiple-value-bind (a b c)
        (valid-p n y)
      (format t "~A ~A ~A~%" a b c))))

#-swank (main)


(defun valid-p (n y)
  (dotimes (a n)
    (unless (< y (* a 10000))
      (dotimes (b n)
        (unless (< y (* a 10000) (* b 5000))
          (dotimes (c n)
            (let ((sum (+ (* a 10000)
                          (* b 5000)
                          (* c 1000))))
              (cond ((= y sum)
                     (return-from valid-p (values a b c)))
                    ((< y sum)
                     (return))))))))))

(defun main ()
  (let ((n (read))
        (y (read)))
    (multiple-value-bind (a b c)
        (valid-p n y)
      (format t "~A ~A ~A~%" a b c))))

#-swank (main)


(defun valid-p (n y)
  (declare (fixnum n y)
           (optimize (speed 3) (safety 0) (debug 0)))
  (labels ((f (n sum a b c)
             (declare (fixnum n sum a b c))
             (cond ((< y n))
                   ((= n 0)
                    (if (= sum y)
                        (return-from valid-p (values a b c))))
                   (t
                    (f (1- n) (+ sum 10000) (1+ a) b c)
                    (f (1- n) (+ sum 5000) a (1+ b) c)
                    (f (1- n) (+ sum 1000) a b (1+ c))))))
    (f n 0 0 0 0)
    (values -1 -1 -1)))

(defun main ()
  (let ((n (read))
        (y (read)))
    (multiple-value-bind (a b c)
        (valid-p n y)
      (format t "~A ~A ~A~%" a b c))))

(main)


(let* ((n (read))
       (m (read))
       (ans (loop :for x :from 0 :upto n
                    :thereis (loop :for y :from 0 :upto n
                                     :thereis (if (and (<= 0 (- n x y)) (= m (+ (* 10000 x) (* 5000 y) (* (- n x y) 1000))) )
                                                  (list x y (- n x y)))))))
  (if ans
      (format t "~A ~A ~A" (first ans) (second ans) (third ans))
      (format t "-1 -1 -1")))


(let* ((n (read))
       (m (read))
       (ans (loop :for x :from 0 :upto n
                    :thereis (loop :for y :from 0 :upto n
                                     :thereis (if (= m (+ (* 10000 x) (* 5000 y) (* (- n x y) 1000)))
                                                  (list x y (- n x y)))))))
  (if ans
      (format t "~A ~A ~A" (first ans) (second ans) (third ans))
      (format t "-1 -1 -1")))


(let* ((n (read))
       (m (read)))
  (defun f (price lst)
    (if (= (+ price (* (- n (length lst)) 1000)) m)
        lst
        (if (or (> (+ price (* (- n (length lst)) 1000)) m) (< (- n (length lst)) 0))
            nil
            (cond ((f (+ price 10000) (cons 10000 lst)))
                  ((f (+ price 5000) (cons 5000 lst)))))))
  (let* ((k (f 0 nil)))
    (if k
        (format t "~A ~A ~A" (count 10000 k) (count 5000 k) (- n (length k)))
        (format t "-1 -1 -1"))))


(let* ((n (read))
       (m (read)))
  (defun f (price lst)
    (if (= (+ price (* (- n (length lst)) 1000)) m)
        lst
        (if (or (> (+ price (* (- n (length lst)) 1000)) m) (< (- n (length lst)) 0))
            nil
            (cond ((f (+ price 10000) (cons 10000 lst)))
                  ((f (+ price 5000) (cons 5000 lst)))))))
  (let* ((k (f 0 nil)))
    (if (minusp (- n (length k)))
        (format t "-1 -1 -1")
        (format t "~A ~A ~A" (count 10000 k) (count 5000 k) (- n (length k))))))


(let* ((n (read))
       (m (read)))
  (defun f (price lst)
    ;(format t "~A ~A~%" price lst)
    (if (= (+ price (* (- n (length lst)) 1000)) m)
        lst
        (if (> (+ price (* (- n (length lst)) 1000)) m)
            nil
            (cond ((f (+ price 10000) (cons 10000 lst)))
                  ((f (+ price 5000) (cons 5000 lst)))))))
  (let* ((k (f 0 nil)))
    (if (minusp (- n (length k)))
        (format t "-1 -1 -1")
        (format t "~A ~A ~A" (count 10000 k) (count 5000 k) (- n (length k))))))


(let* ((n (read))
       (m (read))
       (res '(1000 5000 10000))
       (ans '(0 0 0)))
  (setf m (- m (* n (first res))))
  (multiple-value-bind (x y) (floor m (- (third res) (first res)))
    (setf ans (list (- n (+ x y)) y x)))
  (if (equal nil (remove-if-not #'minusp ans))
      (format t "~{~A ~}~%" (reverse ans))
      (format t "-1 -1 -1~%")))


(defun otoshidama (n y)
  (let ((res10000 -1)
        (res5000 -1)
        (res1000 -1)
        (c 0)
        (total 0))
    (dotimes (a n)
      (dotimes (b (- n a))
        (setf c (- n a b))
        (setf total (+ (* 10000 a) (* 5000 b) (* 1000 c)))
        (if (= total y)
            (progn
              (setf res10000 a)
              (setf res5000 b)
              (setf res1000 c)))))
    (values res10000 res5000 res1000)))

(multiple-value-bind (res10000 res5000 res1000) (otoshidama (read) (read))
  (format t "~A ~A ~A~%" res10000 res5000 res1000))


(defun sum (a b c)
  (+ (* 10000 a) (* 5000 b) (* 1000 c)))

(defun solver ()
  (let ((n (read)) (y (read)) (flag 0) (money 0) k)
    (loop named outer for i from n downto 0 do
          (loop named inner for j from (- n i) downto 0 do
                (setf k (- n i j) money (sum i j k))
                (when (= y money)
                  (incf flag)
                  (return-from outer (format t "~a ~a ~a~%" i j k)))))
    (when (= flag 0) (format t "-1 -1 -1~%"))))

(solver)


(defun solver ()
  (let ((n (read)) (y (read)) (flag 0))
    (loop named outer for i from n downto 0 do
          (loop for j from (- n i) downto 0 do
                (loop for k from (- n i j) downto 0 do
                      (let ((money (+ (* 10000 i) (* 5000 j) (* 1000 k))))
                        (when (= y money)
                          (incf flag)
                          (return-from outer (format t "~a ~a ~a~%" i j k)))
                        (when (> y money) (return-from outer))))))
    (when (= flag 0) (format t "-1 -1 -1~%"))))

(solver)


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


(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-int:defconstant-eqx OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))
    #'equal)
  #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
  #-swank (set-dispatch-macro-character
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setq minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(defun main ()
  (declare #.OPT
           (inline sort))
  (let* ((n (read))
         (h (read))
         (as (make-array n :element-type 'uint32))
         (bs (make-array n :element-type 'uint32)))
    (declare (uint32 n h))
    (dotimes (i n)
      (setf (aref as i) (read-fixnum)
            (aref bs i) (read-fixnum)))
    (setq bs (sort bs #'>))
    (let ((max-a (reduce #'max as)))
      (loop for i below n
            for b = (aref bs i)
            while (and (> b max-a) (> h 0))
            do (setq h (max 0 (- h b)))
            finally (println (+ i (ceiling h max-a)))))))

#-swank (main)

;;;
;;; Test and benchmark
;;;

#+swank
(defun io-equal (in-string out-string &key (function #'main) (test #'equal))
  "Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if
the string output to *STANDARD-OUTPUT* is equal to OUT-STRING."
  (labels ((ensure-last-lf (s)
             (if (eql (uiop:last-char s) #\Linefeed)
                 s
                 (uiop:strcat s uiop:+lf+))))
    (funcall test
             (ensure-last-lf out-string)
             (with-output-to-string (out)
               (let ((*standard-output* out))
                 (with-input-from-string (*standard-input* (ensure-last-lf in-string))
                   (funcall function)))))))

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))
#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *this-pathname*))

#+swank
(defun run (&optional thing (out *standard-output*))
  "THING := null | string | symbol | pathname

null: run #'MAIN using the text on clipboard as input.
string: run #'MAIN using the string as input.
symbol: alias of FIVEAM:RUN!.
pathname: run #'MAIN using the text file as input."
  (let ((*standard-output* out))
    (etypecase thing
      (null
       (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
         (main)))
      (string
       (with-input-from-string (*standard-input* (delete #\Return thing))
         (main)))
      (symbol (5am:run! thing))
      (pathname
       (with-open-file (*standard-input* thing)
         (main))))))

#+swank
(defun gen-dat ()
  (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)
    (format out "")))

#+swank
(defun bench (&optional (out (make-broadcast-stream)))
  (time (run *dat-pathname* out)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "1 10
3 5
"
    "3
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "2 10
3 5
2 6
"
    "2
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "4 1000000000
1 1
1 10000000
1 30000000
1 99999999
"
    "860000004
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "5 500
35 44
28 83
46 62
31 79
40 43
"
    "9
")))

Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:

Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.

Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.

The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Constraints

1 ≤ N ≤ 10^5

1 ≤ H ≤ 10^9

1 ≤ a_i ≤ b_i ≤ 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N H
a_1 b_1
:
a_N b_N

Output

Print the minimum total number of attacks required to vanish the monster.

Sample Input 1

1 10
3 5

Sample Output 1

3

You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.

Sample Input 2

2 10
3 5
2 6

Sample Output 2

2

In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.

Sample Input 3

4 1000000000
1 1
1 10000000
1 30000000
1 99999999

Sample Output 3

860000004

Sample Input 4

5 500
35 44
28 83
46 62
31 79
40 43

Sample Output 4

9


(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-int:defconstant-eqx OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))
    #'equal)
  #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
  #-swank (set-dispatch-macro-character
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setq minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(defun main ()
  (declare (inline sort))
  (let* ((n (read))
         (h (read))
         (as (make-array n :element-type 'uint32))
         (bs (make-array n :element-type 'uint32)))
    (dotimes (i n)
      (setf (aref as i) (read-fixnum)
            (aref bs i) (read-fixnum)))
    (setq bs (sort bs #'>))
    (let ((max-a (reduce #'max as)))
      (loop for i below n
            for b = (aref bs i)
            while (and (> b max-a) (> h 0))
            do (decf h b)
            finally (println (+ i (ceiling h max-a)))))))

#-swank (main)

;;;
;;; Test and benchmark
;;;

#+swank
(defun io-equal (in-string out-string &key (function #'main) (test #'equal))
  "Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if
the string output to *STANDARD-OUTPUT* is equal to OUT-STRING."
  (labels ((ensure-last-lf (s)
             (if (eql (uiop:last-char s) #\Linefeed)
                 s
                 (uiop:strcat s uiop:+lf+))))
    (funcall test
             (ensure-last-lf out-string)
             (with-output-to-string (out)
               (let ((*standard-output* out))
                 (with-input-from-string (*standard-input* (ensure-last-lf in-string))
                   (funcall function)))))))

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))
#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *this-pathname*))

#+swank
(defun run (&optional thing (out *standard-output*))
  "THING := null | string | symbol | pathname

null: run #'MAIN using the text on clipboard as input.
string: run #'MAIN using the string as input.
symbol: alias of FIVEAM:RUN!.
pathname: run #'MAIN using the text file as input."
  (let ((*standard-output* out))
    (etypecase thing
      (null
       (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
         (main)))
      (string
       (with-input-from-string (*standard-input* (delete #\Return thing))
         (main)))
      (symbol (5am:run! thing))
      (pathname
       (with-open-file (*standard-input* thing)
         (main))))))

#+swank
(defun gen-dat ()
  (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)
    (format out "")))

#+swank
(defun bench (&optional (out (make-broadcast-stream)))
  (time (run *dat-pathname* out)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "1 10
3 5
"
    "3
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "2 10
3 5
2 6
"
    "2
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "4 1000000000
1 1
1 10000000
1 30000000
1 99999999
"
    "860000004
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "5 500
35 44
28 83
46 62
31 79
40 43
"
    "9
")))


(let* ((n (read))
       (h (read))
       (lst (loop :repeat n :collect (cons (read) (read))))
       (tw (reduce #'+ lst :key #'cdr)))
  (princ (if (< h tw)
             (1+ (loop :for k :in (sort lst #'> :key #'cdr)
                       :with a = 0 :count (if (< (+ a (cdr k)) h)
                                              (incf a (cdr k)))))
             (let* ((mx (reduce #'max lst :key #'car))
                    (x (mapcar #'cdr (remove-if (lambda (k) (< k mx)) lst :key #'cdr))))
               (+ (length x) (ceiling (- h (reduce #'+ x)) mx))))))


(let* ((n (read))
       (h (read))
       (lst (loop :repeat n :collect (cons (read) (read))))
       (tw (reduce #'+ lst :key #'cdr)))
  (princ (if (< h tw)
             (1+ (loop :for k :in lst :with a = 0 :count (if (< (+ a (cdr k)) h)
                                                         (incf a (cdr k)))))
             (+ n (ceiling (- h tw) (reduce #'max lst :key #'car))))))


;; -*- coding:utf-8 -*-

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter O3 '(optimize (speed 3) (safety 0) (debug 0)))
  (defparameter O2 '(optimize (speed 3) (safety 1))))

(defmacro print-line (obj &optional (stream '*standard-output*))
  `(prog1 (princ ,obj ,stream) (terpri ,stream)))

;; Hauptteil

(defmacro split-and-bind (arg-lst string &body body)
  (let ((pos1 (gensym "POS"))
	(pos2 (gensym "POS"))
	(str-evaled (gensym "STR")))
    (labels ((expand (arg-lst &optional (init-pos1 t))
	       (if (null arg-lst)
		   body
		   `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))
			    (,pos2 (position #\space ,str-evaled :start ,pos1 :test #'char=))
			    (,(car arg-lst) (parse-integer ,str-evaled :start ,pos1 :end ,pos2)))
		       ,@(expand (cdr arg-lst) nil))))))
      `(let ((,str-evaled ,string))
	 ,@(expand arg-lst)))))

(deftype unum () '(integer 0 1000000000))

(defun qsort (arr)
  (declare #.O3
	   ((simple-array unum) arr))
  (labels ((quicksort (arr lo hi)
	     (declare (unum hi lo)
		      ((simple-array unum) arr))
	     (if (> hi lo)
		 (let* ((mid (round (+ lo hi) 2))
			(i lo)
			(j (+ hi 1))
			(p (aref arr mid)))
		   (declare (unum i j))
		   (rotatef (aref arr mid) (aref arr lo))
		   (loop
		      (loop do (incf i)
			 until (or (> i hi)
				   (> p (aref arr i)))) ; beliebige Präd.
		      (loop do (decf j)
			 until (or (<= j lo)
				   (> (aref arr j) p))) ; beliebige Präd.
		      (if (< j i) (return))
		      (rotatef (aref arr i)(aref arr j)))
		   (rotatef (aref arr lo) (aref arr j))
		   (quicksort arr lo (- j 1))
		   (quicksort arr i hi)))
	     arr))
    (quicksort arr 0 (- (length arr) 1))))

(defun main ()
  (declare #.O3)
  (let* ((n (the unum (read)))
	 (init-hp (read))
	 (max-a 0)
	 (arr-b (make-array n :element-type 'unum)))
    (dotimes (idx n)
      (split-and-bind (a b) (the string (read-line))
	(declare (unum a b))
	(when (>= a max-a) (setf max-a a))
	(setf (aref arr-b idx) b)))
    (let* ((arr-b (qsort arr-b)))
      (declare ((simple-array unum) arr-b))
      (print-line
       (loop with hp of-type fixnum = init-hp
	  for idx of-type unum from 0 below n
	  until (> max-a (aref arr-b idx))
	  do (decf hp (aref arr-b idx))
	    (when (<= hp 0)
	      (return (+ idx 1)))
	  finally (return (+ idx
			     (ceiling (max hp 0) max-a))))))))

#-swank(main)

;; Für Test
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))

(defun test ()
  (with-input-from-string (*standard-input* (delete #\return (get-clipbrd)))
    (main)))

;; Für Benchmark
(defparameter *file-path* *load-pathname*)
(defparameter *dir-path* (pathname (directory-namestring *file-path*)))
(defparameter *dat-path* (merge-pathnames "test.dat" *dir-path*))

#+swank
(with-open-file (out *dat-path*
		     :direction :output :if-exists :supersede)
  )

(defun bench ()
  (let ((*standard-output* (make-broadcast-stream)))
    (with-open-file (*standard-input* *dat-path*)
      (time (main)))))


;; -*- coding:utf-8 -*-

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter O3 '(optimize (speed 3) (safety 0) (debug 0)))
  (defparameter O2 '(optimize (speed 3) (safety 1))))

(defmacro print-line (obj &optional (stream '*standard-output*))
  `(prog1 (princ ,obj ,stream) (terpri ,stream)))

;; Hauptteil

(defmacro split-and-bind (arg-lst string &body body)
  (let ((pos1 (gensym "POS"))
	(pos2 (gensym "POS"))
	(str-evaled (gensym "STR")))
    (labels ((expand (arg-lst &optional (init-pos1 t))
	       (if (null arg-lst)
		   body
		   `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))
			    (,pos2 (position #\space ,str-evaled :start ,pos1 :test #'char=))
			    (,(car arg-lst) (parse-integer ,str-evaled :start ,pos1 :end ,pos2)))
		       ,@(expand (cdr arg-lst) nil))))))
      `(let ((,str-evaled ,string))
	 ,@(expand arg-lst)))))

(deftype unum () '(integer 0 1000000000))
(defun main ()
  (declare #.O3)
  (let* ((n (the unum (read)))
	 (init-hp (read))
	 (max-a 0)
	 (lst-b nil))
    (dotimes (idx n)
      (split-and-bind (a b) (the string (read-line))
	(declare (unum a b))
	(when (>= a max-a) (setf max-a a))
	(push b lst-b)))
    (let* ((lst-b (sort lst-b #'>)))
      (print-line
       (loop with hp of-type fixnum = init-hp
	  with b-throw of-type unum = 0
	  for b of-type unum in lst-b
	  until (> max-a b)
	  do (incf b-throw)
	    (decf hp b)
	  until (<= hp 0)
	  finally (return (+ b-throw
			     (ceiling (max hp 0) max-a))))))))

#-swank(main)

;; Für Test
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))

(defun test ()
  (with-input-from-string (*standard-input* (delete #\return (get-clipbrd)))
    (main)))

;; Für Benchmark
(defparameter *file-path* *load-pathname*)
(defparameter *dir-path* (pathname (directory-namestring *file-path*)))
(defparameter *dat-path* (merge-pathnames "test.dat" *dir-path*))

#+swank
(with-open-file (out *dat-path*
		     :direction :output :if-exists :supersede)
  )

(defun bench ()
  (let ((*standard-output* (make-broadcast-stream)))
    (with-open-file (*standard-input* *dat-path*)
      (time (main)))))


;; -*- coding:utf-8 -*-

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter O3 '(optimize (speed 3) (safety 0) (debug 0)))
  (defparameter O2 '(optimize (speed 3) (safety 1))))

(defmacro print-line (obj &optional (stream '*standard-output*))
  `(prog1 (princ ,obj ,stream) (terpri ,stream)))

;; Hauptteil

(defmacro split-and-bind (arg-lst string &body body)
  (let ((pos1 (gensym "POS"))
	(pos2 (gensym "POS"))
	(str-evaled (gensym "STR")))
    (labels ((expand (arg-lst &optional (init-pos1 t))
	       (if (null arg-lst)
		   `(progn ,@body)
		   `(let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))
			   (,pos2 (position #\space ,str-evaled :start ,pos1 :test #'char=))
			   (,(car arg-lst) (parse-integer ,str-evaled :start ,pos1 :end ,pos2)))
		      ,(expand (cdr arg-lst) nil)))))
      `(let ((,str-evaled ,string))
	 ,(expand arg-lst)))))

(deftype unum () '(integer 0 1000000000))
(defun main ()
  (declare #.O3)
  (let* ((n (read))
	 (init-hp (read))
	 (arr-a (make-array n :element-type 'fixnum))
	 (arr-b (make-array n :element-type 'fixnum)))
    (dotimes (idx n)
      (split-and-bind (a b) (the string (read-line))
	(setf (aref arr-a idx) a
	      (aref arr-b idx) b)))
    (let* ((max-a (loop for idx from 0 below n maximize (aref arr-a idx)))
	   (arr-b (sort arr-b #'>=))
	   (end-idx (loop for idx from 0
		       do (cond ((= idx n) (return n))
				((> max-a (aref arr-b idx))
				 (return idx))))))
      (print-line
       (loop for idx of-type unum from 0 below end-idx
	  and hp of-type fixnum = init-hp then (- hp (aref arr-b idx))
	  until (<= hp 0)
	  finally (return (+ idx
			     (ceiling (max hp 0) max-a))))))))

#-swank(main)

;; Für Test
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))

(defun test ()
  (with-input-from-string (*standard-input* (delete #\return (get-clipbrd)))
    (main)))

;; Für Benchmark
(defparameter *file-path* *load-pathname*)
(defparameter *dir-path* (pathname (directory-namestring *file-path*)))
(defparameter *dat-path* (merge-pathnames "test.dat" *dir-path*))

#+swank
(with-open-file (out *dat-path*
		     :direction :output :if-exists :supersede)
  )

(defun bench ()
  (let ((*standard-output* (make-broadcast-stream)))
    (with-open-file (*standard-input* *dat-path*)
      (time (main)))))


(defun find-sum (n)
  (let ((sum 0))
    (while (> n 0)
      (setf sum (+ sum (rem n 10)))
      (setf n (floor n 10)))
    sum))

(defun some-sums (n a b)
  (let ((ans 0)
        (sum 0))
    (dotimes (i (+ n 1))
      (setf sum (find-sum i))
      (if (and (>= sum a) (<= sum b))
        (setf ans (+ ans i))))
    ans))

(format t "~A~%" (some-sums (read) (read) (read)))

Score : 200 points

Problem Statement

Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Constraints

1 \leq N \leq 10^4

1 \leq A \leq B \leq 36

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Sample Input 1

20 2 5

Sample Output 1

84

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.

Sample Input 2

10 1 2

Sample Output 2

13

Sample Input 3

100 4 16

Sample Output 3

4554


(defmacro while (test &body body)
  `(do ()
       ((not ,test))
     ,@body))

(defun find-sum (n)
	(let ((sum 0))
		(while (> n 0)
			(setf sum (+ sum (rem n 10)))
			(setf n (floor n 10))
		)
	sum
	)
)

(defun some-sums (n a b)
	(let ((ans 0) (sum 0))
	(dotimes (i (+ n 1))
		(setf sum (find-sum (i)))
		(if (and (>= sum a) (<= sum b))
			(setf ans (+ ans i))
		)
	)
	ans
	)
)

(format t "~A~%" (some-sums ((read) (read) (read))))


(defun some-sums (n a b)
	(let ((ans 0 sum 0))
	(dotimes (i (+ n 1))
		(setf sum (finds-some (i)))
		(if (and (>= sum a) (<= sum b) )
			(setf total (+ total i))
		)
	)
	total
	)
)

(defun find-sum (n)
	(let ((sum 0))
		(while (> n 0)
			(setf sum (+ sum (rem n 10)))
			(setf n (floor n 10))
		)
	sum
	)
)

(format t "~D~%" (some-sums (read) (read) (read)))


#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main (str)
  (count #\1 str))

(defun func (x)
  (loop for x across (write-to-string x)
        sum (- (char-code x) (char-code #\0))))

(defun main (n min max)
  (loop for i from 1 to n
        for v = (func i)
        when (<= min v max)
          sum i))

(princ (main (read) (read) (read)))


(defvar N)
(setf N (read))

(defun range (m n &optional l)
  (if (< n m) l
      (range m (1- n) (cons n l)) ))

(defun sum_digit (N)
  (reduce #'(lambda (sum s)
                    (+ sum (digit-char-p s)))
          (write-to-string N) :initial-value 0))

(let ((a (read))
      (b (read)))
     (defun in[a.b] (x) (and (<= a x) (<= x b))))

(princ
 (reduce #'+
         (remove-if-not
          (lambda (x) (in[a.b] (sum_digit x)))
         (range 1 N))
 :initial-value 0 ))


(princ (loop :for k :from 1 :upto (read) :with a := (read) :with b := (read)
             :for x := (loop :for l :from (1+ (floor (log k 10))) :downto 1
                             :for j := k :then (mod j (expt 10 l))
                             :sum (floor j (expt 10 (1- l))))
             :if (<= a x b) :sum k))


(defun counting (n)
  (if (eq n 0)
      0
      (+ (rem n 10) (counting (floor n 10)))))

(defun some-sums (n a b)
  (if (and
       (<= a (counting n))
       (>= b (counting n)))
      (+ n (some-sums (1- n) a b))
      (some-sums (1- n) a b)))

(format t "~A~%" (some-sums (read) (read) (read)))


(defmacro while (condition &body body)
  `(do ()
       ((not ,condition))
     ,@body))

(defun counting (n)
  (let ((sum 0))
    (while (> n 0)
      (setf sum (+ sum (rem n 10)))
      (setf n (floor n 10)))
    sum))

(defun some-sums ()
    (let ((n (1+ (read)))
	  (a (read))
	  (b (read))
	  (ans 0))
      (dotimes (i n)
	(if (and
	     (>= (counting i) a)
	     (<= (counting i) b))
	    (setf ans (+ ans i))))
      ans))

(format t "~A~%" (some-sums))


(defmacro while (condition &body body)
  `(do ()
       ((not ,condition))
     ,@body))

(defun counting (n)
  (let ((sum 0))
    (while (> n 0)
      (setf sum (+ sum (rem n 10)))
      (setf n (floor n 10)))
    sum))

(defun some-sums ()
    (let ((n (1+ (read)))
	  (a (read))
	  (b (read))
	  (ans 0))
      (dotimes (i n)
	(if (and
	     (>= (counting i) a)
	     (<= (counting i) b))
	    (incf ans)))
      ans))

(format t "~A~%" (some-sums))


(defun sum (x)
  (let ((ret 0))
    (loop
       (if (zerop x) (return))
       (setf ret (+ ret (rem x 10)))
       (setf x (floor x 10)))
    ret))

(defun fun (n a b)
  (let ((ans 0)
	(x 0))
    (dotimes (i (1+ n))
      (setf x (sum i))
      (if (and
	   (<= a x)
	   (>= b x))
	  (setf ans (+ ans x))))
    ans))

(format t "~A~%" (fun (read) (read) (read)))


(defun sum (x)
  (let ((ret 0))
    (loop
       (if (zerop x) (return))
       (setf ret (+ ret (rem x 10)))
       (setf x (floor x 10)))
    ret))

(defun fun (n a b)
  (let ((ans 0)
	(x 0))
    (dotimes (i (1+ n))
      (setf x (sum i))
      (if (and
	   (<= a x)
	   (>= b x))
	  (incf ans)))
    ans))

(format t "~A~%" (fun (read) (read) (read)))


(defun f(x)
    (if (< x 10)
        x
        (+ (rem x 10) (f (floor (/ x 10))))))
(defun g (x a b)
    (and (>= x a) (<= x b)))
(let ((n (read))
      (a (read))
      (b (read))
      (ans 0))

      (loop :for i :from 1 :to n :do (when (g (f i) a b) (setf ans (+ ans i))))
      (princ ans)
      )


(defun f (k)
  (+ (loop :for a :from 4 :downto 1 :sum(mod (floor k (* 10 a)) (* 10 a))) (mod k 10)))
(let ((n (read))
      (a (read))
      (b (read)))
  (princ (reduce #'+ (remove-if-not (lambda (q) (<= a (f q) b)) (loop :for x :from 1 :upto n :collect x)))))


(let((n(read))(a(read))(b(read))(s 0))
  (loop for i from 1 to n do
		(setq m(apply #'+(mapcar #'(lambda(c)(-(char-int c)48))(concatenate 'list (princ-to-string i)))))
		(if(and(>= m a)(<= m b))(incf s i)))
  (princ s))


(defmacro while (test &body body)
  `(do ()
       ((not ,test))
     ,@body))

(defun find-sum-of-digits (n)
  (let ((sum 0))
    (while (> n 0)
      (setf sum (+ sum (rem n 10)))
      (setf n (floor n 10)))
    sum))

(defun some-sums (n a b)
  (let ((total 0)
        (sum 0))
    (dotimes (i (+ n 1))
      (setf sum (find-sum-of-digits i))
      (if (and (>= sum a) (<= sum b))
          (setf total (+ total i))))
    total))

(format t "~A~%" (some-sums (read) (read) (read)))


(defun digit-sum (n)
  (labels ((inner (m rv)
             (cond
               ((zerop m) rv)
               (t
                (multiple-value-bind (q r) (floor m 10)
                  (inner q (+ rv r)))))))
    (inner n 0)))

(defparameter sums
  (loop for n from 0 upto 10000
        collect `(,n ,(digit-sum n))))

(defun filter-sum (n a b)
  (let ((k (if (< 10001 n)
               10001
               (1+ n))))
    (remove-if-not #'(lambda (m) (<= a m b))
                   (subseq sums 0 k)
                   :key #'cadr)))

(defun answer (n a b)
  (loop for k in (filter-sum n a b)
        sum (car k)))

(let ((n (read)) (a (read)) (b (read)))
  (format t "~a~%" (answer n a b)))


(format t "~A~%" (loop for s across (read-line)
      count (eq s #\1)))

Score : 100 points

Problem Statement

Snuke has a grid consisting of three squares numbered 1, 2 and 3.
In each square, either 0 or 1 is written. The number written in Square i is s_i.

Snuke will place a marble on each square that says 1.
Find the number of squares on which Snuke will place a marble.

Constraints

Each of s_1, s_2 and s_3 is either 1 or 0.

Input

Input is given from Standard Input in the following format:

s_{1}s_{2}s_{3}

Output

Print the answer.

Sample Input 1

101

Sample Output 1

2

A marble will be placed on Square 1 and 3.

Sample Input 2

000

Sample Output 2

0

No marble will be placed on any square.


(defun placing-marbles (s)
  (let ((counter 0))
    (loop :for c :across s
          :do (if (string= c "1") (incf counter)))
    counter))

(format t "~A~%" (placing-marbles (read-line)))


(defun placing-marbles (s)
  (loop :for c :across s
        :count (char= c #\1)))

(format t "~A~%" (placing-marbles (read-line)))


(defun placing-marbles (s)
  (loop :for c
        :across s
        :count (=string c "1")))

(format t "~A~%" (placing-marbles (read-line)))(defun placing-marbles (s)
  (loop :for c
        :across s
        :count (=char c #\1)))

(format t "~A~%" (placing-marbles (read-line)))


(defun placing-marbles ()
  (let ((s (read-line))
        (counter 0))
    (loop for i across s
       do (if (string= i "1") (incf counter)))
    counter))

(format t "~D~%" (placing-marbles))


(princ (loop :for k :across (read-line) :count (char= #\1 k)))


(defun fun (s)
  (loop :for c :across s
     :count (char= c #\1)))

(format t "~A~%" (fun (read-line)))


(defun fun (s)
  (loop :for c :across s
     :count (char= c #\1)))

(format t "~A~%" (fun (read)))


(defun func (x)
	(if x
		(+
			(if (string= (car x) "0")
				0
				1)
			(func (cdr x)))
		0))

(write (func (concatenate 'list (read-line))))


(defparameter N (read-line))

(format t "~a" (count-if #'oddp
                         (map 'list (lambda (x) (digit-char-p x 16))
                              N)))


(defun placing-marbels (s)
	(let ((counter 0))
		(loop :for c :across s
			  :do (if (string= c "1") (incf counter)))
		counter))

(format t "~A~%" (placing-marbels (read-line)))


(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))

;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))
(defmacro aif (test-form then-form &optional else-form)
  `(let ((it ,test-form))
     (if it ,then-form ,else-form)))

;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))
(defmacro read-str ()
  `(write-to-string (read)))

;;本体
(defun ctoi (c)
  (- (char-code c) (char-code #\0)))
(defun main()
  (println (reduce #'+ (map 'list #'ctoi (read-str)))))

#-swank(main)


;; 写経
(defun placing-marbles (s)
  (let ((counter 0))
    (loop :for c :across s
	  :do (if (string= c "1") (incf counter)))
    counter))

(defun placing-marbles2 (s)
  (loop :for c :across s
	:count (char= c #\1)))

(format t "~a~%" (placing-marbles2 (read-line)))


(defun placing-marbles (s)
  (count #\1 (read-line)))

(format t "~A~%" (placing-marbles (read-line)))


(format t "~A~%" (count #\1 (read-line)))


(defun count_one (str index)
  (if (<= (length str) index) 0
    (if (equal (elt str index) #\0)
      (count_one str (+ index 1))
      (+ 1 (count_one str (+ index 1)))
      )))

(format t "~A~%" (count_one (read-line) 0))


(setq a (read))
(setq b (+ (truncate (/ a 100)) (mod (truncate (/ a 10)) 10) (mod a 10)))
(print b)


(let ((s (read-line)))
  (format t "~A~%"
          (loop for ch across s sum (- (char-code ch)
                                       (char-code #\0)))))


(let* ((n (read-line))
       (s (read-line))
       (a nil))
  (defun f-equal (a b)
    (reduce (lambda (x y) (and x y))
            (map 'list (lambda (x y) (if (char= #\? x)
                                               t (char= x y))) a b)))
  (setf a (position t (loop :for k :from 0 :to (- (length n) (length s)) :collect (f-equal (subseq n k (+ k (length s))) s)) :from-end t))
  (if a
      (princ (map 'string (lambda (k) (if (char= #\? k) #\a k)) (concatenate 'string (subseq n 0 a) s (subseq n (+ a (length s)))) ))
      (princ "UNRESTORABLE")))

Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.

One more thing he found is a sheet of paper with the following facts written on it:

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.


(let* ((h (read))
    (w (read))
    (s (make-array (list (+ h 2) (+ w 2)) :initial-element "0")))

    (loop for i below h do
        (let ((a (read-line)))
            (loop for j below w do
                (setf (aref s (+ i 1) (+ j 1)) (char a j))
            )
        )
    )
    (loop for i from 1 to h do
        (loop for j from 1 to w do
            (let ((ans 0))
                (if (string= (aref s i j) ".")
                    (progn
                        (loop for k from (- i 1) to (+ i 1) do
                            (loop for l from (- j 1) to (+ j 1) do
                                (if (string= (aref s k l) "#")
                                    (incf ans)
                                )
                            )
                        )
                        (format t "~D" ans)
                    )
                    (format t "#")
                )
            )
        )
        (format t "~%")
    )
)

Score : 200 points

Problem Statement

You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).

. stands for an empty square, and # stands for a square containing a bomb.

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.

Print the strings after the process.

Constraints

1 \leq H,W \leq 50

S_i is a string of length W consisting of # and ..

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).

Sample Input 1

3 5
.....
.#.#.
.....

Sample Output 1

11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.

Sample Input 2

3 5
#####
#####
#####

Sample Output 2

#####
#####
#####

It is possible that there is no empty square.

Sample Input 3

6 6
#####.
#.#.##
####.#
.#..#.
#.##..
#.#...

Sample Output 3

#####3
#8#7##
####5#
4#65#2
#5##21
#4#310


(defun split (x str)
  (let ((size (length x))
	(retval nil))
    (loop
       :with pos = (search x str)
       :if pos
       :do
	 (push (subseq str 0 pos) retval)
	 (setq str (subseq str (+ size pos)))
	 (setq pos (search x str))
       :else
       :do (return (reverse (push str retval))))))

(defun numbers-by-readline ()
  (mapcar #'parse-integer (split " " (read-line))))

(defconstant blank 0)
(defconstant mine 1)

(defun neighbors (pos w)
  (remove-if #'null
	     (list (if (= (mod pos w) 0) nil (- pos w 1))
		   (- pos w)
		   (if (= (mod pos w) (1- w)) nil (- pos w -1))
		   (if (= (mod pos w) 0) nil (- pos 1))
		   (if (= (mod pos w) (1- w)) nil (+ pos 1))
		   (if (= (mod pos w) 0) nil (+ pos w -1))
		   (+ pos w)
		   (if (= (mod pos w) (1- w)) nil (+ pos w 1)))))

(defun full-inputs ()
  (let ((size (numbers-by-readline)))
    (values
     size
     (format nil "~{~A~}" (loop :repeat (car size) :collect (read-line))))))

(defun find-mine (board w)
  (loop
     :for i :below (length board)
     :collect
       (if (equal (aref board i) #\#)
	   #\#
	   (mapcar #'(lambda (x)
		       (if (equal (aref board x) #\#)
			   mine
			   blank))
		   (remove-if #'(lambda (x)
				  (or (< x 0) (>= x (length board))))
			      (neighbors i w))))))

(defun reshape (l)
  (mapcar #'(lambda (x)
	      (if (listp x)
		  (reduce #'+ x)
		  x))
	  l))

(defun show-result (s w)
  (labels ((f (w)
	     (concatenate 'string "~{~<~%~," (princ-to-string w) ":;~A~>~}")))
    (format t (f w) s)))

(defun mine-sweeper ()
  (multiple-value-bind (s b) (full-inputs)
    (show-result (reshape (find-mine b (cadr s))) (cadr s))))

(mine-sweeper)


(defparameter *dx-dy*
  '((-1 . -1)
    (-1 . 0)
    (-1 . 1)
    (0 . -1)
    (0 . 1)
    (1 . -1)
    (1 . 0)
    (1 . 1)))

(defun solve (h w board)
  (declare (optimize speed))
  (labels ((count-mine (y x board &optional (cnt 0))
             (dotimes (d 8 cnt)
               (let ((nx (+ x (first (nth d *dx-dy*))))
                     (ny (+ y (rest (nth d *dx-dy*)))))
                 (when (and (<= 0 nx (1- w))
                            (<= 0 ny (1- h))
                            (char-equal (aref (aref board ny) nx) #\#))
                   (incf cnt))))))
    (dotimes (i h)
      (dotimes (j w)
        (unless (char-equal (aref (aref board i) j) #\#)
          (setf (aref (aref board i) j) (digit-char (count-mine i j board))))))
    board))

(defun main ()
  (declare (optimize speed))
  (let* ((h (read))
         (w (read))
         (board (make-array h :initial-element "")))
    (dotimes (i h)
      (setf (aref board i) (read-line)))
    (let ((ans (solve h w board)))
      (dotimes (i h)
        (fresh-line)
        (princ (aref ans i))))
    (fresh-line)))

(main)


(defparameter *dx-dy*
  '((-1 . -1)
    (-1 . 0)
    (-1 . 1)
    (0 . -1)
    (0 . 1)
    (1 . -1)
    (1 . 0)
    (1 . 1)))

(defun solve (h w board)
  (labels ((count-mine (y x board &optional (cnt 0))
             (dotimes (d 8 cnt)
               (let ((nx (+ x (first (nth d *dx-dy*))))
                     (ny (+ y (rest (nth d *dx-dy*)))))
                 (when (and (<= 0 nx (1- w))
                            (<= 0 ny (1- h))
                            (char-equal (aref (aref board ny) nx) #\#))
                   (incf cnt))))))
    (dotimes (i h)
      (dotimes (j w)
        (unless (char-equal (aref (aref board i) j) #\#)
          (setf (aref (aref board i) j) (digit-char (count-mine i j board))))))
    board))

(defun main ()
  (let* ((h (read))
         (w (read))
         (board (make-array h :initial-element "")))
    (dotimes (i h)
      (setf (aref board i) (read-line)))
    (let ((ans (solve h w board)))
      (dotimes (i h)
        (fresh-line)
        (princ (aref ans i))))
    (fresh-line)))

(main)


(defun get-input-array-string (n)
  (let ((input-array (make-array n)))
    (dotimes (i n)
      (setf (aref input-array i) (read-line)))
    input-array))

(defun main (h w)
  (let* ((rst 0)
         (input-array (get-input-array-string h)))
    (loop for x from 0 to (- h 1)
          do (loop for y from 0 to (- w 1)
                   do (setf rst 0)
                   if (string= (aref (aref input-array x) y) #\.)
                   do (progn (loop for dx from (- x 1) to (+ x 1)
                                   do (loop for dy from (- y 1) to (+ y 1)
                                            if (and (>= dx 0) (<= dx (- h 1)) (>= dy 0) (<= dy (- w 1)))
                                            do (progn (if (string= (aref (aref input-array dx) dy) #\#)
                                                          (incf rst)))))
                        (setf (aref (aref input-array x) y)
                              (aref (write-to-string rst) 0)))
                   ))
    input-array))

  (let* ((h (read))
         (result (main h (read))))
    (dotimes (i h)
      (format t "~A~%" (aref result i))))


(let* ((n (read))
       (m (read))
       (lst (make-array (list n m) :initial-contents (loop :repeat n :collect (concatenate 'list (read-line)))))
       (ans (make-array (list n m) :initial-element 0)))
  (defun accessor (x y)
    (if (and (<= 0 x (1- n)) (<= 0 y (1- m)))
        (if (char= #\. (aref lst x y))
            (incf (aref ans x y))
            (setf (aref ans x y) #\#))))
  (loop :for y :from 0 :upto (1- m)
        :do(loop :for x :from 0 :upto (1- n) :do(if (char= #\# (aref lst x y))
                                               (loop :for p :from (1- y) :upto (1+ y)
                                                     :do(loop :for q :from (1- x) :upto (1+ x) :do(accessor q p))))))
  (loop :for x :from 0 :upto (1- n) :do(loop :for y :from 0 :upto (1- m) :do(princ (aref ans x y))) :do (format t "~%")))


(defun read-list (x &optional ret)
  (if (< x 1)
    ret
    (read-list (1- x) (cons (read) (cons (read) ret)))))

(defun count-people (lst &optional (ans 0))
  (if (null lst)
    ans
    (count-people (cddr lst) (+ (1+ (- (cadr lst) (car lst))) ans))))

(let* ((n (read))
       (l (read-list n)))

  (format t "~A~%"
          (count-people l)))

Score : 200 points

Problem Statement

Joisino is working as a receptionist at a theater.

The theater has 100000 seats, numbered from 1 to 100000.

According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).

How many people are sitting at the theater now?

Constraints

1≤N≤1000

1≤l_i≤r_i≤100000

No seat is occupied by more than one person.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
l_1 r_1
:
l_N r_N

Output

Print the number of people sitting at the theater.

Sample Input 1

1
24 30

Sample Output 1

7

There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30.

Sample Input 2

2
6 8
3 3

Sample Output 2

4


(defun read-list (x &optional ret)
  (if (< x 1)
    ret
    (read-list (1- x) (cons (read) (cons (read) ret)))))

(defun count-people (lst &optional (ans 0))
  (if (null lst)
    ans
    (count-people (cddr lst) (+ (1+ (- (cadr lst) (car lst))) ans))))

(let* ((n (read))
       (l (read-list n)))

  (format t "~A~%" l)

  (format t "~A~%"
          (count-people l)))


#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(let ((n (read)))
  (princ (loop repeat n sum (- 1 (- (read) (read))))))


(princ (loop :repeat (read) :sum (+ (* -1 (read)) (read) 1)))


(let* ((n (read))
       (total 0))
  (dotimes (i n)
    (incf total (1+ (abs (- (read) (read))))))
  (format t "~A~%" total))


(loop repeat (read)
      sum (1+ (+ (- (read)) (read))) into ans
      finally (format t "~A~%" ans))


(let ((s (sort (remove-duplicates (concatenate 'list (read-line))
                                  :test #'char=)
               #'char-lessp))
      (alp (concatenate 'list "abcdefghijklmnopqrstuvwxyz")))

  (defun f (lst1 lst2)
    (if (null lst2)
      "None"
      (if (null lst1)
        (car lst2)
        (if (not (char= (car lst1) (car lst2)))
          (car lst2)
          (f (cdr lst1) (cdr lst2))))))

  (format t "~A~%"
          (f s alp)))

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Constraints

1 \leq |S| \leq 10^5 (|S| is the length of string S.)

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the lexicographically smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Sample Input 1

atcoderregularcontest

Sample Output 1

b

The string atcoderregularcontest contains a, but does not contain b.

Sample Input 2

abcdefghijklmnopqrstuvwxyz

Sample Output 2

None

This string contains every lowercase English letter.

Sample Input 3

fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg

Sample Output 3

d


(let ((s (sort (remove-duplicates (concatenate 'list (read-line))
                                  :test #'char=)
               #'char-lessp))
      (alp (concatenate 'list "abcdefghijklmnopqrstuvwxyz")))

  (defun f (lst1 lst2)
    (if (null lst1)
      "None"
      (if (not (char= (car lst1) (car lst2)))
        (car lst2)
        (f (cdr lst1) (cdr lst2)))))

  (format t "~A~%"
          (f s alp)))


(let ((lst (mapcar #'char-code (concatenate 'list (read-line)))))
  (defun f (k)
    (cond ((= k 123) (princ "None"))
          (t (if (find k lst) (f (1+ k)) (princ (code-char k))))))
  (f 97))


(let((s(read-line))(c"None"))
  (loop for i from 122 downto 97 do(if(find(code-char i)s)()(setq c(string(code-char i)))))
  (princ c))


(defun alphabet-index (ch)
  (- (char-code ch) (char-code #\a)))

(let ((s (read-line))
      (seq (make-array 26 :initial-element nil)))
  (dotimes (i (length s))
    (let ((ch (char s i)))
      (setf (aref seq (alphabet-index ch))
            t)))
  (loop for i from 0 below 26
        unless (aref seq i) do
        (format t "~A~%" (code-char (+ (char-code #\a) i)))
        (return)
        finally (format t "None~%")))


(defun alphabet-index (ch)
  (- (char-code ch) (char-code #\a)))

(let ((s (read-line))
      (seq (make-array 26 :initial-element nil)))
  (dotimes (i (length s))
    (let ((ch (char s i)))
      (setf (aref seq (alphabet-index ch))
            t)))
  (let ((end nil))
    (loop until end
          for i from 25 downto 0
          when (aref seq i) do
          (setf end i))
    (loop for i from 0 below end
          unless (aref seq i) do
          (format t "~A~%" (code-char (+ (char-code #\a) i)))
          (return)
          finally (format t "None~%"))))


(defun alphabet-index (ch)
  (- (char-code ch) (char-code #\a)))

(let ((s (read-line))
      (seq (make-array 26 :initial-element nil)))
  (dotimes (i (length s))
    (let ((ch (char s i)))
      (setf (aref seq (alphabet-index ch))
            t)))
  (let ((start nil)
        (end nil))
    (loop until start
          for i from 0 below 26
          when (aref seq i) do
          (setf start i))
    (loop until end
          for i from 25 downto 0
          when (aref seq i) do
          (setf end i))
    (loop for i from start below end
          unless (aref seq i) do
          (format t "~A~%" (code-char (+ (char-code #\a) i)))
          (return)
          finally (format t "None~%"))))


(format t "~A~%" (let* ((S (coerce (read-line) 'list))
                       (a (find-if-not (lambda (x)
                                         (member x S))
                                       (loop for n from 97 to 122
                                             collect (code-char n)))))
                      (if a
                          a
                          "None")))


(defun main ()
  (let ((S (read-line))
        (arr (make-array 26 :element-type 'fixnum))
        (a-int (char-int #\a)))
    (loop for c across S do
      (incf (aref arr (- (char-int c) a-int))))
    (if (zerop (count-if #'zerop arr))
        (format t "None~%")
        (format t "~A~%" (code-char (+ (position-if #'zerop arr) a-int))))))

(main)


(let ((n (read))
    (a (read))
    (b (read))
    (ans 0))
    (if (= a b)
        (setq ans 1)
        (if (and (< a b) (> n 1))
            (setq ans (+ (* (- n 2) (- b a)) 1))
        )
    )
    (format t "~D~%" ans)
)

Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1


(let ((n (read))
    (a (read))
    (b (read))
    (ans 0))
    (if (= a b)
        (setq ans 1)
        (if (< a b)
            (setq ans (+ (* (- n 2) (- b a)) 1))
        )
    )
    (format t "~D~%" ans)
)


;;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)

;; Read fixnum

(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare (inline read-byte)
           #-swank (sb-kernel:ansi-stream in))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (read-byte in nil 0))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setq minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))
              (return (if minus (- result) result))))))))

;; fast read-line

(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\Space))
  (let ((buffer (gensym))
        (character (gensym))
        (idx (gensym)))
    `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))
       (declare (simple-base-string ,buffer)
                (inline read-byte))
       (loop for ,character of-type base-char =
             ,(if (member :swank *features*)
                  `(read-char ,in nil #\Newline) ; on SLIME
                `(code-char (read-byte ,in nil #.(char-code #\Newline))))
             for ,idx from 0
             until (char= ,character #\Newline)
             do (setf (schar ,buffer ,idx) ,character)
             finally (when (< ,idx ,buffer-size)
                       (setf (schar ,buffer ,idx) ,term-char))
             (return (values ,buffer ,idx))))))

;;; invoke child process

#-swank
(unless (member :child-sbcl *features*)
  (quit
    :unix-status
    (process-exit-code
      (run-program *runtime-pathname*
                   `("--control-stack-size" "128MB"
                     "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                     "--eval" "(push :child-sbcl *features*)"
                     "--script" ,(namestring *load-pathname*))
                                                                 :output t :error t :input t))))

;-------------------
; Write code here
;-------------------

(defun solve (n a b)
  (if (> a b)
      0
      (if (= n 1)
          (if (= a b)
              1
              0)
          (let ((s_min (+ b (* (1- n) a)))
                (s_max (+ a (* (1- n) b))))
            (1+ (- s_max s_min))))))

(defun main ()
  (let ((n (read))
        (a (read))
        (b (read)))
    (princ (solve n a b))
    (fresh-line)))

(main)


(defun make-pq (alist)
  (sort (copy-alist alist) (lambda (a b) (< (car a) (car b)))))

(define-modify-macro insert-pq (pair)
                     (lambda (pq pair) (sort (cons pair pq) (lambda (a b) (< (car a) (car b))))))

(define-modify-macro remove-pq-aux () cdr)

(defmacro remove-pq (pq)
  `(let ((aux (copy-alist ,pq)))
     (REMOVE-PQ-AUX ,pq)
     (car aux)))

(let* ((n (read))
       (alen (* 3 n))
       (seq (make-array alen :initial-contents (loop repeat alen collect (read))))
       (ibpq (make-pq (loop for i from 0 below n
                            for a = (aref seq i)
                            collect (cons a a))))
       (ispq (make-pq (loop for i from 0 below n
                            for a = (aref seq (- alen i 1))
                            collect (cons (- a) a))))
       (res 0))
  (setf res
    (loop for k from 0 to n
          with bpq = nil
          with spq = nil do
          (setq bpq (copy-alist ibpq)
                spq (copy-alist ispq))
          (dotimes (i k)
            (let ((a (aref seq (1- (+ n k)))))
              (insert-pq bpq `(,a . ,a))
              (remove-pq bpq)))
          (dotimes (i (- n k))
            (let ((a (aref seq (- (- alen n 1) i))))
              (insert-pq spq `(,(- a) . ,a))
              (remove-pq spq)))
          maximize (- (loop for (x . y) in bpq sum y)
                      (loop for (x . y) in spq sum y))))
  (format t "~A~%" res))

Score : 500 points

Problem Statement

Let N be a positive integer.

There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}).
Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements.
Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a').

Find the maximum possible score of a'.

Constraints

1 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Partial Score

In the test set worth 300 points, N ≤ 1000.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{3N}

Output

Print the maximum possible score of a'.

Sample Input 1

2
3 1 4 1 5 9

Sample Output 1

1

When a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3 + 4) - (1 + 5) = 1.

Sample Input 2

1
1 2 3

Sample Output 2

-1

For example, when a_1 are removed, a' will be (2, 3), which has a score of 2 - 3 = -1.

Sample Input 3

3
8 2 2 7 4 6 5 3 8

Sample Output 3

5

For example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3), which has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5.


(defun make-pq (alist)
  (sort (copy-alist alist) (lambda (a b) (< (car a) (car b)))))

(define-modify-macro insert-pq (pair)
                     (lambda (pq pair) (sort (cons pair pq) (lambda (a b) (< (car a) (car b))))))

(define-modify-macro remove-pq-aux () cdr)

(defmacro remove-pq (pq)
  `(let ((aux (copy-alist ,pq)))
     (REMOVE-PQ-AUX ,pq)
     (car aux)))

(let* ((n (read))
       (alen (* 3 n))
       (seq (make-array alen))
       (res 0))
  (dotimes (i alen) (setf (aref seq i) (read)))
  (setf res
    (loop for k from 0 to n
          with bpq = nil
          with spq = nil do
          (setf bpq (make-pq nil)
                spq (make-pq nil))
          (dotimes (i n)
            (let ((a (aref seq i)))
              (insert-pq bpq `(,a . ,a))))
          (dotimes (i n)
            (let ((a (aref seq (- (1- alen) i))))
              (insert-pq spq `(,(- a) . ,a))))
          (dotimes (i k)
            (let ((a (aref seq (1- (+ n k)))))
              (insert-pq bpq `(,a . ,a))
              (remove-pq bpq)))
          (dotimes (i (- n k))
            (let ((a (aref seq (- (- alen n 1) i))))
              (insert-pq spq `(,(- a) . ,a))
              (remove-pq spq)))
          maximize (- (loop for (x . y) in bpq sum y)
                      (loop for (x . y) in spq sum y))))
  (format t "~A~%" res))


(let* ((s (concatenate 'list (read-line)))
       (lst (member #\A s))
       (lst2 '()))

  (loop for i from 0 to (1- (length lst))
        if (char= (nth i lst) #\Z) do (push (subseq lst 0 (1+ i)) lst2))

  (format t "~A~%"
          (apply #'max (mapcar #'length lst2))))

Score : 200 points

Problem Statement

Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s).

Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z.

Constraints

1 ≦ |s| ≦ 200{,}000

s consists of uppercase English letters.

There exists a substring of s that starts with A and ends with Z.

Input

The input is given from Standard Input in the following format:

s

Output

Print the answer.

Sample Input 1

QWERTYASDFZXCV

Sample Output 1

5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

Sample Input 2

ZABCZ

Sample Output 2

4

Sample Input 3

HASFJGHOGAKZZFEGA

Sample Output 3

12


(let ((a (read-line)))
  (princ (length (subseq a (position #\A a) (1+ (position #\Z a :from-end t))))))


(let ((s (read-line))
      (a 300000)
      (z 0))
     (loop for i from 0 below (length s) do
           (if (eq #\A (char s i)) (setf a (min a i)))
           (if (eq #\Z (char s i)) (setf z (max z i))))
     (princ (1+ (- z a))))


(princ(1+(-(position #\Z(setq s(read-line)):from-end t)(position #\A s))))


(let ((string (read-line)))
  (princ (length (subseq string
			 (position #\A string)
			 (1+ (position #\Z string :from-end t))))))


(format t "~A~%" (let ((s (read-line)))
                   (1+ (- (position #\Z s :from-end t)
                          (position #\A s)))))


(let* ((in (read-line))
       (ap 0)
       (zp (1- (length in))))
  (loop while (not (eq (char in ap) #\A))
        do (incf ap))
  (loop while (not (eq (char in zp) #\Z))
        do (decf zp))
  (format t "~A~%" (1+ (- zp ap))))


(declaim (optimize (speed 3) (debug 0) (safety 0)))
(let ((k (read))
      (s (read)))

  (declare (type fixnum k))
  (declare (type fixnum s))

  (format t "~A~%"
          (loop for i from 0 to k
                sum (loop for j from 0 to k
                          count (and (>= (the fixnum (- s i j)) 0) (<= (the fixnum (- s i j)) k))))))

Score : 200 points

Problem Statement

You are given two integers K and S.

Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.

How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?

Constraints

2≤K≤2500

0≤S≤3K

K and S are integers.

Input

The input is given from Standard Input in the following format:

K S

Output

Print the number of the triples of X, Y and Z that satisfy the condition.

Sample Input 1

2 2

Sample Output 1

6

There are six triples of X, Y and Z that satisfy the condition:

X = 0, Y = 0, Z = 2

X = 0, Y = 2, Z = 0

X = 2, Y = 0, Z = 0

X = 0, Y = 1, Z = 1

X = 1, Y = 0, Z = 1

X = 1, Y = 1, Z = 0

Sample Input 2

5 15

Sample Output 2

1

The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.


(let ((k (read))
      (s (read)))

  (format t "~A~%"
          (loop for i from 0 to k
                sum (loop for j from 0 to k
                          count (<= 0 (- s i j) k)))))


(defvar K (read))
(defvar S (read))

(princ
(loop for x downfrom K to 0
      sum (loop for y downfrom K to 0 with z
                do (setf z (- S x y))
                if (and (<= 0 z)
                        (<= z K))
                count 1)))