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()
X=[]
SS=""
cnt=0
for s in S:
    if s!='x':
        SS+=s
        X.append(cnt)
        cnt=0
    else:
        cnt+=1
X.append(cnt)
flag=True
for i in range(len(SS)//2):
    if SS[i]!=SS[-1-i]:
        flag=False
ans=0
for i in range(len(X)//2):
    ans+=abs(X[i]-X[-1-i])
if flag:
    print(ans)
else:
    print(-1)

Solution (Python):
s = input().rstrip()
n = len(s)
l = 0; r = n-1
ans = 0
while r - l > 0:
    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)
        exit()
print(ans)

Solution (Python):
s = input()
invs = s[::-1]
s = s


i=0
j=0
ans = 0 
while i<len(s) and j<len(s):
  if s[i]==invs[j]:
    i+=1
    j+=1
  elif s[i]=='x':
    i+=1
  elif invs[j]=='x':
    
    j+=1
    ans+=1
  else:
    print(-1)
    break
else:
  if i==j:
    print(ans)
  elif i>j and all([c=='x' for c in invs[j:]]):
    print(ans+i-j)
  elif i<j and all([c=='x' for c in s[i:]]):
    print(ans)
  else:
    print(-1)

Solution (Python):

"""
C - Inserting 'x'
https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_c

"""
import sys


from collections import deque

def solve(s):
    d = deque(s)
    ans = 0
    while len(d) > 1:
        if d[0] == 'x' or d[-1] == 'x':
            if d[0] == 'x' and d[-1] == 'x':
                d.popleft()
                d.pop()
            elif d[0] == 'x':
                d.popleft()
                ans += 1
            else:
                d.pop()
                ans += 1
        else:
            if d[0] == d[-1]:
                d.popleft()
                d.pop()
            else:
                return -1
    return ans


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):

"""
C - Inserting 'x'
https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_c

"""
import sys


from collections import deque

def solve(s):
    d = deque(s)
    ans = 0
    while len(d) > 1:
        if d[0] == 'x' or d[-1] == 'x':
            if d[0] == 'x' and d[-1] == 'x':
                d.popleft()
                d.pop()
            elif d[0] == 'x':
                d.popleft()
                ans += 1
            else:
                d.pop()
                ans += 1
        else:
            if d[0] == d[-1]:
                d.popleft()
                d.pop()
            else:
                return -1
    return ans


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
s = input()
t= "".join(c for c in s if c!="x")
if t!=t[::-1]:
    print(-1)
else:
    ans=0
    i=0
    j=0
    l=len(s)
    while i+j<l-1:
        if s[i] != s[l-1-j]:
            ans+=1
            if s[i] == "x" : i+=1
            else : j+=1
        else:
            i+=1
            j+=1
    print(ans)

Solution (Python):
import collections

s = input()

x_num = collections.deque()
x_num.append(0)
others = collections.deque()
for s_i in s:
    if s_i == 'x':
        x_num[-1] += 1
    else:
        others.append(s_i)
        x_num.append(0)
possible = 1
while len(others) > 1:
    if others.pop() != others.popleft():
        possible = 0
        break
if possible:
    ans = 0
    while len(x_num) > 1:
        ans += abs(x_num.pop() - x_num.popleft())
    print(ans)
else:
    print(-1)

Solution (Python):


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

while r-l>0:
    a,b=s[l],s[r]
    if a==b:
        l+=1
        r-=1
    elif a=='x' and b!='x':
        ans+=1
        l+=1
    elif b=='x' and a!='x':
        ans+=1
        r-=1
    else:
        ans=-1
        break

print(ans)

Solution (Python):
a = input()
b = a[::-1]
s ,t ,r= 0,0,0

while s+t<len(a):
    if a[s] == b[t]:
        s+=1
        t+=1
    elif a[s] =="x":
        r+=1
        s+=1
    elif b[t] =="x":
        r+=1
        t+=1
    else:
        print(-1)
        exit()
