#include #include using namespace std; //ios::sync_with_stdio(false); int main() { unsigned n = 0; while (cin >> n) { if (n == 0) { cout << 0 << endl; continue; } unsigned cages[n]; for (unsigned i=0; i> cages[i]; } unsigned long steps = 0; for (unsigned j=n-1; j>0; --j) { while ( cages[j] != j+1) { int tmp = cages[j]; cages[j] = cages[tmp-1]; cages[tmp-1] = tmp; ++steps; //cout << " -- " << j << " " << cages[j] << endl; } } cout << steps << endl; } }