#C9601. Majority Element II

    ID: 53713 Type: Default 1000ms 256MiB

Majority Element II

Majority Element II

Given an array of integers of size n, find all the elements that appear more than ( \lfloor n/3 \rfloor ) times. In other words, an element is considered a majority element if it appears more than ( \lfloor n/3 \rfloor ) times in the array.

The input is given via standard input (STDIN) where the first line contains a single integer n (the number of elements in the array) and the second line contains n space-separated integers. The output should be printed to standard output (STDOUT) as the list of majority elements in ascending order separated by a single space. If no majority element exists, output an empty line.

inputFormat

The first line of input contains a single integer n, representing the number of elements in the array. The second line contains n space-separated integers representing the elements of the array.

outputFormat

Output the majority elements (those appearing more than ( \lfloor n/3 \rfloor ) times) in ascending order, separated by a single space. If there are no majority elements, output an empty line.## sample

3
3 2 3
3

</p>