#include<iostream>
using namespace std;
int main()
{
long long int n;
cin >> n;
int* a = new int[n];
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
long long int ans;
long long int sum = 0;
long long int end = n - 1;
for (int i = 0; i < n / 2; i++)
{
if (a[i] != a[end])
{
ans = a[i] - a[end];
if (ans < 0)
{
ans *= -1;
}
a[end] = ans;
a[i] = ans;
sum += ans;
}
end--;
}
cout << sum;
return 0;
}