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:

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 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()
s_x = [i for i in s if 'x' not in i]

cnt = 1
cen = int(len(s) / 2)
for i, c in enumerate(s):
    d = len(s_x)/2
    if cnt == int(d):
        cen = i+1
    if c == 'x':
        pass
    elif c != s_x[len(s_x)-cnt]:
        print(-1)
        break
    else:
        cnt += 1
        
else:
    a = s[:cen]
    for i in range(cen, len(s)):
        if s[i] == 'x':
            a += s[i]
        else:
            break
    b = s[cen:]
    b = b[::-1]
    ans = 0
    i, j = 0, 0
    while i < len(a)-1 or j < len(b)-1:
        if i >= len(a):
            i -= 1
        if j >= len(b):
            j -= 1
        if a[i] == b[j]:
            i += 1
            j += 1
        elif a[i] == 'x':
            i += 1
            ans += 1
        elif b[j] == 'x':
            j += 1
            ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import copy

s = input()
S = s.replace("x", "")
judge = 0

if len(s) == 1:
    judge = 5

if judge != 5:
    for i in range(len(S)):
        if S[i] != S[-(i+1)]:
            judge = 1
            break

s1 = []
for i in range(len(s)):
    s1.append(s[i])

ans = 0
s2 = copy.deepcopy(s1)
s2.reverse()
if judge == 0:
    i = 0
    while judge == 0:
        a = 1
        if s1[i] != s2[i]:
            if s1[i] == "x":
                a = 1
                for j in range(1, len(s1)):
                    if s1[i+j] == s2[i]:
                        break
                    a += 1
                for k in range(a):
                    s2.insert(i, "x")
                ans += a
            else:
                a = 1
                for j in range(1, len(s2)):
                    if s2[i+j] == s1[i]:
                        break
                    a += 1
                for k in range(a):
                    s1.insert(i, "x")
                ans += a
        i += a
        if i > max(len(s1), len(s2))/2:
            judge = 2


if judge == 2:
    print(ans)
elif judge == 5:
    print(0)
else:
    print(-1)

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:
    if int(len(kaibun)) % 2 == 1:
        print(int(len(a)) - int(len(kaibun)))
    else:
        print(int(len(a)) - int(len(kaibun)) + 1)

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:
    #もし回文の数が奇数なら、xの数は偶数
    if int(len(kaibun)) % 2 == 1:
        print(int(len(a)) - int(len(kaibun)))
    else:
        print(int(len(a)) - int(len(kaibun)) + 1)

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(-(target + 1), "x")
            ans += 1
            target += 1
        elif s_rev_list[target] == "x":
            s_list.insert(target, "x")
            s_rev_list.insert(-(target + 1), "x")
            ans += 1
            target += 1


    print(ans)

Submission status: Wrong Answer

Solution code:
def palindrome(str):
  return True if str == str[::-1] else False

str, count, i = input(), 0, 1

if not 'x' in str:
  print(-1)
  exit()

while not palindrome(str):
  check_str = str[0:i]

  if not palindrome(check_str):
    appended_check_str = check_str + 'x'
    returned_appended_check_str = 'x' + check_str

    if palindrome(appended_check_str) or palindrome(returned_appended_check_str):
      if palindrome(appended_check_str):
        str = appended_check_str + str[i:]
      elif palindrome(returned_appended_check_str):
        str = returned_appended_check_str + str[i:]
      count += 1

  i += 1

print(count)

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
        loop = 0
        while True:
            loop += 1
            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:
s = list(input())
i,j = 0,len(s)-1
flag = True
count=0

while(i<=j):
    print(i,j)
    if s[i]==s[j]:
        i+=1
        j-=1
        continue
    else:
        if s[i]=='x':
            s.insert(j+1,'x')
        elif s[j]=='x':
            s.insert(i,'x')
        else:
            flag = False
            break
        count+=1
        i+=1

print(count if flag else -1)

Submission status: Wrong Answer

Solution code:
s = input()
sList = []

for i in range(len(s)):
    sList.append(s[i])

while True:
    if 'x' in sList:
        sList.remove('x')
    else:
        break

