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