#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair P; const string weekly = "xxxxxxx"; int cnt[50]; int max_holiday (string s ){ memset (cnt, 0, sizeof (cnt ) ); cnt[0] = (s[0] == 'o' ); int n = s.length(); for (int i = 1; i < n; i++ ){ if (s[i] == 'o' ) cnt[i] = cnt[i-1] + 1; else cnt[i] = 0; } // end for int res = 0; rep (i, n ) res = max (res, cnt[i] ); return res; } /* OK! xxxxooooxxxx --oooooo---- NG! xxxxooooxxxx ---oooooo--- OK! ooooxxxxoooo ---oooooo--- NG! xxxxooooxoxx ---ooooooo-- ×が連続している部分は OK。 ×が離れて存在する部分は NG。 */ string replace (string s, string t, int p ){ string u = ""; u = s; rep (i, t.length() ){ if (u[p+i] == 'o' ) break; u[p+i] = t[i]; } // end rep return u; } int main() { ios_base::sync_with_stdio(0); int D; cin >> D; string c1; cin >> c1; string c2; cin >> c2; string s = ""; rep (i, 2 ) s += weekly; s += c1; s += c2; rep (i, 2 ) s += weekly; string t = ""; rep (i, D ) t += 'o'; int res = 0; rep (i, s.length() - t.length() + 1 ){ string u = replace (s, t, i ); int curr = max_holiday (u ); res = max (res, curr ); } // end rep // cerr << D << ' ' << s << endl; cout << res << endl; return 0; }