Another Permutation Problem

CodeForces - 1859C