Problem p03069 (python)

Fixed submission:
import sys
from itertools import accumulate
N = int(input())
S = input()

if S == '.'*N or S == '#'*N:
    print(0)
    sys.exit()

ind1 = 0
for i, x in enumerate(S):
    if x == '#':
        ind1 = i
        break
num = 0
for i, x in enumerate(S[::-1]):
    if x == '.':
        num = i
        break
ind2 = N - num
s = S[ind1:ind2]
if len(s) == 0:
    print(0)
    sys.exit()

a = s.split('.')
b = s.split('#')
aa = []
bb = []
for x in a:
    if len(x) != 0:
        aa.append(len(x))
for x in b:
    if len(x) != 0:
        bb.append(len(x))
c = [0] + list(accumulate(aa))
d = [0] + list(accumulate(bb))
ls = []
for i in range(len(c)):
    ls.append(c[i] + d[-1] - d[i])
print(min(ls))

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
    sys.exit()
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
    ind2 = N - num
    s = S[ind1:ind2]
    if len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
    sys.exit()
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    ind2 = N - num
    if ind1 > ind2:
        print(0)
        sys.exit()
    s = S[ind1:ind2]
    if s[0] == '.' or s[-1] == '#' or len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    ind2 = N - num
    if ind1 > ind2:
        print(0)
        sys.exit()
    s = S[ind1:ind2]
    if s[0] == '.' or s[-1] == '#' or len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    ind2 = N - num
    s = S[ind1:ind2]
    if s[0] == '.' or s[-1] == '#' or len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
    ind2 = N - num
    s = S[ind1:ind2]
    if s[0] == '.' or s[-1] == '#' or len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
N = int(input())
S = input()
ind1 = 0
for i, x in enumerate(S):
    if x == '#':
        ind1 = i
        break
num = 0
for i, x in enumerate(S[::-1]):
    if x == '.':
        num = i
        break
ind2 = N - num
s = S[ind1:ind2]
if s[0] == '.' or s[-1] == '#' or len(s) == 0:
    print(0)
else:
    a = s.split('.')
    b = s.split('#')
    aa = []
    bb = []
    for x, y in zip(a, b):
        if len(x) != 0:
            aa.append(len(x))
        if len(y) != 0:
            bb.append(len(y))
    d = [0] + list(accumulate(aa))
    e = [0] + list(accumulate(bb))
    p = d[-1]
    ls = []
    for i in range(min(len(d), len(e))):
        ls.append(e[i]+p-d[i])
    print(min(ls))

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
S = input()
ans = S.count('.')
num = 0
for x in S:
    if x == '#':
        break
    else:
        num += 1
print(min(ans-num, S.count('#'))