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

typedef long long ll;

const int Maxn = 1000005;

char tmp[Maxn];
int n;
string A;
string B;

void Read(string &s)
{
	scanf("%s", tmp); s = tmp;
}

int main()
{
	cin >> n;
	Read(A);
	Read(B);
	int asum = 0, bsum = 0;
	int add = 0, neutr = 0;
	ll res = 0;
	for (int i = 0; i < n; i++) if (A[i] != '1' || B[i] != '1') {
		asum += A[i] == '1';
		bsum += B[i] == '1';
		if (A[i] == '0' && B[i] == '1') add++;
		if (A[i] == '0' && B[i] == '0') neutr++;
		if (asum == bsum) {
			if (add > 0) res += add + neutr;
			add = neutr = 0;
		}
	}
	printf("%lld\n", asum != bsum? -1ll: res);
    return 0;
}

 #include<iostream>
 #include<algorithm>
 
 using namespace std;
 const int N=100010;
 
 typedef long long ll;
 
 int n;
 char a[N];
 int sum1[N];
 int sum2[N];
 
 
 int main()
 {
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    
    for(int i=1;i<=n;i++)
    {
        if(a[i]=='A')
        {
            sum1[i]=1;
        }
        else if(a[i]=='T')
        {
            sum1[i]=-1;
        }
        else if (a[i]=='C')
        {
            sum2[i]=1;
        }
        else if (a[i]=='G')
        {
            sum2[i]=-1;
        }
    }
    
    for(int i=1;i<=n;i++)
    {
        sum1[i]+=sum1[i-1];
        sum2[i]+=sum2[i-1];
    }
    
    //只有5000，可以枚举两个区间
    
    ll ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++)
        {
            if(sum1[j]-sum1[i-1]==0&&sum2[j]-sum2[i-1]==0)ans++;
        }
    cout<<ans;
    
    return 0;
 }