Language: C++

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!p)
#define until(p) while(!p)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int counter;
void ask(std::string n){
    std::cout << "? " << n << std::endl;
    ++counter;
}

char answer(){
    char c;
    std::cin >> c;
    return c;
}

char findDigit(std::string s, int start, std::string suffix){
    int64_t lb = 9, ub = start - 1;

    while(std::abs(ub - lb) > 1){
        int64_t mid = (lb + ub) / 2;

        ask(s + (char)(mid + '0') + suffix);
        char ans = answer();
        if(ans == 'Y'){
            lb = mid;
        }else{
            ub = mid;
        }
    }

    return (char)(lb + '0');
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    std::string res = "";    
    bool two = false;
    
    while(res.size() < 9 || (res.size() == 9 && !two)){
        char d = findDigit(res, res.size() == 0 ? 1 : 0, std::string(max(0, 18 - 1 - res.size()), '9'));

        if(d > '0'){
            if(res.size() > 0){two = true;}
            res += d;
        }else{
            {
                ask(res + '9' + std::string(max(0, 18 - 1 - 1 - res.size()), '0'));;
                char ans = answer();
                if(ans == 'N'){
                    res += '0';
                    continue;
                }
            }
            {
                ask(res + "1");
                char ans = answer();
                if(ans == 'N'){
                    res += '0';
                    continue;
                }
            }
            {
                ask(std::string(res.size(), '9'));
                char ans = answer();
                if(ans == 'N'){
                    res += '0';
                }
                break;
            }
        }
    }

    // std::cout << "(res, two) = " << "(\"" << res << "\", " << two << ")" << std::endl;    
    
    std::cout << "! " << res << std::endl;
    // std::cout << "ask count: " << counter << std::endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:73: error: no matching function for call to 'max(int, std::__cxx11::basic_string<char>::size_type)'
   54 |         char d = findDigit(res, res.size() == 0 ? 1 : 0, std::string(max(0, 18 - 1 - res.size()), '9'));
      |                                                                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:54:73: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   54 |         char d = findDigit(res, res.size() == 0 ? 1 : 0, std::string(max(0, 18 - 1 - res.size()), '9'));
      |                                                                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:54:73: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   54 |         char d = findDigit(res, res.size() == 0 ? 1 : 0, std::string(max(0, 18 - 1 - res.size()), '9'));
      |                                                                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:61:48: error: no matching function for call to 'max(int, std::__cxx11::basic_string<char>::size_type)'
   61 |                 ask(res + '9' + std::string(max(0, 18 - 1 - 1 - res.size()), '0'));;
      |                                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:61:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   61 |                 ask(res + '9' + std::string(max(0, 18 - 1 - 1 - res.size()), '0'));;
      |                                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:61:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   61 |                 ask(res + '9' + std::string(max(0, 18 - 1 - 1 - res.size()), '0'));;
      |                                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~