PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000239. Số sinh chung (Common Generator)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số sinh chung (Common Generator)

Common Generator

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

For integers x,y≥2x,y\ge2, xx is called a generator of yy if it can be turned into yy by zero or more operations:

  • Choose a divisor d≥2d\ge2 of the current value zz.
  • Replace zz by z+dz+d.

For example, 33 generates 88 via 3→63\to6 (choose d=3d=3) and 6→86\to8 (choose d=2d=2).

Given nn pairwise distinct integers a1,…,ana_1,\ldots,a_n, each at least 22, find an integer x≥2x\ge2 that generates every aia_i, or print -1 if none exists. Any valid generator is accepted.

Input

  • The first line contains integer nn.
  • The second line contains nn pairwise distinct integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print any integer x≥2x\ge2 generating every array element, or -1 if no such integer exists.

Subtasks

  • Subtask 1 (20 points): 1≤n≤51\le n\le5; 2≤ai≤402\le a_i\le40 for every ii; the elements are pairwise distinct.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le1000; 2≤ai≤50002\le a_i\le5000 for every ii; the elements are pairwise distinct.

  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 2≤ai≤4⋅1052\le a_i\le4\cdot10^5 for every ii; the elements are pairwise distinct.

Examples

Input

3
8 9 10

Output

2

Explanation

For the array [8,9,10][8,9,10], choose x=2x=2. The sequences are 2→4→82\to4\to8 (add 22, then 44), 2→4→6→92\to4\to6\to9 (add 22, 22, then 33), and 2→4→6→8→102\to4\to6\to8\to10 (add 22 at every step). Each increment is a divisor of the current integer and is at least 22. Hence 22 is a common generator.