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



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
num=[]
str1="#"
num3=0
num2=0
if s[0]==".":
    num2=n
    for i in range(n):
        if s[i]==str1:
            num2=i
            break
for i in range(num2,n):
    if s[i]==str1:
        num3+=1
    else:
        if str1=="#":
            str1="."
        else:
            str1="#"
        num.append(num3)
        num3=1
num.append(num3)
if len(num)<2:
    print(0)
else:
    numb=0
    numw=0
    for i in range(len(num)):
        if i%2==0:
            numb+=num[i]
        else:
            numw+=num[i]
    print(min(numb,numw))

Submission status: Wrong Answer

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

b = 0
w = 0
stones = []
for i in S:
    if i == "#":
        b += 1
    else:
        w += 1
    stones.append((b,w))

bb = S.count("#")
if bb == N:
    print(0)
    exit()
ww = S.count(".")

ans = 1e9

for b,w in stones:
    ans = min(ans,b+ww-w)

print(ans)

Submission status: Wrong Answer

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

b = 0
w = 0
stones = []
for i in S:
    if i == "#":
        b += 1
    else:
        w += 1
    stones.append((b,w))

bb = S.count("#")
ww = N-bb

ans = 1e9

for b,w in stones:
    ans = min(ans,b+ww-w)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def main():
    n = int(input().strip())
    S = input().strip()
    query_table = [0] * (n+1)
    for i, s in enumerate(S):
        if s == "#":
            query_table[i + 1] = query_table[i] + 1
        else:
            query_table[i + 1] = query_table[i]
    ans = float("inf")
    print(query_table)

    for ptr in range(n+1):
        # left side
        left_black = query_table[ptr]
        left_white = ptr - left_black

        # right side
        right_black = query_table[n] - left_black
        right_white = n - ptr - right_black
        ans = min(ans, left_black+right_white)

    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n-1):
    if s[i] == "#" and s[i+1] == ".":
        ans += 1
print(ans)

Submission status: Wrong Answer

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

# '#': black, '.': white

prev = None
current = None

fix_place = []

for index, current in enumerate(S):
  if prev == '#' and current == '.': # left: black, current: white
    fix_place.append(index)
  prev = current
    
print(len(fix_place))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = list(input())
    if '#' not in s or '.' not in s:
        print(0)
        return 0
    ans = sorted(s, reverse=True).index('#')
    cnt = 0
    for i in range(ans+1):
        if s[i] == '#':
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = list(input())
    ans = sorted(s, reverse=True)
    if '#' not in ans:
        print(0)
        return 0
    lst = ans.index('#')
    cnt = 0
    for i in range(lst+1):
        if s[i] == '#':
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 10**9

T = "#."
W = '.'
B = '#'

dp_blk = [0]*(N+1)
dp_wht = [0]*(N+1)

if all([B==c for c in S]) or all([W==c for c in S]):
    print(0)
    exit(0)

for ix in range(N):
    if S[ix] == B:
        dp_blk[ix+1] += dp_blk[ix] + 1
        dp_wht[ix+1] += dp_wht[ix]
    else:
        dp_wht[ix+1] += dp_wht[ix] + 1
        dp_blk[ix+1] = dp_blk[ix]

# print("dp_blk", dp_blk)
# print("dp_wht", dp_wht)

for lix in range(N):
    b_flip = dp_blk[lix]
    w_flip = dp_wht[N] - dp_wht[lix]
    flip = b_flip + w_flip
    # print(lix, flip)
    if ans > flip:
        ans = flip

# ab = N - dp_blk[N]
# aw = N - dp_wht[N]
# ans = min(ab, aw, ans)
    
print(ans)

Submission status: Wrong Answer

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

ans = 10**9

T = "#."
W = '.'
B = '#'

dp_blk = [0]*(N+1)
dp_wht = [0]*(N+1)

if all([B==c for c in S]) or all([W==c for c in S]):
    print(0)
    exit(0)

for ix in range(N):
    if S[ix] == B:
        dp_blk[ix+1] += dp_blk[ix] + 1
        dp_wht[ix+1] += dp_wht[ix]
    else:
        dp_wht[ix+1] += dp_wht[ix] + 1
        dp_blk[ix+1] = dp_blk[ix]

# print("dp_blk", dp_blk)
# print("dp_wht", dp_wht)

