Language: C++

#include <iostream>
#include <map>
#include <vector>
#include <cassert>
#include <unordered_set>
#include <set>
#include <bitset>
#include <memory.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;
 
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
 
const int MOD = (int) 1e9 + 7;
const int MAGIC = 400;
 
const bool DEBUG = false;
 
int n;
string w = "RBRBRB";
 
bool f(vector<int> a) {
    string ans = "";
 
    cout << "? " << a[0];
    for (int i = 1; i < a.size(); ++i)
        cout << " " << a[i];
    cout << endl;
 
    if (DEBUG) {
        int num[2] = {0, 0};
        for (int i : a)
            ++num[w[i - 1] == 'R'];
 
        if (num[1] > num[0])
            ans = "Red";
        else
            ans = "Blue";
    } else {
        cin >> ans;
    }
 
    return (ans == "Red");
}
 
mt19937_64 mt_rand(
    chrono::system_clock::now().time_since_epoch().count()
);

int main() {
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    srand(time(0));
 
    if (!DEBUG)
        cin >> n;
    else
        n = w.size() / 2;

    vector<int> pos(n * 2);
    for (int i = 0; i < n * 2; ++i)
        pos[i] = i + 1;

    for (int it = 0; it < rand() % 100; ++it)
        random_shuffle(pos.begin(), pos.end());
 
    vector<int> left;
    vector<int> right;
    for (int i = n; i >= 1; --i) {
        left.push_back(pos[i - 1]);
        right.push_back(pos[n + (n - i + 1) - 1]);
    }
 
    string ans = "";
    for (int i = 0; i < n * 2 + 1; ++i)
        ans += '?';
 
    bool cur = f(left);
 
    int id = -1;
    for (int i = 0; i < n; ++i) {
        swap(left[i], right[i]);
 
        if (f(left) != cur) {
            if (cur) {
                ans[left[i]] = 'B';
                ans[right[i]] = 'R';
            } else {
                ans[left[i]] = 'R';
                ans[right[i]] = 'B';
            }
 
            id = i;
 
            break;
        }
    }
 
    for (int i = 0; i < left.size(); ++i) {
        if (cur) {
            int temp = left[i];
            left[i] = right[id];
            ans[temp] = (f(left) ? 'B' : 'R');
            left[i] = temp;
        } else {
            int temp = left[i];
            left[i] = right[id];
            ans[temp] = (f(left) ? 'B' : 'R');
            left[i] = temp;
        }
    }
 
    swap(left, right);
    cur = !cur;
    for (int i = 0; i < left.size(); ++i) {
        if (cur) {
            int temp = left[i];
            left[i] = right[id];
            ans[temp] = (f(left) ? 'B' : 'R');
            left[i] = temp;
        } else {
            int temp = left[i];
            left[i] = right[id];
            ans[temp] = (f(left) ? 'B' : 'R');
            left[i] = temp;
        }
    }
 
    ans = ans.substr(1, n * 2);
    cout << "! " << ans << endl;
}


Compiler output:
a.cc:51:1: error: 'mt19937_64' does not name a type
   51 | mt19937_64 mt_rand(
      | ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:71:23: warning: 'void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]' is deprecated: use 'std::shuffle' instead [-Wdeprecated-declarations]
   71 |         random_shuffle(pos.begin(), pos.end());
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:9:
/usr/include/c++/14/bits/stl_algo.h:4492:5: note: declared here
 4492 |     random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~~~~~~~~~~~