;; -*- coding: utf-8 -*-
(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)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defun map-run-length-rotative (function seq &key (test #'eql))
  (declare (sequence seq)
           (function test function))
  (etypecase seq
    (vector
     (unless (zerop (length seq))
       (let ((prev (aref seq 0))
             (start 0)
             (init-elm (aref seq 0))
             (init-length 0))
         (declare ((integer 0 #.most-positive-fixnum) start init-length))
         (loop for pos from 1 below (length seq)
               unless (funcall test prev (aref seq pos))
               do (if (zerop init-length)
                      (setf init-length (- pos start))
                      (funcall function prev (- pos start)))
                  (setf prev (aref seq pos)
                        start pos)
               finally (if (funcall test init-elm (aref seq (- pos 1)))
                           (funcall function init-elm (+ init-length (- pos start)))
                           (progn
                             (funcall function prev (- pos start))
                             (funcall function init-elm init-length)))))))
    (list
     (error "Not implemented."))))

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

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

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

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(defun calc (table)
  ;; (format t "~A~%" table)
  (let ((res #xffff))
    (declare (uint32 res))
    (map-run-length-rotative
     (lambda (x num)
       (declare (uint32 x num))
       (if (zerop x)
           (setq res (min res (+ num 1)))
           (when (> num 1)
             (setq res 1))))
     table)
    res))

(defun main ()
  (let* ((n (read))
         (counts (make-array 13 :element-type 'uint8 :initial-element 0))
         (res 0))
    (declare (uint8 res))
    (dotimes (i n) (incf (aref counts (read))))
    (incf (aref counts 0)) ; Takahashi-kun
    (when (>= (aref counts 0) 2)
      (println 0)
      (return-from main))
    (when (>= (aref counts 12) 2)
      (println 0)
      (return-from main))
    (loop for d from 1 to 11
          when (> (aref counts d) 2)
          do (println 0)
             (return-from main))
    (dotimes (bits (ash 1 11))
      (let ((table (make-array 24 :element-type 'bit :initial-element 0)))
        (declare (dynamic-extent table))
        (when (= (aref counts 0) 1)
          (setf (aref table 0) 1))
        (when (= (aref counts 12) 1)
          (setf (aref table 12) 1))
        (loop for d from 1 to 11
              when (= (aref counts d) 2)
              do (setf (aref table d) 1
                       (aref table (- 24 d)) 1))
        (loop for d from 1 to 11
              when (= (aref counts d) 1)
              do (if (logbitp (- d 1) bits)
                     (setf (aref table d) 1)
                     (setf (aref table (- 24 d)) 1)))
        (setf res (max res (calc table)))))
    (println res)))

#-swank (main)


Measured memory_bytes: 24292