#include <iostream>

using namespace std;

int main()
{ 
	int n , G;
	cin >> n;
	int arr[n];
	long long a = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i];
	}
	int h = n / 2;
	for (int i = 0; i < h; ++i)
	{
		if (arr[i] < arr[n-1-i])
		{
			G = arr[n-1-i] - arr[i];
		}
		else
		{
			G = arr[i] - arr[n-1-i];
		}
		a = G + a;
	}
	cout << a;
	return 0;
}