Make a Permutation!

CodeForces - 864D