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())+1
S = '.' + input()
b,w,flg,ans,w_b = 0,0,0,0,0
for i in range(N):
  if S[-(i+1)] == '.':
    if flg == 0:
      w += 1
      flg = 1
    elif flg == 1:
      w +=1
    elif flg == 2:
      if w+w_b > b:
        ans += b
        w_b += b+w
      else:
        ans = w + w_b
      b,w = 0,1
      flg = 1
  elif flg == 1:
    b+=1
    flg = 2
  elif flg == 2:
    b+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
s = input()
l = list(s)
ll = copy.copy(l)
rl = copy.copy(l)
rll = copy.copy(l)
bnextb = 0
btow = 0
rbnextb = 0
rbtow = 0
if n == 1:
  print(0)
else:
  for i in range(n-1):
    if l[i] == "#" and l[i+1] == ".":
      l[i+1] = "#"
      bnextb += 1
  for i in range(n-1):
    if ll[i] == "#" and ll[i+1] == ".":
      ll[i] = "."
      btow += 1
  for i in range(n-1,0,-1):
    if rl[i] == "." and rl[i-1] == "#":
      rl[i-1] = "."
      rbnextb += 1
  for i in range(n-1,0,-1):
    if rll[i] == "." and rll[i-1] == "#":
      rll[i] = "#"
      rbtow += 1
  print(min(bnextb,btow,rbnextb,rbtow))

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:]
    white_to_black = s2.count('.')
    print(min(s.count('#'), s2.count('.')))

Submission status: Wrong Answer

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

flag = -1
for c in S:
    if (c == '#' and flag == -1) or (flag != -1 and c == '.'):
        flag += 1
if flag == -1:
    flag += 1
print(flag)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())+['A']

print(S)
a=b=c=0
f=False
for i in range(len(S)-1):
    c+=1
    if ((S[i]=='#') & (S[i]!=S[i+1])):
        a+=c
        f=True
        c=0
    elif ((S[i]=='.') &( S[i]!=S[i+1])):
        if f==True:
            b+=c
            c=0
        else:
            f=True
            c=0
if a>b:
    print(b)
else : print(a)

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 = 1

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 = 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



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]="#"

to_white_counter=0

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


print(white_count)
print(black_count)
print(counter)
print(to_black_counter)
print(to_white_counter)
print(int(min(white_count, black_count, counter, to_black_counter, to_white_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)

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

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)
    else:
        j += 1

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(min(s.count('.', start), s.count('#', start + 1)))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s += "-"
print(s)
white = [0]
black = [0]
white_acc = 0
black_acc = 0
counter = 0
for i in range(n + 1):
    if s[i] == s[i - 1]:
        pass

    elif s[i - 1] == "#":
        black_acc += counter
        black += [black_acc]
        counter = 0
    elif s[i - 1] == ".":
        white_acc += counter
        white += [white_acc]
        counter = 0
    counter += 1
print(black, white)
if len(black) + len(white) <= 3:
    print(0)
    exit()

last_white = white[len(white) - 1]
min_acc = 2 * 10 ** 5
if s[0] == "#":
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i])

else:
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i - 1])
print(min_acc)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if all([s[i]=="#" for i in range(n)]):
    print(0)
    exit()
if all([s[i]=="." for i in range(n)]):
    print(0)
    exit()
try:
    a=s[::-1].index("#")
    b=s.index("#")
    c=s[::-1].index(".")
except:a=b=0
print(b,c,n)
if b+c==n:
    print(0)
    exit()
count=0
for i in range(b+1,n-a):
    if s[i]=="#":count+=1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
xx = []
ten = []
count = 0#最初
count1 = 0 
count2 = 1
count3 = 0
count4 = 0

for i in S:
    if i=="#" and count==0:
        count1 += 1
        count = 1
       
    elif i =="#" and count2==1 and count==1:
        count1 += 1
        
    elif i =="." and count2==1 and count==1:
        xx.append(count1)
        count1 = 1
        count2 = 0
        
    elif i =="." and count2==0 and count==1:
        count1 += 1

    elif i=="#" and count2==0 and count==1:
        ten.append(count1)
        count1 = 1
        count2 = 1


if count2==0 and count1>=1:
    ten.append(count1)

for i in range(len(xx)):
    if (xx[i]+count4)>=ten[i]:
        count3 += ten[i]
    else:
        count3 += xx[i]

count4 = sum(xx)
if count3 > count4:
    count3 = count4
        
print(count3)

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_b_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:
            if b_c != 0:
                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()

