Perfect Permutation

can someone please tell , what am I doing wrong in the solving the problem perfect permutation from feb cook-off

here’s the link to my [solution](https://www.codechef.com/viewsolution/59366205)

here’s the link to [problem](https://www.codechef.com/COOK138C/problems/PERFPERM)