Compressing a sequence using iterators and combinators

Rust Hard iterators

Task «Compressing a sequence using iterators and combinators»

You are given a sequence of integers. You need to implement a function that compresses the sequence: replaces consecutive identical numbers with a pair (number, count of repetitions). Use iterators and combinators (e.g., map, filter, fold, scan, collect). Input: first an integer N (1 ≤ N ≤ 10^5), then N integers. Output the compressed sequence as pairs (number, count) separated by spaces. If the sequence is empty (N=0), output an empty line.

Input Format

Integer N, then N integers separated by spaces.

Output Format

Pairs (number, count) separated by spaces. Each pair: number and count separated by a comma without a space. If N=0, output an empty string.

Examples

Example 1

INPUT
OUTPUT

Example 2

INPUT
1 42
OUTPUT
42,1

Example 3

INPUT
OUTPUT
main.rs