#C10345. Count and Sort Integers

    ID: 39540 Type: Default 1000ms 256MiB

Count and Sort Integers

Count and Sort Integers

You are given a list of integers read from standard input. Your task is to count the frequency of each integer and output a sorted list of tuples. Each tuple contains an integer and its frequency, and the list must be sorted in ascending order based on the integer value.

Mathematically, if the input list is \(L = [a_1, a_2, \dots, a_n]\), then for each unique integer \(x\) in \(L\), its frequency is given by \(f(x)\). The expected output is a list of tuples: \([(x_1, f(x_1)), (x_2, f(x_2)), \dots, (x_k, f(x_k))]\) with \(x_1 < x_2 < \cdots < x_k\).

inputFormat

The input begins with an integer \(n\) indicating the number of elements in the list. The next line contains \(n\) space-separated integers. In the case where \(n = 0\), the second line will be empty.

outputFormat

Output a list of tuples in the following format: [(x1, f(x1)), (x2, f(x2)), ..., (xk, f(xk))]. Each tuple represents an integer from the input and its corresponding frequency, sorted in ascending order by the integer value.

## sample
9
4 6 3 4 6 1 3 3 4
[(1, 1), (3, 3), (4, 3), (6, 2)]