Problem p03480 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=list(map(int,list(input())))
    N=len(S)
    if N%2==0:
        left=N//2-1
        right=N//2
        ans=N//2
        if S[left]==S[right]:
            x=S[left]
            while left-1>=0 and S[left-1]==x:
                left-=1
            while right+1<N and S[right+1]==x:
                right+=1
            ans+=min(N//2-left,right-N//2+1)
    else:
        left=N//2
        right=N//2
        x=S[N//2]
        ans=N//2+1
        if left-1>=0 and S[left-1]==x:
            while left-1>=0 and S[left-1]==x:
                left-=1
        if right+1<N and S[right+1]==x:
            while right+1<N and S[right+1]==x:
                right+=1
        ans+=min(N//2-left,right-N//2)
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=list(map(int,list(input())))
    if len(S)%2==0:
        left=len(S)//2-1
        right=len(S)//2
        ans=len(S)//2
        if S[left]==S[right]:
            x=S[left]
            while left>=0 and right<len(S) and S[left]==S[right]==x:
                left-=1
                right+=1
                ans+=1
            if left>=0 and right<len(S) and S[left]!=x or S[right]!=x:
                ans-=1
    else:
        left=len(S)//2-1
        right=len(S)//2+1
        ans=len(S)//2+1
        x=S[len(S)//2]
        if left>=0 and right<len(S) and S[left]==S[right]==x:
            ans+=1
            while left>=0 and right<len(S) and S[left]==S[right]==x:
                left-=1
                right+=1
                ans+=1
            if left>=0 and right<len(S) and S[left]!=x or S[right]!=x:
                ans-=1
        elif left>=0 and right<len(S) and S[left]==x or S[right]==x:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=list(map(int,list(input())))
    if len(S)%2==0:
        left=len(S)//2-1
        right=len(S)//2
        ans=len(S)//2
        if S[left]==S[right]:
            x=S[left]
            while left>=0 and right<len(S) and S[left]==S[right]==x:
                left-=1
                right+=1
                ans+=1
            if left>=0 and right<len(S) and S[left]!=x or S[right]!=x:
                ans-=1
    else:
        left=len(S)//2-1
        right=len(S)//2+1
        ans=len(S)//2+1
        x=S[len(S)//2]
        if left>=0 and right<len(S) and S[left]==S[right]==x:
            ans+=1
            while left>=0 and right<len(S) and S[left]==S[right]==x:
                left-=1
                right+=1
                ans+=1
            if S[left]!=x or S[right]!=x:
                ans-=1
        elif left>=0 and right<len(S) and S[left]==x or S[right]==x:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=list(map(int,list(input())))
    if len(S)%2==0:
        left=len(S)//2-1
        right=len(S)//2
        ans=len(S)//2
        if S[left]==S[right]:
            x=S[left]
            while S[left]==S[right]==x and left>=0 and right<len(S):
                left-=1
                right+=1
                ans+=1
            if left>=0 and right<len(S) and S[left]!=x or S[right]!=x:
                ans-=1
    else:
        left=len(S)//2-1
        right=len(S)//2+1
        ans=len(S)//2+1
        x=S[len(S)//2]
        if left>=0 and right<len(S) and S[left]==S[right]==x:
            ans+=1
            while S[left]==S[right]==x and left>=0 and right<len(S):
                left-=1
                right+=1
                ans+=1
            if S[left]!=x or S[right]!=x:
                ans-=1
        elif left>=0 and right<len(S) and S[left]==x or S[right]==x:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=list(map(int,list(input())))
    if len(S)%2==0:
        left=len(S)//2-1
        right=len(S)//2
        ans=len(S)//2
        if S[left]==S[right]:
            x=S[left]
            while S[left]==S[right]==x and left>=0 and right<len(S):
                left-=1
                right+=1
                ans+=1
            if S[left]!=x or S[right]!=x:
                ans-=1
    else:
        left=len(S)//2-1
        right=len(S)//2+1
        ans=len(S)//2+1
        x=S[len(S)//2]
        if S[left]==S[right]==x:
            ans+=1
            while S[left]==S[right]==x and left>=0 and right<len(S):
                left-=1
                right+=1
                ans+=1
            if S[left]!=x or S[right]!=x:
                ans-=1
        elif S[left]==x or S[right]==x:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()