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:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
s = list(ns())
w = 0
b = 0
l = 0
count = 0
white = ['.' for _ in range(n)]
black = ['#' for _ in range(n)]
for i in range(n):
    if s[i] == '#':
        count += 1
lis = ['.' for i in range(n)]
for i in range(n - count, n):
    lis[i] = '#'
for i in range(n):
    if s[i] != white[i]:
        w += 1
    if s[i] != black[i]:
        b += 1
    if s[i] != lis[i]:
        l += 1
print(min(w, b, l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#Stones
N=int(input())
S=input()
count=0
i=0
if S.count("#")==0:
    print(0)
else:
    while S[i]!="#":
        i=i+1
    a=S[i:].count(".")
    print(a)

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=='.')
    ans2 = sum(1 for x in s if x=='#') + 1

    print(min(ans, ans2))
except:
    print(0)

Submission status: Wrong Answer

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


it1=0
it2=N-1
it1f=False
it2f=False
r3=0

while it1<it2:
  if S[it1]!=".":
    it1f=True
    if it1f==True and it2f==True:
      r3+=1
      it1+=1
      it1f=False
  else:
    it1+=1

  if S[it2]!="#":
    it2f=True
    if it1f==True and it2f==True:
      it2f=False
      r3+=1
      it2-=1
  else:
    it2-=1


print(r3)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans1 = 0
ans2 = 0
for i in range(1, n):
    if s[i] != '#':
        ans1 += 1
for i in range(n-1):
    if s[i] != '.':
        ans2 += 1
print(min([ans1, ans2]))

Submission status: Wrong Answer

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

two_pre = ''
one_pre = ''
res = 0
if s.count('.') > s.count('#'):
  print(s.count('#'))
else:
  for i in s:
    if two_pre == '.' and one_pre == '#' and i == '.':
        res += 1
        one_pre = i
        two_pre = '.'

    elif one_pre == '#' and i == '.':
        res += 1
        one_pre = '#'
        two_pre = one_pre
        
    else:
        two_pre = one_pre
        one_pre = i
        
  print(res)

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

print(min(white_count, black_count, counter))

Submission status: Wrong Answer

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

idx = -1
flag = 0
for i, s in enumerate(S):
    if s == '.' and flag:
        idx = i - 1
        break
    if s == '#':
        flag = 1

if idx < 0:
    print(0)
    sys.exit()

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

Submission status: Wrong Answer

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

print(res)

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

first_w = 10 ** 6
last_b = 10 ** 6

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

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

change_num1 = -1
change_num2 = 0
S = "s" + S
if first_w < 10 ** 6:
    for s in S[:first_w]:
        if s == "#":
            change_num1 += 1
    for s in S[first_w:]:
        if s == ".":
            change_num1 += 1

if last_b < 10 ** 6:
    for s in S[:last_b]:
        if s == "#":
            change_num2 += 1
    for s in S[last_b:]:
        if s == ".":
            change_num2 += 1

print(min(change_num1, change_num2))

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
  out1 = 0
  for i in range(first+1,N+1):
    if S[i-1] =='.':
      out1 += 1
  out2 = 0
  for i in range(1,N+1):
    if S[i-1] == '#':
      out2 += 1
  print(min(out1,out2,N-out2))

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+1] + "#" + S[i+2:]
  
if 2*ans < N:
  print(ans)
 
else:
  print(le-ans)
  
print(S)

Submission status: Wrong Answer

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

flag = False
count_w = 0
count_b = 0
for i in list(S):
    if(i == '#'):
       count_b += 1
       if(flag != True):
           flag = True
    else:
        if(flag):
            count_w += 1
print(min(count_w, count_b))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys

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

bcnt = 0
wcnt = 0
bst = 10 ** 6
lastlen = 0

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

print(min(wcnt, bcnt-lastlen))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())
if set(S) == {'#'} or set(S) == {'.'}:
    print(0)
    sys.exit()
