#K63527. Unique Elements and Frequencies

    ID: 31773 Type: Default 1000ms 256MiB

Unique Elements and Frequencies

Unique Elements and Frequencies

You are given multiple test cases. In each test case, you are given an array of integers.

The task is to determine the number of unique elements in the sorted version of the array and compute the frequencies of each unique element. The unique elements should be considered in ascending order.

Formally, for each test case, let \(A\) be the array after sorting. Let \(U\) be the set of unique elements in \(A\) (in sorted order). You must output the size of \(U\) and, in the next line, the frequencies of each element in \(U\) separated by a space.

Input Format: The first line contains an integer \(T\), denoting the number of test cases. For each test case, the first line contains an integer \(N\), the number of elements in the array, followed by a line with \(N\) space-separated integers.

Output Format: For each test case, print two lines. The first line contains a single integer, the number of unique elements. The second line contains the frequencies of each unique element in sorted order separated by a space.

Example: For the input:

2
5
4 5 4 2 2
6
1 1 1 1 1 1

The output should be:

3
2 2 1
1
6

inputFormat

The input is read from standard input (stdin). The first line contains an integer T, representing the number of test cases. For each test case, the first line contains an integer N, denoting the number of elements in the array, and the next line contains N space-separated integers.

outputFormat

For each test case, output two lines. The first line is the count of unique elements (after sorting the array). The second line contains the frequency counts of each unique element (in the sorted order), separated by a space. The output should be written to standard output (stdout).## sample

2
5
4 5 4 2 2
6
1 1 1 1 1 1
3

2 2 1 1 6

</p>