#K42252. Compress Sequence

    ID: 27046 Type: Default 1000ms 256MiB

Compress Sequence

Compress Sequence

You are given a sequence of integers. Your task is to compress the sequence by combining consecutive duplicate numbers and representing the count of each combination.

Formally, given an integer \( n \) and an array of \( n \) integers, you should produce an output sequence \( res \) such that for every block of consecutive identical elements, you append the element followed by the number of times it appears consecutively. For example, if the array is \( [1, 1, 2, 2, 2, 3] \), then the compressed sequence is \( [1, 2, 2, 3, 3, 1] \), because \(1\) appears twice, followed by \(2\) appearing three times and finally \(3\) appearing once.

If \( n = 0 \), then the output should be empty.

inputFormat

The first line contains a non-negative integer \( n \) representing the number of elements in the sequence. If \( n > 0 \), the next line contains \( n \) space-separated integers which represent the array.

outputFormat

Output the compressed sequence as a series of integers separated by a single space. Each unique element is immediately followed by the count of its consecutive occurrences.

## sample
6
1 1 2 2 2 3
1 2 2 3 3 1