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()
tmp = S.count('.')
mini = tmp
def judge(k):
  return bool(S[k]=='.')
def check(k):
  return 1-2*judge(k)
for i in range(N):
  tmp += check(i)
  if tmp < mini:
    mini = tmp
print(mini)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')


def A():
    a, b, c = LI()
    if b < a:
        a,b = b,a
    if a <= c <= b:
        print("Yes")
    else:
        print("No")
    return


def B():
    n = II()
    s = input()
    a = list(set(list(s)))
    k = II()-1
    for i in a:
        if s[k] != i:
            s = s.replace(i, "*")
    print(s)
    return


def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    a, b = 0, 0
    for num,i in enumerate(s):
        if i == "
            dp[num] += 1
    for i in range(1, n):
        dp[i] += dp[i - 1]
    ans = min(s.count("
    shap = s.count("
    for i in range(n):
        a = dp[i] + (n - (i+1) - dp[-1] + dp[i])
        ans = min(ans, a)
    print(ans)


    """
    dp = []
    bf = s[0]
    del s[0]
    a = 
    flg = False
    if bf == ".":
        flg = True
    for i in s:
        if i == bf:
            a += 1
        else:
            dp.append(a)
            a = 1
            bf = i
    dp.append(a)
    a, b = 0, 0
    if flg:
        dp[0] = 0
    if len(s) and s[-1] == "
        dp[-1] = 0
    for d in range(len(dp) - 2, -1, -2):
        a += dp[d]
    for d in range(len(dp) - 1, -1, -2):
        b += dp[d]
    print(dp)
    print(min(a,b))
    """
    return


def D():
    n = II()
    ai = IR(n)
    ai.sort()
    ruiseki = [0 for i in range(n)]
    for num, a in enumerate(ai):
        ruiseki[num] = a + ruiseki[num-1]
    select = list(itertools.combinations(range(n), 3))
    ans = 0
    for a,b,c in select:
        A = ruiseki[a]
        B = ruiseki[b] - ruiseki[a]
        C = ruiseki[c] - ruiseki[b]
        if A + B > C and B + C > A and A + C > B:
            ans += 6
            ans = ans % mod
    print(ans)
    
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    C()

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):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = list(input())

tmp = S.count("
tmp2 = len(S)-tmp
num = [0]*N
num_sharp = 0
num_peri = 0
for i in range(len(S)):
	if S[i] == "
		num_sharp += 1
	else:
		num_peri += 1
	num[i] = num_sharp + (len(S)-(i+1))-(tmp-num_sharp)

print(min(tmp2, min(num)))

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())
dc = S.count(".")
sc = S.count("
dcn = 0
scn = 0
c = 0
count = dc
ans = dc
for i, s in enumerate(S):
    if s == ".":
        dcn += 1
        count -= 1
    if s == "
        scn += 1
        count += 1
    ans = min(ans, count)
print(ans)

Solution (Python):
from heapq import heappush,heappop


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

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

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


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

N = int_raw()
S= input()

dp = {}

def rec(ss):
    return 0

def main():
    global S
    ans = INF
    numB = [0]*len(S)
    
    for i in range(len(S)):
        if i > 0:
            numB[i]=numB[i-1]
        if S[i]=="
            numB[i]+=1
    if numB[len(S)-1]==0 or numB[len(S)-1]==len(S):
        return 0        
    for i in range(len(S)):
        buf = numB[i]+len(S)-1-i-(numB[len(S)-1]-numB[i])
        ans = min(ans, buf)
    ans = min(ans, len(S)-numB[len(S)-1])
    ans = min(ans, numB[len(S)-1])
    return ans



print(main())

Solution (Python):
n = int(input())
s = input()
li = []
for i in range(n):
    if s[i] == "
        li.append(i)
li.append(len(s))
sum = 0
if len(li) == 1:
    print(0)
else:
    for i in range(len(li)-1):
        diff = li[i+1] - li[i] - 1
        if sum + diff >= i+1:
            sum = i+1
        else:
            sum += diff
    print(sum)

Solution (Python):





import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def grouping(N, S):
    g = []
    s = S[0]
    c = 1
    for i in range(1, N):
        if S[i] == s:
            c += 1
        else:
            g.append((s, c))
            c = 1
            s = S[i]
    g.append((s, c))
    return g

def main(N, S):
    g = grouping(N, S)
    gl = len(g)
    l = 0
    r = gl - 1
    if g[l][0] == '.':
        l += 1
    if g[r][0] == '
        r -= 1
    if r - l < 1:
        print(0)
        return
    ll = [0]
    lr = [0]
    lc = 0
    for i in range(l, r, 2):
        ll.append(g[i][1] + ll[-1])
        lr.append(g[i+1][1] + lr[-1])
        lc += 1
    ans = N
    for i in range(lc+1):
        tl = ll[i]
        tr = lr[lc] - lr[i]
        ans = min(ans, tl + tr)
    print(ans)

N = i2n()
S = i2s()
main(N, S)

Solution (Python):


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

    righ_siro = data.count('.')
    righ_kuro = data.count('

    ans = min(righ_kuro, righ_siro)

    left_kuro = 0
    left_shiro = 0

    for i in range(N):
        if data[i] == '.':
            left_shiro +=1
            righ_siro -= 1
        else:
            left_kuro += 1
            righ_kuro -= 1

        kari = left_kuro + righ_siro

        if ans > kari:
            ans = kari

    print(ans)






if __name__ == '__main__':
    main()

Solution (Python):
def main():
    _ = int(input())
    S = input()
    aw = S.count('.')
    ab = S.count('
    w = S.count('.')
    b = 0
    ans = float('INF')
    for s in S:
        if s == '.':
            w -= 1
        if s == '
            b += 1
        ans = min(aw, ab, w + b, ans)
    print(ans)


main()

Solution (Python):
from collections import deque

_ = input()
S = input()

que = deque([])

flag = False 
tmp = 0

for s in S:
    if flag:
        if s == "
            tmp += 1
        else:
            que.append(tmp)
            tmp = 1
            flag = not flag
    else:
        if s == ".":
            tmp += 1
        else:
            que.append(tmp)
            tmp = 1
            flag = not flag

que.append(tmp)

if not flag:
    que.append(0)

cost = 0
fe_cost = []
fe_cost.append(cost)
flag = True
for q in que:
    if flag:
        flag = not flag
    else:
        cost += q
        fe_cost.append(cost)
        flag = not flag
fe_cost.pop()

cost = 0
be_cost = []
be_cost.append(cost)
flag = True
for q in reversed(que):
    if flag:
        flag = not flag
    else:
        cost += q
        be_cost.append(cost)
        flag = not flag
be_cost.pop()
be_cost.reverse()
fe_cost = list(fe_cost)
be_cost = list(be_cost)

cost = [x + y for (x, y) in zip(fe_cost, be_cost)]
print(min(cost))

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

S_r = S[::-1]
w_num = []
b_num = []
w = 0
b = 0
for i in range(N):
  if S[i] == '.':
    w += 1
  w_num.append(w)
  if S_r[i] == '
    b += 1
  b_num.append(b)
b_num = b_num[::-1]
ans = [N-w_num[i]-b_num[i] for i in range(N)]
print(min(ans))

Solution (Python):


def main():
    N = int(input())
    s = input()
    count1 = 0
    count2 = 0
    count3 = 0
    temp = ""
    patern3_white = [0]*N
    patern3_black = [0]*N
    patern3 = []
    if (not "." in s) or (not "
        print(0)
        return

    for i in s:
        if i == ".":
            count1 += 1
        elif i == "
            count2 += 1

    for i in range(N-1):
        if i == 0:
            if s[0] == "
                patern3_white[0] = 1
                patern3_black[0] = count1
            else:
                patern3_white[0] = 0
                patern3_black[0] = count1-1
                
            patern3.append(patern3_white[0] + patern3_black[0])
        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
            patern3.append(patern3_white[i]+patern3_black[i])
    
    
    
    
    count3 = min(patern3)
    
    
    
    print(min(count1,count2,count3))

if __name__ == "__main__":
    main()

Solution (Python):
def solve():
  N = int(input())
  S = input()
  stones = []
  look = S[0]
  cnt = 0

  if S[0] == '.': stones.append(0)
  for s in S:
    if look == s: cnt += 1
    else:
      stones.append(cnt)
      cnt = 1
      look = s
  stones.append(cnt)
  if S[N - 1] == '

  count = sum(stones[1::2])
  ans = count

  for i in range(0, len(stones), 2):
    count = count + stones[i] - stones[i + 1]
    if ans > count: ans = count
  return ans

print(solve())

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


ans1 = 0
found = False
for c in S:
    if c == '.' and found:
        ans1 += 1
    if c == '
        found = True


ans2 = 0
found = False
for c in reversed(S):
    if c == '
        ans2 += 1
    if c == '.':
        found = True

bcounts = [0 for _ in range(len(S))]
wcounts = [0 for _ in range(len(S))]
cs = 0
for i in range(len(S)):
    if S[i] == '
        cs += 1
    bcounts[i] = cs
cs = 0
for i in reversed(range(len(S))):
    if S[i] == '.':
        cs += 1
    wcounts[i] = cs

INF = float('inf')
ans = INF
for i in range(len(S) - 1):
    if S[i] == '
        
        ni = i + 1
        while ni < len(S) and S[ni] == '.':
            ni += 1
        while ni < len(S) and S[ni] == '
            ni += 1
        if ni < len(S):
            wc = wcounts[ni]
        else:
            if wcounts[-1] == '.':
                wc = 1
            else:
                wc = 0
        ans = min(ans, bcounts[i] + wc)

print(min(ans1, ans2, (0 if ans == INF else ans)))

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

b_sum = []
w_sum = []
b_num = 0
w_num = 0




for i in range(n):
    if s[i] == "
        b_num = b_num + 1
    else:
        w_num = w_num + 1
    b_sum.append(b_num)
    w_sum.append(w_num)



ans = []

for i in range(n):
    ans.append(b_sum[i] + w_sum[n - 1] - w_sum[i])
ans.append(w_sum[n - 1])

print(min(ans))

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

w_cnt = 0
w_list = []
b_cnt = 0
b_list = []
for i in range(N):
    if S[i] == '
        w_cnt += 1
        w_list.append(w_cnt)
    else:
        w_list.append(w_cnt)

    if S[N-1-i] == '.':
        b_cnt += 1
        b_list.append(b_cnt)
    else:
        b_list.append(b_cnt)



ans = N
for i in range(N):
    wa = w_list[i] + b_list[N-2-i]
    if ans > wa:
        ans = wa


if b_list[N-1] < ans:
    ans = b_list[N-1]

if w_list[N-1] < ans:
    ans = w_list[N-1]

print(ans)

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

cnt=0
l = []
b = 1 if S[0] == "." else 0

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

if len(l)<=1:
    print("0")
    exit()

s = 0
q = 0
q2 = 0
for c in S:
    if c=="
        q += 1
    else:
        q2 += 1

for j in range(abs(b-1), len(l), 2):
    
    s += l[j]

m = min(q,q2,s)

for j in range(b, len(l), 2):
    
    if j-2 >= 0:
        s += l[j-2]-l[j-1]
    elif j-1 >= 0:
        s += -l[j-1]
    m = min(s, m)



print(m)

Solution (Python):
import numpy as np

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

blacks = [0]
count = 0

for ele in s:
	if ele == '
		count += 1
	blacks.append(count)

whites = [0]
count = 0

for ele in s[::-1]:
	if ele == '.':
		count += 1
	whites.append(count)



blacks = np.array(blacks)
whites = np.array(list(reversed(whites)))

totals = np.add(blacks, whites)


print(min(totals))

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

r1=S.count("
r2=N-r1
c1=r1
c2=r2


it1=0
it2=N-1
it1f=False
it2f=False
r3=0
isLeft=None

while it1<it2:
  if S[it1]!=".":
    if it1f==True and it2f==True and c1<=c2:
      r3+=1
      it1+=1
      it1f=False
      c1-=1
    else:
      it1f=True
  else:
    it1+=1
    c2-=1

  if S[it2]!="
    if it1f==True and it2f==True and c1>c2:
      r3+=1
      it2-=1
      it2f=False
      c2-=1
    else:
      it2f=True
  else:
    it2-=1
    c1-=1

print(r3)

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


CT=0
for j in range(len(S)):
    if S[j] == ".":
        CT+=1



CH=0
A=CT+CH
for i in range(len(S)):
    if S[i] == ".":
        CT-=1
    if S[i] == "
        CH+=1

    A=min(CT+CH, A)


print(A)

Solution (Python):
from itertools import accumulate

N = int(input())
S = input()
L = list()
for s in S:
    if s == '.':
        L.append(0)
    else:
        L.append(1)

sharp_cumsum = [0] + list(accumulate(L))
period_cumsum = ([0] + list(accumulate([x^1 for x in L[::-1]])))[::-1]

ans = 10 ** 9

for i in range(N):
    left = i
    right = i+1
    tmp_ans = sharp_cumsum[left] + period_cumsum[right]
    ans = tmp_ans if tmp_ans < ans else ans
print(ans)

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

    print(res)

if __name__ == '__main__':
    main()

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

a = list(input())
su = 0
co = 1
coo = 0
c = 0
cc = 0
k = a[0]
c1 = n
c2 = 0
c3 = 0
aa = []
p = a.count("
pp = a.count(".")

for i in range(n-1):
	if k == a[i+1]:
		co += 1
	else:
		aa.append([k,co])
		k = a[i+1]
		co = 1

aa.append([k,co])
co = 0
if aa[-1][0] == ".":
	aa.append(["
for i in range(len(aa)):
	if aa[-(i+1)][0] == "
		c += aa[-(i+1)][1]
		c3 += aa[-(i+1)][1]
		c1 = min(c1,cc + p - c)
	else:
		cc += aa[-(i+1)][1]
		c2 += aa[-(i+1)][1]
		c1 = min(c1,cc + p - c)

print(min(c1,c2,c3))

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

ans = N
b_list = [0]
w_list = [0]
for i, s in enumerate(S):
    if s == '
        b_list.append(b_list[i]+1)
    else:
        b_list.append(b_list[i])
for i, s in enumerate(reversed(S)):
    if s == '.':
        w_list.append(w_list[i]+1)
    else:
        w_list.append(w_list[i])

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

Solution (Python):
n=int(input())
s=list(str(input()))
w=0
b=0
wl=[]
bl=[]
for i in range(n):
    if s[i]==".":
        w+=1
    else:
        b+=1
    wl.append(w)
    bl.append(b)
if "
    print(0)
elif s.count(".")==1 and s[0]=="
    print(1)
else:
    ans=[]
    for i in range(n):
        ans.append(bl[i]+wl[-1]-wl[i])
    print(min(min(ans),wl[-1],bl[-1]))

Solution (Python):
n=int(input())
s_o=input()
s_dot=[len(x) for x in s_o.replace("
s_sharp=[len(x) for x in s_o.replace("."," ").split()]
if s_o[0]==".":
  s_dot=s_dot[1:]
if s_o[-1]=="
  s_sharp=s_sharp[:-1]
length=len(s_dot)+1
if len(s_dot)==0 or len(s_sharp)==0:
  print(0)
  exit()
sum_sharp=[0]*length
sum_dot=[0]*length
for i in range(length):
  if i==0:
    sum_sharp[i]=0
  else:
    sum_sharp[i]=sum_sharp[i-1]+s_sharp[i-1]

for i in reversed(range(length)):
  if i==length-1:
    sum_dot[i]=0
  else:
    sum_dot[i]=sum_dot[i+1]+s_dot[i]
ans=[1000000]*(length)
for i in range(length):
  ans[i]=sum_sharp[i]+sum_dot[i]
print(min(ans))

Solution (Python):
import bisect
n = int(input())
s = list(input())
b = [0]*(n+1)
c = [s.count(".")]*(n+1)
a = []
a.append(c[0])
for i in range(n):
    if s[i] == "
        b[i+1] = b[i] + 1
        c[i+1] = c[i]
    else:
        c[i+1] = c[i] - 1
        b[i+1] = b[i]
    a.append(b[i+1] + c[i+1])
if "." not in s:
    a.append(0)
elif "
    a.append(0)
print(min(a))

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

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

cnt_b = [0 for i in range(N)]    
cnt_w = [0 for i in range(N)]

if S[0] == "
    cnt_b[0] = 1
else:
    cnt_w[0] = 1

for i in range(1, N):
    if S[i] == "
        cnt_b[i] = cnt_b[i-1] + 1
        cnt_w[i] = cnt_w[i-1]
    else:
        cnt_b[i] = cnt_b[i-1]
        cnt_w[i] = cnt_w[i-1] + 1

cnt_change_to_w = [0 for i in range(N)]
cnt_change_to_b = [0 for i in range(N)]
for i in range(N):
    cnt_change_to_b[i] = cnt_b[i] + cnt_w[N - 1] - cnt_w[i]

for i in range(N):
    cnt_change_to_w[i] = cnt_b[i] + cnt_w[N - 1] - cnt_w[i]
    if S[i] == "
        cnt_change_to_w[i] -= 1

min1 = min(cnt_change_to_b)
min2 = min(cnt_change_to_w)
print(min(min1, min2))

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

tmp = [0 for _ in range(N+1)]


   

for i in range(N):
    if S[i] == '.':
        tmp[i+1] = tmp[i] + 1
    else:
        tmp[i+1] = tmp[i]
  
res1 = 10 ** 9
for i in range(N):
    res1 = min((i+1) - tmp[i+1] + tmp[N] - tmp[i+1], res1)
        
b = 0
w = 0
for i in range(N):
    if S[i] == '
        b += 1
    else:
        w += 1

res3 = N - max(b, w)

print(min(res1, res3))

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

def run(N, S):
    num_black= S.count('

    arr = []
    nSharp = 0
    nDot = 0
    flagDot = False
    if S[0] == '.':
        flagDot = True
    for i in S:
        if i == '
            if flagDot:
                arr.append((nSharp, nDot))
                flagDot = False
                nSharp = 0
                nDot = 0
            nSharp += 1
        else:
            flagDot = True
            nDot += 1
    arr.append((nSharp, nDot))    

    result = N - num_black
    min_result = result
    for i,val in enumerate(arr):
        result += val[0] - val[1]
        min_result = min(result, min_result)
        
    return min_result
        
print(run(N, S))

Solution (Python):
N=int(input())
S=input()
whi=0
bla=0
c1=0
dp=[[0,0] for i in range(N+1)]
for i in range(N):
    s=S[i]
    if s=="
        dp[i+1][0]=dp[i][0]+1
    else:
        dp[i+1][0]=dp[i][0]
for i in range(N):
    s=S[N-1-i]
    if s==".":
        dp[N-i-1][1]=dp[N-i][1]+1
    else:
        dp[N-i-1][1]=dp[N-i][1]


ans=float("inf")
for i in range(N+1):
    ans=min(ans,dp[i][0]+dp[i][1])
print(ans)

Solution (Python):
n = int(input())
s = input()
l = len(s)
mincnt = n
nums = [[0, 0]]
if s[0] == ".":
    nums[0][0] = 1
else:
    nums[0][1] = 1
if l == 1:
    print(0)
    exit()

for c in s[1:]:
    last = nums[-1]
    nums.append([last[0] + 1, last[1]] if c == "." else [last[0], last[1] + 1])

for i in range(0, l):
    b_before = nums[i][1] - (1 if s[i] == "
    w_after = nums[-1][0] - nums[i][0] + (1 if s[i] == "." else 0)
    mincnt = min(mincnt, b_before + w_after)
mincnt = min(mincnt, nums[-1][1])
print(mincnt)

Solution (Python):


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

wc = S.count('.')
bc = 0
ans = wc + bc
for s in S:
    if s == '.':
        wc -= 1
    else:
        bc += 1
    temp = wc + bc
    ans = min(temp, ans)
        
print(ans)

Solution (Python):

import numpy as np

N = int(input())
s = input()

S = []
for c in s:
    S.append(c)
    
A = np.zeros(N+1)
if S[0] == "
    A[0] = 0 
for i in range(1,N+1):
    if S[i-1] == "
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]
    
minimum = N
for i in range(N+1):
    num = int(A[i] + (N-i-(A[N]-A[i])))
    if minimum > num:
        minimum = num
print(minimum)

Solution (Python):
import numpy as np

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

black_stones = []
white_stones = []

black_stone_counter = 0
for stone_color in S:
    if stone_color == "
        black_stone_counter += 1
    black_stones.append(black_stone_counter)

white_stone_counter = 0
for stone_color in S[::-1]:
    if stone_color == ".":
        white_stone_counter += 1
    white_stones.append(white_stone_counter)

black_stones_np = np.array(black_stones)
white_stones.reverse()
white_stones_np = np.array(white_stones)

sum_stones_np = black_stones_np + white_stones_np

print(sum_stones_np.min()-1)

Solution (Python):
import sys
import collections

def solve():
    N=int(sys.stdin.readline().rstrip())
    S=list(sys.stdin.readline().rstrip())
    whites=[0]*(N+1)
    blacks=[0]*(N+1)
    for i,c in enumerate(S):
        if c=='.':
            whites[i+1]=whites[i]+1
            blacks[i+1]=blacks[i]
        else:
            whites[i+1]=whites[i]
            blacks[i+1]=blacks[i]+1

    
    inf=1<<60
    ans=inf
    
    
    all_whites=whites[N]
    for i in range(N+1):
        ans1=blacks[i] + (all_whites-whites[i])
        
        ans=min(ans,ans1)
    return ans

print(solve())

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

wcs, bcs = [0], [0]
wc, bc = 0, 0
if s[0] == '
  bc = 1
for prevs, _s in zip(s, s[1:]):
  if prevs != _s:
    bcs.append(bc + bcs[-1])
    if _s == '
      bc = 1
    else:
      bc = 0
  else:
    if _s == '
      bc += 1
bcs.append(bc + bcs[-1])

wc, bc = 0, 0
if s[-1] == '.':
  wc = 1
for prevs, _s in zip(s[::-1], s[::-1][1:]):
  if prevs != _s:
    wcs.append(wc + wcs[-1])
    if _s == '.':
      wc = 1
    else:
      wc = 0
  else:
    if _s == '.':
      wc += 1
wcs.append(wc + wcs[-1])

minbw = pow(10, 6)
for bc, wc in zip(bcs, wcs[::-1]):
  if bc + wc < minbw:
    minbw = bc + wc
print(minbw)

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

Solution (Python):
N=int(input())
S=input()
cur=0
lis=["" for i in range(N)]
lis[cur]=S[0]
for c in S[1:]:
	ss=lis[cur]
	if c==".":
		lis[cur]=ss+"."
	else:
		if ss[-1]=="
			lis[cur]=ss+"
		else:
			cur+=1
			lis[cur]="
def counting(sss):
	curb=sss.find("
	curw=sss.rfind(".")
	return tuple([sss[:curw+1].count("

c=0
lasc=0
kugi=[]
for l in lis:
	if l=="":
		break
	else:
		ka=counting(l)
		c+=ka[0]
		kugi.append(ka)
lasc=c
for w,b in kugi[::-1]:
	c=c-w+b
	if c<lasc:
		lasc=c
print(lasc)

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










"""
3


3

"""


def inorderReplace(S , N): 
    S = list(S)
    cnt = 0
    for i in range(N - 1) : 
        nowChar = S[i]
        nextChar = S[i + 1]
        if nowChar == "
            cnt += 1
            S[i + 1] = "
    return cnt

def calcCount(S , N) : 
    countingChar = S[0]
    rst = []
    count = 1
    for s in S[1:] :
        if countingChar == s : 
            count += 1
        else : 
            rst.append((countingChar , count))
            count = 1
            countingChar = s
    rst.append((countingChar , count))
    return rst

def countRightChange(countingList) : 
    
    cnt = 0
    for elem in countingList : 
        if elem[0] == "
            cnt += elem[1]
    return cnt

def countLeftChange(countingList) : 
    
    cnt = 0
    for elem in countingList : 
        if elem[0] == "." : 
            cnt += elem[1]
    return cnt

def calcPoint(countingList) : 
    a = 0
    b = countLeftChange(countingList)
    minVal = a + b
    for i in range(len(countingList)) : 
        elem = countingList[i]
        if elem[0] == "." : 
            a += 0
            b -= elem[1]
        elif elem[0] == "
            a += elem[1]
            b -= 0
        if minVal > a + b : 
            minVal = a + b
    return minVal

countingList = calcCount(S , N)
cnt2 = calcPoint(countingList)

print(cnt2)

Solution (Python):
from sys import stdin
import numpy as np
N=int(stdin.readline().rstrip())
S=(stdin.readline().rstrip())
A=[0]*N 
B=[0]*N 
a_count=0
b_count=0

for ind,i in enumerate(list(S)):
    if i == ".":
        a_count+=1
        A[ind] = a_count
        B[ind] = b_count
    else:
        b_count+=1
        B[ind] = b_count
        A[ind] = a_count
A.insert(0,0)
B.insert(0,0)
dif=np.array(A) - np.array(B)
dif_ind = np.argmax(dif)
ans=B[dif_ind] + A[-1] - A[dif_ind]
print(ans)

Solution (Python):
def main():
    n = int(input())
    s = list(input())
    
    arr = []
    cnt = 1
    for i in range(1, n):
        if s[i] == s[i - 1]:
            cnt += 1
        else:
            arr.append(cnt)
            cnt = 1
    arr.append(cnt)
    
    if s[0] == '.':
        arr = [0] + arr
    if s[-1] == '
        arr += [0]
    
    for i in range(len(arr) - 3, -1, -2):
        arr[i] += arr[i + 2]
    for i in range(2, len(arr), 2):
        arr[i] += arr[i - 2]
    
    arr += [0, 0]
    
    ans = arr[1]
    for i in range(1, len(arr) - 2, 2):
        ans = min(ans, arr[i - 1] + arr[i + 2])
    
    print(ans)
    return 0

main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7

n = int(input())
S = input()
W = [0]*(2*10**5+1)
B = [0]*(2*10**5+1)
for i in range(n):
    if S[i] == '.':
        W[i] = 1
    else:
        B[i] = 1
for i in range(1,2*10**5+1):
    W[i] += W[i-1]
    B[i] += B[i-1]
W = [0] + W
B = [0] + B
res = INF
for i in range(2*10**5+1):
    ans = W[-1]-W[i]+B[i]
    if ans <= res:
        res = ans
print(res)

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

l_count = 0
r_count = sum([1 for c in S if c == "."])
count_if_contain_black = l_count+r_count
count_if_all_white = 0
for c in S:
    if c == "
        l_count += 1
        count_if_all_white += 1
    else:
        r_count -= 1
        
    count_if_contain_black = min(count_if_contain_black, l_count+r_count)

print(min(count_if_all_white, count_if_contain_black))

Solution (Python):
import numpy as np
  
input()
S = np.asarray(list(str(input())))

rw = S[S=="."].size
rb = S[S=="
lw = 0
lb = 0
res = lb + rw
for s in S:
 if s == "
  rb -= 1
  lb += 1
 else:
  rw -= 1
  lw += 1
 res = min(res,lb+rw)
print(res)

Solution (Python):


from sys import stdin
    
def calc(n, s):
    s2 = [ c == '
    total = sum(s2)
    _min = min(total, n-total)
    tr = 0
    for i,c in enumerate(s2):
        if c:
            tr += 1
        op = 2*tr+n-(i+1)-total
        if op < _min:
            _min = op

    return _min

def main():
    n = int(stdin.readline().rstrip())
    s = stdin.readline().rstrip()
    ans = calc(n, s)
    print(ans)
    
if __name__=='__main__':
    main()

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

c = [0]
cc = [0]
for i in range(n):
  if s[i] == ".":
    c.append(c[-1]+1)
    cc.append(cc[-1])
  else:
    c.append(c[-1])
    cc.append(cc[-1]+1)
c = c[1:]
cc = cc[1:]

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

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



 
a = [0] * (N+2)
b = [0] * (N+2)
 
cnt = 2
for x in S:
    if x == "
        a[cnt] = a[cnt-1] + 1
    else:
        a[cnt] = a[cnt-1] 
    cnt += 1
 
cnt =N
Sinv = S[::-1]
for x in Sinv:
    if x == ".":
        b[cnt] = b[cnt+1] + 1
    else:
        b[cnt] = b[cnt+1] 
    cnt -= 1
 
 
 
c = []
 
for index in range(N+2):
    c.append(a[index] + b[index])
c[0] = 999999
 
print(min(c))

Solution (Python):
from itertools import accumulate

N = int(input())
S = input()
black = [int(s=="
white = [int(s==".") for s in S[::-1]]

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

ans = 1000000
for b,w in zip(a_black,a_white):
    ans = min(ans, b+w)
print(ans)

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

i = 0
while i<len(s) and s[i] == '.':
  i+=1
j = n-1
while j>=0 and s[j] == '
  j-=1

s = s[i:j+1]
r = min(s.count('

w = s.count('.')
b = 0
c = 0
for i in range(len(s)):
  if s[i] == '
    b += 1
  else:
    w -= 1
  r = min(r, w+b)

print(r)

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

count_if_all_white = 0
for c in S:
    if c == "
        count_if_all_white += 1

l_count = 0
r_count = sum([1 for c in S if c == "."])
count_if_contain_black = l_count+r_count
for c in S:
    if c == "
        l_count += 1
    else:
        r_count -= 1
        
    count_if_contain_black = min(count_if_contain_black, l_count+r_count)

print(min(count_if_all_white, count_if_contain_black))

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