#include <bits/stdc++.h>
int main() {
  long long n, i, count = 0;
  long long ar[3003];
  scanf("%lld", &n);
  for (i = 0; i < n; i++) scanf("%lld", &ar[i]);
  std::sort(ar, ar + n);
  i = 1;
  while (i < n) {
    if (ar[i] == ar[i - 1] || ar[i] <= ar[i - 1]) {
      ar[i]++;
      count++;
    } else
      i++;
  }
  printf("%lld\n", count);
  return 0;
}
