#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int temp;
  long long int n;
  cin >> n;
  ;
  vector<long long int> v;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    ;
    v.push_back(temp);
  }
  sort(v.begin(), v.end());
  long long int hash[10000] = {0};
  for (int i = 0; i < n; i++) hash[v[i]]++;
  long long int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (hash[v[i]] == 1 || hash[v[i]] == 0) {
      continue;
    } else {
      long long int b = v[i];
      while (hash[b] >= 1) {
        cnt++;
        b++;
      }
      hash[b] = 1;
      hash[v[i]]--;
    }
  }
  cout << cnt;
}
