#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int cnt = 0;
  int c = v[0];
  bitset<3000000> bs;
  for (int i = 0; i < N; i++) {
    if (bs[v[i]]) {
      cnt += abs(v[i] - c);
      v[i] = c;
    }
    bs[v[i]] = 1;
    c = v[i] + 1;
  }
  cout << cnt << endl;
}
