#include #include #include #include #include constexpr uint32_t L = 17; struct PQ { std::priority_queue s, t; void insert(size_t x) { s.push(x); } void erase(size_t x) { t.push(x); } size_t top() { while (t.size() and s.top() == t.top()) s.pop(), t.pop(); return s.top(); } }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); size_t n; std::cin >> n; uint32_t x = 0; std::vector a(n); std::array pqs{}; for (size_t i = 0; i < n; ++i) { std::cin >> a[i], x ^= a[i]; for (uint32_t j = 0; j < L; ++j) { if ((a[i] >> j) & 1) pqs[j].insert(i); } } bool t = x; std::cout << t << '\n', std::cout.flush(); auto update = [&](size_t i, uint32_t k) { for (uint32_t j = 0; j < L; ++j) { if ((a[i] >> j) & 1) { pqs[j].erase(i); } } x ^= a[i]; a[i] -= k; x ^= a[i]; for (uint32_t j = 0; j < L; ++j) { if ((a[i] >> j) & 1) { pqs[j].insert(i); } } }; for (;; t = not t) { if (t) { assert(x); for (uint32_t bit = L; bit-- > 0;) { if ((x >> bit) & 1) { size_t i = pqs[bit].top(); uint32_t k = a[i] - (x ^ a[i]); assert(k and k <= a[i]); update(i, k); std::cout << i + 1 << ' ' << k << '\n', std::cout.flush(); break; } } } else { assert(x == 0); size_t i; uint32_t k; std::cin >> i >> k; --i; update(i, k); } int ret; std::cin >> ret; if (ret == -1) break; } }