#K61642. Frequency Counter
Frequency Counter
Frequency Counter
Given an integer ( n ) and a sequence of ( n ) integers ( a_1, a_2, \ldots, a_n ), count the frequency of each distinct integer in the list. The output should list each unique integer along with its frequency, in ascending order of the integers.
For example, if the input is
( n = 5 ) and the list is ( [3, 3, 1, 2, 2] ), the correct output is:
1 1
2 2
3 2
This can be formally expressed as: Given a set of integers, compute a function ( f: \mathbb{Z} \to \mathbb{N} ) such that ( f(x) ) is the count of ( x ) in the list, and then output the pairs ( (x, f(x)) ) in ascending order of ( x ).
inputFormat
The input is given via standard input (stdin) with the following format:
( n ) — an integer on the first line representing the number of integers in the sequence.
The second line contains ( n ) space-separated integers.
outputFormat
The output should be printed to standard output (stdout). For each unique integer, print a line containing two integers: the number and its frequency, separated by a space, in ascending order by the integer.## sample
5
3 3 1 2 2
1 1
2 2
3 2
</p>