// 2020-11-28 21:00:40
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
// using namespace atcoder;

// clang-format on
void answer() {
  ll a, b, x, y;
  cin >> a >> b >> x >> y;
  ll ans = 0;
  if (a == b) {
    ans = x;
  } else if (a > b) {
    int d = a - b;
    if (x * 2 < y) {
      ans += x * (d - 1) * 2;
    } else {
      ans += y * (d - 1);
    }
    ans += x;
  } else if (a < b) {
    int d = b - a;
    if (x * 2 < y) {
      ans += x * d * 2;
    } else {
      ans += y * d;
    }
    ans += x;
  }
  cout << ans << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}
// Template
#include "bits/stdc++.h"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T> 
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
        os << vec[i] << (i + 1 == vec_len ? "" : " ");
    }
    return os;
}

// Main
int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    
    queue<int> qs, qt;
    rep(i, n) {
        if (s[i] == '1') qs.push(i);
        if (t[i] == '1') qt.push(i);
    }
    
    ll ans = 0;
    while (!qt.empty()) {
        int z = qt.front();
        if (qs.empty()) {
            cout << "-1\n";
            return 0;
        }
        int x = qs.front();
        if (x < z) {
            qs.pop();
            if (qs.empty()) {
                cout << "-1\n";
                return 0;
            }
            int y = qs.front();
            qs.pop();
            ans += y - x;
        } else {
            ans += x - z;
            qs.pop();
            qt.pop();
        }
    }
    while (!qs.empty()) {
        int x = qs.front();
        qs.pop();
        if (qs.empty()) {
            cout << "-1\n";
            return 0;
        }
        int y = qs.front();
        qs.pop();
        ans += y - x;
    }
    cout << ans << "\n";
}
