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:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math,string
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
S = read_str()

def solve():
    ans = 0
    head_dot = 0
    tail_hash = N
    for i in range(N):
        if S[i] != ".":
            break
        head_dot += 1
    for i in range(N):
        if S[N - i -1] != "#":
            break
        tail_hash -= 1
    if head_dot < tail_hash:
        ans = min(S[head_dot:tail_hash+1].count("."), S[head_dot:tail_hash+1].count("#"))
    return ans

if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
# N = int(input())
#
# S = str(input())
#
# cnt = 0
# for i in range(1, N):
#     if S[i-1] == '#' and S[i] == '.':
#         cnt += 1
#
# cnt_2 = 0
# for i in range(N-2, -1, -1):
#     if S[i+1] == '.' and S[i] == '#':
#         cnt_2 += 1
#
#
# print(int(min(cnt, cnt_2)))

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-2, -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 = [i for i in input()]

start = 0
countb = 0
countw = 0
check = -1
ans = []

for i in range(len(S)):
    if(S[i] == "#"):
        start = i
        break

for i in range(start,len(S)):
    if(S[i] == "#"):
        check = 1
        countb = countb + 1
    else:
        check = 0
        countw = countw + 1
    if(check == 1 and countw != 0):
        if(countb < countw):
            ans.append(countb)
        else:
            ans.append(countw)
        countb = 1
        countw = 0
    if(i == N-1 and check == 0):
        if(countb < countw):
            ans.append(countb)
        else:
            ans.append(countw)

if(start == 0):
    ans.append(0)

print(sum(ans))

Submission status: Wrong Answer

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

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

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

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

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

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

S4=list(S)
cnt3=0
for i in range(1, N):
    if S4[i-1]=='#' and S4[i]=='.':
        S4[i]='#'
        cnt3+=1

S5=list(S)
cnt4=0
for i in range(N-1, 0, -1):
    if S5[i-1]=='#' and S5[i]=='.':
        S5[i-1]='.'
        cnt4+=1

print(min(cnt1, cnt2, cnt3, cnt4))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = 0
i = 0
j = N-1
while True:
        while (i < N) and (S[i] == '.'):
                i = i + 1
        while (j >= 0) and (S[j] == '#'):
                j = j -1
        if i > j:
                break
        elif i + 1 == j:
                cnt = cnt + 1
                break
        else:
                cnt = cnt + 2
        i = i + 1
        j = j - 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
s += "#"
b = 0
w = 0
ans = 0
for s_ in s:
  if s_ == "#":
    if w == 0:
      b = b + 1
    else:
      ans = ans + min(b,w)
      b = 1
      w = 0
  if s_ == ".":
    if b > 0:
      w = w + 1

print(ans)

Submission status: Wrong Answer

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

c_b = 0
c_w = 0

# # is black and . is white
c = 0

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


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

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

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

print(c)

Submission status: Wrong Answer

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

slist=[]
for i in range(n):
  slist.append(len([w for w in s[:i] if w=="#"])+len([w for w in s[i:] if w!="#"]))

print(min(slist))

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=="." and N==0:
        cnt2+=1
if cnt1 < cnt2:
    print(cnt1)
else:
    print(cnt2)

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
stemp=input()
s=[ i for i in stemp]
s.append("NG")

ans=0
f=0
f2=0
if s[0]=="#":
    f2=1
for i in range(n):
    if f2 and s[i]==".":
        ans+=1
    else:
        if s[i]=="." and s[i+1]=="#":
                f=1
        elif f:
            if s[i]==".":
                ans+=1
    #print(s[i], i, f, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=0
b=0
if n%2!=0:
    for i in range(0,n-1,2):
        if s[i]!=s[i+1]:
            a=a+1
    if a>0:
        print(a+1)
    else:
        print(a)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = [str(i) for i in input()]

    white = stones(S, ".", "#")
    black = stones(S, "#", ".")

    print(min([white, black]))


def stones(S, color, another):
    # ある色にする
    pre_stone = color
    color_count = 0
    for s in S:
        if pre_stone == color and s == another:
            color_count += 1
            pre_stone = color
        else:
            pre_stone = s

    # 後ろから黒が連続している数
    temp = S
    temp.reverse()

    con_another = 0
    for s in temp:
        if s == another:
            con_another += 1
        else:
            break

    color_count -= con_another
    return color_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
