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

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    S = input()
    
    w_acc, b_acc = [0], [0]
    for i in range(N):
        w_acc.append(w_acc[-1] + (S[i] == '.'))
        b_acc.append(b_acc[-1] + (S[i] == '
    
    ans = w_acc[-1]
    for i in range(1, N + 1):
        ans = min(ans, b_acc[i] + w_acc[-1] - w_acc[i])
    print(ans)


if __name__ == '__main__':
    solve()

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

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

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

print(ans)

Solution (Python):
n=int(input())
S=[0 if i=='.' else 1 for i in input()]
if sum(S)==0 or sum(S)==n:
    print(0)
    exit()
sS=sum(S)
allblack=n-sum(S)
allwhite=sum(S)
bw=10**6
from itertools import accumulate
accS=list(accumulate(S))
for i in range(n):
    bw=min(bw,accS[i]+(n-(i+1))-(sS-accS[i]))
print(min(bw,allblack,allwhite))

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

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


lan0 = []
lan1 = []

if s[0]=='
    lan0.append(0)

cnt0=0
cnt1=0

for i in range(n):
    if s[i] == '.':
        if cnt1 > 0:
            lan1.append(cnt1)
            cnt1=0
            cnt0=1
        else:
            cnt0+=1
    if s[i] == '
        if cnt0 > 0:
            lan0.append(cnt0)
            cnt0=0
            cnt1=1
        else:
            cnt1+=1

if cnt0>0:lan0.append(cnt0)
if cnt1>0:lan1.append(cnt1)



from itertools import accumulate
acc0 = list(reversed(lan0))
acc0 = list(accumulate(acc0))
acc0.reverse()
acc0 = acc0+[0] +[0]


acc1 = [0] + lan1
acc1 = list(accumulate(acc1))
acc1 = [0]+acc1

ans = n
for i in range(len(acc1)):
    ans = min(ans,acc0[i]+acc1[i])

print(ans)

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

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

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

Solution (Python):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    S = input()
    White = np.zeros(n + 1)
    Black = np.zeros(n + 1)

    for i in range(n):
        if S[i] == "
            Black[i + 1] = Black[i] + 1
        else:
            Black[i + 1] = Black[i]

    for i in reversed(range(n)):
        if S[i] == ".":
            White[i] = White[i + 1] + 1
        else:
            White[i] = White[i + 1]

    res = White + Black
    print(int(min(res)))


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    S = input()
    White = [0] * (n + 1)
    Black = [0] * (n + 1)

    for i in range(n):
        if S[i] == "
            Black[i + 1] = Black[i] + 1
        else:
            Black[i + 1] = Black[i]

    for i in reversed(range(n)):
        if S[i] == ".":
            White[i] = White[i + 1] + 1
        else:
            White[i] = White[i + 1]

    res = f_inf
    for i in range(n + 1):
        res = min(res, White[i] + Black[i])

    print(res)


if __name__ == '__main__':
    resolve()

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

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

ans = n+1
for i in range(n+1):
  sub = 2*key[i]+n-i-key[-1]
  if ans > sub:
    ans = sub

print(ans)

Solution (Python):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


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

    if len(set(S)) == 1:
        return print(0)

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


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
INF = 114514191981036436433-4
n = int(input())
s = input()

b = Counter(s)
ans = b["."]

cur = b["."]

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

Solution (Python):
n=int(input())
s=input()
ans=10**9
w=[0]*n
b=[0]*n
cw,cb=0,0
for i in range(n):
  if s[i]==".":
    cw+=1
  else:
    cb+=1
  w[i]=cw
  b[i]=cb

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

Solution (Python):
n=int(input())
s=input()
ans=10**9
w=[0]*n
b=[0]*n
cw,cb=0,0
for i in range(n):
  if s[i]==".":
    cw+=1
  else:
    cb+=1
  w[i]=cw
  b[i]=cb

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

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

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


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


m = 10 ** 6
for i in range(N):
    
    temp = left_black[i] + right_white[i + 1]
    
    m = min(m, temp)
print(m)

Solution (Python):
N,S = open(0).read().split()
ans = 0
ls = []
cnt = 1
p = S[0]
for c in S[1:]:
  if p!=c:
    p = c
    ls.append(cnt)
    cnt = 1
  else:
    cnt += 1
ls.append(cnt)
b = 0
w = 0
if S[0]=='.':
  w = sum(ls[i] for i in range(0, len(ls),2))
  ans = b+w
  for i in range(len(ls)):
    if i%2==0:
      w -= ls[i]
    else:
      b += ls[i]
    ans = min(ans,w+b)
else:
  w = sum(ls[i] for i in range(1,len(ls),2))
  ans = b+w
  for i in range(len(ls)):
    if i%2==0:
      b += ls[i]
    else:
      w -= ls[i]
    ans = min(ans,w+b)

print(ans)

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

if __name__ == '__main__':
    main()

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

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    Ws, Bs = [], []
    c = S[0]
    l = 1
    for i in range(1, N):
        s = S[i]
        if c == s:
            l += 1
        else:
            if c == '.':
                Ws.append(l)
            else:
                Bs.append(l)
            l = 1
            c = s
    if c == '.':
        Ws.append(l)
    else:
        Bs.append(l)
    
    len_ws = len(Ws)
    len_bs = len(Bs)
    if len_ws == 0 or len_bs == 0:
        print(0)
        return
    if len_ws == 1:
        if len_bs == 1:
            if S[0] == '.':
                print(0)
            else:
                print(min(Bs[0], Ws[0]))
        else:
            
            print(min(Ws[0], Bs[0]))
        return
    if len_bs == 1:
        
        print(min(Ws[1], Bs[1]))
        return

    
    sum_w_s, sum_w_r, sum_b_s, sum_b_r = [0]*len_ws, [0]*len_ws,  [0]*len_bs, [0]*len_bs
    sum_w_s[0] = Ws[0]
    sum_w_r[0] = Ws[-1]
    sum_b_s[0] = Bs[0]
    sum_b_r[0] = Bs[-1]
    for i in range(1, len_ws):
        sum_w_s[i] = sum_w_s[i - 1] + Ws[i]
        sum_w_r[i] = sum_w_r[i - 1] + Ws[len_ws - 1 - i]
    for i in range(1, len_bs):
        sum_b_s[i] = sum_b_s[i - 1] + Bs[i]
        sum_b_r[i] = sum_b_r[i - 1] + Bs[len_bs - 1 - i]
    
    ans = min(sum_w_s[-1], sum_b_s[-1])
    if S[0] == '
        for i in range(len_ws - 1):
            a = sum_b_s[i] + sum_w_r[len_ws - 2 - i]
            ans = min(a, ans)
    else:
        ans = min(ans, sum_w_s[-1] - Ws[0])
        for i in range(len_ws - 1):
            a = sum_w_r[i] + sum_b_s[len_bs - 2 - i]
            ans = min(a, ans)
    print(ans)

if __name__ == '__main__':
    main()

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

wr = [0] * (N+1)
bl = [0] * (N+1)

def solve():
    bc = 0
    for i in range(N):
        bl[i] = bc
        if S[i] == '
            bc += 1
    bl[N] = bc
    wc = 0
    for i in range(N-1, -1, -1):
        if S[i] == '.':
            wc += 1
        wr[i] = wc
    wr[N] = 0
    minval = N + 100
    mini = None
    for i in range(N+1):
        cost = bl[i] + wr[i]
        if minval > cost:
            minval = cost
            mini = i
    return minval

print(solve())

Solution (Python):
import sys

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

l = 0
r = n
while l < n and s[l] == ".":
    l += 1
while r > 0 and s[r-1] == "
    r -= 1
if l >= r:
    print(0)
    sys.exit()

A = []
a = 0
b = 0
for i in range(l, r):
    if s[i] == "
        if b > 0:
            A.append([a, b])
            a = 1
            b = 0
        else:
            a += 1
    else:
        b += 1
if b > 0:
    A.append([a, b])


DP = [0, 0]
for i in range(len(A)):
    DPN = DP[:]
    DPN[0] = min(DP) + A[i][1]
    DPN[1] = DP[1] + A[i][0]
    DP = DPN[:]
print(min(DP))

Solution (Python):


















N=int(input())
S=input()
from collections import deque
q=deque(list(S))


while q[0]==".":
  q.popleft()
  if len(q)==0:
    print(0)
    exit(0)
  
while q[-1]=="
  q.pop()
  if len(q)==0:
    print(0)
    exit(0)
  
S="".join(list(q))
pairs=S.replace(".

datas=[[]]*len(pairs)
blackchange=0
for i in range(len(pairs)):
  white=pairs[i].count(".")
  datas[i] = [len(pairs[i])-white,white]
  blackchange+=white


ans=blackchange

for i in range(len(datas)):
  blackchange-=(datas[i][1]-datas[i][0])
  if ans > blackchange:
    ans = blackchange
print(ans)

Solution (Python):
N=int(input())
S=input()
b=[None]*(N+1)
b[0]=0
w=[None]*(N+1)
w[N]=0
for i in range(1,N+1):
    b[i]=b[i-1]+(S[i-1]=='
for i in range(N-1,-1,-1):
    w[i]=w[i+1]+(S[i]=='.')
print(min([x+y for x,y in zip(b,w)]))

Solution (Python):
N = int(input())
S = list(input())
shiro_sum = [0] * (N+1)
kuro_sum = [0] * (N+1)
for i in range(N):
    if S[i] == '.':
        shiro_sum[i+1] = shiro_sum[i] + 1
    else:
        shiro_sum[i+1] = shiro_sum[i] + 0

    if S[i] == '
        kuro_sum[i+1] = kuro_sum[i] + 1
    else:
        kuro_sum[i+1] = kuro_sum[i] + 0

res = 10**9

for i in range(N+1):
    tmp = 0
    
    
    tmp += kuro_sum[i]

    
    
    tmp += shiro_sum[N] - shiro_sum[i]
    res = min(res, tmp)
print(res)

Solution (Python):
N = int(input())
S = list(input())
shiro_sum = [0] * (N+1)
kuro_sum = [0] * (N+1)
for i in range(N):
    if S[i] == '.':
        shiro_sum[i+1] = shiro_sum[i] + 1
    else:
        shiro_sum[i+1] = shiro_sum[i] + 0

    if S[i] == '
        kuro_sum[i+1] = kuro_sum[i] + 1
    else:
        kuro_sum[i+1] = kuro_sum[i] + 0

res = 10**9

for i in range(N+1):
    tmp = 0
    
    
    tmp += kuro_sum[i] - kuro_sum[0]

    
    
    tmp += shiro_sum[N] - shiro_sum[i]
    res = min(res, tmp)
print(res)

Solution (Python):
from itertools import accumulate
n = int(input())
s = list(input())
for i in range(n):
    if s[i] == "
        s[i] = 1
    else:
        s[i] = 0
cs = [0] + list(accumulate(s))
m = n
for i in range(n+1):
    num = cs[i] + (n-i)-(cs[n]-cs[i])
    m = min(m,num)
print(m)

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

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

N = int(input())
S = input()[:-1]
acc = [0]

for Si in S:
    if Si=='
        acc.append(acc[-1]+1)
    else:
        acc.append(acc[-1])

ans = 10**18

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

print(ans)

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

white = [0] * (N + 1)
for i in range(N):
    if S[i] == ".":
        white[i + 1] = white[i] + 1
    else:
        white[i + 1] = white[i]

ans = N
for i in range(N + 1):
    tmp = (i - white[i]) + (white[-1] - white[i])
    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):
n = int(input())
s = list(input())
rw = s.count(".")
rb = n - rw
ans = rw
lw = 0
lb = 0
for i in s:
    if i == ".":
        lw += 1
        rw -= 1
    else:
        lb += 1
        rb -= 1
    ans = min(ans, lb + rw)
print(ans)

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

    s_b = [1 if c=='
    s_w = [1 if c=='.' else 0 for c in s[::-1]]

    s_b = cumsum(s_b)
    s_w = cumsum(s_w)[::-1]

    ans = []
    for i in range(n):
        ans.append(s_b[i]+s_w[i+1])

    print(min(ans))

def cumsum(a):
    s = 0
    sums = [0]
    for a_i in a:
        s+=a_i
        sums.append(s)

    return sums


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
S=list(input())
W=[0]*(n+1)
B=[0]*(n+1)
for i in range(n):
  if S[i]=="
    B[i+1]=B[i]+1
  else:
    B[i+1]=B[i]
for i in range(n-1,-1,-1):
  if S[i]==".":
    W[i]=W[i+1]+1
  else:
    W[i]=W[i+1]
ans=10**10
for i in range(n+1):
  a=W[i]+B[i]
  if a<ans:
    ans=a
print(ans)

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

aw=0
ab=0
for i in range(len(l)):
    aw+=l[i][0]
    ab+=l[i][1]
ans=[]
ans.append(aw)
ans.append(ab)
tmpw=0
tmpb=0
val=0
for i in range(len(l)):
    tmpw+=l[i][1]
    tmpb+=l[i][0]
    val=(ab-tmpw)+tmpb
    ans.append(val)
print(min(ans))

Solution (Python):
N = int(input())
S = input()
t_min = min(S.count("
S_first = 0
S_second = S.count(".")
for i in range(0,N):
    if S[i] == "
        S_first += 1
    else:
        S_second -= 1
    t = S_first + S_second
    t_min = min(t_min, t)
print(t_min)

Solution (Python):

n = int(input())
s = input()
INF = 10**9
white_cnt = s.count('.')
black_cnt = 0
ans = INF
for c in s:
    ans = min(ans, black_cnt + white_cnt)
    if c == '
        black_cnt += 1
    else:
        white_cnt -= 1
else:
    ans = min(ans, black_cnt + white_cnt)

print(ans)

Solution (Python):
import itertools
n = int(input())
s = [i for i in input()]
cnt_s, cnt_d = [0]*(n+1), [0]*(n+1)
for i in range(n):
    if s[i] == "
        cnt_s[i+1] = 1
    else:
        cnt_d[i+1] = 1
cnt_s, cnt_d = list(itertools.accumulate(cnt_s)), list(itertools.accumulate(cnt_d))
ans = 10**6
cnt_d_l = cnt_d[-1]
for i in range(n+1):
    ans = min(ans, cnt_s[i] - cnt_s[0] + (cnt_d_l - cnt_d[i]))
print(ans)

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


black=c.count('
white=n-black
left=0
right=white

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

Solution (Python):
n = int(input())
s = list(input())
b_c,w_c = s.count('
ans = w_c
b_r,w_r = 0,0
for i in range(n-1):
    if s[i]=='
    else:w_r+=1
    if s[i]!=s[i+1]:
        ans = min(ans,b_r+w_c-w_r)
if s[-1]=='
else:w_r+=1
ans = min(ans,b_r+w_c-w_r)
print(ans)

Solution (Python):
def main():
    n = int(input())
    s = input()
    a = [0]*n
    b = [0]*n
    for i in range(n):
        if s[i] == "
            a[i] += 1
        if 0 < i:
            a[i] += a[i-1]
    for i in reversed(range(n)):
        if s[i] == ".":
            b[i] += 1
        if i < n-1:
            b[i] += b[i+1]
    ans = float("inf")
    for i in range(1, n):
        ans = min(ans, a[i-1]+b[i])
    ans = min(ans, b[0], a[n-1])
    print(ans)

if __name__ == "__main__":
    main()

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

sharp_list = [0 for i in range(n)]
dot_list = [0 for i in range(n)]
for i in range(n):
    if s[i] == '
        sharp_list[i] = sharp_list[i-1] + 1
    else:
        sharp_list[i] = sharp_list[i-1]
sharp_list = [0] + sharp_list
for i in range(n-1,-1,-1):
    if s[i] == '.':
        dot_list[i] = dot_list[(i+1)%n] + 1
    else:
        dot_list[i] = dot_list[(i+1)%n]
dot_list += [0]
ans = 10**9
for i in range(n+1):
    ans = min(sharp_list[i]+dot_list[i],ans)
print(ans)

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

ldp = [0] * (N+1)
rdp = [0] * (N+1)

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

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



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

print(ans)

Solution (Python):
n=int(input())
s=input()
l=[]
k=len(s.replace(".",""))
ans=n-k

cnt=0

for i in range(n):
  cnt+=int(s[i]=="
  ans=min(ans,2*cnt+n-i-1-k)
print(ans)

Solution (Python):
n = int(input())
s = list(map(str,input()))
left = 0
right = 0
for i in range(n):
    if s[i]==".":
        right += 1
ans = right
if s[0]==".":
    right -= 1
for j in range(1,n):
    if s[j-1]=="
        left += 1
    if s[j]==".":
        right -= 1
    ans = min([ans,left+right])
if s[n-1]=="
    left += 1
ans = min([ans,left])
print(ans)

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

w = S.count('.')
b = N - w
ans = min(w, b)
l, r = 0, w

for si in S:
    if si == '
        l += 1  
    else:
        r -= 1  
    ans = min(ans, l+r)

print(ans)

Solution (Python):
from decimal import *
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False



def main():
    N = I()
    s = S()
    N = len(s)
    white = [0 if s[i] == '.' else 1 for i in range(N)]
    count = sum(white)
    lst = set()
    lst.add(count)

    for i in range(N-1, -1, -1):
        if white[i]:
            count -= 1
        else:
            count += 1
        lst.add(count)
    print(min(lst))


if __name__ == '__main__':
    main()

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

count_white = [0]*N

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

white_total = count_white[-1]
ans = 10**9
for i in range(N):
    num_black_left = i+1 - count_white[i]
    num_white_right = white_total - count_white[i]

    ans_temp = num_black_left + num_white_right



    ans = min(ans, ans_temp)

print min(ans, white_total)

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

s_list = []

for item in s:
    if item == '.':
        s_list.append(0)
    else:
        s_list.append(1)

min_val = s_list.count(0)

left_val = 0
right_val = s_list.count(0)

for i in range(len(s_list)):
    if s_list[i] == 0:
        right_val -= 1
        min_val = min(left_val + right_val, min_val)
    else:
        left_val += 1

print(min_val)

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

l = [[0]*2 for _ in range(N+1)]
r = [[0]*2 for _ in range(N+1)]

for i,j in enumerate(s, start=1):
    l[i][0] = l[i-1][0]
    l[i][1] = l[i-1][1]
    if j=="
        l[i][0] += 1
    else:
        l[i][1] += 1

for i,j in enumerate(s[::-1], start=1):
    r[N-i][0] = r[N-i+1][0]
    r[N-i][1] = r[N-i+1][1]
    if j=="
        r[N-i][0] += 1
    else:
        r[N-i][1] += 1

ans = N
for i in range(N+1):
    ans = min(ans, l[i][0]+r[i][1])

print(ans)

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

l, r = [[0]*2 for _ in range(N+1)], [[0]*2 for _ in range(N+1)]
for i,j in enumerate(s, start=1):
    if j=="
        l[i][1] = l[i-1][1]
        l[i][0] = l[i-1][0] + 1
    else:
        l[i][0] = l[i-1][0]
        l[i][1] = l[i-1][1] + 1

for i,j in enumerate(s[::-1], start=1):
    if j=="
        r[N-i][1] = r[N-i+1][1]
        r[N-i][0] = r[N-i+1][0] + 1
    else:
        r[N-i][0] = r[N-i+1][0]
        r[N-i][1] = r[N-i+1][1] + 1

ans = N
for i in range(N+1):
    ans = min(ans, l[i][0]+r[i][1])

print(ans)

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

l, r = [[0]*2 for _ in range(N+1)], [[0]*2 for _ in range(N+1)]
for i,j in enumerate(s, start=1):
    if j=="
        l[i][1] = l[i-1][1]
        l[i][0] = l[i-1][0] + 1
    else:
        l[i][0] = l[i-1][0]
        l[i][1] = l[i-1][1] + 1

for i,j in enumerate(s[::-1], start=1):
    if j=="
        r[N-i][1] = r[N-i+1][1]
        r[N-i][0] = r[N-i+1][0] + 1
    else:
        r[N-i][0] = r[N-i+1][0]
        r[N-i][1] = r[N-i+1][1] + 1





ans = N
for i in range(N+1):
    ans = min(ans, l[i][0]+r[i][1])

print(ans)

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

w = s.count('.')
b = n - w
ans = min(w, b)
r = 0
l = w
for si in s:
    if si == '
        r += 1
    else:
        l -= 1
    if ans > r + l:
        ans = r + l
print(ans)

Solution (Python):
N = int(input())
S = input()
lS = len(S)
l = 0
bw = [0, 0]
for i in range(lS):
    if (S[i] == "."):
        bw[1] += 1

ans = sum(bw)
for i in range(lS):
    if (S[i] == "
        bw[0] += 1
    if (S[i] == "."):
        bw[1] -= 1

    if (ans > sum(bw)):
        ans = sum(bw)

print(ans)

Solution (Python):
n = int(input())
s = str(input())
White_rui = [0]
Black_rui = [0]

white = 0
black = 0
for i in range(n):
    if s[i] == '.':
        white += 1
    else:
        black += 1
    White_rui.append(white)
    Black_rui.append(black)

ans = 10**6
for i in range(n):
    white_to_black = White_rui[-1] - White_rui[i+1]
    black_to_white = Black_rui[i] - Black_rui[0]
    ans = min(ans, white_to_black+black_to_white)

print(ans)

Solution (Python):
N = int(input())
S = list(input())
data = [0] * (N + 2)
cnt = 0
for i in range(N):
    if S[i] == "
        cnt += 1
    data[i + 1] = cnt
data[-1] = cnt
ans = float("inf")
for i in range(N + 1):
    turn = data[i] + N - i - data[-1] + data[i]
    if ans > turn:
        ans = turn
print(ans)

Solution (Python):
N=int(input())
S=input()
leftblack=0
rightwhite=0
for i in range(0,N):
    if S[i]==".":
        rightwhite+=1
ans=leftblack+rightwhite
for i in range(0,N):
    if S[i]=='.':
        rightwhite-=1
    else:
        leftblack+=1
    test=leftblack+rightwhite
    if ans>test:
        ans=test

print(ans)

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

N = I()
S = input()

blacks = S.count('
if blacks == 0:
    print(0)
    exit(0)

ans = blacks



w = [0] * N
b = [0] * N
for i, c in enumerate(S):
    if i == 0:
        continue
    if S[i - 1] == '
        b[i] += 1
    if i < N - 1:
        b[i + 1] = b[i]
for i, c in enumerate(reversed(S)):
    i = N - i - 1
    if i == N - 1:
        if c == '.':
            w[i] = 1
        continue
    w[i] = w[i + 1]
    if c == '.':
        w[i] += 1


for i, c in enumerate(S):
    if c == '
        ans = min(ans, w[i] + b[i])

print(ans)

Solution (Python):
def main():
    length = int(input())
    stones = list(input())
    white = [0] * length
    if stones[0] == ".":
        white[0] = 1
    for i in range(1, length):
        if stones[i] == ".":
            white[i] = white[i - 1] + 1
        else:
            white[i] = white[i - 1]
    answer = min(white[-1], length - white[-1])
    for i in range(length):
        answer = min(answer, i + 1 + white[-1] - 2 * white[i])
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = list(input())
b = [0] * n
w = [0] * n
x,y = 0,0
ans = 0
for i in range(n):
    if s[i] == '
        x += 1
    else:
        y += 1
    b[i] = x
    w[i] = y

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

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

wn = s.count('.')
bn = n - wn
ans = min(wn,bn)

lw = 0
lb = 0
for i in range(n):
  if s[i]=='.':
    lw += 1
  else:
    lb += 1      
  ans = min(ans, lb + (wn - lw))
  
print(ans)

Solution (Python):

import sys
INF = 1<<48

def solve(N: int, S: str):
    b = [1 if S[i] == '
    w = [1 if S[i] == '.' else 0 for i in range(N)]

    rb = [0] * (N+1)
    for i in range(N):
        rb[i+1] = rb[i] + b[i]

    rw = [0] * (N+1)
    for i in range(N-1, -1, -1):
        rw[i] = rw[i+1] + w[i]

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

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = next(tokens)  
    solve(N, S)

if __name__ == '__main__':
    main()

Solution (Python):


N = int(input())
S = list(input())
b = [0] * N
w = [0] * N
x, y = 0, 0
ans = 0

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

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

Solution (Python):
N = int(input())
S = input()
lb = 0
rw = sum([s == "." for s in S])
ans = rw

for s in S:
  if s == ".":
    rw -= 1
  else:
    lb += 1
  ans = min(ans, rw+lb)
print(ans)

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

Solution (Python):
import sys


def main():
    N = int(input())
    s = input()
    ans = s.count(".")
    count = ans
    for st in s:
        if st == "
            count += 1
        else:
            count -= 1
        ans = min(ans,count)
        
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = [0 if s == "
ruisekiwa = [0]*(N+2)
i = 1
r = 0
while i <= N:
  r = r+S[i-1]
  ruisekiwa[i] = r
  i += 1
ruisekiwa[N+1] = ruisekiwa[N]
ans = 10**10
i = 1
while i <= N+1:
  towhite = (i-1)-(ruisekiwa[i-1]-ruisekiwa[0])
  toblack = ruisekiwa[N+1]-ruisekiwa[i-1]
  ans = min(ans, towhite+toblack)
  i += 1
print(ans)

Solution (Python):
N=int(input())
S=input()
if S=='
  print(0)
  exit()
rightB=0
for i in S:
  if i=='
    rightB+=1
rightW=N-rightB
leftB=0
leftW=0
ans=min(rightB,rightW)
for i in range(N):
  if S[i]=='.':
    leftW+=1
    rightW-=1
    d=rightW+leftB
    ans=min(ans,d)
  else:
    leftB+=1
    rightB-=1
    d=rightW+leftB
    ans=min(ans,d)
print(ans)

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

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

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

print(ans)

Solution (Python):
def main():
    N = int(input())
    S = input()
    if len(set(S)) == 1:
        return print(0)
    w = S.count(".")
    b = 0
    ans = w
    for s in S:
        if s == "
            b += 1
        else:
            w -= 1
        ans = min(ans, b+w)
    print(ans)


if __name__ == '__main__':
    main()

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

count = []
for i in range(N):
    count.append([0,0])

cb = 0
for i in range(N):
    count[i][0] = cb
    if S[i] == "
        cb += 1
cw = 0
for i in range(N):
    count[N-i-1][1] = cw
    if S[N-i-1] == ".":
        cw += 1

ans = 10**10
for i in range(N):
    ans = min(ans,sum(count[i]))
print(ans)

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

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

w = [0 for k in range(n+1)]
c = 0
for k in range(n):
    if s[-k-1] == ".":
        c += 1
    w[-k-2] = c

ans = 10**9
for k in range(n+1):
    ans = min(ans,b[k]+w[k])

print(ans)

Solution (Python):

n = int(input())
s = input()
white = sum([1 for i in s if i == "."])
ans = white
l = 0 
for i in range(n):
    if s[i] == ".": l += 1
    
    ans = min(ans,i+1+white-2*l)
print(ans)

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

Solution (Python):
n = int(input())
s = input()
best_cost = s.count('.')
cost = best_cost
for i in range(n):
  if s[i] == '
    cost += 1
  else:
    cost -= 1
  if cost < best_cost:
    best_cost = cost

print(best_cost)

Solution (Python):
import numpy as np
def f(lst):
    return np.cumsum(lst)

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

res1 = s.count('.')
res2 = s.count('

a = [0]*n
b = [0]*n

for i in range(n):
    if s[i]=='.':
        a[i] += 1
    else:
        b[i] += 1
cum_a = f(a).tolist()
cum_b = f(b).tolist()
res3 = np.inf
for i in range(n):
    if a[i]==1:
        res3 = min(res3, cum_b[i]+(res1-cum_a[i]))

print(min(res1, res2, res3))

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

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

white_count = [0]*(N+1)
black_count = [0]*(N+1)

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

    
answer = 10**6
for i in range(N+1):
  answer = min(answer,black_count[i]+white_count[N-i])
  
print(answer)