Problem: cf1114_e
Difficulty: medium
Categories: search, math
Time limit: 2000 ms, memory limit: 256 MB

This is an interactive problem!

An arithmetic progression or arithmetic sequence is a sequence of integers such that the subtraction of element with its previous element ($x_i - x_{i - 1}$, where $i \ge 2$) is constant — such difference is called a common difference of the sequence.

That is, an arithmetic progression is a sequence of form $x_i = x_1 + (i - 1) d$, where $d$ is a common difference of the sequence.

There is a secret list of $n$ integers $a_1, a_2, \ldots, a_n$.

It is guaranteed that all elements $a_1, a_2, \ldots, a_n$ are between $0$ and $10^9$, inclusive.

This list is special: if sorted in increasing order, it will form an arithmetic progression with positive common difference ($d > 0$). For example, the list $[14, 24, 9, 19]$ satisfies this requirement, after sorting it makes a list $[9, 14, 19, 24]$, which can be produced as $x_n = 9 + 5 \cdot (n - 1)$.

Also you are also given a device, which has a quite discharged battery, thus you can only use it to perform at most $60$ queries of following two types:

* Given a value $i$ ($1 \le i \le n$), the device will show the value of the $a_i$.
* Given a value $x$ ($0 \le x \le 10^9$), the device will return $1$ if an element with a value strictly greater than $x$ exists, and it will return $0$ otherwise.

Your can use this special device for at most $60$ queries. Could you please find out the smallest element and the common difference of the sequence? That is, values $x_1$ and $d$ in the definition of the arithmetic progression. Note that the array $a$ is not sorted.

Interaction

The interaction starts with a single integer $n$ ($2 \le n \le 10^6$), the size of the list of integers.

Then you can make queries of two types:

* "? i" ($1 \le i \le n$) — to get the value of $a_i$.
* "> x" ($0 \le x \le 10^9$) — to check whether there exists an element greater than $x$

After the query read its result $r$ as an integer.

* For the first query type, the $r$ satisfies $0 \le r \le 10^9$.
* For the second query type, the $r$ is either $0$ or $1$.
* In case you make more than $60$ queries or violated the number range in the queries, you will get a $r = -1$.
* If you terminate after receiving the -1, you will get the "Wrong answer" verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

When you find out what the smallest element $x_1$ and common difference $d$, print

* "! $x_1$ $d$"

And quit after that. This query is not counted towards the $60$ queries limit.

After printing any query 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.

Example

Input

```
4

0

1

14

24

9

19
```

Output

```
> 25

> 15

? 1

? 2

? 3

? 4

! 9 5
```

Note

Note that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well.

The list in the example test is $[14, 24, 9, 19]$.

Non-adaptive interactor (C++):











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

using namespace std;


static long long queries = 0;

static const long long query_limit = 60;



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 main(int argc, char** argv) {
    
    registerInteraction(argc, argv);
    
    
    atexit(log_metrics);

    
    
    
    
    
    int n = inf.readInt();
    
    if (n < 2) {
        finish(_fail, "Generator error: n < 2");
    }

    vector<long long> a(n);
    long long min_val = -1;
    long long max_val = -1;

    for (int i = 0; i < n; ++i) {
        a[i] = inf.readLong();
        
        
        if (i == 0) {
            min_val = a[i];
            max_val = a[i];
        } else {
            if (a[i] < min_val) min_val = a[i];
            if (a[i] > max_val) max_val = a[i];
        }
    }

    
    
    
    
    long long true_x1 = min_val;
    long long true_d = (max_val - min_val) / (n - 1);

    
    cout << n << endl;

    
    
    
    long long hard_cap = 500; 

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

        string type;
        if (!(cin >> type)) {
            
            finish(_pe, "Unexpected EOF: expected query or answer");
        }

        if (type == "!") {
            
            long long ans_x1, ans_d;
            if (!(cin >> ans_x1 >> ans_d)) {
                finish(_pe, "Invalid final answer format");
            }
            
            if (ans_x1 == true_x1 && ans_d == true_d) {
                finish(_ok, "Correct");
            } else {
                string msg = "Expected " + to_string(true_x1) + " " + to_string(true_d) +
                             ", got " + to_string(ans_x1) + " " + to_string(ans_d);
                finish(_wa, msg);
            }
        } else if (type == "?") {
            
            int i;
            if (!(cin >> i)) {
                finish(_pe, "Invalid format for '?' query");
            }
            queries++;

            
            if (i < 1 || i > n) {
                finish(_wa, "Index out of range: " + to_string(i));
            }

            cout << a[i-1] << endl;
        } else if (type == ">") {
            
            long long x;
            if (!(cin >> x)) {
                finish(_pe, "Invalid format for '>' query");
            }
            queries++;

            
            if (x < 0 || x > 1000000000LL) {
                finish(_wa, "Value out of range: " + to_string(x));
            }

            
            
            cout << (max_val > x ? 1 : 0) << endl;
        } else {
            finish(_pe, "Unknown token: " + type);
        }

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

    return 0;
}


