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):
N = int(input())
S = input()

penals1 = []
tmp1 = 0
penals2 = []
tmp2 = 0


N_even = (N % 2 == 0)
half_N = N // 2 if N_even else (N-1) // 2 

if N == 1:
    min_val = 0
else:
    for i in range(half_N):
        if S[i] == "
            tmp1 += 1
        penals1.append(tmp1)

        if S[N-1-i] == ".":
            tmp2 += 1
        penals2.append(tmp2)

    if N_even:
        min_val = penals1[half_N-1] + penals2[half_N-1] 

        j = 1
        for i in range(half_N, N):
            if S[i] == "
                tmp1 += 1
            
            val1 = tmp1 + penals2[half_N-1-j]

            if S[N-1-i] == ".":
                tmp2 += 1
            
            val2 = penals1[half_N-1-j] + tmp2

            min_val = min(min_val, val1, val2)
            j += 1

    else:
        first = True
        j = 0

        
        for i in range(half_N, N):
            if S[i] == "
                tmp1 += 1
            val1 = tmp1 + penals2[half_N-1-j]

            if S[N-1-i] == ".":
                tmp2 += 1
            val2 = penals1[half_N-1-j] + tmp2

            if first:
                min_val = min(val1, val2)
                first = False
            else:
                min_val = min(min_val, val1, val2)
            j += 1

    if S[N-1] == "
        tmp1 += 1
    if S[0] == ".":
        tmp2 += 1

    min_val = min(tmp1, tmp2, min_val)
print(min_val)

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

res = x

for c in s:
    if c == '
        x += 1
    else:
        x -= 1
    res = min(res , x)
print(res)

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

res = x

for c in s:
    if c == '
        x += 1
    else:
        x -= 1
    res = min(res , x)
print(res)

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


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


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


m = min(b + w for b, w in zip(leftB, rightW))
print(m)

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

ans = N

