#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<int> vec;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int val;
    cin >> val;
    vec.push_back(val);
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (vec[i] == vec[i - 1]) {
      vec[i]++;
      ans++;
    } else if (vec[i - 1] > vec[i]) {
      int dif = vec[i - 1] - vec[i];
      vec[i] += dif + 1;
      ans += dif + 1;
    }
  }
  cout << ans;
  return 0;
}
