Buggy python submission (verdict: Time Limit Exceeded):

# -*- coding: utf-8 -*-

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

# 0 0 1 1 全部黒
# 0 1 2 2
# 0 1 1 1
# 0 1 1 2 全部白
#  # . #

sum = [0]*(n+1)
ans = n

for i in range(n+1):
    for j in range(0,i):
        # print('i = {}, j = {}'.format(i,j))
        if s[j] == '#':
            sum[j+1] = sum[j] + 1
        else:
            sum[j+1] = sum[j]
        if sum[j+1]>ans:
            break

    for k in range(i, n):
        # print('i = {}, k = {}'.format(i,k))
        if s[k] == '.':
            sum[k+1] = sum[k] + 1
        else:
            sum[k+1] = sum[k]
        if sum[k+1]>ans:
            break
    ans = min(ans, sum[n])
print(ans)

Fixed submission:

# -*- coding: utf-8 -*-

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

sum_w = [0]*(n+1)
sum_b = [0]*(n+1)
ans = n

for i in range(n):
    if s[i] == '#':
        sum_b[i+1] = sum_b[i] + 1
    else:
        sum_b[i+1] = sum_b[i]

    if s[i] == '.':
        sum_w[i+1] = sum_w[i] + 1
    else:
        sum_w[i+1] = sum_w[i]

ans = n
for i in range(n+1):
    ans = min(ans, sum_b[i]+sum_w[n]-sum_w[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

# -*- coding: utf-8 -*-

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

# 0 0 1 1 全部黒
# 0 1 2 2
# 0 1 1 1
# 0 1 1 2 全部白
#  # . #


ans = n

for i in range(n+1):
    sum = [0]*(n+1)
    for j in range(0,i):
        # print('i = {}, j = {}'.format(i,j))
        if s[j] == '#':
            sum[j+1] = sum[j] + 1
        else:
            sum[j+1] = sum[j]
        if sum[j+1]>n:
            break

    for k in range(i, n):
        # print('i = {}, k = {}'.format(i,k))
        if s[k] == '.':
            sum[k+1] = sum[k] + 1
        else:
            sum[k+1] = sum[k]
        if sum[k+1]>n:
            break
    ans = min(ans, sum[n])
print(ans)

Fixed submission:

# -*- coding: utf-8 -*-

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

sum_w = [0]*(n+1)
sum_b = [0]*(n+1)
ans = n

for i in range(n):
    if s[i] == '#':
        sum_b[i+1] = sum_b[i] + 1
    else:
        sum_b[i+1] = sum_b[i]

    if s[i] == '.':
        sum_w[i+1] = sum_w[i] + 1
    else:
        sum_w[i+1] = sum_w[i]

ans = n
for i in range(n+1):
    ans = min(ans, sum_b[i]+sum_w[n]-sum_w[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

# -*- coding: utf-8 -*-

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

# 0 0 1 1 全部黒
# 0 1 2 2
# 0 1 1 1
# 0 1 1 2 全部白
#  # . #

sum = [0]*(n+1)
ans = n

for i in range(n+1):
    for j in range(0,i):
        # print('i = {}, j = {}'.format(i,j))
        if s[j] == '#':
            sum[j+1] = sum[j] + 1
        else:
            sum[j+1] = sum[j]

    for k in range(i, n):
        # print('i = {}, k = {}'.format(i,k))
        if s[k] == '.':
            sum[k+1] = sum[k] + 1
        else:
            sum[k+1] = sum[k]
    ans = min(ans, sum[n])
print(ans)

Fixed submission:

# -*- coding: utf-8 -*-

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

sum_w = [0]*(n+1)
sum_b = [0]*(n+1)
ans = n

for i in range(n):
    if s[i] == '#':
        sum_b[i+1] = sum_b[i] + 1
    else:
        sum_b[i+1] = sum_b[i]

    if s[i] == '.':
        sum_w[i+1] = sum_w[i] + 1
    else:
        sum_w[i+1] = sum_w[i]

ans = n
for i in range(n+1):
    ans = min(ans, sum_b[i]+sum_w[n]-sum_w[i])
print(ans)