Long Permutation

CodeForces - 1443E