This is an interactive problem.

Given a directed acyclic graph (DAG) with $n$ vertices and $m$ edges, each edge has an associated weight.

There may be multiple paths between any pair of vertices $s$ and $t$ . We define the weight of a path as the product of the weights of all edges along that path. Let $f ( s , t , c )$ denote the sum of the path weights of all distinct paths from $s$ to $t$ after multiplying the weight of every edge in the graph by $c$ . Since the result can be extremely large, $f ( s , t , c )$ is taken modulo 998244353.

Xiao M will inform you of the structure of the DAG in advance (excluding the edge weights).

You may provide parameters $s$ , $t$ , and $c$ ; the interactor will return the value of $f ( s , t , c )$ . You are allowed to make at most 999 such queries to obtain certain information about the graph. After several query cycles, the interactor will provide a parameter $k$ , and you need to determine the value of $f ( 1 , n , k )$ .

# Input

The first line contains two positive integers $n$ and $m$ $1 \leq n \leq 1 0 0 0 , 1 \leq m \leq 5 0 0 0$ ), where $n$ represents the number of vertices in the graph and $m$ represents the number of edges.

In the following $m$ lines, each line contains two positive integers $x$ and $y$ $1 \leq x , y \leq 1 0 0 0 \rangle$ , indicating that there is a directed edge from vertex $x$ to vertex $y$ in the graph. It is guaranteed that the graph is a Directed Acyclic Graph (DAG).

# Interaction Protocol

For each query, you need to output in the format $\texttt { ? s t c } ( 1 \leq s , t \leq n , 0 \leq c < 9 9 8 2 4 4 3 5 3 )$ where $s , t , c$ are all integers, and the interactor will return the answer of $f ( s , t , c )$ .

When you are confident that the information you have is sufficient to answer the query, output !, and the interactor will return a integer parameter $k$ ( $0 \leq k < 9 9 8 2 4 4 3 5 3 $ , which means you are asked for the weight of $f ( 1 , n , k )$ .

You need to output the result of $f ( 1 , n , k )$ .

After printing a query or the answer, do not forget to output the end of the line and flush the output. Otherwise, you will get the verdict Idleness Limit Exceeded. To do this, use:

fflush(stdout) or cout.flush() in $\mathrm { C } + +$ ; System.out.flush() in Java; flush(output) in Pascal;
stdout.flush() in Python; see the documentation for other languages.

# Example

standard input	standard output

33	？121

12

23	？231

13

1	？131

2	！

12	31488

123

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

const int MOD = 998244353;
const long long QUERY_LIMIT = 999;
const long long HARD_CAP = 20000;

int N, M;
struct Edge {
    int v;
    int w;
};
vector<vector<Edge>> adj;
int K_param;
long long queries = 0;

vector<int> memo;

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 solve(int u, int target, int c) {
    if (u == target) return 1;
    if (memo[u] != -1) return memo[u];

    long long res = 0;
    for (const auto& e : adj[u]) {

        long long ew = (1LL * e.w * c) % MOD;
        if (ew == 0) continue;

        int val = solve(e.v, target, c);
        res = (res + ew * val) % MOD;
    }
    return memo[u] = res;
}

int get_f(int s, int t, int c) {
    if (s == t) return 1;

    fill(memo.begin(), memo.end(), -1);
    return solve(s, t, c);
}

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

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

    N = inf.readInt();
    M = inf.readInt();

    adj.resize(N + 1);
    memo.resize(N + 1);

    vector<pair<int, int>> structure;
    structure.reserve(M);

    for (int i = 0; i < M; ++i) {
        int u = inf.readInt();
        int v = inf.readInt();
        int w = inf.readInt();
        adj[u].push_back({v, w});
        structure.push_back({u, v});
    }
    K_param = inf.readInt();

    cout << N << " " << M << endl;
    for (const auto& p : structure) {
        cout << p.first << " " << p.second << endl;
    }
    cout.flush();

    log_metrics();

    while (true) {

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

        string token;

        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF (expected '?' or '!')");
        }

        if (token == "!") {

            cout << K_param << endl;

            int user_ans;
            if (!(cin >> user_ans)) {
                finish(_wa, "Failed to read answer after '!'");
            }

            int correct_ans = get_f(1, N, K_param);
            if (user_ans == correct_ans) {
                finish(_ok, "Correct answer");
            } else {
                finish(_wa, format("Wrong answer: expected %d, got %d", correct_ans, user_ans));
            }
        } else {

            int s, t, c;

            if (token == "?") {
                if (!(cin >> s >> t >> c)) {
                    finish(_wa, "Invalid query format");
                }
            } else {

                try {
                    s = stoi(token);
                } catch (...) {
                    finish(_wa, "Invalid token (expected integer, '?', or '!')");
                }
                if (!(cin >> t >> c)) {
                    finish(_wa, "Invalid query format (expected t c)");
                }
            }

            if (s < 1 || s > N || t < 1 || t > N) {
                finish(_wa, format("Query vertices out of range: %d %d", s, t));
            }
            if (c < 0 || c >= MOD) {
                finish(_wa, format("Query constant out of range: %d", c));
            }

            queries++;

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

            int ans = get_f(s, t, c);
            cout << ans << endl;
        }
    }

    return 0;
}

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

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

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());
}

const int MOD = 998244353;

struct Edge {
    int to;
    int w;
};

int n, m;
vector<vector<Edge>> adj;
vector<int> topo_order;
int K_param;

void compute_topo() {
    vector<int> in_degree(n + 1, 0);
    for (int u = 1; u <= n; u++) {
        for (const auto& e : adj[u]) {
            in_degree[e.to]++;
        }
    }
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        if (in_degree[i] == 0) q.push(i);
    }
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        topo_order.push_back(u);
        for (const auto& e : adj[u]) {
            in_degree[e.to]--;
            if (in_degree[e.to] == 0) q.push(e.to);
        }
    }
}

int solve(int s, int t, int c) {
    if (s == t) return 1;

    static vector<int> dp;
    if ((int)dp.size() <= n) dp.resize(n + 1);
    fill(dp.begin(), dp.end(), 0);

    dp[s] = 1;

    for (int u : topo_order) {
        if (dp[u] == 0) continue;

        long long current_val = dp[u];
        for (const auto& e : adj[u]) {
            long long edge_contribution = (1LL * e.w * c) % MOD;
            long long add = (current_val * edge_contribution) % MOD;
            dp[e.to] = (dp[e.to] + add) % MOD;
        }
    }

    return dp[t];
}

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

    n = inf.readInt(1, 1000, "n");
    m = inf.readInt(1, 5000, "m");
    inf.readEoln();

    adj.resize(n + 1);
    vector<pair<int, int>> edges;
    for (int i = 0; i < m; i++) {
        int u = inf.readInt(1, n, "u");
        inf.readSpace();
        int v = inf.readInt(1, n, "v");
        inf.readSpace();
        int w = inf.readInt(0, MOD - 1, "w");
        inf.readEoln();
        adj[u].push_back({v, w});
        edges.push_back({u, v});
    }
    K_param = inf.readInt(0, MOD - 1, "K");

    compute_topo();

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

    log_metrics();

    int hard_cap = 15000;

    while (true) {
        if (queries > hard_cap) {
            finish(_pe, "Hard query limit exceeded");
        }

        string type;
        if (!(cin >> type)) {
            finish(_pe, "Unexpected end of input from contestant");
        }

        if (type == "?") {
            queries++;
            if (queries % 50 == 0) log_metrics();

            int s, t, c;
            if (!(cin >> s >> t >> c)) finish(_pe, "Invalid query format");

            if (s < 1 || s > n || t < 1 || t > n || c < 0 || c >= MOD) {
                finish(_pe, "Query parameters out of range");
            }

            int ans = solve(s, t, c);
            cout << ans << endl;
        }
        else if (type == "!") {
            cout << K_param << endl;

            int ans;
            if (!(cin >> ans)) finish(_pe, "Expected answer after !");

            int expected = solve(1, n, K_param);
            if (ans == expected) finish(_ok, "Correct");
            else finish(_wa, format("Expected %d, found %d", expected, ans));
        }
        else {
            finish(_pe, format("Unknown query type '%s'", type.c_str()));
        }
    }

    return 0;
}

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

const int MOD = 998244353;

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

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

    if (n == -1) {

        int t = rnd.next(100);
        if (t < 5) n = rnd.next(2, 5);
        else if (t < 15) n = rnd.next(6, 20);
        else if (t < 40) n = rnd.next(21, 100);
        else n = rnd.next(900, 1000);
    }

    n = max(n, 2);

    long long max_edges = 1LL * n * (n - 1) / 2;
    int limit_m = (int)min((long long)5000, max_edges);

    if (m == -1) {
        int t = rnd.next(100);
        if (t < 20) m = rnd.next(1, (int)min((long long)n * 2, (long long)limit_m));
        else if (t < 50) m = rnd.next(1, limit_m);
        else m = rnd.next(max(1, limit_m - (int)min((long long)2000, max_edges/2)), limit_m);
    }
    m = max(1, min(m, limit_m));

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

    if (rnd.next(10) > 0) {
        int pos1 = -1, posn = -1;
        for(int i=0; i<n; ++i) {
            if (p[i] == 1) pos1 = i;
            if (p[i] == n) posn = i;
        }
        if (pos1 > posn) swap(p[pos1], p[posn]);
    }

    set<pair<int,int>> edges_set;

    int pos1 = -1, posn = -1;
    for(int i=0; i<n; ++i) {
        if (p[i] == 1) pos1 = i;
        if (p[i] == n) posn = i;
    }

    if (pos1 != -1 && posn != -1 && pos1 < posn) {
        int curr = pos1;

        while(curr != posn && (int)edges_set.size() < m) {
            int next_node = posn;

            if (posn - curr > 1) {

                int jump_range = min(posn - curr, 10);
                if (rnd.next(5) == 0) jump_range = posn - curr;
                int jump = rnd.next(1, jump_range);
                next_node = curr + jump;
            }
            edges_set.insert({p[curr], p[next_node]});
            curr = next_node;
        }
    }

    if (m > max_edges / 2) {

        vector<pair<int,int>> cands;
        cands.reserve(max_edges);
        for(int i=0; i<n; ++i) {
            for(int j=i+1; j<n; ++j) {
                if (!edges_set.count({p[i], p[j]})) {
                    cands.push_back({p[i], p[j]});
                }
            }
        }
        shuffle(cands.begin(), cands.end());
        for(auto &e : cands) {
            if ((int)edges_set.size() == m) break;
            edges_set.insert(e);
        }
    } else {

        while((int)edges_set.size() < m) {
            int u = rnd.next(0, n - 2);
            int v = rnd.next(u + 1, n - 1);
            edges_set.insert({p[u], p[v]});
        }
    }

    vector<tuple<int,int,int>> final_edges;
    final_edges.reserve(m);

    for(auto &e : edges_set) {
        int w;
        if (mode == "adp") {

            int type = rnd.next(100);
            if (type < 15) w = 0;
            else if (type < 30) w = 1;
            else if (type < 35) w = MOD - 1;
            else w = rnd.next(MOD);
        } else {

            w = rnd.next(MOD);
        }
        final_edges.emplace_back(e.first, e.second, w);
    }

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

    int k = rnd.next(MOD);

    cout << n << " " << m << "\n";
    for(auto &[u, v, w] : final_edges) {
        cout << u << " " << v << " " << w << "\n";
    }
    cout << k << "\n";

    return 0;
}


