Help me in solving NCOPIES problem

My issue

My approach is find the prefix sum array and checking for prefix sum and suffix sum for each and every element in prefix array if they are equal increase good. At the end print good

My code

#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	long long tc=0;
	cin>>tc;
	while(tc--) {
	    long long n=0,m=0;
	    cin>>n>>m;
	    string str="";
	    cin>>str;
	    long long i=0,j=1,k=n*m;
	    vector<long long> prefix(k,0);
	    prefix[0]=str[0]-'0';
	    for(i=1;i<k;i++) {
	        prefix[i]=prefix[i-1]+(str[j%n]-'0');
	        j++;
	    }
	    j=0;
	    for(i=0;i<k;i++) {
	        if(2*prefix[i]==prefix[k-1])
	        j++;
	    }
	    cout<<j<<endl;
	}
	return 0;
}

Problem Link: Copy and Paste Practice Coding Problem - CodeChef

@gkey_pradeep25
plzz refer my c++ code for better understanding of the logic

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    long long int n,m;
	    cin>>n>>m;
	    string s;
	    cin>>s;
	    long long int ans=0,cnt=0,cnt1=0;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='0')
	        cnt++;
	        else
	        cnt1++;
	    }
	    if(cnt==n)
	    {
	        ans=n*m;
	    }
	    else
	    {
	        int c=0;
	        if(m%2)
	        {
	            for(int i=0;i<n;i++)
	            {
	                if(s[i]=='1')
	                c++;
	                if(c==cnt1-c)
	                {
	                    ans++;
	                }
	            }
	        }
	        else
	        {
	            s+=s;
	            cnt1*=2;
	            for(int i=0;i<s.size();i++)
	            {
	                if(s[i]=='1')
	                c++;
	                if(c==cnt1-c)
	                {
	                    ans++;
	                }
	            }
	        }
	    }
	    cout<<ans<<endl;
	}

}

Thank you. I understood the logic