#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[3003], ans = 0;
  int s[6003] = {0};
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    s[a[i]]++;
  }
  sort(a, a + n);
  for (int i = 1; i < n; ++i) {
    if (s[a[i]] > 1) {
      s[a[i]]--;
      while (1) {
        a[i]++;
        ans++;
        if (s[a[i]] == 0) break;
      }
      s[a[i]]++;
    }
  }
  cout << ans << "\n";
  return 0;
}
