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