Problem: cf1063_c
Difficulty: easy
Categories: search, math
Time limit: 2000 ms, memory limit: 256 MB

This is an interactive problem.

In good old times dwarves tried to develop extrasensory abilities:

* Exactly *n* dwarves entered completely dark cave.
* Each dwarf received a hat — white or black. While in cave, none of the dwarves was able to see either his own hat or hats of other Dwarves.
* Dwarves went out of the cave to the meadow and sat at an arbitrary place one after the other. When a dwarf leaves the cave, he sees the colors of all hats of all dwarves that are seating on the meadow (i.e. left the cave before him). However, he is not able to see the color of his own hat and none of the dwarves can give him this information.
* The task for dwarves was to got diverged into two parts — one with dwarves with white hats and one with black hats.

After many centuries, dwarves finally managed to select the right place on the meadow without error. Will you be able to repeat their success?

You are asked to successively name *n* different integer points on the plane. After naming each new point you will be given its color — black or white. Your task is to ensure that the named points can be split by a line in such a way that all points of one color lie on the same side from the line and points of different colors lie on different sides. Moreover, no points can belong to the line. Also, you need to report any such line at the end of the process.

In this problem, the interactor is adaptive — the colors of the points in the tests are not fixed beforehand and the jury program can select them arbitrarily, in particular, depending on your program output.

Interaction

The first line of the standard input stream contains an integer *n* (1 ≤ *n* ≤ 30) — the number of points your program should name.

Then *n* times your program must print two integer coordinates *x* and *y* (0 ≤ *x* ≤ 109, 0 ≤ *y* ≤ 109). All points you print must be distinct.

In response to each coordinate pair your program will receive the string "black", if the point is black, or "white", if the point is white.

When all *n* points are processed, you need to print four integers *x*1, *y*1, *x*2 and *y*2 (0 ≤ *x*1, *y*1 ≤ 109, 0 ≤ *x*2, *y*2 ≤ 109) — coordinates of points (*x*1, *y*1) and (*x*2, *y*2), which form a line, which separates *n* points into black and white. Points (*x*1, *y*1) and (*x*2, *y*2) should not coincide.

Example

Input

```
5  
  
black  
  
black  
  
white  
  
white  
  
black
```

Output

```
0 0  
  
3 1  
  
2 3  
  
4 4  
  
0 2  
  
1 3 4 1
```

Note

In the sample input and output values are aligned only for simplicity of interpreting them chronologically. In real interaction no "extra" line breaks should appear.

The following picture illustrates the first test.

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

Non-adaptive interactor (C++):
#include "testlib.h"

#include <algorithm>
#include <csignal>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

struct Point {
    long long x = 0;
    long long y = 0;
};

static int queries = 0;
static int query_limit = 0;

static void log_queries() {
    tout << "queries=" << queries << "\n";
    tout << "query_limit=" << query_limit << "\n";
}

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

static long long cross(const Point& a, const Point& b, const Point& p) {
    
    return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x);
}

