273 传统题

[CF1538B] 朋友与糖果 (Friends and Candies)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
1/ 4
难度
2

[CF1538B] 朋友与糖果 (Friends and Candies)

Problem Statement

Polycarp has nn friends, the ii-th of whom has aia_i candies. Polycarp wants all friends to have the same number of candies by performing the following operation at most once:

  • Choose any kk (0≤k≤n0 \le k \le n) friends, collect all of their candies, and redistribute those candies among all nn friends in any non-negative integer amounts.

Find the minimum value of kk such that everyone can end up with the same number of candies, or -1 if it is impossible.

Input

The first line contains tt (1≤t≤1041 \le t \le 10^4). Each test case consists of nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) followed by nn integers a1,…,ana_1, \dots, a_n (0≤ai≤1040 \le a_i \le 10^4). The sum of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, print the minimum kk, 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:1≤t≤1041 \le t \le 10^4,1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,0≤ai≤1040 \le a_i \le 10^4,∑n≤2⋅105\sum n \le 2 \cdot 10^5。
  • Source:Codeforces 1538B · Friends and Candies