Problem:
 Score : 400 points    Problem Statement 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.      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.      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       Output If the objective is achievable, print the number of operations required.
If it is not, print -1 instead.        Sample Input 1 xabxa      Sample Output 1 2  One solution is as follows (newly inserted x are shown in bold):  xabxa → xa x bxa → xaxbxa x       Sample Input 2 ab      Sample Output 2 -1  No sequence of operations can turn s into a palindrome.       Sample Input 3 a      Sample Output 3 0  s is a palindrome already at the beginning.       Sample Input 4 oxxx      Sample Output 4 3  One solution is as follows:  oxxx → x oxxx → x xoxxx → x xxoxxx

Solution (Python):
S = input()
l, r = 0, len(S)-1
cnt = 0
while l < r:
  if S[l] == S[r]:
    l += 1
    r -= 1
  else:
    if S[l] != 'x' and S[r] != 'x':
      print(-1)
      exit()
    if S[l] == 'x':
      l += 1
    if S[r] == 'x':
      r -= 1
    cnt += 1
print(cnt)

Solution (Python):
S = input()
N = len(S)
i = 0
j = N-1
ans = 0
while i < j:
    if S[i] == 'x' and S[j] != 'x':
        ans += 1
        i += 1
    elif S[i] != 'x' and S[j] == 'x':
        ans += 1
        j -= 1
    elif S[i] == S[j]:
        i += 1
        j -= 1
    else:
        ans = -1
        break
print(ans)

Solution (Python):
import sys 
S = input()
A = []
for i,s in enumerate(S):
    if s != 'x':  A.append(i)
if not A:
    print(0)
    sys.exit()
