#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    vector<int> T(3 * n + 1), v;
    for (int i = 0; i < n; ++i) {
      int x;
      scanf("%d", &x);
      x--;
      if (!T[x])
        T[x] = 1;
      else
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < ((int)(v).size()); ++i) {
      int x = v[i];
      int ind = -1;
      for (int j = x;; ++j)
        if (!T[j]) {
          ind = j;
          break;
        }
      T[ind] = 1;
      ans += ind - x;
    }
    printf("%d\n", ans);
  }
}
