New Year and Permutation

CodeForces - 1284C