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
s = input()

l = s.replace("x", "")
ll = len(l) // 2
lr = len(l) - ll
if l[:ll] != l[lr:][::-1]:
    print(-1)
    sys.exit()

xcnt = [0] * lr
c = 0
cnt = 0
i = 0
while c != lr:
    if s[i] != "x":
        xcnt[c] = cnt
        c += 1
        cnt = 0
    else:
        cnt += 1
    i += 1
    
c = 0
cnt = 0
i = len(s) - 1
while c != lr:
    if s[i] != "x":
        xcnt[c] -= cnt
        xcnt[c] = abs(xcnt[c])
        c += 1
        cnt = 0
    else:
        cnt += 1
    i -= 1

print(sum(xcnt))

Solution (Python):
S = input()
S1 = [s for s in S if s != 'x']


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

Solution (Python):
from collections import deque

s = input()
s_list = deque(list(s))

x_count = 0
flag = True
while len(s_list) > 1:

    s_head = s_list.popleft()
    s_tail = s_list.pop()

    if s_head == s_tail:
        continue
    elif s_head == "x":
        x_count += 1
        s_list.append(s_tail)
        continue
    elif s_tail == "x":
        x_count += 1
        s_list.appendleft(s_head)
        continue
    else:
        flag = False
        break

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

Solution (Python):
import sys


S = input()
length_S = len(S)

cursor_head = 0
cursor_tail = -1

ret = 0

while length_S + cursor_tail > cursor_head:
  if S[cursor_head] == S[cursor_tail]:
    cursor_head += 1
    cursor_tail -= 1
  else:
    if S[cursor_head] == 'x':
      cursor_head += 1
      ret += 1
    elif S[cursor_tail] == 'x':
      cursor_tail -= 1
      ret += 1
    else:
      print(-1)
      sys.exit()
    
print(ret)

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

Solution (Python):
from collections import deque
S = input()
q = deque(S)
c = 0
while len(q):
  l = q[0]
  r = q[len(q)-1]
  if l == r:
    if len(q) != 1:
      q.pop()
    q.popleft()
  elif l == 'x':
    q.append('x')
    c += 1
  elif r == 'x':
    q.appendleft('x')
    c += 1
  else:
    print(-1)
    exit()
print(c)

Solution (Python):
s=input()
l=0
r=len(s)-1
ans=0
while r>l:
    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
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline







S = input().strip()

q = deque(S)
c = 0
while len(q):
     l = q[0]
     r = q[len(q)-1]

     if l == r:
          if len(q) != 1:
               q.pop()
          q.popleft()
     elif l == 'x':
          q.append('x')
          c += 1
     elif r == 'x':
          q.appendleft('x')
          c += 1
     else:
          print(-1)
          exit()

print(c)

Solution (Python):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline







S = input().strip()

q = deque(S)
c = 0
while len(q):
     l = q[0]
     r = q[len(q)-1]

     if l == r:
          if len(q) != 1:
               q.pop()
          q.popleft()
     elif l == 'x':
          q.append('x')
          c += 1
     elif r == 'x':
          q.appendleft('x')
          c += 1
     else:
          print(-1)
          exit()

print(c)

Solution (Python):
S = input()
N = len(S)
si, ei = 0, N-1
cnt = 0
while si<ei:
  if S[si] != S[ei]:
    if S[si] == 'x':
      si += 1
      cnt+=1
    elif S[ei] == 'x':
      ei -= 1
      cnt+=1
    else:
      print(-1)
      exit()
  else:
    si += 1
    ei -= 1
print(cnt)

Solution (Python):
s=input()

l=0
r=len(s)-1
ans=0
while l<r:
    if s[l]=='x' and s[r]=='x':
        l+=1
        r-=1
    elif s[l]=='x' and s[r]!='x':
        l+=1
        ans+=1
    elif s[l]!='x' and s[r]=='x':
        r-=1
        ans+=1
    elif s[l] == s[r]:
        l+=1
        r-=1
    else:
        ans=-1
        break
print(ans)

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

Solution (Python):
S = input().strip()


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

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

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

S = list(input().rstrip())
L = len(S)

