# Top $K$ Most Frequent Elements
## Problem Statement
You are tasked with maintaining a dynamic collection of integers and processing queries on it. Initially, the collection is empty. There are two types of queries:
1. **Type 1 (Add)**: Given an integer $x$, add $x$ to the collection. This operation increases the frequency of $x$ by one. If $x$ was not previously in the collection, its frequency becomes $1$.
2. **Type 2 (Query Top $K$)**: For this problem, $K=10$. You must report the $K$ distinct numbers with the highest frequencies in the current collection. If there are fewer than $K$ distinct numbers in the collection, report all of them. The numbers should be printed in a specific order:
* First, sort by frequency in decreasing order.
* If two numbers have the same frequency, sort them by their value in decreasing order.
## Input Format
- The first line contains a single integer $q$ ($1 \le q \le 10^5$), representing the total number of queries.
- Each of the following $q$ lines describes a query:
- If the query is of type 1: `1 x`, where $x$ is an integer ($-10^9 \le x \le 10^9$). This indicates that $x$ should be added to the collection.
- If the query is of type 2: `2`. This indicates that you should print the top $K=10$ most frequent elements.
## Output Format
For each query of type 2, print a single line containing up to $10$ space-separated integers. These integers must be the most frequent numbers, sorted first by decreasing frequency, and then by decreasing value for ties.
## Sample Test Cases
### Sample Input 1
```
7
1 5
1 2
1 5
2
1 3
1 2
2
```
### Sample Output 1
```
5 2
5 2 3
```
### Sample Input 2
```
5
1 10
1 20
1 30
1 40
2
```
### Sample Output 2
```
40 30 20 10
```
## Constraints
- $1 \le q \le 10^5$
- $-10^9 \le x \le 10^9$ for type 1 queries.
- The total number of elements added across all type 1 queries does not exceed $10^5$.
- Time limit: 1 second
- Memory limit: 256 MB
## Explanation
### Sample Input 1:
1. `1 5`: Collection: $\{5:1\}$
2. `1 2`: Collection: $\{5:1, 2:1\}$
3. `1 5`: Collection: $\{5:2, 2:1\}$
4. `2`: Query for top $K=10$. Frequencies: $5$ (occurs $2$ times), $2$ (occurs $1$ time). Output: `5 2`. (Number $5$ has higher frequency. If frequencies were tied, the larger value would come first.)
5. `1 3`: Collection: $\{5:2, 2:1, 3:1\}$
6. `1 2`: Collection: $\{5:2, 2:2, 3:1\}$
7. `2`: Query for top $K=10$. Frequencies: $5$ (occurs $2$ times), $2$ (occurs $2$ times), $3$ (occurs $1$ time). Output: `5 2 3`. (Numbers $5$ and $2$ have the same highest frequency, but $5 > 2$, so $5$ comes first. Then $3$ with frequency $1$.)
### Sample Input 2:
1. `1 10`: Collection: $\{10:1\}$
2. `1 20`: Collection: $\{10:1, 20:1\}$
3. `1 30`: Collection: $\{10:1, 20:1, 30:1\}$
4. `1 40`: Collection: $\{10:1, 20:1, 30:1, 40:1\}$
5. `2`: Query for top $K=10$. All distinct numbers have frequency $1$. Sorted by value in decreasing order: `40 30 20 10`.
Loading problem statement...