Language: C++

#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 5005;

using namespace std;

int get(string s)
{
        cout << "? " << s << endl;
        int x;
        cin >> x;
        return x;
}

vector < int > v;
int c[N];
bool good[N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(false);

        for(int i = 'a'; i <= 'z'; i++) v.push_back(i);
        for(int i = 'A'; i <= 'Z'; i++) v.push_back(i);
        for(int i = '0'; i <= '9'; i++) v.push_back(i);

        int L = 0;
        for(int i = 0; i < v.size(); i++){
                string s = "";
                for(int j = 0; j < 128; j++){
                        s += char(v[i]);
                }
                c[i] = 128 - get(s);
                L += c[i];
        }

        string res = "";
        vector < pair < int, int > > g;
        for(int i = 0; i < v.size(); i++) g.push_back({c[i], i});
        sort(g.begin(), g.end());
        int bad = L;
        if(g[0].fi == 0){
                for(int j = 0; j < L; j++){
                        res += char(g[0].se);
                }
        } else{
                while(true){
                        res = "";
                        for(int j = 0; j < L; j++){
                                if(rand() & 1){
                                        res += char(g[0].se);
                                } else{
                                        res += char(g[1].se);
                                }
                        }
                        if(get(res) == L){
                                break;
                        }
                }
        }

        vector < int > ord;
        for(int i = 0; i < v.size(); i++) if(c[i]) ord.push_back(i);

        for(int i: ord){
                while(c[i]--){
                        vector < int > V;
                        for(int j = 0; j < L; j++) if(!good[j]) V.push_back(j);

                        int l = -1;
                        for(int it = 8; it >= 0; it--){
                                if(l + (1 << it) >= V.size()){
                                        continue;
                                }
                                l += (1 << it);
                                for(int j = 0; j <= l; j++){
                                        res[V[j]] = v[i];
                                }
                                int g = get(res);
                                for(int j = 0; j <= l; j++){
                                        res[V[j]] = v[x];
                                }

                                if(g < bad){
                                        l -= (1 << it);
                                }
                        }
                        l += 1;
                        bad -= 1;
                        res[V[l]] = v[i];
                        good[V[l]] = 1;
                }
        }
        cout << "! " << res << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:87:55: error: 'x' was not declared in this scope
   87 |                                         res[V[j]] = v[x];
      |                                                       ^