values = [7, 2, 5]
print("Initial:", values)
values.append(9)
print("Append 9:", values)
values.insert(1, 4)
print("Insert 4 at index 1:", values)
removed = values.pop(0)
print("Remove index 0:", removed, values)
print("Index 2:", values[2])

original = [7, 2, 5]
alias = original
copied = original[:]
alias[0] = 8
print("Original after alias assignment:", original)
print("Separate outer copy:", copied)

nested = [[7], [2]]
shallow = nested[:]
shallow[0].append(9)
print("Nested original:", nested)
print("Nested shallow copy:", shallow)

def compact_nonzero(values: list[int]) -> int:
    """Move nonzero values into an ordered prefix of the same list.

    Args:
        values: Integer values to modify in place.

    Returns:
        The number of retained values. The remaining suffix is unspecified.
    """
    write = 0
    for read in range(len(values)):
        if values[read] != 0:
            values[write] = values[read]
            write += 1
    return write


buffer = [0, 7, 0, 2, 5]
write = 0
print("read value write retained")
for read in range(len(buffer)):
    current = buffer[read]
    if current != 0:
        buffer[write] = current
        write += 1
    print(read, current, write, buffer[:write])

sample = [0, 7, 0, 2, 5]
kept = compact_nonzero(sample)
print("Retained prefix:", sample[:kept])
print("Full buffer:", sample)

for case in ([], [0], [6], [0, 0], [3, -2, 0, 3]):
    working = case[:]
    length = compact_nonzero(working)
    expected = [value for value in case if value != 0]
    assert working[:length] == expected
    assert len(working) == len(case)
print("Boundary checks passed.")
