#include <bits/stdc++.h>
using namespace std;
int b[6002] = {0};
int c[6002] = {0};
int main() {
  int n;
  cin >> n;
  int a[n];
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (i = 0; i < n; i++) {
    if (b[a[i]] == 0) {
      b[a[i]] = 1;
    } else {
      c[count] = a[i];
      count++;
    }
  }
  int j;
  int ans = 0;
  for (i = 0; i < count; i++) {
    for (j = c[i] + 1; j < 2 * n; j++) {
      if (b[j] == 0) {
        b[j] = 1;
        ans = ans + j - c[i];
        break;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
