#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include "combo.h"
using namespace std;
// constexpr int MAX_N = 2000;
// constexpr int MAX_NUM_MOVES = 8000;
// int N;
// string S;
// int num_moves;
// void wrong_answer(const char *MSG) {
//   printf("Wrong Answer: %s\n", MSG);
//   exit(0);
// }
// int press(std::string p) {
//   //cout<<p<<' ';
//   if (++num_moves > MAX_NUM_MOVES) {
//     wrong_answer("too many moves");
//   }
//   int len = p.length();
//   if (len > 4 * N) {
//     wrong_answer("invalid press");
//   }
//   for (int i = 0; i < len; ++i) {
//     if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
//       wrong_answer("invalid press");
//     }
//   }
//   int coins = 0;
//   for (int i = 0, j = 0; i < len; ++i) {
//     if (j < N && S[j] == p[i]) {
//       ++j;
//     } else if (S[0] == p[i]) {
//       j = 1;
//     } else {
//       j = 0;
//     }
//     coins = std::max(coins, j);
//   }
//   return coins;
// }
string guess_sequence(int N) {
  string s;
    vector <char> cr = {'A', 'B' , 'X' , 'Y'};
    string p = "AB";
    
    int c = press(p);
    if(c >= 1){
        c = press("A");
        if(c == 1)s+='A';
        else s += 'B';
    }
    else{
        c = press("Y");
        if(c == 1)s += 'Y';
        else s += 'X';
    }
    if (N==1)return s;
    //cout<<s<<endl;
    char fr;
    fr = s[0];
    string tem;
    for(char ch : cr){
        if(ch == fr)continue ;
        tem += ch;
    }
    //cout<<tem<<endl;
    int tmp=N-2;
    int cnt=1;
    while(tmp--){
        string e = s + tem[0]
                 + s + tem[1] + tem[0] 
                 + s + tem[1] + tem[1] 
                 + s + tem[1] + tem[2];
        //cout<<e<<endl;
        c = press(e);
        //cout<<s.size()<<endl;
        if(c == s.size() + 1){
            s += tem[0];
        }
        else if(c == s.size() + 2){
            s += tem[1];
        }
        else{
            s += tem[2];
        }
    }
    //cout<<s<<endl;
    string e = s + tem[0] + s + tem[1];
    int cc = press(e);
    if(cc == s.size()){
        //cout<<"DSFDSF";
        s += tem[2];
    }
    else{
      
        e = s + tem[0];
        cc = press(e);
        if(cc == s.size()){
            s += tem[1];
        }
        else{
            s += tem[0];
        }
    }
  return s;
}
// int main() {
//   char buffer[MAX_N + 1];
//   if (scanf("%s", buffer) != 1) {
//     fprintf(stderr, "Error while reading input\n");
//     exit(1);
//   }
//   S = buffer;
//   N = S.length();
//   num_moves = 0;
//   string answer = guess_sequence(N);
//   if (answer != S) {
//     wrong_answer("wrong guess");
//     exit(0);
//   }
//   printf("Accepted: %d\n", num_moves);
//   return 0;
// }
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |