Buggy python submission (verdict: Runtime Error):
n = int(input())
s = '.'+input()
ans = []

def div(i, s):
  l = s[:i.start()+1]
  r = s[i.end()-1:]
  lb = l.count('#')
  rw = r.count('.')
  return l, lb, r, rw
  
for i in re.finditer(r'#\.', s):
  l, lb, r, rw = div(i, s)
  ans.append(lb+rw)
for i in re.finditer(r'\.#', s):
  l, lb, r, rw = div(i, s)
  ans.append(lb+rw)
if len(ans) > 0:
  print(min(ans))
else:
  print(0)

Fixed submission:
n = int(input())
s = '.'+input()
lb, rw = 0, s.count('.')-1
ans = lb+rw
for i in range(1,n+1):
  if s[i] == '#':
    lb += 1
  elif s[i] == '.':
    rw -= 1
  if lb+rw < ans:
    ans = lb+rw
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = '.'+input()
ans = []

def div(i, s):
  l = s[:i.start()+1]
  r = s[i.end()-1:]
  lb = l.count('#')
  rw = r.count('.')
  return l, lb, r, rw
  
for i in re.finditer(r'#\.', s):
  l, lb, r, rw = div(i, s)
  print(l, lb, r, rw)
  ans.append(lb+rw)
print()
for i in re.finditer(r'\.#', s):
  l, lb, r, rw = div(i, s)
  print(l, lb, r, rw)
  ans.append(lb+rw)
print('\n',ans)
if len(ans) > 0:
  print(min(ans))
else:
  print(0)

Fixed submission:
n = int(input())
s = '.'+input()
lb, rw = 0, s.count('.')-1
ans = lb+rw
for i in range(1,n+1):
  if s[i] == '#':
    lb += 1
  elif s[i] == '.':
    rw -= 1
  if lb+rw < ans:
    ans = lb+rw
print(ans)

Buggy python submission (verdict: Runtime Error):
import re
n = int(input())
s = input()
anss = []
for i in re.finditer(r'#\.|\.#', s):
  l = s[:i.start()+1]
  r = s[i.end()-1:]
  anss.append(l.count('#')+r.count('.'))
print(min(anss))

Fixed submission:
n = int(input())
s = '.'+input()
lb, rw = 0, s.count('.')-1
ans = lb+rw
for i in range(1,n+1):
  if s[i] == '#':
    lb += 1
  elif s[i] == '.':
    rw -= 1
  if lb+rw < ans:
    ans = lb+rw
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
anss = []
for i in re.finditer(r'#\.|\.#', s):
  l = s[:i.start()+1]
  r = s[i.end()-1:]
  anss.append(l.count('#')+r.count('.'))
print(min(anss))

Fixed submission:
n = int(input())
s = '.'+input()
lb, rw = 0, s.count('.')-1
ans = lb+rw
for i in range(1,n+1):
  if s[i] == '#':
    lb += 1
  elif s[i] == '.':
    rw -= 1
  if lb+rw < ans:
    ans = lb+rw
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

def next(s):
  if s == '':  # empty
    return 0, 0, None
  if len(s) == s.count('#') or len(s) == s.count('.'):  # . or # only
    return s.count('#'), s.count('.'), None

  l = s.index('#')
  try:
    c = s.index('#.')+1
    try:
      r = s.index('.#')+1
    except:
      r = len(s)-1
  except:
    c,r = len(s)-1
  b = c - l
  w = r - c
  return b, w, s[r:]

black, white = 0, 0
if n == s.count('#') or n == s.count('.'):  # . or # only
  black += s.count('#')
  white += s.count('.')
  s = None
else:
  if s[0] == '.':
    s = s[s.index('.#')+1:]
while(s != None):
  b, w, s = next(s)
  black += b
  white += w
print(min(black, white))

Fixed submission:
n = int(input())
s = '.'+input()
lb, rw = 0, s.count('.')-1
ans = lb+rw
for i in range(1,n+1):
  if s[i] == '#':
    lb += 1
  elif s[i] == '.':
    rw -= 1
  if lb+rw < ans:
    ans = lb+rw
print(ans)

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

def next(s):
  if s == '':  # empty
    return 0, 0, None
  if len(s) == s.count('.') or len(s) == s.count('#'):  # . or # only
    return s.count('#'), s.count('.'), ''

  l = s.index('#')
  if s.count('#.') > 0:
    c = s.index('#.')+1
    if s.count('.#') > 0:
      r = s.index('.#')+1
    else:
      r = len(s)-1
  else:
    c,r = len(s)-1
  b = c - l
  w = r - c
  return b, w, s[r:]

black, white = 0, 0
if s[0] != '#':
  s = s[s.index('.#')+1:]
while(s != None):
  b, w, s = next(s)
  black += b
  white += w
print(min(black, white))

Fixed submission:
n = int(input())
s = '.'+input()
lb, rw = 0, s.count('.')-1
ans = lb+rw
for i in range(1,n+1):
  if s[i] == '#':
    lb += 1
  elif s[i] == '.':
    rw -= 1
  if lb+rw < ans:
    ans = lb+rw
print(ans)