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

cnts_b_from_r = [0 for i in range(-1,N)]
cnts_w_from_l = [0 for i in range(-1,N)]

# count num for each color
lst = list(S)
last_black = 0
for i,val in enumerate(lst):
	if S[i] == "#":
		last_black += 1
	
	cnts_b_from_r[i] = last_black
	
lst.reverse
last_white = 0
for i,val in enumerate(lst):
	if val == ".":
		last_white += 1
	
	cnts_w_from_l[i] = last_white

min_val = N
for i in range(-1,N):
	new_val = cnts_b_from_r[i] + cnts_w_from_l[N-(i+2)]
	min_val = min(new_val,min_val)

print(min_val)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
change_list = []
change_list.append(0)
result1 = 0
result2 = 0
result3 = 20001
result4 = 20001
for i in range(len(S)-1):
	if S[i] !=S[i+1]:
		change_list.append(i+1)
change_list.append(len(S))
if S[0] == '.':
	for i in range(2,len(change_list)):
		if i % 2==0 and i!=len(change_list)-1:
			result1+=change_list[i]-change_list[i-1]
		elif i % 2 !=0:
			result2+=change_list[i]-change_list[i-1]
	if len(change_list)>=6:
		if S[-1] == '.':
			result3=result1-(change_list[-2]-change_list[-3])+change_list[-1]-change_list[-2]
			result4=result2-(change_list[-1]-change_list[-2])+change_list[-1]-change_list[-2]
		else:
			result3=result1-(change_list[-3]-change_list[-4])+change_list[-2]-change_list[-3]
			result4=result2-(change_list[-2]-change_list[-3])+change_list[-2]-change_list[-3]
		print(min(result1,result2,result3,result4))
	else:
		print(min(result1,result2))
