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

#GL0000242. Tìm mô-đun tạo phần dư chiếm đa số (Yet Another mod M)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tìm mô-đun tạo phần dư chiếm đa số (Yet Another mod M)

Tìm mô-đun tạo phần dư chiếm đa số (Yet Another mod M)

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn pairwise distinct positive integers, find any modulus MM with 3≤M≤1093\le M\le10^9 such that strictly more than half of the elements share the same residue modulo MM. Output any valid MM, or -1 if none exists.

Input

  • First line: integer nn.
  • Second line: nn array elements. All elements must be distinct.

Output

Print any valid modulus MM, or -1 if no solution exists.

Subtasks

  • Subtask 1 (20 points): 3≤n≤20, 1≤ai≤1043\le n\le20,\ 1\le a_i\le10^4.
  • Subtask 2 (30 points): 3≤n≤1000, 1≤ai≤1073\le n\le1000,\ 1\le a_i\le10^7.
  • Subtask 3 (50 points): 3≤n≤5000, 1≤ai≤1093\le n\le5000,\ 1\le a_i\le10^9.

Examples

Example 1

Input

5
3 17 8 14 10

Output

7

Explanation

Modulo 7 yields residues (3,3,1,0,3)(3,3,1,0,3); residue 3 appears three times out of five.

Example 2

Input

10
1 2 3 4 5 6 7 8 9 10

Output

-1

Explanation

No residue can appear more than five times under any modulus at least 3.