#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n;
  vector<int> bad;
  for (int i = 0; i < n; i++) {
    cin >> x;
    bad.push_back(x);
  }
  sort(bad.begin(), bad.end());
  int curr = 1, cost = 0;
  for (int i = 1; i < n; i++) {
    while (bad[i] <= bad[i - 1]) {
      bad[i]++;
      cost++;
    }
    curr++;
  }
  cout << cost << endl;
  return 0;
}
