#K3826. Rearrange to Palindrome

    ID: 26159 Type: Default 1000ms 256MiB

Rearrange to Palindrome

Rearrange to Palindrome

You are given a sequence of integers. Your task is to determine whether the sequence can be rearranged to form a palindrome.

A palindrome is a sequence that reads the same forwards and backwards. Mathematically, a sequence can be rearranged into a palindrome if and only if the number of elements with an odd frequency does not exceed one, i.e., $$\text{odd\_count} \le 1$$.

The input consists of several test cases. For each test case, you need to output "YES" if the sequence can be rearranged to form a palindrome, otherwise output "NO".

inputFormat

The first line of input contains a single integer T representing the number of test cases.

Each test case consists of a single line starting with an integer n (the length of the sequence) followed by n integers separated by spaces.

Example:

4
5 1 2 3 2 1
4 4 3 3 4
3 1 2 3
2 5 5

outputFormat

For each test case, print a single line containing "YES" if the sequence can be rearranged into a palindrome, or "NO" otherwise.

Example output corresponding to the sample input:

YES
YES
NO
YES
## sample
4
5 1 2 3 2 1
4 4 3 3 4
3 1 2 3
2 5 5
YES

YES NO YES

</p>