CANDY - Candy I


Jennifer is a teacher in the first year of a primary school. She has gone for a trip with her class today. She has taken a packet of candies for each child. Unfortunately, the sizes of the packets are not the same.

Jennifer is afraid that each child will want to have the biggest packet of candies and this will lead to quarrels or even fights among children. She wants to avoid this. Therefore, she has decided to open all the packets, count the candies in each packet and move some candies from bigger packets to smaller ones so that each packet will contain the same number of candies. The question is how many candies she has to move.

Input specification

The input file consists of several blocks of data. Each block starts with the number of candy packets N (1<= N <=10000) followed by N integers (each less than 1000) in separate lines, giving the number of candies in each packet. After the last block of data there is the number -1.

Output specification

The output file should contain one line with the smallest number of moves for each block of data. One move consists of taking one candy from a packet and putting it into another one. If it is not possible to have the same number of candies in each packet, output the number -1.

Example

Input file:
5
1
1
1
1
6
2
3
4
-1

Output file:
4
-1

hide comments
gamer496: 2014-11-09 10:15:06

i hate silly mistakes

Dipti Roy: 2014-10-25 01:17:45

time limit exceeded. no idea why

Gopesh Tulsyan: 2014-10-21 17:01:14

easy peasy!!!

Gopesh Tulsyan: 2014-10-21 16:13:44

can we consider this that if sum of candies divided by n doesn't give a integer then the result is simplty -1

NIKHIL KUMAR SINGH: 2014-09-28 12:41:48

Accepted in one go ......Even got it compiled on PC in one command :)

shankar: 2014-09-19 14:23:40

It should be moved to tutorials so that people who are actually trying to improve their coding skills may not need to waste their time on this.

Last edit: 2014-09-19 14:24:49
Namra Alkeshbhai Saheba: 2014-09-11 16:17:04

AC in the first attempt and that too without debugging the code :)

Rajat (1307086): 2014-08-25 21:30:12

easy one......silly mistake caused me WA

noog: 2014-08-24 07:18:21

Somebody pls tell me what's wrong with this code...
<snip>

Last edit: 2022-10-07 23:11:11
arpit jain: 2014-08-20 19:29:59

easy ......AC in one go.....
just think logically


Added by:Fudan University Problem Setters
Date:2007-12-01
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO
Resource:IPSC 1999