题目描述
On the eve of Republic Day, Teacher decided to distribute candies among N students.She brought the candies in a box and
placed it in front of students. She allowed every student to take out some candies. But each one of them tried
to take out as much candies as possible. That's why, Not all students were happy. She called all students and
requested for their bags of candies. Now she wants to distribute candies equally among all bags. She'll be performing
two operations.
Pick up a candy from a bag.
Put a candy into another bag.
Both operations require 1 unit of time. You are given with bags of N students with number of candies
in it. You have to check whether candies can be distributed equally among all bags or not. If it can be distributed then
calculate the time required for total distribution.
Input
First Line contains number of test cases T.
Every test case consist of two lines, First line contains N i.e. Number of Bags and next line contains N
space separated integers A1, A2, ..., AN , where i^th integer
indicates number of candies in i^th bag.
Output
If candies can be distributed equally then output the time required for distribution in new line,
else, output "-1" (without quotes) in new line.
Constraints
1 ≤ T ≤ 10
1 ≤ N ≤ 100
0 ≤ Number of Candies in each bag ≤ 1000
Example
Input:
3
3
1 2 3
3
1 2 1
4
9 7 8 0
Output:
2
-1
12
Explanation
Example case 1.Teacher picks up a candy from a bag with maximum candies i.e. 3^rd bag and put it in the bag with minimum candies i.e. 1^st bag. Now all bags have two candies each. Total time required for distribution is 2.
输入格式
见题面
输出格式
见题面