end = 0
while True:
    if len(sList) == 0 or len(sList) == 1:
        print('Yes')
        break
    elif sList[0] != sList[-1]:
        print(-1)
        end = 1
        break
    else:
        del sList[-1]
        del sList[0]  

        
count = 0
F0 = 0
R0 = 0
if end == 0:
    sList2 = []
    sListF = []
    sListR = []
    
    for i in range(len(s)):
        sList2.append(s[i])
        sListF.append(s[i])
        sListR.append(s[-(i+1)])
        
    while True:
        if 'x' in sList2:
            sList2.remove('x')
        else:
            break
    
    
    if len(sList2)%2==0:
        number = len(sList2)//2
    else:
        number = (len(sList2)+1)//2
    
    for i in range(number):
        F = sListF.index(sList2[i])-F0
        R = sListR.index(sList2[i])-R0
        count += max([F, R])-min([F, R])
        F0 += F
        R0 += R


    
    print(count)

Submission status: Wrong Answer

Solution code:
s = input()
s_x = [i for i in s if 'x' not in i]

cnt = 1
a, b = ' ', ''
for c in s:
    if c == 'x':
        pass
    elif c != s_x[len(s_x)-cnt]:
        print(-1)
        break
    else:
        cnt += 1
    d = len(s_x)/2
    if cnt <= d+1:
        print(cnt)
        a += c
        if c == 'x' and cnt > d:
            b += c
    elif cnt > d:
        b += c
