#include <bits/stdc++.h>
using namespace std;
void cp() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n, x;
  cin >> n;
  long long count = 0;
  set<long long> a;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (a.count(x)) {
      while (a.count(x) != 0) {
        count++;
        x++;
      }
      a.insert(x);
    } else
      a.insert(x);
  }
  cout << count;
  return 0;
}
