P28344 [洛谷] [Code+#3] Vote Counting
普及+
题目描述

Problem Description

To summarize the past period of problem-setting work, Captain Wang organized a "Favorite Problem" selection event and invited contestants to vote for their favorite problems.

Specifically, each problem has a positive integer as its identifier. There are $n$ contestants voting, and each contestant votes for exactly one problem. The identifier of the problem voted for by the $i$-th contestant is $a_i$.

Due to the large number of voters, Captain Wang has asked you to help count the votes. You need to find out the number of problems that received the most votes and their identifiers, listing these identifiers in ascending order. However, there is an exception: if all voted-for problems have the same number of votes, Captain Wang considers the event a failure, and you should output -1.

Input Format

The first line of the input data contains a positive integer $T$, indicating the number of test cases. There are no blank lines between different test cases.

The next $2T$ lines describe each test case:

Each test case contains two lines. The first line contains a positive integer $n$, representing the number of contestants participating in the event. The second line contains $n$ positive integers separated by spaces, $a_1$ to $a_n$, where $a_i$ represents the identifier of the problem voted for by the $i$-th contestant.

Output Format

The output should consist of $T$ sets of data, with no blank lines between different sets. For each set of data:

If the exception described in the problem does not occur, output two lines for this test case. The first line outputs a positive integer $m$, indicating the number of problems that received the most votes. The second line outputs $m$ positive integers in ascending order, representing the identifiers of these problems.

If the exception occurs, output one line for this test case, outputting -1.

Sample Input and Output

Input Sample #1

3
10
2 6 1 2 1 1 2 6 7 1
10
10 3 6 6 3 10 6 6 6 2
10
8 8 10 10 10 10 8 5 8 8

Output Sample #1

1
1
1
6
1
8

Input Sample #2

3
10
1 4 3 1 8 8 7 2 8 7
10
1 10 9 1 3 2 9 9 2 1
10
4 1 5 4 1 9 5 5 4 1

Output Sample #2

1
8
2
1 9
3
1 4 5

Input Sample #3

3
10
3 3 10 8 8 3 10 8 10 3
10
2 2 8 6 8 4 2 4 4 8
10
6 2 5 6 7 5 7 10 2 10

Output Sample #3

1
3
3
2 4 8
-1

Notes

Test Case Number Range of $n$ Range of $a_i$ Special Conditions
1 $=2000$ $\leq n$ Unique problem with the most votes
2 Same as above Same as above Same as above
3 Same as above $\leq 10^9$ Same as above
4 Same as above $\leq n$ No exception will occur
5 Same as above Same as above Same as above
6 Same as above $\leq 10^9$ Same as above
7 Same as above $\leq n$ None
8 Same as above Same as above Same as above
9 Same as above $\leq 10^9$ Same as above
10 Same as above Same as above Same as above
11 $=100000$ $\leq n$ Unique problem with the most votes
12 Same as above Same as above Same as above
13 Same as above $\leq 10^9$ Same as above
14 Same as above $\leq n$ No exception will occur
15 Same as above Same as above Same as above
16 Same as above $\leq 10^9$ Same as above
17 Same as above $\leq n$ None
18 Same as above Same as above Same as above
19 Same as above $\leq 10^9$ Same as above
20 Same as above Same as above Same as above
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 10 2 6 1 2 1 1 2 6 7 1 10 10 3 6 6 3 10 6 6 6 2 10 8 8 10 10 10 10 8 5 8 8
样例输出
1 1 1 6 1 8