right = [S.count('
right.append(N-right[0])
left = [0, 0]

for s in S:
    ans = min(ans, left[0]+right[1])
    if s == '
        left[0] += 1
        right[0] -= 1
    else:
        left[1] += 1
        right[1] -= 1
print(min(ans, left[0]+right[1]))

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

w_N = S.count(".")
ans = w_N
b = 0
w = 0

for i, s in enumerate(S):
    if s == "
        b += 1
    if s == ".":
        w += 1
    ans = min(ans,b + w_N - w)

print(ans)

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

b = [0] * (N+1)
w = [0] * (N+1)

for i, s in enumerate(S):
    b[i+1] = b[i]
    w[i+1] = w[i]
    if s == "
        b[i+1] += 1
    if s == ".":
        w[i+1] += 1

ans = float('inf')

for i in range(N+1):
    ans = min(ans, b[i] + w[N] - w[i])

print(ans)

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

ans = S.count(".")
ans2 = ans

for i in S:
    if i == "
        ans2 += 1
    else:
        ans2 -= 1
    ans = min(ans, ans2)

print(ans)

Solution (Python):


def main():
    N = int(input())
    s = input()
    count_white = 0
    count_black = 0
    count_border = N

    if (not "." in s) or (not "
        print(0)
        return

    for i in s:
        if i == ".":
            count_white += 1
        elif i == "
            count_black += 1

    patern_border_white = 0
    patern_border_black = 0
    temp_border_white = 0
    temp_border_black = 0
    
    for i in range(N-1):
        if i == 0:
            if s[0] == "
                temp_border_white = 1
                temp_border_black = count_white

            else:
                temp_border_white = 0
                temp_border_black = count_white -1

        else :
            if s[i] == "
                temp_border_white = patern_border_white + 1
                temp_border_black = patern_border_black
            else :
                temp_border_white = patern_border_white
                temp_border_black = patern_border_black - 1

        if count_border > temp_border_white + temp_border_black :
            count_border = temp_border_white + temp_border_black

        patern_border_white = temp_border_white
        patern_border_black = temp_border_black

    print(min(count_white,count_black,count_border))
    return

if __name__ == "__main__":
    main()

Solution (Python):


def main():
    N = int(input())
    s = input()
    count_white = 0
    count_black = 0
    count_border = N
    
    

    if (not "." in s) or (not "
        print(0)
        return

    for i in s:
        if i == ".":
            count_white += 1
        elif i == "
            count_black += 1

    patern_border_white = 0
    patern_border_black = 0
    temp_border_white = 0
    temp_border_black = 0
    
    for i in range(N-1):
        if i == 0:
            if s[0] == "
                
                
                temp_border_white = 1
                temp_border_black = count_white

            else:
                
                
                temp_border_white = 0
                temp_border_black = count_white -1

        else :
            if s[i] == "
                
                
                temp_border_white = patern_border_white + 1
                temp_border_black = patern_border_black
            else :
                
                
                temp_border_white = patern_border_white
                temp_border_black = patern_border_black - 1

        if count_border > temp_border_white + temp_border_black :
            count_border = temp_border_white + temp_border_black

        patern_border_white = temp_border_white
        patern_border_black = temp_border_black

    print(min(count_white,count_black,count_border))

if __name__ == "__main__":
    main()

Solution (Python):


def main():
    N = int(input())
    s = input()
    count_white = 0
    count_black = 0
    count_border = N
    temp = ""
    patern3_white = [0]*N
    patern3_black = [0]*N
    
    if (not "." in s) or (not "
        print(0)
        return

    for i in s:
        if i == ".":
            count_white += 1
        elif i == "
            count_black += 1

    for i in range(N-1):
        if i == 0:
            if s[0] == "
                patern3_white[0] = 1
                patern3_black[0] = count_white
            else:
                patern3_white[0] = 0
                patern3_black[0] = count_white -1
        else :
            if s[i] == "
                patern3_white[i] = patern3_white[i-1] + 1
                patern3_black[i] = patern3_black[i-1]
            else :
                patern3_white[i] = patern3_white[i-1]
                patern3_black[i] = patern3_black[i-1] - 1
        

        if count_border > patern3_white[i] + patern3_black[i] :
            count_border = patern3_white[i] + patern3_black[i]

    
    
    
    
    
    
    
    
    print(min(count_white,count_black,count_border))

if __name__ == "__main__":
    main()

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

black0 = 0
white0 = 0
for i in range(n):
    if s[i] == '
        black0 += 1
    else:
        white0 += 1
        
black = 0
white = 0
best = min(black0, white0)
for i in range(n):
    if s[i] == '
        best = min(best, black + white0 - white)
        black += 1
    else:
        white += 1
        
print(best)

Solution (Python):
n = int(input())
s = input()
cum_sum = 0
black = s.count("
ans = n - black
for i, c in enumerate(s):
    if c == "
        cum_sum += 1
    ans = min(ans, cum_sum + n - i - 1 - (black - cum_sum))
print(ans)

Solution (Python):
from itertools import accumulate

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

black = [0] * n
white = [0] * n

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


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



ans = 1e10
for i in range(n+1):
    ans = min(ans, black[i] + white[i])

print(ans)

Solution (Python):
from collections import Counter

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

    res = dot = S.count(".")
    sha = 0
    

    for i in range(N):
        if S[i] == "
            sha += 1
        else:
            dot -= 1
        tmp = sha + dot
        res = min(tmp, res)
    print(res)
main()

Solution (Python):
from itertools import accumulate

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

black = [0] * n
white = [0] * n

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


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



ans = 1e10
for i in range(n+1):
    ans = min(ans, black[i] + white[i])

print(ans)

Solution (Python):
n = int(input())
input_str = input()
left_black = 0
right_white = input_str.count('.')
ans = [left_black + right_white]

for s in input_str:
  if( s == '
    left_black += 1
  if( s == '.' ):
    right_white -= 1
  ans.append(left_black + right_white)
print(min(ans))

Solution (Python):
import sys
from sys import stdin
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())
res = 10**9
ctb = 0
ctw = 0
bs = [0]*N
ws = [0]*N
for i in range(N):
    if S[i] == '.':
        ctw += 1
    else:
        ctb += 1
    bs[i] = ctb
    ws[i] = ctw
for i in range(N):
    res = min(res, bs[i]+ws[-1]-ws[i])
res = min(res, bs[-1], ws[-1])
print(res)

Solution (Python):
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)

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

res = dot = S.count(".")
sha = 0
for i in range(N):
    if S[i] == "
        sha += 1
    else:
        dot -= 1
    tmp = sha + dot
    res = min(res, tmp)

print(res)

Solution (Python):
N = int(input())
S = input()
ans = N
sumB = [0] * (N + 1)
tmp = 0
for i in range(N):
    if S[i] == '
        tmp += 1
    sumB[i+1] = tmp
for i in range(N+1):
    ans = min(sumB[i] + (N - i) - (sumB[N] - sumB[i]), ans)
    
print(ans)

Solution (Python):


















import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right



dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]
INF = float("inf")

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))

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

l = [0] * (N+1)

for i, si in enumerate(S):
    if si == "
        l[i+1] = l[i] + 1
    else:
        l[i+1] = l[i]

ans = INF
for i in range(0, N+1):
    l_black = l[i]
    r_white = (N - i) - (l[-1] - l[i])
    ans = min(ans, (l_black + r_white))

print(ans)

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
    elif s==".":
        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())
s = list(input())
ans = white = s.count('.')
black = 0
for i in s:
    if i == '.':
        white -= 1
    else:
        black += 1
    ans = min(ans,white+black)
print(ans)

Solution (Python):
n = int(input())
s = input()
bcnt = [0]*n
wcnt = [0]*n
result = 2 * 10 ** 5


if s[0] == "
    bcnt[0] = 1
if s[n-1] == ".":
    wcnt[n-1] = 1

for i in range(1,n):
    bcnt[i] = bcnt[i-1]
    if s[i] == "
        bcnt[i] += 1
for i in range(n-2,-1,-1):
    wcnt[i] = wcnt[i+1]
    if s[i] == ".":
        wcnt[i] += 1


for i in range(0,n-1):
    result = min(bcnt[i] + wcnt[i+1],result)

result = min(result,bcnt[n-1])
result = min(result,wcnt[0])

print(result)

Solution (Python):
SIRO = '.'
KURO = '
N = int(input())
S = input()
sCnt = S.count(SIRO)
kCnt = 0
ans = sCnt
for i in S:
    if i == KURO:
        kCnt += 1
    else:
        sCnt -= 1
    ans = min(ans, kCnt + sCnt)

print(ans)

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






nwhite, nblack = [], []

nwhite_current, nblack_current = 0, 0

for c in S:
    if c == '.':
        nwhite_current += 1
    else:
        nblack_current += 1

    nwhite.append(nwhite_current)
    nblack.append(nblack_current)

ans = 0

if nwhite_current != 0 and nblack_current != 0:

    ans = N + 1

    
    for i in range(N):

        ans_current = 0

        
        if i > 0:
            ans_current = nblack[i-1]

        
        ans_current += (nwhite_current - nwhite[i])

        ans = min(ans, ans_current)

print(ans)

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    INF = float("inf")
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input().rstrip())
    S = list(_ for _ in input())
    
    
    
    cnt_w = S.count('.') 
    cnt_b = 0 
    ans = cnt_w 
    for i in range(N): 
        if(S[i] == '
            cnt_b +=1
        else: 
            cnt_w -=1
        ans = min(ans,cnt_b+cnt_w)
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=_I()
S=input()


black=0
white=S.count(".")
ans=white
for idx in range(len(S)):
	if S[idx] == "
		black+=1
	else:
		white-=1
	ans=min(ans,black+white)


	
print(ans)

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

list_b = []
cnt_b = 0
list_w = []
cnt_w = 0
for i in range(n):
    if s[i] == "
        cnt_b += 1
    else:
        cnt_w += 1
    list_b.append(cnt_b)
    list_w.append(cnt_w)
ans = 2*10**5
for i in range(n):
    if ans > list_b[i] + list_w[n-1] - list_w[i]:
        ans = list_b[i] + list_w[n-1] - list_w[i]
print(min(ans,list_b[n-1],list_w[n-1]))

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
s = list(input())
res = 10**6
ctw = 0
ctb = 0
w = [0]*n
b = [0]*n

for i in range(n):
     if s[i] == ".":
          ctw += 1
     else:
          ctb += 1
     w[i]= ctw
     b[i]= ctb
for i in range(n):
     res = min(res,b[i]+w[-1]-w[i])
res = min(res,w[-1],b[-1])
print(res)

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

a = s.count('.')
b = 0

ans = a

for i in range(n):
    if s[i] == '
        b += 1
    else:
        a -= 1
    ans = min(ans,a+b)

print(ans)

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

left_black = 0
right_white = S.count('.')
ans = right_white

for i in range(N):
    if S[i] == '
        left_black += 1 
    else:
        right_white -= 1
    ans = min(ans, left_black + right_white)
print(ans)

Solution (Python):
from itertools import accumulate

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

B = [0] * N
W = [0] * N

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

B = [0] + B
B = list(accumulate(B)) 
W = [0] + W[::-1]
W = list(accumulate(W))[::-1] 

ans = []
for i in range(N+1):
    ans.append(B[i] + W[i])
print(min(ans))

Solution (Python):
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)

Solution (Python):
N = int(input())
S = 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)

Solution (Python):
N=input()
S=raw_input()
L=[0]

for i,x in enumerate(S):
	if x=="
		L.append( L[-1]+1 )
	else:
		L.append( L[-1] )
			

ans=float("inf")
for i in range(N+1):
	b=L[i]			
	w=N-i-(L[-1]-L[i])	
	ans=min(ans , b+w)

print ans

Solution (Python):
N=input()
S=raw_input()
L=[0]

for i,x in enumerate(S):
	if x=="
		L.append( L[-1]+1 )
	else:
		L.append( L[-1] )
			

ans=float("inf")
for i in range(N+1):
	b=L[i]	
	w=N-i-(L[-1]-L[i])
	ans=min(ans , b+w)

print ans

Solution (Python):
def C(N, S):
    n_diff_chars = S.count(".")
    cand_list = [n_diff_chars]
    for c in S:
        if c == ".":
            n_diff_chars -= 1
        else:
            n_diff_chars += 1
        cand_list.append(n_diff_chars)
    print(min(cand_list))


if __name__ == "__main__":
    N = int(input())
    S = input()
    C(N, S)

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

cnt = 0
cnt_black = 0
should_change = 0

cnt_black_arr = [0] * (N+1)

for i in range(N):
    if S[i] == '
        cnt_black += 1
    cnt_black_arr[i+1] = cnt_black

res = cnt_black
for i in range(N):
    num_black = N-i
    right_white = N - cnt_black - (i - cnt_black_arr[i])
    res = min(res, cnt_black_arr[i] + right_white)

print(res)

Solution (Python):
N = int(input())
S = input()
 
arr = [0] if S[0] == "." else []
b, w = 0, 0
for i in range(len(S)):
  if S[i] == ".":
    w += 1
  else:
    b += 1
  if S[i:i+2] == "
    arr.append(b)
  if S[i:i+2] == ".
    arr.append(w)
if S[-1] == ".":
  arr.append(w)

 
result = w
for i in range(0, len(arr), 2):
  result = min([arr[i]+w-arr[i+1], result])

print(result)

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

check=s_input.count('.')
ans=check
for s in s_input:
    if s=='.':
        
        check-=1
    else:
        check+=1
    ans=min(ans,check)
print(ans)

Solution (Python):
def C(N, S):
    cand = "
    n_diff_chars = sum(a!=b for a, b in zip(cand, S))
    min_n_diff_chars = n_diff_chars
    for c in S:
        if c == ".":
            n_diff_chars -= 1
        else:
            n_diff_chars += 1
        min_n_diff_chars = min(min_n_diff_chars, n_diff_chars)
    print(min_n_diff_chars)


if __name__ == "__main__":
    N = int(input())
    S = input()
    C(N, S)

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

ans =  S.count(".")
l = [0, ans]
for i in range(N):
    if S[i] == "
        l[0] += 1
    else:
         l[1] -= 1
    
    if ans > sum(l):
        ans = sum(l)
print(ans)

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

CW = 0

for s in S:
    if s == '.' : CW += 1
    
CB = 0
ans = (CB+CW)
for s in S:
    if s == '.' : CW -= 1
    if s == '
    ans = min(ans,CB+CW)
    
print(ans)

Solution (Python):
N=input()
s=input()

N=int(N)
wn=[]
bn=[]
a=0
b=0


wn.append(0)
for i in range(N):
    j=N-(i+1)
    if(s[j]=="."):
        a+=1
    if(s[i]=="
        b+=1
    bn.append(a)
    wn.append(b)

bn.reverse()
bn.append(0)




min=1000000
for i in range(N+1):
    score=bn[i]+wn[i]
    if(score<min):
        min=score

print(min)

Solution (Python):
n = int(input())
s = input()
sr = s[::-1]

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

Solution (Python):
n = int(input())
s = input()
w = 0
b = 0

for i in s:
    if i == ".":
        w += 1

m = w + b

for i in range(0, n):
    if s[i] == ".":
        w -= 1
    else:
        b += 1
    if w + b < m:
        m = w + b

print(m)

Solution (Python):
n = int(input())
s = input()
black = 0
ans = white = s.count('.')

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

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

b = [0]  
w = [0]  

count_b = 0
count_w = 0
for i in range(n):
    if s[i] == "
        
        count_b += 1
    else:
        
        count_w += 1
    b.append(count_b)
    w.append(count_w)

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

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

left_black = 0
right_white = 0

for s in S:
    if s == '.':
        right_white += 1

c_min = left_black + right_white

for i in range(N):
    if S[i] == '
        left_black += 1
    elif S[i] == '.':
        right_white -= 1
    c = left_black + right_white
    if c < c_min:
        c_min = c
print(c_min)

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

num = S.count('.')

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

print(min(anslist))

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


if S[0] == '.':
    count_white = [1]
    count_black = [0]
else:
    count_white = [0]
    count_black = [1]


for i in range(1, N):
    if S[i] == '.':
        
        count_white.append(count_white[i-1]+1)
        count_black.append(count_black[i-1])
    else:
        
        count_white.append(count_white[i-1])
        count_black.append(count_black[i-1]+1)

tmp = 9999999999
for i in range(1, N):
    min_sum = 0
    min_sum += count_black[i-1]
    min_sum += (count_white[N-1] - count_white[i])
    tmp = min(tmp, min_sum)



cnt = 0
target = S[0]
for i in range(1, N):
    if target == '
        cnt += 1
        target = '
        continue

    if S[i] == '
        target = '
    else:
        target = '.'

cnt_2 = 0
aim = S[-1]
for i in range(N-1, -1, -1):
    if aim == '.' and S[i] == '
        cnt_2 += 1
        aim = '.'
        continue

    if S[i] == '
        aim = '
    else:
        aim = '.'


print(int(min(cnt, cnt_2, tmp)))

Solution (Python):
N = int(input())
s = input()
l = []
b = 0
w = s.count(".")

for i in range(N):
    if s[i] == "
        l.append(b+w)
        b += 1
    else:
        w -= 1
        l.append(b+w)
print(min(l))

Solution (Python):
import sys
input=sys.stdin.readline
N=int(input())
S=input()
w=S.count('.')
c=w
for i in range(N):
  if S[i]=='.':
    w-=1
  else:
    w+=1
  c=min(c,w)
print(c)

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

Solution (Python):
from itertools import accumulate

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

false_black = [0] * n
false_white = [0] * n
for i, x in enumerate(s):
    if s[i] == "
        false_black[i] = 1
    else:
        false_white[i] = 1


ac_fb = [0] + false_black
ac_fb = list(accumulate(ac_fb))
ac_fw = [0] + false_white
ac_fw = list(accumulate(ac_fw))

ans = 10 ** 6
for i, x in enumerate(s):
    tmp_ans = ac_fb[i] + (ac_fw[-1] - ac_fw[i])
    ans = min(ans, tmp_ans)
    

print(min(ans, ac_fw[-1], ac_fb[-1]))

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

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())
s=input()
res=s.count('.')
ans=res

for i in range(n):
    if s[i]=='
        res+=1
    else:
        res-=1
    ans=min(ans,res)
print(ans)

Solution (Python):
import numpy as np
from itertools import accumulate
N =int(input())
S = input()

s = np.array(list(S))

