#include #include #include #include #include #include #include using namespace std; template class y_combinator_result { Fun fun_; public: template explicit y_combinator_result(T &&fun): fun_(std::forward(fun)) {} template decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward(args)...); } }; template decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result>(std::forward(fun)); } typedef array state; const string GOAL = "NAC"; const string ALPHABET = "NACL"; // definitely not a chemistry reference state getnext(state s, char ch, int k) { auto [n, a, c] = s; if(ch == 'N') n++; else if(ch == 'A') a += n; else if(ch == 'C') c += a; return {min(n, k+1), min(a, k+1), min(c, k+1)}; } bool possible(state s, int k, int numleft) { for(int n = 0; n < numleft; n++) { for(int a = 0; n + a < numleft; a++) { int c = numleft-n-a; state curr = {s[0] + n, s[1], s[2]}; curr[1] += curr[0] * a; curr[2] += curr[1] * c; if(curr[2] >= k) return true; } } return false; } int main() { int n, k; string s; cin >> n >> k >> s; set> seen; auto dfs = y_combinator([&](auto self, string& ret, state curr) -> bool { int added = 0; while(ret.size() < n && s[ret.size()] != '?') { state ncurr = getnext(curr, s[ret.size()], k); ret += s[ret.size()]; curr = ncurr; added++; } array key = {curr[0], curr[1], curr[2], ret.size()}; if(curr[2] > k) { while(added--) ret.pop_back(); return false; } if(ret.size() == n) { if(curr[2] == k) return true; while(added--) ret.pop_back(); return false; } if(!possible(curr, k, n-ret.size())) { while(added--) ret.pop_back(); return false; } if(seen.count(key)) { while(added--) ret.pop_back(); return false; } seen.insert(key); for(auto out: ALPHABET) { state ncurr = getnext(curr, out, k); ret += out; if(self(ret, ncurr)) return true; ret.pop_back(); } while(added--) ret.pop_back(); return false; }); string ans = ""; state start = {0, 0, 0}; if(dfs(ans, start)) { cout << ans << "\n"; return 0; } cout << "-1\n"; }