You, a young astronomer, are interested in the spatial arrangement of a set of stars with distinctive features. Knowing this might contribute to the understanding of early-universe cosmology. You can perform measurements using a specialized instrument for this purpose.

The instrument uses its own three-dimensional Cartesian coordinate system, in which the origin $( 0 , 0 , 0 )$ is set on Earth, and the positions of the stars are modeled as lattice points (points whose coordinates are all integers). You already know the distances to all the stars of interest from Earth, but their directions are unknown.

In a single measurement, you specify two distinct stars, and the instrument reports the distance between them. Note that the instrument does not report the absolute or relative directions of the stars.

Determine the distances between all pairs of the stars within the limited number of measurements.

# Interaction

The first line of input contains an integer $n$ , the number of stars of interest $2 \leq n \leq 1 0 0 )$ ). The stars are numbered from 1 to $n$ . The second line contains $n$ integers. The $i$ -th of them is the squared distance from the origin to star $i$ . It is guaranteed that all stars have integer coordinates, each between $- 4 0 0 0$ and 4000, inclusive. No two stars are at the same position. No star is at the origin.

After reading in these two lines, you may start measurements. To measure the distance between stars $i$ and $j$ , write a line of the form “measure i $j ^ {  }$ , where $i$ and $j$ are distinct integers between 1 and $n$ , inclusive. In response, an input line containing an integer denoting the squared distance between stars $i$ and $j$ becomes available. You can perform up to 300 measurements.

When you have determined the distances between all pairs of the stars, write a line containing only answer, followed by $n - 1$ lines of the following format.

$$
\begin{array} { l } { d _ { 1 , 2 } \ d _ { 1 , 3 } \cdot \cdot \cdot \ d _ { 1 , n } } \\ { d _ { 2 , 3 } \cdot \cdot \cdot \ d _ { 2 , n } } \\ { \vdots } \\ { d _ { n - 1 , n } } \end{array}
$$

Here, $d _ { i , j }$ $1 \leq i < j \leq n )$ is an integer denoting the squared distance between stars $i$ and $j$ . Note that you do not need to determine the stars’ coordinates. After writing these lines, the interaction stops, and your program must terminate without any extra output.

If your output does not conform to the specifications above, or if the number of measurements exceeds 300, your submission will be judged as a wrong answer.

The coordinates of the stars are fixed before the interaction starts; they do not change during the interaction.

You are provided with a command-line tool for local testing. For more details, refer to the clarifications in the contest system.

![](images/001161dfce019aa030296ebf135f8e15920cf3265b3635dd3b1faa04e10f89c7.jpg)

In Sample Interaction 1, the stars’ coordinates can be as follows:

• star 1 is at $( 1 , 0 , 0 )$ , • star 2 is at $( - 1 , - 1 , 3 )$ , and • star 3 is at $( - 2 , 0 , 0 )$ .

The distance between stars 1 and 2 is $\sqrt { 1 4 }$ . In the first measurement, the squared distance, 14, is returned.

![](images/50f45462b7f92cd3b88fe7049446a4a418a7aac75e7d55b8ba13bf5296299c6b.jpg)
Figure F.1. Illustration of Sample Interaction 1

Write

answer

191728099 2 191824043

191760077 12

191856029

Read Sample Interaction 3	Write

5

14950149

	answer

51045162

13 38 181

29206

371

In Sample Interaction 2, the stars’ coordinates can be as follows:

• star 1 is at $\left( - 3 9 9 8 , - 3 9 9 8 , - 3 9 9 7 \right)$ , • star 2 is at (3997, 3997, 3996), • star 3 is at $\left( - 3 9 9 9 , - 3 9 9 8 , - 3 9 9 8 \right)$ , and • star 4 is at (3999, 3999, 3998).

In Sample Interaction 3, the stars’ coordinates can be as follows:

• star 1 is at $( 1 , 0 , 0 )$ , • star 2 is at $( 0 , - 2 , 0 )$ , • star 3 is at $( 0 , 0 , 3 )$ , • star 4 is at $( 3 , - 4 , 5 )$ , and • star 5 is at $\left( - 6 , 7 , - 8 \right)$ .

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

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

struct Point {
    long long x, y, z;
};
int n;
vector<Point> stars;

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

    }
}

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

long long distSq(int i, int j) {
    long long dx = stars[i].x - stars[j].x;
    long long dy = stars[i].y - stars[j].y;
    long long dz = stars[i].z - stars[j].z;
    return dx * dx + dy * dy + dz * dz;
}

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

    n = inf.readInt(2, 100, "n");
    stars.resize(n + 1);
    for (int i = 1; i <= n; ++i) {
        stars[i].x = inf.readLong(-4000LL, 4000LL, "x");
        stars[i].y = inf.readLong(-4000LL, 4000LL, "y");
        stars[i].z = inf.readLong(-4000LL, 4000LL, "z");
    }

    cout << n << endl;
    for (int i = 1; i <= n; ++i) {
        long long d2 = stars[i].x * stars[i].x + stars[i].y * stars[i].y + stars[i].z * stars[i].z;
        cout << d2 << (i == n ? "" : " ");
    }
    cout << endl;

    while (true) {

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

        if (queries > 200000) {
            finish(_pe, "Hard query limit exceeded.");
        }

        string token;

        if (!(cin >> token)) {
            finish(_pe, "Unexpected EOF waiting for command.");
        }

        bool is_query = false;
        bool is_answer = false;
        int u = -1, v = -1;

        if (token == "measure" || token == "?") {
            if (!(cin >> u >> v)) finish(_pe, "Unexpected EOF reading query arguments.");
            is_query = true;
        } else if (token == "answer" || token == "!") {
            is_answer = true;
        } else {

            try {
                size_t idx;
                u = stoi(token, &idx);
                if (idx != token.size()) throw exception();
            } catch (...) {
                finish(_pe, "Invalid token: '" + token + "'. Expected 'measure', 'answer', or star index.");
            }
            if (!(cin >> v)) finish(_pe, "Unexpected EOF reading second star index.");
            is_query = true;
        }

        if (is_answer) {

            long long processed = 0;
            for (int i = 1; i < n; ++i) {
                for (int j = i + 1; j <= n; ++j) {
                    string valToken;
                    if (!(cin >> valToken)) {
                        finish(_pe, "Unexpected EOF reading answer values.");
                    }

                    if (processed == 0 && valToken == "answer") {
                         if (!(cin >> valToken)) finish(_pe, "Unexpected EOF after 'answer'.");
                    }

                    long long userDist;
                    try {
                        userDist = stoll(valToken);
                    } catch (...) {
                        finish(_pe, "Invalid number in answer: '" + valToken + "'.");
                    }

                    long long trueDist = distSq(i, j);
                    if (userDist != trueDist) {
                        finish(_wa, format("Wrong distance for pair (%d,%d). Expected %lld, got %lld.", i, j, trueDist, userDist));
                    }
                    processed++;
                }
            }

            finish(_ok, format("Correct! Queries used: %lld.", queries));
        }

        if (is_query) {
            queries++;

            if (u < 1 || u > n || v < 1 || v > n) {
                finish(_pe, format("Star index out of bounds: %d %d (N=%d).", u, v, n));
            }
            if (u == v) {
                finish(_pe, format("Cannot measure distance to itself: %d.", u));
            }

            cout << distSq(u, v) << endl;
        }
    }

    return 0;
}

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

using namespace std;

const int MAX_C = 4000;
const int MIN_C = -4000;

struct Point {
    int x, y, z;
    long long normSq() const {
        return 1LL * x * x + 1LL * y * y + 1LL * z * z;
    }
    bool operator<(const Point& other) const {
        return tie(x, y, z) < tie(other.x, other.y, other.z);
    }
    bool operator==(const Point& other) const {
        return tie(x, y, z) == tie(other.x, other.y, other.z);
    }
};

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

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

    long long seedVal = 0;
    if (argc > 1) {
        try {
            seedVal = stoll(argv[1]);
        } catch (...) {
            seedVal = 0;
        }
    }

    int n;

    if (seedVal == 1) n = 2;
    else if (seedVal == 2) n = 100;
    else if (seedVal == 3) n = 100;
    else {

        if (rnd.next(3) == 0) n = rnd.next(2, 100);
        else n = rnd.next(90, 100);
    }

    if (mode == "adp") n = 100;

    int strategy = 0;

    if (mode == "adp") {

        strategy = rnd.next(1, 2);
    } else {
        if (seedVal == 1) strategy = 0;
        else if (seedVal == 3) strategy = 1;
        else if (seedVal == 4) strategy = 2;
        else if (seedVal == 5) strategy = 3;
        else strategy = rnd.next(0, 3);
    }

    vector<Point> result;
    set<Point> used;

    if (strategy == 1) {
        map<long long, vector<Point>> buckets;

        int range = 250;
        int max_ops = 3000000;
        bool found = false;

        for (int k = 0; k < max_ops; k++) {
            int x = rnd.next(-range, range);
            int y = rnd.next(-range, range);
            int z = rnd.next(-range, range);
            if (x == 0 && y == 0 && z == 0) continue;

            Point p = {x, y, z};
            long long d = p.normSq();
            buckets[d].push_back(p);

            if (buckets[d].size() >= (size_t)n + 5) {
                sort(buckets[d].begin(), buckets[d].end());
                buckets[d].erase(unique(buckets[d].begin(), buckets[d].end()), buckets[d].end());
                if (buckets[d].size() >= (size_t)n) {
                    for (int i = 0; i < n; i++) result.push_back(buckets[d][i]);
                    found = true;
                    break;
                }
            }
        }
        if (!found) strategy = 0;
    }

    if (result.empty()) {
        int cx = 0, cy = 0, cz = 0;

        if (strategy == 3) {
            cx = rnd.next(2000, 3500) * (rnd.next(0, 1) ? 1 : -1);
            cy = rnd.next(2000, 3500) * (rnd.next(0, 1) ? 1 : -1);
            cz = rnd.next(2000, 3500) * (rnd.next(0, 1) ? 1 : -1);
        }

        while (result.size() < (size_t)n) {
            int x, y, z;
            if (strategy == 2) {
                z = 0;
                x = rnd.next(MIN_C, MAX_C);
                y = rnd.next(MIN_C, MAX_C);
            } else if (strategy == 3) {
                int r = 100;
                x = cx + rnd.next(-r, r);
                y = cy + rnd.next(-r, r);
                z = cz + rnd.next(-r, r);

                x = max(MIN_C, min(MAX_C, x));
                y = max(MIN_C, min(MAX_C, y));
                z = max(MIN_C, min(MAX_C, z));
            } else {
                x = rnd.next(MIN_C, MAX_C);
                y = rnd.next(MIN_C, MAX_C);
                z = rnd.next(MIN_C, MAX_C);
            }

            if (x == 0 && y == 0 && z == 0) continue;
            Point p = {x, y, z};
            if (used.find(p) == used.end()) {
                used.insert(p);
                result.push_back(p);
            }
        }
    }

    cout << n << endl;
    shuffle(result.begin(), result.end());
    for (const auto& p : result) {
        cout << p.x << " " << p.y << " " << p.z << endl;
    }

    return 0;
}


