Inserting 'x'

AtCoder
IDcode_festival_2017_qualc_c
Time2000ms
Memory256MB
Difficulty
We have a string $s$ consisting of lowercase English letters. Snuke can perform the following operation repeatedly: * Insert a letter `x` to any position in $s$ of his choice, including the beginning and end of $s$. Snuke's objective is to turn $s$ into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required. ## Constraints * $1 \leq |s| \leq 10^5$ * $s$ consists of lowercase English letters. ## Input Input is given from Standard Input in the following format: $s$ [samples] ## Notes A _palindrome_ is a string that reads the same forward and backward. For example, `a`, `aa`, `abba` and `abcba` are palindromes, while `ab`, `abab` and `abcda` are not.
Samples
Input #1
xabxa
Output #1
2

One solution is as follows (newly inserted `x` are shown in bold):
xabxa → xa**x**bxa → xaxbxa**x**
Input #2
ab
Output #2
\-1

No sequence of operations can turn $s$ into a palindrome.
Input #3
a
Output #3
0

$s$ is a palindrome already at the beginning.
Input #4
oxxx
Output #4
3

One solution is as follows:
oxxx → **x**oxxx → **x**xoxxx → **x**xxoxxx
API Response (JSON)
{
  "problem": {
    "name": "Inserting 'x'",
    "description": {
      "content": "We have a string $s$ consisting of lowercase English letters. Snuke can perform the following operation repeatedly: *   Insert a letter `x` to any position in $s$ of his choice, including the beginni",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "code_festival_2017_qualc_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a string $s$ consisting of lowercase English letters. Snuke can perform the following operation repeatedly:\n\n*   Insert a letter `x` to any position in $s$ of his choice, including the beginni...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments