Thursday, June 28, 2018

CANDY - Candy I : Classical

#The solution in Python 3 is as follows:


while True:
n = int(input())
if n == -1: break
A = [int(input()) for _ in range(n)]
s = sum(A)
if s%n:                    #check if the candies can be distributed equally
print(-1)       
else:
print(sum(abs(s//n-a) for a in A)//2)


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!