#include <bits/stdc++.h>
using namespace std;
void input(vector<long long> &arr, long long n) {
  for (long long i = 0; i < n; i++) cin >> arr[i];
}
long long sumarr(vector<long long> &arr, long long n) {
  long long sum = 0;
  for (long long i = 0; i < n; i++) sum += arr[i];
  return sum;
}
vector<long long> prearr(vector<long long> &arr, long long n) {
  vector<long long> temp(n);
  temp[0] = arr[0];
  for (long long i = 1; i < n; i++) temp[i] = temp[i - 1] + arr[i];
  return temp;
}
vector<long long> postarr(vector<long long> &arr, long long n) {
  vector<long long> temp(n);
  temp[n - 1] = arr[n - 1];
  for (long long i = n - 2; i >= 0; i--) temp[i] = temp[i + 1] + arr[i];
  return temp;
}
int32_t main() {
  long long tt = 1;
  while (tt--) {
    long long n;
    cin >> n;
    long long arr[n];
    for (long long i = 0; i < n; i++) cin >> arr[i];
    long long cost = 0;
    bool test = false;
    do {
      test = false;
      sort(arr, arr + n);
      for (long long i = 0; i < n - 1; i++) {
        if (arr[i] == arr[i + 1]) {
          arr[i + 1] += 1;
          cost += 1;
          test = true;
        }
      }
    } while (test);
    cout << cost << "\n";
  }
  return 0;
}
