Compressing a sequence using a loop
Go
Medium
loops
Task «Compressing a sequence using a loop»
Write a Go program that reads an integer N (1 ≤ N ≤ 100), then N integers. It should output a compressed sequence, replacing each group of consecutive identical numbers with a pair (value, count). Output the pairs in the format "value count", separated by spaces. If N = 0, output an empty line.
Input Format
First line: an integer N. The next line contains N integers separated by spaces.
Output Format
A string of pairs of numbers separated by spaces. Each pair: a value and a quantity separated by a space.
Examples
Example 1
INPUT
8
7 7 7 7 7 7 7 7
OUTPUT
7 8
Example 2
INPUT
0
OUTPUT
main.go