注意超过n的情况,因此我把上界设置为10000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI (M_PI)
#define INF (0x3f3f3f3f)
#define MOD (1000000007)
#define EPS (1e-12)
#define MAX (1000000)
#define LEN (MAX+5)
int c[10005];
int main()
{
int n,x;
cin >> n;
for(int i = 1;i <= n;++i){
scanf("%d",&x);
c[x]++;
}
int s = 0;
for(int i = 1;i <= 10000;++i){
if(c[i] > 1){
s += c[i] - 1;
c[i + 1] += c[i] - 1;
}
}
cout << s << endl;
return 0;
}