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 → xaxbxa → xaxbxax

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 → xoxxx → xxoxxx → xxxoxxx



Sample input:
xabxa


Sample output:
2

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#CODEFESTIVAL2017 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()

def check(s):
    if s == s[::-1]:
        return True
    else:
        return False
if check(s):
    print(0)
else:
    t = ''
    for i in range(len(s)):
        if s[i] != 'x':
            t += s[i]
    lst = list(Counter(t).items())
    lst.sort(key = itemgetter(1))
    if len(lst) != 1:
        if lst[0][1] == 1 and lst[1][1] == 1:
            print(-1)
            quit()
    mid = s.index(lst[0][0])
    front = []
    back = []
    for i in range(mid):
        if s[i] == 'x':
            front.append(i)
    for i in range(mid,len(s)):
        if s[i] == 'x':
            back.append(i)
    ans1 = 0
    for i in front:
        if i not in back:
            ans1 += 1
    ans2 = 0
    for i in back:
        if i not in front:
            ans2 += 1
    ans = ans1 + ans2
    print(ans)

Submission status: Wrong Answer

Solution code:
s=input()

tmp="".join(s.split("x"))
for i in range(len(tmp)//2):
  if tmp[i]!=tmp[-i]:
    print(-1)
    exit()

res=0
l=list(s)
while len(l)>1:
  if l[0]==l[-1]:
    l.pop(0)
    l.pop(-1)
  elif l[0]=="x":
    l.append("x")
    res+=1
  else: #l[-1]=="x"
    l.insert(0,"x")
    res+=1
    
print(res)

Submission status: Wrong Answer

Solution code:
def solve(s):
    n = len(s)
    t = "".join(filter(lambda _: _!= "x", s))
    if t != t[::-1]:
        return -1
    l = 0
    r = n-1
    res = 0
    while l < r:
        nl = 0
        while (l < r) and (s[l] == "x"):
            nl += 1
            l += 1
        nr = 0
        while (l < r) and (s[r] == "x"):
            nr += 1
            r -= 1
        res += abs(nl - nr)
        l += 1
        r -= 1
    return res

s = input()
print(solve(s))

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
while len(s) > 0:
    if s[0] == s[-1]:
        s = s[1:-2]
    else:
        if s[0] == 'x':
            s += 'x'
            cnt += 1
        if s[-1] == 'x':
            s = 'x' + s
            cnt += 1
        if s[0] != 'x' and s[-1] != 'x':
            print(-1)
            exit()
print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()

T = []

x_list = []

temp = 0
for i in range(len(S)):
    if S[i]!="x":
        T.append(S[i])
        x_list.append(temp)
    else:
        temp+=1
x_list.append(temp)

U = T[::-1]
flag=False
for i in range(len(T)):
    if T[i]!=U[i]:
        flag=True
        break

if flag:
    print(-1)
else:
    count=0
    for i in range(len(x_list)//2):
        count+=abs(x_list[i]-x_list[len(x_list)-i-1])

    print(count)

Submission status: Wrong Answer

Solution code:
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+=max(X[i],X[-1-i])
if flag:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

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


i=0
j=0
ans = 0 #sへのｘの挿入をカウント
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':
    # sにxを挿入する想定
    j+=1
    ans+=1
  else:
    print(-1)
    break
else:
  if i==j:
    print(ans)
  elif i>j and invs[j]=='x':
    print(ans+1)
  elif i<j and s[i]=='x':
    print(ans)
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
S = input()

T = ""
cnt = 0

for s in S :
    if s == "x" :
        cnt += 1
    else :
        T += s

if T == T[::-1] :
    ans = cnt
else :
    ans = -1

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
swx=s.replace("x","")
ls,lswx=len(s),len(swx)
for i in range(lswx//2):
    print(swx[i],swx[-i-1])
    if swx[i]!=swx[-i-1]:
        print(-1)
        break
else:
    x,l,r=0,0,ls-1
    while l+(ls-r)<ls:
        if s[l]==s[r]:
            l+=1
            r-=1
        elif s[l]=="x":
            l+=1
            x+=1
        elif s[r]=="x":
            r-=1
            x+=1
        else:
            print("What?")
            break
    print(x)

Submission status: Wrong Answer

Solution code:
s=input()
swx=s.replace("x","")
ls,lswx=len(s),len(swx)
print(swx)
for i in range(lswx//2):
    print(swx[i],swx[-i-1])
    if swx[i]!=swx[-i-1]:
        print(-1)
        break
else:
    x,l,r=0,0,ls-1
    while l+(ls-r)<ls:
        if s[l]==s[r]:
            l+=1
            r-=1
        elif s[l]=="x":
            l+=1
            x+=1
        elif s[r]=="x":
            r-=1
            x+=1
        else:
            print("What?")
            break
    print(x)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()

ns = ""

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

if ns != ns[::-1] or ns == "":
    print(-1)
    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)

Submission status: Wrong Answer

Solution code:
s = list(input())
if s == s[::-1]:
    print(0)
    exit()
cnt = 0
for i in range(len(s)):
    if s[i] == "x":
        s[i] = ""
        cnt += 1
a = "".join(map(str,s))

if a == a[::-1]:
    print(cnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
s = list(input())
cnt = 0
for i in range(len(s)):
    if s[i] == "x":
        s[i] = ""
        cnt += 1
a = "".join(map(str,s))
if len(a)==0:
    print(0)
elif a == a[::-1]:
    print(cnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
s = list(input())
cnt = 0
for i in range(len(s)):
    if s[i] == "x":
        s[i] = ""
        cnt += 1
a = "".join(map(str,s))
if a == a[::-1]:
    print(cnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from sys import exit
s=input()
wox=""
for i in range(len(s)):
  if s[i]!="x":
    wox+=s[i]

lw=len(wox)
left=""
right=""

if lw%2==1:
  left=wox[0:int(lw/2)]
  right=wox[int(lw/2+0.5):-1]
else:
  left=wox[0:int(lw/2)]
  right=wox[int(lw/2):]

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

Submission status: Wrong Answer

Solution code:
#CODEFESTIVAL2017qualC-C
#Inserting'x'
S=input()
notx=''
data=[]
cnt=0
for s in S:
    if s=='x':
        cnt+=1
    else:
        notx+=s
        data.append(cnt)
        cnt=0
data.append(cnt)
ans=0
for i in range((1+len(notx))//2):
    if notx[i]!=notx[len(notx)-i-1]:
        ans=-1
        break
    else:
        ans+=max(data[i],data[-1*i-1])
print(ans)
#notsub

Submission status: Wrong Answer

Solution code:
s = input()
t = s.replace('x', '')
if t != t[::-1]:
    print(-1)
else:
    cnt = 0
    index = 0
    for i in range(len(s)):
        if s[i] != 'x':
            cnt += 1
        if cnt == (len(t)-1) // 2 + 1:
            index = i
            break
    a = s[:index+1]
    b = s[index:] if len(t) % 2 else s[index+1:]
    ans = 0
    la = lb = ra = rb = 0
    while la < len(a) and lb < len(b):
        while ra < len(a) and a[ra] == 'x':
            ra += 1
        while rb < len(b) and b[rb] == 'x':
            rb += 1
        ans += abs((ra-la) - (rb-lb))
        la, lb = ra, rb
        ra += 1
        rb += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
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:
    #print(news)
    #print(s[w],s[v])
    if s[w]!=s[v]:
        if s[w]=="x":
            news+=1
            w+=1
        else:
            news+=1
            v-=1
    else:
        news+=(s[w]=="x")
        w+=1
        v-=1
print(news)

Submission status: Wrong Answer

Solution code:
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=""
while v-w>0:
    #print(news)
    #print(s[w],s[v])
    if s[w]!=s[v]:
        if s[w]=="x":
            news+=s[w]
            w+=1
        else:
            news+=s[v]
            v-=1
    else:
        news+=s[w]
        w+=1
        v-=1
print(news.count("x"))

Submission status: Wrong Answer

Solution code:
s=input()
baks=s[:]
s="".join(list(filter(lambda x:x!="x",s)))
revs="".join(list(reversed(s)))
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)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
lb = 0
rb = len(s) - 1
while rb - lb > 1:
    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)
# https://img.atcoder.jp/code-festival-2017-qualc/editorial.pdf

Submission status: Wrong Answer

Solution code:
import bisect
s = input()
N = len(s)
count = [0] * N
for i in range(N):
    if s[i] != 'x':
        count[i] = count[i - 1] + 1
    else:
        count[i] = count[i - 1]
if count[-1] % 2:
    lb = bisect.bisect_left(count, (count[-1] + 1) // 2)
    ans = 0
    t = s[:lb]
    u = s[lb + 1:][::-1]
else:
    lb = bisect.bisect_left(count, (count[-1] + 1) // 2)
    rb = bisect.bisect_right(count, (count[-1] + 1) // 2)
    ans = (rb - 1 - lb) % 2
    t = s[:lb]
    u = s[rb:][::-1]
i = len(t) - 1
j = len(u) - 1
while i > -1 or j > -1:
    if i > -1 and j > -1 and t[i] == u[j]:
        i -= 1
        j -= 1
    elif i > -1 and t[i] == 'x':
        i -= 1
        ans += 1
    elif j > -1 and u[j] == 'x':
        j -= 1
        ans += 1
    else:
        ans = -1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
s = input()
N = len(s)
count = [0] * N
for i in range(N):
    if s[i] != 'x':
        count[i] = count[i - 1] + 1
    else:
        count[i] = count[i - 1]
count = count
if count[-1] % 2:
    rb = bisect.bisect_left(count, (count[-1] + 1) // 2)
    t = s[:rb]
    u = s[rb + 1:][::-1]
else:
    rb1 = bisect.bisect_left(count, (count[-1] + 1) // 2)
    t = s[:rb1 + 1]
    rb2 = bisect.bisect_left(count, (count[-1] + 1) // 2 + 1)
    u = s[rb2:][::-1]
ans = 0
i = len(t) - 1
j = len(u) - 1
while i > -1 or j > -1:
    if i > -1 and j > -1 and t[i] == u[j]:
        i -= 1
        j -= 1
    elif i > -1 and t[i] == 'x':
        i -= 1
        ans += 1
    elif j > -1 and u[j] == 'x':
        j -= 1
        ans += 1
    else:
        ans = -1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
N = len(s)
count_x = [0] * N
for i in range(N):
    if s[i] == 'x':
        count_x[i] = count_x[i - 1] + 1
    else:
        count_x[i] = count_x[i - 1]
M = N - count_x[-1]
for i in range(N):
    if i - count_x[i] == M // 2:
        break
t = s[:i]
u = s[i + M % 2:][::-1]
ans = 0
i = len(t) - 1
j = len(u) - 1
while i > -1 or j > -1:
    if i > -1 and j > -1 and t[i] == u[j]:
        i -= 1
        j -= 1
    elif i > -1 and t[i] == 'x':
        i -= 1
        ans += 1
    elif j > -1 and u[j] == 'x':
        j -= 1
        ans += 1
    else:
        ans = -1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
s=list(input())
S=[]
for i in range(len(s)):
    if s[i]=="x":
        pass
    else:
        S.append(s[i])
        
#print(S)
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 sf in range(len(s)):
        if len(SF)==L:
            break
        elif s[sf]=="x":
            cntx+=1
        else:
            SF.append(cntx)
            cntx=0
    SE=[]
    cntx=0
    for se in range(len(s)):
        if len(SE)==L:
            break
        elif sr[se]=="x":
            cntx+=1
        else:
            SE.append(cntx)
    ans=0
    for x in range(len(SF)):
        ans+=abs(SE[x]-SF[x])
    print(ans)

Submission status: Wrong Answer

Solution code:
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 += max(x[i], x[-i-1])
print(res)

Submission status: Wrong Answer

Solution code:
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:
        mid = A[(len(NX) - 1)//2]
        Xleft, Xright = set(), set()
        if len(NX) % 2 == 1:
            for x in X:
                if x < mid: Xleft |= {mid-x}
                else: Xright |= {x-mid}
        else:
            mid2 = A[len(NX)//2]
            midX = 0
            for x in X:
                if x < mid: Xleft |= {mid-x}
                elif mid < x < mid2: continue
                else: Xright |= {x-mid2}
        print(len(Xleft ^ Xright))

Submission status: Wrong Answer

Solution code:
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)
    
NXr = ""
for i in reversed(range(len(NX))): NXr += NX[i]

if NXr != NX: print(-1)
elif NX == "": print(0)
else:
    mid = A[(len(NX) - 1)//2]
    Xleft, Xright = set(), set()
    if len(NX) % 2 == 1:
        for x in X:
            if x < mid: Xleft |= {mid-x}
            else: Xright |= {x-mid}
    else:
        mid2 = A[len(NX)//2]
        midX = 0
        for x in X:
            if x < mid: Xleft |= {mid-x}
            elif mid < x < mid2: continue
            else: Xright |= {x-mid2}
    print(len(Xleft ^ Xright))

Submission status: Wrong Answer

Solution code:
S = list(input())
X = []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: NX += S[i]
    
NXr = ""
for i in reversed(range(len(NX))): NXr += NX[i]

if NXr != NX: print(-1)
elif NX == "": print(0)
else:
    mid = S.index(NX[(len(NX) - 1)//2])
    Xleft, Xright = set(), set()
    if len(NX) % 2 == 1:
        for x in X:
            if x < mid: Xleft |= {mid-x}
            else: Xright |= {x-mid}
    else:
        mid2 = S.index(NX[len(NX)//2])
        midX = 0
        for x in X:
            if x < mid: Xleft |= {mid-x}
            elif mid < x < mid2: continue
            else: Xright |= {x-mid2}
    print(len(Xleft ^ Xright))

Submission status: Wrong Answer

Solution code:
S = list(input())
X = []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: NX += S[i]
    
NXr = ""
for i in reversed(range(len(NX))): NXr += NX[i]

if NXr != NX: print(-1)
elif NX:
    mid = S.index(NX[(len(NX) - 1)//2])
    Xleft, Xright = set(), set()
    for x in X:
        if x < mid: Xleft |= {mid-x}
        else: Xright |= {x-mid}
    print(len(Xleft ^ Xright))
else: print(0)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
pa = s.replace('x', '')
if pa != pa[::-1]:
    print(-1)
ans = 0
for i in range(n):
  if s[i] != s[n-i-1]:
    ans += 1
print(ans//2)

Submission status: Wrong Answer

Solution code:
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[:-2]
  else:
    print(-1)
    sys.exit()
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)

X = max(A)
ans = sum([X-a for a in A])
print(ans)

Submission status: Wrong Answer

Solution code:
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]
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)

Submission status: Wrong Answer

Solution code:
import math
s = input();l = len(s);count=0
if l%2==0:
    for i in range(int(l/2)):
        if s[i]!=s[l-1-i]:
            if s[i]=="x" or s[l-1-i]=="x":
                count +=1
            else:
                count+=2
else:
    for i in range(math.floor(l/2)):
        if s[i]!=s[l-1-i]:
            if s[i]=="x" or s[l-1-i]=="x":
                count +=1
            else:
                count+=2
print(count if count!=0 else -1)

Submission status: Wrong Answer

Solution code:
import math
s = input();l = len(s);count=0
if l%2==0:
    for i in range(int(l/2)):
        if s[i]!=s[l-1-i]:
            if s[i]=="x" or s[l-1-i]=="x":
                count +=1
            else:
                count+=2
else:
    for i in range(math.floor(l/2)):
        if s[i]!=s[l-1-i]:
            if s[i]=="x" or s[l-1-i]=="x":
                count +=1
            else:
                count+=2
print(count)

Submission status: Wrong Answer

Solution code:
import sys
S=raw_input()
if S==S[::-1]:
	print "0"
	sys.exit()

l=list(S)
#print l

cnt=0
if l[0]!=l[-1]:
	if l[0]=="x":
		l.append("x")
		cnt+=1
	elif l[-1]=="x":
		l.insert(0,"x")
		cnt+=1
	else:
		print "-1"
		sys.exit()
		
#print l

l1=[]
str_tmp=""
for i,val in enumerate(l):
	if val!="x":
		l1.append([val,i])
		str_tmp+=val

#print l1
#print str_tmp

if str_tmp!= str_tmp[::-1]:
	print "-1"
	sys.exit()

if len(str_tmp)%2==1:
	c_ind_num=l1[len(str_tmp)/2][1]
	cnt+=abs( (len(l)-c_ind_num-1) - c_ind_num )
	print cnt
else:
	cnt+=abs ( (len(l)- l1[len(str_tmp)/2][1]) - (l1[len(str_tmp)/2-1][1]+1) ) 
	print cnt

Submission status: Wrong Answer

Solution code:
import sys
S=raw_input()
if S==S[::-1]:
	print "0"
	sys.exit()

l=list(S)
#print l

cnt=0
if l[0]!=l[-1]:
	if l[0]=="x":
		l.append("x")
		cnt+=1
	elif l[-1]=="x":
		l.insert(0,"x")
		cnt+=1
	else:
		print "-1"
		sys.exit()
		
#print l

l1=[]
for i in l:
	if i!="x":
		l1.append(i)

#print l1
S1=''.join(l1)

if S1!=S1[::-1]:
	print "-1"
	sys.exit()

center_char=S1[len(S1)/2]
c_ind_num=l.index(center_char)
cnt+=abs( (len(l)-c_ind_num-1) - c_ind_num )

print cnt

Submission status: Wrong Answer

Solution code:
s = input()

count = 0
left, right = 0, len(s)-1
for i in range(100):
    if s[left] == s[right]:
        left, right = left+1, right-1
    elif s[left] == 'x':
        left = left+1
        count += 1
    elif s[right] == 'x':
        right = right-1
        count += 1
    else :
        count = -1
        break
    if left >= right:
        break
print(count)

Submission status: Wrong Answer

Solution code:
s = input()

count = 0
left, right = 0, len(s)-1
for i in range(100):
    if s[left] == s[right]:
        left, right = left+1, right-1
    elif s[left] == 'x':
        left = left+1
        count += 1
    elif s[right] == 'x':
        right = right-1
        count += 1
    else :
        count = -1
        break
    if left >= right:
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def calc(value):
    res = 0
    while True:
        if len(value) == 1 or len(value):
            break
        elif value[0] != value[-1] and value[0] != "x" and value[-1] != "x":
            res = -1
            break
        elif value[0] == value[-1]:
            value.pop(0)
            value.pop()
        else:
            value.extend("x") if value[0] == "x" else value.insert(0, "x")
            value.pop(0)
            value.pop()
            res += 1
    return res


def main():
    value = list(input())
    print(calc(value))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
 
ans = 0
p = 0
q = len(s) - 1
while p < 1:
	if s[p] == s[q]:
		p += 1
		q -= 1
	elif s[p] == "x":
		p += 1
		ans += 1
	elif s[q] == "x":
		q -= 1
		ans += 1
	else:
		ans = -1
		break
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
l = 0
n = len(s)-1
ans = 0
for i in range(len(s)):
    if(s[l] == s[n] and l <= n):
        l += 1
        n -= 1
    elif(s[l] == 'x' and l <= n):
        l += 1
        ans += 1
    elif(s[n] == 'x' and l <= n):
        n -= 1
        ans += 1
    elif(s[l] != 'x' and s[n] != 'x'):
        ans = -1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import re

def main():
    s = [i for i in stdin.readline()]
    ans = 0
    f = True
    
    while f:
        if len(s) == 1:
            break
        elif len(s)==2:
            if s[0] == s[1]:
                break
            else:
                f = False
                break
            
        else:
            while len(s)>1:
                if s[0]==s[-1]:
                    del s[0]
                    del s[-1]
                elif s[0] == 'x':
                    s.append('x')
                    ans += 1
                elif s[-1] == 'x':
                    s.insert(0,'x')
                    ans += 1
                elif s[0] != s[-1]:
                    f = False
                    break
    if f:
        print(ans)
    else:
        print(-1)
    
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import re

def main():
    s = [i for i in stdin.readline()]
    ans = 0
    f = True
    while f:
        if len(s) == 1:
            break
        else:
            while len(s)>1:
                if s[0]==s[-1]:
                    del s[0]
                    del s[-1]
                    
                elif s[0] == 'x':
                    s.append('x')
                    ans += 1
                elif s[-1] == 'x':
                    s.insert(0,'x')
                    ans += 1
                elif s[0] != s[-1]:
                    f = False
                    break
    if f:
        print(ans)
    else:
        print(-1)
    
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()

if s == s[::-1]:
    print(0)
else:
    t = s.replace('x', '')
    if t != t[::-1]:
        print(-1)
    else:
        u = list(set(t))
        count = 0
        while True:
            if len(u) == 1 and len(t) > 1:
                tmp = 0
                a = []
                for i in range(len(s)):
                    if s[i] == u[0]:
                        a.append(i-tmp)
                        tmp = i + 1
                a.append(len(s) - tmp)
                for i in range(int((len(a)+1)/2)):
                    count += abs(a[i]-a[len(a)-1-i])
                u.remove(u[0])
                front = s[:int(len(s)/2)+1]
                back = s[int(len(s)/2)+1:]
            else:
                key = t[int((len(t)-1)/2)]
                for i in range(len(s)):
                    if s[i] == key:
                        cen = i+1
                        break
                front = s[:cen].replace(key, '')
                back = s[cen:].replace(key, '')
                u.remove(key)
                if len(front) == 0:
                    flag = 1
                    f_num = 0
                else:
                    flag = 0
                    for i in range(len(front)-1, -1, -1):
                        if front[i] in u:
                            flag = 1
                            f_num = len(front) - 1 - i
                            break
                if flag == 0:
                    f_num = len(front)
                if len(back) == 0:
                    flag = 1
                    b_num = 0
                else:
                    flag = 0
                    for i in range(len(back)):
                        if back[i] in u:
                            flag = 1
                            b_num = i
                            break
                if flag == 0:
                    b_num = len(back)
                count += abs(f_num - b_num)
                front = front[:len(front)-f_num]
                back = back[b_num:]
            if front[:] == back[::-1] or len(u) == 0:
                break
            else:
                s = front+back
                t = t.replace(key, '')
        print(count)

Submission status: Wrong Answer

Solution code:
import sys


def is_kaibun(mojiretu):
    for i in range(0, len(mojiretu) // 2):
        if mojiretu[i] != mojiretu[len(mojiretu) - (i + 1)]:
            return False

    return True


if __name__ == '__main__':
    s = input()
    if not is_kaibun(s.replace("x", "")):
        print(-1)
        sys.exit()

    s_rev = s[::-1]

    target = 0
    ans = 0
    s_list = list(s)
    s_rev_list = list(s_rev)
    while True:
        if len(s) // 2 < target:
            break

        if s_list[target] == s_rev_list[target]:
            target += 1
            continue
        elif s_list[target] == "x":
            s_rev_list.insert(target, "x")
            s_list.insert(len(s_list) - target, "x")
            ans += 1
            target += 1
        elif s_rev_list[target] == "x":
            s_list.insert(target, "x")
            s_rev_list.insert(len(s_rev_list) - target, "x")
            ans += 1
            target += 1
        # print(s_list)

    print(ans)

Submission status: Wrong Answer

Solution code:
a = input()
kaibun = a.replace("x","")

def palindrome(string):
    return 0 if string==string[::-1] else -1

if palindrome(kaibun) == -1:
    print(-1)
elif palindrome(a) == 0:
    print(0)
else:
    print(int(len(a)) - int(len(kaibun)))

Submission status: Wrong Answer

Solution code:
import string

S = input()
S1 = [s for s in S if s != 'x']
if S == S[::-1]:
    print(0)
    exit()

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

ret = 0

l = -1
r = len(S)
for i, s in enumerate(S):
    if s == 'x':
        l += 1
    else:
        break

for i, s in enumerate(S[::-1]):
    if s == 'x':
        r -= 1
    else:
        break

ret += abs(l + 1 - (len(S) - r))

S2 = S[l + 1:r]

for s1, s2 in zip(S2, S2[::-1]):
    if (s1 == 'x' and s2 != 'x') or (s1 != 'x' and s2 == 'x'):
        ret += 0.5

print(int(ret))

Submission status: Wrong Answer

Solution code:

s = list(input())
s2 = list(filter(lambda x:x!="x" , s))

def cycle_check(S , level):
    
    # 回文になっているかどうかのみ
    if level == 1:
        for i in range(len(S)//2):
            if S[i] != S[-i-1]:
                return True
        else:
            return False
    
    # 必要なxの個数
    if level == 2:
        x_cnt = 0
        x_list = []
        for s in S:
            if s != "x":
                if x_cnt > 0:
                    x_list.append(x_cnt)
                x_list.append(0)
                x_cnt = 0
            else:
                x_cnt += 1
        
        if x_cnt > 0:
            x_list.append(x_cnt)
        
        ans = 0
        left_slide = 0
        right_slide = 0
        i = 0
        check_list = [True] * len(x_list)
        
        while True:
            check_list[i-left_slide] = False
            check_list[-i-1+right_slide] = False
            if abs(x_list[i-left_slide]-x_list[-i-1+right_slide]) != 0:
                ans += abs(x_list[i-left_slide]-x_list[-i-1+right_slide])
                if x_list[i-left_slide] > x_list[-i-1+right_slide]:
                    right_slide += 1
                else:
                    left_slide += 1
            if i + max(left_slide,right_slide) >= len(x_list)//2:
                if check_list.count(True) <= 1:
                    break
            i += 1 
                
        return ans
    
if cycle_check(s2,1):
    print(-1)

else:
    print(cycle_check(s, 2))

Submission status: Wrong Answer

Solution code:
s = input()
list(s)
a = []
n = 0
for i in range(len(s)):
    if s[i] == "x" :
        continue
    else :
        a.append(s[i])
for i in range(len(a)//2):
    if a[i] != a[-(i+1)]:
        print(-1)
        break
    else:
        for i in range(len(s)):
            if s[i] == "x" :
                if s[-(i+1)] != s[i]:
                   n=+1
        print(n)