Daisies and Love

Interview

Time limit1sMemory limit1024 MB

Summary
Find the largest M so that every petal count L_i is congruent to some common value modulo M, where all L_i are multiples of M.
Level

Medium4 of 10

Topics
Math, Number theory, Implementation
Solved
No attempts yet

Problem

An M-state affection list (with M>1M > 1) is a sequence defined as follows: the first entry is the state “loves”, and the remaining M−1M-1 entries are some other (distinct) affection states.

A girl reads a boy's feelings toward her by plucking, one at a time, the petals of a daisy he gives her, using the following rules:

  1. Before the first petal is plucked, we are in the state “loves”.
  2. Each time a petal is plucked, the affection state advances to the next state in the list.
  3. The state that follows the last state in the list is again “loves” (the list wraps around).
  4. When the flower has no petals left, we finish with this daisy and return the current state as its result.

For example, consider the 33-state list “loves”-“likes”-“indifferent”. With this list, a daisy of 55 petals gives the result “indifferent”, while a daisy of 77 petals gives “likes”.

The girl believes the boy loves her only if he gives her daisies and every one of them points to the state “loves”. The boy wants to convince her, so he gives her NN daisies and wants to design the longest possible affection list.

For the given daisies, find the largest value of MM for which the girl concludes that the boy loves her.

Input

The first line contains the number of daisies NN (1≤N≤10001 \le N \le 1000). The second line contains NN integers LiL_i (1≤Li≤1001 \le L_i \le 100) separated by spaces, where LiL_i is the number of petals on the ii-th daisy.

Output

Print a single integer: the largest possible value of MM. If the petal counts of the daisies share no common divisor greater than 11, print 11.

Examples5

  1. Example 1

    Input
    4
    3 21 12 6
    
    Expected output
    3
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    100
    
    Expected output
    100
    
  4. Example 4

    Input
    2
    2 3
    
    Expected output
    1
    
  5. Example 5

    Input
    3
    12 18 24
    
    Expected output
    6