#include <bits/stdc++.h>
int arr[3005];
int main() {
  int n;
  int ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  std::sort(arr, arr + n);
  for (int i = 0; i < n - 1; i++) {
    while (arr[i] >= arr[i + 1]) {
      arr[i + 1]++;
      ans++;
    }
  }
  printf("%d", ans);
  return 0;
}