else:
	start = change_list[1]-change_list.pop(0)
	for i in range(2,len(change_list)):
		if i % 2==0 and i!=len(change_list)-1:
			result1+=change_list[i]-change_list[i-1]
		elif i % 2 !=0:
			result2+=change_list[i]-change_list[i-1]
	if len(change_list)>=6:
		if S[-1] == '.':
			result3=result1-(change_list[-2]-change_list[-3])+change_list[-1]-change_list[-2]
			result4=result2-(change_list[-1]-change_list[-2])+change_list[-1]-change_list[-2]
		else:
			result3=result1-(change_list[-3]-change_list[-4])+change_list[-2]-change_list[-3]
			result4=result2-(change_list[-2]-change_list[-3])+change_list[-2]-change_list[-3]
		print(min(result1+start,result2+start,result3+start,result4+start,S.count('.')))
	else:
		print(min(result1+start,result2+start,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 = input()

a=0
b=0
d=0
dot_c=0
sharp_c=0
revS = S[::-1]

for i in S:
    if i == ".":
        dot_c += 1
    else:
        break

for i in revS:
    if i == "#":
        sharp_c += 1
    else:
        break

if S.find("#.") != -1:
    for i in revS:
        if i == "#":
            a+=1

        else:
            b+=1

    if a>b:
        print(b-dot_c)
    else:
        print(a-sharp_c)

else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
S = input()
S = S.replace('.', '1')
S = S.replace('#', '0')
S = list(map(int, S))
w = np.array(S)
v = w[:-1] - w[1:]
v = np.where(v != 0)[0] + 1
v = np.hstack((v, np.array([len(w)])))
v = np.hstack((np.array([0]), v))
v = v[1:] - v[:-1]
if S[0] == '0':
    v = np.hstack((np.array([0]), v))
if len(v) % 2 != 0:
    v = np.hstack((v,np.array([0])))
v = np.reshape(v, (-1,2)).T
y = [sum(v[0,:n])+sum(v[1,n:]) for n in range(v.shape[1]+1)]
print(min(y))

Submission status: Wrong Answer

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

bcnt = []
wcnt = []

if s[0]=="#":
    bcnt += [1]
    wcnt += [0]
else:
    bcnt += [0]
    wcnt += [1]

for i in range(1,n):
    if s[i]=="#":
        bcnt += [bcnt[i-1]+1]
        wcnt += [wcnt[i-1]]
    else:
        bcnt += [bcnt[i-1]]
        wcnt += [wcnt[i-1]+1]

# print(bcnt)


wcnt.reverse()

# print(wcnt)

nuru = [0]*(n+1)
nuru[0] = wcnt[0]

for i in range(1,n):
    nuru[i] = wcnt[i]+bcnt[i-1]
    
nuru[n] = bcnt[n-1]

# print(nuru)

# print(bcnt)
# print(wcnt)
print(min(nuru))

Submission status: Wrong Answer

Solution code:
from __future__ import print_function
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


n=int(input())
S=list(input())

cnt_temp=0
cnt_temp2=0
stack=[]
cnt=0

# # eprint(n)
# # eprint(S)

# for i in range(n):
#     # eprint(i)


flag=0
flag2=0
start=0

for i in range(n):
    if S[i] == '.':
        cnt_temp+=1



if S[0] == '.':
    flag =1
# eprint("flag: ",end="")
# eprint(flag)

if flag==1:
    for i in range(n-1):
        if S[i]=='#' and S[i+1]=='.':
            flag2=1
            for j in range(i+1,n):
                if S[j] =='.':
                    cnt_temp2+=1
            break
# eprint("flag2: ",end="")
# eprint(flag2)
        

        
for _ in S:
    print( _ , end="")
print()
        
for i in range(n-1):
    if S[i]=='#' and S[i+1]=='#':
        stack.append(i)
    elif S[i]=='#' and S[i+1]=='.':
        
        S[i]='.'
        cnt+=1
        
        # for _ in S:
            # eprint(_,end="")
        # eprint()
        
        
        
        while stack!=[]:
            temp=stack.pop()
            S[temp]='.'
            cnt+=1
            # for _ in S:
                # eprint(_,end="")
            # eprint()

            
        
# eprint("cnt: ",end="")
# eprint(cnt)
# eprint("cnt_temp2: ",end="")
# eprint(cnt_temp2)

print(min(cnt,cnt_temp,cnt_temp2))
            #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c = 0
A = int(S.count("."))
B = N - A
if len(S) == N:
    if 1 <= N <= 2 * 10 ** 5:
        if "." in S:
            if "#" in S:
                S.replace("#.","ee")
                D = S.find("e") + 1
                C = N - D + 1                
                print(N - C + B)

Submission status: Wrong Answer

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

c=0
b=0
w=0
skip=0
res=0
for i in range(n-1):
	if i < skip:
		continue
	if sl[i]=="#":
		b=b+1
	else:
		b=0

	if sl[i]=="#" and sl[i+1]==".":
		for j in range(1, n-i):
			if sl[i+j]==".":
				w=w+1
			else:
				break
		if b <= w:
			res=res+b
			b=0
			w=0
		else:
			res=res+w
			b=b+w
			skip=i+w+1
			w=0
			#print(skip)
print(res)

Submission status: Wrong Answer

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

print(min(count,count_))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Color=[]
CNT=[]	#Count
cnt=0
prev=""
for i in range(N):
	if i==0:
		if S[i]=="#": Color.append("b")
		else: Color.append("w")
		cnt+=1
	else:
		if prev==S[i]:
			cnt+=1
		else:
			CNT.append(cnt)
			if S[i]=="#": Color.append("b")
			else: Color.append("w")	
			cnt=1	

	prev=S[i]
else:
	CNT.append(cnt)

l=len(Color)

ans=0
for i in range(l-1):
	if Color[i]=="b" and Color[i+1]=="w" :
		if CNT[i]<=CNT[i+1]:
			ans+=CNT[i]
			Color[i]="w"
		else:
			ans+=CNT[i+1]
			Color[i+1]="b"


print ans

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c=0
d=0
switch=0
for i in range(N):
    if S[i]=='#' and switch==0:
        switch=1
    elif switch==1 and S[i]=='.':
        c=S[i-1:].count('.')
        break
S=S[::-1]
for i in range(N):
    if S[i]=='.' and switch==0:
        switch=1
    elif switch==1 and S[-i]=='#':
        d=S[i-1:].count('#')
        break
print(min(c,d))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
count = 1
for i in s:
  if i == ["#"]:
    if s[(s.index(i))] == ["."]:
      count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
start = S.find("#")
if start == -1:
    print("0")
else:
    di = {".":"0","#":"1"}
    S_bin = int("0b"+S[start:].translate(str.maketrans(di)), 0)
    a = int("0b"+"1"*int(N-start) ,0)
    ans1 = min(bin(a^S_bin).count("1"),bin(a^S_bin).count("0"))
    ans4 = min(bin(int("0b"+"0"*int(N-start) ,0)^S_bin).count("1"),bin(int("0b"+"0"*int(N-start) ,0)^S_bin).count("0"))
    ans2 = min(bin(0^int("0b"+S.translate(str.maketrans(di)), 0)).count("1"),bin(0^int("0b"+S.translate(str.maketrans(di)), 0)).count("0"))
    ans3 = min(bin((int("0b"+"1"*int(N) ,0))^int("0b"+S.translate(str.maketrans(di)), 0)).count("1"),bin((int("0b"+"1"*int(N) ,0))^int("0b"+S.translate(str.maketrans(di)), 0)).count("1"))
    print(min(ans1,ans2,ans3,ans4))

Submission status: Wrong Answer

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

post = ''
ans=0
data=[]

left=[]
right=[]

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]=="#" and tmp!=0:
        right.append(tmp)
        tmp=0

right.reverse()
# 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:
def main():
    N = int(input())
    S = input()
    cand = []
    b = []
    cand.append(S.count('#'))
    cand.append(S.count('.'))
    for i in range(N):
        if S[i] == '#':
            b.append(i)
    S = int(S.replace('#', '1').replace('.', '0'), 2)
    for i in range(len(b)-1):
        cand.append(str(S^int('1'*(N - 1 - b[i+1] + 1),2)).count('1'))
    print(min(cand))
main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
_ = input()
s = list(input())
cnt = 0

for i in range(1, len(s)-1):
    if s[i-1] == '.' and s[i] =='#' and s[i+1] == '.':
        s[i] = '.'
        cnt +=  1
    elif s[i] == '#' and s[i+1] == '#':
        if s[i+2:].count('#') > s[i+2:].count('.'):
            break
        else:
            s[i], s[i+1] = '#', '#'


try:
    sl = s[s.index('#'):]
    if sl.count('#') < sl.count('.'):
        print(sl.count('#') + cnt)
    else:
        print(sl.count('.') + cnt)
except:
    print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
B,W =0,0
hoge = 0
for c in S[0:N]:
    if c=="#":
        hoge += 1
    if c == ".":
        B += hoge
        hoge = 0
        if B > 0:
            W += 1
print(min(B,W))

Submission status: Wrong Answer

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

a = len(re.findall('#.', S))
print(min(a,N-a))

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] == '.': # white
            b = b + 1
    for k in range(a, N - 1):
        if S[k] == '#': # black
            c = c + 1

    print(min(b,c))

