#K38922. Run-Length Encoding
Run-Length Encoding
Run-Length Encoding
You are given a sequence of n integers. Your task is to perform run-length encoding on the sequence. In other words, for each contiguous subsequence of identical integers, output the integer and the number of times it appears consecutively.
Formally, for a given array a of length n, you need to output pairs \((x, c)\) such that x is an element and c is the count of consecutive occurrences of x. For example, if \(a = [1, 1, 2, 2, 2, 3, 3, 1, 1, 2]\), the result will be \( [(1, 2), (2, 3), (3, 2), (1, 2), (2, 1)] \).
If the input array is empty, you should output nothing.
Note: Ensure that you read the input from standard input (stdin) and write the result to standard output (stdout).
inputFormat
The first line of the input contains a single integer (n) (the number of elements). The second line contains (n) space-separated integers representing the array.
outputFormat
For each contiguous block in the array, output a line containing two integers: the integer value and its consecutive count, separated by a space.## sample
10
1 1 2 2 2 3 3 1 1 2
1 2
2 3
3 2
1 2
2 1
</p>