#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  long long sum = 0;
  int m = v[0];
  for (int i = 1; i < n; i++) {
    if (v[i] <= m) {
      sum += m - v[i] + 1;
      v[i] = m + 1;
    }
    m = v[i];
  }
  cout << sum << endl;
  return 0;
}
