#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int arr[n];
for ( int i = 0 ; i < n ; i ++ )
{
cin >> arr[i];
}
long long int shot = 0;
int j = n - 1;
for ( int i = 0 ; i < n / 2 ; i ++ )
{
if ( arr[i] > arr[j] )
{
shot = shot + ( arr[i] - arr[j] );
}
else if ( arr[i] < arr[j] )
{
shot = shot + ( arr[j] - arr[i] );
}
j --;
}
cout << shot;
return 0;
}