#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 21 13:02:50 2017

@author: root
"""
stop = False
while stop == False:
    x = int(raw_input())
    if x == 0:
        stop = True
    else:
        duit = 0.00
        si = []
        for z in range(x):
            si.append(float(raw_input()))
            duit+=si[z]
        avg = duit/x
        n = 0.00
        p = 0.00
        for i in si:
            if(i > avg):
                p+= i - avg
            else:
                n+= avg - i
                
        if(n < p):
            print n
        else:
            print p
