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 (Python):
N = int(input())
S = input()
ns = []
i = 0
while i < N:
  j = S.find(".", i)
  if j < 0: j = N
  k = S.find("
  if k < 0: k = N
  ns.append((j-i, k-j))
  i = k

rs = []
r = sum([w for b, w in ns])
rs.append(r)
for b, w in ns:
  r += b-w
  rs.append(r)

r = min(rs)
print(r)

Solution (Python):
N = int(input())
S = input()




ans = S.count('.')
tmp = ans
for i in range(N):
  if S[i] == '.':
    tmp -= 1
  else:
    tmp += 1
  ans = min(ans,tmp)
print(ans)

Solution (Python):
n = int(input())
s = input()

w = [0]
cnt = 0
for i in range(n):
  if s[i] == '
    cnt += 1
  w.append(cnt)

ans = len(s)
for i in range(n+1):
  ans = min(ans, w[i]+(n-i-(w[-1]-w[i])))
print(ans)

Solution (Python):
n=int(input())
s=input()

white=s.count(".")
black=0
ans=white

for s_i in s:
    if s_i == "
        black+=1
    else:
        white-=1
    ans = min(ans, white+black)
print(ans)

Solution (Python):
def main():

    N = int(input())
    S = input()
    suffix_w = [0]
    for i in range(N-1, -1, -1):
        if S[i] == ".":
            suffix_w.append(suffix_w[-1] + 1)
        else:
            suffix_w.append(suffix_w[-1])
        
    suffix_w = suffix_w[::-1]
    


    min_c = float('inf')
    countb = 0
    countw = 0
    for i in range(N):
        if S[i] == "
            c = suffix_w[i+1] + countb
            min_c = min(min_c, c)
            countb += 1
        else:
            countw += 1
    min_c = min(min_c, countb, countw)
    return min_c

if __name__ == '__main__':
    print(main())

Solution (Python):
N = int(input())
S = input()

black = S.count('
white = S.count('.')

ans = white
prev_black = 0
for i in range(N):
    if(S[i] == '.'):
        white -= 1
    else:
        prev_black += 1
    ans = min(white + prev_black, ans)

print(ans)

Solution (Python):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    S = input().rstrip()

    
    ans = min(S.count('.'), S.count('

    white = [0] * (N + 1)

    for i, s in enumerate(S, start=1):
        white[i] += white[i - 1]
        if s == '.':
            white[i] += 1

    for mid, s in enumerate(S):
        
        left = (mid - white[mid])

        
        right = white[N] - white[mid + 1]

        ans = min(ans, left + right)

    print(ans)

sol()

Solution (Python):
n = int(input())
s = input()
counter = 0
counter = s.count('.')
result = counter
for i in s:
    if i == '
        counter += 1
    else:
        counter -= 1
    result = min(result, counter)
print(result)

Solution (Python):
N=int(input())
S=input()
b=0
w=S.count(".")
ans=b+w
for s in S:
    if s=="
        b+=1
    else:
        w-=1
    ans=min(ans, b+w)
print(ans)

Solution (Python):
n = int(input())
s = input()

ans = s.count(".")
temp = ans

for i in s:
    temp += 1 if i == "
    ans = min(ans, temp)

print(ans)

Solution (Python):
n = int(input())
s = input()


cost = 0
bc = 0
for it in s:
    if it =="
        bc += 1
    elif bc > 0:
        cost += 1
        bc -= 1

print(cost)

Solution (Python):
N = int(input())
S = input()

cum_lw = [0] * N
cum_rw = [0] * N

if S[0] == ".":
    cum_lw[0] = 1

if S[-1] == ".":
    cum_rw[-1] = 1 

for i in range(1,N):
    if S[i] == ".":
        cum_lw[i] = cum_lw[i-1] + 1
    else:
        cum_lw[i] = cum_lw[i-1]

    if S[N-1-i] == ".":
        cum_rw[N-1-i] = cum_rw[N-i] + 1
    else:
         cum_rw[N-1-i] = cum_rw[N-i]

ans = N
for i in range(N):
    if i != N-1:
        bb = cum_lw[i] + cum_rw[i+1]
        wb = (i+1)-cum_lw[i] + cum_rw[i+1]
        ww = (i+1)-cum_lw[i] + (N-1-i)-cum_rw[i+1]
    else:
        bb = cum_lw[i]
        wb = (i+1)-cum_lw[i]
        ww = (i+1)-cum_lw[i]
    ans = min([ans, bb, wb, ww])

print(ans)

Solution (Python):
n,s=open(0)
b=0;a=w=s.count(".")
for x in s:
	b+=x<"."
	w-=x>"
	a=min(a,b+w)
print(a)

Solution (Python):
n=int(input())
s=input()
l_b=0
r_w=s.count(".")
ans=l_b+r_w
for x in s:
	if x=="
		l_b+=1
	else:
		r_w-=1
	ans=min(ans,l_b+r_w)
print(ans)

Solution (Python):
n = int(input())
s = list(input())
b, w = 0, 0
for x in s:
    if x == '
    elif b > 0: 
        w += 1
        b -= 1
print(w)

Solution (Python):
n=int(input())
s=input()
w=s.count(".")
ww=0
b=s.count("
bb=0
ans=[bb+w]
for i in range(n):
	if s[i]==".":
		w-=1
		ww+=1
	else:
		b-=1
		bb+=1
	ans.append(bb+w)
print(min(ans))

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

n = int(input())
S = input()
f = [0] * (n+1)
for i in range(n):
    f[i+1] = f[i] + (S[i] == '
g = [0] * (n+1)
for i in range(n):
    g[i+1] = g[i] + (S[i] == '.')
k = S.index('
ans = min(f[n], g[n]-g[k])
lst = []
for i in range(n-1):
    if S[i:i+2] == '
        lst.append(i)
for i, j in zip(lst, lst[1:]):
    ans = min(ans, f[i+1]+g[n]-g[j])
print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    a,b,c = LI()
    if min(a,b) < c < max(a,b):
        print("Yes")
    else:
        print("No")
    return


def B():
    n = I()
    s = S()
    k = I()
    f = s[k-1]
    for i in range(n):
        if s[i] != f:
            print("*",end = "")
        else:
            print(s[i],end = "")
    print()
    return


def C():
    n = I()
    s = S()
    ans = 0
    f = [0]*(n+1)
    for i in range(n):
        f[i+1] = 1 if s[i] == "
    for i in range(n):
        f[i+1] += f[i]
    ans = float("inf")
    for i in range(n+1):
        ans = min(ans, f[i]+(n-i)-f[n]+f[i])
    print(ans)
    return


def D():

    return


def E():

    return


def F():

    return


def G():

    return


if __name__ == "__main__":
    C()

Solution (Python):
n = int(input())
s = input()
white = s.count('.')
black = 0
min = white
for i in range(n):
    if s[i] == '
        black += 1
    else:
        white -= 1
    if black + white < min:
        min = black + white 
print(min)

Solution (Python):
import fractions,math,sys
from collections import Counter
n = int(input())
s = list(input())
cnt = Counter(s)
white_l = 0
black_l = 0
min = cnt['.']
for i in range(n):
    if s[i] == '
        black_l += 1
        cnt['
    else:
        white_l += 1
        cnt['.'] -= 1
    if black_l + cnt['.'] < min:
        min = black_l + cnt['.']
print(min)

Solution (Python):
N = int(input())
S = list(input())

W = [0 for _ in range(N)]
cnt = 0
for i in range(N):
    if S[i] == "
        cnt += 1
    W[i] = cnt
cnt = 0

B = [0 for _ in range(N)]
for i in range(N)[::-1]:
    if S[i] == ".":
        cnt += 1
    B[i] = cnt

X = [W[i] + B[i+1] for i in range(N-1)]
X.append(W[N-1])
X.append(B[0])

print(min(X))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = input().rstrip()

S




Lb = [0] * (N+1)
for i,s in enumerate(S,1):
    Lb[i] = Lb[i-1] + (1 if s == '

answer = N + 100
black = Lb[-1]
for i in range(N+1):
    j = i+1
    
    left = Lb[i]
    right = N - i - (black - Lb[i])
    cost = left + right
    if answer > cost:
        answer = cost

print(answer)

Solution (Python):
N=int(input())
S=input()
b=0
w=S.count(".")
ans=b+w
for s in S:
  if s=="
    b+=1
  else:
    w-=1
  ans=min(ans, b+w)
print(ans)

Solution (Python):
N = int(input())
S = list(str(input()))

right_white = S.count('.')
right_black = len(S) - right_white

ans = right_white

left_white=0
left_black=0

for i in range(N):
    if(S[i] == '
        left_black = left_black+1
        right_black = right_black-1
    else:
        left_white = left_white+1
        right_white = right_white-1

    if(ans > (left_black + right_white)):
        ans = (left_black + right_white)

print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
s = input()
d = [0]+[1 if s[i] == "
d = list(accumulate(d))
ans = float('inf')
for i in range(1,n+1):
    ans = min(ans,d[i-1]+(n-i)-(d[-1]-d[i]))
print(ans)

Solution (Python):



n=int(input())
s=list(input())
bk=0
wh=s.count('.')
cnt=wh
for i in range(n):
	if s[i]=='
	else:wh-=1
	cnt=min(cnt,bk+wh)

print(cnt)

Solution (Python):
N = int(input())
S = input()

tb = S.count(".")
tw = 0
mi = tb + tw
for i in range(N):
    if S[i] == "
        tw = tw +1
    else:
        tb = tb -1
    mi = min(mi,tb+tw)


print(mi)

Solution (Python):
N = int(input())
S = input()

left = 0
right = 0
for i in range(N):
    if S[i] == ".":
        right += 1

ans = left + right

for i in range(N):
    if S[i] == "
        left += 1
    else:
        right -= 1
    ans = min(ans, left + right)

print(ans)

Solution (Python):
n=int(input())
s=input()
l=[0]
r=[0]
for i in range(n):
    if s[i]=="
        l.append(l[i]+1)
    else:
        l.append(l[i])
    if s[n-i-1]==".":
        r.append(r[i]+1)
    else:
        r.append(r[i])
r.reverse()
print(min([l[i]+r[i] for i in range(n+1)]))

Solution (Python):
N = int(input())
S = input()

W = [0] * N
W[-1] += S[-1] == "."
for i in range(N - 2, -1, -1):
    W[i] = W[i + 1] + (S[i] == ".")

B = [0] * N
B[0] += S[0] == "
for i in range(1, N):
    B[i] = B[i - 1] + (S[i] == "

T = [w + b - 1 for w, b in zip(W, B)]
T = min(T)
print(min(T, W[0], B[-1]))

Solution (Python):
N = int(input())
S = str(input())
x = S.count(".")
ans = x
for i in range(N):
    if S[i]=="
        x += 1
    else:
        x -= 1
    ans = (min(ans,x))
print(ans)

Solution (Python):
n = int(input())
s = str(input())
leftblack = 0
rightwhite = s.count(".")
ans = rightwhite

for i in range(n):
  if s[i] == "
    leftblack += 1
  else:
    rightwhite -= 1
  ans = min(ans,leftblack + rightwhite)
print(ans)

Solution (Python):
n = int(input())
s = input()
m = s.count(".")
ans = m

for i in range(n):
    if s[i] == "
        m += 1
    else:
        m -= 1
    ans = min(ans, m)
print(ans)

Solution (Python):
n = int(input())
s = input()
m = s.count(".")
ans = m

for i in range(len(s)):
    if s[i] == "
        m += 1
    else:
        m -= 1
    ans = min(ans, m)
print(ans)

Solution (Python):
def solve(n, s):
    total = s.count(".")
    ans = total
    cnt = 0
    for i in range(n):
        if s[i] == "
            cnt += 1
        else:
            cnt -= 1
        ans = min(ans, total+cnt)
    return ans

assert solve(3, "
assert solve(5, "
assert solve(9, ".........") == 0

n = int(input())
s = input()
print(solve(n, s))

Solution (Python):
n = int(input())
s = input()
m = s.count('.')
ans = m

for i in range(n):
    if s[i] == '
        m += 1
    else:
        m -= 1
    ans = min(ans, m)
    
print(ans)

Solution (Python):
n = int(input())
s = input()
m = s.count(".")
ans = m

for i in range(n):
    if s[i] == "
        m += 1
    else:
        m -=1
    ans = min(ans, m)
print(ans)

Solution (Python):
n = int(input())
s = input()
m = s.count('.')
ans = m

for i in range(n):
    if s[i] == '
        m += 1
    else:
        m -= 1
    ans = min(ans, m)

print(ans)

Solution (Python):
n = int(input())
s = input()

t = s.count(".")
r = 0
ans = t
for m in range(n) :
    if s[m] == "." :
        t -= 1
    else :
        r += 1
    ans = min(ans, t+r)
print(ans)

Solution (Python):
n = int(input())
s = input()

if "." not in s or "
    print(0)
else:
    ans = len(s)

    s = s[s.find("
    if s == "":
        print(0)
    else:
        cnt_b = [0 for i in range(len(s))]
        cnt = 0
        for i in range(len(s)):
            if s[i] == "
                cnt += 1
            cnt_b[i] = cnt
        ans = min(ans, len(s)-cnt_b[-1])
        for i in range(len(s)):
            ans = min(ans, cnt_b[i] + (len(s)-cnt_b[-1])-(i+1-cnt_b[i]))
        print(ans)

Solution (Python):
n=int(input())
s=input()
w=s.count('.')
b=0
ans=w
for i in range(n):
    if s[i]=='
        b+=1
    else:
        w-=1
    ans=min(ans,w+b)
print(ans)

Solution (Python):
n = int(input())
S = [s for s in input()]
w,b = [0],[0]
for i in range(n):
    if S[i] is '
    else:   w.append(w[i])
    if S[n-i-1] is '.': b.append(b[i]+1)
    else:   b.append(b[i])
b = b[::-1]

ans = float('inf')
for i in range(n+1):
    ans = min(ans, w[i]+b[i])
print(ans)

Solution (Python):
n = int(input())
s = input()


left_black = 0
right_white = s.count(".")
answer = left_black + right_white

for w in s:
    if w == "
        left_black += 1
    else:
        right_white -= 1
    answer = min(answer, left_black + right_white)

print(answer)

Solution (Python):

N = int(input())
S = " " + str(input()) + " "

ans = N+2
prev = ""


black = 0
white = S.count(".")

first_white = white
first_black = N - first_white

for i in range(N+2):
    current = S[i]

    ans = min(ans, black+white)

    if current is ".":
        white -= 1
    elif current is "
        black += 1

    prev = current

"""
if ans == N + 1:
    ans = 0
"""

print(min(ans, first_black, first_white))

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    S = input()

    total_b = S.count("
    total_w = S.count(".")
    ans = min(total_b, total_w)
    b, w = 0, 0
    for i in range(N):
        left_b = b
        right_w = total_w - w
        ans = min(ans, left_b + right_w)

        if S[i] == "
            b += 1
        else:
            w += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



"方針：ある場所を起点にそこから右の白を黒に(その点も含む)、そこより左を黒を全て白に"
N = int(input())
S = str(input())

black = [0]
white = [0]

for i in range(N):
    if S[i] == '
        black.append(black[-1] + 1)
        white.append(white[-1])
    else:
        black.append(black[-1])
        white.append(white[-1]+1)

ans = N
for i in range(N+1):
    ans = min(ans, black[i] + (white[-1]-white[i]))

print(ans)

Solution (Python):
N = int(input())
S = str(input())

black = [0]
white = [0]

for i in range(N):
    if S[i] == '
        black.append(black[-1]+1)
        white.append(white[-1])
    else:
        black.append(black[-1])
        white.append(white[-1]+1)

ans = N

for i in range(N+1):
    ans = min(ans, black[i] + (white[-1]-white[i]))
    

print(ans)

Solution (Python):
N = int(input())
S = input()

W = [0]*N
B = [0]*N
white = 0
black = 0

for i in range(N):
    if S[i] == '.':
        white += 1
    if S[-i-1] == '
        black += 1

    W[i] = white
    B[-i-1] = black

ans = N - max(white, black)
for i in range(N-1):
    tmp = abs((i+1)-W[i]) + abs((N-i-1)-B[i+1])
    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):
input()
S=input()
dot=S.count(".")
ans=dot
count=0
for s in S:
    if s=="
    else:dot-=1
    ans=(min(ans,count+dot))
print(ans)

Solution (Python):
n = int(input())
S = input()
W = [0]*(n+1)
B = [0]*(n+1)
for i in range(n):
    if S[i] == '.':
        W[i] = 1
    else:
        B[i] = 1
for i in range(1,n+1):
    W[i] += W[i-1]
    B[i] += B[i-1]
W = [0] + W
B = [0] + B
res = n
for i in range(n+1):
    res = min(W[-1]-W[i]+B[i],res)
print(res)

Solution (Python):
N = int(input())
S = list(input())

m = S.count('.')
mi = m

for s in S:
    if s == '.':
        m -= 1
    else:
        m += 1
    mi = min(mi,m)



print(mi)

Solution (Python):

n = int(input())
s = input()
ans = 0
blk = 0
for i in s:
    if i == "
        blk += 1
    else:
        if blk > 0:
            ans += 1
            blk -= 1
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline

n = int(input())
s = input().rstrip()
ans = 0
blk = 0
for i in s:
    if i == "
        blk += 1
    else:
        if blk > 0:
            ans += 1
            blk -= 1
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

n = int(input())
s = list(input())
res = 10 ** 9

cta = 0
ctb = 0
a = [0] * n
b = [0] * n
for i in range(n):
    if s[i] == ".":
        cta += 1
    else:
        ctb += 1
    a[i] = cta
    b[i] = ctb
for i in range(n):
    res = min(res, b[i] + a[-1] - a[i])
res = min(res, a[-1], b[-1])
print(res)

Solution (Python):

n = int(input())
s = input()
ans = 0
blk = 0
for i in s:
    if i == "
        blk += 1
    else:
        if blk > 0:
            ans += 1
            blk -= 1
print(ans)

Solution (Python):
N = int(input())
S = input()
ac = [0]


for i in range(N):
    if S[i] == "
        ac.append(ac[i] + 1)
    else:
        ac.append(ac[i])



work_min = N
for j in range(0, N + 1):
    work_sum = ac[j] + (N - j - (ac[N] - ac[j]))
    if work_min > work_sum:
        work_min = work_sum

print(work_min)

Solution (Python):
n = int(input())
s = input()
cost = s.count('.')
min = cost
for i in range(len(s)):
  if s[i]  == '.':
  	cost -= 1
  else:
    cost += 1
  if cost < min:
    min = cost
print(min)

Solution (Python):
N = int(input())
S = input()
ans1 = S.count("
ans2 = S.count(".")

L =[0]*(N+1)
for i in range(N):
    if S[i] == "
        L[i+1] = L[i] + 1
    else:
        L[i+1] = L[i]
ans3 = N
for i in range(1,N+1):
    if ans3 > 2*L[i]+N-i-L[N]:
        ans3 =  2*L[i]+N-i-L[N]
print(min(ans1,ans2,ans3))

Solution (Python):



def main():
    n = int(input())
    s = list(input())
    black_count = [0 for _ in range(n + 1)]
    ans = float('inf')

    for i, si in enumerate(s):
        if si == '
            black_count[i + 1] = black_count[i] + 1
        else:
            black_count[i + 1] = black_count[i]

    for j in range(n + 1):
        ans = min(ans, black_count[j] + (n - j) - black_count[n] + black_count[j])

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

"""
C - Stones
https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

"""
import sys


def solve(N, S):
    black = 0
    white = S.count('.')
    ans = float('inf')

    for s in S + ' ':
        ans = min(ans, black+white)
        if s == '
            black += 1
        else:
            white -= 1
    return ans


def __solve(N, S):
    ans1 = 0
    prev = '@'
    for s in S:
        if prev == '
            ans1 += 1
            prev = '
        else:
            prev = s
    return ans1


def main(args):
    N = int(input())
    S = input()
    ans = solve(N, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
n=int(input())
s=input()
w=[0]
b=[0]
for i in range(n):
    if s[i]==".":
        w.append(w[i]+1)
        b.append(b[i])
    else:
        w.append(w[i])
        b.append(b[i]+1)
ans=1000000
cnt=s.count(".")
for j in range(n+1):
    if ans>b[j]+cnt-w[j]:
        ans=b[j]+cnt-w[j]
print(ans)

Solution (Python):
n = int(input())
s = input()
bc = 0
cost = 0

for i in s:
  if i == '
    bc += 1
  else:
    if bc > 0:
      bc -= 1
      cost += 1
print(cost)

Solution (Python):
n = int(input())
s = list(input())

diff = s.count('.')

difflist = [diff]

for i in s:
  if i == '.':
    diff -= 1
  else:
    diff += 1
    
  difflist.append(diff)
  
print(min(difflist))

Solution (Python):
N = int(input())
S = input()

white = len([char for char in S if char == '.'])

left_black = 0
right_white = white
result = left_black + right_white
for char in S:
    if char == '.':
        right_white -= 1
    else:
        left_black += 1
    result = min(result, right_white + left_black)
print(result)

Solution (Python):
N = int(input())
S = input()

white = len([char for char in S if char == '.'])

result = 0
if white == 0:
    result = 0
else:
    result = white
    left_black = 0
    right_white = white
    for char in S:
        if char == '.':
            right_white -= 1
        else:
            left_black += 1
        result = min(result, right_white + left_black)
print(result)

Solution (Python):
n = int(input())
s = input()

count_list = []

black = 0
white = s.count('.')

count_list.append(white)

for i in range(n):
    if s[i] == '
        black += 1
    if s[i] == '.':
        white -= 1
    count_list.append(black + white)

print(min(count_list))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

N = int(input())
S = input()

result = S.count('.')
r = result
def dfs(i):
    global result
    global r
    if i == N:
        return float('inf')
    if S[i] == '
        r += 1
    else:
        r -= 1
    result = min(result,r)
    return min(result,dfs(i+1))

print(dfs(0))

Solution (Python):
n = int(input())
s = list(input())

b = 0
w = s.count(".")
m = w

for i in range(n):
	if s[i] == "
		b += 1
	else:
		w -= 1
	m = min(m, b + w)
print(m)

Solution (Python):
N = int(input())
S = str(input())
cntw = [0]*(N+1)
cntb = [0]*(N+1)
for i in range(N):
    cntb[i+1] = cntb[i]+1 if S[i]=="
    cntw[N-1-i] = cntw[N-i]+1 if S[N-1-i]=="." else cntw[N-i]
ans = 1e10
for i in range(N+1):
    ans = ans if ans < cntb[i]+cntw[i] else cntb[i]+cntw[i]
print(ans)

Solution (Python):
N = int(input())
S = input()
 

l_b = 0
r_w = S.count('.')
 
needHand = l_b + r_w
for i,v in enumerate(S):
  if S[i] == '
    l_b += 1
  else:
    r_w -= 1
  ret = l_b + r_w
  
  if ret <= needHand:
    needHand = ret
 
ans = needHand
print("{}".format(ans))

Solution (Python):
N = int(input())
S = input()


l_b = 0
r_w = S.count('.')

needHand = l_b + r_w
for i in S:
  if i == '
    l_b += 1
  else:
    r_w -= 1  
  needHand = min(needHand, l_b + r_w)

ans = needHand
print("{}".format(ans))

Solution (Python):
n=int(input())
s=input()

w=0
for i in s:
        if i==".":
                w+=1

b=0
min=10**5+1
for i in range(len(s)):
        temp=0
        if i>=1 and s[i-1]=="
                b+=1
        if s[i]==".":
                w-=1
        temp=w+b
        if temp<min:
                min=temp

print(min)

Solution (Python):
def main():
    N = int(input())
    S = input()
    left_black = 0
    right_white = S.count('.')
    min_change = left_black + right_white
    for s in S:
        if s == '
            left_black += 1
        else:
            right_white -= 1
        min_change = min(min_change, left_black + right_white)
    print(min_change)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = input()

score_list = [0 for i in range(n+2)]
score_list[0] = sum([1 if _s == "

score_list[n+1] = n - score_list[0]
 
for i in range(1, n+1):
    if s[i-1] == ".":
        score_list[i] = score_list[i-1] + 1
    else:
        score_list[i] = score_list[i-1] - 1

max_score = max(score_list)
print(n - max_score)

Solution (Python):
N = int(input())
S = input()
a = [0] * N
b = [0] * N
counter = []

if S[0] == '
    a[0] = 1
if S[N-1] == '.':
    b[N-1] = 1

for i in range(N-1):
    if S[i+1] == '
        a[i+1] = a[i] + 1
    else:
        a[i+1] = a[i]
    if S[N-i-2] =='.':
        b[N-i-2] = b[N-i-1] + 1
    else:
        b[N-i-2] = b[N-i-1]
counter.append(a[N-1])
counter.append(b[0])
for i in range(N-1):
    counter.append(a[i] + b[i+1])

print(min(counter))

Solution (Python):
N = int(input())
S = input()



dist = S.count(".")
min_dist = dist
for i in range(N):
  
  if S[i] == "
    dist += 1
  else:
    dist -= 1
    if dist < min_dist:
      min_dist = dist

print(min_dist)

Solution (Python):
N = int(input())
S = list(input())

W = S.count('.')
B = 0
ans = W
if W == 0:
    print (0)
else:
    for i in range(0,N):

        if S[i] == '
            B += 1
        else:
            W -= 1
        ans = min(ans, B+W)
    print (ans)

Solution (Python):
N = int(input())
S = list(input())

black = S.count('
white = N - black

answer = 0
if (white > 0 and black > 0):
  answer = min(black, white)
  black_left = 0
  white_left = 0
  for i in range(N - 1):
    if (S[i] == '
      black_left += 1
    else:
      white_left += 1
    black_right = black - black_left
    white_right = white - white_left
    answer = min(answer, black_left + white_right)

print(answer)

Solution (Python):
N = int(input())
S = input()
W = S.count(".")
B = 0
ans = B+W
for i in range(N):
    if S[i] == ".":
        W -= 1
    elif S[i] == "
        B += 1
    ans = min(ans, B+W)
print(ans)

Solution (Python):
n = int(input())
s = input()
white_count = 0
black_count = 0

for c in s:
    if c == ".":
        white_count += 1

maybe_answer_list = []

maybe_answer_list.append(white_count + black_count)

for c in s:
    if c == "
        black_count += 1
    else:
        white_count -= 1
    maybe_answer_list.append(white_count + black_count)

print(min(maybe_answer_list))

Solution (Python):
from itertools import accumulate
N=int(input())
S=input()
black=[0]*N
white=[0]*N
for i,s in enumerate(S):
        if s=='
                black[i]=1
        else:
                white[i]=1
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]
ans=[]
for i in range(N+1):
        ans.append(black[i]+white[i])
print(min(ans))

Solution (Python):
N = int(input())
S = input()

answer = ['.' for i in range(N)]
diff = 0
for i in range(N):
    if S[i] != answer[i]:
        diff += 1

counts = [diff]

for i in range(1, N+1):
    v = answer[-i] 
    if v == S[-i]:
        diff += 1
    else:
        diff -= 1
    answer[-i] = '.' if v == '
    counts.append(diff)

print(min(counts))

Solution (Python):
N = int(input())
S = input()

num_of_white = 0
num_of_black = 0

for i in range(1, N):
  if S[i] == '.':
    num_of_white += 1

result = num_of_white

for i in range(1, N):
  if S[i-1] == '
    num_of_black += 1
  if S[i] == '.':
    num_of_white -= 1
  
  if result > (num_of_black + num_of_white):
    result = num_of_black + num_of_white

print(result)

Solution (Python):
N = int(input())
S = input()

count = [0]*(len(S)+1)
count[0] = S.count('.')
for i in range(1, len(S)+1):
    count[i] = count[i-1] + (1 if S[i-1]=='

print(min(count))

Solution (Python):
n = int(input())
s = input()
black = s[:0].count("
white = s[0:].count(".")
count = [black+white]    
    
for i in range(1, n+1):
    if s[i-1]== "
        black +=1
    else:
        white -=1
    count.append(white+black)
    
print(min(count))

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
s = list(input())
res = 10**9

cta = 0
ctb = 0
a = [0]*n
b = [0]*n
for i in range(n):
    if s[i] == '.':
        cta += 1
    else:
        ctb += 1
    a[i] = cta
    b[i] = ctb
for i in range(n):
    res = min(res,b[i]+a[-1]-a[i])
res = min(res,a[-1],b[-1])
print(res)

Solution (Python):
N=int(input())
S=input()


num=S.count("
if num>S.count("."):
  num=S.count(".")
  
  
c_w=0
c_b=S.count(".")

for i in range(0,N): 
  if S[i]=="
    c_w+=1
  else:
    c_w=c_w
    c_b-=1
  num=min(num,c_w+c_b)
 
print(num)

Solution (Python):
N = int(input())
S = input()

c_b = 0
c_w = S.count('.')
ans = c_w

for i in range(N):
    if S[i] == '
        c_b += 1
    else:
        c_w -= 1
    ans = min(c_b+c_w, ans)

print(ans)

Solution (Python):
N=int(input())
S=input()
b,w,ans=0,0,0
w=S.count('.')
ans=w
for i in S:
    if i=='
        b+=1
    else:
        w-=1
    ans=min(b+w,ans)
print(ans)

Solution (Python):
import collections
n = int(input())

a = list(input())
su = 0
co = 1
coo = 0
c = 0
cc = 0
k = a[0]
c1 = n
c2 = 0
c3 = 0
aa = []
p = a.count("
pp = a.count(".")

for i in range(n-1):
	if k == a[i+1]:
		co += 1
	else:
		aa.append([k,co])
		k = a[i+1]
		co = 1

aa.append([k,co])
co = 0
if aa[-1][0] == ".":
	aa.append(["
for i in range(len(aa)):
	if aa[-(i+1)][0] == "
		c += aa[-(i+1)][1]
		c3 += aa[-(i+1)][1]
		c1 = min(c1,cc + p - c)
	else:
		cc += aa[-(i+1)][1]
		c2 += aa[-(i+1)][1]
		c1 = min(c1,cc + p - c)

print(min(c1,c2,c3))

Solution (Python):
N, S = int(input()), input()
bl = [0] * N
for i in range(N):
    if S[i] == "
        bl[i] += 1
bl_sum = [0] * N
for i in range(N):
    if i == 0:
        bl_sum[i] = bl[i]
    else:
        bl_sum[i] = bl_sum[i-1] + bl[i]

ans = N - bl_sum[N-1]

for i in range(N):
    ans = min(ans, bl_sum[i] + (N-i-1)-(bl_sum[N-1]-bl_sum[i]))

print(ans)

Solution (Python):
N = int(input())
S = input()

left_s = 0
right_d = 0

right_d = S.count('.')
ans = right_d

for i in range(N):
    if S[i] == '
        left_s += 1
    else:
        right_d -=1
    ans_tmp = left_s + right_d
    if ans > ans_tmp:
        ans = ans_tmp
print(ans)

Solution (Python):
N = int(input())
S = input()

s = [0 for _ in range(N+1)]
for i, x in enumerate(S):
    if x == "
        s[i+1] = s[i] + 1
    else:
        s[i+1] = s[i]
num = N
for i in range(N+1):
    w = s[i] - s[0]
    b = (N - i) - (s[N] - s[i])
    if w + b < num:
        num = w + b
print(num)

Solution (Python):
from sys import stdin
def solve():
  n = int(input())
  s = stdin.readline().rstrip()
  
  leftblack = 0
  leftwhite = 0
  rightblack = s.count('
  rightwhite = s.count(".")
  
  ans = leftblack+rightwhite
  
  for i in range(n):
    if s[i] == "
      leftblack += 1
      rightblack -= 1
    else:
      leftwhite += 1
      rightwhite -= 1
    ans = min(ans,leftblack+rightwhite)
  
  print(ans)
solve()