#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a) cin >> x;
  sort(a.begin(), a.end());
  set<int> s;
  int ans = 0, x;
  for (int i = 0; i < n; i++) {
    x = a[i];
    if (s.find(x) != s.end()) {
      while (1) {
        if (s.find(x) != s.end())
          ans++;
        else
          break;
        x++;
      }
    }
    s.insert(x);
  }
  cout << ans << "\n";
  return 0;
}
