Annoying bug in Equal LIS Start22

Any one knows what’s wrong with this code Solution: 56719255 | CodeChef (only 1 failed)

After contest, I figured out the issue is the case when n == 4, so i use a next_permutation for this. and AC Solution: 56733682 | CodeChef

But really don’t know why the first version failed in n == 4?