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 Python (3.4.3) (judge verdict: Wrong Answer)

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

'''考え方
1.白・黒それぞれの一番左端の位置を確認する
2.黒の右に白い石が存在するか否かを判断
3.変更するべき石の数が、白・黒どちらの方が多いか判断
'''

first_white = S.find('.')
first_black = S.find('#')
last_white = S.rfind('.')
last_black = S.rfind('#')

# blackのラストブロックのサイズを求めておく

cnt = 1
for s in reversed(S[:last_black]):
  if s == '#':
    cnt += 1
  else:
    break


out = 0


# 1.どちらか一色のみ 
if first_black == -1 or first_white == -1:
  out = 0

# 2.黒い石よりも右側に白色の石が存在する場合
elif S[first_black:].find('.') > -1:
  # 2-1.一番右のブロックが白色
  if last_white > last_black:
    cnt_white = S[first_black:].count('.')
    cnt_black = S[first_black:].count('#')
  # 2-2.一番右のブロックが黒色
  else:
    cnt_white = S[first_black:].count('.')
    cnt_black = S[first_black:].count('#') - cnt

  out = min(cnt_white,cnt_black)

# 3.左に白、右に黒、と完全に別れる場合
elif last_white < first_black:
  out = 0

print(out)