#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  int n, kol = 0;
  cin >> n;
  vector<int> vec(n);
  for (auto &i : vec) cin >> i;
  sort(vec.begin(), vec.end());
  set<int> s;
  s.insert(vec[0]);
  for (int i = 1; i < n; ++i) {
    while (s.count(vec[i]) == 1) {
      vec[i]++;
      kol++;
    }
    s.insert(vec[i]);
  }
  cout << kol;
}
