#include <bits/stdc++.h>
using namespace std;
int num[3005], use[6005];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int ans = 0;
    memset(use, false, sizeof(use));
    for (int i = 0; i < n; i++) scanf("%d", &num[i]);
    sort(num, num + n);
    for (int i = 0; i < n; i++) {
      if (!use[num[i]])
        use[num[i]] = true;
      else {
        int tmp = num[i];
        while (use[tmp]) {
          tmp++;
          ans++;
        }
        use[tmp] = true;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