else:
    b = ' ' + b[::-1]
    ans = 0
    i, j = 0, 0
    while i < len(a)-1 or j < len(b)-1:
        if i >= len(a):
            i -= 1
        if j >= len(b):
            j -= 1
        if a[i] == b[j]:
            i += 1
            j += 1
        elif a[i] == 'x':
            i += 1
            ans += 1
        elif b[j] == 'x':
            j += 1
            ans += 1
    print(ans)

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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""code-fes-2017-qual-c-c"""


import sys

MID = ''

OP_NUM = 0

def solve(s):
    """Solve."""
    assert len(s) >= 0
    global OP_NUM
    global MID

    try:
        if len(s) == 0:
            return ""
        if len(s) == 1:
            MID = s
            return ""

        if s[0] == 'x':
            if s[-1] == 'x':
                return 'x' + solve(s[1:-1])
            OP_NUM += 1
            return 'x' + solve(s[1:])

        if s[0] == s[-1]:
            return s[0] + solve(s[1:-1])
        if 'x' == s[-1]:
            OP_NUM += 1
            return 'x' + solve(s[:-1])
    except:
        return None


def main():
    """Main function."""
    s = input()

    forward = solve(s)
    if forward is None:
        print(-1)
    else:
        print(OP_NUM)


if __name__ == '__main__':
    sys.exit(main())

Submission status: Wrong Answer

Solution code:
def readLine_int_list():return list(map(int, stdin.readline().split()))

from sys import stdin, stdout
import re

def main():
    s = [i for i in stdin.readline()]

    left = 0
    right = 0
    
    if len(s) == 1:
        print(0)
        
    else:
        
        f = True
        while f:
            if len(s) == 1:
                break
            else:
                while s[0]=='x' or s[-1]=='x':
                    if s[0] == 'x':
                        del s[0]
                        left += 1 
                    if s[-1] == 'x':
                        del s[-1]
                        right += 1
                        
                if s[0] != s[-1]:
                    f = False
                else:
                    if len(s)>1:
                        del s[0]
                        del s[-1]
                if len(s)<2:
                    break
       
    
        if f:
            if left-right == 0:
                print(left + right)
            elif left-right != 0:
                print(abs(left-right))
        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()]

    left = 0
    right = 0
    
    if len(s) == 1:
        print(0)
        
    else:
        
        f = True
        while f:
            if len(s) == 1:
                break
            else:
                while s[0]=='x' or s[-1]=='x' and len(s)>0:
                    if s[0] == 'x':
                        del s[0]
                        left += 1 
                    if s[-1] == 'x':
                        del s[-1]
                        right += 1
                        
                if s[0] != s[-1]:
                    f = False
                else:
                    if len(s)>1:
                        del s[0]
                        del s[-1]
       
    if f:
        if left-right == 0:
            print(left + right)
        elif left-right != 0:
            print(abs(left-right))
    else:
        print(-1)
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
xnum = s.count('x')
scopy = [item for item in s if item is not "x"]
if(scopy != scopy[::-1]):
    print(-1)
elif(scopy == scopy[::-1]):
    print(xnum)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = raw_input()


def split(string):
    mid = len(string) / 2
    if len(string) % 2:
        left = string[:mid]
        center = string[mid]
        right = (string[mid + 1:])[::-1]
    else:
        left = string[:mid]
        center = ''
        right = (string[mid:])[::-1]
    return left, center, right


def join(left, center, right):
    return left + center + right[::-1]


def check(string, count):
    left, center, right = split(string)

    # check done
    if left == right:
        return count

    # insert x
    for i in range(len(left)):
        if left[i] != right[i]:
            if left[i:].count('x') < right[i:].count('x'):
                left = 'x' + left
            else:
                right = 'x' + right
            break

    string = left + center + right[::-1]
    return check(string, count + 1)


# check char mismatch
left, center, right = split(S)
left_count = {c: left.count(c) for c in left}
right_count = {c: right.count(c) for c in right}
linr = sum(c not in right_count or v == right_count[c]
           for c, v in left_count.iteritems() if c != 'x')
rinl = sum(c not in left_count or v == left_count[c]
           for c, v in right_count.iteritems() if c != 'x')

if linr + rinl > 1:
    print -1
elif len(S) == 0:
    print 0
else:
    print check(S, 0)

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
xnum = s.count('x')
scopy = [i for i in s]
for i in range(xnum):
    scopy.remove('x')
if(scopy != scopy[::-1]):
    print(-1)
elif(scopy == scopy[::-1]):
    print(xnum)

Submission status: Wrong Answer

Solution code:
s = input()

if len(s) == 1:
  print(-1)
elif 'x' not in set(s) and len(s)>=2:
  print(-1)
else:
  print(s.count("x"))

Submission status: Wrong Answer

Solution code:
s = input()
s_x = [i for i in s if 'x' not in i]

cnt = 1
a, b = ' ', ''
for c in s:
    if cnt <= len(s_x)/2:
        a += c
    elif cnt >= len(s_x)/2:
        b += c
    if c == 'x':
        pass
    elif c != s_x[len(s_x)-cnt]:
        print(-1)
        break
    else:
        cnt += 1
else:
    b = ' ' + b[::-1]
    ans = 0
    i, j = 0, 0
    while i < len(a)-1 or j < len(b)-1:
        if i >= len(a):
            i -= 1
        if j >= len(b):
            j -= 1
        if a[i] == b[j]:
            i += 1
            j += 1
        elif a[i] == 'x':
            i += 1
            ans += 1
        elif b[j] == 'x':
            j += 1
            ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
s = []
roop = True
index = [0]
cnt = 0
for i in S:
    if not(i == "x"):
        s.append(i)
        index.append(0)
    else:
        index[-1] += 1
for i in range(len(s) // 2):
    if s[i] != s[-1]:
        roop = False
if roop:
    for i in range(len(index) // 2):
        if index[i] - index[- i - 1] >= 0:
            cnt += index[i] - index[- i - 1]
        else:
            cnt += index[- i - 1] - index[i]
    print(cnt)
else:
    print(-1)

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
        for i in range(len(x_list)//2):
            ans += abs(x_list[i]-x_list[-i-1])
            
        return ans
    
if cycle_check(s2,1):
    print(-1)

else:
    print(cycle_check(s, 2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = raw_input()


def check(string, count):
    mid = len(string) / 2
    if len(string) % 2:
        left = string[:mid]
        center = string[mid]
        right = (string[mid + 1:])[::-1]
    else:
        left = string[:mid]
        center = ''
        right = (string[mid:])[::-1]

    left_count = {c: left.count(c) for c in left}
    right_count = {c: right.count(c) for c in right}

    # check done
    if left_count == right_count:
        return count

    # check char mismatch
    linr = sum(c not in right_count or v == right_count[c]
               for c, v in left_count.iteritems() if c != 'x')
    rinl = sum(c not in left_count or v == left_count[c]
               for c, v in right_count.iteritems() if c != 'x')
    if linr + rinl > 1:
        return -1

    # insert x
    for i in range(len(left)):
        if left[i] != right[i]:
            if left[i:].count('x') < right[i:].count('x'):
                left = 'x' + left
            else:
                right = 'x' + right
            break

    string = left + center + right[::-1]
    return check(string, count + 1)


if len(S) == 0:
    print 0
else:
    print check(S, 0)

Submission status: Wrong Answer

Solution code:
s = input()

if len(s) == 1:
  print(-1)
else:
  print(s.count("x"))

Submission status: Wrong Answer

Solution code:
import string

S = input()

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

find_odd = False
index = -1
for a in string.ascii_lowercase:
    if a == 'x':
        continue
    if S.count(a) % 2:
        if find_odd:
            print(-1)
            exit()
        else:
            find_odd = True
            index = S.find(a)
ret = 0
N = len(S)

if find_odd:
    l = index - 1
    r = index + 1
else:
    l = N // 2 - 1
    r = N // 2 + 1
while l >= 0 or r < N:
    if l < 0:
        if S[r] == 'x':
            ret += 1
    elif r >= N:
        if S[l] == 'x':
            ret += 1
    elif (S[r] == 'x' and S[l] != 'x') or (S[r] != 'x' and S[l] == 'x'):
        ret += 1
    l += -1
    r += +1

print(ret)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = raw_input()


def check(string, count):
    mid = len(string) / 2
    if len(string) % 2:
        left = string[:mid]
        center = string[mid]
        right = (string[mid + 1:])[::-1]
    else:
        left = string[:mid]
        center = ''
        right = (string[mid:])[::-1]

    left_count = {c: left.count(c) for c in left}
    right_count = {c: right.count(c) for c in right}

    # check done
    if left_count == right_count:
        return count

    # check char mismatch
    linr = sum(c not in right_count for c in left_count if c != 'x')
    rinl = sum(c not in left_count for c in right_count if c != 'x')
    if linr + rinl > 1:
        return -1

    # insert x
    for i in range(len(left)):
        if left[i] != right[i]:
            if left[i:].count('x') < right[i:].count('x'):
                left = 'x' + left
            else:
                right = 'x' + right
            break

    string = left + center + right[::-1]
    return check(string, count + 1)


if len(S) == 0:
    print 0
else:
    print check(S, 0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct  9 22:12:40 2017

@author: kitagenbakurou
"""
import numpy as np
import copy

