#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const double EPS = 1e-6;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
inline void time() { cerr << (clock() * 1.0 / CLOCKS_PER_SEC * 1.0); }
inline int read() {
  int x;
  scanf("%d", &x);
  return x;
}
inline int write(int x) { printf("%d", x); }
int a[10000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  int ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i < n; i++) {
    while (a[i] >= a[i + 1]) {
      ans++;
      a[i + 1]++;
    }
  }
  cout << ans;
  return 0;
}
