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