#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long N = 1000005;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  long long h[6005] = {0};
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    h[a[i]]++;
  }
  long long k = 0;
  for (long long i = 1; i < 6000; i++) {
    if (h[i] > 1) {
      h[i + 1] += (h[i] - 1);
      k += (h[i] - 1);
    }
  }
  cout << k << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) solve();
}
