#include <bits/stdc++.h>
using namespace std;
int N, val[10001 + 2], cfbd = 0;
int main() {
  int i, j, k, x;
  scanf("%d", &N);
  for (i = 0; i < N; i++) scanf("%d", &x), val[x]++;
  for (i = 1; i <= 10001; i++) {
    if (val[i] > 1) {
      cfbd += val[i] - 1;
      val[i + 1] += val[i] - 1;
    }
  }
  printf("%d", cfbd);
  return 0;
}