This is an interactive problem.

Vasya and Petya are going to play the following game: Petya has some positive integer number $a$. After that Vasya should guess this number using the following questions. He can say a pair of non-negative integer numbers $(x, y)$. Petya will answer him:

* "x", if $(x \bmod a) \geq (y \bmod a)$.
* "y", if $(x \bmod a) < (y \bmod a)$.

We define $(x \bmod a)$ as a remainder of division $x$ by $a$.

Vasya should guess the number $a$ using no more, than 60 questions.

It's guaranteed that Petya has a number, that satisfies the inequality $1 \leq a \leq 10^9$.

Help Vasya playing this game and write a program, that will guess the number $a$.

Interaction

Your program should play several games.

Before the start of any game your program should read the string:

* "start" (without quotes) — the start of the new game.
* "mistake" (without quotes) — in the previous game, you found the wrong answer. Your program should terminate after reading this string and it will get verdict "Wrong answer".
* "end" (without quotes) — all games finished. Your program should terminate after reading this string.

After reading the string "start" (without quotes) the new game starts.

At the beginning, your program should ask several questions about pairs of non-negative integer numbers $(x, y)$. You can only ask the numbers, that satisfy the inequalities $0 \leq x, y \leq 2 \cdot 10^9$. To ask a question print "? x y" (without quotes). As the answer, you should read one symbol:

* "x" (without quotes), if $(x \bmod a) \geq (y \bmod a)$.
* "y" (without quotes), if $(x \bmod a) < (y \bmod a)$.
* "e" (without quotes) — you asked more than $60$ questions. Your program should terminate after reading this string and it will get verdict "Wrong answer".

After your program asked several questions your program should print the answer in form "! a" (without quotes). You should print the number $a$ satisfying the inequalities $1 \leq a \leq 10^9$. It's guaranteed that Petya's number $a$ satisfied this condition. After that, the current game will finish.

We recall that your program can't ask more than $60$ questions during one game.

If your program doesn't terminate after reading "mistake" (without quotes), "end" (without quotes) or "e" (without quotes), it can get any verdict, because it will continue reading from closed input. Also, if your program prints answer or question in the incorrect format it can get any verdict, too. Be careful.

Don't forget to flush the output after printing questions and answers.

To flush the output, you can use:

* fflush(stdout) in C++.
* System.out.flush() in Java.
* stdout.flush() in Python.
* flush(output) in Pascal.
* See the documentation for other languages.

It's guaranteed that you should play at least $1$ and no more than $100$ games.

Example

Input

```
start
x
x
start
x
x
y
start
x
x
y
y
end
```

Output

```
? 0 0
? 10 1
! 1
? 0 0
? 3 4
? 2 5
! 2
? 2 4
? 2 5
? 3 10
? 9 1
! 3
```

Note

In the first test, you should play $3$ games with Petya's numbers $1$, $2$ and $3$.

In the first game, Petya will answer "x" (without quotes) to any question, because $(x \bmod 1) = 0$ for any integer $x$.

In the second game, if you will ask pair $(0, 0)$, the answer will be "x" (without quotes), because $(0 \bmod 2) \geq (0 \bmod 2)$. But if you will ask pair $(2, 5)$, the answer will be "y" (without quotes), because $(2 \bmod 2) < (5 \bmod 2)$, because $(2 \bmod 2) = 0$ and $(5 \bmod 2) = 1$.

#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 bool parseLongLong(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    bool neg = false;
    if (s[i] == '+' || s[i] == '-') {
        neg = (s[i] == '-');
        i++;
        if (i == (int)s.size()) return false;
    }
    __int128 val = 0;
    for (; i < (int)s.size(); i++) {
        char c = s[i];
        if (c < '0' || c > '9') return false;
        val = val * 10 + (c - '0');
        if (val > (__int128)LLONG_MAX + 1) return false;
    }
    if (neg) val = -val;
    if (val < (__int128)LLONG_MIN || val > (__int128)LLONG_MAX) return false;
    out = (long long)val;
    return true;
}

static string readTokenOrPE(const string& what) {
    string t;
    if (!(cin >> t)) finish(_pe, "Unexpected EOF while reading " + what);
    return t;
}

static long long readLLOrPE(const string& what) {
    string s = readTokenOrPE(what);
    long long v = 0;
    if (!parseLongLong(s, v)) finish(_pe, "Malformed integer for " + what);
    return v;
}

static void sendLine(const string& s) {
    cout << s << "\n";
    cout.flush();
}

static void play_one_game(long long a, bool last_game, long long hard_cap) {
    sendLine("start");

    long long game_queries = 0;

    while (true) {
        string cmd = readTokenOrPE("command");

        if (cmd == "?") {
            long long x = readLLOrPE("x");
            long long y = readLLOrPE("y");

            if (x < 0 || y < 0 || x > 2000000000LL || y > 2000000000LL) {
                finish(_pe, "Query numbers out of allowed range");
            }

            queries++;
            game_queries++;
            if (queries > hard_cap) finish(_pe, "Hard cap exceeded (too many queries)");

            long long rx = x % a;
            long long ry = y % a;
            char ans = (rx >= ry) ? 'x' : 'y';
            cout << ans << "\n";
            cout.flush();
        } else if (cmd == "!") {
            long long guess = readLLOrPE("answer");
            if (guess < 1 || guess > 1000000000LL) finish(_pe, "Answer out of allowed range");

            if (guess != a) {
                sendLine("mistake");
                finish(_wa, "Wrong guessed a");
            }

            if (last_game) {
                sendLine("end");
                finish(_ok, "OK");
            }
            return;
        } else {
            finish(_pe, "Invalid command token");
        }
    }
}

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

    int T = inf.readInt(1, 100, "T");
    vector<long long> a(T);
    for (int i = 0; i < T; i++) {
        a[i] = inf.readLong(1LL, 1000000000LL, "a");
    }

    query_limit = 60LL * T;
    log_metrics();

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

    for (int i = 0; i < T; i++) {
        play_one_game(a[i], i + 1 == T, hard_cap);
    }

    finish(_ok, "OK");
}

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

struct Interval {
    int l, r;
};

static long long queries = 0;
static long long query_limit = 0;
static long long hard_cap = 200000;

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 bool parseLongLongStrict(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    bool neg = false;
    if (s[0] == '-') {
        neg = true;
        i = 1;
    }
    if (i == (int)s.size()) return false;
    for (int j = i; j < (int)s.size(); j++) {
        if (s[j] < '0' || s[j] > '9') return false;
    }
    if ((int)s.size() > 20) return false;
    try {
        size_t pos = 0;
        long long v = stoll(s, &pos, 10);
        if (pos != s.size()) return false;
        out = v;
        (void)neg;
        return true;
    } catch (...) {
        return false;
    }
}

static long long floor_div(long long a, long long b_pos) {

    if (b_pos <= 0) throw runtime_error("floor_div: non-positive denominator");
    long long q = a / b_pos;
    long long r = a % b_pos;
    if (r != 0 && a < 0) q -= 1;
    return q;
}

static long long ceil_div(long long a, long long b_pos) {

    if (b_pos <= 0) throw runtime_error("ceil_div: non-positive denominator");
    return -floor_div(-a, b_pos);
}

static void addInterval(vector<Interval>& v, long long l, long long r) {
    if (l > r) return;
    if (l < 1) l = 1;
    if (r > 1000000000LL) r = 1000000000LL;
    if (l > r) return;
    int L = (int)l, R = (int)r;
    if (!v.empty() && (long long)v.back().r + 1 >= L) {
        v.back().r = max(v.back().r, R);
    } else {
        v.push_back({L, R});
    }
}

static long long countIntegers(const vector<Interval>& v) {
    long long s = 0;
    for (const auto& it : v) {
        s += (long long)it.r - (long long)it.l + 1LL;
    }
    return s;
}

