At the Bacteria And Protein Centre, you own a large collection of DNA. In fact, new strands of DNA come in all the time. To organise the vast amount of data, you identify each piece by its unique substrings: substrings that do not already occur in the database.

Your database can quickly determine whether a given piece of DNA occurs as a substring in the database or not. Naturally, if a certain DNA string is found in the database, it also contains all its substrings.

![](images/42ca1e80023c37d2cb76250f86ff30b6c4a748396bbe9a006665e860d0632c9f.jpg)
CC BY-NC-SA 2.0 by Argonne National Laboratory on Flickr

You now want to determine the uniqueness of a given piece of DNA: the maximal number of disjoint substrings it contains that are absent from the database.

You are given the length $n$ of the query string $q _ { 1 } \ldots q _ { n }$ , and you can repeatedly ask the database whether it contains the substring $q _ { i } \ldots q _ { j - 1 }$ .

As an example, consider the first sample interaction. In this case, the database contains strings “TGC” and “CT”, and the query string is “CTGCAA”. It has uniqueness 3, because it can be split into the new substrings “CTGC”, “A”, and “A”. The new substring “CTGC” cannot be split up further: for example, the subdivision “CT” and “ $\mathrm { G C }$ ” is not allowed, because both substrings occur (possibly as substrings) in the database. Note that the actual characters in the string are not used in the interaction.

You may use at most $2 n$ queries to the database.

# Interaction

This is an interactive problem. Your submission will be run against an interactor, which reads from the standard output of your submission and writes to the standard input of your submission. This interaction needs to follow a specific protocol:

The interactor first sends one line with an integer $n$ ( $1 \leq n \leq 1 0 0 0 0$ ), the length of the DNA piece for which you need to compute the uniqueness.

Then, your program should make at most $2 n$ queries. Each query is made by printing one line of the form “? i $j ^ { \flat }$ ( $0 \leq i < j \leq n$ ), indicating that you want to query whether the substring starting at position $i$ and ending at position $j - 1$ occurs in the database. The interactor will respond with either “present” or “absent”, indicating whether the substring was found in the database.

When you have determined the uniqueness $x$ of the piece of DNA, print one line of the form “! $x$ ”, after which the interaction will stop. Printing the answer does not count as a query.

Make sure you flush the buffer after each write.

A testing tool is provided to help you develop your solution.

Using more than $2 n$ queries will result in a wrong answer.

![](images/4f1df1d40797a152a234c34e3b8266b1fdc7150ff42c84e1cba9aed3fa4ce22b.jpg)

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int solve_ground_truth(int n, const vector<int>& m) {

    vector<pair<int, int>> intervals;
    intervals.reserve(n);
    for (int i = 0; i < n; i++) {
        int len = m[i] + 1;
        int end = i + len;
        if (end <= n) {
            intervals.push_back({i, end});
        }
    }

    sort(intervals.begin(), intervals.end(), [](const pair<int,int>& a, const pair<int,int>& b){
        if (a.second != b.second) return a.second < b.second;
        return a.first < b.first;
    });

    int count = 0;
    int last_end = 0;
    for (const auto& p : intervals) {
        if (p.first >= last_end) {
            count++;
            last_end = p.second;
        }
    }
    return count;
}

int main(int argc, char** argv) {

    registerInteraction(argc, argv);
    atexit(log_metrics);

    int n = inf.readInt();
    vector<int> m(n);
    for (int i = 0; i < n; i++) {
        m[i] = inf.readInt();
    }

    query_limit = 2LL * n;
    long long hard_cap = max(200000LL, 10 * query_limit);

    cout << n << endl;
    log_metrics();

    while (true) {

        if (queries > hard_cap) {
            finish(_pe, "Hard query limit exceeded (potential infinite loop)");
        }

        string token;
        if (!(cin >> token)) {
            finish(_pe, "Unexpected EOF (did not receive answer)");
        }

        if (token == "!") {

            int user_ans;
            if (!(cin >> user_ans)) {
                finish(_pe, "Expected integer after '!'");
            }

            int correct_ans = solve_ground_truth(n, m);
            if (user_ans == correct_ans) {
                finish(_ok, "Correct answer " + to_string(user_ans));
            } else {
                finish(_wa, "Wrong answer. Expected " + to_string(correct_ans) + ", found " + to_string(user_ans));
            }
        } else {

            int i, j;
            if (token == "?") {
                if (!(cin >> i >> j)) {
                    finish(_pe, "Invalid query format after '?'");
                }
            } else {
                try {
                    i = stoi(token);
                } catch (...) {
                    finish(_pe, "Invalid token '" + token + "' (expected integer, '?' or '!')");
                }
                if (!(cin >> j)) {
                    finish(_pe, "Invalid query format (expected j)");
                }
            }

            if (i < 0 || i >= n || j <= i || j > n) {
                finish(_pe, "Invalid query indices i=" + to_string(i) + ", j=" + to_string(j) + " (N=" + to_string(n) + ")");
            }

            queries++;
            if (queries % 100 == 0) log_metrics();

            int len = j - i;
            if (len <= m[i]) {
                cout << "present" << endl;
            } else {
                cout << "absent" << endl;
            }
        }
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long queries = 0;
static long long query_limit = 0;
static bool finished = false;

static void log_metrics() {
    if (finished) return;
    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    finished = true;
    quitf(verdict, "%s", msg.c_str());
}

static int n;
static vector<int> L, R;

void propagate() {
    bool changed = true;
    while (changed) {
        changed = false;

        for (int i = 0; i < n - 1; i++) {
            if (L[i+1] < L[i] - 1) {
                L[i+1] = L[i] - 1;
                changed = true;
            }
        }

        for (int i = n - 2; i >= 0; i--) {
            if (R[i] > R[i+1] + 1) {
                R[i] = R[i+1] + 1;
                changed = true;
            }
        }

        for(int i=0; i<n; i++) {
            if (L[i] > R[i]) L[i] = R[i];

        }
    }
}

int calc_uniqueness(const vector<int>& M) {
    vector<pair<int, int>> intervals;
    for (int i = 0; i < n; i++) {

        if (M[i] < n - i) {
            int start = i;
            int end = i + M[i] + 1;

            if (end <= n) {
                intervals.push_back({end, start});
            }
        }
    }

    sort(intervals.begin(), intervals.end());

    int count = 0;
    int last_end = 0;
    for (auto& p : intervals) {
        if (p.second >= last_end) {
            count++;
            last_end = p.first;
        }
    }
    return count;
}

int main(int argc, char** argv) {

    registerInteraction(argc, argv);
    atexit(log_metrics);

    n = inf.readInt(1, 10000, "n");

    query_limit = 2LL * n;

    cout << n << endl;

    L.resize(n, 0);
    R.resize(n);
    for (int i = 0; i < n; i++) R[i] = n - i;

    int hard_cap = max(20000, 10 * (int)query_limit);

    while (true) {
        string type;
        if (!(cin >> type)) {
            finish(_pe, "Unexpected EOF (contestant output ended)");
        }

        if (type == "!") {
            int ans;
            if (!(cin >> ans)) finish(_pe, "Expected integer after '!'");

            propagate();

            int u_max = calc_uniqueness(L);
            int u_min = calc_uniqueness(R);

            if (u_min == u_max) {
                if (ans == u_min) {
                    finish(_ok, "Correct uniqueness " + to_string(ans));
                } else {
                    finish(_wa, "Wrong answer. Expected " + to_string(u_min) + ", found " + to_string(ans));
                }
            } else {

                if (ans < u_min || ans > u_max) {
                    finish(_wa, "Answer " + to_string(ans) + " not in feasible range [" + to_string(u_min) + ", " + to_string(u_max) + "]");
                } else {
                    finish(_wa, "Ambiguous result. Uniqueness could be " + to_string(u_min) + " or " + to_string(u_max));
                }
            }
            break;
        }
        else if (type == "?" || (type.size() > 0 && type[0] == '?')) {
            int i, j;

            if (type == "?") {
                if (!(cin >> i >> j)) finish(_pe, "Invalid query format");
            } else {
                finish(_pe, "Query token must be '?'");
            }

            queries++;

            if (queries > hard_cap) finish(_pe, "Hard query limit exceeded");

            if (i < 0 || i >= n || j <= i || j > n) {
                finish(_pe, "Query indices out of bounds");
            }

            int len = j - i;

            bool can_present = (R[i] >= len);
            bool can_absent = (L[i] < len);

            bool reply_present = false;

            if (!can_present && !can_absent) {
                finish(_wa, "Internal Error: Inconsistent state");
            } else if (can_present && !can_absent) {
                reply_present = true;
            } else if (!can_present && can_absent) {
                reply_present = false;
            } else {

                int mid = L[i] + (R[i] - L[i]) / 2;
                if (len <= mid) reply_present = true;
                else reply_present = false;
            }

            if (reply_present) {
                cout << "present" << endl;
                L[i] = max(L[i], len);
            } else {
                cout << "absent" << endl;
                R[i] = min(R[i], len - 1);
            }

            propagate();

            if (queries % 1000 == 0) log_metrics();

        } else {
            finish(_pe, "Unknown token '" + type + "'");
        }
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> generate_M(int n, int type) {
    vector<int> m(n);
    if (type == 0) {
        fill(m.begin(), m.end(), 0);
    } else if (type == 1) {
        for (int i = 0; i < n; i++) m[i] = n - i;
    } else if (type == 2) {
        m[0] = rnd.next(0, n);
        for (int i = 0; i < n - 1; i++) {
            int low = max(0, m[i] - 1);
            int high = n - (i + 1);
            m[i+1] = rnd.next(low, high);
        }
    } else if (type == 3) {
        m[0] = rnd.next(0, n);
        for (int i = 0; i < n - 1; i++) {
            int low = max(0, m[i] - 1);
            int high = n - (i + 1);

            if (rnd.next(5) == 0) {
                m[i+1] = rnd.next(low, high);
            } else {
                m[i+1] = low;
            }
        }
    }
    return m;
}

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");
    int n_arg = opt<int>("n", -1);

    long long seed_val = 0;
    if (argc > 1) seed_val = atoll(argv[1]);

    int n = n_arg;
    if (n == -1) {
        if (seed_val >= 1 && seed_val <= 5) n = 10;
        else if (seed_val >= 6 && seed_val <= 10) n = 100;
        else n = rnd.next(100, 10000);
    }

    if (mode == "adp") {
        cout << n << endl;
        cout << -1 << endl;
        return 0;
    }

    cout << n << endl;

    vector<int> m;
    if (seed_val == 1) {
        m = generate_M(n, 0);
    } else if (seed_val == 2) {
        m = generate_M(n, 1);
    } else if (seed_val == 3) {
        m.resize(n);
        for(int i=0; i<n; i++) m[i] = (i % 2 == 0) ? 0 : 1;
    } else {

        int type = (rnd.next(3) == 0) ? 2 : 3;
        m = generate_M(n, type);
    }

    for (int i = 0; i < n; i++) {
        cout << m[i] << (i == n - 1 ? "" : " ");
    }
    cout << endl;

    return 0;
}


# This is an interactive problem.

Alice and Bob are playing the following game. The game is specified by a parameter $t \in \{ 0 , 1 \}$ and is described as follows:

There are $n$ integers $a _ { 1 } , a _ { 2 } , \ldots , a _ { n } \in \{ 0 , 1 \}$ , arranged in a line. The two players take turns to perform the following operation when at least two integers are remaining, starting from Alice:

• Choose two integers $x$ and $y$ that are adjacent, replace them with either $x + y$ or $x \times y$ (arithmetic addition or arithmetic multiplication).

The game ends when there is only one integer remaining, and the result of the game is judged by the parity of the remaining integer and the parameter $t$ as follows:

• $t = 0$ : Alice wins if the remaining integer is even and Bob wins otherwise.
• $t = 1$ : Alice wins if the remaining integer is odd and Bob wins otherwise.

You are given the initial $n$ integers $a _ { 1 } , a _ { 2 } , \ldots , a _ { n }$ and the parameter $t$ . You must choose to play as Alice or Bob, then play this game against the interactor who takes the opponent’s role. Your goal is to win the game.

# Input

The first line of input contains two integers $n$ and $t$ ( $2 \leq n \leq 5 0 0 , t \in \{ 0 , 1 \}$ ), denoting the size of the array and the parameter of the game.

The second line of input contains $n$ integers $a _ { 1 } , a _ { 2 } , \ldots , a _ { n }$ ( $0 \leq a _ { i } \leq 1$ ), denoting the array.

# Interaction Protocol

The interaction begins after reading the two integers $n , t$ and the array $\{ a _ { i } \} _ { 1 \leq i \leq n }$

You should start interaction by printing a single line containing either “Alice” or “Bob”, representing the player you choose to play as. If you choose to play Alice, you are the first to operate. Otherwise, you are the second to operate.

The game proceeds as follows:

• If it’s your turn to operate. Suppose the current array is $b _ { 1 } , b _ { 2 } , \dots , b _ { m }$ with length $m$ $2 \leq m \leq n$ ), you should output an integer $p$ ( $1 \leq p \leq m - 1 _ { \cdot }$ ) and a character $c$ $( c \in \{ { ^ { \circ } } + , { ^ { \circ } } { * } ^ { \prime } \} )$ in a line, separated by a space, denoting you choose to merge the two integers $b _ { p }$ and $b _ { p + 1 }$ with the operation denoted by $c$ . After your operation, the array becomes $b _ { 1 } , b _ { 2 } , \dotsc , b _ { p - 1 } , ( b _ { p } \ c b _ { p + 1 } ) , b _ { p + 2 } , \dotsc , b _ { m }$ with length $m - 1$ .
• If it’s the opponent’s turn to operate. Suppose the current array is $b _ { 1 } , b _ { 2 } , \dots , b _ { m }$ with length $m$ ( $2 \leq m \leq n$ ), you should read an integer $p$ ( $0 \leq p \leq m - 1$ ) and a character $c$ $( c \in \{ { ^ { \circ } } + , { ^ { \circ } } { * } ^ { \prime } \} )$ in a line, denoting the opponent chooses to merge the two integers $b _ { p }$ and $b _ { p + 1 }$ with the operation denoted by $c$ . After the opponent’s operation, the array becomes $b _ { 1 } , b _ { 2 } , \dotsc , b _ { p - 1 } , ( b _ { p } \ c b _ { p + 1 } ) , b _ { p + 2 } , \dotsc , b _ { m }$ with length $m - 1$ . Here, if the integer $p$ is $0$ , then it means the last operation you perform is incorrect. In that case, your program should terminate immediately to receive a “Wrong Answer” verdict, or you could get any possible verdict.

When there is only one integer in the array, the game finishes and is judged according to the rule in the statement. If you win the game, your program will be considered correct for this test case. If you lose the game, or it is you to perform the last operation and your last operation is invalid, you will receive a “Wrong Answer” verdict. You should terminate the program immediately when the game finishes.

After printing the player you choose to play as and the operation you perform, do not forget to output the end of the line and flush the output. Otherwise, you may not get the correct verdict. To flush the output, use:

• fflush(stdout) or cout.flush() in C++;
• System.out.flush() in Java;
• stdout.flush() in Python;

# Example

standard input	standard output

41

0101

	Alice

2*	1+

# Note

Note that additional empty lines in the sample test are for better understanding, and you should not output any additional empty lines in your program.

Here, we provide graphical illustrations of the interaction in the sample test. For the given $\{ a _ { i } \} _ { 1 \leq i \leq n }$ and $t$ , it is optimal for the player to choose to play Alice and go first.

![](images/5157783eb7691df2ae5941895ccd7e4bc2b4071573a2eeb310367e5b9525e3b3.jpg)

In the sample interaction, the player chooses to merge the first two numbers with the addition operator,

![](images/f66242b22245916fcb8e663bd932cf836d02261ca92b7b0ec4a16e7dc6b0af56.jpg)

and the opponent chooses to merge the last two numbers with the multiplication operator.

![](images/469c959e130ed6733141393c272803177f52e6b4db81c84daf415dbbf545e3b4.jpg)

Then, the player chooses to merge the remaining two numbers with the addition operator and wins the game.

![](images/28d447e6df73f0b9678036d596d4ccfb11656ced0124731dbdd427cbc13d21ad.jpg)

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {

        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int apply_op(int x, int y, char op) {
    if (op == '+') return (x + y) % 2;
    if (op == '*') return (x * y) % 2;
    return -1;
}

int main(int argc, char* argv[]) {

    registerInteraction(argc, argv);
    atexit(log_metrics);

    int n = inf.readInt();
    int t = inf.readInt();
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        a[i] = inf.readInt();
    }

    query_limit = n;

    tout << "queries=" << queries << endl;
    tout << "query_limit=" << query_limit << endl;

    cout << n << " " << t << endl;
    for (int i = 0; i < n; ++i) {
        cout << a[i] << (i == n - 1 ? "" : " ");
    }
    cout << endl;

    string role_token;
    if (!(cin >> role_token)) {
        finish(_pe, "Failed to read role (EOF)");
    }

    bool user_is_alice = false;
    if (role_token == "Alice") user_is_alice = true;
    else if (role_token == "Bob") user_is_alice = false;
    else finish(_wa, "Invalid role '" + role_token + "'. Expected 'Alice' or 'Bob'");

    int interactor_target = -1;
    if (user_is_alice) {

        interactor_target = 1 - t;
    } else {

        interactor_target = t;
    }

    for (int step = 0; step < n - 1; ++step) {
        bool is_alice_turn = (step % 2 == 0);
        bool is_user_turn = (user_is_alice == is_alice_turn);

        if (is_user_turn) {

            string p_str;
            if (!(cin >> p_str)) {
                finish(_pe, "Expected user move (p), got EOF");
            }

            int p = -1;
            try {
                size_t idx;
                p = stoi(p_str, &idx);
                if (idx != p_str.size()) finish(_pe, "Token p is not a valid integer");
            } catch (...) {
                finish(_pe, "Token p is not a valid integer");
            }

            char c;
            if (!(cin >> c)) {
                finish(_pe, "Expected user move (c), got EOF");
            }

            if (p < 1 || p >= (int)a.size()) {
                finish(_wa, format("Invalid index p=%d. Must be in [1, %d]", p, (int)a.size() - 1));
            }
            if (c != '+' && c != '*') {
                finish(_wa, format("Invalid operator c='%c'. Must be '+' or '*'", c));
            }

            int idx = p - 1;
            int val = apply_op(a[idx], a[idx+1], c);

            a[idx] = val;
            a.erase(a.begin() + idx + 1);

            queries++;

            if (queries % 10 == 0) log_metrics();

        } else {

            int best_idx = -1;
            char best_op = ' ';
            bool found = false;

            for (int i = 0; i < (int)a.size() - 1; ++i) {

                if (apply_op(a[i], a[i+1], '+') == interactor_target) {
                    best_idx = i;
                    best_op = '+';
                    found = true;
                    break;
                }

                if (apply_op(a[i], a[i+1], '*') == interactor_target) {
                    best_idx = i;
                    best_op = '*';
                    found = true;
                    break;
                }
            }

            if (!found) {
                best_idx = 0;
                best_op = '+';
            }

            cout << (best_idx + 1) << " " << best_op << endl;

            int val = apply_op(a[best_idx], a[best_idx+1], best_op);
            a[best_idx] = val;
            a.erase(a.begin() + best_idx + 1);
        }
    }

    if (a.size() != 1) {
        finish(_wa, "Internal Error: Game finished with size != 1");
    }

    int final_val = a[0];

    bool alice_wins = (final_val == t);

    if (user_is_alice) {
        if (alice_wins) finish(_ok, "Contestant (Alice) wins");
        else finish(_wa, "Contestant (Alice) loses");
    } else {
        if (!alice_wins) finish(_ok, "Contestant (Bob) wins");
        else finish(_wa, "Contestant (Bob) loses");
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

int N_init, T_target;
vector<int> A;
long long queries = 0;
long long query_limit = 0;

void log_metrics() {
    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {}
}

void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int apply_op(int x, int y, char op) {
    if (op == '+') return (x + y) % 2;
    if (op == '*') return (x * y) % 2;
    return 0;
}

int solve_greedy(int c0, int c1, int turn) {
    int cur_c0 = c0;
    int cur_c1 = c1;

    while (cur_c0 + cur_c1 > 1) {
        bool is_alice = (turn % 2 == 0);

        int target = (is_alice ? T_target : 1 - T_target);
        bool wants_1 = (target == 1);

        if (wants_1) {

            if (cur_c0 > 0 && cur_c1 > 0) {

                cur_c0--;
            } else if (cur_c0 == 0) {

                cur_c1--;
            } else {

                cur_c0--;
            }
        } else {

            if (cur_c0 > 0 && cur_c1 > 0) {

                cur_c1--;
            } else if (cur_c1 == 0) {

                cur_c0--;
            } else {

                cur_c1 -= 2;
                cur_c0++;
            }
        }
        turn++;
    }
    return (cur_c1 > 0 ? 1 : 0);
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);

    atexit(log_metrics);

    N_init = inf.readInt();
    T_target = inf.readInt();
    int c0 = 0, c1 = 0;
    for (int i = 0; i < N_init; ++i) {
        int x = inf.readInt();
        A.push_back(x);
        if (x == 0) c0++; else c1++;
    }

    query_limit = N_init - 1;
    log_metrics();

    cout << N_init << " " << T_target << endl;
    for (int i = 0; i < N_init; ++i) {
        cout << A[i] << (i == N_init - 1 ? "" : " ");
    }
    cout << endl;

    string role_str;
    if (!(cin >> role_str)) finish(_wa, "Cannot read role");

    bool contestant_is_alice = false;
    if (role_str == "Alice") contestant_is_alice = true;
    else if (role_str == "Bob") contestant_is_alice = false;
    else finish(_wa, "Invalid role: " + role_str);

    bool interactor_is_alice = !contestant_is_alice;

    int moves = 0;
    while ((int)A.size() > 1) {

        queries = moves;
        log_metrics();

        bool is_alice_turn = (moves % 2 == 0);
        bool my_turn = (is_alice_turn == interactor_is_alice);

        if (my_turn) {

            int best_idx = 0;
            char best_op = '+';
            bool found_win = false;
            int my_target = (interactor_is_alice ? T_target : 1 - T_target);

            for (int i = 0; i < (int)A.size() - 1; ++i) {
                for (char op : {'+', '*'}) {

                    int x = A[i];
                    int y = A[i+1];
                    int res = apply_op(x, y, op);

                    int n_c0 = c0;
                    int n_c1 = c1;
                    if (x==0) n_c0--; else n_c1--;
                    if (y==0) n_c0--; else n_c1--;
                    if (res==0) n_c0++; else n_c1++;

                    int outcome = solve_greedy(n_c0, n_c1, moves + 1);

                    if (outcome == my_target) {
                        best_idx = i;
                        best_op = op;
                        found_win = true;
                        goto found;
                    }
                }
            }

            if (!found_win) {
                bool wants_1 = (my_target == 1);
                bool attacked = false;

                for (int i = 0; i < (int)A.size() - 1; ++i) {
                    if ((A[i] ^ A[i+1]) == 1) {
                        best_idx = i;
                        best_op = (wants_1 ? '+' : '*');
                        attacked = true;
                        break;
                    }
                }
                if (!attacked) {

                    best_idx = 0;
                    if (wants_1) {
                        if (c1 >= 2) best_op = '*';
                        else best_op = '+';
                    } else {
                        if (c1 >= 2) best_op = '+';
                        else best_op = '*';
                    }
                }
            }

            found:;

            int i = best_idx;
            int x = A[i];
            int y = A[i+1];
            int res = apply_op(x, y, best_op);

            cout << (i + 1) << " " << best_op << endl;

            vector<int> next_A;
            next_A.reserve(A.size() - 1);
            for(int k=0; k<i; ++k) next_A.push_back(A[k]);
            next_A.push_back(res);
            for(int k=i+2; k<(int)A.size(); ++k) next_A.push_back(A[k]);
            A = next_A;

            if(x==0) c0--; else c1--;
            if(y==0) c0--; else c1--;
            if(res==0) c0++; else c1++;

        } else {

            int p;
            string op_str;
            if (!(cin >> p >> op_str)) finish(_wa, "Cannot read move");

            if (p < 1 || p >= (int)A.size()) finish(_wa, "Invalid index: " + to_string(p));
            if (op_str.length() != 1 || (op_str[0] != '+' && op_str[0] != '*')) finish(_wa, "Invalid op: " + op_str);
            char op = op_str[0];

            int i = p - 1;
            int x = A[i];
            int y = A[i+1];
            int res = apply_op(x, y, op);

            vector<int> next_A;
            next_A.reserve(A.size() - 1);
            for(int k=0; k<i; ++k) next_A.push_back(A[k]);
            next_A.push_back(res);
            for(int k=i+2; k<(int)A.size(); ++k) next_A.push_back(A[k]);
            A = next_A;

            if(x==0) c0--; else c1--;
            if(y==0) c0--; else c1--;
            if(res==0) c0++; else c1++;
        }

        moves++;
    }

    queries = moves;
    int final_val = A[0];
    bool alice_wins = (final_val == T_target);

    if (alice_wins == contestant_is_alice) {
        finish(_ok, "Contestant won");
    } else {
        finish(_wa, "Contestant lost");
    }
    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");
    int n_opt = opt<int>("n", -1);
    int t_opt = opt<int>("t", -1);

    int seed_idx = -1;
    try {
        seed_idx = stoi(argv[1]);
    } catch (...) {

    }

    int n;
    int t;
    vector<int> a;

    if (seed_idx >= 1 && seed_idx <= 10) {

        switch (seed_idx) {
            case 1: n = 2; t = 0; a = {0, 0}; break;
            case 2: n = 2; t = 1; a = {0, 0}; break;
            case 3: n = 2; t = 0; a = {0, 1}; break;
            case 4: n = 2; t = 1; a = {1, 0}; break;
            case 5: n = 3; t = 0; a = {1, 1, 1}; break;
            case 6: n = 3; t = 1; a = {0, 0, 0}; break;
            case 7: n = 3; t = 0; a = {1, 0, 1}; break;
            case 8: n = 4; t = 1; a = {0, 1, 1, 0}; break;
            case 9: n = 5; t = 0; a = {1, 0, 0, 0, 1}; break;
            case 10: n = 10; t = 1; a.assign(10, 1); break;
            default: n = 2; t = 0; a = {0, 0}; break;
        }

        if (t_opt != -1) t = t_opt;
    }

    else {

        if (n_opt != -1) n = n_opt;
        else n = rnd.next(2, 500);

        if (t_opt != -1) t = t_opt;
        else t = rnd.next(0, 1);

        a.resize(n);

        if (mode == "non") {

            int dist_type = rnd.next(1, 10);

            if (dist_type <= 5) {

                for (int &x : a) x = rnd.next(0, 1);
            } else if (dist_type <= 8) {

                int dominant = rnd.next(0, 1);
                int prob = rnd.next(60, 90);
                for (int &x : a) x = (rnd.next(0, 100) < prob) ? dominant : 1 - dominant;
            } else {

                int current = rnd.next(0, 1);
                for (int i = 0; i < n; ) {
                    int len = rnd.next(1, max(1, min(n - i, n / 5)));
                    for (int k = 0; k < len; k++) a[i++] = current;
                    current = 1 - current;
                }
            }
        } else {

            int pattern = rnd.next(1, 5);

            if (pattern == 1) {

                int start = rnd.next(0, 1);
                for (int i = 0; i < n; i++) a[i] = (start + i) % 2;
            } else if (pattern == 2) {

                int dom = rnd.next(0, 1);
                fill(a.begin(), a.end(), dom);
                int cnt = rnd.next(1, max(1, n / 10));
                vector<int> p = rnd.distinct(cnt, 0, n - 1);
                for (int idx : p) a[idx] = 1 - dom;
            } else if (pattern == 3) {

                for (int i = 0; i < (n + 1) / 2; i++) {
                    a[i] = rnd.next(0, 1);
                    a[n - 1 - i] = a[i];
                }
            } else if (pattern == 4) {

                int val = rnd.next(0, 1);
                for (int i = 0; i < n; i++) {
                    if (i % 2 == 0) val = rnd.next(0, 1);
                    a[i] = val;
                }
            } else {

                int bias = rnd.next(10, 90);
                for (int &x : a) x = (rnd.next(0, 100) < bias) ? 1 : 0;
            }
        }
    }

    cout << n << " " << t << "\n";
    for (int i = 0; i < n; i++) {
        cout << a[i] << (i == n - 1 ? "" : " ");
    }
    cout << "\n";

    return 0;
}


This is an interactive problem.

There is a permutation$^{\text{∗}}$ $p$ of length $n$.

Someone secretly chose two integers $l, r$ ($1 \le l \le r \le n$) and modified the permutation in the following way:

* For every index $i$ such that $l \le i \le r$, set $p_i := p_i + 1$.

Let $a$ denote the resulting array obtained by modifying the permutation.

You are given an integer $n$ denoting the length of the permutation $p$.

In one query, you are allowed to choose two integers $l, r$ ($1 \le l \le r \le n$) and ask for the sum of the subarray either of the original permutation $p[l \dots r]$ or of the modified array $a[l \dots r]$. The answer to such a query will be the corresponding integer sum.

Your task is to find the pair $(l, r)$ that was chosen to obtain $a$ in no more than $\bf{40}$ queries.

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in any order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation (the number $2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$, but the array contains $4$).

Input

The first line of input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

Each test case contains a single integer $n$ ($1 \le n \le 2\cdot10^4$) — the length of the permutation.

It is guaranteed that the sum of $n$ over all the test cases does not exceed $2\cdot10^4$.

Interaction

The interaction for each test case begins by reading the integer $n$.

You can ask two types of queries.

* Print "$ \texttt{1 l r} $" ($1 \le l \le r \le n$).

  In response, you should read a line containing a single integer $x$ — the sum of the subarray of the original permutation. (Formally, $x = p_l + p_{l + 1} + \dots + p_r$).
* Print "$ \texttt{2 l r} $" ($1 \le l \le r \le n$).

  In response, you should read a line containing a single integer $y$ — the sum of the subarray of the modified array. (Formally, $y = a_l + a_{l + 1} + \dots + a_r$).

The permutation $p$ and the chosen integers $l$, $r$ are fixed beforehand and can't be changed during the time of interaction.

You can output the final answer by printing "$ \texttt{! l r} $", where $l$, $r$ denote the integers that were chosen to obtain $a$. After printing the answer, your program should proceed to the next test case or terminate if there are no more.

You can ask no more than $40$ queries per testcase. Printing the answer doesn't count as a query. If your program performs more than $40$ queries for one test case or makes an invalid query, you may receive a Wrong Answer verdict.

After printing a query, do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded.

Example

Input

```
2

3

4

5

4

8

8

9
```

Output

```
1 1 2

2 1 2

! 2 2

1 2 4

2 1 3

2 3 4

! 2 4
```

Note

For the first testcase, $p = [3, 1, 2]$ and $l = 2$, $r = 2$. Hence, the modified array $a$ will be equal to $[3, 2, 2]$.

So, querying "$\texttt{1 1 2}$" gives $p_1 + p_2 = 3 + 1 = 4$. And querying "$\texttt{2 1 2}$" gives $a_1 + a_2 = 3 + 2 = 5$.

For the second testcase, $p = [2, 1, 3, 4]$ and $l = 2$, $r = 4$.

Note that the queries shown in the sample test are only for demonstration purposes, and they may not correspond to any optimal solution.

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long max_queries = 0;
static const long long QUERY_LIMIT_PER_CASE = 40;

static void log_metrics() {
    try {
        tout << "queries=" << max_queries << endl;
        tout << "query_limit=" << QUERY_LIMIT_PER_CASE << endl;
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    int T = inf.readInt();

    cout << T << endl;

    for (int t = 1; t <= T; ++t) {

        int n = inf.readInt();
        vector<int> p(n + 1);
        vector<long long> pref_p(n + 1, 0);
        for (int i = 1; i <= n; ++i) {
            p[i] = inf.readInt();
            pref_p[i] = pref_p[i-1] + p[i];
        }
        int L_ans = inf.readInt();
        int R_ans = inf.readInt();

        cout << n << endl;

        int current_queries = 0;
        bool solved = false;

        while (true) {

            if (current_queries > 2000) {
                finish(_pe, "Too many queries (hard cap hit)");
            }

            string token;
            if (!(cin >> token)) {
                finish(_wa, "Unexpected EOF (contestant terminated early)");
            }

            if (token == "!") {
                int l_sub, r_sub;
                if (!(cin >> l_sub >> r_sub)) {
                    finish(_wa, "Invalid answer format after '!'");
                }

                if (l_sub != L_ans || r_sub != R_ans) {
                    finish(_wa, format("Incorrect answer for testcase %d. Expected %d %d, got %d %d", t, L_ans, R_ans, l_sub, r_sub));
                }

                solved = true;
                break;
            }

            int type, l, r;
            if (token == "?") {
                if (!(cin >> type >> l >> r)) {
                    finish(_wa, "Invalid query format after '?'");
                }
            } else {

                try {
                    type = stoi(token);
                } catch (...) {
                    finish(_wa, "Invalid token (expected query type or '!')");
                }
                if (!(cin >> l >> r)) {
                    finish(_wa, "Invalid query parameters");
                }
            }

            if (type != 1 && type != 2) {
                finish(_wa, format("Invalid query type %d", type));
            }
            if (l < 1 || r > n || l > r) {
                finish(_wa, format("Invalid range [%d, %d] with n=%d", l, r, n));
            }

            current_queries++;
            if (current_queries > max_queries) {
                max_queries = current_queries;
            }

            if (current_queries % 10 == 0) {
                log_metrics();
            }

            long long ans = 0;

            long long sum_p = pref_p[r] - pref_p[l-1];

            if (type == 1) {

                ans = sum_p;
            } else {

                int intersect_l = max(l, L_ans);
                int intersect_r = min(r, R_ans);
                int count = 0;
                if (intersect_l <= intersect_r) {
                    count = intersect_r - intersect_l + 1;
                }
                ans = sum_p + count;
            }

            cout << ans << endl;
        }

        if (!solved) {
            finish(_wa, "Loop terminated without answer");
        }
    }

    finish(_ok, "All test cases passed");
    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long max_queries = 0;
static const long long QUERY_LIMIT_PER_CASE = 40;

static void log_metrics() {
    try {
        tout << "queries=" << max_queries << endl;
        tout << "query_limit=" << QUERY_LIMIT_PER_CASE << endl;
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    if (verdict != _ok) {
        cout << -1 << endl;
        cout.flush();
    }
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static void my_atexit() {
    log_metrics();
}

static void solve_one(int n) {

    vector<int> p = rnd.perm(n, 1);

    vector<long long> pref(n + 1, 0);
    for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + p[i - 1];

    int L = 1, R = 1;
    if (rnd.next(5) == 0) {

        int type = rnd.next(5);
        if (type == 0) { L = 1; R = n; }
        else if (type == 1) { L = 1; R = rnd.next(1, n); }
        else if (type == 2) { R = n; L = rnd.next(1, n); }
        else if (type == 3) { L = rnd.next(1, n); R = L; }
        else {
            if (n > 1) { L = rnd.next(1, n - 1); R = L + 1; }
            else { L = 1; R = 1; }
        }
    } else {
        L = rnd.next(1, n);
        R = rnd.next(1, n);
        if (L > R) swap(L, R);
    }

    int used = 0;
    while (true) {
        string tok;
        if (!(cin >> tok)) finish(_wa, "Unexpected EOF");

        if (tok == "!") {
            int l, r;
            if (!(cin >> l >> r)) finish(_wa, "Malformed answer");
            if (l == L && r == R) return;
            finish(_wa, format("Wrong answer (expected %d %d, got %d %d)", L, R, l, r));
        }

        int type = -1;
        if (tok == "1") type = 1;
        else if (tok == "2") type = 2;
        else finish(_wa, "Invalid token (expected '1', '2', or '!')");

        int l, r;
        if (!(cin >> l >> r)) finish(_wa, "Malformed query");
        if (l < 1 || r > n || l > r) finish(_wa, format("Invalid range [%d,%d] (n=%d)", l, r, n));

        used++;
        if (used > (int)QUERY_LIMIT_PER_CASE) finish(_wa, "Query limit exceeded (40 per testcase)");
        max_queries = max<long long>(max_queries, used);
        if (used % 10 == 0) log_metrics();

        long long sum_p = pref[r] - pref[l - 1];
        if (type == 1) {
            cout << sum_p << endl;
            cout.flush();
            continue;
        }

        int il = max(l, L);
        int ir = min(r, R);
        long long add = (il <= ir) ? (ir - il + 1) : 0;
        cout << (sum_p + add) << endl;
        cout.flush();
    }
}

int main(int argc, char* argv[]) {

    registerInteraction(argc, argv);
    atexit(my_atexit);

    int t = inf.readInt();
    cout << t << endl;
    cout.flush();
    log_metrics();

    for (int i = 0; i < t; ++i) {
        int n = inf.readInt();
        cout << n << endl;
        cout.flush();
        solve_one(n);
    }

    finish(_ok, "All test cases passed");
    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");

    int opt_t = opt<int>("t", -1);
    int opt_n = opt<int>("n", -1);

    const int MAX_SUM_N = 20000;
    vector<int> ns;

    bool custom = (opt_t != -1 || opt_n != -1);

    if (!custom) {

        string seedStr = (argc > 1 ? argv[1] : "1");

        if (seedStr == "1") {

            ns = {MAX_SUM_N};
        } else if (seedStr == "2") {

            ns.assign(10000, 2);
        } else if (seedStr == "3") {

            int rem = MAX_SUM_N;
            while (rem > 0) {
                int cur = rnd.next(10, 500);
                if (cur > rem) cur = rem;
                ns.push_back(cur);
                rem -= cur;
            }
        } else {

            int total_n = rnd.next(1, MAX_SUM_N);
            int t = 1;
            if (total_n > 1) {
                int type = rnd.next(10);
                if (type < 5) {
                    t = 1;
                } else if (type < 8) {

                    t = rnd.next(2, min(total_n, 10));
                } else {

                    int low = min(total_n, 10);
                    int high = min(total_n, 100);
                    t = rnd.next(low, high);
                }
            }
            ns = rnd.partition(t, total_n, 1);
        }
    } else {

        int S = (opt_n == -1) ? MAX_SUM_N : opt_n;
        int T = (opt_t == -1) ? -1 : opt_t;

        if (T == -1) {
            if (S > 5000) T = 1;
            else T = rnd.next(1, min(S, 10));
        }

        if (T > S) T = S;
        if (T < 1) T = 1;

        ns = rnd.partition(T, S, 1);
    }

    println(ns.size());

    for (int n : ns) {
        if (mode == "non") {
            println(n);
            vector<int> p = rnd.perm(n, 1);
            println(p);

            int l, r;

            if (rnd.next(5) == 0) {
                int type = rnd.next(5);
                if (type == 0) { l = 1; r = n; }
                else if (type == 1) { l = 1; r = rnd.next(1, n); }
                else if (type == 2) { r = n; l = rnd.next(1, n); }
                else if (type == 3) { l = rnd.next(1, n); r = l; }
                else {
                    if (n > 1) { l = rnd.next(1, n-1); r = l + 1; }
                    else { l = 1; r = 1; }
                }
            } else {

                l = rnd.next(1, n);
                r = rnd.next(1, n);
                if (l > r) swap(l, r);
            }
            println(l, r);
        } else {

            println(n);
        }
    }

    return 0;
}


This is the medium version of the problem. In this version, you can send at most $\mathbf{4}$ commands.

This is an interactive problem.

Welcome, Duelists! In this interactive challenge, there is an unknown integer $x$ ($1 \le x \le 10^9$). You must make it equal to a given integer in the input $n$. By harnessing the power of "Mathmech" monsters, you can send a command to do one of the following:

|  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- |
| Command | Constraint | Result | Case | Update | Jury's response |
| "add $y$" | $-10^{18} \le y \le 10^{18}$ | $\mathrm{res} = x + y$ | $\text{if } 1 \le \mathrm{res} \le 10^{18}$ | $x \leftarrow \mathrm{res}$ | "1" |
| $\mathrm{else}$ | $x \leftarrow x$ | "0" |
| "mul $y$" | $1 \le y \le 10^{18}$ | $\mathrm{res} = x \cdot y$ | $\text{if } 1 \le \mathrm{res} \le 10^{18}$ | $x \leftarrow \mathrm{res}$ | "1" |
| $\mathrm{else}$ | $x \leftarrow x$ | "0" |
| "div $y$" | $1 \le y \le 10^{18}$ | $\mathrm{res} = x/y$ | $\text{if } y$ divides $x$ | $x \leftarrow \mathrm{res}$ | "1" |
| $\mathrm{else}$ | $x \leftarrow x$ | "0" |
| "digit" | — | $\mathrm{res} = S(x)$$^{\text{∗}}$ | — | $x \leftarrow \mathrm{res}$ | "1" |

You have to make $x$ equal to $n$ using at most $\mathbf{4}$ commands.

$^{\text{∗}}$$S(n)$ is a function that returns the sum of all the individual digits of a non-negative integer $n$. For example, $S(123) = 1 + 2 + 3 = 6$

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). The description of the test cases follows.

The first and only line of each test case contains one integer $n$ ($1 \le n \le 10^9$).

Interaction

The interaction for each test case begins by reading the integer $n$.

To send a command, output a line in the following format:

* "add $y$" Add some integer $y$ ($-10^{18} \le y \le 10^{18}$) to $x$.

  The jury will output "1" if $x + y$ is within $[1, 10^{18}]$ (successful), and "0" otherwise. If successful, update $x \leftarrow x + y$.
* "mul $y$" Multiply $x$ by a positive integer $y$ ($1 \le y \le 10^{18}$).

  The jury will output "1" if $x \cdot y$ is within $[1, 10^{18}]$ (successful), and "0" otherwise. If successful, update $x \leftarrow x \cdot y$.
* "div $y$" Divide $x$ by a positive integer $y$ ($1 \le y \le 10^{18}$).

  The jury will output "1" if $y$ is a divisor of $x$ (successful), and "0" otherwise. If successful, update $x \leftarrow \frac{x}{y}$.
* "digit" Make $x$ equal to the sum of its digits.

  The jury will always output "1" and update $x \leftarrow S(x)$.

Note that commands are case sensitive.

When you have determined that $x$ is equal to $n$, output a line in the following format:

* "!" — where the jury will output a "1" if $n$ is equal to $x$, and "-1" otherwise.

Note that answering does not count toward your limit of $\mathbf{4}$ commands.

If your program makes more than $\mathbf{4}$ commands for one test case, or makes an invalid command, then the response to the command will be "-1". After receiving such a response, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, it may receive any other verdict.

After printing a command, do not forget to output the end of the line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* sys.stdout.flush() in Python;
* std::io::stdout().flush() in Rust;
* see the documentation for other languages.

The interactor is non-adaptive. The unknown integer $x$ does not change during the interaction.

Example

Input

```
2
100

0

1

1

1

5

1

1

1
```

Output

```
add -10

add 1

mul 10

!

digit

div 2

!
```

Note

|  |  |  |
| --- | --- | --- |
| Solution | Jury | Explanation |
|  | $\texttt{2}$ | There are 2 test cases. |
|  | $\texttt{100}$ | In the first test case, the unknown integer $x = 9$ and we have to make it equal to $n = 100$. |
| $\texttt{add -10}$ | $\texttt{0}$ | The answer to "add -10" is "0". This means that the addition command was not successful as $x + y = 9 + (-10) \le 0$, and $x$ remains $9$ after the command |
| $\texttt{add 1}$ | $\texttt{1}$ | The answer to "add 1" is "1". This means that the addition command was successful as $x + y = 9 + 1 = 10$, and $x$ changes to $10$ after the command. |
| $\texttt{mul 10}$ | $\texttt{1}$ | The answer to "mul 10" is "1". This means that the multiplication command was successful as $x \cdot y = 10 \cdot 10 = 100$, and $x$ changes to $100$ after the command. |
| $\texttt{!}$ | $\texttt{1}$ | The answer to "!" is "1". This means you have determined that $x$ equals $n$. |
|  | $\texttt{5}$ | In the second test case, the unknown integer $x = 1234$ and we have to make it equal to $n = 5$. |
| $\texttt{digit}$ | $\texttt{1}$ | The answer to "digit" is "1". This means that $x$ turned into the sum of its digits $1 + 2 + 3 + 4 = 10$, and $x$ changes to $10$ after the command. |
| $\texttt{div 2}$ | $\texttt{1}$ | The answer to "div 2" is "1". This means that the division command was successful as $y = 2$ is a divisor of $x = 10$, and $x$ changes to $\frac{x}{y} = \frac{10}{2} = 5$ after the command. |
| $\texttt{!}$ | $\texttt{1}$ | The answer to "!" is "1". This means you have determined that $x$ equals $n$. |

Note that the empty lines in the example input and output are for the sake of clarity, and do not occur in the real interaction.

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << '\n';
        tout << "query_limit=" << query_limit << '\n';
        tout.flush();
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static string trimWs(const string& s) {
    size_t i = 0, j = s.size();
    while (i < j && isspace((unsigned char)s[i])) i++;
    while (j > i && isspace((unsigned char)s[j - 1])) j--;
    return s.substr(i, j - i);
}

static bool readNonEmptyLine(string& line) {
    while (true) {
        if (!std::getline(cin, line)) return false;
        line = trimWs(line);
        if (!line.empty()) return true;
    }
}

static vector<string> splitWs(const string& line) {
    vector<string> toks;
    istringstream iss(line);
    string t;
    while (iss >> t) toks.push_back(t);
    return toks;
}

static bool parseSignedInt128(const string& s, __int128& out) {
    if (s.empty()) return false;
    int sign = 1;
    size_t i = 0;
    if (s[i] == '+') {
        i++;
    } else if (s[i] == '-') {
        sign = -1;
        i++;
    }
    if (i >= s.size()) return false;

    __int128 val = 0;
    for (; i < s.size(); i++) {
        char c = s[i];
        if (c < '0' || c > '9') return false;
        val = val * 10 + (c - '0');
        if (val > (__int128)9e18) {

        }
    }
    out = val * sign;
    return true;
}

static bool parseLongLongInRange(const string& s, long long lo, long long hi, long long& out) {
    __int128 v;
    if (!parseSignedInt128(s, v)) return false;
    if (v < (__int128)lo || v > (__int128)hi) return false;
    out = (long long)v;
    return true;
}

static long long digitSumLL(long long x) {
    long long s = 0;
    while (x > 0) {
        s += x % 10;
        x /= 10;
    }
    return s;
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    int t = 0;
    try {
        t = inf.readInt(1, 5000, "t");
    } catch (...) {

        query_limit = 0;
        log_metrics();
        quitf(_fail, "Invalid hidden input: cannot read t");
    }

    vector<long long> ns(t), xs(t);
    for (int i = 0; i < t; i++) {
        long long n = inf.readLong(1, 1000000000LL, "n");
        long long x = inf.readLong(1, 1000000000LL, "x");
        ns[i] = n;
        xs[i] = x;
    }

    query_limit = 4LL * t;
    const long long hard_cap = max(200000LL, 10LL * query_limit);

    log_metrics();

    cout << t << '\n';
    cout.flush();

    for (int tc = 0; tc < t; tc++) {
        long long n = ns[tc];
        long long x = xs[tc];

        cout << n << '\n';
        cout.flush();

        while (true) {
            string line;
            if (!readNonEmptyLine(line)) {
                finish(_pe, "Unexpected EOF from contestant");
            }

            vector<string> toks = splitWs(line);
            if (toks.empty()) continue;

            const string& cmd = toks[0];

            if (cmd == "!") {
                if (toks.size() != 1) {
                    cout << -1 << '\n';
                    cout.flush();
                    finish(_pe, "Invalid answer format");
                }
                if (x == n) {
                    cout << 1 << '\n';
                    cout.flush();
                    break;
                } else {
                    cout << -1 << '\n';
                    cout.flush();
                    finish(_wa, "Wrong final answer");
                }
            } else if (cmd == "digit") {
                if (toks.size() != 1) {
                    cout << -1 << '\n';
                    cout.flush();
                    finish(_pe, "Invalid digit command format");
                }
                queries++;
                if (queries > hard_cap) finish(_pe, "Hard cap exceeded");
                x = digitSumLL(x);
                cout << 1 << '\n';
                cout.flush();
            } else if (cmd == "add") {
                if (toks.size() != 2) {
                    cout << -1 << '\n';
                    cout.flush();
                    finish(_pe, "Invalid add command format");
                }
                long long y;
                if (!parseLongLongInRange(toks[1], -1000000000000000000LL, 1000000000000000000LL, y)) {
                    cout << -1 << '\n';
                    cout.flush();
                    finish(_pe, "Invalid add argument");
                }
                queries++;
                if (queries > hard_cap) finish(_pe, "Hard cap exceeded");

                __int128 res = (__int128)x + (__int128)y;
                if (res >= 1 && res <= (__int128)1000000000000000000LL) {
                    x = (long long)res;
                    cout << 1 << '\n';
                } else {
                    cout << 0 << '\n';
                }
                cout.flush();
            } else if (cmd == "mul") {
                if (toks.size() != 2) {
                    cout << -1 << '\n';
                    cout.flush();
                    finish(_pe, "Invalid mul command format");
                }
                long long y;
                if (!parseLongLongInRange(toks[1], 1LL, 1000000000000000000LL, y)) {
                    cout << -1 << '\n';
                    cout.flush();
                    finish(_pe, "Invalid mul argument");
                }
                queries++;
                if (queries > hard_cap) finish(_pe, "Hard cap exceeded");

                __int128 res = (__int128)x * (__int128)y;
                if (res >= 1 && res <= (__int128)1000000000000000000LL) {
                    x = (long long)res;
                    cout << 1 << '\n';
                } else {
                    cout << 0 << '\n';
                }
                cout.flush();
            } else if (cmd == "div") {
                if (toks.size() != 2) {
                    cout << -1 << '\n';
                    cout.flush();
                    finish(_pe, "Invalid div command format");
                }
                long long y;
                if (!parseLongLongInRange(toks[1], 1LL, 1000000000000000000LL, y)) {
                    cout << -1 << '\n';
                    cout.flush();
                    finish(_pe, "Invalid div argument");
                }
                queries++;
                if (queries > hard_cap) finish(_pe, "Hard cap exceeded");

                if (y != 0 && x % y == 0) {
                    x /= y;
                    cout << 1 << '\n';
                } else {
                    cout << 0 << '\n';
                }
                cout.flush();
            } else {
                cout << -1 << '\n';
                cout.flush();
                finish(_pe, "Unknown command");
            }
        }
    }

    finish(_ok, "OK");
    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long clampLL(long long v, long long lo, long long hi) {
    if (v < lo) return lo;
    if (v > hi) return hi;
    return v;
}

static long long pickFrom(const vector<long long>& a) {
    int i = rnd.next(0, (int)a.size() - 1);
    return a[i];
}

static long long genN(long long nmax, const vector<long long>& specialN) {
    int roll = rnd.next(0, 99);
    if (roll < 40) return pickFrom(specialN);
    if (roll < 55) {

        int type = rnd.next(0, 4);
        if (type == 0) {
            int d = rnd.next(1, 9);
            int len = rnd.next(1, 10);
            long long v = 0;
            for (int i = 0; i < len; i++) v = v * 10 + d;
            return clampLL(v, 1LL, nmax);
        } else if (type == 1) {
            int k = rnd.next(0, 9);
            long long p10 = 1;
            for (int i = 0; i < k; i++) p10 *= 10;
            long long delta = rnd.next(-1000LL, 1000LL);
            long long v = p10 + delta;
            return clampLL(v, 1LL, nmax);
        } else if (type == 2) {

            long long delta = rnd.next(0LL, min(100000LL, nmax - 1));
            return nmax - delta;
        } else if (type == 3) {

            long long v = rnd.next(1LL, 1000LL);
            return clampLL(v, 1LL, nmax);
        } else {

            long long hi = min(nmax, 1000000LL);
            return rnd.next(1LL, hi);
        }
    }
    return rnd.next(1LL, nmax);
}

static long long genX(long long xmax, const vector<long long>& specialX) {
    int roll = rnd.next(0, 99);
    if (roll < 45) return pickFrom(specialX);
    if (roll < 70) {

        int type = rnd.next(0, 3);
        if (type == 0) return 1000000000LL;
        if (type == 1) return 999999999LL;
        if (type == 2) return 888888888LL;
        return 111111111LL;
    }
    if (roll < 85) {

        if (rnd.next(0, 1) == 0) return rnd.next(1LL, 1000LL);
        long long delta = rnd.next(0LL, min(100000LL, xmax - 1));
        return xmax - delta;
    }
    return rnd.next(1LL, xmax);
}

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");
    int tOpt = opt<int>("t", 5000);

    const long long NMAX = opt<long long>("nmax", 1000000000LL);
    const long long XMAX = opt<long long>("xmax", 1000000000LL);

    ensuref(NMAX >= 1 && NMAX <= 1000000000LL, "nmax must be in [1, 1e9]");
    ensuref(XMAX >= 1 && XMAX <= 1000000000LL, "xmax must be in [1, 1e9]");
    ensuref(tOpt >= 1 && tOpt <= 5000, "t must be in [1, 5000]");

    vector<long long> specialN = {
        1, 2, 3, 4, 5, 6, 7, 8, 9,
        10, 11, 12, 18, 19, 20,
        81, 82, 83, 89, 90, 99,
        100, 101, 109, 110, 111,
        1000, 9999, 100000, 1000000,
        123456789, 987654321, 555555555, 999999999,
        999999937, 1000000000
    };
    for (auto& v : specialN) v = clampLL(v, 1LL, NMAX);

    vector<long long> specialX = {
        1, 2, 3, 7, 8, 9,
        10, 11, 12, 18, 19, 20,
        21, 22, 27, 28,
        97, 99, 100, 101,
        999, 1000, 1001,
        1234, 9999, 10000,
        111111111, 222222222, 333333333, 444444444,
        555555555, 666666666, 777777777, 888888888, 999999999,
        123456789, 987654321,
        999999937, 1000000000
    };
    for (auto& v : specialX) v = clampLL(v, 1LL, XMAX);

    struct Case { long long n, x; };
    vector<Case> cases;

    long long seed = atoll(argv[1]);

    auto addCase = [&](long long n, long long x) {
        n = clampLL(n, 1LL, NMAX);
        x = clampLL(x, 1LL, XMAX);
        cases.push_back({n, x});
    };

    if (seed == 1) {

        addCase(1, 1);
        addCase(1000000000LL, 1);
        addCase(1, 1000000000LL);
        addCase(1000000000LL, 1000000000LL);
        addCase(81, 999999999LL);
        addCase(82, 1000000000LL);
        addCase(9, 999999999LL);
        addCase(10, 999999999LL);
        addCase(100, 9);
        addCase(5, 1234);
        addCase(999999937LL, 999999999LL);
        addCase(999999999LL, 1000000000LL);
        addCase(987654321LL, 123456789LL);
        addCase(123456789LL, 987654321LL);
        addCase(555555555LL, 111111111LL);
        addCase(99, 100);
        addCase(11, 10);
        addCase(19, 20);
        addCase(20, 19);
    } else if (seed == 2) {

        addCase(999999999LL, 999999999LL);
        addCase(1000000000LL, 999999999LL);
        addCase(999999937LL, 1000000000LL);
        addCase(1, 999999999LL);
        addCase(9, 1000000000LL);
        addCase(81, 1000000000LL);
        addCase(82, 999999999LL);
        addCase(90, 888888888LL);
        addCase(99, 111111111LL);
        addCase(100, 999999937LL);
        addCase(101, 987654321LL);
        addCase(109, 123456789LL);
        addCase(110, 555555555LL);
        addCase(111, 444444444LL);
        addCase(987654321LL, 888888888LL);
        addCase(123456789LL, 111111111LL);
        addCase(555555555LL, 999999999LL);
        addCase(10, 1);
        addCase(11, 2);
        addCase(12, 3);
    } else if (seed == 3) {

        int t = 5000;
        cases.reserve(t);

        for (int i = 0; i < 120; i++) {
            long long n = specialN[i % (int)specialN.size()];
            long long x = specialX[(i * 7) % (int)specialX.size()];
            addCase(n, x);
        }

        while ((int)cases.size() < t) {
            int i = (int)cases.size();
            long long n, x;
            int roll = rnd.next(0, 99);
            if (roll < 25) {

                x = (i % 2 == 0) ? 999999999LL : 1000000000LL;
                n = (i % 3 == 0) ? 81 : ((i % 3 == 1) ? 9 : 1000000000LL);
            } else if (roll < 50) {

                n = clampLL(NMAX - rnd.next(0LL, 100000LL), 1LL, NMAX);
                x = genX(XMAX, specialX);
            } else if (roll < 75) {

                n = genN(NMAX, specialN);
                x = pickFrom(specialX);
            } else {

                n = genN(NMAX, specialN);
                x = genX(XMAX, specialX);
            }
            addCase(n, x);
        }
    } else {
        int t = tOpt;
        cases.reserve(t);

        vector<pair<long long,long long>> curated = {
            {1, 1},
            {NMAX, 1},
            {1, XMAX},
            {NMAX, XMAX},
            {81, 999999999LL},
            {82, 1000000000LL},
            {9, 999999999LL},
            {10, 999999999LL},
            {100, 9},
            {999999937LL, 999999999LL},
            {999999999LL, 1000000000LL},
            {123456789LL, 987654321LL},
            {987654321LL, 123456789LL},
            {555555555LL, 111111111LL},
            {99, 100},
            {11, 10},
        };
        for (auto [n, x] : curated) {
            if ((int)cases.size() >= t) break;
            addCase(n, x);
        }

        while ((int)cases.size() < t) {
            long long n = genN(NMAX, specialN);
            long long x = genX(XMAX, specialX);

            int roll = rnd.next(0, 99);
            if (roll < 20) {
                x = (rnd.next(0, 1) == 0) ? 1000000000LL : 999999999LL;

                long long base = clampLL(NMAX - rnd.next(0LL, 1000000LL), 1LL, NMAX);
                long long tweak = rnd.next(-12345LL, 12345LL);
                n = clampLL(base + tweak, 1LL, NMAX);
            } else if (roll < 35) {

                long long v = 1;
                int steps = rnd.next(3, 8);
                for (int i = 0; i < steps; i++) {
                    long long p = pickFrom(vector<long long>{2, 3, 5, 7, 11, 13});
                    if (v > NMAX / p) break;
                    v *= p;
                }
                n = clampLL(v + rnd.next(-50LL, 50LL), 1LL, NMAX);
            } else if (roll < 50) {

                x = pickFrom(specialX);
            }

            addCase(n, x);
        }
    }

    ensuref(!cases.empty(), "No cases generated");

    if (mode == "non") {
        cout << cases.size() << "\n";
        for (auto &tc : cases) {
            cout << tc.n << " " << tc.x << "\n";
        }
    } else if (mode == "adp") {

        cout << cases.size() << "\n";
        for (auto &tc : cases) {
            cout << tc.n << "\n";
        }
    } else {
        ensuref(false, "Unknown mode: %s", mode.c_str());
    }

    return 0;
}


This is an interactive problem.

You are given two integers $c$ and $n$. The jury has a randomly generated set $A$ of distinct positive integers not greater than $c$ (it is generated from all such possible sets with equal probability). The size of $A$ is equal to $n$.

Your task is to guess the set $A$. In order to guess it, you can ask at most $\lceil 0.65 \cdot c \rceil$ queries.

In each query, you choose a single integer $1 \le x \le c$. As the answer to this query you will be given the bitwise xor sum of all $y$, such that $y \in A$ and $gcd(x, y) = 1$ (i.e. $x$ and $y$ are coprime). If there is no such $y$ this xor sum is equal to $0$.

You can ask all queries at the beginning and you will receive the answers to all your queries. After that, you won't have the possibility to ask queries.

You should find any set $A'$, such that $|A'| = n$ and $A'$ and $A$ have the same answers for all $c$ possible queries.

Input

Firstly you are given two integers $c$ and $n$ ($100 \le c \le 10^6$, $0 \le n \le c$).

Interaction

In the first line you should print an integer $q$ $(0 \le q \le \lceil 0.65 \cdot c \rceil)$ — the number of queries you want to ask. After that in the same line print $q$ integers $x_1, x_2, \ldots, x_q$ $(1 \le x_i \le c)$ — the queries.

For these queries you should read $q$ integers, $i$-th of them is the answer to the described query for $x = x_i$.

After that you should print $n$ distinct integers $A'_1, A'_2, \ldots, A'_n$ — the set $A'$ you found.

If there are different sets $A'$ that have the same answers for all possible queries, print any of them.

If you will ask more than $\lceil 0.65 \cdot c \rceil$ queries or if the queries will be invalid, the interactor will terminate immediately and your program will receive verdict Wrong Answer.

After printing the queries and answers do not forget to output end of line and flush the output buffer. Otherwise, you will get the Idleness limit exceeded verdict. To do flush use:

* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* Read documentation for other languages.

Example

Input

```
10 6

1 4 2 11 4 4 4
```

Output

```
7 10 2 3 5 7 1 6

1 4 5 6 8 10
```

Note

The sample is made only for you to understand the interaction protocol. Your solution will not be tested on the sample.

In the sample $A = \{1, 4, 5, 6, 8, 10\}$. $7$ queries are made, $7 \le \lceil 0.65 \cdot 10 \rceil = 7$, so the query limit is not exceeded.

Answers for the queries:

* For $10$: $1$ is the only number in the set $A$ coprime with $10$, so the answer is $1$
* For $2$: $1_{10} \oplus 5_{10} = 001_2 \oplus 101_2 = 4_{10}$, where $\oplus$ is the bitwise xor
* For $3$: $1_{10} \oplus 4_{10} \oplus 5_{10} \oplus 8_{10} \oplus 10_{10} = 0001_2 \oplus 0100_2 \oplus 0101_2 \oplus 1000_2 \oplus 1010_2 = 2_{10}$
* For $5$: $1_{10} \oplus 4_{10} \oplus 6_{10} \oplus 8_{10} = 0001_2 \oplus 0100_2 \oplus 0110_2 \oplus 1000_2 = 11_{10}$
* For $7$: $1_{10} \oplus 4_{10} \oplus 5_{10} \oplus 6_{10} \oplus 8_{10} \oplus 10_{10} = 0001_2 \oplus 0100_2 \oplus 0101_2 \oplus 0110_2 \oplus 1000_2 \oplus 1010_2 = 4_{10}$
* For $1$: $1_{10} \oplus 4_{10} \oplus 5_{10} \oplus 6_{10} \oplus 8_{10} \oplus 10_{10} = 0001_2 \oplus 0100_2 \oplus 0101_2 \oplus 0110_2 \oplus 1000_2 \oplus 1010_2 = 4_{10}$
* For $6$: $1_{10} \oplus 5_{10} = 0001_2 \oplus 0101_2 = 4_{10}$

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int main(int argc, char* argv[]) {
    registerInteraction(argc, argv);
    atexit(log_metrics);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    const int c = inf.readInt(100, 1000000, "c");
    const int n = inf.readInt(0, c, "n");

    vector<char> inA(c + 1, 0);
    for (int i = 0; i < n; i++) {
        int v = inf.readInt(1, c, "A[i]");
        if (inA[v]) finish(_fail, "Invalid hidden set: duplicates");
        inA[v] = 1;
    }

    vector<int> G(c + 1, 0);
    for (int d = 1; d <= c; d++) {
        int acc = 0;
        for (int m = d; m <= c; m += d) {
            if (inA[m]) acc ^= m;
        }
        G[d] = acc;
    }

    vector<char> squarefree(c + 1, 1);
    for (long long p = 2; p * p <= c; p++) {
        long long sq = p * p;
        for (long long m = sq; m <= c; m += sq) {
            squarefree[(int)m] = 0;
        }
    }

    vector<int> ans_all(c + 1, 0);
    for (int d = 1; d <= c; d++) {
        if (!squarefree[d]) continue;
        int v = G[d];
        if (v == 0) continue;
        for (int m = d; m <= c; m += d) {
            ans_all[m] ^= v;
        }
    }

    query_limit = (65LL * c + 99) / 100;

    log_metrics();

    cout << c << " " << n << "\n";
    cout.flush();

    long long q_ll = 0;
    if (!(cin >> q_ll)) finish(_pe, "Unexpected EOF reading q");
    if (q_ll < 0 || q_ll > query_limit) finish(_wa, "Query limit exceeded");
    int q = (int)q_ll;

    vector<int> xs(q);
    for (int i = 0; i < q; i++) {
        long long x_ll = 0;
        if (!(cin >> x_ll)) finish(_pe, "Unexpected EOF reading query x");
        if (x_ll < 1 || x_ll > c) finish(_wa, "Query x out of range");
        xs[i] = (int)x_ll;
    }
    queries = q;

    for (int i = 0; i < q; i++) {
        if (i) cout << ' ';
        cout << ans_all[xs[i]];
    }
    cout << "\n";
    cout.flush();

    vector<char> inB(c + 1, 0);
    for (int i = 0; i < n; i++) {
        long long v_ll = 0;
        if (!(cin >> v_ll)) finish(_pe, "Unexpected EOF reading final set");
        if (v_ll < 1 || v_ll > c) finish(_wa, "Final value out of range");
        int v = (int)v_ll;
        if (inB[v]) finish(_wa, "Final set contains duplicates");
        inB[v] = 1;
    }

    vector<int> G2(c + 1, 0);
    for (int d = 1; d <= c; d++) {
        int acc = 0;
        for (int m = d; m <= c; m += d) {
            if (inB[m]) acc ^= m;
        }
        G2[d] = acc;
    }
    vector<int> ans2(c + 1, 0);
    for (int d = 1; d <= c; d++) {
        if (!squarefree[d]) continue;
        int v = G2[d];
        if (v == 0) continue;
        for (int m = d; m <= c; m += d) {
            ans2[m] ^= v;
        }
    }

    for (int x = 1; x <= c; x++) {
        if (ans2[x] != ans_all[x]) finish(_wa, "Final set is not equivalent to hidden set");
    }

    finish(_ok, "OK");
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static void fyShuffle(vector<int> &v) {
    for (int i = (int)v.size() - 1; i > 0; --i) {
        int j = rnd.next(0, i);
        swap(v[i], v[j]);
    }
}

static vector<int> buildCaseNon(int c, int n, long long seed) {
    (void)seed;
    if (n == 0) return {};

    vector<int> pool(c);
    iota(pool.begin(), pool.end(), 1);
    fyShuffle(pool);
    pool.resize(n);
    return pool;
}

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");

    long long seed = 0;
    if (argc >= 2) {

        seed = atoll(argv[1]);
    }

    int cOpt = opt<int>("c", -1);
    int nOpt = opt<int>("n", -1);

    int c, n;

    if (cOpt != -1) c = cOpt;
    else {
        if (seed == 1) c = 100;
        else if (seed == 2) c = 1000000;
        else if (seed == 3) c = 1000000;
        else c = 1000000;
    }

    c = max(100, min(1000000, c));

    if (nOpt != -1) n = nOpt;
    else {
        if (seed == 1) n = 0;
        else n = min(c, 500000);
    }

    n = max(0, min(c, n));

    if (mode == "adp") {

        cout << c << " " << n << "\n";
        return 0;
    }

    vector<int> A = buildCaseNon(c, n, seed);
    if ((int)A.size() != n) {

        A.clear();
        for (int i = 1; i <= c && (int)A.size() < n; ++i) A.push_back(i);
    }

    cout << c << " " << n << "\n";
    if (n > 0) {
        for (int i = 0; i < n; ++i) {
            if (i) cout << ' ';
            cout << A[i];
        }
        cout << "\n";
    }
    return 0;
}


All problems in this contest share the same statement, the only difference is the test your solution runs on. For further information on scoring please refer to "Scoring" section of the statement.

This is an interactive problem.

Imagine you are a treasure hunter, a very skillful one. One day you came across an ancient map which could help you to become rich. The map shows multiple forestry roads, and at each junction there is a treasure. So, you start your journey hoping to retrieve all the hidden treasures, but you don't know yet that there is a wicked wizard standing against you and craving to tangle up these roads and impede your achievements.

The treasure map is represented as an undirected graph in which vertices correspond to junctions and edges correspond to roads. Your path begins at a certain fixed vertex with a label known to you. Every time you come to a vertex that you have not been to before, you dig up a treasure chest and put a flag in this vertex. At the initial vertex you'll find a treasure chest immediately and, consequently, you'll put a flag there immediately as well.

When you are standing at the junction you can see for each of the adjacent vertices its degree and if there is a flag there. There are no other things you can see from there. Besides, the power of the wicked wizard is so great that he is able to change the location of the roads and junctions on the map without changing the graph structure. Therefore, the sequence of the roads coming from the junction $v$ might be different each time you come in the junction $v$. However, keep in mind that the set of adjacent crossroads does not change, and you are well aware of previously dug treasures at each adjacent to $v$ vertex.

Your goal is to collect treasures from all vertices of the graph as fast as you can. Good luck in hunting!

Interaction

On the first line the interactor prints an integer $t$ ($1 \leq t \leq 5$) — the number of maps for which you need to solve the problem.

Then for each of the $t$ maps interactor firstly prints the graph description and after that interaction on this map starts. The map description is given in the following format.

The first line contains four integers $n, m, start, base\_move\_count$ ($2 \leq n \leq 300$, $1 \leq m \leq min(\frac{n(n-1)}{2}, 25n)$, $1 \leq start \leq n$, $1000 \leq base\_move\_count \leq 30000$) — the number of vertices and edges in the graph, the label of the vertex where you start the journey and some base move count, on which the score for the map depends. It's guaranteed that the jury has a solution traversing the map using not more than $base\_move\_count$ moves with high probability.

The next $m$ lines contain descriptions of the edges of the graph $u, v$ ($1 \leq u, v \leq n$, $u \neq v$). It is guaranteed that the graph is connected, does not contain multiple edges and the degrees of all vertices do not exceed 50.

You can find map descriptions for all tests in the archive 'map\_descriptions.zip' which you can find in any of the archives 'problem-X-materials.zip' in the section "Contest materials" — they are all the same.

After that the interaction begins. The interactor prints vertex descriptions in the following format:

R~d~deg\_1~flag\_1~deg\_2~flag\_2 \ldots deg\_d~flag\_d, where $d$ is the degree of the current vertex, $deg_i$ is the degree of the $i$-th vertex adjacent to the current one, and $flag_i$ (0 or 1) is an indicator if the $i$-th adjacent vertex contains a flag. The order of neighbors in the vertex description is chosen by the interactor uniformly at random independently each time. Please keep in mind that you are not given the actual labels of adajacent vertices.

In response to the description of the vertex you should print a single integer $i$ ($1 \leq i \leq d$), which means that you have chosen the vertex with description $deg_i~flag_i$. Remember to use the flush operation after each output. If your output is invalid, you will get a "Wrong Answer" verdict.

When you have visited all the vertices of the graph at least once, the interactor prints the string "AC" instead of the vertex description. If you use more than $2 \cdot base\_move\_count$ moves, the interactor prints the string "F". In both cases, you have to either start reading the description of the next map, or terminate the program, if it has been the last map in the test.

Below the example of interaction is presented. Note that the test from the example is not the same that your solution will be tested on.

```
|  |  |
| --- | --- |
| Interactor | Solution |
| 1 |  |
| 3 3 1 1000 |  |
| 1 2 |  |
| 2 3 |  |
| 3 1 |  |
| R 2 2 0 2 0 |  |
|  | 1 |
| R 2 2 0 2 1 |  |
|  | 2 |
| R 2 2 0 2 1 |  |
|  | 1 |
| AC |  |
```

Scoring

All problems of this contest share the same statement and differ only in the test. Each problem contains one test. Map descriptions for the test are available to look at in the archive.

Each test consists of several maps.

The solution score for the problem will be $0$ in case your solution for some map failed to get an answer "AC" or "F". If the solution correctly interacted with the interactor on all $t$ maps, the score for the task will be equal to the sum of the scores for each of the maps.

If you have successfully passed all vertices of a graph with $n$ vertices using $moves$ moves, the score for the map is calculated as follows. Denote

base\\_fraction=\frac{base\\_move\\_count + 1}{n},sol\\_fraction=\frac{moves+1}{n},c=\frac{90}{\sqrt{base\\_fraction - 1}}.

Then:

* if $moves \leq base\_move\_count$, you get $100-c \sqrt{sol\_fraction - 1}$ points.
* if $base\_move\_count < moves \leq 2 \cdot base\_move\_count$, you get $20 - \frac{10\cdot(moves + 1)}{base\_move\_count + 1}$ points.

If you use more than $2 \cdot base\_move\_count$ moves, you get 0 points for the map.

For each problem the solution with the highest score is chosen. Please note that the maximum is chosen for the entire test as a whole, not for each separate map.

The final result of the participant is the sum of points for each of the problems.

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long global_queries = 0;
static long long global_query_limit = 0;

void log_metrics() {
    try {
        tout << "queries=" << global_queries << endl;
        tout << "query_limit=" << global_query_limit << endl;
    } catch (...) {

    }
}

template <typename... Args>
void finish(TResult verdict, const char* fmt, Args... args) {
    log_metrics();
    quitf(verdict, fmt, args...);
}

int parse_int(const string& s) {
    try {
        size_t pos;
        int val = stoi(s, &pos);
        if (pos != s.size()) return -1;
        return val;
    } catch (...) {
        return -1;
    }
}

int main(int argc, char** argv) {

    registerInteraction(argc, argv);
    atexit(log_metrics);

    mt19937 rng(589214);

    int t = inf.readInt();

    cout << t << endl;

    for (int ti = 0; ti < t; ti++) {

        int n = inf.readInt();
        int m = inf.readInt();
        int start_node = inf.readInt();
        int base_move_count = inf.readInt();

        long long current_limit = 2LL * base_move_count;
        global_query_limit += current_limit;

        if (ti == 0) log_metrics();

        vector<pair<int, int>> edges;
        vector<vector<int>> adj(n + 1);
        vector<int> deg(n + 1, 0);

        for (int i = 0; i < m; i++) {
            int u = inf.readInt();
            int v = inf.readInt();
            edges.push_back({u, v});

            adj[u].push_back(v);
            adj[v].push_back(u);
            deg[u]++;
            deg[v]++;
        }

        cout << n << " " << m << " " << start_node << " " << base_move_count << endl;

        for (const auto& e : edges) {
            cout << e.first << " " << e.second << endl;
        }
        cout.flush();

        int current_u = start_node;
        vector<bool> visited(n + 1, false);
        visited[start_node] = true;
        int visited_count = 1;
        int moves = 0;

        while (true) {

            if (visited_count == n) {
                cout << "AC" << endl;
                break;
            }

            if (moves > current_limit) {
                cout << "F" << endl;
                break;
            }

            vector<int> neighbors = adj[current_u];
            shuffle(neighbors.begin(), neighbors.end(), rng);

            cout << "R " << deg[current_u];
            for (int v : neighbors) {
                cout << " " << deg[v] << " " << (visited[v] ? 1 : 0);
            }
            cout << endl;

            int choice;
            if (!(cin >> choice)) {
                finish(_wa, "Unexpected EOF while reading move");
            }

            if (choice < 1 || choice > (int)neighbors.size()) {
                finish(_wa, "Move index %d out of range [1, %d]", choice, (int)neighbors.size());
            }

            int next_u = neighbors[choice - 1];
            current_u = next_u;
            moves++;
            global_queries++;

            if (global_queries % 50 == 0) log_metrics();

            if (!visited[current_u]) {
                visited[current_u] = true;
                visited_count++;
            }
        }
    }

    finish(_ok, "Processed %d maps", t);
    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long total_queries = 0;
static long long total_query_limit = 0;

static void log_metrics() {

    try {
        tout << "queries=" << total_queries << endl;
        tout << "query_limit=" << total_query_limit << endl;
    } catch (...) {}
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int main(int argc, char** argv) {

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int t = inf.readInt(1, 5, "t");
    cout << t << endl;

    std::mt19937 rng(5489u);

    bool all_maps_ok = true;

    for (int ti = 0; ti < t; ++ti) {

        int n = inf.readInt(2, 300, "n");

        int m = inf.readInt(1, n * (n - 1) / 2, "m");
        int start = inf.readInt(1, n, "start");
        int base_move_count = inf.readInt(1000, 30000, "base_move_count");

        long long current_limit = 2LL * base_move_count;
        total_query_limit += current_limit;

        log_metrics();

        vector<vector<int>> adj(n + 1);
        vector<pair<int, int>> edges;
        edges.reserve(m);

        for (int i = 0; i < m; ++i) {
            int u = inf.readInt(1, n, "u");
            int v = inf.readInt(1, n, "v");
            adj[u].push_back(v);
            adj[v].push_back(u);
            edges.push_back({u, v});
        }

        cout << n << " " << m << " " << start << " " << base_move_count << endl;
        for (const auto& e : edges) {
            cout << e.first << " " << e.second << endl;
        }

        cout.flush();

        vector<bool> visited(n + 1, false);
        int visited_count = 0;
        int current_u = start;

        if (!visited[current_u]) {
            visited[current_u] = true;
            visited_count++;
        }

        long long moves = 0;
        bool map_solved = false;

        long long hard_cap = current_limit + 2000;

        while (true) {

            if (visited_count == n) {
                map_solved = true;
                break;
            }

            if (moves > current_limit) {
                break;
            }
            if (moves > hard_cap) {
                 finish(_pe, "Solution exceeded hard move cap (infinite loop?)");
            }

            vector<int> neighbors = adj[current_u];

            std::shuffle(neighbors.begin(), neighbors.end(), rng);

            cout << "R " << neighbors.size();
            for (int v : neighbors) {
                int deg = (int)adj[v].size();
                int flg = visited[v] ? 1 : 0;
                cout << " " << deg << " " << flg;
            }
            cout << endl;

            int choice;
            if (!(cin >> choice)) {

                finish(_wa, "Unexpected EOF or invalid input from solution");
            }

            if (choice < 1 || choice > (int)neighbors.size()) {
                finish(_wa, format("Invalid neighbor index %d, expected 1..%d", choice, (int)neighbors.size()));
            }

            current_u = neighbors[choice - 1];
            moves++;
            total_queries++;

            if (moves % 500 == 0) log_metrics();

            if (!visited[current_u]) {
                visited[current_u] = true;
                visited_count++;
            }
        }

        if (map_solved) {
            cout << "AC" << endl;
        } else {
            cout << "F" << endl;

            all_maps_ok = false;
        }
    }

    if (!all_maps_ok) {
        finish(_wa, "Failed to traverse at least one map within move limit");
    } else {
        finish(_ok, "All maps traversed successfully");
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");

    int t = 1;
    println(t);

    for (int ti = 0; ti < t; ti++) {
        int n;
        if (mode == "non") {

            n = rnd.next(2, 300);
        } else {

            n = rnd.next(200, 300);
        }

        vector<set<int>> adj(n);
        vector<int> deg(n, 0);

        auto try_add_edge = [&](int u, int v) {
            if (u == v) return false;
            if (adj[u].count(v)) return false;

            if (deg[u] >= 50 || deg[v] >= 50) return false;

            adj[u].insert(v);
            adj[v].insert(u);
            deg[u]++;
            deg[v]++;
            return true;
        };

        if (mode == "non") {

            vector<int> p(n);
            iota(p.begin(), p.end(), 0);
            shuffle(p.begin(), p.end());

            for (int i = 1; i < n; i++) {

                int parent = p[rnd.next(0, i - 1)];

                if (deg[parent] >= 50) {
                    for (int k = 0; k < i; k++) {
                        if (deg[p[k]] < 50) {
                            parent = p[k];
                            break;
                        }
                    }
                }

                if (deg[parent] < 50) {
                    try_add_edge(p[i], parent);
                }
            }

            long long max_m = min((long long)n * (n - 1) / 2, (long long)25 * n);

            int target_m = rnd.next(n - 1, (int)max_m);

            int current_m = 0;
            for(int i=0; i<n; ++i) current_m += deg[i];
            current_m /= 2;

            int fails = 0;
            while (current_m < target_m && fails < 1000) {
                int u = rnd.next(0, n - 1);
                int v = rnd.next(0, n - 1);
                if (try_add_edge(u, v)) {
                    current_m++;
                    fails = 0;
                } else {
                    fails++;
                }
            }

        } else {

            int k = rnd.next(3, 48);

            vector<int> p(n);
            iota(p.begin(), p.end(), 0);
            shuffle(p.begin(), p.end());

            for (int i = 0; i < n; i++) {
                try_add_edge(p[i], p[(i + 1) % n]);
            }

            vector<int> candidates(n);
            iota(candidates.begin(), candidates.end(), 0);

            int fails = 0;

            while (fails < 2000 && candidates.size() >= 2) {

                int idx1 = rnd.next(0, (int)candidates.size() - 1);
                int u = candidates[idx1];
                if (deg[u] >= k) {
                    candidates[idx1] = candidates.back();
                    candidates.pop_back();
                    continue;
                }

                int idx2 = rnd.next(0, (int)candidates.size() - 1);
                int v = candidates[idx2];
                if (u == v) continue;
                if (deg[v] >= k) {
                    candidates[idx2] = candidates.back();
                    candidates.pop_back();
                    continue;
                }

                if (try_add_edge(u, v)) {
                    fails = 0;
                } else {
                    fails++;
                }
            }
        }

        vector<pair<int, int>> edges;
        for (int u = 0; u < n; u++) {
            for (int v : adj[u]) {
                if (u < v) {
                    edges.push_back({u + 1, v + 1});
                }
            }
        }

        shuffle(edges.begin(), edges.end());

        int start = rnd.next(1, n);

        int base_move_count = rnd.next(1000, 3000);

        println(n, (int)edges.size(), start, base_move_count);
        for (const auto& e : edges) {
            println(e.first, e.second);
        }
    }

    return 0;
}