#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> badges;
  vector<bool> used(6010, false);
  for (int i = 0; i < N; i++) {
    int temp;
    scanf("%d", &temp);
    if (used[temp])
      badges.push_back(temp);
    else
      used[temp] = true;
  }
  sort(badges.begin(), badges.end());
  int cost = 0;
  for (int i = 0, j = 0; i < badges.size(); j++) {
    if (badges[i] > j) continue;
    if (used[j] == false) {
      cost += j - badges[i];
      i++;
    }
  }
  printf("%d\n", cost);
  return 0;
}
