Problem:
 Score : 300 points    Problem Statement There are N stones arranged in a row. Every stone is painted white or black.
A string S represents the color of the stones. The i -th stone from the left is white if the i -th character of S is . , and the stone is black if the character is # .  Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.
Find the minimum number of stones that needs to be recolored.      Constraints  1 \leq N \leq 2\times 10^5  S is a string of length N consisting of . and # .         Input Input is given from Standard Input in the following format:  N  S       Output Print the minimum number of stones that needs to be recolored.        Sample Input 1 3
#.#      Sample Output 1 1  It is enough to change the color of the first stone to white.       Sample Input 2 5
#.##.      Sample Output 2 2       Sample Input 3 9
.........      Sample Output 3 0

Solution (Python):
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))
INF = 1 << 29


def runLength(in_str):
    kukan = 1
    start = 0
    ret = []
    for i in range(1,len(in_str)):
        if in_str[i-1]!=in_str[i]:
            ret.append([in_str[i-1],kukan,start])
            start = i
            kukan=0
        kukan+=1
    ret.append([in_str[-1],kukan,start])
    return ret

N = int_raw()
S= input()
 
def main():
    ans = INF
    numB = [0]
    for c in S:
        numB.append(numB[-1])
        if c=="
            numB[-1]+=1
    for i in range(len(S)+1):
        ans = min(ans, numB[i]+ len(S)-i-(numB[-1]-numB[i]))
    return ans

print(main())

Solution (Python):
n = int(input())
s = input()

a = []