raw = input()
start_idx = 0
count = 0

for s in raw:
    if s == '#':
        break
    start_idx = start_idx + 1
 
tmpb = 1
tmpw = 1
flg = '#'
reset = False
for i in range(start_idx, n):
    if reset:
        tmpb = 1
        tmpw = 1
        flg = '#'
        reset = False
    if flg == '#':
        if raw[i] == flg:
            tmpb = tmpb + 1
        else:
            flg = '.'
    else:
        if raw[i] == flg:
            tmpw = tmpw + 1
        else:
            reset = True
            if tmpb >= tmpw:
                count = count + tmpw
            else:
                count = count + tmpb

if raw[-1] == '.': 
    if tmpb >= tmpw:
        count = count + tmpw
    else:
        count = count + tmpb
 
 
print(count)

Submission status: Wrong Answer

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

li = list(S)
count = 0

for i in range(N-1):
    if '#' == li[i] and '#' == li[i+1]:
        li[i] = li[i] = '.'

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

Submission status: Wrong Answer

Solution code:
import re

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

kind = []
stone = []
change = []
s = 0

for i in range(N):
    if i == 0:
        kind.append(S[i])
        s += 1
    elif S[i-1] != S[i]:
        stone.append(s)
        kind.append(S[i])
        s = 1
        if S[i]=='#':
            change.append(len(stone))
    else:
        s += 1
    if i == N-1:
        stone.append(s)

if len(kind)==1:
    print(0)
else: 
    min = 2 * 10 ** 5
    # print(kind, stone)
    if kind[0] == '.':
        start = 1
    else:
        start = 0
    # .#となっている所の#の個数を持つstoneのindexがi
    for i in change:
        tmp = 0
        # 左側の #の数を数えて足す
        for j in range(start,i,2):
            tmp += stone[j]
        # print('i=', i, 'tmp=', tmp)
        # 右側の .の数を数えて足す
        for j in range(i+1,len(stone),2):
            tmp += stone[j]
        # print('i=', i, 'tmp=', tmp)
        if tmp < min:
            min = tmp
    print(min)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S = list(input())
 
S_1 = copy.copy(S)
S_3 = copy.copy(S)
count_1 = 0
count_3 = 0

for i in range(N-1):
  if S_1[i] == "#" and S_1[i+1] == ".":
    if i != N - 2:
      if S_1[i+2] == "#":
        S_1[i+1] = "#"
      elif i != 0 and S_1[i-1] == ".":
        S_1[i] = "."
      else:
        S_1[i+1] = "#"
    else:
      S_1[N-1] = "#"
    count_1 += 1
    
#for i in range(N-1):
#  if S_2[i] == "#" and S_2[i+1] == ".":
#    S_2[i] = "."
#    count_2 += 1
    
for i in range(N-1):
  if S_3[N - i - 1] == "." and S_3[N - i - 2] == "#":
    if i != N - 2:
      if S_3[N - i -3] == ".":
        S_3[N - i - 2] = "."
      elif i != 0 and S_3[N - i] == "#":
        S_3[N - i - 1] = "#"
      else:
        S_3[N - i - 2] = "."
    else:
      S_3[0] = "."
    count_3 += 1
    
#for i in range(N-1):
#  if S_4[N - i - 1] == "." and S_4[N - i - 2] == "#":
#    S_4[N - i - 2] = "."
#    count_4 += 1
    
print(min(count_1, count_3))

Submission status: Wrong Answer

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

res1 = 0
res2 = 0
index = 0
if s[0] == ".":
    for i in range(1, len(s)):
        if s[i] != s[i - 1]:
            index = i
            break
        index = len(s)
for i in range(index, len(s)):
    if s[i] == ".":
        res1 += 1
for i in range(index, len(s) - 1):
    if s[i] == "#":
        res2 += 1