for i in range(len(A)//2):
    if S[A[i]] != S[A[-i-1]]:
        print(-1)
        sys.exit()
ans = abs((len(S)-1-A[-1])-A[0])
for i in range(len(A)//2):
    cnt = abs(A[i+1]-A[i] - (A[-1-i]-A[-2-i]))
    ans += cnt
print(ans)

Solution (Python):

def resolve():
    S = input()
    l, r = 0, len(S) - 1
    ans = 0
    while l < r:
        
        if S[l] == S[r]:
            l += 1
            r -= 1
        
        elif S[l] == "x":
            ans += 1
            l += 1
        
        elif S[r] == "x":
            ans += 1
            r -= 1
        else:
            print(-1)
            return

    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):

import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    s = input()

    l, r = 0, len(s) - 1
    x_l, x_r = 0, 0

    while l <= r:
        if s[l] == s[r]:
            l += 1
            r -= 1
            continue
        if s[l] == 'x':
            l += 1
            x_l += 1
            continue
        if s[r] == 'x':
            r -= 1
            x_r += 1
            continue
        print(-1)
        return

    print(x_l + x_r)


main()

Solution (Python):
import sys
s = list(input())
if list(set(s)) == ["x"]:
    print(0)
    sys.exit()
t = [i for i in s if i != "x"]
n = len(t)
if "".join(t) != "".join(t[::-1]):
    print(-1)
else:
    dic = {}
    cnt = 0
    if n % 2 == 0:
        for j in range(len(s)):
            if s[j] != "x":
                cnt += 1
                if cnt == n//2:
                    a = s[:j+1]
                    a = a[::-1]
                if cnt == n//2 + 1:
                    b = s[j:]
                    break
        c = 0
        fa = []
        fb = []
        for k in range(len(a)):
            if a[k] == "x":
                c += 1
            else:
                fa.append(c)
                c = 0
        fa.append(c)
        c = 0
        for p in range(len(b)):
            if b[p] == "x":
                c += 1
            else:
                fb.append(c)
                c = 0
        fb.append(c)
        ans = 0
        for q in range(len(fa)):
            ans += max(fa[q],fb[q]) - min(fa[q],fb[q])
        print(ans)
    else:
        for j in range(len(s)):
            if s[j] != "x":
                cnt += 1
                if cnt == int(n/2) + 1:
                    a = s[:j+1]
                    a = a[::-1]
                    b = s[j:]
                    break
        c = 0
        fa = []
        fb = []
        for k in range(len(a)):
            if a[k] == "x":
                c += 1
            else:
                fa.append(c)
                c = 0
        fa.append(c)
        c = 0
        for p in range(len(b)):
            if b[p] == "x":
                c += 1
            else:
                fb.append(c)
                c = 0
        fb.append(c)
        ans = 0
        for q in range(len(fa)):
            ans += max(fa[q],fb[q]) - min(fa[q],fb[q])
        print(ans)

Solution (Python):
s = input()
t = ''
for c in s:
    if c != 'x':
        t += c
if t[::-1] != t:
    print(-1)
    exit()
m = len(t)
l = [0] * (m + 1)
ind = 0
for c in s:
    if c == 'x':
        l[ind] += 1
    else:
        ind += 1
ans = 0
for i in range((m+1)//2):
    ans += abs(l[i] - l[-1-i])
print(ans)

Solution (Python):
s=input()
t=""
num=[]
for i in range(len(s)):
    if s[i]!="x":
        t+=s[i]
        num.append(i)
yn=0
for i in range(-(len(t)//-2)):
    if t[i]!=t[-1-i]:
        yn=1
        break
if yn==1:
    print(-1)
else:
    if len(num)==0:
        print(0)
    else:
        ans=abs(num[0]-(len(s)-num[-1]-1))
        for i in range(len(num)//2):
            ans+=abs((num[i+1]-num[i])-(num[-1-i]-num[-2-i]))
        print(ans)

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    
    s = S()

    ex = s.replace("x", "")

    for i in range(len(ex)//2):
        if ex[i] != ex[len(ex)-1-i]:
            print(-1)
            exit(0)

    
    l = -1
    r = len(s)
    ans = 0

    while True:
        l += 1
        r -= 1
        lcnt = 0
        rcnt = 0

        while l < len(s):
            if s[l] == "x":
                lcnt += 1
                l += 1
            else:
                break

        while r > -1:
            if s[r] == "x":
                rcnt += 1
                r -= 1
            else:
                break

        if l > r:
            break
        ans += abs(lcnt-rcnt)

    print(ans)
    
main()

Solution (Python):



from math import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
S = input()
ln = len(S)-1
i = 0
j = ln
ans = 0
while i < j:
    if S[i] == S[j]:
        i += 1;
        j -= 1;
    elif S[i] == 'x':
        ans += 1
        i += 1
    elif S[j] == 'x':
        ans += 1
        j -= 1
    else:
        print(-1)
        exit()
print(ans)

Solution (Python):
s = input()
cnt = 0

while True:
  if len(s) < 2:
    break
  if s[0] == s[-1]:
    s = s[1:-1]
  elif s[0] == 'x':
    s += 'x'
    cnt += 1
  elif s[-1] == 'x':
    s = 'x' + s
    cnt += 1
  else:
    print (-1)
    exit()
print (cnt)

Solution (Python):
from collections import deque
S=input()
deque_S=deque(S)
flag=0
ans=0
while True:
    if len(deque_S)<=1:
        break
    if deque_S[0] == deque_S[-1]:
        deque_S.pop()
        deque_S.popleft()
    else:
        if deque_S[0] == 'x':
            ans+=1
            deque_S.popleft()
        elif deque_S[-1] == 'x':
            ans+=1
            deque_S.pop()
        else:
            flag=1
            break
if flag==1:
    print(-1)
else:
    print(ans)

Solution (Python):
from collections import deque

s = deque(list(input()))

ans = 0
while len(s) > 1:
    l = s.popleft()
    r = s.pop()
    if l == r:
        continue
    elif l == 'x':
        ans += 1
        s.append(r)
    elif r == 'x':
        ans += 1
        s.appendleft(l)
    else:
        print(-1)
        exit()

print(ans)

Solution (Python):
s = input()
l = 0
r = len(s)-1

flag = True
ans = 0
while l < r:
  if s[l] == s[r]:
    l += 1
    r -= 1
  elif s[l] == "x":
    l += 1
    ans += 1
  elif s[r] == "x":
    r -= 1
    ans += 1
  else:
    flag = False
    break

if flag:
  print(ans)
else:
  print(-1)

Solution (Python):
S = input()
i = 0
j = len(S) - 1
cnt = 0

while i < j:
    if S[i] == S[j]:
        i += 1
        j -= 1
    elif S[i] == 'x':
        cnt += 1
        i += 1
    elif S[j] == 'x':
        cnt += 1
        j -= 1
    else:
        print(-1)
        exit()
print(cnt)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

s=input()
N=len(s)
t=''.join(list(s.replace('x',''))[::-1])
if s.replace('x','')!=t:
    print(-1)
    exit()
ans=0
i=0
j=N-1
while i<j:
    if s[i]==s[j]:
        i+=1
        j-=1
    elif s[i]=='x':
        ans+=1
        i+=1
    else:
        ans+=1
        j-=1
print(ans)

Solution (Python):
import sys

from collections import deque


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S_deq = deque(list(input()))
    cnt = 0
    while S_deq:
        
        if len(S_deq) == 1:
            S_deq.pop()
        
        elif S_deq[0] == S_deq[-1]:
            S_deq.popleft()
            S_deq.pop()
        
        elif S_deq[0] == "x":
            S_deq.popleft()
            cnt += 1
        elif S_deq[-1] == "x":
            S_deq.pop()
            cnt += 1
        else:
            print(-1)
            return
    print(cnt)
    return


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    
    import sys
    input = lambda:sys.stdin.readline().strip()
    S = input()
    N = len(S)
    
    left = 0
    right = N-1

    ans = 0
    while left<=right:
        if right==left:
            break
        if S[left]==S[right]:
            left+=1
            right-=1
            continue
        if S[left]!='x' and S[right]!='x':
            print(-1);exit()
        if S[left]=='x':
            left+=1
            ans+=1
        if S[right]=='x':
            right-=1
            ans+=1
    if right>left:
        print(-1)
    else:
        print(ans)


if __name__=='__main__':
    main()

Solution (Python):
s = input()

l = 0
r = len(s)-1
cnt = 0

while l < r:
    lx = 0
    while s[l] == "x" and l < len(s)-1:
        lx += 1
        l += 1

    rx = 0
    while s[r] == "x" and r > 0:
        rx += 1
        r -= 1

    if s[l] == s[r]:
        cnt += abs(rx-lx)

        l += 1
        r -= 1
    else:
        cnt = -1
        break

print(cnt)

Solution (Python):
from collections import deque

S = deque(list(input()))

ans = 0
while len(S) > 1:
    l = S.popleft()
    r = S.pop()
    if l == r:
        continue
    elif l == 'x':
        ans += 1
        S.append(r)
    elif r == 'x':
        ans += 1
        S.appendleft(l)
    else:
        print(-1)
        exit()
print(ans)

Solution (Python):
import numpy as np

S = np.array(list(input()))
num_x = np.count_nonzero(S == 'x')

A = [s for s in S if s != 'x']


if len(A) % 2 == 0:
    L = A[:len(A) // 2]
    R = A[len(A) // 2:][::-1]
else:
    L = A[:len(A) // 2]
    R = A[len(A) // 2 + 1:][::-1]

if not np.all(L == R):
    print(-1)
    exit()



T = []
subset = ''
for s in S:
    
    if s == 'x':
        subset += 'x'
    else:
        T.append(subset)
        subset = ''
T.append(subset)
len_T = np.array([len(t) for t in T])

ans = np.abs(len_T - len_T[::-1]).sum() // 2
print(ans)

Solution (Python):
import numpy as np

S = np.array(list(input()))
num_x = np.count_nonzero(S == 'x')

A = [s for s in S if s != 'x']


if len(A) % 2 == 0:
    L = A[:len(A) // 2]
    R = A[len(A) // 2:][::-1]
else:
    L = A[:len(A) // 2]
    R = A[len(A) // 2 + 1:][::-1]

if not np.all(L == R):
    print(-1)
    exit()




T = []
subset = ''
for s in S:
    
    if s == 'x':
        subset += 'x'
    else:
        T.append(subset)
        subset = ''
T.append(subset)
len_T = np.array([len(t) for t in T])

ans = np.abs(len_T - len_T[::-1]).sum() // 2
print(ans)

Solution (Python):
import numpy as np

S = np.array(list(input()))
num_x = np.count_nonzero(S == 'x')

A = [s for s in S if s != 'x']


if len(A) % 2 == 0:
    L = A[:len(A) // 2]
    R = A[len(A) // 2:][::-1]
else:
    L = A[:len(A) // 2]
    R = A[len(A) // 2 + 1:][::-1]

if not np.all(L == R):
    print(-1)
    exit()




reverse_S = S[::-1]
i = 0
j = 0



T = []
subset = ''
for s in S:
    
    if s == 'x':
        subset += 'x'
    else:
        T.append(subset)
        subset = ''
T.append(subset)
len_T = np.array([len(t) for t in T])

ans = np.abs(len_T - len_T[::-1]).sum() // 2
print(ans)

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  l=0
  r=len(s)-1

  ans=0
  while l<r:
    if s[l]=='x':
      if s[r]=='x':
        l+=1
        r-=1
      else:
        l+=1
        ans+=1
    else:
      if s[r]=='x':
        r-=1
        ans+=1
      else:
        if s[l]==s[r]:
          l+=1
          r-=1
        else:
          return -1

  return ans


print(main())

Solution (Python):
def main():
    s = input()
    n = len(s)
    l, r, ans = 0, n-1, 0
    while l < r:
        if s[l] == s[r]:
            l += 1
            r -= 1
        elif s[l] == "x":
            ans += 1
            l += 1
        elif s[r] == "x":
            r -= 1
            ans += 1
        else:
            print(-1)
            exit()
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
s = list(input())
ans = 0
l = 0
r = len(s)-1
while l < r:
    if s[l] != s[r]:
        if s[l] == "x":
            ans += 1
            r += 1
        elif s[r] == "x":
            ans += 1
            l -= 1
        else:
            print(-1)
            exit()
    l += 1
    r -= 1
print(ans)

Solution (Python):
'''
Created on 2020/09/02

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  s=list(pin()[:-1])
  
  cnt=0
  while s:
    if len(s)==1:
      break
    elif s[0]==s[-1]:
      s.pop(0)
      s.pop(-1)
    else:
      if s[0]!='x' and s[-1]!='x':
        print(-1)
        return 
      else:
        if s[0]=='x':
          s.pop(0)
        else:
          s.pop(-1)
        cnt+=1
  print(cnt)
  return 
main()

Solution (Python):
s = input()

i = 0
j = len(s)-1

ans = 0
while i < j:
    if s[i] == s[j]:
        i += 1
        j -= 1
    elif s[i] == "x":
        i += 1
        ans += 1
    elif s[j] == "x":
        j -= 1
        ans += 1
    else:
        break

if i >= j:
    print(ans)
else:
    print(-1)

Solution (Python):
l=a=0;r=len(s:=input())-1
while l<r:
  X=((L:=s[l])==(R:=s[r]))
  l+=((L:=(L=='x'))+X>0)
  r-=((R:=(R=='x'))+X>0)
  a+=(X<1)*(L+R>0)
  if X+L+R<1:a=-1;break
print(a)

Solution (Python):
l=a=0;r=len(s:=input())-1;c='x'
while l<r:
  X=((L:=s[l])==(R:=s[r]))
  l+=((L:=(L==c))+X>0)
  r-=((R:=(R==c))+X>0)
  a+=(X<1 and (L+R>0))
  if X+L+R<1:a=-1;break
print(a)

Solution (Python):
l=a=0;r=len(s:=input())-1;c='x'
while l<r:
  L,R=s[l],s[r]
  X=(L==R)
  L=(L==c)
  R=(R==c)
  l+=(L+X>0)
  r-=(R+X>0)
  a+=(X<1 and (L+R>0))
  if X+L+R<1:a=-1;break
print(a)

Solution (Python):
A=list(input())
from collections import deque
A=deque(A)
cnt=0
while len(A)>1:
   if A[0]==A[-1]:
      A.pop()
      A.popleft()
   elif (A[0]!="x" and A[-1]=="x" ):
      cnt+=1
      A.pop()
   elif (A[0]=="x" and A[-1]!="x" ):
      cnt+=1
      A.popleft()
   else:
      print(-1)
      exit()
print(cnt)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd


s=input()
n=len(s)
t=[]
x="x"
for i in range(n):
    if s[i]!=x:
        t.append([s[i],i])
m=len(t)
resl=0
resr=n-1
ans=0
for i in range((m+1)//2):
    lt,l=t[i]
    rt,r=t[m-1-i]
    if lt==rt:
        ans+=abs((l-resl)-(resr-r))
        resl=l
        resr=r
    else:
        print(-1)
        exit()
print(ans)

Solution (Python):
import sys
s = input()
num = len(s)
l, r = 0, num-1
ans = 0

while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        ans += 1
        if s[l] == 'x':
            l += 1
        elif s[r] == 'x':
            r -= 1
        else:
            print(-1)
            sys.exit()
print(ans)

Solution (Python):
def main():
    S = input()
    no_x = ''.join(S.split('x'))
    if no_x != no_x[::-1]:
        print(-1)
        return
    left, right = 0, len(S) - 1
    ans = 0
    while left <= right:
        if S[left] != S[right]:
            if S[left] == 'x':
                while S[left] != S[right]:
                    left += 1
                    ans += 1
            else:  
                while S[left] != S[right]:
                    right -= 1
                    ans += 1
        left += 1
        right -= 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math


sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

 
def rle_comp(S):
     rle = []
     chain = 0
     for c in S:
         if c == 'x':
             chain += 1
         else:
            rle.append(chain)
            chain = 0
     rle.append(chain)
 
     
     return rle

s = input()
ans = 0


t = [i for i in s if i != 'x']
t2 = t[::-1]
if t != t2:
    ans = -1


if ans != -1:
    N = len(t)
    
    nums = rle_comp(s)

    for i in range(len(nums)//2):
        
        ans += max(nums[i], nums[ len(nums)-1-i]) - min(nums[i], nums[ len(nums)-1-i])

print(ans)

Solution (Python):
s = input()
l = 0
r = len(s) - 1
ans = 0
while r > l:
    if s[r] == s[l]:
        l += 1
        r -= 1
    elif s[r] == "x":
        r -= 1
        ans += 1
    elif s[l] == "x":
        l += 1
        ans += 1
    else:
        ans = -1
        break
print(ans)

Solution (Python):
S = input()
snx = S.replace('x', '')
ls = len(S)
if ls == 1 or len(snx) == 0:
    print(0)
    exit(0)
l = 0
r = ls-1

ans = 0
while l < r:
    lxc = 0
    while S[l] == 'x':
        l += 1
        lxc += 1
    rxc = 0
    while S[r] == 'x':
        r -= 1
        rxc += 1
    ans += abs(lxc-rxc)

    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(ans)

Solution (Python):
s = input()
S = []
for i in range(len(s)):
    S.append(s[i])

check = []
for i in S:
    if i == 'x':
        continue
    else:
        check.append(i)

if check == check[::-1]:
    
    first = 0
    last = len(S) - 1
    count = 0
    while first < last:
        if S[first] != S[last] and S[first] == 'x':
            count += 1
            first += 1
            continue
        elif S[first] != S[last] and S[last] == 'x':
            count += 1
            last -= 1
            continue
        else:
            first += 1
            last -= 1
            continue
    print(count)

else:
    print(-1)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)









INF = 1 << 50

def run():
    S = input()

    l = 0
    r = len(S) - 1

    ans = 0
    while l < r:
        if S[l] == S[r]:
            l+=1
            r-=1
        elif S[l] == 'x':
            l += 1
            ans += 1
        elif S[r] == 'x':
            r -= 1
            ans += 1
        else:
            print(-1)
            return
    print(ans)

if __name__ == "__main__":
    run()

Solution (Python):
S=input()
xs=S.split('x')
xs=''.join(xs)

if xs!=xs[::-1]:
    print(-1)
else:
    ans=0
    N=len(S)
    M=len(xs)
    count1=[0]*(M+1)
    count2=[0]*(M+1)
    rs=S[::-1]
    i=j=0
    a=b=0
    while i<N:
        if S[i]!='x':
            a+=1
        else:
            count1[a]+=1
        if rs[i]!='x':
            b+=1
        else:
            count2[b]+=1
        i+=1
    for a,b in zip(count1,count2):
        ans+=abs(a-b)
    print(ans//2)

Solution (Python):






from collections import deque





s = input()





S = [x for x in s]
ans = 0
l = 0
r = len(S)-1
while l<r:
    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        if S[l] == "x":
            l += 1
            ans += 1
        elif S[r] == "x":
            r -= 1
            ans += 1
        else:
            ans = -1
            break
print(ans)

Solution (Python):
S=input()

T=S.replace("x","")
if T!=T[::-1]:
    print(-1)
    exit()

S="*"+S+"*"
U=S[::-1]

a,b=0,0
K=0
for _ in range(len(T)+2):
    old_a,old_b=a,b
    while S[a]=="x":
        a+=1

    while U[b]=="x":
        b+=1

    delta_a=a-old_a
    delta_b=b-old_b

    K+=max(delta_a,delta_b)-min(delta_a,delta_b)

    a+=1
    b+=1
    assert 1

print(K//2)

Solution (Python):
S = input()

def solver(S):
    l = 0   
    r = len(S)-1

    ans = 0
    while l < r:
        if S[l] == S[r]:
            l += 1
            r -= 1
            continue

        if S[l] == "x":
            l += 1
            ans += 1
            continue
        
        if S[r] == "x":
            r -= 1
            ans += 1
            continue
        
        return -1
    
    return ans


print(solver(S))

Solution (Python):
s=input()
t=s.replace('x','')
n=len(t)
if not(n==1 or t[:n//2]==t[(n+1)//2:][::-1]):
  print(-1)
  exit()
n=len(s)
r=n-1
l=0
ans=0
while r>l:
  nr,nl=r,l
  while s[r]=='x' and r>0:r-=1
  while s[l]=='x' and l<n-1:l+=1
  ans+=abs(nr-r+nl-l)
  while s[r]==s[l] and l<r:
    r-=1
    l+=1
print(ans)

Solution (Python):
from collections import deque
s = deque(input())
ans = 0
while len(s) > 1:
    if s[0] == s[-1]:
        s.popleft()
        s.pop()
    elif s[0] == 'x':
        ans += 1
        s.popleft()
    elif s[-1] == 'x':
        ans += 1
        s.pop()
    else:
        print(-1)
        exit()
print(ans)

Solution (Python):
s = input()
n = len(s)

t = []
for a in s:
    if a != "x":
        t.append(a)
t = "".join(t)
m = len(t)

sw = 1
for i in range(m//2):
    if t[i] == t[-1-i]:
        pass
    else:
        sw = 0
        
if sw == 0:
    ans = -1
else:
    ans = 0
    i,j = 0,0
    while i+j<n:
        if s[i] == s[-1-j]:
            i += 1
            j += 1
        elif s[i] == "x":
            i += 1
            ans += 1
        elif s[-1-j] == "x":
            j += 1
            ans += 1
            
        else:
            ans = -float("Inf")
            
print(ans)

Solution (Python):
s = list(input())
l, r = 0, len(s) - 1
ans = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        if s[l] == "x":
            l += 1
            ans += 1
        elif s[r] == "x":
            r -= 1
            ans += 1
        else:
            ans = -1
            break

print(ans)

Solution (Python):
s = list(input())
l = 0
r = len(s)-1
ans = 0
while l < r:
    if s[l] == s[r]:
        l+=1
        r-=1
    elif s[l] == 'x':
        l+=1
        ans+=1
    elif s[r] == 'x':
        r-=1
        ans+=1
    else:
        print(-1)
        exit()
print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    noX = S.replace('x','')
    if list(noX) == list(reversed(noX)):
        l = 0
        r = len(S)-1
        count = 0
        while l<r:
            if S[l] == S[r]:
                l += 1
                r -= 1
            else:
                if S[l] == 'x':
                    count += 1
                    l += 1
                else:
                    count += 1
                    r -= 1
        print(count)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
s2 = ""
for i in s:
    if i != "x":
        s2 += i
if s2 != s2[::-1]:
    print(-1)
else:
    temp = s2[:(len(s2) + 1) // 2]
    ans = 0
    num1 = 0
    num2 = len(s) - 1
    for i in range(len(temp)):
        count1 = 0
        while s[num1] != temp[i]:
            count1 += 1
            num1 += 1
        else:
            num1 += 1
        count2 = 0
        while s[num2] != temp[i]:
            count2 += 1
            num2 -= 1
        else:
            num2 -= 1
        ans += abs(count1 - count2)
    print(ans)

Solution (Python):

s = input()
n = len(s)
ans = 0
f = 0
b = -1
while True:
    if f - b > n - 1:
        break
    nf = s[f] in ("x", s[b])
    nb = s[b] in ("x", s[f])
    ans += "x" in (s[b], s[f]) and s[b] != s[f]
    if nf + nb < 1:
        ans = -1
        break
    f += nf
    b -= nb
print(ans)

Solution (Python):

s = input()
n = len(s)
ans = 0
f = 0
b = -1
while True:
    if f - b > n - 1:
        break
    if s[f] != s[b]:
        if "x" in (s[f], s[b]):
            ans += 1
            f += "x" == s[f]
            b -= "x" == s[b]
        else:
            ans = -1
            break
    else:
        f += 1
        b -= 1
print(ans)

Solution (Python):
s = input()
n = len(s)
check_ls = []
for i in range(n):
    if s[i] != 'x':
        check_ls.append(s[i])
n_check = len(check_ls)
is_kaibun = True
for i in range(n_check//2):
    if check_ls[i] != check_ls[-i-1]:
        is_kaibun = False
if not is_kaibun:
    print(-1)
else:
    num_target = -(-n_check//2)
    not_x_count = 0
    for i in range(n):
        if s[i] != 'x':
            not_x_count += 1
        if not_x_count == num_target:
            center_ind = i
            break
    ans = 0
    
        
        
    right = n-1
    left = 0
    while right > left:
        if s[right] == 'x' and s[left] != 'x':
            ans += 1
            left -= 1
        elif s[right] != 'x' and s[left] == 'x':
            ans += 1
            right += 1
        right -= 1
        left += 1
    print(ans)

Solution (Python):
s=input()

left=0
right=len(s)-1
cnt=0
while left<right:
    if s[left]==s[right]:
        left+=1
        right-=1
    elif s[left]=='x':
        left+=1
        cnt+=1
    elif s[right]=='x':
        right-=1
        cnt+=1
    else:
        print(-1)
        exit(0)
        
print(cnt)

Solution (Python):
S = input()
N = len(S)

cnt = 0
i = 0
j = N-1
while i < j:
  if S[i] == 'x':
    if S[j] == 'x':
      i += 1
      j -= 1
    else:
      i += 1
      cnt += 1
  else:
    if S[i] == S[j]:
      i += 1
      j -= 1
    elif S[j] == 'x':
      cnt += 1
      j -= 1
    else:
      print(-1)
      exit()
print(cnt)

Solution (Python):
S = input()
N = len(S)
nx = S.replace('x', '')
N2 = len(nx)
for i in range(N2):
  if nx[i] != nx[N2-i-1]:
    print(-1)
    exit()

if N == N2:
  
  print(0)
else:
  cnt = 0
  i = 0
  j = N-1
  while i < j:
    if S[i] == 'x':
      if S[j] == 'x':
        i += 1
        j -= 1
      else:
        i += 1
        cnt += 1
    else:
      if S[i] == S[j]:
        i += 1
        j -= 1
      elif S[j] == 'x':
        cnt += 1
        j -= 1
  print(cnt)

Solution (Python):
s = '0' + input() + '0'
prev = 0
n = len(s)
t = ''
L = []
for i in range(n):
  if s[i] != 'x':
    L.append(i)
    t = t[:] + s[i]
flg = True
n = len(t)
for i in range(n//2):
  flg *= (t[i] == t[n-i-1])
for i in range(n-1):
  L[i] = L[i+1] - L[i] - 1
n -= 1
if flg:
  cnt = 0
  for i in range(n//2):
    cnt += abs(L[i] - L[n-i-1])
  print(cnt)
else:
  print(-1)

Solution (Python):
s = str(input())
check = s.replace('x', '')

if check == check[::-1]:
  left = 0
  right = len(s)-1
  ans = 0
  while left < right:
    if s[left] == s[right]:
      left += 1
      right -= 1
    else:
      if s[left] == 'x':
        s = s[:right+1] + 'x' + s[right+1:]
      else:
        s = s[:left] + 'x' + s[left:]
      left += 1
      ans += 1
  print(ans)
else:
  print(-1)