#include using namespace std; typedef long long ll; typedef pair pii; #define TOP 0 #define LEFT 1 #define BOT 2 #define RIGHT 3 map str2move = { {"left", LEFT}, {"top", TOP}, {"right", RIGHT}, {"bottom", BOT} }; string move2str[] = {"top", "left", "bottom", "right"}; int calcXor (vector& vals) { int res = 0; for (auto val : vals) { res ^= val; } return res; } void print (vector& vals) { for (auto val : vals) { cerr << val << " "; } cerr << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int R, C, k; cin >> R >> C >> k; int r0 = R, c0 = C, r1 = 1, c1 = 1; for (int i = 0; i < k; i++) { int r, c; cin >> r >> c; r0 = min(r0, r); r1 = max(r1, r); c0 = min(c0, c); c1 = max(c1, c); } vector piles = {r0 - 1, c0 - 1, R - r1, C - c1}; // top, left, bot, right int currXor = calcXor(piles); // first move if (currXor == 0) { cout << "pass" << endl; string opMove; cin >> opMove; if (opMove == "yuck") { return 0; } int i; cin >> i; piles[str2move[opMove]] -= i; } // remaining moves while (true) { currXor = calcXor(piles); string move; int val = -1; for (int i = 0; i < 4; i++) { int newVal = piles[i] ^ currXor; if (newVal > piles[i]) { continue; } val = piles[i] - newVal; move = move2str[i]; piles[i] = newVal; // don't forget to update after your move! break; } assert(val != -1); cout << move << " " << val << endl; // read opponent's move string opMove; cin >> opMove; if (opMove == "yuck") { return 0; } int i; cin >> i; piles[str2move[opMove]] -= i; } return 0; }