import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int M = sc.nextInt(); int[] v = new int[M]; int sum = 0; int r = 0; for(int i = 0; i < M; ++i){ v[i] = sc.nextInt(); sum += v[i]; } if(sum%M != 0){//不能除尽就不能平分 System.out.println(-1); System.exit(0); }else{ int av = sum/M; for(int i = 0; i < M; ++i){ int temp = Math.abs(av - v[i]); if(temp%2 == 0){//只有距离平均数偶数个才能补齐、削平 r += temp/2; }else{ System.out.println(-1); System.exit(0); } } } System.out.println(r/2);//一半人被补齐,一半人被削平(一次操作削一补一) } }