Once upon a time, a special mouse tried to discover a secret permutation p[1] … p[N]. However, he wasn’t able to without using a special device called the “permutation discoverer”. Given some permutation q[1] … q[N], this device tells him the number of positions i for which p[i] = q[i]. He cannot use the device more than a certain number of times though.
More formally, there exists a secret permutation p[1] … p[N]. You can use an operation query(q[1] … q[N]) that returns the number of positions i for which p[i] = q[i].
Given N, using a small enough number of queries, find p.