Problem p03073 (python)

Fixed submission:
Tiles=input()
N_len=len(Tiles)
if N_len == 1:
    print("0")
    exit()
    
cur=Tiles[0]

change=0
for i in range(1, N_len):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change+=1

        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]

    #print("new cur={}".format(cur))

min_change = change


change_first=1
if Tiles[0] == "0":
    cur = "1"
else:
    cur = "0"

for i in range(1, N_len):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change_first+=1
        if min_change <= change_first:
            break

        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]
        
if min_change > change_first:
    min_change = change_first

        
change_reverse=0
cur=Tiles[N_len-1]
for i in reversed(range(0, N_len-1)):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change_reverse+=1
        if min_change <= change_reverse:
            break


        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]

    #print("new cur={}".format(cur))
    
if min_change > change_reverse:
    min_change = change_reverse


change_reverse_first=1
if Tiles[N_len-1] == "0":
    cur = "1"
else:
    cur = "0"

for i in reversed(range(0, N_len-1)):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change_reverse_first+=1
        if min_change <= change_reverse_first:
            break

        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]

if min_change > change_reverse_first:
    min_change = change_reverse_first

print(str(min_change))

Buggy submission (verdict: Runtime Error):
Tiles=input()
N_len=len(Tiles)
if N_len == 1:
    print("0")
    return
    
cur=Tiles[0]

change=0
for i in range(1, N_len):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change+=1

        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]

    #print("new cur={}".format(cur))

min_change = change


change_first=1
if Tiles[0] == "0":
    cur = "1"
else:
    cur = "0"

for i in range(1, N_len):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change_first+=1
        if min_change <= change_first:
            break

        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]
        
if min_change > change_first:
    min_change = change_first

        
change_reverse=0
cur=Tiles[N_len-1]
for i in reversed(range(0, N_len-1)):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change_reverse+=1
        if min_change <= change_reverse:
            break


        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]

    #print("new cur={}".format(cur))
    
if min_change > change_reverse:
    min_change = change_reverse


change_reverse_first=1
if Tiles[N_len-1] == "0":
    cur = "1"
else:
    cur = "0"

for i in reversed(range(0, N_len-1)):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change_reverse_first+=1
        if min_change <= change_reverse_first:
            break

        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]

if min_change > change_reverse_first:
    min_change = change_reverse_first
    
print(min_change)

Buggy submission (verdict: Runtime Error):
Tiles=input()
N_len=len(Tiles)
if N_len == 1:
    print("0")
    exit
    
cur=Tiles[0]

change=0
for i in range(1, N_len):
    if cur is TilePuttern[i]:
        change+=1
        cur = "0" if Tiles[i] == 0 else "1"
    else:
        cur=Tiles[i]
        
change_reverse=0
cur=Tiles[N_len-1]
for i in reversed(range(1, N_len-1)):
    if cur is TilePuttern[i]:
        change_reverse+=1
        cur = "0" if Tiles[i] == 0 else "1"
    else:
        cur=Tiles[i]

print(change if change < change_reverse else change_reverse)