#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int arr[4000];
    int sum = 0, sum1 = 0, x;
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    for (int i = 1; i < n; i++) {
      if (arr[i] >= arr[i + 1]) {
        sum1 = arr[i] + 1 - arr[i + 1];
        sum += sum1;
        arr[i + 1] += sum1;
      }
    }
    cout << sum << endl;
  }
}
