#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, ns[10005] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    ns[a]++;
  }
  int ans = 0;
  for (int i = 0; i < 10000; i++) {
    int j = i + 1;
    while (ns[i] > 1) {
      for (; j < 10000 && ns[j] != 0; j++)
        ;
      ns[j]++;
      ns[i]--;
      ans += j - i;
    }
  }
  cout << ans << endl;
  return 0;
}
