#K44657. Transforming Binary Palindrome

    ID: 27580 Type: Default 1000ms 256MiB

Transforming Binary Palindrome

Transforming Binary Palindrome

You are given a binary string S of length n. The task is to determine if it is possible to transform S into a palindrome by performing adjacent swaps.

A string is a palindrome if it reads the same forwards and backwards. For a binary string, in order to rearrange it into a palindrome, at most one character can have an odd frequency. In other words, let ( f(0) ) and ( f(1) ) be the frequency of characters '0' and '1' respectively. The condition to form a palindrome is:

[ \text{At most one of } f(0) \text{ and } f(1) \text{ is odd.} ]

If both frequencies are odd, then it is impossible to rearrange the string into a palindrome using any number of adjacent swaps. Otherwise, it is possible.

Your task is to implement a program that reads the input from stdin and prints "YES" if it is possible to rearrange the string into a palindrome, and "NO" otherwise.

inputFormat

The input consists of two lines. The first line contains a single integer n, the length of the binary string. The second line contains the binary string S of length n.

outputFormat

Output a single line containing "YES" if it is possible to rearrange the binary string into a palindrome using adjacent swaps, or "NO" otherwise.## sample

5
11011
YES

</p>