w = s.count(".")
b = s.count("
m = min(w,b)

bb=0

for i in range(n):
    if s[i]=='.':
        w-=1
        a.append(bb+w)
    if s[i]=='
        bb += 1
        a.append(bb+w)
if len(a)>0:
    I = min(a)
    print(min(m,I))
else:
    print(m)

Solution (Python):
N = int(input())
S = input()
b = [0]*N
w = [0]*N
ans = []
for n in range(N):
    if S[n] == '
        if n == 0:
            b[n] = 1
        else:
            b[n] = b[n-1] +1
    else:
        if n == 0:
            b[n] = 0
        else:
            b[n] = b[n-1]

    if S[N-1-n] == '.':
        if N-1-n == N-1:
            w[N-1-n] = 1
        else:
            w[N-1-n] = w[N-n] +1
    else:
        if N-1-n == N-1:
            w[N-1-n] = 0
        else:
            w[N-1-n] = w[N-n]

for n in range(N):
    ans.append(b[n]+w[n])


print(min(ans)-1)

Solution (Python):

N = int(input())
S = list(input())
ans = S.count(".")
cnt = ans
for i in range(N):
    if S[i] == "
        cnt += 1
    else:
        cnt -= 1
    ans = min(ans, cnt)
print(ans)

Solution (Python):
n=int(input())
sl=list(input())

bi=0
wi=0
b=[]
w=[]
for i in range(n):
	if sl[i] == "
		bi = bi+1
	else:
		wi = wi+1
	b.append(bi)
	w.append(wi)

c=0
res=2*10**6
for i in range(n-1):
	if (sl[i]=="
		c = b[i] + w[n-1]-w[i]
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]
if w[0]==1:
	for i in range(n-1):
		if w[i]==w[i+1]:
			w0=w[n-1]-w[i]
			break
if b[n-1]-b[n-2]==1:
	for i in range(n-1):
		if b[n-1-i]==b[n-1-i-1]:
			b0=b[n-1-i]
			break

if w0<res:
	res=w0
if b0<res:
	res=b0

print(res)

Solution (Python):
n = int(input())
S = list(input())
ans = S.count('.')
c = ans
for i in range(n):
    if (S[i] == '
        c += 1
    else:
        c -= 1
    ans = min(ans, c)


print(ans)

Solution (Python):
N = int(input())
S = input()                                                      
list_S = list(S)
N1 = 0
list_X =[]
X = list_S.count('.')
list_X.append(X)
    
for color in list_S:
    if list_S[N1] == '.':
        X -= 1
        list_X.append(X)
        N1 +=1
    else:
        X += 1
        list_X.append(X)
        N1 +=1

X = list_S.count('
list_X.append(X)

X_MIN = min(list_X)
print(X_MIN)

Solution (Python):
N = int(input())
S = list(input())

black_sum = [0]*(N+1)
white_sum = [0]*(N+1)
ans = S.count('.')
for i in range(N):
    key_black = 0
    key_white = 0
    if S[i]=='
        key_black = 1
    else:
        key_white = 1

    black_sum[i+1]=black_sum[i]+key_black
    white_sum[i+1]=white_sum[i]+key_white
tmp = 0
for i in range(1,len(black_sum)):
    
        left = black_sum[i]  
        right = white_sum[-1]-white_sum[i]  
        tmp = left + right
        ans = min(tmp,ans)

print(ans)

Solution (Python):

n = int(input())
stones = input()
score = stones.count(".")
r = score
for i in range(n):
	if stones[i] == ".":
		r -= 1
	else:
		r += 1
	score = min(r, score)
print(score)

Solution (Python):
n=int(input())
s=input()
a=s.count(".")
ans=a
for i in range(n):
  if s[i]==".":
    a-=1
  else:
    a+=1
  ans=min(ans,a)
print(ans)

Solution (Python):
n = int(input())
s = input()

count_black = 0
count_white = 0
a = n + 1
cnt_white = [0] * a
cnt_black = [0] * a
result = []

for i in range(n):
    if s[i] == ".":
        count_white += 1

cnt_white[0] = count_white

for i in range(n):
    if s[i] == "
        count_black += 1
    else:
        count_white -= 1
    cnt_white[i+1] = count_white
    cnt_black[i+1] = count_black

for i in range(n+1):
    result.append(cnt_black[i] + cnt_white[i])

ans = min(result)

print(ans)

Solution (Python):
N = int(input())
S = input()
A = [S.count(".")]
for i in range(N):
  if S[i] == "
    A.append(A[i] + 1)
  else:
    A.append(A[i] - 1)
print(min(A))

Solution (Python):
n=int(input())
l=input()
l1=[]
c=0
for i in range(n):
  if l[i]=="
    c+=1
  l1.append(c)
l2=[]
for i in range(n):
  l2.append(n-(i+1)-(c-l1[i])+l1[i])
print(min(min(l2),c,n-c))

Solution (Python):

N = int(input())
S = str(input())
sign = ('.', '
if N == 1:
    print(0)
else:
    c1, c2 = 0, S.count('.')
    ans = c1 + c2
    for i in range(0,N):
        if S[i] == '
            c1 += 1
        else:
            c2 -= 1
        tmp = c1 + c2
        ans = min(ans, tmp)
    print(ans)

Solution (Python):
N = int(input())
S = input()
 
 
r = S.count(".")
result = r
for i in range(N):
    if S[i] == "
        r += 1
    else:
        r -= 1
    result = min(result, r)
 
print(result)

Solution (Python):
N = int(input())
S = str(input())

white = S.count(".")
black = 0
ans = S.count(".")

for i in range(N):
  if S[i] == ".":
    white -=1
  else:
    black +=1
  ans = min(ans,white+black)

print(ans)

Solution (Python):
N  = int (input())
S = input()


b = S.count("
w = S.count(".")

cotB = 0
cotW = 0
ans = w
for i,s in enumerate(S):
    if s ==".":
        cotW+= 1
    else:
        cotB+=1
    if ans >=  cotB + (w - cotW):
        ans = cotB + (w - cotW)
print(ans)

Solution (Python):

import numpy

N = int(input())
S = [int(x) for x in input().replace('

b_cumsum = numpy.cumsum(S)
w_cumsum = numpy.cumsum(S[::-1])
b_total = b_cumsum[-1]




ans = N
for i in range(N):

    
    w_num = i + 1
    
    w_rev_num = b_cumsum[i]  

    
    b_num = N - w_num
    
    b_cur = w_cumsum[b_num]
    ans = min(ans, w_rev_num + b_num - b_cur)

print(ans)

Solution (Python):
N = int(input())
S = input()
 
left_black=0
right_white=S.count(".")
ans=left_black+right_white
 
for i in S:
    if i==".":
        right_white-=1
        ans=min(ans,left_black+right_white)
    else:
        left_black+=1
        ans=min(ans,left_black+right_white)
print(ans)

Solution (Python):
n = int(input())
s = str(input())
b = []
nb = 0
w = []
nw = 0
for s_ in s:
  if s_ == "
    nb += 1
  if s_ == ".":
    nw += 1
  b.append(nb)
  w.append(nw)
ans = []


for i in range(n):
  if i == n-1 and s[i] == ".":
    ans.append(b[i]+1)
  elif i == 0:
    ans.append(w[n-1])
  else:
    ans.append(b[i-1]+w[n-1]-w[i-1])
ans.append(b[n-1])

if n == 1:
  print("0")
else:
  print(min(ans))

Solution (Python):
N = int(input())
S = input()

cum_sum_b = [0]
cum_sum_w = [0]

sum_b = 0
sum_w = 0
for i, s in enumerate(S):
    if s == '
        sum_b += 1
    else:
        sum_w += 1
    cum_sum_b.append(sum_b)
    cum_sum_w.append(sum_w)

ans = N
for i in range(0, len(S) + 1):
    count = cum_sum_b[i] + cum_sum_w[len(S)] - cum_sum_w[i]
    ans = min(ans, count)

print(ans)

Solution (Python):
from sys import exit

N = int(input())
S = input()

stack = []

black = 0
white = 0

for i in range(len(S)):
    if S[i] == '.':
        white += 1

ans = len(S)
for i in range(len(S) + 1):
    if ans > black + white:
        ans = black + white

    if i == len(S):
        continue
    if S[i] == '.':
        white -= 1
    else:
        black += 1

print(ans)

Solution (Python):
N = int(input())
S = input()
 
left_black=0
right_white=S.count(".")
ans=left_black+right_white
 
for i in S:
    if i==".":
        right_white-=1
        ans=min(ans,left_black+right_white)
    else:
        left_black+=1
        ans=min(ans,left_black+right_white)
print(ans)

Solution (Python):
n=int(input())
s=input()
t=s.count("
for i in s:
    if i=="
    else: t+=1
    t=min(t,s.count("
print(t)

Solution (Python):
n = int(input())
s = input()
b = [0]*n
w = [0]*n
if s[0] == "
    b[0] = 1
for i in range(1,n):
    if s[i]=="
        b[i] = b[i-1]+1
    else:
        b[i] = b[i-1]
if s[-1] == ".":
    w[-1] = 1
for i in range(n-2,-1,-1):
    if s[i]==".":
        w[i] = w[i+1]+1
    else:
        w[i] = w[i+1]
a = min(w[0],b[n-1])
for i in range(n-1):
    if a > b[i]+w[i+1]:
        a = b[i]+w[i+1]
print(a)

Solution (Python):
n = int(input())
s = input()

shiro_num = s.count(".")
kuro_num = n - shiro_num

right_kuro_num = kuro_num
right_siro_num = shiro_num

result = shiro_num

for e in s:
    if e == '.':
        right_siro_num -= 1
    else:
        right_kuro_num -= 1
    num = right_siro_num + kuro_num - right_kuro_num
    result = min(num,result)

print(result)

Solution (Python):
import numpy
N=int(input())
S=list(map(str,input()))
S_modify = [0 if i=="." else 1 for i in S]
count_list = []

sum_list=numpy.cumsum(S_modify)
sum_list_reverse=numpy.cumsum(S_modify[::-1])
for i in range(N):
    count = sum_list[i]+((N-i-1)-sum_list_reverse[N-i-1])
    count_list.append(count)
print(min(count_list))

Solution (Python):
import numpy
N=int(input())
S=input()
S_modify = list(map(int,S.replace('.','0').replace('
count_list = []

sum_list=numpy.cumsum(S_modify)
sum_list_reverse=numpy.cumsum(S_modify[::-1])
for i in range(N):
    count = sum_list[i]+((N-i-1)-sum_list_reverse[N-i-1])
    count_list.append(count)
print(min(count_list))

Solution (Python):
N = int(input())
S = input()

A = [0] * (N+1)
B = [0] * (N+1)

for i in range(N):
    A[i+1] = A[i]
    if S[i] == "
        A[i+1] += 1

for i in range(N,0,-1):
    B[i-1] = B[i]
    if S[i-1] == ".":
        B[i-1] += 1

ans = 10 ** 9
for i in range(N+1):
    ans = min(ans, A[i] + B[i])

print(ans)

Solution (Python):
n=int(input())
s=input()
bres=0
wres=0
blst=[]
wlst=[]
for i in range(n):
    if s[i]=='
        bres+=1
    blst.append(bres)
for i in range(n-1,-1,-1):
    if s[i]=='.':
        wres+=1
    wlst.append(wres)
wlst=wlst[::-1]
ans=10**9
blst.insert(0,0)
wlst.insert(n,0)
for i in range(n+1):
    ans=min(blst[i]+wlst[i],ans)
print(ans)

Solution (Python):
N = int(input())
S = input()
c1 = [0] * N
c2 = [0] * N
ans = N
for i in range(N):
    c1[i] += c1[i - 1] + 1 * (S[i] == "
    c2[i] += c2[i - 1] + 1 * (S[i] == ".")
c1 = [0] + c1
c2 = [0] + c2
for i in range(N):
    ans = min(ans, c1[i] + c2[N] - c2[i + 1])
print(ans)

Solution (Python):
N = int(input())
S = input()
c1 = [0] * N
c2 = [0] * N
ans = N
for i in range(N):
    c1[i] += c1[i - 1] + 1 * (S[i] == "
    c2[i] += c2[i - 1] + 1 * (S[i] == ".")
c1 = [0] + c1
c2 = [0] + c2


for i in range(N):
    
    ans = min(ans, c1[i] + c2[N] - c2[i + 1])
print(ans)

Solution (Python):
n = int(input())
s = input()
cnt = 0
narabi = []
befores = '
for S in s:
    if S == befores:
        cnt += 1
    else:
        narabi.append(cnt)
        befores = S
        cnt = 1
narabi.append(cnt)
if s[-1] == '
    narabi.append(0)
hennkann = s.count('.')
saishou = s.count('.')
hashu = 0
dot = 1
for i in range(int(len(narabi) / 2)):
    hennkann = hennkann - narabi[dot] + narabi[hashu]
    saishou = min(saishou,hennkann)
    dot += 2
    hashu += 2
print(saishou)

Solution (Python):
N=int(input())
S=input()

cost=[]
left=0
right=0
for i in range(N):
	if S[i]=='
		right+=1

cost.append(N-right)
for i in range(0,N):
	if S[i]=='
		left+=1
		right-=1
	cost.append(left+N-i-1-right)

cost.sort()
print(cost[0])

Solution (Python):
import numpy as np

N = int(input())
S = list(input())

S_map = [1 if i=="." else 0 for i in S]
cumsum = np.array(S_map).cumsum()
cumsum = np.insert(cumsum, 0, 0)
ans = []

for i in range(N+1):
    if(i == 0 or i == N or S[i-1] != S[i]):
        if(i != 0):
            left_white = cumsum[i]
            left_black = i - left_white
        else:
            left_white = 0
            left_black = 0
        if(i != N):
            right_white = cumsum[-1] - cumsum[i]
            right_black = (N - i) - right_white
        else:
            right_white = 0
            right_black = 0
        ans.append(min(left_white+right_white, left_black+right_black, left_black+right_white))
print(min(ans))

Solution (Python):
N = int(input())
S = input()

white_count = S.count(".")
black_count = 0
ans = white_count
for s in S:
    if s == "
        black_count += 1
    else:
        white_count -= 1
    if ans > black_count + white_count:
        ans = black_count + white_count

print(ans)

Solution (Python):

import copy
import random
import bisect 
import math

N = int(input())
S = str(input())


cnt = S.count(".")

l = [cnt] 
for i in range(N):
    if S[i]==".":
        cnt -= 1
        l.append(cnt)
    else:
        cnt += 1
        l.append(cnt)


print(min(l))

Solution (Python):

import copy
import numpy as np
import random
import bisect 
import math

N = int(input())
S = str(input())



























cnt = S.count(".")

l = [cnt] 
for i in range(N):
    if S[i]==".":
        cnt -= 1
        l.append(cnt)
    else:
        cnt += 1
        l.append(cnt)


print(min(l))

Solution (Python):
n = int(input())
s = list(input())
white = s.count(".")
diff = 0
diff_min = 0
for i in range(n):
    diff += (1 if s[i] == "
    diff_min = min(diff, diff_min)
        
print(white + diff_min)

Solution (Python):
n = int(input())
s = list(input())
m = n
counts = s[:].count(".")
m = min(n,counts)
for i in range(n):
    counts += s[i].count("
    if m > counts:
        m = counts
        
print(m)

Solution (Python):

import re
import bisect
from datetime import datetime as dt
n = input()
s = raw_input()

m = n
left = s[:0].count('
right = s[0:].count('.')
m = min(m, left + right)
for i in range(len(s)):
    if s[i] == '.':
        right -= 1
    else:
        left += 1
    m = min(m, right + left)
print m

Solution (Python):
n=int(input())
s=input()
sirocnt=s.count('.')
kurocnt=0
ans=[sirocnt]
for i in range(n):
    if s[i]=='.':
        sirocnt-=1
    else:
        kurocnt+=1
    ans.append(sirocnt+kurocnt)
print(min(ans))

Solution (Python):
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
s = list(IS())
black = [0] * 200005
black[0] = 0
counter = 0
for i in s:
    counter += 1
    if i == '
        black[counter] = black[counter-1] + 1
    else:
        black[counter] = black[counter-1]
mini = len(s) - black[n]
for i in range(1,n+1):
    mini = min(mini,(black[i] + n - i - (black[n] - black[i])))
print(mini)

Solution (Python):
n=int(input())
s=str(input())






memo = []
countwb=0
now = s[0]
count = 0
if now == "
    memo.append(0)
while(count<n):
    if s[count]==now:
        countwb+=1
    else:
        memo.append(countwb)
        countwb = 1
        now = s[count]
    count+=1
memo.append(countwb)


memo_r=[]
for i in range(len(memo)):
    memo_r.append(memo[-1*(i+1)])


count_w = []
c_w = 0
if len(memo_r)%2==1:
    count_w.append(0)
    for  i in range(0,len(memo_r),2):
            c_w += memo_r[i]
            count_w.append(c_w)
else:
    count_w.append(0)
    count_w.append(0)
    for  i in range(1,len(memo_r),2):
            c_w += memo_r[i]
            count_w.append(c_w)


count_b = []
count_b.append(0)
count_b.append(0)
c_b = 0
for  i in range(1,len(memo),2):
        c_b += memo[i]
        count_b.append(c_b)


count_list = []
for i in range(len(count_b)):
    temp = count_w[-1*(i+1)]+count_b[i]
    count_list.append(temp)


print(min(count_list))

Solution (Python):

n = int(raw_input())
s = str(raw_input())

ans=[]
black=[]
for i in range(0,n):
    ans.append(-1)
    black.append(-1)
ans[0]=0
if s[0]==".":
    black[0]=0
else:
    black[0]=1

for i in range(1,n):
    if s[i] == ".":
        black[i] = black[i-1]
        ans[i] = min(black[i-1], ans[i-1]+1)
    else:
        black[i] = black[i-1] + 1
        ans[i] = min(ans[i-1], black[i-1]+1)

print ans[n-1]

Solution (Python):
N = int(input())
S = input()
 
left_black=0
right_white=S.count(".")
ans=left_black+right_white

for i in S:
    if i==".":
        right_white-=1
        ans=min(ans,left_black+right_white)
    else:
        left_black+=1
        ans=min(ans,left_black+right_white)
print(ans)

Solution (Python):
N = input()
S = input()
count = 0

list_str = S
count_black = 0
count_white = S.count('.')
ans = count_black + count_white

for i in S:
    if i == '
        count_black += 1
    else:
        count_white -= 1

    if ans >= count_white + count_black:
        ans = count_black + count_white




print(ans)

Solution (Python):
n = int(input())
s = input()
b = [0] * (n + 1)
w = [0] * (n + 1)

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

for i in range(n - 1, -1, -1):
    if s[i] == '.':
        w[i] = w[i + 1] + 1
    else:
        w[i] = w[i + 1]

ans = [vb + vw for vb, vw in zip(b, w)]
print(min(ans))

Solution (Python):
N = int(input())
S = input()

wsum = [0]
bsum = [0]

for s in S:
	wsum.append(wsum[-1] if "." == s else wsum[-1] + 1)
for s in S[::-1]:
	bsum.append(bsum[-1] if "




msum = 2**31-1
for i in range(len(S) + 1):
	msum = min(msum, wsum[i] + bsum[-1-i])

print(msum)

Solution (Python):
N=int(input())
S = input()
w = [0]*(N+1)
b = [0]*(N+1)
for i, s in enumerate(S):
    if s=='.':
        w[i+1] = w[i]+1
        b[i+1] = b[i]
    elif s=='
        b[i+1] = b[i]+1
        w[i+1] = w[i]
ans = 10**20
for i in range(N+1):
    ans = min(ans, b[i]+w[N]-w[i])
print(ans)

Solution (Python):


def solve():
    N = int(input())
    S = input()

    kuro_num = 0
    siro_num = 0
    for moji in S:
        if moji == "
            kuro_num += 1
        else:
            siro_num += 1

    """
    
    .
    ..
    (略)
    ..........
    (略)
    ....................
    .....................
    ......................
    の全パターンのうち、最も回数が少ないものが答え
    """
    right_kuro_num = kuro_num
    right_siro_num = siro_num
    ans = siro_num
    for moji in S:
        if moji == "
            right_kuro_num -= 1
        else:
            right_siro_num -= 1
        num = right_siro_num + (kuro_num - right_kuro_num)
        ans = min(ans, num)

    print(ans)

"""
26
...
"""
if __name__ == "__main__":
    solve()

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
sum = 0
wh = s.count('.')
cnt = 0
for itr in range(N):
    if s[itr] == '
        cnt += 1
        continue
    if cnt > 0:
        sum += 1
        cnt -= 1
print(sum)

Solution (Python):
N=int(input())
S=input()

if N==1:
    print("0")
else:
    cnt_left=0
    cnt_right=S.count(".")
    cnt = cnt_left + cnt_right
    for i in range(N):
        if S[i] == "
            cnt_left += 1
        else:
            cnt_right -= 1

        if cnt_left + cnt_right < cnt:
            cnt = cnt_left + cnt_right
    print(cnt)

Solution (Python):

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

bcnt = [0 for _ in range(n+1)]
wcnt = [0 for _ in range(n+1)]
b = 0
w = 0
for i, (c, r) in enumerate(zip(s, s[::-1])):
    b += 1 if c == '
    bcnt[i+1] = b

    w += 1 if r == '.' else 0
    wcnt[n-i-1] = w

change = [b + w for b, w in zip(bcnt, wcnt)]
print(min(change))

Solution (Python):
N = int(input())
S = input()

b = [0] * N
for i, s in enumerate(S):
    if s == '
        b[i] = b[i-1] + 1
    else:
        b[i] = b[i-1]
b = [0] + b + [0]
ans = N
for i in range(N+1):
    ans = min(ans, b[i] + N - i - b[N] + b[i-1])

print(ans)

Solution (Python):


def solve():
    N = int(input())
    S = input()

    kuro_num = 0
    siro_num = 0
    for moji in S:
        if moji == "
            kuro_num += 1
        else:
            siro_num += 1

    
    right_kuro_num = kuro_num
    right_siro_num = siro_num
    ans = siro_num
    for moji in S:
        if moji == "
            right_kuro_num -= 1
        else:
            right_siro_num -= 1
        num = right_siro_num + (kuro_num - right_kuro_num)
        ans = min(ans, num)

    print(ans)

"""
26
...
"""
if __name__ == "__main__":
    solve()

Solution (Python):
import sys
from itertools import accumulate
N = int(input())
S = input()

if S == '.'*N or S == '
    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))

Solution (Python):
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
bs = [0] * (N + 1)
ws = [0] * (N + 1)
total = float("inf")
left_b = 0
right_w = 0
for i, s in enumerate(S):
    if s == "
        left_b += 1
    bs[i + 1] = left_b
for i in reversed(range(N)):
    if S[i] == ".":
        right_w += 1
    ws[i] = right_w

for i in range(N):
    total = min(total, ws[i+1] + bs[i])

print(total)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
S=input()

sm1=[0]*(N+2)
for i in range(N):
    sm1[i+1]=sm1[i]
    if S[i]=='
        sm1[i+1]+=1
sm2=[0]*(N+2)
for i in range(N+1, 1, -1):
    sm2[i-1]=sm2[i]
    if S[i-2]=='.':
        sm2[i-1]+=1

ans=INF
for i in range(N+1):
    ans=min(ans, sm1[i]+sm2[i+1])
print(ans)

Solution (Python):
n = int(input())
s = input()
r = s.count(".")
l = 0

ans = l+r
for i in s:
    if i == "
        l += 1
    else:
        r -= 1
    ans = min(ans,l+r)
print(ans)

Solution (Python):


def solve():
    N = int(input())
    S = input()

    kuro_num = 0
    siro_num = 0
    for moji in S:
        if moji == "
            kuro_num += 1
        else:
            siro_num += 1

    if siro_num == N:
        print(0)
        exit()

    
    right_kuro_num = kuro_num
    right_siro_num = siro_num
    ans = siro_num
    for moji in S:
        if moji == "
            right_kuro_num -= 1
        else:
            right_siro_num -= 1
        num = right_siro_num + (kuro_num - right_kuro_num)
        ans = min(ans, num)

    print(ans)

"""
26
...
"""
if __name__ == "__main__":
    solve()

Solution (Python):
n=int(input())
s=input()
w = s.count('.')
b = 0
ans=w+b
for i in s:
    if i=='
        b+=1
    else:
        w-=1
    if ans>=b+w:
        ans=b+w
print(ans)

Solution (Python):

"""
ある境目を考える。境目より左が全て白、境目より右が全て黒でなくてはいけない。
ゆえに、境目より左の黒の数と境目より右の白の数を数えれば、その境目における「変更が必要な石の数」がわかる。
よって、境目を端から端まで動かしてその中で最小の「変更が必要な石の数」を求めればよい。
"""
N = int(input())
str = input()
minDistance = 0

black = "
white = "."
leftblack = 0
rightwhite = 0

for i in range(N):
    if str[i] == white:
        rightwhite += 1

minDistance += rightwhite

for j in range(0, N):
    if str[j] == black:
        leftblack += 1
    else:
        rightwhite -= 1
    if leftblack + rightwhite < minDistance:
        minDistance = leftblack+rightwhite

print("{}".format(minDistance))

Solution (Python):
N=int(input())
S=input()
A=[]
a=S.count(".")
A.append(a)
for i in range(N):
    if S[i]=="
        a=a+1
    else:
        a=a-1
    A.append(a)
print(min(A))

Solution (Python):
from itertools import accumulate


N = int(input())
S = input()

black = [0]*N
white = [0]*N

for i, s in enumerate(S):
    if s == '
        black[i] = 1
    else:
        white[i] = 1


black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]

ans = []
for i in range(N+1):
    ans.append(black[i] + white[i])

print(min(ans))

Solution (Python):

"""
ある境目を考える。境目より左が全て白、境目より右が全て黒でなくてはいけない。
ゆえに、境目より左の黒の数と境目より右の白の数を数えれば、その境目における「変更が必要な石の数」がわかる。
よって、境目を端から端まで動かしてその中で最小の「変更が必要な石の数」を求めればよい。
"""
N = int(input())
str = input()
minDistance = 0

black = "
white = "."
leftblack = 0
rightwhite = 0

for i in range(N):
    if str[i] == white:
        rightwhite += 1

minDistance += rightwhite

for j in range(0, N):
    if str[j] == black:
        leftblack += 1
    else:
        rightwhite -= 1
    if leftblack + rightwhite < minDistance:
        minDistance = leftblack+rightwhite

print("{}".format(minDistance))

Solution (Python):
N=int(input())
S=input()
A=[]
r=S.count(".")
result=r
for i in range(N):
    if S[i]=="
        r=r+1
    else:
        r=r-1
    result=min(result,r)
print(result)

Solution (Python):
n=int(input())
s=input()
r=s.count(".")
ans=[r]
for i in s:
    if i=="
        r+=1
    else:
        r-=1
    ans.append(r)
print(min(ans))

Solution (Python):
N=int(input())
S=input()

blk=0
white=S.count(".")

ans=white

for n in range(N):
	if S[n]=="
		blk += 1
	else:
		white -= 1
	
	ans=min(blk+white,ans)


print(ans)

Solution (Python):
N = int(input())
S = list(input())

bcount = 0
wcount = 0
mins = []

for i in range(N):
    if S[i] == ".":
        wcount += 1

mins.append(wcount)
        
for i in range(N):
    if S[i] == '
        bcount += 1
    else:
        wcount -= 1
    mins.append(bcount + wcount)

print(min(mins))

Solution (Python):
N = int(input())
S = input()

w = S.count('.')
b = 0

k = w

for i in range(N):
    if S[i] == '.':
        w -= 1
    else:
        b += 1

    k = min(k, w + b)

print(k)

Solution (Python):


def solve():
    N = int(input())
    S = input()

    kuro_num = 0
    siro_num = 0
    for moji in S:
        if moji == "
            kuro_num += 1
        else:
            siro_num += 1

    if siro_num == N:
        print(0)
        exit()

    
    rest_kuro_num = kuro_num
    rest_siro_num = siro_num
    ans = siro_num
    for i in range(0, len(S)):
        num = rest_siro_num
        if S[i] == "
            num += 1 + (kuro_num - rest_kuro_num)
            rest_kuro_num -= 1
        else:
            num -= 1
            num += kuro_num - rest_kuro_num
            rest_siro_num -= 1
        ans = min(ans, num)

    print(ans)

"""
26
...
"""
if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
s = input()

left = 0
right = s.count(".")
res = min(right, s.count("
for i in range(n):
    if s[i] == "
        left += 1
    else:
        right -= 1
    res = min(res, left+right)

print(res)

Solution (Python):
N = int(input())
S = input()
left = 0
right = S.count(".")
ans = left + right

for c in S:
    if c == "
        left += 1
    else:
        right -= 1
    ans = min(ans, left + right)

print(ans)

Solution (Python):
N = int(input())
S = list(input())
b = S.count("
w = S.count(".")
ans = min(b,w)
if b>=1 and w>=1:
  cost = N-w
  for i in range(N-1, -1, -1):
    if S[i]=='.':
      cost+=1
    else: 
      cost-=1
      ans = min(ans,cost)
print(ans)

Solution (Python):
n = int(input())
s = input()
w = s.count('.')
b = 0
ans = w
for i in s:
  if i =='
    b += 1
    
  else:
    w -=1
  ans = min(ans,b+w)
print(ans)

Solution (Python):
n=int(input())
s=input()


w=s.count(".")
ans = w

for i in range(n):

    if s[i]=="
        w+=1
    if s[i]==".":
        w-=1
    ans=min(ans,w)
    
print(ans)

Solution (Python):
n = int(input())
l = list(input())

result = l.count(".")
boundary = l.count(".")
for i in range(n):
    if l[i] == ".":
        boundary -= 1
    else:
        boundary += 1
    result = min(result, boundary)    
print(result)

Solution (Python):
n = int(input())
s = input()
w = s.count('.')

ans = w
for i in s:
  if i =='
    w += 1
    
  else:
    w -=1
  ans = min(ans,w)
print(ans)

Solution (Python):
n=int(input())
s=input()
b=s.count("
w=s.count(".")
M=n
noww=0
for i in range(n-1):
    if s[i]==".":
        noww+=1
        if s[i+1]=="
            M=min(M,(i-noww+1)+w-noww)

print(min(b,w,M))

Solution (Python):
n=int(input())
s=input()
w=b=0
mn=0
for sk in s:
    if sk=="
        b+=1
    else:
        w-=1
    if mn>b+w:
        mn=b+w
print(mn-w)

Solution (Python):
N = int(input())
S = input()
ans = cnt = S.count(".")
for s in S :
    if s == "
        cnt += 1
    else :
        cnt -= 1
    ans = min(ans,cnt)
print(ans)

Solution (Python):
N = int(input())
S = input()

b = 0
w = S.count('.')
ans = w

for s in S:
  if s == '
    b += 1
  else:
    w -= 1
  ans = min(ans, b + w)

print(ans)

Solution (Python):
n = int(input())
s = input()
m = s.count(".")
ans = m
for i in range(n):
    if s[i] == "
        m += 1
    else:
        m -= 1
    ans = min(ans, m)
print(ans)

Solution (Python):
N = int(input())
S = input()
Bsum = [0] 
Wsum = [0] 
for i in range(N):
    Bsum += [Bsum[-1]+(1 if S[i]=="
    Wsum += [Wsum[-1]+(1 if S[N-i-1]=="." else 0)]
print(min([Bsum[i]+Wsum[N-i] for i in range(N+1)]))

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
S=input()

sm1=[0]*N
if S[0]=='
    sm1[0]=1
for i in range(1, N):
    sm1[i]=sm1[i-1]
    if S[i]=='
        sm1[i]+=1
sm2=[0]*N
if S[-1]=='.':
    sm2[-1]=1
for i in range(N-2, -1, -1):
    sm2[i]=sm2[i+1]
    if S[i]=='.':
        sm2[i]+=1

ans=INF
for i in range(1, N):
    ans=min(ans, sm1[i-1]+sm2[i])
print(min(ans, S.count('

Solution (Python):
def main():
    N = int(input())
    S = input()

    n_dot_right = S.count('.')
    n_hash_left = 0

    ans = [n_dot_right + n_hash_left]

    for c in S:
        if c == '.':
            n_dot_right -= 1
        else:
            n_hash_left += 1
        ans.append(n_dot_right + n_hash_left)

    print(min(ans))
    

main()

Solution (Python):
n = int(input())
s = str(input())


bl = s.count('
wh = s.count('.')
cnt = wh
mincnt = cnt
for i in range(n):
    if s[i] == '
        cnt += 1
    else:
        cnt -= 1
    mincnt = min(mincnt, cnt)

print(mincnt)