#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n;
    string s;
    cin>>n>>s;
    for(auto &x : s)
    {
    	if(x=='A')
    		x = '0';
    	if(x=='G')
    		x = '1';
    	if(x=='C')
    		x = '2';
    	if(x=='T')
    		x = '3';
    }
    int c[n][4];
    fill(c,0);
    for (int i = 0; i < n; ++i)
    {
    	c[i][s[i]-'0']++;
    }
    for (int i = 1; i < n; ++i)
    {
    	for (int j = 0; j < 4; ++j)
    	{
    		c[i][j]+=c[i-1][j];
    	}
    }
    // cout<<s;
    int ans = 0;
    for(int i = 0 ; i < n ; i++)
    {
    	for(int j = i+1 ; j < n ; j++)
    	{
    		int cc = c[j][2];
    		if(i)
    			cc-=c[i-1][2];

    		int cg = c[j][1];
    		if(i)
    			cg-=c[i-1][1];

    		int ct = c[j][3];
    		if(i)
    			ct-=c[i-1][3];

    		int ca = c[j][0];
    		if(i)
    			ca-=c[i-1][0];

    		if(ca==ct&&cg==cc)
    		{
    			ans++;
    		}
    	}
    }
    cout<<ans;

    printclock;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
#define Maxn 500010
#define cout cerr
char ch[Maxn];
int S[Maxn],T[Maxn];
int seq[Maxn],cnt;
int A[Maxn],a,B[Maxn],b;

int main(){
	scanf("%d",&n);
	scanf("%s",ch+1);
	for(int i=1;i<=n;++i)S[i]=ch[i]-'0';
	scanf("%s",ch+1);
	for(int i=1;i<=n;++i)T[i]=ch[i]-'0';
	long long Ans=0;
	for(int i=1;i<=n;++i){
		if(S[i])A[++a]=i;
		if(T[i])B[++b]=i;
	}
	if(a<b){
		puts("-1");
		return 0;
	}
	if((a-b)&1){
		puts("-1");
		return 0;
	}
	int j=1;
	for(int i=1;i<=b;++i)
		if(A[j]<B[i]){
			if(j>=a){
				puts("-1");
				return 0;
			}
			while(A[j]<B[i]){
				if(j>=a){
					puts("-1");
					return 0;
				}
				Ans+=A[j+1]-A[j];
				j+=2;
			}
			if(j>a){
				puts("-1");
				return 0;
			}
			Ans+=A[j]-B[i];
			j++;
		}else{
			Ans+=A[j]-B[i];
			j++;
		}
	for(int i=j;i<=a;i+=2)Ans+=A[i+1]-A[i];
	printf("%lld\n",Ans);
	return 0;
}