#include <bits/stdc++.h>
using namespace std;
vector<int> a(3007), b(30000);
int n, i, s, bar, j;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (i = 1; i <= n; i++) {
    if (b[i] > 1) {
      for (j = i + 1;; j++)
        if (b[j] == 0) {
          b[j]++;
          s += j - i;
          if (--b[i] == 1) break;
        }
    }
  }
  cout << s;
}
