#C14799. Compact Consecutive Duplicates

    ID: 44487 Type: Default 1000ms 256MiB

Compact Consecutive Duplicates

Compact Consecutive Duplicates

You are given a sequence of integers. Your task is to compact the sequence by removing all adjacent (consecutive) duplicate numbers. In other words, for every maximal contiguous block of equal numbers, only the first occurrence should be retained.

For example, given the input sequence:

(1 ; 1 ; 2 ; 3 ; 3 ; 3 ; 4 ; 1 ; 1)

the output should be:

(1 ; 2 ; 3 ; 4 ; 1)

Please note that only consecutive duplicates are removed. Non-consecutive duplicate numbers are considered as separate and must be preserved.

inputFormat

The first line of input contains a single integer \(n\) representing the number of elements in the sequence. The second line contains \(n\) space-separated integers.

outputFormat

Output the compacted list of integers with no consecutive duplicates. Print the integers in one line separated by a single space.

## sample
5
1 2 3 4 5
1 2 3 4 5