Chef and His Characters(Cakewalk) SIGSEGV c++ error. Chat-GPT says nothing wrong with code!

I am curious as to where I am going wrong in my code. It seems that there are some submissions that contain the same logic, but somehow my code gets a SIGSEGV error. Can anyone please help me and let me know where I am going wrong? Your help will be much appreciated.

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

int main(){
    int t;
        string s;
        int count = 0;
        for(int i = 0; i < s.size()-3; ++i){
            string temp ;
            for(int j = i;j < i+4; ++j){
            if(temp == "cefh")++count;
        count > 0?cout<<"lovely "<<count<<endl:cout<<"normal"<<endl;
    return 0;

Problem: CHEFCHR Problem | CodeChef

Hi there folks,

I just confirmed my solution with Chat-GPT. This is what it had to say:

Why does Codechef through a SIGSEGV error? Is it something wrong from their side or is there really something wrong with my code.

Chat-GPT is complete shit and you shouldn’t refer to it for advice.

for(int i=0;i<s.size()-3;++i){

In this line of code, s.size() returns unsigned int, and if it is less than 3, then subtracting 3 will result in an underflow into a very large number.

for(int i=0;i<(int)s.size()-3;++i){ 

This is the correct way to write it.

I wouldn’t bad mouth Chat-GPT as it can generate code(sometimes optimized version), it is actually great. I decided to post here, cause I know that Chat-GPT might go wrong somewhere. You are right, advice from Chat-GPT might not always be true. Thank you for helping me @a7742525643 .