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()
dp = [0 for i in range(N)]
b = 0
w = 0
flag1 = True
flag2 = True
for i in range(N):
    if flag1 and S[i] == '.':
        pass
    elif flag1:
        flag1 = False
        b += 1
    elif S[i] == '.':
        dp[i] = b
    else:
        b += 1

for i in reversed(range(N)):
    if flag2 and S[i] == '#':
        pass
    elif flag2:
        flag2 = False
        w += 1
    elif S[i] == '#':
        dp[i] = w
    else:
        w += 1
ans = float('inf')
for i in range(N-1):
    if (S[i] == '.' and S[i+1] == '#') or (S[i] == '#' and S[i+1] == '.'):
        ans = min(ans,dp[i]+dp[i+1])

if ans == float('inf'):
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

start = -1
black = 0
white = 0

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()[::-1]
i = 0
while S[i] == "#":
	if i == N-1:
		break
	i += 1
c = 0
t = i
while i < N:
	if S[i] == "#":
		c += 1
	i += 1
print(min(c,(N-t)-c))

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=list(input()[:-1])
b=S.count(".")
w=N-b
print(min(b,w))

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()
## ケース: ..##..##.. の場合、先頭の要素を除いたもので少ない方のみ変換すればよい
else:
  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])

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
flag = 0
for i in range(n):
    if s[i] == '#':
        location = i
        flag = 1
        break

if flag == 0:
    print(0)
else:
    print(s[location:n].count('.'))

Submission status: Wrong Answer

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

count = 0

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

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

print(min(sharp_num,dot_num))

Submission status: Wrong Answer

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

s.count('#.')

Submission status: Wrong Answer

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

white = 0
black = 0

if N != 0:
  if S[N-1] == "#":
    N = N-1

  if S[0] ==".":
    N = N-1

  for i in range(N):
    if S[i] == "#":
      black +=1
    else:
      white +=1
  print(min(white,black))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
countbw = s.count("#.")
print(countbw)

Submission status: Wrong Answer

Solution code:
n=2
string_list=[input() for i in range(n)]
c=0
new=''
a=0
b=0
f=0
for stone in string_list[1]:
    if stone=='.' and c==0:
        continue
    elif stone=='#':
        c+=1
        a+=1
        f+=1
    elif stone=='.':
        b+=1
        f=0

if b>=a:
    print(a-f)
else:
    print(b)

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(1)
else:
    S = S[b_start:w_goal+1]
    print(min(S.count('.'),S.count('#')))

Submission status: Wrong Answer

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

blackCnt = 0
whiteCnt = 0

for i in range(n):
    if stone[i] == '#':
        blackCnt += 1
    elif stone[i] == '.' and blackCnt > 0:
        whiteCnt += 1

if blackCnt > 0 and whiteCnt > 0:
    if blackCnt > whiteCnt:
        print(whiteCnt)
    else:
        print(blackCnt)
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

'''
black_count = 0
white_count = 0
right_white_pos=-1
for i in range(N):
    if(S[i]=="."):
        white_count+=1
        right_white_pos=i
    else:
        black_count+=1

counter = 0
for i in range(N):
    if(i<right_white_pos):
        if(S[i]=="#"):
            counter +=1

print(white_count)
print(black_count)
print(counter)
print(min(white_count, black_count, counter))
'''


black_count = 0
white_count = 0
right_white_pos=-1
for i in range(N):
    if(S[i]=="."):
        white_count+=1
        right_white_pos=i
    else:
        black_count+=1

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

print(min(white_count, black_count, counter))

Submission status: Wrong Answer

Solution code:
N = int(input())
K = list(input())
count = 0
count_b = 0
b=-1

for i in range(N):
    if K[i]=='#':
        b = i
        break
    else :
        continue

if b != -1:
    for j in range(N-b-1):
        if K[j+b+1] == '.':
            count+=1
        elif K[j+b+1] == '#':
            count_b +=1


c = min(count,count_b+1)

