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):
def solve():
  n = int(input())
  s = input()
  
  leftblack = 0
  leftwhite = 0
  rightblack = s.count('
  rightwhite = s.count(".")
  
  ans = leftblack+rightwhite
  
  for i in range(n):
    if s[i] == "
      leftblack += 1
      rightblack -= 1
    else:
      leftwhite += 1
      rightwhite -= 1
    ans = min(ans,leftblack+rightwhite)
  
  print(ans)
solve()

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

Solution (Python):


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

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

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):

    
    black = sum_b[i]
    
    white = sum_w[n]-sum_w[i]

    ans = min(ans, black + white)
print(ans)

Solution (Python):



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)

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

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

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

print(ans)

Solution (Python):
n = int(input())
s = input()
bool = []
for i in s:
    if i == "
        bool.append(1)
    else:
        bool.append(0)
black = sum(bool)
bool_t = [0]
for i in range(n):
    bool_t.append(bool[i] + bool_t[i])
ans = float("inf")
for i in range(n + 1):
    ans = min(ans, bool_t[i] + n - black - (i - bool_t[i]))
print(ans)

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(tmp, ans)
    
print(ans)

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

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

count = 0
brack_stone_num = 0
white_stone_num = 0
WtoB_stone_num = 0
for i in range(N-1, -1, -1):
    if S[i] == "
        if  white_stone_num == 0:
            brack_stone_num = 0
        else:
            brack_stone_num += 1
        if brack_stone_num > white_stone_num:
            WtoB_stone_num += white_stone_num
            brack_stone_num = 0
            white_stone_num = 0
    else:
        white_stone_num += 1
    
print(brack_stone_num + WtoB_stone_num)

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

w = 0
e = s.count('.')
result = e

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

    result = min(result, w+e)

print(result)

Solution (Python):
n=int(input())
s=list(input())
sharp=[0]*n
dot=[0]*n
if s[0]=="
    sharp[0]+=1
else:
    dot[0]+=1
for i in range(1,n):
    if s[i]=="
        sharp[i]=sharp[i-1]+1
        dot[i]=dot[i-1]
    else:
        sharp[i]=sharp[i-1]
        dot[i]=dot[i-1]+1
MIN=3*10**6
for i in range(n):
    if s[i]=="
        MIN=min(MIN,(sharp[i]-1)+(dot[-1]-dot[i]))
    else:
        MIN=min(MIN,sharp[i]+(dot[-1]-dot[i]))
print(MIN)

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

Solution (Python):
N = int(input())
S = input()
b = S.count(".")    
w = 0               
ans = b

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

    else:
        b -= 1
    t = w + b
    ans = min(ans, t)

print(ans)

Solution (Python):
N = int(input())
S = input()
i = 0
b = S.count('.')
w = 0
min = b
for i in range(N):
    if S[i] == '
        w += 1
    else:
        b -= 1
    
    T = b + w
    if T < min:
        min = T

print(min)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,random
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
S = input()
Sum_White = [0]
Sum_Black = [0]

tmp_w = tmp_b = 0
for s in S:
    if s == '
        tmp_b += 1
    else:
        tmp_w += 1
    Sum_Black.append(tmp_b)
    Sum_White.append(tmp_w)


ans = INF
for i in range(N+1):
    tmp = Sum_Black[i] + (Sum_White[N]-Sum_White[i])
    ans = min(ans,tmp)
    

print(ans)

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

Solution (Python):
from __future__ import print_function
import numpy as np
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n=int(input())
S=list(input())
array0=np.zeros(n,dtype=int)
array1=np.zeros(n,dtype=int)
array2=np.zeros(n,dtype=int)

array0[0]= 1 if S[0]=='
for i in range(1,n):
    array0[i]= array0[i-1]+1 if S[i]=='


array1[n-1]= 1 if S[n-1]=='.' else 0
for i in range(n-2,-1,-1):
    array1[i]= array1[i+1]+1 if S[i]=='.' else array1[i+1]
    
for i in range(0,n):
    array2[i]=array0[i]+array1[i]
eprint(array0)
eprint(array1)
eprint(array2)
    
