#C6939. Transform to Palindrome?
Transform to Palindrome?
Transform to Palindrome?
You are given a string s
that consists of lowercase letters and the character '?'
. The task is to determine whether it is possible to replace each occurrence of '?'
with a lowercase letter such that the resulting string is a palindrome.
A string is a palindrome if it reads the same forward and backward. Formally, for a string of length n, it must satisfy the condition $$s_i = s_{n-i-1}\quad \text{for all } 0 \le i < \frac{n}{2}.$$
If for every position i
in the first half of the string, either s[i] == s[n-i-1]
or at least one of them is '?'
, then it is always possible to choose appropriate letters to form a palindrome. Otherwise, if there exists an index i
such that both characters are fixed and not equal, then the answer is "NO".
Print YES
if it is possible to form a palindrome, otherwise print NO
.
inputFormat
The input consists of a single line containing the string s
with length between 1 and 105. The string contains only lowercase letters and the character '?'
.
outputFormat
Output a single line with either YES
if the string can be transformed into a palindrome, or NO
otherwise.
a?c?c?a
YES