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