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):
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)


input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  
    fac = [0] * SIZE  
    finv = [0] * SIZE  
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    
    
    
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    
    return X.flatten().tolist()[0]

class TwoDimGrid:
    
    def __init__(self, h, w, wall="
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        
        
        
        
        


def soinsu(n):
    ret = defaultdict(int)
    for i in range(2, int(math.sqrt(n) + 2)):
        if n % i == 0:
            while True:
                if n % i == 0:
                    ret[i] += 1
                    n //= i
                else:
                    break

    if not ret:
        return {n: 1}
    return ret


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

    if r == l + 1:
        if S[l] == S[r]:
            l += 1
            r -= 1
        else:
            if S[l] == "x":
                ans += 1
                l += 1
            elif S[r] == "x":
                ans += 1
                r -= 1
            else:
                print(-1)
                return

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    
    solve()

Solution (Python):
S = input()

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

while l < r:
    if S[l] == S[r]:
        l += 1
        r -= 1
    elif S[l] == "x":
        l += 1
        cnt += 1
    elif S[r] == "x":
        r -= 1
        cnt += 1
    else:
        print(-1)
        exit()
        
print(cnt)

Solution (Python):
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": 
        l+=1
        ans+=1
    elif s[r]=="x":
        r-=1
        ans+=1
    else:
        print(-1)
        exit()
print(ans)

Solution (Python):
s=input()
temp=""
for c in s:
     if c!="x": temp+=c
if temp!=temp[::-1]: print(-1)
elif len(temp)==0:  print(0)
else:
    a=temp[0:len(temp)//2]
    l,r=0,len(s)-1
    ans=0
    while l<r:
        if s[l]==s[r]:
            l+=1
            r-=1
            continue
        elif s[l]=="x": l+=1
        else: r-=1
        ans+=1
    print(ans)

Solution (Python):
S = input()

S_rmv =S.replace('x','')

count = 0
if S_rmv == S_rmv[::-1]:
    i = 0
    j = len(S)-1
    while i<j:
        if S[i] == S[j]:
            i +=1
            j -=1
        elif S[i] == 'x':
            i +=1
            count +=1
        elif S[j] == 'x':
            j -=1
            count +=1
    print(count)
else:
    print(-1)

Solution (Python):
s=list(input())
ans=0
for i in range(len(s)):
    if len(s)<=1:
        break
    if s[0]==s[-1]:
        del s[0]
        del s[-1]
    else:
        if s[0]=="x":
            ans+=1
            del s[0]
        elif s[-1]=="x":
            ans+=1
            del s[-1]
        else:
            ans=-1
            break
print(ans)

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

if s1 != s1[::-1]:
    print(-1)
else:
    li = [0] * (len(s1) + 1)
    cnt = 0
    ans = 0
    for i in range(len(s)):
        if s[i] == 'x':
            li[cnt] += 1
        else:
            cnt += 1

    for i in range((len(s1)+1) // 2):
        a = li[i]
        b = li[-i-1]
        ans += abs(a-b)

    print(ans)

Solution (Python):

s = input()
l, r = 0, len(s) - 1
c = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == "x":
        l += 1
        c += 1
    elif s[r] == "x":
        r -= 1
        c += 1
    else:
        print(-1)
        exit()
print(c)

Solution (Python):
def main():
    import sys

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

    s = input()
    n = len(s)
    sr = s.replace('x', '')
    if sr == '':
        print(0)
        return
    elif sr != sr[::-1]:
        print(-1)
        return
    cur_l = 0
    cur_r = n-1
    ans = 0
    cnt = 0
    while cur_l < cur_r:
        while s[cur_l] == 'x':
            cnt += 1
            cur_l += 1
        while s[cur_r] != s[cur_l]:
            cur_r-=1
            cnt -= 1
        ans += abs(cnt)
        cur_l += 1
        cur_r -= 1
        cnt = 0
        
    print(ans)   
    
        

if __name__ == '__main__':
    main()

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    t = ""

    for c in s:
        if c != "x":
            t += c

    lt = len(t)
    lh = lt // 2
    tf = t[:lh]
    ts = t[lt-lh:][::-1]

    if tf == ts:
        cnt_end = lh + 1

        cnt = 0
        xf = []
        cur = 0
        for c in s:
            if c != "x":
                xf.append(cur)
                cur = 0
                cnt += 1
                if cnt == cnt_end:
                    break
            else:
                cur += 1

        cnt = 0
        xs = []
        cur = 0
        for c in s[::-1]:
            if c != "x":
                xs.append(cur)
                cur = 0
                cnt += 1
                if cnt == cnt_end:
                    break
            else:
                cur += 1

        ans = 0
        for x1, x2 in zip(xf, xs):
            ans += abs(x1 - x2)

        print(ans)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
import collections

s = input()
slen = len(s)

sl = collections.deque(list(s))
sl_inv = collections.deque(list(s[::-1]))
cnt = 0
while len(sl)>0:
    if sl[0]== sl_inv[0]:
        sl.popleft()
        sl_inv.popleft()
    elif sl[0] == 'x' and sl_inv[0] !='x':
        sl.popleft()
    elif sl[0] != 'x' and sl_inv[0] == 'x':
        cnt += 1
        sl_inv.popleft()
    elif sl[0] != 'x' and sl_inv[0] != 'x' and sl[0]!=sl_inv[0]:
        print(-1)
        exit()
    if len(sl_inv) ==0:
        break
    
print(cnt+len(sl_inv))

Solution (Python):
def main():
    s = input()
    N = len(s)

    nox = []
    idxs = []
    ans = 0
    for i, c in enumerate(s):
        if c != "x":
            nox.append(c)
            idxs.append(i)
    
    if nox != nox[::-1]:
        print(-1)
        exit()
    
    if len(nox) == 0:
        print(0)
        exit()

    if len(nox)%2 == 0:
        left = len(nox)//2 - 1
        right = len(nox)//2
        
        left_idx = idxs[left]
        right_idx = idxs[right]

    else:
        center = len(nox)//2
        left_idx = idxs[center]
        right_idx = idxs[center]

    while not(left_idx == 0 and right_idx == N-1):
        if s[left_idx] == s[right_idx]:
            if left_idx > 0 and right_idx < N - 1:
                left_idx -= 1
                right_idx += 1
            else:
                if left_idx <= idxs[0] and right_idx >= idxs[-1] and (left_idx > 0 or right_idx < N - 1):
                    ans += 1
                if left_idx > 0:
                    left_idx -= 1
                if right_idx < N-1:
                    right_idx += 1

        elif s[left_idx] == "x":
            ans += 1
            if left_idx > 0:
                left_idx -= 1
        elif s[right_idx] == "x":
            ans += 1
            if right_idx < N-1:
                right_idx += 1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys

s = sys.stdin.readline().strip()

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

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

print(ans)

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:
        ans=-1
        break    
print(ans)

Solution (Python):
s = input()

left = 0
right = len(s) - 1
x_cnt = 0

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

print(x_cnt)

Solution (Python):
s=input()
i=0
j=len(s)-1
ans=0
while i<j:
    while s[i]==s[j]=="x":
        i+=1
        j-=1
        if i>j:break
    if i>j:break    
    while s[i]=="x":
        i+=1
        ans+=1
        if i>j:break
    if i>j:break
    while s[j]=="x":
        j-=1
        ans+=1
        if i>j:break
    if i>j:break
    if s[i]!=s[j]:
        ans=-1
        break
    i+=1
    j-=1
    if i>j:break
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    return S,


def is_palindrome(seq):
    n = len(seq)
    for i in range(n//2):
        if seq[i] != seq[n-i-1]:
            return False
    return True


def solve(S):
    S = "*" + S + "*"
    T = [a for a in S if a != "x"]
    N = len(T) // 2 + len(T) % 2
    if not is_palindrome(T):
        return -1
    l = 0
    r = len(S)-1
    c = 0
    while c < N:
        if S[l] != "x":
            c += 1
        l += 1
    c = 0
    while c < N:
        if S[r] != "x":
            c += 1
        r -= 1
    
    L = S[:l]
    R = S[r+1:][::-1]
    ans = 0
    l, r = 0, 0
    for i in range(N+1):
        lc = 0
        rc = 0
        while l < len(L) and L[l] == "x":
            lc += 1
            l += 1
        while r < len(R) and R[r] == "x":
            rc += 1
            r += 1
        ans += abs(lc-rc)
        l += 1
        r += 1
    return ans


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Solution (Python):
def main():
    s = input()

    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

        print(-1)
        return

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    n = len(s)
    ss = "".join(s.replace("x", ""))
    if ss != ss[::-1]:
        print(-1)
        exit()

    res = 0
    left = 0
    right = n - 1
    while left <= right:
        if s[left] == s[right]:
            left += 1
            right -= 1
        else:
            if s[left] == "x":
                left += 1
            else:
                right -= 1
            res += 1
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
*s, = input()

i = 0
j = -1
n = len(s)
ans = 0

while n > 0:
    if s[i] == s[j]:
        i += 1
        j -= 1
        n -= 2
    else:
        ans += 1
        if s[i] == 'x':
            i += 1
            n -= 1
        elif s[j] == 'x':
            j -= 1
            n -= 1
        else:
            ans = -1
            break

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
new = []
for s in S:
    if s=='x':
        continue
    new.append(s)

leng = len(new)
for n in range(leng//2):
    if new[n]!=new[-n-1]:
        print(-1)
        break
else:
    lis = []
    cnt = 0
    for s in S:
        if s!='x':
            lis.append(cnt)
            cnt = 0
        else:
            cnt += 1
    lis.append(cnt)
    leng = len(lis)
    ans = 0
    for i in range(leng//2):
        ans += abs(lis[i]-lis[-i-1])
    print(ans)

Solution (Python):
from collections import deque

s = input()

que = deque(s)
ans = 0
while que.__len__() > 1:
    if que[0] == que[-1]:
        que.popleft()
        que.pop()
    elif que[0] == 'x' and que[-1] != 'x':
        que.append('x')
        ans += 1
    elif que[0] != 'x' and que[-1] == 'x':
        que.appendleft('x')
        ans += 1
    else:
        print(-1)
        exit()
print(ans)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
from queue import deque
q = deque(s)
ans = 0
while q:
    if q[0]==q[-1]:
        q.popleft()
        if q:
            q.pop()
    elif q[0]=="x":
        ans += 1
        q.popleft()
    elif q[-1]=="x":
        ans += 1
        q.pop()
    else:
        ans = -1
        break
print(ans)

Solution (Python):

"""
@author: H_Hoshigi
"""
def main():
    S = input()
    r = 0
    l = len(S)-1

    counter = 0
    while (l - r) >= 1 :
        if S[r] == S[l]:
            r += 1
            l -= 1
        elif S[r] == "x":
            r += 1
            counter += 1
        elif S[l] == "x":
            l -= 1
            counter += 1
        else:
            counter = -1
            break
    print(counter)

if __name__ == "__main__":
    main()

Solution (Python):
s = input()

s1 = s.replace('x', '')

if s1 != s1[::-1]:
    print(-1)
    exit()

l, r = 0, 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
print(ans)

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

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

Solution (Python):
s = input()

ans = 0

while s:

    
    if s[0] == s[-1]:
        s = s[1:-1]

    

    
    elif s[0] == 'x':
        
        s = s[1:]
        ans += 1

    
    elif s[-1] == 'x':
        
        s = s[:-1]
        ans += 1

    
    else:
        print(-1)
        exit()

print(ans)

Solution (Python):


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    from collections import deque
    s=list(input())
    dq=deque(s)
    
    ans=0
    while len(dq)>=2:
        l=dq.popleft()
        r=dq.pop()
        if l==r:
            pass
        elif l=="x":
            ans+=1
            dq.append(r)
        elif r=="x":
            ans+=1
            dq.appendleft(l)
        else:
            print(-1)
            exit()
            
    print(ans)

main()

Solution (Python):
import sys
s=input()
b=[]
an=0
for i in range(len(s)):
  if s[i]!="x":
    b.append(s[i])
for i in range(len(b)):
  if b[i]!=b[-i-1]:
    print(-1)
    sys.exit()

i=j=0 
while i<=len(s)-1-j:
  if s[i]==s[-1-j]:
    i+=1
    j+=1
  elif s[i]=="x":
    i+=1
    an+=1
  elif s[-1-j]=="x":
    j+=1
    an+=1

print(an)

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

j = N-1
xi = 0
xj = 0
res = 0
for i in range(N):
    if s[i] == 'x':
        xi += 1
        continue
    while j>=i:
        if s[j] == 'x':
            xj += 1
            j -= 1
            continue

        if s[i] != s[j]:
            print(-1)
            exit()
        res += abs(xj-xi)
        j -= 1
        break
    xi = xj = 0
print(res)

Solution (Python):
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()

i = 0
ans = 0
while s:
    if s[0] == s[-1]:
        s = s[1:-1]
    elif s[0] == 'x':
        s = s[1:]
        ans += 1
    elif s[-1] == 'x':
        s = s[:-1]
        ans += 1
    else:
        print(-1)
        exit()
print(ans)

Solution (Python):
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()

i = 0
j = len(s)-1
ans = 0
while i <= j:
    if s[i] == 'x' and s[j] != 'x':
        while i <= j and s[i] == 'x':
            ans += 1
            i += 1
    elif s[j] == 'x' and s[i] != 'x':
        while i <= j and s[j] == 'x':
            ans += 1
            j -= 1

    if i <= j:
        if s[i] != s[j]:
            print(-1)
            exit()
        i += 1
        j -= 1
    else:
        break

print(ans)

Solution (Python):
s = input()

s1 = s.replace('x', '')


if s1 != s1[::-1]:
    print(-1)
    exit()

l, r = 0, 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:
        AssertionError('ここには来ないはず')
        pass

print(ans)

Solution (Python):
S = input()
ans = 0
while len(S)>=2:
    if S[0]==S[-1]:
        S = S[1:-1]
    elif S[0]=='x':
        ans += 1
        S = S[1:]
    elif S[-1]=='x':
        ans += 1
        S = S[:-1]
    else:
        ans = -1
        break
print(ans)

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

Solution (Python):
from collections import deque
def m():
    S = input()
    N = len(S)

    q = deque(S)
    ans = 0
    while len(q) > 1:
        left,right = q[0], q[-1]
        if left == right:
            q.pop()
            q.popleft()
            continue
        if left == 'x':
            q.popleft()
            ans +=1
            continue
        if right == 'x':
            ans +=1
            q.pop()
            continue
        return -1
    return ans


print(m())

Solution (Python):
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    s = in_s()

    if s == s[::-1]:
        print(0)
        exit()

    t = s.replace('x', '')
    if t != t[::-1]:
        print(-1)
        exit()

    f = (s[0] == 'x')
    xnum = []
    count = 0
    s = s + 'a'
    N = len(s)

    for i in range(N):
        if s[i] == 'x':
            if f:
                count += 1
            else:
                count = 1
            f = True
        else:
            if f:
                xnum.append(count)
                count = 0
            else:
                xnum.append(0)
            f = False

    ans = 0
    xn = len(xnum)
    for i in range(xn // 2):
        ans += abs(xnum[i] - xnum[xn - 1 - i])

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque

s = deque(input())

ans = 0
while len(s) > 1:
    if s[0] == s[-1]:
        s.pop()
        s.popleft()
    elif s[0] == 'x':
        s.popleft()
        ans += 1
    elif s[-1] == 'x':
        s.pop()
        ans += 1
    elif s[0] != s[-1]:
        print(-1)
        break
else:
    print(ans)

Solution (Python):
from collections import deque

s = deque(input())

ans = 0
while len(s) > 1:
    if s[0] == s[-1]:
        s.pop()
        s.popleft()
    elif s[0] == 'x':
        s.popleft()
        ans += 1
    elif s[-1] == 'x':
        s.pop()
        ans += 1
    else:
        print(-1)
        break
else:
    print(ans)

Solution (Python):
s = list(input())
swox = []
xnum = []

count = 0
for i in range(len(s)):
    if s[i] != 'x':
        swox.append(s[i])
        xnum.append(count)
        count = 0
    if s[i] == 'x':
        count += 1

xnum.append(count)

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

if len(swox) == 0 or sum(xnum) == 0:
    print(0)
else:
    ans = 0
    for i in range(len(xnum)//2):
        ans += abs(xnum[i]-xnum[-i-1])
    print(ans)

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

if n==1:
    print(0)
    exit(0)
from collections import deque

d=deque(s)
i=0
j=1
cnt=0
while d:
    f=d[0]
    l=d[-1]
    if f==l:
        d.popleft()
        if len(d)==0:
            break
        d.pop()
    else:
        if f=='x' and l!='x':
            cnt+=1
            d.popleft()
        elif f!='x' and l=='x':
            cnt+=1
            d.pop()
        else:
            print(-1)
            exit(0)

print(cnt)

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

Solution (Python):
s = input()

core = []

for c in s:
    if c != 'x':
        core.append(c)
if core == []:
    print(0)
    exit()
l = 0
r = len(core) - 1

while l <= r:
    if core[l] != core[r]:
        print(-1)
        exit()
    l += 1
    r -= 1

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

while l <= r:
    lx = 0
    rx = 0
    while s[l] == 'x':
        l += 1
        lx += 1
    while s[r] == 'x':
        r -= 1
        rx += 1
    ans += abs(lx - rx)
    l += 1
    r -= 1
print(ans)

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



if __name__ == '__main__':
    main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    s_x = [i for i in s if i != 'x']
    l_s_x = len(s_x)
    for i in range(l_s_x):
        if s_x[i] != s_x[l_s_x-1-i]:
            print(-1)
            return

    x_num = []
    cnt = 0
    for i in s:
        if i == 'x':
            cnt += 1
        else:
            x_num.append(cnt)
            cnt = 0
    if s[-1] == 'x':
        x_num.append(cnt)
    else:
        x_num.append(0)

    len_x_num = len(x_num)
    ans = 0
    for i in range(len_x_num):
        ans += max(x_num[len_x_num-1-i] - x_num[i], 0)

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    s_x = [i for i in s if i != 'x']
    l_s_x = len(s_x)
    for i in range(l_s_x):
        if s_x[i] != s_x[l_s_x-1-i]:
            print(-1)
            return

    x_num = []
    cnt = 0
    for i in s:
        if i == 'x':
            cnt += 1
        else:
            x_num.append(cnt)
            cnt = 0
    if s[-1] == 'x':
        x_num.append(cnt)
    else:
        x_num.append(0)

    ans = 0
    for i in range(len(x_num)):
        ans += max(x_num[len(x_num)-1-i] - x_num[i], 0)

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):


import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union































def main():
    Num = Union[int, float]
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    def debug(x):print(x, file=sys.stderr)
    
    
    def check_palindrome(s):
        n = len(s)
        for i in range(n//2):
            if s[i] != s[n-1-i]:
                return False
        return True
    
    def find_center(s, cnt):
        num = 0
        n = len(s)
        for i in range(n):
            if s[i] != 'x':
                num += 1
            if num == cnt:
                return i

    def find_center_even(s, cnt):
        num = 0
        n = len(s)
        left, right = -1, -1
        for i in range(n):
            if s[i] != 'x':
                num += 1     
            if num == cnt:
                if left == -1:
                    left = i
                    debug(f"left {left}")
            if num == cnt + 1:
                right = i
                debug(f"right {right}")
                return (left + right) / 2
    
    def not_x_split(s):
        buf = []
        s += 'E'
        n = len(s)
        x_cnt = 0
        for i in range(n):
            if s[i] != 'x':
                buf.append(x_cnt)
                x_cnt = 0
            else:
                x_cnt += 1
        return buf



    def solve(s, buf):
        bufsize = len(buf)
        if bufsize % 2 == 0:
            cnt = bufsize // 2
            ind = find_center_even(s, cnt)
        else:
            cnt = (bufsize + 1) // 2
            ind = find_center(s, cnt)
        
        if ind % 1 == 0:
            left_s = s[:int(ind)][::-1]
            right_s = s[int(ind)+1:]
        else:
            left_s = s[:int(ind)+1][::-1]
            right_s = s[int(ind)+1:]

        
        
        
        left = not_x_split(left_s)
        right = not_x_split(right_s)
        
        
        assert len(left) == len(right)
        ans = 0
        for i in range(len(left)):
            ans += max(left[i], right[i]) - min(left[i], right[i])
        return ans

    
    s = input()
    if check_palindrome(s):
        print(0)
    else:
        buf = [char for char in s if char != 'x']
        if not check_palindrome(buf):
            print(-1)
        else:
            
            print(solve(s, buf))



if __name__ == "__main__":
    main()