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=list(input())
bl=0 ; wh=s.count(".")
ans=s.count("

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

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



cum1=[0]
cnt=0
for i in range(N):
  if S[i]=='
    cnt += 1
  cum1.append(cnt)
  
cum2=[0]
cnt=0
for s in reversed(S):
  if s=='.':
    cnt += 1
  cum2.append(cnt)
  
cum2 = cum2[::-1]

print(min([cum1[i]+cum2[i] for i in range(N+1)]))

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

white = 0
black = 0
for e in s:
    if e == "
        black += 1
    else:
        white += 1

ans = white
b = 0
w = white
for e in s:
    if e == "
        b += 1

    else:
        w -= 1

    ans = min(ans, b + w)

print(ans)

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

Solution (Python):
N = int(input())
S = input()
w = S.count(".")
b = 0

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

Solution (Python):
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]



N = ii()
S = input()
'''
cnt = [0]*(N+1)
ans = N+1

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

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

print(ans)
'''

dp = dp2(0, 2, N+1)

if S[0] == '.':
    dp[1][0] = 0
    dp[1][1] = 1
else:
    dp[1][0] = 1
    dp[1][1] = 0

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

print(min(dp[N][0], dp[N][1]))

Solution (Python):
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]




    
    
    
'''
N = ii()
S = input()

w_cnt = 0
b_cnt = 0

for i in S:
    if i == '.':
        w_cnt += 1
    else:
        break

for i in S[::-1]:
    if i == '
        b_cnt += 1
    else:
        break

w = b = 0

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

cnt = 0

for i in S:
    if i == '
        cnt += 1



print(min(w, b, cnt, N-cnt))
'''
N = ii()
S = input()

cnt = [0]*(N+1)
ans = N+1

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

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

print(ans)

Solution (Python):
from itertools import accumulate

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

white=[]
black=[]
w=0
b=0

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

if white==[] or black==[]:
    print(0)
    exit()

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

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

    B = [0]
    cnt = 0
    for s in S:
        if s == '
            cnt += 1
        B.append(cnt)

    W = [0]
    cnt = 0
    for s in reversed(S):
        if s == '.':
            cnt += 1
        W.append(cnt)
    W.reverse()

    min = 10 ** 9
    for w, b in zip(W, B):
        if w+b < min:
            min = w+b
    print(min)

if __name__ == '__main__':
    main()

Solution (Python):


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

tot_w = s.count('.')

ret = tot_w  
w = 0
b = 0
for c in s:
    if c == '
        b += 1
    else:
        w += 1
    cost = b + tot_w - w
    ret = min(ret, cost)

print(ret)

Solution (Python):
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key


def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()

def main():
    inf = int(1e9)
    N = ri()
    S = rs()
    dp = [[inf] * N for i in range(2)]
    
    if S[0] == '.':
        dp[0][0] = 0
        dp[1][0] = 1
    else:
        dp[0][0] = 1
        dp[1][0] = 0
    for i in range(1, N):
        if S[i] == '.':
            dp[0][i] = min(dp[0][i], dp[0][i-1])
            dp[1][i] = min(dp[1][i], dp[0][i-1] + 1)
            dp[1][i] = min(dp[1][i], dp[1][i-1] + 1)
        else :
            dp[0][i] = min(dp[0][i], dp[0][i-1] + 1)
            dp[1][i] = min(dp[1][i], dp[0][i-1])
            dp[1][i] = min(dp[1][i], dp[1][i-1])
    print(min(dp[0][N-1], dp[1][N-1]))



if __name__ == "__main__":
    main()

Solution (Python):
a = input()
b = input()
c = list(b)
d = 0
e = c.count(".")
f = 0
for i in range(len(c)+1): 
    if i == 0:
        ans = e
    else:
        if c[i-1] == ".":
            d = d + 1 
        f = (i - d) + (e - d) 
        ans = min(ans, f)
print(ans)

