#include<iostream>
#include<cstring>
using namespace std;

typedef long long LL;
LL b[300];
int p = 200;

int main()
{
    int n, a;
    cin >> n;
    memset(b, 0, sizeof b);
    for(int i = 0; i < n; i++){
        cin >> a; a = a % p;
        b[a]++;
    }
    LL ans = 0;
    for(int i = 0; i < 205; i++){
        if(b[i] != 0 && b[i] != 1){
            LL k = b[i] * (b[i] - 1) / 2;
            ans += k;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 500005

int n;
char s[MAXN], t[MAXN];
vii v;
int ans;

int main() {
	scanf("%d", &n);
	scanf(" %s", s);
	scanf(" %s", t);
	int cnt = 0;
	int lo = 0;
	REP (i, 0, n) {
		if (s[i] == t[i]) continue;
		if (s[i] == '1' && t[i] == '0') {
			cnt++;
		} else if (s[i] == '0' & t[i] == '1') {
			cnt--;
		}
		if (cnt == 0) {
			v.pb(lo, i);
			lo = i + 1;
		}
	}
	if (cnt != 0) {
		printf("-1\n");
		return 0;
	}
	for (auto [lo, hi] : v) {
		while (s[lo] == t[lo]) lo++;
		while (s[hi] == t[hi]) hi--;
		if (s[lo] == '0') {
			assert(t[lo] == '1');
			reverse(s + lo, s + hi + 1);
			reverse(t + lo, t + hi + 1);
		}
		//printf("%d %d\n", lo, hi);
		//REP (i, lo, hi + 1) {
			//printf("%c", s[i]);
		//}
		//printf("\n");
		//REP (i, lo, hi + 1) {
			//printf("%c", t[i]);
		//}
		//printf("\n\n");
		REP (i, lo, hi + 1) {
			if (s[i] == '0') ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}