Adaptive interactor (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;


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



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


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

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

    
    int n = inf.readInt();
    
    
    
    
    
    
    char sep = inf.readChar();
    
    
    if (sep == '\r') {
        inf.readChar(); 
        sep = '\n';
    }

    
    
    bool is_adaptive = (sep == ' ');

    vector<long long> a;
    long long x1_secret, d_secret;

    if (is_adaptive) {
        
        x1_secret = inf.readLong();
        d_secret = inf.readLong();
        
        a.resize(n);
        for(int i=0; i<n; ++i) {
            a[i] = x1_secret + (long long)i * d_secret;
        }
        
        shuffle(a.begin(), a.end());
    } else {
        
        a.resize(n);
        for(int i=0; i<n; ++i) {
            a[i] = inf.readLong();
        }
        
        
        vector<long long> sorted_a = a;
        sort(sorted_a.begin(), sorted_a.end());
        x1_secret = sorted_a[0];
        
        d_secret = sorted_a[1] - sorted_a[0];
    }

    
    long long max_val = -1;
    for (long long x : a) {
        if (x > max_val) max_val = x;
    }

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

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

        string type;
        if (!(cin >> type)) {
            finish(_wa, "Unexpected EOF from solution");
        }

        if (type == "!") {
            
            long long ans_x1, ans_d;
            if (!(cin >> ans_x1 >> ans_d)) {
                finish(_pe, "Invalid answer format");
            }
            
            if (ans_x1 == x1_secret && ans_d == d_secret) {
                finish(_ok, "Correct");
            } else {
                finish(_wa, format("Expected x1=%lld d=%lld, but found x1=%lld d=%lld", 
                                   x1_secret, d_secret, ans_x1, ans_d));
            }
        } else if (type == "?") {
            
            queries++;
            
            
            if (queries > query_limit) {
                cout << -1 << endl;
                finish(_wa, "Query limit exceeded (60)");
            }

            int i;
            if (!(cin >> i)) finish(_pe, "Invalid index format");
            
            if (i < 1 || i > n) {
                cout << -1 << endl;
                finish(_wa, "Index out of range");
            }
            
            cout << a[i-1] << endl;
        } else if (type == ">") {
            
            queries++;

            
            if (queries > query_limit) {
                cout << -1 << endl;
                finish(_wa, "Query limit exceeded (60)");
            }

            long long x;
            if (!(cin >> x)) finish(_pe, "Invalid value format");
            
            if (x < 0 || x > 1000000000LL) {
                cout << -1 << endl;
                finish(_wa, "Value out of range");
            }
            
            cout << (max_val > x ? 1 : 0) << endl;
        } else {
            finish(_pe, "Unknown query type: " + type);
        }
        
        
        if (queries % 10 == 0) log_metrics();
    }
}


Test generator (C++):
#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 seed_val = atoi(argv[1]);

    long long n, x1, d;

    
    if (seed_val == 1) {
        
        n = 2;
        d = 1000000000;
        x1 = 0; 
        
    } else if (seed_val == 2) {
        
        n = 1000000;
        d = 1;
        x1 = 0;
        
    } else if (seed_val == 3) {
        
        n = 1000000;
        
        d = 1000;
        
        x1 = 1000000000LL - (n - 1) * d;
    } else {
        
        
        
        int n_type = rnd.next(1, 10);
        if (n_type <= 3) {
            
            n = rnd.next(2, 100);
        } else if (n_type <= 6) {
            
            n = rnd.next(101, 50000);
        } else {
            
            n = rnd.next(50001, 1000000);
        }

        
        long long max_d = 1000000000LL / (n - 1);
        if (max_d < 1) max_d = 1; 

        
        if (rnd.next(3) == 0) {
            
            d = rnd.next(1LL, max_d);
        } else {
            
            d = rnd.next(1LL, min(max_d, 2000LL));
        }

        
        long long max_x1 = 1000000000LL - (n - 1) * d;
        int x1_type = rnd.next(1, 5);
        if (x1_type == 1) {
            x1 = 0; 
        } else if (x1_type == 2) {
            x1 = max_x1; 
        } else {
            x1 = rnd.next(0LL, max_x1); 
        }
    }

    
    if (mode == "non") {
        
        cout << n << "\n";
        vector<long long> a(n);
        for (int i = 0; i < n; i++) {
            a[i] = x1 + (long long)i * d;
        }
        
        shuffle(a.begin(), a.end());
        println(a);
    } else {
        
        
        cout << n << " " << x1 << " " << d << "\n";
    }

    return 0;
}