#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
  int n;
  cin>>n;
  string s;
  string t;
  cin>>s>>t;
  int a=0,b=0;
  for(int i=0;i<n;i++){
    if(s[i]=='1')a++;
    if(t[i]=='1')b++;
  }
  if(a<b||a%2!=b%2){
    cout<<-1<<"\n";
    return 0;
  }
  queue<ll> c,d;
  ll ans=0;
  for(int i=0;i<n;i++){
    if(t[i]=='1'){
      d.emplace(i);
    }
      if(s[i]=='1'){
          if(c.size()&&d.size()){
             if(c.front()<d.front()){
                   ans+=i-c.front();
                   c.pop();
             }else{
               ans+=i-d.front();
               d.pop();
             }
          }else if(c.size()){
                   ans+=i-c.front();
                   c.pop();         
          }else if(d.size()){
              ans+=i-d.front();
              d.pop();
          }else{
            c.emplace(i);
          }
      }
  }
  if(c.size()||d.size()){
    cout<<-1<<"\n";
    return 0;
  }
  cout<<ans<<"\n";
}
#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define bck(i, a, b) if ((i) >= (a) && (i) < (b))
#define trav(x, a) for (auto &x : (a))
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define dbg(X) std::cerr << "[DBG]("<<__FUNCTION__<<":"<<__LINE__<<") " << #X << ": " << X << std::endl;
using namespace std;
typedef long long ll;
typedef string str;
template<typename T> using vec = vector<T>;
template<typename T> using pq = priority_queue<T, vector<T>, std::greater<T>>;
template<typename T> using mxpq = priority_queue<T>;
typedef pair<int,int> pii;
typedef vec<int> vi;
typedef vec<pii> vii;
typedef vec<vi> vvi;
typedef pair<ll,ll> pll;
typedef vec<ll> vl;
typedef vec<pll> vll;
typedef vec<vl> vvl;
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<typename A, typename B>
istream& operator>>(istream& s, pair<A,B>& p) { return s>>p.first>>p.second; }
template<typename T>
istream& operator>>(istream& s, vec<T>& p) { for (T& t : p) s >> t; return s; }
template<typename T>
ostream& operator<<(ostream& s, const vec<T>& p) { for (const T& t : p) s << t << " "; return s; }

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vl a(n); cin >> a;
    for (int i=0; i<n; i+=2) a[i] *= -1;
    map<ll,ll> seen;
    seen[0]=1;
    ll sum = 0, c = 0;
    rep(i, 0, n) {
        sum += a[i];
        c += seen[sum]++;
    }
    cout << c << endl;
}
