Why am I getting nzec error?

HI , I was trying this codechef beginner level ques link:https://www.codechef.com/problems/SNELECT ,
and I am encountering a NZEC error in python 3.5 solution for this question , It works fine when I try this code in my computer. Please Help me understand the problem , I am fairly new to practice coding on sites like these

My Code - https://www.codechef.com/viewsolution/14701174

First give a check that you are not going out of index under any circumstance. Like, if there is a mongoose at last of the string, (Eg - sssm), them make sure you arent checking the ‘next’ element being a snake, because there is no element after it! These type of operations were prime reason why suers got NZEC and out of index errors, please give your code a check for it.

If thats not the issue, then i will be happy to help.