#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, pay;
  while (scanf("%d", &n) != EOF) {
    int i, j, k;
    int a[3005] = {0};
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a, a + n);
    int flag = 0, t = 0;
    for (j = 0; j < n; j++)
      for (i = j + 1; i < n; i++) {
        if (a[j] >= a[i] && i != j) {
          flag += a[j] - a[i] + 1;
          a[i] = a[j] + 1;
        }
      }
    printf("%d\n", flag);
  }
  return 0;
}
