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. Unfortunatelly, 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
thepankj: 2020-08-10 11:17:45

Why tf is it showing TLE?!!
In the ideone it's doing the computation in 0.02s

uttsav1998: 2020-07-11 21:11:09

@krritik the answer would be

6


explaination
since there are 6 students and the number of candies 30 with teacher

so each students get 5 candies
since 3 student have less than 5 candies so 2 candies each of the 3 students so 6 candies to be distributed

memran: 2020-07-02 08:01:42

AC in 10th go,
I am a pro :)

rise09062000: 2020-06-19 18:50:35

ac in one go!

prafulla_1503: 2020-05-31 13:14:44

i am a newbiee...still AC in one go

badcoder_100: 2020-05-23 22:24:39

What the hell is wrong with the showoff at this site?? Do u think even an hour after a person reads your "AC in one go :) " he is gonna remember your name?? So give space for hints and tips for beginners rather than the show off.
Y'all one goers probably need validation for "success" and are nothing but a bunch of show offs.

Last edit: 2020-05-23 22:25:08
user_666: 2020-05-03 09:03:49

In my code, if i put check that if(N>10000) exit(0); then i get a WA...but if I remove this check condition and submit my solution, then I get AC...WHY?? anyone plz tell me what could be the error in this line??

vishal_0303: 2020-04-15 04:17:51

@ap_mit2704
probably use of endl after every cout will ac it.

Last edit: 2020-04-15 04:19:09
vk9299497: 2020-04-06 13:48:13

how input and output are taken

fluffy_minded: 2020-01-16 18:03:13

no one cares about your AC in one go!


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