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