#C5605. Element Appearing More Than N/3 Times

    ID: 49273 Type: Default 1000ms 256MiB

Element Appearing More Than N/3 Times

Element Appearing More Than N/3 Times

Given an array of N integers, determine whether there exists an element that appears strictly more than \( \frac{N}{3} \) times.

If such an element exists, output the element; otherwise, output No. The check is performed using strict inequality, i.e., the frequency of the element must satisfy \( count > \frac{N}{3} \).

For instance, if \( N = 6 \) and the array is [1, 2, 3, 1, 1, 1], the number 1 appears 4 times which is more than \( \frac{6}{3} = 2 \), so the output should be 1.

inputFormat

The input is given via standard input and consists of two lines:

  • The first line contains an 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 via standard output a single line:

  • If there exists an element that appears strictly more than \( \frac{N}{3} \) times, print that element.
  • Otherwise, print No (without quotes).
## sample
6
1 2 3 1 1 1
1