seen: set[int] = set()
for value in [4, 1, 4, 2, 1]:
    duplicate = value in seen
    seen.add(value)
    print("Read:", value, "Duplicate:", duplicate, "Members:", sorted(seen))
seen.discard(9)
seen.remove(2)
print("After removals:", sorted(seen))
print("Intersection:", sorted(seen & {1, 3, 4}))
print("Difference:", sorted(seen - {1}))

def longest_consecutive(values: list[int]) -> int:
    """Find the length of the longest run of consecutive integers.

    Args:
        values: Unsorted integers, possibly with duplicates.

    Returns:
        The maximum run length, or zero for an empty input.
    """
    members = set(values)
    longest = 0
    for start in members:
        if start - 1 in members:
            continue
        end = start
        while end in members:
            end += 1
        longest = max(longest, end - start)
    return longest


checkpoints = [8, 3, 5, 4, 3, 10]
members = set(checkpoints)
for start in sorted(members):
    if start - 1 in members:
        print("Skip non-start:", start)
        continue
    run = []
    current = start
    while current in members:
        run.append(current)
        current += 1
    print("Run from:", start, "Members:", run)
print("Longest length:", longest_consecutive(checkpoints))

assert longest_consecutive([]) == 0
assert longest_consecutive([6, 6, 6]) == 1
assert longest_consecutive([-2, 0, -1, 5]) == 3
assert longest_consecutive([1, 3, 5]) == 1
assert longest_consecutive([4, 3, 2, 1]) == 4
print("Boundary checks passed.")
