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: Runtime Error)

using System;
using System.Collections.Generic;
using System.Linq;

namespace T1PBC2019C
{
    class MainClass
    {


        static int[] n;

        public static void Main(string[] args)
        {

            n = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);
            string s = Console.ReadLine();



            int blkcnt = 0;
            int whtcnt = 0;
            var bwlst = new List<int[]>();
            for(int i = 0; i < n[0]-1; i++)
            {
                if (s[i] == '#')
                {
                    blkcnt++;
                    if (s[i + 1] == '.')
                    {
                        int[] b = new int[2] { blkcnt, 1 };
                        bwlst.Add(b);
                        blkcnt = 0;
                        if(i== (n[0] - 2))
                        {
                            int[] w = new int[2] { 1, 0 };
                            bwlst.Add(w);
                        }
                    }
                    else if (i == (n[0] - 2))
                    {
                        int[] b = new int[2] { blkcnt+1, 1 };
                        bwlst.Add(b);
                        blkcnt = 0;
                    }
                }
                else
                {
                    whtcnt++;
                    if (s[i + 1] == '#')
                    {
                        int[] w = new int[2] { whtcnt, 0 };
                        bwlst.Add(w);
                        whtcnt = 0;
                        if (i == (n[0] - 2))
                        {
                            int[] b = new int[2] { 1, 1 };
                            bwlst.Add(b);
                        }
                    }
                    else if (i == (n[0] - 2))
                    {
                        int[] w = new int[2] { whtcnt + 1, 0 };
                        bwlst.Add(w);
                        whtcnt = 0;
                    }
                }
            }

            if (bwlst.First()[1] == 0)bwlst.RemoveAt(0);
            if (bwlst.Count == 0)
            {
                Console.WriteLine(0);
                return;
            }
            else
            {
                if (bwlst.Last()[1] == 1) bwlst.RemoveAt(bwlst.Count - 1);
                if (bwlst.Count == 0)
                {
                    Console.WriteLine(0);
                    return;
                }
            }
            var anslst = new List<int>();
            for(int i = 0; i < bwlst.Count/2; i++)
            {
                int ans = 0;
                for(int j = 0; j < i * 2; j++)
                {
                    if (j % 2 == 0)
                    {
                        ans += bwlst[j][0];
                    }
                }
                for(int j = i * 2; j < bwlst.Count; j++)
                {
                    if (j % 2 == 1)
                    {
                        ans += bwlst[j][0];
                    }
                }
                anslst.Add(ans);
            }
            anslst.Sort();






            Console.WriteLine(anslst.First());

        }
    }
}