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: Wrong Answer)

/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{

        static int MOD = (int)1e9+7;

        // for dfs
        static int n;
        static int ansi;
        static int[] w;
        static int[] ww;
        static boolean[] isvisited;
        //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String s = sc.next();
        // all white or ...#### only ok
        int[] cntbl = new int[n];
        int[] cntwi = new int[n];
        int ans = n;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '.'){
                cntwi[i]++;
            }else{
                cntbl[i]++;
            }
        }
        for (int i = 0; i < n; i++) {
            if (i>0) {
                cntbl[i] += cntbl[i-1];
                cntwi[i] += cntwi[i-1];
            }
        }

        for (int i = 0; i < n; i++) {
                ans = Math.min( cntbl[i]+(cntwi[n-1] - cntwi[i]) , ans );
        }
        System.out.println(ans);



        sc.close();
    }

    /*
    For Numeric Analysis
    */
    public static int ManhattanDist(int x, int y, int xx, int yy) {
        return(Math.abs(xx-x) + Math.abs(yy-y));
    }

    public static double FuncOfx(double x, int funcnum) {
        switch (funcnum) {
            case 1:
                return x*x;

            case 2:
                return Math.exp(-1*x)-x*x;
        
            default:
                throw new IllegalArgumentException("Such Func doesn't Exist.");
        }
            
    }

    public static void Nibutan(double target, int funcnum) {
        int callcounter = 0;
        double lowbound = Integer.MIN_VALUE;
        double highbound = Integer.MAX_VALUE;
        double pivot = (lowbound + highbound)/2;
        double tmp;
        double tmp4swap;
        if (funcnum == 1) {
            lowbound = 0;
            pivot = (lowbound+highbound)/2;
        }
        while (true) {
            callcounter++;
            if (FuncOfx(highbound, funcnum) < FuncOfx(lowbound, funcnum)) {
                tmp4swap = highbound;
                highbound = lowbound;
                lowbound = tmp4swap;
            }

            if (FuncOfx(pivot,funcnum) > target) {
                System.out.println(String.format("%2d", callcounter) + ": " 
                            + String.format("%.6f", pivot) + " f(" + String.format("%.6f", pivot) +") is " 
                            + String.format("%.6f",FuncOfx(pivot,funcnum))  + ", so too high :(");
                tmp = (lowbound + pivot)/2;
                if ( Math.abs(tmp-pivot) < 0.00005 ) {
                    System.out.println("Found!" +String.format("%.3f", tmp)+" is the answer.");
                    return;
                }
                highbound = pivot;
                pivot = tmp;
            }else if(FuncOfx(pivot,funcnum) < target){
                System.out.println(String.format("%2d", callcounter) + ": " 
                            + String.format("%.6f", pivot) + " f(" + String.format("%.6f", pivot) +") is " 
                            + String.format("%.6f",FuncOfx(pivot,funcnum))  + ", so too high :(");
                tmp = (highbound + pivot)/2;
                if ( Math.abs(tmp-pivot) < 0.00005 ) {
                    System.out.println("Found!" +String.format("%.3f", tmp)+" is the answer.");
                    return;
                }
                lowbound = pivot;
                pivot = tmp;
            }
        }
        
    }

    /*
    Numeric Analysis End
    */

    private static long[][] CombinationLong_nCk(long n, long k) {
        n++; k++;
        long[][] ans = new long[(int)n][(int)k];
        for (int i = 0; i < n; i++) {
            ans[i][0] = 1;
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < k-1; j++) {
                if (i < j) {
                    ans[i][j] = 0;
                }else{
                    ans[i+1][j+1] = ans[i][j] + ans[i][j+1];
                }
            }
        }
        return ans;
    }

        public static int gcd_int(int a, int b) {
        
            if (a < b) {
                int tmpp = a;
                a = b;
                b = tmpp;
            }
            if (b == 0) {
                return a;
            }else{
                return gcd_int(b, a%b);
            }
        } 

        public static long gcd_long(long a, long b) {
        
            if (a < b) {
                long tmpp = a;
                a = b;
                b = tmpp;
            }
            if (b == 0) {
                return a;
            }else{
                return gcd_long(b, a%b);
            }
        }

        public static int lcm_int(int a, int b) {
            int gcd = gcd_int(a,b);
            return a/gcd*b;
        }

        public static long lcm_long(long a, long b) {
            long gcd = gcd_long(a,b);
            return a/gcd*b;
        }

        public static void dfs(int placenow) {
            // if went all -> success! 
            // if not went all -> fail...
            
            /*
            dfs    
            Go All Place that there is way to and not having been yet. 

             if island 1 is start point, dfs(1);
            if there is way to island 2 and island 3,
            - island 2 changes non-visited -> visited, and dfs(2).
            - island 3 changes non-visited -> visited, and dfs(3).
    
            */

            isvisited[placenow] = true;
            boolean success = true;
            for (int i = 0; i < n; i++) {
                if (isvisited[i] == false) { // not go all place
                    success = false;
                    break;
                }
            }
            if (success) {
                ansi++;
                isvisited[placenow] = false;
                return;
            }

            for (int i = 0; i < n; i++) {
                if (w[i] == placenow && isvisited[ww[i]] == false ) {
                    dfs(ww[i]);
                }else if(ww[i] == placenow && isvisited[w[i]] == false){
                    dfs(w[i]);
                }else{
                    continue;
                }
            }
            isvisited[placenow] = false;
            return;
        }

}