for lix in range(N):
    b_flip = dp_blk[lix+1]
    w_flip = dp_wht[N] - dp_wht[lix+1]
    flip = b_flip + w_flip
    # print(lix, flip)
    if ans > flip:
        ans = flip

# ab = N - dp_blk[N]
# aw = N - dp_wht[N]
# ans = min(ab, aw, ans)
    
print(ans)

Submission status: Wrong Answer

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

ans = 10**9

T = "#."
W = '.'
B = '#'

dp_blk = [0]*(N+1)
dp_wht = [0]*(N+1)

for ix in range(N):
    if S[ix] == B:
        dp_blk[ix+1] += dp_blk[ix] + 1
        dp_wht[ix+1] += dp_wht[ix]
    else:
        dp_wht[ix+1] += dp_wht[ix] + 1
        dp_blk[ix+1] = dp_blk[ix]

# print("dp_blk", dp_blk)
# print("dp_wht", dp_wht)

for lix in range(N):
    b_flip = dp_blk[lix+1]
    w_flip = dp_wht[N] - dp_wht[lix+1]
    flip = b_flip + w_flip
    # print(lix, flip)
    if ans > flip:
        ans = flip

# ab = N - dp_blk[N]
# aw = N - dp_wht[N]
# ans = min(ab, aw, ans)
    
print(ans)

Submission status: Wrong Answer

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

ans = 10**9

T = "#."
W = '.'
B = '#'

for _ in range(2):
    cnt = 0
    SS = S.copy()
    if _ & 1:
        for ix in range(0, N-1):
            if SS[ix] == B and SS[ix+1] == W:
                SS[ix+1] = B
                cnt += 1
    else:
        for ix in range(N-1, 0, -1):
            if SS[ix] == W and SS[ix-1] == B:
                SS[ix-1] = W
                cnt += 1

    if cnt < ans:
        ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