print(r)

Solution (Python):
a = input()
b = a[::-1]
s ,t ,r= 0,0,0

while s+t<len(a):
    if a[s] == b[t]:
        s+=1
        t+=1
    elif a[s] =="x":
        r+=1
        s+=1
    elif b[t] =="x":
        r+=1
        t+=1
    else:
        print(-1)
        exit()
print(r)

Solution (Python):
s = input()
d = s.replace('x','')
l = ''
r=''
if d!= d[::-1]:
    print(-1)
    exit()
ans =0
l=[]
cnt = 0
for i in s:
    if i=='x':
        cnt+=1
    else:
        l.append(cnt)
        cnt=0
l.append(cnt)
l1 = l[:len(l)//2]
l2 = l[::-1]
for i in range(len(l1)):
    ans+=abs(l1[i]-l2[i])
print(ans)

Solution (Python):
s = input()

a = ''
for i in range(len(s)):
    if s[i]!='x':
        a+=s[i]

b = ''
for i in range(len(a)):
    b+=a[-1-i]

if a!=b:
    print(-1)
else:
    ss = ''
    for i in range(len(s)):
        ss += s[-1-i]
    i = 0
    j=0
    ans = 0
    while True:
        if i>=len(s):
            ans += len(ss)-j
            break
        elif j>=len(ss):
            ans += len(s)-i
            break
        if s[i]!=ss[j]:
            if s[i]=='x':
                i+=1
            else:
                j+=1
            ans += 1
        else:
            i+=1
            j+=1
    print(ans//2)

Solution (Python):
S = input()

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

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

print(ans)

Solution (Python):
s=input()
t=s.translate(str.maketrans('','','x'))
n=len(t)
if t!=t[::-1]:
  print(-1)
else:
  A=[0]*(n+1)
  cur,ct=0,0
  for i in range(len(s)):
    if s[i]=="x":
      ct+=1
    else:
      A[cur]=ct
      cur+=1
      ct=0
    A[n]=ct
  B=A[::-1]
  ans=0
  for i in range((n+1)//2):
    ans+=abs(A[i]-B[i])
  print(ans)

Solution (Python):
s = input()
t = s[::-1]
N = len(s)

ss = ""
for i in s:
	if i != "x":
		ss += i

if ss != ss[::-1]:
	print(-1)
else:
	i = 0
	j = 0
	xcount = 0
	while i < N and j < N:
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			if s[i] == "x":
				i += 1
			else:
				j += 1
				xcount += 1
	print(xcount + N - j)

Solution (Python):
s = input()

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

while r-l >= 1:
    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:
        ans = -1
        break

print(ans)

Solution (Python):
from collections import deque

s = deque(input())

ans = 0

while len(s) >= 2:
    if s[0] == s[-1]:
        s.popleft()
        s.pop()
    elif s[0] == "x":
        s.append("x")
        ans += 1
    elif s[-1] == "x":
        s.appendleft("x")
        ans += 1
    else:
        ans = -1
        break

print(ans)

Solution (Python):
from collections import deque

s = input()

left = deque(s+"@")
right = deque(s[::-1]+"@")

ans = 0

while left or right:
    if left[0] == right[0]:
        left.popleft()
        right.popleft()
    elif left[0] == "x":
        ans += 1
        left.popleft()
    elif right[0] == "x":
        ans += 1
        right.popleft()
    else:
        ans = -1
        break

ans //= 2
print(ans)

Solution (Python):
from collections import deque

s = input()

ns = ""

for s_i in s:
    if s_i != "x":
        ns += s_i

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

if ns == "":
    print(0)
    exit()

if len(ns) % 2 == 1:
    cnt = -1
    for i,s_i in enumerate(s):
        if s_i != "x":
            cnt += 1
        if cnt == len(ns)//2:
            note = i
            break
    left = deque(s[:note][::-1] + "@")
    right = deque(s[note+1:] + "@")
else:
    cnt = -1
    f = 1
    for i,s_i in enumerate(s):
        if s_i != "x":
            cnt += 1
        if cnt == len(ns)//2 - 1 and f:
            l = i
            f = 0
        if cnt == len(ns)//2:
            r = i
            break
    left = deque(s[:l][::-1] + "@")
    right = deque(s[r+1:] + "@")

ans = 0

while left or right:
    if left[0] == right[0]:
        left.popleft()
        right.popleft()
    elif left[0] == "x":
        left.popleft()
        ans += 1
    elif right[0] == "x":
        right.popleft()
        ans += 1

print(ans)

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

Solution (Python):
S=input()
data=[]
X=''
cnt=0
for s in S:
    if s=='x':
        cnt+=1
    else:
        data.append(cnt)
        cnt=0
        X+=s
data.append(cnt)
ans=0
for i in range(len(data)//2):
    ans+=abs(data[i]-data[-1*i-1])
flag=True
for i in range(len(X)//2):
    if X[i]!=X[-1*i-1]:
        flag=False
if flag:print(ans)
else:print(-1)

Solution (Python):
s = input()

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

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

Solution (Python):
s = input()

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

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

Solution (Python):
s = input()

N = len(s)

score = 0
j = 0
left_len = 0
right_len = 0
flag = 0

for i in range(N):
    flag = 0
    if i + j >= N:
        continue
    left = s[i]
    if left == "x":
        left_len += 1
    else:
        while flag == 0:
            right = s[N-1-j]
            if right == "x":
                right_len += 1
            else:
                if left != right:
                    print(-1)
                    exit()
                else:
                    score += max(left_len,right_len) - min(left_len,right_len)
                    left_len = 0
                    right_len = 0
                    flag = 1
            j += 1

print(score)

Solution (Python):
s = input()
n = len(s)
t = s.replace('x', '')
if t != t[::-1]:
    print(-1)
else:
    u = s[::-1]
    cnt = 0
    l = r = 0
    while l < n or r < n:
        if l >= n:
            cnt += 1
            r += 1
        elif r >= n:
            cnt += 1
            l += 1
        elif s[l] == u[r]:
            l += 1
            r += 1
        elif s[l] == 'x':
            cnt += 1
            l += 1
        else:
            cnt += 1
            r += 1
    print(cnt // 2)

Solution (Python):
s=input()

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

v=len(t)
if len(t)%2==1:
    if t[v//2+1:]!=t[:v//2][::-1]:
        print(-1)
        exit()
else:
    if t[v//2:]!=t[:v//2][::-1]:
        print(-1)
        exit()
v=len(s)-1
w=0
news=0
while v-w>0:
    
    
    if s[w]!=s[v]:
        if s[w]=="x":
            news+=1
            w+=1
        else:
            news+=1
            v-=1
    else:
        w+=1
        v-=1
print(news)

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

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

Solution (Python):


import sys
from collections import deque

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=input()

S2=S.replace('x', '')
for i in range(len(S2)//2):
    if S2[i]!=S2[-(1+i)]:
        print(-1)
        exit()

que=deque(S)
i=cnt=0
while len(que)>1:
    if que[0]!=que[-1]:
        cnt+=1  
        if que[0]=='x':
            que.popleft()
        elif que[-1]=='x':
            que.pop()
    else:
        que.popleft()
        que.pop()
print(cnt)

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

Solution (Python):
from collections import deque
s = deque(input())
le = len(s)
cnt = 0
while le>1:
  if s[0] == s[-1]:
    s.pop()
    s.popleft()
    le -= 2
  elif s[0] == "x":
    s.popleft()
    cnt += 1
    le -= 1
  elif s[-1] == "x":
    s.pop()
    cnt += 1
    le -= 1
  else:
    print(-1)
    break
else:
  print(cnt)

Solution (Python):

import sys
from collections import deque
import copy
import math

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]
    head = 0
    tail = len(S) - 1
    count = 0
    
    while 1:
        if head >= tail:
            break
        if S[head] != S[tail]:
            if S[head] == "x":
                count += 1
                head += 1
            elif S[tail] == "x":
                count += 1
                tail -= 1
            else:
                print -1
                return
        else:
            head += 1
            tail -= 1
    print count


if __name__ == '__main__':
    main()

Solution (Python):

s = input()
rs = "".join(reversed(s))
n = len(s)

res = 0
i = 0
j = 0
while i+j<n:
    if s[i]==rs[j]:
        i += 1
        j += 1
    elif s[i]=="x":
        res += 1
        i += 1
    elif rs[j]=="x":
        res += 1
        j += 1
    else:
        print(-1)
        exit()

print(res)

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":
    ans+=1
    i+=1
  elif s[j]=="x":
    ans+=1
    j-=1
  else:  break
if i <=j :
  print(-1)
  exit(0) 
else: print(ans)

Solution (Python):
s = input()
n = len(s)
mae = 0
ushiro = n - 1
ans = 0

while mae != ushiro:
    if s[mae] == s[ushiro]:
        mae += 1
        ushiro -= 1
        if mae == ushiro + 1:
            break
    elif s[mae] != s[ushiro]:
        if s[mae] == "x":
            mae += 1
            ans += 1
        elif s[ushiro] == "x":
            ushiro -= 1
            ans += 1
        else:
            print(-1)
            exit()

print(ans)

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

print(ans)

Solution (Python):
s = input()
N = len( s)
ans = 0
l = 0
r = N-1
while l < r:
    lx = 0
    rx = 0
    while l <= N-1:
        if s[l] == "x":
            lx += 1
            l += 1
        else:
            break
    while 0 <= r:
        if s[r] == "x":
            rx += 1
            r -= 1
        else:
            break
    if l == r:
        ans += abs( lx - rx)
    if l < r:
        if s[l] == s[r]:
            ans += abs(lx - rx)
        else:
            ans = -1
            break
    l += 1
    r -= 1
print( ans)

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

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

Solution (Python):
s = list(input())
without_x = []
notx_index = []
for i in range(len(s)):
	if s[i] != "x":
		without_x.append(s[i])
		notx_index.append(i)
if not without_x:
	print(0)
elif without_x != without_x[::-1]:
	print(-1)
else:
	n = len(notx_index)
	
	x_num = [notx_index[0]]
	for i in range(n-1):
		x_num.append(notx_index[i+1] - notx_index[i] - 1)
	x_num.append(len(s)-1 - notx_index[n-1])
	
	ans = 0
	for i in range(n // 2 + 1):
		ans += abs(x_num[i] - x_num[n-i])

	print(ans)

Solution (Python):
s=list(input())
S=[]
for i in range(len(s)):
    if s[i]=="x":
        pass
    else:
        S.append(s[i])
        

sr=s[::-1]
SR=S[::-1]
if S!=SR:
    print(-1)
else:
    if len(S)%2==0:
        L=len(S)//2
    else:
        L=len(S)//2+1
    SF=[]
    cntx=0
    for y in range(len(s)):
        if s[y]=="x":
            cntx+=1
        else:
            SF.append(cntx)
            cntx=0
    SF.append(cntx)
    SE=SF[::-1]
    ans=0
    for x in range(len(SE)):
        ans+=abs(SE[x]-SF[x])
    print(ans//2)

Solution (Python):
s = input()
t = s.replace('x','')
if t != t[::-1]:
	print(-1)
	exit()
x = []
cnt = 0
for i in s:
	if i == 'x':
		cnt += 1
	else:
		x.append(cnt)
		cnt = 0
else:
	x.append(cnt)
res = 0
for i in range(len(x)//2):
	res += abs(x[i]-x[-i-1])
print(res)

Solution (Python):
import sys
s = input()
t = s.replace('x', '')
if t != t[::-1]:
    print(-1)
    sys.exit()
if not t:
    print(0)
    sys.exit()
H = []
ctr = 0
for i in s:
    if i != 'x':
        H.append(ctr)
        ctr = 0
        continue
    ctr += 1
H.append(ctr)
print(sum([abs(i-j) for i, j in zip(H, H[::-1])])//2)

Solution (Python):
from math import ceil
S=list(input())
num_x=S.count("x")
N=len(S)
num=N-num_x
cf,cr=0,0
F,R=[],[]

f,r=0,N-1
while len(F)<ceil(num/2):
  if S[f]=="x":
    cf+=1
  else:
    F.append((S[f],cf))
    cf=0
  f+=1
      
while len(R)<ceil(num/2):
  if S[r]=="x":
    cr+=1
  else:
    R.append((S[r],cr))
    cr=0
  r-=1
ans=0  
for i in range(ceil(num/2)):   
  if F[i][0]!=R[i][0]:
    print(-1)
    exit()
  else:
    ans+=abs(F[i][1]-R[i][1])
print(ans)

Solution (Python):
S = list(input())
X, A = [], []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: 
        NX += S[i]
        A.append(i)
    
for i in range(len(NX)//2):
    if NX[i] != NX[-1-i]:
        print(-1)
        break
else:
    if NX == "": print(0)
    else:
        l, r = 0, len(S)-1
        midl = A[(len(NX)-1)//2]
        midr = (A[(len(NX)-1)//2] if len(NX)%2==1 else A[(len(NX)-1)//2 + 1])
        Add = 0
        while l < midl or r > midr:
            if S[l] == S[r] == "x":
                l += 1
                r -= 1
            elif S[l] == "x":
                l += 1
                Add += 1
            elif S[r] == "x":
                r -= 1
                Add += 1
            else:
                l += 1
                r -= 1
        print(Add)

Solution (Python):
S = input()

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

while l<r:
  if S[l] == S[r]:
    l, 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(0)
    
print(cnt)

Solution (Python):
import math
s = str(input())
cou = 0
co = 0
ans = 0
while cou + co +2 <= len(s):
  if s[cou] == "x":
    if s[-1-co] == "x":
      cou += 1
      co += 1
    else:
      cou += 1
      ans += 1
  else:
    if s[-1-co] == "x":
      co += 1
      ans += 1
    else:
      if s[cou] == s[-1-co]:
        cou += 1
        co += 1
      else:
        print(-1)
        exit()
print(ans)

Solution (Python):
S=input()
X=S.replace("x","")
N=len(X)
M=len(S)
for i in range(N):
    if X[i]!=X[-i-1]:
        print(-1)
        exit()
T=""
for i in range(M):
    if S[i]!="x":
        T=T+"o"
    else:
        T=T+"x"
U=[len(i) for i in T.split("o")]
ans=0
K=len(U)
for i in range(K):
    ans+=abs(U[i]-U[-i-1])
    tmp=max(U[i],U[-i-1])
    U[i]=tmp
    U[-1-i]=tmp
print(ans)

Solution (Python):
s = input()
n = len(s)
ans = 0
while s:
  a = s[0]
  b = s[-1]
  if a == b:
    s = s[1:-1]
  elif a == "x" and b != "x":
    s = s[1:]
    ans += 1
  elif a != "x" and b == "x":
    s = s[:-1]
    ans += 1
  else:
    print(-1)
    exit()
print(ans)

Solution (Python):
import sys
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:
    print(-1)
    sys.exit()
print(ans)

Solution (Python):
s=input()
s1=s[::-1]
a,b=0,0
ca,cb=0,0
while a<len(s) and b<len(s):
    if s[a]==s1[b]:
        a+=1
        b+=1
    else:
        if s[a]=='x':
            ca+=1
            a+=1
        elif s1[b]=='x':
            cb+=1
            b+=1
        else:
            ca,cb=-1,-1
            break
print(max(ca,cb))

Solution (Python):
s = input()
L = ""
for c in s:
    if c!="x":
        L += c
n = len(L)
for i in range(n):
    if L[i] == L[-1-i]:
        continue
    else:
        print(-1)
        exit()
x = 0
il = 0
ir = 0
ans = 0
for c in L[:(n+1)//2]:
    x = 0
    while s[il]=="x":
        x+=1
        il+=1
    il+=1
    while s[-1-ir]=="x":
        x-=1
        ir+=1
    ir+=1
    ans += abs(x)
print(ans)

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

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

s = deque(lc())
lens = len(s)

ok = True
ans = 0

while len(s):
    if len(s) == 1:
        s.pop()
    
    elif s[0] == s[-1]:
        s.pop()
        s.popleft()
        
    else:
        if s[0] == "x":
            s.append("x")
            ans += 1
        elif s[-1] == "x":
            s.appendleft("x")
            ans += 1
        else:
            ok = False
            break
    
if ok:
    print(ans)
else:
    print(-1)

Solution (Python):
import re
s = input()
pa = s.replace('x', '')
if pa != pa[::-1]:
    print(-1)
else:
    ans = 0
    sp = re.split(r'[a-wyz]', s)
    for r, l in zip(sp, sp[::-1]):
        ans += abs(len(r) - len(l))
    print(ans // 2)

Solution (Python):
import copy
S = list(input())
s = copy.copy(S)
ans = 1
i = 0
while True:
    if i >= len(s):
        break
    if s[i] == "x":
        del s[i]
        i -= 1
    i += 1

def main(s):
    for i in range(int((len(s)) / 2)):
        if s[i] != s[len(s) - 1 - i]:
            print(-1)
            return 0
    cnt = 0
    num = [-1]
    for i in range(len(S)):
        if S[i] != "x":
            num.append(i)
    num.append(len(S))
    i = 0
    s = copy.copy(S)
    cnt = 0
    
    if len(num) % 2 == 0:
        i = int(len(num) / 2)
        for j in range(i, len(num) - 1):
            
            cnt += abs(abs(num[j] - num[j + 1]) - abs(num[len(num) - j - 1] - num[len(num) - j - 2]))
            
            
    else:
        i = int(len(num) / 2)
        for j in range(i, len(num) - 1):
            
            cnt += abs(abs(num[j] - num[j + 1]) - abs(num[len(num) - j - 1] - num[len(num) - j - 2]))
            
            
    print(cnt)
    return 0
        
            
main(s)

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)
    break
else:
  print(c)

Solution (Python):
s = raw_input()

l = 0
r = len(s)-1

ans = 0
while l <= r and -1 < l < len(s) and -1 < r < len(s):
	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
			quit()
	
print ans

Solution (Python):
s = input()
go = []
back = []
start = 0
end = len(s)-1
res = 0
while start<=end:
    gox = 0
    backx = 0
    while s[end] == 'x' or s[start] == 'x':
        if s[start] == 'x' and start<end:
            start+=1
            gox += 1
        if s[end] == 'x'and start<end:
            end -= 1
            backx +=1
        if start == end:break
    if start == end and s[start] == 'x':
        break
    if s[start] == s[end]:
        start += 1
        end -=1
        res += abs(gox-backx)
        gox = 0
        backx = 0
    else:
        res = -1
        break

print(res)

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

    ss = [i for i in s if i != 'x']
    for i in range(len(ss)//2):
        if ss[i] != ss[len(ss)-1-i]:
            print("-1")
            return

    x_idx, idx, j = [0 for i in range(len(ss)+1)], 0, 0
    while idx < len(s):
        cnt = 0
        while idx < len(s) and s[idx] == 'x':
            cnt += 1
            idx += 1
        x_idx[j] = cnt

        while idx < len(s) and s[idx] != 'x':
            idx += 1
            j += 1

    ans = 0
    for i in range(len(ss)+1):
        if x_idx[i] != x_idx[len(ss)-i]:
            ans += max(x_idx[len(ss)-i], x_idx[i]) - min(x_idx[len(ss)-i], x_idx[i])
            x_idx[i] = x_idx[len(ss)-i] = max(x_idx[len(ss)-i], x_idx[i])

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
Sx = S.replace('x','')

if Sx == Sx[::-1]:
	xx = []
	tmp = 0
	for s in S:
		if s == 'x':
			tmp += 1
		else:
			xx.append(tmp)
			tmp = 0
	xx.append(tmp)
	ans = 0
	L = len(xx)
	for i in range(L//2):
		ans += abs(xx[i]-xx[L-1-i])
	print(ans)
else:
	print(-1)

Solution (Python):
S = input()
S2 = "".join([s for s in S if s != "x"])

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

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

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

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

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

Solution (Python):
s=input()
ss=""
res=0
for c in s:
    ss+=c if c!="x" else ""
if ss!=ss[-1::-1]:
    print(-1)
elif len(ss)%2==0:
    ss=ss[:len(ss)//2]
    for c in ss:
        l=s.find(c)
        r=s.rfind(c)
        res+=max(l,len(s)-1-r)-min(l,len(s)-1-r)
        s=s[l+1:r]
    print(res)
else:
    cent=ss[len(ss)//2]
    ss=ss[:len(ss)//2]
    for c in ss:
        l=s.find(c)
        r=s.rfind(c)
        res+=max(l,len(s)-1-r)-min(l,len(s)-1-r)
        s=s[l+1:r]
    l=s.find(cent)
    r=s.rfind(cent)
    res+=max(l,len(s)-1-r)-min(l,len(s)-1-r)
    print(res)

Solution (Python):
from collections import deque
s = input()
tmp = s.replace('x','')
if tmp == tmp[::-1]:
  left = 0
  right = len(s)-1
  result = deque()
  while 1:
    if right == left:
      result.append(s[left])
      break
    if s[left] == s[right]:
      result.appendleft(s[left])
      result.append(s[right])
      left += 1
      right -= 1
    else:
      result.appendleft('x')
      result.append('x')
      if s[left] == 'x':
        left += 1
      else:
        right -= 1
    if right < left:
      break
  print(len(result)-len(s))
else:
  print(-1)

Solution (Python):

import sys

s = input()

swox = "".join(list(filter("x".__ne__, list(s))))


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

if not is_palind(swox):
    print(-1)
    sys.exit(0)

l = 0
r = -1
count = 0

while True:
    
    
    if l >= r+len(s):
        break
    if s[l] == "x" and s[r] == "x":
        l += 1
        r -= 1
    elif s[l] == "x":
        l += 1
        count += 1
    elif s[r] == "x":
        r -= 1
        count += 1
    else:
        l += 1
        r -= 1
print(count)

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

Solution (Python):
s = input()

s_x = s.replace('x', '')
s = list(s)

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

Solution (Python):
import sys
S=raw_input()

cnt=0
while len(S)>1:
	
	if S[0]==S[-1]:
		S=S[1:-1]
	elif S[0]!=S[-1] and S[0]=="x":
		cnt+=1
		S=S+"x"
	elif S[0]!=S[-1] and S[-1]=="x":
		S="x"+S
		cnt+=1
	else:
		print "-1"
		sys.exit()
print cnt

Solution (Python):
def main():
    s = list(input())
    wox = [i for i in s if i != "x"]
    if len(wox) == 0: return 0
    wowr = list(reversed(wox))
    for i in range(len(wox)//2+1):
        if wox[i] != wowr[i]:
            return -1
    sr = list(reversed(s))
    si = ri = 0
    ret = 0
    while si < len(s) and ri < len(sr):
        if s[si] == sr[ri]:
            si += 1
            ri += 1
        elif s[si] == "x":
            si += 1
            ret += 1
        else:
            ri += 1
            ret += 1
    return (ret + len(s) - min(si,ri))//2
print(main())