How do you optimize a piece of code that is consuming excessive memory in a containerized environment?
Implement count_distinct_sorted(numbers) so it counts distinct values without copying the input or storing all previously seen values. The input is a nondecreasing list of integers, and the function returns an integer count.
def count_distinct_sorted(numbers):