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()
cnt1 = 0
cnt2 = 0
for idx,s in enumerate(S):
    if s != "." and idx != len(S)-1:
        cnt1 += 1
    elif s!="#":
        cnt2+=1
print(min([cnt1,cnt2]))

Submission status: Wrong Answer

Solution code:
n=int(input())
S=input()
sflag=0
a=0
b=0
c=0
for i in S:
    if i=="#" and sflag==0:
        sflag=1
    if sflag==1:
        if i==".":
            a+=1
        else:
            b+=1

a2=0
b2=0
sflag=0
for i in S[::-1]:
    if i=="." and sflag==0:
        sflag=1
    if sflag==1:
        if i==".":
            a2+=1
        else:
            b2+=1

print(min(a,b,a2,b2))

Submission status: Wrong Answer

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

white = S.count(".")
black = N - white
ans_w = white
ans_b = black

S_reverse = S[::-1]
for s in S_reverse:
  if s == "#":
    ans_b -= 1
  else:
    break

for s in S:
  if s == ".":
    ans_w -= 1
  else:
    break

print(min(ans_b, ans_w))

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:
  S = S[1:]
  for i in range(N-1):
    if S[i] == ".":
        W_C += 1
    elif S[i] == "#":
        B_C += 1
  #print(W_C,B_C)
  print(min(W_C,B_C))

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 = list(input())
if all([v == '.' for v in s]):
    print(0)
else:
    print(s[s.index('#'):].count('.'))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
fK = N
ansSK = 0
ansSS = 0
for i in range(N):
    if S[i] == '#':
        fK = i
        break
for j in range(fK,N):
    if S[j] == '.':
        ansSK += 1
    else:
        if j == N:
            break
        ansSS += 1
print(min(ansSK,ansSS))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()+'?'
white=s.count('.')
black=s.count('#')
ans1=n-black
ans2=n-white
ans3=10**10
if '.' in s:
  index=s.index('.')
  for i in range(index,n+1):
    if s[i]=='.':
      continue
    else:
      index=i
      break
  ans3=s[:index].count('#')+s[index:].count('.')
print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
t = S.count(".")
if t == N:
    print(0)
    exit(0)

b = 0
for k in range(N):
    if S[k] == "#":
        b = k
        break

print(S[b:].count("."))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = input()
    s_list = list(s)
    ans = 0
    for i in range(len(s_list) - 1):
        if s_list[i] == '#' and s_list[i + 1] == '.':
            if i == 0 or s_list[i - 1] != '#':
                s_list[i] = '.'
            else:
                s_list[i + 1] = '#'
            ans += 1
    print(ans)

Submission status: Wrong Answer

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

print(moji)
counter=0
flag=0
for i in range(N):
    if flag ==0 and moji[i]=="#":
        flag=1
    elif flag==1 and moji[i]==".":
        counter+=1
        flag=0
print(counter)

Submission status: Wrong Answer

Solution code:
n,s=int(input()),input()
while s[0]==".":
  s=s[1:]
  if s=="":print(0);exit()
while s[-1]=="#":
  s=s[:-1]
  if s=="":print(0);exit()
b,w=0,0
for i in s:
  if i=="#":b+=1
  else:w+=1
print(min(b,w))

Submission status: Wrong Answer

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

if s.count('.') == len(s):
    print(0)