num_w_p = S.count(".")
num_b_p = N - num_w_p

state = False
counter = 0

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

for i in range(len(S)):
  if S[i] == "#":
    state = True
    counter += 1
  else:
    counter = 0
    state = False
if state == True:
  S = S[:-1*counter]
  
b_num = S.count("#")
w_num = len(S) - b_num
if b_num <= w_num:
  num_decide = b_num
else:
  num_decide = w_num
if num_decide > num_w_p:
  num_decide = num_w_p
elif num_decide > num_b_p:
  num_decide = num_b_p
print(num_decide)

Submission status: Wrong Answer

Solution code:
n = int(input())

str = input()
count = 0

for i in range(n):
  if str[i] == "#":
    k = i
    for s in range(k,n):
      if str[s] == ".":
        count += 1
    break
    
count2 = 0
i = n-1
while i  >= 0:
  if str[i] == ".":
    k = i
    while k >= 0:
      if str[k] == "#":
        count2 += 1
      k -= 1
    break
  i -= 1



print(min(count,count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == '.':
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
tw = 0
tb = 0
A = 0
for i in reversed(range(N)):
    if S[i] == '.':
        if cb[i] <= cw[i]:
            a += cb[i]
            print(a)
            exit()
        else:
            a += 1
print(a)

Submission status: Wrong Answer

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

stack = []


for i in range(len(S)):
    if S[i] == '.':
        stack.append(i)

if stack:
    ans = min(stack[-1] - (len(stack) - 1), len(stack))
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

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

def count_renzoku(S,s):
    renzoku=1
    for i in range(1,len(S)):
        if S[i]==s:
            renzoku+=1
        else:
            break
    return renzoku

if S.count('#')==N or S.count('.')==N:
    print(0)
else:
    a=min(S.count('#'),S.count('.'))
    T=S[::-1]
    if T[0]=='#':
        T=T[count_renzoku(T,'#'):]
        U=T[::-1]
        if U[0]=='.':
            U=U[count_renzoku(U,'.'):]
        b=min(U.count('#'),U.count('.'))
        print(min(a,b))
    elif S[0]=='.':
        S=S[count_renzoku(S,'.'):]
        b=min(S.count('#'),S.count('.'))
        print(min(a,b))
    else:
        print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
s=list(input())
t=-1
k=0
for i in range(n):
    if s[-1]=="#":
        continue
    k+=1
    s.pop(-1)
print(math.floor((s.count(".")+s.count("#"))/2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = S[::-1]
S += 'X'
tmps = 0; tmpd = 0
sharp = []; dot = []
if '#' not in list(S) or '.' not in list(S):
    print(0)
else:
    for i in range(N):
        if S[i] == '#':
            tmps += 1
            if S[i+1] != '#':
                sharp.append(tmps)
                tmps = 0
        if S[i] == '.':
            tmpd += 1
            if S[i+1] != '.':
                dot.append(tmpd)
                tmpd = 0
    if S[0] == '#':
        del sharp[0]
        ans = sum(sharp)
    else:
        del sharp[0]
        ans = sum(sharp) + dot[0]
    print(min(N - S.count('#'), N - S.count('.'), ans))

Submission status: Wrong Answer

Solution code:
import re
N = int(input())
S = input()
ans=2*10**5

l = []
for i in range(len(S)):
    if S[i] == ".#":
        l.append(i)


if S.count("#") == 0 or S.count(".") == 0:
    print(0)

else:
    for i in l:
        a = S[i+1:].count(".")+S[:i].count("#")
        ans = min(a,ans)
    print(ans)

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 S[flg + j:].find('.') == -1:
            break
        cntW += 1

print(min(cntB, cntW))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
black =False
w_num = 0
b_num =0
for i in range(N):
    if black:
        if S[i]==".":
            w_num +=1
    
    if S[i]=="#":
        black =True
        b_num +=1
r_black =0
for j in range(N):
    if S[N-j-1] == "#":
        r_black += 1
    else:
        break


ans = min([w_num,b_num-r_black,N-b_num])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input() + '#'
 
flag = 0
b = 0
w = 0
ans = 0
ans2 = 0
for i in range(N + 1):
    if S[i] == '#':
        if flag == 2:
            ans += b
            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 = input()

s1 = 0
s2 = 0

for s in S:
  if s == '.':
    s1 += 1
  else:
    break
    
for s in S[::-1]:
  if s == '#':
    s2 += 1
  else:
    break

s1 = max(1, s1)
s2 = max(1, s2)
print(min(S[s1:].count('.'), S[:-(s2)].count('#')))

Submission status: Wrong Answer

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

ans = 0
ans_ = 0
for i, s in enumerate(S):
    check = -1
    if i == N-1:
        break
    if s is '#':
        ans_ += 1
        ans__ = 0
        count = i
        for s_ in S[count+1:]:
            if count + 1 == N or s_ is '#':
                break
            if s_ is '.' :
                ans__ += 1
                check = 1
        if check == 1:
            ans += min(ans_, ans__)
            ans_ = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N = long(sys.stdin.readline())
    S = sys.stdin.readline()
    numA = S.count('.')
    numB = S.count('#')
    print(min(numA, numB))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S = list(input())
S_2 = copy.copy(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 j in range(N-1):
    if (S_2[j] == "#" and S_2[j + 1] == "."):
        S_2[j] = "."
        ans_2 += 1

print(min(ans, ans_2))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
cnt1 = 0
cnt2 = 0
for idx,s in enumerate(S):
    if s == "#" and idx != N-1:
        cnt1+=1
    if s==".":
        cnt2+=1
if cnt1 < cnt2:
    print(cnt1)
else:
    print(cnt2)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
count1 = 0
count2 = 0
count = 0
counter = []
flag = False

for i in range(N):
    if S[i] == '#':
        flag = True
    if S[i] == '.' and flag == True:
        count2 += 1
        
for i in range(N-1):
    if S[i:i+2] == ['#','.']:
        count1 += 1
        if count:
            counter.append(count)
        count = 0
        S[i] = '.'
    elif S[i:i+2] == ['#', '#']:
        count += 1
    else:
        if count:
            counter.append(count)
        count = 0

for i in counter:
    count1 += i
    
print(min(count1, count2))

Submission status: Wrong Answer

Solution code:
size = int(input())
stone= str(input())
cnt=0
cnt2=0
cnt3=0
for i in range(size):
    if(stone[i]=="."):
        cnt+=1
    else:
        break
for i in range(size):
    if(stone[i]=="."):
        cnt2+=1
    else:
        cnt3+=1
        
if(stone[0]=="#"):
    print(cnt2)
else:
    if(cnt2-cnt<cnt3):
        print(cnt2-cnt)
    else:
        print(cnt3)

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 = '.'

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

less_color = min(black, white)
if (black <= white) and S[-1] == '#':
    less_color -= 1

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c=0
switch=0
for i in range(N):
    if S[i]=='#' and switch==0:
        switch=1
    elif switch==1 and S[i]=='.':
        c=S[i-1:].count('.')
        break


    
print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import re

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

first = 0
position = 0
secondposition = 0
count2 = 0
for i in reversed(range(n)):
    if(first == 0 and s[i] == '#'):
        first += 1
        position = i+1
    if(first == 1 and s[i] == '.'):
        secondposition = i+1
        break;
if(position == 0):
    ans1 = 0
elif(secondposition == 0):
    ans1 =min(n-position,position)
else:
    for j in range(secondposition-1):
        if(s[j] == '#'):
            count2 += 1

    count1 = n - position

    ans1 = count1 + count2


first2 = 0
position2 = 0
secondposition2 = 0
count4 = 0
for i in range(n):
    if(first2 == 0 and s[i] == '.'):
        first2 += 1
        position2 = i+1
    if(first2 == 1 and s[i] == '#'):
        secondposition2 = i+1
        break;
if(position2 == 0):
    ans2 = 0
elif(secondposition2 == 0):
    ans2 = min(n-position2,position2)
else:
    for j in range(secondposition2-1,n):
        if(s[j] == '.'):
            count4 += 1

    count3 = position2-1

    ans2 = count3 + count4
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
h=0
b=0
for i in range(n):
    if s[i]=="#":
        b+=1
    elif s[i]=="." and b!=0:
        h+=1
b2=0
h2=0
for i in range(n-1,-1,-1):
    if s[i]==".":
        h2+=1
    elif s[i]=="#" and h2!=0:
        b2+=1


print(min(h,b2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
SS = list(S)
 
D = 0
 
black = S.split("#")
white = S.split(".")

if S[0] == ".":
  black.pop(0)
 
if S[-1] == "#":
  white.pop()
    
black = [bb for bb in black if bb != ""]
white = [ww for ww in white if ww != ""]
  
for b, i in zip(black,white):
  D += min(len(b),len(i))
  
print(D)

Submission status: Wrong Answer

Solution code:
n = int(input())

str = input()
count = 0

for i in range(n):
  if str[i] == "#":
    k = i
    for s in range(k,n):
      if str[s] == ".":
        count += 1
    break
    
count2 = 0
i = n-1
while i  >= 0:
  if str[i] == ".":
    k = i
    while k >= 0:
      if str[k] == "#":
        count2 += 1
      k -= 1
    break
  i -= 1


print(count,count2)
print(min(count,count2))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c=S.count('#')
if ('.' in S) & ('#' in S):
	s=S.index('.')
	p=S.index('#')
	k=S[p::]
	a=k.count('.')
	if (s==0)&(a==0):
		print(0)
	elif a>c:
		 print(c-1)
	else:
		 print(a)
else:
	print(0)

Submission status: Wrong Answer

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

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

middle = S[1:-1]
white = middle.count('.')
black = middle.count('#')

if white < black:
  if S[-1] == '':
    print(white+1)
  else:
    print(white)
else:
  if S[0] == '#':
    print(black+1)
  else:
    print(black)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
c = 0
b = s[:n-1].count('#')
w = s[1:].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:
N = int(input())
S = str(input())

y = 0
for x in range(N):
    if S[x] == '.':
        y += 1

n = 0
for m in range(N):
    if S[m] == '#':
        n += 1

print(min(y, n))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
white = S.count(".")
black = S.count("#")
print(min(white,black) if white*black != 0 else 0)

Submission status: Wrong Answer

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

b_sum = []
w_sum = []
b_num = 0
w_num = 0

#b_sum:i番目まで黒が何個か
#w_sum:i番目まで白が何個か

for i in range(n):
    if s[i] == "#":
        b_num = b_num + 1
    else:
        w_num = w_num + 1
    b_sum.append(b_num)
    w_sum.append(w_num)

#i番目まで白になるときは何個ひっくり返す？

ans = []

for i in range(n):
    ans.append(b_sum[i] + w_sum[n - 1] - w_sum[i])

print(min(ans))

Submission status: Wrong Answer

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

first_b = s.index('#') if '#' in s else n
w2b = b2w = 0

for i in range(first_b, n):
    b2w += 1 if s[i] == '#' else 0
    w2b += 1 if s[i] == '.' else 0

print(min(b2w, w2b))

Submission status: Wrong Answer

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

white = 0
black = 0

first_black_index = 0

while S[first_black_index] == ".":
  first_black_index += 1
  if first_black_index == N:
    print(0)
    break
if first_black_index != N:
  S = S[first_black_index:N+1]

  if S[len(S)-1] == "#":
    N = N-1


  for i in range(len(S)):
    if S[i] == "#":
      black +=1
    else:
      white +=1

  print(min(white,black))

Submission status: Wrong Answer

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

a = S.find('#')
b = 0
c = 0

if a < 0:
    print('0')

else:
    for k in range(a, N):
        if S[k] == '.':
            b = b + 1
        else:
            c = c + 1
    print(min(b,c))

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N = int(sys.stdin.readline())
    S = sys.stdin.readline()
    numA = S.count('.')
    numB = S.count('#')
    print(min(numA, numB))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt1 = 0
cnt2 = 0
S1 = S
S2 = S
for i in range(1, N):
  if S1[i-1] == "#" and S1[i] == ".":
    S1 = S1.replace(S1[i-1], ".", 1)
    cnt1 += 1
for i in range(1, N):
  if S2[i-1] == "#" and S2[i] == ".":
    S2 = S2.replace(S2[i-1], "#", 1)
    cnt2 += 1
  
print(min(cnt1,cnt2, S.count("#"), S.count(".")))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=0
first = s[0]
w = s.count('.')
for i in range(0,n-1):
    if (first=='#')&(s[i+1]=='.'):
        ans+=1
        first='#'
print(min(ans,w,n-w))

Submission status: Wrong Answer

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

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)
cnt1=0
for i in range(1, N):
    if S2[i-1]=='#' and S2[i]=='.':
        if sm1[i-1]>=sm2[i]:
            S2[i]='#'
            cnt1+=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]='.'
            cnt1+=1
S3=list(S)
cnt2=0
for i in range(1, N):
    if S3[i-1]=='#' and S3[i]=='.':
        if sm1[i-1]>sm2[i]:
            S3[i]='#'
            cnt2+=1
for i in range(N-1, 0, -1):
    if S3[i-1]=='#' and S3[i]=='.':
        if sm1[i-1]<=sm2[i]:
            S3[i-1]='.'
            cnt2+=1

print(min(cnt1, cnt2))

Submission status: Wrong Answer

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

Bflag = False
countA = 0
countB = 0
for i in range(N):
  if S[i] == '#':
    Bflag = True
    countB = countB + 1
  elif Bflag is True:
    countA = countA + 1

if countA < countB:
  print(countA)
else:
  if countB == 1:
    print(0)
  else:
    print(countB)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()



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

if ( count > 0 ):
  l.append(count)

#print(l)

ans = 99999
for i in range(len(l)):
  if ((i%2)!=0) :
    continue

  count = 0
  for j in range(int(i/2)):
    count += l[j*2+1]
  for j in range(int((len(l)-i-1)/2)):
    count += l[i+(j+1)*2]

  #print(i, count)

  if (ans>count):
    ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s += "-"
white = [0]
black = [0]
white_acc = 0
black_acc = 0
counter = 0
for i in range(n + 1):
    if s[i] == s[i - 1]:
        pass

    elif s[i - 1] == "#":
        black_acc += counter
        black += [black_acc]
        counter = 0
    elif s[i - 1] == ".":
        white_acc += counter
        white += [white_acc]
        counter = 0
    counter += 1
if len(black) + len(white) <= 1:
    print(0)
    exit()

last_white = white[len(white) - 1]
min_acc = 2 * 10 ** 5
if s[0] == "#":
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i])

else:
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i - 1])
print(min_acc)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
count2 = 0
flag = False
for x in range(N):
    if S[x] == '#':
        flag = True
    if S[x] == '.' and flag == True:
        count += 1

flag = False

for x in range(N)[::-1]:
    if S[x] == '.':
        flag = True
    if S[x] == '#' and flag == True:
        count2 += 1

print(min(count,count2))

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!="#"])


