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:
def main(word):
    strs = list(word)
    b_count = strs.count("#")
    w_count = strs.count(".")

    if b_count < w_count:
        if strs[len(strs)-1] == "#":
            return b_count-1
        else:
            return b_count

    else:
        return w_count


if __name__ == "__main__":
    input()
    word = input()
    print(main(word))

    # count = 0
    # iRegular = False
    # for i, _ in enumerate(strs):
    #     if i == 0:
    #         continue
    #     if strs[i-1] == "#" and strs[i] == ".":
    #         count += 1
    #         continue

    #     if i < 2:
    #         continue
    #     if iRegular and strs == ".":
    #         count += 1
    #         continue
    #     else:
    #         iRegular = False
    #     if strs[i-2] == "#" and strs[i-1] == "." and strs[i] == ".":
    #         iRegular = True
    #         count += 1

Submission status: Wrong Answer

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

cnta = 0
la = l
cntb= 0
lb = l
for i in range(1, n):
    if (la[i-1] == "#")&(la[i-1] != la[i]):
        la[i] = "#"
        cnta += 1

for i in range(0, n-1):
    if (lb[i+1] == "#")&(lb[i+1] != lb[i]):
        lb[i] = "."
        cntb += 1

print(min(cnta, cntb))

Submission status: Wrong Answer

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

pre_i = ''
res = 0
flag = 0
start_index = 0

for i in range(n):
      
    if flag == 1 and s[i] != '.':
      ver_s = s[start_index:i]
      black = ver_s.count('#')
      white = ver_s.count('.')
      res += white if white < black else black
      
      start_index = i
      pre_i = '.' if white < black else '#'
      flag = 0
      
    if s[i] == '.' and pre_i == '#':
      
      flag = 1
      
    else:
    	pre_i = s[i]
    
      
      
if flag == 1:
      ver_s = s[start_index:]
      black = ver_s.count('#')
      white = ver_s.count('.')
      res += white if white < black else black
     
print(res)

Submission status: Wrong Answer

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

N = int(input())
S = list(input())
count = 0

# for i in reversed(range(len(S) - 1)):
#     if S[i] == '#':
#         count += 1

# print(S)

for i in range(len(S)):

    if S[i] == '.':
        if S[i - 1] == '#':
            count += 1
            S[i] = '#'

print(count)

Submission status: Wrong Answer

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

for i in range(N):
    if S[i]=='#':
        break
B = S[i:].count('#')
W = S[i:].count('.')
if S[-1]=="#":
    B -= 1
ans = min(B,W)
print(ans)

Submission status: Wrong Answer

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

prev = '.'
ans = 0

for i, s in enumerate(S):
    if s == '.' and prev == '#':
        ans += 1
    if prev == '.' and s == '#':
        prev = '#'

prev = '#'
count_b = 0
for i, s in enumerate(reversed(S)):
    if s == '.' and prev == '#':
        prev = '.'
    if s == '#' and prev == '.':
        count_b += 1

ans = min(count_b, ans)
print(ans)

Submission status: Wrong Answer

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

w,b = 0,0
ws,bs = [],[]
for s in S:
    if s != '.':
        break
    ws.append('.')

for s in S[::-1]:
    if s != '#':
        break
    bs.append('#')

S.lstrip(''.join(ws))
S.rstrip(''.join(bs))

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

if b > w:
    print(w)
else:
    print(b)

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('.')
e = S[:S.find('.')].count('#') + S[::-1][:S[::-1].find('#')].count('.')
print(min(a, b, c, d, e))

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s = input()
n_sharp = s.count('#')
n_dot = s.count('.')
result = None
if n_sharp < n_dot:
    result = re.sub('#+\.', '#', s)
else:
    result = re.sub('#\.+', '.', s)
# print(result)
print(len(s) - len(result))

Submission status: Wrong Answer

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

# 石リスト：黒→白→黒→白……→白の個数の配列
stonelist = []

if S[0] == ".":
    stonelist.append(0)

lastisblack = True

count = 0

for c in S:
    if (lastisblack == False and c == "." ) or \
        (lastisblack == True and c == "#"):
        count += 1
    else:
        stonelist.append(count)
        count = 1
        lastisblack = not lastisblack

stonelist.append(count)

# 右が必ず白で終わるようにする
if S[-1] == "#":
    stonelist.append(0)

ans = N

