#line 2 "/home/nok0/documents/programming/library/template/header.hpp" #include #line 3 "/home/nok0/documents/programming/library/template/def_const.hpp" const int inf = 1000000000; const long long INF = 1000000000000000000ll; #line 4 "/home/nok0/documents/programming/library/template/debug.hpp" namespace viewer { void view(const long long &e) { if(e == INF) std::cerr << "INF"; else if(e == -INF) std::cerr << "-INF"; else std::cerr << e; } void view(const int &e) { if(e == inf) std::cerr << "inf"; else if(e == -inf) std::cerr << "-inf"; else std::cerr << e; } template void view(const T &e) { std::cerr << e; } template void view(const std::pair &p) { std::cerr << "("; view(p.first); std::cerr << ", "; view(p.second); std::cerr << ")"; } template void view(const std::tuple &p) { std::cerr << "("; view(std::get<0>(p)); std::cerr << ", "; view(std::get<1>(p)); std::cerr << ", "; view(std::get<2>(p)); std::cerr << ")"; } template void view(const std::tuple &p) { std::cerr << "("; view(std::get<0>(p)); std::cerr << ", "; view(std::get<1>(p)); std::cerr << ", "; view(std::get<2>(p)); std::cerr << ", "; view(std::get<3>(p)); std::cerr << ")"; } template void view(const std::set &s) { if(s.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(auto &t : s) { view(t); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::unordered_set &s) { if(s.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(auto &t : s) { view(t); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::multiset &s) { if(s.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(auto &t : s) { view(t); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::unordered_multiset &s) { if(s.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(auto &t : s) { view(t); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::vector &v) { if(v.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(const auto &e : v) { view(e); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::array &v) { if(v.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(const auto &e : v) { view(e); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::vector> &vv) { std::cerr << "{\n"; for(const auto &v : vv) { std::cerr << "\t"; view(v); std::cerr << '\n'; } std::cerr << "}"; } template void view(const std::vector> &v) { std::cerr << "{\n"; for(const auto &c : v) { std::cerr << "\t("; view(c.first); std::cerr << ", "; view(c.second); std::cerr << ")\n"; } std::cerr << "}"; } template void view(const std::vector> &v) { if(v.empty()) { std::cerr << "{ }"; return; } std::cerr << '{'; for(const auto &t : v) { std::cerr << "\n\t"; view(t); std::cerr << ","; } std::cerr << "\n}"; } template void view(const std::vector> &v) { if(v.empty()) { std::cerr << "{ }"; return; } std::cerr << '{'; for(const auto &t : v) { std::cerr << "\n\t"; view(t); std::cerr << ","; } std::cerr << "\n}"; } template void view(const std::map &m) { std::cerr << "{\n"; for(const auto &t : m) { std::cerr << "\t["; view(t.first); std::cerr << "] : "; view(t.second); std::cerr << '\n'; } std::cerr << "}"; } template void view(const std::unordered_map &m) { std::cerr << "{\n"; for(const auto &t : m) { std::cerr << "\t["; view(t.first); std::cerr << "] : "; view(t.second); std::cerr << '\n'; } std::cerr << "}"; } } // namespace viewer // when compiling : g++ foo.cpp -DLOCAL #ifdef LOCAL void debug_out() {} template void debug_out(Head H, Tail... T) { viewer::view(H); std::cerr << ", "; debug_out(T...); } #define debug(...) \ do { \ std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \ debug_out(__VA_ARGS__); \ std::cerr << "\b\b]\n"; \ } while(0) #define dump(x) \ do { \ std::cerr << __LINE__ << " " << #x << " : "; \ viewer::view(x); \ std::cerr << '\n'; \ } while(0) #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif #line 3 "/home/nok0/documents/programming/library/template/def_name.hpp" #define pb push_back #define eb emplace_back #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define popcnt(x) __builtin_popcountll(x) template using V = std::vector; template using VV = std::vector>; template using pqup = std::priority_queue, std::greater>; using ll = long long; using ld = long double; using int128 = __int128_t; using pii = std::pair; using pll = std::pair; #line 3 "/home/nok0/documents/programming/library/template/fast_io.hpp" struct fast_io { fast_io() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); } } fast_io_; #line 3 "/home/nok0/documents/programming/library/template/input.hpp" template std::istream &operator>>(std::istream &is, std::pair &p) { is >> p.first >> p.second; return is; } template std::istream &operator>>(std::istream &is, std::vector &v) { for(T &i : v) is >> i; return is; } std::istream &operator>>(std::istream &is, __int128_t &a) { std::string s; is >> s; __int128_t ret = 0; for(int i = 0; i < (int)s.length(); i++) if('0' <= s[i] and s[i] <= '9') ret = 10 * ret + s[i] - '0'; a = ret * (s[0] == '-' ? -1 : 1); return is; } namespace scanner { void scan(int &a) { std::cin >> a; } void scan(long long &a) { std::cin >> a; } void scan(std::string &a) { std::cin >> a; } void scan(char &a) { std::cin >> a; } void scan(char a[]) { std::scanf("%s", a); } void scan(double &a) { std::cin >> a; } void scan(long double &a) { std::cin >> a; } template void scan(std::pair &p) { std::cin >> p; } template void scan(std::vector &a) { std::cin >> a; } void INPUT() {} template void INPUT(Head &head, Tail &...tail) { scan(head); INPUT(tail...); } } // namespace scanner #define VEC(type, name, size) \ std::vector name(size); \ scanner::INPUT(name) #define VVEC(type, name, h, w) \ std::vector> name(h, std::vector(w)); \ scanner::INPUT(name) #define INT(...) \ int __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define LL(...) \ long long __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define STR(...) \ std::string __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define DOUBLE(...) \ double __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define LD(...) \ long double __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #line 3 "/home/nok0/documents/programming/library/template/math.hpp" template inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; } template inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; } template T divup(T x, T y) { return (x + y - 1) / y; } template T POW(T a, long long n) { T ret = 1; while(n) { if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; } long long POW(long long a, long long n, const int mod) { long long ret = 1; a = (a % mod + mod) % mod; while(n) { if(n & 1) (ret *= a) %= mod; (a *= a) %= mod; n >>= 1; } return ret; } template T bin_search(T ok, T ng, const F &f) { while(abs(ok - ng) > 1) { T mid = (ok + ng) >> 1; (f(mid) ? ok : ng) = mid; } return ok; } template T bin_search(T ok, T ng, const F &f, int loop) { for(int i = 0; i < loop; i++) { T mid = (ok + ng) / 2; (f(mid) ? ok : ng) = mid; } return ok; } #line 3 "/home/nok0/documents/programming/library/template/output.hpp" template std::ostream &operator<<(std::ostream &os, const std::pair &p) { os << p.first << " " << p.second; return os; } template std::ostream &operator<<(std::ostream &os, const std::vector &a) { for(int i = 0; i < int(a.size()); ++i) { if(i) os << " "; os << a[i]; } return os; } std::ostream &operator<<(std::ostream &dest, __int128_t &value) { std::ostream::sentry s(dest); if(s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while(tmp != 0); if(value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if(dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } template void print(const T a) { std::cout << a << '\n'; } template void print(Head H, Tail... T) { std::cout << H << ' '; print(T...); } template void printel(const T a) { std::cout << a << '\n'; } template void printel(const std::vector &a) { for(const auto &v : a) std::cout << v << '\n'; } template void printel(Head H, Tail... T) { std::cout << H << '\n'; printel(T...); } void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); } void No() { std::cout << "No\n"; } void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); } void NO() { std::cout << "NO\n"; } #line 2 "/home/nok0/documents/programming/library/template/rep.hpp" #define foa(v, a) for(auto &v : a) #define repname(a, b, c, d, e, ...) e #define rep(...) repname(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__) #define rep0(x) for(int rep_counter = 0; rep_counter < (x); ++rep_counter) #define rep1(i, x) for(int i = 0; i < (x); ++i) #define rep2(i, l, r) for(int i = (l); i < (r); ++i) #define rep3(i, l, r, c) for(int i = (l); i < (r); i += (c)) #define repsname(a, b, c, ...) c #define reps(...) repsname(__VA_ARGS__, reps1, reps0)(__VA_ARGS__) #define reps0(x) for(int reps_counter = 1; reps_counter <= (x); ++reps_counter) #define reps1(i, x) for(int i = 1; i <= (x); ++i) #define rrepname(a, b, c, ...) c #define rrep(...) rrepname(__VA_ARGS__, rrep1, rrep0)(__VA_ARGS__) #define rrep0(x) for(int rrep_counter = (x)-1; rrep_counter >= 0; --rrep_counter) #define rrep1(i, x) for(int i = (x)-1; i >= 0; --i) #line 3 "/home/nok0/documents/programming/library/template/vector.hpp" template int lb(const std::vector &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); } template int ub(const std::vector &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); } template void UNIQUE(std::vector &a) { std::sort(a.begin(), a.end()); a.erase(std::unique(a.begin(), a.end()), a.end()); } template std::vector press(std::vector &a) { auto res = a; UNIQUE(res); for(auto &v : a) v = lb(res, v); return res; } #define SORTname(a, b, c, ...) c #define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__) #define SORT0(a) std::sort((a).begin(), (a).end()) #define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; }) template void ADD(std::vector &a, const T x = 1) { for(auto &v : a) v += x; } template void SUB(std::vector &a, const T x = 1) { for(auto &v : a) v -= x; } template struct cum_vector { public: cum_vector() = default; template cum_vector(const std::vector &vec) : cum((int)vec.size() + 1) { for(int i = 0; i < (int)vec.size(); i++) cum[i + 1] = cum[i] + vec[i]; } T prod(int l, int r) { return cum[r] - cum[l]; } private: std::vector cum; }; std::vector> rle(const std::string &s) { const int n = s.size(); std::vector> ret; for(int l = 0; l < n;) { int r = l + 1; for(; r < n and s[l] == s[r]; r++) {} ret.emplace_back(s[l], r - l); l = r; } return ret; } template std::vector> rle(const std::vector &v) { int n = v.size(); std::vector> ret; for(int l = 0; l < n;) { int r = l + 1; for(; r < n and v[l] == v[r]; r++) {} ret.emplace_back(v[l], r - l); l = r; } return ret; } std::vector iota(int n) { std::vector p(n); std::iota(p.begin(), p.end(), 0); return p; } #line 11 "/home/nok0/documents/programming/library/template/all" using namespace std; #line 2 "a.cpp" void main_(); int main() { int t = 1; while(t--) main_(); } void main_() { INT(n, a, b); STR(s); //ブロックの個数 高々 1e4 dp が出来ないか?攻めすぎな気もするけど。。 V<> bs; rep(i, n - 2) { int tmp = 0; while(s.substr(i, 3) == "con") { tmp++; i += 3; } if(tmp) bs.pb(tmp); } n = SZ(bs); const int m = 10000; vector dp(m, -inf); dp[0] = 0; rep(i, n) { vector ndp(m, -inf); rep(k, m) { if(dp[k] == -inf) break; for(int d = 0, j = 0; j <= bs[i] and k + d < m; d++, j += a) { chmax(ndp[k + d], dp[k] + (bs[i] - j) / b); } } dp = move(ndp); } int res = 0; rep(j, m) { if(dp[j] < 0) break; if(j > dp[j]) chmax(res, dp[j] * 2 + 1); else chmax(res, j * 2); } print(res); }