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 = input()
"""
a = s.find("#")
anum = s.count("#")
b = s.find(".")
bnum = n - anum


if a == -1 or b == -1:
    print(0)
elif "." in s[b+1:] and "#" in s[b+1:]:
    print(min(s[a:].count("."),s[:b+1].count("#"),anum,bnum))
else:
    print(min(s[a:].count("."),anum,bnum))
    #一番左の"#"から数えていくつ "." があるか
    #一番左の"."から数えていくつ"#"があるか
"""
moto = "0b"
wb = "0b"
ww = "0b"+"0"*n
bb = "0b"+"1"*n
checker = 0
for i in range(n):
    if s[i] == "#":
        moto += "1"
        checker = 1
    else:
        moto += "0"

    if checker == 1:
        wb += "1"
    else:
        wb += "0"

#print(min(str(int(moto,0) ^ int(wb,0)).count("1"),str(int(moto,0) ^ int(ww,0)).count("1"),str(int(moto,0) ^ int(bb,0)).count("1")))
print(min(str(bin(int(moto,0) ^ int(wb,0))).count("1"),str(bin(int(moto,0) ^ int(ww,0))).count("1"),str(bin(int(moto,0) ^ int(bb,0))).count("1")))

Submission status: Wrong Answer

Solution code:
#C - Stones
n = int(input())
s = list(input())
isFound = False
cnt = 0
right = 0
#一番右の白を見つける
for i in range(n):
    if s[i] == '.':
        right = max(right, i)
print(right)
#rightまでの黒を数える
for i in range(right+1):
    if s[i] == '#':
        cnt += 1
print(cnt)
print(min(s.count('.'), s.count('#'), cnt))

Submission status: Wrong Answer

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

s = list(s)

count = 0

for i in range(n-1):
    if s[i] != s[i+1]:
        s[i+1] = s[i]
        count += 1
        
if s[0] == '.':
    count -=1

print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
	n = int(input())
	s = input()
	ans = 0
	ans = change(n, s, ans)
	print(ans)

def change(n, s, count):

	tmp = list(s)
	for i in range(n-1):
		if s[i] == '#' and s[i+1] == '.':
			tmp[i] = '.'
			count += 1
	"".join(tmp)
	if tmp != s:
		change(n, tmp, count)

	return count

