/* -*- coding: utf-8 -*- * * 204.cc: No.204 ゴールデン・ウィーク(2) - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_D = 14; const char chs[] = {'x', 'o'}; /* typedef */ typedef vector vi; /* global variables */ /* subroutines */ /* main */ int main() { int d; string w0, w1; cin >> d >> w0 >> w1; string s = string(MAX_D, 'x') + w0 + w1 + string(MAX_D, 'x'); int n = s.size(); //cout << s << endl; vi ds[2]; int pc = 0, k = 0; for (int i = 0; i < n; i++) { if (chs[pc] == s[i]) k++; else { if (k > 0) ds[pc].push_back(k); pc ^= 1; k = 1; } } if (k > 0) ds[pc].push_back(k); int maxl = d, dn = ds[1].size(); for (int i = 0; i < dn; i++) { int l0 = min(ds[0][i], d) + ds[1][i]; if (maxl < l0) maxl = l0; int l1; if (ds[0][i + 1] > d) l1 = ds[1][i] + d; else { l1 = ds[1][i] + ds[0][i + 1]; if (i < dn - 1) l1 += ds[1][i + 1]; } if (maxl < l1) maxl = l1; } printf("%d\n", maxl); return 0; }