#include using namespace std; int main() { int N, ans = 0; cin >> N; vector A(N); for (int i = 0; i < N; i++) { int tmp; cin >> tmp; A.at(tmp - 1)++; } for (int i = 0; i < N; i++) { while (A.at(i) > 1) { for (int j = 0; j < N; j++) { if (A.at(j) == 0) { ans += abs(i - j); A.at(i)--; A.at(j)++; break; } } } } cout << ans << endl; }