first_b = S.index('#')
b_count = S.count('#')
w_count = S[first_b:].count('.')
if b_count < w_count:
    print(b_count)
else:
    print(w_count)

Submission status: Wrong Answer

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

c=0
res=0
for i in range(n-1):
	if sl[i]=="#" and sl[i+1]==".":
		res= res + 1
		c=i+1
	elif sl[i]=="." and sl[i+1]=="." and i==c:
		res= res + 1
		c=i+1
print(res)

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(min(t,S.count("#"),S[b:].count(".")))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s = S.find('#')
print(S[s:].count('.') if s!= -1 else 0)

Submission status: Wrong Answer

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

ans=s.count(".")
if n==ans:
    print(0)
    sys.exit()
if s[0]==".":
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

allw = 0
allb = 0
tmpb = 0
ss = True if s[0] == '.' else False
for _s in s:
  if not ss and _s == '.':
    allb += 1
    if tmpb > 0:
      allw += tmpb
  elif _s == '#':
    tmpb += 1
    ss = False
print(min(allw, allb))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

n = int(input())

s = input()

idx = s.find("#.")
ans = 0
if idx == -1:
  ans = 0
else:
  if idx != 0:
      if s[idx-1] == "#":#左がbならwは置けない
        ans = s[idx:].count(".")
      else:
        ans = min(s[idx:].count("."), s[idx:].count("#"))
  else:
    ans = min(s.count("."), s.count("#"))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count1 = s.count('.')
count2 = s.count('#')

index=0
while(True):
    if(index < n):
        if(s[index]=="."):
            index+=1
        else:
            break
    else:
        break
if(count1 > s[index:].count(".") and index!=n):
    print(s[index:].count("."))
else:
    print(min(count1, count2))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
w,b = 0,0
for s in S:
    if s == '.':
        w += 1
    else:
        b += 1

if b > w:
    print(w)
else:
    if S[len(S)-1] == '#':
        print(b-1)
    else:
        print(b)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
white_change = 0 if s.count("#") == 0 else s[s.index("#"):].count(".")
if s.count("#") < white_change:
    print(s.count("#"))
else:
    print(white_change)

Submission status: Wrong Answer

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

n1 = len(new1str)
for i in range(n1):
    if new1str[n1-1-i] == ".":
        newstr = new1str[:n1-i]
        break

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

Submission status: Wrong Answer

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

ans = 0

for i in range(1,n):
    if s[i-1] != s[i]:
        if s[i-1] == '.':
            s[i-1] = '#'
        elif s[i] == '.':
            s[i] = '#' 
        ans += 1



print(ans)

Submission status: Wrong Answer

Solution code:
A = int(input())
B = input()
B += ' '
C = B
cnt = 0
x = 0
for i in range(0,A):
  if B[i] == '#' and B[i+1] == '.':
    B = B.replace(B[i+1], '#', 1)
    cnt += 1
for i in range(0, A):
  if C[i] == '#' and C[i+1] == '.':
    C = C.replace(C[i], '.', 1)
    x += 1

if cnt <= x:
  print(cnt)
else:
  print(x)

Submission status: Wrong Answer

Solution code:
#!/snap/bin/pypy3

def sharpcounter(string):
    for i, char in enumerate(string):
        if char != '#':
            return i
    else:
        return len(string)


def main():
    N = int(input())
    S = input()

    count = 0
    tmp_sharp = 0
    for i, char in enumerate(S):
        if char == '#':
            tmp_sharp += 1
        else:
            if i + 1 < N and S[i+1] == '#':
                count += 1
            elif i + 1 == N:
                count += int(tmp_sharp > 0)
            else:
                count += min(tmp_sharp, sharpcounter(S[i+1:]))
                tmp_sharp = 0 

    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

res = float("inf")

counts = []
counts.append((0, 0))
a, b = 0, 0
for s in S:
    if s == "#":
        a += 1
    elif s == ".":
        b += 1
    counts.append((a, b))