static vector<Interval> filterByAnswer(const vector<Interval>& feasible, long long x, long long y, bool wantX) {
    vector<Interval> res;
    res.reserve(feasible.size());

    for (const auto& seg : feasible) {
        long long L = seg.l, R = seg.r;
        long long a = L;
        while (a <= R) {
            long long qx = (a <= x ? x / a : 0);
            long long qy = (a <= y ? y / a : 0);

            long long nextX = (qx == 0 ? R : min(R, x / qx));
            long long nextY = (qy == 0 ? R : min(R, y / qy));
            long long segR = min(nextX, nextY);

            long long dV = x - y;
            long long dQ = qx - qy;

            long long takeL = 1, takeR = 0;
            if (wantX) {

                if (dQ == 0) {
                    if (dV >= 0) {
                        takeL = a;
                        takeR = segR;
                    }
                } else if (dQ > 0) {
                    if (dV >= 0) {
                        long long ub = floor_div(dV, dQ);
                        takeL = a;
                        takeR = min(segR, ub);
                    }
                } else {
                    long long p = -dQ;
                    long long lb = ceil_div(-dV, p);
                    takeL = max(a, lb);
                    takeR = segR;
                }
            } else {

                if (dQ == 0) {
                    if (dV < 0) {
                        takeL = a;
                        takeR = segR;
                    }
                } else if (dQ > 0) {
                    long long lb = floor_div(dV, dQ) + 1;
                    takeL = max(a, lb);
                    takeR = segR;
                } else {
                    long long p = -dQ;
                    long long N = -dV;
                    if (N > 0) {
                        long long ub = floor_div(N - 1, p);
                        takeL = a;
                        takeR = min(segR, ub);
                    }
                }
            }

            if (takeL <= takeR) addInterval(res, takeL, takeR);

            if (segR == R) break;
            a = segR + 1;
        }
    }

    return res;
}

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

    int T = inf.readInt();
    if (T < 1 || T > 100) finish(_pe, "bad T in input");

    string dummy = inf.readLine();

    vector<pair<int,int>> ranges;
    ranges.reserve(T);
    for (int i = 0; i < T; i++) {
        string line;
        do {
            if (inf.eof()) finish(_pe, "unexpected EOF while reading games");
            line = inf.readLine();
        } while (line.size() == 0);

        stringstream ss(line);
        long long a, b;
        if (!(ss >> a)) finish(_pe, "bad game line (no number)");
        if (ss >> b) {

        } else {

            b = a;
        }

        if (a < 1) a = 1;
        if (b < 1) b = 1;
        if (a > 1000000000LL) a = 1000000000LL;
        if (b > 1000000000LL) b = 1000000000LL;
        if (a > b) swap(a, b);
        ranges.push_back({(int)a, (int)b});
    }

    query_limit = 60LL * (long long)T;
    hard_cap = max(200000LL, 10LL * query_limit);

    log_metrics();

    for (int game = 0; game < T; game++) {
        cout << "start" << endl;

        vector<Interval> feasible;
        feasible.push_back({ranges[game].first, ranges[game].second});

        for (;;) {
            string cmd;
            if (!(cin >> cmd)) finish(_pe, "unexpected EOF from contestant");

            if (cmd == "?") {
                string sx, sy;
                if (!(cin >> sx >> sy)) finish(_pe, "bad query format");
                long long x, y;
                if (!parseLongLongStrict(sx, x) || !parseLongLongStrict(sy, y)) finish(_pe, "non-integer in query");
                if (x < 0 || y < 0 || x > 2000000000LL || y > 2000000000LL) finish(_pe, "query out of range");

                queries++;
                if (queries > hard_cap) finish(_pe, "too many queries (hard cap exceeded)");

                if (feasible.empty()) finish(_pe, "internal error: empty feasible set");

                vector<Interval> keepX = filterByAnswer(feasible, x, y, true);
                vector<Interval> keepY = filterByAnswer(feasible, x, y, false);

                long long cntX = countIntegers(keepX);
                long long cntY = countIntegers(keepY);

                if (cntX == 0 && cntY == 0) finish(_pe, "internal error: both branches empty");

                char ans;
                if (cntX > cntY) {
                    ans = 'x';
                    feasible.swap(keepX);
                } else if (cntY > cntX) {
                    ans = 'y';
                    feasible.swap(keepY);
                } else {

                    ans = (cntX > 0 ? 'x' : 'y');
                    if (ans == 'x') feasible.swap(keepX);
                    else feasible.swap(keepY);
                }

                cout << ans << endl;

                log_metrics();
            } else if (cmd == "!") {
                string sa;
                if (!(cin >> sa)) finish(_pe, "bad answer format");
                long long guess;
                if (!parseLongLongStrict(sa, guess)) finish(_pe, "non-integer answer");
                if (guess < 1 || guess > 1000000000LL) finish(_pe, "answer out of range");
                if (feasible.empty()) finish(_pe, "internal error: empty feasible set at answer");

                bool ok = false;
                if (feasible.size() == 1 && feasible[0].l == feasible[0].r && feasible[0].l == (int)guess) {
                    ok = true;
                }

                if (!ok) finish(_wa, "answer is not uniquely determined / wrong under some feasible instance");
                break;
            } else {
                finish(_pe, "unknown command token");
            }
        }
    }

    cout << "end" << endl;
    finish(_ok, "all games finished");
}

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

static long long clampA(long long a) {
    if (a < 1) return 1;
    if (a > 1000000000LL) return 1000000000LL;
    return a;
}

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]);

    if (mode == "non") {
        int T = opt<int>("t", (seed >= 1 && seed <= 3) ? 9 : 99);
        if (T < 1) T = 1;
        if (T > 99) T = 99;

        vector<long long> a;
        a.reserve(T);

        vector<long long> preset;
        if (seed == 1) {
            preset = {1, 2, 3, 4, 5, 999999937LL, 1000000000LL, 536870912LL, 268435455LL};
        } else if (seed == 2) {
            preset = {1, 6, 7, 8, 9, 10, 536870912LL, 536870913LL, 999999937LL};
        } else if (seed == 3) {
            preset = {1, 2, 999983LL, 720720LL, 500000000LL, 500000001LL, 999999929LL, 999999937LL, 1000000000LL};
        } else {
            preset = {
                1, 2, 3, 4, 5, 7, 8, 9, 10,
                999999937LL, 999999929LL, 1000000000LL,
                536870912LL, 268435455LL, 268435456LL, 268435457LL,
                500000000LL, 500000001LL, 999983LL, 720720LL
            };
        }

        unordered_set<long long> used;
        used.reserve((size_t)T * 2 + 64);

        for (long long v : preset) {
            if ((int)a.size() >= T) break;
            v = clampA(v);
            if (!used.count(v)) {
                used.insert(v);
                a.push_back(v);
            }
        }

        int attempts = 0;
        while ((int)a.size() < T && attempts < 200000) {
            ++attempts;
            int typ = rnd.next(0, 3);
            long long v = 1;

            if (typ == 0) {

                v = rnd.next(1LL, 1000LL);
            } else if (typ == 1) {

                int k = rnd.next(0, 29);
                v = (1LL << k);
                long long delta = rnd.next(-3LL, 3LL);
                v = clampA(v + delta);
            } else if (typ == 2) {

                v = 1000000000LL - rnd.next(0LL, 300000LL);
                v = clampA(v);
            } else {

                v = rnd.next(1LL, 1000000000LL);
            }

            if (!used.count(v)) {
                used.insert(v);
                a.push_back(v);
            }
        }

        while ((int)a.size() < T) a.push_back(1);

        cout << T << "\n";
        for (int i = 0; i < T; i++) {
            cout << a[i] << "\n";
        }
        return 0;
    }

    if (mode == "adp") {
        int T = opt<int>("t", (seed >= 1 && seed <= 3) ? 8 : 100);
        if (T < 1) T = 1;
        if (T > 100) T = 100;

        long long defL = opt<long long>("l", 1LL);
        long long defR = opt<long long>("r", 1000000000LL);
        if (defL < 1) defL = 1;
        if (defR > 1000000000LL) defR = 1000000000LL;
        if (defL > defR) swap(defL, defR);

        vector<pair<long long, long long>> ranges;
        ranges.reserve(T);

        if (seed == 1) {
            vector<pair<long long, long long>> p = {
                {1, 1}, {2, 2}, {1000000000LL, 1000000000LL}, {999999937LL, 999999937LL},
                {1, 2}, {536870912LL, 536870912LL}, {268435455LL, 268435455LL}, {1, 1000000000LL}
            };
            for (int i = 0; i < T; i++) ranges.push_back(p[i % (int)p.size()]);
        } else if (seed == 2) {
            vector<pair<long long, long long>> p = {
                {1, 2}, {2, 3}, {3, 5}, {999999900LL, 1000000000LL},
                {536870900LL, 536870930LL}, {268435440LL, 268435470LL}, {1, 1000000000LL}, {999999937LL, 999999937LL}
            };
            for (int i = 0; i < T; i++) ranges.push_back(p[i % (int)p.size()]);
        } else if (seed == 3) {
            vector<pair<long long, long long>> p = {
                {1, 1000000000LL}, {1, 1000}, {999000000LL, 1000000000LL}, {1, 2},
                {500000000LL, 500000010LL}, {720720LL, 720720LL}, {999983LL, 1000000LL}, {268435455LL, 268435457LL}
            };
            for (int i = 0; i < T; i++) ranges.push_back(p[i % (int)p.size()]);
        } else {

            for (int i = 0; i < T; i++) {
                int typ = (i % 5);
                long long L = defL, R = defR;
                if (typ == 0) {
                    L = 1; R = 1000000000LL;
                } else if (typ == 1) {
                    long long width = rnd.next(0LL, 5000LL);
                    L = 1000000000LL - rnd.next(0LL, 200000LL);
                    R = clampA(L + width);
                    L = clampA(L);
                    if (L > R) swap(L, R);
                } else if (typ == 2) {
                    int k = rnd.next(0, 29);
                    long long center = (1LL << k);
                    long long w = rnd.next(0LL, 20LL);
                    L = clampA(center - w);
                    R = clampA(center + w);
                    if (L > R) swap(L, R);
                } else if (typ == 3) {
                    long long x = rnd.next(1LL, 1000000000LL);
                    L = x; R = x;
                } else {
                    L = defL; R = defR;
                }
                ranges.push_back({L, R});
            }
        }

        cout << T << "\n";
        for (int i = 0; i < T; i++) {
            cout << ranges[i].first << " " << ranges[i].second << "\n";
        }
        return 0;
    }

    cout << 1 << "\n" << 999999937LL << "\n";
    return 0;
}


Once upon a time, in the Land of the Shamans, everyone lived on the Sky-High Beanstalk. Each shaman had a unique identifying number $i$ between $0$ and $N-1$, and an altitude value $H_i$, representing how high he lived above ground level. The distance between two altitudes is the absolute value of their difference.

All shamans lived together in peace, until one of them stole the formula of the world-famous Potion of Great Power. To cover his/her tracks, the Thief has put a Curse on the land: most inhabitants could no longer trust each other...

Despite the very difficult circumstances, the Order of Good Investigators have gained the following information about the Curse:

* When the Curse first takes effect, everyone stops trusting each other.
* The Curse is unstable: at the end of each day (exactly at midnight), one pair of shamans will start or stop trusting each other.
* Unfortunately, each shaman will only ever trust at most $D$ others at any given time.

They have also reconstructed a log of who trusted whom: for each night they know which pair of shamans started/stopped trusting each other.

They believe the Thief has whispered the formula to an Evil Shaman. To avoid detection, both of them visited the home of one of their (respective) trusted friends. During the visit, the Thief whispered the formula to the Evil Shaman through the window. (Note: this trusted friend did not have to be home at the time. In fact, it's even possible that they visited each other's houses – shamans are weird.)

Fortunately, whispers only travel short distances, so the Order knows the two trusted friends visited (by the Thief and the Evil Shaman) must live very close to each other.

They ask you to help with their investigation. They would like to test their suspicions: what if the Thief was $x$, the Evil Shaman was $y$, and the formula was whispered on day $v$? What is the smallest distance the whispered formula had to travel? That is, what is the minimum distance between the apartments of some shamans $x'$ and $y'$ (i.e. $\min\left(\left|H_{x'} - H_{y'}\right|\right)$), such that $x'$ was a trusted friend of $x$ and $y'$ was a trusted friend of $y$ on day $v$?

They will share all their information with you, then ask you a number of questions. You need to answer each question immediately, before receiving the next one.

Interaction

The interaction will begin with a line containing $N$, $D$, $U$ and $Q$ $(2 \leq N \leq 100000$, $1 \leq D \leq 500$, $0 \leq U \leq 200000$, $1 \leq Q \leq 50000)$ – the number of shamans, the maximum number of trusted friends a shaman can have at any given point, the number of days, and the number of questions.

On the next line $N$ space separated integers will follow, the $i$th $(1\leq i \leq N)$ of which being $H_{i-1}$ $(0\leq H_{i-1} \leq 10^9)$, the altitude of shaman $i-1$.

