#K55887. Almost Palindrome

    ID: 30075 Type: Default 1000ms 256MiB

Almost Palindrome

Almost Palindrome

You are given a string s of lowercase letters and an integer n representing its length. Determine if the string can be transformed into a palindrome by changing at most one character. In other words, if the number of mismatched character pairs (when comparing the i-th character from the start and the i-th character from the end) is at most one, then it is possible to make s a palindrome.

Note: A palindrome is a string that reads the same forwards and backwards. The allowed operation is to change any single character to any other character.

The mathematical condition for this problem can be written in LaTeX as:

$$\text{mismatches} = \sum_{i=1}^{\lfloor n/2\rfloor} \mathbb{1}_{s_i \neq s_{n-i+1}} \leq 1. $$

inputFormat

The first line contains an integer n (the length of the string). The second line contains the string s consisting of lowercase letters.

For example:

5
abcca

outputFormat

Output a single line containing YES if the string can be transformed into a palindrome by changing at most one character, otherwise output NO.

For the sample above, the output should be:

YES
## sample
5
abcca
YES