if c != N-1:
    print(c)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
if all([v == '.' for v in s]):
    print(0)
else:
    t = s[s.index('#'):]
    print(min(t.count('.'), t.count('#')))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
black = False
cnt = 0
for i in range(n):
    if s[i] == "#":
        black = True
    elif black:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

idx = -1
flag = 0
for i, s in enumerate(S):
    if s == '.' and flag:
        idx = i - 1
        break
    if s == '#':
        flag = 1
        
if idx < 0:
    print(0)
    sys.exit()    
    
S = S[idx:]

if S[-1] == '#':
    idx = 0
    for i in range(len(S)):
        if S[-(i + 1)] == '#':
            continue
        idx = i
        break
    if idx == 0:
        print(0)
        sys.exit()
    S = S[: -idx]
    

num_black = S.count('#')
num_white = S.count('.')
print(min([num_black, num_white]))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c=S.count('#')
if ('.' in S) & ('#' in S):
	s=S.index('.')
	p=S.index('#')
	k=S[s::]
	a=k.count('.')
	if s==0:
		print(0)
	elif a>c:
		 print(c)
	else:
		 print(a)
else:
	print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = 200000
for i in range(n):
    x = 0
    for k in range(i + 1):
        if s[k] == '#':
            x += 1
    for k in range(n - i - 1):
        if s[k] == '.':
            x += 1
    if x < ans:
        ans = x
print(ans)

Submission status: Wrong Answer

Solution code:
black = '#'
white = '.'

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

    ans = 0

    for i in range(len(s)):
        if needToChange(s, i):
            s[i] = black
            ans += 1

    print(ans)

def needToChange(s, i):
    if s[i] == white:
        return False
    if i >= len(s) - 1:
        return False
    if s[i + 1] == white:
        return True
    return False

main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(str(input()))
l=[]
w=0
b=0
wl=[]
bl=[]
for i in range(n):
    if s[i]==".":
        w+=1
    else:
        b+=1
    wl.append(w)
    bl.append(b)
if "#" not in s or "." not in s:
    print(0)
else:
    ans=[]
    for i in range(n):
        ans.append(bl[i]+wl[-1]-wl[i])
    print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()[::-1]
i = 0
while S[i] == "#":
	if i == N-1:
		break
	i += 1
c = 0
t = i
print(t)
while i < N:
	if S[i] == "#":
		c += 1
	i += 1
print(min(c,(N-t)-c))

Submission status: Wrong Answer

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

S1 = list(S)
S2 = list(S)

count1 = 0
count2 = 0

while(1):
  if "#." not in str("".join(S1)):
    break
  for i in range(N-1):
    if S1[i] == "#" and S1[i+1] == ".":
      S1[i+1] = "#"
      count1 += 1
while(1):
  if "#." not in str("".join(S2)):
    break
  for i in range(N-1):
     if S2[i] == "#" and S2[i+1] == ".":
       S2[i] = "."
       count2 += 1


print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=list(input()[:-1])
print(S)
b=S.count(".")
w=N-b
print(min(b,w))

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
s = input().strip()
 
exe1 = ""
exe2 = ""
exe3 = ""
 
for i in range(n):
  exe1 = exe1 + "#"
  exe2 = exe2 + "."
  if i < n-1:
    exe3 = exe3 + "."
  else:
    exe3 = exe3 + "#"
    
cnt1 = 0
cnt2 = 0
cnt3 = 0
 
for i in range(n):
  if s[i] != exe1[i]:
    cnt1 += 1
  if s[i] != exe2[i]:
    cnt2 += 1
  if s[i] != exe3[i]:
    cnt3 += 1
    
mincnt = cnt1
if mincnt > cnt2:
  mincnt = cnt2
if mincnt >cnt3:
  mincnt = cnt3
  
