import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int n; string s; scan(n); scan(s); int l, r; l = s.countUntil('#').to!int; r = s.length.to!int - 1 - s.retro().countUntil('#').to!int; n--; if (l == r && n == l) { writeln(3); return; } int ans; if (n <= l) { auto d = new int[](r + 1 - n); ans = l2r(s[n .. r + 1], d); } else if (r <= n) { auto d = new int[](n+1 - l); ans = l2r(s[l .. n+1].retro().to!string, d); } else { auto d1 = new int[](r + 1 - l); foreach (i ; 0 .. n - l) { d1[i]++; } ans = l2r(s[l .. r+1], d1); auto d2 = new int[](r + 1 - l); foreach (i ; 0 .. r - n) { d2[i]++; } debug { writeln(d2); } ans = min(ans, l2r(s[l .. r+1].retro.to!string, d2)); } writeln(ans); } int l2r(string ss, int[] d) { auto s = new int[](ss.length); foreach (i ; 0 .. ss.length) { s[i] = (ss[i] == '#'); } foreach (i ; 0 .. s.length - 1) { d[i+1]++; if (s[i] != (d[i] & 1)) { d[i]++; if (i + 1 < s.length - 1) { d[i+1]++; } } } debug { writeln(d); } return d.sum(); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }