#ifndef LOCAL #pragma GCC optimize("O3") #endif #include using namespace std; #define sim template < class c #define ris return * this #define mor > muu & operator << ( #define R22(r) sim > typename \ enable_if<1 r sizeof dud(0), muu&>::type operator<<( c g) { sim > struct rge { c b, e; }; sim > rge range(c h, c n) { return {h, n}; } sim > auto dud(c * r) -> decltype(cerr << *r); sim > char dud(...); struct muu { #ifdef LOCAL stringstream a; ~muu() { cerr << a.str() << endl; } R22(<) a << boolalpha << g; ris; } R22(==) ris << range(begin(g), end(g)); } sim, class b mor pair < b, c> r) { ris << "(" << r.first << ", " << r.second << ")"; } sim mor rge u) { a << "["; for (c i = u.b; i != u.e; ++i) *this << ", " + 2 * (i == u.b) << *i; ris << "]"; } #else sim mor const c&) { ris; } #endif muu & operator()() { ris; } }; #define imie(r...) "[" #r ": " << (r) << "] " #define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ") vector stosy; map kier = {{"left", 0}, {"right", 1}, {"top", 2}, {"bottom", 3}}; map odwrkier = {{0, "left"}, {1, "right"}, {2, "top"}, {3, "bottom"}}; int xoruj(const vector &t) { int res = 0; for (int x : t) res ^= x; return res; } void getMove() { string s; cin >> s; if (s == "yuck!") { exit(0); } int ki = kier[s]; int ile; cin >> ile; stosy[ki] -= ile; } int main() { ios_base::sync_with_stdio(0); int R, C, k; cin >> R >> C >> k; // left right up down stosy = {C, C, R, R}; for (int i = 0; i < k; ++i) { int r, c; cin >> r >> c; stosy[0] = min(stosy[0], c - 1); stosy[1] = min(stosy[1], C - c); stosy[2] = min(stosy[2], r - 1); stosy[3] = min(stosy[3], R - r); } int xoru = xoruj(stosy); if (xoru == 0) { cout << "pass" << endl; getMove(); } while (1) { xoru = xoruj(stosy); assert (xoru > 0); bool juz = 0; for (int i = 0; i < 4 && !juz; ++i) { for (int j = 0; j < stosy[i] && !juz; ++j) { int pom = xoru ^ stosy[i] ^ j; if (pom == 0) { juz = 1; cout << odwrkier[i] << ' ' << stosy[i] - j << endl; stosy[i] = j; break; } } } assert (juz); getMove(); } }