print(min(res1, res2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
back = 0
for i in reversed(range(len(s))):
    if s[i] == "#":
        back += 1
    else:
        break
if back > 0:
    s = s[:-back]
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
if s.count("#") > ans:
    print(ans)
else:
    print(s.count("#"))

Submission status: Wrong Answer

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

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

for j in range(N - 1):
    if s[j]=='#' and s[j + 1]=='.':
        s[j+1] = s[j]
        count2 += 1

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

Submission status: Wrong Answer

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

r = S.count(".")
l = n - r
i = 0
flag = True
while flag:
    if i < n:
        if S[i] == ".":
            r -= 1
        else:
            flag = False
    else:
        flag = False
    i += 1
j = n-1
flag = True
while flag:
    if j >= 0:
        if S[j] == "#":
            l -= 1
        else:
            flag = False
    else:
        flag = False
    j -= 1

print(min(r, l))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
count = 0
state = 0
b = 0
w = 0
sh = 0
for i in range(n):
    if s[i] == "#":
        sh += 1
        if state == 0:
            state = 1
            b += 1
        elif state == 1:
            b += 1
        elif state == 2:
            if b > w:
                count += w
                b = 1 + b + w
                w = 0
                state = 1
                if count >= sh:
                    count = sh
                    sh = 1
                    b = 1
            else:
                count += b
                b = 1
                w = 0
                sh = 1
                state = 1
    else:
        if state == 1:
            state = 2
            w += 1
        elif state == 2:
            w += 1

if state == 2:
    count += min([b,w])
    if count >= sh:
        count = sh

print(count)

Submission status: Wrong Answer

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

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

if (S.count('.') == 0 or S.count('#') == 0) or (S.count('.' == 1 or S.count('#') == 1)):
  print('0')
else:
  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:
stone=input()
color=input()
a=int(stone)
counter=0
counter2=0
black = 0
white = 0
xxx=[]
yyy=[]
list=[]
for i in range(a):
    list.append(color[i])
for i in range(a):
    if list[i]=='#':
        xxx.append(i)
        black += 1
    if list[i]=='.':
        yyy.append(i)
        white += 1
if white ==0 or black==0:
    print('0')
else:
    s = min(xxx)
    t = max(yyy)
    for k in range(s,a):
        if list[k]=='.' :
            counter = 1+ counter
    for j in range(0,t):
        if list[j]=='#':
            counter2 = 1 +counter2
    if counter > counter2:
        print(counter)
    else:
        print(counter2)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c=0
d=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

for i in range(N):
    if S[-i]=='.' and switch==0:
        switch=1
    elif switch==1 and S[-i]=='#':
        d=S[:-(i+1)].count('#')
        break
print(min(c,d))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(input())
c = 0
d = 0
e = []
st = a[N-1]
f = [st,1]
for i in range(2,N+1):
    if a[N-i] == st:
        f[1] += 1
    else:
        e.append(f)
        st = a[N-i]
        f = [st,1]
e.append(f)
for i in range(len(e) - 1):
    if e[i][0] == ".":
        c += e[i][1]
print(c)

Submission status: Wrong Answer

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

BLACK = '#'
WHITE = '.'

count = 0
for idx in range(N - 1):
    if S[idx] == BLACK and S[idx + 1] == WHITE:
        if idx > 0 and S[idx - 1] == WHITE:
            S[idx] = WHITE
        else:
            S[idx + 1] = BLACK
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(input())
cnta = 0
la = l.copy()
cntb= 0
lb = l.copy()
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] == "#")&(lb[i-1] != lb[i]):
        lb[i] = "."
        cntb += 1

print(min(cnta, cntb))

Submission status: Wrong Answer

Solution code:
N=int(input())
S = input()
left = -1
for i, s in enumerate(S):
    if s == '#':
        left = i
        break
now = ''
left2 = -1
for i, s in enumerate(S[::-1]):
    if s == '.' and now=='':
        now='.'
    elif s=='#' and now=='.':
        now = '#'
    elif s=='.' and now=='#':
        left2 = i
        break

left2 = len(S)-left2
left3 = 0
for i in range(left2, len(S)):
    if S[i]=='#':
        left3+=1
    else:
        break
left3 = left2+left3

ans = min(S[left:left2].count('.'), S[left:left2].count('#')) + min(left3-left2, len(S)-left3-len(S.split('.')[-1]))
if ans < 0:
    print(min(S.count('#'), S[left:].count('.')))
else:
    print(ans)

Submission status: Wrong Answer

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

