(defun lcs (str1 str2 &key (backtrace nil))
  (let* ((dp-table (make-array (list (1+ (length str1)) (1+ (length str2)))
                               :initial-element 0 :element-type 'fixnum)))
    (loop :for k :from 1 :upto (length str1)
          :do(loop :for l :from 1 :upto (length str2)
                   :do (setf (aref dp-table k l) (max (aref dp-table (1- k) l)
                                                      (aref dp-table k (1- l))
                                                      (if (char= (aref str1 (1- k))
                                                                 (aref str2 (1- l)))
                                                          (1+ (aref dp-table (1- k) (1- l)))
                                                          0)))))
    (if backtrace
        (let* ((ret nil)
               (mem (length str2)))
          (loop :for k :from (length str1) :downto 1
                :do(loop :for l :from mem :downto 1
                         :always (= (aref dp-table k l)
                                    (aref dp-table k mem))
                         :never (if (and (not (= (aref dp-table k l) (aref dp-table (1- k) l)))
                                         (not (= (aref dp-table k l) (aref dp-table k (1- l)))))
                                    (progn (push l ret) (setf mem (1- l))))))
          (concatenate 'String (loop :for k :in ret :collect (aref str2 (1- k)))))
        dp-table)))
(princ (lcs (read-line) (read-line) :backtrace t))


(defun lcs (str1 str2 &key (backtrace nil))
  (let* ((dp-table (make-array (list (1+ (length str1)) (1+ (length str2)))
                               :initial-element 0 :element-type 'fixnum)))
    (loop :for k :from 1 :upto (length str1)
          :do(loop :for l :from 1 :upto (length str2)
                   :do (setf (aref dp-table k l) (max (aref dp-table (1- k) l)
                                                      (aref dp-table k (1- l))
                                                      (if (char= (aref str1 (1- k))
                                                                 (aref str2 (1- l)))
                                                          (1+ (aref dp-table (1- k) (1- l)))
                                                          0)))))
    (if backtrace
        (let* ((ret nil)
               (mem (length str2)))
          (loop :for k :from (length str1) :downto 1
                :do(loop :for l :from (1- mem) :downto 1
                         :always (= (aref dp-table k l)
                                    (aref dp-table k (1- mem)))
                         :never (if (and (not (= (aref dp-table k l) (aref dp-table (1- k) l)))
                                         (not (= (aref dp-table k l) (aref dp-table k (1- l)))))
                                    (push l ret))))
          (concatenate 'String (loop :for k :in ret :collect (aref str2 (1- k)))))
        dp-table)))
(princ (lcs (read-line) (read-line) :backtrace t))

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

Score : 100 points

Problem Statement

You are given strings s and t.
Find one longest string that is a subsequence of both s and t.

Notes

A subsequence of a string x is the string obtained by removing zero or more characters from x and concatenating the remaining characters without changing the order.

Constraints

s and t are strings consisting of lowercase English letters.

1 \leq |s|, |t| \leq 3000

Input

Input is given from Standard Input in the following format:

s
t

Output

Print one longest string that is a subsequence of both s and t.
If there are multiple such strings, any of them will be accepted.

Sample Input 1

axyb
abyxb

Sample Output 1

axb

The answer is axb or ayb; either will be accepted.

Sample Input 2

aa
xayaz

Sample Output 2

aa

Sample Input 3

a
z

Sample Output 3

The answer is (an empty string).

Sample Input 4

abracadabra
avadakedavra

Sample Output 4

aaadara

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.


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

;; BEGIN_INSERTED_CONTENTS
(defmacro nlet (name args &body body)
  (labels ((ensure-list (x) (if (listp x) x (list x))))
    (let ((args (mapcar #'ensure-list args)))
      `(labels ((,name ,(mapcar #'car args) ,@body))
         (,name ,@(mapcar #'cadr args))))))

;; (with-memoizing (:hash-table :test #'equal :key #'cons)
;;   (defun ...))
;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)
;;   (defun ...))
(defmacro with-memoizing (cache-attribs def-form)
  (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))
         (cache-type (first cache-attribs))
         (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))
         (dimensions (remove '* dimensions-with-*))
         (rank (length dimensions))
         (rest-attribs (ecase cache-type
                         (:hash-table (cdr cache-attribs))
                         (:array (cddr cache-attribs))))
         (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))
         (cache-form (case cache-type
                       (:hash-table `(make-hash-table ,@rest-attribs))
                       (:array `(make-array ',dimensions ,@rest-attribs))))
         (initial-element (when (eql cache-type :array)
                            (assert (member :initial-element rest-attribs))
                            (getf rest-attribs :initial-element))))
    (let ((cache (gensym))
          (value (gensym))
	  (present-p (gensym))
          (name-alias (gensym))
	  (args-lst (gensym))
          (indices (loop repeat rank collect (gensym))))
      (labels ((make-cache-check-form (cache-type args)
                 (case cache-type
                   (:hash-table
                    `(let ((,args-lst (funcall ,(or key #'list) ,@args)))
                       (multiple-value-bind (,value ,present-p)
                           (gethash ,args-lst ,cache)
                         (if ,present-p
                             ,value
                             (setf (gethash ,args-lst ,cache)
                                   (,name-alias ,@args))))))
                   (:array
                    (let ((memoized-args (loop for dimension in dimensions-with-*
                                               for arg in args
                                               unless (eql dimension '*)
                                               collect arg)))
                      (if key
                          `(multiple-value-bind ,indices
                               (funcall ,key ,@memoized-args)
                             (let ((,value (aref ,cache ,@indices)))
                               (if (eql ,initial-element ,value)
                                   (setf (aref ,cache ,@indices)
                                         (,name-alias ,@args))
                                   ,value)))
                          `(let ((,value (aref ,cache ,@memoized-args)))
                             (if (eql ,initial-element ,value)
                                 (setf (aref ,cache ,@memoized-args)
                                       (,name-alias ,@args))
                                 ,value)))))))
               (make-reset-form (cache-type)
                 (case cache-type
                   (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))
                   (:array `(prog1 nil
                              (fill (array-storage-vector ,cache) ,initial-element)))))
               (make-reset-name (name)
                 (intern (format nil "RESET-~A" (symbol-name name))))
               (extract-declarations (body)
                 (remove-if-not (lambda (form) (eql 'declare (car form))) body)))
        (ecase (car def-form)
          ((defun)
           (destructuring-bind (_ name args &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (defun ,(make-reset-name name) () ,(make-reset-form cache-type))
                (defun ,name ,args
                  (labels ((,name-alias ,args ,@body))
                    (declare (inline ,name-alias))
                    ,@(extract-declarations body)
                    ,(make-cache-check-form cache-type args))))))
          ((nlet)
           (destructuring-bind (_ name bindings &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (nlet ,name ,bindings
                      ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))
                         `(labels ((,name-alias ,args ,@body))
                            (declare (inline ,name-alias))
                            ,@(extract-declarations body)
                            ,(make-cache-check-form cache-type args)))))))
          ((labels flet)
           (destructuring-bind (_ definitions &body labels-body) def-form
             (declare (ignore _))
             (destructuring-bind (name args &body body) (car definitions)
               `(let ((,cache ,cache-form))
                  (,(car def-form)
                   ((,(make-reset-name name) () ,(make-reset-form cache-type))
                    (,name ,args
                           (labels ((,name-alias ,args ,@body))
                             (declare (inline ,name-alias))
                             ,@(extract-declarations body)
                             ,(make-cache-check-form cache-type args)))
                    ,@(cdr definitions))
                   (declare (ignorable #',(make-reset-name name)))
                   ,@labels-body))))))))))

;; (test with-memoizing
;;   (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (labels ((add (x y) (+ x y))
;; 		                     (my-print (x) (print x)))
;; 	                      (add 1 2))))))

(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 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil

(defun solve (str1 str2)
  (declare #.OPT
           (simple-base-string str1 str2))
  (let ((len1 (length str1))
        (len2 (length str2))
        (lcs-table (make-array '(3001 3001) :element-type 'list
                                            :initial-element nil)))
    (declare ((simple-array list (* *)) lcs-table))
    (with-memoizing (:array (3001 3001) :element-type 'uint15
                     :initial-element #.(- (expt 2 15) 1))
      (nlet recurse ((i 0) (j 0))
        (cond ((or (= len1 i) (= len2 j)) 0)
              ((char= (schar str1 i) (schar str2 j))
               (let* ((res1 (1+ (recurse (+ i 1) (+ j 1))))
                      (res2 (recurse i (+ j 1)))
                      (res3 (recurse (+ i 1) j))
                      (maxres (max res1 res2 res3)))
                 (setf (aref lcs-table i j)
                       (cond ((= res1 maxres)
                              (cons (schar str1 i) (aref lcs-table (+ i 1) (+ j 1))))
                             ((= res2 maxres)
                              (aref lcs-table i (+ j 1)))
                             (t
                              (aref lcs-table (+ i 1) j))))
                 maxres))
              (t
               (let* ((res1 (recurse i (+ j 1)))
                      (res2 (recurse (+ i 1) j))
                      (maxres (max res1 res2)))
                 (setf (aref lcs-table i j)
                       (if (= res1 maxres)
                           (aref lcs-table i (+ j 1))
                           (aref lcs-table (+ i 1) j)))
                 maxres)))))
    (coerce (aref lcs-table 0 0) 'simple-base-string)))

(defun main ()
  (let* ((str1 (coerce (read-line) 'simple-base-string))
         (str2 (coerce (read-line) 'simple-base-string)))
    (write-line (solve str1 str2))))

#-swank(main)


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

;; BEGIN_INSERTED_CONTENTS
(defmacro nlet (name args &body body)
  (labels ((ensure-list (x) (if (listp x) x (list x))))
    (let ((args (mapcar #'ensure-list args)))
      `(labels ((,name ,(mapcar #'car args) ,@body))
         (,name ,@(mapcar #'cadr args))))))

;; (with-memoizing (:hash-table :test #'equal :key #'cons)
;;   (defun ...))
;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)
;;   (defun ...))
(defmacro with-memoizing (cache-attribs def-form)
  (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))
         (cache-type (first cache-attribs))
         (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))
         (dimensions (remove '* dimensions-with-*))
         (rank (length dimensions))
         (rest-attribs (ecase cache-type
                         (:hash-table (cdr cache-attribs))
                         (:array (cddr cache-attribs))))
         (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))
         (cache-form (case cache-type
                       (:hash-table `(make-hash-table ,@rest-attribs))
                       (:array `(make-array ',dimensions ,@rest-attribs))))
         (initial-element (when (eql cache-type :array)
                            (assert (member :initial-element rest-attribs))
                            (getf rest-attribs :initial-element))))
    (let ((cache (gensym))
          (value (gensym))
	  (present-p (gensym))
          (name-alias (gensym))
	  (args-lst (gensym))
          (indices (loop repeat rank collect (gensym))))
      (labels ((make-cache-check-form (cache-type args)
                 (case cache-type
                   (:hash-table
                    `(let ((,args-lst (funcall ,(or key #'list) ,@args)))
                       (multiple-value-bind (,value ,present-p)
                           (gethash ,args-lst ,cache)
                         (if ,present-p
                             ,value
                             (setf (gethash ,args-lst ,cache)
                                   (,name-alias ,@args))))))
                   (:array
                    (let ((memoized-args (loop for dimension in dimensions-with-*
                                               for arg in args
                                               unless (eql dimension '*)
                                               collect arg)))
                      (if key
                          `(multiple-value-bind ,indices
                               (funcall ,key ,@memoized-args)
                             (let ((,value (aref ,cache ,@indices)))
                               (if (eql ,initial-element ,value)
                                   (setf (aref ,cache ,@indices)
                                         (,name-alias ,@args))
                                   ,value)))
                          `(let ((,value (aref ,cache ,@memoized-args)))
                             (if (eql ,initial-element ,value)
                                 (setf (aref ,cache ,@memoized-args)
                                       (,name-alias ,@args))
                                 ,value)))))))
               (make-reset-form (cache-type)
                 (case cache-type
                   (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))
                   (:array `(prog1 nil
                              (fill (array-storage-vector ,cache) ,initial-element)))))
               (make-reset-name (name)
                 (intern (format nil "RESET-~A" (symbol-name name))))
               (extract-declarations (body)
                 (remove-if-not (lambda (form) (eql 'declare (car form))) body)))
        (ecase (car def-form)
          ((defun)
           (destructuring-bind (_ name args &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (defun ,(make-reset-name name) () ,(make-reset-form cache-type))
                (defun ,name ,args
                  (labels ((,name-alias ,args ,@body))
                    (declare (inline ,name-alias))
                    ,@(extract-declarations body)
                    ,(make-cache-check-form cache-type args))))))
          ((nlet)
           (destructuring-bind (_ name bindings &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (nlet ,name ,bindings
                      ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))
                         `(labels ((,name-alias ,args ,@body))
                            (declare (inline ,name-alias))
                            ,@(extract-declarations body)
                            ,(make-cache-check-form cache-type args)))))))
          ((labels flet)
           (destructuring-bind (_ definitions &body labels-body) def-form
             (declare (ignore _))
             (destructuring-bind (name args &body body) (car definitions)
               `(let ((,cache ,cache-form))
                  (,(car def-form)
                   ((,(make-reset-name name) () ,(make-reset-form cache-type))
                    (,name ,args
                           (labels ((,name-alias ,args ,@body))
                             (declare (inline ,name-alias))
                             ,@(extract-declarations body)
                             ,(make-cache-check-form cache-type args)))
                    ,@(cdr definitions))
                   (declare (ignorable #',(make-reset-name name)))
                   ,@labels-body))))))))))

;; (test with-memoizing
;;   (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (labels ((add (x y) (+ x y))
;; 		                     (my-print (x) (print x)))
;; 	                      (add 1 2))))))

(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 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil

(defun solve (str1 str2)
  (declare #.OPT
           (simple-base-string str1 str2))
  (let ((len1 (length str1))
        (len2 (length str2))
        (lcs-table (make-array '(3001 3001) :element-type 'list
                                            :initial-element nil)))
    (declare (dynamic-extent lcs-table))
    (with-memoizing (:array (3001 3001) :element-type 'uint15
                     :initial-element #.(- (expt 2 15) 1))
      (nlet recurse ((i 0) (j 0))
        (cond ((or (= len1 i) (= len2 j)) 0)
              ((char= (schar str1 i) (schar str2 j))
               (let* ((res1 (1+ (recurse (+ i 1) (+ j 1))))
                      (res2 (recurse i (+ j 1)))
                      (res3 (recurse (+ i 1) j))
                      (maxres (max res1 res2 res3)))
                 (setf (aref lcs-table i j)
                       (cond ((= res1 maxres)
                              (cons (schar str1 i) (aref lcs-table (+ i 1) (+ j 1))))
                             ((= res2 maxres)
                              (aref lcs-table i (+ j 1)))
                             (t
                              (aref lcs-table (+ i 1) j))))
                 maxres))
              (t
               (let* ((res1 (recurse i (+ j 1)))
                      (res2 (recurse (+ i 1) j))
                      (maxres (max res1 res2)))
                 (setf (aref lcs-table i j)
                       (if (= res1 maxres)
                           (aref lcs-table i (+ j 1))
                           (aref lcs-table (+ i 1) j)))
                 maxres)))))
    (coerce (aref lcs-table 0 0) 'simple-base-string)))

(defun main ()
  (let* ((str1 (coerce (read-line) 'simple-base-string))
         (str2 (coerce (read-line) 'simple-base-string)))
    (write-line (solve str1 str2))))

#-swank(main)


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

;; BEGIN_INSERTED_CONTENTS
(defmacro nlet (name args &body body)
  (labels ((ensure-list (x) (if (listp x) x (list x))))
    (let ((args (mapcar #'ensure-list args)))
      `(labels ((,name ,(mapcar #'car args) ,@body))
         (,name ,@(mapcar #'cadr args))))))

;; (with-memoizing (:hash-table :test #'equal :key #'cons)
;;   (defun ...))
;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)
;;   (defun ...))
(defmacro with-memoizing (cache-attribs def-form)
  (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))
         (cache-type (first cache-attribs))
         (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))
         (dimensions (remove '* dimensions-with-*))
         (rank (length dimensions))
         (rest-attribs (ecase cache-type
                         (:hash-table (cdr cache-attribs))
                         (:array (cddr cache-attribs))))
         (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))
         (cache-form (case cache-type
                       (:hash-table `(make-hash-table ,@rest-attribs))
                       (:array `(make-array ',dimensions ,@rest-attribs))))
         (initial-element (when (eql cache-type :array)
                            (assert (member :initial-element rest-attribs))
                            (getf rest-attribs :initial-element))))
    (let ((cache (gensym))
          (value (gensym))
	  (present-p (gensym))
          (name-alias (gensym))
	  (args-lst (gensym))
          (indices (loop repeat rank collect (gensym))))
      (labels ((make-cache-check-form (cache-type args)
                 (case cache-type
                   (:hash-table
                    `(let ((,args-lst (funcall ,(or key #'list) ,@args)))
                       (multiple-value-bind (,value ,present-p)
                           (gethash ,args-lst ,cache)
                         (if ,present-p
                             ,value
                             (setf (gethash ,args-lst ,cache)
                                   (,name-alias ,@args))))))
                   (:array
                    (let ((memoized-args (loop for dimension in dimensions-with-*
                                               for arg in args
                                               unless (eql dimension '*)
                                               collect arg)))
                      (if key
                          `(multiple-value-bind ,indices
                               (funcall ,key ,@memoized-args)
                             (let ((,value (aref ,cache ,@indices)))
                               (if (eql ,initial-element ,value)
                                   (setf (aref ,cache ,@indices)
                                         (,name-alias ,@args))
                                   ,value)))
                          `(let ((,value (aref ,cache ,@memoized-args)))
                             (if (eql ,initial-element ,value)
                                 (setf (aref ,cache ,@memoized-args)
                                       (,name-alias ,@args))
                                 ,value)))))))
               (make-reset-form (cache-type)
                 (case cache-type
                   (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))
                   (:array `(prog1 nil
                              (fill (array-storage-vector ,cache) ,initial-element)))))
               (make-reset-name (name)
                 (intern (format nil "RESET-~A" (symbol-name name))))
               (extract-declarations (body)
                 (remove-if-not (lambda (form) (eql 'declare (car form))) body)))
        (ecase (car def-form)
          ((defun)
           (destructuring-bind (_ name args &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (defun ,(make-reset-name name) () ,(make-reset-form cache-type))
                (defun ,name ,args
                  (labels ((,name-alias ,args ,@body))
                    (declare (inline ,name-alias))
                    ,@(extract-declarations body)
                    ,(make-cache-check-form cache-type args))))))
          ((nlet)
           (destructuring-bind (_ name bindings &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (nlet ,name ,bindings
                      ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))
                         `(labels ((,name-alias ,args ,@body))
                            (declare (inline ,name-alias))
                            ,@(extract-declarations body)
                            ,(make-cache-check-form cache-type args)))))))
          ((labels flet)
           (destructuring-bind (_ definitions &body labels-body) def-form
             (declare (ignore _))
             (destructuring-bind (name args &body body) (car definitions)
               `(let ((,cache ,cache-form))
                  (,(car def-form)
                   ((,(make-reset-name name) () ,(make-reset-form cache-type))
                    (,name ,args
                           (labels ((,name-alias ,args ,@body))
                             (declare (inline ,name-alias))
                             ,@(extract-declarations body)
                             ,(make-cache-check-form cache-type args)))
                    ,@(cdr definitions))
                   (declare (ignorable #',(make-reset-name name)))
                   ,@labels-body))))))))))

;; (test with-memoizing
;;   (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (labels ((add (x y) (+ x y))
;; 		                     (my-print (x) (print x)))
;; 	                      (add 1 2))))))

(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 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil

(defun solve (str1 str2)
  (declare #.OPT)
  (let ((len1 (length str1))
        (len2 (length str2))
        (lcs-table (make-array '(3001 3001) :element-type 'list
                                            :initial-element nil)))
    (with-memoizing (:array (3001 3001) :element-type 'uint16
                     :initial-element #.(- (expt 2 16) 1))
      (nlet recurse ((i 0) (j 0))
        (cond ((or (= len1 i) (= len2 j)) 0)
              ((eql (schar str1 i) (schar str2 j))
               (let* ((res1 (1+ (recurse (+ i 1) (+ j 1))))
                      (res2 (recurse i (+ j 1)))
                      (res3 (recurse (+ i 1) j))
                      (maxres (max res1 res2 res3)))
                 (setf (aref lcs-table i j)
                       (cond ((= res1 maxres)
                              (cons (schar str1 i) (aref lcs-table (+ i 1) (+ j 1))))
                             ((= res2 maxres)
                              (aref lcs-table i (+ j 1)))
                             (t
                              (aref lcs-table (+ i 1) j))))
                 maxres))
              (t
               (let* ((res1 (recurse i (+ j 1)))
                      (res2 (recurse (+ i 1) j))
                      (maxres (max res1 res2)))
                 (setf (aref lcs-table i j)
                       (if (= res1 maxres)
                           (aref lcs-table i (+ j 1))
                           (aref lcs-table (+ i 1) j)))
                 maxres)))))
    (coerce (aref lcs-table 0 0) 'simple-base-string)))

(defun main ()
  (let* ((str1 (coerce (read-line) 'simple-base-string))
         (str2 (coerce (read-line) 'simple-base-string)))
    (write-line (solve str1 str2))))

#-swank(main)


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

;; BEGIN_INSERTED_CONTENTS
(defmacro nlet (name args &body body)
  (labels ((ensure-list (x) (if (listp x) x (list x))))
    (let ((args (mapcar #'ensure-list args)))
      `(labels ((,name ,(mapcar #'car args) ,@body))
         (,name ,@(mapcar #'cadr args))))))

;; (with-memoizing (:hash-table :test #'equal :key #'cons)
;;   (defun ...))
;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)
;;   (defun ...))
(defmacro with-memoizing (cache-attribs def-form)
  (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))
         (cache-type (first cache-attribs))
         (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))
         (dimensions (remove '* dimensions-with-*))
         (rank (length dimensions))
         (rest-attribs (ecase cache-type
                         (:hash-table (cdr cache-attribs))
                         (:array (cddr cache-attribs))))
         (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))
         (cache-form (case cache-type
                       (:hash-table `(make-hash-table ,@rest-attribs))
                       (:array `(make-array ',dimensions ,@rest-attribs))))
         (initial-element (when (eql cache-type :array)
                            (assert (member :initial-element rest-attribs))
                            (getf rest-attribs :initial-element))))
    (let ((cache (gensym))
          (value (gensym))
	  (present-p (gensym))
          (name-alias (gensym))
	  (args-lst (gensym))
          (indices (loop repeat rank collect (gensym))))
      (labels ((make-cache-check-form (cache-type args)
                 (case cache-type
                   (:hash-table
                    `(let ((,args-lst (funcall ,(or key #'list) ,@args)))
                       (multiple-value-bind (,value ,present-p)
                           (gethash ,args-lst ,cache)
                         (if ,present-p
                             ,value
                             (setf (gethash ,args-lst ,cache)
                                   (,name-alias ,@args))))))
                   (:array
                    (let ((memoized-args (loop for dimension in dimensions-with-*
                                               for arg in args
                                               unless (eql dimension '*)
                                               collect arg)))
                      (if key
                          `(multiple-value-bind ,indices
                               (funcall ,key ,@memoized-args)
                             (let ((,value (aref ,cache ,@indices)))
                               (if (eql ,initial-element ,value)
                                   (setf (aref ,cache ,@indices)
                                         (,name-alias ,@args))
                                   ,value)))
                          `(let ((,value (aref ,cache ,@memoized-args)))
                             (if (eql ,initial-element ,value)
                                 (setf (aref ,cache ,@memoized-args)
                                       (,name-alias ,@args))
                                 ,value)))))))
               (make-reset-form (cache-type)
                 (case cache-type
                   (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))
                   (:array `(prog1 nil
                              (fill (array-storage-vector ,cache) ,initial-element)))))
               (make-reset-name (name)
                 (intern (format nil "RESET-~A" (symbol-name name))))
               (extract-declarations (body)
                 (remove-if-not (lambda (form) (eql 'declare (car form))) body)))
        (ecase (car def-form)
          ((defun)
           (destructuring-bind (_ name args &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (defun ,(make-reset-name name) () ,(make-reset-form cache-type))
                (defun ,name ,args
                  (labels ((,name-alias ,args ,@body))
                    (declare (inline ,name-alias))
                    ,@(extract-declarations body)
                    ,(make-cache-check-form cache-type args))))))
          ((nlet)
           (destructuring-bind (_ name bindings &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (nlet ,name ,bindings
                      ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))
                         `(labels ((,name-alias ,args ,@body))
                            (declare (inline ,name-alias))
                            ,@(extract-declarations body)
                            ,(make-cache-check-form cache-type args)))))))
          ((labels flet)
           (destructuring-bind (_ definitions &body labels-body) def-form
             (declare (ignore _))
             (destructuring-bind (name args &body body) (car definitions)
               `(let ((,cache ,cache-form))
                  (,(car def-form)
                   ((,(make-reset-name name) () ,(make-reset-form cache-type))
                    (,name ,args
                           (labels ((,name-alias ,args ,@body))
                             (declare (inline ,name-alias))
                             ,@(extract-declarations body)
                             ,(make-cache-check-form cache-type args)))
                    ,@(cdr definitions))
                   (declare (ignorable #',(make-reset-name name)))
                   ,@labels-body))))))))))

;; (test with-memoizing
;;   (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (labels ((add (x y) (+ x y))
;; 		                     (my-print (x) (print x)))
;; 	                      (add 1 2))))))

(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 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil

(defun solve (str1 str2)
  (let ((len1 (length str1))
        (len2 (length str2))
        (lcs-table (make-array '(3001 3001) :element-type 'list
                                            :initial-element nil)))
    (with-memoizing (:array (3001 3001) :element-type 'uint16
                     :initial-element #.(- (expt 2 16) 1))
      (nlet recurse ((i 0) (j 0))
        (cond ((or (= len1 i) (= len2 j)) 0)
              ((eql (schar str1 i) (schar str2 j))
               (let* ((res1 (1+ (recurse (+ i 1) (+ j 1))))
                      (res2 (recurse i (+ j 1)))
                      (res3 (recurse (+ i 1) j))
                      (maxres (max res1 res2 res3)))
                 (setf (aref lcs-table i j)
                       (cond ((= res1 maxres)
                              (cons (schar str1 i) (aref lcs-table (+ i 1) (+ j 1))))
                             ((= res2 maxres)
                              (aref lcs-table i (+ j 1)))
                             ((= res3 maxres)
                              (aref lcs-table (+ i 1) j))
                             (t (error "Huh?"))))
                 maxres))
              (t
               (let* ((res1 (recurse i (+ j 1)))
                      (res2 (recurse (+ i 1) j))
                      (maxres (max res1 res2)))
                 (setf (aref lcs-table i j)
                       (cond ((= res1 maxres)
                              (aref lcs-table i (+ j 1)))
                             ((= res2 maxres)
                              (aref lcs-table (+ i 1) j))
                             (t (error "Huh?"))))
                 maxres)))))
    (coerce (aref lcs-table 0 0) 'simple-base-string)))

(defun main ()
  (let* ((str1 (coerce (read-line) 'simple-base-string))
         (str2 (coerce (read-line) 'simple-base-string)))
    (write-line (solve str1 str2))))

#-swank(main)


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

;; BEGIN_INSERTED_CONTENTS
(defmacro nlet (name args &body body)
  (labels ((ensure-list (x) (if (listp x) x (list x))))
    (let ((args (mapcar #'ensure-list args)))
      `(labels ((,name ,(mapcar #'car args) ,@body))
         (,name ,@(mapcar #'cadr args))))))

;; (with-memoizing (:hash-table :test #'equal :key #'cons)
;;   (defun ...))
;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)
;;   (defun ...))
(defmacro with-memoizing (cache-attribs def-form)
  (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))
         (cache-type (first cache-attribs))
         (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))
         (dimensions (remove '* dimensions-with-*))
         (rank (length dimensions))
         (rest-attribs (ecase cache-type
                         (:hash-table (cdr cache-attribs))
                         (:array (cddr cache-attribs))))
         (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))
         (cache-form (case cache-type
                       (:hash-table `(make-hash-table ,@rest-attribs))
                       (:array `(make-array ',dimensions ,@rest-attribs))))
         (initial-element (when (eql cache-type :array)
                            (assert (member :initial-element rest-attribs))
                            (getf rest-attribs :initial-element))))
    (let ((cache (gensym))
          (value (gensym))
	  (present-p (gensym))
          (name-alias (gensym))
	  (args-lst (gensym))
          (indices (loop repeat rank collect (gensym))))
      (labels ((make-cache-check-form (cache-type args)
                 (case cache-type
                   (:hash-table
                    `(let ((,args-lst (funcall ,(or key #'list) ,@args)))
                       (multiple-value-bind (,value ,present-p)
                           (gethash ,args-lst ,cache)
                         (if ,present-p
                             ,value
                             (setf (gethash ,args-lst ,cache)
                                   (,name-alias ,@args))))))
                   (:array
                    (let ((memoized-args (loop for dimension in dimensions-with-*
                                               for arg in args
                                               unless (eql dimension '*)
                                               collect arg)))
                      (if key
                          `(multiple-value-bind ,indices
                               (funcall ,key ,@memoized-args)
                             (let ((,value (aref ,cache ,@indices)))
                               (if (eql ,initial-element ,value)
                                   (setf (aref ,cache ,@indices)
                                         (,name-alias ,@args))
                                   ,value)))
                          `(let ((,value (aref ,cache ,@memoized-args)))
                             (if (eql ,initial-element ,value)
                                 (setf (aref ,cache ,@memoized-args)
                                       (,name-alias ,@args))
                                 ,value)))))))
               (make-reset-form (cache-type)
                 (case cache-type
                   (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))
                   (:array `(prog1 nil
                              (fill (array-storage-vector ,cache) ,initial-element)))))
               (make-reset-name (name)
                 (intern (format nil "RESET-~A" (symbol-name name))))
               (extract-declarations (body)
                 (remove-if-not (lambda (form) (eql 'declare (car form))) body)))
        (ecase (car def-form)
          ((defun)
           (destructuring-bind (_ name args &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (defun ,(make-reset-name name) () ,(make-reset-form cache-type))
                (defun ,name ,args
                  (labels ((,name-alias ,args ,@body))
                    (declare (inline ,name-alias))
                    ,@(extract-declarations body)
                    ,(make-cache-check-form cache-type args))))))
          ((nlet)
           (destructuring-bind (_ name bindings &body body) def-form
             (declare (ignore _))
             `(let ((,cache ,cache-form))
                (nlet ,name ,bindings
                      ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))
                         `(labels ((,name-alias ,args ,@body))
                            (declare (inline ,name-alias))
                            ,@(extract-declarations body)
                            ,(make-cache-check-form cache-type args)))))))
          ((labels flet)
           (destructuring-bind (_ definitions &body labels-body) def-form
             (declare (ignore _))
             (destructuring-bind (name args &body body) (car definitions)
               `(let ((,cache ,cache-form))
                  (,(car def-form)
                   ((,(make-reset-name name) () ,(make-reset-form cache-type))
                    (,name ,args
                           (labels ((,name-alias ,args ,@body))
                             (declare (inline ,name-alias))
                             ,@(extract-declarations body)
                             ,(make-cache-check-form cache-type args)))
                    ,@(cdr definitions))
                   (declare (ignorable #',(make-reset-name name)))
                   ,@labels-body))))))))))

;; (test with-memoizing
;;   (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (defun add (x y) (+ x y)))))
;;   (finishes (macroexpand `(with-memoizing (:array '(10 10)
;;                                            :element-type 'fixnum
;;                                            :initial-element -1)
;;                             (labels ((add (x y) (+ x y))
;; 		                     (my-print (x) (print x)))
;; 	                      (add 1 2))))))

(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 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil

(defun solve (str1 str2)
  (let ((len1 (length str1))
        (len2 (length str2))
        (lcs-table (make-array '(3001 3001) :element-type 'list
                                            :initial-element nil)))
    (with-memoizing (:array (3001 3001) :element-type 'uint16
                     :initial-element #.(- (expt 2 16) 1))
      (nlet recurse ((i len1) (j len2))
        (cond ((or (zerop i) (zerop j)) 0)
              ((eql (schar str1 (- i 1)) (schar str2 (- j 1)))
               (let* ((res1 (1+ (recurse (- i 1) (- j 1))))
                      (res2 (recurse i (- j 1)))
                      (res3 (recurse (- i 1) j))
                      (maxres (max res1 res2 res3)))
                 (setf (aref lcs-table i j)
                       (cond ((= res1 maxres)
                              (cons (schar str1 (- i 1))
                                    (aref lcs-table (- i 1) (- j 1))))
                             ((= res2 maxres)
                              (aref lcs-table i (- j 1)))
                             ((= res3 maxres)
                              (aref lcs-table (- i 1) j))
                             (t (error "Huh?"))))
                 maxres))
              (t
               (let* ((res1 (recurse i (- j 1)))
                      (res2 (recurse (- i 1) j))
                      (maxres (max res1 res2)))
                 (setf (aref lcs-table i j)
                       (cond ((= res1 maxres)
                              (aref lcs-table i (- j 1)))
                             ((= res2 maxres)
                              (aref lcs-table (- i 1) j))
                             (t (error "Huh?"))))
                 maxres)))))
    (coerce (nreverse (aref lcs-table len1 len2)) 'string)))

(defun main ()
  (let* ((str1 (coerce (read-line) 'simple-base-string))
         (str2 (coerce (read-line) 'simple-base-string)))
    (write-line (solve str1 str2))))

#-swank(main)


(write-line (ecase (read)
  (22 "Christmas Eve Eve Eve")
  (23 "Christmas Eve Eve")
  (24 "Christmas Eve")
  (25 "Christmas")))

Score : 100 points

Problem Statement

In some other world, today is December D-th.

Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.

Constraints

22 \leq D \leq 25

D is an integer.

Input

Input is given from Standard Input in the following format:

D

Output

Print the specified string (case-sensitive).

Sample Input 1

25

Sample Output 1

Christmas

Sample Input 2

22

Sample Output 2

Christmas Eve Eve Eve

Be sure to print spaces between the words.


(let ((d (read)))
     (cond
       ((= d 25) (princ "Christmas"))
       ((= d 24) (princ "Christmas Eve"))
       ((= d 23) (princ "Christmas Eve Eve"))
       (t        (princ "Christmas Eve Eve Eve")))


(defun func (x)
  (when (< x 25)
	(progn
	  (princ " Eve")
	  (func (1+ x)))))

(princ "Christmas")
(func (read))


(defparameter d (read))
(defparameter num (- 25 d))
(defparameter s "Christmas")
(dotimes (i num)
  (setq s (concatenate 'string s " Eve")))
(princ s)


(defparameter d (read))
(defparameter num (- 25 d))
(defparameter s "Chiristmas")
(dotimes (i num)
  (setq s (concatenate 'string s " Eve")))
(princ s)


  (let ((D (read)))
    (princ
      (case D
        (25 "Christmas")
        (24 "Christmas Eve")
        (23 "Christmas Eve Eve")
        (22 "Christmas Eve Eve Eve"))))


(defmacro ch-pr (n)
  `(progn (princ "Christmas")
  (loop :repeat ,n :do(princ " Eve"))))
(case (read)
  ((22) (ch-pr 3))
  ((23) (ch-pr 2))
  ((24) (ch-pr 1))
  ((25) (ch-pr 0)))


(setq n(- 25(read)))
(princ"Christmas")
(dotimes(i n)(princ" Eve"))


(let ((d (read)))
  (cond ((= d 25)
         (princ "Christmas"))
        ((= d 24)
         (princ "Christmas Eve"))
        ((= d 23)
         (princ "Christmas Eve Eve"))
        ((= d 22)
         (princ "Christmas Eve Eve Eve"))))


(defun pyramid-height (c n h)
  (+ h (abs (- (car n) (car c))) (abs (- (cdr n) (cdr c)))))

(defun pyramid-find (list)
  (loop :for cx :from 0 :upto 100
          :thereis(loop :for cy :from 0 :upto 100
                          :thereis (if (and
                                        (apply #'= (mapcar (lambda (k)
                                                             (pyramid-height (cons cx cy) (first k) (second k))) list))
                                        (<= 0 (pyramid-height (cons cx cy) (first (car list)) (second (car list))) ))
                                       (format t "~A ~A ~A" cx cy (pyramid-height (cons cx cy) (first (car list)) (second (car list))))))))
(let* ((n (read))
       (lst (loop :repeat n :collect (list (cons (read) (read)) (read)))))
  (pyramid-find lst))

Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

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

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.


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

;; BEGIN_INSERTED_CONTENTS
(defmacro split-ints-bind (vars string &body body)
  (let ((position (gensym))
        (s (gensym)))
    (labels ((expand (vars &optional init-pos)
               (if (null vars)
                   body
                   `((multiple-value-bind (,(car vars) ,position)
                         (parse-integer ,s :start ,(or init-pos position)
                                           :junk-allowed t)
                       ,@(when (null (cdr vars)) `((declare (ignore ,position))))
                       ,@(expand (cdr vars)))))))
      `(let ((,s ,string))
         (declare (string ,s))
         ,@(expand vars 0)))))

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

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((n (read))
         (hxy-table (make-array n :element-type '(cons uint32 (cons uint32 uint32)))))
    (dotimes (i n)
      (split-ints-bind (x y h) (read-line)
        (setf (aref hxy-table i) (list h x y))))
    (setf hxy-table (sort hxy-table #'> :key #'car))
    (when (zerop (car (aref hxy-table 0)))
      (error "Huh?"))
    (dotimes (cx 101)
      (dotimes (cy 101)
        (loop with cand-height = most-positive-fixnum
              for i below n
              for (h x y) of-type (uint32 uint32 uint32) = (aref hxy-table i)
              do (if (zerop h)
                     (unless (<= cand-height (+ (abs (- x cx)) (abs (- y cy))))
                       (return))
                     (let ((must-height (+ h (abs (- x cx)) (abs (- y cy)))))
                       (when (< must-height 1)
                         (return))
                       (if (= cand-height most-positive-fixnum)
                           (setf cand-height must-height)
                           (unless (= cand-height must-height)
                             (return)))))
              finally (format t "~A ~A ~A~%" cx cy cand-height)
                      (return-from main))))))

#-swank(main)


(defvar *N* (read))
(defvar *MAX* (expt 10 9))

(defun calc (x-lst y-lst h-lst)
  (let ((tmp-h -1)
        (done nil))
    (dotimes (c-x 101)
      (dotimes (c-y 101)
        (dotimes (n *N*)
          (let* ((x (nth n x-lst))
                 (y (nth n y-lst))
                 (h (+ (nth n h-lst) (abs (- c-x x)) (abs (- c-y y)))))
            (when (/= h 0)
              (setq tmp-h h)
              (return-from nil))))
        (setq done t)
        (dotimes (n *N*)
          (let ((r (max (- tmp-h (abs (- c-x (nth n x-lst))) (abs (- c-y (nth n y-lst)))) 0)))
            (when (/= (nth n h-lst ) r)
              (setq done nil))))
        (when done
          (format t "~a ~a ~a" c-x c-y tmp-h)
          (return-from calc nil))))))

(defun main ()
  (let ((x-lst (list nil))
        (y-lst (list nil))
        (h-lst (list nil)))
    (loop repeat *N*
          do (progn
               (push (read) x-lst)
               (push (read) y-lst)
               (push (read) h-lst)))
    (setq x-lst (cdr (reverse x-lst)))
    (setq y-lst (cdr (reverse y-lst)))
    (setq h-lst (cdr (reverse h-lst)))
    (let ((count 0)
          (size (length h-lst)))
      (dolist (x h-lst)
        (when (= x 0)
          (incf count)))
      (if (= count size)
          (format t "0 0 1~%")
          (calc x-lst y-lst h-lst)))))

(main)


(defvar *N* (read))
(defvar *MAX* (expt 10 9))

(defun calc (x-lst y-lst h-lst)
  (let ((tmp-h -1)
        (done nil))
    (dotimes (c-x 101)
      (dotimes (c-y 101)
        (dotimes (n *N*)
          (let* ((x (nth n x-lst))
                 (y (nth n y-lst))
                 (h (+ (nth n h-lst) (abs (- c-x x)) (abs (- c-y y)))))
            (when (/= h 0)
              (setq tmp-h h)
              (return-from nil))))
        (setq done t)
        (dotimes (n *N*)
          (let ((r (max (- tmp-h (abs (- c-x (nth n x-lst))) (abs (- c-y (nth n y-lst)))) 0)))
            (when (/= (nth n h-lst ) r)
              (setq done nil))))
        (when done
          (format t "~a ~a ~a" c-x c-y tmp-h)
          (return-from calc nil))))))

(defun main ()
  (let ((x-lst (list nil))
        (y-lst (list nil))
        (h-lst (list nil)))
    (loop repeat *N*
          do (progn
               (push (read) x-lst)
               (push (read) y-lst)
               (push (read) h-lst)))
    (setq x-lst (cdr (reverse x-lst)))
    (setq y-lst (cdr (reverse y-lst)))
    (setq h-lst (cdr (reverse h-lst)))
    (calc x-lst y-lst h-lst)))

(main)


(defvar *N* (read))

(defun calc-center (lst n)
  (let ((tmp (floor (/ (apply #'+ lst) n))))
    tmp))

(defun calc-high (x-lst y-lst h-lst c-x c-y &optional (tmp-lst (list nil)))
  (if (null (car x-lst))
      (car (sort (cdr (reverse tmp-lst)) #'>))
      (let ((tmp (+ (car h-lst) (abs (- (car x-lst) c-x)) (abs (- (car y-lst) c-y))))
            (lst tmp-lst))
        (push (max tmp 0) lst)
        (calc-high (cdr x-lst) (cdr y-lst) (cdr h-lst) c-x c-y lst))))

(defun main ()
  (let ((x-lst (list nil))
        (y-lst (list nil))
        (h-lst (list nil)))
    (loop repeat *N*
          do (progn
               (push (read) x-lst)
               (push (read) y-lst)
               (push (read) h-lst)))
    (setq x-lst (cdr (reverse x-lst)))
    (setq y-lst (cdr (reverse y-lst)))
    (setq h-lst (cdr (reverse h-lst)))
    (let ((c-x (calc-center x-lst *N*))
          (c-y (calc-center y-lst *N*)))
      (when (oddp *N*)
        (when (/= c-x 0)
            (incf c-x))
        (when (/= c-y 0)
          (incf c-y)))
      (let ((h (calc-high x-lst y-lst h-lst c-x c-y)))
        (format t "~a ~a ~a~%" c-x c-y h)))))

(main)


(in-package :cl-user)
(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 (set-dispatch-macro-character #\# #\> #'cl-debug-print:debug-print-reader)

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

(defconstant +mod+ 1000000007)

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

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

;; BEGIN_INSERTED_CONTENTS
;; BEGIN_USE_PACKAGE
(in-package :cl-user)

;;;
;;; Body
;;;

(defun main ()
  (let* ((digits (loop repeat 3 collect (read)))
         (max (reduce #'max digits))
         (digits (delete max digits :count 1)))
    (println (+ (* 10 max) (reduce #'+ digits)))))

#-swank (main)

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

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    #+os-windows (run-program "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)
    #+os-unix (run-program "xsel" '("-b" "-o") :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* (or out (make-string-output-stream)))
         (res (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))))))
    (if out res (get-output-stream-string *standard-output*))))

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

#-swank
(eval-when (:compile-toplevel)
  (when (and (boundp 'sb-c::*compiler-warning-count*)
             (> sb-c::*compiler-warning-count* 0))
    (sb-ext:quit :unix-status 1)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (5am:is
   (equal "53
"
          (run "1 5 2
" nil)))
  (5am:is
   (equal "108
"
          (run "9 9 9
" nil)))
  (5am:is
   (equal "82
"
          (run "6 6 7
" nil))))

Score : 100 points

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

The game is played as follows:

There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.

The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)

Then, the amount of the allowance will be equal to the resulting value of the formula.

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

Constraints

All values in input are integers.

1 \leq A, B, C \leq 9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum possible amount of the allowance.

Sample Input 1

1 5 2

Sample Output 1

53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

Sample Input 2

9 9 9

Sample Output 2

108

Sample Input 3

6 6 7

Sample Output 3

82


(setf l (make-array 3))

(defun in (a b c)
  (when (< b c)
	(progn
	  (setf (aref a b) (read))
	  (in a (1+ b) c))))

(in l 0 3)

(let ((x (sort l #'>)))
  (princ (+ (* (aref x 0) 10) (aref x 1) (aref x 2))))


(defun f (x)
  (+ (* (car x) 10) (cadr x) (caddr x)))
(print
 (f
  (sort
   (copy-list (list (read) (read) (read)))
   #'>)))


(defun f (x)
  (+ (* (car x) 10) (cadr x) (caddr x)))
(print
 (sort
  (copy-list (list (read) (read) (read)))
  #'>))


(defun maximizeFomula (a b c) (+ (* (max a b c) 9) a b c))
(format t "~A~%" (maximizeFomula (read) (read) (read)))


(let* ((a (read)) (b (read)) (c (read)) (lst (sort (list a b c) #'>)))
  (princ (+ (* 10 (car lst)) (cadr lst) (caddr lst))))


(setf n (sort (list (read) (read) (read)) #'>))
(format t "~A" (+ (* (first n) 10) (second n) (third n)))


(setf n (sort (list (read) (read) (read)) #'>))
(format t "~A" (+ (* (first n) 10) (second n) (third)))


(defparameter *a* (read))
(defparameter *b* (read))
(defparameter *c* (read))

(defun f (a b c)
  (let ((lst (sort (list a b c) #'>)))
    (+ (* (first lst) 10) (second lst) (third lst))))

(princ (f *a* *b* *c*))


(princ(+(setq a(read))(setq b(read))(setq c(read))(*(max a b c)9)))


(princ(+(setq a(read))(setq b(read))(setq c(read))(max a b c)))


(defvar *a* (read))
(defvar *b* (read))
(defvar *c* (read))

(defun main ()
  (let ((lst (list *a* *b* *c*)))
    (setq lst (sort lst #'>))
    (let ((left (concatenate 'string (write-to-string (nth 0 lst)) (write-to-string (nth 1 lst)))))
      (princ (+ (parse-integer left) (nth 2 lst))))))

(main)


(in-package :cl-user)
(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 (set-dispatch-macro-character #\# #\> #'cl-debug-print:debug-print-reader)

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

(defconstant +mod+ 1000000007)

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

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

;; BEGIN_INSERTED_CONTENTS
(defpackage :cp/modify-macro
  (:use :cl)
  (:export #:minf #:maxf #:mulf #:divf #:iorf #:xorf #:andf))
(in-package :cp/modify-macro)

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

;; BEGIN_USE_PACKAGE
(eval-when (:compile-toplevel :load-toplevel :execute)
  (use-package :cp/modify-macro :cl-user))
(in-package :cl-user)

;;;
;;; Body
;;;

(defun main ()
  (let* ((n (read))
         (m (read))
         (max (read))
         (min (read)))
    (dotimes (_ n) (maxf max (read)))
    (dotimes (_ m) (minf min (read)))
    (write-line (if (< max min)
                    "No War"
                    "War"))))

#-swank (main)

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

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    #+os-windows (run-program "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)
    #+os-unix (run-program "xsel" '("-b" "-o") :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* (or out (make-string-output-stream)))
         (res (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))))))
    (if out res (get-output-stream-string *standard-output*))))

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

#-swank
(eval-when (:compile-toplevel)
  (when (and (boundp 'sb-c::*compiler-warning-count*)
             (> sb-c::*compiler-warning-count* 0))
    (sb-ext:quit :unix-status 1)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (5am:is
   (equal "No War
"
          (run "3 2 10 20
8 15 13
16 22
" nil)))
  (5am:is
   (equal "War
"
          (run "4 2 -48 -1
-20 -35 -91 -23
-22 66
" nil)))
  (5am:is
   (equal "War
"
          (run "5 3 6 8
-10 3 1 5 -100
100 6 14
" nil))))

Score : 200 points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

X < Z \leq Y

x_1, x_2, ..., x_N < Z

y_1, y_2, ..., y_M \geq Z

Determine if war will break out.

Constraints

All values in input are integers.

1 \leq N, M \leq 100

-100 \leq X < Y \leq 100

-100 \leq x_i, y_i \leq 100

x_1, x_2, ..., x_N \neq X

x_i are all different.

y_1, y_2, ..., y_M \neq Y

y_i are all different.

Input

Input is given from Standard Input in the following format:

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

If war will break out, print War; otherwise, print No War.

Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

X = 10 < 16 \leq 20 = Y

8, 15, 13 < 16

16, 22 \geq 16

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War


(let* ((N (read))
       (M (read))
       (X (read))
       (Y (read))
       (Xi (loop :repeat N :collect (read)))
       (Z (apply #'min
                 (loop :repeat M :collect (read)))))
  (if (and (< X Z)
           (<= Z Y)
           (not (dolist (w Xi)
                  (if (>= w Z) (return t)))))
      (princ "No War") (princ "War")))


(let* ((N (read))
       (M (read))
       (X (read))
       (Y (read))
       (Xi (loop :repeat N :collect (read)))
       (Z (apply #'min
                 (loop :repeat M :collect (read)))))
  (if (and (< X Z)
           (<= Z Y)
           (not (dolist (w Xi)
                  (if (> w Z) (return t)))))
      (princ "No War") (princ "War")))


(defun get-max (n)
  (cond
    ((< n 1) -10000000000)
    (t (let ((x (read)))
	 (max x (get-max (- n 1)))))))
(defun get-min (n)
  (cond
    ((< n 1) 10000000000)
    (t (let ((x (read)))
	 (min x (get-min (- n 1)))))))
(let*
    ((n (read))
     (m (read))
     (x (read))
     (y (read))
     (xmax (max (get-max n) x))
     (ymin (min (get-min m) y)))
  (if (>= xmax ymin)
      (princ "War")
      (princ "No War")))


(let* ((n (read))
       (m (read))
       (x (read))
       (y (read))
       (xn (first (sort (loop :for p :from 1 :upto n collect(read)) #'>)))
       (xm (first (sort (loop :for q :from 1 :upto m collect(read)) #'<))))
  (if (and (< x xm) (>= y xm) (< xn xm))
      (princ "No War")
      (princ "War")))


(defparameter *n* (read))
(defparameter *m* (read))
(defparameter *x* (read))
(defparameter *y* (read))
(defparameter *xs* (loop repeat *n*
                         collect (read)))
(defparameter *ys* (loop repeat *m*
                         collect (read)))

(defun andmap (pred lst)
  (every #'identity (mapcar pred lst)))

(defun f (x y xs ys)
  (let* ((sed-xs (sort xs #'<))
         (sed-ys (sort ys #'<))
         (max-x (car (last sed-xs)))
         (min-y (first sed-ys)))
    (if (and
          (< x y)
          (< x max-x min-y y))
        "No War"
        "War")))

(princ (f *x* *y* *xs* *ys*))


(defconstant *n* (read))
(defconstant *m* (read))
(defconstant *x* (read))
(defconstant *y* (read))

(defmacro set-lst (n)
  `(loop for i from 1 to ,n
        collect (read)))

(defconstant *x-n* (nth 0 (sort (set-lst *n*) #'>)))
(defconstant *y-m* (nth 0 (sort (set-lst *m*) #'<)))

(defun calc (x y z)
  (cond ((and (< x z) (>= y z) (< *x* z) (>= *y* z))
         t)
        ((> z *y*)
         nil)
        (t (calc x y (1+ z)))))

(if (calc *x-n* *y-m* (1+ *x*))
    (princ "No War")
    (princ "War"))


(defvar *n* (read))
(defvar *m* (read))
(defvar *x* (read))
(defvar *y* (read))

(defun set-lst (n)
  (loop for i from 1 to n
        collect (read)))

(defvar *x-n* (nth 0 (sort (set-lst *n*) #'>)))
(defvar *y-m* (nth 0 (sort (set-lst *m*) #'<)))

(defun calc (x y z)
  (cond ((and (< x z) (>= y z) (< *x* z) (>= *y* z))
         t)
        ((> z *y*)
         nil)
        (t (calc x y (1+ z)))))

(if (calc *x-n* *y-m* (1+ *x*))
    (princ "No War")
    (princ "War"))


(defvar *n* (read))
(defvar *m* (read))
(defvar *x* (read))
(defvar *y* (read))

(defun set-lst (n)
  (let ((lst (list nil)))
    (dotimes (x n)
      (let ((tmp (read)))
        (push tmp lst)))
    (cdr (reverse lst))))

(defvar *lst-x* (nth 0 (sort (set-lst *n*) #'>)))
(defvar *lst-y* (nth 0 (sort (set-lst *m*)) #'<))

(defun calc (x y z)
  (cond ((and (< x z) (>= y z) (< *x* z) (>= *y* z))
         t)
        ((> z *y*)
         nil)
        (t (calc x y (1+ z)))))

(if (calc (nth 0 *lst-x*) (nth 0 *lst-y*) (1+ *x*))
    (princ "No War")
    (princ "War"))


(defvar *n* (read))
(defvar *m* (read))
(defvar *x* (read))
(defvar *y* (read))

(defun set-lst (n)
  (let ((lst (list nil)))
    (dotimes (x n)
      (let ((tmp (read)))
        (push (read) lst)))
    (cdr (reverse lst))))

(defvar *xn* (nth 0 (sort (set-lst *n*) #'>)))
(defvar *ym* (nth 0 (sort (set-lst *m*) #'<)))

(defun calc (x y z)
  (cond ((and (< x z) (>= y z) (< *x* z) (>= *y* z))
         t)
        ((> z *y*)
         nil)
        (t (calc x y (1+ z)))))

(if (calc *xn* *ym* (1+ *x*))
    (princ "No War")
    (princ "War"))


(defvar *n* (read))
(defvar *m* (read))
(defvar *x* (read))
(defvar *y* (read))

(defun set-lst (n)
  (let ((lst (list nil)))
    (dotimes (x n)
        (push (read) lst))
    (cdr (reverse lst))))

(defvar *lst-x* (sort (set-lst *n*) #'>))
(defvar *lst-y* (sort (set-lst *m*) #'<))

(defun calc (x y z)
  (cond ((and (< x z) (>= y z) (< *x* z) (>= *y* z))
         t)
        ((> z *y*)
         nil)
        (t (calc x y (1+ z)))))

(defun main ()
  (if (calc (nth 0 *lst-x*) (nth 0 *lst-y*) (1+ *x*))
      (princ "No War")
      (princ "War")))

(main)


(defvar *n* (read))
(defvar *m* (read))
(defvar *x* (read))
(defvar *y* (read))

(defun set-lst (n)
  (let ((lst (list nil)))
    (dotimes (x n)
      (let ((tmp (read)))
        (push tmp lst)))
    (cdr (reverse lst))))

(defvar *lst-x* (set-lst *n*))
(setq *lst-x* (sort *lst-x* #'>))

(defvar *lst-y* (set-lst *m*))
(setq *lst-y* (sort *lst-y* #'<))

(defun calc (x y z)
  (cond ((and (< x z) (>= y z) (< *x* z) (>= *y* z))
         t)
        ((> z *y*)
         nil)
        (t (calc x y (1+ z)))))

(defun main ()
  (if (calc (nth 0 *lst-x*) (nth 0 *lst-y*) (1+ *x*))
      (princ "No War")
      (princ "War")))

(main)


(setq n(read))(setq m(read))(setq x(read))(setq y(read))
(princ(if(<(apply #'max(cons x(loop for i from 1 to n collect(read))))(apply #'min(cons y(loop for i from 1 to m collect(read)))))"No War""War"))


(defvar *n* (read))
(defvar *m* (read))
(defvar *x* (read))
(defvar *y* (read))

(defun set-lst (n)
  (let ((lst (list nil)))
    (dotimes (x n)
      (let ((tmp (read)))
        (push tmp lst)))
    (cdr (reverse lst))))

(defun calc (x y z)
  (cond ((> z y)
         nil)
        ((and (< x z) (>= y z))
         z)
        (t (calc x y (1+ z)))))

(defun main ()
  (let ((lst-x (sort (set-lst *n*) #'>))
        (lst-y (sort (set-lst *m*) #'>)))
      (let* ((x (nth 0 lst-x))
             (y (nth 0 lst-y))
             (z (calc x y (1+ *x*))))
        (if (null z)
            (format t "War~%")
            (format t "No War~%")))))

(main)


(defvar *n* (read))
(defvar *m* (read))
(defvar *x* (read))
(defvar *y* (read))

(defun set-lst (n)
  (let ((lst (list nil)))
    (dotimes (x n)
      (let ((tmp (read)))
        (push tmp lst)))
    (cdr (reverse lst))))

(defun calc (x y z)
  (cond ((> z y)
         nil)
        ((and (< x z) (>= y z))
         z)
        (t (calc x y (1+ z)))))

(defun main ()
  (let ((lst-x (set-lst *n*)))
    (let ((lst-y (set-lst *m*)))
      (setq lst-x (sort lst-x #'>))
      (setq lst-y (sort lst-y #'>))
      (let* ((x (nth 0 lst-x))
             (y (nth 0 lst-y))
             (z (calc x y (1+ *x*))))
        (if (null z)
            (princ "War")
            (princ "No War"))))))

(main)


(in-package :cl-user)
(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 (set-dispatch-macro-character #\# #\> #'cl-debug-print:debug-print-reader)

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

(defconstant +mod+ 1000000007)

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

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

;; BEGIN_INSERTED_CONTENTS
;; BEGIN_USE_PACKAGE
(in-package :cl-user)

;;;
;;; Body
;;;

(defun main ()
  (let* ((a (read))
         (b (read)))
    (write-line (if (and (oddp a) (oddp b))
                    "Yes"
                    "No"))))

#-swank (main)

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

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    #+os-windows (run-program "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)
    #+os-unix (run-program "xsel" '("-b" "-o") :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* (or out (make-string-output-stream)))
         (res (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))))))
    (if out res (get-output-stream-string *standard-output*))))

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

#-swank
(eval-when (:compile-toplevel)
  (when (and (boundp 'sb-c::*compiler-warning-count*)
             (> sb-c::*compiler-warning-count* 0))
    (sb-ext:quit :unix-status 1)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (5am:is
   (equal "Yes
"
          (run "3 1
" nil)))
  (5am:is
   (equal "No
"
          (run "1 2
" nil)))
  (5am:is
   (equal "No
"
          (run "2 2
" nil))))

Score : 100 points

Problem Statement

You are given integers A and B, each between 1 and 3 (inclusive).

Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.

Constraints

All values in input are integers.

1 \leq A, B \leq 3

Input

Input is given from Standard Input in the following format:

A B

Output

If there is an integer C between 1 and 3 that satisfies the condition, print Yes; otherwise, print No.

Sample Input 1

3 1

Sample Output 1

Yes

Let C = 3. Then, A \times B \times C = 3 \times 1 \times 3 = 9, which is an odd number.

Sample Input 2

1 2

Sample Output 2

No

Sample Input 3

2 2

Sample Output 3

No


(let ((a (read))
      (b (read)))
  (if (oddp (* a b))
      (princ "Yes")
      (princ "No")))


(princ (if (oddp (* (read) (read))) "Yes" "No"))


(if (equal (mod (* (read) (read)) 2) 1) (print 'Yes) (print 'No))


(if (equal (mod (* (read) (read)) 2) 1) 'Yes 'No)


(if (equal (mod (* (read) (read)) 2) 1 'Yes 'No)


(defvar a (read))
(defvar b (read))
(if (and (= (mod a 2) 1) (= (mod b 2) 1))
  (princ "Yes")
  (princ "No"))


(defvar a (read))
(defvar b (read))
(if (and (= (mod a 2) 0) (= (mod b 2) 0))
  (princ "Yes")
  (princ "No"))


(let ((a (read)) (b (read)))
  (if (and (oddp a) (oddp b))
    (princ "Yes")
    (princ "No")))


(defparameter A (read))
(defparameter B (read))

(if (oddp (* A B))
  (princ "Yes")
  (princ "No"))
(fresh-line)


(defun even (n) (if (= 0 (mod n 2)) t nil))
(defun f (a b) (and (even a) (even b)))

(if (f (read) (read)) (print "No") (print "Yes"))


(defun main ()
  (defparameter s_list (loop :for a :from 1 :upto (read) collect(read-line)))
  (if (equal s_list (remove-duplicates s_list :test #'equal))
      (if (loop :for k :from 1 :upto (1- (length s_list)) always(equal (car (last (concatenate 'list (nth (1- k) s_list)))) (char (nth k s_list) 0)))
          "Yes"
          "No")
      "No")
  )
(format t "~A" (main))


(defun calc (a b &optional (c 1) (ans "No"))
  (let ((r (* c (* a b))))
    (cond ((> c 3)
           ans)
          ((oddp r)
           "Yes")
          (t (calc a b (incf c))))))

(defun main ()
  (let ((a (read)))
    (let ((b (read)))
      (format t "~a~%" (calc a b)))))

(main)


(defun calc (a b &optional (c 1) (ans "No"))
  (let ((r (* c (* a b))))
    (cond ((> c 3)
           ans)
          ((oddp r)
           "Yes")
          (t (calc a b (incf c))))))

(defun main ()
  (let ((a (read)))
    (let ((b (read)))
      (format t "~s~%" (calc a b)))))

(main)


(format t "~A" (if (= 3 (* (read) (read))) "Yes" "No"))


(in-package :cl-user)
(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 (set-dispatch-macro-character #\# #\> #'cl-debug-print:debug-print-reader)

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

(defconstant +mod+ 1000000007)

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

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

;; BEGIN_INSERTED_CONTENTS
;; BEGIN_USE_PACKAGE
(in-package :cl-user)

;;;
;;; Body
;;;

(defun main ()
  (let* ((n (read))
         (ws (loop repeat n collect (read-line))))
    (write-line (if (and (loop for (w1 w2) on ws
                               while w2
                               always (char= (aref w1 (- (length w1) 1))
                                             (aref w2 0)))
                         (= n (length (remove-duplicates ws :test #'string=))))
                    "Yes"
                    "No"))))

#-swank (main)

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

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    #+os-windows (run-program "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)
    #+os-unix (run-program "xsel" '("-b" "-o") :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* (or out (make-string-output-stream)))
         (res (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))))))
    (if out res (get-output-stream-string *standard-output*))))

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

#-swank
(eval-when (:compile-toplevel)
  (when (and (boundp 'sb-c::*compiler-warning-count*)
             (> sb-c::*compiler-warning-count* 0))
    (sb-ext:quit :unix-status 1)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (5am:is
   (equal "No
"
          (run "4
hoge
english
hoge
enigma
" nil)))
  (5am:is
   (equal "Yes
"
          (run "9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly
" nil)))
  (5am:is
   (equal "No
"
          (run "8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa
" nil)))
  (5am:is
   (equal "No
"
          (run "3
abc
arc
agc
" nil))))

Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No


(setq n(read))
(setq s(loop for i from 1 to n collect(read-line)))
(setq f 0)
(loop for i from 1 to(1- n)do
	  (if(char/=(char(nth(1- i)s)(1-(length(nth(1- i)s))))(char(nth i s)0))(incf f)))
(princ(if(or(> f 0)(<(length(remove-duplicates s :test #'equal))n))"No""Yes"))


(defvar *n* (read))

(defun check-first-and-last (lst)
  (let ((count 0)
        (previous nil)
        (check t))
    (dolist (s lst)
      (let* ((tmp (concatenate 'list s))
             (size (length tmp)))
        (if (= count 0)
            (progn (setq previous (nth (- size 1) tmp))
                   (incf count))
            (if (not (eql previous (car tmp)))
                (setq check nil)
                (setq previous (nth (- size 1) tmp))))))
    check))

(defun word-count (lst)
  (let ((tmp (sort lst 'string<))
        (previous nil)
        (check t))
    (dolist (s tmp)
      (if (null previous)
          (setq previous s)
          (if (string= previous s)
              (setq check nil)
              (setq previous s))))
    check))

(defun main ()
  (let ((lst (list nil)))
    (dotimes (x *n*)
      (push (read-line) lst))
    (setq lst (cdr (reverse lst)))
    (if (null (check-first-and-last lst))
        (format t "No~%")
        (if (null (word-count lst))
            (format t "No~%")
            (format t "Yes~%")))))

(main)


(defvar *n* (read))

(defun check-first-and-last (lst)
  (let ((count 0)
        (previous nil)
        (check t))
    (dolist (s lst)
      (if (= count 0)
          (let* ((tmp (concatenate 'list s))
                 (size (length tmp)))
            (setq previous (nth (- size 1) tmp))
            (incf count))
          (let* ((tmp (concatenate 'list s))
                 (size (length tmp)))
            (if (eql previous (car tmp))
                (setq check nil)
                (setq previous (nth (- size 1) tmp))))))
    check))

(defun word-count (lst)
  (let ((tmp (sort lst 'string<))
        (previous nil)
        (check t))
    (dolist (s tmp)
      (if (null previous)
          (setq previous s)
          (if (string= previous s)
              (setq check nil)
              (setq previous s))))
    check))

(defun main ()
  (let ((lst (list nil)))
    (dotimes (x *n*)
      (push (read-line) lst))
    (setq lst (cdr (reverse lst)))
    (if (null (check-first-and-last lst))
        (format t "No~%")
        (if (null (word-count lst))
            (format t "No~%")
            (format t "Yes~%")))))

(main)


(defvar *n* (read))

(defun check-first-and-last (lst)
  (let ((count 0)
        (previous nil))
    (dolist (s lst)
      (if (= count 0)
          (let* ((tmp (concatenate 'list s))
                 (size (length tmp)))
            (setq previous (nth (- size 1) tmp))
            (incf count))
          (let* ((tmp (concatenate 'list s))
                 (size (length tmp)))
            (if (eql previous (car tmp))
                (return-from nil)
                (setq previous (nth (- size 1) tmp)))))))
  t)

(defun word-count (lst)
  (let ((tmp (sort lst 'string<))
        (previous nil)
        (check t))
    (dolist (s tmp)
      (if (null previous)
          (setq previous s)
          (if (string= previous s)
              (setq check nil)
              (setq previous s))))
    check))

(defun main ()
  (let ((lst (list nil)))
    (dotimes (x *n*)
      (push (read-line) lst))
    (setq lst (cdr (reverse lst)))
    (if (null (check-first-and-last lst))
        (format t "No~%")
        (if (null (word-count lst))
            (format t "No~%")
            (format t "Yes~%")))))

(main)


(let ((n (read))
      (a (make-array 0 :element-type 'string
                       :fill-pointer 0
                       :adjustable t))
      temp
      lst
      (flg t))
  (setf temp (read-line))
  (loop repeat (1- n) do
        (vector-push-extend temp a)
        (setf lst (char temp (1- (length temp))))
        (setf temp (read-line))
        (if (not (equal lst (char temp 0))) (setf flg nil))
        (loop for i across a do
              (if (equal i temp) (setf flg nil))))
  (princ (if flg "Yes" "No")))


(defun main ()
  (defparameter s_list (loop :for a :from 1 :upto (read) collect(read-line)))
  (if (equal s_list (remove-duplicates s_list))
      (if (loop :for k :from 1 :upto (1- (length s_list)) always(equal (car (last (concatenate 'list (nth (1- k) s_list)))) (char (nth k s_list) 0)))
          "Yes"
          "No")
      "No")
  )
(format t "~A" (main))


(defun abc109c ()
  (let* ((n (read))
	 (x (read))
	 (xs (loop for i below n collect (read))))
    (format t "~a~%"
	    (reduce #'gcd (mapcar (lambda (a) (abs (- a x))) xs)
		    :initial-value 0))))

(abc109c)

Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999


(let* ((n (read))
       (m (read))
       (lst (loop :repeat n :collect (read))))
  (push m lst)
  (setf lst (sort lst #'<))
  (princ (apply #'gcd (mapcar #'- (cdr lst) lst))))


(princ(apply'gcd(loop repeat(read)with x =(read)collect(-(read)x))))


(princ(reduce'gcd(loop repeat(read)with x =(read)collect(-(read)x))))


(princ(reduce'gcd(loop repeat(read)with x =(read)collect(abs(-(read)x)))))


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

;; BEGIN_INSERTED_CONTENTS
(declaim (inline split-ints-into-vector))
(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))
  (declare (string string)
           (function key)
           ((array * (*)) dest-vector)
           ((integer 0 #.most-positive-fixnum) offset))
  (loop with position = 0
        for idx from offset below (length dest-vector)
        do (setf (values (aref dest-vector idx) position)
                 (parse-integer string :start position :junk-allowed t))
           (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))
        finally (return dest-vector)))

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

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((n (read))
         (x (read))
         (xs (make-array n :element-type 'uint32)))
    (split-ints-into-vector (read-line) xs)
    (dotimes (i n)
      (setf (aref xs i) (abs (- (aref xs i) x))))
    (println (reduce #'gcd xs))))

#-swank(main)


(let((s 0)(n(read))(a(read)))(princ(dotimes(i n s)(setq s(gcd(-(read)a)s)))))


(let ((n (read))
      (x (read))
      (ans (read)))
  (setf ans (abs (- ans x)))
  (loop repeat (1- n) do
        (setf ans (gcd ans (abs (- x (read))))))
  (princ ans))