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

#GL0000381. Một nửa có cùng số dư (Half of Same)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Một nửa có cùng số dư (Half of Same)

Half of Same

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn integers, where nn is even and values may be negative. Choose a positive integer kk. You may repeatedly select an index ii and subtract kk from aia_i.

Find the largest kk for which at least n/2n/2 array elements can be made equal. Output -1 if arbitrarily large values of kk work. Zero operations are allowed. Elements with the same remainder modulo kk can all be decreased to a common sufficiently small value.

PHOJ input convention: Each .in file contains one test case, with no leading tt. This is a single-case version of Codeforces 1593D2.

Input

The first line contains even nn, and the second line contains the nn integers.

Output

Output the maximum positive kk, or -1 if it is unbounded.

Subtasks

  • Subtask 1 (20 points): even 4≤n≤104\le n\le10, −50≤ai≤50-50\le a_i\le50.

  • Subtask 2 (30 points): even 4≤n≤244\le n\le24, −104≤ai≤104-10^4\le a_i\le10^4.

  • Subtask 3 (50 points): even 4≤n≤404\le n\le40, −106≤ai≤106-10^6\le a_i\le10^6.

Examples

Example 1

Input

6
48 13 22 -15 16 35

Output

13

Explanation

The three values 48,22,3548,22,35 are all congruent to 99 modulo 1313, and can be reduced to 99. This supplies the required n/2=3n/2=3 equal elements. No greater candidate divisor of a pairwise difference works.

Example 2

Input

4
100 -1000 -1000 -1000

Output

-1

Explanation

Three entries are already equal to −1000-1000; no operation is necessary, so kk is unbounded.