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