print(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:
    while True:
        ans += 1
    print(ans2)
    quit()

if S[-1] == ".":
    i = 2
    while True:
        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:
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
                    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
                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 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()
ans = 0
if N == 1:
    print(0)
    exit()
elif N == 2 and (S[0] == '.' and S[1] == '#'):
    print(0)
    exit()
else:
    S = '#' + S + '#'
    for n in range(N):
        if S[n] == '.' and S[n + 2] == '.' and S[n + 1] == '#':
            ans += 1
        elif S[n] == '#' and S[n + 2] == '#' and S[n + 1] == '.':
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from re import findall

readline = stdin.readline

_ = readline()
s = readline().rstrip().rstrip('#')

a = findall(r'#+\.+', s)
c = ''.join(a)

print(min(c.count('#'), c.count('.')))

Submission status: Wrong Answer

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

white = "."
black = "#"

s_list = list(s)
count = 0
for i in range(len(s)-1):
    if s_list[i] == black and s_list[i+1] == white:
        s_list[i+1] = black
        count +=1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [i for i in input()]
for i in range(N):
    if(S[i]=='#'):
        break
for j in range(N-1,-1,-1):
    if(S[j]=='.'):
        break
t = N -(j+1)
s = S[i:]

a = s.count('#')

print(min(a-t,len(s)-a))

Submission status: Wrong Answer

Solution code:
import sys
index = int(input())
s = list(input())

count = 0
check = True
while True:
  t = 0
  for i in range(index-1):
    if s[i] == '#' and s[i+1] == '.':
      count += 1
      s[i] = '.'
    else:
      t += 1
  if t+1 == index:
    print(count)
    sys.exit(0)

Submission status: Wrong Answer

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

ans = [0,0]
cnt = 0
judge_b = 0
judge_w = 0
for i in range(n):
    if s[i] == "#" and judge_b == 1 and ans[1] != 0:
        cnt += min(ans)
        ans[0] = 1
        ans[1] = 0
        judge_b = 0
        judge_w = 0
    elif s[i] == "#":
        ans[0] += 1
        judge_b = 1
    elif s[i] == "." and judge_w == 1 and ans[0] != 0:
        cnt += min(ans)
        ans[0] = 0
        ans[1] = 1
        judge_b = 0
        judge_w = 0
    elif s[i] == ".":
        ans[1] += 1
    if i == n-1 and ans[1] != 0 and s[i] == ".":
        cnt += min(ans)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

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

flag = 0
count = 0

for i in range(N):
    if flag == 0:
        if S[i] == ".":
            count += 1
        elif S[i] == "#":
            break
            
a = S.count(".")
            
print(a - count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S.count('#') < S.count('.'):
  ans = S.count('#')
else:
  ans = S.count('.')
count = 0
for i in range(N-1):
  if S[i] == '#' and S[i+1] == '.':
    count+=1
if count<ans:
  print(count)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
start = s[0]
pattern = []

prev = ''
b = 0
w = 0
for i in s:
    if i == '#' and prev == '#' or prev =='':
        b += 1
    elif i == '.' and prev == '.' or prev == '':
        w += 1
    elif i == '#':
        b += 1
        pattern.append(w)
        w = 0
    else:
        w += 1
        pattern.append(b)
        b = 0
    prev = i
    
if prev == '#':
    pattern.append(b)
else:
    pattern.append(w)

totalb = 0
totalw = 0
for i in range(len(pattern)):
    if start == '.':
        if i % 2 == 0:
            totalw += pattern[i]
        else:
            totalb += pattern[i]
    else:
        if i % 2 == 0:
            totalb += pattern[i]
        else:
            totalw += pattern[i]
        
if len(pattern) == 1 or (len(pattern) == 2 and start == '.'):
    print(0)
else:
    if start == '.':
        print(min(totalw - pattern[0], totalb))
    else:
        print(min(totalw, totalb))

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
n = int(input())  
s = input()  
cnt = Counter(s)
cb = cnt['#']
cw = cnt['.']
cbw = 0
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
    
for i in range(n):
  if s[i] == '#':
    cbw += 1
  else:
    break
    
for i in range(n-1, -1, -1):
  if s[i] == '.':
    cbw += 1
  else:
    break

if cbw == 0:
  print(min(cw,cb))
else:
  print(min(cw, cb, cbw))

Submission status: Wrong Answer

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

prev = '#'
conv_idx = len(S)
for i, s in enumerate(reversed(S)):
    if s == '.':
        conv_idx = len(S) - i
        break

count_b = 0
count_w = 0
for i, s in enumerate(S[:conv_idx]):
    if s == '#':
        count_b += 1
    else:
        count_w += 1

ans = min(count_b, count_w)

print(ans)

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")
    ans3 = bin((int("0b"+"1"*int(N) ,0))^int("0b"+S.translate(str.maketrans(di)), 0)).count("1")
    print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s = input()
if not '#' in s:
    print(0)
else:
    s = s.rsplit('.#', 1)[0] + '.#' if '.#' in s else  s
    ptn = re.search(re.compile('\.#+?$'), s)
    if ptn:
        s = s[:ptn.end()]
    print(min(s.count('.'), s.count('#')))

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 = int(input())
s = input()

count_s = 0
count_d = 0
for i in range(1,n+1):
    if s[-i] == '#':
        count_s += 1
    else:
        break

for i in range(n):
    if s[i] == '.':
        count_d += 1
    else:
        break

s = s[count_d:n-count_s]
sharp_num = s.count('#')
dot_num = s.count('.')

print(min(sharp_num,dot_num))

Submission status: Wrong Answer

Solution code:
import sys

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

score1 = 0
score2 = 0
length = 1
check = S[0]
A = []
B = []
flag = 0

for i in range(N-1):
    if S[i] == S[i+1]:
        length += 1
    else:
        A.append(length)
        length = 1

if length != 1:
    A.append(length)

if len(A) != 0:
    if S[-1] != S[-2]:
        A.append(1)

if len(A) <= 1:
    print(0)
    sys.exit()

if S[0] == ".":
    A.pop(0)

if S[len(S)-1] == "#":
    A.pop(-1)

if len(A) == 0:
    print(0)
    sys.exit()

for i in range(len(A)):
    if i % 2 == 0:
        score1 += A[i]
    else:
        score2 += A[i]
        
ans = min(score1,score2)

if S[0] == "#":
    score3 = A[0] + score2 - A[1]

    ans = min(ans,score3)

if S[-1] == ".":
    score4 = A[len(A)-1] + score1 - A[len(A)-2]

    ans = min(ans,score4)


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
r = N - 1
l = 0
while 0<= r and S[r] == "#":
    r -= 1
while l < N and S[l] == ".":
    l += 1
# cnt = Counter(S[l:r+1])
# print(min(cnt["."], cnt["#"]))
B, W = 0, 0
for s in reversed(S[l:r+1]):
    if s == "#":
        W += 1
    else:
        B += 1
print(min(W, B))

Submission status: Wrong Answer

Solution code:
import sys

N =  int(sys.stdin.readline())
S = input()
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:
num = int(input())
a = input()
a = list(a)
count = 0
count1 = a.count("#")
for i in range(num):
  if i <= num-2 and a[i] == "#" and a[i+1] == ".":
    count += 1
    a[i+1] = "#"
if count1 <= count:
  print(count1)
else:
  print(count)

Submission status: Wrong Answer

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

count = 0
lst = []
for i,char in enumerate(S):
  if (char == "."):
    lst.append(i)
    
length = len(lst)
if (length > 0):
  for idx, i in enumerate(lst):
    if (i == 1):
      count += 1
    else:
      sum1 = i - lst[idx-1] - 1
      count += sum1
      
min = 0
if (count > length):
  min = length
else:
  min = count
  
print(min)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    S = lines.pop(0)
    # reverse
    S = S[::-1]
    # 白が現れるまで省く
    idx = S.find('.')
    S = S[idx:]

    res = 0
    while(True):
        w = S.find('#')
        b = S[w:].find('.')

        if w < 0:
            break

        if ( w < b ):
            res += w
            S = S[w+b:]
        else:
            res += min(S.count('.'), S.count('#'))
            break

    print(res)
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
white = (S)
white = S.count('.')
black = S.count('#')
for i in range(0,N):
    if S[i] == '.':
        last_white = i+1
if white == 0:
    last_white = 0
l_w = last_white - white
if l_w <= white and l_w <= black:
    print(l_w)
elif white <= l_w and white <= black:
    print(white)
elif black <= l_w and black <= white:
    print(black)