import java.util.Arrays; import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner; public class Main { void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long[] Y = new long[N]; for (int i = 0; i < N; ++i) Y[i] = sc.nextLong(); Arrays.sort(Y); long ans = 0; for (int i = 0; i < N; ++i) ans += Math.abs(Y[i] - Y[N / 2]); System.out.println(ans); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } public static void main(String[] args) { new Main().run(); } }