Problem: cf1838_f
Difficulty: hard
Categories: search
Time limit: 2000 ms, memory limit: 256 MB

This is an interactive problem.

There is an $n$ by $n$ grid of conveyor belts, in positions $(1, 1)$ through $(n, n)$ of a coordinate plane. Every other square in the plane is empty. Each conveyor belt can be configured to move boxes up ('^'), down ('v'), left ('<'), or right ('>'). If a box moves onto an empty square, it stops moving.

However, one of the $n^2$ belts is stuck, and will always move boxes in the same direction, no matter how it is configured. Your goal is to perform a series of tests to determine which conveyor belt is stuck, and the direction in which it sends items.

To achieve this, you can perform up to $25$ tests. In each test, you assign a direction to all $n^2$ belts, place a box on top of one of them, and then turn all of the conveyors on.

![](https://espresso.codeforces.com/3914cfd55bb4a91bdd525023ad83966f6c6a23cc.png)One possible result of a query with $n=4$. In this case, the box starts at $(2, 2)$. If there were no stuck conveyor, it would end up at $(5, 4)$, but because of the stuck '>' conveyor at $(3, 3)$, it enters an infinite loop.

The conveyors move the box around too quickly for you to see, so the only information you receive from a test is whether the box eventually stopped moving, and if so, the coordinates of its final position.

Interaction

You begin the interaction by reading a single integer $n$ ($2 \le n\le 100$) — the number of rows and columns in the grid.

Then, you can make at most $25$ queries.

Each query should begin with a line of the form ? r c, where r and c are the initial row and column of the box, respectively.

The next $n$ lines of the query should contain $n$ characters each. The $j$th character of the $i$th row should be one of '^', 'v', '<', or '>', indicating the direction of conveyor $(i, j)$ for this query.

After each query, you will receive two integers $x$ and $y$. If $x = y = -1$, then the box entered an infinite loop. Otherwise, its final position was $(x, y)$.

If you make too many queries or make an invalid query, you will receive the Wrong Answer verdict.

After you have found the stuck conveyor and its direction, print a single line ! r c dir, where r and c are the row and column of the stuck conveyor, respectively, and dir is one of '^', 'v', '<', or '>', indicating the direction of the stuck conveyor. Note that printing this answer does not count towards your total of $25$ queries. After printing this line, your program should terminate.

The interactor is non-adaptive. This means that the location and direction of the stuck belt is fixed at the start of the interaction, and does not change after the queries.

After printing a query do not forget to output the 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 the documentation for other languages.

Examples

Input

```
3

-1 -1

0 2
```

Output

```
? 2 2
>><
>>v
^<<

? 1 1
>><
>>v
^<<

! 1 2 ^
```

Input

```
4

-1 -1
```

Output

```
? 2 2
v>v<
^v<v
v>v^
>v>v

! 3 3 >
```

Note

For the first query of the first sample input, the box starts on $(2, 2)$ and enters an infinite loop containing rows $2$ and $3$. Because the stuck conveyor is in row $1$, it does not affect the outcome of the query.

For the second query of the first sample input, the conveyors are configured in the same way, but the box starts on $(1, 1)$. If there were no stuck conveyor, it would enter an infinite loop between $(1, 2)$ and $(1, 3)$. However, the stuck conveyor redirects it to $(0, 2)$.

After these two queries, the program is able to determine that the stuck conveyor is at $(1, 2)$ and directs items upward.

The query for the second sample input corresponds to the picture above. After asking the query, there are many possibilities for the stuck conveyor, but the program correctly guesses that it is at $(3, 3)$ and directs items to the right.

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 = 25; 



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



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

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

    
    
    int n = inf.readInt(2, 100, "n");
    int h_r = inf.readInt(1, n, "hidden_r");
    int h_c = inf.readInt(1, n, "hidden_c");
    string h_dir_str = inf.readToken("[\\^v<>]+", "hidden_dir");
    char h_dir = h_dir_str[0];

    
    log_metrics();

    
    cout << n << endl;

    
    string token;
    while (cin >> token) {
        if (token == "!") {
            
            int ans_r, ans_c;
            string ans_dir_str;
            if (!(cin >> ans_r >> ans_c >> ans_dir_str)) {
                finish(_pe, "Invalid answer format: expected 'r c dir' after '!'");
            }
            
            char ans_dir = ans_dir_str.empty() ? '?' : ans_dir_str[0];
            
            
            if (ans_r == h_r && ans_c == h_c && ans_dir == h_dir) {
                finish(_ok, "Correct stuck conveyor location and direction");
            } else {
                finish(_wa, format("Incorrect answer. Expected (%d, %d, %c), Got (%d, %d, %c)", 
                                   h_r, h_c, h_dir, ans_r, ans_c, ans_dir));
            }
            
        } else {
            
            
            int q_r, q_c;
            if (token == "?") {
                if (!(cin >> q_r >> q_c)) {
                    finish(_pe, "Invalid query format: expected 'r c' after '?'");
                }
            } else {
                
                try {
                    q_r = stoi(token);
                } catch (...) {
                    finish(_pe, format("Expected '?' or integer row index, got '%s'", token.c_str()));
                }
                if (!(cin >> q_c)) {
                    finish(_pe, "Invalid query format: expected column index after row");
                }
            }

            
            
            vector<string> grid(n);
            for (int i = 0; i < n; ++i) {
                if (!(cin >> grid[i])) {
                    finish(_pe, "Unexpected end of input while reading grid");
                }
                if ((int)grid[i].length() != n) {
                    finish(_pe, format("Grid row %d length is %d, expected %d", i + 1, (int)grid[i].length(), n));
                }
                
                for (char c : grid[i]) {
                    if (c != '^' && c != 'v' && c != '<' && c != '>') {
                        finish(_pe, format("Invalid character '%c' in grid", c));
                    }
                }
            }

            
            if (q_r < 1 || q_r > n || q_c < 1 || q_c > n) {
                finish(_wa, format("Query start position (%d, %d) is out of bounds [1, %d]", q_r, q_c, n));
            }

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

            
            int curr_r = q_r;
            int curr_c = q_c;
            
            
            
            static vector<vector<bool>> vis;
            vis.assign(n + 1, vector<bool>(n + 1, false));

            bool infinite_loop = false;
            while (true) {
                
                if (curr_r < 1 || curr_r > n || curr_c < 1 || curr_c > n) {
                    break;
                }
                
                
                if (vis[curr_r][curr_c]) {
                    infinite_loop = true;
                    break;
                }
                vis[curr_r][curr_c] = true;

                
                char d;
                if (curr_r == h_r && curr_c == h_c) {
                    d = h_dir; 
                } else {
                    d = grid[curr_r - 1][curr_c - 1]; 
                }

                
                if (d == '^') curr_r--;
                else if (d == 'v') curr_r++;
                else if (d == '<') curr_c--;
                else if (d == '>') curr_c++;
            }

            
            if (infinite_loop) {
                cout << "-1 -1" << endl;
            } else {
                cout << curr_r << " " << curr_c << endl;
            }

            
            if (queries > 250) {
                finish(_pe, "Hard query limit exceeded (too many queries)");
            }
        }
    }

    
    finish(_wa, "Unexpected EOF: solution terminated without providing an answer");
    return 0;
}


