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