#include <bits/stdc++.h>
using namespace std;
int main() {
  int s = 0, n, a[3005];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  for (int i = 1; i < n; i++) {
    s += max(0, a[i - 1] + 1 - a[i]);
    a[i] = max(a[i], a[i - 1] + 1);
  }
  cout << s;
  return 0;
}
