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

ans = 2*10**5
c_b = 0
c_w = 0
for i in range(N):
    if S[i] == '#':
        c_b += 1
    else:
        c_w += 1

ans = min(ans, c_b, c_w)

nums = []
ns = 0
if S[0] == '#':
    nums.append(0)
    ns = 1

count = 0
for i in range(N):
    if S[i] == '.':
        if ns == 0:
            count += 1
        else:
            nums.append(count)
            count = 1
            ns = 1 - ns
    if S[i] == '#':
        if ns == 1:
            count += 1
        else:
            nums.append(count)
            count = 1
            ns = 1 - ns
nums.append(count)

if len(nums) < 3:
    print(0)
    quit()

count = 0
for i in range(0, len(nums), 2):
    if i != 0:
        if nums[i-1] != 0:
            count += nums[i-1]
ans = min(ans, count)

count = 0
for i in range(1, len(nums), 2):
    if nums[i-1] != 0:
        count += nums[i-1]
print(min(ans, count))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=0
s.append('A')
if s[0]=='#':
    a=1
    while s[a]=='.' and a!=n-1:
        a+=1
        ans+=1
for i in range(1,n):
    if s[i]=='#' and i!=n-1:
        a=i+1
        while s[a]=='.' and a!=n:
            a+=1
            ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

S = input()

count1 = 0
count2 = 0
ans = 0
for i in range(len(S)):
    s = S[i]
    if s == '#':
        if i != 0 and S[i-1] == '.':
            if count1 > 0:
                ans += min(count1, count2)
            count2 = 0
            count1 = 0
        count1 += 1
    elif s == '.':
        count2 += 1
    
    if i == len(S)-1 and s == '.':
        ans += min(count1, count2)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
mini = N
tmp = S.count('.')
def judge(k):
  return bool(S[k]=='.')
def check(k):
  return 1-2*judge(k)
for i in range(N):
  tmp += check(i)
  if tmp < mini:
    mini = tmp
print(mini)

Submission status: Wrong Answer

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

ans = [0,0]
cnt = 0
judge_b = 0
judge_w = 0
for i in range(n):
    if s[i] == "#" and judge_b == 1 and ans[1] != 0:
        cnt += min(ans)
        ans[0] = 1
        ans[1] = 0
        print(ans)
        judge_b = 0
        judge_w = 0
    elif s[i] == "#":
        ans[0] += 1
        judge_b = 1
        print(ans)
    elif s[i] == "." and judge_w == 1 and ans[0] != 0:
        cnt += min(ans)
        ans[0] = 0
        ans[1] = 1
        print(ans)
        judge_b = 0
        judge_w = 0
    elif s[i] == ".":
        ans[1] += 1
        print(ans)
    if i == n-1 and ans[1] != 0 and s[i] == ".":
        cnt += min(ans)
print(cnt)

Submission status: Wrong Answer

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

d = 0
for i in range(n):
    if s[i] != ".":
        d = i
        break

    if i == n-1:
        d = i

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

else:      
    for j in range(n-d):
        if s[j+d] == "#":
            count += 1
    print(min((count, n-d-count)))

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s = input()
if not '#' in s:
    print(0)
else:
    s = s.rsplit('.#', 1)[0] + '.#' if '.#' in s else  s
    ptn = re.search(re.compile('\.#+?$'), s)
    if ptn:
        s = s[:ptn.end()]
    print(s)
    print(min(s.count('.'), s.count('#')))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
li = []
i = 0
j = 0
cnt = 0
ans = 0
while i<n:
    while j<n and s[i]==s[j]:
        cnt += 1
        j += 1
    i = j
    li.append(cnt)
    cnt = 0

if s[0] == "#" and len(li)!=1:
    if len(li)%2==0:
        a = sum(li[0::2])
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
    else:
        a = sum(li[0::2]) - li[-1]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
elif s[0] == "." and len(li)!=1:
    if len(li)%2==0:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2]) - li[0]
        if a<b:
            ans = a
        else:
            ans = b
    else:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
else:
    ans = 0

print(str(ans))

Submission status: Wrong Answer

Solution code:
def indexOfLeftWhite(S) :
    for i in range(len(S)):
        if (S[i] == ".") :
            return i
    return -1

def indexOfLeftBlack(S) :
    for i in range(len(S)):
        if (S[i] == "#") :
            return i
    return -1

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

counter = 0

if (S[-2:] == "#.") :
    S = S[:-1] + "#"
    counter += 1
