#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 10;
int f[maxn], n, ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    f[a]++;
  }
  for (int i = 0; i < maxn; i++) {
    if (!f[i]) continue;
    ans += f[i] - 1;
    f[i + 1] += f[i] - 1;
  }
  cout << ans << endl;
  return 0;
}
