Problem:
Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.

Solution in Common Lisp (SBCL 1.1.14) (judge verdict: Wrong Answer)

;; -*- coding: utf-8 -*-
(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))))))

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

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

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

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

(defconstant +mod+ 1000000007)

;; Body

(declaim (ftype (function * (values (array (integer 0 #.most-positive-fixnum) (*))))
                enum-divisors))
(defun enum-divisors (x)
  "Enumerates divisors of X in ascending order"
  (declare #.OPT (fixnum x))
  (setf x (abs x))
  (let* ((sqrt (isqrt x))
         (res (make-array sqrt
                          :element-type '(integer 0 #.most-positive-fixnum)
                          :fill-pointer 0)))
    (loop for i from 1 to sqrt
          do (multiple-value-bind (quot rem) (floor x i)
               (when (zerop rem)
                 (vector-push-extend i res)
                 (unless (= i quot)
                   (vector-push-extend quot res)))))
    res))

(declaim (inline unique-merge))
(defun unique-merge (element-type vec1 vec2 predicate)
  (declare (function predicate))
  (let ((res (make-array 0
                         :element-type element-type
                         :fill-pointer 0)))
    (let ((i1 1)
          (i2 0)
          (pos -1))
      (declare ((integer -1 #.most-positive-fixnum) i1 i2 pos))
      (loop (if (= i1 (length vec1))
                (loop (when (= i2 (length vec2))
                        (return-from unique-merge res))
                      (when (or (= -1 pos)
                                (funcall predicate (aref res pos) (aref vec2 i2)))
                        (vector-push-extend (aref vec2 i2) res)
                        (incf pos))
                      (incf i2))
                (when (= i2 (length vec2))
                  (loop (when (= i1 (length vec1))
                          (return-from unique-merge res))
                        (when (or (= -1 pos)
                                  (funcall predicate (aref res pos) (aref vec1 i1)))
                          (vector-push-extend (aref vec1 i1) res)
                          (incf pos))
                        (incf i1))))
            (if (funcall predicate (aref vec1 i1) (aref vec2 i2))
                (progn
                  (when (or (= -1 pos)
                            (funcall predicate (aref res pos) (aref vec1 i1)))
                    (vector-push-extend (aref vec1 i1) res)
                    (incf pos))
                  (incf i1))
                (progn
                  (when (or (= -1 pos)
                            (funcall predicate (aref res pos) (aref vec2 i2)))
                    (vector-push-extend (aref vec2 i2) res)
                    (incf pos))
                  (incf i2)))))))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (as (make-array (- n 2) :element-type 'uint32))
         (a1 (read-fixnum))
         (a2 (read-fixnum)))
    (declare (uint32 n))
    (dotimes (i (- n 2))
      (setf (aref as i) (read-fixnum)))
    (let* ((div1 (sort (enum-divisors a1) #'>))
           (div2 (sort (enum-divisors a2) #'>))
           (div (unique-merge 'uint32 div1 div2
                              (lambda (x y)
                                (declare (uint32 x y))
                                (> x y)))))
      (declare ((array uint32 (*)) div))
      (loop for d across div
            when (every (lambda (a) (zerop (mod (the uint32 a) d))) as)
            do (println d)
               (return-from main)
            finally (error "Huh?")))))

#-swank(main)