On the next $U$ lines there will be two integers each, on the $i$th ($1 \leq i \leq U$) $A_i$ and $B_i$ $(0 \leq A_i, B_i < N$ and $A_i \neq B_i)$, which represents a pair of shamans who started or stopped trusting each other at the end of day $i-1$. That is, if $A_i$ and $B_i$ trusted each other on day $i-1$, they did not trust each other on day $i$, or vice versa. Read all of these integers.

The interactor now will ask you $Q$ question, so the following interaction should happen $Q$ times:

1. Read $3$ integers describing the current query: $x,y$ and $v$ ($x \neq y$, $0 \leq x,y < N$ and $0 \leq v \leq U$), where $x$ is the suspected Thief, $y$ is the suspected Evil Shaman, and $v$ is the suspected day..
2. Then print the answer to this query on a single line, i.e. you should print the minimum distance the whispered formula had to travel from some trusted friend $x'$ of $x$ to a trusted friend $y'$ of $y$.
   * In case someone trusted both $x$ and $y$ (i.e. $x'=y'$), you should print $0$.
   * If $x$ or $y$ had no trusted friends, print $10^9$.

After printing each line do not forget to output end of 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;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.

Scoring

 $ \begin{array}{|c|c|c|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & 0 & \text{samples}\\ \hline 2 & 17 & Q,U \leq 1000 \\ \hline 3 & 14 & v=U \: \text{for all questions} \\ \hline 4 & 18 & H_i \in \left\{0,1\right\} \: \text{for all shamans} \: i \\ \hline 5 & 21 & U,N \leq 10000\\ \hline 6 & 30 & \text{no additional constraints}\\ \hline \end{array} $

Example

Input

```
6 5 11 4
2 42 1000 54 68 234
0 1
2 0
3 4
3 5
3 5
1 3
5 3
0 5
3 0
1 3
3 5
0 3 4
3 0 8
0 5 5
3 0 11
```

Output

```
26
0
1000000000
14
```

Note

Example queries: ![](https://espresso.codeforces.com/c1c942c8e50047ce7929e1f2d50a8d18611589c9.png)

Evolution of friendships: ![](https://espresso.codeforces.com/896597d0952437505a39da5fbf78ec2d233360b8.png)

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

static long long queries_count = 0;
static long long query_limit = 0;

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

    }
}

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

struct Query {
    int x, y, v, id;
};

const int INF_DIST = 1000000000;

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

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

    int N = inf.readInt(2, 100000, "N");
    int D = inf.readInt(1, 500, "D");
    int U = inf.readInt(0, 200000, "U");
    int Q = inf.readInt(1, 50000, "Q");

    query_limit = Q;
    log_metrics();

    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        H[i] = inf.readInt(0, 1000000000, format("H[%d]", i));
    }

    vector<pair<int, int>> updates(U);
    for (int i = 0; i < U; i++) {
        updates[i].first = inf.readInt(0, N - 1, format("u_u[%d]", i));
        updates[i].second = inf.readInt(0, N - 1, format("u_v[%d]", i));
    }

    vector<Query> all_queries(Q);

    vector<vector<int>> queries_at_time(U + 1);
    for (int i = 0; i < Q; i++) {
        all_queries[i].x = inf.readInt(0, N - 1, format("q_x[%d]", i));
        all_queries[i].y = inf.readInt(0, N - 1, format("q_y[%d]", i));
        all_queries[i].v = inf.readInt(0, U, format("q_v[%d]", i));
        all_queries[i].id = i;
        queries_at_time[all_queries[i].v].push_back(i);
    }

    vector<vector<pair<int, int>>> adj(N);
    vector<long long> expected_answers(Q);

    auto toggle_edge = [&](int u, int v) {
        int h_v = H[v];
        pair<int, int> val = {h_v, v};

        auto it = lower_bound(adj[u].begin(), adj[u].end(), val);
        if (it != adj[u].end() && it->first == h_v && it->second == v) {

            adj[u].erase(it);
        } else {

            adj[u].insert(it, val);
        }
    };

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

        if (t > 0) {
            int u = updates[t-1].first;
            int v = updates[t-1].second;
            toggle_edge(u, v);
            toggle_edge(v, u);
        }

        for (int q_idx : queries_at_time[t]) {
            int x = all_queries[q_idx].x;
            int y = all_queries[q_idx].y;

            const auto& list_x = adj[x];
            const auto& list_y = adj[y];

            if (list_x.empty() || list_y.empty()) {
                expected_answers[q_idx] = INF_DIST;
            } else {
                long long min_dist = 2000000000LL;

                size_t i = 0, j = 0;
                while (i < list_x.size() && j < list_y.size()) {
                    long long diff = abs(list_x[i].first - list_y[j].first);
                    if (diff < min_dist) min_dist = diff;

                    if (min_dist == 0) break;

                    if (list_x[i].first < list_y[j].first) {
                        i++;
                    } else {
                        j++;
                    }
                }
                expected_answers[q_idx] = min_dist;
            }
        }
    }

    cout << N << " " << D << " " << U << " " << Q << endl;

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

    for (int i = 0; i < U; i++) {
        cout << updates[i].first << " " << updates[i].second << endl;
    }
    cout.flush();

    for (int i = 0; i < Q; i++) {

        cout << all_queries[i].x << " " << all_queries[i].y << " " << all_queries[i].v << endl;

        long long user_ans;
        if (!(cin >> user_ans)) {
            finish(_pe, "Unexpected end of file or malformed output while waiting for answer to query " + to_string(i + 1));
        }

        if (user_ans != expected_answers[i]) {
            finish(_wa, "Wrong answer on query " + to_string(i + 1) +
                   ": expected " + to_string(expected_answers[i]) +
                   ", found " + to_string(user_ans));
        }

        queries_count++;

        if (queries_count % 100 == 0) log_metrics();
    }

    finish(_ok, "All " + to_string(Q) + " queries correct");
    return 0;
}

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

using namespace std;

static int queries_count = 0;
static int query_limit = 0;

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

    }
}

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

const int MAXN = 100005;
int H[MAXN];
vector<int> adj[MAXN];

struct Update {
    int u, v;
};

struct Query {
    int id;
    int x, y, v;
    long long expected_ans;
};

void toggle_edge(int u, int v) {
    auto toggle = [](vector<int>& vec, int val) {
        for (size_t i = 0; i < vec.size(); ++i) {
            if (vec[i] == val) {

                vec[i] = vec.back();
                vec.pop_back();
                return;
            }
        }

        vec.push_back(val);
    };

    toggle(adj[u], v);
    toggle(adj[v], u);
}

long long solve_query(int x, int y) {

    if (adj[x].empty() || adj[y].empty()) return 1000000000LL;

    static vector<int> hx, hy;
    hx.clear(); hy.clear();
    hx.reserve(adj[x].size());
    hy.reserve(adj[y].size());

    for (int n : adj[x]) hx.push_back(H[n]);
    for (int n : adj[y]) hy.push_back(H[n]);

    sort(hx.begin(), hx.end());
    sort(hy.begin(), hy.end());

    long long min_diff = 2000000000LL;
    size_t i = 0, j = 0;
    while (i < hx.size() && j < hy.size()) {
        long long diff = abs((long long)hx[i] - hy[j]);
        if (diff < min_diff) min_diff = diff;
        if (min_diff == 0) return 0;

        if (hx[i] < hy[j]) i++;
        else j++;
    }
    return min_diff;
}

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

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

    int N = inf.readInt();
    int D = inf.readInt();
    int U = inf.readInt();
    int Q = inf.readInt();

    query_limit = Q;
    log_metrics();

    cout << N << " " << D << " " << U << " " << Q << endl;

    for (int i = 0; i < N; ++i) {
        H[i] = inf.readInt();
        if (i > 0) cout << " ";
        cout << H[i];
    }
    cout << endl;

    vector<Update> updates(U);
    for (int i = 0; i < U; ++i) {
        updates[i].u = inf.readInt();
        updates[i].v = inf.readInt();

        cout << updates[i].u << " " << updates[i].v << "\n";
    }
    cout.flush();

    vector<Query> queries(Q);
    for (int i = 0; i < Q; ++i) {
        queries[i].id = i;
        queries[i].x = inf.readInt();
        queries[i].y = inf.readInt();
        queries[i].v = inf.readInt();
        queries[i].expected_ans = -1;
    }

    vector<Query*> query_ptrs(Q);
    for (int i = 0; i < Q; ++i) query_ptrs[i] = &queries[i];
    sort(query_ptrs.begin(), query_ptrs.end(), [](Query* a, Query* b) {
        return a->v < b->v;
    });

    int current_time = 0;
    for (Query* q : query_ptrs) {

        while (current_time < q->v) {
            toggle_edge(updates[current_time].u, updates[current_time].v);
            current_time++;
        }
        q->expected_ans = solve_query(q->x, q->y);
    }

    for (int i = 0; i < Q; ++i) {

        if (i > 0 && i % 10 == 0) log_metrics();

        cout << queries[i].x << " " << queries[i].y << " " << queries[i].v << endl;
        queries_count++;

        long long val;
        if (!(cin >> val)) {
            finish(_pe, "Unexpected EOF or malformed output from contestant");
        }

        if (val != queries[i].expected_ans) {
             string msg = "Wrong answer on query " + to_string(i+1) +
                         " (x=" + to_string(queries[i].x) +
                         ", y=" + to_string(queries[i].y) +
                         ", v=" + to_string(queries[i].v) + ")" +
                         ". Expected " + to_string(queries[i].expected_ans) +
                         ", found " + to_string(val);
             finish(_wa, msg);
        }
    }

    finish(_ok, "All queries correct");
    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 seedVal = atoi(argv[1]);

    int N, D, U, Q;
    const int MAX_N = 100000;
    const int MAX_D = 500;
    const int MAX_U = 200000;
    const int MAX_Q = 50000;

    if (seedVal == 1) {
        N = rnd.next(5, 20);
        D = rnd.next(2, 5);
        U = rnd.next(5, 20);
        Q = rnd.next(5, 20);
    }
    else if (seedVal == 2) {
        N = MAX_N;
        D = 1;
        U = MAX_U;
        Q = MAX_Q;
    }
    else if (seedVal == 3) {
        N = MAX_N;
        D = MAX_D;
        U = MAX_U;
        Q = MAX_Q;
    }
    else if (seedVal == 4) {
        N = MAX_N;
        D = rnd.next(5, 50);
        U = MAX_U;
        Q = MAX_Q;
    }
    else if (seedVal == 5) {
        N = MAX_N;
        D = rnd.next(10, 100);
        U = MAX_U;
        Q = MAX_Q;
    }
    else {
        N = rnd.next(MAX_N / 2, MAX_N);
        D = rnd.next(1, MAX_D);
        U = rnd.next(MAX_U / 2, MAX_U);
        Q = rnd.next(MAX_Q / 2, MAX_Q);
    }

    cout << N << " " << D << " " << U << " " << Q << "\n";

    vector<int> H(N);
    for (int i = 0; i < N; ++i) {
        if (seedVal == 4) H[i] = rnd.next(0, 1);
        else H[i] = rnd.next(0, 1000000000);
    }
    for (int i = 0; i < N; ++i) {
        cout << H[i] << (i == N - 1 ? "" : " ");
    }
    cout << "\n";

    vector<vector<int>> adj(N);
    vector<int> deg(N, 0);
    vector<pair<int, int>> existing_edges;

    auto hasEdge = [&](int u, int target) {
        for (int v : adj[u]) if (v == target) return true;
        return false;
    };

    for (int i = 0; i < U; ++i) {
        bool op_add;

        if (existing_edges.empty()) op_add = true;
        else if (i > U - 1000 && existing_edges.size() < 100) op_add = true;
        else op_add = (rnd.next(2) == 0);

        int u = -1, v = -1;
        bool success = false;

        auto try_current_op = [&]() -> bool {
            if (op_add) {
                int cu = rnd.next(N);
                if (deg[cu] >= D) return false;
                int cv = rnd.next(N);
                if (cu == cv || deg[cv] >= D) return false;
                if (!hasEdge(cu, cv)) {
                    u = cu; v = cv;
                    return true;
                }
            } else {
                if (existing_edges.empty()) return false;
                int idx = rnd.next(existing_edges.size());
                u = existing_edges[idx].first;
                v = existing_edges[idx].second;

                existing_edges[idx] = existing_edges.back();
                existing_edges.pop_back();
                return true;
            }
            return false;
        };

        for (int k = 0; k < 20; ++k) {
            if (try_current_op()) { success = true; break; }
        }

        if (!success) {
            op_add = !op_add;
            int attempts = 0;
            while (!success && attempts < 50) {
                if (try_current_op()) success = true;
                attempts++;
            }

            if (!success && op_add) {
                for(int k=0; k<500; ++k) {
                   int cu = rnd.next(N), cv = rnd.next(N);
                   if (cu!=cv && deg[cu]<D && deg[cv]<D && !hasEdge(cu,cv)) {
                       u=cu; v=cv; success=true; break;
                   }
               }
            }
        }

        if (!success) {
            u = 0; v = 1;

            if (hasEdge(u, v)) {
                op_add = false;

                for(size_t k=0; k<existing_edges.size(); ++k) {
                    if ((existing_edges[k].first==u && existing_edges[k].second==v) ||
                        (existing_edges[k].first==v && existing_edges[k].second==u)) {
                        existing_edges[k] = existing_edges.back();
                        existing_edges.pop_back();
                        break;
                    }
                }
            } else {
                op_add = true;
            }
        }

        cout << u << " " << v << "\n";

        if (op_add) {
            adj[u].push_back(v);
            adj[v].push_back(u);
            deg[u]++; deg[v]++;
            existing_edges.push_back({u, v});
        } else {

            for(size_t k=0; k<adj[u].size(); ++k) if(adj[u][k] == v) { adj[u].erase(adj[u].begin()+k); break; }
            for(size_t k=0; k<adj[v].size(); ++k) if(adj[v][k] == u) { adj[v].erase(adj[v].begin()+k); break; }
            deg[u]--; deg[v]--;
        }
    }

    if (mode == "non") {
        for (int i = 0; i < Q; ++i) {
            int x = rnd.next(N);
            int y = rnd.next(N);
            while (y == x) y = rnd.next(N);
            int v_day = (seedVal == 5) ? U : rnd.next(0, U);
            cout << x << " " << y << " " << v_day << "\n";
        }
    }

    return 0;
}