"""
else:
    for i in range(1,len(S))[::-1] :
        if (S[i-1:i+2] == "#.#") :
            S = S[:i-1] + "###" + S[i+2:]
            counter += 1
        elif (S[i-1:i+2] == "#..") :
            S = S[:i-1] + "..." + S[i+2:]
            counter += 1
"""

tmp = S.replace("#..", "...") 
L = tmp.replace("#.#", "###")

for i in range(len(S)) :
    if (S[i] != L[i]) :
        counter += 1

print(counter)

Submission status: Wrong Answer

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

count_s = 0
count_d = 0
for i in range(1,n+1):
    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]
print(s)
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()
flag = 0
location1 = 0
location2 = 0
for i in range(n):
    if s[i] == '#':
        location1 = i
        flag = 1
        break

count1 = s[location1:n].count('.')

s = s[::-1]
i = 0

for i in range(n):
    if s[i] == '.':
        location2 = i
        flag = 1
        break

count2 = s[location2:n].count('#')

if flag == 0:
    print(0)
else:
    print(min(count1, count2))

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N = long(sys.stdin.readline())
    S = sys.stdin.readline().lstrip('.').rstrip('#')
    numA = S.count('.')
    numB = S.count('#')
    print(min(numA, numB))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

S = str(input())

cnt = 0
for i in range(1, N):
    if S[i-1] == '#' and S[i] == '.':
        cnt += 1
        continue

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


print(int(min(cnt, cnt_2)))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
counter = 0
for i in range(n):
    if s[i] == "#":
        for j in range(i,n):
            if s[j] == ".":
                counter += 1
        break
print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N = raw_input()
S = raw_input()
 
flag = 0
cnt = 0
cnt2 = 0
T =  S.rstrip("#")
for s in T:
    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()

cnt = 0

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

x = 2*10**5


for i in range(n//2+2):
    b = 0
    w = 0
    for j in range(i):
        if s[j] == "#":
            b = b + 1

    w = n  - i - cnt + b

    x = min(x,b+w,n-b-w)

print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
if N == 1:
    print(0)
    exit()
elif N == 2 and (S[0] == '#' and S[1] == '.'):
    print(1)
    exit()
else:
    S = '.' + S + '#'
    for n in range(N):
        if S[n] == '.' and S[n + 2] == '.' and S[n + 1] == '#':
            ans += 1
        elif S[n] == '#' and S[n + 2] == '#' and S[n + 1] == '.':
            ans += 1
print(ans)

Submission status: Wrong Answer

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

middle = S[1:-1]
white = middle.count('.')
black = middle.count('#')

if S.count('.') == 0 or S.count('#') == 0:
  print('0')
else:
  if white < black:
    if S[-1] == '.':
      print(white+1)
    else:
      print(white)
  else:
    if S[0] == '#':
      print(black+1)
    else:
      print(black)

Submission status: Wrong Answer

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

for i in range(n):
    if (i == n-1 and s[i] == '#') or (i == 0 and s[i] == '.'):
        continue
    if s[i] == '.':
        w_num += 1
    else:
        b_num += 1

print(w_num if w_num < b_num else b_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
white = '.'
black = '#'

cnt = 0
for i in S:
    if(i==black):
        break
    else:
        cnt += 1
#print(cnt)
#print(S)
bS = S[cnt:]
#print(S)

black_chg_cnt = 0
white_chg_cnt = 0
for i in bS:
    if(i==white):
        black_chg_cnt += 1
    else:
        white_chg_cnt += 1

if(S[-1] == black):
    white_chg_cnt -= 1

if(black_chg_cnt<white_chg_cnt):
    print(black_chg_cnt)
else:
    print(white_chg_cnt)

Submission status: Wrong Answer

Solution code:
def indexOfLeftWhite(S) :
    for i in range(len(S)):
        if (S[i] == ".") :
            return i
    return -1

def indexOfLeftBlack(S) :
    for i in range(len(S)):
        if (S[i] == "#") :
            return i
    return -1

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

counter = 0

if (S[-2:] == "#.") :
    S = S[:-1] + "#"
    counter += 1
"""
else:
    for i in range(1,len(S))[::-1] :
        if (S[i-1:i+2] == "#.#") :
            S = S[:i-1] + "###" + S[i+2:]
            counter += 1
        elif (S[i-1:i+2] == "#..") :
            S = S[:i-1] + "..." + S[i+2:]
            counter += 1
"""

tmp = S.replace("#..", "...") 
L = tmp.replace("#.#", "###")

print(L)

for i in range(len(S)) :
    if (S[i] != L[i]) :
        counter += 1

print(counter)

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])
s = [int(n) for n in s]
sums = sum(list(s))
print(min(sums, n-sums, n-b-a))

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 #black
flag=-1 #first black
for i in range(n):
    if s[i]=="#":
        count+=1
        if flag==-1:
            flag=i
