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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *


N = INT()
S = input()

b = [0]*(N-1)
w = [0]*(N-1)

tmp_b = 0
for i in range(N-1):
	if S[i] == "#":
		tmp_b += 1
	else:
		tmp_b = 0
	b[i] = tmp_b

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

ans = [min(b[i], w[i]) for i in range(N-1)]

#print(b)
#print(w)
#print(ans)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *


N = INT()
S = input()

ans = 0
l = 0
for r in range(1, N):
	if S[r-1] == "." and S[r] == "#":
		ans += min(S[l:r].count("."), S[l:r].count("#"))
		l = r
	elif r == N-1:
		ans += min(S[l:].count("."), S[l:].count("#"))

print(ans)

Submission status: Wrong Answer

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

w1=[0 for i in range(n+1)]
b1=[0 for i in range(n+1)]

for i in range(1,n+1):
    w1[i]=w1[i-1]
    b1[i]=b1[i-1]
    if s[i-1]=='.':
        w1[i]+=1
    else:
        b1[i]+=1
        
#w1.pop(0)
#print(w1)

s=s[::-1]
w2=[0 for i in range(n+1)]
b2=[0 for i in range(n+1)]

for i in range(1,n+1):
    w2[i]=w2[i-1]
    b2[i]=b2[i-1]
    if s[i-1]=='.':
        w2[i]+=1
    else:
        b2[i]+=1

#b2.pop(0)
b2=b2[::-1]
#print(b2)

ans=10**10
for i in range(n):
    ans=min(ans,w1[i]+b2[i])

print(ans)

Submission status: Wrong Answer

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

w1=[0 for i in range(n+1)]
b1=[0 for i in range(n+1)]

for i in range(1,n+1):
    w1[i]=w1[i-1]
    b1[i]=b1[i-1]
    if s[i-1]=='.':
        w1[i]+=1
    else:
        b1[i]+=1
        
w1.pop(0)
#print(w1)

s=s[::-1]
w2=[0 for i in range(n+1)]
b2=[0 for i in range(n+1)]

for i in range(1,n+1):
    w2[i]=w2[i-1]
    b2[i]=b2[i-1]
    if s[i-1]=='.':
        w2[i]+=1
    else:
        b2[i]+=1

b2.pop(0)
b2=b2[::-1]
#print(b2)

ans=10**10
for i in range(n):
    ans=min(ans,w1[i]+b2[i])

print(ans)

Submission status: Wrong Answer

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

def ranlength(A):
    num = list(A)
    count = 1
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                table.append(count)
                count = 1
        except:
            table.append(count)
    return(table)

r=ranlength(s)

if s[0]=='.':
    r.pop(0)
if s[-1]=='#':
    r.pop()

cnt=0
for i in range(len(r)//2):
    cnt+=min(r[2*i],r[2*i+1])

print(cnt)

Submission status: Wrong Answer

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

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

#print(cnt1)


cnt2=0
s=s[::-1]
for i in range(1,n):
    if s[i-1]=='.' and s[i]=='#':
        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

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input());a=[0];b=[0]
for i in input():t=i=='.';a+=[a[-1]+t];b+=[b[-1]+1-t];
print(min([b[i]+a[n]-a[i]for i in range(n)]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())

if len(S) == 1:
    print(0)
    exit()

cnt_b = S.count("#")
cnt_w = N - cnt_b

ans_1 = cnt_w
ans_2 = 0
flag = False
for s in S:
    if s == ".":
        if flag:
            ans_2 += 1
    else:
        if not flag:
            flag = True

print(min(ans_1, ans_2))

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())

if len(S) == 1:
    print(0)
    exit()

cnt_b = S.count("#")
cnt_w = N - cnt_b

ans_1 = cnt_b
ans_2 = 0
flag = False
for s in S:
    if s == ".":
        if flag:
            ans_2 += 1
    else:
        if not flag:
            flag = True
            
print(min(ans_1, ans_2))

Submission status: Wrong Answer

Solution code:
import sys
from itertools import groupby
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())

S_rep = ""
cnt = []
for k, v in groupby(S):
    S_rep += k
    cnt.append(len(list(v)))

