#include #define NIM(a, b, c, d) ((a) ^ (b) ^ (c) ^ (d)) using std::cin; using std::cout; using std::endl; using std::string; using std::max; int rows, columns, bombs; int minX, maxX, minY, maxY; int x, y; unsigned left, right, top, bottom; bool read() { string w; int v; cin >> w; if (w == "yuck!") return true; cin >> v; if (w == "left") left -= v; if (w == "right") right -= v; if (w == "top") top -= v; if (w == "bottom") bottom -= v; return false; } void take() { for (int i = 1; i <= max({left, right, top, bottom}); i++) { if (i <= left && (NIM(left - i, right, top, bottom) == 0)) { left -= i; cout << "left " << i << endl; } else if (i <= right && (NIM(left, right - i, top, bottom) == 0)) { right -= i; cout << "right " << i << endl; } else if (i <= top && (NIM(left, right, top - i, bottom) == 0)) { top -= i; cout << "top " << i << endl; } else if (i <= bottom && (NIM(left, right, top, bottom - i) == 0)) { bottom -= i; cout << "bottom " << i << endl; } else { continue; } return; } throw "unexpected"; } int main() { std::ios::sync_with_stdio(false); cin >> rows >> columns >> bombs; for (int i = 0; i < bombs; i++) { cin >> y >> x; if (i == 0) { minX = x; maxX = x; minY = y; maxY = y; } if (y < minY) { minY = y; } if (x < minX) { minX = x; } if (y > maxY) { maxY = y; } if (x > maxX) { maxX = x; } } left = minX - 1; right = columns - maxX; top = minY - 1; bottom = rows - maxY; if (NIM(left, right, top, bottom) == 0) { cout << "pass" << endl; read(); } while (left != 0 || right != 0 || top != 0 || bottom != 0) { take(); if (read()) break; } return 0; }