if count==0:
    ans=0
elif count==n:
    ans=0
else:
    a=count #black to white
    b=n-count-flag #white to black
    ans=min(a,b)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def main():
    input()
    s = list(input())

    # 最初に現れた"#"以降の"."と"#"をそれぞれカウントし、最小のものを返す
    w_num = 0
    b_num = 0
    is_start = False
    for c in s:
        if not is_start:
            if c != "#":
                continue
            is_start = True
        else:
            if c == ".":
                w_num += 1
            elif c == "#":
                b_num += 1

    return min(w_num, b_num)


print(main())

Submission status: Wrong Answer

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

num_w = 0
num_b = 0
while num_w <= N - 1 and S[num_w] == '.':
  num_w += 1
if num_w == N:
  print(0)
  exit()
while num_b <= N - 1 and S[N - 1 - num_b] == '#':
  num_b += 1
if num_b == N:
  print(0)
  exit()
target = S[num_w: N - num_b]
print(min(target.count('.'), target.count('#')))

Submission status: Wrong Answer

Solution code:
def get_cost_change_black(S):
    return S.count(".")

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

indexs = [i for i, x in enumerate(S) if x == "#"]
if len(indexs) == 0:
    print(0)
else:
    answer = 10000000
    change_white = 0
    change_black = get_cost_change_black(S[indexs[0]:])
    for i, ind in enumerate(indexs):
        x = change_white + change_black
        if x < answer:
            answer = x
        if i == len(indexs) - 1:
            break
        change_black = change_black + (indexs[i+1] - indexs[i] - 1)
        change_white = change_white + 1
    print(answer)

Submission status: Wrong Answer

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

if N == 1:
  print('0')
  import sys
  sys.exit()

count = 0
for i in range(N-3):
  s = S[i:i+4]
  # print(s)
  if s[1] == '#' and s[2] == '.':
    if s == '##..':
      count += 2
    else:
      count += 1

shead = '.' + S[:3]
stail = S[-3:] + '#'

if shead[1] == '#' and shead[2] == '.':
  if shead == '##..':
    count += 2
  else:
    count += 1

if stail[1] == '#' and stail[2] == '.':
  if stail == '##..':
    count += 2
  else:
    count += 1

# print(shead)
# print(stail)
print(count)

Submission status: Wrong Answer

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

count_w = 0
count_b = 0
s2=''

for i, wb in enumerate(s):
    if i != (n-1):
        if wb == '#':
            s2 = s[i:]
            break

count_w = s2.count('.')
count_b = s.count('#')
print(min(count_w, count_b))

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
sum = 0
for char in s:
    if char == '#':
       sum = sum +1 
if sum > eval(n)/2:
    sum = eval(n) - sum
print(sum)

Submission status: Wrong Answer

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

left = stones.find("#")

if left == -1:
    print(0)
