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

kind = []
stone = []
s = 0

for i in range(N):
    if i == 0:
        kind.append(S[i])
        s += 1
    elif S[i-1] != S[i]:
        stone.append(s)
        kind.append(S[i])
        s = 1
    else:
        s += 1
    if i == N-1:
        stone.append(s)

if len(kind)==1:
    print(0)
elif len(kind)==2 and kind[0]=='
    print(min(stone[0],stone[1]))
else: 
    min = 0
    
    if kind[0] == '.':
        start = 1
    else:
        start = 0 
    
    for i in range(start+1,len(stone),2):
        min += stone[i]

    
    for i in range(start,len(stone),2):
        if i==start:
            tmp = min
        else:
            tmp += stone[i-2]
            tmp -= stone[i-1]
        if tmp < min:
            min = tmp
    print(min)

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

S0 = S[0]
L = []
count = 1
Wk=[]
Bk=[]
if N>1:
    for i in range(1,N):
        if S[i-1]!=S[i]:
            L.append(count)
            count =1

        else:
            count +=1
        if i ==N-1:
            L.append(count)
else:
    L.append(1)
lenL=len(L)
Numw =0
Numb =0
Numx =0

if S0 == '.':
    Wk.append(L[0])
    Bk.append(0)
    if S[-1] =='.':
        for i in range(1,lenL):
            if i%2 == 0:
                Numw +=L[i]
                Wk.append(Wk[-1]+L[i])
                Bk.append(Bk[-1])

            else: 
                Numb +=L[i]
                Bk.append(Bk[-1]+L[i])
                Wk.append(Wk[-1])

        m=(min(Numw,Numb))

        tmp = float("inf")


        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))
        
    else:

        for i in range(1,len(L)-1):
            if i%2 ==0:
                Numw +=L[i]
                Wk.append(Wk[-1]+L[i])
                Bk.append(Bk[-1])
            else:
                Numb +=L[i]
                Bk.append(Bk[-1]+L[i])
                Wk.append(Wk[-1])
        if Bk:
            Bk.append(Bk[-1]+L[-1])
        else:
            Bk.append(L[-1])
        if Wk:
            Wk.append(Wk[-1])
        else:
            Wk.append(0)

        m=(min(Numb,Numw))
        tmp = float("inf")

        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

         

else:
    if S[-1]=='.':
        for i in range(len(L)):
            if i%2 ==0:
                Numb += L[i]
                if Bk:
                    Bk.append(Bk[-1]+L[i])
                else:
                    Bk.append(L[i])
                if Wk:
                    Wk.append(Wk[-1])
                else:
                    Wk.append(0)

            else:
                Numw += L[i]
                if Bk:
                    Bk.append(Bk[-1])
                else:
                    Bk.append(0)
                if Wk:
                    Wk.append(Wk[-1]+L[i])
                else:
                    Wk.append(L[i])

        m=(min(Numb,Numw))
        tmp = float("inf")

        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

    else:
        for i in range(len(L)-1):
            if i%2 ==0:
                Numb += L[i]
                if Bk:
                    Bk.append(Bk[-1]+L[i])
                else:
                    Bk.append(L[i])
                if Wk:
                    Wk.append(Wk[-1])
                else:
                    Wk.append(0)

            else:
                Numw += L[i]
                if Bk:
                    Bk.append(Bk[-1])
                else:
                    Bk.append(0)
                if Wk:
                    Wk.append(Wk[-1]+L[i])
                else:
                    Wk.append(L[i])
        if Bk:
            Bk.append(Bk[-1]+L[-1])
        else:
            Bk.append(L[-1])
        if Wk:
            Wk.append(Wk[-1])      
        else:
            Wk.append(0)
        m=(min(Numb,Numw))
        tmp =float("inf")  


        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

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

listS = list(S)

result = listS.count('.')
boundary = listS.count('.')

for i in range(N):
    if listS[i] == '.':
        boundary -= 1
    else:
        boundary += 1
    result = min(result, boundary)

print(result)

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()
b,w,ans=0,0,0
w=S.count('.')
ans=w
for i in S:
	if i=='
	else:w-=1
	ans=min(b+w,ans)
