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()
# . = しろ
# # = 黒
# #の横に.がないようにしたい
# #の横に.があったら#を.に変える
# or #の横に.があったら.を#に変える

# when do you replace now char to .
# 

# テストケース
"""
9
.#.#.#.#.
"""
# => .....# = 2

def inorderReplace(S , N): 
    S = list(S)
    cnt = 0
    for i in range(N - 1) : 
        nowChar = S[i]
        nextChar = S[i + 1]
        if nowChar == "#" and nextChar == "." : 
            cnt += 1
            S[i + 1] = "#"
    return cnt

def calcCount(S , N) : 
    countingChar = S[0]
    rst = []
    count = 1
    for s in S[1:] :
        if countingChar == s : 
            count += 1
        else : 
            rst.append((countingChar , count))
            count = 1
            countingChar = s
    rst.append((countingChar , count))
    return rst

def countRightChange(countingList) : 
    #全部を.に変えるコスト
    cnt = 0
    for elem in countingList : 
        if elem[0] == "#" : 
            cnt += elem[1]
    return cnt

def countLeftChange(countingList) : 
    # 全部を#に変えるコスト
    cnt = 0
    for elem in countingList : 
        if elem[0] == "." : 
            cnt += elem[1]
    return cnt

def calcPoint(countingList) : 
    minVal = 9999999999999
    for i in range(len(countingList)) : 
        a = countRightChange(countingList[ : i])
        b = countLeftChange(countingList[i : ])
        print(a , b)
        if minVal > a + b : 
            minVal = a + b
    return minVal




#cnt = inorderReplace(S , N)
countingList = calcCount(S , N)
print(countingList)
cnt2 = calcPoint(countingList)

print(cnt2)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
ans = stdin.readline().rstrip()
count = 0
if ans[0] == '#':
    count += 1
if ans[N-1] =='#':
    count += 1
list = ans.split("#")
if list[len(list)-1] != '':
    count += 1
# print(count)
# print(list)
if len(list) == 1:
    print(0)
else:
    print(len(list)-count)

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input()) ###
    S = list(input())
    
    count_sharp = S.count('#')
    count_dot = S.count('.')
    # print(count_sharp, count_dot, count_sharp > count_dot) ###
    count = 0

    for i in range(1, len(S)):
        
        # print(S, end=' ') ###
        one = S[i-1]
        two = S[i]
        
        if count_sharp > count_dot: # . -> #
            if (one == '#') and (two == '.'):
                count += 1
                S[i] = '#'
            # elif (one == '#') and (two == '#') :
            #     S[i] = '.'
            #     count += 1
        else:
            if (one == '#') and (two == '.'):
                count += 1
                S[i] = '.'
            # elif (one == '#') and (two == '#'):
            #     S[i-1] = '.'
            #     count += 1
        # print(count, end=' ') ###
        # print(S) ###

    print(count)
    #..#.#....##...# -> (.)..(.).(.)....(.)(.)...#

    ###..#.##

main()

Submission status: Wrong Answer

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

sharp = 0
dot = 0
for string in s:
	if(string == "#"):
		sharp += 1
	else:
		dot += 1 


sb = s.copy()

ans = 0

for i in range(len(s)-1):
	if(s[i] == "#" and s[i+1] == "."):
		if(i == 0):
			s[i] = "."
		elif(i > 0 and s[i-1] != "#"):
			s[i] = "."
		else:
			s[i+1] = "#"
		ans += 1

ansb = 0
for i in range(len(sb)-1):
	if(i == 0 and sb[i] != "."):
		sb[i] = "."
		ansb += 1
	elif(sb[i] == "#" and sb[i+1] == "."):
		if(i > 0 and sb[i-1] != "#"):
			sb[i] = "."
		else:
			sb[i+1] = "#"
		ansb += 1


#print(s)
#print(sb)


#print(ans)
#print(ansb)

