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()
S=S+'9'
ans=0
for i in range(N):
    if S[i]=='#' and S[i+1]=='.':
        cntj=0
        for j in range(i,0,-1):
            if S[j]=='#':
                cntj+=1
            else:
                break
        cntk=0
        for k in range(i+1,N):
            if S[k]=='.':
                cntk+=1
            else:
                break
        if cntj > cntk:
            ans += cntj
        else:
            ans += cntk
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
st=input()
flag=False
count=0
for i in range(n):
	if st[i]=='#' and not flag:
		flag=True
	if flag and st[i]=='.':
		count+=1
count1=0
flag=False
for i in range(n):
	if st[-i]=='.' and not flag:
		flag=True
	if flag and st[-i]=='#':
		count1+=1

print(min([count,count1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if all([s[i]=="#" for i in range(n)]):
    print(0)
    exit()
try:
    a=s[::-1].index("#")
    b=s.index("#")
except:a=b=0
count=0
for i in range(b+1,n-a):
    if s[i]=="#":count+=1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if not '#.' in s:
    print(0)
else:
    s = s.split('#.', 1)[-1]
    print(s.count('.')+1)

Submission status: Wrong Answer

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

count = 0

for i in range(1, N):

    tmp = S[i]

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


print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())-1
s = [x for x in input()]
count_a = 0

for i in range(len(s)-1):
    if(s[i] == "#" and s[i+1] == "."):
        s[i+1] = "#"
        count_a = count_a + 1

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

if count_a >= count_b:
    count = count_a
else:
    count = count_b

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
whi=0
bla=0
c1=0
for i in S:
    if i==".":
        break
    c1+=1
for i in S:
    if i==".":
        whi+=1
    else:
        bla+=1
if whi==0 or bla==0:
    print(0)
    quit()
c2=0
for i in S[::-1]:
    if i=="#":
        break
    c2+=1
print(min(whi-c1,bla-c2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
S1 = S[:]
S2 = S[:]
S3 = S[:]
output1 = 0
output2 = 0
output3 = 0

for i in range(N):
    if S1[i] == "." :
        S1[i] = "#"
        output1 += 1
for j in range(N):
    if S2[j] == "#":
        S2[j] == "."
        output2 += 1

flag = 0
for k in range(N):
    if (S3[k] == ".") and (flag==1):
        S3[k] == "#"
        output3 += 1
    if (S3[k] == "#") and (flag==0):
        flag = 1

output = min(output1,output2,output3)
print(output)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
flag = False
for char in S:
    if char == '#':
        flag = True
        continue
    elif flag:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=[]
for i in range(n):
    if i==0:
        if s[0]=="#":
            a.append(1)
        else:
            a.append(0)
    else:
        if s[i]=="#":
            a.append(a[i-1]+1)
        else:
            a.append(a[i-1])
min=n
for i in range(n):
    m=a[i]
    r=n-i-1-(a[n-1]-a[i])
    q=m+r
    if q<min:
        min=q
if a[n-1]==n:
    min=0
print(min)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
ans1=0
ans2=0
for i in range(N-1):
  if S[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 = input()

li = list(S)
temp1 = 0
temp2 = 0
count = 0

for i in range(N-1):
    if '#' == li[i] and '.' == li[i+1]:
        li[i] = '.'
        temp1 += 1

li = list(S)
for i in range(N-1):
    if '#' == li[i] and '.' == li[i+1]:
        li[i+1] = '#'
        temp2 += 1

count = min(temp1, temp2)
print(count)

Submission status: Wrong Answer

Solution code:
import re
N = int(input())
S = input()
S = re.sub("(?<=\.)#+$", "", S)
S = re.sub("^\.+(?=#)", "", S)
if len(S) == 0:
    print("0")
else:
    n_white = S.count(".")
    n_black = S.count("#")
    print(min(n_white, n_black))

Submission status: Wrong Answer

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

l = []
for i in S:
	if i == '#':
		l.append(0) #黒
	else:
		l.append(1) #白



ans = 0
for i in range(len(l)):
	if l[i:i+2] == [0, 1]:
		ans = ans + 1
		l[i+1] = 0


print(ans)

Submission status: Wrong Answer

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

f = 0
w = 0
b = 0
b2 = 0
sb = '$'
for s in S:
    if s=='.' and sb=='#':
        f=1

    if f and s=='.':
        w+=1

    if s=='#':
        b+=1
        b2+=1
    else:
        b2=0
    sb=s

print(min(w, b-b2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
f = S.find('#')
black = S.count('#',f,S.rfind('.'))
white = S.count('.',f)
if black < white:
    print(black)
else:
    print(white)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 10 ** 9
White = [0] * (N + 1)
Black = [0] * (N + 1)
for i, c in enumerate(S):
    if c == ".":
        White[i + 1] = White[i] + 1
        Black[i + 1] = Black[i]
    else:
        White[i + 1] = White[i]
        Black[i + 1] = Black[i] + 1

ans = min(ans, Black[N], White[N])

for i in range(1, N):
    temp = Black[i] + White[N] - White[i-1]
    ans = min(ans, temp)
print(ans)

Submission status: Wrong Answer

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

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


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

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

Submission status: Wrong Answer

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

cnt = 0
i = 0
while True:
    if s[i] == '.':
        break
    else:
        if i == n-1:
            break
    i += 1

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

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
a = []
for l in sys.stdin:
    a.append(l)


haichi = a[0]
prev_haichi = '.'
count = 0
for each_haichi in haichi:
    if prev_haichi == '#' and each_haichi == '.':
        count += 1
        prev_haichi = '#'
    else:
        prev_haich = each_haichi
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
arg=0
for i in range(n):
    if s[i]=="#":
        arg=i
        break
ans=s[arg:].count(".")
ans_1=s.count("#")
k=0
for i in range(n):
    if s[-1-i]!="#":
        break
ans_1-=i
print(ans if ans < ans_1 else ans_1)

Submission status: Wrong Answer

Solution code:
n = int(input())
k,d = 0,0
s = list(input())
 
for i in s:
  if s == '#':
    k+=1
  else:
    d+=1
print(min(k,d))

Submission status: Wrong Answer

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

#違反している黒と白の数数えて
#少ない方で置き換える

answer = 0

#まず一番左の黒のいちを見つける
left_black = -1
right_white = -1

for i in range(N):
    if S[i]=='#':
        if S.count('#')==N-i:
            break
        left_black = i
        break

for i in reversed(range(N)):
    if S[i]=='.':
        right_white = i
        break

# print(right_white)



# print(left_black)
#left_blackが-1かN-1なら自動的に0


if left_black!=-1 and left_black!=N-1:
    white_disc = S[left_black:right_white+1].count('.')
    black_disc = S[left_black:right_white+1].count('#')
    if(white_disc<black_disc):
        answer = white_disc
    else:
        answer = black_disc

print(answer)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

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

print(cnt)

Submission status: Wrong Answer

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

if S.find("#") == -1 or S.find(".") == -1:
    print(0)

else:
    x = S[S.find("#"):].count(".")
    y = S[:(S.rfind(".")+1)].count("#")
    print(min(x,y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flag = 0
count = 0
for i in range(N):
    if S[i] == '#':
        flag = 1
    else:
        if flag == 1:
            S[i] = '#'
            count = count + 1

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    S = lines.pop(0)
    # reverse
    S = S[::-1]
    try:
        # 白が現れるまで省く
        idx = S.index('.')
        S = S[idx:]
        #あとは少ない方を裏返せば良い
        print(min(S.count('.'), S.count('#')))
    except:
        print(0)

lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

Submission status: Wrong Answer

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

s=input()

tr = "#"
ans_1 = 0
ans_2=0
for i in range(n):
	if tr != s[i]:
		ans_1 +=1

tr ="."
for i in range(n):
	if tr != s[i]:
		ans_2 +=1
        
print(ans_1 if ans_1 <= ans_2 else ans_2)

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

for i in S:
    if S.sum()==0:
        print(0)
        break
    elif i==1:
        print((S[i:]!=1).sum())
        break

Submission status: Wrong Answer

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

# 白にする
res1 = 0
for i in range(len(s) - 1):
    if s[i] == "#":
        res1 += 1

# 黒にする
res2 = 0
for i in range(1, len(s)):
    if s[i] == ".":
        res2 += 1

print(min(res1, res2))

Submission status: Wrong Answer

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

print(s.count("#."))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = str(input())
res = 0

for i in range(a):
    if b[i:i+2] == "#.":
        res = b[i:a].count(".")
        break
        
for i in range(a,-1,-1):
    if b[i:i+2] == "#.":
        res = min(b[0:i+2].count("#"),res)
        break

print(res)

Submission status: Wrong Answer

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

flug = False
cnt = 0
for i,n in enumerate(S):
    if S[i]=='#':
        flug=True
    else:
        if flug and S[i]=='.':
            cnt+=1
        flug=False
    
print(cnt)

Submission status: Wrong Answer

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

replace_dot_result = 0
replace_sharp_result = 0
is_before_white_only = True
for char in s:
    if char == "#":
        is_before_white_only = False
        replace_sharp_result += 1

    elif not is_before_white_only and char == ".":
        replace_dot_result += 1

print(min(replace_dot_result, replace_sharp_result))

Submission status: Wrong Answer

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#n=int(input())
#li=input().split()
#S=input()
#import fractions
#lis=list(map(int,input().split()))

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

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


print(ans)

Submission status: Wrong Answer

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

if N == 1 :
    ans = 0
else :
    a = S.count(".")
    if "#" in S[:-1] :
        ans = min(a, N-a)
    else :
        ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
dp = [0 for i in range(N)]
b = 0
w = 0
for i in range(N):
    if S[i] == '.':
        dp[i] = b
    else:
        b += 1

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
S=S+'9'
ans=0
for i in range(N):
    if S[i]=='#' and S[i+1]=='.':
        cntj=0
        for j in range(i,0,-1):
            if S[j]=='#':
                cntj+=1
            else:
                break
        cntk=0
        for k in range(i+1,N):
            if S[k]=='.':
                cntk+=1
            else:
                break
        if cntj > cntj:
            ans += cntj
        else:
            ans += cntk
print(ans)

Submission status: Wrong Answer

Solution code:
input()
s = input()
i = s.find('#')
if i < 0:
    print(0)
else:
    print(s[i+1:].count('.'))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
list = [0]*N

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

print(max(list))

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+1]='#'
        count+=1
print(count)

Submission status: Wrong Answer

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

ans = 0
flag = True

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

if flag == False:
    print(s.count('.'))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ndot=0
nx=0
mx=10000000
for i in range(n+1):
    if i==0:
        ndot=sum([1 for i in s if i=="."])
        nx=0
    else:
        if s[i-1]==".":
            ndot-=1
        elif s[i-1]=="#":
            nx+=1

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
scount=0
ccount=0
for i in b:
        if scount==0 and i ==".":
                pass
        elif i =="#":
                scount=1
        elif i == ".":
                ccount+=1
                scount=0
                
print(ccount)

Submission status: Wrong Answer

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

BKList = [i for i in range(N) if S[i] == '#']
if BKList != []:
    idx = min(BKList)
    BK = S[idx + 1:].count('.')
else:
    BK = 0

WHList = [i for i in range(N) if S[i] == '.']
if WHList != []:
    idx = max(WHList)
    WH = S[:idx].count('#')
else:
    WH = 0
print(min(BK, WH))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
nb = s.count('#')
nw = s.count('.')
if nw == n or nb == n:
    print(0)
    exit()
lb = 0
rw = nw
print(lb, rw)

b = False
ans = float('inf')
for i in range(n):
    if b == False and s[i] == '#':
        ans = min(ans, lb + rw)
        b = True
        lb += 1
    elif s[i] == '#':
        b = False
    elif s[i] == '.':
        rw -= 1
        b = False
print(ans)

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):
  #print(input_str[i],target)
  if input_str[i] == target:
    stones = stones + target
  else:
    stones_list.append(stones)
    target = set_next_target(target)
    stones = target

stones_list.append(stones)

count_0 = 0
count_1 = 0

for i in range(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:
# coding: utf-8
_ = int(input())
s = list(input()) + [' ']
try:
    print(s[s.index('#'):].count('.'))
except:
    print(0)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop


def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))


def runLength(in_str):
    kukan = 1
    start = 0
    ret = []
    for i in range(1,len(in_str)):
        if in_str[i-1]!=in_str[i]:
            ret.append([in_str[i-1],kukan,start])
            start = i
            kukan=0
        kukan+=1
    ret.append([in_str[-1],kukan,start])
    return ret

N = int_raw()
S= input()

dp = {}

def rec(ss):
    return 0

def main():
    ans =0
    numB = 0
    leftMostW = -1
    for i in range(len(S)-1,-1,-1):
        if S[i]==".":
            leftMostW = i
            break
    if leftMostW ==-1:
        return 0
    for i in range(leftMostW):
        if S[i] == "#":
            numB+=1
    return min(numB,leftMostW+1-numB)



print(main())

Submission status: Wrong Answer

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

ans = 0
has_black = False
has_white = False
cnt_black = 0
cnt_white = 0
for c in s:
    if c == '#':
        if has_black and has_white:
            has_black = False
            ans += min(cnt_white, cnt_black)
            cnt_white = 0
            cnt_black = 0
        else:
            has_black = True
            cnt_black += 1
    elif c == '.' and has_black:
        has_white = True
        cnt_white += 1

if c == '.':
    ans += min(cnt_black, cnt_white)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
S = input()
ls = S.split('#')
ans = 0
if S[0] == '.':
    if len(S) == 1:
        print(0)
    else:
        for x in ls[1:]:
            ans += len(x)
    print(ans)
if S[0] == '#':
    for x in ls:
        ans += len(x)
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
p=[]
for i in range(n):
    c=0
    for j in range(n):
        if i < j:k="#"
        else:k="."
        if s[j]!=k:c+=1
    p.append(c)
print(min(p))

Submission status: Wrong Answer

Solution code:
import sys,copy
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

n = int(input())
S = list(input())
S = S[::-1]
T = copy.copy(S)
cnt = 0
for i in range(1,n):
    if S[i-1] == '.' and S[i] == '#':
        cnt += 1
        S[i] = '.'
tmp = 0
for i in range(n-1):
    if T[i] == '.' and T[i+1] == '#':
        tmp += 1
        T[i] = '#'
print(min(cnt,tmp))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if len(s)==0:
  print(0)
elif "#" in s:
  k=s.index("#")
  print(s[k+1:len(s)].count("."))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    S = input()
    ps = ''
    ans = 0
    for s in S:
        if s == '.' and ps == '#':
            ans += 1
        ps = s
    print(ans)


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
acount = S.count(".")
bcount = S.count("#")
if acount == 0  or bcount == 0:
    print(0)
else:
    print(min(acount,bcount))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S == '.' * N:
  print(0)
else:
  first = 0
  for i in range(1,N+1):
    if S[i-1] == '#':
      first = i
      break
  out = 0
  for i in range(first+1,N+1):
    if S[i-1] =='.':
      out += 1
  print(out)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
cnt = 0
for i in s:
    if i==".":
        ans += 1
for i in s:
    if i==".":
        cnt += 1
    else:
        break
print(ans-cnt)

Submission status: Wrong Answer

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

black_count = 0
white_count = 0
right_white_pos=0
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
    else:
        if(S[i]=="."):
            counter+=1

print(min(white_count, black_count, counter))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 0
color = s[0]
if s[0] == ".":
    curw = 1
    curb = 0
else:
    curb = 1
    curw = 0
if color ==".":
    bool = 1
else:
    bool = 0
for i in range(1,n):
    if s[i] == color:
        if color == ".":
            curw +=1
        else:
            curb += 1
    elif i == n-1 and s[i] =="." and s[i] !=color :
        ans += 1
    else:
        if bool %2 == 0:
            if s[i] == ".":
                curw +=1
            else:
                curb += 1
            color = s[i]
            bool +=1
        else:
            ans += min(curw,curb)
            curw = 0
            curb = 0
            if s[i] ==".":
                curw += 1
            else:
                curb += 1
            color = s[i]
            bool += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
black = 0
white = 0
count = 0
find = True

for i in reversed(range(0,n)):
    if find == True and s[i] == '#':
        black += 1
    elif s[i] == '.':
        white += 1
        find = True
    if black == white:
        count += white
        white = 0
        black = 0
        find = False
count += black
print(count)

Submission status: Wrong Answer

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

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

MIN = 10000000
for i in range(N):
    cnt = S[:i+1].count('1') + S[i+1:].count('0')
    MIN = min(MIN, cnt)
print(MIN)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=0
now="."
stack=[]
for i in s:
  if i=="#":
    ans+=min(stack.count("#"),stack.count("."))
    stack=[]
    stack.append(i)
  else:
    stack.append(i)
ans+=min(stack.count("#"),stack.count("."))
print(ans)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
list = [0]*N

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

print(max(list))

Submission status: Wrong Answer

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

ans = 0

if len(S) == 1:
    print(ans)
elif len(S) == 2:
    if S == '.#':
        print(ans)
else:
    for i in range(len(S)-2):
        if S[i] == '#' and S[i+1] == '.':
            if S[i+2] == '.':
                S[i] = '.'
            else:
                S[i+1] = '#'
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import re
n=int(input())
s=input()
ans=0
a=re.findall("#.",s)
print(len(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
B_C = 0
W_C = 0
if S[0] == "#":
  for i in range(N):
      if S[i] == ".":
          W_C += 1
      elif S[i] == "#":
          B_C += 1
  #print(W_C,B_C)
  print(min(W_C,B_C))
else:
  K = 1
  for i in range(N-1):
    if S[i] == "." and S[i+1] == ".":
      K += 1
    else:
      break
  S = S[K:]
  for i in range(N-K):
    if S[i] == ".":
        W_C += 1
    elif S[i] == "#":
        B_C += 1
  #print(K,W_C,B_C)
  print(min(W_C,B_C))

Submission status: Wrong Answer

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

a=0
for i in range(len(S)-1):
    if (S[i]=='#') & (S[i+1]=='.'):
        S[i+1]='#'
        a += 1
print(a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

b = S.count('#')
w = N - b
b_loc = 10**6
for i in range(N):
    if S[i] == '#':
        b_loc = i
        break
if b_loc ==10**6:
    ans = 0
else:
    ans = min(b, N - b - b_loc )
print(ans)

Submission status: Wrong Answer

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

i = 0
ans = 0

while i < N and S[i] == ".":
    i += 1

if i == N -1:
    print("0")
else:
    while i < N:
        if S[i] == "." :
            ans += 1
        i += 1

print(ans)

Submission status: Wrong Answer

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

b=s.count('#')
#w=s.count('.')

ans=0
flag=False
for i in range(n):
    if flag == True and s[i] == '.':
        ans+=1
    elif s[i] == '#':
        flag=True
    elif ans>=b:
        break

#print(min(b,w))
print(min(b,ans))

Submission status: Wrong Answer

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

D = 0

black = S.split("#")
white = S.split(".")
if S[0] == ".":
  white.pop(0)
  
if S[-1] == "#":
  black.pop()
  
for b, i in zip(black,white):
  D += min(len(b),len(i))
  
print(D)

Submission status: Wrong Answer

Solution code:
from sys import stdin
input=[]
for i in range(2):
    input.append(stdin.readline().rstrip())

input[0]=int(input[0])
#print(input)
# #の右に.があってはいけない
output=0
for i in range(0,input[0]-1):
    if input[1][i]=="#":
        if input[1][i+1]==".":
            output+=1

print(output)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
s = input()
l = list(s)
ll = copy.copy(l)
bnextb = 0
btow = 0
if n == 1:
  print(0)
else:
  for i in range(n-1):
    if l[i] == "#" and l[i+1] == ".":
      l[i+1] = "#"
      bnextb += 1
  for i in range(n-1):
    if ll[i] == "#" and ll[i+1] == ".":
      ll[i] = "."
      btow += 1
  print(min(bnextb,btow))

Submission status: Wrong Answer

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

cnt = 0
ans = 0
flag = False
for i in range(N):
    # print(S[i])
    if S[i] == "#": #黒い場合
        if flag: #黒が出てる
            # ans += cnt
            cnt = 0
        else:
            flag = True
    else:#白い場合
        if flag:
            ans += 1
            # ans += cnt
    # print(cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
S = list(str(input()))

#print(N,S)

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

print(counter)

Submission status: Wrong Answer

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

ans = 0

for i in range(1,n,2):
    if s[i-1] != s[i]:
        ans += 1

if (len(s) % 2) != 0:
    if  s[n-1] == '.' and s[n-1] != s[n-2]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count_if_all_white     = 0
count_if_contain_black = 0

found_black = False
for c in S:
    if c == "#":
        found_black = True
        count_if_all_white += 1
    if found_black and c == ".":
        count_if_contain_black += 1

print(min(count_if_all_white, count_if_contain_black))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
white = S.count(".")
if S[0] == "#":
    B = [1]*N
    W = [white]*N
else:
    B = [0]*N
    W = [white-1]*N
for i in range(1,N):
    if S[i] == "#":
        B[i] = B[i-1] + 1
        W[i] = W[i-1]
    else:
        B[i] = B[i-1]
        W[i] = W[i-1] - 1
#print(B)
#print(W)
Ans = [B[i]+W[i] for i in range(N)]
print(min(Ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
	n = int(input())
	s = input()
	ans = 0
	tmp = s[0]
	for i in range(0, n-1):
		if s[i] == '#' and s[i+1] == '.':
			ans += 1


	print(ans)

	
if __name__ == '__main__':
	import sys
	sys.exit(main())

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N = makeInt(input_string[0])
    S = input_string[1].rstrip()
    S = list("."+S)
    w = "."
    b = "#"
    c = 0
    for i in range(N):
        if S[i] == b:
            if S[i-1] == w and S[i+1] == w:
                S[i] = w
                c += 1
    i = N
    if i == N:
        #print("a")
        #print(S)
        #print(S[i])
        if S[i-1] == b and S[i] == w:
            S[i] = b
            c += 1
    return c

            
        
        
        
    r = S[K-1]
    rS = ""
    for t in S:
        #print(t)
        if t != r:
            rS += "*"
        else:
            rS += t
    return rS


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

num = 0
for i in range(n):
    try:
        if s[i] == '#' and s[i+1] == ('.'):
            num += 1
        else:
            pass
    except:
        break
print(num)

Submission status: Wrong Answer

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

white, black = 0, 0

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

for j in range(n):
    if s[n-j-1] == ".":
        black = s[:n-j-1].count("#")
        break

print(min(white, black))