Run time Error in Google Kick Start Round G 2020

Yesterday, I had participated in Google Kick Start and submitted my solution, but it show RE while sample cases are passed successfully.

I have also try my code on "ideone " for sample cases.

Anyone who find some error or bug in my code please make me it noted.

Problem Statement: https://codingcompetitions.withgoogle.com/kickstart/round/00000000001a0069/0000000000414bfb

My solution:

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

int main(){
    int tc,m,n,fs;
    cin>>tc;
    string s;
    string s1="KICK",s2="START";
    for(int i=0;i<tc;i++){
        cin>>s;
        m=0,n=0,fs=0;
        for(int j=0;j<s.size()-3;j++)
        {
            
            if(s1.compare(s.substr(j,4)) == 0){
                //cout<<s.substr(j,4)<<endl;
                m++;  
            }
            if(s2.compare(s.substr(j,5)) == 0 && j<s.size()-4){
                //cout<<s.substr(j,5)<<endl;
                n+=m;
                
            }
            
        }
        
        cout<<"Case #"<<i+1<<": "<<n<<endl;
    }
    
}

s.substr is getting out of bound
j<s.size()-4 should come before s2.compareā€¦ because for ex cond1&&cond2&&cond3 the order is from cond1 to cond2

can someone check my code for problem no. 3, Combination Locks, no idea where it is failing. I have used Binary Search+Prefix Sum, help would be appreciated.Thanks!
Code : https://ideone.com/0jY4Ko