Problem: cf713_b
Difficulty: hard
Categories: search
Time limit: 1000 ms, memory limit: 256 MB

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

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

To make a query you have to print "? *x*1 *y*1 *x*2 *y*2" (without quotes) (1 ≤ *x*1 ≤ *x*2 ≤ *n*, 1 ≤ *y*1 ≤ *y*2 ≤ *n*), where (*x*1, *y*1) stands for the position of the bottom left cell of the query and (*x*2, *y*2) 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 "! *x*11 *y*11 *x*12 *y*12 *x*21 *y*21 *x*22 *y*22" (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

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).

Example

Input

```
5  
2  
1  
0  
1  
1  
1  
0  
1
```

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
```

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


static long long queries = 0;
static long long query_limit = 200; 


struct Rect {
    int x1, y1, x2, y2;
    
    
    bool operator==(const Rect& other) const {
        return x1 == other.x1 && y1 == other.y1 && x2 == other.x2 && y2 == other.y2;
    }
};

Rect r1, r2;
int n;


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


bool is_inside(const Rect& r, const Rect& q) {
    return (q.x1 <= r.x1 && r.x2 <= q.x2 &&
            q.y1 <= r.y1 && r.y2 <= q.y2);
}

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

    
    
    
    
    
    n = inf.readInt(2, 65536, "n");
    
    r1.x1 = inf.readInt(1, n, "r1.x1");
    r1.y1 = inf.readInt(1, n, "r1.y1");
    r1.x2 = inf.readInt(1, n, "r1.x2");
    r1.y2 = inf.readInt(1, n, "r1.y2");
    
    r2.x1 = inf.readInt(1, n, "r2.x1");
    r2.y1 = inf.readInt(1, n, "r2.y1");
    r2.x2 = inf.readInt(1, n, "r2.x2");
    r2.y2 = inf.readInt(1, n, "r2.y2");

    
    log_metrics();

    
    cout << n << endl;

    
    const int HARD_CAP = 2000;

    while (true) {
        
        string token;
        if (!(cin >> token)) {
            
            break;
        }

        if (token == "!") {
            
            
            vector<int> a(8);
            bool read_ok = true;
            for (int i = 0; i < 8; ++i) {
                if (!(cin >> a[i])) {
                    read_ok = false;
                    break;
                }
            }
            if (!read_ok) {
                finish(_pe, "Unexpected end of input reading answer coordinates");
            }

            Rect ans1 = {a[0], a[1], a[2], a[3]};
            Rect ans2 = {a[4], a[5], a[6], a[7]};

            
            bool correct = false;
            if ((ans1 == r1 && ans2 == r2) || (ans1 == r2 && ans2 == r1)) {
                correct = true;
            }

            if (correct) {
                finish(_ok, "Correct rectangles found");
            } else {
                finish(_wa, "Incorrect rectangles reported");
            }

        } else {
            
            
            int qx1, qy1, qx2, qy2;

            if (token == "?") {
                if (!(cin >> qx1 >> qy1 >> qx2 >> qy2)) {
                    finish(_pe, "Unexpected end of input reading query");
                }
            } else {
                
                try {
                    qx1 = stoi(token);
                } catch (...) {
                    finish(_pe, "Expected integer or '?' as first token");
                }
                if (!(cin >> qy1 >> qx2 >> qy2)) {
                    finish(_pe, "Unexpected end of input reading query");
                }
            }

            
            queries++;

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

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

            
            
            if (qx1 < 1 || qx1 > qx2 || qx2 > n ||
                qy1 < 1 || qy1 > qy2 || qy2 > n) {
                finish(_wa, format("Query coordinates invalid: %d %d %d %d (n=%d)", qx1, qy1, qx2, qy2, n));
            }

            
            int cnt = 0;
            Rect q = {qx1, qy1, qx2, qy2};
            if (is_inside(r1, q)) cnt++;
            if (is_inside(r2, q)) cnt++;

            
            cout << cnt << endl;
        }
    }

    
    finish(_pe, "Interaction ended without final answer (!)");
    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 = 200;
static int n;


struct Rect {
    int x1, y1, x2, y2;
    
    
    bool operator==(const Rect& other) const {
        return x1 == other.x1 && y1 == other.y1 && x2 == other.x2 && y2 == other.y2;
    }

    
    bool inside(const Rect& query) const {
        return x1 >= query.x1 && x2 <= query.x2 &&
               y1 >= query.y1 && y2 <= query.y2;
    }

    
    bool valid(int limit) const {
        return x1 >= 1 && x1 <= x2 && x2 <= limit &&
               y1 >= 1 && y1 <= y2 && y2 <= limit;
    }
};

static Rect r1_hidden, r2_hidden;


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


void generate_hidden() {
    
    
    rnd.setSeed(n * 239017LL + 7777);

    
    int axis = rnd.next(2); 
    int split = rnd.next(1, n - 1);

    auto get_interval = [&](int min_v, int max_v) {
        int a = rnd.next(min_v, max_v);
        int b = rnd.next(min_v, max_v);
        if (a > b) swap(a, b);
        return pair<int,int>{a, b};
    };

    if (axis == 0) { 
        
        
        pair<int,int> x1r = get_interval(1, split);
        pair<int,int> x2r = get_interval(split + 1, n);
        pair<int,int> y1r = get_interval(1, n);
        pair<int,int> y2r = get_interval(1, n);
        
        r1_hidden = {x1r.first, y1r.first, x1r.second, y1r.second};
        r2_hidden = {x2r.first, y2r.first, x2r.second, y2r.second};
    } else { 
        
        pair<int,int> y1r = get_interval(1, split);
        pair<int,int> y2r = get_interval(split + 1, n);
        pair<int,int> x1r = get_interval(1, n);
        pair<int,int> x2r = get_interval(1, n);

        r1_hidden = {x1r.first, y1r.first, x1r.second, y1r.second};
        r2_hidden = {x2r.first, y2r.first, x2r.second, y2r.second};
    }
}

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

    
    n = inf.readInt();

    
    
    if (!inf.seekEof()) {
        r1_hidden.x1 = inf.readInt();
        r1_hidden.y1 = inf.readInt();
        r1_hidden.x2 = inf.readInt();
        r1_hidden.y2 = inf.readInt();
        
        r2_hidden.x1 = inf.readInt();
        r2_hidden.y1 = inf.readInt();
        r2_hidden.x2 = inf.readInt();
        r2_hidden.y2 = inf.readInt();
    } else {
        
        generate_hidden();
    }

    
    log_metrics();

    
    cout << n << endl;

    string cmd;
    while (true) {
        if (cin.eof()) break;
        cin >> cmd;
        if (cin.fail()) break;

        if (cmd == "?") {
            queries++;
            
            if (queries > query_limit) {
                finish(_wa, "Query limit exceeded (200)");
            }
            
            
            if (queries % 10 == 0) log_metrics();

            Rect q;
            cin >> q.x1 >> q.y1 >> q.x2 >> q.y2;
            if (cin.fail()) finish(_pe, "Invalid query format");

            
            if (!q.valid(n)) {
                finish(_pe, format("Query out of bounds: %d %d %d %d", q.x1, q.y1, q.x2, q.y2));
            }

            int cnt = 0;
            if (r1_hidden.inside(q)) cnt++;
            if (r2_hidden.inside(q)) cnt++;

            cout << cnt << endl;
        } else if (cmd == "!") {
            Rect u1, u2;
            cin >> u1.x1 >> u1.y1 >> u1.x2 >> u1.y2;
            cin >> u2.x1 >> u2.y1 >> u2.x2 >> u2.y2;
            if (cin.fail()) finish(_pe, "Invalid answer format");

            if (!u1.valid(n) || !u2.valid(n)) {
                finish(_wa, "Answer coordinates out of bounds");
            }

            
            bool match = false;
            if ((u1 == r1_hidden && u2 == r2_hidden) || (u1 == r2_hidden && u2 == r1_hidden)) {
                match = true;
            }

            if (match) {
                finish(_ok, format("Correct! Used %d queries.", queries));
            } else {
                finish(_wa, format("Incorrect. Expected: (%d %d %d %d), (%d %d %d %d)", 
                    r1_hidden.x1, r1_hidden.y1, r1_hidden.x2, r1_hidden.y2,
                    r2_hidden.x1, r2_hidden.y1, r2_hidden.x2, r2_hidden.y2));
            }
        } else {
            finish(_pe, "Unknown command: " + cmd);
        }
    }

    finish(_pe, "Unexpected EOF without answer");
    return 0;
}


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


struct Rect {
    int x1, y1, x2, y2;
};


pair<int, int> getInterval(int minVal, int maxVal) {
    if (minVal > maxVal) return {minVal, minVal};
    int a = rnd.next(minVal, maxVal);
    int b = rnd.next(minVal, maxVal);
    if (a > b) swap(a, b);
    return {a, b};
}

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

    
    
    
    string mode = opt<string>("mode", "non");
    int n_arg = opt<int>("n", 0);

    int n;
    if (n_arg > 0) {
        n = n_arg;
    } else {
        
        
        long long seedVal = atoll(argv[1]);
        
        
        if (seedVal == 1) n = 2;          
        else if (seedVal == 2) n = 65536; 
        else if (seedVal == 3) n = 10;    
        else if (seedVal == 4) n = 100;   
        else if (seedVal == 5) n = 3;     
        else {
            
            int p = rnd.next(100);
            if (p < 5) n = rnd.next(2, 50);
            else if (p < 15) n = rnd.next(51, 1000);
            else n = rnd.next(1001, 65536);
        }
    }

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

    
    
    
    
    int axis = rnd.next(2);
    
    
    
    int split = rnd.next(1, n - 1);

    
    bool touch = (rnd.next(3) == 0); 
    bool align = (rnd.next(5) == 0); 

    pair<int, int> rA_split, rB_split; 
    pair<int, int> rA_other, rB_other; 

    
    rA_split = getInterval(1, split);
    rB_split = getInterval(split + 1, n);

    if (touch) {
        
        if (rnd.next(2)) rA_split.second = split;
        if (rnd.next(2)) rB_split.first = split + 1;
    }

    
    rA_other = getInterval(1, n);
    if (align) {
        rB_other = rA_other;
    } else {
        rB_other = getInterval(1, n);
    }
    
    
    if (rnd.next(10) == 0) {
        rA_other = {1, n};
        if (rnd.next(2)) rB_other = {1, n};
    }

    Rect r1, r2;
    if (axis == 0) { 
        
        r1 = {rA_split.first, rA_other.first, rA_split.second, rA_other.second};
        r2 = {rB_split.first, rB_other.first, rB_split.second, rB_other.second};
    } else { 
        
        r1 = {rA_other.first, rA_split.first, rA_other.second, rA_split.second};
        r2 = {rB_other.first, rB_split.first, rB_other.second, rB_split.second};
    }

    
    if (rnd.next(2)) swap(r1, r2);

    
    cout << n << endl;
    cout << r1.x1 << " " << r1.y1 << " " << r1.x2 << " " << r1.y2 << endl;
    cout << r2.x1 << " " << r2.y1 << " " << r2.x2 << " " << r2.y2 << endl;

    return 0;
}