for i in range(0,len(stonelist)+1):
    cnt = 0
    printwhite = 0
    printblack = 0
    while  cnt < i:
        if cnt % 2 == 0:
            printwhite += stonelist[cnt]
        cnt += 1
    while cnt < len(stonelist):
        if cnt % 2 == 1:
            printblack += stonelist[cnt]
        cnt += 1

    ans = min(ans,(printblack + printwhite))

print(ans)

Submission status: Wrong Answer

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

for i in range(n-1):
  if s[i] == '#' and s[i+1] == '.':
    s[i] = '.'
    cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

print(min(S.count("#"), S.count(".")))

Submission status: Wrong Answer

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

if len(set(S)) == 1:
    print(0)
    quit()

a = S.count(".")
b = S.count("#")
ans2 = min(a,b)

ans = 0

if S[0] == "#":
    i = 1
    while True:
        if S[i] == ".":
            ans = i
            S = S[i:]
            break
        else:
            i += 1
else:
    flag = False
    for i in S:
        if i == "#":
            flag = True
        if flag and i == ".":
            break
    else:
        print(0)
        quit()

if len(set(S)) == 1:
    print(ans2)
    quit()

if S[-1] == ".":
    i = 2
    while True:
        print(S, i)
        if S[-i] == "#":
            ans += (i-1)
            S = S[:-i+1]
            break
        else:
            i += 1


for i in range(len(S)):
    if S[i] == "#":
        S = S[i:]
        break
for i in range(1, len(S)+1):
    if S[-i] == ".":
        S = S[:-(i-1)]
        break

print(min(min(S.count("."), S.count("#")) + ans, ans2))

Submission status: Wrong Answer

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

sharp = list()
dot = list()
count = 0

while '#.' in S:
    S = list(S)
    for i in range(N):
        if S[i] == '#':
            if len(sharp) > 0 and len(dot) > 0:
                if len(sharp) >= len(dot):
                    for j in dot:
                        S[j] = '#'
                        count += 1
                else:
                    for j in sharp:
                        S[j] = '.'
                        count += 1
                
                sharp = list()
                dot = list()
            sharp.append(i)
        else:
            dot.append(i)
    S = ''.join(S)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input().rstrip()
s = s.rstrip('#')
if len(s) == 0:
    print(0)
    exit()

start = s.find('#.')
if start == -1:
    print(0)
    exit()
print(s.count('.', start))

Submission status: Wrong Answer

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

index = 0
dotCounter = 0
flag=1
while index < len(listS):
    if flag:
        if listS[index]=="#":
            flag=0
    else:
        if listS[index]==".":
            dotCounter+=1
    index+=1


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S_1 = S.copy()

cnt_n = 0
cnt_r = 0
prev_n = S[0]
prev_r = S_1[0]
suc = 0

for i in range(1, len(S)):
    if prev_n == '#' and S[i] == '.':
        S[i] = '#'
        cnt_n += 1
    if prev_r == '#' and S_1[i] == '.':
        cnt_r += suc
        suc = 0
    else:
        suc += 1
    prev_n = S[i]
    prev_r = S_1[i]
    
print(min([cnt_n, cnt_r]))

Submission status: Wrong Answer

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input() + '#'
 
flag = 0
b = 0
w = 0
ans = 0
for i in range(N + 1):
    if S[i] == '#':
        if flag == 2:
            ans += b
            b = 1
            w = 0
            flag = 1
        else:
            b += 1
            flag = 1
    else:
        if flag == 1:
            w += 1
            flag = 2
        elif flag == 2:
            w += 1
        
flag = 0
b = 0
w = 0
ans2 = 0
for i in range(N + 1):
    if S[i] == '#':
        if flag == 2:
            ans2 += w
            b = 1
            w = 0
            flag = 1
        else:
            b += 1
            flag = 1
    else:
        if flag == 1:
            w += 1
            flag = 2
        elif flag == 2:
            w += 1
        
print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
li=[]
if s[0]=='.':
  a=0
  s.insert(0,"あ")
  for i in range (1,n+1):
    if s[i]==s[i-1]:
      a=a+1
    else:
      li.append(a)
      a=1
  li.append(a)
else:
  a=1
  for i in range (0,n-1):
    if s[i+1]==s[i]:
      a=a+1
    else:
      li.append(a)
      a=1
  if s[n-2]==s[n-1]:
    a=a+1
    li.append(a)
  else:
    li.append(a)
if s[0]=="あ":
  s.pop(0)