print(min(array2)-1)

Solution (Python):
N = int(input())
S = [1 if i == "." else 0 for i in input()]





rw = sum(S)

lb = 0
min_temp = rw+lb
for idx,s in enumerate(S):
    
    if s==0:
        
        lb += 1
    
    elif s==1:
        rw -= 1
    
    min_temp = min([min_temp,rw+lb])
    if min_temp == 0:break
print(min_temp)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    S = input()

    if '
        print(0)
        exit()

    b_num = 0
    w_num = S.count('.')
    ans = 10e6

    for i in range(N+1):
        ans = min(ans, b_num + w_num)
        if i != N:
            if S[i] == '
                w_num += 1
            else:
                b_num -= 1

    print(ans)

Solution (Python):



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

white = S.count('.')
black = N - white

l_white = 0
l_black = 0
r_white = white
r_black = black

cost = l_black + r_white

for s in S:
    if s == '.':
        l_white += 1
        r_white -= 1
    else:
        l_black += 1
        r_black -= 1
    cost = min(cost, l_black + r_white)
    
print(cost)

Solution (Python):
N = int(input())
S = input()
N = [[0 for _ in range(2)] for _  in  range(len(S))]

B,W = 0,1

for idx,s in enumerate(S):
  if s is "
    N[idx][B] = N[idx-1][B] + 1
    N[idx][W] = N[idx-1][W]
  else:
    N[idx][B] = N[idx-1][B]
    N[idx][W] = N[idx-1][W] + 1

print(int(min([N[i][B]+N[-1][W]-N[i][W] for i in range(len(S)-1)]+[N[-1][W],N[-1][B]]   )))

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

black_point = 0
turn_to_white = 0
turn_to_black = s.count(".")
min_turn = turn_to_black
previous_s = s[0]

for i, current_s in enumerate(s[1:]):
	if previous_s == "
		turn_to_white += 1
	else:
		turn_to_black -= 1
	min_turn = min(turn_to_white + turn_to_black, min_turn)
	previous_s = current_s

if s[-1] == "
	turn_to_white += 1
else:
	turn_to_black -= 1
min_turn = min(turn_to_white + turn_to_black, min_turn)

print(min_turn)

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

import numpy as np

N = np.zeros((len(S),2))
B,W = 0,1

for idx,s in enumerate(S):
  if s is "
    N[idx,B] = N[idx-1,B] + 1
    N[idx,W] = N[idx-1,W]
  else:
    N[idx,B] = N[idx-1,B]
    N[idx,W] = N[idx-1,W] + 1

print(int(min([N[i,B]+N[-1,W]-N[i,W] for i in range(len(S)-1)]+[N[-1,W],N[-1,B]]   )))

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

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
	
def main():
	N = int(input())
	S = input()
	
	if N == 1:
		print(0)
		sys.exit()
	
	kuro = []
	for i, val in enumerate(S):
		if i == 0:
			if val == "
				kuro.append(1)
			else:
				kuro.append(0)
			continue
		if val == "
			kuro.append(kuro[i-1] + 1)
		else:
			kuro.append(kuro[i-1])
	
	shiro = [0 for _ in range(N)]
	for i in range(N-1, -1, -1):
		if i == N-1:
			if S[i] == ".":
				shiro[i] = 1
			else:
				shiro[i] = 0
			continue
		if S[i] == ".":
			shiro[i] = shiro[i+1] + 1
		else:
			shiro[i] = shiro[i+1]
			
	ans = -1
	for i in range(N):
		if i == 0:
			continue
		tmp = kuro[i-1] + shiro[i]
		if ans > tmp or ans == -1:
			ans = tmp
	
	
	
	print(min(ans,shiro[0],kuro[N-1]))
	
	
if __name__ == "__main__":
	main()

Solution (Python):
from functools import reduce
l = int(input())
src = list(map(lambda x: 1 if x=="." else 0, input()))
lb = 0
rw = sum(src)
a = rw
for i in range(l):
  if src[i]==0:
    lb+=1
  else:
    rw-=1
  a = min(a, lb + rw)
  if a==0:
    break
