Need help with RAINBOWA

Hi, I am not sure if I should ask the question here. I thought to ask it in reddit, stackoverflow and quora and then thought to ask here since this seems most appropriate.

I solved the RAINBOWA problem but upon submission, the result is wrong answer. But the example inputs are passing. How can I know which test cases are failing?

Link to my code : https://www.codechef.com/viewsolution/25934125

Best regards,
code_hyena.

Consider e.g.

1 
16  
1 2 3 4 5 6 6 7 6 7 6 5 4 3 2 1