Problem p03069 (python)

Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
s = list(input())
res = 10**9

cta = 0
ctb = 0
a = [0]*n
b = [0]*n
for i in range(n):
    if s[i] == '.':
        cta += 1
    else:
        ctb += 1
    a[i] = cta
    b[i] = ctb
for i in range(n):
    res = min(res,b[i]+a[-1]-a[i])
res = min(res,a[-1],b[-1])
print(res)

Buggy submission (verdict: Runtime Error):

n = int(input())
s = input()

min_num = n
white_num = s.count('.')
black_num = 0

if white_num == n or s.count('#') == n:
    print(0)
else:
    for i in range(n):
        if s[i] == '#':
            black_num += 1
        else:
            white_num -= 1
        if min_num >= black_num + white_num
            min_num = black_num + white_num
    print(min_num)

Buggy submission (verdict: Runtime Error):

n = int(input())
s = input()

ans = n
cnt_w = s.count('.')
cnt_k = 0
if cnt == n or cnt == 0:
    ans = 0
    print(ans)
else:
    for i in range(n):
        if s[i] == '.':
            cnt_w -= 1
        else:
            cnt_k += 1
        if ans > cnt_w + cnt_k:
            ans = cnt_w + cnt_k
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

ans = n
cnt_w = s.count('.')
cnt_k = 0
if cnt == n or cnt == 0:
    ans = 0
    print(ans)
else:
    for i in range(n):
        if s[i] == '.':
            cnt_w -= 1
        else:
            cnt_k += 1
        if ans > cnt_w + cnt_k:
            ans = cnt_w + cnt_k:
    print(ans)

Buggy submission (verdict: Runtime Error):

n = int(input())
s = input()

ans = n
if s.count('#') == n or s.count('.') == n:
    ans = 0
    print(ans)
else:
    if num < ans:
        ans = num
    for i in range(n):
        num = s[:i].count('#') + s[i:].count('.')
        if num < ans:
            ans = num
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

ans = 0
while s.find('#.') != -1:
    pos = s.find('#.')
    if pos-1 >= 0:
        if s[pos-1] == '#':
            s = s[:pos] + '##' + s[pos+2:]
    if pos+2 <= n-1:
        elif s[pos+2] == '.':
            s = s[:pos] + '..' + s[pos+2:]
    if pos-2 <= 0:
        elif s[pos-2:pos] == '#.':
            s = s[:pos] + '##' + s[pos+2:]
    if pos+4 <= n-1:
        elif s[pos+2:pos+4] == '#.':
            s = s[:pos] + '..' + s[pos+2:]
    else:
        s = s[:pos] + '##' + s[pos+2:]
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

ans = 0
while s.find('#.') != -1:
    pos = s.find('#.')
    if s[pos-1] == '#':
        s = s[:pos] + '##' + s[pos+2:]
    elif s[pos+2] == '.':
        s = s[:pos] + '..' + s[pos+2:]
    elif s[pos-2:pos] == '#.':
        s = s[:pos] + '##' + s[pos+2:]
    elif s[pos+2:pos+4] == '#.':
        s = s[:pos] + '..' + s[pos+2:]
    else:
        s = s[:pos] + '##' + s[pos+2:]
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

ans = 0
while s.find('#.') != -1:
    if s.find('##.#'):
        s = s[:pos] + '####' + s[pos+4:]
        ans += 1
    elif s.find('##..'):
        # ?
        s = s[:pos] + '####' + s[pos+4:]
        ans += 2
    elif s.find('.#.#'):
        s = s[:pos] + '...#' + s[pos+4:]
        ans += 1
    elif s.find('.#..'):
        s = s[:pos] + '....' + s[pos+4:]
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

ans = 0
while s.find('#.') != -1:
    pos = s.find('#.')
    if s[pos-1] == '#':
        s = s[:pos] + '##' + s[pos+2:]
    elif s[pos+2] == '.':
        s = s[:pos] + '..' + s[pos+2:]
    else:
        s = s[:pos] + '##' + s[pos+2:]
    ans += 1
print(ans)