#include <bits/stdc++.h>
using namespace std;
void read(long long &n) { scanf("%lld", &n); }
void read(double &n) { scanf("%lf", &n); }
void read(int &n) { scanf("%d", &n); }
void read(char *s) { scanf("%s", s); }
int n;
int A[10010];
int x;
int c = 0;
int main() {
  cin >> n;
  vector<int> vc;
  vc.resize(n);
  for (int i = 0; i < n; i++) cin >> vc[i];
  sort(vc.begin(), vc.end());
  for (int i = 0; i < n - 1; i++) {
    if (vc[i] < vc[i + 1]) continue;
    int a = vc[i] + 1;
    c += abs(a - vc[i + 1]);
    vc[i + 1] = a;
  }
  cout << c << endl;
  return 0;
}