for i in range(N):
    print(i)
    res = min(res, counts[i + 1][0] + counts[-1][1] - counts[i + 1][1])

print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().rstrip()
index = S.find("#")
answer = 0
if index == -1:
    print(0)
    exit()
else:
    answer = S[index:].count(".")
index = S.rfind(".")
answer = S[:index].count("#") if S[:index].count("#")<answer else answer
print(answer)

Submission status: Wrong Answer

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

i = s.find('#')
j = s.count('.')
k = s.rfind('.')

if i == -1 or k == -1:
    print(0)
else:
    print(min(j - i, k - j + 1))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = [str(i) for i in input()]

    black_num = 0
    white_num = 0

    last_color = "black"

    for s in S:
        if s == "#":
            black_num += 1
            last_color = "black"
        elif s == ".":
            white_num += 1
            last_color = "white"

    if N != black_num + white_num:
        print("error")
        return

    if last_color == "black":
        black_num -= 1

    print(min([black_num, white_num]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

siro = s.count(".")

kuro = n-siro

mini = min(siro,kuro)

    
print(mini)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
last = s[-1]
count = 0

for c in reversed(s[:-1]):
	if(last == '.' and c == '#'):
		count += 1
	last = c

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())[::-1]


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

ans1 = s.count('.')
ans2 = s.count('#')
print(min([ans1, ans2]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
ans = 0
black = False
for i in range(N):
    if S[i] == '#':
        black = True
    elif black == True and S[i] == '.':
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
x = int(input());
s=list(input());
 
j = 0;
 
for i in range(len(s)):
    if str(s[i]) == '#':
        if i != len(s) - 1:
          if str(s[i+1]) == '.':
              s[i] = '.';
              j = j + 1;
 
print(j);

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans1 = 0
ans2 = 0
for i in range(n):
    if s[i] != '#':
        ans1 += 1
for i in range(n-1):
    if s[i] != '.':
        ans2 += 1
print(min([ans1, ans2]))

Submission status: Wrong Answer

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


black=0
white=0
for st in s:
  if st=="#":
    black=black+1
  else:
    white=white+1
change=0
s = list(s)

if black>white:
  for i in range(n-1):
    if s[i]=="#" and s[i+1]==".":
      change=change+1
      s[i+1]="#"

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

print(change)

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 = list(input())

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

tmp2 = None
for i in range(len(S)-1, -1, -1):
	if S[i] == "#":
		S[i] = "."
	else:
		break
else:
	tmp2 = 0

if tmp2 != 0:
	tmp2 = S.count("#")
# print(tmp2)
print(min(tmp1, tmp2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
# . = しろ
# # = 黒
# #の横に.がないようにしたい
# #の横に.があったら#を.に変える
# or #の横に.があったら.を#に変える

# テストケース
"""
11
#..#.##.##.
"""
# => .....# = 2

def inorderReplace(S , N): 
    S = list(S)
    cnt = 0
    for i in range(N - 1) : 
        nowChar = S[i]
        nextChar = S[i + 1]
        if nowChar == "#" and nextChar == "." : 
            cnt += 1
            S[i + 1] = "#"
    return cnt

def preorderReplace(S , N) : 
    S = list(S)
    cnt = 0
    for i in reversed(range(1, N)) : 
        nowChar = S[i]
        prevChar = S[i - 1]
        if prevChar == "#" and nowChar == "." : 
            cnt += 1
            S[i - 1] = "."
    return cnt


cnt = inorderReplace(S , N)
cnt2 = preorderReplace(S , N)
print(min(cnt , cnt2))

Submission status: Wrong Answer

Solution code:
import sys

l = raw_input().split()
N = int(l[0])
l = raw_input().split()
S = list(l[0])

num_black = 0
num_white = 0

temp_black = 0
for s in S:
    if s == '#':
        temp_black += 1
    else:
        num_white += 1
        num_black += temp_black
        temp_black = 0

print(min(num_black, num_white))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
curb=S.find("#")
curw=S.rfind(".")
def solve():
	if curb==-1:
		return 0
	else:
		if curw==-1:
			return 0
		else:
			return min(S[:curw+1].count("#"),S[curb:].count("."))
print(solve())

Submission status: Wrong Answer

Solution code:
import copy
N = input()
S = list(input())

# BtoW
bs = copy.deepcopy(S)

b_count = 0
for index in range(len(S) - 1):
    if bs[index] == '#' and bs[index +1] == '.':
        bs[index + 1] = '#'
        b_count += 1


#WtoB
ws = copy.deepcopy(S)
w_count = 0
for index in range(len(S) - 1):
    rindex = -1 * index -1
    if ws[rindex-1] == '#' and ws[rindex] == '.':
        ws[rindex - 1] = '.'
        w_count += 1

print(min(b_count, w_count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#.#
tilnow = []
tilnow.append(S[0])
ans1 = 0

#白を断固として消すパターン
for i,s in enumerate(S[1:]):
    if s == ".": 
        if tilnow[i-1] == "#":
            ans1+=1
            tilnow.append("#")
        else:
            tilnow.append(".")
    else:
        tilnow.append("#")


ans2 = 0
#黒を断固として消すパターン
i= 0

while True:
  s = S[i]
  if i+1 == N:
    break
  if s == "#":
        if S[i+1] == ".":
            ans2+=1
            tilnow.append(".")
        else:
            tilnow.append("#")
  else:
      tilnow.append(".")
  i+=1


print(min(ans1,ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = s.find("#")
anum = s.count("#")
b = s.find(".")
bnum = n - anum


if a == -1 or b == -1:
    print(0)
else:
    print(min(s[a:].count("."),sorted(s)[b:].count("#"),bnum,anum))
    #print(s[a:].count("."),sorted(s)[b:].count("#"),bnum,anum)
#print(b)
#print(s[:b+1].count("#"))

Submission status: Wrong Answer

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

black_ind = S.find("#")
white_ind_reverse = S[::-1].find(".")
if black_ind == -1 or white_ind_reverse == -1:
    print(0)
else:
    white_ind = N - white_ind_reverse - 1
    # 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:
N = int(input())
S = input()
S = list(S)
K = S.copy()

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

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

print(min(res1, res2))

Submission status: Wrong Answer

Solution code:
from sys import stdin
# import math
import numpy as np
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]

N = int(stdin.readline().rstrip().split()[0])
S = stdin.readline().rstrip().split()[0]

white = S.count(".")
if white == N:
  print(0)
else:
  first_black = S.index("#")
  print(white - first_black)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
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 = list(input())
T = S.copy()

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

Submission status: Wrong Answer

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

count = 0
for i,char in enumerate(S):
  if (i < len(S) - 1):
    if (char == "#"):
      if (S[i+1] == "."):
        count += 1
      
print(count)

Submission status: Wrong Answer

Solution code:
def chec(s):
    clis = []
    for i in range(len(s)):
        if i+1 != len(s) and s[i] == '#' and s[i+1] == '.' :
            clis.append(i)
    return len(clis)


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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math,string
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
S = read_str()

def solve():
    ans = 0
    head_dot = 0
    tail_hash = N
    for i in range(N):
        if S[i] != ".":
            break
        head_dot += 1
    for i in range(N):
        if S[N - i -1] != "#":
            break
        tail_hash -= 1

    ans = min(S[head_dot:tail_hash].count("."), S[head_dot:tail_hash].count("#"),)
    return ans

if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
import re


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

match = re.match('^\.*#', S)
if match:
    first_match = len(match.group(0))
else:
    print(0)
    exit()

ca1 = S[first_match:].count('.')
ca2 = S.count('#')

print(min((ca1, ca2)))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s_list = list(S)
count_1 = 0
count_2 = 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 += 1
            flag += 1
    if flag == 0:
        break

while True:
    flag = 0
    for i in range(N-1):
        if s_list[i] == "#" and s_list[i+1] == ".":
            s_list[i] = "."
            count_2 += 1
            flag += 1
    if flag == 0:
        break
if count_1 > 0 and count_2 > 0:
    print(min(count_1,count_2))
else:
    print(count_1)

Submission status: Wrong Answer

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

ans = 0

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

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 < cntk:
            ans += cntj
        else:
            ans += cntk
print(ans)

Submission status: Wrong Answer

Solution code:
import re

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

pattern = r'#.'
match = re.findall(pattern, S)
print(len(match))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
col = "#."
hoge = 0
C = [0]
for i in range(N):
    if S[i] == col[hoge%2]:
        C[-1] += 1
    else:
        C.append(1)
        hoge += 1
B,W =0,0
for i in range(int(len(C)/2)):
    B += C[i*2]
    W += C[i*2+1]
if C[0] == 0:
    W -= C[1]
print(min(B,W))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans1 = S[0]
Sr = S[::-1]
ans2 = Sr[0]
cnt1 = 0
cnt2 = 0
for i in range(1, N):
  if ans1[-1]=='#' and S[i]=='.':
    ans1+='#'
    cnt1+=1
  else:
    ans1+=S[i]
  
  if ans2[-1]=='.' and Sr[i]=='#':
    ans2 +='#'
    cnt2 += 1
  else:
    ans2+=Sr[i]

print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
white_count = 0
black_count = 0
count = 0
for i in range(N):
    if S[i] == ".":
        white_count += 1
    else:
        black_count += 1
        if i != N-1 and S[i+1] == ".":
            count += 1
print(min(white_count,black_count,count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = [0 for i in range(n + 1)]

for i in range(n):
    for j in range(n + 1):
        if j <= i:
            if s[i] == '.':
                ans[j] += 1
        else:
            if s[i] == '#':
                ans[j] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
S = input()
ans = S.count('.')
num = 0
for x in S:
    if x == '#':
        break
    else:
        num += 1
print(ans-num)

Submission status: Wrong Answer

Solution code:
import math
 
#n=list(map(int,input().split()))
#x=int(input())
n=int(input())
s=input()
count=0
f=False
for a in range(len(s)):
    if f==True and s[a]==".":
        count+=1
    if s[a]=="#":
        f=True
count2=0
f=False
for a in range(len(s)):
    if f==True and s[len(s)-1-a]=="#":
        count2+=1
    if s[len(s)-1-a]==".":
        f=True
print(min([count,count2]))

Submission status: Wrong Answer

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

index=0
shCounter=0
jhC=0
while index < len(listS):
    if listS[index] == "#":
        jhC+=1
    else:
        shCounter+=jhC
        jhC=0
    index+=1

index=len(listS)-1
dotCounter=0
jhC = 0
while index > -1:
    if listS[index] == ".":
        jhC += 1
    else:
        dotCounter += jhC
        jhC = 0
    index -= 1

print(min(shCounter, dotCounter))

Submission status: Wrong Answer

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

X = [0 if x == '#' else 1 for x in S]
Y = list(reversed(X))

if 0 not in X or 1 not in X:
    ans = 0 
else:
    idx = X.index(1)
    X = sum(X[idx:])
    Y = N - X - Y.index(0)
    ans = min(X, Y)

print(ans)

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
  out1 = 0
  for i in range(first+1,N+1):
    if S[i-1] =='.':
      out1 += 1
  out2 = 0
  for i in range(1,N+1):
    if S[i-1] == '#':
      out2 += 1
  print(min(out1,out2))

Submission status: Wrong Answer

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

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

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

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

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

print(min(ANS1, ANS2))

Submission status: Wrong Answer

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

flag = s.count("#") > s.count(".")

if flag:
    print(s.count("."))
else:
    print(s.count("#"))

Submission status: Wrong Answer

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

print(min(a,b,c,d))

Submission status: Wrong Answer

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