Searching Rectangles
Contest: Codeforces Round 371 (Div. 1)
Difficulty rating: 2200
Tags: binary search, constructive algorithms, interactive

Filya just learned new geometry object — rectangle. He is given a field consisting of n × n unit cells. Rows are numbered from bottom to top with integer from 1 to n. Columns are numbered from left to right with integers from 1 to n. Cell, located at the intersection of the row r and column c is denoted as (r, c). Filya has painted two rectangles, such that their sides are parallel to coordinate axes and each cell lies fully inside or fully outside each of them. Moreover, no cell lies in both rectangles.

Later, hedgehog Filya became interested in the location of his rectangles but was unable to find the sheet of paper they were painted on. They were taken by Sonya and now she wants to play a little game with Filya. He tells her a query rectangle and she replies with the number of initial rectangles that lie fully inside the given query rectangle. The query rectangle should match the same conditions as initial rectangles. Rectangle lies fully inside the query if each o its cells lies inside the query.

Filya knows Sonya really well, so is sure that if he asks more than 200 questions she will stop to reply.

Input format:
The first line of the input contains an integer n (2 ≤ n ≤ 216) — size of the field.

For each query an integer between 0 and 2 is returned — the number of initial rectangles that lie fully inside the query rectangle.

Output format:
To make a query you have to print "? x1 y1 x2 y2" (without quotes) (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ n), where (x1, y1) stands for the position of the bottom left cell of the query and (x2, y2) stands for the up right cell of the query. You are allowed to ask no more than 200 queries. After each query you should perform "flush" operation and read the answer.

In case you suppose you've already determined the location of two rectangles (or run out of queries) you should print "! x11 y11 x12 y12 x21 y21 x22 y22" (without quotes), where first four integers describe the bottom left and up right cells of the first rectangle, and following four describe the corresponding cells of the second rectangle. You can print the rectangles in an arbitrary order. After you have printed the answer, print the end of the line and perform "flush". Your program should terminate immediately after it print the answer.

Interaction format:
To flush you can use (just after printing an integer and end-of-line):

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

You will get the Wrong Answer verdict if you ask more than 200 queries, or if you print an incorrect coordinates.

You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below).

Hacking.

The first line should contain an integer n (2 ≤ n ≤ 216).

The second line should contain four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ n) — the description of the first rectangle.

The third line contains the description of the second rectangle in the similar way.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Example input:
5
2
1
0
1
1
1
0
1

Example output:
? 1 1 5 5
? 1 1 3 3
? 1 1 3 1
? 2 2 2 2
? 3 3 5 5
? 3 3 3 5
? 3 3 3 4
? 3 4 3 5
! 2 2 2 2 3 4 3 5

Editorial:
Assume we have just one rectangle. First we can find its right side. In binary search we check is out rectangle to the left of some line x2 using function get(1,1,x2,n). As soon as we found right coordinate we can 'cut' everything to the right of the line, because there is nothing to look. In the same way we will find all sides.
O(12 * logN):
Main idea is to find a line which will split space in the way that rectangles will lie in different parts, as rectangles are not intersected it is always possible.
We can assume that intersected line is parallel to y coordinate and use binary search by x. On each step of search we will count amount of rectangles on each side. If we have pair (1, 1) then line is found. If we have pair (0, 0) then intersected line is parallel to x coordinate. Otherwise we should search in the half where we have some rectangles.
In worst case we will have 2 searches each will take 2 * log(n) time, also we have 4 * log(n) time to find separated rectangle. In total we 2 * 2 * log(n) + 2 * 4 * log(n) = 12 * log(n).
O(8 * logN):
We can find first rectangle assuming that here is just one rectangle. In each of four of our search we will assume that rectangle is present if get will return 1 or 2.
When we have one rectangle we can search second assuming that we can modify get function to get2, which will assume coordinates of first rectangle and decrease original value if it is required.