qyliang/CodeNanoFix huggingface dataset:
Buggy code:
s = list(input())
s1=s[::-1]
ans = 0
cnt = 0
cnt1 = 0
while cnt<len(s) and cnt1<len(s) and cnt!=len(s)-1-cnt1:
  #print(s[cnt],s1[cnt1])
  if s[cnt]!=s1[cnt1]:
    if s[cnt]=="x" and s1[cnt1]!="x":
      cnt+=1
      ans+=1
    if s1[cnt1]=="x" and s[cnt]!="x":
      cnt1+=1
      ans+=1
    if s1[cnt1]=="x" and s[cnt]=="x":
      cnt+=1
      cnt1+=1
    if s[cnt]!="x" and s1[cnt1]!="x":
      print(-1)
      exit()
  elif s[cnt]==s1[cnt1]:
    cnt+=1
    cnt1+=1
print(ans)


Fixed code:
s = list(input())
s1=s[::-1]
ans = 0
cnt = 0
cnt1 = 0
while cnt<len(s) and cnt1<len(s) and cnt<=len(s)-1-cnt1:
  if s[cnt]!=s1[cnt1]:
    if s[cnt]=="x" and s1[cnt1]!="x":
      cnt+=1
      ans+=1
    elif s1[cnt1]=="x" and s[cnt]!="x":
      cnt1+=1
      ans+=1
    elif s[cnt]!="x" and s1[cnt1]!="x":
      print(-1)
      exit()
  elif s[cnt]==s1[cnt1]:
    cnt+=1
    cnt1+=1
print(ans)
Buggy code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  i_f=0
  i_b=len(s)-1

  ans=0
  while True:
    if i_f>=i_b:
      return ans

    print(i_f,i_b)
    if s[i_f]==s[i_b]:
      i_f+=1
      i_b-=1
    else:
      if s[i_f]=='x':
        i_f+=1
        ans+=1
      elif s[i_b]=='x':
        i_b-=1
        ans+=1
      else:
        return -1

# main()
print(main())


Fixed code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  i_f=0
  i_b=len(s)-1

  ans=0
  while True:
    if i_f>=i_b:
      return ans

    # print(i_f,i_b)
    if s[i_f]==s[i_b]:
      i_f+=1
      i_b-=1
    else:
      if s[i_f]=='x':
        i_f+=1
        ans+=1
      elif s[i_b]=='x':
        i_b-=1
        ans+=1
      else:
        return -1

# main()
print(main())
Buggy code:
s = input()
n = len(s)
t = s.replace("x","")
if not t:
  print(0)
  exit()
l = len(t)
if t != t[::-1]:
  print(-1)
  exit()
plc = [-1]
for i in range(n):
  if s[i] != x:
    plc.append(i)