if s[n-1]==".":
  li.append(0)
len_li=len(li)
import math
t=math.floor(len_li/2)+1
l=[]
m=0
for j in range (0,t-1):
  m=m+li[2*j+1]
x=0
y=0
for k in range (0,t):
  l.append(m+y-x)
  y=y+li[2*k]
  if k!=t-1:
    x=x+li[2*k+1]
l.sort()
print(l[0])

Submission status: Wrong Answer

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

a = 0
b = 0

x = 0
y = 0
z = 0
w = 0
while x == 0 and y<N:
  if S[y] == '.':
    y += 1
  else:
    x = 1
while z == 0 and w<N:
  if S[N-w-1] == '#':
    w += 1
  else:
    z = 1

if y+1 == N:
  print(0)
else:
  for i in range(y, N-w):
    if S[i] == '.':
      a += 1
    else:
      b += 1
  print(min(a, b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ss = []
for i in s:
    if i == "#":
        ss.append(1)
    else:
        ss.append(0)

now = 0
cnt = 0
x = []

for i in range(n):
    if ss[i] == now:
        cnt += 1
    else:
        x.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    x.append(cnt)
if ss[-1] == 0:
    x.append(0)

#print(x)
x.pop(0)
x.pop(-1)
c1 = 0
c2 = 0
for i in range(len(x)):
    if i % 2 == 0:
        c1 += x[i]
    else:
        c2 += x[i]

print(min(c1,c2))

Submission status: Wrong Answer

Solution code:
def indexOfLeftWhite(S) :
    for i in range(len(S)):
        if (S[i] == ".") :
            return i
    return -1

def indexOfLeftBlack(S) :
    for i in range(len(S)):
        if (S[i] == "#") :
            return i
    return -1

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

counter = 0

if (S[-2:] == "#.") :
    S = S[:-1] + "#" 
    counter += 1

if (N <= 2) :
    print(counter)
else:
    for i in range(1,len(S))[::-1] :
        if (S[i-1:i+2] == "#.#") :
            S = S[:i-1] + "###" + S[i+2:]
            counter += 1
        elif (S[i-1:i+2] == "#..") :
            S = S[:i-1] + "..." + S[i+2:]
            counter += 1

print(counter)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N = makeInt(input_string[0])
    S = input_string[1].rstrip()
    if len(S) == 1:
        return 0
    if S == "#.":
        return 1
    S = list("."+S)
    w = "."
    b = "#"
    c = 0
    b_c = 0
    b_b_c = 0
    for i in range(N):
        if S[i] == w and S[i-1] == b:
            if b_b_c == 0:
                #b_c = 0
                w_c = 0
                for j in range(i, N+1):
                    if S[j] == w:
                        w_c += 1
                    else:
                        break
                #for k in range(0, i)[::-1]:
                #    if S[k] == b:
                #         b_c += 1
                #    else:
                #        break

                #print(w_c)
                #print(b_c)
                if w_c > b_c:
                    for h in range(0, i)[::-1]:
                        if S[h] == b:
                            S[h] = w
                            c += 1
                        else:
                            break
        if S[i] == b:
            b_c += 1
        else:
            b_b_c = b_c
            b_c = 0
        if S[i] == b:
            if S[i-1] == w and S[i+1] == w:
                S[i] = w
                c += 1
                continue
        if i > 0 and S[i] == w:
            #print(S)
            #print(S[i])
            if S[i-1] == b:
                S[i] = b
                c += 1
    i = N
    if i == N:
        #print("a")
        #print(S)
        #print(S[i])
        if S[i-1] == b and S[i] == w:
            S[i] = b
            c += 1
    return c


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cntB = 0
cntW = 0

flg = S.find('#')

for j in range(N - flg):
    if S[flg + j] == '.':
        cntB += 1
    else:
        if j == N - flg - 1:
            continue
        cntW += 1

print(min(cntB, cntW))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    fb = 0
    cand = []
    b = []
    w = []
    cand.append(S.count('#'))
    cand.append(S.count('.'))
    for i in range(N):
        if S[i] == '#':
            b.append(i)
        elif S[i] == '.':
            w.append(i)
    for i in range(len(b) - 1):
        wh = 0
        for j in w:
            if j > b[i + 1]:
                wh += 1
        cand.append(1 + i + wh)
    print(min(cand))
main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
index = S.find("#")
answer = -1
if(index == -1):
    answer = 0
elif(index == 0 and len(S) == 1):
    answer = 0
else:
    test = S[index:N]
    count_s = test.count("#")
    count_d = test.count(".")
    answer = min(count_s,count_d)
    if(count_s == len(test)):
        answer = 0
print(answer)

Submission status: Wrong Answer

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

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

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

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

print(min(c1,c2,c3))

Submission status: Wrong Answer

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

if S[0]=='#':
    count+=1
    S[0] = '.'
for i in range(N-2):
    if S[i]=='#' and S[i+1]=='#' and S[i+2]=='.':
        S[i+2]='#'
        count+=1
    elif S[i]=='.' and S[i+1]=='#' and S[i+2]=='.':
        S[i+1]='.'
        count+=1
print(count)

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]
sums = sum(list(s))
if sums==0:
    print(0)
else:
    if n-b-a>sums:
        print(sums)
    else:
        print("n-b-a", n-b-a)

Submission status: Wrong Answer

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

if not "#" in s:
    print(0)
    exit()
kuro = s.count("#")
idx = s.index("#")
for i in range(idx):
    s_init.pop(0)
shiro = s_init.count(".")

print(min(kuro,shiro))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
S = input()
b = 0
w = 0
x = ""
for i, (k, v) in enumerate(groupby(S)):
  if not x:
    if k == ".":
      continue
  v = len(list(v))
  if k == "#":
    b += v
  else:
    w += v
  x += k
if x:
  if x[-1] == "#":
    b -= v
print(min(b,w))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans1 = 0
ans2 = 0

for i in range(len(s)):
    if i != 0 and s[i] == '.' and s[i-1] == '#' :
         ans1 += 1
    elif i != len(s)-1 and s[i] == '#' and s[i+1] == '.':
        ans2 += 1

if ans1 < ans2:
    print(ans1)   
else:
    print(ans2)

Submission status: Wrong Answer

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

left = stones.find("#")

if left == -1:
    print(0)
else:
    right = stones.rfind("#")
    stonesToChange = stones[left : right]
    print(min(stonesToChange.count("."), stonesToChange.count("#")))

Submission status: Wrong Answer

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

flag = True
cnt_b = 0
cnt_w = 0

while True:
    if len(S) == 1:
        print(0)
        exit()
    elif S[0] == ".":
        S = S[1:]
        #print(S)
    else:
        break

while True:
    if len(S) == 1:
        print(0)
        exit()
    elif S[len(S)-1] == "#":
        S = S[:len(S)-1]
        #print(S)
    else:
        break

for i in S:
    if i == "#":
        #print("debag b")
        cnt_b += 1
    else:
        #print("debag w")
        cnt_w += 1

if cnt_b < cnt_w:
    print(cnt_b)
else:
    print(cnt_w)

Submission status: Wrong Answer

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

black_start = s.find("#")
black_end = s.rfind("#")

white_start = s[black_start:].find(".")
white_end = s[black_start:].rfind(".")

black = s[black_start:].count("#")
white = s[black_start:].count(".")

if black == 0 or white ==0:
    print(0)
else:
    if white_end < black_end:
        print(black-1)
    else:
        print(min(black, white))

Submission status: Wrong Answer

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

#all白
s1=len([w for w in s if w=="#"])

#all黒
s2=len([w for w in s if w!="#"])

#右1黒
if s[-1]=="#":
  s3=len([w for w in s[:-1] if w=="#"])
else:
  s3=len([w for w in s if w=="#"])

print(min([s1,s2,s3]))

Submission status: Wrong Answer

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

    sharp_place = S.find("#")

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

    answer1 = 0

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

    answer2 = S.count("#")
    answer3 = S.count(".")

    answer = min(answer1, answer2)
    answer = min(answer, answer3)

    print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
a = 0
b = 0
for i in S:
    if i in '#':
        a += 1
    if i in '.':
        b += 1
print(min(a, b))

Submission status: Wrong Answer

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

bcounts = [0 for _ in range(len(S))]
wcounts = [0 for _ in range(len(S))]
cs = 0
for i in range(len(S)):
    if S[i] == '#':
        cs += 1
    bcounts[i] = cs
cs = 0
for i in reversed(range(len(S))):
    if S[i] == '.':
        cs += 1
    wcounts[i] = cs

INF = float('inf')
ans = INF
for i in range(len(S) - 1):
    if S[i] == '#' and S[i + 1] == '.':
        # 次の黒を超えたところの wcounts
        ni = i + 1
        while ni < len(S) and S[ni] == '.':
            ni += 1
        while ni < len(S) and S[ni] == '#':
            ni += 1
        wc = wcounts[ni] if ni < len(S) else wcounts[-1]
        ans = min(ans, bcounts[i] + wc)

print(0 if ans == INF else ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sr = s[::-1]
count_w = 0
count_b = 0
first_b = n
first_w = n
last_b = n
last_w = 0

for i in range(n):
    if s[i] == "#":
        first_w = i
        first_b = i+1
        break
for i in range(n):
    if sr[i] == ".":
        last_b = i
        break
if first_w+last_b == n:
    print(0)
    exit()

for i in range(n):
    if s[i] == "#":
        count_b += 1
    elif  s[i] == ".":
        count_w += 1

for i in range(first_b, n):
    if s[i] == ".":
        last_w += 1
print(min(count_b, count_w, last_w))

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(".#", "")

print(min(counting(S, "#"), counting(S, ".")) + base_count)

Submission status: Wrong Answer

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

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

s_list = list(s)
b_list = []
a_list = []

cnt_d= 0
cnt_s = 0
cnt_min = 2*10**5
for i in range(n-1):
    if s_list[i] == '#' and s_list[i+1] == '.':
        b_list = s_list[:i+1]
        cnt_s = b_list.count('#')
        a_list = s_list[i+2:]
        cnt_d = a_list.count('.')
        cnt_min = min(cnt_min, cnt_s+cnt_d)
if cnt_min == 2*10**5:
    cnt_min = 0

print(cnt_min)

Submission status: Wrong Answer

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
S=input()

sm1=[0]*N
prev=False
if S[0]=='#':
    sm1[0]=1
    prev=True
for i in range(1, N):
    if S[i]=='#':
        if prev:
            sm1[i]=sm1[i-1]+1
        else:
            sm1[i]=1
            prev=True
    else:
        prev=False
sm2=[0]*N
prev=False
if S[-1]=='.':
    sm2[-1]=1
    prev=True
for i in range(N-1, 0, -1):
    if S[i-1]=='.':
        if prev:
            sm2[i-1]=sm2[i]+1
        else:
            sm2[i-1]=1
            prev=True
    else:
        prev=False

S2=list(S)
cnt=0
for i in range(1, N):
    if S2[i-1]=='#' and S2[i]=='.':
        if sm1[i-1]>=sm2[i]:
            S2[i]='#'
            cnt+=1
for i in range(N-1, 0, -1):
    if S2[i-1]=='#' and S2[i]=='.':
        if sm1[i-1]<sm2[i]:
            S2[i-1]='.'
            cnt+=1
print(cnt)

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+=sc
            sc=0
        else:
            ans+=tc
            sc+=tc
        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:
# -*- coding: utf-8 -*-

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

wc = S.count('.')
bc = 0
ans = wc + bc
for s in S:
    if s == '.':
        wc -= 1
    else:
        bc += 1
    temp = wc + bc
    ans = min(temp, ans)
        
print(ans)

Submission status: Wrong Answer

Solution code:
stones_count = int(input())
input_str = input()

target = input_str[0]

def set_next_target(target_char):
  if target_char == '#':
    return '.'
  else:
    return '#'

stones = ''
stones_list = []

for i in range(stones_count):
  if input_str[i] == target:
    stones = stones + target
  else:
    stones_list.append(stones)
    target = set_next_target(target)
    stones = target

stones_list.append(stones)
#print(stones_list)

count_0 = 0
count_1 = 0

## ケース: .. or ## の場合、変換は不要
if len(stones_list) == 1 :
  print(0)
  exit()
## ケース: ..## の場合、変換は不要
elif len(stones_list) == 2 and '#' in stones_list[-1]:
  print(0)
  exit()
## ケース: ..##..##.. の場合、先頭の要素を除いたもので少ない方のみ変換すればよい
elif '.' in stones_list[0]:
  if '#' in stones_list[-1]:
    for i in range(1, len(stones_list)-1):
      if i % 2 == 0:
       count_0 += len(stones_list[i])
      else:
       count_1 += len(stones_list[i])
  else:
    for i in range(1, len(stones_list)):
      if i % 2 == 0:
       count_0 += len(stones_list[i])
      else:
       count_1 += len(stones_list[i])
## ケース: ##..##.. の場合、すべてを変換する前提で少ないものを選べばよい
else:
  if '#' in stones_list[-1]:
    for i in range(0, len(stones_list)-1):
      if i % 2 == 0:
       count_0 += len(stones_list[i])
      else:
       count_1 += len(stones_list[i])
  else:
    for i in range(0, len(stones_list)):
      if i % 2 == 0:
       count_0 += len(stones_list[i])
      else:
       count_1 += len(stones_list[i])

if count_0 > count_1:
  print(count_1)
else:
  print(count_0)

Submission status: Wrong Answer

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

for i in range(N):
    if S[i]=='#':
        break
B = S[i:].count('#')
W = S[i:].count('.')
if B<=W:
    ans = B
    if S[-1]=="#":
        ans -= 1
else:
    ans = W
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = input()
    s = s[:n]

    try:
        first_black = s.index('#')
    except ValueError as e:
        print(0)
        exit(0)

    s2 = s[first_black+1:]
    print(s2.count('.'))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
index = S.find("#")
answer = -1
if(index == -1):
    answer = 0
elif(index == 0 and len(S) == 1):
    answer = 1
else:
    test = S[index:N]
    count_s = test.count("#")
    count_d = test.count(".")
    answer = min(count_s,count_d)
    if(count_s == len(test)):
        answer = 0
print(answer)

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

front_write = 0
for i in char_list:
    if i == ".": 
        front_write += 1
    else:
        break


if write -front_write <= black - back_black:
    print(write - front_write)
else:
    print(black - back_black)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
A=[]
B=[]
for i in S:
    A.append(i)
for i in S:
    B.append(i)
count1=0
count2=0
for i in range(N-1):
    if (A[i]=="#")and( A[i+1]=="."):
        A[i+1]="#"
        count1+=1
for i  in range(N-1):
    if B[ i]  =="#":
        B[i]="."
        count2+=1
ans=min(count1,count2)
print(ans)

Submission status: Wrong Answer

Solution code:
def pro():
    _, s = input(), [s for s in input()]
    if "#" not in s:
        return print(0)
    s = s[s.index("#"):]
    a = s.count(".")
    b = len(s) - a
    if a >= b:
        return print(b)
    else:
        return print(a)
pro()

Submission status: Wrong Answer

Solution code:
n = input()
s = list(raw_input())
count = 0
count_a = s.count("#")

for i in range(n-1,0,-1):
 if s[i] == "#" and s[i-1] == "#":
  count_a -= 1
 else:
  if count_a != 0:
   count_a -= 1
  break

for j in range(n-1):
 if s[j] == "#" and s[j+1] == ".":
  count += 1
  s[j+1] = "#"

print min(count,count_a)

Submission status: Wrong Answer

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

x = 0
for i in range(N):
    if S[i] == '#':
        x += S[i+1:].count('.')
        break       
    else:
        continue

print(x)

Submission status: Wrong Answer

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

print(min(c,b,w))

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('#')-1 < 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:
stones = [raw_input() for i in range(2)][1]
if "." not in stones or "#" not in stones:
    print(0)

else:
    for start, i in enumerate(stones):
        if i == "#":
            break
    for end, i in enumerate(reversed(stones)):
        if i == ".":
            break

    b, w = 0, 0
    for i in stones[start:len(stones) - end]:
        if i == ".":
            w += 1
        else:
            b += 1
    print(min(b, w))

Submission status: Wrong Answer

Solution code:
#!/snap/bin/pypy3

def sharpcounter(string):
    for i, char in enumerate(string):
        if char != '#':
            return i
    else:
        return len(string)


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

    count = 0
    tmp_sharp = 0
    for i, char in enumerate(S):
        if char == '#':
            tmp_sharp += 1
        else:
            if i + 1 < N and S[i+1] == '#':
                count += 1
                tmp_sharp += 1
            elif i + 1 == N:
                count += int(tmp_sharp > 0)
            else:
                count += min(tmp_sharp, sharpcounter(S[i+1:]))
                tmp_sharp = 0 

    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x = int(input());
s=list(input());
 
j = 0;
k = 0;

for i in reversed(range(len(s))):
    if str(s[i]) == '.':
        if i != 0:
         if str(s[i-1]) == '#':
              s[i-1] = '.';
              j = j + 1;

for i in range(len(s)):
    if str(s[i]) == '#':
        if i != len(s) - 1:
          if str(s[i+1]) == '.':
              s[i] = '.';
              k = k + 1;
 
print(max(k,j));