print(min([s1,s2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
def a (str) :
	_ans = 200000
	for i in range(n) :
		k = 0
		if str[i] == "#" :
			for j in s[0:i+1] :
				if j == "#" : k+=1
				if k > _ans : break
			for j in s[i:-1] : 
				if j == "." : k += 1
				if k > _ans : break
			if k<_ans : _ans = k
	return (_ans)
ans = a(s)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
p = 0
cnt = 0
while p < len(S):
    p += 1
    if S[p-1] == '#':
        if len(S) <= p:
            break
        elif S[p] == '.':
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
first_B = S.find('#') #最初の黒より前の白を消去するため
if first_B == -1: #黒がない=全部白-->回数0
    answer = 0
else:
    S = S[first_B:] #最初の白の部分を全部消去
    rev_S = S[::-1] #反転
#    print (rev_S, 'rev_S')
#    print(S)
    last_W = rev_S.find('.') #(反転後で)最初の白より前の黒を消去するため
    if last_W == -1:
            n_W = S.count('.')
            n_B = S.count('#')
            if n_W > n_B:
                answer = n_B
            else:
                answer = n_W
    else:
        S = rev_S[last_W:] #最初の黒の部分を全部消去
        S = S[::-1] #反転
#        print (S)
        n_W = S.count('.')
        n_B = S.count('#')
        if n_W > n_B:
            answer = n_B
        else:
            answer = n_W
print (answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
h=0
b=0
for i in range(n):
    if s[i]=="#":
        b+=1
    if s[i]=="." and b!=0:
        h+=1
b2=0
h2=0
for i in range(n-1,-1,-1):
    if s[i]==".":
        h2+=1
    if s[i]=="#" and h2!=0:
        b2+=1
    

print(min(h,b2))

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("#")
s_init = s_init[idx:]
shiro = s_init.count(".")
print(min(kuro,shiro))

Submission status: Wrong Answer

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

a = len(re.findall('#+.', S))
b = len(re.findall('#+.', S))
print(a)

Submission status: Wrong Answer

Solution code:
import re
N = int(input())
S = input()
ans=2*10**5

l = []
for i in range(len(S)):
    if S[i] == "#.":
        l.append(i)


if S.count("#") == 0 or S.count(".") == 0:
    print(0)

else:
    for i in l:
        a = S[i:].count(".")+S[:i+1].count("#")
        ans = min(a,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())-1;S=input();f=[];flag=0;l=0;
for i in range(N):
 if S[i] == "#" and i != N:
  if S[i+1] == ".":
   while (1):
    if S[i-l] != "#" or (l>0 and i == 0):
     f.append(abs(l));l=0;break
    l+=1;
   while (1):
    if i+l != N:
     if S[i+l+1] != ".":
      f.append(l);l=0;break
     l+=1
    else:
     f.append(l);l=0;break
   flag += min(f);f=[];
print(flag)

Submission status: Wrong Answer

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