else:
    right = stones.rfind("#")
    if right != -1:
        stonesToChange = stones[left : right]
    else:
        stonesToChange = stones[left:]
    print(min(stonesToChange.count("."), stonesToChange.count("#")))

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
tmp=[s[:i].count("#")+s[i:N].count(".") for i in range(N+1)]
print(min(tmp)+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
count_sharp = s.count("#")
count_dot = s.count(".")
print(min(count_dot, count_sharp))

Submission status: Wrong Answer

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

cb = 0
cw = 0

i = 0
while i < N-1:
    idx = i
    if S[i] == '#' and S[i+1] == '.':
        cb += 1
        i += 1
        j = 1
        while True:
            if idx + j + 1 < N and S[idx +1 +  j] == '.':
                j += 1
                cb += 1
                i += 1
            else:
                break
    i += 1
        
                
i = N-2
while i >= 0:
    idx = i
    if S[i] == '#' and S[i+1] == '.':
        cw += 1
        i -= 1
        j = 1
        while True:
            if idx - j >= 0 and S[idx - j] == '#':
                j += 1
                cw += 1
                i -= 1
            else:
                break
    i -= 1
print(min(cb,cw))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s=input()
B=True
if s=='.'*n:
    B=False
if B:
    num=list(s).index('#')
    plst=[]
    if num!=n-1:
        for i in range(num,n-1):
            if s[i]=='.' and s[i+1]=='#':
                l=n-i-1
            if s[i]=='#' and s[i+1]=='.':
                plst.append(i)
        moji=s[num:]
        moji+='.'
        lst=dict(Counter(moji).items())
        a=lst['#'];b=lst['.']
        if b==1:
            print(0)
        else:
            if s[-1]=='#':
                print(min(a-l,b-1))
            else:
                ans=min((n-plst[-1]-1)+len(plst)-1,min(a,b-1))
                print(ans)
    else:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
if S.count('.')>S.count('#'):
    print(S.count('#'))
else:
    print(S.count('.'))

Submission status: Wrong Answer

Solution code:
import re
N = int(input())
S = input()
ans=2*10**5

l = []
for i in range(len(S)-1):
    if S[i]+S[i+1] == ".#":
        l.append(i)
        
if S.count("#") == 0 or S.count(".") == 0:
    print(0)

else:
    for i in l:
        a = S[i+1:].count(".")+S[:i].count("#")
        ans = min(a,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
re_S = S[::-1]

x = 0
y = 0
for i in range(N):
    if S[i] == '#':
        x += S[i+1:].count('.')
        break       
    else:
        continue
for i in range(N):
    if re_S[i] == '.':
        y += re_S[i+1:].count('#')
        break       
    else:
        continue
 
print(min(x, y))

Submission status: Wrong Answer

Solution code:
import numpy as np
n=2
a=[input() for i in range(n)]
N=int(a[0])
S=list(a[1])
 
kazuXD=0
flg=0
kazu=0
geri=0
for i in range(N):
  if S[i]=="#":
    geri+=1
for i in range(N):
  if flg==0:
    if S[i]==".":
      kazu+=1
    else:
      flg=1
flg=0
for i in range(N):
  if i>=kazu:
    if S[i]==".":
      S[i]="#"
      kazuXD+=1

if geri>kazuXD:
  print(kazuXD)
else:
  print(geri)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ss = []
for i in s:
    if i == "#":
        ss.append(1)
    else:
        ss.append(0)

now = 0
cnt = 0
x = []

for i in range(n):
    if ss[i] == now:
        cnt += 1
    else:
        x.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    x.append(cnt)
if ss[-1] == 0:
    x.append(0)

#print(x)
#x.pop(0)
#x.pop(-1)
c1 = 0
c2 = 0
for i in range(len(x)):
    if i % 2 != 0:
        c1 += x[i]
    else:
        c2 += x[i]

print(min(c1,c2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
def a (str) :
	_ans = 200000
	for i in range(n) :
		k = 0
		if str[i] == "#" :
			for j in s[0:i] :
				if j == "#" : k+=1
				if k > _ans : break
			for j in s[i:-1] : 
				if j == "." : k += 1
				if k > _ans : break
			if k<_ans : _ans = k
	return (_ans)
ans = a(s)
print(ans)

Submission status: Wrong Answer

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

post = ''
ans=0
data=[]

# left = [0 for _ in range(len(s))]
# right = [0 for _ in range(len(s))]
left=[]
right=[]

tmp=0
# for i in range(n):
#     if s[i]=='#':
#         tmp+=1
#     elif tmp!= 0:
#         left[i]=tmp
#         tmp=0

for i in range(n):
    if s[i]=='#':
        tmp+=1
    elif tmp!= 0:
        left.append(tmp)
        tmp=0


tmp=0
# for i in range(n):
#     if s[n-i-1]=='.':
#         tmp+=1
#     if n-i-1-1 >=0 and s[n-i-1-1]=="#":
#         right[n-i-1] = tmp
#         tmp=0

for i in range(n):
    if s[n-i-1]=='.':
        tmp+=1
    if n-i-1-1 >=0 and s[n-i-1-1]=="#" and tmp!=0:
        right.append(tmp)
        tmp=0

# print(s)
# print(left)
# print(right)

for i in range(len(left)):
    if i == len(left)-1:
        ans+=min(left[i],right[i])
        break
    l = left[i]
    r = right[i]
    if l > r:
        ans+=r
        left[i+1]=l+r+left[i+1]
    else:
        ans+=l


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s += "-"
white = [0]
black = [0]
white_acc = 0
black_acc = 0
counter = 0
for i in range(n + 1):
    if s[i] == s[i - 1]:
        pass

    elif s[i - 1] == "#":
        black_acc += counter
        black += [black_acc]
        counter = 0
    elif s[i - 1] == ".":
        white_acc += counter
        white += [white_acc]
        counter = 0
    counter += 1
if len(black) + len(white) <= 3:
    print(0)
    exit()

last_white = white[len(white) - 1]
min_acc = 2 * 10 ** 5
if s[0] == "#":
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i])

else:
    black += [0]
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i - 1])
print(min_acc)

