#K64427. Repeated Elements in an Array
Repeated Elements in an Array
Repeated Elements in an Array
You are given an array of n integers. Your task is to output all elements that occur strictly more than once in the array, sorted in ascending order. Each such element should appear only once in the output.
In mathematical terms, let the array be \(A = [a_1, a_2, \dots, a_n]\). For any integer \(x\), if the frequency \(f(x) > 1\), then \(x\) should be included in the result. The resulting list \(R\) should satisfy:
[ R = { x \mid x \in A \text{ and } f(x) > 1 } \quad,\quad R \text{ is sorted in ascending order.} ]
If no number repeats, output an empty line.
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains a single integer
n
representing the number of elements in the array. - The second line contains
n
space-separated integers which are the elements of the array.
outputFormat
Output the repeated elements in ascending order as a single line with each number separated by a single space. If there are no repeated elements, output an empty line.
## sample8
1 2 2 3 4 4 4 5
2 4
</p>