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 JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"Focm":[function(require,module,exports) {
var t={};!function(t){"use strict";var n=function(t){this.compose=t},a=new n(function(t){return function(n){return function(a){return t(n(a))}}});t.compose=function(t){return t.compose},t.Semigroupoid=n,t.semigroupoidFn=a}(t["Control.Semigroupoid"]=t["Control.Semigroupoid"]||{}),function(n){"use strict";var a=t["Control.Semigroupoid"],r=function(t,n){this.Semigroupoid0=t,this.identity=n},e=new r(function(){return a.semigroupoidFn},function(t){return t});n.Category=r,n.identity=function(t){return t.identity},n.categoryFn=e}(t["Control.Category"]=t["Control.Category"]||{}),function(n){"use strict";(t["Data.Boolean"]=t["Data.Boolean"]||{}).otherwise=!0}(),function(n){"use strict";t["Control.Category"],t["Data.Boolean"],t["Data.Ord"],t["Data.Ring"];n.const=function(t){return function(n){return t}}}(t["Data.Function"]=t["Data.Function"]||{}),function(n){"use strict";t["Data.Functor"],t["Control.Semigroupoid"],t["Data.Function"],t["Data.Unit"];n.Functor=function(t){this.map=t},n.map=function(t){return t.map}}(t["Data.Functor"]=t["Data.Functor"]||{}),function(n){"use strict";t["Control.Apply"],t["Control.Category"],t["Data.Function"],t["Data.Functor"];n.Apply=function(t,n){this.Functor0=t,this.apply=n},n.apply=function(t){return t.apply}}(t["Control.Apply"]=t["Control.Apply"]||{}),function(n){"use strict";t["Control.Apply"],t["Data.Functor"],t["Data.Unit"];n.Applicative=function(t,n){this.Apply0=t,this.pure=n},n.pure=function(t){return t.pure}}(t["Control.Applicative"]=t["Control.Applicative"]||{}),function(n){"use strict";t["Control.Bind"],t["Control.Applicative"],t["Control.Apply"],t["Control.Category"],t["Data.Function"],t["Data.Functor"],t["Data.Unit"];n.Bind=function(t,n){this.Apply0=t,this.bind=n},n.bind=function(t){return t.bind}}(t["Control.Bind"]=t["Control.Bind"]||{}),function(n){"use strict";(t["Data.Eq"]=t["Data.Eq"]||{}).refEq=function(t){return function(n){return t===n}}}(),function(n){"use strict";var a=t["Data.Eq"],r=(t["Data.HeytingAlgebra"],t["Data.Symbol"],t["Data.Unit"],t["Data.Void"],t["Record.Unsafe"],t["Type.Data.RowList"],function(t){this.eq=t}),e=new r(a.refEq);n.Eq=r,n.eq=function(t){return t.eq},n.eqChar=e}(t["Data.Eq"]=t["Data.Eq"]||{}),function(n){"use strict";(t["Data.Show"]=t["Data.Show"]||{}).showIntImpl=function(t){return t.toString()}}(),function(n){"use strict";var a=t["Data.Show"],r=(t["Data.Symbol"],t["Record.Unsafe"],t["Type.Data.RowList"],function(t){this.show=t}),e=new r(a.showIntImpl);n.Show=r,n.show=function(t){return t.show},n.showInt=e}(t["Data.Show"]=t["Data.Show"]||{}),function(n){"use strict";t["Control.Alt"],t["Control.Alternative"],t["Control.Applicative"];var a=t["Control.Apply"],r=t["Control.Bind"],e=(t["Control.Category"],t["Control.Extend"],t["Control.Monad"],t["Control.MonadZero"],t["Control.Plus"],t["Data.Bounded"],t["Data.Eq"],t["Data.Function"]),o=t["Data.Functor"],i=(t["Data.Functor.Invariant"],t["Data.Monoid"],t["Data.Ord"],t["Data.Ordering"],t["Data.Semigroup"],t["Data.Show"],t["Data.Unit"],t.Prelude,function(){function t(){}return t.value=new t,t}()),u=function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}(),c=function(t){return function(n){return function(a){if(a instanceof i)return t;if(a instanceof u)return n(a.value0);throw new Error("Failed pattern match at Data.Maybe (line 217, column 1 - line 217, column 51): "+[t.constructor.name,n.constructor.name,a.constructor.name])}}},l=c(!0)(e.const(!1)),f=new o.Functor(function(t){return function(n){return n instanceof u?new u(t(n.value0)):i.value}}),s=new a.Apply(function(){return f},function(t){return function(n){if(t instanceof u)return o.map(f)(t.value0)(n);if(t instanceof i)return i.value;throw new Error("Failed pattern match at Data.Maybe (line 67, column 1 - line 67, column 35): "+[t.constructor.name,n.constructor.name])}}),D=new r.Bind(function(){return s},function(t){return function(n){if(t instanceof u)return n(t.value0);if(t instanceof i)return i.value;throw new Error("Failed pattern match at Data.Maybe (line 125, column 1 - line 125, column 33): "+[t.constructor.name,n.constructor.name])}});n.Nothing=i,n.Just=u,n.maybe=c,n.isNothing=l,n.fromJust=function(t){return function(t){if(t instanceof u)return t.value0;throw new Error("Failed pattern match at Data.Maybe (line 268, column 1 - line 268, column 46): "+[t.constructor.name])}},n.functorMaybe=f,n.applyMaybe=s,n.bindMaybe=D}(t["Data.Maybe"]=t["Data.Maybe"]||{}),function(n){"use strict";t["Control.Alt"];var a=t["Control.Applicative"],r=t["Control.Apply"],e=t["Control.Bind"],o=(t["Control.Extend"],t["Control.Monad"],t["Control.Semigroupoid"],t["Data.Bifoldable"],t["Data.Bifunctor"],t["Data.Bitraversable"],t["Data.Bounded"],t["Data.Eq"],t["Data.Foldable"],t["Data.FoldableWithIndex"],t["Data.Function"],t["Data.Functor"]),i=(t["Data.Functor.Invariant"],t["Data.FunctorWithIndex"],t["Data.Maybe"]),u=(t["Data.Monoid"],t["Data.Ord"],t["Data.Ordering"],t["Data.Semigroup"],t["Data.Show"],t["Data.Traversable"],t["Data.TraversableWithIndex"],t["Data.Unit"],t.Prelude,function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}()),c=function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}(),l=new o.Functor(function(t){return function(n){if(n instanceof u)return new u(n.value0);if(n instanceof c)return new c(t(n.value0));throw new Error("Failed pattern match at Data.Either (line 38, column 8 - line 38, column 52): "+[n.constructor.name])}}),f=function(t){return function(n){return function(a){if(a instanceof u)return t(a.value0);if(a instanceof c)return n(a.value0);throw new Error("Failed pattern match at Data.Either (line 238, column 1 - line 238, column 64): "+[t.constructor.name,n.constructor.name,a.constructor.name])}}},s=new r.Apply(function(){return l},function(t){return function(n){if(t instanceof u)return new u(t.value0);if(t instanceof c)return o.map(l)(t.value0)(n);throw new Error("Failed pattern match at Data.Either (line 82, column 1 - line 82, column 41): "+[t.constructor.name,n.constructor.name])}}),D=new e.Bind(function(){return s},f(function(t){return function(n){return new u(t)}})(function(t){return function(n){return n(t)}})),d=new a.Applicative(function(){return s},c.create);n.Left=u,n.Right=c,n.either=f,n.note=function(t){return i.maybe(new u(t))(c.create)},n.functorEither=l,n.applyEither=s,n.applicativeEither=d,n.bindEither=D}(t["Data.Either"]=t["Data.Either"]||{}),function(n){"use strict";(t["Partial.Unsafe"]=t["Partial.Unsafe"]||{}).unsafePartial=function(t){return t()}}(),function(n){"use strict";(t["Partial"]=t["Partial"]||{}).crashWith=function(){return function(t){throw new Error(t)}}}(),function(n){"use strict";var a=t.Partial;n.crashWith=a.crashWith}(t.Partial=t.Partial||{}),function(n){"use strict";var a=t["Partial.Unsafe"],r=t.Partial;n.unsafeCrashWith=function(t){return a.unsafePartial(function(n){return r.crashWith(n)(t)})}}(t["Partial.Unsafe"]=t["Partial.Unsafe"]||{}),function(n){"use strict";t["Control.Applicative"],t["Control.Bind"],t["Control.Monad"],t["Control.Semigroupoid"],t["Data.Bifunctor"],t["Data.Either"],t["Data.Functor"],t["Data.Identity"],t["Data.Maybe"],t["Data.Unit"],t.Effect,t["Effect.Ref"],t["Partial.Unsafe"],t.Prelude;var a=function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}(),r=function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}();n.Loop=a,n.Done=r,n.tailRec=function(t){return function(n){return function(n){var e,o=!1;function i(e){if(!(e instanceof a)){if(e instanceof r)return o=!0,e.value0;throw new Error("Failed pattern match at Control.Monad.Rec.Class (line 91, column 3 - line 91, column 25): "+[e.constructor.name])}n=t(e.value0)}for(;!o;)e=i(n);return e}(t(n))}}}(t["Control.Monad.Rec.Class"]=t["Control.Monad.Rec.Class"]||{}),function(t){"use strict";t.length=function(t){return t.length},t.indexImpl=function(t){return function(n){return function(a){return function(r){return r<0||r>=a.length?n:t(a[r])}}}},t.filter=function(t){return function(n){return n.filter(t)}},t.slice=function(t){return function(n){return function(a){return a.slice(t,n)}}},t.drop=function(t){return function(n){return t<1?n:n.slice(t)}}}(t["Data.Array"]=t["Data.Array"]||{}),function(n){"use strict";t["Control.Applicative"],t["Control.Apply"],t["Control.Biapplicative"],t["Control.Biapply"],t["Control.Bind"],t["Control.Comonad"],t["Control.Extend"],t["Control.Lazy"],t["Control.Monad"],t["Control.Semigroupoid"],t["Data.Bifoldable"],t["Data.Bifunctor"],t["Data.Bitraversable"],t["Data.BooleanAlgebra"],t["Data.Bounded"],t["Data.CommutativeRing"],t["Data.Distributive"],t["Data.Eq"],t["Data.Foldable"],t["Data.FoldableWithIndex"],t["Data.Function"],t["Data.Functor"],t["Data.Functor.Invariant"],t["Data.FunctorWithIndex"],t["Data.HeytingAlgebra"],t["Data.Maybe"],t["Data.Maybe.First"],t["Data.Monoid"],t["Data.Newtype"],t["Data.Ord"],t["Data.Ordering"],t["Data.Ring"],t["Data.Semigroup"],t["Data.Semigroup.Foldable"],t["Data.Semigroup.Traversable"],t["Data.Semiring"],t["Data.Show"],t["Data.Traversable"],t["Data.TraversableWithIndex"],t["Data.Unit"],t.Prelude,t["Type.Equality"];var a=function(){function t(t,n){this.value0=t,this.value1=n}return t.create=function(n){return function(a){return new t(n,a)}},t}();n.Tuple=a}(t["Data.Tuple"]=t["Data.Tuple"]||{}),function(n){"use strict";(t["Unsafe.Coerce"]=t["Unsafe.Coerce"]||{}).unsafeCoerce=function(t){return t}}(),function(n){"use strict";var a=t["Unsafe.Coerce"];n.unsafeCoerce=a.unsafeCoerce}(t["Unsafe.Coerce"]=t["Unsafe.Coerce"]||{}),function(n){"use strict";var a=t["Data.Array"],r=(t["Control.Alt"],t["Control.Alternative"],t["Control.Applicative"],t["Control.Apply"],t["Control.Bind"],t["Control.Category"],t["Control.Lazy"],t["Control.Monad.Rec.Class"],t["Control.Monad.ST"],t["Control.Monad.ST.Internal"],t["Control.Semigroupoid"],t["Data.Array.NonEmpty.Internal"],t["Data.Array.ST"],t["Data.Array.ST.Iterator"],t["Data.Boolean"],t["Data.Eq"],t["Data.Foldable"],t["Data.Function"],t["Data.Functor"],t["Data.HeytingAlgebra"],t["Data.Maybe"]),e=(t["Data.Ord"],t["Data.Ordering"],t["Data.Ring"],t["Data.Semigroup"],t["Data.Semiring"],t["Data.Traversable"],t["Data.Tuple"],t["Data.Unfoldable"],t["Partial.Unsafe"],t.Prelude,t["Unsafe.Coerce"],a.indexImpl(r.Just.create)(r.Nothing.value));n.head=function(t){return e(t)(0)},n.index=e,n.length=a.length,n.filter=a.filter,n.drop=a.drop}(t["Data.Array"]=t["Data.Array"]||{}),function(n){"use strict";(t["Data.Int"]=t["Data.Int"]||{}).fromStringAsImpl=function(t){return function(n){return function(a){var r;r=a<11?"[0-"+(a-1).toString()+"]":11===a?"[0-9a]":"[0-9a-"+String.fromCharCode(86+a)+"]";var e=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(r){if(e.test(r)){var o=parseInt(r,a);return(0|o)===o?t(o):n}return n}}}}}(),function(n){"use strict";var a=t["Data.Int"],r=(t["Control.Category"],t["Control.Semigroupoid"],t["Data.Boolean"],t["Data.Bounded"],t["Data.CommutativeRing"],t["Data.DivisionRing"],t["Data.Eq"],t["Data.EuclideanRing"],t["Data.HeytingAlgebra"],t["Data.Int.Bits"],t["Data.Maybe"]),e=(t["Data.Ord"],t["Data.Ordering"],t["Data.Ring"],t["Data.Semiring"],t["Data.Show"],t.Global,t.Math,t.Prelude,a.fromStringAsImpl(r.Just.create)(r.Nothing.value)),o=e(10);n.fromString=o,n.fromStringAs=e}(t["Data.Int"]=t["Data.Int"]||{}),function(t){"use strict";t.toCharArray=function(t){return t.split("")},t.length=function(t){return t.length},t["_indexOf'"]=function(t){return function(n){return function(a){return function(r){return function(e){if(r<0||r>e.length)return n;var o=e.indexOf(a,r);return-1===o?n:t(o)}}}}},t._slice=function(t){return function(n){return function(a){return a.slice(t,n)}}}}(t["Data.String.CodeUnits"]=t["Data.String.CodeUnits"]||{}),function(n){"use strict";var a=t["Data.String.CodeUnits"],r=(t["Control.Semigroupoid"],t["Data.Boolean"]),e=(t["Data.Eq"],t["Data.Function"],t["Data.HeytingAlgebra"],t["Data.Maybe"]),o=(t["Data.Ord"],t["Data.Ring"],t["Data.Semiring"],t["Data.String.Pattern"],t["Data.String.Unsafe"],t.Prelude,a["_indexOf'"](e.Just.create)(e.Nothing.value));n["indexOf'"]=o,n.slice=function(t){return function(n){return function(o){var i=a.length(o),u=function(t){if(t<0)return i+t|0;if(r.otherwise)return t;throw new Error("Failed pattern match at Data.String.CodeUnits (line 314, column 5 - line 315, column 27): "+[t.constructor.name])},c=u(n),l=u(t);return l<0||l>=i||c<0||c>i||l>c?e.Nothing.value:new e.Just(a._slice(t)(n)(o))}}},n.toCharArray=a.toCharArray,n.length=a.length}(t["Data.String.CodeUnits"]=t["Data.String.CodeUnits"]||{}),function(t){"use strict";t.split=function(t){return function(n){return n.split(t)}},t.trim=function(t){return t.trim()}}(t["Data.String.Common"]=t["Data.String.Common"]||{}),function(n){"use strict";var a=t["Data.String.Common"];t["Data.Eq"],t["Data.Ordering"],t["Data.String.Pattern"],t.Prelude;n.split=a.split,n.trim=a.trim}(t["Data.String.Common"]=t["Data.String.Common"]||{}),function(n){"use strict";var a=t["Control.Applicative"],r=t["Control.Bind"],e=t["Control.Category"],o=t["Control.Monad.Rec.Class"],i=t["Data.Array"],u=t["Data.Either"],c=t["Data.Eq"],l=t["Data.Int"],f=t["Data.Maybe"],s=(t["Data.Semiring"],t["Data.Show"]),D=(t["Data.String"],t["Data.String.CodeUnits"]),d=t["Data.String.Common"],p=(t["Data.String.Pattern"],t["Data.Tuple"]),C=t["Partial.Unsafe"];t.Prelude;n.solve=function(t){return u.either(function(t){return C.unsafeCrashWith(t)})(e.identity(e.categoryFn))((n=d.split("\n")(d.trim(t)),r.bind(u.bindEither)(u.note("n")(r.bind(f.bindMaybe)(i.head(n))(l.fromString)))(function(t){return r.bind(u.bindEither)(u.note("s")(i.head(i.drop(1)(n))))(function(t){return a.pure(u.applicativeEither)(s.show(s.showInt)((n=t,o.tailRec(function(t){var a=D["indexOf'"]("#.")(t.value0)(n);if(a instanceof f.Nothing)return new o.Done(t.value1);if(a instanceof f.Just)return f.isNothing(D["indexOf'"]("#.")(a.value0+2|0)(n))?new o.Loop(new p.Tuple(a.value0+1|0,t.value1+1|0)):new o.Done(t.value1+i.length(i.filter(c.eq(c.eqChar)("."))(D.toCharArray(f.fromJust()(D.slice(a.value0+1|0)(D.length(n))(n)))))|0);throw new Error("Failed pattern match at AtCoder.Tenka12019Beginner.C (line 30, column 7 - line 37, column 177): "+[a.constructor.name])})(new p.Tuple(0,0)))));var n})})));var n}}(t["AtCoder.Tenka12019Beginner.C"]=t["AtCoder.Tenka12019Beginner.C"]||{}),function(n){"use strict";(t["Effect.Console"]=t["Effect.Console"]||{}).log=function(t){return function(){return console.log(t),{}}}}(),function(n){"use strict";var a=t["Effect.Console"];t["Data.Show"],t["Data.Unit"],t.Effect;n.log=a.log}(t["Effect.Console"]=t["Effect.Console"]||{}),function(n){"use strict";t["Node.Encoding"];var a=t["Data.Show"],r=(t.Prelude,function(){function t(){}return t.value=new t,t}()),e=function(){function t(){}return t.value=new t,t}(),o=function(){function t(){}return t.value=new t,t}(),i=function(){function t(){}return t.value=new t,t}(),u=function(){function t(){}return t.value=new t,t}(),c=function(){function t(){}return t.value=new t,t}(),l=function(){function t(){}return t.value=new t,t}(),f=function(){function t(){}return t.value=new t,t}(),s=new a.Show(function(t){if(t instanceof r)return"ASCII";if(t instanceof e)return"UTF8";if(t instanceof o)return"UTF16LE";if(t instanceof i)return"UCS2";if(t instanceof u)return"Base64";if(t instanceof c)return"Latin1";if(t instanceof l)return"Binary";if(t instanceof f)return"Hex";throw new Error("Failed pattern match at Node.Encoding (line 19, column 1 - line 19, column 39): "+[t.constructor.name])});n.ASCII=r,n.UTF8=e,n.UTF16LE=o,n.UCS2=i,n.Base64=u,n.Latin1=c,n.Binary=l,n.Hex=f,n.showEncoding=s}(t["Node.Encoding"]=t["Node.Encoding"]||{}),function(n){"use strict";(t["Node.FS.Internal"]=t["Node.FS.Internal"]||{}).unsafeRequireFS=require("fs")}(),function(n){"use strict";var a=t["Node.FS.Internal"],r=(t.Effect,t.Prelude,t["Unsafe.Coerce"].unsafeCoerce);n.mkEffect=r,n.unsafeRequireFS=a.unsafeRequireFS}(t["Node.FS.Internal"]=t["Node.FS.Internal"]||{}),function(n){"use strict";t["Control.Bind"],t["Control.Semigroupoid"],t["Data.DateTime"],t["Data.DateTime.Instant"],t["Data.EuclideanRing"],t["Data.Function"],t["Data.Function.Uncurried"],t["Data.Functor"],t["Data.Int"],t["Data.Maybe"],t["Data.Nullable"];var a=t["Data.Show"],r=(t["Data.Time.Duration"],t.Effect,t["Node.Buffer"],t["Node.Encoding"]),e=(t["Node.FS"],t["Node.FS.Internal"]),o=(t["Node.FS.Perms"],t["Node.FS.Stats"],t["Node.Path"],t.Prelude,e.unsafeRequireFS);n.readTextFile=function(t){return function(n){return e.mkEffect(function(e){return o.readFileSync(n,{encoding:a.show(r.showEncoding)(t)})})}}}(t["Node.FS.Sync"]=t["Node.FS.Sync"]||{}),function(n){"use strict";var a=t["AtCoder.Tenka12019Beginner.C"],r=(t["Control.Applicative"],t["Control.Bind"],t.Effect,t["Effect.Console"]),e=t["Node.Encoding"],o=t["Node.FS.Sync"];t.Prelude;n.main=function(){var t=o.readTextFile(e.UTF8.value)("/dev/stdin")(),n=a.solve(t);return r.log(n)()}}(t.Main=t.Main||{}),t.Main.main();
},{}]},{},["Focm"], null)