print(ans)

Solution (Python):
"""
python3 a.py < input.txt
"""
import math
import itertools as it
import heapq

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

T=[S[0]]
U=[1]
for si in S[1:]:
    if T[-1] == si:
        U[-1] = U[-1]+1
    else:
        T.append(si)
        U.append(1)
M=len(T)

B=[U[i] if T[i] == "
sumB=[B[0]]
for b in B[1:]:
    sumB.append(sumB[-1]+b)

W=[U[i] if T[i] == "." else 0 for i in range(M)]
sumW=[W[-1]]
for w in reversed(W[:-1]):
    sumW.append(sumW[-1]+w)
sumW=list(reversed(sumW))

l=[sum(B), sum(W)]
for i in range(M):
    if T[i] == "
        l.append(sumB[max(0, i-1)] + sumW[min(i+1, M-1)])









print(min(l))

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

left_black = [0 for i in range(n+1)]
right_white = [0 for i in range(n+1)]


b=0
for i in range(n):
    if s[i]=="
        b+=1
    left_black[i+1] = b

w=0
for i in reversed(range(n)):
    if s[i] == ".":
        w+=1
    right_white[i]=w

ans=int(1e9)
for i in range(n+1):
    ans = min(ans, left_black[i]+right_white[i])

print(ans)

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

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

Solution (Python):

def main():
    N=int(input())
    line = list(input())
    ans= line.count(".")
    num = ans
    for i in line:
        if i ==".":
            num -=1
        else:
            num +=1
        ans = min(ans,num)

    return ans


print(main())

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

c = S.count('.')
Min = c


for j in range(n):
    if S[j] == '
        c += 1
    else:
        c -= 1
    Min = min(Min, c)
        
print(Min)

Solution (Python):

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

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

ans = n




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

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

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

if w == 0 or b == 0:
    print(0)
    exit()

nw = w
nb = 0
ans = nw
for i in range(N):
    if S[i] == '.':
        nw -= 1
    else:
        nb += 1
    ans = min(ans, nb + nw)

print(ans)

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

a = S.count('.')
r = a

for i in range(N):
    if S[i] == '
        a += 1
    else:
        a -= 1
    r = min(r, a)

print(r)

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

Solution (Python):
n = int(input())
s = input()
lis = []
ws=s.count('.')
lis.append(ws)
bs = 0
for x in s:
    if x == '
        bs += 1
        lis.append(bs+ws)
    else:
        ws -= 1
    lis.append(bs+ws)
print(min(lis))

Solution (Python):
n = int(input())
s = input()
ans = [s.count(".")]
test = s.count(".")

for i in s:
    if i == ".":
        test -= 1
    else:
        test += 1
    ans.append(test)

print(min(ans))

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

s = S


dot_num = s.count('.')
sharp_num = 0

ans = dot_num

for c in s:
    if c == '
        sharp_num = sharp_num + 1
    else:
        dot_num = dot_num - 1
    
    ans = min(ans, sharp_num + dot_num)
print(ans)

Solution (Python):
import re

n = int(input())
s = input()
left = 0
right = len(re.findall('\.', s))

cnt = [left + right]
for i in range(n):
    if s[i] == '
        left += 1
    else:
        right -= 1
    cnt.append(left + right)

print(min(cnt))

Solution (Python):
import numpy as np
N = int(input())
S = list(input())

white_count=0
black_count=0
white_acc_list=[0]
black_acc_list=[0]
for i in range(N):
    if(S[i]=="."):
        white_count+=1
    else:
        black_count+=1
    black_acc_list.append(black_count)
    white_acc_list.append(white_count)

v = []
for i in range(N+1):
    v.append(black_acc_list[i]+(white_acc_list[N]-white_acc_list[i]))





print(np.min(v))

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

countW = 0
for i in range(N):
    if S[i] == '.':
        countW += 1
countB = N - countW

count = 0
counter = [countW]
for i in range(N):
    if S[i] == '
        count += 1
    else:
        countW -= 1
    counter.append(count + countW)

print(min(counter))

Solution (Python):
n = int(input())
s = input()
ans = s.count('.')
num = ans
for c in s:
  if c == '.':
    num -= 1
  else:
    num += 1
  
  ans = min(ans,num)

print(ans)

Solution (Python):
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
bcount = 0
wcount = 0
for word in s:
    if word == '.':
        wcount += 1
ans = wcount
preans = ans
for word in s:
    if word == '
        preans += 1
    else:
        preans -= 1
    ans = min(ans, preans)
print(ans)

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

    white = []
    black = []

    
    black_num = 0
    for s in S:
        black.append(black_num)
        if s == "
            black_num += 1
    black.append(black_num)

    
    S.reverse()
    white_num = 0
    for s in S:
        white.append(white_num)
        if s == ".":
            white_num += 1
    white.append(white_num)
    white.reverse()

    min_num = N
    for i in range(N + 1):
        temp_sum = white[i] + black[i]
        if min_num > temp_sum:
            min_num = temp_sum

    print(min_num)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
S = input()
p = 0
C = [[0,0]]
W = 0
for i in range(N):
    if p==0:
        if S[i] == "
            C[-1][0] += 1
        else:
            p = 1
            C[-1][1] += 1
            W += 1
    else:
        if S[i] == ".":
            C[-1][1] += 1
            W += 1
        else:
            C.append([1,0])
            p = 0
if C[0][0] == 0:
    W -= C.pop(0)[1]
if len(C) >0:
    if C[-1][1] == 0:
        C.pop(-1)
tmp = W
ans = W
for b,w in C:
    tmp += b
    tmp -= w
    ans = min(tmp,ans)

print(ans)

Solution (Python):
N = int(input())
a = list(input())
result = N
count = 0
result = N
white = [0]*(N+1)
for i in range(N):
	white[i+1] = white[i]
	if a[i] == ".":
		white[i+1] += 1
for i in range(N+1):
    count = i-white[i] + white[N] - white[i]
    if count < result:
        result = count
print(result)

Solution (Python):

N = int(input())
S = [1 if x == '.'  else 0 for x in list(input())]

cost = sum(S)
min_cost = cost

for i in range(N):
    if S[i] == 0:
        cost += 1
    else:
        cost -= 1

    if min_cost > cost:
        min_cost = cost

print(min_cost)

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

p = s.count('.')
q = 0
r = p

for i in range(n):
    if s[i] == '
        q += 1
    else:
        p -= 1
    
    r = r if r < p + q else p + q

print(r)

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

Solution (Python):
import sys

n = int(sys.stdin.readline())
s = sys.stdin.readline().strip()

bcnt = 0
ans = 0
for t in s:
    if t == '
        bcnt += 1
    else:
        if bcnt > 0:
            ans += 1
            bcnt -= 1

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
    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()
M=S.count('.')
ans=M

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

Solution (Python):
argN = int(input())
aryS = list(input())

cnt = aryS.count(".") 
ans = cnt
for i in range(argN):
  if aryS[i] == ".":
    cnt -= 1
  elif aryS[i] == "
    cnt += 1

  if ans > cnt:
    ans = cnt

print(ans)

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

p = s.count('.')
q = 0
r = p

for i in range(n):
    if s[i] == '
        q += 1
    else:
        p -= 1
    r = min(r, p + q)
    

print(r)

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

ans = S.count(".")

printnum = ans

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

print(ans)

Solution (Python):
from itertools import accumulate


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

black = [0 for _ in range(N)]
white = [0 for _ in range(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):


trial_num = int(input())
stones = list(input())

left_black_stone = 0
right_white_stone = stones.count(".")
min_turn_stones = right_white_stone

for i in range(trial_num):
    if(stones[i] == "
        left_black_stone += 1
    else:
        right_white_stone -= 1

    tmp_min = left_black_stone + right_white_stone
    if(tmp_min < min_turn_stones):
        min_turn_stones = tmp_min


print(min_turn_stones)

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

all_count_b = s.count("
all_count_w = n - all_count_b

count_b = 0
count_w = all_count_w

minimum = min([all_count_b, all_count_w])

for s1, s2 in zip(s, s[1:]):
    if s1 == "
        count_b += 1
    else:
        count_w -= 1
        if s2 == "
            minimum = min([count_b + count_w, minimum])

print(minimum)

Solution (Python):


N = int(input())
S = input().rstrip('

lb = 0
rw = S.count('.')
ans = lb + rw

for i in range(len(S)):
  if S[i] == '.':
    rw -= 1
  else:
    lb += 1
  ans = min(ans, rw + lb)

print(ans)

Solution (Python):
n = int(input())
s = input()
l = [0]*(n+1)
count = 0
for i in range(len(s)) :
    if s[i] == "." :
        count += 1
    l[i+1] = count
siro = l[-1]
ans = 1000000000000000000000
for i in range(n+1):
    ans = min(ans,i-2*l[i]+siro)
print(ans)

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


MIN = N
lb = 0
rw = 0
for i in range(N):
	rw += 1 if S[i] == "." else 0

for i in range(N):
	MIN = min(lb+rw,MIN)
	lb += 1 if S[i] == "
	rw -= 1 if S[i] == "." else 0

MIN = min(lb,MIN)
print(MIN)

Solution (Python):
N = int(input())
S = input()
whites = S.count('.')
stones = [0, whites]
ans = sum(stones)
for char in S:
    if char == '.':
        stones[1] -= 1
    else:
        stones[0] += 1
    if ans > sum(stones):
        ans = sum(stones)
print(ans)

Solution (Python):


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

    countMin = 200001
    counttemp = 0
    isWhite = True
    numlist = []
    for t in S:
        if t == "
            isWhite = False
            numlist.append(counttemp)
            counttemp = 0
        if t == "." and not isWhite:
            isWhite = True
            numlist.append(counttemp)
            counttemp = 0
        counttemp += 1
    
    numlist.append(counttemp)
    if len(numlist) <= 2:
        countMin = 0
    else:
        countMin = sum(numlist[2::2])
        temp = countMin
        i = 2
        while i < len(numlist):
            temp += numlist[i-1] - numlist[i]
            countMin = temp if temp < countMin else countMin
            i += 2

    print(countMin)

Solution (Python):
n = int(input())
s = str(input())
k = [s.count('.')]

for i in range(n):
  if s[i] == "
    k.append(k[i]+1)
  else:
    k.append(k[i]-1)
    
print(min(k))

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

r_list = []
lb = 0
rw = S.count(".")
r_list.append(lb + rw)
for i in range(N):
  if S[i] == "
    lb += 1
  else:
    rw -= 1
  r_list.append(lb + rw)
print(min(r_list))

Solution (Python):
n = int(input())
s = input()
ans = s.count('.')
num = ans
for c in s:
  if c == '.':
    num -= 1
  else:
    num += 1
  
  ans = min(ans,num)

print(ans)

Solution (Python):
input()
S=input()
dot=S.count(".")
ans=dot
sharp=0
for s in S:
    if s=="
    else:dot-=1
    ans=min(ans,sharp+dot)
print(ans)

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

WHITE = '.'
BLACK = '

b_num = 0
w_num = S.count(WHITE)
ans = b_num + w_num
for v in S:
    if v == BLACK:
        b_num += 1
    else:
        w_num -= 1
    ans = min(ans, b_num + w_num)

print(ans)

Solution (Python):

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

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

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

        ans = min(ans, left_black + right_white)

    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
n = input()
s = list(input())
 
ans = len(s)

sharp = 0
dot = 0
for string in s:
	if(string == "
		sharp += 1
	else:
		dot += 1 

left_sharp = 0
right_dot = dot

for i in range(len(s)):
	temp_ans = left_sharp + right_dot
	ans = min(ans,temp_ans)
	if(s[i] == "."):
		right_dot -= 1
	else:
		left_sharp += 1

ans = min(ans, len(s) - dot) 

print(ans)

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

c0 = [0] * n
c1 = [0] * n
for i in range(1, n):
  c0[i] = c0[i-1] + (s[i-1] == "
  c1[n-i-1] = c1[n-i] + (s[n-i] == ".")

min = n
for x, y in zip(c0, c1):
  if min > x + y:
    min = x + y
print(min)

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

b = 0
w = 0
for s in S:
  if s == '
    b += 1
  else:
    w += 1
dp = w
min = w
for s in S:
  if s == '.':
    dp -= 1
  else:
    dp += 1
    
  if dp < min:
    min = dp
print(min)

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

def calc():
    min_cost = n
    left_cost = 0
    right_cost = s.count('.')

    cost = left_cost + right_cost
    if cost < min_cost:
        min_cost = cost

    for i in range(n):
        if s[i] == '
            left_cost += 1
        else:
            right_cost -= 1
        cost = left_cost + right_cost
        if cost < min_cost:
            min_cost = cost

    return(min_cost)

print(calc())

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

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

leftblack = 0
rightwhite = len([x for x in L if x == 0])
ans = leftblack + rightwhite

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

Solution (Python):
N = int(input())
S = input()
LB = 0
RW = S.count(".")
ans = LB +RW
for x in range(N):
    if S[x] == "
        LB += 1
    else:
        RW -= 1
    count = LB +RW
    if count < ans:
        ans = count
print(ans)

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

white_num_r = len([val for val in S if val == "."])
black_num_l = 0

min_val = white_num_r
for val in S:
	if val == ".":
		white_num_r -= 1
	else:
		black_num_l += 1
	new_val = white_num_r + black_num_l
	min_val = min(new_val,min_val)

print(min_val)

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

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

a = [white + black]
for i in range(len(Sarray)):
    if Sarray[i] == '.':
        black -= 1
    else:
        white += 1
    a.append(white + black)
a.sort()
print(a[0])

Solution (Python):
def c_stones(N, S):
    black_left_of_the_boundary, white_right_of_the_boundary = 0, S.count('.')
    ans = black_left_of_the_boundary + white_right_of_the_boundary
    for c in S:
        if c == '
            black_left_of_the_boundary += 1
        else:
            white_right_of_the_boundary -= 1
        ans = min(ans, black_left_of_the_boundary + white_right_of_the_boundary)
    return ans

N = int(input())
S = input()
print(c_stones(N, S))

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

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

if len(num) == 1:
    print(0)
else:
    b = 0
    w = n
    offset = 0
    if first == '
        offset = 1
    w = sum(num[offset::2])
    minlist = [b + w]
    for i in range(len(num)):
        if i % 2 == offset:
            w -= num[i]
        else:
            b += num[i]
        minlist.append(b + w)
    print(min(minlist))

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

l = []
now = '.'
count = 0
for i in range(n):
  if ( s[i] != now ):
    l.append(count)
    now = s[i]
    count = 0
  count += 1

if ( count > 0 ):
  l.append(count)

l.append(0)



ans = 99999999999
left = 0
right = 0

for j in range(int((len(l)-1)/2)):
  right += l[(j+1)*2]

for ii in range(int(len(l)/2)):
  i = ii*2

  if( i!=0):
    right -= l[i]

  count = 0
  if ( i!=0):
    left += l[i-1]
  
  count = left + right
  
  


  if (ans>count):
    ans = count

if (ans == 99999999999):
  ans = 0

print(ans)

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

Solution (Python):
from collections import deque
n=int(input())
s=input()
black=0
write=s.count(".")
koho=deque([write,s.count("
for i in s:
    if i==".":
        write-=1
    else:
        black+=1
    koho.append(write+black)
print(min(koho))

Solution (Python):


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

nb, lb = 0, [0]
for i in range(N):
    if S[i] == '
        nb += 1
    lb.append(nb)

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

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

ss = '
ret = 0
for j in range(n):
  if s[j] != ss[j]:
    ret += 1

cnt = ret
for j in range(n):
  if s[j] == '.':
    cnt -= 1
  else:
    cnt += 1
  if cnt < ret:
    ret = cnt

print(ret)

Solution (Python):
def get_cost_change_black(S):
    return S.count(".")

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

indexs = [i for i, x in enumerate(S) if x == "
if len(indexs) == 0:
    print(0)
else:
    answer = 10000000000
    change_white = 0
    change_black = get_cost_change_black(S[indexs[0]:])
    for i, ind in enumerate(indexs):
        x = change_white + change_black
        if x < answer:
            answer = x
        change_white = change_white + 1
        if i == len(indexs) - 1:
            if change_white < answer:
                answer = change_white
            break
        change_black = change_black - (indexs[i+1] - indexs[i] - 1)
    print(answer)

Solution (Python):
from numpy import cumsum

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


ss = S.replace("
* ls, = map(int, ss)


cum_ls = cumsum(ls)


first_black = -1
for i in range(N):
    if S[i] == "
        first_black = i
        break


last_black = N
for i in reversed(range(N)):
    if S[i] == "
        last_black = i
    else:
        break
if first_black == -1:
    print(0)
else:
    
    ans_temp = 10 ** 10
    for i in range(N):
        ans_temp = min(ans_temp, cum_ls[i] +
                       (N-(i+1) - (cum_ls[-1] - cum_ls[i])))

    ans = min(S[first_black:].count("."), S[first_black:].count(
        "

    print(ans)

Solution (Python):


import sys
input = sys.stdin.readline

def io_generator():
	return input()


	
def main(io):
	n=int(io())
	s=io()[:n]
	
	nw=len([c for c in list(s) if c=='.'])
	ret=min(nw, n-nw)
	cnw=0
	cnb=0
	nnw=nw
	nnb=n-nw
	for i in list(s):
		if i=='.':
			cnw+=1
			nnw-=1
			ret = min(cnb+nnw, ret)
		if i =='
			cnb+=1
			nnb-=1
			ret = min(cnb+nnw, ret)
	return ret



if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Solution (Python):


import sys
input = sys.stdin.readline

def io_generator():
	return input()


	
def main(io):
	n=int(io())
	s=io()[:n]
	
	nw=len([c for c in list(s) if c=='.'])
	ret=min(nw, n-nw)
	cnw=0
	cnb=0
	nnw=nw
	nnb=n-nw
	for i in list(s):
		if i=='.':
			cnw+=1
			nnw-=1
			ret = min(cnb+nnw, ret)
		if i =='
			cnb+=1
			nnb-=1
			ret = min(cnb+nnw, ret)
	return ret



if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Solution (Python):
N = int(input())
S = input()
c1 = S.count("
c2 = S.count(".")
r1 = [0] * N
r2 = [0] * (N + 1)
if S[0] == "
    r1[0] = 1
for i in range(1, N):
    if S[i] == "
        r1[i] = r1[i - 1] + 1
    else:
        r1[i] = r1[i - 1]
r2[N - 1] = 1 * (S[N - 1] == ".")
r2[N] = r2[N - 1]
for i in range(N - 2, -1, -1):
    if S[i] == ".":
        r2[i] = r2[i + 1] + 1
    else:
        r2[i] = r2[i + 1]
res = N
for i in range(N):
    res = min(res, r1[i] + r2[i + 1])
print(min(res, c1, c2))

Solution (Python):


def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  S = input()

  st = N
  for i in range(N):
    if S[i] != '.':
      st = i
      break
  ed = 0
  for i in range(N):
    if S[N - 1 - i] != '
      ed = N - i
      break

  if ed <= st:
    print(0)
    return

  nWhite = 0
  for i in range(st, ed):
    if S[i] == '.':
      nWhite += 1

  countBlack = 0
  countWhite = 0
  ans = N
  for i in range(st, ed):
    w = nWhite - countWhite
    b = countBlack
    ans = min(ans, w + b)
    if S[i] == '
      countBlack += 1
    else:
      countWhite += 1
  ans = min(ans, countBlack)
  print(ans)

if __name__ == "__main__":
  main()

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

ans = S.count(".")

printnum = ans

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

print(ans)

Solution (Python):
n = int(input())
s = [1 if c == '
l = [0] * (n + 1)
l2 = [0] * (n + 1)
for i in range(n):
    l[i + 1] = s[i] + l[i]
s = s[::-1]
for i in range(n):
    l2[i + 1] = 1-s[i] + l2[i]
l2 = l2[::-1]
ans = float('inf')
for i in range(n + 1):
    ans = min(ans, l[i] + l2[i])
print(ans)

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

A = [None]*(N+1)
A[0] = 0
cnt = 0
for i,s in enumerate(S[::-1]):
    if s=='.':
        A[i+1] = A[i]+1
    else:
        A[i+1] = A[i]-1
        cnt += 1
print(min(A)+cnt)

Solution (Python):
n = int(input())
s = input()
temp = []
c = 0
pitem = ''
s2 = '.' + s + 'a'
for item in s2:
    if pitem == '' or item == pitem:
        c += 1
        pitem = item
    if item != pitem:
        temp.append(c)
        c = 1
        pitem = item
        continue




t = s2.count('.')
c = 0
c2 = 0
cs = []
for i in range(len(temp)):
    c2 += temp[i]
    if i % 2 == 1:
        c += temp[i]
    cs.append(c + t - (c2 - c))
print(min(cs))

Solution (Python):
N = int(input())
S = input()
c1 = S.count("
c2 = S.count(".")
r1 = [0] * N
r2 = [0] * (N + 1)
r1[0] = 1 * (S[0] == '
for i in range(1, N):
    if S[i] == "
        r1[i] = r1[i - 1] + 1
    else:
        r1[i] = r1[i - 1]
r2[N - 1] = 1 * (S[N - 1] == ".")
r2[N] = r2[N - 1]
for i in range(N - 2, -1, -1):
    if S[i] == ".":
        r2[i] = r2[i + 1] + 1
    else:
        r2[i] = r2[i + 1]
res = N
for i in range(N):
    res = min(res, r1[i] + r2[i + 1])
print(min(res, c1, c2))

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

W = [0] * n
B = [0] * n

for i in range(n):
    if i == 0:
        if s[-1] == '.':
            W[-1] = 1
    elif s[-i-1] == '.':
        W[-i-1] = W[-i] + 1
    else:
        W[-i-1] = W[-i]



for i in range(n):
    if i == 0:
        B[i] = 0
    elif s[i-1] == '
        B[i] = B[i-1] + 1
    else:
        B[i] = B[i-1]



if W[0] == n:
    print(0)
else:
    ans = n
    for i in range(n):
        c = W[i] + B[i]

        ans = min(ans, c)

    ans = min(ans, s.count('

    print(ans)

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

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

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

Solution (Python):
N = int(input())
S = input()
r1 = [0] * N
r2 = [0] * (N+1)
r1[0] = 1 * (S[0] == '
for i in range(1, N):
    if S[i] == "
        r1[i] = r1[i - 1] + 1
    else:
        r1[i] = r1[i - 1]

r2[N - 1] = 1 * (S[N - 1] == ".")
r2[N] = r2[N-1]
for i in range(N - 2, -1, -1):
    if S[i] == ".":
        r2[i] = r2[i + 1] + 1
    else:
        r2[i] = r2[i + 1]

c1 = S.count("
c2 = S.count(".")
ans = N
for i in range(N):
    ans = min(ans, r1[i] + r2[i + 1])
print(min(ans, c1, c2))

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

lb = [0]*len(s)
lw = [0]*len(s)

sb = 0
sw = 0
min = len(s)

for i in range(len(s)):
    if s[i] == '
        sb += 1
    if s[len(s)-(i+1)] == '.':
        sw += 1
    lw[len(s)-(i+1)] = sw
    lb[i] = sb

lb.insert(0,0)
lw.append(0)




for i in range(len(s)+1):
    if lb[i]+lw[i] < min:
        min = lb[i]+lw[i]

print(min)

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
s = list(ns())
count1 = 0
count2 = 0
lis1 = [0 for i in range(n)]
lis2 = [0 for i in range(n)]
for i in range(len(s)):
    if s[i] == '.':
        count1 += 1
        lis1[i] = count1
    if s[i] == '
        count1 -= 1
        lis1[i] = count1
idx1 = lis1.index(max(lis1))
for i in range(len(s)-1, -1, -1):
    if s[i] == '
        count2 += 1
        lis2[i] = count2
    if s[i] == '.':
        count2 -= 1
        lis2[i] = count2
idx2 = lis2.index(max(lis2))
ans1 = s[:idx1 + 1].count('
ans2 = s[:idx2].count('
print(min(ans1, ans2))