ans_b = 0
ans_w = 0
for i in range(len(S_rep) - 1):
    if S_rep[i] + S_rep[i + 1] == "#.":
        ans_w += cnt[i]
        ans_b += cnt[i + 1]
print(min(ans_b, ans_w))

Submission status: Wrong Answer

Solution code:
import sys
from itertools import groupby
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())

S_rep = ""
cnt = []
for k, v in groupby(S):
    S_rep += k
    cnt.append(len(list(v)))
# print(S_rep)
# print(cnt)
ans = 0
for i in range(len(S_rep) - 1):
    if S_rep[i] + S_rep[i + 1] == "#.":
        if cnt[i] <= cnt[i + 1]:
            ans += cnt[i]
        else:
            if i + 2 < len(S_rep):
                cnt[i + 2] += cnt[i + 1]
            ans += cnt[i + 1]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())
ans = 0
for i in range(N - 1):
    if S[i] + S[i + 1] == "#.":
        if 0 <= i - 1 and S[i - 1] == "#":
            S[i + 1] = "#"    
        else:
            S[i] = "."
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())
ans = 0
for i in range(N - 1):
    if S[i] + S[i + 1] == "#.":
        if S[i - 1] == "#":
            S[i + 1] = "#"    
        else:
            S[i] = "."
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())
ans = 0
for i in range(N - 1):
    if S[i] + S[i + 1] == "#.":
        if S[i - 1] == "#":
            S[i + 1] = "#"    
        else:
            S[i] == "."
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())
ans = 0
for i in range(N - 1):
    if S[i] + S[i + 1] == "#.":
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=input()
kuro=0
shiro=0

count=-1

for i in range(N):
    if A[i:i+2]=="#.": 
        count=i
        break
for i in range(N):
    if A[i]=="#":
        kuro+=1

for i in range(count+1,N):
    if A[i]==".":
        shiro+=1
if count==-1:
    print(0)
else:
    print(min(shiro,kuro))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=input()
kuro=0
shiro=0

count=0

for i in range(N):
    if A[i:i+2]=="#.": 
        count=i
        break
for i in range(N):
    if A[i]=="#":
        kuro+=1

for i in range(count+1,N):
    if A[i]==".":
        shiro+=1

print(min(shiro,kuro))

Submission status: Wrong Answer

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

count=0
for i in range(N):
    if A[i:i+2]=="#.":
        count+=1
        
print(count)

Submission status: Wrong Answer

