#C12053. Remove Consecutive Duplicates
Remove Consecutive Duplicates
Remove Consecutive Duplicates
Given a sequence of integers, your task is to remove consecutive duplicate elements. More specifically, if the same number appears several times in a row, only the first occurrence should be kept. Formally, for an input list \( A = [a_1, a_2, \dots, a_n] \), you need to produce an output list \( B \) such that \( B[0] = a_1 \) and for every \( i \ge 2 \), \( B[i-1] = a_j \) if \( a_j \neq a_{j-1} \) and the consecutive block from \( a_{j-1} \) to \( a_j \) has been reduced to one element.
You must implement the solution such that it reads from standard input and outputs to standard output.
inputFormat
The input is read from standard input in the following format:
- The first line contains a single integer \( n \) which denotes the number of elements in the list.
- The second line contains \( n \) space-separated integers.
outputFormat
Print the list after removing consecutive duplicates. The elements should be printed in the same order as they appear in the processed list and separated by a single space. If the resulting list is empty, print nothing.
## sample8
1 1 2 2 3 3 3 4
1 2 3 4