#include <bits/stdc++.h>
void sortBadges(int nElement, int arry[]) {
  int swap;
  for (int i = 0; i < nElement; i++) {
    for (int j = i + 1; j < nElement; j++) {
      if (arry[i] > arry[j]) {
        swap = arry[i];
        arry[i] = arry[j];
        arry[j] = swap;
      }
    }
  }
}
int main() {
  int nSoldier, badge[3000], result, temp;
  while (scanf("%d", &nSoldier) == 1) {
    for (int i = 0; i < nSoldier; i++) scanf("%d", &badge[i]);
    sortBadges(nSoldier, badge);
    result = 0;
    for (int i = 0; i < nSoldier - 1; i++) {
      if (badge[i] == badge[i + 1]) {
        result++;
        badge[i + 1]++;
      }
      if (badge[i] > badge[i + 1]) {
        temp = badge[i] - badge[i + 1];
        badge[i + 1] = badge[i + 1] + temp + 1;
        result = result + temp + 1;
      }
    }
    printf("%d\n", result);
  }
  return 0;
}
