#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, total = 0;
  scanf("%d", &n);
  int a[n], freq[2 * n];
  memset(freq, 0, sizeof freq);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    freq[a[i]]++;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (freq[a[i]] > 1) {
      for (int j = 1; j <= n; j++) {
        if (freq[a[i] + j] == 0) {
          total += j;
          freq[a[i] + j]++;
          freq[a[i]]--;
          break;
        }
      }
    }
  }
  printf("%d\n", total);
}
