Problem:


Score : 300 points

Problem Statement

There are N stones arranged in a row. Every stone is painted white or black.
A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.

Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.
Find the minimum number of stones that needs to be recolored.

Constraints

1 \leq N \leq 2\times 10^5

S is a string of length N consisting of . and #.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the minimum number of stones that needs to be recolored.

Sample Input 1

3
#.#

Sample Output 1

1

It is enough to change the color of the first stone to white.

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
kuro = 0
siro = 0
p = 0 
for i in range(n):
    if p == 0 and s[i] == "#":
        p = 1
    if p == 1 and s[i] == ".":
        siro += 1

p = 0
for i in reversed(range(n)):
    if p == 0 and s[i] == ".":
        p = 1
    if p == 1 and s[i] == "#":
        kuro += 1
        
print(min(siro,kuro))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
print(min(s[s.find("#"):s.rfind(".")].count("#"),s[s.find("#"):s.rfind(".")+1].count(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
print(min(s[s.find("#"):].count("#"),s[s.find("#"):].count(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
B = [0]*(n+1)
W = [0]*(n+1)

for i in range(n):
    B[i+1] = B[i]
    if s[i] == '#':
        B[i+1] += 1

s.reverse()
for i in range(n):
    W[i+1] = W[i]
    if s[i] == '.':
        W[i+1] += 1

B += [B[-1]]
W += [W[-1]]

ans = 10**18
for i in range(-1, n+1):
    ans = min(B[i+1]+W[n-i], ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
b = 0
w = 0
X = []
for i in range(n):
    if s[i] == '#':
        b += 1
    else:
        w += 1
    if i != n-1:
        if s[i] == '.' and s[i+1] == '#':
            X.append((b, w))
            b = 0
            w = 0
else:
    X.append((b, w))
#print(X)
ans = 0
for i in range(len(X)):
    ans += min(X[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
ans = 0
for i in reversed(range(1, n)):
    if i != n-1:
        if s[i] == '.' and s[i-1] == '#':
            if s[i+1] != '.':
                s[i] = '#'
            else:
                s[i-1] = '.'
            ans += 1
    else:
        if s[i] == '.' and s[i-1] == '#':
            s[i] = '#'
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
s = ns()

b, w = 0, 0
for i in range(n):
    b += s[i] == '#'
    w += s[i] == '.'

ib, iw = 0, 0
i = n - 1
while i >= 0 and s[i] == '#':
    ib += 1
    i -= 1
i = 0
while i < n and s[i] == '.':
    iw += 1
    i += 1

print(min(w - iw, b - ib))

Submission status: Wrong Answer

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

i=0
for ss in s:
  if ss=="#":
    break
  i+=1

s=s[i:]  
if s=="":
  print(0)
  exit()


while s[-1]=="#":
  s=s[:-1]
  if s=="":
    print(0)
    exit()
  
print(min(s.count("."),s.count("#")))

Submission status: Wrong Answer

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

i=0
for ss in s:
  if ss=="#":
    break
  i+=1
  
s=s[i:]
print(min(s.count("."),s.count("#")))

Submission status: Wrong Answer

Solution code:
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    c = collections.Counter(S)

    for i in range(N):
        if S[i] == '.':
            c['.'] -= 1
        else:
            break

    for i in range(N - 1, -1, -1):
        if S[i] == '#':
            c['#'] -= 1
        else:
            break

    print(max(0, min(c['.'], c['#'])))



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def colored(S):
    output = ""
    for i in range(len(S)):
        if S[i] == "#":
            output += "B"
        else:
            output += "W"
    return output

def rewrite(S):
    S = list(S)
    if len(set(S)) == 1:
        return 0
    else:
        #最終的には上書きした結果端以外はどちらかの色に統一される
        output_B = S[1:].count("W")
        output_W = S[:len(S)-1].count("B")
        return min(output_B,output_W)

def main():
    N = int(input())
    S = input()
    S = colored(S)
    ans = rewrite(S)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    a = 0
    c = S[0]
    for i in range(1, N):
        if c == '#' and S[i] == '.':
            a += 1
            c = '#'
        else:
            c = S[i]

    b = 0
    c = S[-1]
    for i in range(N - 2, -1, -1):
        if c == '.' and S[i] == '#':
            b += 1
            c = '.'
        else:
            c = S[i]

    print(min(a, b))
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

cnt1 = 0
S1 = S.copy()
for i in range(N-1):
    if (S1[i] == "#" and S1[i+1] == "."):
        cnt1 += 1
        S1[i+1] = "#"

S2 = S.copy()
S2 = list(reversed(S2))
cnt2 = 0
for i in range(N-1):
    if (S2[i] == "#" and S2[i+1] == "."):
        cnt2 += 1
        S2[i] = "."



print(min(cnt1, cnt2))

Submission status: Wrong Answer

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

cnt1 = 0
S1 = S.copy()
for i in range(N-1):
    if (S1[i] == "#" and S1[i+1] == "."):
        cnt1 += 1
        S1[i+1] = "#"

S2 = S.copy()
cnt2 = 0
for i in range(N-1):
    if (S2[i] == "#" and S2[i+1] == "."):
        cnt2 += 1
        S2[i] = "."
        
        

print(min(cnt1, cnt2))

Submission status: Wrong Answer

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

cnt1 = 0
S1 = S.copy()
for i in range(N-1):
    if (S1[i] == "#" and S1[i+1] == "."):
        cnt1 += 1
        S1[i+1] = "#"

S2 = S.copy()
cnt2 = 0
for i in range(N-1):
    if (S1[i] == "#" and S1[i+1] == "."):
        cnt1 += 1
        S1[i] = "."

print(min(cnt1, cnt2))

Submission status: Wrong Answer

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

cnt1 = 0
S1 = S.copy()
for i in range(N-1):
    if (S1[i] == "#" and S1[i+1] == "."):
        cnt1 += 1
        S1[i+1] = "#"

S2 = S.copy()
cnt2 = 0
for i in range(N-1):
    if (S2[-i-1] == "." and S2[-i-2] == "#"):
        S2[-i-1] = "#"
        cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Wrong Answer

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

cnt = 0

for i in range(N-1):
    if (S[i] == "#" and S[i+1] == "."):
        cnt += 1
        S[i+1] = "#"

print(cnt)

Submission status: Wrong Answer

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

for i in range(N-1):
    if S[i] == '#':
        for j in range(N-i-1):
            if S[i+j+1] == '.':
                c += 1
        break
    
    else:
        continue
                
print(c)

Submission status: Wrong Answer

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

for i in range(N-1):
    if S[i] == '#':
        for j in range(N-i-1):
            if S[i+j+1] == '.':
                c += 1
        break
    
    else:
        continue
                
print(c)

Submission status: Wrong Answer

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

for i in range(N):
    if S[i] == '#':
        for j in range(N-i-1):
            if S[i+j+1] == '.':
                c += 1
        break
    
    else:
        continue
                
print(c)

Submission status: Wrong Answer

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

for i in range(N):
    if S[i] == '#':
        for j in range(N-i-1):
            if S[i+j+1] == '.':
                c += 1
    break
                
print(c)

Submission status: Wrong Answer

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

for i in range(N):
    if S[i] == '#':
        for j in range(N-i):
            if S[i+j] == '.':
                c += 1
    break
                
print(c)

Submission status: Wrong Answer

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

w = S.count(".")
b = S.count("#")

if w == N or b == N:
  print(0)
  exit()
  
h = S[S.index("#"):].count(".")
ans = min(w, b, h)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

    # ???.#### ---> ???.
    i = N - 1
    while 0 <= i:
        if S[i] == ".":
            break
        else:
            i -= 1
    S = S[:i + 1]

    ans = 0
    i = 0
    while i < len(S) - 1:
        if S[i] == "#" and S[i + 1] == ".":
            ans += 1
            i += 2
        elif S[i] == S[i + 1] == "#":
            n_black = S[i:].count("#")
            n_white = S[i:].count(".")
            ans += min(n_black, n_white)
            break
        else:
            i += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

    ans = 0
    i = 0
    while i < N - 1:
        if S[i] == "#" and S[i + 1] == ".":
            ans += 1
            i += 2
        elif S[i] == S[i + 1] == "#":
            n_black = S[i:].count("#")
            n_white = S[i:].count(".")
            ans += min(n_black, n_white)
            break
        else:
            i += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

    ans = 0
    i = 0
    while i < N - 1:
        if S[i] == "#" and S[i + 1] == ".":
            ans += 1
            i += 2
        else:
            i += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

from copy import deepcopy
n = int(input())
s = list(input())
t = deepcopy(s)
t1 = 0
for i in range(n - 1):
    if s[i] == '#' and s[i + 1] == '.':
        t1 += 1
        s[i + 1] = '#'

t2 = 0
for i in range(1, n)[::-1]:
    if t[i - 1] == '#' and t[i] == '.':
        t2 += 1
        t[i - 1] = '.'
ans = min(t1, t2)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

from copy import deepcopy
n = int(input())
s = list(input())
t = deepcopy(s)
t1 = 0
for i in range(n - 1):
    if s[i] == '#' and s[i + 1] == '.':
        t1 += 1
        s[i + 1] = '#'

t2 = 0
for i in range(n - 1)[::-1]:
    if t[i] == '#' and t[i + 1] == '.':
        t2 += 1
        t[i] = '.'
ans = min(t1, t2)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

from copy import deepcopy
n = int(input())
s = list(input())
t = deepcopy(s)
t1 = 0
for i in range(n - 1):
    if s[i] == '#' and s[i + 1] == '.':
        t1 += 1
        s[i + 1] = '#'

t2 = 0
for i in range(n - 1):
    if t[i] == '#' and t[i + 1] == '.':
        t2 += 1
        t[i] = '.'
ans = min(t1, t2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = '.' + read().rstrip().decode() + '#'
index1 = s.index('#')
index2 = n + 2 - s[::-1].index('.')
print(min(s[index1:index2].count('#'), s[index1:index2].count('.')))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = '.' + read().rstrip().decode() + '#'
index1 = s.index('#')
index2 = n - s[::-1].index('.')
print(min(s[index1:index2].count('#'), s[index1:index2].count('.')))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = read().rstrip().decode()
index = n - 1
for i, ss in enumerate(s):
    if ss == '#':
        index = i
        break
print(min(s[index:].count('#'), s[index:].count('.')))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = read().rstrip().decode()
print(s.count('#.'))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import sys
sys.setrecursionlimit(10**7)
def main():
  n=int(input())
  s=input()
  sw,sb=[0],[0]
  w,b=0,0
  for si in s:
    if si=='#':
      b+=1
    else:
      w+=1
    sw.append(w)
    sb.append(b)
  ans=n
  for i in range(n+1):
    ans=min(ans,sb[n]-sb[i]+sw[i])
  print(ans)
if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

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

print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(str(input()))
count1,count2 = 0,0
j = 0
for i in range(N-1,-1,-1):
  if S[i] == "#":
    j = i
    break
count1 = S[:j+1].count("#")
for i in range(1,N):
  if S[i-1] == "#" and S[i] == ".":
    count2 += 1
    S[i] = "#"

print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(str(input()))
count = 0
for i in range(1,N):
  if S[i-1] == "#" and S[i] == ".":
    count += 1
    S[i] = "#"

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = str(input())
S = list(s[i] for i in range(N))

test = S
countf = 0

if S == list(sorted(S)[::-1]):
    print(0)

else:
    while len(test) != 0:
        a = test.index("#")
        test[a] = "."
        countf += 1
        #print(test)
        del test[0:a+1]
        #print(test)
        if len(test) == 1 or len(test) == 0:
            countf -= 1
            break
        test.reverse()
        b = test.index(".")
        test[b] = "#"
        countf += 1
        #print(test)
        del test[0:b+1]
        #print(test)
        test.reverse()
        if len(test) == 1 or len(test) == 0:
            countf -= 1
            break

    print(countf)

Submission status: Wrong Answer

Solution code:
n=int(input())

s=list(input())

black = [0]*n

white = [0]*n

for i in range(n):
    if s[i] == '.':
        white[i] = white[i-1]+1
        black[i] = black[i-1]
    else:
        white[i] = white[i-1]
        black[i] = black[i-1]+1
        
ans = 100000000

for i in range(n-1):
    if s[i] != s[i+1]:
        ans = min(ans,black[i]+(white[-1]-white[i+1]))
        
if ans == 100000000:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

s=list(input())

black = [0]*n

white = [0]*n

for i in range(n):
    if s[i] == '.':
        white[i] = white[i-1]+1
        black[i] = black[i-1]
    else:
        white[i] = white[i-1]
        black[i] = black[i-1]+1
        
ans = 100000000

for i in range(n-1):
    if s[i] != s[i+1]:
        ans = min(ans,black[i]+(white[-1]-white[i]))
        
if ans == 100000000:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# ed ans
n = int(input())
s = input()

# i について，whiteとblackの個数を見て最小

# 全部白，全部黒にする
# ans1 = s.count(".")
ans2 = s.count("#")

# wwwbbbbbの形にする
# 初期
ans = int(1e18)
black_left = 0
white_right = s.count(".")
# print(0, black_left, white_right, ans)

for ch in s:
    if ch == '#':
        black_left += 1
    else:
        white_right -= 1
    ans = min(ans, black_left + white_right)
    # print(i, black_left, white_right, ans)

print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
# ed ans
n = int(input())
s = input()

# i について，whiteとblackの個数を見て最小

# 全部白，全部黒にする
# ans1 = s.count(".")
ans2 = s.count("#")

# wwwbbbbbの形にする
# 初期
ans = int(1e18)
black_left = 1 if s[0] == '#' else 0
white_right = s[1:].count(".")
# print(0, black_left, white_right, ans)

for i in range(1, n):
    if s[i] == '#':
        black_left += 1
    else:
        white_right -= 1
    ans = min(ans, black_left + white_right)
    # print(i, black_left, white_right, ans)

print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
C = [0] * (N + 1)

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


# print(C)

j = N
count = 0
while j > 0:
    jj = j - 1
    while jj >= 0 and C[jj] == C[j]:
        jj -= 1
    
    if jj >= 0 and jj < j - 1:
        count += j - jj - 1

    # print(j, jj)
    j = jj

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = []
string = s[0]
cnt = 0
for i in range(n):
    if string == s[i]:cnt +=1
    else:
        l.append((string, cnt))
        string, cnt = s[i], 1

l.append((string, cnt))
#print(l)
WorB = [0, 0]
dic = {'.':0, '#':1}
for i in range(len(l)):
    if i == 0 and l[0][0] == '.':continue
    if i == n - 1 and l[-1][0] == '#':continue
    temp, num = l[i]
    WorB[dic[temp]] += num

print(min(WorB))

Submission status: Wrong Answer

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

l = []
string = s[0]
cnt = 0
for i in range(n):
    if string == s[i]:cnt +=1
    else:
        l.append((string, cnt))
        string, cnt = s[i], 1

l.append((string, cnt))
#print(l)
string = l[0]
ans = 0
for str, i in l:
    if string[0] == '#' and str == '.':
        ans += min(i, string[1])
        string = ('.', 0)
    else:
        string = (str, i)
print(ans)

Submission status: Wrong Answer

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

l = []
string = s[0]
cnt = 0
for i in range(n):
    if string == s[i]:cnt +=1
    else:
        l.append((string, cnt))
        string, cnt = s[i], 1

l.append((string, cnt))
#print(l)
string = ('.', 0)
ans = 0
for str, i in l:
    if string[0] == '#' and str == '.':
        ans += min(i, string[1])
        string = ('.', 0)
    else:
        string = (str, i)
print(ans)

Submission status: Wrong Answer

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

right_white = S.count(".")
left_black = 0

ans = float("inf")
for i in range(N):
    if S[i] == ".":
        right_white -= 1
    else:
        left_black += 1
    ans = min(ans, right_white+left_black)

print(ans)

Submission status: Wrong Answer

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

white = []
black = []
tmp_white = 0
tmp_black = 0

for i in range(N):
    if S[i] == ".":
        tmp_white += 1
        if tmp_black > 0:
            black.append(tmp_black)
            tmp_black = 0
    else:
        tmp_black += 1
        if tmp_white > 0:
            white.append(tmp_white)
            tmp_white = 0

if tmp_black > 0:
    black.append(tmp_black)

if tmp_white > 0:
    white.append(tmp_white)

if S[0] == ".":
    white = white[1:]

if S[-1] == "#":
    black = black[:-1]

print(min(sum(white), sum(black)))

Submission status: Wrong Answer

Solution code:
n=int(input())
S=[0 if i=='.' else 1 for i in input()]
if sum(S)==0 or sum(S)==n:
    print(0)
    exit()
Skai=[]
tmp=0
for i in range(n):
    if S[i]==1:
        if tmp==0:
            Skai.append(0)
        tmp+=1
    if S[i]==0:
        if tmp!=0:
            Skai.append(tmp)
        tmp=0
        if i==n-1:
            Skai.append(0)
ans2=sum(Skai)-Skai[-1]

start=0
for i in range(n):
    if S[i]==1:
        start=i
        break

newS=S[start:]
ans=0
for s in newS:
    if s==0:
        ans+=1
print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
n=int(input())
S=[0 if i=='.' else 1 for i in input()]
if sum(S)==0 or sum(S)==n:
    print(0)
    exit()

start=0
for i in range(n):
    if S[i]==1:
        start=i
        break

S=S[start:]
ans=0
for s in S:
    if s==0:
        ans+=1
if len(S)-ans>=0:
    print(min(ans, len(S)-ans))
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=[0 if i=='.' else 1 for i in input()]
if sum(S)==0 or sum(S)==n:
    print(0)
    exit()

start=0
for i in range(n):
    if S[i]==1:
        start=i
        break

S=S[start:]
ans=0
for s in S:
    if s==0:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w = 0
res = 0
save = 0
b = 0
for s in reversed(S):
  if s == '.':
    if 0 < b:
      res += min(save, b)
      b = 0
      save = 0
      w = 0
    w += 1
  else:
    if 0 < w:
      save = w
      b += 1

if s == '#':
  res += min(save, b)

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w = 0
res = 0
for s in reversed(S):
  if s == '.':
    w += 1
  else:
    res += w
    w = 0
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input() #sys.stdin.readlineは最後が改行

ans1 = s.count('.')
ans2 = s.count('#')

ans = 0
tmp = 0
for i in reversed(range(n)):
    if s[i] == '.':
        tmp+=1
    elif s[i] == '#':
        ans += tmp
        tmp = 0

print(min(ans1,ans2,ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input() #sys.stdin.readlineは最後が改行

ans = 0
tmp = 0
for i in reversed(range(n)):
    if s[i] == '.':
        tmp+=1
    elif s[i] == '#':
        ans += tmp
        tmp = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    S = input()
    D = Counter(S)

    cnt = 0
    for i in reversed(range(n)):
        if S[i] == "#":
            cnt += 1
        else:
            break

    print(min(D["#"] - cnt, D["."]))


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    if N == 1:
        print(0)
    else:
        S = list(input())

        B = [0] * N
        W = [0] * N

        cntb = 0
        cntw = 0
        for i in range(N):
            if S[i] == '#':
                cntb += 1
                B[i] = cntb
                W[i] = cntw
            else:
                cntw += 1
                B[i] = cntb
                W[i] = cntw
        if cntb == N or cntb == 0:
            print(0)
        else:

            B = [0] + B
            W = [0] + W

            ans = 10 ** 9
            for i in range(1, N + 1):
                if i!=N:
                    ans = min(ans, B[i] + W[-1] - W[i])
                else:
                    ans=min(ans, B[i] + W[-1] - W[-2])
            print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    if N == 1:
        print(0)
    else:
        S = list(input())

        B = [0] * N
        W = [0] * N

        cntb = 0
        cntw = 0
        for i in range(N):
            if S[i] == '#':
                cntb += 1
                B[i] = cntb
                W[i] = cntw
            else:
                cntw += 1
                B[i] = cntb
                W[i] = cntw
        if cntb == N or cntb == 0:
            print(0)
        else:

            B = [0] + B + [cntb]
            W = [0] + W + [cntw]

            ans = 10 ** 9
            for i in range(1, N + 2):
                ans = min(ans, B[i] + W[-1] - W[i])
            print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    if N == 1:
        print(0)
    else:
        S = list(input())

        B = [0] * N
        W = [0] * N

        cntb = 0
        cntw = 0
        for i in range(N):
            if S[i] == '#':
                cntb += 1
                B[i] = cntb
                W[i] = cntw
            else:
                cntw += 1
                B[i] = cntb
                W[i] = cntw
        if cntb==N or cntb==0:
            print(0)
        else:

            B = [0] + B
            W = [0] + W

            ans = 10 ** 9
            for i in range(1, N + 1):
                ans = min(ans, B[i] + W[-1] - W[i])
            print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    if N == 1:
        print(0)
    else:
        S = list(input())

        B = [0] * N
        W = [0] * N

        cntb = 0
        cntw = 0
        if cntb==N or cntb==0:
            print(0)
        else:
            for i in range(N):
                if S[i] == '#':
                    cntb += 1
                    B[i] = cntb
                    W[i] = cntw
                else:
                    cntw += 1
                    B[i] = cntb
                    W[i] = cntw
            B = [0] + B
            W = [0] + W

            ans = 10 ** 9
            for i in range(1, N + 1):
                ans = min(ans, B[i] + W[-1] - W[i])
            print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    if N==1:
        print(0)
    else:
        S = list(input())

        B=[0]*N
        W=[0]*N

        cntb=0
        cntw=0
        for i in range(N):
            if S[i]=='#':
                cntb+=1
                B[i]=cntb
                W[i]=cntw
            else:
                cntw+=1
                B[i]=cntb
                W[i]=cntw
        B=[0]+B
        W=[0]+W

        ans=10**9
        for i in range(1,N+1):
            ans=min(ans,B[i]+W[-1]-W[i])
        print(ans)






resolve()

Submission status: Wrong Answer

Solution code:
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    S = list(input())

    B=[0]*N
    W=[0]*N

    cntb=0
    cntw=0
    for i in range(N):
        if S[i]=='#':
            cntb+=1
            B[i]=cntb
            W[i]=cntw
        else:
            cntw+=1
            B[i]=cntb
            W[i]=cntw
    B=[0]+B
    W=[0]+W

    ans=10**9
    for i in range(1,N+1):
        ans=min(ans,B[i]+W[-1]-W[i])
    print(ans)






resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N=int(input())
    S=list(input())
    cnt=0
    flag=False
    for i in range(N):
        if S[i]=='#':
            flag=True
        else:
            if flag==True:
                cnt+=1
                flag=False
    print(cnt)

resolve()

Submission status: Wrong Answer

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

key = [False]*n

ans1 = 0
for i in range(1, n):
  if (s[i-1] == "#" or key[i-1]) and s[i] == "." :
    ans1 += 1
    key[i] = True

ans2 = 0
for i in range(n-1, 0, -1):
  if (s[i] == "." or key[i]) and s[i-1] == "#":
    ans2 += 1
    key[i-1] = True

print(min([ans1, ans2]))

Submission status: Wrong Answer

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

key = [False]*n

ans = 0
for i in range(1, n):
  if (s[i-1] == "#" or key[i-1]) and s[i] == "." :
    ans += 1
    key[i] = True

print(ans)

Submission status: Wrong Answer

Solution code:
from copy import copy

def rewrite_B(S):
    output = 0
    for i in range(1,len(S)):
        if S[i-1] == "B" and S[i] == "W":
            S[i] = "B"
            output += 1
    return output

def rewrite_W(S):
    output = 0
    for i in reversed(range(1,len(S))):
        if S[i-1] == "B" and S[i] == "W":
            S[i-1] = "W"
            output += 1
    return output

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

for i in range(N):
    if S[i] == ".":
        S[i] = "W"
    else:
        S[i] = "B"

a,b = rewrite_B(copy(S)),rewrite_W(copy(S))
print(min(a,b))

Submission status: Wrong Answer

Solution code:
from copy import copy

def rewrite_B(S):
    output = 0
    for i in range(1,len(S)):
        if S[i-1] == "B" and S[i] == "W":
            S[i] = "B"
            output += 1
    return output

def rewrite_W(S):
    output = 0
    for i in reversed(range(1,len(S))):
        if S[i-1] == "B" and S[i] == "W":
            S[i-1] = "W"
            output += 1
    return output

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

for i in range(N):
    if S[i] == ".":
        S[i] = "W"
    else:
        S[i] = "B"

S1,S2 = copy(S),copy(S)
print(min(rewrite_B(S1),rewrite_W(S2)))

Submission status: Wrong Answer

Solution code:
from copy import copy

def rewrite(S,c):
    output = 0
    for i in range(1,len(S)):
        if S[i-1] == "B" and S[i] == "W":
            if c == "B":
                S[i-1] = "W"
            else:
                S[i] = "B"
            output += 1
    return output

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

b,w = 0,0
for i in range(N):
    if S[i] == ".":
        S[i] = "W"
        w += 1
    else:
        S[i] = "B"
        b += 1

S1,S2 = copy(S),copy(S)
print(min(rewrite(S1,"W"),rewrite(S2,"B")))