Submission status: Wrong Answer

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

s=input()

ans = n

for i in range(n):
	tmp_w=""
	tmp_b=""
	tmp_t=""
	tmp_ans=0
	for k in range(i):
		tmp_b += "#"
	for m in range(n-i):
		tmp_w += "."
	tmp_t = tmp_w + tmp_b
	#print(tmp_t)
	for loop in range(n):
		if s[loop] != tmp_t[loop]:
			tmp_ans +=1
	ans =min([ans,tmp_ans])

print(ans)

Submission status: Wrong Answer

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

ans = 0
now = S[0]
# start = S[0]
end = S[-1]
for i in range(N):
    if S[i] != now:
        ans += 1
        now = '#' if now == '.' else '.'
if ans > 1:
    ans -= 1

print(ans)

Submission status: Wrong Answer

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

left = stones.find("#")

if left == -1:
    print(0)
else:
    right = stones.rfind("#")
    if right == -1:
        stonesToChange = stones[left : right]
    else:
        stonesToChange = stones[left:]
    print(min(stonesToChange.count("."), stonesToChange.count("#")))

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
w=True
resw=0
for s in S[::-1]:
    if(s=="."):
        if(w):
            resw+=1
        else:
            break
    else:
        w=False


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

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

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()
    if len(S) == 1:
        return 0
    if S == "#.":
        return 1
    S = list("."+S)
    w = "."
    b = "#"
    c = 0
    b_c = 0
    b_b_c = 0
    for i in range(N):
        if S[i] == w and S[i-1] == b:
            #if b_b_c == 0:
            #b_c = 0
            w_c = 0
            for j in range(i, N+1):
                if S[j] == w:
                    w_c += 1
                else:
                    break
            #for k in range(0, i)[::-1]:
            #    if S[k] == b:
            #         b_c += 1
            #    else:
            #        break

            #print(w_c)
            #print(b_c)
            if w_c > b_b_c + b_c:
                for h in range(0, i)[::-1]:
                    if S[h] == b:
                        S[h] = w
                        c += 1
                    else:
                        break
        if S[i] == b:
            b_c += 1
        else:
            if b_c != 0:
                b_b_c += b_c
            b_c = 0
        if S[i] == b:
            if S[i-1] == w and S[i+1] == w:
                S[i] = w
                c += 1
                continue
        if i > 0 and S[i] == w:
            #print(S)
            #print(S[i])
            if S[i-1] == b:
                S[i] = b
                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


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 = input()
n=len(s)
x = 0
for i in range(n-1):
    if s[i] == "#" and s[i + 1] == ".":
        y=0
        for j in reversed(range(i + 1)):
            if s[j] == "#":
                y += 1
            else:
                break

        x+=min(y, n-1-i)

print(str(x))

Submission status: Wrong Answer

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

a = S.find('#')
b = 0
c = 0

if a < 0:
    print('0')

else:
    for k in range(a, N):
        if S[k] == '.':
            b = b + 1
        else:
            c = c + 1
    if S[N-1] == '#':
        c = c - 1
    print(min(b,c))

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s = input()
if not '#' in s:
    print(0)
else:
    s = s.rsplit('.#', 1)[0] + '.#' if '.#' in s else  s
    ptn = re.search(re.compile('\.#+?$'), s)
    if ptn:
        s = s[:ptn.start()]
    print(min(s.count('.'), s.count('#')))

Submission status: Wrong Answer

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

print S.count('#.')

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
count=0
if s[0]=="#":
  for i in range(1,n):
    if s[i]==".":
      count=count+1
else:
  count1=0
  count2=0
  for i in range(n):
    if s[i]=="#":
      count1=count1+1
    else:
      count2=count2+1
  count=min(count1,count2)
print(count)

Submission status: Wrong Answer

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

sharp = list()
dot = list()
count = 0