def insert(pos, s, x):
  return x.join([s[:pos], s[pos:] ])

s = input()
N = len(s)

i = 0
cnt = 0
flag = True
while i < N - i - 1 : 
    if s[i] != s[N - i - 1] : 
        if s[i] == "x" : 
            cnt += 1
            s = insert(N - i  , s , "x")
            i = -1
        elif s[N - i - 1] == "x" : 
            cnt += 1
            s = insert(i , s , "x")
            i = -1
        else : 
            flag = False
            break
    N = len(s)
    i += 1

print(s)
if flag : 
    print(cnt)
else : 
    print(-1)

Submission status: Wrong Answer

Solution code:
import string

S = input()

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

find_odd = False
index = -1
for a in string.ascii_lowercase:
    if a == 'x':
        continue
    if S.count(a) % 2:
        if find_odd:
            print(-1)
            exit()
        else:
            find_odd = True
            index = S.find(a)
ret = 0
l = index - 1
r = index + 1
N = len(S)
while l >= 0 or r < N:
    if l < 0:
        if S[r] == 'x':
            ret += 1
    elif r >= N:
        if S[l] == 'x':
            ret += 1
    elif (S[r] == 'x' and S[l] != 'x') or (S[r] != 'x' and S[l] == 'x'):
        ret += 1
    l += -1
    r += +1

print(ret)

Submission status: Wrong Answer

Solution code:
def insert_c(s, idx, c):
    return s[:idx] + c + s[idx:]