22min 30sec WA
"""

def main():
    N = int(input())
    S = input()
    S += "#"

    answer = 0
    hash_counter = 0
    dot_counter = 0
    for i in range(N+1):
        if S[i] == "#":
            if dot_counter >= 1:
                answer += min(hash_counter, dot_counter)
                hash_counter = 1
                dot_counter = 0
            else:
                hash_counter += 1
        elif hash_counter >= 1:
            dot_counter += 1
    print(answer)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""

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

    hash_r = 0
    while S[hash_r] != "#" and hash_r <= N-2:
        hash_r += 1

    dot_l = len(S)-1
    while S[dot_l] != "." and dot_l >= 1:
        dot_l -= 1

    print(
        min(
            S[hash_r+1:].count("."),
            S[:dot_l].count("#")
        )
    )

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cnt_w, cnt_b = s.count("."), 0
ans = 10 ** 6
if s.count(".") == n or s.count("#") == n:
    ans = 0
else:
    for i in range(n):
        if s[i] == "#":
            cnt_b += 1
        else:
            cnt_w -= 1
        if i != n - 1 and s[i] != s[i + 1]:
            ans = min(ans, cnt_w + cnt_b)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cnt_w, cnt_b = s.count("."), 0
ans = 10 ** 6
for i in range(n):
    if s[i] == "#":
        cnt_b += 1
    else:
        cnt_w -= 1
    if i == n - 1 or s[i] != s[i + 1]:
        ans = min(ans, cnt_w + cnt_b)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cnt_w, cnt_b = s.count("."), 0
ans = 10 ** 6
for i in range(n):
    if s[i] == "#":
        cnt_b += 1
    else:
        cnt_w -= 1
    if i != n - 1 and s[i] != s[i + 1]:
        ans = min(ans, cnt_w + cnt_b)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cnt_w, cnt_b = 0, 0
for i in range(n):
    if s[i] == "#":
        for j in range(i, n):
            if s[j] == ".":
                cnt_w += 1
        break
for i in range(n - 1, -1, -1):
    if s[i] == ".":
        for j in range(i, -1, -1):
            if s[j] == "#":
                cnt_b += 1
        
        break
print(min(cnt_w, cnt_b))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()
    flg = False
    w = [0] * n
    cnt = 0
    for i in range(n):
        if not flg:
            if s[i] == "#":
                flg = True
        if flg:
            if s[i] == ".":
                cnt += 1
            w[i] = cnt
    flg = False
    b = [0] * n
    cnt = 0
    for i in reversed(range(n)):
        if not flg:
            if s[i] == ".":
                flg = True
        if flg:
            if s[i] == "#":
                cnt += 1
            b[i] = cnt

    res = f_inf
    for i, j in zip(w, b):
        res = min(res, i + j)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()
    flg = False
    w = 0
    for i in range(n):
        if not flg:
            if s[i] == "#":
                flg = True
        if flg:
            if s[i] == ".":
                w += 1
    flg = False
    b = 0
    for i in reversed(range(n)):
        if not flg:
            if s[i] == ".":
                flg = True
        if flg:
            if s[i] == "#":
                b += 1
    print(min(w, b))


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
n = S.count('.')
ans = min(n, N-n)
lsc = 0
rsc = N-n
for i, c in enumerate(S):
    if c == '#':
        lsc += 1
        rsc -= 1
    a = lsc + ((N-i) - rsc)
    ans = min(ans, a)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input())
b=a.count('#')
c=a.count('.')
print(min(b,c))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input())
c=0
import sys
b=0
for i in range(n):
    if a[i]=='#':
        b=1
    elif b==1 and a[i]==".":
        c+=1

print(c)

Submission status: Wrong Answer

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

c1=0
c2=0
f1=-1
f2=-1
for i in range(n):
  
  if f1==-1 and s[-i-1]==".":f1=1
  if f1==1 and s[-i-1]=="#":c1+=1 
 
  if f2==-1 and s[i]=="#":f2=1
  if f2==1 and s[i]==".":c2+=1

print(min(c1,c2))

Submission status: Wrong Answer

Solution code:
n = int(input())
stones = input()
white = stones.count('.')
black = 0
ans = float('inf')
for c in stones:
    if c == '#':
        black += 1
    else:
        white -= 1
    score = black + white
    ans = min(score, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
stones = input()
b = 0 
w = 0
prev = False
ans = 0
for c in stones:
    if c == '#':
        if prev is True:
            ans += min(b, w)
            b = 0
            w = 0
        b += 1
        prev = False
    else:
        w += 1
        prev = True
ans += min(b, w)
print(ans)

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
stones = input()
s_w = re.findall('#{1,}\.{1,}', stones)
ans = 0
for match in s_w:
    ans += min(match.count('#'), match.count('.'))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input() + '#'

idx = s.index('#')

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

res1 = cnt
res2 = s.count('.')
res3 = s[:n].count('#')

print(min(res1, res2, res3))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
flag = False
ans1 = 0
for s in S:
    if s=='#':
        flag = True
    elif flag:
        ans1 += 1
flag = False
ans2 = 0
for s in S[::-1]:
    if s=='.':
        flag = True
    elif flag:
        ans2 += 1
print(min(ans1, ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
from itertools import groupby
from collections import deque
s=list(input())
gr=groupby(s)
#flg=0:白の状態
flg=0
black=[]
white=[]
for k,v in gr:
    if flg==0 and k=='#':
        flg=1
        black.append(len(list(v)))
    elif flg==1:
        if k=='#':
            black.append(len(list(v)))
        else:
            white.append(len(list(v)))
if len(black)==0 or len(white)==0:
    print(0)
    exit(0)


cnt=sum(white)
white=deque(white)
black=deque(black)
ans=[]
for i in range(len(white)):
    cnt+=(black[i]-white[i])
    ans.append(cnt)

print(min(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
from itertools import groupby

s=list(input())

gr=groupby(s)

#flg=0:白の状態
cnt=0
flg=0
bflg=0
for k,v in gr:
    if flg==0:
        if k=='#':
            flg=1
            b=len(list(v))
    else:
        if k=='.':
            w=len(list(v))
            if bflg==0:
                if b>=w:
                    cnt+=w
                    bflg=1
                else:
                    cnt+=b
            else:
                cnt+=w
                bflg=0

            flg=0

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
from itertools import groupby

s=list(input())

gr=groupby(s)

#flg=0:白の状態
cnt=0
flg=0
prev=0
for k,v in gr:
    if flg==0:
        if k=='#':
            flg=1
            b=len(list(v))
    else:
        if k=='.':
            w=len(list(v))
            if b>=w:
                cnt+=w
            else:
                cnt+=b
            flg=0

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
"""
count_1 = 0
for i in range(n-1):
    if s[i] == "#" and s[i+1] == ".":
        count_1 += 1
