codeforces#P1205C. Palindromic Paths
Palindromic Paths
Description
This is an interactive problem
You are given a grid , where is odd. Rows are enumerated from to from up to down, columns are enumerated from to from left to right. Cell, standing on the intersection of row and column , is denoted by .
Every cell contains or . It is known that the top-left cell contains , and the bottom-right cell contains .
We want to know numbers in all cells of the grid. To do so we can ask the following questions:
" ", where , , and . In other words, we output two different cells , of the grid such that we can get from the first to the second by moving only to the right and down, and they aren't adjacent.
As a response to such question you will be told if there exists a path between and , going only to the right or down, numbers in cells of which form a palindrome.
For example, paths, shown in green, are palindromic, so answer for " " and " " would be that there exists such path. However, there is no palindromic path between and .

Determine all cells of the grid by asking not more than questions. It can be shown that the answer always exists.
The first line contains odd integer () — the side of the grid.
Interaction
You begin the interaction by reading .
To ask a question about cells , in a separate line output " ".
Numbers in the query have to satisfy , , and . Don't forget to 'flush', to get the answer.
In response, you will receive , if there exists a path going from to only to the right or down, numbers in cells of which form a palindrome, and otherwise.
In case your query is invalid or you asked more than queries, program will print and will finish interaction. You will receive Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.
When you determine numbers in all cells, output "!".
Then output lines, the -th of which is a string of length , corresponding to numbers in the -th row of the grid.
After printing a 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.
Hack Format
To hack, use the following format.
The first line should contain a single odd integer (side of your grid).
The -th of following lines should contain a string of length corresponding to the -th row of the grid. Top left element of the grid has to be equal to , bottom right has to be equal to .
Input
The first line contains odd integer () — the side of the grid.