#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int cost = 0;
  for (int i = 0; i < n; i++) {
    int key = a[i];
    for (int j = 0; j < n; j++) {
      if (a[j] == a[i] && i != j) {
        a[j] = a[i] + 1;
        cost++;
      }
    }
  }
  cout << cost << endl;
}
