#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  int total = 0;
  for (int i = 1; i < n; i++) {
    if (arr[i] <= arr[i - 1]) {
      int d = arr[i - 1] + 1 - arr[i];
      arr[i] += d;
      total += d;
    }
  }
  cout << total;
  return 0;
}
