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