New Year Permutation

CodeForces - 500B