#K37452. Valid Palindrome with One Deletion

    ID: 25979 Type: Default 1000ms 256MiB

Valid Palindrome with One Deletion

Valid Palindrome with One Deletion

You are given a string S. Your task is to determine whether the string is a palindrome or can be transformed into a palindrome by deleting at most one character. A string is a palindrome if it reads the same forwards and backwards, i.e., it satisfies: $$S[i] = S[n-i-1]$$ for all valid indices \(i\), where \(n\) is the length of the string.

If the string already is a palindrome, output YES. Otherwise, if you can remove at most one character from S to make it a palindrome, output YES. If neither condition can be met, output NO.

For example:

  • racecar is already a palindrome, so the answer is YES.
  • abca can be turned into aba by deleting the character at index 1, so the answer is YES.
  • string cannot be converted into a palindrome with at most one deletion, so the answer is NO.

inputFormat

The input is read from standard input (stdin) and consists of a single line containing the string S. The string can contain alphabets and its length can be from 0 to a moderate size.

outputFormat

Print a single line to standard output (stdout) containing YES if the string is a palindrome or can be transformed into one by deleting at most one character. Otherwise, print NO.

## sample
racecar
YES

</p>