Solution (Python):
a = input()
b = input()
c = list(b)
d = 0
e = c.count(".")
f = 0
for i in range(len(c)+1): 
    if i == 0:
        ans = e
    else:
        if c[i-1] == ".":
            d = d + 1 
        f = (i - d) + (e - d) 
        ans = min(ans, f)
print(ans)

Solution (Python):
a = input()
b = input()
c = list(b)
d = 0
e = c.count(".")
f = 0
for i in range(len(c)+1): 
    if i == 0:
        ans = e
    else:
        if c[i-1] == ".":
            d = d + 1 
        f = (i - d) + (e - d) 
        ans = min(ans, f)
print(ans)

Solution (Python):
N = int(input())
Stone = list(input())
Black_count = 0
White_count = 0
Cost = []


for i in range(N):
  if Stone[i] == '.':
    White_count += 1




for j in range(N):
  
  if Stone[j] == '.':
    White_count -= 1
    Cost.append(White_count + Black_count)
  
  else:
    Cost.append(White_count + Black_count)
    Black_count += 1

print(min(Cost))

Solution (Python):
import sys,bisect,heapq

mod = 10**9+7
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(input())
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while(a%b != 0):
        a,b = b,a%b
    return b

def LCM(a,b):
    return a*b//GCD(a,b)

def main():
    N = I()
    s = S()

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

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

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

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

T = [0 for _ in range(N+1)]
a = 0
for i, s in enumerate(S):
    if s == '
        a += 1
    T[i+1] = a

ans = N
for l in range(N+1):
    a = T[l] + (N-l)-(T[-1]-T[l])
    ans = min(ans, a)


print(ans)

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

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

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

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

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

ans = S.count('.')
min_ = ans

for s in S:
    if s == '
        ans += 1
    else:
        ans -= 1
    min_ = min(ans,min_)

print(min_)

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

curr = 0
nblack = 0

for ch in s:
  if ch == '.':
    curr = min(nblack, 1 + curr)
  else:
    nblack += 1

print(curr)

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

