#include #include #include #include #include using namespace std; int main() { int n, cnt = 0; cin >> n; vector v(n, 0); for (int i = 0; i < n; i++){ int t; cin >> t; v[t-1]++; } for (int i = 0; i < n; i++){ if (v[i] > 1){ int j = i + 1; while (v[i] != 1){ if (v[j] == 0){ cnt += (j - i); v[i]--; v[j]++; } else j++; } } else if (!v[i]){ for (int j = i; j < n; j++){ if (v[j] > 1){ cnt += (j - i); v[j]--; v[i]++; break; } } } } cout << cnt << endl; }