#include "cup.h"
#include <vector>
using namespace std;
vector<int> find_cup() {
// 1. We pick a very small coordinate as our base.
// The problem limits are roughly +/- 5e8.
// -1e9 is safely "to the left" and "below" any possible cup location.
const int START = -1e9;
// This returns: (target_x - START) XOR (target_y - START)
int xor_sum = ask_shahrasb(START, START);
int dist_x = 0;
int dist_y = 0;
// 2. We determine bits for dist_x.
// We iterate up to 30 bits to cover the range up to 10^9.
for (int i = 0; i < 30; i++) {
int bit = (1 << i);
// If the bit is already determined by the xor_sum,
// we only need to check if it belongs to X or Y.
if (xor_sum & bit) {
// We "test" the bit by shifting our query point.
// We use (START + bit) to see if the distance decreases.
int result = ask_shahrasb(START + bit, START);
// If the bit was in X, changing the query point by +bit
// reduces the distance (target_x - START) by exactly 'bit'.
// This would flip that bit in the XOR result.
if ((result ^ xor_sum) != bit) {
// If it didn't behave like a simple flip,
// it means this bit belongs to Y, not X.
dist_y |= bit;
} else {
dist_x |= bit;
}
} else {
// If the bit is NOT in xor_sum, it's either in both or neither.
// We test X again.
int result = ask_shahrasb(START + bit, START);
if ((result ^ xor_sum) != bit) {
// The bit must be in both!
dist_x |= bit;
dist_y |= bit;
}
// Otherwise, the bit is in neither (stays 0).
}
}
// 3. Convert distances back to actual coordinates.
// dist_x = target_x - START => target_x = dist_x + START
return {dist_x + START, dist_y + START};
}