#C14957. Compressed Count of Integers

    ID: 44663 Type: Default 1000ms 256MiB

Compressed Count of Integers

Compressed Count of Integers

Given a sequence of integers, your task is to count the number of compressed occurrences of each integer. In other words, when the same integer appears consecutively, it is counted as one occurrence. However, if the same integer appears again later (after a different number), it is counted as another occurrence.

For example, if the input is:

1 2 2 1 1 3 3 3

Then the number 1 appears in two separate groups, 2 appears in one group, and 3 appears in one group. Thus, the answer will be:

1 2
2 1
3 1

You need to read the input from stdin and output your result to stdout as described below.

inputFormat

The input consists of two lines:

  • The first line contains a single integer n representing the number of elements in the sequence.
  • The second line contains n integers separated by spaces.

If n is 0, the list is empty and nothing should be output.

outputFormat

Output the compressed count for each distinct integer on separate lines. Each line should contain two numbers: the integer and the number of times it appears as a group (i.e., consecutive occurrences are counted as one), separated by a space. The order of the output should follow the order in which the integers first appear in the input.

## sample
5
1 2 3 4 5
1 1

2 1 3 1 4 1 5 1

</p>