#include <bits/stdc++.h>
using namespace std;
int coolness[6001];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    fill(coolness, coolness + 6001, 0);
    for (int i = 0; i < n; i++) {
      int temp;
      scanf("%d", &temp);
      coolness[temp]++;
    }
    int cost = 0;
    for (int i = 1; i <= n; i++) {
      for (; coolness[i] > 1; coolness[i]--) {
        for (int j = i + 1;; j++) {
          if (coolness[j] == 0) {
            coolness[j]++;
            cost += j - i;
            break;
          }
        }
      }
    }
    printf("%d\n", cost);
  }
}
