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