if __name__ == '__main__':
	import sys
	sys.exit(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
b_start = N
w_goal = -1
for i in range(N):
    if S[i]=='#':
        b_start=i
        break
for i in range(N-1,-1,-1):
    if S[i]=='.':
        w_goal = i
        break
if b_start>w_goal:
    print(0)
else:
    S = S[b_start:w_goal+1]
    left = S[:0].count('#')
    right = S[0:].count('.')
    cou = 10**10
    for i in range(1,len(S)+1):
        if S[i-1]=='#':
            left+=1
        else:
            right-=1
        cou = min(cou,left+right)
    print(cou)

Submission status: Wrong Answer

Solution code:
N = int(input())
stone_list = list(input())
stone_list.append('end')
if stone_list[0] == '#':
    stone_list.insert(0,'.')

normalized_list = []
count = 0
stone = stone_list[0]
for s in stone_list:
    if s == stone:
        count += 1
    else:
        normalized_list.append(count)
        count = 1
        stone = s
    

total_a = 0
for i in range(1,len(normalized_list),2):
    total_a += normalized_list[i]

total_b = 0
for i in range(2,len(normalized_list),2):
    total_b += normalized_list[i]

print(min(total_a,total_b))

Submission status: Wrong Answer

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


def main(s):
    if s.count("#") == 0 or s.count(".") == 0:
        print(0)
        return

    strip_left = s.find("#")
    s = s[strip_left:]

    strip_right = s[::-1].find(".")
    if strip_right != 0:
        s = s[:-strip_right]
    
    n = len(s)
    n_white = s.count(".")

    ans = 0
    for i, l in enumerate(s):
        if i <= n_white-1:
            if l == "#":
                ans += 1
        else:
            if l == ".":
                ans += 1

    print(min(ans, n_white, n-n_white))
    return
#%%
main(s)



#%%


#%%


#%%

Submission status: Wrong Answer

Solution code:
import numpy

n = int(input())
char = input()

char_list = numpy.array(list(char),dtype=str)

write = sum(char_list == ".")
black = sum(char_list == "#")
back_black = 0
for i in reversed(char_list):
    if i == "#": 
        back_black += 1
    else:
        break

if char_list[-1] == "#":
    if write <= black - back_black:
        print(write)
    else:
        print(black -back_black)
else:
    if write <= black:
        print(write)
    else:
        print(black)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if len(set(S)) == 1:
    print(0)
    exit()

c1 = S.count('#.')
c2 = S.count('.#')
print(min(c1, c2))

Submission status: Wrong Answer

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

def inverse(b, w, index, first):
    # offset = 0
    # if first == '*':
    #     offset = 1
    
    count = b[index//2] + w[-1] - w[index//2]

    return count

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

b = [0]
w = [0]
offset = 0
bsum = 0
wsum = 0
if first == '*':
    offset = 1
for i in range(len(num)):
    if i % 2 == offset:
        bsum += num[i]
        b.append(bsum)

if end == '*':
    offset = 0
else:
    offset = 1
for i in range(len(num)):
    if i % 2 == offset:
        wsum += num[-(i+1)]
        w.append(wsum)

if len(num) == 1:
    print(0)
else:
    minlist = []
    minlist.append(sum(num[::2]))
    minlist.append(sum(num[1::2]))
    for i in range(len(num)):
        minlist.append(inverse(b, w, i, first))
    print(min(minlist))

Submission status: Wrong Answer

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

index = 0
shCounter = 0
jhC = 0
while index < len(listS):
    if listS[index] == "#":
        jhC += 1
    else:
        shCounter += jhC
        jhC = 0
    index += 1

index = len(listS)-1
dotCounter = 0
jhC = 0
while index > -1:
    if listS[index] == ".":
        jhC += 1
    else:
        dotCounter += jhC
        jhC = 0
    index -= 1

count=0
flag=1
while flag:
    flag=0
    index=0
    bef=0
    while index < len(listS):
        if index == 0:
            bef = listS[index]
        else:
            if bef == "#":
                if listS[index] == ".":
                    listS[index-1]="."
                    flag=1
                    count+=1
            bef = listS[index]
        index+=1
print(min(shCounter, dotCounter, count))

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
ans=0
if s.count(".")==n or s.count("#"):
    print(0)
    sys.exit()
for i in range(len(s)):
    if s[i]=="#":
        print(min(s[i+1:].count("."),s[i:].count("#")))
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cmp1,cmp2,cmp3 = 0,0,0

if s.count('.') == n:
    print('0')
else:
    cmp1 = s[s.index('#'):].count('.')
    reverse_s = s[::-1]
    cmp2 = reverse_s[reverse_s.index('#')+1:].count('#') + reverse_s[:reverse_s.index('#')].count('.')
    cmp3 = reverse_s[reverse_s.index('#'):].count('#')
    print(min(cmp1,cmp2,cmp3))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
for s in S:
    if s == ".":
        count += 1
left = 0
right = count
minimum = left+right
for n in range(N):
    if S[n] == "#":
        left += 1
    else:
        right -= 1
    if max(left, right) < minimum:
        minimum = left+right
print(minimum)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
b = []
w = []
count = 0
for i in range(N):
  tmp = S[i:]
  b.append(tmp.count('#'))
  w.append(tmp.count('.'))
bw = [b[i]-w[i] for i in range(N)]
ind = bw.index(max(bw))
tmp1 = S[:ind]
tmp2 = S[ind:]
ans = 0
if tmp1.count('#') < tmp1.count('.'):
  ans += tmp1.count('#')
  if tmp2.count('#') < tmp2.count('.'):
    ans += tmp2.count('#')
  else:
    ans += tmp2.count('.')
else:
  ans += tmp1.count('.')
  ans += tmp2.count('.')
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cou = 0
for i in range(1, len(s)):
    if s[i-1] == '#':
        if not s[i-1] == s[i]:
            cou += 1

print(cou)

Submission status: Wrong Answer

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

ans = S.count('#')
for i in range(len(S)-1):
    n = S[:i].count('.')+S[i:].count('#')
    print(n)
    ans = min(ans, n)
print(ans)

Submission status: Wrong Answer

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

if "#" not in S or "." not in S:
	print("0")
	exit(0)

mostLeftBlack=S.index("#")
mostRightWhite=S.rindex(".")

tmpS=S[mostLeftBlack:]
targ="."
ansB=tmpS.count(targ)

tmpS=S[:mostRightWhite]
targ="#"
ansW=tmpS.count(targ)

ans = min(ansB,ansW)


print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
kuro = S.count("#")
shiro = S.count(".")
Slist =list(S)
if Slist[N-1] == ".":
	s=S.split('#')
	if len(s) == 2:
		print(1)
	else:
		if Slist[N-1] == "#":
			print(min(kuro-1,shiro))
		else:
			print(min(kuro,shiro))
		
else:
	if Slist[N-1] == "#":
		print(min(kuro-1,shiro))
	else:
		print(min(kuro,shiro))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
sl=[x for x in S]
cnt=0
for i in range(len(S)-1):
    if sl[i]=='#' and sl[i+1]=='.':
        cnt+=1
        sl[i]='.'
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
t=s[::-1]
count1=0
count2=0
for i in range(n-1):
    if(s[i]=='#'):
        if(s[i+1]=='.'):
            count1+=1
            s[i+1]='#'
        else:
            continue
    else:
        continue
for j in range(n-1):
    if(t[j]=='.'):
        if(t[j+1]=='#'):
            count2+=1
            t[j+1]='.'
        else:
            continue
    else:
        continue
print(min(count1,count2))

Submission status: Wrong Answer

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

count = 0
j = 0

for i in range(N):
    if j < N and S[j] == '#':
        j += 1
        b = 1
        w = 0
        while j < N and S[j] =='#':
            b += 1
            j += 1
        while j < N and S[j] =='.':
            w += 1
            j += 1
        count += min(b,w)

print(count)

Submission status: Wrong Answer

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

s=[]
s1=""
for i in range(N):
    if S[i:i+2]==".#":
        s.append(i)
    elif  S[i:i+2]=="#.":
        s.append(i)
    if len(s)==2:
        break
if len(s)<2:
    print("0")
    sys.exit()
else:
    cnt=0
    if S[0]=="#":
        cnt+=s[0]+1
    for i in range(N):
        if i-1>=s[1] and S[i]==".":
            cnt += 1
    print(cnt)

Submission status: Wrong Answer

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


n = int(input())
s = input()
s = list(s)
# print(s)



pre = s[0]
cnt = 0
for i in range(1, n):

    if pre=='#' and s[i]=='#':
        cnt +=1

    if pre=='#' and s[i]=='.':
        temp = i
        break
    pre = s[i]

    if s[i]=='.':
        cnt=0


# print(temp)
try:
    s = s[temp:]
    ans = sum(1 for x in s if x=='.')
    ans2 = sum(1 for x in s if x=='#') + 1 + cnt



    print(min(ans, ans2))
except:
    print(0)

Submission status: Wrong Answer

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

count = 0
while True:
    flag = True
    for i in range(N - 1):
        if S[i] + S[i+1] == "#.":
            S[i+1] = "#"
            Flag = False
            count += 1
    if True:
        break

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
a = S[S.find('#'):].count('#')
b = S[S.find('#'):].count('.')
c = S[::-1][S[::-1].find('.'):].count('#')
d = S[::-1][S[::-1].find('.'):].count('.')
print(min(a, b, c, d))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])
    s = lines[1]

    return (n, s)


