#include <bits/stdc++.h>
int a[6001];
int main() {
  int i;
  int b;
  int n;
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &b);
    a[b]++;
  }
  int count = 0;
  for (i = 0; i < n * 2; i++) {
    if (a[i] > 1) {
      count += a[i] - 1;
      a[i + 1] += a[i] - 1;
    }
  }
  printf("%d", count);
  return 0;
}
