#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e5 + 5;
int arr[N];
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%d", &arr[i]);
sort(arr, arr+n);
int warehouse = arr[n/2];
int res = 0;
for (int i = 0; i < n; ++i)
res += abs(warehouse - arr[i]);
printf("%d", res);
return 0;
}