k = np.where(s=="

l = [0] + list(accumulate(k))
ans = []
for i in range(N+1):
    p = l[i] +  N-i-l[N]+l[i]
    ans.append(p)

print(min(ans))

Solution (Python):
n = int(input())
s = input()
white = 0
black = 0
for i in range(n):
    if s[i] == ".":
        white += 1
ans = white + black
for j in range(n):
    if s[j] == ".":
        white -= 1
    else:
        black += 1
    if white + black < ans:
        ans = white + black
print(ans)

Solution (Python):
n = int(input())
s = input()
white = 0
black = 0
for i in range(n):
    if s[i] == ".":
        white += 1
ans = float("inf")
for j in range(n + 1):
    if white + black < ans:
        ans = white + black
    if j == n:
        break
    if s[j] == ".":
        white -= 1
    else:
        black += 1
print(ans)

Solution (Python):
N = int(input())
S = [i for i in input()]

flg = 0
idx = 0
for i in S:
    if i == '
        flg = 1
        break
    idx += 1

if flg == 1:
    a = S[idx+1:].count('.')
    b = S[idx:].count('
    if S[-1] == '
        for ct in range(1, N+1):
            if S[-ct] == '.':
                break
        b -= ct-1
    ans = min(a, b)
else:
    ans = 0

count_blk = []
count_wht = []

ct_blk = 0
ct_wht = 0
for i in S:
    if i == '
        ct_blk += 1
    else:
        ct_wht += 1
    count_blk.append(ct_blk)
    count_wht.append(ct_wht)

for i in range(N):
    ans = min(ans, count_blk[i] + ct_wht - count_wht[i])

print(ans)

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

r=s.count(".")
l=0
c=0
ans=r

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

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

ans = 0
kari = 0
for i in range(N):
        if S[i] == ".":
                ans += 1
                kari += 1
for j in range(N):
        if S[j] == "
                kari += 1
        elif S[j] == ".":
                kari -= 1
        if kari < ans:
                ans = kari
print(ans)

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

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

if '.' not in S or '
  print(0)
  sys.exit()
  
l = 0  
r = S.count('.')  
ans = l+r
for s in S:
  if s == '.':
    r -= 1
  else:
    l += 1
  ans = min(l+r, ans)

print(ans)

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

count_w = s.count('.')
count_b = 0
ans = count_w + count_b

for si in s:
    if si == '.':
        count_w -= 1
    else:
        count_b += 1
    now = count_w + count_b
    if now < ans:
        ans = now

print(ans)

Solution (Python):
n = int(input())
s = input()
bs = 0
ws = s.count('.')
ans = ws
for c in s:
    if c == '.':
        ws -= 1
    else:
        bs += 1
    now = ws + bs
    if ans > now:
        ans = now
print(ans)

Solution (Python):
input()

minv = res = rd = 0
for e in input():
    if e == ".":
        res += 1
        rd -= 1
        if rd < minv:
            minv = rd
    else:
        rd += 1

print(res + minv)

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

minv = res = rd = 0
for e in input():
    if e == ".":
        res += 1
        rd -= 1
        minv = min(minv, rd)
    else:
        rd += 1

print(res + minv)

Solution (Python):

def count(s):
    w = s.count('.')
    candidate = w
    for i in range(len(s)):
        if s[i] == '
            w += 1
        else:
            w -= 1
        candidate = min(candidate, w)

    return candidate


def main():
    _ = int(input())
    s = input()  

    print(count(s))


main()

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

tmp = S.count('.')
ans = tmp
for i in range(N):
    if S[i] == '.':
        tmp -= 1
    else:
        tmp += 1
    ans = min(ans, tmp)
    
print(ans)

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



w = S.count('.')

ans = 10**9
cost = 0
for c in S:
    if c == '.':
        
        w -= 1
        
        if w + cost < ans:
            ans = w + cost
    else:
        
        if w + cost< ans:
            ans = w + cost
        
        cost += 1

print(ans)

Solution (Python):
n = int(input())
s = list(input())
b = [0]*(n)
w = [0]*(n)
if n == 1:
    print(0)
    exit()
if s[0] ==".":
    w[0] =1
else:
    b[0] =1

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

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

Solution (Python):
N = int (input ())
S = str (input ())
S = '.' + S
N += 1
cnt = 0
inf = int(1e9)

A = list(range(N))
for i in range(N):
    A[i] =[inf,inf]
A[0][0] = A[0][1] = 0
for i in range (1,N):
    for j in range (2):
        if j == 1:
            if S[i] == '.':
                A[i][j] = min(A[i][j], A[i-1][0] + 1)
                A[i][j] = min(A[i][j], A[i-1][1] + 1)
            else:
                A[i][j] = min(A[i][j], A[i-1][0] )
                A[i][j] = min(A[i][j], A[i-1][1] )
        else:
            if S[i] == '
                A[i][j] = min(A[i][j], A[i-1][0] + 1)
            else:
                A[i][j] = min(A[i][j], A[i-1][0])                

ans = min(A[N-1][0],A[N-1][1])

print (ans)

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


print(ans)

Solution (Python):
n = int(input())
s = input()
blacks_in_left = [0 for i in range(n+1)]
whites_in_right = [0 for i in range(n+1)]
for i in range(n):
  blacks_in_left[i+1] = blacks_in_left[i] + int(s[i] == '
  whites_in_right[n-1-i] = whites_in_right[n-i] + int(s[n-1-i] == '.')

res = n + 1
for i in range(n+1):
  
  res = min(res, blacks_in_left[i] + whites_in_right[i])
  


print(res)

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


stone_list = []
tmp = 1
for i in range(N):
    if i == N-1:
        stone_list.append(tmp)
        break
    if S[i+1] != S[i]:
        stone_list.append(tmp)
        tmp = 1
    else:
        tmp += 1
        

if S[0] == '
    stone_list = [0] + stone_list
if S[N-1] == '
    stone_list = stone_list + [0]

tmp = sum(stone_list[2::2])
ans = tmp
for i in range(1,len(stone_list)-1,2):
    tmp = tmp + stone_list[i] - stone_list[i+1]
    if tmp < ans:
        ans = tmp
print(ans)