This is an interactive problem.

There is a secret permutation $p$ ($1$-indexed) of numbers from $1$ to $n$. More formally, for $1 \leq i \leq n$, $1 \leq p[i] \leq n$ and for $1 \leq i < j \leq n$, $p[i] \neq p[j]$. It is known that $p[1]<p[2]$.

In $1$ query, you give $3$ distinct integers $a,b,c$ ($1 \leq a,b,c \leq n$), and receive the median of $\{|p[a]-p[b]|,|p[b]-p[c]|,|p[a]-p[c]|\}$.

In this case, the median is the $2$-nd element ($1$-indexed) of the sequence when sorted in non-decreasing order. The median of $\{4,6,2\}$ is $4$ and the median of $\{0,123,33\}$ is $33$.

Can you find the secret permutation in not more than $2n+420$ queries?

Note: the grader is not adaptive: the permutation is fixed before any queries are made.

Input

The first line of input contains a single integer $t$ $(1 \leq t \leq 1000)$ — the number of testcases.

The first line of each testcase consists of a single integer $n$ $(20 \leq n \leq 100000)$ — the length of the secret permutation.

It is guaranteed that the sum of $n$ over all test cases does not exceed $100000$.

Interaction

For each testcase, you begin the interaction by reading $n$.

To perform a query, output "? a b c" where $a,b,c$ is the $3$ indices you want to use for the query.

Numbers have to satisfy $1 \leq a,b,c \leq n$ and $a \neq b$,$b \neq c$,$a \neq c$.

For each query, you will receive a single integer $x$: the median of $\{|p[a]-p[b]|,|p[b]-p[c]|,|p[a]-p[c]|\}$.

In case your query is invalid or you asked more than $2n+420$ queries, the interactor will print "−1" and will finish interaction. You will receive Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

When you have determined the secret permutation, output "! p[1] p[2] ... p[n]". If the secret permutation is correct, the interactor will print "1". Otherwise, the interactor will print "-1" and will finish interaction. You will receive Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

After printing a query do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded verdict.

To do this, use:

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

Example

Input

```
1
20

6

9

1
```

Output

```
? 1 5 2

? 20 19 2

! 9 10 19 7 16 18 11 14 15 6 20 8 17 4 5 3 12 2 13 1
```

Note

The secret permutation is $\{9,10,19,7,16,18,11,14,15,6,20,8,17,4,5,3,12,2,13,1\}$.

For the first query, the values of $(a,b,c)$ is $(1,5,2)$. Since $p[1]=9$, $p[5]=16$ and $p[2]=10$. The return value is the median of $\{|9-16|,|16-10|,|9-10|\}$ which is $6$.

For the second query, the values of $(a,b,c)$ is $(20,19,2)$. Since $p[20]=1$, $p[19]=13$ and $p[2]=10$. The return value is the median of $\{|1-13|,|13-10|,|1-10|\}$ which is $9$.

By some miracle, we have figured out that the secret permutation is $\{9,10,19,7,16,18,11,14,15,6,20,8,17,4,5,3,12,2,13,1\}$. We output it and receive $1$ from the interactor, meaning that we have guessed the secret permutation correctly.

#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 int median3(int a, int b, int c) {
    array<int, 3> v{a, b, c};
    sort(v.begin(), v.end());
    return v[1];
}

static void sendMinusOne() {
    cout << -1 << "\n";
    cout.flush();
}

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

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = inf.readInt(1, 1000, "t");
    vector<int> ns(t);
    vector<vector<int>> perms(t);

    long long sumN = 0;
    for (int tc = 0; tc < t; tc++) {
        int n = inf.readInt(20, 100000, "n");
        ns[tc] = n;
        sumN += n;

        vector<int> p(n + 1, 0);
        vector<int> seen(n + 1, 0);
        for (int i = 1; i <= n; i++) {
            int v = inf.readInt(1, n, "p[i]");
            p[i] = v;
            if (++seen[v] != 1) finish(_fail, "Invalid hidden permutation: duplicates");
        }
        if (!(p[1] < p[2])) finish(_fail, "Invalid hidden permutation: expected p[1] < p[2]");
        perms[tc] = std::move(p);

        query_limit += 2LL * n + 420;
    }
    if (sumN > 100000) finish(_fail, "Invalid hidden input: sum(n) exceeds 100000");

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

    log_metrics();

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

    for (int tc = 0; tc < t; tc++) {
        const int n = ns[tc];
        const vector<int>& p = perms[tc];

        const long long per_case_limit = 2LL * n + 420;
        long long used = 0;

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

        while (true) {
            string op;
            if (!(cin >> op)) finish(_pe, "Unexpected EOF from contestant");

            if (!op.empty() && op[0] == '?') {
                long long a_ll, b_ll, c_ll;
                if (!(cin >> a_ll >> b_ll >> c_ll)) {
                    sendMinusOne();
                    finish(_pe, "Malformed query (expected '? a b c')");
                }

                queries++;
                used++;
                if (queries > hard_cap) finish(_pe, "Hard cap exceeded (possible infinite loop)");
                if (used > per_case_limit) {
                    sendMinusOne();
                    finish(_wa, "Query limit exceeded");
                }

                if (!(1 <= a_ll && a_ll <= n && 1 <= b_ll && b_ll <= n && 1 <= c_ll && c_ll <= n)) {
                    sendMinusOne();
                    finish(_wa, "Query index out of range");
                }
                int a = (int)a_ll, b = (int)b_ll, c = (int)c_ll;
                if (a == b || b == c || a == c) {
                    sendMinusOne();
                    finish(_wa, "Query indices not distinct");
                }

                int d1 = abs(p[a] - p[b]);
                int d2 = abs(p[b] - p[c]);
                int d3 = abs(p[a] - p[c]);
                int ans = median3(d1, d2, d3);

                cout << ans << "\n";
                cout.flush();
            } else if (!op.empty() && op[0] == '!') {
                vector<int> guess(n + 1, 0);
                vector<int> seen(n + 1, 0);
                for (int i = 1; i <= n; i++) {
                    long long v_ll;
                    if (!(cin >> v_ll)) {
                        sendMinusOne();
                        finish(_pe, "Malformed final answer (not enough integers)");
                    }
                    if (v_ll < 1 || v_ll > n) {
                        sendMinusOne();
                        finish(_wa, "Final answer contains out-of-range value");
                    }
                    int v = (int)v_ll;
                    guess[i] = v;
                    if (++seen[v] != 1) {
                        sendMinusOne();
                        finish(_wa, "Final answer is not a permutation");
                    }
                }

                bool ok = true;
                for (int i = 1; i <= n; i++) {
                    if (guess[i] != p[i]) {
                        ok = false;
                        break;
                    }
                }
                if (!ok) {
                    sendMinusOne();
                    finish(_wa, "Wrong permutation");
                }

                cout << 1 << "\n";
                cout.flush();
                if (tc == t - 1) finish(_ok, "OK");
                break;
            } else {
                sendMinusOne();
                finish(_pe, "Unknown operation token (expected '?' or '!')");
            }
        }
    }

    finish(_pe, "Contestant did not terminate properly after all testcases");
    return 0;
}

#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 uint64_t fnv1a64(const string& s) {
    uint64_t h = 14695981039346656037ULL;
    for (unsigned char c : s) {
        h ^= (uint64_t)c;
        h *= 1099511628211ULL;
    }
    return h;
}

static uint64_t splitmix64(uint64_t& x) {
    uint64_t z = (x += 0x9e3779b97f4a7c15ULL);
    z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
    z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
    return z ^ (z >> 31);
}

