Problem: cf1715_f
Difficulty: medium
Categories: math
Time limit: 1000 ms, memory limit: 256 MB

This is an interactive problem.

Farmer Stanley grows corn on a rectangular field of size $ n \times m $ meters with corners in points $(0, 0)$, $(0, m)$, $(n, 0)$, $(n, m)$. This year the harvest was plentiful and corn covered the whole field.

The night before harvest aliens arrived and poisoned the corn in a single $1 \times 1$ square with sides parallel to field borders. The corn inside the square must not be eaten, but you cannot distinguish it from ordinary corn by sight. Stanley can only collect a sample of corn from an arbitrary polygon and bring it to the laboratory, where it will be analyzed and Stanley will be told the amount of corn in the sample that was poisoned. Since the harvest will soon deteriorate, such a study can be carried out no more than $5$ times.

More formally, it is allowed to make no more than $5$ queries, each of them calculates the area of intersection of a chosen polygon with a square of poisoned corn. It is necessary to find out the coordinates of the lower-left corner of the drawn square (the vertex of the square with the smallest $x$ and $y$ coordinates).

Input

First line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — field sizes.

Interaction

In order to query the area of intersection of a polygon with $k$ ($3 \le k \le 1000$) vertices at points with coordinates $(x_1, y_1),\; \dots ,\;(x_k, y_k)$ with a square of poisoned corn print $k+1$ lines. In the first of these lines print "? k". In the $i$-th of the next $k$ lines print two real numbers $x_i$ and $y_i$ ($|x_i|, |y_i| \le 10^4$) with at most $15$ digits after decimal place.

The polygon must have strictly positive area and contain no self-intersections.

In response to this query you will receive a real number $s$ ($0 \le s \le 1$) with $15$ digits after decimal place — the area of intersection of the square with the given polygon. If the polygon is invalid, there is no guarantee on the valid response.

When you have identified the drawn square, print on a separate line "! x y", where $x$ and $y$ are real numbers with at most $15$ digits after decimal place representing the coordinates of its lower-left corner ($0 \le x \le n - 1$, $0 \le y \le m - 1$), and then you have to terminate your program.

Your answer will be considered correct if its absolute or relative error on both coordinates does not exceed $10^{-6}$. Formally let your answer be $a$, jury answer be $b$. Your answer will be considered correct if $\frac{|a-b|}{max(1,|b|)} \le 10^{-6}$.

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.

Example

Input

```
3 3

0.5

0.5
```

Output

```
? 4
0 0
2 0
2 3
0 3

? 4
0 0
0 1
3 1
3 0

! 1.5 0.5
```

Note

In the first test from the statement, the aliens poisoned a square of corn with vertices at points with coordinates $(1.5, 0.5)$, $(1.5, 1.5)$, $(2.5, 1.5)$, $(2.5, 0.5)$. In the picture, it is red, the polygon selected in the query is blue, and their intersection is green.