Adaptive interactor (C++):

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 n = opt<int>("n", -1);

    
    long long seedVal = 0;
    bool isHandCrafted = false;
    if (argc > 1) {
        try {
            seedVal = stoll(string(argv[1]));
            if (seedVal >= 1 && seedVal <= 3) {
                isHandCrafted = true;
            }
        } catch (...) {
            
        }
    }

    
    if (n == -1) {
        if (isHandCrafted) {
            if (seedVal == 1) n = 2;       
            else n = 100;                  
        } else {
            
            
            if (rnd.next(10) == 0) {
                n = rnd.next(2, 100);
            } else {
                n = rnd.wnext(2, 100, 15);
            }
        }
    }

    
    cout << n << endl;

    if (mode == "non") {
        
        int r, c;
        char dir;
        string dirs = "^v<>";

        if (isHandCrafted) {
            if (seedVal == 1) {
                
                r = 1; c = 1; dir = '^';
            } else if (seedVal == 2) {
                
                r = n; c = n; dir = '>';
            } else {
                
                r = n / 2; c = n / 2; dir = 'v';
            }
        } else {
            
            r = rnd.next(1, n);
            c = rnd.next(1, n);
            dir = dirs[rnd.next(4)];
        }
        cout << r << " " << c << " " << dir << endl;
    }
    

    return 0;
}