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