#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  vector<int> count(10000);
  int answer = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (count[arr[i]] == 0) {
      count[arr[i]]++;
    } else {
      for (int j = arr[i] + 1; j < 10000; j++) {
        if (count[j] == 0) {
          answer += j - arr[i];
          count[j]++;
          break;
        }
      }
    }
  }
  cout << answer;
  return 0;
}
