Problem:


Score : 300 points

Problem Statement

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

3
#.#

Sample Output 1

1

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

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    s = input()
    start = 0
    end = N-1
    for c in s:
        if c == ".":
            start += 1
        else:
            break
    for c in s[::-1]:
        if c == "#":
            end -= 1
        else:
            break
    dot = 0
    has = 0
    for c in s[start:end+1]:
        if c == ".":
            dot += 1
        else:
            has += 1
    print(min(dot, has))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ret = 0
prev = None
i = 0
bs = 0
start = None
ws = 0

while i < n:
    if s[i] == '#':
        bs += 1
    else:
        if bs > 0:
            ws += 1
    i += 1


print(min(ws, bs))

Submission status: Wrong Answer

Solution code:
# C
n = int(input())
s = str(input())

dot = True
count_dot = 0
for i in range(n):
    if dot and s[i] == ".":
        continue
    else:
        dot = False
        if s[i] == ".":
            count_dot += 1
black_count = 0
for i in range(n):
    if s[i] == "#":
        black_count += 1
if s[n-1] == "#":
    for i in range(n):
        if s[-i] == "#":
            black_count -= 1
        else:
            break
    
print(min(count_dot, black_count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
S = raw_input()
flag1 = 0
a = 0
count = [0,0]
count2 = []
count3 = []
for c in S:
	if(c == "#"):
		count[0] += 1
		if(flag1 == 1):
			flag1 = 0
			count2.append(count[0])
			count3.append(count[1])
	else:
		count[1] += 1
		flag1 = 1
countf = []
for i in range(len(count2)):
	countf.append(count2[i] + count[1] - count3[i])
countf.append(N - count[0])
countf.append(N - count[1])
print(min(countf))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ctb=0;ctw=0;f=0;cte=0;cts=0

for j in range(n-1):
  if s[j]=='#' and s[j+1]=='.':
    f=+1
for k in range(n-1,-1,-1):
  if s[k]=='#':
    cte+=1
  else:
    break
for l in range(n):
  if s[l]=='.':
    cts+=1
  else:
    break

for i in range(cts,n-cte):
  if s[i]=='.':ctb+=1
  else:ctw+=1

if f==0:
  print(0)
else:
  print(min(ctb,ctw))

Submission status: Wrong Answer

Solution code:
N = int(input())
S =(list(input()))
newS=[]
for i in S:
    if i == ".":
        newS.append(0)
    else:
        newS.append(1)
before = 0
count = 0
finalS =[]
for i in newS:
    flag = i - before
    if flag < 0:
        finalS.append(1)
        count = count +1
        before = 1
    else:
        finalS.append(i)
        before = i

Submission status: Wrong Answer

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

m1=0
m2=0

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

m3=0
a=-1
flag=0

for i in range(n):
  if s[n-i-1] == '#':
    a=n-i-1
    flag=1
    continue
  if s[n-i-1] == '.' and flag == 1:
    break

for i in range(n):
  if a == -1:
    print(min(m1,m2))
    exit()
  if i<a:
    if s[i] == '#':
      m3+=1
  elif i>a:
    if s[i] == '.':
      m3+=1

print(min(m1,m2,m3))

Submission status: Wrong Answer

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

    white = 0
    black = 0
    color = ''
    counter = 0
    for i in range(n)[::-1]:
        if color != s[i]:
            if color == '.':
                white += counter
            else:
                black += counter
            counter = 0
        counter += 1
        color = s[i]

    if color == '#':
        black += counter

    if white * black == 0:
        print(0)
        return
    if white < black:
        print(white)
    else:
        print(black)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

for i in range(len(S)):
    if S[i] == '#':  # 最初の黒石以降と抜き出す
        S = S[i:]
        break
else:
    S = ''
S = S[::-1]
for i in range(len(S)):
    if S[i] == '.':
        S = S[i:]
        break
else:
    S = ''

b, w = 0, 0
for s in S:
    if s == '.':
        w += 1
    else:
        b += 1
print(min(w, b))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
cnt = 0

if '#' in s :
    i = s.index('#')
    cnt = min(s[i:].count('.'),s[i:N-1].count('#'))
print(cnt)

Submission status: Wrong Answer

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

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

s = s[t:]
white = s.count(".")
print(min(white, black))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
cnt = 0

if '#' in s :
    i = s.index('#')
    cnt = min(s[i:].count('.'),s[i:N-2].count('#'))
print(cnt)

Submission status: Wrong Answer

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

ans = float("inf")
ans = min(ans,s.count("#"))
bunsuirei = s.find("#")

if bunsuirei != -1:
  ans = min(ans,s[bunsuirei:].count("."))


print(ans)

Submission status: Wrong Answer

Solution code:
N, S = int(input()), input()
# print(N, S)
# left = sum(s for s in S if )
# left = 0
for l, s in enumerate(S):
    if s != '.':
        break
else:
    l += 1
# print(l)
for r, s in enumerate(S[::-1]):
    if s != '#':
        break
else:
    r += 1
r = len(S) - r
# print(r)
# print(S[l:r])

w_num = sum(True for s in S[l:r] if s == '#')
# print(w_num,r - l - w_num)
print(min(w_num,r - l - w_num))

Submission status: Wrong Answer

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

w = [0] * N
b = [0] * N
wc = 0
bc = 0
for i in range(N):
  if S[i] == "#":
    wc += 1
  w[i] = wc
for i in range(N - 1, -1, -1):
  if S[i] == ".":
    bc += 1
  b[i] = bc

Ans = 1000000
for i in range(N):
  t = 0
  if i > 1:
    t += w[i - 1]
  t += b[i]
  Ans = min(Ans, t)
print(Ans)

Submission status: Wrong Answer

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

white = 0
black = 0

for i in range(n):
    if s[i]=='#':
        for j in range(i,n):
            if s[j]=='.':
                white +=1
        break

for i in range(n):
    if s[n-i-1]=='.':
        for j in range(i,n):
            if s[n-j-1]=='#':
                black +=1
        break

print(min(white, black))

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7

# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

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

ret = 999999999999999
for d in range(N):
    cnt = 0
    for i in range(0, d):
        if S[i] == "#":
            cnt += 1
    for i in range(d, N ):
        if S[i] == ".":
            cnt += 1
    ret = min(cnt,ret)

print(ret)

Submission status: Wrong Answer

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

ans1 = 0
ans2 = 0
idx1 = 1e9
idx2 = 1e9

for i, ele in enumerate(s):
  if ele=="#":
    idx1 = i
    break

for i, ele in enumerate(s[::-1]):
  if ele==".":
    idx2 = i
    break

if idx1<len(s):
  for ele in s[idx1::]:
    if ele==".":
      ans1 += 1

if idx2<len(s):
  for ele in s[len(s)-idx2-1::-1]:
    if ele=="#":
      ans2 += 1

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import sys



fin = sys.stdin.readline
N = int(fin())
S = fin().rstrip("\n")
assert len(S) == N

# 満たしている状態での処理数
# min_changes_at = [[float('inf')] * 2 for _ in range(N)]
# min_changes_at[0] = [1, 0] if S[0] == BLACK else [0, 1]

# for i, color in enumerate(S[1:], start=1):
#     if color == "#":
#         min_changes_at[i][WHITE] = min(min_changes_at[i - 1]) + 1
#         min_changes_at[i][BLACK] = min(min_changes_at[i - 1])
#     else:  # WHITE
#         min_changes_at[i][WHITE] = min_changes_at[i - 1][WHITE]
#         min_changes_at[i][BLACK] = min(min_changes_at[i - 1]) + 1
# print(min_changes_at)
# print(min(min_changes_at[-1]))

WHITE, BLACK = ".", "#"
grouped_S = []
prev_color = S[0]
count = 1
for color in S[1:]:
    if prev_color != color:
        grouped_S.append((prev_color, count))
        count = 1
    else:
        count += 1
    prev_color = color

grouped_S.append((prev_color, count))

# print(grouped_S)
if grouped_S[0][0] == WHITE:
    grouped_S = grouped_S[1:]
if grouped_S and grouped_S[-1][0] == BLACK:
    grouped_S.pop()

print(min(sum(count for color, count in grouped_S if color == BLACK),
      sum(count for color, count in grouped_S if color == WHITE)))

Submission status: Wrong Answer

Solution code:
input()
st = input()
state = st[0]
lis = []
problem = 0
cnt = 0
for s in st:
    if s == state:
        cnt += 1
    else:
        problem += (state == '#') and (s == '.')
        state = s
        lis.append(cnt)
        cnt = 1
lis.append(cnt)

if problem:
    # #->.
    first = (st[0] == '.')
    if st[-1] == '#':
        res1 = sum(lis[first:-1:2])
    else:
        res1 = sum(lis[first::2])
    # .->#
    first = 2
    if st[0] == '#':
        first = 1
    res2 = sum(lis[first::2])
else:
    res1, res2 = 0, 0

print(min(res1, res2))

Submission status: Wrong Answer

Solution code:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
import queue
 
 
N = int(input())
S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
 
ch = False
ans = 0
bl  = 0
for s in S:
	if s == "#":
		ch = True
		bl += 1
	elif ch and s == ".":
		ans += 1
for s in S[::-1]:
	if s == "#":
		bl -= 1
	else:
		break
print(min(ans,bl))

Submission status: Wrong Answer

Solution code:
# C
n = int(input())
s = str(input())

dot = True
count_dot = 0
for i in range(n):
    if dot and s[i] == ".":
        continue
    else:
        dot = False
        if s[i] == ".":
            count_dot += 1
black_count = 0
for i in range(n):
    if s[i] == "#" and i != n-1:
        black_count += 1
print(min(count_dot, black_count))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
tem = -1
for cnt, item in enumerate(S):
  if item == "#":
    tem = cnt
    break
if tem == -1:
  print(0)
else:
  tem2 = 0
  for cnt in reversed(range(N)):
    if S[cnt] == "#":
      tem2 = cnt
      break
  an2 = S[:cnt].count("#")
  print(min(S[tem:].count("."), an2))

Submission status: Wrong Answer

Solution code:
import re


def main():
    n = int(input())
    s = input()

    count = 0

    for _ in range(n):

        relst = re.findall(r"#\.", s)

        count += len(relst)

        s = s.replace("#.", "..")

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = 0
T1 = S.copy()
f = False
for i in range(N):
    s = T1[i]
    if s == ".":
        continue
    else:
        if i < N - 1 and T1[i+1] == ".":
            if not f and i + 1 < N - 1 and T1[i+2] == ".":
                ans += 1
            else:
                f = True
                T1[i+1] = "#"
                ans += 1
        else:
            f = True
ans2 = 0

for i in range(N):
    s = S[i]
    if s == ".":
        continue
    else:
        ans2 += 1

ans3 = 0

for i in range(N):
    s = S[i]
    if s == ".":
        ans3 += 1
    else:
        continue
print(min(ans2, ans, ans3))

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    s=input()
    if '.' not in s or '#' not in s:
        print(0)
        return
    for i in range(n):
        if s[i] == '.':
            j = i
    a = len([i for i in s[:j] if i == '#'])
    j = s.index('#')
    b = len([i for i in s[j:] if i == '.'])
    print(min([a, b]))

main()

Submission status: Wrong Answer

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

n = int(input())
line = input()

w = 0
for i in range(n):
    if line[i] == ".":
        w += 1
b = n-w

w_coutner = 0
b_counter = 0
ans = n
for i in range(n):
    if line[i] == ".":
        w_coutner += 1
    b_counter = i+1 - w_coutner
    wtob = b_counter
    btow = w - w_coutner
    ans_i = wtob + btow
    print(i,ans_i)
    ans = min(ans,ans_i)

print(ans)

Submission status: Wrong Answer

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

if len(set(s)) == 1:
   print(0)
else :
   idx = s.find('#')
   print(s[idx:].count('.'))

Submission status: Wrong Answer

Solution code:
n=int(input())
S=list(input())
if len(set(S))==1:
    print(0)
    exit()
W,B=[0]*n,[0]*n
if S[0]=='.':
    W[0]=1
else:
    B[0]=1
for i in range(1,n):
    if S[i]=='.':
        W[i]=W[i-1]+1
        B[i]=B[i-1]
    else:
        W[i]=W[i-1]
        B[i]=B[i-1]+1
ans=float('inf')
for i in range(n-1):
    w=W[i]
    b=B[-1]-B[i]
    tmp=n-w-b
    ans=min(ans,tmp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

black = False
white = False
counter = 0
for item in s:
    if item == "#":
        black = True
        continue
    if black:
        if item == '.':
            counter += 1
            white = True
        if white and item == '#':
            black = 0
            white = False
print(counter)

Submission status: Wrong Answer

Solution code:
# C
n = int(input())
s = str(input())

dot = True
count_dot = 0
for i in range(n):
    if dot and s[i] == ".":
        continue
    else:
        dot = False
        if s[i] == ".":
            count_dot += 1
black_count = 0
for i in range(n):
    if s[i] == "#":
        black_count += 1
print(min(count_dot, black_count))

Submission status: Wrong Answer

Solution code:

n = int(input())
s = input()
s = s[::-1]

sum = 0
while True:
    s = s[s.find('.'):]
    y = s.find('#')
    x = s[y:].find('.')
    if y == -1:
        break

    s = s[x + y:]
    sum += min(x,y)
print(sum)

Submission status: Wrong Answer

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

for i,c in enumerate(S):
    if c == "#":
        break
for j,c in enumerate(S[::-1]):
    if c == ".":
        break
print(min(S[i:N-j].count("."),S[i:N-j].count("#")))

Submission status: Wrong Answer

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

m1=0
m2=0

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

m3=0
a=-1
flag=0

for i in range(n):
  if s[n-i-1] == '.' and flag == 0:
    flag=1
    continue
  if s[n-i-1] == '#':
    a=n-i-1
    flag=1
    continue
  if s[n-i-1] == '.' and flag == 1:
    break

for i in range(n):
  if a == -1:
    break
  if i<a:
    if s[i] == '#':
      m3+=1
  elif i>a:
    if s[i] == '.':
      m3+=1

print(min(m1,m2,m3))

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b
ans = 100000000
n = int(input())
stones = input()
black = 0
white = 0
for c in stones:
    if c == ".":
        white += 1

for c in stones:
    if c == ".":
        white -= 1
    else:
        black += 1
    tmp = black + white
    if ans > tmp:
        ans = tmp

print(ans)

"""
10 
....##....#########.

"""

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    n = ip.I()
    s = input()
    f = s.find('#')
    # p(s)
    # p(f)
    if f == -1:
        pass
    else:
        s = s[f:]
    a = s.count('#')
    b = s.count('.')
    p(min(a, b))


main()

Submission status: Wrong Answer

Solution code:
raw_input()
t=raw_input()
has_black=False
cant=0
for i in t:
  if i=="#": has_black=True
  else:
    if has_black:
      cant+=1


has_white=False
cantB=0
for i in t[::-1]:
  if i==".": has_white=True
  else:
    if has_white:
      cantB+=1
print min(cant, cantB)

Submission status: Wrong Answer

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

ans = 0
w, b = 0,0
if S[0]==".": w += 1
else: b += 1
for i in range(1, N):
    # print(b, w, ans)
    if S[i-1]=="#" and S[i]=="#":
        b += 1
    elif S[i-1]=="#" and S[i]==".":
        w += 1
    elif S[i-1]=="." and S[i]==".":
        w += 1
    else: # S[i-1]=="." and S[i]=="#":
        ans += min(b, w)
        b, w = 1,0

ans += min(b, w)
print(ans)

Submission status: Wrong Answer

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

wh = 0
bl = 0
a = []
for i in range(n):
    if s[i] == ".":
        wh += 1
    else:
        bl += 1
    a.append([wh,bl])
#print(a)

ans = n
for i in range(n):
    k = (a[i][1]) + (a[n-1][0]-a[i][0])
    #print(i,k,(a[i][1]),(a[n-1][0]-a[i][0]))
    ans = min(ans,  k)

print(ans)

Submission status: Wrong Answer

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

w = [0] * N
b = [0] * N
wc = 0
bc = 0
for i in range(N):
  if S[i] == "#":
    wc += 1
  w[i] = wc
for i in range(N - 1, -1, -1):
  if S[i] == ".":
    bc += 1
  b[i] = bc

Ans = 1000000
for i in range(N):
  t = 0
  if i > 1:
    t += w[i - 1]
  if i < N - 1:
    t += b[i]
  Ans = min(Ans, t)
print(Ans)

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
S = list(input())
count = 0
count_two = 0
A = copy.copy(S)
B = copy.copy(S)
for i in range(N-1):
    if A[i] == '#' and A[i+1] == '.':
        A[i] = '.'
        count += 1
    if B[i] == '#' and B[i+1] == '.':
        B[i+1] = '#'
        count_two += 1

print(min([count, count_two]))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    s = SI()

    W = [0]
    B = [0]
    for c in s:
        b = c == '#'
        w = c == '.'
        B.append(B[-1] + b)
        W.append(W[-1] + w)

    res = n - max(B[-1], W[-1])
    for i in range(n - 1):
        if s[i] == '#' and s[i + 1] == '.':
            res = min(res, B[i] + W[-1] - W[i + 1])

    return res


print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
p = N - S[::-1].find('.')
w = sum([s == '.' for s in S[:p]])
print(min(w, p - w))

Submission status: Wrong Answer

Solution code:
def main(n):
	flg = False
	s = input()
	ans = 0
	blk = 0
	for i in range(0,n-1):
		if s[i] == "#":
			blk += 1
		if s[i] == "#" and s[i+1] == ".":
			flg = True
		if flg and s[i] == ".":
			ans += 1
	if s[-1] == "#":
		blk += 1
	if flg and s[-1] == ".":
		ans += 1
	print(min(ans, blk))
main(int(input()))

Submission status: Wrong Answer

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

ans1 = 0
ans2 = 0
idx1 = 1e9
idx2 = 1e9

for i, ele in enumerate(s):
  if ele=="#":
    idx1 = i
    break

for i, ele in enumerate(s[::-1]):
  if ele==".":
    idx2 = i
    break

if idx1<len(s):
  for ele in s[idx1::]:
    if ele==".":
      ans1 += 1

if idx2<len(s):
  for ele in s[idx2::-1]:
    if ele=="#":
      ans2 += 1

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
black = s.count("#")
white = n - black
ans = float("inf")
for i in range(n):
    if s[i] == "#":
        ans = min(ans, white - i)
        break
s = list(reversed(list(s)))
for i in range(n):
    if s[i] == ".":
        ans = min(ans, black - i)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
read = input
n = int(read())
s = read()
leftB = -1
rightW = -1
# print(s)
for i,c in enumerate(s):
    if c == '#':
        leftB = i
        break
        
for i in range(len(s)-1, -1, -1): # smart way
    c = s[i]
    if c == '.':
        rightW = i
        break
# print(leftB, rightW)
if leftB < 0 or rightW < 0:
    print(0)
else :
    total = rightW - leftB + 1
    ans = total
    ans = min(
        ans, total - sum(
                            map(lambda x:1, 
                                    filter(
                                        lambda c:c == '.', list(s[leftB:(rightW+1)] )
                                    )
                              )
                          )
               )
    ans = min(
        ans, total - sum(
                            map(lambda x:1, 
                                    filter(
                                        lambda c:c == '#', list(s[leftB:(rightW+1)] )
                                    )
                              )
                          )
               )
    
    print(ans)

Submission status: Wrong Answer

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

ans = 0

white = 0
black = 0

black_right = 0

for i in range(n):
    if s[i]=='#':
        for j in range(i,n):
            if s[j]=='.':
                white +=1
                black_right =0
            if s[j]=='#':
                black +=1
                black_right += 1
        break


print(min(white, black-black_right))

Submission status: Wrong Answer

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

ans = float("inf")

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

bunsuirei = s.find("#")

if bunsuirei != -1:
  ans = min(ans,s[bunsuirei:].count("."))

print(ans)

Submission status: Wrong Answer

Solution code:
#TENKA1-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
S=S()
B=[0]*n
W=[0]*n
for i in range(n):
    if S[i]=="#":
        B[i]=1
    else:
        W[i]=1
for i in range(n-1):
    B[i+1]+=B[i]
    W[i+1]+=W[i]
B=[0]+B
W=[0]+W
ans=2*n
for i in range(n):
    tans=B[i+1]-B[0]+W[-1]-W[i+1]
    ans=min(ans,tans)
if B[-1]==n:
    ans=0
if B[-2]==n-1 and S[-1]==".":
    ans=1
print(ans)

Submission status: Wrong Answer

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

S = list(S)

stone =('.','#')
count = 0
out = 0
for i in range(len(S)-1):
    if (S[i] == stone[1])&(S[i+1] == stone[0]):
        count = count +1
        if((i>0)&(S[i-1] == stone[1]))&((i<len(S)-1)&(S[i+1] == stone[0])):
            
            l = 0
            for j in range(i):
                if (S[i-(j+1)] == stone[0]):
                    break
                l = l+1
            r = 0
            for j in range(N-i-1):
                if (S[i+(j+1)] == stone[1]):
                    break
                r = r+1
            out = out+min(l,r)
if count == 0:
    print count
else:
    print count+out

Submission status: Wrong Answer

Solution code:
import re


def main():
    n = int(input())
    s = input()

    relst = re.findall(r"#\.", s)

    print(len(relst))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

cnt_b = s.count("#")
cnt_w = s.count(".")

#全部黒にする
ans = cnt_w
ansa = ans
for i in range(n):
  if s[i] == ".":
     ans -= 1
  else:
     ans += 1
  ansaa = min(ans,ansa)
print(ansa)

Submission status: Wrong Answer

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

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

siro=s.count(".")
kuro=s.count("#")
print(min(siro,cnt,kuro))

Submission status: Wrong Answer

Solution code:
N = int(input())
S =(list(input()))
newS=[]
for i in S:
    if i == ".":
        newS.append(0)
    else:
        newS.append(1)
before = 0
count = 0
finalS =[]
for i in newS:
    flag = i - before
    if flag < 0:
        finalS.append(1)
        count = count +1
    else:
        finalS.append(i)
    before = i

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
left_white = 0
i = 0
while S[i] == ".":
	left_white += 1
	if i != N - 1:
		i += 1
	else:
		break
right_black = 0
j = N - 1
while S[j] == "#":
	right_black += 1
	if j != 0:
		j -= 1
	else:
		break
black = 0
white = 0
for k in range(N - right_black - left_white):
	if S[i + k] == "#":
		black += 1
	else:
		white += 1
ans = white
ans2 = black
print(min(ans,ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
for i in range(N):
    if S[i] == '#':
        break
S1 = S[i:]
S = S[::-1]
for i in range(N):
    if S[i] == '.':
        break
S2 = S[i:]
print(min(S1.count('.'),S1.count('#'),S2.count('.'),S2.count('#')))

Submission status: Wrong Answer

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

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

    if white * black == 0:
        print(0)
        return
    if white < black:
        print(white)
    else:
        print(black)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
input()
S = input()

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

print(min(S[1:].count('#')+contB, S.count('.')))