#include <bits/stdc++.h>
int main() {
  int n, i, j, t, k = 0, x, h = 0;
  int a[10010];
  memset(a, 0, sizeof(a));
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (x > h) h = x;
    a[x]++;
  }
  for (i = 1; i <= h; i++) {
    if (a[i] > 1) {
      a[i + 1] += a[i] - 1;
      k += a[i] - 1;
      a[i] = 1;
    }
  }
  j = a[h + 1];
  if (j > 1) {
    while (j) {
      k += j - 1;
      j--;
    }
  }
  printf("%d\n", k);
}