int main(int argc, char* argv[]) {
    registerInteraction(argc, argv);
    signal(SIGPIPE, SIG_IGN);
    atexit(log_queries);

    const int n = inf.readInt();
    Point line_a, line_b;
    if (inf.seekEof()) {
        
        line_a = Point{0, 0};
        line_b = Point{1000000000LL, 999999999LL};
    } else {
        line_a = Point{inf.readLong(), inf.readLong()};
        line_b = Point{inf.readLong(), inf.readLong()};
    }

    query_limit = n;
    vector<Point> points;
    points.reserve(n);
    vector<int> color;  
    color.reserve(n);
    set<pair<long long, long long>> seen;

    cout << n << "\n" << flush;

    for (int i = 0; i < n; i++) {
        Point p;
        if (!(cin >> p.x >> p.y)) {
            quit_with(_wa, "Failed to read point");
        }
        if (p.x < 0 || p.x > 1000000000LL || p.y < 0 || p.y > 1000000000LL) {
            quit_with(_wa, "Point out of range");
        }
        if (!seen.insert({p.x, p.y}).second) {
            quit_with(_wa, "Points must be distinct");
        }
        points.push_back(p);

        long long s = cross(line_a, line_b, p);
        
        int c = (s < 0) ? 1 : 0;
        color.push_back(c);
        queries++;

        cout << (c == 0 ? "white" : "black") << "\n" << flush;
    }

    Point out_a, out_b;
    if (!(cin >> out_a.x >> out_a.y >> out_b.x >> out_b.y)) {
        quit_with(_wa, "Failed to read final line");
    }
    if (out_a.x == out_b.x && out_a.y == out_b.y) {
        quit_with(_wa, "Degenerate line");
    }
    for (const Point& p : {out_a, out_b}) {
        if (p.x < 0 || p.x > 1000000000LL || p.y < 0 || p.y > 1000000000LL) {
            quit_with(_wa, "Line endpoints out of range");
        }
    }

    bool has_white = false;
    bool has_black = false;
    bool all_white_pos = true, all_white_neg = true;
    bool all_black_pos = true, all_black_neg = true;

    for (int i = 0; i < n; i++) {
        long long s = cross(out_a, out_b, points[i]);
        if (s == 0) {
            quit_with(_wa, "A point lies on the reported line");
        }
        if (color[i] == 0) {
            has_white = true;
            all_white_pos = all_white_pos && (s > 0);
            all_white_neg = all_white_neg && (s < 0);
        } else {
            has_black = true;
            all_black_pos = all_black_pos && (s > 0);
            all_black_neg = all_black_neg && (s < 0);
        }
    }

    if (!has_white || !has_black) {
        quit_with(_ok, "Trivial separation (single color)");
    }

    const bool ok =
        (all_white_pos && all_black_neg) ||
        (all_white_neg && all_black_pos);
    if (ok) {
        quit_with(_ok, "Correct");
    }
    quit_with(_wa, "Line does not separate colors");
}


Adaptive interactor (C++):
#include "testlib.h"

#include <algorithm>
#include <climits>
#include <csignal>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

struct Point {
    long long x = 0;
    long long y = 0;
};

struct Axis {
    long long a = 0;
    long long b = 0;
};

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

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

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

static __int128 cross128(const Point& a, const Point& b, const Point& p) {
    
    return (__int128)(b.x - a.x) * (p.y - a.y) - (__int128)(b.y - a.y) * (p.x - a.x);
}

static long long proj(const Axis& ax, const Point& p) {
    return ax.a * p.x + ax.b * p.y;
}

struct SepMetrics {
    bool feasible = false;
    bool has_both_colors = false;
    int separating_axes = 0;
    long long min_gap = LLONG_MAX;  
};

static SepMetrics evaluate_separability(const vector<Point>& pts, const vector<int>& col) {
    SepMetrics m;
    const int n = (int)pts.size();
    int white_cnt = 0, black_cnt = 0;
    for (int c : col) {
        if (c == 0) white_cnt++;
        else black_cnt++;
    }
    m.has_both_colors = (white_cnt > 0 && black_cnt > 0);
    if (!m.has_both_colors) {
        m.feasible = true;
        m.separating_axes = 0;
        m.min_gap = LLONG_MAX;
        return m;
    }

    vector<Axis> axes;
    axes.reserve(2 + n * (n - 1) / 2);
    axes.push_back(Axis{1, 0});
    axes.push_back(Axis{0, 1});
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            const long long dx = pts[j].x - pts[i].x;
            const long long dy = pts[j].y - pts[i].y;
            if (dx == 0 && dy == 0) continue;
            axes.push_back(Axis{dy, -dx});
        }
    }

    for (const Axis& ax : axes) {
        long long min_w = LLONG_MAX, max_w = LLONG_MIN;
        long long min_b = LLONG_MAX, max_b = LLONG_MIN;
        for (int i = 0; i < n; i++) {
            const long long v = proj(ax, pts[i]);
            if (col[i] == 0) {
                min_w = min(min_w, v);
                max_w = max(max_w, v);
            } else {
                min_b = min(min_b, v);
                max_b = max(max_b, v);
            }
        }
        const long long gap1 = min_b - max_w;  
        const long long gap2 = min_w - max_b;  
        const long long gap = max(gap1, gap2);
        if (gap > 0) {
            m.separating_axes++;
            m.min_gap = min(m.min_gap, gap);
        }
    }

    m.feasible = (m.separating_axes > 0);
    return m;
}

