Problem:


Score : 300 points

Problem Statement

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

3
#.#

Sample Output 1

1

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

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

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


ini_w = 0
for i in range(len(S)):
    if S[i] == '.':
        ini_w = ini_w + 1
    else:
        break
    
if ini_w >= len(S)-1:
    print(0)
    exit()
    
S = S[ini_w:]

all_w = len(S) - S.count(".")
all_b = len(S) - all_w

other = 2*10000000
if S[-1] == '#':
    other = all_w - 1

print(min(all_w,all_b,other))

Submission status: Wrong Answer

Solution code:
def cutw(s,n):
    t = 0
    for i in range(n):
        if s[i] == '#':
            break
        else:
            t += 1
    s = s[t:]
    n = len(s)
    return s,n

def cutb(s,n):
    t = n
    for i in range(n-1, -1,-1):
        if s[i] == '.':
            break
        else:
            t -= 1
    s = s[:t]
    n = len(s)
    return s,n

def main():
    n = int(input())
    s = input()
    res = 0
    s1 = s
    n1 = n
    res1 = 0
    while True:
        s,n = cutw(s,n)
        if n>0:
            s = '.'+s[1:]
            res += 1
        else:
            break
    while True:
        s1,n1 = cutb(s1,n1)
        if n1>0:
            s1 = s1[:n1-1] + '#'
            res1 += 1
        else:
            break
    print(min(res,res1))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
#print(S)
ans = 0
hens = 0
for j in range(N):
    if S[j] == "#":
        for i in range(N - j -1):
            if S[i] == ".":
                ans += 1
        break

for k in range(N):
    if S[-k-1] == ".":
        for u in range(N - k -1):
            if S[-u-1] == "#":
                hens += 1
        break

print(min(ans, hens))

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
ans=0
if s.count(".")==n:
    print(0)
    sys.exit()
for i in range(len(s)):
    if s[i]=="#":
        print(s[i+1:].count("."))
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
l = [1]
flg = S[0]
index = 1
#文字列分割が謎
while index != len(S):
    if S[index] == flg:
        l[len(l)-1] += 1
    else:
        l.append(1)
        flg = S[index]
    index += 1
if len(l) == 1:
    print(0)
elif len(l) == 2:
    if S[0] == ".":
        print(0)
    else:
        print(min(l[0],l[1]))
else:
    if S[0] == ".":
        l[0] = 0
    if S[len(S)-1] == "#":
        l[len(l)-1] = 0
    a = 0
    b = 0
    k = 0
    while k+1 < len(l):
        a += l[k]
        b += l[k+1]
        k += 2
    if k == len(l) - 1:
        a += l[k]
    print(min(a,b))

Submission status: Wrong Answer

Solution code:
N=input()
S=list(map(str,input()))
#block
index_num = [n for n,v in enumerate(S) if v =='#']
b_count = 0
for i in index_num:
    if i!=len(S)-1 and S[i+1]=='.':
        b_count += 1
#white
index_num = [n for n,v in enumerate(S) if v =='.']
w_count = 0
for i in index_num:
    if i!=0 and S[i-1]=='#':
        w_count += 1
print(min([b_count, w_count]))

Submission status: Wrong Answer

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

ans = 0
index = 0
index2 = 0

if S.count("#") == 0:
    print(ans)
    exit()

for i in range(N):
    if S[N - 1 - i] == "#":
        index = N - 1 - i
        break

ans += N - index - 1

ans += S[:index].count(".")

another_ans = S.count("#")

