Buggy python submission (verdict: Time Limit Exceeded):
n=int(raw_input())
s=raw_input()
ret=n
for i in range(n+1):
    head=s[:i]
    tail=s[i:]
    temp=head.count("#")+tail.count(".")
    if temp<ret:
        ret=temp
    if temp==0:
        ret=0
        break
print(ret)


Fixed submission:
n=int(raw_input())
s=raw_input()

temp=s.count("#")
if temp==0 or temp==n:
    print(0)
else:
    head=0
    tail=n-temp
    ret=tail+head
    for c in s:
        if c=="#":
            head+=1
        else:
            tail-=1
        temp2=head+tail
        if temp2<ret:
            ret=temp2
    print(ret)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
preans = 0
pew = 0
bflag = 0
b2w = 0
for i, word in enumerate(s):
    if bflag == 0:
        if word == '#':
            bflag = 1
    else:
        if word == '.':
            b2w = 1
    if b2w == 1:
        if word == '.':
            preans += 1
skip = 1
ans2 = 0
wcount = 0
bcount = 0
for i, word in enumerate(s):
    if b2w > skip:
        ans = min(preans, preans + bcount - wcount)
        preans = preans + bcount - wcount
        skip += 1
        wcount = 0
        bcount = 0

    if word == '#':
        bcount += 1

    if bflag == 0:
        if word == '#':
            bflag = 1
    else:
        if word == '.':
            b2w += 1
            bflag = 0

    if b2w == skip and word == '.':
        wcount += 1
print(ans)


Fixed submission:
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
bcount = 0
wcount = 0
for word in s:
    if word == '.':
        wcount += 1
ans = wcount
preans = ans
for word in s:
    if word == '#':
        preans += 1
    else:
        preans -= 1
    ans = min(ans, preans)
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
preans = 0
pew = 0
bflag = 0
b2w = 0
for i, word in enumerate(s):
    if bflag == 0:
        if word == '#':
            bflag = 1
    else:
        if word == '.':
            b2w = 1
    if b2w == 1:
        if word == '.':
            preans += 1
skip = 1
ans2 = 0
for i, word in enumerate(s):
    if b2w > skip:
        ans = min(preans, preans + bcount - wcount)
        preans = preans + bcount - wcount
        skip += 1
        wcount = 0
        bcount = 0

    if word == '#':
        bcount += 1

    if bflag == 0:
        if word == '#':
            bflag = 1
        else:
    else:
        if word == '#':
        else:
            b2w += 1
            bflag = 0

    if b2w == skip and word == '.':
        wcount += 1
print(ans)


Fixed submission:
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
bcount = 0
wcount = 0
for word in s:
    if word == '.':
        wcount += 1
ans = wcount
preans = ans
for word in s:
    if word == '#':
        preans += 1
    else:
        preans -= 1
    ans = min(ans, preans)
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
ans = 0
bflag = 0
for i, st in enumerate(s):
    if bflag == 1:
        if st == '.':
            ans += 1
        else:
            bflag = 0
    else:
        if st == '#':
            bflag = 1
wflag = 0
ans2 = 0
for i in range(1, N + 1):
    if wflag == 1:
        if s[-i] == '#':
            ans2 += 1
        else:
            wflag == 0:
    else:
        if s[-i] == '.':
            wflag == 1
print(min(ans, ans2))


Fixed submission:
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
bcount = 0
wcount = 0
for word in s:
    if word == '.':
        wcount += 1
ans = wcount
preans = ans
for word in s:
    if word == '#':
        preans += 1
    else:
        preans -= 1
    ans = min(ans, preans)
print(ans)