#K75782. Palindromic Rearrangement
Palindromic Rearrangement
Palindromic Rearrangement
Given an array of integers, determine if it can be rearranged to form a palindromic sequence.
A palindrome is a sequence which reads the same backwards as forwards. For an array to be rearranged into a palindrome, the frequency of each integer must satisfy a specific condition. More formally, let \( n \) be the length of the array. Then:
- If \( n \) is even, each integer must appear an even number of times.
- If \( n \) is odd, exactly one integer is allowed to appear an odd number of times, while all others appear an even number of times.
Your task is to implement a program that checks whether a given array satisfies this condition.
inputFormat
The input is provided via standard input (stdin) and consists of two lines:
- The first line contains a single integer \( n \), which is the number of elements in the array.
- The second line contains \( n \) space-separated integers representing the array.
Example:
5 1 2 3 2 1
outputFormat
Output a single line to standard output (stdout) containing either "YES" if the array can be rearranged into a palindrome, or "NO" otherwise.
## sample5
1 2 3 2 1
YES