[CF1538B] 朋友与糖果 (Friends and Candies)
Problem Statement
Polycarp has friends, the -th of whom has candies. Polycarp wants all friends to have the same number of candies by performing the following operation at most once:
- Choose any () friends, collect all of their candies, and redistribute those candies among all friends in any non-negative integer amounts.
Find the minimum value of such that everyone can end up with the same number of candies, or -1 if it is impossible.
Input
The first line contains (). Each test case consists of () followed by integers (). The sum of across all test cases does not exceed .
Output
For each test case, print the minimum , or -1 if impossible.
Example
5
4
4 5 2 5
2
2 2
1
10
5
1 3 7 0 9
3
1 2 4
2
0
0
2
-1
Note
- Constraints:,,,。
- Source:Codeforces 1538B · Friends and Candies