405685: GYM102035 I Abu Tahun Mod problem

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Abu Tahun Mod problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Abu Tahun loves palindromes.

An array is palindrome if it reads the same backwards and forwards, for example arrays $$$\{1\}$$$, $$$\{1,1,1\}$$$, $$$\{1,2,1\}$$$ , $$$\{1,3,2,3,1\}$$$ are palindrome, but arrays $$$\{11,3,5,11\}$$$, $$$\{1,12\}$$$ are not.

Abu Tahun has an array of $$$n$$$ integers $$$A$$$. He wants his array to be palindrome. He can choose an integer $$$m$$$, then change the value of all $$$A_i$$$ $$$(1 \leq i \leq n)$$$ to ($$$A_i\mod m$$$).

what is the maximum value of $$$m$$$ he can choose, such that the array becomes palindrome?

Input

The first line of input contains a single integer $$$n$$$ $$$( 1 \leq n \leq 10^{5})$$$

The second line contains integers $$$A_1$$$,$$$A_2$$$,...,$$$A_n$$$ $$$(1 \leq A_i \leq 10^{9})$$$

Output

Print the maximum value of $$$m$$$ Abu Tahun can choose, if $$$m$$$ is arbitrarily large print -1.

ExamplesInput
4
1 1 1 1
Output
-1
Input
4
1 2 3 4
Output
1
Input
3
8 12 16
Output
8

Source/Category

加入题单

上一题 下一题 算法标签: