import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int[]Y = new int[N]; for(int i = 0; i < N; i++) { Y[i] = scan.nextInt(); } scan.close(); Arrays.sort(Y); if(N % 2 == 0) { int t = (Y[N / 2] + Y[N /2 - 1]) / 2; long ans = 0; for(int i = 0; i < N; i++) { ans += Math.abs(t - Y[i]); } System.out.println(ans); }else { long ans = 0; int t = Y[N / 2]; for(int i = 0; i < N; i++) { ans += Math.abs(t - Y[i]); } System.out.println(ans); } } }