Submission status: Wrong Answer

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

S += "q"

L = []
cnt = 0
for i in range(N) :
    cnt += 1
    if S[i] != S[i+1] :
        L.append(cnt)
        cnt = 0

A = []
B = []

for i in range(len(L)) :
    if i % 2 == 0 :
        A.append(L[i])
    else :
        B.append(L[i])

if len(L) == 1 :
    ans = 0
elif len(L) == 2 :
    if S[0] == "#" :
        ans = min(L)
    else :
        ans = 0
elif len(L) == 3 :
    if S[0] == "#" :
        ans = min(L[0],L[1])
    else :
        min(L[0]+L[2],L[1])
else :
    if S[0] == "#" :
        if len(L) % 2 == 0 :
            a = min(A.pop(-1), B.pop(-1))
            b = min(sum(A),sum(B))
            ans = a+b
        else :
            A.pop(-1)
            a = min(A.pop(-1), B.pop(-1))
            b = min(sum(A),sum(B))
            ans = a+b
    else :
        if len(L) % 2 == 0 :
            B.pop(-1)
            A.pop(0)
            if len(L) == 4 :
                ans = min(A[0],B[0])
            else :
                a = min(A.pop(-1),B.pop(-1))
                b = min(sum(A),sum(B))
                ans = a+b
        else :
            A.pop(0)
            a = min(A.pop(-1),B.pop(-1))
            b = min(sum(A),sum(B))
            ans = a+b
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
S = input().rstrip("#")

