Help me in solving SUMMODE problem

My issue

could you give me a proper solution to this problem with explanation

My code

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

int main() {
	// your code goes here
	return 0;
}

Problem Link: Sum of Modes Practice Coding Problem

@yuvrj123
plzz refer my c++ code for better understanding .
logic is i have calculated total number of subarray which will give 1 and than adding extra one for whose that have even length subarray having equal number of ones and zeros.

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    long long int n;
	    cin>>n;
	    string s;
	    cin>>s;
	    long long int sm=0,ans=0;
	    map<long long int,long long int> mp;
	    mp[0]=1;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='0')
	        sm--;
	        else
	        sm++;
	        ans+=mp[sm];
	        mp[sm]++;
	        
	    }
	    ans+=(n*(n+1))/2;
	    cout<<ans<<endl;
	    
	    
	}
}

oh, I got it.
thanks for helping me out.