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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
#define int long long
#define double long double
#define fst first
#define snd second
#define fr(s,n,i) for(int i=s;i<n;i++)
#define times(n) for(int i=0;i<n;i++)
#define fr_(s,n,i) for(int i=s;i>=n;i--)
#define srt(v) sort(v.begin(), v.end());
#define upr(v, aim, ind) int ind; ind=(int)distance(v.begin(), upper_bound(v.begin(),v.end(), aim))
#define sz(v) (int)v.size()
#define ers(v, i) v.erase(v.begin() + i)
#define last(v) v[sz(v) - 1]
#define swp(v, i, j) int buf = v[j]; v[j] = v[i]; v[i] = buf
#define shout(a) cout << a << endl
#define dshout(a) printf("%.16Lf\n", a)
#define pr pair<int, int>
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vd vector<double>
#define vdd vector<vd>
#define mx(a, b) a = max(a, b)
#define mn(a, b) a = min(a, b)
#define mulM(a,b,c) a = a * b % c
#define squM(a,b) a = a * a % b
#define mpr(a,b) make_pair(a,b)
#define iinp(a) int a; cin >> a
#define sinp(a) string a; cin >> a
#define dinp(a) double a; cin >> a
#define ios() ios_base::sync_with_stdio(0);cin.tie(0)

int MOD = 998244353;
int INF = ~(1LL << 63);

int powM(int base, int exp){
    int ret = 1;
    int buf = base;
    while(exp > 0){
        if(exp & 1){
            ret *= buf;
        }
        squM(buf, MOD);
        exp >>= 1;
    }
    return ret;
}
int combM(int a, int b){
    if(b == 0){
        return 1;
    }
    if(a-b < b){
        return combM(a, a-b);
    }
    int ans = 1;
    fr(1,b+1,i){
        ans *= a + 1 - i;
        ans /= i;
    }
    return ans;
}
void solve();
signed main() {
    ios();
    solve();
    return 0;
}

void solve(){
    int in;
    string a;
    cin >> in >> a;
    int allwht = 0;
    map <int,int> wht;
    map <int,int> blk;
    fr(0,a.length(),i){
        if(a[i] == '.'){
            allwht++;
        }
        wht[i] = allwht;
    }
    int ans = min(allwht, (int)a.length() - allwht);
    fr(0,a.length(),i){
        int leftb = (i+1 - wht[i]);
        int rightw =(allwht - wht[i]);
        int buf = leftb + rightw;
        // cout << leftb << "," << rightw << "," <<buf << endl;
        ans = min(ans, buf);
    }
    cout << ans << endl;
}