Equal Parity

3.5

10 votes
Linear Search, , Algorithms, Greedy algorithm
Problem

You are given an array A containing 2N inetegers. You want to obtain exactly N even integers in the array. Is it possible to achieve the goal using the following operation any number of times(possibly zero) ? 

  • Choose two distinct indices i,j(1i,jN,ij) such that Ai is an even integer, then set Ai=Ai2,Aj=Aj2

 Input format

  • The first line contains denoting the number of test cases. The description of T test cases is as follows:
  • For each test case:
    • The first line contains an integer N where 2N denotes size of array A.
    • The second line contains 2N space-separated integers A1,A2,,A2N - denoting the elements of A.

Output format

For each test case, print "YES" (without quotes) if it is possible to achieve the goal and "NO" (without quotes) otherwise.

Constraints

1T1041N1051Ai109

The sum of  N over all test cases does not exceed 2105.

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test case, it is impossible to have two even integers in the given array.

In the second test case, apply the operation on indices i=1,j=2 making A=[4,10,1,3] which contains two even integers,

Editor Image

?