#K61262. Taco Rearrangement Problem

    ID: 31271 Type: Default 1000ms 256MiB

Taco Rearrangement Problem

Taco Rearrangement Problem

Problem Statement:

Given a sequence of integers, determine whether it can be rearranged so that every integer that appears more than once appears exactly twice. In other words, if an integer appears only once, it is acceptable, but if it appears more than once, it must appear exactly two times.

For example, the sequence [1, 2, 2, 1] can be rearranged (or even left as-is) so that 1 and 2 each appear exactly twice, so the answer is "YES". However, the sequence [3, 3, 2, 2, 2] cannot be rearranged to satisfy the property, making the answer "NO".

The sequence could also be empty, in which case it trivially satisfies the condition.

Your task is to write a program that processes multiple test cases and prints the appropriate answer for each.

inputFormat

Input Format:

  • The first line contains an integer T denoting the number of test cases.
  • For each test case:
    • The first line contains an integer n representing the length of the sequence.
    • The second line contains n space-separated integers.

outputFormat

Output Format:

For each test case, output a single line containing "YES" if the sequence can be rearranged so that every integer that appears more than once appears exactly twice. Otherwise, print "NO".

## sample
5
4
1 2 2 1
5
3 3 2 2 2
6
4 4 1 1 2 2
3
7 7 7
2
5 6
YES

NO YES NO YES

</p>