#GL0000381. Một nửa có cùng số dư (Half of Same)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 integers, where is even and values may be negative. Choose a positive integer . You may repeatedly select an index and subtract from .
Find the largest for which at least array elements can be made equal. Output -1 if arbitrarily large values of work. Zero operations are allowed. Elements with the same remainder modulo can all be decreased to a common sufficiently small value.
PHOJ input convention: Each .in file contains one test case, with no leading . This is a single-case version of Codeforces 1593D2.
Input
The first line contains even , and the second line contains the integers.
Output
Output the maximum positive , or -1 if it is unbounded.
Subtasks
-
Subtask 1 (20 points): even , .
-
Subtask 2 (30 points): even , .
-
Subtask 3 (50 points): even , .
Examples
Example 1
Input
6
48 13 22 -15 16 35
Output
13
Explanation
The three values are all congruent to modulo , and can be reduced to . This supplies the required 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 ; no operation is necessary, so is unbounded.