else:
    for i, wb in enumerate(s):
        if wb == '#':
            break
        else:
            s = s[i+1:]

    print(s.count('.'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    # 最初に黒い石が出現した後に出現した白い石の色を変更する必要がある
    num = 0
    is_start = False
    for c in s:
        if not is_start and c == "#":
            is_start = True
            continue
        if is_start and c == '.':
            num += 1

    return num


print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
for x,y in zip(S[:N:],S[1::]):
    if x == '#' and y == '.':
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate

def main():
    input = sys.stdin.readline
    N = int(input())
    S = [0 if c == '.' else 1 for c in input().strip()]
    T = [0] + list(accumulate(S))

    B = T[N]
    if B == 0 or B == N:
        return 0

    ans = 10**5
    for i in range(N+1):
        convert_w = T[i]
        convert_b = N - (B - T[i])
        ans = min(ans, convert_w + convert_b)

    return ans


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = list(input())
    
    count_sharp = S.count('#')
    count_dot = S.count('.')
    # print(count_sharp, count_dot)
    count = 0

    for i in range(len(S) - 1):
        # print(S, end='')
        one = S[i]
        two = S[i+1]
        if (one == '#') and (two == '.'):
            count += 1
            if count_sharp < count_dot:
                S[i+1] = '.'
            else:
                S[i+1] = '#'
        



        # print(S)

    print(count)

main()

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)
#print(len(stones_list))

if len(stones_list) == 1:
  print(0)
if len(stones_list) == 3:
  print(1)
elif len(stones_list) %2 == 0:
  print(len(stones_list) // 2)
else:
  print(len(stones_list) // 2 - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
f,ans,b,w = 0,0,0,0
for i in s:
  if i == '#':
    if f == 0:
      ans+= min(b,w)
      b,w = 0,0
    b+=1
    f = 1
  else:
    w +=1
ans += min(b,w)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
flag = False
count = 0
for c in S:
    if c == ".":
        flag = True
    if flag == True and c == "#":
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
t = '#.'
print(S.count(t))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = input()
BN = [0 for i in range(N)]
if S[0] == '.':
    BN[0] = 0
else:
    BN[0] = 1
for i in range(1, N):
    if S[i] == '.':
        BN[i] = BN[i-1]
        continue
    BN[i] = BN[i-1] + 1
ans = min(N-BN[-1], BN[-1])
for i in range(1,N):
    white = BN[i-1]
    black = N-(i)-(BN[i]-BN[i-1])
    ans = min(ans, white+black)
print(ans)

Submission status: Wrong Answer

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

S_list = [S[i] for i in range(len(S))]

t = 0
kekka = 0
for x in S_list:
    t += 1
    if t != len(S_list):
        if x == "#":
            kekka += 1


print(kekka)

Submission status: Wrong Answer

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

le=len(S)

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 < len(S):
  print(ans)
 
else:
  print(le-ans-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w=0
b=0
c=0
for i in range(n):
    if s[i]=='#':
        c=i
        break
for i in range(c,n):
    if s[i]=='.':
        w+=1
s=s[::-1]
for i in range(n):
    if s[i]=='.':
        c=i
        break
for i in range(c,n):
    if s[i]=='#':
        b+=1
if b<w:
    print(b)
else:
    print(w)

Submission status: Wrong Answer

Solution code:

def main():
    _ = int(input())
    s = input()  # '#.#' -> '###'

    count = 0
    first_hit = False
    for char in s:
        if not first_hit:
            if char == '.':
                continue
            else:
                first_hit = True
        else:
            if char == '.':
                count += 1

    print(count)


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flag = 0
cnt = 0
ans = 0
for i in range(N):
    if S[i] == '#':
        flag = 1
    if flag == 1:
        if S[i] == '.':
            cnt += 1
        
print(cnt)

Submission status: Wrong Answer

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

black_ind = S.find("#")
white_ind = N - S[::-1].find(".") - 1
if black_ind == -1 or white_ind == N:
    print(0)
else:
    # print(black_ind)
    # print(white_ind)
    black = "." * black_ind + "#" * (N - black_ind)
    # print(black)
    white = "." * (white_ind+1) + "#" * (N - white_ind - 1)
    # print(white)

    countb = len([1 for (s, b) in zip(S, black) if s != b])
    # print(countb)
    countw = len([1 for (s, w) in zip(S, white) if s != w])
    # print(countw)
    print(min(countb, countw))

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

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(str(input()))

print(b)
try:
    firstb = b.index('#')
except ValueError:
    firstb = len(b) + 1

numberb = b[firstb:].count('#')
if b[-1] == '#':
    numberb -= 1
numberw = b[firstb:].count('.')

if numberb < numberw:
    print(numberb)
else:
    print(numberw)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
first_black = -1
last_black = N
for i in range(N):
    if S[i] == "#":
        first_black = i
        break
for i in reversed(range(N)):
    if S[i] == "#":
        last_black = i
    else:
        break
if first_black == -1:
    print(0)
else:
    ans = min(S[first_black:].count("."), S[first_black:].count(
        "#"), S[:last_black].count("#"))

    print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/tenka1-2019-beginner
# -*- coding: utf-8 -*-

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

flag = 0
counter1 = 0
counter2 = 0
for i in s:
    if i is "." and flag is 0:
        continue

    if i is "#":
        flag = 1
        counter2 += 1

    if i is "." and flag is 1:
        counter1 += 1

print(min(counter1,counter2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#A, B, C = map(int,input().split())


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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
t=s.find("#")
r=s.find(".")
if t==-1 or r==-1:
    print(0)
else:
    print(min(s[t:].count("#"),s[t:].count("."),s.count("."),s.count("#")))

Submission status: Wrong Answer

Solution code:
n = int(input())  # 数値入力
str = list(input())  # 一文字ずつ格納
newstr = []
for i in range(len(str)):
    if str[i] == "#":
        newstr = str[i:]
        break

if len(newstr) == 0:
    print("0")
else:
    print(newstr.count("."))

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番目が白い石

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 = input()
binS = []
for i in range(N):
    if S[i] == '.':
        binS.append(0)
    else:
        binS.append(1)
# print(binS)

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

print(counter)

Submission status: Wrong Answer

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

i = 0
end = len(s) -1
ans = 0
while(True):
    if i == end:
        break
    c = s[i] + s[i+1]
    if c == '#.':
        ans = ans + 1
    i += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import exit

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

stack = []


for i in range(N):
    if S[i] == '.':
        stack.append(i)
        j = i

if N // 2 >= len(stack):
    ans = len(stack)
else:
    ans = N - len(stack)

if not stack:
    print(ans)
    exit()

if j - (len(stack) - 1) < ans:
    ans = stack[len(stack) - 1] - len(stack) - 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
allblack = S.count('.')
allwhite = S.count('#')
lastblack = S[:-1].count('#') + S[-1].count('.')
print(min(allblack, allwhite, lastblack))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

white = s.count('.')
black = s.count('#')
if black > 0:
    del s[:s.index('#')]
    print(white if white<=black else black)
else:
    print('0')

Submission status: Wrong Answer

Solution code:
import collections

def solve():
    N=int(input())
    S=list(input())
    left=0
    right=N-1
    for i,c in enumerate(S):
        if c=='.':
            continue
        left=i
        break
    else:
        left=N
    for i in range(N-1,-1,-1):
        if S[i]=='#':
            continue
        right=i
        break
    else:
        right=-1
    #print(left,right)
    if left>right:
        return 0
    S=S[left:right+1]
    cnt=collections.Counter(S)
    #print(cnt)
    if cnt['.']>cnt['#']:
        return cnt['#']
    else:
        return cnt['.']

print(solve())

Submission status: Wrong Answer

Solution code:
n=int(input())
A=True
cnt=0
b=0
w=0
s=input()
for i in range(1,n-1):
    if s[i-1]=='#' and s[i]=='.':
        A=False
        break
from collections import Counter
l=list(Counter(list(s)).values())
if A:
    print(0)
else:
    print(min(l))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
count = 0
for i in range(0,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()
s = list(s)
cnt = 0
for i in range(n-2):
  if s[i] == '.' and s[i+1] == '#' and s[i+2] == '.':
    s[i+1] == '.'
    cnt+=1
  if s[i] == '#' and s[i+1] == '.':
    s[i+1] == '#'
    cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
nb = s.count('#')
nw = s.count('.')
lb = 0
rw = nw
b = False
ans = 0
for i in range(n):
    if b == False and s[i] == '#':
        ans = max(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:
N = int(input())
S = list(input())
black =False
w_num = 0
b_num =0
for i in range(N):
    if black:
        if S[i]==".":
            w_num +=1
    
    if S[i]=="#":
        black =True
        b_num +=1
        
ans = min(w_num,b_num)
print(ans)

Submission status: Wrong Answer

Solution code:
def ns():
    import sys
    return map(int, sys.stdin.readline().split())
  
def ss():
    import sys
    return sys.stdin.readline().strip()
  
N, = ns()
S = ss()

ans = float('inf')
for i in [0]*N:
  c = 0
  for s, t in zip(S, '.'*i+'#'*(N-i)):
    if s != t:
      c += 1
  ans = min(ans, c)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s_list = list(S)
count = 0
while True:
    flag = 0
    for i in range(N-1):
        if s_list[i] == "#" and s_list[i+1] == ".":
            s_list[i+1] = "#"
            count += 1
            flag += 1
    if flag == 0:
        break
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    S = input_raw[0]

    new_S1 = ""
    new_S2 = ""
    flag = False
    for i in range(N):
        if S[i] == "." and flag == False:
            new_S1 += "."
        else:
            new_S1 += "#"
            flag = True

    flag = False
    for i in range(N):
        if S[N - i - 1] == "#" and flag == False:
            new_S2 += "#"
        else:
            new_S2 += "."
            flag = True
    count1 = 0
    count2 = 0
    new_S2 = new_S2[::-1]
    for i in range(N):
        if S[i] != new_S1[i]:
            count1 += 1
        if S[i] != new_S2[i]:
            count2 += 1
    print min(count1, count2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
dst = 0
first_kuro = False
for c in s:
    if first_kuro:
        if c == ".":
            dst += 1
    if c == "#":
        first_kuro = True
print(dst)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


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



pre = s[0]
for i in range(1, n):
    if pre=='#' and s[i]=='.':
        temp = i
        break
    pre = s[i]


# print(temp)
try:
    s = s[temp:]
    ans = sum(1 for x in s if x=='.')
    print(ans)
except:
    print(0)

Submission status: Wrong Answer

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

cnt = 0
cnt_black = 0
should_change = 0
to_fl = 0
for i in range(N):

    if S[i] == '#':
        cnt_black += 1
        to_fl += 1
    else:
        should_change += to_fl
        to_fl = 0


# print(N, cnt_black, N-cnt_black, should_change)

if should_change < N - cnt_black:
    print(should_change)
else:
    print(N-cnt_black)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
 
 
S2 = S.split("#")[1:]
if S2 == S:
        print("0")
else:
    sn = S2.count(".")
    sn2 = S.count("#")
    print(min(sn,sn2))
    print(sn)

Submission status: Wrong Answer

Solution code:
n = int(input())

lines = list(input())


count = 0
for line in lines:
    if line == ".":
        count+=1
    else:
        break

total = lines.count('.')

ans = total-count

print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = input()

ans = 0
change = 0
for i in range(a):
  if(b[i] == '#' or change == 1):
    change = 0
    if(i + 1 >= a):
      break
    else:
      if(b[i+1] == '.'):
        ans += 1
        change = 1
print(ans)

Submission status: Wrong Answer

Solution code:
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
s = list(IS())
count = 0
for i in range(len(s)):
    if i == len(s)-1:
        break
    if s[i] == '#' and s[i+1] == '.':
        count += 1
        s[i] == '.'
print(count)

Submission status: Wrong Answer

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

cnt = 0
for s in S:
    if s == ".":
        cnt += 1
    else:
        break
ws = S[cnt:]
w = S.count(".")
bs = S[::-1]
cnt = 0
for s in bs:
    if s == "#":
        cnt += 1
    else:
        break
bs = bs[cnt:]
b = bs.count("#")
print(min(w, b))

Submission status: Wrong Answer

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

def main_f():
    first_sharp = S.find('#')
    if first_sharp == -1:
        print(0)
        return
    
    sub_s = S[first_sharp:]
    sharp_num = sub_s.count('#')
    dot_num = sub_s.count('.')
    print(min(sharp_num, dot_num))

main_f()

Submission status: Wrong Answer

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

ans = 0
for i, s in enumerate(S):
    if i == N-1:
        break
    if s is '#' and S[i+1] is '.':
        ans += 1
print(ans)

Submission status: Wrong Answer

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

# 最初の黒以降の白全部置き換える
ans1 = 0
found = False
for c in S:
    if c == '.' and found:
        ans1 += 1
    if c == '#':
        found = True

# 最後の白より前の黒を全部置き換える
ans2 = 0
found = False
for c in reversed(S):
    if c == '#' and found:
        ans2 += 1
    if c == '.':
        found = True

print(min(ans1, ans2))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
num=S.count('BW')
print(num)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

def main():
    N = int(input())
    s = input()
    count1 = 0
    count2 = 0
    temp = ""
    for i in s:
        if i == "." and temp == "#":
            count1 += 1
        temp = i

    print(count1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s = input()
result = re.sub('#\.+', '.', s)
# print(result)
print(len(s) - len(result))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=input()[:-1]
b=0;w=0
for s in S:
  if s=='.':
    b+=1
  else:
    w+=1
print(min(b,w))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input().rstrip()
    i = 0
    b_count = 0
    w_count = 0
    # Comsume left whites
    while i < len(s):
        if s[i] == '.':
            i += 1
        else:
            break

    #Consume right blacks
    j = len(s) - 1
    while j > i:
        if s[j] != '.':
            j -= 1
        else:
            break

    while i <= j:
        if s[i] == '.':
            i += 1
            w_count += 1
        else:
            i += 1
            b_count += 1

    print(min(w_count, b_count))

if __name__ == "__main__":
    main()

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()
b_c=0
b_t=s.count("#")
ans=b_t
for i in range(n):
  a=i-b_c+(n-i)-(b_t-b_c)
  ans=min(a,ans)
  if s[i]=="#":
    b_c+=1
print(ans)

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

# if (S not in "#"):
#     print("0")
#     exit()
count = 0
ans = 0
revcount = 0
for i in range(N-1,-1,-1):
    if S[i] == ".":
        count+=1
    else:
        revcount+=1
        ans+=count
        count=0
print(min(revcount,ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
tmp = S.count('#.')
print(tmp)

Submission status: Wrong Answer

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

ans = 0
for i in range(n-2):
    if s[i]+s[i+1] == "#.":
        if s[i+2] == "#":
            s.replace(s[i+1],"#")
            ans += 1
        if s[i+2] == ".":
            s.replace(s[i+1],".")
            ans += 1
        if s[-2]+s[-1] == "#.":
            s.replace(s[i+1],"#")
            ans += 1
print(ans)

Submission status: Wrong Answer

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

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

for i in range(index + 1,N):
    if S[i] == ".":
        cou += 1

cou2 = 0
index2 = 0

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

for i in range(0,index2):
    if S[i] == "#":
        cou2 +=1

print(min(cou,cou2))

Submission status: Wrong Answer

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

count = 0

while True:
    flag = True
    for i in range(N - 1):
        if S[i] + S[i+1] == "#.":
            Flag = False
            count += 1
    if True:
        break

print(count)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = input()

for i in range(len(S)):
	if S[i] == "#":
		left = i
		break
else:
	left = None
if not left:
	print(0)
else:
	print(S[left:].count("."))

Submission status: Wrong Answer

Solution code:
#C
N=int(input())
S=input()
even = "#"*N
odd  = "."*(N-1) +"#"
odd2 = "."*N
eve_c=0
odd_c=0
odd_2=0
for i in range(N):
    if S[i]!=even[i]:
        eve_c+=1

    if S[i]!=odd[i]:
        odd_c+=1

    if S[i]!=odd2[i]:
        odd_2+=1

print(min(eve_c,odd_c,odd_2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
left = []
right = [0 for i in range(n)]
br = 0
for i in range(n):
    if s[i] == "#":
        br += 1
    left.append(br)
br = 0
for i in range(n):
    if s[n - i - 1] == ".":
        br += 1
    right[n - i - 1] = br
p = []
for i in range(n - 1):
    p.append(left[i] + right[i + 1])
p.append(left[n - 1])
print(min(p))

Submission status: Wrong Answer

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

white = S.count('.')
# if(white == N):
#     print('0')
# else:
count = 0
for s in S:
    if s == '.':
        count += 1
    else:
        break
print(white - count)

Submission status: Wrong Answer

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

for i in range(0, N):
    if S[i] != '.':
        break
print(min(S[i:].count('.'), S[i:].count('#')))

Submission status: Wrong Answer

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

li = list(S)
count = 0

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
s = input()
first = n
for i in range(n):
  if (s[i] == '#'):
    first = i
    break
if (first < n):
  print(s[first:].count('.'))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if s.count("#")==0 or s.count(".")==0:
    print(0)
    exit()
bi=s.index("#")
wi=n-s[::-1].index(".")
bc=s[bi:wi].count("#")
print(min(bc,wi-bi-bc))

Submission status: Wrong Answer

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

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

S2 = map(lambda x: x == '#', S)
c1 = 0
c2 = 0
for i in reversed(list(S2)):
    if i:
        if c2 > 0:
            c1 += 1
    else:
        c2 += 1

print(min(c1, c2))

Submission status: Wrong Answer

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

if '.' not in s or '#' not in s:
  print(0)
elif '#.' not in s:
  print(0)
else:
  if s[n-1] == '#':
    s = s[:s.rfind('.')+1]
  print(min(s.count('.'), s.count('#')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
memo = 0
count = 0
for i in range(N):
    if S[i] == "#":
        memo = i
        S_right = S[i:]
        count = S_right.count(".")
        break

print(count)

Submission status: Wrong Answer

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

print(0 if '#' not in s else s.count('.'))