print(mincnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


from sys import stdin



############################################


# read data for n sequences.
n = stdin.readline()
N = int(n)
n = stdin.readline()
S = str(n)

#data = [int(stdin.readline().rstrip()) for _ in range(n)]

out=[]
count=0
for i,l in enumerate(S):
	if i < N:	
		if l == "#":
			count+=1

# count black on right
countX=0
for l in reversed(S):
	print(l)
	if l == "#":
		countX+=1
	else:
		break
N-=countX
count2=N-count
count-=countX
print(min([count,count2]))

Submission status: Wrong Answer

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

f = 0
cnt = 0
for s_ in s:
  if f == 0 and s_ == "#":
    f = 1
  if f == 1 and s_ == ".":
    cnt = cnt + 1
print(cnt)

Submission status: Wrong Answer

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

score1 = 0
score2 = 0
length = 1
check = S[0]
A = []

for i in range(N-1):
    if S[i] == S[i+1]:
        length += 1
    else:
        A.append(length)
        length = 1

if length != 1:
    A.append(length)

if len(A) != 0:
    if S[-1] != S[-2]:
        A.append(1)

if len(A) == 0:
    A.append(0)

if S[0] == ".":
    A.pop(0)

if S[len(S)-1] == "#":
    A.pop(-1)


for i in range(len(A)):
    if i % 2 == 0:
        score1 += A[i]
    else:
        score2 += A[i]

ans = min(score1,score2)


print(ans)

Submission status: Wrong Answer

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

N = int(input())
S = str(input())
Sarray = list(S)
Sarraynum = []

#白0
for i in range(len(Sarray)):
    if Sarray[i] == '.':
        Sarraynum.append(0)
    else:
        Sarraynum.append(1)

a = 2 * len(Sarraynum)
for i in range(len(Sarraynum)):
    black2white = 0
    white2black = 0
    jmax = len(Sarraynum) - i - 1
    if jmax < i:
        jmax = i

    for j in range(jmax):
        if j <= i:
            black2white += Sarraynum[j]
        if i + 1 + j < len(Sarraynum):
            if Sarraynum[i + 1 + j] == 0:
                white2black += 1

        if black2white + white2black >= a:
            break
    
    if black2white + white2black < a:
        a = black2white + white2black


print(a)

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]=='.':
            k = k+1
    return k

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

Submission status: Wrong Answer

Solution code:
N = int(raw_input())                                                                                                                                           
S = list(raw_input())                                                                                                                                          
                                                                                                                                                               
c = 0                                                                                                                                                          
for i in range(N):                                                                                                                                             
      if S[N-1-i] == "#":                                                                                                                                      
            c += 1                                                                                                                                             
      else:                                                                                                                                                    
            break                                                                                                                                              
if c > 0:                                                                                                                                                      
      S = S[:-c]                                                                                                                                               
                                                                                                                                                               
cc = 0                                                                                                                                                         
                                                                                                                                                               
for j in range(N-c):                                                                                                                                           
      if S[j] == ".":                                                                                                                                          
            cc += 1                
if N-c-cc > 0:
      print(min(cc, N-c-cc))
else:
      print("0")

Submission status: Wrong Answer

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

sl = []
for i in range(n):
    sl += s[i]

c = 0
cs = []
for i in range(n):
    l = ['.']*n
    for k in range(i, n):
        l[i] = '#'
    for k in range(n):
        if l[k] != sl[k]:
            c += 1
    cs += [c]
print(min(cs))

Submission status: Wrong Answer

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

state = False
counter = 0

for i in range(N):
  if S[i] == ".":
    counter += 1
  else:
    break
S = S[counter:]

for i in range(len(S)):
  if S[i] == "#":
    state = True
    counter += 1
  else:
    counter = 0
    state = False
if state == True:
  S = S[:-1*counter]
  
b_num = S.count("#")
w_num = len(S) - b_num
if b_num <= w_num:
  print(b_num)