print(a)

Solution (Python):
from functools import reduce
l = int(input())
src = list(map(lambda x: 1 if x=="." else 0, input()))
left_black = 0
right_white = sum(src)
ans = right_white
for i in range(l):
  if src[i]==0:
    left_black+=1
  else:
    right_white-=1
  ans = min(ans, left_black + right_white)
  if ans==0:
    break
print(ans)

Solution (Python):
n = int(input())
s = input()
black_in_left = 0
white_in_right = s.count('.')
ans = black_in_left + white_in_right

for x in s:
    if x == '
        black_in_left += 1
    if x == '.':
        white_in_right -= 1
    cost = black_in_left + white_in_right
    ans = min(ans, cost)
print(ans)

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

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

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

print(ans)

Solution (Python):
N = int(input())
S = input()
ans = S.count(".")
b = 0
w = ans
for i in S:
    if i == "
        b += 1
    else:
        w -= 1

    ans = min(ans, w + b)

print(ans)

Solution (Python):
N=int(input())
S=input()
list1=[0]*N
for i in reversed(range(N)):
    if i==N-1 and S[i]==".":
        list1[i]+=1
    elif i==N-1:
        list1[i]=0
    elif S[i]==".":
        list1[i]=list1[i+1]+1
    else:
        list1[i]=list1[i+1]   
list2=[]
for i in range(N+1):
    if i==0:
        tmp=N-list1[0]
    elif i==N:
        tmp=list1[0]
    else:
        tmp=i-list1[0]+2*list1[i]
    list2.append(tmp)
print(min(list2))

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

white = S.count('.')
black = 0
ans = white + black

for x in S:
    if x == '.':
        white -= 1
    else:
        black += 1
    ans = min(ans, white+black)

print(ans)

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

c_b = 0
c_w = S.count('.')
sum = []

for i in S:
        if i == '.':
                c_w = c_w - 1
        sum.extend([c_b+c_w])
        if i == '
                c_b = c_b + 1

print(min(sum))

Solution (Python):
N = int(input())
S = input()
b = S.count(".")
c = 0
d = N
for i in range(0, N):
    if S[i] == ".":
        b -= 1
        d = min(b+c, d)
    if S[i] == "
        c += 1
        d = min(b + c -1, d)
print(d)

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

Solution (Python):
N = int(input())
S = input()
min = N
clm_sum = [0]
for s in S:
    if s == '
        clm_sum.append(clm_sum[-1] + 1)
    else:
        clm_sum.append(clm_sum[-1])
for i in range(1,len(clm_sum)):
    if clm_sum[i-1] + ((N - i) - (clm_sum[-1] - clm_sum[i])) < min:
        min = clm_sum[i-1] + ((N - i) - (clm_sum[-1] - clm_sum[i]))
print(min)

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

a,b = 0,0
for i in s:
    if i == '.':
        a += 1 
    else:
        b += 1 

min_c = c = 10**10
counta, countb = 0, 0
for k, i in enumerate(s):
    if s[k] == '.':
        counta += 1
    if s[k] == '
        countb += 1
        c = (a - counta) + (countb - 1)
    if min_c > c:
        min_c = c
        
print(min(a,b, min_c))

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

