(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
;;;
;;; Arithmetic operations with static modulus
;;;

;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of
;; parameters is one.
(defmacro define-mod-operations (divisor)
  `(progn
     (defun mod* (&rest args)
       (reduce (lambda (x y) (mod (* x y) ,divisor)) args))

     (defun mod+ (&rest args)
       (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))

     #+sbcl
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (locally (declare (muffle-conditions warning))
         (sb-c:define-source-transform mod* (&rest args)
           (if (null args)
               1
               (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))
         (sb-c:define-source-transform mod+ (&rest args)
           (if (null args)
               0
               (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))

     (define-modify-macro incfmod (delta)
       (lambda (x y) (mod (+ x y) ,divisor)))

     (define-modify-macro decfmod (delta)
       (lambda (x y) (mod (- x y) ,divisor)))

     (define-modify-macro mulfmod (multiplier)
       (lambda (x y) (mod (* x y) ,divisor)))))

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

;;;
;;; Body
;;;

(define-mod-operations +mod+)
(defun main ()
  (let* ((s (map '(simple-array uint8 (*)) #'digit-char-p (read-line)))
         (n (length s))
         (cumul (make-array (+ n 1) :element-type 'uint31 :initial-element 0))
         (invs (make-array (+ n 1) :element-type 'uint31 :initial-element 0))
         (table (make-array 2020 :element-type 'uint31 :initial-element 0)))
    (setf (aref invs 0) 1)
    (dotimes (i n)
      (setf (aref invs (+ i 1))
            (mod* 202 (aref invs i))))
    #>invs
    (dotimes (i n)
      (setf (aref cumul (+ i 1))
            (mod+ (mod* (aref cumul i) 10) (aref s i))))
    #>cumul
    (let ((res 0))
      (dotimes (i (+ n 1))
        (let ((f (mod* (aref cumul i) (aref invs i))))
          (incf res (aref table f))
          (incf (aref table f))))
      (println 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 "1817181712114
"
    "3
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "14282668646
"
    "2
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "2119
"
    "0
")))


(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 *radius* (read))

(format t "~,6F" (* 2 pi *radius*))

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

Score : 100 points

Problem Statement

Print the circumference of a circle of radius R.

Constraints

1 \leq R \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

R

Output

Print the circumference of the circle.
Your output is considered correct if and only if its absolute or relative error from our answer is at most 10^{-2}.

Sample Input 1

1

Sample Output 1

6.28318530717958623200

Since we accept an absolute or relative error of at most 10^{-2}, 6.28 is also an acceptable output, but 6 is not.

Sample Input 2

73

Sample Output 2

458.67252742410977361942

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.


(format t "~,100F" (coerce (* pi (read) 2) 'double-float))


(princ (coerce (float (* x pi 2)) 'single-float))


(let ((*read-default-float-format* 'double-float))
  (let ((r (read)))
    (format t "~a~%" (* 2 pi r))))


(defun main ()
  (let ((r (read)))
    (format t "~f~%" (* 2 pi r))))
(main)


(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* ((r (read)))
    (println (* 2 pi r))))

#-swank (main)

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

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

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

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

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

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

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

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

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "1
"
    "6.28318530717958623200
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "73
"
    "458.67252742410977361942
")))


(let ((r (read)))
  (format t "~F~%" (* 2 r pi)))


(format t "~a~%"
	(let ((r (read)))
	  (* 2 pi r)))


(let ((r (read)))
(format t "~A" (* 2 r pi)))


(let ((r (read)))
   (format t "~a~%" (* 2 pi r)))


(princ
  (if (equal (find #\7 (read-line) :test #'equal) #\7)
      "Yes"
      "No"))

Score : 100 points

Problem Statement

Given is a three-digit integer N. Does N contain the digit 7?

If so, print Yes; otherwise, print No.

Constraints

100 \leq N \leq 999

Input

Input is given from Standard Input in the following format:

N

Output

If N contains the digit 7, print Yes; otherwise, print No.

Sample Input 1

117

Sample Output 1

Yes

117 contains 7 as its last digit.

Sample Input 2

123

Sample Output 2

No

123 does not contain the digit 7.

Sample Input 3

777

Sample Output 3

Yes


(defun app ()
    (let ((n (read-line))
        (ans "No"))

        (if (or (equal "7" (subseq n 0 1)) (equal "7" (subseq n 1 2)) (equal "7" (subseq n 2 3)))
        (setq ans "Yes"))

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

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

(format t "~:[No~;Yes~]" (loop for i fixnum = (read) then (floor i 10)
			      for r fixnum = (mod i 10)
			      while (/= i 0)
			      when (= r 7) do (return t)
			      finally (return nil)))


(princ (if (find #\7 (coerce (read-line) 'list)) "Yes" "No"))


(defun has777p (str)
 (< 0 (loop :as c :across str
               :as c7 :across "777"
        :when (eq c7 c)
        :count 1)))

(let ((str (read-line)))
  (princ (if (has777p str)
             "Yes"
             "No")))


(defun main ()
  (let* ((n (read-line)))
    (if (zerop (loop for c across n count (equal c #\7)))
      (format t "~a~%" "No")
      (format t "~a~%" "Yes"))))
(main)


(defun lucky-7 (s)
  (let ((counter 0))
    (loop :for c :across s
          :do (if (string= c "7") (incf counter)))
    (if (> counter 0)
        (princ "Yes")
        (princ "No"))))

(lucky-7 (read-line))


(if (some (lambda (x) (char= x #\7)) (concatenate 'list (read-line)))
    (princ "Yes")
    (princ "No"))


(let ((n (read-line)))
  (format t "~a~%" (if (some #'(lambda (x) (char= x #\7)) n)
                       "Yes"
                       "No")))


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

;; BEGIN_INSERTED_CONTENTS
(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-line)))
    (write-line (if (or (char= #\7 (aref n 0))
                        (char= #\7 (aref n 1))
                        (char= #\7 (aref n 2)))
                    "Yes"
                    "No"))))

#-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 "117
"
    "Yes
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "123
"
    "No
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "777
"
    "Yes
")))


;;(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 (integer 1 200) *k*))
(defvar *k* (read))

;; gcd(a,b,c) = gcd(gcd(a,b),c)

(princ (loop for a from 1 to *k* summing
	     (loop for b from 1 to *k*
		   for z = (gcd a b) summing
		   (loop for c from 1 to *k* summing
			 (gcd z c) fixnum) fixnum) fixnum))

Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692


(defun main ()
  (let ((n (read)))
    (princ (loop :as i :below n
                 :sum  (loop :as j :below n
                           :sum (loop :as k :below n
                                     :sum (gcd (+ i 1)
                                               (+ j 1)
                                               (+ k 1))))))))
(main)


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

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

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

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

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(defun main ()
  (declare #.OPT)
  (let* ((k (read))
         (res 0)
         (table (make-array 65536 :element-type 'uint8)))
    (declare (uint31 k res))
    (loop for x from 1 to k
          do (loop for y from 1 to k
                   do (setf (aref table (+ (ash x 8) y)) (gcd x y))))
    (loop for a from 1 to 200
          do (loop for b from 1 to 200
                   for gcd<<8 = (ash (aref table (+ (ash a 8) b)) 8)
                   do (loop for c from (+ gcd<<8 1) to (+ gcd<<8 191) by 10
                            do (incf res (aref table c))
                               (incf res (aref table (+ c 1)))
                               (incf res (aref table (+ c 2)))
                               (incf res (aref table (+ c 3)))
                               (incf res (aref table (+ c 4)))
                               (incf res (aref table (+ c 5)))
                               (incf res (aref table (+ c 6)))
                               (incf res (aref table (+ c 7)))
                               (incf res (aref table (+ c 8)))
                               (incf res (aref table (+ c 9))))))
    (println 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
"
    "9
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "200
"
    "10813692
")))


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

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

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

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

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(defun main ()
  (declare #.OPT)
  (let* ((k (read))
         (res 0)
         (table (make-array '65536 :element-type 'uint8)))
    (declare (uint31 k res))
    (loop for x from 1 to 200
          do (loop for y from 1 to 200
                   do (setf (aref table (+ (ash x 8) y)) (gcd x y))))
    (loop for a from 1 to k
          do (loop for b from 1 to k
                   for gcd<<8 = (ash (aref table (+ (ash a 8) b)) 8)
                   do (loop for c from 1 to k
                            do (incf res (aref table (+ gcd<<8 c))))))
    (println 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
"
    "9
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "200
"
    "10813692
")))


(defun Sum-of-gcd-of-Tuples (n)
    (let ((ans 0))
        (progn
            (loop
                :for i :from 1 :to n
                :do (loop
                        :for j :from 1 :to n
                        :do (loop
                                :for k :from 1 :to n
                                :do (incf ans (gcd (gcd i j) (gcd i k))))))
            ans)))

(princ (Sum-of-gcd-of-Tuples (read)))


(defun main ()
  (let* ((k (read)))
    (format t "~A~%"
	    (loop for a from 1 to k sum
		  (loop for b from 1 to k sum
			(loop for c from 1 to k sum
			      (gcd a b c)))))))
(main)


(defvar K (read))

(loop for a from 1 to K with s = 0 do
  (loop for b from 1 to K do
    (loop for c from 1 to K do
      (incf s (gcd a b c))
      ))
  finally (princ s))


(defvar K (read))

(loop for a from 1 to K with s
  (loop for b from 1 to K
    (loop for c from 1 to K
      (incf s (gcd a b c))
      ))
  finally (princ s))


(let ((k (read)))
  (format t "~a~%"
          (loop for a from 1 to k
                summing (loop for b from 1 to k
                              for gcd-ab = (gcd a b)
                              summing (loop for c from 1 to k
                                            summing (gcd gcd-ab c))))))


(let* ((n (read)))
  (princ (loop :for a :from 1 :upto n
               :sum(loop :for b :from 1 :upto n
                         :sum(loop :for c :from 1 :upto n
                                   :sum(gcd a b c))))))


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

;; BEGIN_INSERTED_CONTENTS
(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* ((k (read))
         (res 0))
    (declare (uint31 k))
    (loop for a from 1 to k
          do (loop for b from 1 to k
                   do (loop for c from 1 to k
                            do (incf res (gcd a b c)))))
    (println 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
"
    "9
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "200
"
    "10813692
")))


#+swank (declaim (optimize (speed 0) (safety 3) (debug 3)))
#-swank (declaim (optimize (speed 3) (safety 0) (debug 0)))

(defconstant +mod+ 1000000007)

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

(defmethod fast-sort ((sequence list) &key (test #'<))
  (declare (inline sort)
           (inline sb-impl::stable-sort-list))
  (sort sequence (lambda (x y)
                   (funcall test x y))))

(defmethod fast-sort ((sequence array) &key (test #'<))
  (declare (inline sort))
  (sort sequence (lambda (x y)
                   (funcall test x y))))

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

(defmacro read-numbers-to-array (size)
  `(progn
     (when (not (integerp ,size))
       (error "Size must be integer."))
     (when (< ,size 0)
       (error "Size must be plus or zero."))
     (make-array ,size :initial-contents (read-numbers-to-list ,size))))

(defmacro read-numbers-to-board (row-size column-size)
  (let ((board (gensym))
        (r (gensym))
        (c (gensym)))
    `(let ((,board (make-array '(,row-size ,column-size))))
       (dotimes (,r ,row-size)
         (dotimes (,c ,column-size)
           (setf (aref ,board ,r ,c) (read))))
       ,board)))

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

(defun unwrap (list)
  (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)))))

;;; Write code here

(defun solve (n s)
  (declare (fixnum n)
           (string s))
  (the fixnum
       (let ((ans (*
                   (count #\R s :test #'char-equal)
                   (count #\G s :test #'char-equal)
                   (count #\B s :test #'char-equal)
                   )))
         (declare (fixnum ans))
         (loop for i from 0 below (- n 2) do
              (loop for j from (1+ i) below (- n 1) do
                   (let ((k (- (* j 2)
                               i
                               )))
                     (unless (or
                              (>= k n)
                              (char-equal (elt s k)
                                          (elt s i))
                              (char-equal (elt s k)
                                          (elt s j))
                              (char-equal (elt s i)
                                          (elt s j)))
                       (decf ans))))
            finally
              (return ans)))))

(defun main ()
  (let ((n (read))
        (s (read-line)))
    (declare (fixnum n))
    (format t "~a~&" (solve n s))))

#-swank (main)

Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800


#+swank (declaim (optimize (speed 0) (safety 3) (debug 3)))
#-swank (declaim (optimize (speed 3) (safety 0) (debug 0)))

(defconstant +mod+ 1000000007)

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

(defmethod fast-sort ((sequence list) &key (test #'<))
  (declare (inline sort)
           (inline sb-impl::stable-sort-list))
  (sort sequence (lambda (x y)
                   (funcall test x y))))

(defmethod fast-sort ((sequence array) &key (test #'<))
  (declare (inline sort))
  (sort sequence (lambda (x y)
                   (funcall test x y))))

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

(defmacro read-numbers-to-array (size)
  `(progn
     (when (not (integerp ,size))
       (error "Size must be integer."))
     (when (< ,size 0)
       (error "Size must be plus or zero."))
     (make-array ,size :initial-contents (read-numbers-to-list ,size))))

(defmacro read-numbers-to-board (row-size column-size)
  (let ((board (gensym))
        (r (gensym))
        (c (gensym)))
    `(let ((,board (make-array '(,row-size ,column-size))))
       (dotimes (,r ,row-size)
         (dotimes (,c ,column-size)
           (setf (aref ,board ,r ,c) (read))))
       ,board)))

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

(defun unwrap (list)
  (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)))))

;;; Write code here

(defun solve (n s)
  (let ((ans 0))
    (loop for i from 0 below (- n 2) do
         (loop for j from (1+ i) below (- n 1) do
              (unless (char-equal (elt s i)
                                  (elt s j))
                (loop for k from (1+ j) below n do
                     (unless (or
                              (char-equal (elt s j)
                                          (elt s k))
                              (char-equal (elt s i)
                                          (elt s k))
                              (= (- j i)
                                 (- k j)))
                       (incf ans)))))
       finally
         (return ans))))

(defun main ()
  (let ((n (read))
        (s (read-line)))
    (format t "~a~&" (solve n s))))

#-swank (main)


(let ((n (read))
      (s (read-line))
      (ans 0))
  (loop :for a :from 0 :to (1- n)
        :for x := (char s a)
        :do (loop :for b :from (1+ a) :to (1- n)
                  :for y := (char s b)
                  :do (loop :for c :from (1+ b) :to (1- n)
                            :for z := (char s c)
                            :if (and (char/= x y z)
                                     (/= (- b a) (- c b)))
                            :do (incf ans))))
  (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 (integer 1 4000) *str-len*))
(defvar *str-len* (read))

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

;; t_i = s[0..i]
;; cnt(t_n) = cnt(t_(n-1)) +

(declaim (type (simple-array fixnum (*)) *table*))
(defvar *table* (make-array (1+ *str-len*)
			    :element-type 'fixnum))
(setf (aref *table* 0) 0)
(setf (aref *table* 1) 0)

(loop for i of-type (integer 1 4000) from 2 to (1- *str-len*) do
      ;; calculate (aref *table i)
      (let ((sum (aref *table* (1- i))))
	(loop for j of-type (integer 0 4000) from (1- i) downto 1 do
	      (when (char/= (aref *str* i) (aref *str* j))
		(incf sum
		      (count-if #'(lambda (c) (and (char/= (aref *str* j)
							   (aref *str* i)
							   c)))
				*str*
				:start 0
				:end j))
		(when (and (>= (+ j j (- i)) 0)
			   (char/= (aref *str* j)
				   (aref *str* i)
				   (aref *str* (+ j j (- i)))))
		  (decf sum))))
	(setf (aref *table* i) sum)))
(princ (aref *table* (1- *str-len*)))


(defun count-RGB (s c)
  (let ((counter 0))
    (loop :for i :across s
          :do (if (string= i c) (incf counter)))
    counter))

(defun RGB-Triplets (n s)
    (let ((ans 0))
        (incf ans (* (count-RGB s "R") (count-RGB s "G") (count-RGB s "B")))
        (loop
            :for i :from 0 :to (- n 3)
            :do (loop
                    :for j :from (+ i 2) :to (- n 1) :by 2
                    :do (cond
                            ((string= (char s i) (char s j)) ())
                            ((string= (char s i) (char s (/ (+ i j) 2))) ())
                            ((string= (char s j) (char s (/ (+ i j) 2))) ())
                            (t (decf ans)))))
        ans))

(princ (RGB-Triplets (read) (read-line)))


(defun count-RGB (s c)
  (let ((counter 0))
    (loop :for i :across s
          :do (if (string= i c) (incf counter)))
    counter))

(defun RGB-Triplets (n s)
    (let ((ans 0))
        (incf ans (* (* (count-RGB s "R") (count-RGB s "G") (count-RGB s "B"))))
        (loop
            :for i :from 0 :to (- n 2)
            :do (loop
                    :for j :from i :to (- n 1)
                    :do (cond
                            ((/= (mod (- j i) 2) 0) ())
                            ((string= (char s i) (char s j)) ())
                            ((string= (char s i) (char s (/ (+ i j) 2))) ())
                            ((string= (char s j) (char s (/ (+ i j) 2))) ())
                            (t (decf ans)))))
        ans))

(princ (RGB-Triplets (read) (read-line)))


(defun RGB-Triplets (n s)
    (let ((ans 0))
        (loop
            :for i :from 0 :to (- n 1)
            :do (loop
                    :for j :from i :to (- n 1)
                    :do (loop
                            :for k :from j :to (- n 1)
                            :do (cond
                                    ((> i j) ())
                                    ((> j k) ())
                                    ((= (- j i) (- k j))())
                                    ((char= (char s i) (char s j)) ())
                                    ((string= (char s j) (char s k)) ())
                                    ((string= (char s k) (char s i)) ())
                                    (t (incf ans))))))
        ans))

(princ (RGB-Triplets (read) (read-line)))


(defun calc (n text)
  (loop with r = 0
        with g = 0
        with b = 0
        for i below n
        do (case (schar text i)
             (#\R (incf r))
             (#\G (incf g))
             (#\B (incf b)))
        finally (return (* r g b))))

(defun minus (n text)
  (loop with x = 0
        for i below n
        do (loop for j from (1+ i) below n
                 if (< (- (* 2 j) i)
                       n)
                 do (if (and (not (equal (schar text i)
                                         (schar text j)))
                             (not (equal (schar text j)
                                         (schar text (- (* 2 j) i))))
                             (not (equal (schar text i)
                                         (schar text (- (* 2 j) i)))))
                        (incf x)))
        finally (return x)))

(let ((n (read))
      (text (read-line)))
     (format t "~A" (- (calc n text)
                       (minus n text))))


(defun main ()
  (let* ((n (read))
         (s (read-line))
         (ans 0))
     (dotimes (i n)
      (dotimes (j (- n i))
        (dotimes (k (- n i j))
          (if (and (/= j  k)  (char/= (aref s i) (aref s (+ i j)) (aref s (+ i j k))))
              (incf ans)))))
    (format t "~d~%" ans)))

(main)


(defun RGB-Triplets (n s)
    (let ((ans 0))
        (progn
            (loop
                :for i :across s
                :do (loop
                        :for j :across s
                        :do (loop
                                :for k :across s
                                :do (cond
                                        ((> i j) ())
                                        ((> j k) ())
                                        ((= (- j i) (- k j))())
                                        ((string= i j) ())
                                        ((string= j k) ())
                                        (t (incf ans))))))
            ans)))

(princ (RGB-Triplets (read) (read-line)))


(let* ((n (read))
       (r nil)
       (g nil)
       (b nil))
  (loop :for k :in (concatenate 'list (read-line))
        :for j :from 1
        :do(cond ((char= #\R k) (push j r))
                 ((char= #\G k) (push j g))
                 ((char= #\B k) (push j b))))
  (defun f (xx yy zz)
    (loop :for x :in xx
          :sum (loop :for y :in yy
                     :sum (loop :for z :in zz
                                  :if (and (not (cond ((< x y z) (= (- x y) (- y z)))
                                                      ((< x z y) (= (- x z) (- z y)))
                                                      ((< y x z) (= (- y x) (- x z)))
                                                      ((< y z x) (= (- y z) (- z x)))
                                                      ((< z x y) (= (- z x) (- x y)))
                                                      ((< z y x) (= (- z y) (- y x))))))
                                 :count t))))
  (print (f r g b)))


(defun search-index (v x)
  (declare (optimize (speed 3) (debug 0) (safety 0)))
  (loop for i from 0 below (length v)
        when (< x (aref v i))
        do (return i)
        finally (return (length v))))

(defun solve ()
  (declare (optimize (speed 3) (debug 0) (safety 0)))
  (let* ((n (read))
         (s (read-line))
         (si (make-array n :element-type 'fixnum))
         (count 0)
         r-list g-list b-list)
    (loop for i from 0 below n
          for c = (char s i)
          do (setf (aref si i)
                   (case c
                     (#\R 1)
                     (#\G 2)
                     (#\B 4)))
          do (case c
               (#\R (push i r-list))
               (#\G (push i g-list))
               (#\B (push i b-list))))
    (let ((v (vector (coerce (nreverse r-list) 'vector)
                     (coerce (nreverse g-list) 'vector)
                     (coerce (nreverse b-list) 'vector))))
      (labels ((get-index (c1 c2)
                 (case (+ c1 c2)
                   (3 2)
                   (5 1)
                   (6 0))))
      (loop for i from 0 below n
            do (loop for j from (+ i 1) below n
                     for k = (+ j (- j i))
                     when (/= (aref si i) (aref si j))
                     do (let* ((rgbv (aref v (get-index (aref si i)
                                                        (aref si j))))
                               (index (search-index rgbv j)))
                          (incf count (- (length rgbv) index)))
                     do (when (and (< k n)
                                   (/= (aref si i)
                                       (aref si j)
                                       (aref si k)))
                          (decf count))))
        (format t "~a~%" count)))))

(solve)


(defun main ()
  (let* ((n (read))
         (s (read-line))
         (ans 0))
    (dotimes (i n)
      (dotimes (j (- n i))
        (dotimes (k (- n i j))
          (if (and (char/= (aref s i) (aref s (+ i j)) (aref s (+ i j k))) (/= (- (+ j i) i) (- (+ i j k) (+ j i))))
              (incf ans)))))
    (format t "~d~%" ans)))

(main)


(defun main ()
  (let* ((n (read))
         (s (read-line))
         (ans 0))
    (dotimes (i n)
      (dotimes (j n)
        (dotimes (k n)
          (when (< i j k)
            (if (and (char/= (aref s i) (aref s j) (aref s k)) (/= (- j i) (- k j)))
                (incf ans))))))
    (format t "~d~%" ans)))

(main)


(declaim (optimize (speed 3) (debug 0) (safety 0)))
(defun parse-data (n text)
  (loop with x = 0
        for i from 0 below (- n 2)
        do (loop for j from (1+ i) below (1- n)
                 do (loop for k from (1+ j) below n
                          if (and (not (equal (schar text i)
                                              (schar text j)))
                                  (not (equal (schar text i)
                                              (schar text k)))
                                  (not (equal (schar text j)
                                              (schar text k)))
                                  (not (= (- j i)
                                          (- k j))))
                          do (incf x)))
        finally (format t "~A" x)))

(let ((n (read))
      (data (read-line)))
     (parse-data n data))


(defun solve ()
  (declare (optimize (speed 3) (debug 0) (safety 0)))
  (let ((n (read))
        (s (read-line))
        (count 0))
    (declare (type simple-string s))
    (flet ((check (i j k)
             (declare (type fixnum i j k))
             (and (/= (- j i) (- k j))
                  (char/= (char s i)
                          (char s j)
                          (char s k)))))
      (loop for i fixnum from 0 below n
            do (loop for j from (+ i 1) below n
                     when (char/= (char s i) (char s j))
                     do (loop for k from (+ j 1) below n
                              when (check i j k)
                              do (incf count))))
      (format t "~a~%" count))))

(solve)


(declaim (optimize (speed 3) (debug 0) (safety 0)))
(defun parse-data (text)
  (loop with x = 0
        for i from 0 below (- (length text) 2)
        do (loop for j from (1+ i) below (1- (length text))
                 do (loop for k from (1+ j) below (length text)
                          if (and (not (equal (aref text i)
                                              (aref text j)))
                                  (not (equal (aref text i)
                                              (aref text k)))
                                  (not (equal (aref text j)
                                              (aref text k)))
                                  (not (= (- j i)
                                          (- k j))))
                          do (incf x)))
        finally (format t "~A" x)))

(let ((n (read))
      (data (read-line)))
     (parse-data data))


(let ((n (read))
      (s (read-line))
      (count 0))
  (flet ((check (i j k)
           (and (/= (- j i) (- k j))
                (char/= (char s i)
                        (char s j)
                        (char s k)))))
    (loop for i from 0 below n
          do (loop for j from (+ i 1) below n
                   do (loop for k from (+ j 1) below n
                            when (check i j k)
                            do (incf count))))
    (format t "~a~%" count)))


(defun parse-data (text)
  (loop with x = 0
        for i from 0 below (- (length text) 2)
        do (loop for j from (1+ i) below (1- (length text))
                 do (loop for k from (1+ j) below (length text)
                          if (and (not (equal (aref text i)
                                              (aref text j)))
                                  (not (equal (aref text i)
                                              (aref text k)))
                                  (not (equal (aref text j)
                                              (aref text k)))
                                  (not (= (- j i)
                                          (- k j))))
                          do (incf x)))
        finally (format t "~A" x)))

(let ((n (read))
      (data (read-line)))
     (parse-data data))


(defun app ()
    (let ((a (read))
        (b (read))
        (c (read)))
    (format t "~D ~D ~D~%" c a b)
    )
)

(app)

Score : 100 points

Problem Statement

We have three boxes A, B, and C, each of which contains an integer.

Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.

We will now do the operations below in order. Find the content of each box afterward.

Swap the contents of the boxes A and B

Swap the contents of the boxes A and C

Constraints

1 \leq X,Y,Z \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z

Output

Print the integers contained in the boxes A, B, and C, in this order, with space in between.

Sample Input 1

1 2 3

Sample Output 1

3 1 2

After the contents of the boxes A and B are swapped, A, B, and C contain 2, 1, and 3, respectively.

Then, after the contents of A and C are swapped, A, B, and C contain 3, 1, and 2, respectively.

Sample Input 2

100 100 100

Sample Output 2

100 100 100

Sample Input 3

41 59 31

Sample Output 3

31 41 59


;; A - ABC Swap

(let ((x (read))
      (y (read))
      (z (read)))
  (format t "~{~a~^ ~}~%" (list z x y)))


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

;; BEGIN_INSERTED_CONTENTS
(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* ((x (read))
         (y (read))
         (z (read)))
    (rotatef x y)
    (rotatef x z)
    (format t "~D ~D ~D~%" x y z)))

#-swank (main)

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

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

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

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

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

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

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

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

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "1 2 3
"
    "3 1 2
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "100 100 100
"
    "100 100 100
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "41 59 31
"
    "31 41 59
")))


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

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

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

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

(defun main (a b c)
  (format t "~a ~a ~a~%" c a b))

(let ((a (read))
      (b (read))
      (c (read)))
  (main a b c))


#include <bits/stdc++.h>
using namespace std；

int a,b,c;

int main(){
	cin>>a>>b>>c;
	swap(a,b);
    swap(a,c);
	cout<<a<<' '<<b<<' '<<c;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<' '<<b<<' '<<c;
	return 0;
}


(let ((A (read))
      (B (read))
      (C (read))
      )
  (format t "~A ~A ~A~%" C A B ))


(let ((x (read))
      (y (read))
      (z (read)))
  (format t "~a ~a ~a~%" z x y))


(let ((a (read))
      (b (read))
      (c (read)))
     (format t "~A ~A ~A" c a b))


(defun app ()
    (let* ((n (read))
        (m (read))
        (a (make-array n :initial-element 0))
        (sum 0)
        (ans "Yes"))
        (dotimes (i n)
            (setf (aref a i) (read))
            (incf sum (aref a i))
        )
        (sort a '>)

        (dotimes (i m)
        (if (<= (aref a i) (/ sum (* 4 m)))
            (setq ans "No")
        )
        )
    (format t "~A~%" ans)
    )
)

(app)

Score : 200 points

Problem Statement

We have held a popularity poll for N items on sale. Item i received A_i votes.

From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.

If M popular items can be selected, print Yes; otherwise, print No.

Constraints

1 \leq M \leq N \leq 100

1 \leq A_i \leq 1000

A_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_N

Output

If M popular items can be selected, print Yes; otherwise, print No.

Sample Input 1

4 1
5 4 2 1

Sample Output 1

Yes

There were 12 votes in total. The most popular item received 5 votes, and we can select it.

Sample Input 2

3 2
380 19 1

Sample Output 2

No

There were 400 votes in total. The second and third most popular items received less than \dfrac{1}{4\times 2} of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.

Sample Input 3

12 3
4 56 78 901 2 345 67 890 123 45 6 789

Sample Output 3

Yes


;; B - Popular Vote

(defun can-choose (m a)
  "総得票数の1/(4*m)以上票を得た商品がm個以上あるか"
  (let* ((total (reduce #'+ a))
         (thres (ceiling total (* 4 m)))
         (npop  (count-if #'(lambda (x) (>= x thres)) a)))
    (>= npop m)))

(let* ((n (read))
       (m (read))
       (a (loop repeat n collect (read))))
  (princ (if (can-choose m a) "Yes" "No")))


(let* ((n (read))
       (m (read))
       (as (loop :repeat n :collect (read)))
       (sum (loop :as i :in as :sum i)))
    (if (<= m (length (remove-if (lambda (x) (< x (/ sum (* 4 m)))) as)))
        (princ "Yes")
        (princ "No")))


(let* ((n (read))
       (m (read))
       (as (loop :repeat n :collect (read)))
       (sum (loop :as i :in as :sum i)))
    (if (< m (length (remove-if (lambda (x) (< x (/ sum (* 4 m)))) as)))
        (princ "Yes")
        (princ "No")))


(let* ((n (read))
       (m (read))
       (a (list (read) (read) (read)))
       (lst (sort (concatenate 'list
                               (loop :repeat (first a) :collect (cons (read) 1))
                               (loop :repeat (second a) :collect (cons (read) 2))
                               (loop :repeat (third a) :collect (cons (read) 0)))
                  #'> :key #'car))
       (stkcount 0)
       (ans 0))
  (loop :for (k . j) :in lst :if (= (+ n m) stkcount) :return 0 :end
        :do(cond ((= j 1) (if (not (= 0 n))
                              (decf n)))
                 ((= j 2) (if (not (= 0 n))
                              (decf m)))
                 ((= j 0) (incf stkcount)))
        :do(incf ans k))
  (princ ans))

Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74


(defvar x (read))
(defvar y (read))
(defvar A (read))
(defvar B (read))
(defvar C (read))

(defvar  p (loop repeat A collect (read)))
(defvar  q (loop repeat B collect (read)))
(defvar  r (loop repeat C collect (read)))

(setf r (sort r #'>))

(defvar pq (sort (nconc
                  (nthcdr (- A x)  (sort p #'<))
                  (nthcdr (- B y)  (sort q #'<))
                  ) #'<))

(princ (loop repeat (+ x y)
             sum (max (or (car r) 0) (car pq))
             do (setf  r (cdr r))
             (setf  pq (cdr pq))
            ))


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

;; BEGIN_INSERTED_CONTENTS
(macrolet ((def (name fname)
             `(define-modify-macro ,name (new-value) ,fname)))
  (def minf min)
  (def maxf max)
  (def mulf *)
  (def divf /)
  (def iorf logior)
  (def xorf logxor)
  (def andf logand))

;;;
;;; Implicit treap
;;; (treap with implicit key)
;;;

;; Note:
;; - An empty treap is NIL.

(declaim (inline op))
(defun op (a b)
  "Is a binary operator comprising a monoid."
  (declare (fixnum a b))
  (+ a b))

(defconstant +op-identity+ 0
  "identity element w.r.t. OP")

(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value)))
                  (:copier nil)
                  (:conc-name %itreap-))
  (value +op-identity+ :type fixnum)
  (accumulator +op-identity+ :type fixnum)
  (priority 0 :type (integer 0 #.most-positive-fixnum))
  (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap
  (left nil :type (or null itreap))
  (right nil :type (or null itreap)))

(declaim (inline itreap-count))
(defun itreap-count (itreap)
  "Returns the number of the elements."
  (declare ((or null itreap) itreap))
  (if itreap
      (%itreap-count itreap)
      0))

(declaim (inline itreap-accumulator))
(defun itreap-accumulator (itreap)
  "Returns the sum (w.r.t. OP) of the whole ITREAP:
ITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1]."
  (declare ((or null itreap) itreap))
  (if itreap
      (%itreap-accumulator itreap)
      +op-identity+))

(declaim (inline update-count))
(defun update-count (itreap)
  (declare (itreap itreap))
  (setf (%itreap-count itreap)
        (+ 1
           (itreap-count (%itreap-left itreap))
           (itreap-count (%itreap-right itreap)))))

(declaim (inline update-accumulator))
(defun update-accumulator (itreap)
  (declare (itreap itreap))
  (setf (%itreap-accumulator itreap)
        (if (%itreap-left itreap)
            (if (%itreap-right itreap)
                (let ((mid (op (%itreap-accumulator (%itreap-left itreap))
                               (%itreap-value itreap))))
                  (declare (dynamic-extent mid))
                  (op mid (%itreap-accumulator (%itreap-right itreap))))
                (op (%itreap-accumulator (%itreap-left itreap))
                    (%itreap-value itreap)))
            (if (%itreap-right itreap)
                (op (%itreap-value itreap)
                    (%itreap-accumulator (%itreap-right itreap)))
                (%itreap-value itreap)))))

(declaim (inline force-up))
(defun force-up (itreap)
  "Propagates up the information from children."
  (declare (itreap itreap))
  (update-count itreap)
  (update-accumulator itreap))

(defun %heapify (top)
  "Properly swaps the priorities of the node and its two children."
  (declare (optimize (speed 3) (safety 0)))
  (when top
    (let ((high-priority-node top))
      (when (and (%itreap-left top)
                 (> (%itreap-priority (%itreap-left top))
                    (%itreap-priority high-priority-node)))
        (setq high-priority-node (%itreap-left top)))
      (when (and (%itreap-right top)
                 (> (%itreap-priority (%itreap-right top))
                    (%itreap-priority high-priority-node)))
        (setq high-priority-node (%itreap-right top)))
      (unless (eql high-priority-node top)
        (rotatef (%itreap-priority high-priority-node)
                 (%itreap-priority top))
        (%heapify high-priority-node)))))

(declaim (inline make-itreap))
(defun make-itreap (size &key initial-contents)
  "Makes a treap of SIZE in O(SIZE) time. Its values are filled with the
identity element unless INITIAL-CONTENTS are supplied."
  (declare ((or null vector) initial-contents))
  (labels ((build (l r)
             (declare ((integer 0 #.most-positive-fixnum) l r))
             (if (= l r)
                 nil
                 (let* ((mid (ash (+ l r) -1))
                        (node (%make-itreap (if initial-contents
                                                (aref initial-contents mid)
                                                +op-identity+)
                                           (random most-positive-fixnum))))
                   (setf (%itreap-left node) (build l mid))
                   (setf (%itreap-right node) (build (+ mid 1) r))
                   (%heapify node)
                   (force-up node)
                   node))))
    (build 0 size)))

(define-condition invalid-itreap-index-error (type-error)
  ((itreap :initarg :itreap :reader invalid-itreap-index-error-itreap)
   (index :initarg :index :reader invalid-itreap-index-error-index))
  (:report
   (lambda (condition stream)
     (let ((index (invalid-itreap-index-error-index condition)))
       (if (consp index)
           (format stream "Invalid range [~W, ~W) for itreap ~W."
                   (car index)
                   (cdr index)
                   (invalid-itreap-index-error-itreap condition))
           (format stream "Invalid index ~W for itreap ~W."
                   index
                   (invalid-itreap-index-error-itreap condition)))))))

(defun itreap-split (itreap index)
  "Destructively splits the ITREAP into two nodes [0, INDEX) and [INDEX, N),
where N is the number of the elements in ITREAP."
  (declare (optimize (speed 3))
           ((integer 0 #.most-positive-fixnum) index))
  (unless (<= index (itreap-count itreap))
    (error 'invalid-itreap-index-error :index index :itreap itreap))
  (labels ((recur (itreap ikey)
             (unless itreap
               (return-from itreap-split (values nil nil)))
             (let ((left-count (itreap-count (%itreap-left itreap))))
               (if (<= ikey left-count)
                   (multiple-value-bind (left right)
                       (itreap-split (%itreap-left itreap) ikey)
                     (setf (%itreap-left itreap) right)
                     (force-up itreap)
                     (values left itreap))
                   (multiple-value-bind (left right)
                       (itreap-split (%itreap-right itreap) (- ikey left-count 1))
                     (setf (%itreap-right itreap) left)
                     (force-up itreap)
                     (values itreap right))))))
    (recur itreap index)))

(defun itreap-merge (left right)
  "Destructively concatenates two ITREAPs."
  (declare (optimize (speed 3))
           ((or null itreap) left right))
  (cond ((null left) (when right (force-up right)) right)
        ((null right) (when left (force-up left)) left)
        (t (if (> (%itreap-priority left) (%itreap-priority right))
               (progn
                 (setf (%itreap-right left)
                       (itreap-merge (%itreap-right left) right))
                 (force-up left)
                 left)
               (progn
                 (setf (%itreap-left right)
                       (itreap-merge left (%itreap-left right)))
                 (force-up right)
                 right)))))

(defun itreap-insert (itreap index obj)
  "Destructively inserts OBJ into ITREAP and returns the resultant treap.

You cannot rely on the side effect. Use the returned value."
  (declare (optimize (speed 3))
           ((or null itreap) itreap)
           ((integer 0 #.most-positive-fixnum) index))
  (unless (<= index (itreap-count itreap))
    (error 'invalid-itreap-index-error :itreap itreap :index index))
  (let ((node (%make-itreap obj (random most-positive-fixnum))))
    (labels ((recur (itreap ikey)
               (declare ((integer 0 #.most-positive-fixnum) ikey))
               (unless itreap (return-from recur node))
               (if (> (%itreap-priority node) (%itreap-priority itreap))
                   (progn
                     (setf (values (%itreap-left node) (%itreap-right node))
                           (itreap-split itreap ikey))
                     (force-up node)
                     node)
                   (let ((left-count (itreap-count (%itreap-left itreap))))
                     (if (<= ikey left-count)
                         (setf (%itreap-left itreap)
                               (recur (%itreap-left itreap) ikey))
                         (setf (%itreap-right itreap)
                               (recur (%itreap-right itreap) (- ikey left-count 1))))
                     (force-up itreap)
                     itreap))))
      (recur itreap index))))

(defun itreap-delete (itreap index)
  "Destructively deletes the object at INDEX in ITREAP.

You cannot rely on the side effect. Use the returned value."
  (declare (optimize (speed 3))
           ((integer 0 #.most-positive-fixnum) index))
  (unless (< index (itreap-count itreap))
    (error 'invalid-itreap-index-error :itreap itreap :index index))
  (labels ((recur (itreap ikey)
             (declare ((integer 0 #.most-positive-fixnum) ikey))
             (let ((left-count (itreap-count (%itreap-left itreap))))
               (cond ((< ikey left-count)
                      (setf (%itreap-left itreap)
                            (recur (%itreap-left itreap) ikey))
                      (force-up itreap)
                      itreap)
                     ((> ikey left-count)
                      (setf (%itreap-right itreap)
                            (recur (%itreap-right itreap) (- ikey left-count 1)))
                      (force-up itreap)
                      itreap)
                     (t
                      (itreap-merge (%itreap-left itreap) (%itreap-right itreap)))))))
    (recur itreap index)))

(defmacro itreap-push (obj itreap pos)
  "Pushes OBJ to ITREAP at POS."
  `(setf ,itreap (itreap-insert ,itreap ,pos ,obj)))

(defmacro itreap-pop (itreap pos)
  "Returns the object at POS and deletes it."
  (let ((p (gensym)))
    `(let ((,p ,pos))
       (prog1 (itreap-ref ,itreap ,p)
         (setf ,itreap (itreap-delete ,itreap ,p))))))

(declaim (inline itreap-map))
(defun itreap-map (function itreap)
  "Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1]."
  (declare (function function))
  (labels ((recur (node)
             (when node
               (recur (%itreap-left node))
               (funcall function (%itreap-value node))
               (recur (%itreap-right node))
               (force-up node))))
    (recur itreap)))

(defmethod print-object ((object itreap) stream)
  (print-unreadable-object (object stream :type t)
    (let ((init t))
      (itreap-map (lambda (x)
                    (if init
                        (setq init nil)
                        (write-char #\  stream))
                   (write x :stream stream))
                 object))))

(defmacro do-itreap ((var itreap &optional result) &body body)
  "Successively binds ITREAP[0], ..., ITREAP[SIZE-1] to VAR and executes BODY
each time."
  `(block nil
     (itreap-map (lambda (,var) ,@body) ,itreap)
     ,result))

(defun itreap (&rest args)
  ;; NOTE: This function takes O(nlog(n)) time. Use MAKE-ITREAP for efficiency.
  (labels ((recur (list position itreap)
             (declare ((integer 0 #.most-positive-fixnum) position))
             (if (null list)
                 itreap
                 (recur (cdr list)
                        (1+ position)
                        (itreap-insert itreap position (car list))))))
    (recur args 0 nil)))

(declaim (inline itreap-ref))
(defun itreap-ref (itreap index)
  "Returns the element ITREAP[INDEX]."
  (declare ((integer 0 #.most-positive-fixnum) index))
  (unless (< index (itreap-count itreap))
    (error 'invalid-itreap-index-error :itreap itreap :index index))
  (labels ((%ref (itreap index)
             (declare ((integer 0 #.most-positive-fixnum) index))
             (prog1
                 (let ((left-count (itreap-count (%itreap-left itreap))))
                   (cond ((< index left-count)
                          (%ref (%itreap-left itreap) index))
                         ((> index left-count)
                          (%ref (%itreap-right itreap) (- index left-count 1)))
                         (t (%itreap-value itreap))))
               (force-up itreap))))
    (%ref itreap index)))

(declaim (inline (setf itreap-ref)))
(defun (setf itreap-ref) (new-value itreap index)
  "Sets ITREAP[INDEX] to the given value."
  (declare ((integer 0 #.most-positive-fixnum) index))
  (unless (< index (itreap-count itreap))
    (error 'invalid-itreap-index-error :itreap itreap :index index))
  (labels ((%set (itreap index)
             (declare ((integer 0 #.most-positive-fixnum) index))
             (prog1
                 (let ((left-count (itreap-count (%itreap-left itreap))))
                   (cond ((< index left-count)
                          (%set (%itreap-left itreap) index))
                         ((> index left-count)
                          (%set (%itreap-right itreap) (- index left-count 1)))
                         (t (setf (%itreap-value itreap) new-value))))
               (force-up itreap))))
    (%set itreap index)
    new-value))

(declaim (inline itreap-query))
(defun itreap-query (itreap l r)
  "Queries the `sum' (w.r.t. OP) of the range ITREAP[L, R)."
  (declare ((integer 0 #.most-positive-fixnum) l r))
  (unless (<= l r (itreap-count itreap))
    (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))
  (labels
      ((recur (itreap l r)
         (declare ((integer 0 #.most-positive-fixnum) l r))
         (unless itreap
           (return-from recur +op-identity+))
         (prog1
             (if (and (zerop l) (= r (%itreap-count itreap)))
                 (itreap-accumulator itreap)
                 (let ((left-count (itreap-count (%itreap-left itreap))))
                   (if (<= l left-count)
                       (if (< left-count r)
                           ;; LEFT-COUNT is in [L, R)
                           (op (op (recur (%itreap-left itreap) l (min r left-count))
                                   (%itreap-value itreap))
                               (recur (%itreap-right itreap) 0 (- r left-count 1)))
                           ;; LEFT-COUNT is in [R, END)
                           (recur (%itreap-left itreap) l (min r left-count)))
                       ;; LEFT-COUNT is in [0, L)
                       (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))
           (force-up itreap))))
    (recur itreap l r)))

;; FIXME: might be problematic when two priorities collide and START is not
;; zero. (It will be negligible from the viewpoint of probability, however.)
(declaim (inline itreap-range-bisect-left))
(defun itreap-range-bisect-left (itreap value order &optional (start 0))
  "Returns the smallest index that satisfies ITREAP[START]+ ITREAP[START+1] +
... + ITREAP[index] >= VALUE (if ORDER is #'<).

Note:
- This function handles a **closed** interval.
- This function returns the length of ITREAP instead if ITREAP[START]+
... +ITREAP[length-1] < VALUE.
- The prefix sums of ITREAP, (ITREAP[START], ITREAP[START]+ITREAP[START+1], ...)
  must be monotone w.r.t. ORDER.
- ORDER must be a strict order"
  (declare ((integer 0 #.most-positive-fixnum) start))
  (multiple-value-bind (itreap-prefix itreap)
      (if (zerop start)
          (values nil itreap)
          (itreap-split itreap start))
    (labels
        ((recur (itreap offset prev-sum)
           (declare ((integer 0 #.most-positive-fixnum) offset)
                    #+sbcl (values (integer 0 #.most-positive-fixnum)))
           (unless itreap
             (return-from recur offset))
           (let ((sum prev-sum))
             (prog1
                 (cond ((not (funcall order
                                      (setq sum (op sum (itreap-accumulator (%itreap-left itreap))))
                                      value))
                        (recur (%itreap-left itreap) offset prev-sum))
                       ((not (funcall order
                                      (setq sum (op sum (%itreap-value itreap)))
                                      value))
                        (+ offset (itreap-count (%itreap-left itreap))))
                       (t
                        (recur (%itreap-right itreap)
                               (+ offset (itreap-count (%itreap-left itreap)) 1)
                               sum)))
               (force-up itreap)))))
      (prog1 (+ start (recur itreap 0 +op-identity+))
        (itreap-merge itreap-prefix itreap)))))

;; merge/split version of itreap-query (a bit slower but simpler)
;; FIXME: might be problematic when two priorities collide.
#|
(declaim (inline itreap-query))
(defun itreap-query (itreap l r)
  "Queries the `sum' (w.r.t. OP) of the interval [L, R)."
  (declare ((integer 0 #.most-positive-fixnum) l r))
  (unless (<= l r (itreap-count itreap))
    (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))
  (if (= l r)
      +op-identity+
      (multiple-value-bind (itreap-0-l itreap-l-n)
          (itreap-split itreap l)
        (multiple-value-bind (itreap-l-r itreap-r-n)
            (itreap-split itreap-l-n (- r l))
          (prog1 (%itreap-accumulator itreap-l-r)
            (itreap-merge itreap-0-l (itreap-merge itreap-l-r itreap-r-n)))))))
;|#

;; merge/split version of itreap-update (a bit slower but simpler)
#|
(declaim (inline itreap-update))
(defun itreap-update (itreap operand l r)
  "Updates ITREAP[i] := (OP ITREAP[i] OPERAND) for all i in [l, r)"
  (declare ((integer 0 #.most-positive-fixnum) l r))
  (unless (<= l r (itreap-count itreap))
    (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))
  (multiple-value-bind (itreap-0-l itreap-l-n)
      (itreap-split itreap l)
    (multiple-value-bind (itreap-l-r itreap-r-n)
        (itreap-split itreap-l-n (- r l))
      (when itreap-l-r
        (setf (%itreap-lazy itreap-l-r)
              (updater-op (%itreap-lazy itreap-l-r) operand)))
      (itreap-merge itreap-0-l (itreap-merge itreap-l-r itreap-r-n)))))
;|#

;;;
;;; Utilities for sorted treap
;;;

(declaim (inline itreap-bisect-left)
         (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-left))
(defun itreap-bisect-left (itreap threshold order)
  "Takes a **sorted** treap and returns the smallest index that satisfies
ITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the
size of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is
O(log(n))."
  (labels ((recur (count itreap)
             (declare ((integer 0 #.most-positive-fixnum) count))
             (cond ((null itreap) nil)
                   ((funcall order (%itreap-value itreap) threshold)
                    (recur count (%itreap-right itreap)))
                   (t
                    (let ((left-count (- count (itreap-count (%itreap-right itreap)) 1)))
                      (or (recur left-count (%itreap-left itreap))
                          left-count))))))
    (or (recur (itreap-count itreap) itreap)
        (itreap-count itreap))))

(declaim (inline itreap-bisect-right)
         (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-right))
(defun itreap-bisect-right (itreap threshold order)
  "Takes a **sorted** treap and returns the smallest index that satisfies
THRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if
ITREAP[length-1] <= THRESHOLD. The time complexity is O(log(n))."
  (labels ((recur (count itreap)
             (declare ((integer 0 #.most-positive-fixnum) count))
             (cond ((null itreap) nil)
                   ((funcall order threshold (%itreap-value itreap))
                    (let ((left-count (- count (itreap-count (%itreap-right itreap)) 1)))
                      (or (recur left-count (%itreap-left itreap))
                          left-count)))
                   (t
                    (recur count (%itreap-right itreap))))))
    (or (recur (itreap-count itreap) itreap)
        (itreap-count itreap))))

(declaim (inline itreap-insort))
(defun itreap-insort (itreap obj order)
  "Does insertion to the sorted treap."
  (let ((pos (itreap-bisect-left itreap obj order)))
    (itreap-insert itreap pos obj)))

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

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

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

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

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(defun %sort (vec)
  (declare ((simple-array uint32 (*)) vec)
           (inline sort))
  (sort vec #'>))

(defun main ()
  (let* ((x (read))
         (y (read))
         (a (read))
         (b (read))
         (c (read))
         (ps (make-array a :element-type 'uint32))
         (qs (make-array b :element-type 'uint32))
         (rs (make-array c :element-type 'uint32)))
    (dotimes (i a)
      (setf (aref ps i) (read-fixnum)))
    (dotimes (i b)
      (setf (aref qs i) (read-fixnum)))
    (dotimes (i c)
      (setf (aref rs i) (read-fixnum)))
    (setq ps (%sort ps)
          qs (%sort qs)
          rs (%sort rs))
    (let ((cumuls-red (make-array (+ 1 a) :element-type 'uint62))
          (cumuls-colorless (make-array (+ 1 c) :element-type 'uint62))
          (dp (make-itreap b :initial-contents qs))
          (res 0))
      (dotimes (i a)
        (setf (aref cumuls-red (+ i 1))
              (+ (aref cumuls-red i) (aref ps i))))
      (dotimes (i c)
        (setf (aref cumuls-colorless (+ i 1))
              (+ (aref cumuls-colorless i) (aref rs i))))
      #>cumuls-red
      #>cumuls-colorless
      (loop for k from c downto 0
            do (unless (= k c)
                 (setq dp (itreap-insort dp (aref rs k) #'>)))
               #>dp
               (when (<= k x)
                 ;; 先頭k個を赤に塗る。赤からは上位x-k個を選ぶ
                 (maxf res (+ (aref cumuls-red (- x k))
                              (aref cumuls-colorless k)
                              #>(itreap-query dp 0 (min y (itreap-count dp)))))))
      (println 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 "1 2 2 2 1
2 4
5 1
3
"
    "12
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "2 2 2 2 2
8 6
9 1
2 1
"
    "25
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4
"
    "74
")))


(let ((a (read))
      (b (read))
      (c (read)))
  (if (and (< 0 (- c a b))
           (< (* 4 a b) (expt (- c a b) 2)))
      (format t "Yes~%")
      (format t "No~%")))

Score : 300 points

Problem Statement

Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?

Constraints

1 \leq a, b, c \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a \ b \ c

Output

If \sqrt{a} + \sqrt{b} < \sqrt{c}, print Yes; otherwise, print No.

Sample Input 1

2 3 9

Sample Output 1

No

\sqrt{2} + \sqrt{3} < \sqrt{9} does not hold.

Sample Input 2

2 3 10

Sample Output 2

Yes

\sqrt{2} + \sqrt{3} < \sqrt{10} holds.


(defun sqrt-inequality ()
  (let ((a (read))
        (b (read))
        (c (read))
        (ans "No"))
    (if (and (< 0 (- c a b)) (< (* 4 a b) (expt (- c a b) 2)))
      (setf ans "Yes"))
    ans))

(format t "~A~%" (sqrt-inequality))


(format t "~:[No~;Yes~]~%"
	(let* ((a (read))
	       (b (read))
	       (c (read))
	       (d (- c a b)))
	  (and (plusp d)
	       (< (* 4 a b) (expt d 2)))))


(format t "~A"
	(if (> 0 (-(+ (sqrt (read)) (sqrt (read)))(sqrt (read)))) "Yes" "No"))


(format t "~A~%"
	(if (> 0 (-(+ (sqrt (read)) (sqrt (read)))(sqrt (read)))) "Yes" "No"))


(defun sqrt-inequality ()
  (let ((a (read))
        (b (read))
        (c (read))
        (ans "Yes"))
    (unless (< (+ (sqrt a) (sqrt b)) (sqrt c))
      (setf ans "No"))
    ans))

(format t "~A~%" (sqrt-inequality))


(format t "~:[No~;Yes~]~%"
	(< (+ (sqrt (read)) (sqrt (read))) (sqrt (read))))


(let ((a (read))
      (b (read))
      (c (read)))
  (if (< (+ (sqrt a) (sqrt b)) (sqrt c))
      (princ "Yes")
      (princ "No")))


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

;; BEGIN_INSERTED_CONTENTS
(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)))
    (write-line
     (if (< (- c a b) 0)
         "No"
         (if (< (* 4 a b) (expt (- c a b) 2))
             "Yes"
             "No")))))

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


(defun main ()
  (let* ((n (read))
         (m (read))
         (s (make-array `(,n) :element-type 'character :initial-element #\0))
         (c (make-array `(,(1+ n)) :initial-element nil)))
    (if (/= n 1) (setf (aref s 0) #\1))
    (loop
          :for i :from 1 :to m
          :do (let ((x (read))
                    (y (read)))
                (when (and (aref c x) (/= (aref c x) y))
                  (format t "-1~%")
                  (return-from main))
                (setf (aref c x) y)
                (setf (aref s (1- x)) (code-char (+ y 48)))
                (when (and (/= n 1) (= x 1) (= y 0))
                  (format t "-1~%")
                  (return-from main))))
    (format t "~A~%" s)))
(main)

Score : 300 points

Problem Statement

If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)

The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)

Constraints

All values in input are integers.

1 \leq N \leq 3

0 \leq M \leq 5

1 \leq s_i \leq N

0 \leq c_i \leq 9

Input

Input is given from Standard Input in the following format:

N M
s_1 c_1
\vdots
s_M c_M

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702

702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them.

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1


(defun main ()
  (let* ((n (read))
         (m (read))
         (s (make-array `(,n) :element-type 'character :initial-element #\0))
         (c (make-array `(,(1+ n)) :initial-element nil)))
    (setf (aref s 0) #\1)
    (loop
          :for i :from 1 :to m
          :do (let ((x (read))
                    (y (read)))
                (when (and (aref c x) (/= (aref c x) y))
                  (format t "-1~%")
                  (return-from main))
                (setf (aref c x) y)
                (setf (aref s (1- x)) (code-char (+ y 48)))
                (when (and (/= n 1) (= x 1) (= y 0))
                  (format t "-1~%")
                  (return-from main))))
    (format t "~A~%" s)))
(main)


(defun main ()
  (let* ((n (read))
         (m (read))
         (s (make-array `(,n) :element-type 'character :initial-element #\0))
         (c (make-array `(,(1+ n)) :initial-element nil)))
    (setf (aref s 0) #\1)
    (loop
          :for i :from 1 :to m
          :do (let ((x (read))
                    (y (read)))
                (when (and (aref c x) (/= (aref c x) y))
                  (format t "-1~%")
                  (return-from main))
                (setf (aref c x) y)
                (setf (aref s (1- x)) (code-char (+ y 48)))
                (when (and (= x 1) (= y 0))
                  (format t "-1~%")
                  (return-from main))))
    (format t "~A~%" s)))
(main)


(defstruct const s c)

(defun solve (N M lst)
  (loop named outer
        for i from (if (= N 1) 0 (expt 10 (1- N)))
        to (1- (expt 10 N)) do
        (loop for x in lst
              with vec = (concatenate 'vector (princ-to-string i))
              unless (eq (aref vec (const-s x))
                         (const-c x))
              return nil
              finally (return-from outer i))
        finally (return-from outer -1)))

(let ((N (read))
      (M (read)))
     (princ (solve N M
                   (loop repeat M
                         collect (make-const :s (1- (read)) :c (read-char))))))


(defvar N)
(defvar M)
(defvar arr)
(setf N (read)
      M (read)
      arr (make-array (1+ N)
                      :initial-element nil)
      (aref arr 0) 'dummy)

(defun input ()
  (loop with Si
        and Ci
        repeat M do
        (setf Si (read)
              Ci (read))
        (if #1=(aref arr Si)
            (if (/= #1# Ci)
                (return nil))
            (setf #1# Ci))
        finally (return t)))

(defun output ()
  (if (null #2=(aref arr 1)) (setf #2# 1))
  (if (zerop #2#)
      (princ -1)
      (loop with x = 0
            repeat N
            do
            (princ (or (aref arr (incf x))
                       0 )))))

(if (input)
    (output)
    (princ -1))