Picture for the first query:

 ![](https://espresso.codeforces.com/e70c9b0c1e0606c47d8a7ba38838a3ec425f7228.png) 

Picture for the second query:

 ![](https://espresso.codeforces.com/e136a8c98a49c8ffde15bbb7290ae7d54d7ad09a.png)

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

using namespace std;

struct Pt {
    double x;
    double y;
};

static long long queries = 0;
static long long query_limit = 5;

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

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

static double polygon_area_abs(const vector<Pt>& poly) {
    if (poly.size() < 3) return 0.0;
    long double s = 0.0L;
    for (size_t i = 0; i < poly.size(); i++) {
        const auto& a = poly[i];
        const auto& b = poly[(i + 1) % poly.size()];
        s += (long double)a.x * (long double)b.y - (long double)b.x * (long double)a.y;
    }
    return (double)fabsl(s * 0.5L);
}

static Pt intersect_x(const Pt& a, const Pt& b, double x) {
    const double dx = b.x - a.x;
    if (fabs(dx) < 1e-18) return {x, a.y};
    const double t = (x - a.x) / dx;
    return {x, a.y + t * (b.y - a.y)};
}

static Pt intersect_y(const Pt& a, const Pt& b, double y) {
    const double dy = b.y - a.y;
    if (fabs(dy) < 1e-18) return {a.x, y};
    const double t = (y - a.y) / dy;
    return {a.x + t * (b.x - a.x), y};
}

static vector<Pt> clip_x_ge(const vector<Pt>& in, double x0) {
    vector<Pt> out;
    if (in.empty()) return out;
    auto inside = [&](const Pt& p) { return p.x >= x0 - 1e-12; };
    Pt prev = in.back();
    bool prev_in = inside(prev);
    for (const auto& cur : in) {
        bool cur_in = inside(cur);
        if (prev_in && cur_in) {
            out.push_back(cur);
        } else if (prev_in && !cur_in) {
            out.push_back(intersect_x(prev, cur, x0));
        } else if (!prev_in && cur_in) {
            out.push_back(intersect_x(prev, cur, x0));
            out.push_back(cur);
        }
        prev = cur;
        prev_in = cur_in;
    }
    return out;
}

static vector<Pt> clip_x_le(const vector<Pt>& in, double x1) {
    vector<Pt> out;
    if (in.empty()) return out;
    auto inside = [&](const Pt& p) { return p.x <= x1 + 1e-12; };
    Pt prev = in.back();
    bool prev_in = inside(prev);
    for (const auto& cur : in) {
        bool cur_in = inside(cur);
        if (prev_in && cur_in) {
            out.push_back(cur);
        } else if (prev_in && !cur_in) {
            out.push_back(intersect_x(prev, cur, x1));
        } else if (!prev_in && cur_in) {
            out.push_back(intersect_x(prev, cur, x1));
            out.push_back(cur);
        }
        prev = cur;
        prev_in = cur_in;
    }
    return out;
}

static vector<Pt> clip_y_ge(const vector<Pt>& in, double y0) {
    vector<Pt> out;
    if (in.empty()) return out;
    auto inside = [&](const Pt& p) { return p.y >= y0 - 1e-12; };
    Pt prev = in.back();
    bool prev_in = inside(prev);
    for (const auto& cur : in) {
        bool cur_in = inside(cur);
        if (prev_in && cur_in) {
            out.push_back(cur);
        } else if (prev_in && !cur_in) {
            out.push_back(intersect_y(prev, cur, y0));
        } else if (!prev_in && cur_in) {
            out.push_back(intersect_y(prev, cur, y0));
            out.push_back(cur);
        }
        prev = cur;
        prev_in = cur_in;
    }
    return out;
}

static vector<Pt> clip_y_le(const vector<Pt>& in, double y1) {
    vector<Pt> out;
    if (in.empty()) return out;
    auto inside = [&](const Pt& p) { return p.y <= y1 + 1e-12; };
    Pt prev = in.back();
    bool prev_in = inside(prev);
    for (const auto& cur : in) {
        bool cur_in = inside(cur);
        if (prev_in && cur_in) {
            out.push_back(cur);
        } else if (prev_in && !cur_in) {
            out.push_back(intersect_y(prev, cur, y1));
        } else if (!prev_in && cur_in) {
            out.push_back(intersect_y(prev, cur, y1));
            out.push_back(cur);
        }
        prev = cur;
        prev_in = cur_in;
    }
    return out;
}

static double intersection_area_with_unit_square(const vector<Pt>& poly, double x0, double y0) {
    vector<Pt> cur = poly;
    cur = clip_x_ge(cur, x0);
    cur = clip_x_le(cur, x0 + 1.0);
    cur = clip_y_ge(cur, y0);
    cur = clip_y_le(cur, y0 + 1.0);
    double a = polygon_area_abs(cur);
    if (a < 0.0) a = 0.0;
    if (a > 1.0) a = 1.0;
    return a;
}

static bool within_1e6(double got, double expected) {
    const double diff = fabs(got - expected);
    const double denom = max(1.0, fabs(expected));
    return diff / denom <= 1e-6;
}

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

    const int n = inf.readInt(1, 100, "n");
    const int m = inf.readInt(1, 100, "m");
    const double x0 = inf.readDouble(0.0, max(0, n - 1), "x");
    const double y0 = inf.readDouble(0.0, max(0, m - 1), "y");

    cout << n << " " << m << "\n";
    cout.flush();

    string tok;
    while (cin >> tok) {
        if (tok == "?") {
            int k = 0;
            if (!(cin >> k)) finish(_pe, "Malformed query: expected k");
            if (k < 3 || k > 1000) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "Invalid k");
            }
            queries++;
            if (queries > query_limit) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "Query limit exceeded");
            }

            vector<Pt> poly;
            poly.reserve((size_t)k);
            for (int i = 0; i < k; i++) {
                double x, y;
                if (!(cin >> x >> y)) finish(_pe, "Malformed query: expected point");
                poly.push_back({x, y});
            }
            if (polygon_area_abs(poly) <= 0.0) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "Invalid polygon (zero area)");
            }

            const double ans = intersection_area_with_unit_square(poly, x0, y0);
            cout << fixed << setprecision(15) << ans << "\n";
            cout.flush();
            log_metrics();
            continue;
        }

        if (tok == "!") {
            double x, y;
            if (!(cin >> x >> y)) finish(_pe, "Malformed answer");
            if (within_1e6(x, x0) && within_1e6(y, y0)) finish(_ok, "OK");
            finish(_wa, format("Wrong answer: expected (%0.15f, %0.15f), got (%0.15f, %0.15f)", x0, y0, x, y));
        }

        
        cout << -1 << "\n";
        cout.flush();
        finish(_pe, format("Unknown token: '%s'", tok.c_str()));
    }

    finish(_pe, "Unexpected EOF");
}



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

