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):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N = INT()
S = list(input())

tmp = S.count("
tmp2 = len(S) - tmp
num = [0]*N
num_sharp = 0
num_peri = 0
for i in range(len(S)):
	if S[i] == "
		num_sharp += 1
	else:
		num_peri += 1
	num[i] = num_sharp + tmp2-num_peri

print(min(tmp2, min(num)))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N = INT()
S = input()

b = [0]*(N+1)
w = [0]*(N+1)

tmp_b = 0
for i in range(N):
	if S[i] == "
		tmp_b += 1
	b[i+1] = tmp_b


tmp_w = 0
for i in range(N-1, -1, -1):
	if S[i] == ".":
		tmp_w += 1
	w[i] = tmp_w

ans = min([b[i]+w[i] for i in range(N+1)])


print(ans)

Solution (Python):
n=int(input())
s=list(input())
l=[[0,s.count('.')]]
for i in range(n):
    if s[i]=='.':
        l.append([l[-1][0],l[-1][1]-1])
    else:
        l.append([l[-1][0]+1,l[-1][1]])

ans=10**10
for i in range(n+1):
    ans=min(ans,sum(l[i]))

print(ans)

Solution (Python):
s=input()=='';b=[0]
for i in input():t=i=='.';b+=[b[-1]+1-t*2];s+=t
print(min([i+s for i in b]))

Solution (Python):
n=int(input());a=[0];b=[0];s=0
for i in input():t=i=='.';b+=[b[-1]+1-t*2];s+=t
print(min([i+s for i in b]))

Solution (Python):
n=int(input());a=[0];b=[0]
for i in input():t=i=='.';a+=[a[-1]+t];b+=[b[-1]+1-t*2];
print(min([i+a[n] for i in b]))

Solution (Python):
n = int(input())
s = input()
cost = 0
bc = 0
for it in s:
    if it =="
        bc += 1
    else:
        if bc > 0:
            cost += 1
            bc -= 1
print(cost)

Solution (Python):
import sys
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())

count = []
cnt_b = 0
cnt_w = 0
for s in S:
    if s == "
        cnt_b += 1
    else:
        cnt_w += 1
    count.append((cnt_b, cnt_w))

ans_1 = N - cnt_b
ans_2 = N - cnt_w
ans_3 = float("inf")

for i, j in count:
    ans_3 = min(ans_3, i + cnt_w - j)

print(min(ans_1, ans_2, ans_3))

