#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

string to_string(const string& str) {
  return str;
}

template<typename T>
string to_string(const set<T>& mys) {
  if(mys.empty()) return "{}";
  string ret = "{";
  for(auto el: mys) ret += to_string(el) + ", ";
  ret.pop_back(), ret.pop_back(); // Remove last space and comma
  ret += "}";
  return ret;
}

template<typename T>
string to_string(const pair<T, T>& pr) {
  return "(" + to_string(pr.fi) + "," + to_string(pr.se) + ")";
}

template<typename T>
string to_string(const vector<T>& vc, int w) {
  if(vc.empty()) return "";
  if(w + 1 == vc.size()) return to_string(vc[w]);
  return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
  return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifdef DEBUG
  freopen("input.txt", "r", stdin);
  #endif

  int n;
  cin >> n;
  vector<ll> arr(n);
  for(auto& el: arr) cin >> el;
  map<ll, ll> mp;
  ll zer = 0, ans = 0;
  for(int i = 0; i < n; i++) {
    ll vl = arr[i];
    if(i & 1) vl = -vl;
    mp[zer]++;
    zer -= vl;
    ans += mp[zer];
  }
  cout << ans << '\n';
}


#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  int S_count_1 = 0; // Sに含まれる1の個数
  int T_count_1 = 0;
  deque <int> S_1; // 1がある位置 0-indexed
  deque <int> T_1;

  ll ans = 0; // 答えである、回数

  rep(i,N){
    if (S[i] == '1'){
      S_count_1 ++;
      S_1.push_back(i);
    }
    if (T[i] == '1'){
      T_count_1 ++;
      T_1.push_back(i);
    }
  }

  if (S_count_1 < T_count_1 || ((S_count_1 - T_count_1) % 2 != 0) ){
    cout << -1 << endl;
    return 0;
  }

  rep(i,N){
    if (S[i] == T[i]){
      if (S[i] == '1') S_1.pop_front();
      continue;
    }
    else if(S[i] == '0'){
      if (S_1.empty()){
        cout << -1 << endl;
        return 0;
      }
      else{
        ans += S_1.front() - i;
        S[S_1.front()] = '0';
        S[i] = '1';
        S_1.pop_front();
      }
    }
    else if(S[i] == '1'){
      S_1.pop_front();
      if (S_1.empty()){
        cout << -1 << endl;
        return 0;
      }
      else{
        ans += S_1.front() - i;
        S[S_1.front()] = '0';
        S[i] = '0';
        S_1.pop_front(); // 二回popする
      }
    }
    // // デバッグ
    // rep(j,N){
    //   cout << S[j];
    // }
    // cout << endl;
    // cout << ans << endl;
    // rep(j,S_1.size()){
    //   cout << S_1[j] << " ";
    // }
    // cout << endl;
  }
  cout << ans << endl;
  return 0;
}
