#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long MOD = 1000000007; int main() { int D; cin >> D; string S[2]; cin >> S[0] >> S[1]; int X[14*3] = {0}; for ( int i = 0; i < 7; i++ ) { if ( S[0][i] == 'o' ) { X[i+14] = 1; } if ( S[1][i] == 'o' ) { X[i+21] = 1; } } int ans = 0; for ( int i = 0; i+D < 14*3; i++ ) { int Y[14*3]; memcpy( Y, X, sizeof(Y) ); bool isOK = true; for ( int j = 0; j < D; j++ ) { if ( Y[i+j] == 0 ) { Y[i+j] = 1; } else { isOK = false; break; } } int a = 0; int m = 0; if ( isOK ) { for ( int j = 0; j < 14*3; j++ ) { if ( Y[j] ) { a++; m = max( m, a ); } else { a = 0; } } } ans = max( ans, m ); } cout << ans << endl; return 0; }