using namespace std;

struct Pt {
    double x;
    double y;
};

static long long queries = 0;
static long long query_limit = 5;

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

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

static long long parse_case_id(const char* case_path) {
    string s(case_path ? case_path : "");
    size_t slash = s.find_last_of("/\\");
    if (slash != string::npos) s = s.substr(slash + 1);
    size_t dot = s.find_last_of('.');
    if (dot != string::npos) s = s.substr(0, dot);
    long long id = 0;
    bool any = false;
    for (unsigned char ch : s) {
        if (isdigit(ch)) {
            any = true;
            id = id * 10 + (ch - '0');
        }
    }
    return any ? id : 0;
}

static double polygon_area_abs(const vector<Pt>& poly) {
    if (poly.size() < 3) return 0.0;
    long double s = 0.0L;
    for (size_t i = 0; i < poly.size(); i++) {
        const auto& a = poly[i];
        const auto& b = poly[(i + 1) % poly.size()];
        s += (long double)a.x * (long double)b.y - (long double)b.x * (long double)a.y;
    }
    return (double)fabsl(s * 0.5L);
}

static Pt intersect_x(const Pt& a, const Pt& b, double x) {
    const double dx = b.x - a.x;
    if (fabs(dx) < 1e-18) return {x, a.y};
    const double t = (x - a.x) / dx;
    return {x, a.y + t * (b.y - a.y)};
}

static Pt intersect_y(const Pt& a, const Pt& b, double y) {
    const double dy = b.y - a.y;
    if (fabs(dy) < 1e-18) return {a.x, y};
    const double t = (y - a.y) / dy;
    return {a.x + t * (b.x - a.x), y};
}

static vector<Pt> clip_x_ge(const vector<Pt>& in, double x0) {
    vector<Pt> out;
    if (in.empty()) return out;
    auto inside = [&](const Pt& p) { return p.x >= x0 - 1e-12; };
    Pt prev = in.back();
    bool prev_in = inside(prev);
    for (const auto& cur : in) {
        bool cur_in = inside(cur);
        if (prev_in && cur_in) {
            out.push_back(cur);
        } else if (prev_in && !cur_in) {
            out.push_back(intersect_x(prev, cur, x0));
        } else if (!prev_in && cur_in) {
            out.push_back(intersect_x(prev, cur, x0));
            out.push_back(cur);
        }
        prev = cur;
        prev_in = cur_in;
    }
    return out;
}