left = [0]*(n+1)
right = [0]*(n+1)
for i in range(n):
    left[i+1] = left[i] + (s[i] == "
    right[n-i-1] = right[n-i] + (s[n-i-1] == ".")
v_min = n + 1
for i in range(n+1):
    v = left[i] + right[i]
    if v_min > v:
        v_min = v
print(v_min)

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

c_b = 0
c_w = S.count('.')
sum = []

for i in S:
	if i == '.':
		c_w = c_w - 1
	sum.extend([c_b+c_w])
	if i == '
		c_b = c_b + 1

print(min(sum))

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

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

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

print(ans)

Solution (Python):


N = int(input())
S = input()
black = 0
white = 0
l = [] 

for s in S:
    if s == "
        black += 1
    else:
        white += 1

if white == 0:
    print(0)
    
else:
    leftBlack = 0
    rightWhite = white
    l.append(leftBlack + rightWhite)
    for s in S:
        if s == "
            leftBlack += 1
        else:
            rightWhite -= 1
            
        l.append(leftBlack + rightWhite)
        
    print(min(l))

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

Solution (Python):


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




sum_black = [0]
sum_white = [0]
for n in range(0,N):
    if S[n] == '
        sum_black.append(sum_black[n] + 1)
        sum_white.append(sum_white[n] + 0)
    else:
        sum_black.append(sum_black[n] + 0)
        sum_white.append(sum_white[n] + 1)

num_min = N
for n in range(0,N+1):
    num = sum_black[n] + (sum_white[-1] - sum_white[n]) 
    if num < num_min:
        num_min = num

print(num_min)

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

for i in range(len(S)):
    if S[i] == ".":
        right -= 1
    else:
        left += 1

    ans = min(ans, left + right)
  
print(ans)

Solution (Python):
n=int(input())
s=input()
w=[0]*n
b=[0]*n
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=min(w[n-1], b[n-1])
for i in range(1, n):
    ans=min(ans, b[i-1]+w[n-1]-w[i-1])
print(ans)

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

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

print(ans)

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

wlist=[0 for i in range(n)]
blist=[0 for i in range(n)]

wnum=0
bnum=0

for i in range(n):
  if s[i]=='.':
    wnum+=1
  else:
    bnum+=1
  wlist[i]=wnum
  blist[i]=bnum


ans=float('inf')  
for i in range(n):
  ans=min(ans,wlist[-1]-wlist[i]+blist[i])
  
ans=min(ans,wlist[-1],blist[-1])

print(ans)

Solution (Python):
N = int(input())
S = input()
whsum = [0]*(N+1)
blsum = [0]*(N+1)
for i in range(N):
    whsum[i+1] = whsum[i]+(1 if S[i]=="." else 0)
    blsum[i+1] = blsum[i]+(1 if S[i]=="
res = 10**6
for left in range(N+1):
    tmp = 0
    tmp += blsum[left]-blsum[0]
    tmp += whsum[N]-whsum[left]
    res = min(res,tmp)
print(res)

Solution (Python):


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

    whitestones = []
    tmpcount = 0
    for stone in S:
        if stone == '.':
            tmpcount += 1
        whitestones.append(tmpcount)

    totalwhite = whitestones[-1]

    print(min(min(i - wstone + totalwhite - wstone for i, wstone in enumerate(whitestones, start=1)), totalwhite))


if __name__ == '__main__':
    main()

Solution (Python):
_ = int(input())
S = input()
ans = 10**9
cost = S.count('.')
for s in S:
    cost -= s == '.'
    ans = cost if cost< ans else ans
    cost += s == '
print(ans)

Solution (Python):
N = int(input())
S = input()
w = S.count('.')

ans = 10**9
cost = 0
for s in S:
    w -= s == '.'
    ans = w + cost if w + cost< ans else ans
    cost += s == '
print(ans)

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

Solution (Python):
def solve(N,S):
	num_b = 0
	counter=["0"]*N
	pointer = []
	flag = 0;
	for i in range(N):
		if(S[i]=='
			if(flag==0):
				counter[i]=num_b
				flag=1
				pointer.append(i)
			num_b+=1
		elif(S[i]=='.'):
			flag=0
	if(pointer==[]):return 0
	min_change=N+1
	for i in pointer:
		
		a = counter[i] + (num_b - counter[i])
		if(min_change>a):min_change=a
		
		a = (i - counter[i]) + (N - i - (num_b - counter[i]))
		if(min_change>a):min_change=a
		
		a = counter[i] + (N - i - (num_b - counter[i]))
		if(min_change>a):min_change=a

	return min_change



if __name__ == '__main__':
	N = int(input())
	S = input()
	print(solve(N,S))

Solution (Python):
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == '.':
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
A = cw[N - 1]
for i in range(N):
    A = min(A, cb[i] + cw[N - 1] - cw[i])
print(A)

Solution (Python):
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == '.':
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
A = cw[i]
for i in range(N):
    A = min(A, cb[i] + cw[N - 1] - cw[i])
print(A)

Solution (Python):

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

s = s.rstrip('
s = s.lstrip('.')

def seek(n, s):
    turn_to_black = s.count('.')
    current_min = turn_to_black
    turn_to_white = 0

    if current_min == 0 or current_min == len(s):
        return(0)
    
    for i in range(len(s)):
        if s[i] == '
            turn_to_white +=1
        else:
            turn_to_black -=1
        current_min = min(current_min, turn_to_black + turn_to_white)
    return current_min
print(seek(n, s))

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

s = s.rstrip('
s = s.lstrip('.')

if len(set(s)) <= 1:
    print(0)
    exit(0)

turn_to_black = s.count('.')
current_min = turn_to_black
turn_to_white = 0

for i in range(len(s)):
    if s[i] == '
        turn_to_white +=1
    else:
        turn_to_black -=1
    current_min = min(current_min, turn_to_black + turn_to_white)
print(current_min)

Solution (Python):
n = int(input())  
str = list(input())  
dotto = str.count(".")
ans = dotto
syapu = 0

for i in range(0, n):
    if str[i] == ".":
        dotto -= 1
    else:
        syapu += 1

    if dotto + syapu < ans:
        ans = dotto + syapu

print(ans)

Solution (Python):
N = int(input())
S = input()
c = []
c.append(S.count('.'))

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

  if S[i-1] == '.':
    c.append(c[i-1] - 1)   

print(min(c))

Solution (Python):
N = int(input())
S = input()
tmp = 0
for i in range(N):
    if S[i] == '.': tmp += 1
minVal = tmp

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

Solution (Python):


import sys
import copy

sys.setrecursionlimit(1000000)






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

W = S.count('.')
B = S.count('

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

w_p_dp, b_p_dp = [0] * (N + 1), [0] * (N + 1)
for i in range(N):
    w_p_dp[i + 1] = w_p_dp[i] + w_dp[i]
    b_p_dp[i + 1] = b_p_dp[i] + b_dp[i]

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

print(ans)

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

all_black_num = S.count('
all_white_num = N - all_black_num

if all_black_num == 0 or all_white_num == 0:
    ans = 0
else:
    left_black_num = 0
    left_white_num = 0
    right_white_num = all_white_num - left_white_num
    right_black_num = all_black_num - left_black_num
    ans = left_black_num + right_white_num
    for i, c in enumerate(S):
        if c == '
            left_black_num += 1
        elif c == '.':
            left_white_num += 1
        right_white_num = all_white_num - left_white_num
        right_black_num = all_black_num - left_black_num
        ans = min(ans, left_black_num + right_white_num)
        if right_black_num == N - i - 1:
            break
print(ans)

Solution (Python):
N = int(input())
S = list(input())
S.insert(0,0)

w = S.count(".")
black = 0
white = w
ans = 2e5
for i in range(N+1):
    if S[i] == "
        black += 1
    elif S[i] == ".":
        white -= 1
    
    ans = min(black + white, ans)
print(ans)

Solution (Python):
_,s=open(0);a=[s.count('.')]
for i in s:a+=a[-1]+(i<'.'or-1),
print(min(a))

Solution (Python):
_,s=open(0);a=[s.count('.')]
for i in s:a+=a[-1]+(i<'.'or-1),
print(min(a))

Solution (Python):
_,s=open(0);c=s.count('.');a=[c]
for i in s:c+=i<'.'or-1;a+=c,
print(min(a))

Solution (Python):
_=input()
S=input()
numc=0
numw=0
numcmin=0
for s in S:
    if s == '
        numc += 1
    else:
        numw += 1
        numc -= 1
        if numc < numcmin:
            numcmin = numc
print(numcmin+numw)

Solution (Python):
_=input()
S=input()
numc=0
numw=0
numcmin=0
for s in S:
    if s == '
        numc = numc + 1
    else:
        numw = numw + 1
        numc = numc - 1
        if numc < numcmin:
            numcmin = numc
print(numcmin + numw)

Solution (Python):

N = int(input())
S = input()
ans = 10 ** 9
white = [0] * (N + 1)
black = [0] * (N + 1)

for i, c in enumerate(S):
    if c == ".":
        white[i + 1] = white[i] + 1
        black[i + 1] = black[i]
    else:
        white[i + 1] = white[i]
        black[i + 1] = black[i] + 1

ans = min(ans, black[N], white[N])

white_sum = white[N]

for i in range(1, N):
    a = white_sum - white[i]
    b = black[i]
    
    
    cnt = a + b
    ans = min(ans, cnt)
print(ans)

Solution (Python):
_,S=input(),input()
numw=S.count('.')
numc,numcmin=0,0
for s in S:
    if s == '
        numc = numc + 1
    else:
        numc = numc - 1
        if numc < numcmin:
            numcmin = numc
print(numcmin+numw)

Solution (Python):
_,S=input(),input()
numc,numw,numcmin=0,0,0
for s in S:
    if s == '
        numc = numc + 1
    else:
        numw = numw + 1
        numc = numc - 1
        if numc < numcmin:
            numcmin = numc
print(numcmin + numw)

Solution (Python):
_ = input()
S = input()
numc = S.count('.')
numcmin = numc
for s in S:
    if s == '
        numc = numc + 1
    else:
        numc = numc -1
        if numc < numcmin:
            numcmin = numc
print(numcmin)

Solution (Python):

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

ans_all_black = 0   
ans_all_white = 0   
ans_right_black = 100 










all_white = 0
left_white=[]

for i in range(N):
  if S[i]==".":
    all_white  = all_white + 1
    if i==0:
      left_white.append(1) 
    else:
      left_white.append(left_white[i-1]+1) 
  else:
    if i==0:
      left_white.append(0) 
    else:
      left_white.append(left_white[i-1])
    
ans_all_black = all_white     
ans_all_white = N - all_white 




ans_right_black = N


for i in range(N):
  
  
  ans_right_black = min(i + 1 - left_white[i] + ans_all_black - left_white[i] , ans_right_black)
  
ans = min(ans_all_white,ans_all_black,ans_right_black)
print(ans)

Solution (Python):
N = int(input())
S = input()
ws = S.count('.')
bs = 0
ans = ws + bs
for i in range(N):
    if S[i] == '
        bs += 1
    else:
        ws -= 1
    ans = min(ans, ws + bs)
print(ans)

Solution (Python):




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

bl = [0] * (n+1)
wl = [0] * (n+1)

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


mins = 10**6
for i in range(0, n+1):
    wks = bl[i] + (wl[n] - wl[i])
    if mins > wks:
        mins = wks


print(mins)

Solution (Python):
N = int(input())
S = input()
 
sm_w = [0]*(N+1)
sm_b = [0]*(N+1)
 
for i in range(N):
    s = S[i]
    sm_w[i+1] += sm_w[i]
    sm_b[i+1] += sm_b[i]
    if s == '.':
        sm_w[i+1] += 1
    else:
        sm_b[i+1] += 1
 
ans = 2**60
for i in range(N+1):
    left_b = 0
    if i!=0:
        left_b = sm_b[i]
    right_w = 0
    if i!=N:
        right_w = sm_w[N] - sm_w[i]
    ret = left_b + right_w
    ans = min(ans, ret)
print(ans)

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

sm_w = [0]*(N+1)
sm_b = [0]*(N+1)

for i in range(N):
    s = S[i]
    sm_w[i+1] = sm_w[i]
    sm_b[i+1] = sm_b[i]
    if s == '.':
        sm_w[i+1] += 1
    else:
        sm_b[i+1] += 1

ans = 2**60
for i in range(N+1):
    left_b = sm_b[i] - sm_b[0]
    right_w = sm_w[N] - sm_w[i]
    ret = left_b + right_w
    ans = min(ans, ret)
print(ans)

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

w_sum = [0]
b_sum = [0]
for i in range(len(s)):
    if s[i] == '.':
        w_sum.append(w_sum[-1] + 1) 
        b_sum.append(b_sum[-1])
    else:
        b_sum.append(b_sum[-1] + 1)
        w_sum.append(w_sum[-1])

assert len(w_sum) == len(b_sum)
assert len(w_sum) == len(s) + 1

minSum = 10 ** 5
for i in range(len(s)):
    minSum = min(minSum, b_sum[i] + (w_sum[-1] - w_sum[i+1]))
    
print(minSum)

Solution (Python):
n = int(input())
s = list(input())
white = s.count(".")
black = s.count("

color_dict = [{"w": 0, "b": 0} for x in range(n)]
for index in range(n):
    if s[index] == ".":
        color_dict[index]["w"] += 1 if index == 0 else color_dict[index-1]["w"] + 1
        color_dict[index]["b"] = color_dict[index-1]["b"]
    else:
        color_dict[index]["b"] += 1 if index == 0 else color_dict[index-1]["b"] + 1
        color_dict[index]["w"] = color_dict[index-1]["w"]

res = float("inf")
for colors in color_dict:
    w = colors["w"]
    b = colors["b"]
    res = min(res, b+(white-w))
print(min(white, black, res))

Solution (Python):
n = int(input())
s = list(input())
n_r_b = s.count('
n_r_w = s.count('.')
n_l_b = 0
n_l_w = 0
ans = n
for i in range(n):
    ans = min(ans,n_l_b+n_r_w)
    if s[i] == '.':
        n_l_w += 1
        n_r_w -= 1
    else:
        n_l_b += 1
        n_r_b -= 1
ans = min(ans,n_l_b+n_r_w)
print(ans)

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

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

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):
from itertools import accumulate

n = int(input())
s = input()
res = 10**5
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()
dot_count = S.count('.')
ans = dot_count

for i in range(N):
    dot_count += 1 if S[i] == '
    ans = min(dot_count,ans)

print(ans)

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

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



list_ = []
last = "."
counter = 0
for i in range(n):
    now = s[i]
    if now != last:
        list_.append(counter)
        counter = 0
    counter += 1
    last = now
list_.append(counter)

if len(list_)%2==1:
    list_.append(0)




list_w = []
list_w.append(0)
list_w.append(0)
c_w = 0
list_b = []
list_b.append(0)
list_b.append(0)
c_b = 0
for i in range(0,len(list_),2):
    c_w += list_[-1*i-2]
    c_b += list_[i+1]
    list_w.append(c_w)
    list_b.append(c_b)
    



list_count = []
for i in range(0,len(list_w)):
    list_count.append(list_b[i]+list_w[-1*i-1])
    


print(min(list_count))

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

suu = []
s_count = S.count('.')
k_count = 0
suu.append(s_count + k_count)
for i in range(N):
    if S[i] == "
        k_count += 1
    else:
        s_count -= 1
    suu.append(k_count + s_count)

print(min(suu))

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

white_all = S.count('.')
ans = white_all

white = 0
black = 0
for i, s in enumerate(S):
    if s is '.':
        white += 1
    else:
        black += 1
    ans = min(black+(white_all-white), ans)

print(ans)

Solution (Python):
N = int(input())
S = list(input())
Black_num,White_num = 0,0

for i in range(N):
 if(S[i] == '
 elif(S[i] == '.'): White_num += 1

tmp_Black_num,tmp_White_num = 0,0

ans1 = White_num 
ans2 = Black_num 
ans = min(ans1,ans2)
for i in range(N):
 if(S[i] == '
 elif(S[i] == '.'): tmp_White_num += 1
 tmp = tmp_Black_num 
 tmp += White_num - tmp_White_num 
 ans = min(ans,tmp)
print(ans)

Solution (Python):
def main():
    N = int(input())
    S = input()
    count_white = 0
    count_black = 0
    count_white_R = S.count('.')
    count_black_R = S.count('
    min_rev = count_black + count_white_R
    for i in range(len(S)):
        if S[i] == '
            count_black += 1
            count_black_R -= 1
        else:
            count_white += 1
            count_white_R -= 1
        rev = count_black + count_white_R
        min_rev = min(rev,min_rev)
    print(min(min_rev,S.count('.'),S.count('

if __name__ == "__main__":
    main()