def stone_cnt(idx):
  return S[:idx].count("#") + S[idx:].count(".")

left = 0
right = len(S)

while left <= right:
  mid = (left + right) // 2
  if stone_cnt(left) > stone_cnt(right):
    left = mid + 1
  else:
    right = mid - 1

print(stone_cnt(mid))

Submission status: Wrong Answer

Solution code:
# n=int(input())
# s=list(input())
# s2=s[:]
# s2.reverse()
# c=0
# for i in range(len(s)):
#   a=s[i]
#   if a=='#':
#     if i!=len(s)-1 and s[i+1]=='.':
#       s[i+1]='#'
#       c+=1
# c2=0
# for i in range(len(s2)):
#   a=s2[i]
#   if a=='.':
#     if i!=len(s2)-1 and s2[i+1]=='#':
#       s2[i+1]='.'
#       c2+=1
# print(s,s2)
# print(min(c,c2))

n=int(input())
s=list(input())
l=[]
a=s[0]
b=a
c=1
for x in s[1:]+['a']:
  if a==x:
    c+=1
  else:
    a=x
    l.append(c)
    c=1

l1=[]
l2=[]
a1=b1=0
f=0
for x in l:
  if f==0:
    a1+=x
    f=1
    l1.append(a1)
  else:
    b1+=x
    f=0
    l2.append(b1)
# print(l1,l2)
mn=1000000
if b=='.':
  l1=[0]+l1
  l2=[0,0]+l2
  for i in range(len(l1)):
    # print(l1[-1]-l1[i]+l2[i])
    mn=min(l1[-1]-l1[i]+l2[i],mn)
  print(mn)
else:
  l1=[0]+l1
  if len(l1)-1==len(l2):
    l2=[0]+l2
  else:
    l2=[0,0]+l2
  for i in range(len(l2)):
    # print(l1[-1]-l1[i]+l2[i])
    mn=min(l1[-1]-l1[i]+l2[i],mn)
  print(mn)

# if b=='#':
#   for i in range(len(l)//2):
#     cx+=(min(l[2*i],l[2*i+1]))
# else:
#   l2=l[1:]+[0]
#   for i in range(len(l2)//2):
#     cx+=(min(l2[2*i],l2[2*i+1]))
# print(cx)

Submission status: Wrong Answer

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

flag = False
ans = 0
l = []
if S != '' :
    if S[0] == '.' :
        firstIsw = True
    else :
        firstIsw = False

cnt = 1
for i in range(1, len(S)) :
    if S[i] == S[i - 1]:
        cnt += 1
    else :
        l.append(cnt)
        cnt = 1
    if i == len(S) - 1 :
        l.append(cnt)

l2 = []
for i in range(len(l)) :
    l2.append(l[i])

for i in range(len(l2) - 2)[::-1] :
    l2[i] += l2[i + 2]


#print(l)
#print(l2)

flag2 = False

if firstIsw :
    for i in range(1, len(l)) :
        if flag2 :
            if i % 2 == 0 :
                ans += l[i]
        else :
            if i % 2 == 1 :
                if i + 1 != len(l) :
                    if l2[i] <= l2[i + 1] :
                        ans += l[i]
                    else :
                        flag2 = True
else :
    for i in range(len(l)) :
        if flag2 :
            if i % 2 == 1 :
                ans += l[i]
        else :
            if i % 2 == 0 :
                if i + 1 != len(l) :
                    if l2[i] <= l2[i + 1] :
                        ans += l[i]
                    else :
                        flag2 = True

print(ans)

Submission status: Wrong Answer

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

cntA = 0
for i in S:
    if i == '.':
        cntA += 1
    else:
        break

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

ANS1 = S[cntA:N-cntB].count('.') 
ANS2 = S[cntA:N-cntB].count('#')
#print(S[cntA:N-cntB])
print(min(ANS1, ANS2))

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:
        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
ans2=s.count('#')
print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:


n = int(input())
s = list(input())
a = list(map(lambda x:x, s))
def stones(s):
    k = 0
    for i in range(len(s)-1):
        if s[i]=='#' and s[i+1]=='.':
            s[i+1] = '#'
            k = k+1
    return k

def stone(a):
    k = 0
    print(a)
    for w in range(len(a)-1):
        if a[w]=='#' and a[w+1]=='.':
            a[w] = '.'
            k = k+1
    return k
print(min(stones(s),stone(a)))

Submission status: Wrong Answer

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

A = [None]*(N+1)
A[0] = 0
cnt = 0
for i,s in enumerate(S[::-1]):
    if s=='.':
        A[i+1] = A[i]+1
    else:
        A[i+1] = A[i]-1
        cnt += 1
print(A)
print(min(A)+cnt)

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) or ((S.count('.') == 1 and S[0] == '.') or (S.count('#') == 1 and S[-1] == '#')):
  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=input()
b=0
w=0
bx=0
wx=0

for i in range(n):
    if s[i] == '#':
        b += 1
        wx = w
    elif s[i] == '.':
        bx = b
        if b>=1:
            w += 1
            wx = w

print(min(bx,wx))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cou = 0
for i in range(1, n):
    if s[i-1] == '#':
        if not s[i-1] == s[i]:
            s[i] = '#'
            cou += 1
    else:
        if not s[i-1] == s[i]:
            s[i] = '.'
            cou += 1

print(cou)

Submission status: Wrong Answer

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

s = list(s)

count1 = 0
count2 = 0

for i in range(n):
    if s[i] == '.':
        count1 += 1
    else:
        count2 += 1
        
if s[0] == '.':
    count1 -= 1
        
print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    """
    #.##...
    """
    n = int(input())
    s = input()
    s = s[:n]

    try:
        first_black = s.index('#')
    except ValueError as e:
        print(0)
        exit(0)

    s2 = s[first_black+1:]
    white_to_black = s2.count('.')
    s.count('#')
    lastb = 0
    for i in reversed(range(len(s))):
        if s[i] == '#':
            lastb += 1
        else:
            break

    black_to_white = s.count('#') - lastb
    print(min(black_to_white, s2.count('.')))

Submission status: Wrong Answer

Solution code:
from numpy import*
from itertools import*
n=int(input())
s=input()
t=s.count("#")
r=s.count(".")
 
l=[t,r]
x=[len(list(v))for k,v in groupby(s)if k=="#"]
y=[len(list(v))for k,v in groupby(s)if k=="."]
if len(x)>len(y):
    y=[0]+y
elif len(x)<len(y):
    x=[0]+x
else:
    if s[0]=="#":
        y=[0]+y
        x=x+[0]
    else:
        y=y+[0]
        x=[0]+x
 
x=array([0]+list(accumulate(x)))
y=array(list(accumulate(y[::-1]+[0]))[::-1])
print(min(x+y))

Submission status: Wrong Answer

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

d = []
s = S[0]
c = 1
for i in range(1,N):
    if s == S[i]:
        c += 1
    else:
        d.append(c)
        c = 1
        s = S[i]
d.append(c)
ans = 0
if S[-1] == "#":
    for i in range(2,len(d),2):
        ans += min(d[-i],d[-i-1])
else:
    for i in range(1,len(d),2):
        ans += min(d[-i],d[-i-1])
