#ABC272G. [ABC272G] Yet Another mod M

[ABC272G] Yet Another mod M

Score : 600600 points

Problem Statement

You are given a sequence A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N) of length NN consisting of positive integers, where the elements of AA are distinct.

You will choose a positive integer MM between 33 and 10910^9 (inclusive) to perform the following operation once:

  • For each integer ii such that 1iN1 \le i \le N, replace AiA_i with AimodMA_i \bmod M.

Can you choose an MM so that AA satisfies the following condition after the operation? If you can, find such an MM.

  • There exists an integer xx such that xx is the majority in AA.

Here, an integer xx is said to be the majority in AA if the number of integers ii such that Ai=xA_i = x is greater than the number of integers ii such that AixA_i \neq x.

Constraints

  • 3N50003 \le N \le 5000
  • 1Ai1091 \le A_i \le 10^9
  • The elements of AA are distinct.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

Output

If there exists an MM that satisfies the condition, print such an MM. Otherwise, print 1-1.

5
3 17 8 14 10
7

If you let M=7M=7 to perform the operation, you will have A=(3,3,1,0,3)A=(3,3,1,0,3), where 33 is the majority in AA, so M=7M=7 satisfies the condition.

10
822848257 553915718 220834133 692082894 567771297 176423255 25919724 849988238 85134228 235637759
37
10
1 2 3 4 5 6 7 8 9 10
-1