#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, temp, count = 0;
  cin >> n;
  vector<int> v(n / 2);
  for (int i = 0; i < n / 2; i++) {
    cin >> v[i];
  }
  if (v[0] == 1) {
    for (int i = 1; i < v.size(); i++) {
      temp = abs((v[i - 1] + 2) - v[i]);
      count = count + temp;
      v[i] = v[i - 1] + 2;
    }
  }
  cout << count;
  return 0;
}