plc.append(n)
l = len(plc)
if l%2 == 0:
  fm = plc[:l//2]
  lt = plc[l//2:]
else:
  fm = plc[l//2+1]
  lt = plc[l//2:]
lt = lt[::-1]
ans = 0
for i in range(1,len(fm)):
  ans += abs((fm[i]-fm[i-1])-(lt[i]-lt[i-1]))
print(ans)
  

Fixed code:
s = input()
n = len(s)
t = s.replace("x","")
if not t:
  print(0)
  exit()
l = len(t)
if t != t[::-1]:
  print(-1)
  exit()
plc = [-1]
for i in range(n):
  if s[i] != "x":
    plc.append(i)
plc.append(n)
l = len(plc)
if l%2 == 0:
  fm = plc[:l//2]
  lt = plc[l//2:]
else:
  fm = plc[:l//2+1]
  lt = plc[l//2:]
lt = lt[::-1]
ans = 0
for i in range(1,len(fm)):
  ans += abs((fm[i]-fm[i-1])-(lt[i-1]-lt[i]))
print(ans)
Buggy code:
s=input()
s_exit_x=''
ans = 0
for n,i in enumerate(s):
    if i !='x':
        s_exit_x += i
if s_exit_x != s_exit_x[::-1]:
    print(-1)
else:
    left=0
    right=len(s)-1
    while left < right:
        if s[left] == s[right]:
            left += 1
            right -=1
        elif s[left]=="x":
            left += 1
            ans += 1
        else:
            right -=1
            ans += 1
print(ans)

Fixed code:
s=input()
s_exit_x=''
ans = 0
for n,i in enumerate(s):
    if i !='x':
        s_exit_x += i
if s_exit_x != s_exit_x[::-1]:
    print(-1)
else:
    left=0
    right=len(s)-1
    while left < right:
        if s[left] == s[right]:
            left += 1
            right -=1
        elif s[left]=="x":
            left += 1
            ans += 1
        else:
            right -=1
            ans += 1
    print(ans)
Buggy code:
import sys
s=input()
ans=0
i=0
j=len(s)-1
xi=0
yj=0
while(i<j):

    while(s[i]=='x'):
        i+=1
        xi+=1
        print(i,xi)

    while(s[j]=='x'):
        j-=1
        yj+=1
        print(j,yj)

    print(i,xi,j,yj)
    if(s[i]!=s[j]):
        print(-1)
        sys.exit()
    else:
        ans+=abs(xi-yj)
        xi=0
        yj=0
        i+=1
        j-=1

print(ans)

Fixed code:
import sys
s=input()
ans=0
i=0
j=len(s)-1
xi=0
yj=0
while(i<j):

    while(i<len(s)-1 and s[i]=='x'):
        i+=1
        xi+=1
#        print(i,xi)

    while(j>0 and s[j]=='x'):
        j-=1
        yj+=1
#        print(j,yj)

#    print(i,xi,j,yj)
    if(s[i]!=s[j]):
        print(-1)
        sys.exit()
    else:
        ans+=abs(xi-yj)
        xi=0
        yj=0
        i+=1
        j-=1

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


Fixed code:
from collections import deque
S = input()
q = deque(S)
c = 0
while len(q):
  l = q[0]
  r = q[len(q)-1]
  if l == r:
    if len(q) != 1:
      q.pop()
    q.popleft()
  elif l == 'x':
    q.append('x')
    c += 1
  elif r == 'x':
    q.appendleft('x')
    c += 1
  else:
    print(-1)
    exit()
print(c)
Buggy code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, W, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
S = input().strip()

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

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

print(c)

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

# N, W, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
S = input().strip()

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

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

print(c)
Buggy code:
s = input()
ans = 0
while s:
  if s[0] == s[-1]:
    s = s[1:-2]
  else:
    if s[0] == "x":
      ans += 1
      s = s[1:]
    elif s[-1] == "x":
      ans += 1
      s = s[:-1]
    else:
      print(-1)
      exit()
print(ans)

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

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

Fixed code:
s = input()
cnt = 0
while len(s) > 0:
    if s[0] == s[-1]:
        s = s[1:-1]
    else:
        if s[0] == "x":
            cnt += 1
            s = s[1:]
        elif s[-1] == "x":
            cnt += 1
            s = s[:-1]
        else:
            cnt = -1
            break
print(cnt)
Buggy code:
s = input()
t = s.replace('x', '')

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

Fixed code:
s = input()
t = s.replace('x', '')

if t != t[::-1] :
    print(-1)
    
else :
    sp = []
    cnt = 0
    for i in s :
        if i != 'x' :
            sp.append(cnt)
            cnt = 0
        else :
            cnt += 1
    
    sp.append(cnt)
    
    ret = 0
    n = len(sp)
    for i in range(n // 2) :
        ret += abs(sp[i] - sp[n-1-i])
        
    print(ret)
Buggy code:
#inserting X
s=input()
length=len(s)
string=""
for i in range(length):
    if s[i]!="x":
        string=string+s[i]
    else:
        continue
print(string)

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

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


flag=True
length2=len(string)
if length2>=2:
    for i in range(length2//2):
        if string[i]!=string[-(i+1)]:
            flag=False
            break
if flag:
    s="x"+s+"X"
    length=len(s)
    checklist=[]
    count=0
    for i in range(length):
        if s[i]=="x":
            count+=1
        else:
            checklist.append(count)
            count=0
    checklist[0]-=1
    ans=0
    for i in range(len(checklist)//2):
        ans+=abs(checklist[i]-checklist[-(i+1)])
    print(ans)
    
else:
    print("-1")
Buggy code:
S = list(input())
invS = []
for s in reversed(S):
    invS.append(s)
cnt = 0
loop = 0
i,j = 0,0
while i <= len(S)-1 and j <= len(S)-1:
    if S[i] == invS[j]:
        i += 1
        j += 1
    elif S[i] == "x":
        cnt += 1
        i += 1
    elif invS[j] == "x":
        cnt += 1
        j += 1
    else:
        cnt = -1
        break
print(cnt)


Fixed code:
S = list(input())
invS = []
for s in reversed(S):
    invS.append(s)
cnt = 0
loop = 0
i,j = 0,0
while i+j < len(S)-1 and i <= len(S)-1 and j <= len(S)-1 :
    if S[i] == invS[j]:
        i += 1
        j += 1
    elif S[i] == "x":
        cnt += 1
        i += 1
    elif invS[j] == "x":
        cnt += 1
        j += 1
    else:
        cnt = -1
        break
print(cnt)
Buggy code:
s = input()
left = 0
right = len(s) - 1
x_left = 0
x_right = 0
if len(s) > 2:
    while (left <= right):
        if s[left] == s[right]:
            left += 1
            right -= 1
        elif s[left] == "x":
            x_left += 1
            left += 1
        elif s[right] == "x":
            x_right += 1
            right -= 1
        if (right - left == 1) & (s[left] != s[right]):
            if (s[left] != "x") & (s[right] != "x"):
                print(-1)
                exit()
    print(x_left + x_right)
else:
    print(0)           

Fixed code:
s = input()
left = 0
right = len(s) - 1
x_left = 0
x_right = 0
if len(s) >= 2:
    while (left <= right):
        if s[left] == s[right]:
            left += 1
            right -= 1
        elif s[left] == "x":
            x_left += 1
            left += 1
        elif s[right] == "x":
            x_right += 1
            right -= 1
        else:
            print(-1)
            exit()
    print(x_left + x_right)
else:
    print(0)
Buggy 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)
        temp=0
    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])

    print(count)

Fixed 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)
        temp=0
    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)-1-i])

    print(count)
Buggy code:
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 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:
    print(left,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)

Fixed code:
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)
Buggy code:
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)

Fixed code:
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)
Buggy code:
from collections import deque
s = deque(input())
print(s)
le = len(s)
cnt = 0
while le:
  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
  print(s)
else:
  print(cnt)


Fixed code:
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)
Buggy code:
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