static vector<int> genPermutation(int n, uint64_t seed) {
    vector<int> p(n + 1, 0);
    for (int i = 1; i <= n; i++) p[i] = i;

    uint64_t x = seed;
    for (int i = n; i >= 2; --i) {
        int j = (int)(splitmix64(x) % (uint64_t)i) + 1;
        swap(p[i], p[j]);
    }
    if (p[1] > p[2]) swap(p[1], p[2]);
    return p;
}

static int median3(int a, int b, int c) {
    array<int, 3> v{a, b, c};
    sort(v.begin(), v.end());
    return v[1];
}

static void sendMinusOne() {
    cout << -1 << "\n";
    cout.flush();
}

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

    uint64_t base_seed = fnv1a64((argc >= 2) ? string(argv[1]) : string("cf1526F"));

    int t = inf.readInt(1, 1000, "t");
    vector<int> ns(t);
    long long sumN = 0;
    for (int tc = 0; tc < t; tc++) {
        int n = inf.readInt(20, 100000, "n");
        ns[tc] = n;
        sumN += n;
        query_limit += 2LL * n + 420;
    }
    if (sumN > 100000) finish(_fail, "Invalid hidden input: sum(n) exceeds 100000");
    if (!inf.seekEof()) finish(_fail, "Unexpected extra tokens in adaptive input");

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

    log_metrics();

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

    for (int tc = 0; tc < t; tc++) {
        const int n = ns[tc];
        const long long per_case_limit = 2LL * n + 420;
        long long used = 0;

        uint64_t seed = base_seed ^ (uint64_t)n ^ (uint64_t)(tc + 1) * 0x9e3779b97f4a7c15ULL;
        vector<int> p = genPermutation(n, seed);

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

        while (true) {
            string op;
            if (!(cin >> op)) finish(_pe, "Unexpected EOF from contestant");

            if (!op.empty() && op[0] == '?') {
                long long a_ll, b_ll, c_ll;
                if (!(cin >> a_ll >> b_ll >> c_ll)) {
                    sendMinusOne();
                    finish(_pe, "Malformed query (expected '? a b c')");
                }

                queries++;
                used++;
                if (queries > hard_cap) finish(_pe, "Hard cap exceeded (possible infinite loop)");
                if (used > per_case_limit) {
                    sendMinusOne();
                    finish(_wa, "Query limit exceeded");
                }

                if (!(1 <= a_ll && a_ll <= n && 1 <= b_ll && b_ll <= n && 1 <= c_ll && c_ll <= n)) {
                    sendMinusOne();
                    finish(_wa, "Query index out of range");
                }
                int a = (int)a_ll, b = (int)b_ll, c = (int)c_ll;
                if (a == b || b == c || a == c) {
                    sendMinusOne();
                    finish(_wa, "Query indices not distinct");
                }

                int d1 = abs(p[a] - p[b]);
                int d2 = abs(p[b] - p[c]);
                int d3 = abs(p[a] - p[c]);
                int ans = median3(d1, d2, d3);

                cout << ans << "\n";
                cout.flush();
            } else if (!op.empty() && op[0] == '!') {
                vector<int> guess(n + 1, 0);
                vector<int> seen(n + 1, 0);
                for (int i = 1; i <= n; i++) {
                    long long v_ll;
                    if (!(cin >> v_ll)) {
                        sendMinusOne();
                        finish(_pe, "Malformed final answer (not enough integers)");
                    }
                    if (v_ll < 1 || v_ll > n) {
                        sendMinusOne();
                        finish(_wa, "Final answer contains out-of-range value");
                    }
                    int v = (int)v_ll;
                    guess[i] = v;
                    if (++seen[v] != 1) {
                        sendMinusOne();
                        finish(_wa, "Final answer is not a permutation");
                    }
                }

                bool ok = true;
                for (int i = 1; i <= n; i++) {
                    if (guess[i] != p[i]) {
                        ok = false;
                        break;
                    }
                }
                if (!ok) {
                    sendMinusOne();
                    finish(_wa, "Wrong permutation");
                }

                cout << 1 << "\n";
                cout.flush();
                if (tc == t - 1) finish(_ok, "OK");
                break;
            } else {
                sendMinusOne();
                finish(_pe, "Unknown operation token (expected '?' or '!')");
            }
        }
    }

    finish(_pe, "Contestant did not terminate properly after all testcases");
    return 0;
}

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

static long long gcdll(long long a, long long b) {
    while (b) { long long t = a % b; a = b; b = t; }
    return a;
}

static vector<int> perm_seed1_n20() {
    int n = 20;
    vector<int> p;
    p.reserve(n);

    p.push_back(1);
    p.push_back(2);
    int lo = 3, hi = n;
    bool takeHi = true;
    while ((int)p.size() < n) {
        if (takeHi) p.push_back(hi--);
        else p.push_back(lo++);
        takeHi = !takeHi;
    }
    if (p[0] > p[1]) swap(p[0], p[1]);
    return p;
}

static vector<int> perm_seed2_rev(int n) {

    vector<int> p;
    p.reserve(n);
    p.push_back(n - 1);
    p.push_back(n);
    for (int x = n - 2; x >= 1; --x) p.push_back(x);
    if ((int)p.size() != n) abort();
    if (p[0] > p[1]) swap(p[0], p[1]);
    return p;
}

static vector<int> perm_affine(int n) {

    long long a;
    do {
        a = rnd.next(1, n - 1);
    } while (gcdll(a, n) != 1);
    long long b = rnd.next(0, n - 1);

    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        long long v = (a * i + b) % n;
        p[i] = (int)v + 1;
    }
    if (p[0] > p[1]) swap(p[0], p[1]);
    return p;
}

static vector<int> perm_blocky(int n) {
    vector<int> base(n);
    iota(base.begin(), base.end(), 1);

    vector<pair<int,int>> blocks;
    for (int i = 0; i < n; ) {
        int rem = n - i;
        int len;
        if (rem <= 5000) len = rem;
        else len = rnd.next(200, 4000);
        blocks.push_back({i, i + len});
        i += len;
    }

    for (int i = 0; i + 1 < (int)blocks.size(); i++) {
        int j = rnd.next(i, min<int>((int)blocks.size() - 1, i + 5));
        swap(blocks[i], blocks[j]);
    }

    vector<int> p;
    p.reserve(n);
    for (auto [l, r] : blocks) {
        bool rev = rnd.next(0, 99) < 65;
        if (!rev) {
            for (int i = l; i < r; i++) p.push_back(base[i]);
        } else {
            for (int i = r - 1; i >= l; i--) p.push_back(base[i]);
        }
    }

    int K = min(n, rnd.next(2000, 8000));
    deque<int> dq;
    for (int i = 0; i < K; i++) dq.push_back(p[i]);
    vector<int> pref;
    pref.reserve(K);
    bool takeBack = true;
    while (!dq.empty()) {
        int run = rnd.next(1, 7);
        while (run-- && !dq.empty()) {
            if (takeBack) { pref.push_back(dq.back()); dq.pop_back(); }
            else { pref.push_back(dq.front()); dq.pop_front(); }
        }
        takeBack = !takeBack;
    }
    for (int i = 0; i < K; i++) p[i] = pref[i];

    if (p[0] > p[1]) swap(p[0], p[1]);
    return p;
}

static vector<int> perm_ends_runs(int n) {
    deque<int> dq;
    for (int i = 1; i <= n; i++) dq.push_back(i);

    vector<int> p;
    p.reserve(n);

    if (n >= 2) {
        p.push_back(n - 1);
        dq.pop_back();
        dq.pop_back();
        p.push_back(n);
    }

    bool takeFront = true;
    while (!dq.empty()) {
        int run = rnd.next(1, 32);
        while (run-- && !dq.empty()) {
            if (takeFront) { p.push_back(dq.front()); dq.pop_front(); }
            else { p.push_back(dq.back()); dq.pop_back(); }
        }
        takeFront = !takeFront;
    }

    if ((int)p.size() != n) abort();
    if (p[0] > p[1]) swap(p[0], p[1]);
    return p;
}

static vector<int> perm_random(int n) {
    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    for (int i = n - 1; i >= 1; --i) {
        int j = rnd.next(0, i);
        swap(p[i], p[j]);
    }
    if (p[0] > p[1]) swap(p[0], p[1]);
    return p;
}

static vector<int> generatePermutation(long long seedArg, int n) {
    if (seedArg == 1) return perm_seed1_n20();
    if (seedArg == 2) return perm_seed2_rev(n);
    if (seedArg == 3) {

        return perm_affine(n);
    }

    int type = rnd.next(0, 3);
    if (type == 0) return perm_ends_runs(n);
    if (type == 1) return perm_blocky(n);
    if (type == 2) {

        vector<int> p = perm_affine(n);
        int ops = rnd.next(8, 20);
        for (int it = 0; it < ops; it++) {
            int l = rnd.next(0, n - 1);
            int r = rnd.next(0, n - 1);
            if (l > r) swap(l, r);
            if (r - l >= 2) reverse(p.begin() + l, p.begin() + r + 1);
        }
        if (p[0] > p[1]) swap(p[0], p[1]);
        return p;
    }
    return perm_random(n);
}

static void printPermutation(const vector<int>& p) {
    for (int i = 0; i < (int)p.size(); i++) {
        if (i) cout << ' ';
        cout << p[i];
    }
    cout << "\n";
}

int main(int argc, char** argv) {
    registerGen(argc, argv, 1);
    string mode = opt<string>("mode", "non");

    long long seedArg = 1;
    if (argc >= 2) {

        seedArg = atoll(argv[1]);
        if (seedArg <= 0) seedArg = 1;
    }

    int nOpt = opt<int>("n", -1);
    int n;
    if (seedArg == 1) n = 20;
    else if (seedArg == 3) n = 99991;
    else n = 100000;

    if (seedArg > 3 && nOpt != -1) n = nOpt;
    n = max(20, min(100000, n));

    cout << 1 << "\n";
    cout << n << "\n";

    if (mode == "non") {
        vector<int> p = generatePermutation(seedArg, n);

        vector<int> seen(n + 1, 0);
        for (int x : p) {
            if (x < 1 || x > n) abort();
            seen[x]++;
        }
        for (int v = 1; v <= n; v++) if (seen[v] != 1) abort();
        if (!(p[0] < p[1])) abort();

        printPermutation(p);
    } else if (mode == "adp") {

    } else {

        vector<int> p = generatePermutation(seedArg, n);
        if (p[0] > p[1]) swap(p[0], p[1]);
        printPermutation(p);
    }

    return 0;
}


