Small Permutation Problem (Hard Version)

Problem Name:
Small Permutation Problem (Hard Version)
Site:CodeForces
Links:
Tags:
Problem setters: