#include <bits/stdc++.h>
using namespace std;
int a[3010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int x = 0;
  for (int i = 0; i < n - 1; i++) {
    while (a[i] >= a[i + 1]) {
      a[i + 1]++;
      x++;
    }
  }
  cout << x;
}
