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