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