#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int k = 0;
  for (long long int i = 1; i < n - 2; i = i + 2) {
    k = k + abs(a[i] - a[i - 1]);
  }
  if (n % 2 != 0) {
    long long int c = max(a[n - 1], a[n - 2]);
    long long int b = max(c, a[n - 3]);
    k = k + b - a[n - 1] + b - a[n - 2] + b - a[n - 3];
  } else {
    k = k + abs(a[n - 1] - a[n - 2]);
  }
  cout << k;
  return 0;
}
