#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,p,n) for(int i=(int)p;i<(int)n;i++) #define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--) #define Sort(x) sort(x.begin(),x.end()) #define PSort(x) sort(begin(x), end(x), pairCompare) #define ll long long #define INF 2000000000 #define pb push_back #define mp make_pair #define fi first #define se second #define PI 3.14159265358979 int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 }; using namespace std; int main(){ int n; cin >> n; vector v(n); rep(i, 0, n)cin >> v[i]; Sort(v); ll middle; middle = v[v.size() / 2]; ll ans = 0; rep(i, 0, n) { ans += abs(v[i] - middle); } cout << (long long int)ans << endl; return 0; }