#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
int a[N], n, res;
int main() {
cin >> n;
for (int i = 0; i < n; i ++ ) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i ++ )
for (int j = i + 1; j < n; j ++ )
if (a[i] == a[j]) {
res ++;
a[j] ++;
}
cout << res << '\n';
return 0;
}