#include #include #include using namespace std; int main() { int n; cin >> n; vector array; array.resize(n + 1, 0); for (int i = 0;i> num; array[num]++; } int cost = n == 1 ? 0 : 10000; vector target1; vector target2; for (int i = 1;i < array.size();i++) { if (array[i]==0) { target2.push_back(i); } else if (array[i]>1) { for (int j = 0;j < array[i]-1;j++) { target1.push_back(i); } } } for (int i = 0;i < target1.size();i++) { vector buf; copy(target1.begin(), target1.end(), back_inserter(buf)); int calc = 0; for (int j = 0;j < target1.size();j++) { calc += abs(target2[j]-target1[j]); } cost = min(cost,calc); for (int j = 0;j < target1.size();j++) { if (j == 0)target1[j] = buf[target1.size() - 1]; else { target1[j] = buf[j - 1]; } } } cout << cost<