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()
la=[0]
lb=[0]
for i in s:
    if i==".":
        la.append(la[-1]+1)
        lb.append(lb[-1])
    if i=="
        la.append(la[-1])
        lb.append(lb[-1]+1)

ans=1000000000000
for i in range(n+1):
    ans=min(ans,lb[i]-lb[0]+la[-1]-la[i])
print(ans)

Solution (Python):
def minToggle(arr, n): 
  
    zero =[0 for i in range(n + 1+1)] 
    zero[0] = 0
   
    
    
    
    
    
    for i in range(1, n + 1): 
      
        
        
        if (arr[i-1] == 0): 
            zero[i] = zero[i-1] + 1
        else: 
            zero[i] = zero[i-1] 
   
    
    
    
    ans = n 
    for i in range(1, n + 1): 
        ans = min(ans, i - zero[i] + zero[n] - zero[i]) 
   
    return ans 
      

n=int(input())
s=input().rstrip()
arr=[]
ansi=min(s.count('.'),s.count('
for i in s:
    if i=='.':
        arr.append(0)
    else:
        arr.append(1)
n = len(arr) 
  
p=minToggle(arr, n)
ansi=min(ansi,p)
print(ansi)

Solution (Python):
N = int(input())
S = str(input())
white_count = 0
black_count = 0
count = 0
white = []
black = []
for i in range(N):
    if S[i] == ".":
        white_count += 1
    else:
        black_count += 1
    white.append(white_count)
    black.append(black_count)

ans = []
for i in range(N):
    ans.append(white_count-white[i]+black[i])
ans_min = min(ans)

print(min(white_count,black_count,ans_min))

Solution (Python):
n=int(input())
S=input()
sflag=0
a=0
b=0
c1=0
c2=0

d=0
for i in S:
    if i==".":
        a+=1
    if i=="
        b+=1
out=min(a,b)
siro=0
kuro=0
for i in S:
    if i==".":
        siro+=1
        a-=1
    else:
        kuro+=1
        b-=1
    if kuro+a < out:
        out=kuro+a
    
print(out)

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

b = [0]*(N+1)
w = [0]*(N+1)

for i,s in enumerate(S):
    b[i+1] = b[i]
    if s == "
        b[i+1] += 1

for i,s in enumerate(S[::-1]):
    w[i+1] = w[i]
    if s == ".":
        w[i+1] += 1

w.reverse()

ans = float('inf')

for B,W in zip(b,w):
    if ans > B+W:
        ans = B+W
print(ans)

Solution (Python):
N = int(input())
S = input()
count = 0
for s in S:
    if s == ".":
        count += 1
left = 0
right = count
minimum = left+right
for n in range(N):
    if S[n] == "
        left += 1
    else:
        right -= 1
    if left+right < minimum:
        minimum = left+right
print(minimum)

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

left = S[:0].count('
right = S[0:].count('.')
cou = left+right

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

Solution (Python):
import sys

input = sys.stdin.readline
n = int(input())
s = input()[:-1]
to_w = 0
to_b = 0
to_w_list = []
to_b_list = []
for i in range(n):
    if s[i] == '
        to_w += 1
    if s[-i-1] == '.':
        to_b += 1
    to_w_list.append(to_w)
    to_b_list.append(to_b)
to_b_list.reverse()
ans = min(to_w_list[-1], to_b_list[0])
for i in range(n-1):
    ans = min(ans, to_w_list[i]+to_b_list[i+1])
print(ans)

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

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

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

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


dp = [[0, 0] for _ in range(n+1)]

for i in range(n):
  if S[i] == '.':
    dp[i+1][0] = dp[i][0]
    dp[i+1][1] = min(dp[i][0], dp[i][1])+1
  else:
    dp[i+1][0] = dp[i][0]+1
    dp[i+1][1] = min(dp[i][0], dp[i][1])
    

print(min(dp[n]))

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

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

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

print(min(dp))

Solution (Python):
n = int(input())
s = list(input())
d = [0]*n
p = [0]*n
for i in range(n):
    if i > 0:
        d[i] = d[i-1]
    if s[i] != '.':
        d[i] += 1
for i in range(n-1, -1, -1):
    if i < (n-1):
        p[i] = p[i+1]
    if s[i] != '
        p[i] += 1

d = [0]+d
p = p+[0]
ans = 2**32
for i in range(n+1):
    t = d[i]+p[i]
    if t < ans:
        ans = t
print(ans)

Solution (Python):
N=int(input())
S=input()
tmp=1
L=[]
ans=10**6
black=0
white=0
for i in range(1,len(S)):
    if S[i]==S[i-1]:
        tmp+=1
    else:
        L.append(tmp)
        tmp=1
    if i ==len(S)-1:
        L.append(tmp)

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

cul=[0]*(len(L)+2)
for i in range(len(L)):
    cul[i+2]=L[i]+cul[i]


if S[0]=='.':
    white+=1
    for i in range(2,len(cul)):
        if i%2==0:
            ans=min(ans,cul[i-1]+white-cul[i])
        else:
            ans=min(ans,cul[i]+white-cul[i-1])
else:
    black+=1
    for i in range(2,len(cul)):
        if i % 2 == 0:
            ans = min(ans,cul[i]+white-cul[i-1])
        else:
            ans = min(ans,cul[i-1]+white-cul[i])


if len(L)==1:
    ans=0
else:
    ans=min(ans,sum(L[0::2]),sum(L[1::2]))

print(ans)

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

w = [0] * N
b = [0] * N

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

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

m = min(b[0], w[N-1])
for n in range(N-1):
    v = w[n] + b[n+1]
    if v < m:
        m = v
print(m)

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

sum_w = [0]
sum_b = [0]
for i in range(N):
  if S[i] == ".":
    sum_w.append(sum_w[-1] + 1)
    sum_b.append(sum_b[-1])
  else:
    sum_b.append(sum_b[-1] + 1)
    sum_w.append(sum_w[-1])

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

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

def black():
    result = [0] * n
    count = 0
    for i in range(n):
        if s[-i-1] == '.':
            count += 1
        result[-i-1] = count
    return result + [0]

def white():
    result = [0] * n
    count = 0
    for i in range(n):
        if s[i] == '
            count += 1
        result[i] = count
    return [0] + result

num = [x + y for x,y in zip(black(), white())]
result = min(num)

print(result)

Solution (Python):
N = int(input())
S = input()
ans = 10**8
li = [0]

b=[0]
w=[0]
for ind,i in enumerate(S):
    if(ind==0):
        if(i=='
            b+=[0]
            b[-1]+=1
        else:
            w[-1]+=1
    elif(ind==N-1):
        if(i==S[ind-1]):
            if(i=='
                b[-1]+=1
            else:
                w[-1]+=1
                b+=[b[-1]]
        else:
            if(i=='
                b+=[b[-1]+1]
            else:
                w+=[w[-1]+1]
                b+=[b[-1]]

    else:
        if(i==S[ind-1]):
            if(i=='
                b[-1]+=1
            else:
                w[-1]+=1
        else:
            if(i=='
                b+=[b[-1]+1]
            else:
                w+=[w[-1]+1]
b = [0]+b
w = [0]+w
for ind,i in enumerate(w):
    ans = min(ans,w[-1]-w[ind]+b[ind])



print(ans)

Solution (Python):
N = int(input())
S = input()
t = S.count(".")
if t == N or t == 0:
    print(0)
    exit(0)

W = [0 for k in range(N+1)]
B = [0 for k in range(N+1)]

for k in range(N):
    if S[k] == "
        B[k] = B[k-1] + 1
    else:
        B[k] = B[k-1]

W[0] = t
for k in range(N):
    if S[k] == ".":
        W[k+1] = W[k] - 1
    else:
        W[k+1] = W[k]
ans = N
for k in range(N):
    ans = min(ans,W[k+1]+B[k])
print(min(ans,t,S.count("

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




answer = 0


left_black = -1
right_white = -1

for i in range(N):
    if S[i]=='
        if S.count('
            break
        left_black = i
        break

for i in reversed(range(N)):
    if S[i]=='.':
        right_white = i
        break









if left_black!=-1 and left_black!=N-1:
    S2 = S[left_black:right_white+1]
    length = len(S2)
    
    white_black_sa = [0]*length
    if S2[0]=='.':
        white_black_sa[0] = 1
    else:
        white_black_sa[0] = -1

    for i in range(1,length):
        if S2[i]=='.':
            white_black_sa[i]=white_black_sa[i-1]+1
        else:
            white_black_sa[i]=white_black_sa[i-1]-1
    
    sa_max_idx = white_black_sa.index(max(white_black_sa))
    
    
    
    black_disc = S2[:sa_max_idx].count('
    white_disc = S2[sa_max_idx+1:].count('.')
    
    
    answer = black_disc + white_disc





print(answer)

Solution (Python):
N = int(input())
S = input()
Min = N
siro = S.count(".")
kuro = S.count("
Min = min([siro, kuro])
siro_now = 0
for i in range(N):
    if S[i] == ".":
        siro_now += 1
    cnt = (((i+1)-siro_now) + (siro - siro_now))
    if Min > cnt:
        Min = cnt
print(Min)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
s = input()
num = []
bl = 0
wh = 0
for i in range(n):
    if s[i] == "
        num.append([i,wh])
        bl += 1
    else:
        wh += 1
min = n
if len(num) > 0:
    for i in range(len(num)):
        temp = (num[i][0] - num[i][1]) + (n - bl - num[i][1])
        if temp < min:
            min = temp
    if min > bl:
        min = bl
    print(min)
else:
    print("0")

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

all = 0
tmp = 0
for i in S:
    if  i == '.':
        all += 1
ans = all
for i in range(N):
    if S[i] == '.':
        tmp += 1
    ans = min(ans, all - tmp + i + 1 - tmp)

print ans

Solution (Python):
N = int(input())
S = input()
first_black = 0
count = 0
for i in range (N):
    if first_black == 0 and S[i]=='
        first_black = 1
    if first_black == 1 and S[i]== '.':
        count +=1
        
first_white = 0
white_count = 0
for i in range (N):
    if first_white == 0 and S[N-i-1]=='.':
        first_white = 1
    if first_white == 1 and S[N-i-1]== '
        white_count +=1

white_black = 10**6

black_count_left = 0
white_count_right = S.count('.')
ans = black_count_left + white_count_right

for i in range (N):
    if S[i] == '
        black_count_left+=1
    elif S[i] == '.':
        white_count_right-=1
    if ans >= black_count_left+white_count_right:
        ans = black_count_left+white_count_right
        
print(min(count,white_count, ans))

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

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

ans=b+w

for s in S:
	if s == "
		b += 1
	else:
		w -= 1
	ans=min(ans, b+w)

print(ans)

Solution (Python):
from copy import deepcopy

N = int(input())
S = input()
M = [0 for i in range(N+1)]

for i in range(N):
    if S[i] != '
        M[0] += 1

mini = deepcopy(M[0])
    
for i in range(N):
    if S[i] == '
        M[i+1] = M[i] + 1
    else:
        M[i+1] = M[i] - 1
        if mini > M[i+1]:
            mini = deepcopy(M[i+1])

print(mini)

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

Solution (Python):
N = int(input())
S = input()
S = list(map(lambda x: 0 if x=="." else 1, S))





ans_list = []
for thresh in range(len(S)):        
    if thresh == 0:
        ans = len(S) - sum(S)
        ans_list.append(ans)
    
    else:
        ans = ans_list[-1]
        if S[thresh-1] == 1: 
            ans += 1
        else:
            ans -= 1
        ans_list.append(ans)
ans_list.append(sum(S))
        
print(min(ans_list))

Solution (Python):
import sys
N  = int(input())
S = input()
black = S.count("
white = N - black
if black == 0 or white == 0:
    print(0)
    sys.exit()


first = 0
for i in range(N):
    if S[i] == '
        first = i
        break
last = N - 1 
for i in reversed(range(N)):
    if S[i] == '.':
        last = i
        break
if first < last:
    S = S[first:last+1]
N = len(S)

black = S.count("
white = N - black
ans = min(black , white)

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

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

Solution (Python):
from itertools import accumulate
 
input()
l = [0] + list(accumulate(c == '.' for c in input()))
print(min(i - x + l[-1] - x for i, x in enumerate(l)))

Solution (Python):

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

ans = 0
a = 0
num1, num2 = 0, 0

dp = [[0] *2 for _ in range(N + 1)]
for i in range(N):
    dp[i + 1][0] = dp[i][0] + (1 if S[i] == '.' else 0)
    dp[i + 1][1] = dp[i][1] + (1 if S[i] == '

ans = 1e10
for i in range(1, N + 1):
    num = dp[i - 1][1] + (dp[N][0] - dp[i - 1][0])
    ans = min(ans, num)
ans = min(ans, dp[N][1])
print(ans)

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

b = []
w = []
for i in range(N):
    if S[i] == '
        b.append(i)
    if S[i] == '.':
        w.append(i)

kouho = []
for i in range(0,N+1):
    cost = 0
    
    cost += len(w) - bisect.bisect_left(w,i)
    
    cost += bisect.bisect_left(b,i)
    
    if cost >= 0:
        kouho.append(cost)

print(min(kouho))

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

cnt = [0 for _ in range(N + 1)]
black = 0
white = 0

for idx in range(N):
    if S[idx] == '
        black += 1
    else:
        white += 1
    cnt[idx] = black - white

print(min(cnt) + white)

Solution (Python):
import math
from operator import itemgetter
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

a = s.count("
b = s.count(".")
cnta = 0
cntb = 0
ans = MAX_INT
for i in range(N):
	if s[i] == "
		ans = min(ans,cnta + (b-cntb))
		cnta += 1
	else:
		cntb += 1
if ans == MAX_INT:
	print(0)
else:
	print(min(ans,a,b))

Solution (Python):


import re

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

numw, numb = 0, 0
lw, lb = [0], [0]
for i in range(len(S)):
    if S[i] == '.':
        numw += 1
    else:
        numb += 1
    lw.append(numw)
    lb.append(numb)

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

print(ans)

Solution (Python):
n = int(input())
s = input()
cnt = 0
cnt2 = 0
tmp = 0
tmp2 = 0
ans = 10**9
for i in s:
    if i=="
        cnt += 1
    else:
        cnt2 += 1
for i in s:
    if i=="
        tmp += 1
    else:
        tmp2 += 1
    ans = min(ans,tmp+cnt2-tmp2)
print(min(ans,cnt,cnt2))

Solution (Python):
import itertools

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

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

B = list(itertools.accumulate(S))

MIN = 10000000
cnt = []
for i in range(N):
    cnt.append(B[i] + N - B[N-1] + B[i] - i - 1)
    
MIN = min(cnt)



S_s = list(set(S))
if len(S_s) == 1:
    MIN = 0
else:
    MIN = min(MIN, S.count(0))
print(MIN)

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

Solution (Python):

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

b = 0
w = 0
tb = 0
tw = 0

for i in reversed(range(n)):
    if s[i] == '
        tb += 1
        if tb > tw:
            b += tb
            w += tw
            tb = 0
            tw = 0
    else:
        tw += 1
print(tb + w)

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

res = float("inf")




counts = []
counts.append((0, 0))
a, b = 0, 0
for s in S:
    if s == "
        a += 1
    elif s == ".":
        b += 1
    counts.append((a, b))

for i in range(N + 1):
    res = min(res, counts[i][0] + counts[-1][1] - counts[i][1])

print(res)

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

temp=s.count("
if temp==0 or temp==n:
    print(0)
else:
    head=0
    tail=n-temp
    ret=tail+head
    for c in s:
        if c=="
            head+=1
        else:
            tail-=1
        temp2=head+tail
        if temp2<ret:
            ret=temp2
    print(ret)

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

alBlack = S.count('.')
alWhite = S.count('





accumB = [] 


cnt = 0
for i in range(N): 
  if S[i] == '
    cnt += 1
  accumB.append(cnt)

minRev = N 
for i in range(1, N, 1): 
  
  leftRev = accumB[i-1] 
  rightRev = N - accumB[N-1] - (i - accumB[i-1])
  
  
  minRev = min(minRev, leftRev+rightRev)
  
print(min(minRev,alBlack,alWhite))

Solution (Python):
n = int(input())
s = list(input())
bi = [0]
wi = [0]
b = 0
w = 0
for i in range(n):
    if s[i] == '
        b += 1
    if s[-i-1] == '.':
        w += 1
    bi.append(b)
    wi.append(w)
print(min(bi[i]+wi[-i-1] for i in range(n+1)))

Solution (Python):
N = int(input())
S = input()
dp = [0 for i in range(N)]
b = 0
w = 0
flag1 = True
flag2 = True
for i in range(N):
    if flag1 and S[i] == '.':
        pass
    elif flag1:
        flag1 = False
        b += 1
    elif S[i] == '.':
        dp[i] = b
    else:
        b += 1

for i in reversed(range(N)):
    if flag2 and S[i] == '
        pass
    elif flag2:
        flag2 = False
        w += 1
    elif S[i] == '
        dp[i] = w
    else:
        w += 1
ans = float('inf')
for i in range(N-1):
    if (S[i] == '.' and S[i+1] == '
        ans = min(ans,dp[i]+dp[i+1])

if ans == float('inf'):
    print(0)
else:
    print(min(b,w,ans))

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


cost = 0
bc = 0
for it in s:
    if it =="
        bc += 1
    else:
        if bc > 0:
            cost += 1
            bc -= 1

print(cost)

Solution (Python):
from sys import stdin

import numpy as np





N = int(stdin.readline().rstrip().split()[0])
S = stdin.readline().rstrip().split()[0]

B =[]
W =[]
b=0
w=0
for i in range(N):
  if S[i]==".":
    w+=1
  W.append(w)
  
  if S[N-1-i]=="
    b+=1
  B.append(b)

W=np.array(W)
B=np.array(B[::-1])
ans = N-np.max(W+B)
print(ans)

Solution (Python):
def main():
    n = int(input())
    s = input().rstrip()
    i = 0
    b_count = 0
    w_count = 0
    
    while i < len(s):
        if s[i] == '.':
            i += 1
        else:
            break

    
    j = len(s) - 1
    while j > i:
        if s[j] != '.':
            j -= 1
        else:
            break

    
    left = i
    right = j
    while i <= j:
        if s[i] == '.':
            w_count += 1
        i += 1
            

    i = left
    min_count = w_count
    count = w_count
    while i <= right:
        if s[i] == '.':
            count -= 1
        else:
            count += 1
        i += 1
        if count < min_count:
            min_count = count

    print(min_count)

if __name__ == "__main__":
    main()

Solution (Python):


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

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

output = N

for i in range(len(black_number_list)):
    number = (black_number_list[i][0]) + (N - i - black_number_list[i][1])
    if number < output:
        output = number

print (output)

Solution (Python):
n = int(input())
s = list(input())
import collections as coll
t = coll.Counter(s)
b1,w1=t["

b = 0
w = 0
p = 0
q = w1
for i in range(n):
    if s[i] == "
        b += 1
    elif s[i] == ".":
        w += 1
    
    p = b + w1 - w
    if p < q:
        q = p

print(q)

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

one, d = 0, 0
for i in range(N):
    if S[i] == '
        one += 1
    elif d > one - (i + 1 - one):
        d = one - (i + 1 - one)
print(d + N - one)

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

counter = [[0,0] for i in range(N)]
count = 0
for i in range(N):
    if S[i] == '
        count += 1
    counter[i][0] = count

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

mini = N
for i in range(N-1):
    if mini > counter[i][0] + counter[i+1][1]:
        
        mini = counter[i][0] + counter[i+1][1]

white = S.count('.')
mini = 0 if white == 0 or white == N else mini
mini = white if white < mini else mini
white = S.count('
mini = white if white < mini else mini
print(mini)

Solution (Python):
n = int(input())
s = input()
d = []
for c in s:
    if d==[]:
        d.append([c,1])
    else:
        if c == d[-1][0]:
            d[-1][1]+=1
        else:
            d.append([c,1])

endwhite = 0
endblack = 0
white = 0
black = 0
for p in d:
    if p[0] == '.':
        endwhite = black
        endblack = min(endblack+ p[1],endwhite+p[1])
        white += p[1]
    if p[0] == '
        endblack = min(endblack,endwhite)
        endwhite += p[1]
        black += p[1]
print(min(endwhite,endblack))

Solution (Python):
def ns():
    import sys
    return map(int, sys.stdin.readline().split())
  
def ss():
    import sys
    return sys.stdin.readline().strip()
  
def dp():
  N, = ns()
  S = ss()
  
  c = sum(1 for s in S if s == '.')
  DP = [float('inf')] * (N+1)
  DP[0] = c

  for i, s in enumerate(S):
    if i < N:
      if s == '.':
      	DP[i+1] = DP[i] - 1
      else:
        DP[i+1] = DP[i] + 1
  return min(DP)

print(dp())

Solution (Python):
n = int(input())
s = input()
l = [0] * (n + 1)
l_c = 0
r = [0] * (n + 1)
r_c = 0
for i in range(1,n + 1):
  if s[i - 1] == '
    l_c += 1
  l[i] = l_c
for i in reversed(range(0, n)):
  if s[i] == '.':
    r_c += 1
  r[i] = r_c
m = float('inf')
for i in range(n + 1):
  m = min(m,l[i]+r[i])
print(m)

Solution (Python):
N = int(input())
S = input()
dpw = [0]*N
dpb = [0]*N
if S[0] == '.':
  dpw[0] = 1
else:
  dpb[0] = 1
for i in range(1,N):
  if S[i] == '.':
    dpw[i] = dpw[i-1]+1
    dpb[i] = dpb[i-1]
  else:
    dpb[i] = dpb[i-1]+1
    dpw[i] = dpw[i-1]
totalw = dpw[N-1]
totalb = dpb[N-1]
ans = min(totalw,totalb)
for i in range(N):
  cur = dpb[i]+totalw-dpw[i]
  if cur <= ans:
    ans = cur
print(ans)

Solution (Python):
N = int(input())
S = input()
temp = S.count('.')
cnt = min(temp, N)

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

Solution (Python):
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[-1] == "
    l.pop()

if len(l) == 0:
    print(0)
    exit()

min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

x = len(l)//2
for i in range(x+1):
    m = (black[i] - black[0]) + (white[x] - white[i])
    min_num = min(m, min_num)

print(min_num)

Solution (Python):
n=int(input())
s=list(input())
ans=0
ans2=0
stack=[0]*(n+1)
for i in range(n):
  if s[i]!="
    stack[0]+=1
    stack[i+1]-=1
  else:
    stack[i+1]+=1
for i in range(n):
  stack[i+1]+=stack[i]
print(min(stack))

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

Solution (Python):
import numpy as np
n=int(input())
s=input()
ans = 0
kuro = [0]*(n+1)
siro = [0]*(n+1)
if n==1:
    ans=0
if n ==2:
    if s=="
        ans=1
else: 
    for i,j in enumerate(s[::-1]):
        if j==".":
            kuro[i+1]=kuro[i]+1
        else:
            kuro[i+1]=kuro[i]
    for i,j in enumerate(s):
        if j == "
            siro[i+1]=siro[i]+1
        else:
            siro[i+1]=siro[i]
            
    ku = np.array(kuro[::-1])
    si = np.array(siro)
    ans=np.min(ku+si)
    
print(ans)

Solution (Python):
n = int(input())
s = input()
a = 0
ans = 0
for i in range(n):
  if s[i] == '.':
    ans += 1
a = ans
for i in range(n):
  if s[i] == '.':
    a -= 1
  else:
    a += 1
  if a < ans:
    ans = a
print(ans)

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    S = input_raw[0]

    new_S = ""
    count = 0
    for i in range(N):
        if S[i] != "
            count += 1
    min_count = count
    for i in range(N):
        if S[i] == ".":
            count -= 1
        else:
            count += 1
        min_count = min(min_count, count)
    print min_count






























if __name__ == '__main__':
    main()

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

ans = 0
p = 0
q = 0
sai = 0
v = 0
w = 0
pairs = []
for i in range(n - 1, -1, -1):
    if s[i] == "." and sai == 0:
        p = 0
        q = 0
        p += 1
        v = 1
        sai = 1
    elif s[i] == "." and v == 0:
        pairs.append([q, p])
        p = 0
        q = 0
        w = 0
        p += 1
        v = 1
    elif s[i] == "." and v == 1:
        p += 1
    elif s[i] == "
        v = 0
        q += 1
        w = 1
    elif s[i] == "
        q += 1
pairs.append([q, p])
rp = []
for i in range(len(pairs)):
    rp.append(pairs[-i-1])
d = []
prp = []
p0 = 0
p1 = 0
for i in range(len(rp)):
    p0 += rp[i][0]
    p1 += rp[i][1]
    prp.append([p0, p1])
for i in range(len(prp)):
    d.append(prp[i][0] + prp[len(prp) - 1][1] - prp[i][1])
d.append(prp[len(prp) - 1][0])
d.append(prp[len(prp) - 1][1])
print(min(d))

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

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

if s[0] == '.':
    cost1 = 0
else:
    cost1 = 1
cost1_list = [cost1]
for i in range(1, n):
    if s[i] == '
        
        cost1 += 1
    cost1_list.append(cost1)


cost_all = [w_counter_all]
for i in range(n):
    cost_all.append(n - i - 1 - cost1_list[-1] + cost1_list[i] * 2)
print(min(cost_all))

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

p = S.count('.')
q = 0
ans = p

for i in range(N):
    if S[i] == '
        q += 1
    else:
        p -= 1

    ans = min(ans,p+q)

print(ans)

Solution (Python):
n=int(input())
s=input()+'?'
ans=10**10
arr=[0]*n
ans1=n-s.count('
ans2=n-s.count('.')
if s[0]=='.':
  arr[0]=1
for i in range(1,n):
  if s[i]=='.':
    arr[i]=arr[i-1]+1
  else:
    arr[i]=arr[i-1]
for i in range(1,n):
  tmp=(i-arr[i-1])+(arr[-1]-arr[i])
  if tmp<ans:
    ans=tmp
print(min(ans,ans1,ans2))

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

k = 0
a = [0]
for t in s:
 if t == "
  k += 1
 a.append(k)


m = a[n]
p = n
for i in range(n+1):
 p = min(p, a[i] + (n-i) - (m-a[i]))
print(p)

Solution (Python):
n=int(input())
s=input()+'?'
ans=10**10
arr=[0]*n
ans1=n-s.count('
ans2=n-s.count('.')
if s[0]=='.':
  arr[0]=1
for i in range(1,n):
  if s[i]=='.':
    arr[i]=arr[i-1]+1
  else:
    arr[i]=arr[i-1]
for i in range(1,n):
  tmp=(i-arr[i-1])+(arr[-1]-arr[i])
  if tmp<ans:
    ans=tmp
print(min(ans,ans1,ans2))

Solution (Python):

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
S = read()[:-1]

accum_ten = [0]
accum_sha = [0]
for i, s in enumerate(S):
    if s == '.':
        accum_ten.append(accum_ten[-1] + 1)
        accum_sha.append(accum_sha[-1])
    else:
        accum_ten.append(accum_ten[-1])
        accum_sha.append(accum_sha[-1] + 1)

ans = float('inf')

for i in range(N+1):
    left = accum_sha[i]
    right = accum_ten[-1] - accum_ten[i]
    ans = min(ans, left + right)
    

print(ans)

Solution (Python):

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

if S.count('
    print(0)
else:
    l = 0
    r = S.count('.')
    min = l+r
    for n in range(1,N+1):
        if S[n-1] == '
            l += 1
        else:
            r -= 1
        if l+r < min:
            min = l+r
    print(min)

Solution (Python):
n=int(input())
ls=list(input())
c_list=[ls.count(".")]

for i in ls:
    if i==".":
        c_list.append(c_list[-1]-1)
    else:
        c_list.append(c_list[-1]+1)

print(min(c_list))

Solution (Python):
from numpy import cumsum

N = int(input())
S = input()
ss = S.replace("
* ls, = map(int, ss)
cum_ls = cumsum(ls)
first_black = -1
last_black = N
for i in range(N):
    if S[i] == "
        first_black = i
        break
for i in reversed(range(N)):
    if S[i] == "
        last_black = i
    else:
        break
if first_black == -1:
    print(0)
else:
    
    mans = 10**10
    for i in range(N):
        
        mans = min(mans, cum_ls[i] + (N-(i+1) - (cum_ls[-1] - cum_ls[i])))
        

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

    print(ans)

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

white=S.count(".")

counter=[white]

for i in range(N):
    if S[i]=="
        counter.append(counter[i]+1)
    elif S[i]==".":
        counter.append(counter[i]-1)
        
        
    
print(min(counter))

Solution (Python):
def main():
	N = int(input())
	S = input()
	w = 0
	b = 0
	stack = []
	if S[0] == ".":
		stack.append(0)

	before = S[0]
	current = 0
	for i, c in enumerate(S):
		if c == ".":
			w += 1
		else:
			b += 1
		if c != before:
			stack.append(current)
			before = c
			current = 1
		else:
			current += 1
	stack.append(current)
	if len(stack) %2 != 0:
		stack.append(0)

	ans = min(w, b)
	w_change = 0
	b_change = b
	while stack:
		current_w = stack.pop()
		current_b = stack.pop()
		w_change += current_w
		b_change -= current_b
		ans = min(ans, w_change+b_change)

	print(ans)


if __name__ == '__main__':
    main()