Math (monotonicity + binary search)