#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, p = 0, s1 = 0, s2 = 0, H[5000];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> H[i];
    s1 += H[i];
  }
  sort(H, H + n);
  for (i = 0; i < n; i++) {
    p = H[i];
    for (j = 0; j < n && j != i; j++) {
      if (H[i] == H[j]) {
        p++;
        H[i] = p;
      }
    }
    p = 0;
  }
  for (i = 0; i < n; i++) {
    s2 += H[i];
  }
  cout << abs(s1 - s2);
  return 0;
}
