https://www.codechef.com/problems/COPYPUSH?tab=statement

i am not understanding what is wrong in my code.
void solve()
{
int n;
string s;
cin>>n>>s;
string curr = “”;
bool flag = 1;

for(int i = 0; i<n; i++)
{
    int remlen = n - i;
    bool copied = 0;
    if(curr.length() > 0 && remlen >= curr.length())
    {
        bool now = 1;
        for(int j = 0; j<curr.length(); j++)
        {
            if(s[i + j] != curr[j])
            {
                if(flag)
                {
                    now = 0;
                    break;
                }
                else
                {
                    NO;
                    return;
                }
            }
        }
        if(now)
        {
            curr += curr;
            i = (curr.length()) - 1;
            copied = 1;
            flag = 1;
        }
    }
    else if(!flag)
    {
        NO;
        return;
    }
    
    if(!copied)
    if(flag)
    {
        curr += s[i];
        flag = 0;
    }
    else
    {
        NO;
        return;
    }
}
YES;

}

@jay_yadav93
Your logic is not right
This problem git very interesting logic
plzz refer my c++ code for better understanding .
Ping me if u don’t get the logic

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    string s;
	    cin>>s;
	    int tm=0;
	    while(n>0)
	    {
	        if(n%2==0)
	        {
	            for(int i=0,j=n/2;i<n/2;i++,j++)
	            {
	                if(s[i]!=s[j])
	                {
	                tm=1;
	                break;
	                }
	            }
	            n=n/2;
	        }
	        else
	        n--;
	        
	        if(tm)
	        break;
	    }
	    if(tm)
	    cout<<"No";
	    else
	    cout<<"Yes";
	    cout<<endl;
	}
	return 0;
}