#include #include #include #include using namespace std; int n; string s; string t; int a[200000]; int b[200000]; int main() { int i; cin >> n >> s >> t; if (s[0] != t[0] || s[n - 1] != t[n - 1]) { cout << -1 << endl; return 0; } vector oneA; vector oneB; for (i = 0; i < n - 1; i++) { a[i] = (s[i + 1] != s[i]); b[i] = (t[i + 1] != t[i]); if (i % 2 == 1) { a[i] = !a[i]; b[i] = !b[i]; } if (a[i]) oneA.push_back(i); if (b[i]) oneB.push_back(i); } if (oneA.size() != oneB.size()) { cout << -1 << endl; return 0; } int hanten = 0; for (i = 0; i < oneA.size(); i++) { hanten += abs(oneB[i] - oneA[i]); } cout << hanten << endl; return 0; }