def solve(n, s):
    
    ss = []
    for c in s:
        if c == ".":
            ss.append(True)
        else:
            ss.append(False)

    len_ss = len(ss)
    result = 0
    if len_ss == 1:
        result = 0
    elif len_ss == 2:
        if ss == [False, True]:
            result = 1
    elif len_ss == 3:
        if ss == [True, True, True]:
            pass
        if ss == [True, True, False]:
            pass
        if ss == [True, False, True]:
            result = result + 1
        if ss == [False, True, True]:
            result = result + 1
        if ss == [True, False, False]:
            pass
        if ss == [False, True, False]:
            result = result + 1
        if ss == [False, False, True]:
            result = result + 1
        if ss == [False, False, False]:
            pass
    else:
        result = 0
        for i, d in enumerate(ss):
            if ss[i] is False and i+1 < len_ss and ss[i+1] is True:
                ss[i+1] = False
                result = result + 1
        

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
index = int(input())
s = input()
a = []
for i in s:
  a.append(i)

count = 0
for j in range(index):
  for i in range(index-1):
    if a[i] == '#' and a[i+1] == '.':
      count += 1
      a[i] = '.'
      
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [i for i in input()]
for i in range(N):
    if(S[i]=='#'):
        break
s = S[i:]
if(i==0):
    print(0)
