#include <bits/stdc++.h>
using namespace std;
int main() {
  set<int> s;
  int n, x;
  cin >> n;
  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (s.find(x) == s.end())
      s.insert(x);
    else {
      while (s.find(x) != s.end()) {
        x++;
        res++;
      }
      s.insert(x);
    }
  }
  cout << res;
  return 0;
}
