Help me in solving SNELECTP problem

My issue

how do i overcome runtime error to my code

My code

n=int(input())
for i in range(n):
    s=input()
    n=len(s)
    killed=[False]*n
    for i in range(n):
        if s[i]=='m':
            if i-1>=0 and s[i-1]=='s' and not killed[i-1]:
                killed[i-1]= True
                continue
            if i+1<=n and s[i+1]=='s':
                killed[i+1]= True
        
    snakes=0
    mongoose=0
    for i in range(n):
        if s[i]=='s' and not killed[i]:
            snakes+=1
        elif s[i]=='m':
            mongoose+=1
                
    ans="tie"
    if snakes>mongoose:           
        ans="snakes"
    elif mongoose>snakes:
        ans="mongoose"
    print(ans)

Learning course: Greedy Algorithms
Problem Link: Snakes, Mongooses and the Ultimate Election Practice Problem in Greedy Algorithms - CodeChef

@devyani1508
here plzz refer my c++ code for better understanding of the logic
ping me in case u get stuck at any point.

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    string s;
	    cin>>s;
	    int cnt=0;
	    map<int,int> mp;
	    for(int i=0;i<s.size();i++)
	    {
	        if(s[i]=='m')
	        {
	            int j=i;
	            while(i<s.size()&&s[i]=='m')
	            {
	                i++;
	            }
	            if(i-j==1)
	            {
	                if(j>0&&mp[j-1]==0)
	                mp[j-1]=1;
	                else
	                mp[i]=1;
	            }
	            else
	            {
	                mp[i]=1;
	           if(mp[j-1]!=1)
	            mp[j-1]=1;
	            }
	        
	        }
	    }
	    for(int i=0;i<s.size();i++)
	    {
	        if(mp[i]==1)
	        continue;
	        if(s[i]=='m')
	        cnt++;
	        else
	        cnt--;
	    }
	    if(cnt>0)
	    cout<<"mongooses";
	    else if(cnt<0)
	    cout<<"snakes";
	    else
	    cout<<"tie";
	    cout<<endl;
	}

}