Problem:
Score : 300 points

Problem Statement

N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.

The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.

You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.

At least how many tiles need to be repainted to satisfy the condition?

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum number of tiles that need to be repainted to satisfy the condition.

Sample Input 1

000

Sample Output 1

1

The condition can be satisfied by repainting the middle tile white.

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0

Solution in JavaScript (node.js v5.12) (judge verdict: Accepted)

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(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["Data.Eq"]=t["Data.Eq"]||{}).refEq=function(t){return function(n){return t===n}}}(),function(n){"use strict";var a=t["Data.Eq"],e=(t["Data.HeytingAlgebra"],t["Data.Symbol"],t["Data.Unit"],t["Data.Void"],t["Record.Unsafe"],t["Type.Data.RowList"],function(t){this.eq=t}),r=new e(a.refEq);n.Eq=e,n.eq=function(t){return t.eq},n.eqInt=r}(t["Data.Eq"]=t["Data.Eq"]||{}),function(n){"use strict";(t["Data.Ord.Unsafe"]=t["Data.Ord.Unsafe"]||{}).unsafeCompareImpl=function(t){return function(n){return function(a){return function(e){return function(r){return e<r?t:e===r?n:a}}}}}}(),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"],e=(t["Data.Symbol"],t["Record.Unsafe"],t["Type.Data.RowList"],function(t){this.show=t}),r=new e(a.showIntImpl);n.Show=e,n.show=function(t){return t.show},n.showInt=r}(t["Data.Show"]=t["Data.Show"]||{}),function(n){"use strict";t["Data.Eq"],t["Data.Semigroup"],t["Data.Show"];var a=function(){function t(){}return t.value=new t,t}(),e=function(){function t(){}return t.value=new t,t}(),r=function(){function t(){}return t.value=new t,t}();n.LT=a,n.GT=e,n.EQ=r}(t["Data.Ordering"]=t["Data.Ordering"]||{}),function(n){"use strict";var a=t["Data.Ord.Unsafe"],e=t["Data.Ordering"],r=a.unsafeCompareImpl(e.LT.value)(e.EQ.value)(e.GT.value);n.unsafeCompare=r}(t["Data.Ord.Unsafe"]=t["Data.Ord.Unsafe"]||{}),function(n){"use strict";t["Data.Ord"];var a=t["Data.Eq"],e=t["Data.Ord.Unsafe"],r=t["Data.Ordering"],o=(t["Data.Ring"],t["Data.Semiring"],t["Data.Symbol"],t["Data.Unit"],t["Data.Void"],t["Record.Unsafe"],t["Type.Data.RowList"],function(t,n){this.Eq0=t,this.compare=n}),i=new o(function(){return a.eqInt},e.unsafeCompare),u=function(t){return t.compare};n.Ord=o,n.compare=u,n.min=function(t){return function(n){return function(a){var e=u(t)(n)(a);if(e instanceof r.LT)return n;if(e instanceof r.EQ)return n;if(e instanceof r.GT)return a;throw new Error("Failed pattern match at Data.Ord (line 119, column 3 - line 122, column 12): "+[e.constructor.name])}}},n.ordInt=i}(t["Data.Ord"]=t["Data.Ord"]||{}),function(n){"use strict";t["Control.Alt"],t["Control.Alternative"],t["Control.Applicative"],t["Control.Apply"],t["Control.Bind"],t["Control.Category"],t["Control.Extend"],t["Control.Monad"],t["Control.MonadZero"],t["Control.Plus"],t["Data.Bounded"],t["Data.Eq"],t["Data.Function"],t["Data.Functor"],t["Data.Functor.Invariant"],t["Data.Monoid"],t["Data.Ord"],t["Data.Ordering"],t["Data.Semigroup"],t["Data.Show"],t["Data.Unit"],t.Prelude;var a=function(){function t(){}return t.value=new t,t}(),e=function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}();n.Nothing=a,n.Just=e}(t["Data.Maybe"]=t["Data.Maybe"]||{}),function(n){"use strict";t["Control.Alt"];var a=t["Control.Applicative"],e=t["Control.Apply"],r=(t["Control.Bind"],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"]),o=(t["Data.Functor.Invariant"],t["Data.FunctorWithIndex"],t["Data.Maybe"],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}()),i=function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}(),u=new r.Functor(function(t){return function(n){if(n instanceof o)return new o(n.value0);if(n instanceof i)return new i(t(n.value0));throw new Error("Failed pattern match at Data.Either (line 38, column 8 - line 38, column 52): "+[n.constructor.name])}}),c=new e.Apply(function(){return u},function(t){return function(n){if(t instanceof o)return new o(t.value0);if(t instanceof i)return r.map(u)(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])}}),l=new a.Applicative(function(){return c},i.create);n.Left=o,n.Right=i,n.functorEither=u,n.applyEither=c,n.applicativeEither=l}(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"],e=t.Partial;n.unsafeCrashWith=function(t){return a.unsafePartial(function(n){return e.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}(),e=function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}();n.Loop=a,n.Done=e,n.tailRec=function(t){return function(n){return function(n){var r,o=!1;function i(r){if(!(r instanceof a)){if(r instanceof e)return o=!0,r.value0;throw new Error("Failed pattern match at Control.Monad.Rec.Class (line 91, column 3 - line 91, column 25): "+[r.constructor.name])}n=t(r.value0)}for(;!o;)r=i(n);return r}(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(e){return e<0||e>=a.length?n:t(a[e])}}}}}(t["Data.Array"]=t["Data.Array"]||{}),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"],e=(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"]),r=(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(e.Just.create)(e.Nothing.value));n.index=r,n.length=a.length}(t["Data.Array"]=t["Data.Array"]||{}),function(n){"use strict";t["Data.Int"],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"],t["Data.Ord"],t["Data.Ordering"],t["Data.Ring"],t["Data.Semiring"],t["Data.Show"],t.Global,t.Math,t.Prelude;n.even=function(t){return 0==(1&t)},n.odd=function(t){return 0!=(1&t)}}(t["Data.Int"]=t["Data.Int"]||{}),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"],e=t["Control.Monad.Rec.Class"],r=t["Data.Array"],o=t["Data.Either"],i=(t["Data.Eq"],t["Data.HeytingAlgebra"],t["Data.Int"]),u=t["Data.Maybe"],c=t["Data.Ord"],l=(t["Data.Semiring"],t["Data.Show"]),f=(t["Data.String"],t["Data.String.Common"]),s=(t["Data.String.Pattern"],t["Partial.Unsafe"]),D=(t.Prelude,function(t){var n=f.split("")(f.trim(t));return a.pure(o.applicativeEither)(l.show(l.showInt)(function(t){r.length(t);return e.tailRec(function(n){var a=r.index(t)(n.i);if(a instanceof u.Nothing)return new e.Done(c.min(c.ordInt)(n.e)(n.o));if(a instanceof u.Just)return new e.Loop({i:n.i+1|0,e:n.e+(i.even(n.i)&&"0"===a.value0||i.odd(n.i)&&"1"===a.value0?0:1)|0,o:n.o+(i.even(n.i)&&"1"===a.value0||i.odd(n.i)&&"0"===a.value0?0:1)|0});throw new Error("Failed pattern match at AtCoder.ABC124.C (line 34, column 7 - line 47, column 13): "+[a.constructor.name])})({i:0,e:0,o:0})}(n)))});n.solve=function(t){var n=D(t);if(n instanceof o.Left)return s.unsafeCrashWith(n.value0);if(n instanceof o.Right)return n.value0;throw new Error("Failed pattern match at AtCoder.ABC124.C (line 18, column 3 - line 20, column 24): "+[n.constructor.name])}}(t["AtCoder.ABC124.C"]=t["AtCoder.ABC124.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"],e=(t.Prelude,function(){function t(){}return t.value=new t,t}()),r=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 e)return"ASCII";if(t instanceof r)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=e,n.UTF8=r,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"],e=(t.Effect,t.Prelude,t["Unsafe.Coerce"].unsafeCoerce);n.mkEffect=e,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"],e=(t["Data.Time.Duration"],t.Effect,t["Node.Buffer"],t["Node.Encoding"]),r=(t["Node.FS"],t["Node.FS.Internal"]),o=(t["Node.FS.Perms"],t["Node.FS.Stats"],t["Node.Path"],t.Prelude,r.unsafeRequireFS);n.readTextFile=function(t){return function(n){return r.mkEffect(function(r){return o.readFileSync(n,{encoding:a.show(e.showEncoding)(t)})})}}}(t["Node.FS.Sync"]=t["Node.FS.Sync"]||{}),function(n){"use strict";var a=t["AtCoder.ABC124.C"],e=(t["Control.Applicative"],t["Control.Bind"],t.Effect,t["Effect.Console"]),r=t["Node.Encoding"],o=t["Node.FS.Sync"];t.Prelude;n.main=function(){var t=o.readTextFile(r.UTF8.value)("/dev/stdin")(),n=a.solve(t);return e.log(n)()}}(t.Main=t.Main||{}),t.Main.main();
},{}]},{},["Focm"], null)