#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  map<int, int> m;
  int n, x, i;
  cin >> n;
  long long sum = 0;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (!m.count(x))
      m[x] = x;
    else {
      int c = 0;
      int y = x;
      while (1) {
        y = y + 1;
        if (!m.count(y)) {
          m[y] = y;
          c = 1;
          sum += ((y - x) * 1LL);
        }
        if (c == 1) break;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
