#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0, k;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  k = a[0];
  for (int i = 1; i < n; i++) {
    if (k >= a[i]) {
      s += k - a[i] + 1;
      k++;
    } else
      k = a[i];
  }
  cout << s;
}