Solution code:
import sys


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = list(input())
    numb = 0
    numw = S.count(".")
    answer = INF
    for i in range(N):
        if S[i] == "#":
            numb += 1
        else:
            numw -= 1
        if answer > numb + numw:
            answer = numb + numw

    print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = list(input())
    A = S.copy()
    B = S.copy()
    answer1 = 0
    for i in range(1, N):
        if A[i - 1] == "#" and A[i] == ".":
            A[i] = "#"
            answer1 += 1
    answer2 = 0
    for i in range(1, N):
        j = N - i - 1
        if B[j + 1] == "." and B[j] == "#":
            B[j] = "."
            answer2 += 1

    print(min(answer1, answer2))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = list(input())
    answer = 0
    for i in range(1, N):
        if S[i - 1] == "#" and S[i] == ".":
            S[i] = "#"
            answer += 1
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = float('inf')
L = [[0, s.count('.')]]
for i in range(n):
    if s[i] == '#':
        L.append([L[i][0]+1, L[i][1]])
    else:
        L.append([L[i][0], L[i][1]-1])
    ans = min(ans, L[-1][0] + L[-1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
n = int(input())
s = list(map(str, input().rstrip()))

if s.count("#") == 0 or s.count(".") == 0:
    print(0)
    sys.exit()

s = np.array([x == "#" for x in s])

dp = np.zeros([2, n], dtype=int)

# dp0は黒の数、dp0は白の数
dp[0] = s
dp[1] = ~s

dp = dp.cumsum(axis=1)

# 白の数は「それ以降の」と読み替える
dp[1] = dp[1].max() - dp[1]

print((dp[0] + dp[1]).min())

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
n = int(input())
s = list(map(str, input().rstrip()))

if s.count("#") == 0 or s.count(".") == 0:
    print(0)
    sys.exit()

s = np.array([x == "#" for x in s])

# 全部白くする作戦、全部黒くする作戦、途中から全部黒くする作戦を管理
dp = np.zeros([3, n], dtype=int)

dp[0] = s
dp[1] = ~s

dp = dp.cumsum(axis=1)

dp[2] = dp[0] + dp[1][::-1]

print(min(dp[0, -1], dp[1, -1], dp[2].min()))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
s = np.array(list(map(str, input().split())))

# 全部白くする作戦、全部黒くする作戦、途中から全部黒くする作戦を管理
dp = np.zeros([3, n], dtype=int)

for i in range(n):
    if s[0][i] == "#":
        dp[0, i] += 1
    else:
        dp[1, i] += 1

dp = dp.cumsum(axis=1)

dp[2] = dp[0] + dp[1][::-1]

print(min(dp[0, -1], dp[1, -1], dp[2].min()))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = s.find('#')
r = s.rfind('.')
if l<0 or r<0:
    print(0)
    exit()
a = len(list(filter(lambda x: x == '.', s[l:])))
b = len(list(filter(lambda x: x == '#', s[r::-1])))
print(min([a, len(s[l:])-a, b]))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = s.find('#')
if l<0:
    print(0)
    exit()
a = len(list(filter(lambda x: x == '.', s[l:])))
print(min(a, len(s[l:])-a))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = s.find('#')
if l<0:
    print(0)
    exit()
a = len(list(filter(lambda x: x == '.', s[l:])))
print(min(a, n-a))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = len(list(filter(lambda x: x == '.', s)))
print(min(a, n-a))

Submission status: Wrong Answer

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

# go all white
res = s.count("#")
res = min(res, s.count("."))


blacklist = []
for i in range(n):
    if s[i] == "#":
        blacklist.append(i)

ll = len(blacklist)
#print(blacklist, ll, res)
for i in range(len(blacklist)):
    need = n - i - 1 - (ll- (i + 1))
    res = min(res, need)



print(res)

Submission status: Wrong Answer

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

# go all white
res = s.count("#")
res = min(res, s.count("."))

# go all black from first kuro
for i in range(n):
    if s[i] == "#":
        #
        cnt = 0
        for j in range(i, n):
            if s[j] == ".":
                cnt += 1
        res = min(res, cnt)


        break

print(res)

Submission status: Wrong Answer

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

# go all white
res = s.count("#")

# go all black from first kuro
for i in range(n):
    if s[i] == "#":
        cnt = 0
        for j in range(i, n):
            if s[j] == ".":
                cnt += 1
        res = min(res, cnt)
        break

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cou = 0
if "#" not in s or "." not in s :
  print(0)
else:
  a = s.index("#")
  s_r = s[::-1]
  a1 = s_r.index(".")
  a3 = n-a1
  s1 = s[a:a3]
  b = s1.count(".")
  c = s1.count("#")
#  print(a,a3,b,c)
  print(min(b,c))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cou = 0
if "#" not in s:
  print(0)
else:
  a = s.index("#")
  s1 = s[a:]
  b = s1.count(".")
  c = s1.count("#")
  print(min(b,c))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
rw = s.count(".")
lb = 0
M = float("inf")
for i in range(n):
    if s[i] =="#":
        lb += 1
    else:
        rw -= 1
    M = min(M,rw+lb)
print(M)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
while s[-1] == "#" :
    s.pop()
    if not s:
        print(0)
        exit()
s = "".join(s)
n = len(s)
data = []
ind = []
cnt = 0
ans = 0
for i in range(n):
    if s[i] == "#":
        cnt += 1
        ind.append(i)
    data.append(cnt)
if not ind:
    print(0)
    exit()
for i in ind:
    m = data[-1]-data[i]+1
    l = n-m-i
    if l > m:
        ans += 1
    else:
        print(ans+l)
        break
else:
    print(ans)

Submission status: Wrong Answer

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

W=[1 if S[0]=="." else 0]
ans=float("inf")

for i in range(1,N):
  if S[i]==".":
    W.append(W[-1]+1)
  else:
    W.append(W[-1])
    
if W[-1]==0 or W[-1]==N:
  print(0)
  exit()

for i in range(N):
  cost_W = i+1-W[i]
  cost_B = W[-1]-W[i]
  cost=cost_W+cost_B
  #print(N, W[-1], i+1, W[i])
  #print(i,"cost_W:",cost_W,"cost_B:",cost_B,"Total",cost)
  ans=min(ans,cost)
print(ans)

Submission status: Wrong Answer

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

if N==1:
  print(0)
  exit()
else:
  W=[1 if S[0]=="." else 0]
  ans=float("inf")

  for i in range(1,N):
    if S[i]==".":
      W.append(W[-1]+1)
    else:
      W.append(W[-1])
      
  if W[-1]==0 or W[-1]==N:
    print(0)
    exit()

  for i in range(N):
    cost_W = i+1-W[i]
    cost_B = W[-1]-W[i]
    cost=cost_W+cost_B
    #print(N, W[-1], i+1, W[i])
    #print("cost_W:",cost_W,"cost_B:",cost_B,"Total",cost)
    ans=min(ans,cost)
  print(ans)

Submission status: Wrong Answer

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

if N==1:
  print(0)
  exit()
else:
  W=[1 if S[0]=="." else 0]
  ans=float("inf")

  for i in range(1,N):
    if S[i]==".":
      W.append(W[-1]+1)
    else:
      W.append(W[-1])
      
  if W[-1]==0 or W[-1]==N:
    print(0)
    exit()

  for i in range(N):
    cost_W = i+1-W[i]
    cost_B = W[-1]-W[i]
    cost=cost_W+cost_B
    #print(N, W[-1], i+1, W[i])
    #print("cost_W:",cost_W,"cost_B:",cost_B,"Total",cost)
    ans=min(ans,cost)
    print(ans)

Submission status: Wrong Answer

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

if N==1:
  print(0)
  exit()
else:
  W=[1 if S[0]=="." else 0]
  ans=float("inf")

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

  for i in range(N):
    cost_W = i+1-W[i]
    cost_B = W[-1]-W[i]
    cost=cost_W+cost_B
    #print(N, W[-1], i+1, W[i])
    #print("cost_W:",cost_W,"cost_B:",cost_B,cost)
    ans=min(ans,cost)
  
print(ans)

Submission status: Wrong Answer

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

W=[1 if S[0]=="." else 0]
ans=float("inf")

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

for i in range(N):
  cost_W = i+1-W[i]
  cost_B = W[-1]-W[i]
  cost=cost_W+cost_B
  #print(N, W[-1], i+1, W[i])
  #print("cost_W:",cost_W,"cost_B:",cost_B,cost)
  ans=min(ans,cost)
  
print(ans)

Submission status: Wrong Answer

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

if N==1:
  print(0)
  exit()
else:
  div=[]
  cnt=1
  for i in range(1,N):
    if i==N-1:
      if S[i]==S[i-1]:
        cnt +=1
        div.append(cnt)
      else:
        div.append(cnt)
        div.append(1)
    else:
      if S[i]==S[i-1]:
        cnt +=1
      else:
        div.append(cnt)
        cnt=1
  #print(div)
        
  if S[0]=="#":
    p=sum(div[0:N-2:2]) #黒
    q=sum(div[1:N:2]) #白
  else:
    p=sum(div[1:N-2:2]) #黒
    q=sum(div[2:N:2]) #白
  print(min(p,q))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = 0
w = 0
fb = 0
fw = 0
cnt = 0
for i in range(n):
    if s[i]=='#':
        if fw ==0:
            fb = 1
            b+=1
        else:
            cnt+=min(b,w) 
            fw=0
            w = 0
            fb=1
            b=1
    else:
        if fb==1:
            fw =1
            w +=1
else:
    if fw==1:
        cnt+=min(b,w)
print(cnt)

Submission status: Wrong Answer

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

w = [0 for _ in range(N)]
b = [0 for _ in range(N)]

mark = []
f = 0

for i in range(N):
    if S[i] == "#":
        f = 1
        b[i] += 1
    else:
        if f:
            mark.append(i-1)
            f = 0
        w[i] += 1

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

for i in range(N):
    w_r[i+1] += w[i] + w_r[i]
    b_r[i+1] += b[i] + b_r[i]

ans = 0
if mark:
    ans = float("inf")
# print(w_r)
# print(b_r)
# print(mark)
for i in mark:
    ans = min(ans, b_r[i]+w_r[-1]-w_r[i])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
S1 = S.copy()
S.reverse()
S2 = S.copy()

f = 0
ans1 = 0

for i in range(N):
    if S1[i] == "#":
        f = 1
    else:
        if f:
            ans1 += 1
            S1[i] = "#"

ans2 = 0
f = 0

for i in range(N):
    # print(S2[i])
    if S2[i] == ".":
        f = 1
    else:
        if f:
            ans2 += 1
            S2[i] = "."
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = 0
w = s.count(".")
l = []
for i in range(1, n + 1):
    if s[i - 1] == "#":
        b += 1
    if s[i - 1] == ".":
        w -= 1
    l.append(b + w)
print(min(l))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = 0
w = s.count(".")
l = []
for i in range(1, n):
    if s[i - 1] == "#":
        b += 1
    if s[i - 1] == ".":
        w -= 1
    l.append(b + w)
l.append(b)
print(min(l))

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    S = input()[:-1]

    l = 0
    r = 0
    for i in range(N):
        if S[i] == ".":
            r += 1
    
    ans = INF
    for i in range(N):
        if S[i] == "#":
            l += 1
        else:
            r -= 1
        ans = min(ans, l + r)
    
    print(ans)
    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input());s=input()
b=0
w=s.count('.')
ans=n
for si in s:
  b+=(si=='#')
  w-=(si=='.')
  ans=min(ans,b+w)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s = S.replace('.#', '.0#').replace('#.', '#0.').split('0')

m = len(s)
p0 = s[0]
p1 = False
ans = 0

for i in range(1, m):
    if not p1:
        if i >= m - 1 and s[i][0] == '#':continue
        if i >= m - 1 and s[i][0] == '.':
            ans += min(len(s[i]), len(p0))
        p1 = s[i]
        continue
    if p0[0] == '#' and p1[0] == '.' and s[i][0] == '#':
        if len(p0) > len(p1):
            ans += len(p1)
            p0 = '#' * (len(p0) + len(p1) + len(s[i]))
            p1 = False
        else:
            ans += len(p0)
            p0 = '.' * (len(p0) + len(p1))
            p1 = s[i]
    elif p0[0] == '.' and p1[0] == '#' and s[i][0] == '.':
        if len(p1) >= len(s[i]):
            ans += len(s[i])
            p1 = '#' * (len(p1) + len(s[i]))
        else:
            ans += len(p1)
            p0 = '.' * (len(p0) + len(p1) + len(s[i]))
            p1 = False
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
s = readline().rstrip().decode('utf-8')
res = s.count(".")
res2 = res
ans = 10**10
for i in range(n):
    if s[i] == "#":
        res2 += 1
    else:
        res2 -= 1
    ans = min(res,res2)

print(ans)

Submission status: Wrong Answer

Solution code:

        
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
s = readline().rstrip().decode('utf-8')
res = 0
ans = 10**9
flag = 0
for i in range(n):
    if flag:
        if s[i] == "#":
            res += 1
    elif i+1 < n and s[i] == "#" and s[i+1] == ".":
        flag = 1
        res += 1

ans = min(ans,res)

res = 0
flag = 0
for i in range(n-1,-1,-1):
    if flag:
        if s[i] == ".":
            res += 1
    elif i-1 >= 0 and s[i] == "." and s[i-1] =="#":
        flag = 1
        res += 1
ans = min(ans,res)
print(ans)

Submission status: Wrong Answer

Solution code:
"""
#の右に.が無いようにしたい
一番左にある#.もしくは一番右にある#の部分
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
s = readline().rstrip().decode('utf-8')
res = 0
for i in range(n-1):
    if s[i] == "#":
        if s[i+1] == ".":
            res = i+1
            break
count = 0
if res:
    for i in range(res,n):
        if s[i] == ".":
            count += 1

ans = count
res = n-1
for i in range(n-1,0,-1):
    if s[i] == ".":
        if s[i-1] == "#":
            res = i-1
            break
count = 0
if res != n-1:
    for i in range(res,-1,-1):
        if s[i] == "#":
            count += 1

print(min(ans,count))

Submission status: Wrong Answer

Solution code:
"""
#の右に.が無いようにしたい
一番左にある#.もしくは一番右にある#の部分
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
s = readline().rstrip().decode('utf-8')
ans = 10**9
res = 0
for i in range(n-1):
    if s[i] == "#":
        if s[i+1] == ".":
            res = i
            break

ans = min(ans,n-(1+res))

ans = min(ans,s.count("#"),s.count("."))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans1 = 0
flag = False

for s in S:
    if s == '#':
        flag = True
    if flag and s == '.':
        ans1 += 1

ans2 = 0
flag = False
cnt = 0
for s in S:
    if s == '#':
        cnt += 1
    else:
        ans2 += cnt
        cnt = 0

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
white = s.count(".")
black = s.count("#")

min_num = black
black_num = 0
for i, color in enumerate(s, start = 1):
    if color == "#":
        black_num += 1
    min_num = min(min_num, black_num + white - (i - black_num))
    
print(min_num)

Submission status: Wrong Answer

Solution code:
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    s = input()
    b = w = 0
    f = 0
    for i in range(N):
        if f == 0 and s[i] == '#': f = 1
        if f == 1 and s[i] == '.': w += 1
    f = 0
    for i in range(N):
        if f == 0 and s[-1-i] == '.': f = 1
        if f == 1 and s[-1-i] == '#': b += 1
    print(min(b, w))

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()

    white, black = 0, 1
    s = [int(i) for i in list(input().replace(".", "0").replace("#", "1"))]
    s.insert(0, 0)
    black_total = s.count(1)

    cnt = [0, 0]  # [white,black]
    ans = INF
    for i in range(n, 0, -1):
        # cnt[s[i]] += 1
        # if s[i] == 1 and s[i - 1] == 0:
        ans = min(ans, black_total - cnt[black] + cnt[white])
        cnt[s[i]] += 1

    print(ans if n != 1 else 0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()

    white, black = 0, 1
    s = [int(i) for i in list(input().replace(".", "0").replace("#", "1"))]
    s.insert(0, 0)
    black_total = s.count(1)

    cnt = [0, 0]  # [white,black]
    ans = INF
    for i in range(n, 0, -1):
        # cnt[s[i]] += 1
        # if s[i] == 1 and s[i - 1] == 0:
        ans = min(ans, black_total - cnt[black] + cnt[white])
        cnt[s[i]] += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = []
b = 0
w = s.count(".")
for i in range(n):
    if s[i] == "#":
        b += 1
    elif s[i] == ".":
        w -= 1
    l.append(b + w)
print(min(l))

Submission status: Wrong Answer

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

cnt = [s.count('.'), s.count('#')]

cnt0 = 0
cnt1 = 0
ans = float("inf")
for i in range(n):
    if s[i] == '.':
        cnt0 += 1
    if s[i] == '#':
        cnt1 += 1
    ans = min(ans, cnt1 + cnt[0] - cnt0)

if cnt[0] == 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

cnt = [s.count('.'), s.count('#')]

cnt0 = 0
cnt1 = 0
ans = float("inf")
for i in range(n):
    if s[i] == '.':
        cnt0 += 1
    if s[i] == '#':
        cnt1 += 1
    ans = min(ans, cnt1 + cnt[0] - cnt0)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
#======================================================#
def main():
    n = II()
    s = IS()
    cnt_b = 0
    cnt_w = s.count('.')
    cnt = float('inf')
    for si in s:
        if si == '#':
            cnt_b += 1
        else:
            cnt_w -= 1
        c = cnt_b+cnt_w
        if c < cnt:
            cnt = c
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    cnts = 0; cntd = 0; ans = 0
    S.append('#')
    for i in range(N+1):
        if cnts == 0 and S[i] == '.':
            continue
        if S[i] == '#' and cntd == 0:
            cnts += 1
        elif S[i] == '.':
            cntd += 1
        else:
            ans += min(cnts, cntd)
            cnts = 1
            cntd = 0
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from collections import Counter
#======================================================#
def main():
    n = II()
    s = IS()
    cnt_b = 0
    cnt_w = s.count('.')
    cnt = 2*10**5
    for si in s:
        if si == '#':
            cnt_b += 1
        else:
            cnt_w -= 1
        cnt = min(cnt, cnt_b+cnt_w)
    print(cnt)

if __name__ == '__main__':
    main()