static vector<Pt> clip_x_le(const vector<Pt>& in, double x1) {
    vector<Pt> out;
    if (in.empty()) return out;
    auto inside = [&](const Pt& p) { return p.x <= x1 + 1e-12; };
    Pt prev = in.back();
    bool prev_in = inside(prev);
    for (const auto& cur : in) {
        bool cur_in = inside(cur);
        if (prev_in && cur_in) {
            out.push_back(cur);
        } else if (prev_in && !cur_in) {
            out.push_back(intersect_x(prev, cur, x1));
        } else if (!prev_in && cur_in) {
            out.push_back(intersect_x(prev, cur, x1));
            out.push_back(cur);
        }
        prev = cur;
        prev_in = cur_in;
    }
    return out;
}

static vector<Pt> clip_y_ge(const vector<Pt>& in, double y0) {
    vector<Pt> out;
    if (in.empty()) return out;
    auto inside = [&](const Pt& p) { return p.y >= y0 - 1e-12; };
    Pt prev = in.back();
    bool prev_in = inside(prev);
    for (const auto& cur : in) {
        bool cur_in = inside(cur);
        if (prev_in && cur_in) {
            out.push_back(cur);
        } else if (prev_in && !cur_in) {
            out.push_back(intersect_y(prev, cur, y0));
        } else if (!prev_in && cur_in) {
            out.push_back(intersect_y(prev, cur, y0));
            out.push_back(cur);
        }
        prev = cur;
        prev_in = cur_in;
    }
    return out;
}

static vector<Pt> clip_y_le(const vector<Pt>& in, double y1) {
    vector<Pt> out;
    if (in.empty()) return out;
    auto inside = [&](const Pt& p) { return p.y <= y1 + 1e-12; };
    Pt prev = in.back();
    bool prev_in = inside(prev);
    for (const auto& cur : in) {
        bool cur_in = inside(cur);
        if (prev_in && cur_in) {
            out.push_back(cur);
        } else if (prev_in && !cur_in) {
            out.push_back(intersect_y(prev, cur, y1));
        } else if (!prev_in && cur_in) {
            out.push_back(intersect_y(prev, cur, y1));
            out.push_back(cur);
        }
        prev = cur;
        prev_in = cur_in;
    }
    return out;
}

static double intersection_area_with_unit_square(const vector<Pt>& poly, double x0, double y0) {
    vector<Pt> cur = poly;
    cur = clip_x_ge(cur, x0);
    cur = clip_x_le(cur, x0 + 1.0);
    cur = clip_y_ge(cur, y0);
    cur = clip_y_le(cur, y0 + 1.0);
    double a = polygon_area_abs(cur);
    if (a < 0.0) a = 0.0;
    if (a > 1.0) a = 1.0;
    return a;
}

static bool within_1e6(double got, double expected) {
    const double diff = fabs(got - expected);
    const double denom = max(1.0, fabs(expected));
    return diff / denom <= 1e-6;
}