print(ans)


Fixed code:
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)
Buggy 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


Fixed code:
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)
# https://img.atcoder.jp/code-festival-2017-qualc/editorial.pdf
Buggy 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)

Fixed 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[:-1]
  else:
    print(-1)
    sys.exit()
print(ans)
Buggy code:
s=input()
l=0
r=len(s)-1
x=0
while l<r:
  if s[l]==s[r]:
    l+=1
    r-=1
  elif s[l]=='x':
    x+=1
    l+=1
  elif s[l]=='x':
    x+=1
    r-=1
  else:
    x=-1
    break
print(x)

Fixed code:
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)
Buggy 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)

Fixed 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]
    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)
Buggy 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)

Fixed code:
s = input()
ans = 0
p = 0
q = len(s) - 1
while p < q:
	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)
Buggy code:
s = input()
len_s = len(s)
l_index = 0
r_index = s - 1
counter = 0
while l_index < r_index:
    if s[l_index] == s[r_index]:
        l_index += 1
        r_index -= 1
    elif s[l_index] == "x":
        counter += 1
        l_index += 1
    elif s[r_index] == "x":
        counter += 1
        r_index -=1
    else:
        counter = -1
        break
print(counter)

Fixed code:
s = input()
len_s = len(s)
l_index = 0
r_index = len_s - 1
counter = 0
while l_index < r_index:
    if s[l_index] == s[r_index]:
        l_index += 1
        r_index -= 1
    elif s[l_index] == "x":
        counter += 1
        l_index += 1
    elif s[r_index] == "x":
        counter += 1
        r_index -=1
    else:
        counter = -1
        break
print(counter)
Buggy 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)

Fixed 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
j = N - 1
cnt = 0
flag = True
while i < j : 
    if s[i] != s[j] : 
        if s[i] == "x" : 
            cnt += 1
            #s = insert(N - i  , s , "x")
            i += 1
            j += 0
        elif s[j] == "x" : 
            cnt += 1
            #s = insert(i , s , "x")
            i +=0
            j -= 1
        else : 
            flag = False
            break
    else : 
        i += 1
        j -= 1

if flag : 
    print(cnt)
else : 
    print(-1)
Buggy 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)



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

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

print(ist)
Buggy 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)


Fixed 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)