ans = min(ans, ansb, len(s) - sharp, len(s) - dot)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
result = 0
max_len_s = len(s) - 1
for i in range(max_len_s):
    if s[i] + s[i + 1] == "#.":
        s = s.replace(s[i], ".", 1)
        result += 1
print(result)

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] = "."
        ans_2 += 1
print(min(ans,ans_2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sr = s[::-1]
left_b = 0
right_w = 0
first_w = n
last_b = n
for i in range(n):
    if s[i] == "#":
        first_w = i
        break
for i in range(n):
    if sr[i] == ".":
        last_b = i
        break
if first_w+last_b == n:
    print(0)
    exit()

loop = n//2
for i in  range(loop):
    if s[i] == "#":
        left_b += 1
    if sr[i] == ".":
        right_w += 1
print(left_b + right_w)

Submission status: Wrong Answer

Solution code:
N = int(input())

S = str(input())

cnt = 0
target = S[0]
for i in range(1, N):
    if target == '#' and S[i] == '.':
        cnt += 1
        target = '#'  # 黒に変える
        continue

    if S[i] == '#':
        target = '#'
    else:
        target = '.'

cnt_2 = 0
aim = S[-1]
for i in range(N-1, -1, -1):
    if aim == '.' and S[i] == '#':
        cnt_2 += 1
        aim = '.'
        continue

    if S[i] == '#':
        aim = '#'
    else:
        aim = '.'


print(int(min(cnt, cnt_2)))

Submission status: Wrong Answer

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

s = list(s)

i = 0
cnt1 = 0

if "."*n == s:
    print(0)
elif "#"*n == s:
    print(0)
else:
    for i in range(len(s)-1):
        if (s[i] == "#") and (s[i+1] == "."):
            s[i+1] = "#"
            cnt1 += 1
    print(cnt1)

Submission status: Wrong Answer

Solution code:
SIRO = '.'
KURO = '#'
N = int(input())
S = input()
sLst = []
for i in S:
    sLst.append(i)
ans = 0
kCnt = S.count(KURO)
sCnt = S.count(SIRO)
if kCnt >= sCnt:
    for i in range(0, N - 1):
        if sLst[i] == KURO:
            if sLst[i + 1] == SIRO:
                sLst[i + 1] = KURO
                ans += 1
else:
    for i in range(N - 1, 1, -1):
        if sLst[i] == SIRO:
            if sLst[i - 1] == KURO:
                sLst[i - 1] == SIRO
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
try:
  leftb = s.index('#')
except:
  leftb = -1
try:
  rightw = s[::-1].index('.')
except:
  rightw = -1

if leftb < 0 or rightw < 0:
  print(0)
else:
  w = s[leftb:].count('.')
  b = s[leftb:].count('#') - rightw
  ans = min(w,b)
  print(max(0, ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = str(input())

ans_black = 0
ans_white = 0

for i in range(N-1):
  #print(i,end="")
  #print(S[i])
  if S[i]=="#" and S[i+1]==".":
    ans_black=ans_black + 1
  if S[i]=="#":
    ans_white=ans_white + 1  

ans=min(ans_white,ans_black)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import*
n=int(input())
s=input()
t=s.count("#")
r=s.count(".")

l=[t,r]
x=[[k,len(list(v))]for k,v in groupby(s)]
ans=0
for i in range(len(x)):
    n,m=x[i]
    #print(t,r)
    if n==".":
        r-=m
        l.append(r)
    else:
        l.append(t)
        t-=m
        ans+=m
        l.append(ans+r)
l.append(t)
print(min(l))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a = S.count('#')
b = S.count('.')
ans = min(a, b)
print(ans)

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('.') 

cnt = 0
newS = ''.join(list(reversed(S)))
for i in newS:
    if i == '#':
        cnt += 1
    else:
        break

ANS3 = newS[cnt:].count('#') 

print(min([ANS1, ANS2, ANS3]))

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
stemp=input()
s=[ i for i in stemp]

s2=copy.copy(s)
ans=0
ans2=0
ans3=0
f=0
for i in range(n):
    #print(i)
    if 1<=i and i<=n-1:
        if s[i]==".":
            ans+=1
    if i<=n-2:
        if s2[i]=="#":
            ans2+=1
    #print(n-i-1)
    if n-i-1>0:
        if s[n-i-1]==".":
            f=1
    if n-i-1>0:
        if f>0:
            if s[n-i-1]=="#":
                ans3+=1


#print(s)
#print(s2)
#print(ans,ans2)
print(min(ans,ans2, ans3))

Submission status: Wrong Answer

Solution code:
import sys

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N-1):
        if S[i:i+2]=='#.':
            if (i-1)>=0 and (i+2)<N and S[i-1]=='#' and S[i+2]=='.':
                S = S[:i+1] + '#' + S[i+2:]
                ans += 1
            else:
                ans += 1

            # if i==0 or ((i-1)>=0 and S[i-1]=='.'):
            #     # S = S[:i] + '.' + S[i+1:]
            #     ans += 1
            # elif i+1==N-1 or ((i+2)<N and S[i+2]=='#'):
            #     ans += 1
            # else:
            #     S = S[:i+1] + '#' + S[i+2:]
            #     ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S1 = list(input())
S2 = copy.copy(S1)
count1 = 0
count2 = 0
for i in range(N - 1):
    if S1[i] == "#" and S1[i + 1]==".":
        S1[i + 1] = "#"
        count1 +=1

for i in range(N-1,1,-1):
    if S2[i-1] == "#" and S2[i] == ".":
        S2[i-1] = "."
        count2 += 1 

print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = str(input())
res = 0

for i in range(a):
    if b[i:i+2] == "#.":
        res = b[i:].count(".")
        break

for i in range(a,-1,-1):
    if b[i:i+2] == "#.":
        res = min(b[:i+2].count("#"),res)
        break

print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
 
a=s.count(".")
tmp=s.rfind(".")
if tmp==-1:
  print(0)
  exit()
b=s[0:tmp].count("#")
tmp=s.find("#")

if tmp==-1:
  print(0)
  exit()
c=s[tmp:].count(".")
print(min(a,b,c))

Submission status: Wrong Answer

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

back = 0
for i in range(len(s)-1,0,-1):
    if s[i] == "#":
        back += 1
    else:
        break
ans = ans - back
if s.count("#") > ans:
    print(ans)
else:
    print(s.count("#"))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 19:26:31 2019
Tenka1C
@author: maezawa
"""

n = int(input())
s = input()
#n = len(s)

cnt = 0
k = -1
for i in range(n):
    if s[i] == '#':
        k = i
        break
if k == n-1:
    pass
elif k == -1:
    pass      
else:
    for j in range(k, n):
        if s[j] == '.':
            cnt += 1

s2 = reversed(s)
cnt2 = 0
k2 = -1
for i in range(n):
    if s[i] == '.':
        k2 = i
        break
if k2 == n-1:
    pass
elif k2 == -1:
    pass      
else:
    for j in range(k2, n):
        if s[j] == '#':
            cnt2 += 1

print(min(cnt,cnt2))

Submission status: Wrong Answer

Solution code:
N=input()
S=list(map(str,input()))

index_num = [n for n,v in enumerate(S) if v =='#']
#block >= harf

if len(index_num) >= len(S):
    print(len(index_num))
else:
    index_num_w = [n for n,v in enumerate(S) if v =='.']
    w_count = 0
    for i in index_num_w:
        if i!=0 and S[i-1]=='#':
            w_count += 1
    print(w_count)

Submission status: Wrong Answer

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

def counting(seq, s):
  return seq.count(s)

base_count = S.count(".#")

S = S.replace(".#", "")
count_list = []
for i in range(len(S)):
  count_list.append(counting(S[:i], "#") + counting(S[i:], "."))
count_list.append(counting(S, "#")+0)
print(min(count_list) + base_count)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    S = str(input())

    sharp_place = S.find("#")

    if sharp_place == -1:
        ok_pattern = "."*N
    else:
        ok_pattern = "."*sharp_place + "#" * (N-sharp_place)

    answer = 0

    for j in range(0, len(ok_pattern)):
        if ok_pattern[j] != S[j]:
            answer += 1

    print(answer)

Submission status: Wrong Answer

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

if s == "." * n or s == "#" * n:
    print(0)
else:
    black = s.index("#")
    white = sr.index(".")
    wb = [i for i, x in enumerate(s[black:]) if x == "."]
    bw = [i for i, x in enumerate(sr[white:]) if x == "#"]
    print(min(len(wb), len(bw)))

Submission status: Wrong Answer

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

fst = '.' if S[0:1] == '.' else '#'
snd = '.' if S[0:1] != '.' else '#'
result = 0

for i in range(len(S)):
    b1 = S[i:i+1]
    if i < N-1:
        b2 = S[i+1:i+2]
    else:
        break
    
    if b1 != b2:
        result += 1
        if b2 == fst:
            S = S[:i+1]+snd+S[i+2:]
        else:
            S = S[:i+1]+fst+S[i+2:]

print(result)

Submission status: Wrong Answer

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

d = []

s = S[0]
c = 1
for i in range(1,N):
    if s == S[i]:
        c += 1
    else:
        d.append(c)
        c = 1
        s = S[i]
d.append(c)
ans = 0
for i in range(1,len(d),2):
    ans += min(d[-i],d[-i-1])
print(ans)

Submission status: Wrong Answer

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

to_replace = 0

c2 = S[0]

for i in range(N-1):
  c1 = c2
  c2 = S[i+1]
  if c1=='#' and c2=='.':
    to_replace += 1

print(to_replace)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

b = sum([1 for i in s if i=="#"])
b2 = b
w = len(s)-b
w2 = w

ans1 = 0
ans2 = 0

f = False

for i in s:
    if i == "#":
        b-=1
        if b<w and not f:
            ans1+=1
        else:
            f = True
    else:
        if f:
            ans1+=1
        w-=1

f = False

for i in reversed(s):
    if i == ".":
        w2-=1
        if w2<b2 and not f:
            ans2+=1
        else:
            f = True
    else:
        if f:
            ans2+=1
        b2-=1
        
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
S = input()
ans = 0
stone = ""
num = []
for k, v in groupby(S):
  stone += k
  num.append(len(list(v)))
if stone[0] == ".":
  stone = stone[1:]
  num = num[1:]
if stone:
  if stone[-1] == "#":
    stone = stone[:-1]
    num = num[:-1]
if stone:
  ans = min(sum(num[::2]), sum(num[1::2]))
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
sp = s.find('#')
if sp != -1:
  s = s[sp:]
ep = s.rfind('.')
if ep != -1:
  s = s[:ep+1]
b = s.count('#')
w = s.count('.')

lpb = s.rfind('#')
ew = len(s) - (lpb+1)
s = s[:lpb]
s = s[:s.rfind('.')+1]
bn = s.count('#')

ans = min([b,w,bn+ew])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
numw=len([x for x in s if x=="#"])
numb=len([x for x in s if x=="."])
if s[-1]=="#":
    numw-=1
if s[0]==".":
    numb-=1
print(min(numb,numw))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
import bisect

def main():
    N = int(input())
    S = list(input())
    # print(S)

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

    total_white = S.count('.')
    ans = 0
    rest_white = total_white

    S += '#'  # 番兵
    black_count = 0
    white_count = 0
    for i in range(len(S)):
        if S[i] == '#':
            black_count += 1
            if white_count > 0:
                # consider
                if black_count - 1 > white_count + rest_white:
                    # print("b {}".format(white_count + rest_white))
                    ans += white_count + rest_white
                    break
                else:
                    # print("c {}".format(black_count - 1))
                    ans += (black_count - 1)
                white_count = 0
                black_count = 1
        else:
            if black_count > 0:
                white_count += 1
            # print('w')
            rest_white -= 1
    print(ans)

if __name__ == '__main__':
    main()

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(".")
c = s.count("#")

print(min([a, b, c]))

Submission status: Wrong Answer

Solution code:
stones = [raw_input() for i in range(2)][1]
for ind, i in enumerate(stones, start=0):
    if i == "#":
        b, w = 0, 0
        for i in stones[ind:]:
            if i == ".":
                w += 1
            else:
                b += 1
        print(min(b, w))
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
n = int(input())
s = str(input())
s = s.replace(".", "0").replace('#', "1")
b = s.find("1")
a = 0
for i in range(b, n):
    a+=int(s[i])
    
s = [int(n) for n in s]
if sum(list(s))==0:
    print(0)
else:
    print(n-b-a)

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)
#rightまでの黒を数える
for i in range(right+1):
    if s[i] == '#':
        cnt += 1
print(min(s.count('.'), s.count('#'), cnt))

Submission status: Wrong Answer

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

#print(S[0:])
X = 0
for i in range(N):
    if (S[i] == "#"):
        X = i
        break

#print(S[X:])
print(min(S[X:].count("#"), S[X:].count(".")))

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
ans=0
if s.count(".")==n or s.count("#")==n:
    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()
index = S.find("#")
answer = -1
if(index == -1):
    answer = 0
else:
    test = S[index:N]
    count_s = S.count("#")
    count_d = S.count(".")
    answer = min(count_s,count_d)
    if(count_s == len(test)):
        answer = 0
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
n = int(input())  
s = input()  
cnt = Counter(s)
cb = cnt['#']
cw = cnt['.']
 
for i in range(n):
  if s[i] == '.':
    cw -= 1
  else:
    break
    
for i in range(n-1, -1, -1):
  if s[i] == '#':
    cb -= 1
  else:
    break

print(min(cw,cb))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
ans_alt = 0
cs = str(s)
while s.count("#.") != 0:
    ans_alt += s.count("#.")
    s = s.replace("#.", "..")


while cs.count("#.") != 0:
    ans += cs.count("#.")
    cs = cs.replace("#.", "##")


if ans > ans_alt:
    ans = ans_alt

print(ans)

Submission status: Wrong Answer

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

count_if_all_white = 0
for c in S:
    if c == "#":
        count_if_all_white += 1

count_if_contain_black = None
l_count = 0
r_count = sum([1 for c in S if c == "."])
for c in S:
    if c == "#":
        l_count += 1
    else:
        r_count -= 1

    count = l_count + r_count
    if not count_if_contain_black:
        count_if_contain_black = count
    else:
        count_if_contain_black = min(count_if_contain_black, count)

print(min(count_if_all_white, count_if_contain_black))

Submission status: Wrong Answer

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

start = -1
black = 1
white = 0

for i in range(n):
    if s[i] == "#":
        start = i
        break

if start != -1:
    for i in range(n):
        if i > start:
            if s[i] == "#":
                black+=1
            else:
                white+=1
    if black<=white:
        print(black)
    else:
        print(white)

else:
    print(0)

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 i != 0 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=input()
sl=list(s)

c=0
b=0
w=0
res=0
for i in range(n-1):
	if sl[i]=="#":
		b=b+1
	else:
		b=0

	if sl[i]=="#" and sl[i+1]==".":
		for j in range(1, n-i):
			if sl[i+j]==".":
				w=w+1
			else:
				break
		if b <= w:
			res=res+b
			b=0
			w=0
		else:
			res=res+w
			b=0
			w=0
print(res)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
S = input()
s_list = list(S)
temp_start = temp_end = 0
count_1 = 0
count_2 = 0
for i in range(N-1):
    if s_list[i] == "#" and s_list[i+1] == ".":
        temp_start = i
        break
if temp_start == 0:
    print(0)
    sys.exit()
for i in range(N)[::-1]:
    if s_list[i] != "#":
        temp_end = i
        break
if temp_end == 0:
    temp_end = N-1
for i in range(temp_start,temp_end + 1):
    if s_list[i] == "#":
        count_1 += 1
    else :
        count_2 += 1
print(min(count_1,count_2))

Submission status: Wrong Answer

Solution code:
def remove_fwhite(S):
    fwhite = 0
    for fw in S:
        if fw == '.':
            fwhite += 1
        else:
            break
    return fwhite

def count_stone(S):
    black = 0
    white = 0
    for stone in S:
        if stone == '#':
            black += 1
        else:
            white += 1
    print(white)

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


fw = remove_fwhite(S)
if fw ==0:
    count_stone(S)
elif fw == N:
    print('0')
else:
    count_stone(S[fw:])

Submission status: Wrong Answer

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

sList = list(S)

leftInd = 0
rightInd = N - 1
ind = (leftInd + rightInd) // 2

def myFunc(ind):
    
    leftNum = sList[:ind].count("#")
    rightNum = sList[ind:].count(".")

    return leftNum, rightNum


if len(set(sList)) == 1:
    ans = 0
else:
    while True:
        ind = (leftInd + rightInd) // 2
        leftNum, rightNum = myFunc(ind)
        leftNum1, rightNum1 = myFunc(ind - 1)
        leftNum2, rightNum2 = myFunc(ind + 1)
        if abs(leftNum - rightNum) <= 1 or abs(leftNum1 - rightNum1) <= 1 or abs(leftNum2 - rightNum2) <= 1:
            ans = min(leftNum + rightNum, leftNum1 + rightNum1, leftNum2 + rightNum2)
            break
        elif leftNum > rightNum:
            rightInd = ind
        else:
            leftInd = ind

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
whi=0
bla=0
c1=0
dp=[[0,0] for i in range(N+1)]
for i in range(N):
    s=S[i]
    if s=="#":
        dp[i+1][0]=dp[i][0]+1
    else:
        dp[i+1][0]=dp[i][0]
    if s==".":
        dp[N-i-1][1]=dp[N-i][1]+1
    else:
        dp[N-i-1][1]=dp[N-i][1]


ans=1<<20
for i in range(N+1):
    ans=min(ans,dp[i][0]+dp[i][1])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        break

count=0
#print(dot+sha)
for i in range(N):
    if i<dot and S[i]!=".":
        count+=1
for i in range(N):
    if i<sha and s_r[i]!="#":
        count+=1
#print(count)

a=0
b=0

for i in range(N):
    if S[i]!=".":
        a+=1
    if S[i]!="#":
        b+=1

#print(count)
ans=min(count,a,b)
print(ans)

Submission status: Wrong Answer

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

first = S[0]
count = 0

for i, data in enumerate(S):
    if i == 0:
        pass
    else:
        if data == '.' and S[i - 1] == '#':
            count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

tmp = [0 for _ in range(N+1)]

if S[0] == '.':
    tmp[0] = 1

for i in range(N):
    if S[i] == '.':
        tmp[i+1] = tmp[i] + 1
    else:
        tmp[i+1] = tmp[i]
  
res1 = 10 ** 9
for i in range(N):
    res1 = min((i + 1) - tmp[i] + tmp[N] - tmp[i], res1)
        

b = 0
w = 0
for i in range(N):
    if S[i] == '#':
        b += 1
    else:
        w += 1

res3 = N - max(b, w)

print(min(res1, res3))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
a = 0
b = 0
flag = 0
for i in range(len(s)):
    if flag == 0:
        if s[i] == '#':
            if i != 0:
                ans += min(a,b)
                if a < b:
                    flag = 1
                a = 0
                b = 0
            a += 1
        if s[i] == '.':
            b += 1
            if i == len(s) -1:
                ans += min(a,b)
    if flag == 1:
        ans += s[i+1:].count('.')
        break
cta = 0
ctb = 0
ind1 = s.find('#')
ind2 = s.rfind('.')
for i in range(ind1+1,len(s)):
    if s[i] == '.':
        cta += 1
for i in range(ind2):
    if s[i] == '#':
        ctb += 1
print(min(ans,cta,ctb))

Submission status: Wrong Answer

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

ans = 0
ans2 = 0
for i in range(n-1,0,-1):
    if ne[i] == '.' and ne[i-1] == '#':
        ne[i-1] = '.'
        ans += 1
ne = []
for a in s:
    ne.append(a)
for i in range(n-1):
    if ne[i] == '#' and ne[i+1] == '.':
        ne[i+1] = '#'
        ans2 += 1

print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

    if N == 1:
        print(0)
        return

    white, black = [], []
    cntw, cntb = 0, 0
    prev = S[0]
    for s in S:
        if prev != s:
            white.append(cntw)
            black.append(cntb)
            cntw, cntb = 0, 0
        if s == '.':
            cntw += 1
        else:
            cntb += 1
        prev = s
    white.append(cntw)
    black.append(cntb)

    ans = 0
    for i in range(len(black)-1):
        if black[i] and not black[i+1]:
            if black[i] < white[i]:
                ans += black[i]
                white[i], black[i] = black[i], white[i]
            else:
                ans += white[i+1]
                white[i+1], black[i+1] = black[i+1], white[i+1]
    print(ans)

input = lambda: stdin.readline().rstrip()
main()

Submission status: Wrong Answer

Solution code:
#s=".###.##.###.##.."
#N=len(s)
#s=[s[i] for i in range(len(s))]
N=int(input())
s=input()
tmp=N
for i in range(N):
    a=s[:i].count("#")
    b=s[i:N].count(".")
    if tmp>a+b:
        tmp=a+b
print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = input()
black = l.count("#")
white = l.count(".")
if l[N-1]=="#":
	print(min(black-1,white))
else:
	print(min(black,white))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
start = S.find("#")
if start == -1:
    print("0")
else:
    di = {".":"0","#":"1"}
    S_bin = int("0b"+S[start:].translate(str.maketrans(di)), 0)
    a = int("0b"+"1"*int(N-start) ,0)
    ans1 = bin(a^S_bin).count("1")
    ans2 = bin(0^int("0b"+S.translate(str.maketrans(di)), 0)).count("1")
    print(min(ans1,ans2))

Submission status: Wrong Answer

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

num = 0
result = 0

if S[N-1] ==".":
    dot = S.count(".")
    if dot > N-dot:
        result = (N-dot)
    else:
        for i in range(N):
            if S[i] == "#":
                num = i
                break
        for i in range(i,N):#  .###..
            if S[i] == ".":
                num = i
                break
        result = S[i:N].count(".")

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

    white = S[0:num].count('.')
    black = S[0:num].count('#')
    if white < black:
        result = white
    else:
        result = black
print(result)

Submission status: Wrong Answer

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

w_cnt = 0
w_list = []
for i in range(N):
    if S[i] == '#':
        w_cnt += 1
        w_list.append(w_cnt)
    else:
        w_list.append(w_cnt)

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


ans = N
for i in range(N):
    wa = w_list[i] + b_list[N-2-i]
    if ans > wa:
        ans = wa

print(ans)

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] = "."
        ans_2 += 1
print(min(ans,ans_2))

Submission status: Wrong Answer

Solution code:
import sys

N =  int(sys.stdin.readline())
S = sys.stdin.readline()[:-1]
res = 0

i = S.find('#')
S = S[i:]

if S.count('#') < S.count('.'):
  if S[-1] != '#':
    res = S.count('#')
  else:
    res = S.count('#') -1
else:
    res = S.count('.')

print(res)

Submission status: Wrong Answer

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

def dot_num ():
    cnt = 0
    for i in range (N):
        if S [i] == '.':
            cnt += 1
    return cnt

def hash_num ():
    cnt = 0
    for i in range (N):
        if S [i] == '#':
            cnt += 1
    return cnt

dots = dot_num ()
hashes = hash_num ()

if S [0] == '.':
    dots -= 1

if S [N-1] == '#':
    hashes -= 1
    
print (min (dots, hashes))