Problem: ioi07_a
Categories: search, math
Difficulty: easy
Time limit: 1000 ms | Memory limit: 64 MB

Mirko is a big fan of crop circles, geometrical formations of flattened crops that are supposedly of alien origin.

One summer night he decided to make his own formation on his grandmother's meadow. The great patriot that he is, Mirko decided to make a crop formation that would have the shape of the shield part of the Croatian coat of arms, which is a $5 \times 5$ chessboard with $13$ red squares and $12$ white squares.

![](https://ioi.contest.codeforces.com/espresso/08818a0e55bc586b67034b4c4fa314f49d8f0e57.png)

The chessboard part of the Croatian coat of arms. Grandma's meadow is a square divided into $N \times N$ cells. The cell in the lower left corner of the meadow is represented by the coordinates $(1, 1)$ and the cell in the upper right corner is represented by $(N, N)$.

Mirko decided to flatten only the grass belonging to red squares in the chessboard, leaving the rest of the grass intact. He picked an odd integer $M \ge 3$ and flattened the grass so that each square of the chessboard comprises $M \times M$ cells in the meadow, and the chessboard completely fits inside the meadow.

![](https://ioi.contest.codeforces.com/espresso/6856cf1ac83cbecbb3180c112fd11dedcc5d750e.png)

Example meadow and Mirko's crop formation, with $N = 19$ and $M = 3$. Cells with flattened grass are shown in gray. The center of the formation is at $(12, 9)$ and is marked with a black point.

After Mirko went to sleep, his peculiar creation drew the attention of real aliens! They are floating high above the meadow in their spaceship and examining Mirko's crop formation with a simple device. This device can only determine whether the grass in a particular cell is flattened or not.

The aliens have found one cell with flattened grass and now they want to find the center cell of Mirko's masterpiece, so that they may marvel at its beauty. They do not know the size $M$ of each square in Mirko's formation.

Write a program that, given the size $N$ of the meadow, the coordinates $(X_0, Y_0)$ of one cell with flattened grass, and the ability to interact with the alien device, finds the coordinates of the center cell of Mirko's crop formation.

The device may be used at most $300$ times in one test run.

Interaction

This is an interactive task. Your program sends commands to the alien device using the standard output, and receives feedback from the device by reading from the standard input.

* At the beginning of your program, you should read three integers $N$, $X_0$ and $Y_0$ from the standard input, separated by single spaces. The number $N$ ($15 \le N \le 2\,000\,000\,000$) is the size of the meadow, while $(X_0, Y_0)$ are the coordinates of one cell with flattened grass.
* To examine the grass in the cell $(X, Y)$ using the alien device, you should output a line of the form "examine X Y" to the standard output. If the coordinates $(X, Y)$ are not inside the meadow (the conditions $1 \le X \le N$ and $1 \le Y \le N$ are not satisfied), or if you use this facility more than $300$ times, your program will receive a score of zero on that test run.
* The alien device will respond with a single line containing the word "true" if the grass in cell $(X, Y)$ is flattened and the word "false" otherwise.
* When your program has found the center cell, it should output a line of the form "solution $X_C$ $Y_C$" to the standard output, where $(X_C, Y_C)$ are the coordinates of the center cell.

In order to interact properly with the grader, your program needs to flush the standard output after every write operation.

Scoring

In test cases worth a total of $40$ points, the size $M$ of each of Mirko's squares will be at most $100$. Each test run will have a unique correct answer that will not depend on the questions asked by your program.

Example

Input

```
19 7 4

true

false

false

true
```

Output

```
examine 11 2

examine 2 5

examine 9 14

examine 18 3

solution 12 9
```

Interactor / grader files:
aliens_interactor.cpp: // IOI07_A (aliens) - Interactor
// Check if point is inside circle
#include <bits/stdc++.h>
using namespace std;

int N, R;
int cx, cy;  // circle center
int known_x, known_y;  // known flattened point
int queries = 0;
const int MAX_QUERIES = 300;

void finish(int code, const char* msg) {
    fprintf(stderr, "%s\n", msg);
    FILE* tout = fopen("tout.txt", "w");
    if (tout) {
        fprintf(tout, "queries=%d\n", queries);
        fprintf(tout, "query_limit=%d\n", MAX_QUERIES);
        fclose(tout);
    }
    exit(code);
}

bool inside_circle(int x, int y) {
    long long dx = x - cx;
    long long dy = y - cy;
    return dx * dx + dy * dy <= (long long)R * R;
}

int main(int argc, char* argv[]) {
    if (argc < 2) {
        finish(2, "Usage: interactor <input_file>");
    }

    FILE* fin = fopen(argv[1], "r");
    if (!fin) {
        finish(2, "Cannot open input file");
    }

    fscanf(fin, "%d %d", &N, &R);
    fscanf(fin, "%d %d", &cx, &cy);
    fscanf(fin, "%d %d", &known_x, &known_y);
    fclose(fin);

    // Send initial info: N, known_x, known_y
    printf("%d %d %d\n", N, known_x, known_y);
    fflush(stdout);

    char cmd[20];
    while (scanf("%s", cmd) == 1) {
        if (strcmp(cmd, "examine") == 0) {
            int x, y;
            if (scanf("%d %d", &x, &y) != 2) {
                finish(2, "PE: Invalid examine format");
            }

            queries++;
            if (queries > MAX_QUERIES) {
                finish(1, "WA: Query limit exceeded");
            }

            if (x < 1 || x > N || y < 1 || y > N) {
                finish(1, "WA: Point out of bounds");
            }

            printf("%s\n", inside_circle(x, y) ? "true" : "false");
            fflush(stdout);

        } else if (strcmp(cmd, "solution") == 0) {
            int sx, sy;
            if (scanf("%d %d", &sx, &sy) != 2) {
                finish(2, "PE: Invalid solution format");
            }

            if (sx == cx && sy == cy) {
                finish(0, "OK");
            } else {
                finish(1, "WA: Wrong center");
            }
        } else {
            finish(2, "PE: Unknown command");
        }
    }

    finish(2, "PE: No solution provided");
    return 0;
}

non_adaptive.cpp: // IOI07_A (aliens) - Croatian Coat of Arms Interactor
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static int queries = 0;
static int query_limit = 300;
static long long N, M, cx, cy;

void log_metrics() {
    tout << "queries=" << queries << endl;
    tout << "query_limit=" << query_limit << endl;
}

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

bool is_flattened(long long x, long long y) {
    // Check if (x,y) is within the 5x5 chessboard pattern centered at (cx,cy)
    // Each square is M×M, total size is 5M×5M
    long long half = (5 * M) / 2;  // 2.5 * M, but M is odd so 5M is odd

    // Bounds of the chessboard
    long long left = cx - half;
    long long right = cx + half;
    long long bottom = cy - half;
    long long top = cy + half;

    if (x < left || x > right || y < bottom || y > top) {
        return false;
    }

    // Determine which square (i, j) the point is in (0-indexed, 0-4)
    // Square (0,0) is bottom-left, (4,4) is top-right
    long long dx = x - left;
    long long dy = y - bottom;
    int i = dx / M;  // column (0-4)
    int j = dy / M;  // row (0-4)

    if (i < 0 || i > 4 || j < 0 || j > 4) {
        return false;
    }

    // Red squares: (i + j) % 2 == 0
    // Pattern (j from top to bottom, i from left to right):
    // R W R W R  (j=4)
    // W R W R W  (j=3)
    // R W R W R  (j=2)
    // W R W R W  (j=1)
    // R W R W R  (j=0)
    return (i + j) % 2 == 0;
}

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

    N = inf.readLong();
    M = inf.readLong();
    long long x0 = inf.readLong();
    long long y0 = inf.readLong();
    cx = inf.readLong();
    cy = inf.readLong();

    log_metrics();

    cout << N << " " << x0 << " " << y0 << endl;
    cout.flush();

    string cmd;
    while (cin >> cmd) {
        if (cmd == "examine") {
            long long x, y;
            if (!(cin >> x >> y)) {
                finish(_pe, "Invalid examine format");
            }

            queries++;
            if (queries > query_limit) {
                finish(_wa, "Query limit exceeded");
            }

            if (x < 1 || x > N || y < 1 || y > N) {
                finish(_wa, "Point out of bounds");
            }

            cout << (is_flattened(x, y) ? "true" : "false") << endl;
            cout.flush();

        } else if (cmd == "solution") {
            long long sx, sy;
            if (!(cin >> sx >> sy)) {
                finish(_pe, "Invalid solution format");
            }

            if (sx == cx && sy == cy) {
                finish(_ok, "Correct");
            } else {
                finish(_wa, "Wrong center");
            }
        } else {
            finish(_pe, "Unknown command");
        }
    }

    finish(_pe, "No solution provided");
    return 0;
}