while '#.' in S:
    S = list(S)
    for i in range(N):
        if S[i] == '#':
            if len(sharp) > 0 and len(dot) > 0:
                if len(sharp) >= len(dot):
                    for j in dot:
                        S[j] = '#'
                        count += 1
                else:
                    for j in sharp:
                        S[j] = '.'
                        count += 1
                
                sharp = list()
                dot = list()
            sharp.append(i)
        elif S[i] == '.' and len(sharp) > 0:
            dot.append(i)
    S = ''.join(S)
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
cnt1 = 0
cnt2 = 0
for idx,s in enumerate(S):
    if s == "#" and idx < N:
        cnt1+=1
    if s==".":
        cnt2+=1
if cnt1 < cnt2:
    print(cnt1)
else:
    print(cnt2)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S = list(input())
 
S_1 = copy.copy(S)
S_2 = copy.copy(S)
S_3 = copy.copy(S)
S_4 = copy.copy(S)
count_1 = 0
count_3 = 0

for i in range(N-1):
  if S_1[i] == "#" and S_1[i+1] == ".":
    if i != N - 2:
      if S_1[i+2] == "#":
        S_1[i+1] = "#"
      elif i != 0 and S_1[i-1] == ".":
        S_1[i] = "."
      else:
        S_1[i+1] = "#"
    count_1 += 1
    
#for i in range(N-1):
#  if S_2[i] == "#" and S_2[i+1] == ".":
#    S_2[i] = "."
#    count_2 += 1
    
for i in range(N-1):
  if S_3[N - i - 1] == "." and S_3[N - i - 2] == "#":
    if i != N - 2:
      if S_3[N - i -3] == ".":
        S_3[N - i - 2] = "."
      elif i != 0 and S_3[N - i] == "#":
        S_3[N - i - 1] = "#"
      else:
        S_3[N - i - 2] = "."
    count_3 += 1
    
#for i in range(N-1):
#  if S_4[N - i - 1] == "." and S_4[N - i - 2] == "#":
#    S_4[N - i - 2] = "."
#    count_4 += 1
    
print(min(count_1, count_3))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt


n = input()
s = raw_input()

c = 0
a = 0
for i in range(len(s)):
    if s[i] == '#':
        s = s[i:]
        break
for i in range(len(s), 0, -1):
    if s[i - 1] == '.':
        s = s[:i]
        break
print min(s.count('#'), s.count('.'))

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]
print(s)
sharp_num = s.count('#')
dot_num = s.count('.')

print(min(sharp_num,dot_num) - 1)

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]=='#.':
            j = 1
            while i-j>=0 and S[i-j]=='#':
                j += 1
            k = 1
            while i+1+k<N and S[i+1+k]=='.':
                k += 1
            if j <= k:
                ans += j
            else:
                ans += k

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

W = [0] * n
B = [0] * n

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

#print(W)

for i in range(n):
    if i == 0:
        B[i] = 0
    elif s[i-1] == '#':
        B[i] = B[i-1] + 1
    else:
        B[i] = B[i-1]

#print(B)

if W[0] == n:
    print(0)
else:
    ans = n
    for i in range(n):
        c = W[i] + B[i]

        ans = min(ans, c)

    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
stone = input()
ans = 0
blackCnt = 0
whiteCnt = 0
sw = False
for i in range(n):
    if blackCnt > 0 and whiteCnt > 0 and stone[i] == '#':
        if blackCnt > whiteCnt:
            ans = whiteCnt
        else:
            ans = blackCnt
        blackCnt = 1
        whiteCnt = 0

    elif stone[i] == '#':
        sw = True
        blackCnt += 1
    elif stone[i] == '.' and sw == True:
        whiteCnt += 1

if blackCnt > 0 and whiteCnt > 0:
    if blackCnt > whiteCnt:
        ans += whiteCnt
    else:
        ans += blackCnt

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
fb = -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:
N=int(input())
S=str(input())
A=[]
B=[]
for i in S:
    A.append(i)
for i in S:
    B.append(i)
count1=0
count2=0
for i in range(N-1):
    if (A[i]=="#")and( A[i+1]=="."):
        A[i+1]="#"
        count1+=1
for i  in range(N):
    if B[ i]  =="#":
        B[i]="."
        count2+=1
ans=min(count1,count2)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=[str(i) for i in input().split()][0]
try:
    start=S.index("#")
    end=max([n for n,i in enumerate(S) if i=="."])
    X=S[start:end]
    if start > end:
        print(0)
    else:
        sharp=X.count("#")
        dot=X.count(".")+1
        print(min([sharp,dot])) 
except:
    print(0)