if another_ans < ans:
    print(another_ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
s = list(a)
r = 0

i = 0
while i<len(s) and s[i] == '.':
  i+=1

s = s[i:]
print(s.count('#'),s.count('.'))


while i<len(s):
  b = 0
  while i<len(s) and s[i] == '#':
    b+=1
    i+=1
  w = 0
  while i<len(s) and s[i] == '.':
    w+=1
    i+=1
  r += min(b,w)

print(r)

Submission status: Wrong Answer

Solution code:
import sys
import math
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N = ni()
S = ns()

#最初のBが出てくるまでを数える
fastB = False
fastW = False
secondB=False
w0,w1,b0,b1 = 0,0,0,0

for s in S:
    if(s=="."):
        #print("w")
        if(fastB and fastW):
            secondB=True
            w1+=1
        else:
            fastW=True
            w0+=1
    elif(s=="#"):
        #print("b")
        if(fastB and fastW and secondB):
            b1+=1
        else:
            fastB=True
            fastW=True
            b0+=1
w=True
res=0
for s in S[::-1]:
    if(s=="#"):
        if(w):
            res+=1
        else:
            break
    else:
        w=False


#print(b0+b1,w0+w1,w1)
#print(b0,b1,w0,w1)

print(min(b0+b1-res,w0+w1,w1))

Submission status: Wrong Answer

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

w = 0
b = 0
for s in S:
  if s == '.':
    w += 1
  else:
    b += 1

if S[-1] == '#':
  b -= 1

print (min(w, b))

Submission status: Wrong Answer

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

bw = []
if S[0] == "#":
  bw.append(0)
for i in range(N):
  if i == 0 or S[i] != S[i - 1]:
    bw.append(1)
  else:
    bw[-1] += 1
  
ans = float("inf")
for i in range(len(bw)):
  tmp = 0
  for j in range(len(bw)):
    if j <= i and j % 2 == 1:
      tmp += bw[j]
    elif j > i and j % 2 == 0:
      tmp += bw[j]
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

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

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

index = 0
for i in range(0,N):
    if S[i] == '#':
        index = i
        break

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
binS = []
for i in range(N):
    if S[i] == '.':
        binS.append(0)
    else:
        binS.append(1)
# print(binS)

dp = [0]
for i in range(1, N):
    if binS[i-1] == 1 and binS[i] == 0:
        dp.append(dp[i-1]+1)
    else:
        dp.append(dp[i-1])

print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
k,d = 0,0
s = list(input())

if s[0] == '.':
  c = 0
  for j in s:
    if j == '.':
      c+=1
    else:
      break
      
  for i in range(c,n):
    if s[i] == '#':
      k+=1
    else:
      d+=1
  
  
else:
  for i in range(n):
    if s[i] == '#':
      k+=1
    else:
      d+=1
print(min(k,d))

Submission status: Wrong Answer

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

kuro = s.count("#")
for i in range(n):
    s.append("#")

count = 0
for i in range(n):
    if s[i] == "#" and s[i+1] == ".":
        init = i+1
        break
for i in range(n):
    # #=kuro .=shiro

    if s[i] == "#" and s[i+1] == ".":
        c = 1
        for j in range(n):
            if s[i+j+2] == ".":
                c += 1
            else:
                break
        if count == 0 and init < c:
            c = init
        count += c
print(min(count,kuro))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
b = 0
w = 0
c = 0
ans = 0
n = int(input())
s = input()
for i in range(n):
    if s[i]=="#":
        b+=1
    elif s[i]==".":
        w+=1

if b>=w:
    for i in range(n):
        if s[i]=="#":
            c = i
            break
    ans = w-c
    
if b<w:
    ans = b

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
c=0
for i in range(0,N,1):
  if S[i]=="#":
    moji=S[i:]
    c=moji.count(".")
    break
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
b = 0
w = 0
w2 ,b2 =0,0
for i in range(n):
    if s[i] != ".":
        b += 1
    else:
        w += 1
for i in range(n):
    if s[i] == ".":
        w2 +=1
    else:
        break
for j in range(n-1,-1,-1):
    if s[j] != ".":
        b2 +=1
    else:
        break

print(min(b-b2,w-w2))

Submission status: Wrong Answer

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

fb = -1
lw = -1
awc = 0
abc = 0
fbrwc = 0
lwlbc = 0
work = 0
for i in range(N):
  if S[i] == '.':
    awc += 1
    lwlbc += work
    work = 0
    if fb >= 0:
      fbrwc += 1
  if S[i] == '#':
    abc += 1
    work += 1
    if fb <0:
      fb = i
count = []
count.append(awc)
count.append(abc)
count.append(lwlbc)
count.append(fbrwc)
print(min(count))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
n = int(input())
s = str(input())
s = s.replace(".", "0").replace('#', "1")
b = s.find("1")
a = 0
for i in range(b, n):
    a+=int(s[i])
print(n-b-a)

Submission status: Wrong Answer

Solution code:
import itertools

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

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

B = list(itertools.accumulate(S))

MIN = 10000000
cnt = []
for i in range(N):
    cnt.append(B[i] + N - B[N-1] + B[i] - i - 1)
    # MIN = min(MIN, cnt)
MIN = min(cnt)



S_s = list(set(S))
if len(S_s) == 1:
    MIN = 0
elif S.count('0') == 1:
    MIN = min(MIN, 1)
print(MIN)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
S = input().strip()

def stone_cnt(idx):
  return S[:idx].count("#") + S[idx:].count(".")

left = 0
right = len(S)

while left <= right:
  mid = (left + right) // 2
  if stone_cnt(left) > stone_cnt(right):
    left = mid + 1
  else:
    right = mid - 1

print(stone_cnt(mid))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = 0
if len(set(S)) == 1:
    print(0)
    exit()
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()
count1 = 0
count2 = 0
for i in range(N-1):
    if S[i:i+2] == '#.':
        count1 += 1

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

print(min(count1, count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = 0
l = []
l.append(S[0])
for i in range(1,N,1):
    l.append(S[i])
    if l[i-1] == "#" and l[i] == ".":
        cnt +=1
        l[i] = "#"
bcount = S.count("#")
wcount = S.count(".")
if bcount > wcount:
    print(cnt)
else:
    print(min(bcount,wcount,cnt))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
S = input()
count = 0

# for i in reversed(range(len(S) - 1)):
#     if S[i] == '#':
#         count += 1

for i in range(1, len(S)):

    if S[i] == '.':
        if S[i - 1] == '#':
            count += 1

print(count)

Submission status: Wrong Answer

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

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

if fb==(n-1):
    ans=1
elif fb==-1:
    ans=0
else:
    w=0
    b=1
    for i in range(fb+1,n):
        if s[i]=='.':
            w+=1
        else:
            b+=1
    ans=min(w,b)

print(ans)

Submission status: Wrong Answer

Solution code:
b = input()
a = list(str(input()))
counter = int(0)
if len(a) == 1:
    counter = 0
else:
    for i in range(0,len(a)-1):
        if a[i] == "#":
            if a[i] != a[i+1]:
                a[i+1] = '#'
                counter = counter + 1
        else:
            pass
print(counter)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import os

x = int(input())
y = list(input())

before = y[0]

for i in range(len(y)):
    if before == '#' and y[i] == '.':
        #ダメポイント見つけた
        #文字列を分割する
        mae = y[:i]
        ushiro = y[i:]
        print(min(ushiro.count('.'), ushiro.count('#')))
        exit(0)
    else:
        before = y[i]

print('0')

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
k = -1
tmp=0
for n,i in enumerate(S):
    if i=="#":
        k = n
        break
for i in S[::-1]:
    if i=="#":
        tmp-=1
    else:
        break
if tmp!=0:
    SS = S[k:tmp]
else:
    SS = S[k:]
if k ==-1:
    print(0)
else:
    t =  sum([1 if i=="." else 0 for i in SS])
    print(min(t,len(SS)-t))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if b < a:
        a,b = b,a
    if a <= c <= b:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    s = input()
    a = list(set(list(s)))
    k = II()-1
    for i in a:
        if s[k] != i:
            s = s.replace(i, "*")
    print(s)
    return

#C
def C():
    n = II()
    s = S()
    dp = []
    bf = s[0]
    del s[0]
    a = 1
    flg = False
    if bf == ".":
        flg = True
    for i in s:
        if i == bf:
            a += 1
        else:
            dp.append(a)
            a = 1
            bf = i
    dp.append(a)
    ans = 0
    a, b = 0, 0
    if flg:
        dp[0] = 0
    for d in range(len(dp) - 2, -1, -2):
        a += dp[d]
    for d in range(len(dp) - 1, -1, -2):
        b += dp[d]
    print(min(a,b))

    return

#D
def D():
    n = II()
    ai = IR(n)
    ai.sort()
    ruiseki = [0 for i in range(n)]
    for num, a in enumerate(ai):
        ruiseki[num] = a + ruiseki[num-1]
    select = list(itertools.combinations(range(n), 3))
    ans = 0
    for a,b,c in select:
        A = ruiseki[a]
        B = ruiseki[b] - ruiseki[a]
        C = ruiseki[c] - ruiseki[b]
        if A + B > C and B + C > A and A + C > B:
            ans += 6
            ans = ans % mod
    print(ans)
    
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
st = input()

re = []
num = 0

for i in range(N-1):
  if st[i] == "#" and st[i+1] == ".":
    re.append(".")
    num += 1
  else:
    re.append(st[i])

print(num)

Submission status: Wrong Answer

Solution code:
N = int(input()) 
S = input() 
 
#.......######
# a[n] = n個目より左にある#の数
# b[n] = n個目より右にある.の数
 
a = [0] * (N+2)
b = [0] * (N+3)
 
cnt = 2
for x in S:
    if x == "#":
        a[cnt] = a[cnt-1] + 1
    else:
        a[cnt] = a[cnt-1] 
    cnt += 1
 
cnt =N+1
Sinv = S[::-1]
for x in S:
    if x == ".":
        b[cnt] = b[cnt+1] + 1
    else:
        b[cnt] = b[cnt+1] 
    cnt -= 1
b[cnt] = b[cnt+1]
 
 
 
c = []
 
for index in range(N+2):
    c.append(a[index] + b[index])
c[0] = 999999
 
print(a)
print(b)
print(min(c))

Submission status: Wrong Answer

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

sb = s.copy()

ans = 0

for i in range(len(s)-1):
	if(s[i] == "#" and s[i+1] == "."):
		if(i == 0):
			s[i] = "."
		elif(i > 0 and s[i-1] != "#"):
			s[i] = "."
		else:
			s[i+1] = "#"
		ans += 1

ansb = 0
for i in range(len(sb)-1):
	if(i == 0 and sb[i] != "."):
		sb[i] = "."
		ansb += 1
	elif(sb[i] == "#" and sb[i+1] == "."):
		if(i > 0 and sb[i-1] != "#"):
			sb[i] = "."
		else:
			sb[i+1] = "#"
		ansb += 1

#print(s)
#print(sb)


#print(ans)
#print(ansb)

ans = min(ans, ansb)

print(ans)

Submission status: Wrong Answer

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

i = s.find("#")
if i < 0:
  i = 0
a = s[i:].count(".")
j = s.rfind("#")
b = s[:j].count("#")

if a < b:
  print(a)
else:
  print(b)

Submission status: Wrong Answer

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

for i in range(N-1):
    if s[i]!=s[i+1]:
        s[i+1]=s[i]
        count+=1

print(count)

Submission status: Wrong Answer

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

start = -1
black = 0
white = 1

for i in range(n):
    if s[i] == "#":
        start = i
        break

if start != -1:
    for i in range(n):
        print(i)
        print(start)
        if i > start:
            if s[i] == "#":
                black+=1
            else:
                white+=1
    if black<=white:
        print(black)
    else:
        print(white)

else:
    print(0)

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
#print(N,S)

if not "#" in S:
  print(0)
else:
  print(S.count("."))

Submission status: Wrong Answer

Solution code:
stones_count = int(input())
input_str = input()

target = input_str[0]

def set_next_target(target_char):
  if target_char == '#':
    return '.'
  else:
    return '#'

stones = ''
stones_list = []

for i in range(stones_count):
  if input_str[i] == target:
    stones = stones + target
  else:
    stones_list.append(stones)
    target = set_next_target(target)
    stones = target

stones_list.append(stones)
#print(stones_list)

count_0 = 0
count_1 = 0

## ケース: .. or ## の場合、変換は不要
if len(stones_list) == 1 :
  print(0)
  exit()
## ケース: ..## の場合、変換は不要
elif len(stones_list) == 2 and '#' in stones_list[-1]:
  print(0)
  exit()
## ケース: ..##..##.. の場合、先頭の要素を除いたもので少ない方のみ変換すればよい
elif '.' in stones_list[0]:
  for i in range(1, len(stones_list)):
    if i % 2 == 0:
     count_0 += len(stones_list[i])
    else:
     count_1 += len(stones_list[i])
## ケース: ##..##.. の場合、すべてを変換する前提で少ないものを選べばよい
else:
  for i in range(0, len(stones_list)):
    if i % 2 == 0:
     count_0 += len(stones_list[i])
    else:
     count_1 += len(stones_list[i])

if count_0 > count_1:
  print(count_1)
else:
  print(count_0)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=input()
sflag=0
a=0
b=0
c1=0
c2=0

d=0
for i in S[::-1]:
    if i=="#":
        d+=1
    else:
        break

for i in S:
    if i==".":
        a+=1
    if i=="#":
        b+=1
    if i=="#" and sflag==0:
        sflag=1
    if sflag==1:
        if i==".":
            c1+=1
        if i =="#":
            c2+=1

print(min(a,b,c1,c2-d))

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
count=0
ten_count=[0,0]
if b[0]=="#": 
    ten_count[0]+=1
for i in range(1,a):
    if b[i]=="#" and b[i-1]=="#":
        ten_count[0]+=1
    elif b[i-1]=="#" and b[i]==".":
        ten_count[1]+=1
        if i==a-1:
            count+=1
    elif ten_count[0]>0 and b[i-1]=="." and b[i]=="." :
        ten_count[1]+=1
        if i==a-1:
            count+=min(ten_count[0],ten_count[1])
    elif (b[i-1]=="." and b[i]=="#") :
        count+=min(ten_count[0], ten_count[1])
        ten_count[0]=1
        ten_count[1]=0
print(count)

Submission status: Wrong Answer

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

a=S.count('#')
b=S.count('.')

print(min(a,b))

Submission status: Wrong Answer

Solution code:
stones = [raw_input() for i in range(2)][1]
if "#" not in stones:
    print 0
else:
    counter = 0
    for ind, i in enumerate(stones, start=1):
        if i == "#":
            break
    for i in stones[ind:]:
        if i == ".":
            counter += 1
    print(counter)

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline())
s = sys.stdin.readline()

bcnt = 0
wcnt = 0
bst = -1
lastlen = 0

for i in range(n):
    tmp = s[i:i + 1]
    if "#" in tmp:
        bcnt += 1
        if bst == -1:
            bst = i
        lastlen += 1
    else:
        if bst >= 0:
            wcnt += 1
        lastlen = 0

print(min(wcnt, bcnt-lastlen))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s1 = '#'
i = 0
slis = []
ini = True

for s in S:
  if s == s1:
    i += 1
  if s != s1:
    if ini:
      slis.append(i)
      ini = False
    else:
      slis.append(i + 1)
    s1 = s
    i = 0

slis.append(i+1)

if S.startswith('.'):
  sum1 = sum(slis[2::2])
  sum2 = sum(slis[3::2])
elif S.endswith('#'):
  sum1 = sum(slis[0:-1:2])
  sum2 = sum(slis[1:-1:2])
else:
  sum1 = sum(slis[0::2])
  sum2 = sum(slis[1::2])

print(min(sum1, sum2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
b_start = N
w_goal = -1
for i in range(N):
    if S[i]=='#':
        b_start=i
        break
for i in range(N-1,-1,-1):
    if S[i]=='.':
        w_goal = i
        break
if b_start>w_goal:
    print(0)
else:
    S = S[b_start:w_goal+1]
    print(min(S.count('.'),S.count('#')))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
if S.count("#")==0:
    a=0
else:
    i=0
    while S[i]!="#":
        i=i+1
    a=S[i:].count(".")
S2 = ''.join(list(reversed(S)))
if S2.count(".")==0:
    b=0
else:
    i=0
    while S2[i]!=".":
        i=i+1
    b=S2[i:].count("#")
print(min(a,b))

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s =input()
ss = ''.join(re.findall("#+\.+",s))
print(min(ss.count('#'),ss.count('.')))

Submission status: Wrong Answer

Solution code:
N,S = [input() for i in range(2)]
a = list(S)
c = 0
for i in range(int(N)-1):
    if a[i] == "#":
        c += 1
print(min(c,int(N)-c))

Submission status: Wrong Answer

Solution code:
import numpy as np

dic={'.':0,'#':1}
N=int(input())
S=np.array([dic[i] for i in input()])

if S.sum()==0:
    print(0)
elif S.sum()==N:
    print(0)    
else:
    for i,j in enumerate(S):
        if j==1:
            black=(S[i+1:]==0).sum()
            white=(S[i:]==1).sum()
            print(min(black,white))
            break

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ne = []
for i in s:
    ne.append(i)

ans = 0
ans2 = 0
for i in range(n-1,1,-1):
    if ne[i] == '.' and ne[i-1] == '#':
        ne[i-1] = '.'
        ans += 1
ne = []
for i in s:
    ne.append(i)
for i in range(n-1):
    if ne[i] == '#' and ne[i+1] == '.':
        ne[i+1] = '#'
        ans2 += 1

print(min(ans,ans2))

Submission status: Wrong Answer

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

count = 0

while s.count("#.") != 0:
    t = re.subn("#.", '..', s)
    s = t[0]
    count += t[1]

print(count)

Submission status: Wrong Answer

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

ans = 0
flag = False

for i in range(n):
    if s[i] == '.':
         ans += 1
    else :
        flag = True


if flag:
    print(ans)
else:
    print("0")

Submission status: Wrong Answer

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

n = int(input())
s = str(input())
s = s.replace(".", "0").replace('#', "1")
b = s.find("1")
a = 0
for i in range(b, n):
    a+=int(s[i])
print("n-b-a", n-b-a)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        break

count=0
#print(dot+sha)
for i in range(N):
    if i<dot and S[i]!=".":
        count+=1
for i in range(N):
    if i<sha and s_r[i]!="#":
        count+=1
print(count)

Submission status: Wrong Answer

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

if n == 1:
    print(0)
elif n == 2:
    if s[0]=="#" and s[1]==".":
        print(1)
else :
    t = s[0]
    
    r = []
    cnt = 1
    for i in range(1, n):
        if t == s[i]:
            cnt += 1
        else :
            r.append(cnt)
            cnt = 1
            t = s[i]
    
    r.append(cnt)
    
    if s[0] == ".":
        r.pop(0)

    if len(r) <= 1:
        print(0)
        
    else :
        ans = 0
        if len(r) % 2 == 0:
            for i in range(0, len(r), 2):
                if r[i] > r[i+1]:
                    ans += r[i+1]
                else :
                    ans += r[i]
        else :
            for i in range(0, len(r)-1, 2):
                if r[i] > r[i+1]:
                    ans += r[i+1]
                else :
                    ans += r[i]    
        print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
num = 1000000
if s.count('#') == 0 or s.count('.') == 0:
    print(0)
    exit()
for i in range(n):
    if s[i - 1] == s[i]:
        continue
    num = min(num,s[:i].count('#') + s[i:].count('.'))
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
flg = 0
cntB = 0
cntW = 0

for i in range(N):
    if S[i] == '#':
        flg = i
        break

for j in range(N - flg):
    if S[flg + j] == '.':
        cntB += 1
    if S[flg + j] == '#':
        cntW += 1

print(min(cntB, cntW))

Submission status: Wrong Answer

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

cnt = 0
for i in S:
    if i == '#':
        cnt += 1
    else:
        break

ANS1 = S[cnt:].count('.') 

cnt = 0
newS = ''.join(list(reversed(S)))
for i in newS:
    if i == '#':
        cnt += 1
    else:
        break

ANS2 = newS[cnt:].count('.') 

print(min(ANS1, ANS2))

Submission status: Wrong Answer

Solution code:
def stones(s):
    k = 0
    for i in range(len(s)-1):
        if s[i]=='#' and s[i+1]=='.':
            s[i+1] = '#'
            k = k+1
    return k

n = int(input())
s = list(input())
print(stones(s))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())  
s = input()  
cnt = Counter(s)
cb = cnt['#']
cw = cnt['.']

for i in range(n):
  if s[i] == '.':
    cw -= 1
  else:
    break
    
for i in range(n-1, 0, -1):
  if s[i] == '#':
    cb -= 1
  else:
    break

print(min(cw,cb))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count1 = 0
count2 = 0
for i in range(N-1):
    if S[i:i+2] == '#.':
        count1 += 1

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

print(min(count1, count2))

Submission status: Wrong Answer

Solution code:
import sys

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N-1):
        if S[i:i+2]=='#.':
            if i==0 or ((i-1)>=0 and S[i-1]=='.'):
                # S = S[:i] + '.' + S[i+1:]
                ans += 1
            else:
                # S = S[:i+1] + '#' + S[i+2:]
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
S=list(input())
ans1=0
tmp=0
ans2=0
A=copy.copy(S)
for i in range(N-1):
  if A[N-i-1]=='#' and A[N-i-2]=='#':
    A.pop(N-i-1)
    tmp+=1
for i in range(N-tmp-1):
  if A[i]=='#':
    ans1+=1
for i in range(N-1):
  if S[i]=='#':
    if S[i+1]=='.':
      S[i+1]='#'
      ans2+=1
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == '.':
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
tw = 0
tb = 0
A = 0
for i in range(N):
    if c == 0 and S[i] == '#':
        if cw[N - 1] - cw[i] >= cb[N - 1] - cb[i] + 1:
            a += 1
        else:
            A = cw[N - 1] - cw[i]
            c = 1
            tb += 1
    elif c == 1 and S[i] == '#':
        tb += 1
    elif c == 1 or c == 2 and S[i] == '.':
        c = 2
        tw += 1
    elif c == 2:
        if tb > tw:
            a += A
            print(a)
            break
        else:
            c = 0
            a += tb
            tw = 0
            tb = 0
print(a + tw)

Submission status: Wrong Answer

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

a=0
b=0

if S.find("#.") != -1:
    for i in S:
        if i == "#":
            a+=1
        else:
            b+=1

    if a>b:
        print(b)
    else:
        print(a)

else:
    print(0)

Submission status: Wrong Answer

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

'''考え方
1.白・黒それぞれの一番左端の位置を確認する
2.黒の右に白い石が存在するか否かを判断
3.変更するべき石の数が、白・黒どちらの方が多いか判断
'''

first_white = S.find('.')
first_black = S.find('#')
last_white = S.rfind('.')
last_black = S.rfind('#')

# blackのラストブロックのサイズを求めておく

cnt = 1
for s in reversed(S[:last_black]):
  if s == '#':
    cnt += 1
  else:
    break


out = 0
# 1.どちらか一色のみ 
if first_black == -1 or first_white == -1:
  out = 0

# 2.左に白、右に黒、と完全に別れる場合
elif last_white < first_black:
  out = 0

# 3.左に黒、右に白、と完全に別れる場合
elif last_black < first_white:
  out = min(S.count('.'),S.find('#'))

# 4.混在
else:
  # 4-1.一番右のブロックが白色
  if last_white > last_black:
    cnt_white = S[first_black:].count('.')
    cnt_black = S[first_black:].count('#')
  # 4-2.一番右のブロックが黒色
  else:
    cnt_white = S[first_black:].count('.')
    cnt_black = S[first_black:].count('#') - cnt

  out = min(cnt_white,cnt_black)



print(out)

Submission status: Wrong Answer

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

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

print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = list(S)

change = False
count = 0
for c in s:
    if c == '#':
        change = True
    elif change == True:
        count += 1

change = False
r_count = 0
for c in (reversed(s)):
    if c == '.':
        change = True
    elif change == True:
        r_count += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
prev = ''
count = 0

for i in range(n):
    if prev == "#" and s[i] == ".":
        count += 1
    prev = s[i]

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input().lstrip(".").rstrip("#")
print(min(S.count("#"), S.count(".")))