print(ans+1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import re

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

first = 0
position = 0
secondposition = 0
count2 = 0
for i in reversed(range(n)):
    if(first == 0 and s[i] == '#'):
        first += 1
        position = i+1
    if(first == 1 and s[i] == '.'):
        secondposition = i+1
        break;
if(position == 0):
    ans1 = 0
elif(secondposition == 0):
    ans1 =min(n-position,position)
else:
    for j in range(secondposition-1):
        if(s[j] == '#'):
            count2 += 1

    count1 = n - position

    ans1 = count1 + count2


first2 = 0
position2 = 0
secondposition2 = 0
count4 = 0
for i in range(n):
    if(first2 == 0 and s[i] == '.'):
        first2 += 1
        position2 = i+1
    if(first2 == 1 and s[i] == '#'):
        secondposition2 = i+1
        break;
if(position2 == 0):
    ans2 = 0
elif(secondposition2 == 0):
    ans2 = min(n-position2+1,position2)
else:
    for j in range(secondposition2-1,n):
        if(s[j] == '.'):
            count4 += 1

    count3 = position2-1

    ans2 = count3 + count4
print(min(ans1,ans2))

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[:i] :
				if j == "#" : k+=1
				if k > _ans : break
			for j in s[i:] : 
				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:
def remove_fwhite(S):
    fwhite = 0
    for fw in S:
        if fw == '.':
            fwhite += 1
        else:
            break
    return fwhite

def remove_fblack(S):
    fblack = 0
    for fb in S[::-1]:
        if fb == '#':
            fblack += 1
        else:
            break
    return fblack

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

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

fw = remove_fwhite(S)
fb = remove_fblack(S)
print(S[fw:N-fb])
if fw == 0 or fb == 0:
    count_stone(S)
else:
    count_stone(S[fw:N-fb])

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
kazu=kazu-1
for i in range(N):
  if i>kazu:
    if S[i]==".":
      kazuXD+=1

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

Submission status: Wrong Answer

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

cnt = 0
cnt1 = 0
cnt2 = 0
if N == 1:
    print("0")
    exit()
else:
    for i in range(N-1):
        x = S[i]
        y = S[i+1]
        if x == "#" and y == ".":
            cnt += 1
            if cnt2 == 0:
                S = S.replace(".","#",cnt1+1)
            else:
                S = S.replace(".","#",1)
        if x == ".":
            cnt1 += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
lw = 0
fw = 0
cb=0
cw=0
n = int(input())
s = input()

for i in reversed(range(n)):
    if s[i]==".":
        lw=i
        break
for i in range(n):
    if s[i]=="#":
        fw=i
        break

for i in range(fw,lw+1):
    if s[i]=="#":
        cb+=1
    elif s[i]==".":
        cw+=1
        
print(min(cb, cw))

Submission status: Wrong Answer

Solution code:
import sys

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

num = int(a[0])
haichi = a[1]
count_list = []

# 左側を全部白にする手数 (= 左側の黒の数)
split_left_count = [sum([x == '#' for x in haichi[:i]]) for i, k in enumerate(haichi)]

# 右側を全部黒にする手数 (= 右側の白の数)
split_right_count = [sum([x == '.' for x in haichi[i:]]) for i, k in enumerate(haichi)]

for i in range(num):
    each_haichi = haichi[i]
    count_list.append(split_left_count[i]+split_right_count[i])

print(min(count_list))

Submission status: Wrong Answer

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

cnt = 0
stones = list(S)

# print(stones)
flg = False
cnt = 0
for i in range(0, N):
    if flg:
        if stones[i] == ".":
            cnt += 1
    elif stones[i] == "#":
        flg = True

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=0
b=0
if n%2!=0:
    for i in range(0,n-1,2):
        if s[i]!=s[i+1]:
            a=a+1
    if a>0 and s[n-1]!='#':
        print(a+1)
    else:
        print(a)
else:
    for i in range(0,n,2):
        if s[i]!=s[i+1]:
            a=a+1
    print(a)

Submission status: Wrong Answer

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

d = []
s = S[0]
c = 1
for i in range(1,N):
    if s == S[i]:
        c += 1
    else:
        d.append(c)
        c = 1
        s = S[i]
d.append(c)
ans = 0
if S[-1] == "#":
    for i in range(2,len(d),2):
        ans += min(d[-i],d[-i-1])
else:
    for i in range(1,len(d),2):
        ans += min(d[-i],d[-i-1])
print(ans-1)

Submission status: Wrong Answer

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

s = S
first_sharp = s.find('#')
s = s[first_sharp:]

ans = 2 * 10 ** 5
for i in range(len(s)):
    #print(S[:i], S[i:])
    sharp_num = s[i:].count('#') # 後ろを#→.
    dot_num = s[:i].count('.') # 前を . → #
    ans = min(ans, dot_num + sharp_num)
print(ans)

Submission status: Wrong Answer

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

white = "."
black = "#"

s_list1 = list(s)
s_list2 = list(s)
count1 = 0
count2 = 0
for i in range(len(s)-1):
    if s_list1[i] == black and s_list1[i+1] == white:
        s_list1[i+1] = black
        count1 +=1

    if s_list2[i] == black and s_list2[i+1] == white:
        s_list2[i] = white
        count2 +=1
if count1 > count2: 
    print(count2)
else:
    print(count1)

Submission status: Wrong Answer

Solution code:
import re
n = input()
N = int(n)

S = input()

pattern = r'\#+|\.+'
repatter = re.compile(pattern)
result = repatter.findall(S)
# print(result)

pre = False
count = 0
ans = 0
for r in result:
    if r[0] == '.' and pre == True:
        tmpc = len(r)
        if count < tmpc:
            ans += count
        else:
            ans += tmpc
        pre = False

    if r[0] == '#':
        count = len(r)
        pre = True
print(ans)

Submission status: Wrong Answer

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

post = ''
ans=0
data=[]

left=[]
right=[]

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]=="#" and tmp!=0:
        right.append(tmp)
        tmp=0