static double gen_coord(int lim, mt19937_64& rng) {
    if (lim <= 1) return 0.0;
    uniform_int_distribution<int> pick(1, 100);
    int t = pick(rng);

    if (t <= 20) {
        uniform_int_distribution<int> dist(0, lim - 1);
        return (double)dist(rng);
    }
    if (t <= 40) {
        uniform_int_distribution<int> dist(0, lim - 2);
        return (double)dist(rng) + 0.5;
    }
    if (t <= 50) {
        uniform_int_distribution<int> dist(0, lim - 1);
        double val = (double)dist(rng);
        const double eps = 1e-7;
        if (val < 0.5) val += eps;
        else if (val > lim - 1.5) val -= eps;
        else val += ((rng() & 1ULL) ? eps : -eps);
        val = max(0.0, min((double)lim - 1.0, val));
        return val;
    }

    uniform_real_distribution<double> dist(0.0, 1.0);
    return dist(rng) * (lim - 1);
}

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

    const int n = inf.readInt(1, 100, "n");
    const int m = inf.readInt(1, 100, "m");

    const long long case_id = (argc >= 2) ? parse_case_id(argv[1]) : 0;
    mt19937_64 rng(0xBADC0FFEEULL ^ (uint64_t)case_id ^ (uint64_t)n * 1315423911ULL ^ (uint64_t)m * 2654435761ULL);

    const double x0 = gen_coord(n, rng);
    const double y0 = gen_coord(m, rng);

    cout << n << " " << m << "\n";
    cout.flush();

    string tok;
    while (cin >> tok) {
        if (tok == "?") {
            int k = 0;
            if (!(cin >> k)) finish(_pe, "Malformed query: expected k");
            if (k < 3 || k > 1000) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "Invalid k");
            }
            queries++;
            if (queries > query_limit) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "Query limit exceeded");
            }

            vector<Pt> poly;
            poly.reserve((size_t)k);
            for (int i = 0; i < k; i++) {
                double x, y;
                if (!(cin >> x >> y)) finish(_pe, "Malformed query: expected point");
                poly.push_back({x, y});
            }
            if (polygon_area_abs(poly) <= 0.0) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "Invalid polygon (zero area)");
            }

            const double ans = intersection_area_with_unit_square(poly, x0, y0);
            cout << fixed << setprecision(15) << ans << "\n";
            cout.flush();
            log_metrics();
            continue;
        }

        if (tok == "!") {
            double x, y;
            if (!(cin >> x >> y)) finish(_pe, "Malformed answer");
            if (within_1e6(x, x0) && within_1e6(y, y0)) finish(_ok, "OK");
            finish(_wa, format("Wrong answer: expected (%0.15f, %0.15f), got (%0.15f, %0.15f)", x0, y0, x, y));
        }

        cout << -1 << "\n";
        cout.flush();
        finish(_pe, format("Unknown token: '%s'", tok.c_str()));
    }

    finish(_pe, "Unexpected EOF");
}



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);
    int m = opt<int>("m", -1);
    
    
    int seed = atoi(argv[1]);

    
    
    if (n == -1) {
        if (seed == 1) {
            n = 1; m = 1;
        } else if (seed == 2) {
            n = 100; m = 100;
        } else if (seed == 3) {
            
            n = 3; m = 3;
        } else {
            n = rnd.next(1, 100);
            m = rnd.next(1, 100);
        }
    }
    
    
    if (m == -1) {
        m = rnd.next(1, 100);
    }

    
    cout << n << " " << m << endl;

    
    if (mode == "non") {
        
        
        auto get_coord = [&](int lim) {
            if (lim == 1) return 0.0;
            
            int t = rnd.next(1, 100);
            
            
            if (t <= 20) { 
                return (double)rnd.next(0, lim - 1);
            }
            
            
            
            if (t <= 40) { 
                return rnd.next(0, lim - 2) + 0.5;
            }
            
            
            if (t <= 50) { 
                double val = rnd.next(0, lim - 1);
                double eps = 1e-7;
                
                if (val < 0.5) val += eps;
                else if (val > lim - 1.5) val -= eps;
                else val += (rnd.next(0, 1) ? eps : -eps);
                return val;
            }
            
            
            return rnd.next() * (lim - 1);
        };

        double x, y;
        
        
        if (seed == 3 && n == 3 && m == 3) {
            x = 1.5; y = 0.5;
        } 
        
        else if (seed == 1 && n == 1 && m == 1) {
            x = 0; y = 0;
        } 
        else {
            x = get_coord(n);
            y = get_coord(m);
        }
        
        cout << fixed << setprecision(15) << x << " " << y << endl;
    }
    
    
    

    return 0;
}