P23618 [AtCoder] Inserting 'x'
普及
题目描述

Problem Description

You are given a string $ s $ consisting of lowercase English letters. Snuke can perform the following operation repeatedly:

  • Choose any position in $ s $ (including the beginning and the end) and insert a single lowercase letter x at that position.

Snuke's goal is to make $ s $ a palindrome. Determine if Snuke's goal is achievable and, if it is, find the minimum number of operations required to achieve it.

Input Format

The input is given from the standard input in the following format:

$ s $

Output Format

If Snuke's goal is achievable, output the minimum number of operations required. If it is not achievable, output -1 instead.

Sample Input and Output

Sample Input #1

xabxa

Sample Output #1

2

Sample Input #2

ab

Sample Output #2

-1

Sample Input #3

a

Sample Output #3

0

Sample Input #4

oxxx

Sample Output #4

3

Notes/Hints

Annotation

A palindrome is a string that reads the same forwards and backwards. For example, a, aa, abba, abcba are palindromes, but ab, abab, abcda are not.

Constraints

  • $1 \leq |s| \leq 10^5$
  • $ s $ consists of lowercase English letters only.

Sample Explanation 1

For example, the operations can be performed as follows (newly inserted xs are shown in bold): xabxa → xaxbxa → xaxbxax

Sample Explanation 2

No matter how the operations are performed, $ s $ cannot be made into a palindrome.

Sample Explanation 3

$ s $ is already a palindrome from the beginning.

Sample Explanation 4

For example, the operations can be performed as follows: oxxx → xoxxx → xxoxxx → xxxoxxx

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
xabxa
样例输出
2