#include #include #include #include using namespace std; int main(){ int N, A, B; cin >> N >> A >> B; string S; cin >> S; vector rle(0); int concnt = 0; int now_idx = 0; while(true){ if (now_idx >= N - 2){ if (concnt >= 1){ rle.push_back(concnt); } break; } else if (S.substr(now_idx, 3) == "con"){ now_idx += 3; concnt++; } else{ now_idx++; if (concnt >= 1){ rle.push_back(concnt); } concnt = 0; } } int len = rle.size(); int INF = N / 3 + 1; int MAX_J = N / 6 + 1; vector divA(INF); for (int i = 0; i < INF; i++){ divA[i] = i / A; } vector divB(INF); for (int i = 0; i < INF; i++){ divB[i] = i / B; } vector dp1(MAX_J, -INF); vector dp2(MAX_J, -INF); dp1[0] = 0; int count = 0; for (int i = 0; i < len; i++){ count += divA[rle[i]]; for (int j = 0; j <= count; j++){ for (int k = 0; k <= divA[rle[i]]; k++){ if (j + k >= MAX_J) continue; dp2[j + k] = max(dp2[j + k], dp1[j] + divB[rle[i] - A * k]); } } for (int j = 0; j < MAX_J; j++){ dp1[j] = dp2[j]; dp2[j] = -INF; } } int ans = 0; for (int j = 0; j < MAX_J; j++){ if (dp1[j] >= j - 1) ans = max(ans, 2 * j - 1); if (dp1[j] >= j) ans = max(ans, 2 * j); } cout << ans << endl; }