MAJOR - Majority

no tags 

The human tribe has just discovered some other tribe and wants to communicate with them. To make sure it is not intercepted by the terminators, they ask their chief computer engineer Rohit to design a system for the purpose. In the design that Rohit proposes, data is transmitted n times. If it is received more than half-the times, it is said to be successfully transmitted. If not, the data is said to be lost. Rohit obviously got a lot of fame and respect for his work. Nitish doesn’t like it and wants to challenge Rohit’s supremacy. He wants to check out the system and has hired you for the process.

Input

The first line of the input contains test cases t (1 <= t <= 100). It is followed by 2*t lines, 2 for each test case. The first line of input for each test case contains a number n (0 <= n <= 106), followed by n elements in the next line. Each number is from -10^3 to +10^3

Output

You are required to output ‘YES’ followed by the number transmitted, if it was transmitted successfully, and ‘NO’ otherwise.

Example

Input:
3
4
2 1 2 2
6
1 1 1 2 2 2
5
1 2 4 5 1

Output:
YES 2
NO
NO

hide comments
l: 2012-01-26 02:41:02

what anshul garg is saying is pretty reasonable ... please explain !

anshul garg: 2012-01-25 11:28:21

I/P:: 1 2 2 1 2 2 1
O/p -> Yes??
We need to check for 1st element only as we are transmitting data so (1st number sh'd be checked) please explain??

Ranker: 2012-01-08 04:40:03

AC :)

Last edit: 2012-12-28 19:25:24
Rajkiran Rajkumar: 2011-12-12 01:53:27

@THALA ROCKS : Yeah man, I was cracking my head over some other logic until I saw your comment, thanks :)

Arvind: 2011-11-05 19:35:12

Just changed cin to scanf n got acc!

rocks: 2011-08-02 16:52:23

thanks @ Gaurav

Radhika: 2011-06-12 15:15:26

@M.Zacky Ardian :
a number is transmitted if it appears more than half times ( more than n/2) .. so for this case atleast it must appear for 3 times.. so ans is "NO"

M.Zacky Ardian : 2011-06-09 13:24:11

Why

5
1 2 4 5 1

its answer is "NO"?

Ozo: 2011-05-16 21:26:47

What will be output for n = 0???

Radhika: 2011-05-13 10:24:17

@The Bartender thks.. got ac :)


Added by:Troika::Bytes
Date:2010-02-18
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: PERL6