#include <bits/stdc++.h>
using namespace std;
int n;
int ans;
int arr[6001];
int main() {
  cin >> n;
  int tmp;
  for (int i = 1; i <= n; i++) {
    cin >> tmp;
    arr[tmp]++;
  }
  int index = 1;
  while (1) {
    if (arr[index] <= 1 && index > n) break;
    if (arr[index] <= 1) {
      index++;
      continue;
    } else {
      index++;
      arr[index] += arr[index - 1] - 1;
      ans += arr[index - 1] - 1;
    }
  }
  cout << ans;
  return 0;
}
