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