Solution (Python):
n=int(input())
s=input()
c=[0]
for i in range(n):
    c.append(c[i]+(s[i]=='
p=n
for i in range(n+1):
    p=min((n-c[-1]+c[i])+(c[i]-i),p)
print(p)

Solution (Python):
from sys import stdin

def main():
    input = stdin.readline

    n = int(input())
    s = input()
    a = [[0, 0] for _ in range(n)]
    if s[0] == '.':
        a[0][0] = 1
    else:
        a[0][1] = 1
    for i in range(1, n):
        if s[i] == '.':
            a[i][0] = a[i - 1][0] + 1
            a[i][1] = a[i - 1][1]
        else:
            a[i][0] = a[i - 1][0]
            a[i][1] = a[i - 1][1] + 1
    min = a[-1][0] if a[-1][0] < a[-1][1] else a[-1][1]
    for i in range(n):
        if min > a[-1][0] - a[i][0] + a[i][1]:
            min = a[-1][0] - a[i][0] + a[i][1]
    print(min)
main()

Solution (Python):
n = int(input())
s = input()
countwhite = [0] * (n+1)
countblack = [0] * (n+1)


cnt = 0
for i in range(n):
    if s[i] == "
        cnt += 1
    countwhite[i+1] = cnt

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



res = 999999999999999
for i in range(n+1):
    res = min(res, countblack[i] + countwhite[i])
print(res)

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = list(input())
    numb = 0
    numw = S.count(".")
    answer = numb + numw
    for i in range(N):
        if S[i] == "
            numb += 1
        else:
            numw -= 1
        if answer > numb + numw:
            answer = numb + numw

    print(answer)


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
import numpy as np
n = int(input())
s = list(map(str, input().rstrip()))

ss = s.count("
sd = s.count(".")

if ss == 0 or sd == 0:
    print(0)
    sys.exit()

s = np.array([x == "

dp = np.zeros([2, n], dtype=int)


dp[0] = s
dp[1] = ~s

dp = dp.cumsum(axis=1)


dp[1] = dp[1].max() - dp[1]

print(min((dp[0] + dp[1]).min(), ss, sd))

Solution (Python):
from itertools import accumulate
n = int(input())
s = input()
l = []
for i in s:
  if i==".":
    l.append(0)
  else:
    l.append(1)
l1 = list(accumulate([0]+l))

l = []
for i in s[::-1]:
  if i==".":
    l.append(1)
  else:
    l.append(0)
l2 = list(accumulate([0]+l))[::-1]

cou = 10**6
if "
  print(0)
else:
  
  for j,k in zip(l1,l2):
    a = j+k
    cou = min(cou,a)
  print(cou)

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

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

W=[1 if S[0]=="." else 0]
ans=float("inf")

for i in range(1,N):
  if S[i]==".":
    W.append(W[-1]+1)
  else:
    W.append(W[-1])
    
if W[-1]==0 or W[-1]==N:
  print(0)
  exit()

for i in range(N):
  cost_W = i+1-W[i]
  cost_B = W[-1]-W[i]
  cost=cost_W+cost_B
  
  
  ans=min(ans,cost)
ans=min(W[-1],N-W[-1],ans)
print(ans)

Solution (Python):
n=int(input());s=input()
b=0
w=s.count('.')
ans=w
for si in s:
  b+=(si=='
  w-=(si=='.')
  ans=min(ans,b+w)
print(ans)

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

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

Solution (Python):
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")



def main():
    N = int(input())
    S = input()[:-1]

    l = 0
    r = 0
    for i in range(N):
        if S[i] == ".":
            r += 1
    
    ans = l + r
    for i in range(N):
        if S[i] == "
            l += 1
        else:
            r -= 1
        ans = min(ans, l + r)
    
    print(ans)
    


if __name__ == '__main__':
    main()

Solution (Python):
def solve():
    N = int(input())
    S = input()
    white = [0] * (N+1)
    black = [0] * (N+1)
    for i in range(1,N+1):
        if S[i-1] == '.':
            white[i] = white[i-1] + 1
            black[i] = black[i-1]
        else:
            black[i] = black[i-1] + 1
            white[i] = white[i-1]
    
    ans = float('inf')
    for i in range(N+1):
        tmp = black[i] + white[-1] - white[i]
        ans = min(ans, tmp)
    
    print(ans)
    
if __name__ == '__main__':
    solve()

Solution (Python):
def solve():
    N = int(input())
    S = input()
    white = [0] * (N+2)
    black = [0] * (N+2)
    for i in range(1,N+1):
        if S[i-1] == '.':
            white[i] = white[i-1] + 1
            black[i] = black[i-1]
        else:
            black[i] = black[i-1] + 1
            white[i] = white[i-1]
    
    ans = float('inf')
    for i in range(N+1):
        tmp = black[i] + white[-2] - white[i]
        ans = min(ans, tmp)
    
    print(ans)
    
if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter

N = int(input())
S = input()
counter_s = Counter(S)
min_stone = counter_s.most_common()[-1][1]
if min_stone == N:
    min_stone = 0
A, B = 0, counter_s['.']
for s in S:
    if s == '
        A += 1
    else:
        B -= 1
    if min_stone > A+B:
        min_stone = A+B
print(min_stone)

Solution (Python):
import itertools

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

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

black = list(itertools.accumulate(black))
white = list(itertools.accumulate(white))

ans = N
num_W = white[-1]
for b, w in zip(black, white):
  ans = min(ans, b + (num_W-w))

print(ans)

Solution (Python):
n=int(input());s=input()
b=0
w=s.count('.')
ans=w
for si in s:
  b+=(si=='
  w-=(si=='.')
  ans=min(ans,b+w)
print(ans)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
s = readline().rstrip().decode('utf-8')
res = s.count(".")
ans = res
for i in range(n):
    if s[i] == "
        res += 1
    else:
        res -= 1
    ans = min(ans,res)

print(ans)

Solution (Python):
N=int(input())
S=input()
leftid=-1
rightid=-1
blcnt=0
whcnt=0
cnt=0
ans=float("inf")




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

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

leftblack.insert(0,0)
rightwhite.insert(N,0)


for i in range(N+1):
    ans=min(ans,leftblack[i]+rightwhite[i])
print(ans)

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

for s in S:
    if s == '.':
        A.append(A[-1] + 1)
    else:
        A.append(A[-1])
ans = float('inf')
for i in range(N + 1):
    ansi = (i - A[i]) + (A[-1] - A[i])
    ans = min(ans, ansi)
print(ans)

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

Solution (Python):
n = int(input())
s = input()
white = s.count(".")
black = s.count("

min_num = min(black, white)
black_num = 0
for i, color in enumerate(s, start = 1):
    if color == "
        black_num += 1
    min_num = min(min_num, black_num + white - (i - black_num))
    
print(min_num)

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

numb=[0]
numw=[0]
cond="b"
for i in range(N):
    numb.append(numb[-1])
    numw.append(numw[-1])
    if S[i]=="
        numb[-1]+=1
    else:
        numw[-1]+=1

ans=[0 for _ in range(N+1)]
for j in range(N+1):
    ans[j]=numb[j]+(numw[-1]-numw[j])
print(min(ans))

Solution (Python):
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    s = input()
    a, b = [0], [0]
    for i in range(N):
        if s[i] == '
        else: a.append(a[-1])

        if s[-1-i] == '.': b.append(b[-1]+1)
        else: b.append(b[-1])
    b = b[::-1]
    output =  10 ** 6
    for x, y in zip(a, b): output = min(output, x + y)
    print(output)

    return

if __name__ == '__main__':
    main()

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

    
    
     

    baseblack = 0
    basewhite = sum([1 for x in S if x == '.'])
    ans = min(basewhite, N-basewhite)
    for i in range(N):
        baseblack += S[i] == '
        basewhite -= S[i] == '.'
        ans = min(ans, baseblack+basewhite)

    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):
import sys


import math
import collections

import bisect

import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()

    white, black = 0, 1
    s = [int(i) for i in list(input().replace(".", "0").replace("
    s.insert(0, 0)
    black_total = s.count(1)

    cnt = [0, 0]  
    ans = INF
    for i in range(n, -1, -1):
        ans = min(ans, black_total - cnt[black] + cnt[white])
        cnt[s[i]] += 1

    print(ans)


if __name__ == '__main__':
    main()

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

cnt = [s.count('.'), s.count('

cnt0 = 0
cnt1 = 0
ans = float("inf")
for i in range(n):
    if s[i] == '.':
        cnt0 += 1
    if s[i] == '
        cnt1 += 1
    ans = min(ans, cnt1 + cnt[0] - cnt0)

if ans > min(cnt):
    print(min(cnt))
else:
    print(ans)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))

def main():
    n = II()
    s = IS()
    cnt_b = 0
    cnt_w = s.count('.')
    cnt = cnt_w
    for si in s:
        if si == '
            cnt_b += 1
        else:
            cnt_w -= 1
        c = cnt_b+cnt_w
        if c < cnt:
            cnt = c
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))

def main():
    n = II()
    s = IS()
    cnt_b = 0
    cnt_w = s.count('.')
    cnt = cnt_w
    for i in range(n):
        if s[i] == '
            cnt_b += 1
        else:
            cnt_w -= 1
        cnt = min(cnt, cnt_b+cnt_w)
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))

def main():
    n = II()
    s = IS()
    cnt_b = 0
    cnt_w = s.count('.')
    cnt = cnt_w
    for si in s:
        if si == '
            cnt_b += 1
        else:
            cnt_w -= 1
        cnt = min(cnt, cnt_b+cnt_w)
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
s=list(ss())

mat=Counter(s)
black=mat["
white=n-black

ans=white

if black==0 or white==0:
    print(0)
    exit()


tmptowhite=0
tmptoblack=white
for i in range(n):
    if s[i]=="
        tmptowhite+=1

    else:

        tmptoblack-=1
    
    ans=min(tmptowhite+tmptoblack,ans)

    
print(ans)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
S = str(input())

dp = [0]*(N+1)
temp = 0
for i in range(N):
    if S[i] == '.':
        temp += 1

dp[0] = temp

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

print(min(dp))

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

    
    wt = [0]
    bk = [0]
    for s in S:
        w, b = wt[-1], bk[-1]
        if s == '.': w += 1
        else: b += 1
        wt.append(w)
        bk.append(b)

    
    ans = 10**9
    for i in range(N+1):
        flip = bk[i] + wt[-1] - wt[i]
        ans = min(flip, ans)
    print(ans)

tenka1bc19_c()

Solution (Python):
n=int(input())
s=list(input())
w=s.count('.')
if s[0]=='.':
    sm=1
else:
    sm=0

def change(y):
    total=(y+1-sm)+(w-sm)
    return total
mn=change(0)
for i in range(1,n):
    if s[i]=='.':
        sm += 1
    mn=min(mn,change(i))
mn=min(mn,w)
print(mn)

Solution (Python):
n = int(input())
s = input()
b_total = 0
w_total = 0
ans = 0
for i in range(n):
  if s[i] == '
    b_total += 1
  if s[i] == '.':
    w_total += 1
if b_total == n:
  print(0)
else:
  b_cnt = 0
  w_cnt = 0
  ans = b_cnt + (w_total - w_cnt)
  for i in range(n):
    if s[i] == '
      b_cnt += 1
    if s[i] == '.':
      w_cnt += 1
    cnt = b_cnt + (w_total - w_cnt)
    ans = min(ans, cnt)
  print(ans)

Solution (Python):




import math
import sys
import bisect
import heapq  
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

n = int(input())
s = input()
siro = [0 for i in range(n+1)]
kuro = [0 for j in range(n+1)]
for i,c in enumerate(s):
    siro[i+1] = siro[i]
    kuro[i+1] = kuro[i]
    if c == '
        kuro[i+1]+=1
    else:
        siro[i+1]+=1
def getSiro(l,r):
    return siro[r]-siro[l]

def getKuro(l,r):
    return kuro[r]-kuro[l]

ans = inf
for i in range(n+1):
    ans = min(ans, getKuro(0,i)+getSiro(i,n))
print(ans)

Solution (Python):
n = int(input())
s = input()
ss = list(s)[::-1]

white = 0
black = 0
w = [0] * n
b = [0] * n

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

ans = 10**9

for i in range(n):
    if b[i] + w[i] < ans:
        ans = b[i] + w[i]

print(ans-1)

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

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

ans = 1e+9
for i in range(n):
  ans = min(ans, l[i] + r[i])
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N = int(input())
    S = list(input())
    bl = [0]*N
    wh = [0]*N

    from itertools import accumulate

    wh_num = 0
    for i in range(N):
        if S[i] == '
            bl[i] = 1
        else:
            wh[i] = 1

    bl = [0] + bl
    wh = [0]+wh

    
    bl = list(accumulate(bl))
    wh = list(accumulate(wh))

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


resolve()

Solution (Python):
from itertools import*;input();s=input();print(min(map(sum,zip(*[list(accumulate([0]+list(map(int,s.translate(str.maketrans("

Solution (Python):
from itertools import*
n = int(input())
s = input()
b, w = [list(accumulate([0] + list(map(int, s.translate(str.maketrans("
m = float("inf")
for i in range(-~n):
    m = min(m, b[i] + w[i])
print(m)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    B = S.count("
    W = S.count(".")

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

    
    ans = min(B, W)
    for i in range(N):
        
        cnt = i + 1 - n_white[i]

        
        cnt += n_white[-1] - n_white[i]

        if cnt < ans:
            ans = cnt

    print(ans)


if __name__ == "__main__":
    main()

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

b_from_l = [0 for _ in range(N)]
w_from_r = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        if S[i] == '
            b_from_l[i] = 1
    else:
        if S[i] == '
            b_from_l[i] = b_from_l[i - 1] + 1
        else:
            b_from_l[i] = b_from_l[i - 1]

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

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

Solution (Python):
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
from collections import Counter, deque, defaultdict

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

mi = 10000000

c = Counter(S)
A = N - c["
B = N - c["."]

l = 0
r = c["."]

for i in range(0, N):

    if S[i] == "
        l += 1
    else:
        r -= 1
    a = l + r
    if mi > a:
        mi = a

print(min(mi, A, B))

Solution (Python):
import collections

N = int(input().split()[0])
S = input()

index2count_dict = collections.defaultdict(int)
left_black_count = 0
for i, char in enumerate(S):
    index2count_dict[i] = left_black_count
    if char == "
        left_black_count += 1

right_white_count = 0
min_count = float("inf")
for i in range(N):
    index = N - (i + 1)
    count = index2count_dict[index] + right_white_count
    min_count = min(min_count, count)
    if S[index] == ".":
        right_white_count += 1

ans = min_count
print(ans)

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

cntW = 0
for s in S:
    if s == '.':
        cntW += 1

cntB = 0
MIN = 10 ** 5
for i in range(N+1):
    MIN = min(cntW+cntB,MIN)
    if i < N:
        if S[i] == '
            cntB += 1
        else:
            cntW -= 1

print(MIN)

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

ll=0 
rr=s.count(".") 

result=ll+rr
for item in s:
    if item=="
        ll+=1
    else:
        rr-=1
    
    result=min(result,ll+rr)

print(result)

Solution (Python):
n = int(input())
s = input()
migi = s.count(".")
hidari = 0
ans = migi
for i in range(n):
    if s[i] == "
        hidari += 1
    elif s[i] == ".":
        migi -= 1
    ans = min(ans,hidari+migi)
print(ans)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
s = ns()

b, w = 0, 0
cub = [0] * (n + 1)
cuw = [0] * (n + 1)
for i in range(1, n + 1):
    cub[i] = cub[i - 1]
    cuw[i] = cuw[i - 1]
    cub[i] += s[i - 1] == '
    cuw[i] += s[i - 1] == '.'

ans = inf
for i in range(n + 1):
    ans = min(cub[i] + cuw[n] - cuw[i], ans)

print(ans)

Solution (Python):
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    c = collections.Counter(S)
    c2 = collections.Counter()
    ans = min(c['.'], c['

    for i in range(N):
        c2[S[i]] += 1
        ans = min(ans, c2['

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=input()
countwhite=[0]*(n+1)
for i in range(n):
    if s[i]==".":
        countwhite[i+1]=countwhite[i]+1
    else:
        countwhite[i+1]=countwhite[i]
ans=10**8
for i in range(n+1):
    change=i-countwhite[i]+(countwhite[-1]-countwhite[i])
    ans=min(ans,change)
print(ans)

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

rightWhite = []
leftBlack = []

cntB = 0
cntW = 0

for i in range(N):
    rightWhite.append(cntW)
    leftBlack.append(cntB)
    if (S[i] == "
        cntB += 1

    if (S[-i-1] == "."):
        cntW += 1

rightWhite = list(reversed(rightWhite))

ans = N

for i in range(N):
    ans = min(rightWhite[i] + leftBlack[i], ans)

print(ans)

Solution (Python):
n=int(input())
s=input()
w=[0]*(n+1)
b=[0]*(n+1)
for i in range(1,n+1):
  w[i]=w[i-1]+1 if s[i-1]=="
  b[-i-1]=b[-i]+1 if s[-i]=="." else b[-i]
print(min([x+y for x,y in zip(w,b)]))

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

B_sum = [0]*(N+1)
for i in range(N):
  if S[i] == "
    B_sum[i+1] = B_sum[i] + 1
  else:
    B_sum[i+1] = B_sum[i]

ans = float("INF")
for i in range(N+1):
  b_cnt = B_sum[i]
  w_cnt = N - i - (B_sum[N] - B_sum[i])
  tmp = b_cnt + w_cnt
  ans = min(ans, tmp)
  
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    S=input()
    C=[[0,0] for _ in range(n)] 
    cunt=0
    for i,s in enumerate(S):
        if s=='
            cunt+=1
        C[i][0]=cunt
    cunt=0
    for i in range(n-1,-1,-1):
        if S[i]=='.':
            cunt+=1
        C[i][1]=cunt  
    ans=C[0][1]
    for i in range(n-1):
        ans=min(ans,C[i][0]+C[i+1][1])
    ans=min(ans,C[n-1][0])
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    S=input()
    C=[[0,0] for _ in range(n)] 
    cunt=0
    for i,s in enumerate(S):
        if s=='
            cunt+=1
        C[i][0]=cunt
    cunt=0
    for i in range(n-1,-1,-1):
        if S[i]=='.':
            cunt+=1
        C[i][1]=cunt  
    ans=C[0][1]
    for i in range(n-1):
        ans=min(ans,C[i][0]+C[i+1][1])
    ans=min(ans,C[n-1][0])
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
import sys

input = sys.stdin.readline


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

    l_black = 0
    r_white = S.count(".")
    ans = r_white
    for i in range(N):
        if S[i] == "
            l_black += 1
        else:
            r_white -= 1
        count = l_black + r_white
        if count < ans:
            ans = count

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


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

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

sumBlack = [0]*(n+1)
sumWhite = [0]*(n+1)
for i in range(1,n+1):
    sumBlack[i] = sumBlack[i-1]
    if s[i-1] == '
        sumBlack[i] += 1

for i in range(n-1,-1,-1):
    sumWhite[i] = sumWhite[i+1]
    if s[i] == '.':
        sumWhite[i] += 1

ans = 12345678901234
for i in range(n+1):
    ans = min(ans,sumBlack[i]+sumWhite[i])
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
import sys
sys.setrecursionlimit(10**7)
def main():
  n=int(input())
  s=input()
  sw,sb=[0],[0]
  w,b=0,0
  for si in s:
    if si=='
      b+=1
    else:
      w+=1
    sw.append(w)
    sb.append(b)
  ans=n
  for i in range(n+1):
    ans=min(ans,sw[n]-sw[i]+sb[i])
  print(ans)
if __name__=='__main__':
  main()

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

print(ans)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    s = list(input())
    all_b = s.count("
    all_w = s.count(".")

    b = [0 for i in range(n)]
    w = [0 for i in range(n)]

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

    ans = min(all_w, all_b)
    for i in range(n):
        ans = min(ans, b[i] + (all_w - w[i]))
    print(ans)

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

s=list(input())

black = [0]*n

white = [0]*n

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

for i in range(n-1):
    if s[i] != s[i+1]:
        ans = min(ans,black[i]+(white[-1]-white[i+1]))
        
ans = min(ans,max(black),max(white))
print(ans)

Solution (Python):

n = int(input())
s = input()

if len(set(s)) == 1:
    print(0)
    exit()









black_left = 0
white_right = s.count(".")
ans = white_right


for ch in s:
    if ch == '
        black_left += 1
    else:
        white_right -= 1
    ans = min(ans, black_left + white_right)
    


print(ans)

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

l = [[0, 0] for i in range(n + 1)]
for i in range(n):
    preB, preW = l[i]
    if s[i] == '
        l[i + 1] = [preB + 1, preW]
    else:
        l[i + 1] = [preB, preW + 1]

SUM_W = l[-1][1]
ans = 10 ** 10
for i, j in l:
    temp = i + SUM_W - j
    if temp < ans:ans = temp
print(ans)