Language: C++

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
int Q(string &s){
    cout << "? " << s << endl;
    int k;
    cin >> k;
    return k;
}
void answer(string &s){
    cout << "! " << s << endl;
}
int len;
string concat(string &s,string &t){
    char c = s[0];
    bool flag = 1;
    for(int i=0;i<s.size();i++){
        if(s[i]!=c)flag = 0;
    }
    for(int i=0;i<t.size();i++){
        if(t[i]!=c)flag = 0;
    }
    if(flag){
        return s+t;
    }
    string res = t;
    int n = s.size();
    int id = 0;
    int cur = t.size();
    rep(i,n){
        if(flag)break;
        while(1){
            if(id>=cur){
                flag = 1;
                for(int j=i;j<n;j++){
                    res.push_back(s[j]);
                }
                break;
            }
            string tmp;
            for(int j=0;j<id;j++){
                tmp.push_back(res[j]);
            }
            tmp.push_back(s[i]);
            for(int j=id;j<cur;j++){
                tmp.push_back(res[j]);
            }
            int k = Q(tmp);
            if(k == len-cur-1){
                cur++;
                res = tmp;
                id++;
                break;
            }else{
                while(id<cur&&s[i]==t[id]){
                    id++;
                }
                id++;
            }
        }
    }
    return res;
}


char c[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'};
int main(){
    int n = 5;
    int L = 128;
    vector<char> t;
    int mi = inf;
    rep(i,n){
        string s;
        s.push_back(c[i]);
        int k = Q(s);
        if(mi==k){
            t.push_back(c[i]);
        }else if(mi>k){
            mi = k;
            t.clear();
            t.push_back(c[i]);
        }
    }   
    len = mi + 1; 
    vector<int> cnt;
    n = t.size();
    rep(i,n){
        string s;
        s.push_back(t[i]);
        int k = 1;
        for(int j=2;j<=L;j++){
            s.push_back(t[i]);
            int p = Q(s);
            if(len-k>p){
                k++;
            }else{
                break;
            }
        }
        cnt.push_back(k);
    }
    // rep(i,n){
    //     cout << t[i] << " " << cnt[i] << endl;
    // }
    int m = len;
    vector<string> a(n);
    int sss = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<cnt[i];j++){
            a[i].push_back(t[i]);
        }
    }
    priority_queue<pair<int,string>,vector<pair<int,string>>,greater<pair<int,string>> > pq;
    rep(i,n){
        pq.push(MP(a[i].size(),a[i]));
    }
    while(pq.size()>1){
        auto x = pq.top();
        pq.pop();
        auto y = pq.top();
        pq.pop();
        string s = concat(x.second,y.second);
        pq.push(MP(s.size(),s));
    }
    answer(pq.top().second);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:175:21: error: binding reference of type 'std::string&' {aka 'std::__cxx11::basic_string<char>&'} to 'const std::__cxx11::basic_string<char>' discards qualifiers
  175 |     answer(pq.top().second);
      |            ~~~~~~~~~^~~~~~
a.cc:60:21: note:   initializing argument 1 of 'void answer(std::string&)'
   60 | void answer(string &s){
      |             ~~~~~~~~^