count_2 = 0
for i in reversed(range(n-1)):
    if s[i] == "#" and s[i+1] == ".":
        count_2 += 1
print(min(count_1,count_2))
"""
print(min(s.count("#"),s.count(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count_1 = 0
for i in range(n-1):
    if s[i] == "#" and s[i+1] == ".":
        count_1 += 1
count_2 = 0
for i in reversed(range(n-1)):
    if s[i] == "#" and s[i+1] == ".":
        count_2 += 1
print(min(count_1,count_2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count = 0
for i in range(n-1):
    if s[i] == "#" and s[i+1] == ".":
        count += 1
        s[i+1] = "."
print(count)

Submission status: Wrong Answer

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

cntB = S.count("#")

i = 0
if cntB != 0:
    i = S.index("#")

print(min(cntB, N - i - cntB))

Submission status: Wrong Answer

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

from itertools import groupby
L = []
for k,v in groupby(s):
    L.append(list(v))
#print(L)
cnt = 0
for i in range(len(L)-1):
    if L[i][0] == "#" and L[i+1][0] == ".":
        cnt += min( len(L[i]),len(L[i+1]) )
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count_W=0
count_B=0
W=0
B=0
tmp=0
L=[[0 for i in range(2)] for j in range(N+1)]
T=[0 for k in range(N+2)]
for i in range(1,N+1):
	if S[i-1]=="#":
		L[i][1]=L[i-1][1]+1
		L[i][0]=L[i-1][0]
	if S[i-1]==".":
		L[i][0]=L[i-1][0]+1
		L[i][1]=L[i-1][1]
for i in range(1,N+2):
	if i==N+1:
		T[i]=L[N][0]+L[N][1]-L[N-1][1]
	else:
		T[i]=L[i][1]-L[i-1][1]+L[i-1][0]

print(min(T[2:]))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count_W=0
count_B=0
W=0
B=0
tmp=0
for i in range(N):
	if B==1 and S[i]==".":
		count_B+=1
	if B==0 and S[i]=="#":
		B=1
for i in range(N):
	if W==0 and S[-(i+1)]==".":
		W=1
	if W==1 and S[-(i+1)]=="#":
		count_W+=1
print(min(count_B,count_W))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
count_2=0
tmp=0
for i in range(N):
	if tmp==1:
		if S[i]=="#":
			count+=1
	elif S[i]==".":
		tmp=1

tmp=0
for i in range(N):
	if tmp==1:
		if S[i]==".":
			count_2+=1
	elif S[i]=="#":
		tmp=1

print(min(count,count_2))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
count_2=0
tmp=0
for i in range(N):
	if S[i]==".":
		tmp=1
	elif tmp==1:
		if S[i]=="#":
			count+=1
tmp=0
for i in range(N):
	if tmp==1:
		if S[i]==".":
			count_2+=1
	elif S[i]=="#":
		tmp=1

print(min(count,count_2))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
count_2=0
tmp=0
for i in range(N):
	if S[i]=="#":
		count+=1

for i in range(N):
	if tmp==1:
		if S[i]==".":
			count_2+=1
	elif S[i]=="#":
		tmp=1

print(min(count,count_2))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
count_2=0
tmp=0
for i in range(N):
	if tmp==1:
		if S[i]=="#":
			count+=1
	elif S[i]==".":
		tmp=1

tmp=0

for i in range(N):
	if tmp==1:
		if S[i]==".":
			count_2+=1
	elif S[i]=="#":
		tmp=1
print(min(count,count_2))

Submission status: Wrong Answer

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

bc = s[0].count('#')
wc = s.count('.') - (bc^1)
ans = n
for i in range(1,n):
    if s[i] == '.':
        wc -= 1
    if s[i] != s[i-1]:
        ans = min(ans, bc + wc)
    if s[i] == '#':
        bc += 1

if ans == n:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

idx = s.find('#')
if idx < 0:
    print(0)
    exit()
    
ans1 = s[idx+1:].count('.')

s = s[::-1]
idx = s.find('.')
if idx < 0:
    print(0)
    exit()

ans2 = s[idx+1:].count('#')

print(min(ans1, ans2))

Submission status: Wrong Answer

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

idx = s.find('#')
if idx < 0:
    print(0)
    exit()
    
ans1 = s[idx:].count('.')

s = s[::-1]
idx = s.find('.')
if idx < 0:
    print(0)
    exit()

ans2 = s[idx:].count('#')

print(min(ans1, ans2))

Submission status: Wrong Answer

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

# 一回でも黒が出現したら以降は白は置けない
idx = s.find('#')
if idx < 0:
    print(0)
else:
    print(s[idx:].count('.'))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 10**6
b = [0]
w = [0]
for i in range(n):
    b.append(b[i]+(s[i]=="#"))
    w.append(w[i]+(s[i]=="."))
for i in range(n):
    #print(b[i+1],w[-1]-w[i+1])
    ans = min(ans,b[i+1]+w[-1]-w[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    S = list(in_s())

    if S.count('#') == 0:
        print(0)
        exit()

    l = S.index('#')
    ans = S[l:N].count('.')
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
accum=[0]*n
if s[0]=="#":
    accum[0]=1
for i in range(n-1):
    accum[i+1]+=accum[i]+(s[i+1]=="#")
ans=10**18
for i in range(n):
    ans=min(ans,accum[i]+n-i-1-accum[n-1]+accum[i])
#print(accum)
if accum[n-1]==n:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
accum=[0]*n
if s[0]=="#":
    accum[0]=1
for i in range(n-1):
    accum[i+1]+=accum[i]+(s[i+1]=="#")
ans=10**18
for i in range(n):
    ans=min(ans,accum[i]+n-i-1-accum[n-1]+accum[i])
#print(accum)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 0
for i in range(n-1):
    if s[i] == "#" and s[i+1] == ".":
        ans += 1
print(ans)

Submission status: Wrong Answer

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

m =s.find("#")

if m < 0:
  print(0)
else:
  k = s[m:n].count(".")
  l = s[m:n].count("#")
  if k <= l: print(k)
  else: print(l)

Submission status: Wrong Answer

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

m =s.find("#")

if m < 0:
  print(0)
else:
  k = s[m:n].count(".")
  l = s[m-1:n].count("#")
  if k < l: print(k)
  else: print(l)

Submission status: Wrong Answer

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

m =s.find("#")

if m < 0:
  print(0)
else:
  k = s[m:n].count(".")
  l = s[m-1:n].count("#")
  if k <= l: print(k)
  else: print(l)

Submission status: Wrong Answer

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

m =s.find("#")

if m < 0:
  print(0)
else:
  print(s[m:n].count("."))

Submission status: Wrong Answer

Solution code:
n = int(input())
s =input()
b = 0   #
w = 0
for i in s:
    if i == "#":
        b += 1
    else:
        w += 1
print(min(b,w))

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    S = SS()

    # #を.に変える個数は最右.から左の#の個数
    # .を#に変える個数は最左#から右の.の個数
    white = []
    black = []
    for i in range(N):
        if S[i] == '.':
            white.append(i)
        else:
            black.append(i)

    right_w = -1
    if white:
        right_w = white[-1]
    left_b = N
    if black:
        left_b = black[0]
    
    S_part = S[left_b:right_w+1]
    S_part_w = S_part.count('.')

    print(min(S_part_w, right_w - left_b + 1 - S_part_w))

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    S = SS()

    # #を.に変える個数は最右.から左の#の個数
    # .を#に変える個数は最左#から右の.の個数
    white = []
    black = []
    for i in range(N):
        if S[i] == '.':
            white.append(i)
        else:
            black.append(i)

    right_w = -1
    if white:
        right_w = white[-1]
    left_b = N
    if black:
        left_b = black[0]

    ans_w = bisect.bisect_left(black, right_w)
    ans_b = len(white) - bisect.bisect_left(white, left_b)

    print(min(ans_w, ans_b))

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())
s = input()
l = 0
r = 0
ans = 0
f = 1
for i in range(n):
    if i != 0 and s[i - 1] == "." and s[i] == "#":
        ans += min(l,r)
    if s[i] == "#":
        l += 1
        r = 0
    else:
        r += 1
    if i == n - 1 and s[i] == ".":
        ans += min(l, r)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s = input()
l = 0
r = 0
ans = 0
f = 1
for i in range(n):
    if f and s[i] == "#":
        ans += min(l, r)
        l = 1
        r = 0
        f = 0
    elif s[i] == "#":
        l += 1
        r = 0
        f = 0
    elif i == n - 1:
        r += 1
        ans += min(l,r)
    else:
        f = 1
        r += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s = input()
l = 0
r = 0
for i in range(n):
    if s[i] == "#":
        l += 1
    else:
        r += 1
ans = 0
for i in range(n-1):
    if s[i: i + 2] == "#.":
        ans += 1
ans = min(ans,min(l, r))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s = input()
l = 0
r = 0
for i in range(n):
    if s[i] == "#":
        l += 1
    else:
        r += 1
print(min(l,r))

Submission status: Wrong Answer

Solution code:
n=int(input())
s = input()
ans = 0
for i in range(n-1):
    if s[i: i + 2] == "#.":
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    S = SS()

    first_black = N
    if '#' in S:
        first_black = S.index('#')

    white = S[first_black:].count('.')
    black = S.count('#')

    print(min(white, black))

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
left = [0] * N
if S[0] == '#':
    left[0] += 1
for i in range(1,N):
    left[i] = left[i-1]
    if S[i] == '#':
        left[i] += 1
if left[-1] == 0:
    print(0)
    exit()

right = [0] * N
if S[-1] == '.':
    right[-1] += 1
for i in reversed(range(N-1)):
    right[i] = right[i+1]
    if S[i] == '.':
        right[i] += 1
if right[0] == 0:
    print(0)
    exit()
ans = 1000000007
for i in range(N):
    if S[i] == '#':
        ans = min(ans,left[i]-1 + right[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
left = [0] * N
if S[0] == '#':
    left[0] += 1
for i in range(1,N):
    left[i] = left[i-1]
    if S[i] == '#':
        left[i] += 1
if left[-1] == 0:
    print(0)
    exit()

right = [0] * N
if S[-1] == '.':
    right[-1] += 1
for i in reversed(range(N-1)):
    right[i] = right[i+1]
    if S[i] == '.':
        right[i] += 1
ans = 1000000007
for i in range(N):
    if S[i] == '#':
        ans = min(ans,left[i]-1 + right[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
S = s[::-1]

cnt1 =0
for i in range(n-1):
    if s[i] == "#" and s[i+1] == ".":
        cnt1 +=1
        s[i+1] = "#"
cnt2 = 0

for i in range(n-1):
    if S[i] == "." and S[i-1] == "#":
        cnt2  +=1
        S[i+1] = "."
        #print(s)
print(min(cnt1,cnt2))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w=s.count(".")
b=s.count("#")
w_r=0
b_l=n-1
for i in range(n):
    if s[i]==".": w_r=i
    if s[n-i-1]=="#": b_l=n-i-1
ba=s[0:w_r].count("#")
wa=s[b_l:n].count(".")
print(min(ba,wa,b,w))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w=s.count(".")
b=s.count("#")
w_r=0
b_l=n-1
for i in range(n):
    if s[i]==".": w_r=i
    if s[n-i-1]=="#": b_l=i
ba=s[0:w_r].count("#")
wa=s[b_l:n].count(".")
print(min(ba,wa,b,w))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w=s.count(".")
b=s.count("#")
ans=0
for i,val in enumerate(s):
    if i<=w-1 and val=="#": ans+=1
    if i>=w and val==".": ans+=1
print(min(ans,b,w))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans,temp=0,0
for i,val in enumerate(s):
    if val==".":
        ans+=(i-temp)
        temp+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()

rw = S.count('.')
rb = S.count('#')
lw = 0
lb = 0

ans = n
for s in S:
    if s == '.':
        lw += 1
        rw -= 1
    else:
        lb += 1
        rb -= 1
    ans = min(ans, lb+rw)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
cwr = -1
cbren = 0
cb = 0
for s in S:
    if cwr == -1 and s == '#':
        cwr = 0
        cbren += 1
    elif cwr >= 0 and s == '.':
        cwr += 1
        cb += cbren
        cbren = 0
    elif cwr >= 0 and s == '#':
        cbren += 1

print(min(cb, max(0, cwr)))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
cwr = -1
cb = 0
for s in S:
    if cwr == -1 and s == '#':
        cwr = 0
        cb += 1
    elif cwr >= 0 and s == '.':
        cwr += 1
    elif cwr >= 0 and s == '#':
        cb += 1

print(min(cb, max(0, cwr)))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
c = -1
for s in S:
    if c == -1 and s == '#':
        c = 0
    elif c >= 0 and s == '.':
        c += 1
print(c if c>=0 else 0)