#-swank
(unless (member :child-sbcl *features*)
  "I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!"
  (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))))
#-swank
(unless (member :child-sbcl *features*)
  "I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!"
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "256MB"
                   "--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 dpline (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))))))

(defmacro dphash (name args &body expr)
  `(let ((table (make-hash-table :test #'equal)))
     (defun  ,name ,args
       (or (gethash (list ,@args) table)
           (setf (gethash (list ,@args) table)
                 (progn
                   ,@expr))))))

(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 range-0-n (n &optional (step 1))
  (loop for i from 0 below n by step collect i))

(defun range-1-n (n &optional (step 1))
  (loop for i from 1 below n by step collect i))

(defun range-a-b (a b &optional (step 1))
  (loop for i from a below b by step collect i))

(defun map-0-n (function n &optional (step 1))
  (mapcar function (range-0-n n step)))

(defun map-1-n (function n &optional (step 1))
  (mapcar function (range-1-n n step)))

(defun map-a-b (function a b &optional (step 1))
  (mapcar function (range-a-b a b step)))

(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 (and result (is-empty char))
            do (return (concatenate 'string (nreverse result)))
          when (null (is-empty char))
            do (push char result))))

(defun merge-sort (lst &optional (compare #'<))
  (let ((turn 0))
    (labels ((merge-list (a b a-length b-length)
               (cond ((zerop a-length) b)
                     ((zerop b-length) a)
                     ((funcall compare (car b) (car a))
                      (incf turn a-length)
                      (cons (car b)
                            (merge-list a (cdr b) a-length (1- b-length))))
                     (t
                      (cons (car a)
                            (merge-list (cdr a) b (1- a-length) b-length)))))
             (f (lst length)
               (if (= length 1)
                   lst
                   (let ((mid (ash length -1)))
                     (merge-list (f (subseq lst 0 mid) mid)
                                 (f (subseq lst mid) (- length mid))
                                 mid
                                 (- length mid))))))
      (values (f lst (length lst)) turn))))

(defun group (lst &optional (test #'eql) (key nil))
  (let ((table (make-hash-table :test test)))
    (mapc (lambda (x)
            (push x (gethash (if key (funcall key x) x) table)))
          lst)
    (loop for value being each hash-value in table
          collect value)))

(defun nearby (&rest args)
  (let ((current (subseq args 0 (ash (length args) -1)))
        (validator (subseq args (ash (length args) -1)))
        (res nil))
    (labels ((check ()
               (every (lambda (x y) (and (<= 0 x) (< x y)))
                      current validator))
             (f (lst)
               (unless lst (return-from f))
               (let ((x (car lst)))
                 (setf (car lst) (1+ x))
                 (when (check) (push (copy-list current) res))
                 (setf (car lst) (1- x))
                 (when (check) (push (copy-list current) res))
                 (setf (car lst) x))
               (f (cdr lst))))
      (f current)
      res)))

(defun count-same (lst)
  (reverse
   (reduce
    (lambda (x y)
      (if (= (caar x) y)
          (progn
            (incf (cdar x))
            x)
          (cons (cons y 1) x)))
    (cdr lst)
    :initial-value (list (cons (car lst) 1)))))

(defun remove-if-duplicates (lst)
  (loop for i in (count-same lst)
        when (= (cdr i) 1)
          collect (car i)))

(defun func (lst)
  (if lst
      (let ((current (car lst)))
        (1+ (func (remove-if (lambda (x) (zerop (mod x current))) lst))))
      0))

(defun main (lst)
  (func (remove-if-duplicates (sort lst #'<))))

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


(defun main ()
  (let* ((n (read))
         (m 1)
         (a (make-array `(,(1+ n)) :initial-element 0))
         (c (make-array `(,(1+ n)) :initial-element 1))
         (b (make-array `(,(1+ n)) :initial-element 0))
         (r 0))
    (when (= n 1)
      (format t "~A~%" 1)
      (return-from main))
    ;; read
    (loop :for i :from 1 :to n
          :do (setf (aref a i) (read)))
    (setf a (sort a #'<))
    ;;
    (setf (aref b 1) (aref a 1))
    (loop :for i :from 2 :to n
          :do (let* ((x (aref a i))
                     (flag t))
                (loop :named inner
                      :for j :from 1 :to m
                      :do (let* ((y (aref b j))
                                 (gcd (gcd x y)))
                            (when (/= gcd 1)
                              (if (= gcd y)
                                  (setf (aref c j) 0)
                                  (setf (aref b j) (min gcd y)))
                              (setf flag nil)
                              (return-from inner))))
                (when flag
                  (setf (aref b (incf m)) x))))
    ;;
    (loop :for i :from 1 :to n
          :if (> (* (aref b i) (aref c i)) 0)
          :do (incf r))
    (format t "~A~%" r)))
(main)

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

Score : 400 points

Problem Statement

Given is a number sequence A of length N.

Find the number of integers i \left(1 \leq i \leq N\right) with the following property:

For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer.

Sample Input 1

5
24 11 8 3 16

Sample Output 1

3

The integers with the property are 2, 3, and 4.

Sample Input 2

4
5 5 5 5

Sample Output 2

0

Note that there can be multiple equal numbers.

Sample Input 3

10
33 18 45 28 8 19 89 86 2 4

Sample Output 3

5

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.


