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 C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        Scanner cin = new Scanner();
        int N = cin.NextInt();
        string s = cin.Next();
        char[] temp = s.ToArray();

        int[] dp = Enumerable.Repeat(0, N).ToArray();

        for (int i = 1; i < N; ++i)
        {
            if (temp[i-1] == '#' && temp[i] == '.')
            {
                dp[i] = dp[i-1] + 1;
                temp[i] = '#';
            }
            else
            {
                dp[i] = dp[i - 1];
            }
        }
        var reversed = s.Reverse().ToArray();
        int blackrem = 0;
        bool blackf = false;
        for (int i = 0; i < N-1; ++i)
        {

            if (reversed[i] == '#' && reversed[i+1] == '.')
            {
                blackf = true;
            }
            if (reversed[i] == '#')
            {
                blackrem++;
            }
            else if (blackf)
            {
                break;
            }
        }

        int whiteright = 0;
        for (int i = 0; i < N; ++i)
        {
            if (reversed[i] == '.')
            {
                whiteright++;
            }
            else
            {
                break;
            }
        }

        int black = s.Where(e => e == '#').Count() - blackrem + whiteright;

        int ans = black >= dp.Last() ? dp.Last() : black;

        Console.WriteLine(ans);

    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}