public static long findMaxLegalValue(
            Function<Long, Boolean> legalChecker, long low, long high) {
        if (!legalChecker.apply(low)) {
            return -1;
        }
        while (low <= high) {
            long mid = (low + high) / 2;
            if (legalChecker.apply(mid)) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        return low - 1;
    }
@Test
    void testFindMaxLegalValue() {
        assertThat(BisectionSearchUtils.findMaxLegalValue(value -> value / 3 <= 3, 1, 17))
                .isEqualTo(11);
        assertThat(BisectionSearchUtils.findMaxLegalValue(value -> value / 3 <= 3, 11, 17))
                .isEqualTo(11);
        assertThat(BisectionSearchUtils.findMaxLegalValue(value -> value / 3 <= 3, 1, 11))
                .isEqualTo(11);
        assertThat(BisectionSearchUtils.findMaxLegalValue(value -> value / 3 <= 3, 1, 10))
                .isEqualTo(10);
        assertThat(BisectionSearchUtils.findMaxLegalValue(value -> value / 3 <= 3, 12, 17))
                .isEqualTo(-1);
    }