What's wrong with my code of CHEFHAM ?

Here is my code :

I have got 60 pts. Actually, for n>3 I rotated the array until and unless there is an answer for that array. For n==3 i took care for that and same for n==2 and n==1. But the problem was with n==4 where there were 3 distinct elements. Please help me with this. 

  [1]: https://www.codechef.com/viewsolution/16506856

When there are 3 distinct elements say 1,1,2,3 replace the element repeated twice with the other 2 elements and for the other 2 replace it with the repeated element.

That is 1,1,2,3 becomes : 2,3,1,1




1 1 2



2 1 1


2 (here)

2 1 1

as 1->2 (1) , 1->1 (still 1) ans 2 -> 1 (2)

Yeah, Exactly. This is what my output was. I have taken all cases into consideration.

And my result was WA. it means it is showing some output(maybe wrong). And this is only possible when there is no match between two arrays, otherwise, it would be NZEC.

Oh Shit, I thought we are required to maximize the index of first matching element.