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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/*Atcoder用
 * 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int a = Integer.parseInt(tmp[0]);
		int b = Integer.parseInt(tmp[1]);
		int c = Integer.parseInt(tmp[2]);


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String get = br.readLine();
		char[] s = get.toCharArray();
		for(char c:s)System.out.println(c);

		List<Integer> ls = new ArrayList<Integer>();
		String[] tmp = br.readLine().split(" ");
		for (int n = 0; n < N; n++) {
			ls.add(Integer.parseInt(tmp[n]));
		}
 */

public class Main {

	public static void main(String[] args) throws IOException {
 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num = br.readLine();
		int N = Integer.parseInt(num);
		String get = br.readLine();
		char[] S = get.toCharArray();

		List<Integer> whiteNum = new ArrayList<Integer>();
		List<Integer> blackNum = new ArrayList<Integer>();

		//TODO: testCase 1 # でバグ
		//		おそらくマスの目まで計算している

		int count = 0;
		for(int i = 0;i<S.length;i++){
			if(S[i] == '.')count++;
			whiteNum.add(count);

		}
		count = 0;
		int memory = 0;
		for(int i = 0;i<S.length;i++){
			if(S[i] == '#')memory++;
			blackNum.add(count);
			count = memory;
		}

		int min = (int) Math.pow(10,10);
		for(int j = 0;j<S.length;j++){
			count = blackNum.get(j) + (whiteNum.get(S.length-1) - whiteNum.get(j));
			min = Math.min(min, count);
		}

		System.out.println(min);

	}

}