#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back 
#define mp make_pair
#define fi first 
#define se second 
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define LL_MAX LLONG_MAX 
 
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
 
#define mod 1000000007
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int fac[1000009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
 
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factor(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); } 
 
int power(int x, int y){int temp;if( y == 0)return 1; temp = power(x, y / 2);if (y % 2 == 0) return temp * temp;else return x * temp * temp;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int log2n( int n){ return (n > 1) ? 1 + log2n(n / 2) : 0;} 
 
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;} 
void sout(set<int>s){for(auto it=s.begin();it!=s.end();++it)cout<<*it<<" ";  cout<<endl;}  
void mout(map<int,int>mm){for(auto it=mm.begin();it!=mm.end();++it) cout<<it->fi<<" "<<it->se<<endl;}
 
#define ms(a,x)  memset(a, x, sizeof(a));
 
#define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl 
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
 
 
// In binary search always report l-1
 
 
signed main()
{
 
 
      run;
 
 
/* 
open for mod factorial
 
     fac[0]=1;
      for(int i=1;i<1000009;i++)
      {
          fac[i]=mul(fac[i-1],i); 
           
      }
*/
 
 
/*
  for sieve open this and use v_prime 
 
          int pp=pow(10,6)+100000;
               Sieve(pp);
*/
 
 
 // factor(n)  &&   USE v_factor For calculating factors && don't forget v_factor.clear();           
 
 
int  t=1;
//cin>>t;
while(t--)
{
             //  map<int,int>mm; // it->second-->frequency
 
 
             int  n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0;
             int  h[100009]={0};
 
 
                  cin>>n;
 
 
                 string s1,s2;cin>>s1>>s2;
                 vector<int>v1,v2;
                 for(i=0;i<n;i++)
                 {
                     if(s1[i]=='0')
                     {
                         v1.pb(i);
                     }
                     if(s2[i]=='0')
                     {
                         v2.pb(i);
                     }
                 }

                 if(v1.size()!=v2.size())
                 {
                     ans=-1;

                 }
                 else
                 {
                     for(i=0;i<v1.size();i++)
                     {
                         if(v1[i]!=v2[i])
                           ans++;
                     }
                 }

                 cout<<ans<<endl;
 
 
         
 
}
}
#include <bits/stdc++.h>
using namespace  std;
#define f(i,n) 		for(i=0;i<n;i++)
#define fr(i,n,a) 	for(i=n;i>=a;i--)
#define fa(i,a,n) 	for(i=a;i<n;i++)
#define deb(x)		cout<<#x<<" "<<x<<endl;
#define deb2(x,y)	cout<<#x<<","<<#y<<" "<<x<<","<<y<<endl;
#define buf(x)		cout<<"Check"<<x<<endl;
#define ll			long long int 
#define ft			first
#define s			second
#define pb			push_back
#define mp			make_pair
#define do			double
#define all(v)		v.begin(),v.end()	
#define et(v)		for(auto itr:v)
#define mod			1000000007
inline void p(vector<ll> x,int n)	{	int i;f(i,n)cout<<x[i]<<" ";cout<<endl; }
 

void solve()
{  	
	ll N,M,i,j,sum=1,pos,neg=0,z=0;
	ll x,y,k;
	cin>>N;
	string s;
	cin>>s;
	vector<ll> arr(N);
	f(i,N)
	{
		if(s[i]=='A')
			arr[i]=1;
		else if(s[i]=='T')
			arr[i]=-1;
		else if(s[i]=='G')
			arr[i]=10000;
		else
		{
			arr[i]=-10000;
		}
		
	}
	
	map<ll,ll> p;
    ll res = 0;
    ll curr = 0;
 
    f(i,N)
	{
 
        curr += arr[i];
 
        if (curr == 0)
            res++;
 
        if (p.find(curr) != p.end())
            res += (p[curr]);

        p[curr]++;
    }

	cout<<res;
}

	

int main()
{	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,c=1;
	//cin>>t;
	while(t--)
	{
		
 
		//cout<<"Case #"<<c++<<": "<<endl;
		solve();
		cout<<"\n";
		
	}
	return 0;
}