cb = S.count("
cw = S.count(".")

if cb == 0:
	ans = 0
else:
	x = 0
	y = cw
	ans = float("inf")
	for i in range(N):
		if S[i] == "
			v = x + y
			if ans > v:
				ans = v
			x += 1
		else:
			y -= 1
			v = x + y
			if ans > v:
				ans = v


print(ans)

Solution (Python):
N = int(input())
stones = input()
white = 0
black = 0
for i in range(N):
    if stones[i] == '.':
        white += 1
ans = white
for i in range(N):
    if stones[i] == '
        black += 1
    else:
        white -= 1
    if ans > black + white:
        ans = black + white
print(ans)

Solution (Python):
import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N,S = ni(),ns()


b_ = [0]*(N+1)
w_ = [0]*(N+1)
if(S[0]=="."):
    b_[0]=0
    w_[0]=1
else:
    b_[0]=1
    w_[0]=0
for i in range(1,N):
    if(S[i]=="."):
        b_[i] = b_[i-1]
        w_[i] = w_[i-1]+1
    else:
        b_[i] = b_[i-1]+1
        w_[i] = w_[i-1]
ans = w_[N-1]
for i in range(N):
    ans = min(ans,b_[i]+w_[N-1]-w_[i])
    

ans = min(ans, b_[N-1])
print(ans)

Solution (Python):


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

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

res = 10**6
for i in range(n+1):
    r = acc[n] - acc[i]
    r += i - acc[i]
    res = min(res, r)

print(res)

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

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

print(min(ans))

Solution (Python):
n=int(input())
s=input()
x=[0]
if s[0]=="
    x.append(1)
else:
    x.append(0)
for i in range(1,n):
    if s[i]=="
        x.append(x[-1]+1)
    else:
        x.append(x[-1])
y=[0]
if s[-1]==".":
    y.append(1)
else:
    y.append(0)
for i in range(2,n+1):
    if s[-i]==".":
        y.append(y[-1]+1)
    else:
        y.append(y[-1])
y=y[::-1]
z=[x[i]+y[i] for i in range(n+1)]
print(min(z))

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

sol = 0
num_hash = 0
num_dot = 0

for si in s:
    if si == ".":
        num_dot += 1
    else:
        num_hash += 1
    sol = min(sol, num_hash - num_dot)

sol += num_dot
print(sol)

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

w = s.count(".")
b = 0
k = w

for c in s:
    if c == ".":
        w -= 1
    else:
        b += 1
    k = min(k, w + b)

print(k)

Solution (Python):

import sys
import math
import numpy as np
import itertools



n = int(input())


h = list(input()) 

lb = [0]*len(h)
rw = [0]*len(h)
b=0
w=0
for i in range(len(h)):
    if h[i]=="
        b += 1
    lb[i] = b

for i in range(len(h)-1,-1,-1):
    if h[i]==".":
        w += 1
    rw[i] = w
answer = rw[0]
for i in range(len(h)-1):
    answer = min(answer,lb[i]+rw[i+1])
answer = min(answer,lb[len(h)-1])

print(answer)

Solution (Python):
def solve2(N, S):
    W = [0]*N
    W[0] = 1 if S[0] == '.' else 0
    for i in range(1, N):
        W[i] = W[i-1] + (1 if S[i] == '.' else 0)
    ans = min(W[-1], N-W[-1])
    temp = []
    for i in range(N-1):
        
        left = i+1-W[i]
        right = W[-1]-W[i+1]
        
        ans = min(ans, left+right)
        temp.append(left+right)
    return ans




N = int(input())
S = str(input())
print(solve2(N, S))

Solution (Python):
def solve(N, S):
    ans = [S.count('.')]
    for i in range(N):
        temp = ans[-1]
        temp += -1 if S[i] == '.' else 1
        ans.append(temp)
    return ans




N = int(input())
S = str(input())
print(min(solve(N, S)))

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

cand = []
black = 0
white = 0

for s in S:
    if s == '.':
        white +=1
cand.append(white)
        
for s in S:
    if s == '
        black += 1
    else:
        white -= 1
    cand.append(black+white)

print(min(cand))

Solution (Python):
N, S = int(input()), input()
b, w = 0, S.count('.')
ans = b + w
for si in S:
    if si == "
        b += 1
    else:
        w -= 1
    ans = min(ans, b + w)
print(ans)

Solution (Python):

N=int(input())
S=str(input())
Slist=list(S)
BSUM=Slist.count("
WSUM=Slist.count(".")
Lb=[]
Rw=[]
for i in range(N+1):
    if i == 0:
        Lb.append(0)
        Rw.append(WSUM)
    else:
        if Slist[i-1] == "
            Lb.append(Lb[i-1]+1)
            Rw.append(Rw[i-1])
        else:
            Lb.append(Lb[i-1])
            Rw.append(Rw[i-1]-1)
MIN=2000001
for i in range(N+1):
    kari=Lb[i]+Rw[i]
    MIN=min(MIN,kari)
print(MIN)

Solution (Python):
import sys

N, S = int(sys.stdin.readline()), sys.stdin.readline()

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

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

print(ans)

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

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

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

ans = b + w
for si in S:
    if si == "
        b += 1
    if si == ".":
        w -= 1
    ans = min(ans, b + w)
    
print(ans)

Solution (Python):
N, S = int(input()), input()
b, w = 0, S.count('.')
ans = b + w
for si in S:
    if si == "
        b += 1
    if si == ".":
        w -= 1
    ans = min(ans, b + w)
print(ans)

Solution (Python):
def seek(n, s):
    s = s.rstrip('
    turn_to_black = s.count('.')
    current_min = turn_to_black
    turn_to_white = 0

    if current_min == 0 or current_min == len(s):
        return 0

    
    for i in range(len(s)):
        if s[i] == '
            turn_to_white += 1
        else:
            turn_to_black -= 1
        current_min = min(current_min, turn_to_black + turn_to_white)
    return current_min


def input_from_console():
    n = int(input())
    s = input()
    return n, s


def main():
    n, s = input_from_console()
    print(seek(n, s))
    

if __name__ == "__main__":
    main()

Solution (Python):


n = int(input())
s = list(input())
ans = 10**9 + 7
black = s.count("
white = s.count(".")
tmp = []

if s[0] == "
    tmp.append([1,0])
else:
    tmp.append([0,1])

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

for i in range(n):
    left = tmp[i][0]
    right = white - tmp[i][1]
    ans = min(ans, left + right)

ans = min(ans, black)
ans = min(ans, white)

print(ans)

Solution (Python):
n = int(input())
lines = list(input())
b_lines= [0 for i in range(len(lines)+1)]
w_lines=[0 for i in range(len(lines)+1)]

for i in range(len(lines)):
    if lines[i] == '
        b_lines[i+1]=b_lines[i]+1
    else:
        b_lines[i+1]=b_lines[i]

for i in reversed(range(len(lines))):
    if lines[i] == '.':
        w_lines[i]=w_lines[i+1]+1
    else:
        w_lines[i]=w_lines[i+1]

ans = list()
for i in range(n+1):
    ans.append(b_lines[i]+w_lines[i])
print(min(ans))

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

ans = [S.count('.')]
for i in range(N):
    temp = ans[-1]
    if S[i] == '
        temp += 1
    else:
        temp -= 1
    ans.append(temp)
    
print(min(ans))

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

ans = N
tmp = 0
for i in range(N+1):
  tmp = cumsum_b[i] + ((N-i) - (cumsum_b[-1] - cumsum_b[i]))
  ans = min(ans,tmp)
else:
  print(ans)

Solution (Python):
n = int(input())
s = input()
white = [0 for _ in range(n+1)]
black = [0 for _ in range(n+1)]
for i in range(1, n+1):
	if s[i-1] == "
		white[i] = white[i-1] + 1
	else:
		white[i] = white[i-1]
for i in range(n-1, -1, -1):
	if s[i] == ".":
		black[i] = black[i+1] + 1
	else:
		black[i] = black[i+1]
print(min([b+w for b, w in zip(black, white)]))

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N = int(input())
S = input()

W = S.count('.')
cur = W
ans = cur
for i in range(N):
    if S[i] == '.':
        cur -= 1
        if cur < ans:
            ans = cur
    else:
        cur += 1
print(ans)

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

Solution (Python):
from itertools import accumulate, chain


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


dp = list(
    accumulate(
        chain(
            [0],
            map(lambda s: s == '
        )
    )
)



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

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

allblack=0
for i in range(N):
  if S[i]!='
    allblack+=1
    
answer=allblack
whitecount=allblack   
blackcount=0

for i in range(N):
  if S[i]=='.':
    whitecount-=1
  else:
    blackcount+=1
  tmp=blackcount+whitecount
  answer=min(answer,tmp)
  
print(answer)

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

S=input()

A = [0]
a=0
for i in range(N):
    if S[i]=="
        a+=1
    A.append(a)
min_score=N

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

Solution (Python):

"""
Created on Sun Apr 21 13:05:54 2019

@author: Yamazaki Kenichi
"""

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

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

print(ans)

Solution (Python):
n = int(input())
s = input()
w = s.count(".")
b = s.count("
ans = w
new_w = 0
new_b = 0
for i in range(n):
  if s[i] == ".":
    new_w += 1
  else:
    new_b += 1
  if new_b + (w - new_w) < ans:
    ans = new_b + (w - new_w)
print(ans)

Solution (Python):
N = int(input())
S = input()
count = S[0:N].count('.')
min = count
for i in range(0, N):
    if S[i:i + 1] == '
        count += 1
    else:
        count -= 1
    if count < min:
        min = count
if N == 1:
    min = 0
print("{}".format(min))

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

dp = [[0 for i in range(2)] for j in range(N+1)]

for i in range(1,N+1) :
    for j in range(2) :
        dp[i][j] = float("inf")

for i in range(N) :
    dp[i+1][0] = dp[i][0] + (S[i] == "
    dp[i+1][1] = min(dp[i][0], dp[i][1]) + (S[i] == ".")

ans = min(dp[N][0], dp[N][1])

print(ans)

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

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

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

Solution (Python):
N=int(input())
S=input()
num=S.count(".")
ans=num
for i in S:
    if i=="
        num+=1
    else:
        num-=1
    ans=min(ans,num)
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())
S = input()
a = S.count('.')
ans = a

for i in S:
    if i == '.':
        a -= 1
    else:
        a += 1
    ans = min(ans, a)

print(ans)

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

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

s = input()

white = list([0]*n)
black = list([0]*n)

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

res = white[-1]

for i in range(n):
    res = min(white[-1] - white[i] + black[i], res)

print(res)

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

Solution (Python):
N = int(input())
S = input()
a,b = S.count('.'),0
ans = a+b

for i in S:
    if i =='.': a -= 1
    else: b += 1
    ans = min(ans,a + b)

print(ans)

Solution (Python):
N = int(input())
S =(list(input()))
newS=[]
for i in S:
    if i == ".":
        newS.append(0)
    else:
        newS.append(1)

countW=newS.count(0)
countB=newS.count(1)
ans=min(countW,countB)
countB=0
for s in newS:
    if s ==1:
        
        countB+=1
    else:
      countW-=1
      
        
    ans=min(ans,countB+countW)
    

print(ans)

Solution (Python):
N = int(input())
S = input()
B = [0] * (N + 1)
W = [0] * (N + 1)

for i in range(1, N + 1):
    B[i] = B[i - 1]
    if S[i - 1] == '
        B[i] += 1
for i in range(N - 1, -1, -1):
    W[i] = W[i + 1]
    if S[i] == '.':
        W[i] += 1
ans = 10**10
for i in range(N + 1):
    ans = min(ans, B[i] + W[i])
print(ans)

Solution (Python):
n=int(input())
s=input()
w = s.count('.')
b = 0
ans=w+b
for i in s:
    if i=='
        b+=1
    else:
        w-=1
    if ans>=b+w:
        ans=b+w
print(ans)

Solution (Python):
import sys


fin = sys.stdin.readline
N = int(fin())
S = fin().rstrip("\n")
assert len(S) == N

WHITE, BLACK = 0, 1


min_changes_at = [[float('inf')] * 2 for _ in range(N)]
min_changes_at[-1] = [1, 0] if S[-1] == "

for i in reversed(range(len(S) - 1)):
    color = S[i]
    if color == "
        
        min_changes_at[i][WHITE] = min(min_changes_at[i + 1]) + 1
        
        min_changes_at[i][BLACK] = min_changes_at[i + 1][BLACK]
    else:  
        
        min_changes_at[i][WHITE] = min(min_changes_at[i + 1])
        
        min_changes_at[i][BLACK] = min_changes_at[i + 1][BLACK] + 1

print(min(min_changes_at[0]))

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

black = 0
white = s.count('.')

ans = white + black

for i in range(n):
    if s[i] == '
        black += 1
    else:
        white -= 1
    ans = min(ans, white + black)

print(ans)

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

ans = float("inf")

r_b = s.count("
r_w = s.count(".")

l_b,l_w = 0,0

ans = min(ans,l_b + r_w)

for i in range(n):
  if s[i] == "
    r_b -= 1
    l_b += 1
  else:
    r_w -= 1
    l_w += 1

  ans = min(ans,l_b + r_w)

print(ans)

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

a = [(0, 0) for _ in range(len(s) + 1)]

i = 0
while i < len(s):
    bs, ws = a[i + 1]
    b0, w0 = a[i]

    if s[i] == '
        bs += 1
    else:
        ws += 1

    a[i + 1] = (bs + b0, ws + w0)
    i += 1


i = 0
can = len(s)
while i < len(a):
    can = min(can, a[i][0] + a[-1][1] - a[i][1])
    i += 1

print(can)

Solution (Python):
import numpy as np
N = int(input())
stones = np.array([0 if stone == "." else 1 for stone in input()])



def count_painted_stones_by_cumsum(stones, length):
    left_black_stones = np.roll(np.cumsum(stones), 1)
    left_black_stones[0] = 0
    right_white_stones = np.roll(np.cumsum(1 - stones[::-1]), 1)
    right_white_stones[0] = 0

    return np.min(left_black_stones + right_white_stones[::-1])


print(count_painted_stones_by_cumsum(stones, len(stones)))

Solution (Python):
N = int(input())
S = input()
blacks = [0 for i in range(N + 1)]
whites = [0 for i in range(N + 1)]
for i in range(N):
    blacks[i + 1] = blacks[i] + (S[i] == '
    whites[i + 1] = whites[i] + (S[i] == '.')
result = N
for i in range(N + 1):
    result = min(result, blacks[i] + (whites[N] - whites[i]))
print(result)

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

acc = [0]
acc2 = [0]
for s in S:
    if s == ".":
        acc.append(acc[-1] + 1)
        acc2.append(acc2[-1])
    else:
        acc.append(acc[-1])
        acc2.append(acc2[-1] + 1)
acc.pop(0)

ans = float("inf")

for i in range(N):
    s = S[i]
    tmp = acc[-1] - acc[i]
    tmp2 = acc2[i]
    ans = min(ans , tmp + tmp2)
print(ans)

Solution (Python):
n=int(input())
S=list(input())
W,B=[0]*(n+1),[0]*(n+1)
for i in range(n):
    if S[i]=='.':
        W[i+1]=W[i]+1
        B[i+1]=B[i]
    else:
        W[i+1]=W[i]
        B[i+1]=B[i]+1
ans=float('inf')
for i in range(n+1):
    w=W[i]
    b=B[-1]-B[i]
    tmp=n-w-b
    ans=min(ans,tmp)
print(ans)

Solution (Python):
import numpy as np

n = int(input())
s = [int(i=='

blacks = 0
whites = np.sum(np.array(s)==0)
ans = [blacks+whites]

for x in s:
  if x==1:
    blacks += 1
  else:
    whites -= 1

  ans.append(blacks + whites)

print(np.min(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()
white = s.count('.')
black = 0
cnt = black + white
for i in s:
    if i == '
        black += 1
    else:
        white -= 1
    cnt = min(cnt,black + white)
    
print(cnt)

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

Solution (Python):
from collections import Counter

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



c = Counter(s)
SL = 0
SR = c['
DL = 0
DR = c['.']
if SR == 0 or DR == 0:
    score = 0
else:

    score = len(s)

    while True:
        x = s.find('.')
        if x == -1:
            break
        SR -= x
        SL += x
        s = s[x:]

        a = DL + DR
        b = SL + SR
        c = SL + DR
        score = min([a,b,c, score])
    


        x = s.find('
        if x == -1:
            break
        DR -= x
        DL += x
        s = s[x:]

        a = DL + DR
        b = SL + SR
        c = SL + DR
        score = min([a,b,c, score])
    
print(score)

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

Solution (Python):
read = input
n = int(read())
s = read()
SW = [0 for i in range(n)]
SB = [0 for i in range(n)]
for i,c in enumerate(s):
    if i == 0:
        SW[i] = 1 if c == '.' else 0
        SB[i] = 1 if c == '
    else :
        SW[i] = SW[i-1] + 1 if c == '.' else SW[i-1]
        SB[i] = SB[i-1] + 1 if c == '
cost = n
for i in range(n):
    pass

for i in range(n + 1):
    startW = 0
    endW = i 
    startB = i 
    endB = n 

    if i == 0: 
        cost = min(cost, SW[n-1])
    elif i == n: 
        cost = min(cost, SB[n-1])
    else:
        cost = min(cost, 
                   SB[i-1] + (SW[n-1] - SW[i-1])
                  )

print(cost)

Solution (Python):
n=int(input())
s=input()
ans=0
import collections
c = collections.Counter(s)
ans=c["."]
t=ans
for i in s:
    if(i=="."):
        t-=1
        ans=min(t,ans)
    if(i=="
        t+=1
        ans=min(t,ans)
print(ans)

Solution (Python):





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

ans1 = 0
ans2 = 0
kuro_frag = False

for i in S:
    if i == "
        kuro_frag = True
    elif kuro_frag:
        ans1 += 1

kuro_count = 0
siro_count = 0

for i in range(N):
    if S[i] == "
        kuro_count += 1
        siro_count = 0
        ans2 += 1
    else:
        kuro_count = 0
        siro_count += 1






sirokuro_list = []

if S[0] == ".":
    first_sirofrag = True
else:
    first_sirofrag = False

kuro_count = 0
siro_count = 0

for i in range(N):
    if S[i] == "
        kuro_count += 1
        if siro_count != 0:
            sirokuro_list.append(siro_count)
        siro_count = 0
    else:
        siro_count += 1
        if kuro_count != 0:
            sirokuro_list.append(kuro_count)
        kuro_count = 0

if siro_count != 0:
    sirokuro_list.append(siro_count)
if first_sirofrag:
    sirokuro_list.pop(0)





i = 2
if len(sirokuro_list) > 1:
    sirowa = [sirokuro_list[1]]
    kurowa = [sirokuro_list[0]]
    while True:
        if i == len(sirokuro_list):
            break

        if (i % 2) == 0:
            kurowa.append(sirokuro_list[i] + kurowa[-1])
        if (i % 2) == 1:
            sirowa.append(sirokuro_list[i] + sirowa[-1])
        i+=1

    
    

    ans3 = min(ans1, ans2)

    for i in range(0, len(kurowa)):
        ans_tmp = 0
        ans_tmp += kurowa[i]
        ans_tmp += sirowa[-1] - sirowa[i]
        
        if ans_tmp < ans3:
            ans3 = ans_tmp

    print(ans3)
else:
    print(0)

Solution (Python):
def main(n):
	flg = False
	s = "." + input()
	ans = 0
	tempans = 0
	blk = 0
	wht = 0
	for i in range(n+1):
		if s[i] == "
			blk += 1
			if s[i-1] == ".":
				flg = True
		else:
			if flg:
				wht += 1
			if blk <= wht:
				ans += blk
				blk = 0
				wht = 0
				flg = False
	print(ans + wht)
main(int(input()))

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

w = [0] * (n + 1)
for i in range(n - 1, -1, -1):
    w[i] = w[i + 1]
    if s[i] == '.':
        w[i] += 1

ans = 0
for i in range(n - 2, -1, -1):
    if s[i] == '
        ans = min(ans + 1, w[i + 1])

print(ans)

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

white = [0] * (N + 1)
black = [0] * (N + 1)
for i, si in enumerate(S):
    black[i + 1] = black[i]
    white[i + 1] = white[i]
    if si == "
        black[i + 1] += 1
    if si == ".":
        white[i + 1] += 1

mi = 10 ** 10
for i in range(N + 1):
    b = black[i]
    w = white[N] - white[i]
    mi = min(w + b, mi)
print(mi)

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

a = []
pc = "."
pi = 0
for i,c in enumerate(S):
    if pc!=c:
        a.append(i-pi)
        pi = i
        pc = c
else:
    a.append(i+1-pi)

l = len(a)
w = 0
b = sum(a[2::2])
ans = w+b
for i in range(1,(l+1)//2):
    
    if -1+i*2 < l:
        w += a[-1+i*2]
    if i*2 < l:
        b -= a[i*2]
    ans = min(ans,w+b)
print(ans)