#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, p = 0, ni = 10000000;
  int s;
  cin >> n;
  std::vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> m;
    v.push_back(m);
  }
  sort(v.begin(), v.end());
  s = 1;
  for (int i = 0; i < n; i++) {
    s = max(s, v[i]);
    p += s - v[i];
    s++;
  }
  cout << p;
  return 0;
}
