#C13512. Count Consecutive Occurrences

    ID: 43059 Type: Default 1000ms 256MiB

Count Consecutive Occurrences

Count Consecutive Occurrences

You are given a list of integers. Your task is to count the number of consecutive occurrences of each integer in the order they appear. For each contiguous group of the same integer, output the integer and the count of its consecutive occurrences.

For example, if the input sequence is 1 1 2 2 2 3 4 4 4 4 5, then there are:

  • Two consecutive occurrences of 1
  • Three consecutive occurrences of 2
  • One occurrence of 3
  • Four consecutive occurrences of 4
  • One occurrence of 5

The expected output for this example is:

1 2
2 3
3 1
4 4
5 1

You may find the concept of consecutive counting useful in scenarios where you need to compress repetitive data. In mathematical notation, if the input list is \(a_1, a_2, \dots, a_n\), then for every maximal segment of equal elements \(a_i = a_{i+1} = \cdots = a_{j}\), output the pair \((a_i, j-i+1)\).

inputFormat

The input is read from stdin and consists of two parts:

  1. The first line contains a single integer \(n\) (where \(n \ge 0\)) representing the number of elements in the list.
  2. If \(n > 0\), the second line contains \(n\) space-separated integers.

outputFormat

For each group of consecutive identical numbers, output a line with two space-separated integers: the number and its consecutive count. The output should be written to stdout.

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

2 3 3 1 4 4 5 1

</p>