#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int find_best(int n) {
// ask 450 qn first
int sumMax = 0, posMax = 0;
for (int i = 0; i < 450; i++){
vector<int> q = ask(i);
if (q[0] + q[1] == 0){
// found it alr lmao
return i;
}
if (sumMax <= q[0] + q[1]){
sumMax = q[0] + q[1];
posMax = i;
}
}
int cur = 450, maxRight = 0;
if (posMax != 449){
// means we have to climb
while(true){
vector<int> q = ask(cur);
if (q[0] + q[1] == 0){
// found it alr lmao
return cur;
}
if (sumMax <= q[0] + q[1]){
sumMax = q[0] + q[1];
maxRight = q[1];
break;
}
cur++;
}
}
// now that we are at the worst one
while(true){
// find right endpoint
int l = cur, r = n-1;
while(l < r){
int mid = (l + r)/2;
vector<int> askMid = ask(mid);
if (askMid[0] + askMid[1] == 0){
// found it alr lmao
return mid;
}
if (askMid[0] + askMid[1] == sumMax && askMid[1] == maxRight){
l = mid;
}
else{
r = mid-1;
}
}
// we got the l = lastRight
// climb to next worst one
cur = l + 1;
while(true){
vector<int> q = ask(cur);
if (q[0] + q[1] == 0){
// found it alr lmao
return cur;
}
if (sumMax <= q[0] + q[1]){
sumMax = q[0] + q[1];
maxRight = q[1];
break;
}
cur++;
}
}
}