T = []
Inds = [-1]
for i, s in enumerate(S):
    if s != "x":
        T.append(s)
        Inds.append(i)
Inds.append(L)

if T != T[::-1]:
    print(-1)
else:
    R = len(T)
    ans = 0
    for i in range((R+1)//2):
        l = Inds[i+1] - Inds[i]
        r = Inds[-i-1] - Inds[-i-2]
        ans += abs(r-l)
    print(ans)

Solution (Python):







s = input()

if len(s) == 1:
    print(0)
    exit()
t = ""
for sv in s:
    if sv != "x":
        t += sv
if t != t[::-1]:
    print(-1)
    exit()

l, r = 0, len(s) - 1
ls, rs = "", ""
ans = 0
x = False
while l < r:
    if s[l] == s[r]:
        ls += s[l]
        rs += s[r]
        l += 1
        r -= 1
    else:
        if s[l] == "x":
            while l < r and s[l] != s[r]:
                l += 1
                ans += 1
        else:
            while l < r and s[r] != s[l]:
                r -= 1
                ans += 1
print(ans)

Solution (Python):
s = input()
findex = 0
eindex = len(s) - 1
cnt = 0
ftmp = 0
if len(s) == 1:
    print(0)
    exit()
while eindex - findex > 0:

    if s[findex] == s[eindex]:
        findex += 1
        eindex -= 1
        continue

    else:
        if s[eindex] != 'x' and s[findex] == 'x':
            findex += 1
            cnt += 1
        elif s[findex] != 'x' and s[eindex] == 'x':
            eindex -= 1
            cnt += 1
        else:
            cnt = -1
            break

print(cnt)

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

Solution (Python):
import re
s = input()
t = s.replace("x", "")
if t != t[::-1]:
  print(-1)
else:
  k = re.split('[abcdefghijklmnopqrstuvwyz]', s)
  l = len(k)
  ans = 0
  for i in range(l//2):
    ans += abs(len(k[i]) - len(k[l-1-i]))
  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:
        print(-1)
        exit()
print(ans)

Solution (Python):
S = input()
rev_S = S.replace("x", "")

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

res = 0

N = len(S)
l, r = 0, N - 1
while l < r:
    if S[l] == S[r]:
        l, r = l + 1, r - 1
    elif S[l] == "x":
        l += 1
        res += 1
    elif S[r] == "x":
        r -= 1
        res += 1

print(res)

Solution (Python):
def codef(S):
    
    s_tmp = S.replace("x", "")
    for i, j in zip(s_tmp, s_tmp[::-1]):
        if i != j:
            return -1

    cnt = 0
    x_cnt = []
    for s in S:
        if s == "x":
            cnt += 1
        else:
            x_cnt.append(cnt)
            cnt = 0
    x_cnt.append(cnt)

    res = sum(abs(x-y) for x, y in zip(x_cnt, x_cnt[::-1])) // 2
    return res


if __name__ == "__main__":
    s = input()
    ans = codef(s)
    print(ans)

Solution (Python):
def main():
    s = input()
    chars = list(s)
    length = len(s)
    l = 0
    r = length - 1
    xcount = 0
    while l <= r and 0 <= r and l < length:
        if chars[l] == chars[r]:
            l += 1
            r -= 1
            continue

        if chars[l] == 'x':
            xcount += 1
            l += 1
            continue

        if chars[r] == 'x':
            xcount += 1
            r -= 1
            continue
        print(-1)
        return

    print(xcount)


main()

Solution (Python):
import sys
input = sys.stdin.readline
s = list(input())[: -1]
i = 0
j = len(s) - 1
res = 0
while i < j:
  if s[i] != s[j]:
    res += 1
    if s[i] == "x":
      i += 1
    elif s[j] == "x":
      j -= 1
    else:
      print(-1)
      exit(0)
  else:
    i += 1
    j -= 1
print(res)

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

Solution (Python):
s=input()
t=s.replace('x','')
if t!=t[::-1]:
    print(-1)
else:
    l=[]
    k=0
    for c in s:
        if c=='x':
            k+=1
        else:
            l.append(k)
            k=0
    l.append(k)

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

    print(ans)

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

Solution (Python):
s = input()
l = 0
r = len(s)-1
c = 0
if s.count("x") == len(s):
  print(0)
  exit()
while l < r:
  c_l = 0
  c_r = 0
  while s[l] == "x":
    c_l += 1
    l += 1
  while s[r] == "x":
    c_r += 1
    r -= 1
  if s[l] != s[r]:
    print(-1)
    exit()
  c += abs(c_l-c_r)
  l += 1
  r -= 1
print(c)

Solution (Python):
s = input()

i = 0
j = len(s) - 1
ans = 0
while i != j:
    if abs(i - j) == 1:
        if s[i] == s[j]:
            break
    if s[i] != s[j]:
        if s[i] != "x" and s[j] != "x":
            print(-1)
            exit()
        elif s[i] != "x":
            j -= 1
        else:
            i += 1
        ans += 1
    else:
        i += 1
        j -= 1

print(ans)

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

Solution (Python):
import math
s = input().strip()
A = []
B = [0 for _ in range(len(s)+1)]
y = ""
for i in range(len(s)):
    if s[i]!="x":
        y += s[i]
        A.append(i)
        B[i+1] = B[i]
    else:
        B[i+1] = B[i]+1
flag=0
cnt = 0
for i in range(len(y)//2):
    if y[i]!=y[-(i+1)]:
        flag = 1
        cnt = -1
        break
if flag==0 and len(y)>0:
    if B[A[0]]!=B[-1]-B[A[-1]]:
        cnt += abs(B[A[0]]-(B[-1]-B[A[-1]]))
    for i in range(1,math.ceil(len(A)/2)):
        if B[A[i]]-B[A[i-1]] != B[A[-i]]-B[A[-(i+1)]]:
            cnt += abs(B[A[i]]-B[A[i-1]]-(B[A[-i]]-B[A[-(i+1)]]))
print(cnt)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
l = 0
r = n-1
res = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        res += 1
        l += 1
    elif s[r] == 'x':
        res += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(res)

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


def main():
    s = input().strip()
    import collections
    q = collections.deque(s)
    ans = 0
    while q:
        s, t = q[0], q[-1]
        if s == t:
            q.popleft()
            if q:
                q.pop()
        elif s == "x" and t != "x":
            ans += 1
            q.popleft()
        elif s != "x" and t == "x":
            ans += 1
            q.pop()
        else:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    main()

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


def main():
    s = input().strip()
    l, r = 0, len(s)-1
    ans = 0
    while l < r:
        if s[l] == s[r]:
            l += 1
            r -= 1
        elif s[l] == "x" and s[r] != "x":
            ans += 1
            l += 1
        elif s[l] != "x" and s[r] == "x":
            ans += 1
            r -= 1
        else:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
S=input()
_S=[]
for s in S:
    if s != "x":
        _S.append(s)
len_S=len(_S)
if  sum([_S[i]!=_S[-i-1] for i in range(len_S//2)]):
    print(-1)
else:
    count=0
    i,m=0,len(S)-1
    while m-i>0:
        if S[i]=="x" and S[m]!="x":
            i+=1
            count+=1
        elif S[i]!="x" and S[m]=="x":
            m-=1
            count+=1
        else:
            i+=1
            m-=1
    print(count)

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

if t != t[::-1] :
    print(-1)
    
else :
    sp = []
    cnt = 0
    for i in s :
        if i != 'x' :
            sp.append(cnt)
            cnt = 0
        else :
            cnt += 1
    
    sp.append(cnt)
    
    ret = 0
    n = len(sp)
    for i in range(n // 2) :
        ret += abs(sp[i] - sp[n-1-i])
        
    print(ret)

Solution (Python):
N=list(input())

l=0
r=len(N)-1

c=0
while(True):
    if(r<=l):
        print(c)
        exit()
    
    if(N[l]==N[r]):
        l+=1
        r-=1
    elif(N[l]=="x" and N[r]!="x"):
        l+=1
        c+=1
    elif(N[l]!="x" and N[r]=="x"):
        r-=1
        c+=1
    else:
        print(-1)
        exit()

Solution (Python):
S=input()
ans=0
indf=0
indl=len(S)-1
while indf<indl:
  if S[indf]==S[indl]:
    indf+=1
    indl-=1
    continue
  if S[indf]=="x":
    indf+=1
    ans+=1
  elif S[indl]=="x":
    indl-=1
    ans+=1
  else:
    print(-1)
    break
else:
  print(ans)

Solution (Python):
S=input()
import collections
counter=collections.Counter(S)




ans=0
indf=0
indl=len(S)-1
while indf<indl:
  if S[indf]==S[indl]:
    indf+=1
    indl-=1
    continue
  if S[indf]=="x":
    indf+=1
    ans+=1
  elif S[indl]=="x":
    indl-=1
    ans+=1
  else:
    print(-1)
    break
else:
  print(ans)

Solution (Python):
s = input()

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

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

print(answer)

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


S = sys.stdin.buffer.readline().decode().rstrip()

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

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

print(ans)

Solution (Python):
s=list(input())
count=0
i=0
j=len(s)-1
while j-i>=1:
    if s[i]==s[j]:
        i+=1
        j-=1
    elif s[i]=='x':
        count+=1
        i+=1
    elif s[j]=='x':
        count+=1
        j-=1
    else:
        print(-1)
        exit()
print(count)

Solution (Python):

s_ = "x"+input()+"x"
s = []
c = []
cnt = 0
"""
if s_[0]!="x":
    c.append(0)
"""
for i in range(len(s_)):
    if s_[i]!="x":
        c.append(cnt)
        cnt = 0
        s.append(s_[i])
    else:
        cnt += 1
c.append(cnt)

l = len(s)
for i in range(l//2):
    if s[i]!=s[l-i-1]:
        print(-1)
        exit()
ans = 0
l2 = len(c)
for i in range(l2):
    ans += abs(c[i]-c[l2-i-1])

print(ans//2)

Solution (Python):
s = input()
start = 0
end = len(s) -1
insertions = 0
while(start < end):
    if s[start] == s[end]:
        start += 1
        end -= 1
        continue

    if 'x' == s[end]:
        insertions += 1
        end -= 1
    elif 'x' == s[start]:
        insertions += 1
        start += 1
    else:
        print(-1)
        exit(0)

print(insertions)

Solution (Python):
w=list(input())
b=True
n=len(w)
left=0
right=n-1
count=0
while left<=right:
  if w[left]==w[right]:
    left+=1
    right-=1
  elif w[left]=="x":
    left+=1
    count+=1
  elif w[right]=="x":
    right-=1
    count+=1
  else:
    b=False
    break
if b:
  print(count)
else:
  print(-1)

Solution (Python):

import sys
import collections












def is_palindrome_in(s):
    s = s.replace('x', '')
    if list(s) == list(reversed(s)):
        return True
    return False

def main():
    s = sys.stdin.readline().rstrip()
    
    if not is_palindrome_in(s):
        print(-1)
        sys.exit()
    
    s = collections.deque(s)
    
    count = 0
    while len(s) > 1:
        if s[0] == 'x':
            if s[-1] == 'x':
                s.popleft(); s.pop()
            else:
                s.popleft()
                count += 1
        else:
            if s[-1] != 'x':
                s.popleft(); s.pop()
            else:
                s.pop()
                count += 1

    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
s=input()
p=""
q=[]
cnt=0
for i in range(len(s)):
	if s[i]!="x":
		p+=s[i]
		q.append(cnt)
		cnt=0
	else:
		cnt+=1
q.append(cnt)
if p!=p[::-1]:
	print(-1)
	exit()
ans=0
for i in range(len(q)):
	ans+=abs(q[i]-q[-i-1])
print(ans//2)

Solution (Python):
import sys
from heapq import heappop, heappush


def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return sorted([list(map(int, input().split())) for _ in range(n)])
def graphm():
    n=inp()
    g=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b,w=inpm()
        a-=1
        b-=1
        g[a].append((b,w))
        g[b].append((a,w))
    return n,g


def main():
    s=input()
    n=len(s)
    i_l = 0
    i_r = n-1
    cnt = 0
    flag = False
    while True:
        if i_l >= i_r:
            if i_l == i_r:
                flag = True
            if flag:
                print(cnt)
                return
            else:
                print(-1)
                return
        if s[i_l] == s[i_r]:
            i_l += 1
            i_r -= 1
            flag = True
        elif s[i_l] == 'x' and s[i_r] != 'x':
            cnt += 1
            i_l +=1
            flag = False
        elif s[i_l] != 'x' and s[i_r] == 'x':
            cnt += 1
            i_r -=1
            flag = False
        elif s[i_l] != 'x' and s[i_r] != 'x' and s[i_l] != s[i_r]:
            print(-1)
            return

if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque

def main():
    S = input()
    Q = deque(S)
    cnt = 0
    while Q:
        if len(Q) == 1:
            break
        front = Q.popleft()
        back = Q.pop()
        if front == back:
            continue
        if front == 'x':
            cnt += 1
            Q.append(back)
            continue
        if back == 'x':
            cnt += 1
            Q.appendleft(front)
            continue
        print(-1)
        exit()

    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
S = input()

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
S = input()

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

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

    left = 0
    right = n - 1

    ret = 0
    while left < right:
        if s[left] == s[right]:
            left += 1
            right -= 1
        elif s[left] == 'x':
            ret += 1
            left += 1
        elif s[right] == 'x':
            ret += 1
            right -= 1
        else:
            return -1
    return ret


print(solve())

Solution (Python):
s = str(input())

r = 0
l = len(s)-1
result = 0
h = True
while r < l:
    if s[r] == s[l]:
        r += 1
        l -= 1
    elif s[l] == 'x':
        result += 1
        l -= 1
    elif s[r] == 'x':
        result += 1
        r += 1
    else:
        h = False
        break

if h:
    print(result)
else:
    print(-1)

Solution (Python):
import sys

s = input()

rem = []
remrev = []

for i in s:
    if i != "x":
        rem.append(i)
        remrev.append(i)

remrev.reverse()

for i in range(len(rem)):

    if rem[i] != remrev[i]:
        print (-1)
        sys.exit()

nx = 0
xnum = []

for i in s:

    if i == "x":
        nx += 1
    else:
        xnum.append(nx)
        nx = 0

xnum.append(nx)

xnc = xnum.copy()
xnc.reverse()

ans = 0

for i in range((len(xnum) + 1) // 2):

    ans += abs(xnum[i]-xnc[i])

print (ans)

Solution (Python):
S = list(input())
i, j = 0, 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:
        print('-1')
        break

else:
    print(ans)

Solution (Python):
S = input()


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


print(cnt)

Solution (Python):
import sys
input=sys.stdin.readline
s=input()[:-1]
ans=0
while s:
    a=s[0]
    b=s[-1]
    if a==b:
        s=s[1:-1]
        continue
    elif a=="x":
        s=s[1:]
        ans+=1
        continue
    elif b=="x":
        s=s[:-1]
        ans+=1
        continue
    else:
        print(-1)
        exit()

print(ans)

Solution (Python):
s = input()
lens = len(s)
l = 0
r = lens - 1
cnt = 0
while l != r:
  if s[l] == s[r]:
    l += 1
    r -= 1
    if l > r:
      break
  elif s[l] == 'x':
    cnt += 1
    l += 1
  elif s[r] == 'x':
    cnt += 1
    r -= 1
  else:
    print(-1)
    exit()
print(cnt)

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

l=0
r=len(s)-1

ans=0
while r-l>0:
  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:
      print(-1)
      exit()
      
print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
l = 0
r = n-1
res = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        res += 1
        l += 1
    elif s[r] == 'x':
        res += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(res)

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

Solution (Python):

s=input()
length=len(s)
string=""
for i in range(length):
    if s[i]!="x":
        string=string+s[i]
    else:
        continue


flag=True
length2=len(string)
if length2>=2:
    for i in range(length2//2):
        if string[i]!=string[-(i+1)]:
            flag=False
            break
if flag:
    s="x"+s+"X"
    length=len(s)
    checklist=[]
    count=0
    for i in range(length):
        if s[i]=="x":
            count+=1
        else:
            checklist.append(count)
            count=0
    checklist[0]-=1
    ans=0
    for i in range(len(checklist)//2):
        ans+=abs(checklist[i]-checklist[-(i+1)])
    print(ans)
    
else:
    print("-1")

Solution (Python):
s = input()
l, r = 0, len(s)-1
ans = 0
while(True):
    if l >= r: break
    sl, sr = s[l], s[r]
    if sl == sr: l += 1; r -= 1
    elif sl == "x":
        ans += 1
        l += 1
    elif sr == "x":
        ans += 1
        r -= 1
    elif sl != sr:
        ans = -1
        break

print(ans)

Solution (Python):
s = input()
cnt = 0
while len(s) > 0:

  if s[0] == s[-1]:
    s = s[1:-1]
  elif s[0] == "x":
    cnt += 1
    s = s[1:]
  elif s[-1] == "x":
    cnt += 1
    s = s[:-1]
  else:
    print(-1)
    exit()
print(cnt)

Solution (Python):
S = list(input())
i = 0
r = len(S)-1
ans = 0
while i < len(S) or r >= 0:
  if i >= len(S):
    if r < 0:
      break
    else:
      if S[r] == "x":
        ans += 1
        r -= 1
      else:
        ans = -1
        break
  if r < 0:
    if i >= len(S):
      break
    else:
      if S[i] == "x":
        ans += 1
        i += 1
      else:
        ans = -1
        break
  if i < len(S) and r >= 0:
    if S[i] != S[r]:
      if S[i] == "x":
        ans += 1
        i += 1
      elif S[r] == "x":
        ans += 1
        r -= 1
      else:
        ans = -1
        break
    else:
      i += 1
      r -= 1
print(ans//2)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

def main():
    s = input().strip()
    n = len(s)
    ans = 0
    i = 0
    j = n-1
    while i < j:
        if s[i] != s[j]:
            if s[i] == 'x':
                i += 1
                ans += 1
            elif s[j] == 'x':
                j -= 1
                ans += 1
            else:
                print(-1)
                return
        else:
            i += 1
            j -= 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
s = (stdin.readline().rstrip())
l = 0
r = 1
ans = 0

for i in range(len(s)):

    if l+r >= len(s):
        break

    if s[l] == s[-r]:
        l += 1
        r += 1

    elif s[l] == "x" and s[-r] != "x":
        ans += 1
        l += 1

    elif s[l] != "x" and s[-r] == "x":
        ans += 1
        r += 1

    else:
        ans = -1
        break

print(ans)

Solution (Python):
from sys import stdin
s = (stdin.readline().rstrip())
l = 0
r = 1
ans = 0

for i in range(len(s)):

    if l+r > len(s):
        break

    if s[l] == s[-r]:
        l += 1
        r += 1

    elif s[l] == "x" and s[-r] != "x":
        ans += 1
        l += 1

    elif s[l] != "x" and s[-r] == "x":
        ans += 1
        r += 1

    else:
        ans = -1
        break

print(ans)

Solution (Python):
s = input()
l, r = 0, len(s) - 1
ans = 0
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(0)
    l += 1
    r -= 1
print(ans)

Solution (Python):
import sys
s=list(input())
ct=0
l=0;r=len(s)-1
while l<r:
  if s[l]==s[r]:
    l+=1
    r-=1
  elif s[l]!='x' and s[r]!='x':
    print(-1)
    sys.exit()
  elif s[l]=='x':
    ct+=1
    l+=1
  else:
    ct+=1
    r-=1
print(ct)

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

Solution (Python):
s=input()

r=-1
idx=0
LS=len(s)
st=(LS+1)//2

while True:
    if idx>=len(s)+r:
        break
    if s[idx]==s[r]:
        idx+=1
        r-=1
    elif s[idx]=="x" and s[r]!="x":
        LS+=1
        idx+=1
    elif s[idx]!="x" and s[r]=="x":
        LS+=1
        r-=1
    else:
        print(-1)
        exit()


print(LS-len(s))

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