#include <bits/stdc++.h>
using namespace std;
const int MAX = 3005;
int a[MAX];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int ans = 0;
  for (int i = 1; i < n; i++)
    if (a[i - 1] >= a[i]) {
      ans += a[i - 1] - a[i] + 1;
      a[i] = a[i - 1] + 1;
    }
  cout << ans << endl;
  return 0;
}
