def sorted_pair(
    values: list[int], target: int
) -> tuple[int, int] | None:
    """Find distinct positions with a requested sum in a sorted list.

    Args:
        values: Integer values in nondecreasing order.
        target: Required pair sum.

    Returns:
        A pair of indices, or None if no pair has the target sum.
    """
    left = 0
    right = len(values) - 1
    while left < right:
        total = values[left] + values[right]
        if total == target:
            return left, right
        if total < target:
            left += 1
        else:
            right -= 1
    return None


values = [1, 3, 4, 6, 9]
target = 13
left, right = 0, len(values) - 1
while left < right:
    total = values[left] + values[right]
    print("Indices", (left, right), "values", (values[left], values[right]),
          "sum", total)
    if total == target:
        break
    if total < target:
        left += 1
    else:
        right -= 1
print("Pair indices:", sorted_pair(values, target))

def longest_unique_span(text: str) -> tuple[int, int]:
    """Find the earliest longest span of distinct Unicode code points.

    Args:
        text: String to inspect.

    Returns:
        Start and exclusive end indices of the selected span.
    """
    last_seen: dict[str, int] = {}
    left = 0
    best_start = 0
    best_end = 0
    for right, character in enumerate(text):
        previous = last_seen.get(character, -1)
        left = max(left, previous + 1)
        last_seen[character] = right
        if right + 1 - left > best_end - best_start:
            best_start, best_end = left, right + 1
    return best_start, best_end


text = "abcaefb"
last_seen: dict[str, int] = {}
left = 0
for right, character in enumerate(text):
    previous = last_seen.get(character, -1)
    left = max(left, previous + 1)
    last_seen[character] = right
    print("Read", character, "bounds", (left, right + 1),
          "window", text[left:right + 1])
start, end = longest_unique_span(text)
print("Selected span:", (start, end))
print("Selected substring:", text[start:end])
print("Length:", end - start)

assert sorted_pair([], 4) is None
assert sorted_pair([5], 10) is None
assert sorted_pair([5, 5], 10) == (0, 1)
assert sorted_pair([-5, -1, 2, 8], 3) == (0, 3)
assert sorted_pair([1, 2, 3], 20) is None
assert longest_unique_span("") == (0, 0)
assert longest_unique_span("abba") == (0, 2)
assert longest_unique_span("aaaa") == (0, 1)
assert longest_unique_span("abcd") == (0, 4)
print("The pair and window boundary cases pass.")