int main(int argc, char* argv[]) {
    registerInteraction(argc, argv);
    signal(SIGPIPE, SIG_IGN);
    atexit(log_queries);

    const int n = inf.readInt(1, 30, "n");
    
    
    (void)inf;

    query_limit = n;

    vector<Point> points;
    points.reserve(n);
    vector<int> color;  
    color.reserve(n);

    set<pair<long long, long long>> seen;

    cout << n << "\n" << flush;

    for (int i = 0; i < n; i++) {
        Point p;
        if (!(cin >> p.x >> p.y)) {
            quit_with(_wa, "Failed to read point");
        }
        queries++;

        if (p.x < 0 || p.x > 1000000000LL || p.y < 0 || p.y > 1000000000LL) {
            quit_with(_wa, "Point out of range");
        }
        if (!seen.insert({p.x, p.y}).second) {
            quit_with(_wa, "Points must be distinct");
        }

        
        vector<pair<int, SepMetrics>> options;
        options.reserve(2);
        for (int c = 0; c <= 1; c++) {
            points.push_back(p);
            color.push_back(c);
            SepMetrics m = evaluate_separability(points, color);
            if (m.feasible) options.push_back({c, m});
            points.pop_back();
            color.pop_back();
        }

        if (options.empty()) {
            quit_with(_wa, "No feasible color assignment remains (points not separable)");
        }

        int chosen = options[0].first;
        if (options.size() == 2) {
            
            if (options[0].second.has_both_colors != options[1].second.has_both_colors) {
                chosen = options[0].second.has_both_colors ? options[0].first : options[1].first;
            } else {
                
                const auto& a = options[0];
                const auto& b = options[1];
                if (a.second.separating_axes != b.second.separating_axes) {
                    chosen = (a.second.separating_axes < b.second.separating_axes) ? a.first : b.first;
                } else if (a.second.min_gap != b.second.min_gap) {
                    chosen = (a.second.min_gap < b.second.min_gap) ? a.first : b.first;
                } else {
                    
                    chosen = (i & 1) ? 1 : 0;
                }
            }
        }

        points.push_back(p);
        color.push_back(chosen);
        cout << (chosen == 0 ? "white" : "black") << "\n" << flush;
    }

    Point out_a, out_b;
    if (!(cin >> out_a.x >> out_a.y >> out_b.x >> out_b.y)) {
        quit_with(_wa, "Failed to read final line");
    }
    if (out_a.x == out_b.x && out_a.y == out_b.y) {
        quit_with(_wa, "Degenerate line");
    }
    for (const Point& p : {out_a, out_b}) {
        if (p.x < 0 || p.x > 1000000000LL || p.y < 0 || p.y > 1000000000LL) {
            quit_with(_wa, "Line endpoints out of range");
        }
    }

    bool has_white = false;
    bool has_black = false;
    bool all_white_pos = true, all_white_neg = true;
    bool all_black_pos = true, all_black_neg = true;

    for (int i = 0; i < n; i++) {
        const __int128 s = cross128(out_a, out_b, points[i]);
        if (s == 0) {
            quit_with(_wa, "A point lies on the reported line");
        }
        const bool pos = (s > 0);
        if (color[i] == 0) {
            has_white = true;
            all_white_pos = all_white_pos && pos;
            all_white_neg = all_white_neg && !pos;
        } else {
            has_black = true;
            all_black_pos = all_black_pos && pos;
            all_black_neg = all_black_neg && !pos;
        }
    }

    if (!has_white || !has_black) {
        quit_with(_ok, "Trivial separation (single color)");
    }

    const bool ok =
        (all_white_pos && all_black_neg) ||
        (all_white_neg && all_black_pos);
    if (ok) {
        quit_with(_ok, "Correct");
    }
    quit_with(_wa, "Line does not separate colors");
}


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

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

    
    
    int n = 30;
    if (argc >= 2) {
        long long seed = atoll(argv[1]);
        if (seed == 1) n = 1;
        else if (seed == 2) n = 2;
        else if (seed == 3) n = 3;
        else if (seed <= 10) n = 10 + (int)seed;
        else n = 30;
    }
    n = max(1, min(30, n));

    
    long long x1 = rnd.next(0LL, 1000000000LL);
    long long y1 = rnd.next(0LL, 1000000000LL);
    long long x2 = rnd.next(0LL, 1000000000LL);
    long long y2 = rnd.next(0LL, 1000000000LL);
    if (x1 == x2 && y1 == y2) {
        x2 = (x2 + 1) % 1000000001LL;
    }

    cout << n << "\n";
    cout << x1 << " " << y1 << " " << x2 << " " << y2 << "\n";
    return 0;
}