right.reverse()
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:
#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]=="#" and flag==-1:
        flag=i
        break
a="."*(i-1)+"#"*(n-i+1)
b="."*n
c="#"*n
aa,bb,cc=0,0,0
for i in range(n):
    if a[i]!=s[i]:
        aa+=1
for i in range(n):
    if b[i]!=s[i]:
        bb+=1
for i in range(n):
    if c[i]!=s[i]:
        cc+=1

ans=min(aa,bb,cc)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
fKK = N
for i in range(N):
    if S[i:i+2] == '##':
        fKK = i
for j in range(i):
    if S[j:j+2] == '#.':
        ans += 1
for K in range(i,N):
    if S[K] == '.':
        ans += 1
print(ans)

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[-1]
        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:
N = int(input())
S = list(input())
count=0

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

Submission status: Wrong Answer

Solution code:
input()
S = [1 if v == "." else 0 for v in input()]

count = 0
for s in S:
    if s == 0:
        break
    count += 1

ones = sum(S) - count
zeros = len(S) - sum(S)
print(min(ones, zeros))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

counter1=0
counter2=0
flag1=0
flag2=0
for i in range(N):

    if flag1 ==0 and moji[i]=="#":
            flag1=1
    elif flag1==1 and moji[i]==".":
            counter1+=1

    if flag2==0:
        if moji[N-i-1]==".":
            flag2=1
    elif flag2==1:
        if moji[N-i-1]=="#":
            counter2+=1

print(min(counter1,counter2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
replace_point = -1
while 0 == 0:
    replace_point = S.find("#.")
    right_replace_point = replace_point
    if replace_point == -1:
        break
    left_rep = 1
    right_rep = 1
    if replace_point != 0:
        while 1 == 1:
        # 左を見に行く
            if S[replace_point-1:replace_point] == "#":
                left_rep += 1
                replace_point -= 1
            else:
                break
    if right_replace_point != N:
        while 1 == 1:
        # 右を見に行く
            if S[right_replace_point+2:right_replace_point+3] == ".":
                right_rep += 1
                right_replace_point += 1
            else:
                break
    ans += min(left_rep, right_rep)
    S = S[replace_point+1:]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c = 0
A = int(S.count("."))
B = N - A
if len(S) == N:
    if 1 <= N <= 2 * 10 ** 5:
        if "." in S:
            if "#" in S:
                S.replace("#.","ee")
                D = S.find("e") + 1
                C = N - D + 1                
                print(N - C + B)
            else:
                print(0)