#include using namespace std; long long ask(int a, int b) { cout << "? " << a << " " << b << '\n'; cout.flush(); long long x; cin >> x; if (x == -1) exit(0); // judge error return x; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector d(N, -1); int i = 0; // Process in groups of 3 while (i + 2 < N) { long long ab = ask(i, i+1); long long ac = ask(i, i+2); long long bc = ask(i+1, i+2); vector> cand; for (int A = 0; A <= 9; A++) { for (int B = 0; B <= 9; B++) { for (int C = 0; C <= 9; C++) { if (A * B == ab && A * C == ac && B * C == bc) { cand.push_back({A, B, C}); } } } } // Must be uniquely determined if (cand.size() != 1) { cout << "! -1\n"; cout.flush(); return 0; } d[i] = cand[0][0]; d[i+1] = cand[0][1]; d[i+2] = cand[0][2]; i += 3; } // Handle remaining 1 digit if (i < N) { if (i == 0) { // cannot determine single digit alone cout << "! -1\n"; cout.flush(); return 0; } long long p = ask(i-1, i); if (d[i-1] == 0) { // ambiguous (0 * anything = 0) cout << "! -1\n"; cout.flush(); return 0; } if (p % d[i-1] != 0) { cout << "! -1\n"; cout.flush(); return 0; } d[i] = p / d[i-1]; if (d[i] < 0 || d[i] > 9) { cout << "! -1\n"; cout.flush(); return 0; } } // Handle remaining 2nd digit (if exists) if (i + 1 < N) { long long p = ask(i, i+1); if (d[i] == 0) { cout << "! -1\n"; cout.flush(); return 0; } if (p % d[i] != 0) { cout << "! -1\n"; cout.flush(); return 0; } d[i+1] = p / d[i]; if (d[i+1] < 0 || d[i+1] > 9) { cout << "! -1\n"; cout.flush(); return 0; } } // Construct number long long X = 0, pw = 1; for (int i = 0; i < N; i++) { X += pw * d[i]; pw *= 10; } cout << "! " << X << '\n'; cout.flush(); return 0; }