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 in Ruby (2.3.3) (judge verdict: Accepted)

# 位置i から左にある黒の数と右にある白の数の合計を調べ、最小となる i を求める
N = gets.to_i
S = gets.chomp.chars # chars は Enumerable に変換

# 位置i の左にある黒の数を累積和にする
lb = []
lb[0] = 0
N.times{|i|
	lb[i+1] = lb[i] + 1 if S[i] == '#'
	lb[i+1] = lb[i] if S[i] != '#'
}

#p lb
# ##### --> 0,1,2,3,4,5
# ...## --> 0,0,0,0,1,2

# S を反転して、反転した状態で
# 位置i の左にある白の数を累積和にする
SR = S.reverse
lw = []
lw[0] = 0
N.times{|i|
	lw[i+1] = lw[i] + 1 if SR[i] == '.'
	lw[i+1] = lw[i] if SR[i] != '.'
}
#作成した累積和を反転する
rw = lw.reverse

#p rw
# ##### --> 0,0,0,0,0,0
# ...## --> 3,2,1,0,0,0

ca = [] #計算結果
(N+1).times{|i|
	ca[i] = lb[i]+rw[i]
}

puts ca.min