#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
template <typename T>
void printV(vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int i, j, k;
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  set<int> s;
  sort((v).begin(), (v).end());
  s.insert(v[0]);
  int count = 0;
  for (int i = 1; i < n; i++) {
    if (s.find(v[i]) != s.end()) {
      int x = v[i];
      while (s.find(x) != s.end()) {
        x++;
      }
      s.insert(x);
      count += x - v[i];
    } else {
      s.insert(v[i]);
    }
  }
  cout << count << endl;
  return 0;
}
