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:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__

    str = lambda x=b"": x if type(x) is bytes else __str__(x).encode()

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines += b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


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

    if '#' in s:
        s = s[s.index('#'):]
    else:
        print(0)
        return

    if '.' in s:
        s = s[::-1]
        s = s[s.index('.'):]
    else:
        print(0)
        return

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
n=[0]*N
for i in range(N):
    if S[i]=='#':
        n[i]=n[i-1]+1
    else:
        n[i]=n[i-1]
ans=min(n[-1],N-n[-1])
for i in range(N-1):
    ans=min(ans,n[-1]-n[i+1]+n[i])
print(ans)

Submission status: Wrong Answer

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

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

if i > 2:
    S = S[:-(i-1)]
    N -= (i - 1)

ans = min(S.count('.'), S.count('#'))
print(ans)

Submission status: Wrong Answer

Solution code:
I=lambda:map(int,input().split())
n=int(input())
s=input()
t=[0]
for k in s:t+=[t[-1]+(1 if k=='#' else 0)]
r=[t[i+1]*2+n-i-1-t[-1] for i in range(n)]
print(min(r))

Submission status: Wrong Answer

Solution code:
n=int(input())
print(input().count('#.'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import groupby
n = int(input())
s = input()
ldx = 0
for i in range(n):
    if s[i] == "#":
        break
    else:
        ldx += 1

s = s[ldx:]
m = len(s)

if m > 1:
    rdx = m
    for i in range(m):
        if s[m-1-i] == ".":
            break
        else:
            rdx = m-1-i
    s = s[:rdx]
    m = len(s)

if m <= 1:
    ans = 0
else:
    ans = min(s.count("."), s.count("#"))
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 = 0
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:
import sys

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

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

b_num = 0
flag = False
for s in S:
    if s == '#':
        flag = True
    if flag and s == ".":
        b_num += 1

S = reversed(S)
w_num = 0
flag = False
for s in S:
    if s == '.':
        flag = True
    if flag and s == "#":
        w_num += 1

print(min(b_num, w_num))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ctb=0;ctw=0;f=0;ct=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]=='#':
    ct+=1
  else:
    break
    
for i in range(n-ct):
  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 = input()

count = 0
b_count = 0
already = False
for i in s:
    if already:
        if i == '.':
            count += 1
        else:
            b_count +=1
    else:
        if i == '#':
            already = True
            b_count += 1

if (b_count < count):
    print(b_count)
else:
    print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
flg = list(map(lambda x: 0 if x == '#' else 1 ,S))
flg2 = flg[:]
cnt1 = 0
cnt2 = 0

for i in range(N-1):
    if flg[i] == 0 and flg[i+1] == 1:
        flg[i+1] = 0
        cnt1 += 1

for i in range(N-1):
    if flg2[N-2-i] == 0 and flg2[N-1-i] == 1:
        flg2[N-2-i] = 1
        cnt2 += 1
    
        

print(min(cnt1,cnt2))

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(min(ans, n - ans))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ac
n=int(input())
s=input()
a=[0 if i=="#" else 1 for i in s]
p=[0]+list(ac(a))
b=p[-1]
d=float("inf")
print(p)
for i in range(n+1):
    d=min(i-p[i]+(b-p[i]),d)
print(d)

Submission status: Wrong Answer

Solution code:
import sys


WHITE, BLACK = 0, 1
fin = sys.stdin.readline
N = int(fin())
S = fin().rstrip("\n")
assert len(S) == N

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

grouped_S.append((prev_color, count))

# print(grouped_S)
if grouped_S[0][1] == WHITE:
    grouped_S = grouped_S[1:]
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:
n=input()
s=input()
ans=s.count('.')
s1=s.split('#')
s2=[0]
for i in s1:
    s2.append(s2[-1]+len(i))
ans1=ans
for i in range(len(s2)-2):
    ans1=min(ans1,ans-s2[i+1]+i)
print(ans1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cum_sum = [0 for _ in range(n)]

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

for i in range(n-1):
    cum_sum[i+1] += cum_sum[i]

#print(cum_sum)

ans = 10 ** 10
for i in range(n):
    tmp = 2 * cum_sum[i] + n - i - 1 - cum_sum[n-1]
    #print(ans, tmp)
    if ans > tmp:
        ans = tmp

if n == 1:
    print(0)
elif n == cum_sum[-1]:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

ret = 0
bs = 0 if s[0] == '.' else 1
prev = s[0]
i = 1



while i < n:
    if s[i] == '#':
        bs += 1
        i += 1
    else:
        if prev == '#':
            ws = 1
            i += 1
            while i < n and s[i] == '.':
                i += 1
                ws += 1
            if bs <= ws:
                ret += bs
            else:
                ret += ws
            ws = 0
            bs = 0
        else:
            i += 1


print(ret)

Submission status: Wrong Answer

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

flag = False
count1 = 0
for i in s:
    if(flag == True):
        if(i == "."): count1 += 1
    elif(i == "#"): flag = True

s = s[::-1]
flag = False
count2 = 0
for i in s:
    if(flag == True):
        if(i == "#"): count2 += 1
    elif(i == "."): flag = True



print(min([count1, count2]))

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 flg and s[-1] == ".":
		ans += 1
	print(min(ans, blk))
main(int(input()))

Submission status: Wrong Answer

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

BK = '#'

idx = N
cnt = 0
for i in range(N - 1, -1, -1):
    if s[i] == BK:
        idx = i
        cnt += 1

if idx == N:
    print(0)
else:
    print(N - idx - cnt)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    count = 0
    f = False
    for i in S:
        if f and i == ".":
            count += 1
        elif i == "#":
            f = True
            
    print(min([count, N - count]))
    

if __name__ == '__main__':
    main()

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 = INF
    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 if res != INF else 0


print(main())

Submission status: Wrong Answer

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

for i, s in enumerate(S):
    if s == '#':
        break
S = S[i:]

for i, s in enumerate(reversed(S)):
    if s == '.':
        break
if i != 0:
    S = S[:-i]
        
white = 0
black = 0

for s in S:
    if s == '.':
        white += 1
    else:
        black += 1

print(min(white, black))

Submission status: Wrong Answer

Solution code:
n = int(input())
text = input()
if "#" not in text:
    print(0)
    exit(0)

pos = text.index("#")
result = 0
for i in range(pos+1, len(text)):
    if text[i] == '.':
        result += 1

print(result)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
n=0
s=S[::-1]
for i in range(len(S)):
    if s[i]=="#":
        n+=1
    else:
        break
#print(n)

B=0
W=0
Flag=0
for i in range(len(S)-n):
    if S[i]=="#":
        Flag=1
    if Flag==1:
        if S[i]=="#":
            B+=1
        else:
            W+=1
print(min(B,W))

Submission status: Wrong Answer

Solution code:
l=input()
k =input()

flag = False
count = 0
for i in range(int(l)):
    if k[i] == "#":
        flag=True
    elif flag :
        count += 1
print (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:
    print(S[tem:].count("."))

Submission status: Wrong Answer

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

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]
    else:
        C[i+1] = C[i] + 1
b = C[N]
w = N - b
ans = b
for i in range(N):
    if C[i+1] + N - i - 1 -b + C[i+1] < ans:
        ans = C[i+1] + N - i - 1 -b + C[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cs = [c for c in s]
ans = 0

zero = False
for i in range(0, n):
    if cs[i] == '#':
        break
else:
    zero = True

ans = sum(1 for c in cs[i:] if c=='.') if not zero else 0

for i in range(0, n):
    if cs[n-1-i]=='.':
        break

ans = min(ans, sum(1 for c in cs[:n-1-i] if c=='#'))

print(ans)

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(".")

print(min(siro,cnt))

Submission status: Wrong Answer

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

count = 0
for i in range(len(S)-1):
    gram_2 = S[i:i+2]
    if gram_2 == "#.":
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#.はだめ
n = int(input())
s = list(input())

check = False #左に黒がない
counter = 0
for i in range(n):
    if s[i] == "#":
        check = True
    else:
        if check:
            counter += 1

check = False #右に白がない
counterb = 0
for i in range(n):
    if s[-1-i] == ".":
        check = True
    else:
        if check:
            counterb += 1
    
print(min(counter,counterb))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# S = input()
# N = int(input())
# a = list(map(int, input().split()))
# X = [int(input()) for _ in range(N)]

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

ans1 = 0
ans2 = 0
kuro_frag = False

for i in S:
    if i == "#":
        kuro_frag = True
    elif kuro_frag:
        ans1 += 1

kur0_count = 0

for i in range(N):
    if S[i] == "#":
        kur0_count += 1
        ans2 += 1
    else:
        kur0_count = 0



print(min(ans1,ans2-kur0_count))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from sys import exit
N = int(input())
S = input()
if S == '#'*N:
    print(0)
    exit()
W = [int(s == '.') for s in S]
W = list(accumulate(W))
W += [W[-1]]
w = W[-1]
B = [int(s == '#') for s in S]
B = list(accumulate(B))
print(min(w-i+j for i, j in zip(W, B)))

Submission status: Wrong Answer

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

for c in range(len(S)):
    if S[c] == '#':
        S = S[c:]
        break

for c in range(len(S)-1,-1,-1):
    if S[c] == '.':
        S = S[:c+1]
        break

n = len(S)
w = 0
b = 0
for s in S:
    if s == '.':
        w = w + 1
    else:
        b = b + 1

print(min(n-w, n-b))

Submission status: Wrong Answer

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

ans1 = 0
ans2 = 0
idx = 1e9

for i, ele in enumerate(s):
  if ele==".":
    pass
  else:
    idx = i
    break

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

print(min(ans1, ans2))

Submission status: Wrong Answer

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

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:
N = int(input())
s = input()
cnt = 0

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

Submission status: Wrong Answer

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

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

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=list(input())
#b->w
for i in reversed(range(n)):
    if S[i]=='.':
        break
else:
    print(0)
    exit()
cnt1=S[:i+1].count('#')
#w->b
for i in range(n-1):
    if S[i]=='#':
        break
else:
    print(0)
    exit()
cnt2=S[i+1:].count('.')
print(min(cnt1,cnt2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
f_turn_black = False
for i, c in enumerate(s):
    if f_turn_black:
        if c == '.':
            ans += 1
    elif c == '#':
        i_first_black = i
        f_turn_black = True

print(ans)

Submission status: Wrong Answer

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

S.reverse()

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

if black < white:
    print(black)
else:
    print(white)

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+1:].count("."),S[:N-j-1].count("#")))

Submission status: Wrong Answer

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

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

ans = cnt_w
ansa = cnt_w 
for i in range(n):
  if s[0] == ".":
     ans -= 1
  else:
     ans += 1
      
  ansaa = min(ans,ansa)
print(ansa)

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
print(count_dot)

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

n = int(input())
stones = input()
black, white = 0,0
for c in stones:
    if c == "#":
        black += 1
    else:
        white += 1


for c in stones:
    if c == ".":
        white -= 1
    else:
        break

for c in stones[::-1]:
    if c == "#":
        black -= 1
    else:
        break

print(min(black, white))

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

"""

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
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
A=0
B=0
allwhite=0
blackflag=-1
blackcount=0
whitecount=0
for i in range(N):
  if S[i]!='.':
    allwhite+=1
  if blackflag==-1 and S[i]=='#':
    blackflag=i  
  if blackflag!=-1:
    if S[i]=='#':
      blackcount+=1
    else:
      whitecount+=1
      
print(min(allwhite,blackcount,whitecount))

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

dot = 0
last = "xx"
for i in range(N):
    if last != "." and S[i] == ".":
        dot += 1
    last = S[i]

sharp = 0
last = "xx"
for i in range(N):
    if last != "#" and S[i] == "#":
        sharp += 1
    last = S[i]


print(min(dot, sharp))

Submission status: Wrong Answer

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

ans = 0
T1 = S.copy()

for i in range(N):
    s = T1[i]
    if s == ".":
        continue
    else:
        if i < N - 1 and T1[i+1] == ".":
            T1[i+1] = "#"
            ans += 1

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:
#!/usr/bin/env python3

import re

input()
print(sum(min(m.count('#'), m.count('.')) for m in re.findall('#+\.+', input())))

Submission status: Wrong Answer

Solution code:
#coding: utf-8

def method():
    _ = input()
    string = input()
    previous = ""
    count = 0
    for s in string:
        if previous == "#" and s == ".":
            count = count + 1
        previous = s
    print(count)

method()

Submission status: Wrong Answer

Solution code:
from itertools import groupby
n = int(input())
s = input()
ldx = 0
for i in range(n):
    if s[i] == "#":
        break
    else:
        ldx += 1

s = s[ldx:]
m = len(s)

if m > 1:
    rdx = m
    for i in range(m):
        if s[m-1-i] == ".":
            break
        else:
            rdx = m-1-i
    s = s[:rdx]
    m = len(s)

if m <= 1:
    ans = 0
else:
    ans = s.count(".")
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

start = False
cnt1 = 0
for s in S:
    if (not start) and s == "#":
        start = True
    elif start and s == ".":
        cnt1 += 1

start = False
cnt2 = 0
for i in range(len(S))[::-1]:
    s = S[i]
    if (not start) and s == ".":
        start = True 
    elif start and s == "#":
        cnt2 += 1

print(min(cnt1,cnt2))

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
print cant

Submission status: Wrong Answer

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

ans = 0

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


print(min(white, black))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S += "#"

ans = 0
for i,v in enumerate(S[:N-1]):
  if v == "#" and S[i+1] == ".":
    ans += 1
  else:
    continue
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:58:04 2019

@author: Yamazaki Kenichi
"""

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

a,b = 0,0
flg,flg2 = False,False
for i in range(N):
    if S[-i-1] == '.':
        flg = True
    if flg:
        if S[-i-1] == "#":
            flg2 = True
    if flg2 and S[-i-1] == '#':
        a += 1
    if flg2 and S[-i-1] == '.':
        b += 1
print(min(a,b))

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    s = input().strip()

    cnt = [0] * n
    for i in range(n):
        if i == 0 and s[0] == '#':
            cnt[0] = 1

        if i>0 :
            if s[i]=='#':
                cnt[i] = 1 + cnt[i-1]
            else:
                cnt[i] = cnt[i-1]
    
    ans = 2e5+5
    for i in range(n):
        ans = min(ans, cnt[i] + n + cnt[i] - cnt[n-1] - (i+1))
    
    print(ans)
        

solve()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
pre=""
for i in S:
    if pre=="":
        pre=i
        continue
    if i=="." and pre=="#":
        ans+=1
        pre="#"
    else:
        pre=i
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ss = s[(s.find('#') + 1):]
a = Counter(ss)['.']
c = Counter(s)
ss = s[::-1][s[::-1].find('.') + 1:]
b = Counter(ss)['#']
print(min(min(min(c['#'], c['.']), a), b))

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
# print(l)
for r, s in enumerate(S[::-1]):
    if s != '#':
        break
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:
import sys

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

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

b_num = 0
flag = False
for s in S:
    if s == '#':
        flag = True
    if flag and s == ".":
        b_num += 1

w_num = len([s for s in S if s == "#"])

print(min(b_num, w_num))

Submission status: Wrong Answer

Solution code:

def main():
    buf = input()
    N = int(buf)
    buf = input()
    S = buf
    white_turn = 0
    black_turn = 0
    fullblack_turn = 0
    has_black = False
    for i in S:
        if i == '.':
            fullblack_turn += 1
            if has_black:
                black_turn += 1
        elif i == '#':
            white_turn += 1
            if not has_black:
                has_black = True
    print(min(white_turn, black_turn, fullblack_turn))

if __name__ == '__main__':
    main()

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()
    a = s.count("#")
    b = s.count(".")
    p(min(a, b))




main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i, s in enumerate(reversed(S)):
    if s == '.':
        break

if i != 0:
    S = S[:-i]
        
white = 0
black = 0

for s in S:
    if s == '.':
        white += 1
    else:
        black += 1

print(min(white, black))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input())
s = input().rsplit()[0]
kuro = 0
siro = 0
ans = 0
syo = 0
while syo < n and s[syo] == ".":
    syo += 1
for i in range(syo,n):
    if s[i] == "#":
        if siro:
            ans += min(siro,kuro)
            siro = 0
            kuro = 1
        else:
            kuro += 1
    else:
        siro += 1
ans += min(siro,kuro)
print(ans)