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