#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[3001];
  memset(arr, 0, sizeof(arr));
  int n;
  cin >> n;
  int l = n;
  long int count = 0;
  int i = 0;
  while (n--) {
    cin >> arr[i++];
  }
  sort(arr, arr + l);
  i = 0;
  for (; i < l - 1; i++) {
    if (arr[i + 1] <= arr[i]) {
      count = count + arr[i] - arr[i + 1] + 1;
      arr[i + 1] = arr[i] + 1;
    }
  }
  cout << count;
  return 0;
}
