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)

#pragma warning disable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;


static class MainClass
{
    public static void Main(string[] args)
    {
        var n = Console.ReadLine().ToInt32();
        var s = Console.ReadLine();
        var fbl = -1;
        var lwh = -1;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '#')
            {
                fbl = i;
                break;
            }
        }
        var allwcount = 0;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '.')
            {
                lwh = i;
                allwcount++;
            }
        }

        if (fbl == -1 || lwh == -1)
        {
            Console.WriteLine(0);
        }
        else
        {
            var wcount = 0;
            for (int i = 0; i < lwh; i++)
            {
                if (s[i] == '#')
                {
                    wcount++;
                }
            }
            var bcount = 0;
            for (int i = fbl; i < n; i++)
            {
                if (s[i] == '.')
                {
                    bcount++;
                }
            }
            Console.WriteLine(Math.Min(Math.Min(allwcount, n - allwcount), Math.Min(wcount,bcount)));

            Console.ReadLine();
        }


        //var firstblk = -1;
        //var lastblkStart = -1;
        //for (int i = 0; i < s.Length; i++)
        //{
        //    if (s[i] == '#')
        //    {
        //        firstblk = i;
        //        break;
        //    }
        //}
        //for (int i = s.Length - 1; i >= 0; i--)
        //{
        //    if (s[i] == '#')
        //    {
        //        lastblkStart = i;
        //    }
        //    else
        //    {
        //        break;
        //    }
        //}
        //if (firstblk != -1)
        //{
        //    var toblkcount = 0;

        //    for (int i = firstblk; i < s.Length; i++)
        //    {
        //        if (s[i] == '.')
        //            toblkcount++;
        //    }
        //    var towhitecount = 0;
        //    for (int i = 0; i < (lastblkStart == -1 ? s.Length : lastblkStart); i++)
        //    {
        //        if (s[i] == '#')
        //            towhitecount++;
        //    }
        //    Console.WriteLine(Math.Min(towhitecount, toblkcount));
        //    Console.ReadLine();
        //}
        //else
        //{
        //    Console.WriteLine(0);
        //    Console.ReadLine();
        //}
        
        
    }

    public static int ParentCount;

    public static int[] Parents;
    public static int[] IfParentsChildrenCount;

    public static int[] Ranks;

    public static void InitializeUnionFind(int N)
    {
        Parents = new int[N];
        Ranks = new int[N];
        IfParentsChildrenCount = new int[N];
        for (int i = 0; i < N; i++)
        {
            Parents[i] = i;
            Ranks[i] = 0;
            IfParentsChildrenCount[i] = 1;
        }
        ParentCount = N + 1;
    }

    public static int Root(int a)
    {
        if (Parents[a] == a)
        {
            return a;
        }
        else
        {
            Parents[a] = Root(Parents[a]);
            return Parents[a];
        }
    }

    public static bool Same(int a, int b)
    {
        return Root(a) == Root(b);
    }

    public static void Unite(int a, int b)
    {
        var parentA = Root(a);
        var parentB = Root(b);
        if (parentA == parentB)
            return;
        if (Ranks[parentA] < Ranks[parentB])
        {
            Parents[parentA] = parentB;
            IfParentsChildrenCount[parentB] += IfParentsChildrenCount[parentA];
            ParentCount -= IfParentsChildrenCount[parentA];

            IfParentsChildrenCount[parentA] = 0;
        }
        else
        {
            Parents[parentB] = parentA;
            if (Ranks[parentA] == Ranks[parentB])
            {
                Ranks[parentA]++;
            }
            IfParentsChildrenCount[parentA] += IfParentsChildrenCount[parentB];
            ParentCount -= IfParentsChildrenCount[parentB];
            IfParentsChildrenCount[parentB] = 0;
        }
    }

    #region ライブラリ

    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => str == "" ? 0 : int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 4;
    public const long LONGINF = long.MaxValue / 2;
    public const int Mod1e9 = 1000000007;

    public static void PrintArray(decimal[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            var sb = new StringBuilder();
            for (int j = 0; j < array.GetLength(1); j++)
            {
                sb.Append(array[i, j] + " ");
            }
            Console.WriteLine(sb.ToString());
        }
    }
    public static int Manhattan(int x1, int x2, int y1, int y2)
    {
        return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
    }

    public static Dictionary<T, int> ToCountedDictionary<T>(this IEnumerable<T> items)
    {
        var dic = new Dictionary<T, int>();
        foreach (var item in items)
        {
            if (dic.ContainsKey(item))
                dic[item]++;
            else
                dic.Add(item, 1);
        }
        return dic;
    }

    public static long Sums(IEnumerable<int> list)
    {
        var sum = 0l;
        foreach (var item in list)
        {
            sum += item;
        }
        return sum;
        #endregion
    }

    public static int[] dx = new int[] { -1, 1, 0, 0 };
    public static int[] dy = new int[] { 0, 0, 1, -1 };
}