(defun main ()
  (let* ((n (read))
         (s 1)
         (j (1+ s))
         (m n)
         (a (make-array `(,(1+ n)) :initial-element 0))
         (r 0))
    (when (= n 1)
      (format t "~A~%" 1)
      (return-from main))
    ;; read
    (loop :for i :from 1 :to n
          :do (setf (aref a i) (read)))
    ;;
    (setf a (sort a #'<))
    ;;
    (loop :named main
          :do  (loop :for i :from (1+ s) :to m
                     :do (when (/= 0 (mod (aref a i) (aref a s)))
                           (setf (aref a j) (aref a i))
                           (incf j)))
               (when (= (aref a s) (aref a (1+ s)))
                 (setf (aref a s) 0))
               (incf s)
               (setf m (1- j))
               (setf j (1+ s))
               (when (or (>= s m) (> (aref a s) 500000))
                 (return-from main)))
    (loop :for i :from 1 :to m
          :if (/= 0 (aref a m))
          :do (incf r))
    (format t "~A~%" r)))
(main)


(let* ((n (read))
       (s 1)
       (j (1+ s))
       (m n)
       (a (make-array `(,(1+ n)) :initial-element 0))
       (r 0))
  ;; read
  (loop :for i :from 1 :to n
        :do (setf (aref a i) (read)))
  ;;
  (setf a (sort a #'<))
  ;;
  (loop :named main
        :do  (loop :for i :from (1+ s) :to m
                   :do (when (/= 0 (mod (aref a i) (aref a s)))
                         (setf (aref a j) (aref a i))
                         (incf j)))
             (when (= (aref a s) (aref a (1+ s)))
               (setf (aref a s) 0))
             (incf s)
             (setf m (1- j))
             (setf j (1+ s))
             (when (>= s m)
               (return-from main)))
  (loop :for i :from 1 :to m
        :if (/= 0 (aref a m))
        :do (incf r))
  (format t "~A~%" r))


#-swank
(unless (member :child-sbcl *features*)
  "I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!"
  (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))))
#-swank
(unless (member :child-sbcl *features*)
  "I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!"
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "256MB"
                   "--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 dpline (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))))))

(defmacro dphash (name args &body expr)
  `(let ((table (make-hash-table :test #'equal)))
     (defun  ,name ,args
       (or (gethash (list ,@args) table)
           (setf (gethash (list ,@args) table)
                 (progn
                   ,@expr))))))

(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 range-0-n (n &optional (step 1))
  (loop for i from 0 below n by step collect i))

(defun range-1-n (n &optional (step 1))
  (loop for i from 1 below n by step collect i))

(defun range-a-b (a b &optional (step 1))
  (loop for i from a below b by step collect i))

(defun map-0-n (function n &optional (step 1))
  (mapcar function (range-0-n n step)))

(defun map-1-n (function n &optional (step 1))
  (mapcar function (range-1-n n step)))

(defun map-a-b (function a b &optional (step 1))
  (mapcar function (range-a-b a b step)))

(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 (and result (is-empty char))
            do (return (concatenate 'string (nreverse result)))
          when (null (is-empty char))
            do (push char result))))

(defun merge-sort (lst &optional (compare #'<))
  (let ((turn 0))
    (labels ((merge-list (a b a-length b-length)
               (cond ((zerop a-length) b)
                     ((zerop b-length) a)
                     ((funcall compare (car b) (car a))
                      (incf turn a-length)
                      (cons (car b)
                            (merge-list a (cdr b) a-length (1- b-length))))
                     (t
                      (cons (car a)
                            (merge-list (cdr a) b (1- a-length) b-length)))))
             (f (lst length)
               (if (= length 1)
                   lst
                   (let ((mid (ash length -1)))
                     (merge-list (f (subseq lst 0 mid) mid)
                                 (f (subseq lst mid) (- length mid))
                                 mid
                                 (- length mid))))))
      (values (f lst (length lst)) turn))))

(defun group (lst &optional (test #'eql) (key nil))
  (let ((table (make-hash-table :test test)))
    (mapc (lambda (x)
            (push x (gethash (if key (funcall key x) x) table)))
          lst)
    (loop for value being each hash-value in table
          collect value)))

(defun nearby (&rest args)
  (let ((current (subseq args 0 (ash (length args) -1)))
        (validator (subseq args (ash (length args) -1)))
        (res nil))
    (labels ((check ()
               (every (lambda (x y) (and (<= 0 x) (< x y)))
                      current validator))
             (f (lst)
               (unless lst (return-from f))
               (let ((x (car lst)))
                 (setf (car lst) (1+ x))
                 (when (check) (push (copy-list current) res))
                 (setf (car lst) (1- x))
                 (when (check) (push (copy-list current) res))
                 (setf (car lst) x))
               (f (cdr lst))))
      (f current)
      res)))

(defvar var-max (expt 10 6))

(defun main (n lst)
  (let ((nums (make-array (list (1+ var-max)) :initial-element 0))
        (cnt 0))
    (dolist (i lst)
      (incf (aref nums i)))
    (loop for i from 1 to var-max
          when (= (aref nums i) 1)
            sum 1
          when (>= (aref nums i) 1)
            do
               (loop for j from i to var-max by i
                     do
                     (setf (aref nums j) 0)))))

#-swank
(let ((n (read)))
  (princ (main n (read-times n))))

(main 5
      (list 24 11 8 3 16))


(let* ((n (read))
       (m (sort (loop :repeat n :collect (read)) #'<))
       (ll (make-array (+ 2 (expt 10 6)) :element-type 'bit :initial-element 1))
       (ans 0))
  (loop :for k :in m
        :with x = -1
        :do(if (and (not (= k x)) (= 1 (aref ll k)))
               (progn (loop :for j :from k :upto (1+ (expt 10 6)) :by k
                            :if (= 1 (aref ll j)) :do(setf (aref ll j) 0))
                      (incf ans)))
        :do(setf x k))
  (princ ans))


(let* ((n (read))
       (m (sort (loop :repeat n :collect (read)) #'<))
       (ll (make-array (+ 2 (expt 10 6)) :element-type 'bit :initial-element 1))
       (ans 0))
  (loop :for k :in m
        :with x = -1
        :do(if (and (= k x) (= 1 (aref ll k))) (incf ans))
        :do(loop :for j :from k :upto (1+ (expt 10 6)) :by k
                 :if (= 1 (aref ll j)) :do(setf (aref ll j) 0))
        :do(setf x k))
  (princ ans))


(let* ((n (read))
       (m (concatenate 'vector (loop :repeat n :collect (read)))))
  (loop :for k :from 0 :upto (1- n)
        :count (not (loop :for j :from 0 :upto (1- n)
                          :if (and (not (= k j))
                                   (= 0 (mod (aref m k) (aref m j))))
                            :return t))))


(defun main (lst accum)
  (cond ((not (car lst)) accum)
        ((position 0 lst) 0)
        ((< (expt 10 18) (car lst)) -1)
        ((< (expt 10 18) (* (car lst) accum)) -1)
        (t (main (cdr lst) (* (car lst) accum)))))

(princ (write-to-string (main (sort (loop :repeat (read) :collect (read)) #'<) 1)))

Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0


(defun main (lst accum)
  (cond ((not (car lst)) accum)
        ((find 0 lst) 0)
        ((< (expt 10 18) (* (car lst) accum)) -1)
        (t (main (cdr lst) (* (car lst) accum)))))

(princ (write-to-string (main (loop :repeat (read) :collect (read)) 1)))


(defun main (lst accum)
  (cond ((not (car lst)) accum)
        ((< (expt 10 18) (* (car lst) accum)) -1)
        (t (main (cdr lst) (* (car lst) accum))))  )

(princ (write-to-string (main (loop :repeat (read) :collect (read)) 1)))


(let ((accum 1))
  (dotimes (index (read))
    (setq accum (* accum (read))))
  (princ (if (<= accum (expt 10 18)) (write-to-string accum) "-1")))


(defun main (lst)
  (reduce  #'(lambda (accum elem) (* accum elem)) lst :initial-value 1))

(let ((sum (main (loop :repeat (read) :collect (read)))))
  (princ (if (<= sum (expt 10 18)) (write-to-string sum) "-1")))


(defun App (n)
    (let ((ans 1)
        (a Nil))

    (loop for i below n
        do (push (read) a)
    )

    (setf a (sort a #'<))

    (loop for i in a
        do (progn
            (if (and (= ans 0))
            (return)
            (progn (setf ans (* ans i))
                (if (> ans 1000000000000000000)
                (progn
                    (setq ans -1)
                    (return)
                )
                )
            )
            )
        )
    )
    ans)
)
(format t "~D~%" (App (read)))


(defun main ()
  (let ((l (loop repeat (read)
                 collect (read)))
        (result 1))
    (block calc
      (dolist (x l)
        (if (> (write-to-string result) 18)
            (progn
              (setq result nil)
              (return-from calc nil))
            (setq result (* result x)))))
    (format t "~A~%"
            (if result
                result
                -1))))

(main)


(let* ((n (read))
       (arr (loop :repeat n :collect (read)))
       (product (apply #'* arr)))
      (princ (if (< (expt 10 18) product) -1 product)))


(defun mul (xs &optional (ans 1))
  (cond
    ((null xs) ans)
    ((= ans 0) 0)
    (t (mul (rest xs) (min (+ (expt 10 18) 1) (* ans (first xs)))))))

(defun solve (a)
  (if (> a (expt 10 18))
      -1
      a))

(let ((n (read))
      (a (sort (read-from-string
          (concatenate 'string
                       "(" (read-line) ")")) #'<=)))
     (princ (solve (mul a))))


(defun mul (xs &optional (ans 1))
  (cond
    ((null xs) ans)
    ((= ans 0) 0)
    (t (mul (rest xs) (min (+ (expt 10 18) 1) (* ans (first xs)))))))

(defun solve (a)
  (if (> a (expt 10 18))
      -1
      a))

(let ((n (read))
      (a (read-from-string
          (concatenate 'string
                       "(" (read-line) ")"))))
     (princ (solve (mul a))))


(defun mult-all (n a)
  (let ((res 1))
	(dotimes (i n)
	  (if (zerop (aref a i) )
		  (setf res 0)
		  (setf res (* res (aref a i)))))
	(if (> res 1000000000000000000)
		(setf res -1))
	res))

(defun create-data ()
  (let* ((n (read))
         (a (make-array `(,n) :element-type 'integer)))
    (dotimes (i n)
      (setf (aref a i) (read)))
    (values n a)))

(multiple-value-bind (n a) (create-data)
  (format t "~A~%" (mult-all n a)))


(defun App (n)
    (setf ans 1 hikaku (expt 10 18))
    (loop for i
        below n
        do (setq ans (* ans (read)))
            (if (> ans hikaku)
            (setq ans -1)
        )
        )

        ans)

(format t "~D~%" (App (read)))


(defun main ()
  (let ((n (read))
        (ans 1))
    (dotimes (i n)
      (setf ans (* ans (read))))

    (if (<= ans 1000000000000000000)
        ans
        -1)))

(format t "~d~%" (main))


(defun main ()
  (let ((n (read))
        (a ())
        (ans))
    (dotimes (i n)
      (push (read) a))
    (setf ans (reduce #'* a))

    (if (<= ans 1000000000000000000)
        ans
        -1)))

(format t "~d~%" (main))


(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))

(defun f(lst n)
  (labels ((rec(lst acc n)
             (if (null lst)
               (if (<= acc (expt 10 18)) acc -1)
               (if (<= acc (expt 10 18))
                 (rec (cdr lst) (* (car lst) acc) (1- n))
                 -1))))
    (rec lst 1 n)))
(compile 'f)
(let ((line0 (parse-integer (read-line nil nil)))
      (line (mapcar #'parse-integer (splitat #\space (read-line nil nil)))))
      (format t "~A~%" (f line line0)))


(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))

(defun f(lst n)
  (labels ((rec(lst acc n)
             (if (null lst)
               (if (<= acc (expt 10 18)) acc -1)
               (if (<= acc (expt 10 18))
                 (rec (cdr lst) (* (car lst) acc) (1- n))
                 -1))))
    (rec lst 1 n)))
(compile 'f)
(let ((line0 (read-line nil nil))
      (line (mapcar #'parse-integer (splitat #\space (read-line nil nil)))))
      (format t "~A~%" (f line line0)))


(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))

(defun f(lst)
  (labels ((rec(lst acc)
             (if (null lst)
               (if (<= acc (expt 10 18)) acc -1)
               (if (<= acc (expt 10 18))
                 (rec (cdr lst) (* (car lst) acc))
                 -1))))
    (rec lst 1)))
(compile 'f)
(let ((line0 (read-line nil nil))
      (line (mapcar #'parse-integer (splitat #\space (read-line nil nil)))))
      (format t "~A~%" (f line)))


(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))

(let ((line0 (read-line nil nil))
      (line (mapcar #'parse-integer (splitat #\space (read-line nil nil)))))
  (let ((a (reduce #'* line)))
      (format t "~A~%" (if (<= a (expt 10 18)) a -1))))


(let ((n (read)) (x 1))
  (loop for i below n
        do (setq x (* x (read))))
  (princ x))


;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(defvar *n* (read))
(defvar arr (make-array *n*))
(dotimes (i *n*) (setf (aref arr i) (read)))

(let ((i 0) (p 1))
  (loop for j from 0 below *n*
	for a = (aref arr j)
	when (> p 1000000000000000000) do (return)
	do (setf p (* p a)) (incf i))
  (loop for j from i below *n*
	for a = (aref arr j)
	when (= a 0) do (setf p 0))
  (princ (if (> p 1000000000000000000) -1 p)))


(defun main ()
  (let ((n (read))
        (ans 1)
        (a nil))
    ; read
    (loop :for _ :from 1 :to n
          :do (push (read) a))
    (setf a (sort a #'<))
    ;
    (loop :for ai :in a
          :do (progn
                (setf ans (* ans ai))
                (when (> ans 1000000000000000000)
                  (format t "-1~%")
                  (return-from main))))
    (format t "~A~%" ans)))
(main)


(let ((n (read)))
     (loop with a = 1
           repeat n
           do (setf a (* a (read)))
           finally (if (> a (expt 10 18))
                       (format t "-1")
                       (format t "~A" a))))


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

(in-package :cl-user)

(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 ()
  (let* ((n (read))
         (res 1))
    (dotimes (_ n)
      (setq res (min most-positive-fixnum (* res (read-fixnum)))))
    #>res
    (println
     (if (> res #.(expt 10 18))
         -1
         res))))

#-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 "2
1000000000 1000000000
"
    "1000000000000000000
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "3
101 9901 999999000001
"
    "-1
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0
"
    "0
")))


(princ (truncate (* (read) (rationalize (read)))))

Score : 300 points

Problem Statement

Compute A \times B, truncate its fractional part, and print the result as an integer.

Constraints

0 \leq A \leq 10^{15}

0 \leq B < 10

A is an integer.

B is a number with two digits after the decimal point.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the answer as an integer.

Sample Input 1

198 1.10

Sample Output 1

217

We have 198 \times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217.

Sample Input 2

1 0.01

Sample Output 2

0

Sample Input 3

1000000000000000 9.99

Sample Output 3

9990000000000000


(let ((a (read))
      (b (rationalize (read))))
     (format t "~A~%" (floor (* a b))))


(let ((a (read))
      (b (rationize (read))))
     (format t "~A~%" (floor (* a b))))


(let ((a (read))
      (b (rationalize (read))))
  (prin1 (floor (* a b))))


(defvar a (read))
(defvar b (read))
(princ
 (floor
  (/
   (* a
      (floor (* b 100)
                       )
                    )
                 100)
              )
       )


(defvar a (read))
(defvar b (read))
(princ (floor (* a b)))(defvar a (read))
(defvar b (read))
(princ (floor (/ (* a (floar (* b 100))) 100) ))


(defvar a (read))
(defvar b (read))
(princ (floor (* a b)))(defvar a (read))
(defvar b (read))
(princ (floor (/ (* a (* b 100)) 100) ))


(defvar a (read))
(defvar b (read))
(princ (floor (* a b)))


(let ((a (read))
      (b (round (* (read) 100))))
     (princ (floor (* a b) 100)))


(let ((a (read))
      (b (floor (* (read) 100))))
     (princ (floor (* a b) 100))
     )


(let ((a (read))
      (b (floor (* (read) 100))))
     (princ (floor (* a b) 100)))


(let ((a (read)) (b (read)))
     (setq b (floor (* b 100)))
     (princ (floor (/ (* a b) 100))))


(defun App (a b)
  (floor(* a b)))
(format t "~D~%" (App (read) (read)))


(let* ((n (read))
       (m (read-line))
       (a (/ (parse-integer (remove #\. m :test #'char=))
             (expt 10 (1+ (position #\. m :test #'char=))))))
  (princ (floor (* n a))))


(let ((a (read))
      (b (read)))
     (princ (floor (* a b))))


(format t "~A" (floor (* (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
           #\# #\> (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
(in-package :cl-user)

(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 ()
  (let* ((*read-default-float-format* 'double-float)
         (a (* 100 (read)))
         (b (round (* 100 (read)))))
    (println (floor (/ (* a b) 10000)))))

#-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 "198 1.10
"
    "217
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "1 0.01
"
    "0
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "1000000000000000 9.99
"
    "9990000000000000
")))


;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(declaim (type fixnum n k))
(defvar n (read))
(defvar k (read))

(defvar *a* (make-array (1+ n) :element-type 'fixnum))
(defvar *v* (make-array (1+ n) :initial-element nil :element-type 'boolean))
(loop for i from 1 to n do
      (setf (aref *a* i) (read)))

(defvar *prelude*)
(defvar *cycle*)

(let ((v (make-array n :element-type 'fixnum :fill-pointer 0))
      (town 1))
  (loop
   (when (aref *v* town) ; cycle detected
     (let ((p (position town v)))
       (setf *prelude* (subseq v 0 p))
       (setf *cycle* (subseq v p)))
     (return))
   (setf (aref *v* town) t)
   (vector-push-extend town v)
   (setf town (aref *a* town))))

(princ (if (< k (length *prelude*))
	   (aref *prelude* k)
	 (aref *cycle* (mod (- k (length *prelude*)) (length *cycle*)))))

Score: 400 points

Problem Statement

The Kingdom of Takahashi has N towns, numbered 1 through N.

There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.

Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Help the king by writing a program that answers this question.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq N

1 \leq K \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Sample Input 1

4 5
3 2 4 1

Sample Output 1

4

If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \to 3 \to 4 \to 1 \to 3 \to 4.

Sample Input 2

6 727202214173249351
6 5 2 5 3 2

Sample Output 2

2


;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(declaim (type fixnum n k))
(defvar n (read))
(defvar k (read))

(defvar *a* (make-array (1+ n) :element-type 'fixnum))
(loop for i from 1 to n do
      (setf (aref *a* i) (read)))

(defvar *prelude*)
(defvar *cycle*)

(let ((v (make-array n :element-type 'fixnum :fill-pointer 0))
      (town 1))
  (loop
   (let ((p (position town v)))
     (when p ; cycle detected
       (setf *prelude* (subseq v 0 p))
       (setf *cycle* (subseq v p))
       (return))
     (vector-push-extend town v)
     (setf town (aref *a* town)))))

(princ (if (< k (length *prelude*))
	   (aref *prelude* k)
	 (aref *cycle* (mod (- k (length *prelude*)) (length *cycle*)))))


(let* ((n (read))
       (k (read))
       (a (make-array `(,(1+ n))))
       (last-index 0)
       (memo (make-array `(,(1+ n)) :initial-element nil))
       (hist (make-array `(,(1+ n)) :initial-element nil)))
  ;; input
  (loop :for i :from 1 :to n
        :do (setf (aref a i) (read)))
  ;; init
  (setf (aref hist 0) 1)
  (setf (aref memo 1) 0)
  ;;
  (loop :for m :from 1 :to n
        :for p :from 0
        :for pos := (aref a (aref hist p))
        :until (aref memo pos)
        :do (progn
              (setf (aref memo pos) m)
              (setf (aref hist m) pos)
              (setf last-index m)))
  (let* ((loop-end (aref hist last-index))
         (loop-start (aref a loop-end))
         (loop-end-index (aref memo loop-end))
         (loop-start-index (aref memo loop-start))
         (period (1+ (- loop-end-index loop-start-index))))
    (cond ((<= k loop-start-index)
           (format t "~A~%" (aref hist k)))
          (t
           (format t "~A~%"
                   (aref hist (+ loop-start-index
                                 (mod (- k loop-start-index) period))))))))


(let* ((n (read))
       (k (read))
       (a (make-array `(,(1+ n))))
       (last-index 0)
       (memo (make-array `(,(1+ n)) :initial-element nil))
       (hist (make-array `(,(1+ n)) :initial-element nil)))
  ;; input
  (loop :for i :from 1 :to n
        :do (setf (aref a i) (read)))
  ;; init
  (setf (aref hist 0) 1)
  (setf (aref memo 1) 0)
  ;;
  (loop :for m :from 1 :to n
        :for p :from 0
        :for pos := (aref a (aref hist p))
        :while (null (aref memo pos))
        :do (progn
              (setf (aref memo pos) m)
              (setf (aref hist m) pos)
              (setf last-index m)))
  (let* ((loop-end (aref hist last-index))
         (loop-start (aref a loop-end))
         (loop-end-index (aref memo loop-end))
         (loop-start-index (aref memo loop-start))
         (period (1+ (- loop-end-index loop-start-index))))
    (cond ((<= k loop-start-index)
           (format t "~A~%" k))
          (t
           (format t "~A~%"
                   (aref hist (+ loop-start-index
                                 (mod (- k loop-start-index) period))))))))


(let* ((n (read))
       (k (read))
       (a (make-array `(,(1+ n))))
       (len 1)
       (mem (make-array `(,(1+ n)) :initial-element nil))
       (result (make-array `(,(1+ n)))))
  (loop :for i :from 1 :to n
        :do (setf (aref a i) (read)))
  (setf (aref result 0) 1)
  (setf (aref mem 1) 0)
  (block calc
    (loop :for m :from 1 :to k
          :do (let ((next (aref a (aref result (1- m)))))
                (cond ((aref mem next)
                       (return-from calc))
                      (t
                       (incf len)
                       (setf (aref mem next) m)
                       (setf (aref result m) next))))))
  (let* ((loop-e (aref result (1- len)))
         (loop-s (aref a loop-e))
         (loop-e-num (1- len))
         (loop-s-num (aref mem loop-s)))
    (cond ((<= k loop-s-num)
           (format t "~A~%" loop-s))
          (t
           (format t
                   "~A~%"
                   (aref result
                         (+ loop-s-num (mod (- k loop-s-num) (1+ (- loop-e-num loop-s-num))))))))))


(defun teleporter (n k)
  (let
   ((a (make-array 0 :fill-pointer 0 :adjustable t))
    (b (make-array 0 :fill-pointer 0 :adjustable t))
    (tmp 1)
    (counter 0))
   (loop :repeat n
         :do (vector-push-extend (read) a))
   (loop :repeat n
         :do (incf counter 1)
             (vector-push-extend tmp b)
             (setq tmp (aref a (- tmp 1)))
         :until (= tmp 1))
   (aref b (mod k counter))))

(print (teleporter (read) (read)))


(defun teleporter (n k)
  (let
   ((a (make-array 0 :fill-pointer 0 :adjustable t))
    (b (make-array 0 :fill-pointer 0 :adjustable t))
    (tmp 1)
    (counter 0))
   (loop :repeat n
         :do (vector-push-extend (read) a))
   (loop :repeat n
         :do (incf counter 1)
             (setq tmp (aref a (- tmp 1)))
             (vector-push-extend tmp b)
         :until (= tmp 1))
   (aref b (mod k counter))))

(print (teleporter (read) (read)))


(let* ((n (read))
       (k (read))
       (a (make-array `(,(1+ n))))
       (len 1)
       (mem (make-array `(,(1+ n)) :initial-element nil))
       (result (make-array `(,n))))
  (loop :for i :from 1 :to n
        :do (setf (aref a i) (read)))
  (setf (aref result 0) 1)
  (setf (aref mem 1) 0)
  (block calc
    (loop :for m :from 1 :to k
          :do (let ((next (aref a (aref result (1- m)))))
                (cond ((aref mem next)
                       (return-from calc))
                      (t
                       (incf len)
                       (setf (aref mem next) m)
                       (setf (aref result m) next))))))
  (let* ((loop-e (aref result (1- len)))
         (loop-s (aref a loop-e))
         (loop-e-num (1- len))
         (loop-s-num (aref mem loop-s)))
    (cond ((<= k loop-s-num)
           (format t "~A~%" loop-s))
          (t
           (format t
                   "~A~%"
                   (aref result
                         (+ loop-s-num (mod (- k loop-s-num) (1+ (- loop-e-num loop-s-num))))))))))


(defun teleporter (n k)
  (let
   ((a (make-array 0 :fill-pointer 0 :adjustable t))
    (b (make-array 0 :fill-pointer 0 :adjustable t))
    (tmp 0)
    (counter 0))
   (loop :repeat n
         :do (vector-push-extend (- (read) 1) a))
   (loop :repeat n
         :do (incf counter 1)
             (setq tmp (aref a tmp))
         	 (vector-push-extend tmp b)
         :until (= tmp 0))
   (+ 1 (aref b (mod k counter)))))

(print (teleporter (read) (read)))


(defun get-loop-origin (n arr)
  (let ((visited (make-array n
                             :initial-contents
                             (loop repeat n collect 0))))
       (loop with pos = 0
             while t
             when (= 1 (aref visited pos))
               return (1- (aref arr pos))
             do (setf (aref visited pos) 1)
                (setf pos (1- (aref arr pos))))))

(defun get-loop-length (n arr idx)
  (let ((visited (make-array n
                             :initial-contents
                             (loop repeat n collect 0))))
       (loop with c = 0
             with pos = idx
             when (= 1 (aref visited pos))
               return c
             do (setf (aref visited pos) 1)
                (setf pos (1- (aref arr pos)))
                (incf c))))

(defun cost-until-origin (arr idx)
  (loop with c = 0
        with pos = 0
        when (= pos idx)
          return c
        do (setf pos (1- (aref arr pos)))
           (incf c)))

(defun solve (n arr k)
  (let* ((origin (get-loop-origin n arr))
         (length (get-loop-length n arr origin))
         (cost (cost-until-origin arr origin))
         (shortened-k (mod (- k cost) length)))
        (if (<= k cost)
            (loop with pos = 0
                  with rest-time = k
                  when (= rest-time 0)
                    return (1+ pos)
                  do (setf pos (1- (aref arr pos)))
                     (decf rest-time))
            (loop with pos = 0
                  with rest-time = (+ cost shortened-k)
                  when (= rest-time 0)
                    return (1+ pos)
                  do (setf pos (1- (aref arr pos)))
                     (decf rest-time)))))

(let* ((n (read))
       (k (read))
       (arr (make-array n
                        :initial-contents
                        (loop repeat n collect (read)))))
      (format t "~A" (solve n arr k)))


(let* ((n (read))
       (k (read))
       (a (make-array `(,(1+ n))))
       (len 1)
       (mem (make-hash-table :size (ceiling (* n 1.1))))
       (result (make-array `(,n))))
  (loop :for i :from 1 :to n
        :do (setf (aref a i) (read)))
  (setf (aref result 0) 1)
  (setf (gethash 1 mem) 0)
  (block calc
    (loop :for m :from 1 :to k
          :do (let ((next (aref a (aref result (1- m)))))
                (cond ((gethash next mem)
                       (return-from calc))
                      (t
                       (incf len)
                       (setf (gethash next mem) m)
                       (setf (aref result m) next))))))
  (let* ((loop-e (aref result (1- len)))
         (loop-s (aref a loop-e))
         (loop-e-num (1- len))
         (loop-s-num (gethash loop-s mem)))
    (cond ((<= k loop-s-num)
           (format t "~A~%" loop-s))
          (t
           (format t
                   "~A~%"
                   (aref result
                         (+ loop-s-num (mod (- k loop-s-num) (1+ (- loop-e-num loop-s-num))))))))))


(let* ((n (read))
       (m (read))
       (lst (concatenate 'vector (loop :repeat n :collect (1- (read)))))
       (arr (make-array n :initial-element -1 :element-type 'fixnum))
       (st nil)
       (ans 0))
  (setf st (loop :for j :from 0
                 :for k := 0 :then (aref lst k)
                 :if (= -1 (aref arr k)) :do (setf (aref arr k) j)
                   :else :return (list (aref arr k) k)))
  (setf ans (loop :for j :from 1
                  :for k := (aref lst (second st)) :then (aref lst k)
                  :if (= k (second st)) :return j))
  (if (<= (first st) m)
      (loop :for j :from (mod (- m (first st)) ans) :downto 0
            :for k := (second st) :then (aref lst k)
            :finally (princ (1+ k)))
      (loop :for j :from m :downto 0
            :for k := 0 :then (aref lst k)
            :finally (princ (1+ k)))))


(defun get-loop-origin (n arr)
  (let ((visited (make-array n
                             :initial-contents
                             (loop repeat n collect 0))))
       (loop with pos = 0
             while t
             when (= 1 (aref visited pos))
               return (1- (aref visited pos))
             do (setf (aref visited pos) 1)
                (setf pos (1- (aref arr pos))))))

(defun get-loop-length (n arr idx)
  (let ((visited (make-array n
                             :initial-contents
                             (loop repeat n collect 0))))
       (loop with c = 0
             with pos = idx
             when (= 1 (aref visited pos))
               return c
             do (setf (aref visited pos) 1)
                (setf pos (1- (aref arr pos)))
                (incf c))))

(defun cost-until-origin (arr idx)
  (loop with c = 0
        with pos = 0
        when (= pos idx)
          return c
        do (setf pos (1- (aref arr pos)))
           (incf c)))

(defun solve (n arr k)
  (let* ((origin (get-loop-origin n arr))
         (length (get-loop-length n arr origin))
         (cost (cost-until-origin arr origin))
         (shortened-k (mod (- k cost) length)))
        (if (<= k cost)
            (loop with pos = 0
                  with rest-time = k
                  when (= rest-time 0)
                    return (aref arr pos)
                  do (setf pos (1- (aref arr pos)))
                     (decf rest-time))
            (loop with pos = origin
                  with rest-time = shortened-k
                  when (= rest-time 0)
                    return (aref arr pos)
                  do (setf pos (1- (aref arr pos)))
                     (decf rest-time)))))

(let* ((n (read))
       (k (read))
       (arr (make-array n
                        :initial-contents
                        (loop repeat n collect (read)))))
      (format t "~A" (solve n arr k)))


#-swank
(unless (member :child-sbcl *features*)
  "I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!"
  (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 merge-sort (lst &optional (compare #'<))
  (let ((turn 0))
    (labels ((merge-list (a b a-length b-length)
               (cond ((zerop a-length) b)
                     ((zerop b-length) a)
                     ((funcall compare (car b) (car a))
                      (incf turn a-length)
                      (cons (car b)
                            (merge-list a (cdr b) a-length (1- b-length))))
                     (t
                      (cons (car a)
                            (merge-list (cdr a) b (1- a-length) b-length)))))
             (f (lst length)
               (if (= length 1)
                   lst
                   (let ((mid (ash length -1)))
                     (merge-list (f (subseq lst 0 mid) mid)
                                 (f (subseq lst mid) (- length mid))
                                 mid
                                 (- length mid))))))
      (values (f lst (length lst)) turn))))

(defun group (lst &optional (test #'eql) (key nil))
  (let ((table (make-hash-table :test test)))
    (mapc (lambda (x)
            (push x (gethash (if key (funcall key x) x) table)))
          lst)
    (loop for value being each hash-value in table
          collect value)))

(defun main (n k teleport &aux (teleports (coerce teleport 'vector)))
  (let ((fast (make-array (list n) :initial-element nil)))
    (labels ((f (p time rem)
               (if (and (aref fast p) (>= rem (- time (aref fast p))))
                   (f p time (mod rem (- time (aref fast p))))
                   (if (zerop rem) p
                       (progn
                         (setf (aref fast p) time)
                         (f (aref teleports p) (1+ time) (1- rem)))))))
      (f 0 0 k))))

(let ((n (read))
      (k (read)))
  (princ (1+ (main n k (collect-times n (1- (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
           #\# #\> (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))))))))

;;;
;;; Some operations on symmetric group
;;;

;; NOTE: Here the underlying set is 0-based: {0, 1, 2, ..., N-1}

(declaim (inline decompose-to-cycles))
(defun decompose-to-cycles (permutation)
  "Returns the list of all the cyclic permutations in PERMUTATION and returns
the parity of it as the second value. (Actually the second value is the distance
to the identity permutation, (0, 1, ..., N-1), w.r.t. swapping.)"
  (declare (vector permutation))
  (let* ((n (length permutation))
         result
         (visited (make-array n :element-type 'bit :initial-element 0))
         (sign 0))
    (declare ((integer 0 #.most-positive-fixnum) sign))
    (dotimes (init n)
      (when (zerop (sbit visited init))
        (push (loop for x = init then (aref permutation x)
                    until (= (sbit visited x) 1)
                    collect x
                    do (setf (sbit visited x) 1)
                       (incf sign))
              result)
        (decf sign)))
    (values result sign)))

(declaim (inline perm*))
(defun perm* (perm1 perm2)
  "Composes two permutations."
  (let* ((n (length perm1))
         (result (make-array n :element-type 'fixnum)))
    (dotimes (i n)
      (setf (aref result i) (aref perm2 (aref perm1 i))))
    result))

(declaim (inline perm-inverse))
(defun perm-inverse (perm)
  (let* ((n (length perm))
         (result (make-array n :element-type 'fixnum)))
    (dotimes (i n)
      (setf (aref result (aref perm i)) i))
    result))

;;;
;;; Calculate a^n on any monoids in O(log(n)) time
;;;

(declaim (inline power))
(defun power (base exponent op identity)
  "OP := binary operation (comprising a monoid)
IDENTITY := identity element w.r.t. OP"
  (declare ((integer 0) exponent))
  (labels ((recur (x p)
             (declare ((integer 0 #.most-positive-fixnum) p))
             (cond ((zerop p) identity)
                   ((evenp p) (recur (funcall op x x) (ash p -1)))
                   (t (nth-value 0 (funcall op x (recur x (- p 1)))))))
           (recur-big (x p)
             (declare ((integer 0) p))
             (cond ((zerop p) identity)
                   ((evenp p) (recur-big (funcall op x x) (ash p -1)))
                   (t (nth-value 0 (funcall op x (recur-big x (- p 1))))))))
    (typecase exponent
      (fixnum (recur base exponent))
      (otherwise (recur-big base exponent)))))

(in-package :cl-user)

(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 ()
  (let* ((n (read))
         (k (read))
         (as (make-array n :element-type 'uint31 :initial-element 0))
         (iden (make-array n :element-type 'uint31 :initial-element 0)))
    (dotimes (i n)
      (setf (aref as i) (- (read-fixnum) 1)
            (aref iden i) i))
    #>as
    (let ((res (power as k #'perm* iden)))
      #>res
      (println (+ 1 (aref res 0))))))

#-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 "4 5
3 2 4 1
"
    "4
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "6 727202214173249351
6 5 2 5 3 2
"
    "2
")))


(let ((a (read))
      (b (read))
      (c (read))
      (d (read)))
  (if (<= (ceiling c b) (ceiling a d))
      (format t "Yes~%")
      (format t "No~%")))

Score : 200 points

Problem Statement

Takahashi and Aoki will have a battle using their monsters.

The health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respectively.

The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ...
Here, an attack decreases the opponent's health by the value equal to the attacker's strength.
The monsters keep attacking until the health of one monster becomes 0 or below. The person with the monster whose health becomes 0 or below loses, and the other person wins.

If Takahashi will win, print Yes; if he will lose, print No.

Constraints

1 \leq A,B,C,D \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

If Takahashi will win, print Yes; if he will lose, print No.

Sample Input 1

10 9 10 10

Sample Output 1

No

First, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.

Next, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.

Takahashi's monster is the first to have 0 or less health, so Takahashi loses.

Sample Input 2

46 4 40 5

Sample Output 2

Yes


(defun App ()
    (let ((a (read))
        (b (read))
        (c (read))
        (d (read)))

        (loop while (or (> a 0) (> c 0))
        do (progn
            (setf a (- a d))
            (setf c (- c b))
            (if (<= c 0)
                (progn
                (format t "Yes~%")
                 	(return)
                )
            )
            (if (<= a 0)
                (progn
                (format t "No~%")
                (return)
                )
            )
        )
        )
    )

)

(App)


(declaim (optimize (speed 0) (safety 3) (debug 3)))
#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))
;;(declaim (optimize (speed 3) (safety 0) (debug 0)))

(defvar *t-health* (read))
(defvar *t-attack* (read))
(defvar *a-health* (read))
(defvar *a-attack* (read))

(let ((n-t-die (ceiling *t-health* *a-attack*))
      ;; 青木君に何回攻撃されると高橋君は死ぬか
      (n-a-die (ceiling *a-health* *t-attack*)))
  ;; 高橋君に何回攻撃されると青木君は死ぬか
  (format t "~:[No~;Yes~]" (<= n-a-die n-t-die)))
;; 高橋君が先制攻撃するので死ぬまでの回数が同じなら高橋君の勝ち


(defun attack (a b c d &optional (turn 'takahashi))
  (cond ((<= a 0)
         "No")
        ((<= c 0)
         "Yes")
        ((eq turn 'takahashi)
         (attack a b (- c b) d 'aoki))
        ((eq turn 'aoki)
         (attack (- a d) b c d 'takahashi))))

(princ (attack (read) (read) (read) (read)))


(let* ((a (read))
       (b (read))
       (c (read))
       (d (read))
       (time-t (ceiling (/ c b)))
       (time-a (ceiling (/ a d))))
      (if (<= time-t time-a)
          (format t "Yes")
          (format t "No")))


(let* ((n (cons (read) (read)))
       (m (cons (read) (read))))
  (loop :do (if (<= (car n) 0)
                (progn (princ "No") (return))
                (decf (car m) (cdr n)))
        :do (if (<= (car m) 0)
                (progn (princ "Yes") (return))
                (decf (car n) (cdr m)))
        )
  )


(let ((a (read))
      (b (read))
      (c (read))
      (d (read)))
  (format t "~:[No~;Yes~]~%" (<= (ceiling c b) (ceiling a d))))


(let* ((n (cons (read) (read)))
       (m (cons (read) (read))))
  (loop :do (if (<= (car n) 0)
                (progn (princ "No") (return))
                (decf (car m) (cdr n)))
        :do (if (<= (cdr m) 0)
                (progn (princ "Yes") (return))
                (decf (car n) (cdr m)))
        )
  )


(let ((a (read))
      (b (read))
      (c (read))
      (d (read)))
  (format t "~a~%"
          (if (loop
                do (decf c b)
                if (<= c 0) do (return t)
                do (decf a d)
                if (<= a 0) do (return nil))
              "Yes"
              "No")))


(let ((A (read))
      (B (read))
      (C (read))
      (D (read)))
     (if (< (ceiling A D)
            (ceiling C B))
         (princ "No")
         (princ "Yes")))


(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
           #\# #\> (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
(in-package :cl-user)

(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 ()
  (let* ((a (read))
         (b (read))
         (c (read))
         (d (read)))
    (write-line
     (loop for i from 0
           do (when (<= a 0)
                (return "No"))
              (when (<= c 0)
                (return "Yes"))
              (if (evenp i)
                  (decf c b)
                  (decf a d))))))

#-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 "10 9 10 10
"
    "No
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "46 4 40 5
"
    "Yes
")))


#|
------------------------------------
|               Utils               |
------------------------------------
|#

(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 :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

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

(defconstant +mod+ 1000000007)

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~a" b)) () '(signed-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~a" b)) () '(unsigned-byte ,b))) bits)))

(define-int-types 2 4 8 16 32 64)

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

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

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1
        (write obj :stream stream)
      (fresh-line stream))))

(defmacro safe-sort (list test &key (key #'identity))
  `(progn
    (declaim (inline sort sb-impl::stable-sort-list))
    (sort (copy-seq ,list) ,test :key ,key)))

(defmacro read-numbers-to-list (size)
  `(loop repeat ,size collect (read-fixnum)))

(defmacro read-numbers-to-array (size)
  (let ((i (gensym))
        (arr (gensym)))
    `(let ((,arr (make-array ,size
                             :element-type 'fixnum)))
       (declare ((array fixnum 1) ,arr))
       (loop for ,i of-type fixnum below ,size do
            (setf (aref ,arr ,i) (read))
          finally
            (return ,arr)))))

(defmacro read-characters-to-board (row-size column-size)
  (let ((board (gensym))
        (r (gensym))
        (c (gensym))
        (tmp (gensym)))
    `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))
       (dotimes (,r ,row-size ,board)
         (let ((,tmp (buffered-read-line)))
           (dotimes (,c ,column-size)
             (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))

(defmethod princ-for-each-line ((sequence list))
  (format t "~{~a~&~}" sequence))

(defmethod princ-for-each-line ((sequence vector))
  (loop for i below (length sequence) do
       (princ (aref sequence i))
       (fresh-line)))

(declaim (inline unwrap))
(defun unwrap (list)
  (the string
       (format nil "~{~a~^ ~}" list)))

(defmacro with-buffered-stdout (&body body)
  (let ((out (gensym)))
    `(let ((,out (make-string-output-stream :element-type 'base-char)))
       (let ((*standard-output* ,out))
         ,@body)
       (write-string (get-output-stream-string ,out)))))

(defmacro maxf (place cand)
  `(setf ,place (max ,place ,cand)))

(defmacro minf (place cand)
  `(setf ,place (min ,place ,cand)))

(defmacro modf (place &optional (m +mod+))
  `(setf ,place (mod ,place ,m)))

(defmacro alambda (parms &body body)
  `(labels ((self ,parms ,@body))
     #'self))

(defun iota (count &optional (start 0) (step 1))
  (loop for i from 0 below count collect (+ start (* i step))))

#|
------------------------------------
|               Body               |
------------------------------------
|#

(defun calc-digit (k)
  (length (format nil "~a" k)))

(defun char->int (c)
  (- (char-int c)
     (char-int #\0)))

(defun solve (n)
  (let* ((d (calc-digit n))
         (dp (make-array (1+ d) :initial-element 0))
         (n (reverse (concatenate 'list (format nil "~a" n)))))
    (loop for i below d
       do
         (setf (aref dp (1+ i))
               (mod (+ (aref dp i)
                       (* (char->int (pop n))
                          (expt 10 i)))
                    2019)))
    (loop for i below (1+ d)
       with memo = (make-array 2019)
       do
         (incf (aref memo (aref dp i)))
       finally
         (return
           (reduce #'+
                   (map 'vector (lambda (m)
                                  (floor (* m (1- m)) 2))
                        memo))))))

(defun main ()
  (declare #.OPT)
  (let ((n (read)))
    (princ (solve n))
    (fresh-line)))

#-swank (main)

Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.


#|
------------------------------------
|               Utils               |
------------------------------------
|#

(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 :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

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

(defconstant +mod+ 1000000007)

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~a" b)) () '(signed-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~a" b)) () '(unsigned-byte ,b))) bits)))

(define-int-types 2 4 8 16 32 64)

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

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

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1
        (write obj :stream stream)
      (fresh-line stream))))

(defmacro safe-sort (list test &key (key #'identity))
  `(progn
    (declaim (inline sort sb-impl::stable-sort-list))
    (sort (copy-seq ,list) ,test :key ,key)))

(defmacro read-numbers-to-list (size)
  `(loop repeat ,size collect (read-fixnum)))

(defmacro read-numbers-to-array (size)
  (let ((i (gensym))
        (arr (gensym)))
    `(let ((,arr (make-array ,size
                             :element-type 'fixnum)))
       (declare ((array fixnum 1) ,arr))
       (loop for ,i of-type fixnum below ,size do
            (setf (aref ,arr ,i) (read))
          finally
            (return ,arr)))))

(defmacro read-characters-to-board (row-size column-size)
  (let ((board (gensym))
        (r (gensym))
        (c (gensym))
        (tmp (gensym)))
    `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))
       (dotimes (,r ,row-size ,board)
         (let ((,tmp (buffered-read-line)))
           (dotimes (,c ,column-size)
             (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))

(defmethod princ-for-each-line ((sequence list))
  (format t "~{~a~&~}" sequence))

(defmethod princ-for-each-line ((sequence vector))
  (loop for i below (length sequence) do
       (princ (aref sequence i))
       (fresh-line)))

(declaim (inline unwrap))
(defun unwrap (list)
  (the string
       (format nil "~{~a~^ ~}" list)))

(defmacro with-buffered-stdout (&body body)
  (let ((out (gensym)))
    `(let ((,out (make-string-output-stream :element-type 'base-char)))
       (let ((*standard-output* ,out))
         ,@body)
       (write-string (get-output-stream-string ,out)))))

(defmacro maxf (place cand)
  `(setf ,place (max ,place ,cand)))

(defmacro minf (place cand)
  `(setf ,place (min ,place ,cand)))

(defmacro modf (place &optional (m +mod+))
  `(setf ,place (mod ,place ,m)))

(defmacro alambda (parms &body body)
  `(labels ((self ,parms ,@body))
     #'self))

(defun iota (count &optional (start 0) (step 1))
  (loop for i from 0 below count collect (+ start (* i step))))

#|
------------------------------------
|               Body               |
------------------------------------
|#

(defun calc-digit (k)
  (length (format nil "~a" k)))

(defun int->lst (k &optional (acc nil))
  (if (zerop k)
      acc
      (int->lst (floor k 10) (cons (rem k 10) acc))))

(defun solve (n)
  (let* ((d (calc-digit n))
         (dp (make-array (1+ d) :initial-element 0))
         (l (reverse (int->lst n))))
    (loop for i below d
       do
         (setf (aref dp (1+ i))
               (mod (+ (aref dp i)
                       (* (pop l)
                          (expt 10 i)))
                    2019)))
    (loop for i below (1+ d)
       with memo = (make-array 2019)
       do
         (incf (aref memo (aref dp i)))
       finally
         (return
           (reduce #'+
                   (map 'vector (lambda (m)
                                  (floor (* m (1- m)) 2))
                        memo))))))

(defun main ()
  (declare #.OPT)
  (let ((n (read)))
    (princ (solve n))
    (fresh-line)))

#-swank (main)


#|
------------------------------------
|               Utils               |
------------------------------------
|#

(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 :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

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

(defconstant +mod+ 1000000007)

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~a" b)) () '(signed-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~a" b)) () '(unsigned-byte ,b))) bits)))

(define-int-types 2 4 8 16 32 64)

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

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

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1
        (write obj :stream stream)
      (fresh-line stream))))

(defmacro safe-sort (list test &key (key #'identity))
  `(progn
    (declaim (inline sort sb-impl::stable-sort-list))
    (sort (copy-seq ,list) ,test :key ,key)))

(defmacro read-numbers-to-list (size)
  `(loop repeat ,size collect (read-fixnum)))

(defmacro read-numbers-to-array (size)
  (let ((i (gensym))
        (arr (gensym)))
    `(let ((,arr (make-array ,size
                             :element-type 'fixnum)))
       (declare ((array fixnum 1) ,arr))
       (loop for ,i of-type fixnum below ,size do
            (setf (aref ,arr ,i) (read))
          finally
            (return ,arr)))))

(defmacro read-characters-to-board (row-size column-size)
  (let ((board (gensym))
        (r (gensym))
        (c (gensym))
        (tmp (gensym)))
    `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))
       (dotimes (,r ,row-size ,board)
         (let ((,tmp (buffered-read-line)))
           (dotimes (,c ,column-size)
             (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))

(defmethod princ-for-each-line ((sequence list))
  (format t "~{~a~&~}" sequence))

(defmethod princ-for-each-line ((sequence vector))
  (loop for i below (length sequence) do
       (princ (aref sequence i))
       (fresh-line)))

(declaim (inline unwrap))
(defun unwrap (list)
  (the string
       (format nil "~{~a~^ ~}" list)))

(defmacro with-buffered-stdout (&body body)
  (let ((out (gensym)))
    `(let ((,out (make-string-output-stream :element-type 'base-char)))
       (let ((*standard-output* ,out))
         ,@body)
       (write-string (get-output-stream-string ,out)))))

(defmacro maxf (place cand)
  `(setf ,place (max ,place ,cand)))

(defmacro minf (place cand)
  `(setf ,place (min ,place ,cand)))

(defmacro modf (place &optional (m +mod+))
  `(setf ,place (mod ,place ,m)))

(defmacro alambda (parms &body body)
  `(labels ((self ,parms ,@body))
     #'self))

(defun iota (count &optional (start 0) (step 1))
  (loop for i from 0 below count collect (+ start (* i step))))

#|
------------------------------------
|               Body               |
------------------------------------
|#

(defun calc-digit (k &optional (acc 0))
  (if (zerop k)
      acc
      (calc-digit (floor k 10) (1+ acc))))

(defun int->lst (k &optional (acc nil))
  (if (zerop k)
      acc
      (int->lst (floor k 10) (cons (rem k 10) acc))))

(defun solve (n)
  (let* ((d (calc-digit n))
         (dp (make-array (1+ d) :initial-element 0))
         (l (reverse (int->lst n))))
    (loop for i below d
       do
         (setf (aref dp (1+ i))
               (mod (+ (aref dp i)
                       (* (pop l)
                          (expt 10 i)))
                    2019)))
    (loop for i below 2019
       with res = 0
       with tmp = 0
       do
         (setq tmp (count i dp
                          :test #'=))
         (incf res (floor (* tmp (1- tmp))
                          2))
       finally
         (return res))))

(defun main ()
  (declare #.OPT)
  (let ((n (read)))
    (princ (solve n))
    (fresh-line)))

#-swank (main)


(let* ((s (read-line))
       (n (length s))
       (dp (make-array (list (1+ n)) :initial-element 0))
       (c (make-array (list 2019) :initial-element 0))
       (ans 0))
  ;
  (setf (aref c 0) 1)
  ;
  (loop :for i :downfrom (1- n) :to 0
        :do (setf (aref dp i)
                  (mod (+ (aref dp (1+ i))
                          (* (mod (expt 10 (- n i 1)) 2019)
                             (- (char-code (aref s i)) #x30)))
                       2019))
        :do (incf (aref c (aref dp i))))
  (setf ans (loop :for i :from 0 :to 2018
                  :sum (/ (* (aref c i) (1- (aref c i))) 2)))
  (format t "~A~%" ans))


;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(declaim (type simple-string *s*))
(defvar *s* (coerce (read-line) 'simple-string))

(declaim (type fixnum *count*))
(defvar *count* 0) ;; *count* <= |S| <= 200000

(dotimes (i (length *s*))
  (let ((prev-mod 0))
    (declare (type fixnum prev-mod)) ;; 0<=prev-mod<=2019
    (loop for j from i to (1- (length *s*)) do
	  ;; calc curr-mod
	  (let ((curr-mod (mod (+ (* prev-mod 10)
				  (the (integer 0 10) (- (char-code (aref *s* j))
				     (char-code #\0))))
			       2019)))
	    (if (zerop curr-mod)
		(incf *count*))
	    (setf prev-mod curr-mod)))))
(princ *count*)


(defun create-answer (s size)
  (let ((tmp-result nil)
        (current-pos 0))
    (labels ((detect (base pos)
               (cond ((< size pos)
                      (return-from detect 'success))
                     ((< size (+ pos base))
                      (incf current-pos)
                      (detect 4 current-pos))
                     (t
                      (let ((tmp (subseq s pos (+ pos base))))
                        (if (= (mod (parse-integer tmp) 2019) 0)
                            (progn
                              (push t tmp-result)
                              (incf current-pos)
                              (detect 4 (+ base pos)))
                            (detect (1+ base) pos)))))))
      (detect 4 0)
      (length tmp-result))))

(let ((S (read-line)))
  (princ (create-answer S (length S))))


(let ((s (read-line)))
     (loop with x = 0
           for i from 1 to (floor (/ (parse-integer s)
                                     2019))
           do (let ((num (write-to-string (* i 2019))))
                   (loop for pos from 0 to (- (length s)
                                              (length num))
                         do (if (string= (subseq s
                                                 pos
                                                 (+ pos (length num)))
                                         num)
                                (incf x))))
           finally (format t "~A" x)))


(defun f (n)
  (- (char-code n) 48))

(defun ff (lst)
  (let* ((n (reverse lst)))
    (loop :for k :from 0
          :for j :in n
          :sum (* j (expt 10 k)))))

(let* ((len (map 'vector #'f (concatenate 'list (read-line))))
       (ln (1- (length len))))
  (princ (loop :for k :from 0 :upto (- ln 3)
               :sum (loop :for x :from (+ k 3) :upto ln
                          :for y := (subseq len k (1+ x))
                          :count t))))


(defun f (n)
  (- (char-code n) 48))

(defun ff (lst)
  (let* ((n (reverse lst)))
    (loop :for k :from 0
          :for j :in n
          :sum (* j (expt 10 k)))))

(let* ((len (map 'list #'f (concatenate 'list (read-line))))
       (ln (1- (length len))))
  (princ (loop :for k :from 0 :upto (- ln 3)
               :sum (loop :for x :from (+ k 3) :upto ln
                          :for y := (subseq len k (1+ x))
                          :count (= 0 (mod (ff y) 2019))))))


(let* ((len (map 'list #'f (concatenate 'list (read-line))))
       (ln (1- (length len))))
  (princ (loop :for k :from 0 :upto (- ln 3)
               :sum (loop :for x :from (+ k 3) :upto ln
                          :for y := (subseq len k (1+ x))
                          :count (= 0 (mod (ff y) 2019))))))


(let ((s (read-line)))
     (loop with x = 0
           for i from 0 below (- (length s) 3)
           do (loop for j from (+ i 3) below (length s)
                    do (if (zerop (mod (parse-integer (subseq s i (1+ j)))
                                       2019))
                           (incf x)))
           finally (format t "~A" x)))


(let* ((s (read-line))
       (l (length s))
       m)
  (labels ((f (n)
	     (let ((result (assoc n m :test #'=)))
	       (if result
		   (cdr result)
		   (prog1
		       (setf result (loop for x = n then (floor x 10)
				       until (< x 2019)
				       count (zerop (mod x 2019))))
		     (acons n result m))))))
    (if (< l 4)
	(format t "0~%")
	(format t "~d~%"
		(loop for i upto (- (length s) 4)
		   sum (f (parse-integer s :start i)))))))


(defvar arr1 (make-array 2019 :initial-element 0))
(defvar arr2 (make-array 2019))

(defun solve (S)
  (loop for x in S with result = 0 do
        (loop for i below 2019 with j do
              (setf j (mod (+ (* 10 i) x) 2019))
              (setf (aref arr2 j) (aref arr1 i)))
        (incf (aref arr2 x))
        (incf result (aref arr2 0))
        (rotatef arr1 arr2)
        finally (princ result)))

;(solve (loop repeat 200000 collect 1))

(solve (map 'list #'digit-char-p (read-line)))


(let* ((s (read-line))
       (l (length s)))
  (if (< l 4)
      (format t "0~%")
      (format t "~d~%"
	      (loop for i upto (- l 4)
		 for x = (parse-integer s :start i)
		 sum (loop for j upto (- l 4 i)
			count (zerop (mod (floor x (expt 10 j)) 2019)))))))


(let ((s (read-line)))
     (loop with x = 0
           for i from 0 below (length s)
           do (loop for j from i below (length s)
                    do (if (zerop (mod (parse-integer (subseq s i (1+ j)))
                                       2019))
                           (incf x)))
           finally (format t "~A" x)))