Each year, the fastest platypuses of the world come together for the Great Crawling Platypus Cup (GCPC) to crawl a single lap in the platypus arena. Of course, Perry the platypus wants to take part in this great event. Perry’s arch enemy Dr. Doofenshmirtz got wind of it and plans to capture Perry right when he crosses the finish line at the GCPC. To carry out his evil plan successfully, he needs to find out how long Perry needs to finish the lap. He knows that Perry takes the preparation for the GCPC very seriously and trains by crawling lap after lap in the arena at a constant speed of $1 \%$ . Perry’s training starts this Saturday and Dr. Doofenshmirtz knows that he will run at least $1 0 ^ { 1 8 }$ seconds. To determine the exact length of one lap, Dr. Doofenshmirtz invented the Measurinator which can measure the exact distance Perry has already crawled in his current lap. Unfortunately, the Measurinator will break after too many measurements, so Dr. Doofenshmirtz has to carefully plan when to use it in order to determine the length of one lap.

![](images/3fc0b1d74356080949ea48c757d6fd3c3b0ca7fff68747158119970d76be1253.jpg)
A circular running track. Illustration by Kjrstie, Pixabay

# Interaction

Your submission can print “? t” where $t$ $0 \leq t < 1 0 ^ { 1 8 }$ ) is the point in time when you want to use the Measurinator. The time $t = 0$ marks the point in time where Perry starts practicing i.e. where he starts his first lap at the start and finish line. The Measurinator responds with a single integer $x$ which is the current position of Perry in his current lap. Note that the Measurinator will not respond with the number of meters Perry has already crawled in total! Thus, whenever Perry reaches the start and finish line, the Measurinator will respond with 0. Further note that you recently lost your Timetravellinator and therefore, the values of $t$ must be strictly increasing.

If you determined the length $x$ of one lap, print “! x”. After this, your program should immediately terminate.

All interactions must be ended by a newline. Further note that you additionally need to flush the standard output to ensure that the query is sent. For example, you can use:

• std::cout $< <$ std::flush in $\mathrm { C } { + + }$ • fflush(stdout) in C • System.out.flush() in Java • sys.stdout.flush() in Python

Your submission is considered correct if you followed these rules, found the correct length of one lap, and used no more than 42 queries. Note that giving the answer is also counted as a query.

It is guaranteed that one lap has integer length, is at least one meter long, and at most $1 0 ^ { 1 2 }$ meters long.

A testing tool is provided to help you develop your solution. It can be downloaded from the DOMjudge problems overview page.

Read                                   Sample Interaction 1                                   Write?1

1

	？2

2

	？3

3

	？4

4

	？100

16

	！42

Read                                   Sample Interaction 2                                   Write？10

10

	？20

20

	？30

30

	？40

40

	？10000

641

	！1337

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

using namespace std;

static long long queries = 0;
static const long long query_limit = 42;

static long long C;
static long long last_t = -1;

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());
}

long long parse_long(const string& s) {
    try {
        size_t idx = 0;
        long long val = stoll(s, &idx);
        if (idx != s.size()) {
            finish(_pe, format("Token '%s' contains invalid characters", s.c_str()));
        }
        return val;
    } catch (const out_of_range&) {
        finish(_pe, format("Number '%s' is out of range", s.c_str()));
    } catch (...) {
        finish(_pe, format("Cannot parse '%s' as integer", s.c_str()));
    }
    return 0;
}

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

    C = inf.readLong(1LL, 1000000000000LL, "C");

    int hard_cap = 2000;

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

        string token;

        if (!(cin >> token)) {
            finish(_pe, "Unexpected EOF: solution finished without outputting answer '! x'");
        }

        bool is_answer = false;
        long long val = 0;

        if (token == "!") {

            is_answer = true;
            if (!(cin >> val)) {
                finish(_pe, "Expected integer after '!'");
            }
        } else if (token == "?") {

            is_answer = false;
            if (!(cin >> val)) {
                finish(_pe, "Expected integer after '?'");
            }
        } else if (token.size() > 1 && token[0] == '!') {

            is_answer = true;
            val = parse_long(token.substr(1));
        } else if (token.size() > 1 && token[0] == '?') {

            is_answer = false;
            val = parse_long(token.substr(1));
        } else {

            is_answer = false;
            val = parse_long(token);
        }

        queries++;

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

        if (is_answer) {

            if (val == C) {
                finish(_ok, "Correct answer");
            } else {
                finish(_wa, format("Wrong answer: expected %lld, found %lld", C, val));
            }
        } else {

            if (val < 0) {
                finish(_pe, format("Query t must be non-negative, got %lld", val));
            }
            if (val >= 1000000000000000000LL) {
                finish(_pe, format("Query t must be < 10^18, got %lld", val));
            }

            if (val <= last_t) {
                finish(_pe, format("Query t must be strictly increasing: prev=%lld, curr=%lld", last_t, val));
            }

            last_t = val;

            long long resp = val % C;
            cout << resp << endl;
        }
    }

    return 0;
}

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

using namespace std;

static long long queries_count = 0;
static long long query_limit = 42;

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

    }
}

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

vector<long long> candidates;
long long last_t = -1;

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

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

    vector<long long> params;
    while (!inf.seekEof()) {
        params.push_back(inf.readLong());
    }

    long long L = 1, R = 1000000000000LL;
    if (params.size() >= 2) {
        L = params[0];
        R = params[1];
    } else if (params.size() == 1) {
        L = params[0];
        R = params[0];
    }

    if (R > 1000000000000LL) R = 1000000000000LL;
    if (L < 1) L = 1;
    if (L > R) L = R;

    {
        set<long long> s;
        auto add = [&](long long x) {
            if (x >= L && x <= R) s.insert(x);
        };

        for (long long i = 0; i <= 2000; ++i) {
            add(L + i);
            if (R - i >= L) add(R - i);
        }
        for (long long i = 1; i <= 2000; ++i) add(i);

        for (long long p = 1; p <= R; p *= 2) add(p);
        for (long long p = 1; p <= R; p *= 10) add(p);

        vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
        for (int i = 0; i < 5000; ++i) {
            long long curr = 1;
            int ops = 0;
            while (ops < 60) {
                int p = primes[rnd.next(primes.size())];
                if (__builtin_mul_overflow(curr, p, &curr)) break;
                if (curr > R) break;
                if (curr >= L) s.insert(curr);
                ops++;
            }
        }

        while (s.size() < 150000) {
            s.insert(rnd.next(L, R));
        }

        candidates.assign(s.begin(), s.end());
        shuffle(candidates.begin(), candidates.end());
    }

    log_metrics();

    while (true) {

        if (queries_count > 200) {
            finish(_pe, "Too many queries (>200)");
        }

        string line;
        char c;

        while (cin.get(c) && isspace(c));
        if (cin.eof()) finish(_pe, "Unexpected EOF");
        line += c;
        string rest;
        getline(cin, rest);
        line += rest;

        stringstream ss(line);
        char type;
        ss >> type;

        queries_count++;

        if (type == '?') {
            long long t;
            if (!(ss >> t)) finish(_pe, "Invalid query format");

            if (t < 0 || t >= 1000000000000000000LL) finish(_pe, "t out of bounds [0, 10^18)");
            if (t <= last_t) finish(_pe, "t must be strictly increasing");
            last_t = t;

            static vector<pair<long long, int>> rems;
            rems.clear();
            rems.reserve(candidates.size());

            for (int i = 0; i < (int)candidates.size(); ++i) {
                rems.push_back({t % candidates[i], i});
            }
            sort(rems.begin(), rems.end());

            long long best_rem = -1;
            int max_cnt = -1;
            int cur_cnt = 0;
            long long cur_val = -1;

            for (size_t i = 0; i < rems.size(); ++i) {
                if (i == 0 || rems[i].first != rems[i-1].first) {
                    if (cur_cnt > max_cnt) {
                        max_cnt = cur_cnt;
                        best_rem = cur_val;
                    }
                    cur_val = rems[i].first;
                    cur_cnt = 1;
                } else {
                    cur_cnt++;
                }
            }
            if (cur_cnt > max_cnt) {
                max_cnt = cur_cnt;
                best_rem = cur_val;
            }

            vector<long long> next_pool;
            next_pool.reserve(max_cnt);

            auto it = lower_bound(rems.begin(), rems.end(), make_pair(best_rem, -1));
            while (it != rems.end() && it->first == best_rem) {
                next_pool.push_back(candidates[it->second]);
                it++;
            }
            candidates = move(next_pool);

            cout << best_rem << endl;

        } else if (type == '!') {
            long long ans;
            if (!(ss >> ans)) finish(_pe, "Invalid answer format");

            bool found = false;
            long long other = -1;
            for (long long x : candidates) {
                if (x == ans) found = true;
                else other = x;
            }

            if (!found) {

                finish(_wa, "Answer %lld not consistent with tracked candidates", ans);
            }
            if (other != -1) {

                finish(_wa, "Ambiguous: valid candidates include %lld and %lld", ans, other);
            }

            finish(_ok, "Correct");
        } else {
            finish(_pe, "Unknown request type '%c'", type);
        }

        if (queries_count % 10 == 0) log_metrics();
    }
}

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

using namespace std;

bool is_integer(const string& s) {
    if (s.empty()) return false;
    for (char c : s) if (!isdigit(c)) return false;
    return true;
}

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

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

    const long long MIN_C = 1;
    const long long MAX_C = 1'000'000'000'000LL;

    if (mode == "adp") {
        cout << MIN_C << " " << MAX_C << endl;
        return 0;
    }

    long long C = 1;
    long long seedVal = -1;

    if (argc > 1 && is_integer(argv[1])) {
        try {
            seedVal = stoll(argv[1]);
        } catch (...) {
            seedVal = -1;
        }
    }

    if (seedVal >= 1 && seedVal <= 15) {
        switch (seedVal) {
            case 1: C = MIN_C; break;
            case 2: C = MAX_C; break;
            case 3: C = MAX_C - 1; break;
            case 4: C = 999999999989LL; break;
            case 5: C = 1LL << 39; break;
            case 6:
                {
                    C = 1;
                    vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41};
                    for (int p : primes) {
                        if (MAX_C / p >= C) C *= p;
                    }

                    while (MAX_C / 2 >= C) C *= 2;
                }
                break;
            case 7: C = 2; break;
            case 8: C = 42; break;
            case 9: C = 100; break;
            case 10: C = 123456789123LL; break;
            case 11: C = 1000000007; break;
            case 12: C = rnd.next(MAX_C / 2, MAX_C); break;
            case 13: C = rnd.next(MIN_C, 1000LL); break;
            case 14: C = rnd.next(MAX_C - 10000, MAX_C); break;
            case 15: C = 998244353; break;
        }
    } else {

        int type = rnd.next(4);
        if (type == 0) {

            C = rnd.next(MIN_C, 1000000LL);
        } else if (type == 1) {

            C = rnd.next(1000000LL, 1000000000LL);
        } else if (type == 2) {

            C = rnd.next(1000000000LL, MAX_C);
        } else {

            C = rnd.next(MIN_C, MAX_C);
        }
    }

    if (C < MIN_C) C = MIN_C;
    if (C > MAX_C) C = MAX_C;

    cout << C << endl;

    return 0;
}