int L = minValue, R = maxValue;
while (L < R) {
int M = (L + R + 1) / 2;
if (check(M)) {
L = M;
} else {
R = M - 1;
}
}
return L;
aW50IEwgPSBtaW5WYWx1ZSwgUiA9IG1heFZhbHVlOwp3aGlsZSAoTCA8IFIpIHsKICAgIGludCBNID0gKEwgKyBSICsgMSkgLyAyOwogICAgaWYgKGNoZWNrKE0pKSB7CiAgICAgICAgTCA9IE07CiAgICB9IGVsc2UgewogICAgICAgIFIgPSBNIC0gMTsKICAgIH0KfQpyZXR1cm4gTDs=