#include #include #include #include #include using namespace std; class State { int x = 0; array>, 17> elems; vector iv; public: State(int n) : iv(n) {}; void add(int i, int v) { x ^= v; for (int b = 0; b < 17; ++b) if (v >> b & 1) elems[b].emplace(v, i); iv[i] = v; } int sum() const { return x; } void remove(int i, int k) { const int oval = iv[i]; for (int b = 0; b < 17; ++b) if (oval >> b & 1) elems[b].erase(make_pair(oval, i)); if (const int v = oval - k; v > 0) for (int b = 0; b < 17; ++b) if (v >> b & 1) elems[b].insert(make_pair(v, i)); iv[i] -= k; x ^= oval ^ iv[i]; } pair next_move() { assert(x != 0); const int l = 31 - __builtin_clz(x); assert(x >> l & 1); assert((x >> (l + 1)) == 0); const auto [v, i] = *elems[l].begin(); assert(v > (v ^ x)); return make_pair(i, v - (v ^ x)); } }; int main() { int n; cin >> n; State s(n); for (int i = 0; i < n; ++i) { int a; cin >> a; s.add(i, a); } cout << int(s.sum() != 0) << endl; for (;;) { const int x = s.sum(); cerr << "x = " << x << endl; if (x == 0) { int i, k; cin >> i >> k; i--; s.remove(i, k); } else { const auto [i, k] = s.next_move(); s.remove(i, k); cout << i + 1 << ' ' << k << endl; } int r; cin >> r; if (r == -1) return 0; } }