def calc(s):
    if s == s[::-1]:
        return 0
    if s.replace('x', '') != s.replace('x', '')[::-1]:
        return -1
    # import ipdb;ipdb.set_trace()
    revs = s[::-1]
    cnt = 0
    o_gap, r_gap = 0, 0
    idx = 0
    while idx + o_gap <= len(s) / 2 and idx + r_gap <= len(s) / 2:
        # print(cnt, o_gap, r_gap, idx)
        # print(s[idx + o_gap], revs[idx + r_gap])
        if s[idx + o_gap] != revs[idx + r_gap]:
            # print(s[idx + o_gap], revs[idx + r_gap])
            if s[idx + o_gap] == 'x':
                cnt += 1
                revs = insert_c(revs, idx, 'x')
                # r_gap -= 1
            elif revs[idx + r_gap] == 'x':
                cnt += 1
                s = insert_c(s, idx, 'x')
                # o_gap -= 1
        idx += 1
    return cnt


def main():
    s = input()
    print(calc(s))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
s = []
roop = True
index = 0
index_array = []
cnt = 0
for i in S:
    if not(i == "x"):
        s.append(i)
        index += 1
    else:
        index_array.append(index)
for i in range(len(s) // 2):
    if s[i] != s[-1]:
        roop = False
if roop:
    while len(index_array) > 0:
        for j in range(len(index_array)):
            if len(s) - index_array[0] == index_array[j]:
                if j != 0:
                    del index_array[j], index_array[0]
                else:
                    del index_array[0]
                break
        else:
            del index_array[0]
            cnt += 1
    print(cnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
i = 0
j = len(s)-1
ist = 0

while i < j:
    if s[i] == s[j]:
        i += 1
        j -= 1
        print("i="+str(i))
        print("j="+str(j))
    elif s[i] == 'x':
        ist += 1
        i += 1
        print("i="+str(i))
        print("j="+str(j))
    elif s[j] == 'x':
        ist += 1
        j -= 1
        print("i="+str(i))
        print("j="+str(j))
    else:
        print(-1)
        exit()

print(ist)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

s = list(input())
s_rem = list(s)

rem_num = 0
for i in range(len(s)):
    if(s[i] == "x"):
        rem_num += 1

for i in range(rem_num):
    s_rem.remove("x")

output = 0
length = len(s_rem)
for i in range(length//2):
    if(s_rem[i] != s_rem[length - 1 - i]):
        output = -1
        break

i = 0
j = len(s) - 1

while(i < j):
    if(s[i] == 'x'):
        if(s[j] == 'x'):
            i += 1
            j += -1
        else:
            i += 1
            output += 1
    else:
        if(s[j] == 'x'):
            j += -1
            output += 1
        else:
            i += 1
            j += -1

print(output)

Submission status: Wrong Answer

Solution code:
s = raw_input()
sx = s.replace("x","")
l = len(sx)

if len(s) == 1:
  print 0
  exit(0)
if l % 2 == 0:
    if sx[0:l/2] != sx[l/2:][::-1]:
      #print sx[0:l/2] , sx[l/2:][::-1]
      print "-1"
      exit(0)
    # here we go.
    count = 0
    sx_1 = sx[0:l/2]
    sx_2 = sx[l/2:][::-1]
    p1 = 0
    p2 = 0
    for a in range(l/2):
      prevp1 = p1
      prevp2 = p2
      while sx_1[a] != s[p1]:
        p1 += 1
      while sx_2[a] != s[ len(s) - 1 - p2]:
        p2 += 1
      count += abs((p1-prevp1)-(p2-prevp2))
    print count
else:
    if sx[0:l/2] != sx[l/2+1:][::-1]:
      #print sx[0:l/2] , sx[l/2+1:][::-1]
      print "-1"
      exit(0)
    # here we go.
    count = 0
    sx_1 = sx[0:l/2]
    sx_2 = sx[l/2+1:][::-1]
    p1 = 0
    p2 = 0
    for a in range(l/2):
      prevp1 = p1
      prevp2 = p2
      while sx_1[a] != s[p1]:
        p1 += 1
      while sx_2[a] != s[ len(s) - 1 - p2]:
        p2 += 1
      count += abs((p1-prevp1)-(p2-prevp2))

    prevp1 = p1
    prevp2 = p2
    while sx[l/2] != s[p1]:
      p1 += 1
    while sx[l/2] != s[len(s) - 1 - p2]:
      p2 += 1
    count += abs((p1-prevp1)-(p2-prevp2))
    print count

Submission status: Wrong Answer

Solution code:
def calc(s):
    if s == s[::-1]:
        return 0
    if s.replace('x', '') != s.replace('x', '')[::-1]:
        return -1
    # import ipdb;ipdb.set_trace()
    revs = s[::-1]
    cnt = 0
    o_gap, r_gap = 0, 0
    idx = 0
    while idx + o_gap <= len(s) / 2 and idx + r_gap <= len(s) / 2:
        # print(cnt, o_gap, r_gap, idx)
        # print(s[idx + o_gap], revs[idx + r_gap])
        if s[idx + o_gap] != revs[idx + r_gap]:
            # print(s[idx + o_gap], revs[idx + r_gap])
            if s[idx + o_gap] == 'x':
                cnt += 1
                r_gap -= 1
            elif revs[idx + r_gap] == 'x':
                cnt += 1
                o_gap -= 1
        idx += 1
    return cnt


def main():
    s = input()
    print(calc(s))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

s=list(input())


l=0
r=len(s)-1

count=0
while True:
    #print(s,l,r)
    if s[l]!=s[r]:
        if s[l]=="x":
            #s.insert(r+1,"x")
            l+=1
        elif s[r]=="x":
            #s.insert(l,"x")
            r-=1
            l+=1
        else:
            res=-1
            break

        #print(s,l,r)


        count+=1
    else:
        r-=1
        l+=1

    if l>=r:
        res=count
        break


print(res)

Submission status: Wrong Answer

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))


s = input()
ans = 0
s_nox = s.replace('x', '')
if(s_nox != s_nox[::-1]): ans = -1
else:
    need = (len(s_nox)+1) // 2
    s = list(s)
    s_rev = s[::-1]
    si = 0
    srevi = 0
    si_tmp = -1
    srevi_tmp = -1
    for i in range(need):        
        si_tmp = 0
        srevi_tmp = 0
        while(s[si] == 'x'):
            si += 1
            si_tmp += 1
        while(s_rev[srevi] == 'x'):
            srevi += 1
            srevi_tmp += 1
        print(s[si], ans)
        ans += abs(si_tmp - srevi_tmp)
        si += 1
        srevi += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = raw_input()

replaced = s.replace('x', '')
l = len(replaced)
halfl = int(l / 2)

if l > 1 and replaced[:halfl] != replaced[-halfl:]:
  print "-1"
  exit()

xset = {}
i = 0
for c in s:
  if c == 'x':
    d = min(i, l-i)
    if i != l-i:
      xset[d] = xset.get(d, 0) + [-1, 1][i < l-i]
  else:
    i += 1

ans = 0
for v in xset.itervalues():
  ans += abs(v)
print ans

Submission status: Wrong Answer

Solution code:
s = raw_input()

def precheck():
    res = ""
    for c in s:
        if c != "x":
            res += c
    
    
    if res != "".join(reversed(res)):
        return 0
    return res



def calc(ns):
    lf = ""
    rf = ""
    
    vtype = len(ns) % 2

    pos = 0

    cnt = 0
    while cnt < len(ns)/2:
        lf += s[pos]
        if s[pos] == "x":
            pass
        else:
            cnt+=1
        pos+=1
    
    if vtype:
        while s[pos] == "x":
            lf += s[pos]
            pos+=1
        pos+=1
    else:
         while s[pos] == "x":
            pos+=1

   

    rf = "".join(reversed(s[pos:]))


    lx = 0
    rx = 0

    res = 0
    while 1:

        if lx >= len(lf):
            res += len(rf)-rx
            break
        if rx >= len(rf):
            res += len(lf)-lx
            break

        rrr = rf[rx] == "x"
        lll = lf[lx] == "x"

        if rrr and lll:
            rx+=1
            lx+=1
        elif rrr and not lll:
            rx += 1
            res += 1
        elif not rrr and lll:
            lx += 1
            res += 1
        else:
            rx += 1
            lx += 1
    return res

pc = precheck()
if not pc:
    print -1
else:
    print calc(pc)