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

#GL0000120. Tô màu xen kẽ (Paint the Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tô màu xen kẽ (Paint the Array)

Paint the Array

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn positive integers a1,…,ana_1,\ldots,a_n, choose a positive integer dd. Color every array element divisible by dd red and all other elements blue. The coloring is beautiful if every adjacent pair has different colors. Print any 1≤d≤10181\le d\le10^{18} producing a beautiful coloring, or 0 if impossible.

Input

The first line contains nn; the second contains nn integers aia_i.

Output

Print any valid dd, or 0 if none exists.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le 12; 1≤ai≤1 0001\le a_i\le 1\,000.
  • Subtask 2 (30 points): 2≤n≤502\le n\le 50; 1≤ai≤1 000 000 0001\le a_i\le 1\,000\,000\,000.
  • Subtask 3 (50 points): 2≤n≤1002\le n\le 100; 1≤ai≤1 000 000 000 000 000 0001\le a_i\le 1\,000\,000\,000\,000\,000\,000.

Examples

Input

5
1 2 3 4 5

Output

2

Explanation

For d=2d=2, positions 2 and 4 are red while the others are blue, so adjacent positions always have different colors.