#include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, to) for (int x = 0; x < (to); x++) #define REP(x, a, to) for (int x = (a); x < (to); x++) #define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++) using namespace std; typedef long long ll; typedef pair PII; typedef pair PLL; string s, t, x; int tmp, d; int ans; vector vec; int main() { cin >> d; cin >> s; cin >> t; rep(i, d) x += 'x'; x += s; x += t; rep(i, d) x += 'x'; x += 'o'; //何でもいい //cout << x << endl; rep(i, x.size() - 1) { tmp++; if (x[i] != x[i+1]) { if (x[i] == 'o') { vec.push_back(tmp); } else { vec.push_back(-tmp); } tmp = 0; } } rep(i, vec.size()) { if (vec[i] < 0) { //両方にくっつけられる if (-vec[i] <= d) { int a = i-1>=0 ? abs(vec[i-1]) : 0; int b = i+1>=vec.size() ? 0 : abs(vec[i+1]); ans = max(ans, a - vec[i] + b); } else { //左右どっちかにくっつける int a = i-1>=0 ? abs(vec[i-1]) : 0; int b = i+1>=vec.size() ? 0 : abs(vec[i+1]); ans = max(ans, a + d); //左 ans = max(ans, b + d); //右 } } //cout << vec[i] << "-----" << ans << endl; } cout << ans << endl; return 0; }