#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, badge = 0, Y = 1;
  cin >> N;
  int X[N - 1];
  cin >> X[0];
  for (int i = 1; i < N; i++) {
    cin >> X[i];
    for (int j = 0; j < i; j += Y) {
      if (X[i] == X[j]) {
        X[i]++;
        badge++;
        j = 0;
        Y = 0 - j;
      } else
        Y = 1;
    }
  }
  cout << badge << endl;
}
