#GL0000137. Tất cả đều bằng nhau (All are Same)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tất cả đều bằng nhau (All are Same)
All are Same
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Polycarp has an array of integers. He chooses a positive integer and may repeatedly pick an index and decrease by exactly . Each index can be picked any number of times, including zero.
Find the maximum for which all elements can become equal. Print -1 if valid values of are unbounded. Initial and final elements may be negative.
Input
The first line contains an even integer . The second line contains integers .
Output
Print the largest possible , or -1 if arbitrarily large values are possible.
Subtasks
- Subtask 1 (20 points): and even; .
- Subtask 2 (30 points): and even; .
- Subtask 3 (50 points): and even; .
Examples
Input
6
1 5 3 1 1 5
Output
2
Explanation
The differences from the first element are , whose greatest common divisor is . Choosing makes all numbers equal to by decreasing each twice and once. No larger divides both and .