#112Easy
How many times each number occurs
Time: 1 s · Memory: 256 MB
- Maps and sets
Statement
You are given an array of numbers. Find how many times each distinct number occurs. Print the numbers in the order of their first appearance in the array.
Input format
The first line contains (). The second line contains integers ().
Output format
A separate line for each distinct number: the number and its count.
Examples
Input
8 1 3 2 4 2 1 9 1
Output
1 3 3 1 2 2 4 1 9 1
Input
8 1 2 2 4 1 7 1 2
Output
1 3 2 3 4 1 7 1
Note
A dictionary (dict / map) stores a value by key: the key is the number, the value is its counter. To keep the order, also write a number into a separate list when it appears for the first time (Python's dict keeps the order itself). In the first example: 1 3, 3 1, 2 2, 4 1, 9 1.
For comparing every element with all others ( operations) is too slow — a set or a dictionary does it in one pass.
