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

b = S.count('
w = S.count('.')
black = [0]*int(3e5)
white = [0]*int(3e5)

cnt = 0

for i in range(N):
    check = True

    if S[i] == '
        if not black[cnt]:
            cnt += 1
        black[cnt] += 1
    else:
        if not white[cnt]:
            cnt += 1
        white[cnt] += 1

black2 = [0]*int(3e5)
white2 = [0]*int(3e5)

wa = 0
for i in range(int(3e5)):
    wa += black[i]
    black2[i] = wa

wa = 0
for i in range(int(3e5)):
    wa += white[i]
    white2[i] = wa

ans = int(3e5)
for i in range(N+1):
    check = black2[i] + w - white2[i]
    ans = min(check, ans)

print(ans)

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

if '
    print(0)
elif '.' not in S:
    print(0)
else:
    l=[0 for i in range(N+1)]
    w = 0
    for i in range(N):
        if S[i] == '
            l[i+1] = l[i] + 1
        else:
            l[i+1] = l[i] - 1
            w += 1          

    print(min(l)+w)

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

one = []
zero = []
cnt_one = 0
cnt_zero = 0

if s[0] == "
    zero.append(0)

for i in s:
    if i == "
        cnt_one += + 1
        if cnt_zero != 0:
            zero.append(cnt_zero)
            cnt_zero = 0
    else:
        cnt_zero += 1
        if cnt_one != 0:
            one.append(cnt_one)
            cnt_one = 0

if cnt_one != 0:
    one.append(cnt_one)
else:
    zero.append(cnt_zero)

if s[-1] == "
    zero.append(0)

sum = 0
sum_zero = [0]
for i in range(len(one)):
    sum += zero[len(one)-i]
    sum_zero.append(sum)

sum = 0
sum_one = [0]
for i in range(len(one)):
    sum += one[i]
    sum_one.append(sum)


print(min(sum_one[i] + sum_zero[len(one)-i] for i in range(len(one)+1)))

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

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

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

ans = 9999999999999999999
for i in range(n+1):
    ans = min(ans, left_blacks[i] + right_whits[i])

print(ans)

Solution (Python):
n = int(input())
s = input()
nb = s.count('
nw = s.count('.')
if nw == n or nb == n:
    print(0)
    exit()
lb = 0
rw = nw

b = False
ans = float('inf')
for i in range(n):
    if b == False and s[i] == '
        ans = min(ans, lb + rw)
        b = True
        lb += 1
    elif s[i] == '
        lb += 1
    elif s[i] == '.':
        rw -= 1
        b = False
ans = min(ans, nb)
print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 10 ** 9
White = [0] * (N + 1)
Black = [0] * (N + 1)

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

ans = min(ans, Black[N], White[N])

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

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator



inf = float('inf')
N = 0
S = ""


def set_inputs():
    global N, S
    N = get_int()
    S = get_str()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    
    s = "".join(itertools.dropwhile(lambda c: c == ".", S))
    black = []
    white = []
    count = 0
    prev = "
    for c in s:
        if c == prev:
            count += 1
        else:
            if prev == "
                black.append(count)
            else:
                white.append(count)
            prev = c
            count = 1
    if prev == ".":
        white.append(count)
    t = len(black)
    forward = list(itertools.accumulate([0] + black))
    backward = list(itertools.accumulate([0] + white[::-1]))
    print(min([forward[i] + backward[t-i] for i in range(t+1)]))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


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


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = list(str(input()))
black = 0
white = 0
count = 0
find = False

for i in reversed(range(0,n)):
    if find == True and s[i] == '
        black += 1
    elif s[i] == '.':
        white += 1
        find = True
    if black == white and find == True:
        count += white
        white = 0
        black = 0
        find = False
count += black
print(count)

Solution (Python):
from collections import Counter
N = int(input())
S = input()
pt = S.find("
ct = 0
bl_ls = []
wh_ls = []
last_wh = 0
last_bl = 0
S = "." + S + "
N += 2
for i in range(N):
    if S[i] == ".":
        last_wh += 1
        wh_ls.append(last_wh)
        bl_ls.append(last_bl)
    else:
        last_bl += 1
        wh_ls.append(last_wh)
        bl_ls.append(last_bl)
_min = 1e9
for i in range(N):
    res = wh_ls[N-1] - wh_ls[max(0,i-1)] + bl_ls[max(0,i-1)]
    _min = res if res < _min else _min
print(_min)

Solution (Python):
N = int(input())
S = input()
white = S.count(".")
if white == 0:
    print(0)
    exit()
if S[0] == "
    B = [1]*N
    W = [white]*N
else:
    B = [0]*N
    W = [white-1]*N
for i in range(1,N):
    if S[i] == "
        B[i] = B[i-1] + 1
        W[i] = W[i-1]
    else:
        B[i] = B[i-1]
        W[i] = W[i-1] - 1


Ans = [B[i]+W[i] for i in range(N)]
print(min(min(Ans),white,N-white))

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


left_white = 0
right_black = 0

for ss in s:
    if ss == '.':
        left_white += 1
min_sum = left_white + right_black


for ss in s:
    if ss == '.':
        left_white -= 1
    else:
        right_black += 1
    min_sum = min(min_sum, left_white + right_black)
print(min_sum)

Solution (Python):
n = int(input())
S = input()
left = []
right = []
cl = 0
cr = 0
for i in range(n):
  left += [cl]
  if S[i] == "
    cl += 1
  right += [cr]
  if S[n - 1 -i] == ".":
    cr += 1
min = cl
for i in range(n):
  if S[i] == "
    p = left[i] + right[n - 1 -i]
    if p < min:
      min = p
print(min)

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


import sys
import math


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

csum = [[0 for j in range(2)] for i in range(n+1)]



for i in range(1,n+1):
  csum[i][0] = csum[i-1][0]
  if s[i-1] == "
    csum[i][0] += 1

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

ans = n*2
for i,j in csum:
  ans = min(ans,i+j)

print(ans)

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

Solution (Python):



N = int(input())
S = ['.'] + [x for x in input()] + ['

cum_white = []
count = 0
for i, s in enumerate(S):
    if s == '
        count += 1
    cum_white.append(count)
    
min_num = int(1e10)
for i, n_white in enumerate(cum_white):
    num = n_white + (N + 1 - i - (cum_white[-1] - n_white))
    min_num = min(min_num, num)
    
print(min_num)

Solution (Python):
n=int(input())
s=input()
a=[]
for i in range(n):
    if i==0:
        if s[0]=="
            a.append(1)
        else:
            a.append(0)
    else:
        if s[i]=="
            a.append(a[i-1]+1)
        else:
            a.append(a[i-1])
min=n
for i in range(n):
    m=a[i]
    r=n-i-1-(a[n-1]-a[i])
    q=m+r
    if q<min:
        min=q
if a[n-1]==n:
    min=0
if min>a[n-1]:
    min=a[n-1]
if min>n-a[n-1]:
    min=n-a[n-1]
print(min)

Solution (Python):
n=int(input())
s=list(input())
INF=10**10
cost_w=0
cost_b=s.count(".")
ans=[INF for i in range(n+1)]
ans[0]=cost_b
for i in range(n):
    if s[i]=="
        cost_w+=1
    else:
        cost_b-=1
    ans[i+1]=cost_w+cost_b
print(min(ans))

Solution (Python):
import sys
import numpy as np

readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]

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

w = 0
b = 0
for c in s:
    w += int(c == '.')
    b += int(c == '


wc = 0
bc = 0
ret = min(w, b)
for c in s:
    wc += int(c == '.')
    bc += int(c == '

    ret = min(ret, bc + (w - wc))
print(ret)

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

w = '.'
b = '

white = [0 for i in range(n+1)]
black = [0 for i in range(n+1)]
ans = [0 for i in range(n+1)]
for i in range(n):
    if S[i] == b:
        black[i+1] = black[i] + 1
    else:
        black[i+1] = black[i]
    if S[-i-1] == w:
        white[-i-2] = white[-i-1] + 1
    else:
        white[-i-2] = white[-i-1]

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

Solution (Python):
def get_input():
    N = int(input())
    S = input().strip()
    return N,S

w="."
b="


def solve(N,S):
    cur = 0
    whites = []
    for i in range(N):
        if S[i] == w:
            cur+=1
            whites.append(cur)
        else:
            whites.append(cur)
    cand = []
    for i in range(N):
        if i == 0:
            cand.append(whites[N-1])
        else:
            cand.append(i -whites[i] + (whites[N-1] - whites[i-1])) 
    cand.append(N-whites[-1]) 
    return min(cand)

if __name__ =="__main__":
    N,S = get_input()
    ans = solve(N,S)
    print(ans)

Solution (Python):
def chmin(a,b):
  if a < b:
    return a
  else:
    return b

N = int(input())
S = list(input() + "
dp = [[0,0] for i in range(N+2)]
dp[0][1] = 1

for i in range(N):
  if( S[i] == "
    if( S[i+1] == "
      dp[i+1][0] = chmin(dp[i][0],dp[i][1])
      dp[i+1][1] = dp[i][1]+1
    else:
      dp[i+1][0] = dp[i][1]
      dp[i+1][1] = chmin(dp[i][0],dp[i][1]) + 1
  else:
    if( S[i+1] == "
      dp[i+1][0] = chmin(dp[i][0],dp[i][1])
      dp[i+1][1] = dp[i][0]+1
    else:
      dp[i+1][0] = dp[i][0]
      dp[i+1][1] = chmin(dp[i][0],dp[i][1]) + 1
print( chmin(dp[N-1][0],dp[N-1][1]) )

Solution (Python):


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







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

if S[0] == ".":
    W[0] = 1
else:
    B[0] = 1

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






mn = min(W[-1], B[-1]) 
for i in range(1, N):
    toW = i - W[i-1]
    toB = W[-1] - W[i-1]
    mn = min(mn, toB+toW)
print(mn)

Solution (Python):


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

result = 999999
left = 0
right = len([x for x in S if x == '.'])
result_i = left + right
result = result_i

for i in range(0, N):
    if S[i] == '.':
        right -= 1
    if S[i] == '
        left += 1
    result_i = left + right
    result = min(result, result_i)
print(result)

Solution (Python):
N=int(input())
S=input()
whites=[0]*(N+1)
whites[0]=1
curwhi=1
for k,i in enumerate(S):
    if i==".":
        curwhi+=1
    whites[k+1]=curwhi
curmin=1000000
allwhi=whites[N]
for k,w in enumerate(whites):
    new=k+1+allwhi-2*w
    curmin=min(new,curmin)
print(curmin)

Solution (Python):

n = int(input())

s = input()


white = s.count('.')

lb = 0
rw = white


ans = rw + lb;

for c in s:

    if c == '.':
        rw -= 1
    else:
        lb += 1


    t = rw + lb 

    ans = min(t, ans)

print(ans)

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

black = []
white = []

for i in range(N):
    prev = 0 if i == 0 else white[i-1]
    if S[N-i-1] == '.':
        white.append(prev + 1)
    else:
        white.append(prev)
    prev = 0 if i == 0 else black[i-1]
    if S[i] == '
        black.append(prev + 1)
    else:
        black.append(prev)
white = [0] + white
black = [0] + black
mn = 1e9

for i in range(N+1):
    res = white[N-i] + black[i]
    if res < mn:
        mn = res

print(mn)

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

ans = 10 ** 6
count=0
l_c = [0] * n
for i, c in enumerate(s):
    if c == "
        count += 1
    l_c[i] = count
count=0
r_c = [0] * n
for i, c in enumerate(s[::-1]):
    if c == ".":
        count += 1
    r_c[n-1-i] = count

for i in range(1,n):
    ans = min(ans, l_c[i-1] + r_c[i])

ans = min(ans, s.count("
print(ans)

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
n = ip()                                     


a = input()                                  






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

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

Solution (Python):
N = int(input())
S = input()
T = [0]
for s in S:
    T.append(T[-1] if s == "." else 1+T[-1])
sm = T[-1]
mini = 100000000000000
length = N+1
for t in T:
    length -= 1
    if mini > t+(length-(sm-t)):
        mini = t+(length-(sm-t))
print(mini)

Solution (Python):

N = int(input())
S = input()
lb = 0
lw = 0
rb = S.count("
rw = S.count(".")
ans = lb + rw
for i in range(N):
    if S[i] == "
        lb += 1
        rb -= 1
    else:
        lw += 1
        rw -= 1
    ans = min(ans,lb+rw)
print (ans)

Solution (Python):
n=int(input())
s=input()
ndot=0
nx=0
mx=10000000
for i in range(n+1):
    if i==0:
        ndot=sum([1 for i in s if i=="."])
        nx=0
    else:
        if s[i-1]==".":
            ndot-=1
        elif s[i-1]=="
            nx+=1
    mx=min(mx,nx+ndot)
print(mx)

Solution (Python):
import sys
from itertools import accumulate

def main():
    input = sys.stdin.readline
    N = int(input())
    S = [0 if c == '.' else 1 for c in input().strip()]
    T = [0] + list(accumulate(S))

    B = T[N]
    ans = 10**5
    for i in range(N+1):
        convert_w = T[i]
        convert_b = (N - i) - (B - T[i])
        ans = min(ans, convert_w + convert_b)

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
n=int(input())
s=list(input())	
s2 = s[:]

l=[0]
cnt1=0
for i in range(len(s)):
    if(s[i] == "
        cnt1 +=1
    l.append(cnt1)
ansl=[]
for i in range(len(l)):
    ansl.append(n-i-cnt1+2*l[i])



print(min(ansl))

Solution (Python):

import copy
import numpy as np
import random
import bisect 
import math

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

ans = 10**6
blacks = [0 for i in range(N)]
black = 0
white = 0
for i in range(N):
    if S[i] == "
        black += 1

    else:
        white += 1
    blacks[i] = black

ans = min(black,white,ans)


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

print(ans)

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

white = [0]*(N+2)
black = [0]*(N+2)

black[0] = 0
white[N] = 0

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

    if S[N-i-1] == ".":
        white[N-i-1] = white[N-i]+1
    else:
        white[N-i-1] = white[N-i]

count_min = 2 * 10 ** 6
for i in range(N+1):
    if black[i]+white[i] < count_min:
        count_min = black[i]+white[i]

print(count_min)

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

w = s.count('.')
m = w
for c in s:
    if c == '.':
        w -= 1
        if w < m: m = w
    elif c == '
        w += 1

print(m)

Solution (Python):
from collections import Counter
N = int(input())
S = input()
BN = [0 for i in range(N)]
if S[0] == '.':
    BN[0] = 0
else:
    BN[0] = 1
for i in range(1, N):
    if S[i] == '.':
        BN[i] = BN[i-1]
        continue
    BN[i] = BN[i-1] + 1
ans = min(N-BN[-1], BN[-1])
for i in range(1,N):
    white = BN[i-1]
    black = N-i-(BN[-1]-BN[i-1])
    
    
    ans = min(ans, white+black)
print(ans)

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

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

left_w = [0] * (N)
right_b = [0] * (N)

for i in range(N):
  if i == 0:
    left_w[0] = int(S[0] == '
    right_b[-1] = int(S[-1] == '.')
  else:
    left_w[i] = left_w[i-1] + int(S[i] == '
    right_b[-i-1] = right_b[-i] + int(S[-i-1] == '.')
left_w = [0] + left_w
right_b = right_b + [0]



res = N
for i in range(N+1):
  res = min(res, right_b[i] + left_w[i])
print(res)

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

Solution (Python):
n=int(input())
s=input()
'''
k=int(input())
a,b,c=map(int,input().split())
a=[int(i) in range(n)]
a=[0]*n
for i in range(n):
    a.append(int(i))
'''
pre=0
b=[0]*n
w=[0]*n

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


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

Solution (Python):

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

white_change_counts = [-1] * (N + 1)
black_change_counts = [-1] * (N + 1)
max_count = -1
white_change_counts[0] = 0
black_change_counts[0] = S.count('.')
min_count = white_change_counts[0] + black_change_counts[0]

for index in range(1, N + 1):
    if S[index - 1] == ".":
        white_change_counts[index] = white_change_counts[index - 1]
        black_change_counts[index] = black_change_counts[index - 1] - 1
    else:
        white_change_counts[index] = white_change_counts[index - 1] + 1
        black_change_counts[index] = black_change_counts[index - 1]

    count = white_change_counts[index] + black_change_counts[index]
    if min_count > count:
        min_count = count

print(min_count)

Solution (Python):
N = int(input())
S = input()
w = 0
b = 0
for c in S:
    if c == '.':
        w += 1
    if c == '
        b += 1
w0 = 0
b0 = 0
min_change = w
for c in S:
    if c == '.':
        w0 += 1
        w -= 1
    if c == '
        b0 += 1
        b -= 1
    min_change = min(min_change, w + b0)
print(min_change)

Solution (Python):


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

a = [0] * n

cnt = 0
for i in range(n-1,-1,-1):
    if s[i] == ".":
        cnt += 1
    a[i] = cnt

needs = [n]
cnt = 0
for i in range(n):
    if s[i] == "
        need = 0
        cnt += 1
        need += a[i]
        needs.append(need + cnt - 1)
need = min(needs)

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

print(min(black,need))

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

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

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

clusters=[]
W, B = 0, 1
c_prev = None
seq=0
for c in S:
    if c != c_prev and c_prev!=None:
        clusters.append(seq)
        seq=0
    seq+=1
    c_prev=c
    
clusters.append(seq)
    
if S[0]=='.':
    clusters = [0] + clusters
if S[-1]=='
    clusters.append(0)

min_nflip = nflip = sum(clusters[1::2])
for i in range(len(clusters)//2):
    nflip+=clusters[i*2]-clusters[i*2+1]
    min_nflip = min(min_nflip, nflip)

print(min_nflip)

Solution (Python):
n=int(input())
s=list(str(input()))
m = [0 for i in range(len(s))]
if s[0] == ".":
    m[0] = 1
else:
    m[0] = 0
for i in range(1,len(s)):
    if s[i] == ".":
        m[i] = m[i-1]+1
    else:
        m[i] = m[i-1]
l = [0 for i in range(len(s)+1)]
l[0] = m[-1]
for i in range(1,len(s)+1):
    l[i] = i-m[i-1] + m[-1]-m[i-1]
print(min(l))

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

ruiseki_r = 0
ruiseki_l = 0


left_ruiseki = []
right_ruiseki = []


for s in S:
    if s == '
        ruiseki_l += 1
    left_ruiseki.append(ruiseki_l)


for s in S[::-1]:
    if s == '.':
        ruiseki_r += 1
    right_ruiseki.append(ruiseki_r)

right_ruiseki = right_ruiseki[::-1]
right_ruiseki.append(0)

cost = float('inf')

for i in range(N):
    tmpcost = left_ruiseki[i] + right_ruiseki[i+1]
    cost = min(cost,tmpcost)

ans = min(left_ruiseki[N-1], right_ruiseki[0], cost)

print(ans)

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

w = 0
b = 0
for i in range(len(S)):
    if S[i] == ".":
        w += 1

c = w
for i in range(len(S)):
    if S[i] == ".":
        w -=1
    else:
        b += 1
    if c > w + b:
        c = w + b
print(c)

Solution (Python):
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

n = int(input())
s = input()
b = [0]
w = [0]
for i in range(n):
    bt = b[i]
    wt = w[i]
    if s[i] == "
        bt += 1
    else:
        wt +=1
    b.append(bt)
    w.append(wt)

cost = 1000000000000

for i in range(0,n+1):
    temp = 0
    temp += b[i]
    temp += w[-1]-w[i]

    
    
    

    if cost > temp:
        cost = temp
    
    





print(cost)

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

w = s.count('.')
b = 0
ret = w
for i in range(0, n):
    if s[i] == '.':
        w -= 1
    else:
        b += 1
    if ret > w + b:
        ret = w+b
print(ret)

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

dp = [None]*(N+1)

dp[0] = 0
for s in S:
  if s == '.':
    dp[0] += 1

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

print(min(dp))

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

changes = 0

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

min_changes = changes

for i in range(n):
    if s[n - 1 - i] == ".":
        changes += 1
    else:
        changes -= 1
    
    if changes < min_changes:
        min_changes = changes

print(min_changes)

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

WHITE = '.'
BLACK = '

white_dp = [0 for _ in range(N)]
black_dp = [0 for _ in range(N)]

black2white = 0
for i in range(N):
    black2white += 1 if S[i] == BLACK else 0
    white_dp[i] = black2white
white_dp = [0] + white_dp

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

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

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

s = []
for i in input():
  if i == '.':
    s.append(0)
  else:
    s.append(1)

black_num = sum(s)
change_num = n - black_num
ans = change_num

for i in s:
  if i == 0:
    change_num -= 1
  else:
    change_num += 1
  ans = min(ans,change_num)
    
print(ans)

Solution (Python):
n = int(input())
s = input()
left = []
right = [0 for i in range(n)]
br = 0
for i in range(n):
    if s[i] == "
        br += 1
    left.append(br)
br = 0
for i in range(n):
    if s[n - i - 1] == ".":
        br += 1
    right[n - i - 1] = br
p = []
for i in range(n - 1):
    p.append(left[i] + right[i + 1])
p.append(left[n - 1])
p.append(right[0])
print(min(p))

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

bk_all = wh_all = 0
for s in S:
    if s == "
        bk_all += 1
    else:
        wh_all += 1

ans = min(bk_all, wh_all)


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

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

black = 0
black_counts = [0]*N
white = 0
white_counts = [0]*N
for i in range(N):
    if S[i] == '
        black += 1
    black_counts[i] = black

    if S[-1-i] == '.':
        white += 1
    white_counts[N-1-i] = white

min_count = min(black_counts[N-1], white_counts[0])
for i in range(N-1):
    min_count = min(min_count, black_counts[i] + white_counts[i+1])
print(min_count)

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

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

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

min_num = min(right_white, n-right_white)

for x in s:
    if x == ".":
        right_white -= 1
    else:
        left_black += 1

    min_num = min(min_num, right_white+left_black)

print(min_num)

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

Solution (Python):
n=int(input())
s=input()
w_list=[0]
w_count=0
b_list=[0]
b_count=0
for i in s:
    if i=='.':
        w_count=w_count+1
        w_list.append(w_count)
        b_list.append(b_count)
    else:
        b_count=b_count+1
        w_list.append(w_count)
        b_list.append(b_count)
Min=n
for i in range(0,n+1):
    w_number=i-w_list[i]
    b_number=n-i-(b_list[n]-b_list[i])
    number=w_number+b_number
    if number<Min:
        Min=number
print(Min)

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

rd = 0
for e in s:
    if e == ".":
        rd += 1

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

print(res)

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

b = [0]
w = [0]

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

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

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

def f(s):
    b = 0
    for i in s:
        if i == "
            b += 1
        yield b

def g(cb, n):
    bl = 0 if n == 0 else cb[n-1]
    wr = (len(cb) - n) - (cb[-1] - bl)

    return bl + wr

cb = list(f(S))
print(min([g(cb, i)for i in range(len(cb) + 1)]))

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

num_w=num_b=0
for i in range(n):
    let = s[i]
    if let == ".":
        num_w+=1
    else:
        num_b+=1


ans=num_w

mini = ans

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

print(mini)

Solution (Python):
_n=int(input())
_s=input()
t=len([1 for s in _s if s=="."])
c=[]
c.append((t,0))
for n in range(_n):
    if _s[n]=="
        t+=1
    else:
        t-=1
    c.append((t,n+1))
c.sort()
print(c[0][0])

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

num = s.count('.')
nums = [num]
for c in s:
    if c == '
        num += 1
    else:
        num -= 1
    nums.append(num)

print(min(nums))

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

b = S.count('

cnt = 0

result = N-b

for i in range(N):
    if S[i] == '
        cnt += 1
    result = min(result,cnt+N-i-(b-cnt)-1)

print(result)

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

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

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

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

if s[0]=="
else: B[0]=1

for i in range(1,N):
    if s[i]=="
        B[i]=min(B[i-1],W[i-1])
        W[i]=W[i-1]+1

    else:
        B[i]=min(B[i-1],W[i-1])+1
        W[i]=W[i-1]

print(min(B[N-1],W[N-1]))

Solution (Python):
import sys







from itertools import accumulate







input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



N = ii()
S = li()
intS = [0] * N
for i in range(N):
    if S[i] == '
        intS[i] = 1

acuS = list(accumulate(intS))

minS = 10 ** 9
for i in range(N):
    minS = min(minS, acuS[i] + (N-1-i) - (acuS[N - 1] - acuS[i]))

print(min(minS, N - acuS[N-1]))

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

rd = 0
for e in s:
    if e == ".":
        rd += 1

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

print(res)

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

w = [0]
w_total = 0
b = [0]
b_total = 0
for i in range(N):
    if S[i] == '
        w_total += 1
    w.append(w_total)
    if S[N - 1 - i] == '.':
        b_total += 1
    b.append(b_total)

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

Solution (Python):
n = int(input())
s = input()
black = [0]*(n+1)
white = [0]*(n+1)
for i in range(n):
    if s[i] == '
        black[i+1] = black[i] + 1
        white[i+1] = white[i]
    elif s[i] == '.':
        black[i+1] = black[i]
        white[i+1] = white[i] + 1
ans = 10000000000000000000000000000000000000000
for i in range(n+1):
    ans = min(ans,white[-1]-white[i]+black[i])

print(ans)