else:
  print(w_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
k = -1
for i in range(N):
    if s[i] == "#":
        k = i
        break
if k == -1:
    print(0)
else:
    if s[-1]=="#":
        print(min(s[k:N+1].count("."), s.count("#")-1))
    else:
        print(min(s[k:N+1].count("."), s.count("#")))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
k = -1
for i in range(n):
    if s[i] == '#':
        k = i
        break

if k == n-1:
    pass
elif k == -1:
    pass      
else:
    for j in range(k, n):
        if s[j] == '.':
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import re

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

result = len(re.findall('#\.', s))

print(result)
#
# cntList = list()
# for i in range(n+1):
#     tmp = len(re.findall('#', s[:i]))
#     tmp += len(re.findall('\.', s[i:]))
#     cntList.append(tmp)
#
# print(min(cntList))

Submission status: Wrong Answer

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

ans = 0
index = 0
index2 = 0

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

ans += N - index - 1

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

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

a = s.count("#")
b = s.count(".")
cnta = 0
cntb = 0
ans = MAX_INT
for i in range(N):
	if s[i] == "#":
		ans = min(ans,cnta + (b-cntb))
		cnta += 1
	else:
		cntb += 1
if ans == MAX_INT:
	print(0)
else:
	print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = raw_input()
S = raw_input()
 
flag = 0
cnt = 0
cnt2 = 0
for s in S:
    if s == '#':
        flag = 1
        cnt2 +=1
    elif s == '.' and flag ==1:
        cnt += 1

print(min(cnt, cnt2))

Submission status: Wrong Answer

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

num_black = S.count('#')
num_white = S.count('.')

if num_white < num_black:
    cnt = 0
    S = S[::-1]
    idx = S.index('#')
    prev = S[idx]
    for i in S[idx:]:
        if prev == i:
            cnt +=1
        else:
            break
else:
    cnt = num_white

            
print(cnt)

Submission status: Wrong Answer

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

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

else:
    for i in range(n):
        if s[i] != "#":
            count += 1
    ans = min(count, n-count)


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s=list(input())
ii = -10
count_a = 0
count_b = 1
for index, i in enumerate(s):
  if i == '#' and ii == -10:
    ii = index
    continue;
  elif ii == -10:
    continue;
  else:
    if i == '.':
      count_a+=1
    else:
      if index != N-1:
      	count_b+=1
      
print(min(count_a, count_b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
sc =[]
for i in s:
  sc.append(i)
c = 0
cc = 0

def check():
  for i in range(n-1):
    j = i + 1
    if s[i] == "#" or sc[i] == "#":
      if s[j] == "." or s[j] == ".":
        return True
  return False

while check():
    for i in range(n-1):

      j = i + 1
      if s[i] == "#":
        if s[j] == ".":
          s[j] = "#"
          c += 1

    for i in range(1,n):
      j = i - 1
      if sc[j] == "#":
        if sc[i] == ".":
          sc[j] = "."
          cc += 1
print(min(c,cc))

Submission status: Wrong Answer

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

s_w = S.count('.')
s_b = S.count('#')

if N%2 == 0:
  print( min(S[:N//2].count('#')+S[N//2:].count('.'),min(s_w,s_b)) )
else:
  print( min(S[:N//2].count('#')+S[N//2:].count('.'),S[:N//2+1].count('#')+S[N//2+1:].count('.'),min(s_w,s_b)) )

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n = int(input())
s = input()
a = list(s)

shiro = 0
kuro = 0
flg = False
start = 0
end = 0
for i in range(n):
    if s[i] == '#':
        start = i
        break
for i in reversed(range(n)):
    if s[i] == '.':
        end = i
        break
for i in range(start, end + 1):
    if s[i] == '#':
        kuro += 1
    else:
        shiro += 1
mx = min(kuro, shiro)
print(mx)

Submission status: Wrong Answer

Solution code:
import sys

N =  int(sys.stdin.readline())
S = sys.stdin.readline()[:-1]
res = 0


if S.count('#') < S.count('.'):
  if S[-1] != '#':
    res = S.count('#')
  else:
    res = S.count('#') -1
else:
  if S[0] != '.':
    res = S.count('.')
  else:
    res = S.count('.') - 1

print(res)

Submission status: Wrong Answer

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

targ="#."

ans=S.count(targ)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input())
b=a.copy()
c=a.copy()

sum=0
sum2=0

for i in range(1,n):
  if (a[-i] == "." and a[-i-1] == "#"):
    a[-i-1] = "."
    sum += 1
    
for i in range(n-1):
  if (c[i] == "#" and c[i+1] == "."):
    c[i+1] = "#"
    sum2 += 1
    
print(min([b.count("."),b.count("#"),sum,sum2]))

Submission status: Wrong Answer

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

SLFront = list(S)
SLRear = list(S)

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

#print(SLFront)
countF = 0
for i in range(len(SLFront)-1):
	if SLFront[i] == "#" and SLFront[i+1] == ".":
		SLFront[i] = "."
		countF += 1
		
#print(countF,SLFront)

#print(SLRear)
countR = 0
for i in range(len(SLRear)-1):
	if SLRear[i] == "#" and SLRear[i+1] == ".":
		SLRear[i+1] = "#"
		countR += 1
		
#print(countR,SLRear)

print(min(countF,countR))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
s = 0
l = N - 1
while s < N and S[s] == ".":
    s += 1
while l >= 0 and S[l] == "#":
    l -= 1
if s >= l:
    print(0)
    exit()
ans = min(S[s:l+1].count("."), S[s:l+1].count("#"))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

cnt = 0
if first_black == N:
    pass
else:
    for i in range(first_black-1,N,1):
        if S[i] == '.':
            cnt += 1

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


white = N-first_black-cnt+1-b_cnt
    
if white > cnt:
    print(cnt)
else:
    print(white)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
c=0
b=0
k=[1,1]
for i in range(n):
  if s[i]=="." and s[i-1]=="#":
    c+=b
    b=0
  elif s[i]=="#":
    b+=1
  else:
    b=0
if c>(n/2):
  print(n-c)
else:
  print(c)

Submission status: Wrong Answer

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

flag = -1
for char in S:
    if char == '#' and flag == -1:
        flag += 1
    if flag != -1 and char == '.':
        flag += 1
if flag == -1:
    flag += 1
print(flag)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=s.count(".")
ans=0
if s[0]=="#":
  print(a)
else:
  for i in range(n):
    if s[i]==".":
      ans+=1
    else:
      break
  print(a-ans)

Submission status: Wrong Answer

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

S.reverse()
counterL=0
for i in range(N-1):
    if S[i]=='.' and S[i + 1]=='#':
        counterL+=1
if counterR < counterL:
    print(counterR)
else:
    print(counterL)

Submission status: Wrong Answer

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

i = 0
y = 0
for x in range(N):
    if i^int(S[x]) == 1:
        y += 1

i = 1
n = 0
for m in range(N):
    if i^int(S[m]) == 1:
        n += 1

print(min(y, n))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
blacknum = []
whitenum = []
cnt = 0
now = 0
blackcnt = 0
whitecnt = 0

for i in range(N):
    if now == 0 and S[i] == '#':
        whitenum.append(whitecnt)
        blackcnt += 1
        now = 1
    elif now == 1 and S[i] == '.':
        blacknum.append(blackcnt)
        whitecnt += 1
        now = 0
    elif now == 0 and S[i] == '.':
        whitecnt += 1
    else:
        blackcnt += 1

if now == 0:
    whitenum.append(whitecnt)
else:
    blacknum.append(whitecnt)
if len(whitenum) == len(blacknum):
    whitenum.append(whitecnt)

ans = 0
for i in range(len(blacknum)):
    if blacknum[i] < (whitenum[-1] - whitenum[i]):
        ans = blacknum[i]
    else:
        ans += whitenum[-1] - whitenum[i]
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c1 = 0
for i in range(N - 1, -1, -1):
    if S[i] == ".":
        c1 = i
        break
c2 = 0
for i in range(N):
    if S[i] == '#':
        c2 = i
        break
a = S[:c1 + 1].count(".")
b = S[:c1 + 1].count("#")
cc = S[c2:].count("#")
d = S[c2:].count(".")
ans = min(a, b, cc, d)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#左からleft_count番目が黒い石

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

right_count = 1
for i in range(n):
    if s[-(i + 1)] == ".":
        break
    right_count = right_count + 1

w_count = 0
for i in range(n - left_count):
    if s[i + left_count] == ".":
        w_count = w_count + 1

b_count = 0
for i in range(n - right_count):
    if s[i] == "#":
        b_count = b_count + 1

print(min(w_count, b_count))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cnt = 0 # [. #]

while(len(s)>0 and s[0] == "."):
	s.pop(0)
for i in range(1,len(s)):
	if(s[i] == "."):
		cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
def count_stone(N,S):
    black = 0
    white = 0
    for stone in S:
        if stone == '#':
            black += 1
        else:
            white += 1
    print(min(black,white))

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

count_stone(N,S)

Submission status: Wrong Answer

Solution code:
num = int(input())
stone = list(input())

count = 0
new_stone = ""
for i in range(num - 1):
    if stone[i] == "#" and stone[i + 1] == ".":
        if i == 0:
            stone[i] = "."
        else:
            stone[i + 1] = "#"
        count += 1
# print(count, "".join(stone))
print(count)

Submission status: Wrong Answer

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

A = S.count("#")
B = S.count(".")

if(A == 0 or B == 0):
    print("0")
else:
    P = S.find("#")
    print(S.count(".",P+1))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
cd = 0 ; dh = 0; ok = False
for i in range(0 , len(s)):
  if(s[i] == '#'):
    ok = True ; dh += 1
  if(ok and s[i] == '.'):
    cd += 1
print(min(cd , dh))

Submission status: Wrong Answer

Solution code:
import re

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

ans = len(re.findall("#.#", s))

if s[-2:] == "#." :
    ans+=1;

print(ans)

# .#.#.#.#.

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
i=0
while i < N-1:
    idx = i
    if S[i] == '#' and S[i+1] == '.':
        ans += 1
        
        i += 1
        
        for j in range(1,N):
            if idx -j < 0 or idx + 1 + j > N-1 : break

            if S[idx-j] == '#' and S[idx+1+j] == '.':
                ans += 1
                i += 1
            else:
                break
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
p=[]
m=0
x=s.count("#.")
while x>0:
    x=s.count("#.")
    s=s.replace("#.","..",x)
    m+=x
    p.append(m)
w=s.count("#")
e=n-w
if w>e:
    m=w-e
    p.append(m)
else:
    m=e-w
    p.append(m)
print(min(p))

Submission status: Wrong Answer

Solution code:
#C - Stones
n = int(input())
s = list(input())
isFound = False
cnt = 0
right = 0
#一番右の白を見つける
for i in range(n):
    if s[i] == '.':
        right = max(right, i)
#rightまでの黒を数える
for i in range(right):
    if s[i] == '#':
        cnt += 1
print(min(s.count('.'), s.count('#'), cnt))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=[]
for i in s:
  a.append(i)
if ("#" in a )and("." in a):
  k=a.index("#")
  ans1=a[k+1:len(a)].count(".")
  a.reverse()
  k=a.index(".")
  ans2=a[k+1:len(a)].count("#")
  print(min(ans1,ans2))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
end = len(s) -1

s1 = s[:]
i = 0
ans1 = 0
while(i < end):
    c = s1[i] + s1[i+1]
    if c == '#.':
        s1 = s1[:i] + '.' + s1[i+1:]
        ans1 = ans1+ 1
    i += 1

s2 = s[:]
i = 1
end = len(s)
ans2 = 0
while(i < end):
    c = s2[i-1] + s2[i]
    if c == '#.':
        s1 = s1[:i-1] + '#' + s1[i:]
        ans2 = ans2 + 1
    i += 1


if ans1 <= ans2:
    print(ans1)
else:
    print(ans2)