Restoration of the Permutation

CodeForces - 67B