#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[39000], b[39000];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  long long sum = 0;
  for (int i = 1; i <= 2 * n; i++) {
    if (b[i] > 1) {
      sum += b[i] - 1;
      b[i + 1] += b[i] - 1;
      b[i] = 1;
    }
  }
  cout << sum;
  return 0;
}
