Count Value OccurrencesEasy

Count Value Occurrences

EasyPractice library · +10 XPhash mapcountingfrequency

Given a list of integers, count how many times each unique integer appears in the list. Then, print each unique integer along with its count. The output should be sorted by the unique integers in ascending order.

Input

The first line contains an integer N, the number of integers in the list. The second line contains N space-separated integers.

Output

For each unique integer in the input list, print the integer and its count, separated by a space. Print these pairs in ascending order of the integers. Each pair should be on a new line.

Constraints

1 <= N <= 1000. The integers are between -1000 and 1000.

Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests

Example 1

Input
5
1 2 1 3 2
Output
1 2
2 2
3 1

The number 1 appears twice, 2 appears twice, and 3 appears once. Output is sorted by number.

Example 2

Input
7
-5 0 10 -5 0 -5 10
Output
-5 3
0 2
10 2

Negative numbers and zero are handled. -5 appears 3 times, 0 appears twice, 10 appears twice.

Hints