import java.util.*; public class No609{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long[] Y = new long[N]; long sum = 0; for(int i = 0; i < N; i++){ Y[i] = sc.nextLong(); sum += Y[i]; } long mean; if(sum%N > 0){ mean = sum/N + 1; }else{ mean = sum/N; } long diff = 0; for(int i = 0; i < N; i++){ diff += Math.abs(mean - Y[i]); } System.out.println(diff); } }