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];
bool bad[N];
int was[N];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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], v[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{
                int k = 26;
                int len = L / k;
                int shit = L % k;
                vector < int > block;
                for(int i = 0; i < k; i++){
                        block.push_back(len);
                        if(shit){
                                block.back() += 1;
                                shit -= 1;
                        }
                }
                bad -= g[0].fi;
                for(int j = 0; j < L; j++){
                        res += char(g[0].se);
                }
                int i = 0;
                for(int len: block){
                        //[i, i + len)
                        for(int j = i; j < i + len; j++){
                                res[j] = g[1].se;
                        }
                        int gg = get(res);
                        for(int j = i; j < i + len; j++){
                                res[j] = g[0].se;
                        }
                        if(gg == bad){
                                i += len;
                                continue;
                        }
                        for(int j = 0; j < len; j++){
                                res[i] = g[1].se;
                                gg = get(res);
                                if(gg < bad){
                                        bad -= 1;
                                } else{
                                        res[i] = g[0].se;
                                }
                                i += 1;
                        }
                }
                bad[g[0].se] = bad[g[1].se] = 1;
        }

        vector < int > ord;
        for(int i = 0; i < v.size(); i++) if(c[i] && !bad[v[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++){
                                        was[V[j]] = res[V[j]];
                                        res[V[j]] = v[i];
                                }
                                int g = get(res);
                                for(int j = 0; j <= l; j++){
                                        res[V[j]] = was[V[j]];
                                }

                                if(g < bad || g > bad + 1){
                                        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:97:20: error: invalid types 'int[int]' for array subscript
   97 |                 bad[g[0].se] = bad[g[1].se] = 1;
      |                    ^
a.cc:97:35: error: invalid types 'int[int]' for array subscript
   97 |                 bad[g[0].se] = bad[g[1].se] = 1;
      |                                   ^
a.cc:101:58: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
  101 |         for(int i = 0; i < v.size(); i++) if(c[i] && !bad[v[i]]) ord.push_back(i);
      |                                                          ^