else:
    a = s.count('#')
    print(min(a,len(s)-a))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [s for s in input()]
a = s.count(".")
b = n - a
if a >= b:
    print(b)
else:
    print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S.count('.') == N or S.count('#') ==N:
  print(0)
else:
  start,end = 0,0
  for i in range(N):
    if S[i] == '#':
      start = i
      break
  for i in range(N):
    if S[-i+1] == '.':
      end = N-i+1
      break
  if start > end:
    print(0)
  else:
    M = S[start:end]
    print(min(M.count('.'),M.count('#')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
tmp = S.count('.')
if S[0] == '.':
    counter = 0
    count = 0
    while count < len(S) and S[count] != '#':
        counter += 1
        count += 1
    tmp -= counter 
print(tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
 
if s.count('.') == len(s):
    print(0)
else:
    for i, wb in enumerate(s):
        if wb == '#':
            s_ = s
            break
        else:
            s_ = s[i+1:]
    
    ans_black_change = s_.count('#')
    if s[-1] == '#':
        ans_black_change -= 1
    ans_white_change = s_.count('.')
    
    ans = min(ans_black_change, ans_white_change)
    print(ans)

Submission status: Wrong Answer

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

count = 0
for i in range(len(s)-1):
    if s[i] == '#' and s[i+1] == '.':
        if i == 0:
            s[i] = '.'
            count += 1
        elif i == len(s) -2:
            s[i+1] = '#'
            count += 1
        else:
            if s[i+2] == '.':
                if s[:i+1].count('#') < s[i:].count('.'):
                    count += len(s[:i])
            else:
                s[i+1] = '#'
                count += 1
print(count)

Submission status: Wrong Answer

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

i = s.find("#")
if i < 0:
  i = 0
a = s[i:].count(".")
j = s.rfind("#")
b = s[:j-1].count("#") + s[j:].count(".")

if a < b:
  print(a)
else:
  print(b)

Submission status: Wrong Answer

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


def func(input_s):
    count = input_s.count(".")
    for c, i in enumerate(s):
        if c == "." and input_s[i - 1] == "#":
            tmp_str = input_s
            tmp_str[i - 1] = "."
            tmp_count = func(tmp_str)
            count = min(tmp_count, count)
    return count


pre = ""
print(func(s))

Submission status: Wrong Answer

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

ANS1 = 1000000000
if S[0] == '#':
    ANS1 = S.count('.') 

cnt = 0
for i in S:
    if i == '.':
        cnt += 1
    else:
        break

ANS2 = S[cnt:].count('.') 

print(min(ANS1, ANS2))

Submission status: Wrong Answer

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

for i in range(0, N):
    if S[i] != '.':
        break
for j in range(0, N)[::-1]:
    if S[j] == '.':
        break
print(min(min(S[i:].count('.'), S[i:].count('#')), min(S[0:j+1].count('.'), S[0:j+1].count('#'))))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
print(S.count('#.'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
s = list(S)
if '#' in s:
  id = s.index('#')
  s_a = s[0:id]
  s_b = s[id+1:N-1]
  a = s_a.count('#')
  b = s_b.count('.')
  if a > b:
    print(a)
  else:
    print(b)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

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

#B
def B():
    n = II()
    s = input()
    a = list(set(list(s)))
    k = II()-1
    for i in a:
        if s[k] != i:
            s = s.replace(i, "*")
    print(s)
    return

#C
def C():
    n = II()
    s = S()
    dp = []
    bf = s[0]
    del s[0]
    a = 1
    flg = False
    if bf == ".":
        flg = True
    for i in s:
        if i == bf:
            a += 1
        else:
            dp.append(a)
            a = 1
            bf = i
    dp.append(a)
    a, b = 0, 0
    if flg:
        dp[0] = 0
    if len(s) and s[-1] == "#":
        dp[-1] = 0
    for d in range(len(dp) - 2, -1, -2):
        a += dp[d]
    for d in range(len(dp) - 1, -1, -2):
        b += dp[d]
    print(min(a,b))

    return

#D
def D():
    n = II()
    ai = IR(n)
    ai.sort()
    ruiseki = [0 for i in range(n)]
    for num, a in enumerate(ai):
        ruiseki[num] = a + ruiseki[num-1]
    select = list(itertools.combinations(range(n), 3))
    ans = 0
    for a,b,c in select:
        A = ruiseki[a]
        B = ruiseki[b] - ruiseki[a]
        C = ruiseki[c] - ruiseki[b]
        if A + B > C and B + C > A and A + C > B:
            ans += 6
            ans = ans % mod
    print(ans)
    
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
S=S+'#'
sc=0
tc=0
ans=0
for i in range(N+1):
    if(tc!=0 and S[i]=='#'):
        if(sc>tc):
            ans+=tc
        else:
            ans+=sc
            sc=0
        tc=0

    if(sc!=0 and S[i]=='.'):
        tc+=1
    elif(tc==0 and S[i]=='#'):
        sc+=1
print(str(ans))

Submission status: Wrong Answer

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

if ('.' not in S) or ('#' not in S):
    print(0)
    exit()


def period_change(string):
    flag = False
    cnt = 0
    for char in string:
        if char == '#':
            flag = True
            continue

        if char == '.' and flag:
            cnt += 1
            flag = True
            continue

        flag = False

    return cnt


def sharp_change(string):
    flag = False
    cnt = 0
    for char in string:
        if char == '.':
            flag = True
            continue

        if char == '#' and flag:
            cnt += 1
            flag = True
            continue

        flag = False

    return cnt


print(min(period_change(S), sharp_change(S)))

Submission status: Wrong Answer

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

s=[]
s1=""
for i in range(N):
    if S[i:i+2]==".#":
        s.append(i)
    elif  S[i:i+2]=="#.":
        s.append(i)
    if len(s)==2:
        break
print(s)
if len(s)<2:
    print("0")
    sys.exit()
else:
    cnt=0
    if S[0]=="#":
        cnt+=s[0]+1
    for i in range(N):
        if i-1>=s[1] and S[i]==".":
            cnt += 1
    print(cnt)

Submission status: Wrong Answer

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

c_b = 0
c_w = 0

# # is black and . is white
c = 0

s_c = []
for i in range(N):
    if S[i] == '#':
        c_w += 1
        if c_b > 0:
            s_c.append(['.', c_b])
            c_b = 0
    else:
        c_b += 1
        if c_w > 0:
            s_c.append(['#', c_w])
            c_w = 0


if c_w > 0:
    s_c.append(['#', c_w])
    c_w = 0
if c_b > 0:
    s_c.append(['.', c_b])
    c_b = 0

c = 0
for i in range(len(s_c)-2, -1, -1):
    if s_c[i][0] == '#':
        if s_c[i+1][0] == '.':
            c += min(s_c[i][1], s_c[i+1][1])

print(c)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
flag=0
countB=0
countB2=0
for i in range(N):
  if S[i]=="#":
    if flag==0:
      Nint=i
      flag=1
    countB += 1
    countB2+=1
  else:
    countB2=0
if flag==1:
  countW=N-Nint-countB
  countB=countB-countB2
  if countB>countW:
    print(countW)
  else:
    print(countB)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
cnt = Counter(S)
print(min(cnt["."], cnt["#"]))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())
if set(S) == {'#'} or set(S) == {'.'}:
    print(0)
    sys.exit()
first_b = S.index('#')
if S[-1] == '#':
    b_count = S.count('#')-1
else:
    b_count = S.count('#')
w_count = S[first_b:].count('.')
if b_count < w_count:
    print(b_count)
else:
    print(w_count)

Submission status: Wrong Answer

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

index_1 = [i for i in range(N) if S[i] == "."]
index_2 = [j for j in range(N) if S[j] == "#"]

exist = False
if S[0] == ".":
  for i in range(N-1):
    if S[i+1] != "#":
      exist = False
  if exist:
    print(0)
  elif S[N-1] == "#" and S[N-2] == ".":
    print(min(len(index_1)-1, len(index_2)-1))
  else:
    print(min(len(index_1), len(index_2)))
elif S[N-1] == "#" and S[N-2] == ".":
  print(min(len(index_1)-1, len(index_2)-1))
else:
  print(min(len(index_1), len(index_2)))

Submission status: Wrong Answer

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

    bw_cnt = S.count('#.')

    if bw_cnt == 0:
        print(0)
    else:
        black_cnt = S.count('#')
        white_cnt = S.count('.')
        print(min(black_cnt, white_cnt))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
S_2 = S
ans = 0
ans_2 = 0
for i in range(N-1):
    if (S[i] == "#" and S[i + 1] == "."):
        S[i + 1] = "."
        ans += 1
for i in range(N - 1):
    if (S[i] == "#" and S[i + 1] == "."):
        S_2[i + 1] = "#"
        ans_2 += 1
print(min(ans, ans_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] == ".":
        if (S[i-1] == "." and i >= 1) or (S[i+1] == "." and i == 0):
            S[i] = "."
        else:
            S[i+1] = "#"
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count1=0
count2=0
s=list(S)

for i in range(N-1):
    if s[i]!=s[i+1]:
        s[i+1]=s[i]
        count1+=1

for j in range(N-1):
    if s[j]!=s[j+1]:
        s[j]=s[j+1]
        count2+=1

if count1<count2:
    print(count1)
else:
    print(count2)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
white_change = 0 if s.count("#") == 0 else s[s.index("#"):].count(".")
print(white_change if white_change < s.count("#") else s.count("#") - 1 if s[-1] == "#" else s.count("#"))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
bunki = 0
if(S[0] == '.'):
	print(S.count('#'))
else:
	for i in range(N-1):
		if(S[i] == '.'):
			bunki = i
			break
	if(bunki != 0):
		for j in range(bunki, N):
			if(S[j] == '#'):
				count += 1
	print(count)

Submission status: Wrong Answer

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

count = 0
while S.find("#.") != -1:
    S = S.replace("#.", "..",1)
    count += 1

#print(S)
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
flag_b=0
sum_b=0
sum_w=0
for i in S:
    if i=="." and flag_b==1:
        sum_w+=1
        continue
    if i=="#" and flag_b==1:
        sum_b+=1
        continue
    if i=="#" and flag_b==0:
        flag_b=1
        sum_b+=1
if sum_w >= sum_b:
    print(sum_b)
else:
    print(sum_w)

Submission status: Wrong Answer

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

if S.count('#')==N or S.count('.')==N:
    print(0)
elif S[0]=='#':
    print(min(S.count('#'),S.count('.')))
else:
    renzoku=1
    a=min(S.count('#'),S.count('.'))
    for i in range(1,N):
        if S[i]=='.':
            renzoku+=1
        else:
            break
    S=S[renzoku:]
    print(min(S.count('#'),S.count('.'),a))

Submission status: Wrong Answer

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

cw=0
cb=0

m=0

for j in reversed(range(N)):
    if s[j]=="#":
        m=m+1
    else:
        break

n=0

for k in range(N):
    if s[k]==".":
        n=n+1
    else:
        break

for i in range(n,N-m):
    if s[i]==".":
        cw=cw+1
    if s[i]=="#":
        cb=cb+1

print(min(cw,cb))

Submission status: Wrong Answer

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

r1=S.count("#")
r2=N-r1
c1=r1
c2=r2


it1=0
it2=N-1
it1f=False
it2f=False
r3=0
isLeft=None

while it1<it2:
  if S[it1]!=".":
    if it1f==True and it2f==True and c1<c2:
      r3+=1
      it1+=1
      it1f=False
      c1-=1
      c2+=1
    else:
      it1f=True
  else:
    it1+=1

  if S[it2]!="#":
    if it1f==True and it2f==True and c1>=c2:
      r3+=1
      it2-=1
      it2f=False
      c1+=1
      c2-=1
    else:
      it2f=True
  else:
    it2-=1

print(r3)

Submission status: Wrong Answer

Solution code:
N = int(input())
K = list(input())
count = 0
count_b = 0
b=-1

for i in range(N):
    if K[i]=='#':
        b = i
        break
    else :
        continue

if b != -1:
    for j in range(N-b-1):
        if K[j+b+1] == '.':
            count+=1
        elif K[j+b+1] == '#':
            count_b +=1

if K[N-1]=='#':
    count_b -=1


c = min(count,count_b+1)


if c != N-1:
    print(c)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
c=0
d=0
for i in range(0,N,1):
  if S[i]=="#":
    moji=S[i:]
    c=moji.count(".")
    break

for i in range(0,N,1):
  if S[i]==".":
    moji=S[i:]
    d=moji.count("#")
    break

if c<=d:
  print(c)
elif c>d:
  print(d)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
s = list(IS())
count = 0
if len(s) == 1:
    print(0)
    exit()
for i in range(len(s)):
    if i == 0 and s[i] == '#' and s[i+1] == '.':
        s[i] = '.'
        count += 1
    elif i == len(s)-1:
        break
    elif s[i-1] == '.' and s[i] == '#' and s[i+1] == '.':
        count += 1
        s[i] = '.'
    elif s[i-1] == '#' and s[i] == '#' and s[i+1] == '.':
        count += 1
        s[i+1] = '#'
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
w,b = 0,0
c = S[::-1]

for d in range(len(c)):
    if c[d] != '#':
        break

for s in S:
    if s == '.':
        w += 1
    else:
        b += 1

if d > 0:
    b-= d
if b > w:
    print(w)
else:
    print(b)

Submission status: Wrong Answer

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

'''
black_count = 0
white_count = 0
right_white_pos=-1
for i in range(N):
    if(S[i]=="."):
        white_count+=1
        right_white_pos=i
    else:
        black_count+=1

counter = 0
for i in range(N):
    if(i<right_white_pos):
        if(S[i]=="#"):
            counter +=1

print(white_count)
print(black_count)
print(counter)
print(min(white_count, black_count, counter))
'''


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

S_black_list=list(S)
S_white_list=list(S)

to_black_counter=0
for i in range(N-1):
    if(S_black_list[i]=="#" and S_black_list[i+1]=="."):
        to_black_counter+=1
        S_black_list[i+1]="#"

        

#print(white_count)
#print(black_count)
#print(to_black_counter)
print(min(white_count, black_count, to_black_counter))