#K63177. Find Elements Appearing Exactly Three Times
Find Elements Appearing Exactly Three Times
Find Elements Appearing Exactly Three Times
You are given a list of N integers. Your task is to find all the unique elements that appear exactly three times in the given list and then output these elements in ascending order. Additionally, you need to print the number of such unique elements.
In mathematical terms, let \(A = [a_1, a_2, \dots, a_N]\) be the list of integers. You need to find the set \(S = \{ x \mid count(x, A) = 3 \}\), where \(count(x, A)\) denotes the number of times \(x\) occurs in \(A\). The output should first be the size of \(S\), followed by the sorted elements in \(S\) in ascending order.
Example:
Input: 12 1 2 2 3 3 3 4 4 4 4 5 6</p>Output: 1 3
inputFormat
The first line of input contains an integer N
, the number of elements in the list. The second line contains N
space-separated integers representing the elements of the list.
Input is read from standard input (stdin).
outputFormat
Output the number of unique elements that occur exactly three times, followed by each of these elements on a new line in ascending order.
Output is written to standard output (stdout).
## sample12
1 2 2 3 3 3 4 4 4 4 5 6
1
3
</p>