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=list(input())
counter=0
for i in range(N-1):
    if S[i - 1] == '#' and S[i]=='#' and S[i + 1]=='.':
        S[i + 1] = '#'
        counter += 1
    elif S[i - 1] == '#' and S[i]=='.' and S[i + 1]=='.':
        S[i - 1] = '#'
        counter += 1
    elif S[i - 1] == '#' and S[i]=='.' and S[i + 1]=='#':
        S[i] = '#'
        counter += 1
    elif S[i - 1] == '.' and S[i]=='#' and S[i + 1]=='.':
        S[i] = '.'
        counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
cnt = 0
if S.count('#')>S.count('.'):
  word = '#'
else:
  word = '.'
ans=""
for i in range(N):
  if i==0:
    ans+=S[i]
    pass
  if ans[-1]=='#' and S[i]=='.':
    cnt+=1
    ans+=word
  else:
    ans+=S[i]

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
kurodeta = False
for i, isi in enumerate(S):
    if not kurodeta and isi == ".":
        continue
    if isi == "#":
        kurodeta = True

    if isi == ".":
        cnt += 1

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

ccnt = S.count("#")

print(min([cnt, ccnt]))

Submission status: Wrong Answer

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

    
change=0
s = list(s)

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


if change > n - change:
  change=n-change
print(change)

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

for i in range(kazu,N):
  if S[i]==".":
    S[i]="#"
    kazuXD+=1
  
print(kazuXD)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
onlyb = 0
onlyw = 0
twotn = 0
flag = 0
ch =0
for i in range(N):
    if S[i] == ".":
        onlyb += 1
        ch = 0
        if flag != 0:
            twotn +=1
    else:
        onlyw += 1
        ch +=1
        flag = 1

print(min(onlyb,onlyw-ch,twotn))

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
stemp=input()
s=[ i for i in stemp]

s2=copy.copy(s)
ans=0
ans2=0
ans3=0
f=0
for i in range(n):
    #print(i)
    if 1<=i and i<=n-1:
        if s[i]==".":
            ans+=1
    if i<=n-2:
        if s2[i]=="#":
            ans2+=1
    #print(n-i-1)
    if n-i-1>0:
        if s[n-i-1]==".":
            f=1
    if n-i-1>0:
        if f>0:
            if s[n-i-1]=="#":
                ans3+=1


#print(s)
#print(s2)
#print(ans,ans2)
if ans3!=0:
    print(min(ans,ans2, ans3))
else:
    print(min(ans,ans2))

Submission status: Wrong Answer

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

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

l_ans = 0

for i in range(N-1):
    if S2[i] == "#" and S2[i+1] == ".":
        S2[i+1] = "#"
        l_ans += 1
    #print(S2)
#print(r_ans,l_ans)

print(min(r_ans,l_ans))

Submission status: Wrong Answer

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

tmp = [0 for _ in range(N+1)]

if S[0] == '.':
    tmp[0] = 1

for i in range(N):
    if S[i] == '.':
        tmp[i+1] = tmp[i] + 1
    else:
        tmp[i+1] = tmp[i]
  
res1 = 10 ** 9
for i in range(N+1):
    res1 = min((i + 1) - tmp[i] + tmp[N] - tmp[i], res1)
        

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

res3 = N - max(b, w)

print(min(res1, res3))

Submission status: Wrong Answer

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

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

dot_count = 0
for j in range(index,N):
    if S[j] == "#":
        dot_count += 1

dot_count += S[:index].count(".#")
        
print(min(sharp_count,dot_count))

Submission status: Wrong Answer

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

print(min(c,b,w))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = n
temp_ans = n
for i in range(n):
    temp_ans = s[:i+1].count('#')+s[i+1:].count('.')
    ans = min(ans,temp_ans)
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ANS1 = 1000000000
if S[0] == '#':
    ANS1 = S.count('.') 

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

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

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

ANS3 = newS[cnt:].count('#') 

ANS4 = 1000000000
if newS[0] == '.':
    ANS1 = S.count('#') 

print(min([ANS1, ANS2, ANS3, ANS4]))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
S=S+'#'
sc=0
tc=0
ans=0
for i in range(N+1):
    if(tc!=0 and S[i]=='#'):
        if(sc>tc):
            ans+=tc
            sc+=tc
        else:
            ans+=sc
            sc=0
        tc=0
    if(sc!=0 and S[i]=='.'):
        tc+=1
    elif(tc==0 and S[i]=='#'):
        sc+=1
print(str(ans))

Submission status: Wrong Answer

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

def counting(seq, s):
  return seq.count(s)

base_count = S.count(".#")

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

idx_list = [0, len(S)]
for i in range(len(S)-1):
  if S[i] == "." and S[i+1] == "#":
    idx_list.append(i)

count_list = []
for i in idx_list:
  count_list.append(counting(S[:i], "#") + counting(S[i:], "."))
count_list.append(counting(S, "#")+0)
print(min(count_list) + base_count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
for x in range(N):
    if x == 0:
        ans = S.count(".")
    continue
    count = S[:x].count("#") + S[x:].count(".")
    if count < ans:
        ans = count
count = S.count("#")
if count < ans:
    ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
ans=0
if s.count(".")==n or s.count("#")==n:
    print(0)
    sys.exit()
for i in range(len(s)):
    if s[i]=="#":
        print(min(s[i+1:].count("."),s[i:].count("#")))
        sys.exit()

Submission status: Wrong Answer

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

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

# print(index1)


# 黒にする
res2 = 0
index2 = 0

if s[0] == "#":
    for i in range(1, len(s)):
        if s[i] == ".":
            res2 += 1
else:
     for i in range(1, len(s)):
         if s[i] != s[i - 1]:
             index2 = i
             res2 += 1
             break
     for i in range(index2 + 1, len(s)):
         if s[i] == ".":
             res2 += 1



# print(res1, res2)
print(min(res1, res2))

Submission status: Wrong Answer

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

flag = -1
for char in S:
    if char == '#' and flag == -1:
        flag += 1
    elif flag != -1 and char == '.':
        flag += 1
if flag == -1:
    flag += 1
print(flag)

Submission status: Wrong Answer

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

        res1 += 1
        S[i+1] = '#'

res2 = 0
b,w = 0,0
for i in S:
    if i == '.':
        w += 1
    else:
        b += 1
res2 = min(b,w)

print(min(res1,res2))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
p=[]
m=0
x=s.count("#.")
c=s.count("#.")
while x>0:
    s=s.replace("#.","..",x)
    m+=x
    x=s.count("#.")
    if x==0:
        p.append(m)
p.append(c)
print(min(p))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = 0
sl = list(s)
if n > 2:
  for i in range(n-2):
   if sl[i]=="#" and sl[i+1]==".":
      if sl[i+2]=="." and sl[i-1]==".":
        sl[i]='.'
        c = c + 1
      elif sl[i+2]=="." and sl[i-1]=="#":
        sl[i+1]='#'
        sl[i+2]='#'
        c = c + 2
      elif sl[i+2]=="#":
        sl[i+1]='#'
        c = c + 1
  if sl[n-2]=="#" and sl[n-1]==".":
    sl[i+1]='#'
    c=c+1
elif n == 2:
  if s=="#.":
    c=c+1
else:
  pass
print(c)

Submission status: Wrong Answer

Solution code:
num = int(input())
stone = list(input())

count = 0
# 多分、これだと最小値ではない
# for i in range(num - 1):
#     if stone[i] == "#" and stone[i + 1] == ".":
#         if i == 0:
#             stone[i] = "."
#         else:
#             stone[i + 1] = "#"
#         count += 1

for i in range(num - 1):
    if stone[i] == "#" and stone[i + 1] == ".":
        if i == 0 or stone[i - 1] == ".":
            stone[i] = "."
        else:
            stone[i + 1] = "#"
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    fb = 0
    cand = []
    b = []
    w = []
    cand.append(S.count('#'))
    for i in range(N):
        if S[i] == '#':
            b.append(i)
        elif S[i] == '.':
            w.append(i)
    for i in range(len(b) - 1):
        wh = []
        for j in w:
            if j > b[i + 1]:
                wh.append(j)
        cand.append(1 + i + len(wh))
    print(min(cand))
main()

Submission status: Wrong Answer

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

idxw = -1
idxb = -1
for i in range(N-1, -1, -1):
    if S[i] == '.':
        idxw = i
        break

for i in range(N):
    if S[i] == '#':
        idxb = i
        break

# print(idxw, idxb)

if idxw == -1 or idxb == -1:
    print(0)
else:
    cntw = S[:idxw].count('#')
    cntb = S[idxb:].count('.')

    print(min(cntw, cntb))

Submission status: Wrong Answer

Solution code:
N = int(input())
S=input()
cnt1 = 0
cnt2 = 0
for idx,s in enumerate(S):
    if s == "#" and idx != N-1:
        cnt1+=1
    if s==".":
        cnt2+=1
print(min([cnt1,cnt2]))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
for i, s in enumerate(S.split("#")):
     if i == 0:
         continue
     else:
         count += s.count(".")
print(count)

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
f = 0
c = 0
for i, s in enumerate(S):
    if s == '#' and f == 1:
        f = 0
        c += 1
    elif s == '.' and f == 0:
        f = 1
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:

n = int(input())
s = input().strip()
g = list(s)
r = list(s)
k = 0

for i in range(n-1):
  if g[i] == '#' and g[i+1] == '.':
      k+=1
      g[i+1] = '#'
e = 0
for i in range(n-1):
  
  if r[i] == '.' and r[i+1] == '#':
      e+=1
      r[i+1] = '.' 
print(min(e,k))

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

Submission status: Wrong Answer

Solution code:
SIRO = '.'
KURO = '#'
N = int(input())
S = input()
sLst = []
for i in S:
    sLst.append(i)
ans = 0
kCnt = S.count(KURO)
sCnt = S.count(SIRO)
if kCnt >= sCnt:
    for i in range(0, N - 1):
        if sLst[i] == KURO:
            if sLst[i + 1] == SIRO:
                sLst[i + 1] = KURO
                ans += 1
else:
    for i in range(N - 1, 1, -1):
        if sLst[i] == SIRO:
            if sLst[i - 1] == KURO:
                sLst[i - 1] = SIRO
                ans += 1
print(ans)

Submission status: Wrong Answer

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

if len(S) == 0:
	print(0)
else:
	for n in range(N):
		if S[n:n+2] == "#." :
			M = n+1
			break
		else:
			M = len(S)+1
	for j in range(N):
		if S[-(j+1)] == "#":
			B_end += 1
		if S[-(j+1)] == ".":
			break
	
	WB = S[M:].count(".")
	BW = max(1, S[M:].count("#") - B_end)
	print(min(WB , BW))

Submission status: Wrong Answer

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

count = 0
for n in range(int(N)):
    if (S[n-1] == '#') & (S[n] == '.'):
        count = count+1
        m = n + 1
        if n > m:
            while(S[m]):
                if S[m] == '.':
                    count = count + 1
                    n = m + 1
                else:
                    break

print(count)

Submission status: Wrong Answer

Solution code:
N,S = [input() for i in range(2)]
a = list(S)
c = 0
d = int(N)
for i in range(int(N)-1):
    if a[i] == "#":
        c += 1
        d -= 1
if a[int(N)-1] == "#":
    d -= 1
print(min(c,d))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
#" . #
#  b=black#
#  w=white.
f=[0,1][s[0]=="#"]
b=[0]
w=[0]
for i in s:
    if f==1 and i=="#":
        b[-1]+=1
    elif f==1 and i==".":
        f=0
        if w[-1]!=0: w.append(1)
        else: w[-1]=1
    elif f==0 and i==".":
        w[-1]+=1
    elif f==0 and i=="#":
        f=1
        if b[-1]!=0: b.append(1)
        else: b[-1]=1
x=sum(b)
y=sum(w)
if s[-1]=="#": x-=b[-1]
if s[0]==".": y-=w[0]

ans=min(x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
d = [0]*n
p = [0]*n
for i in range(n):
    if i > 0:
        d[i] = d[i-1]
    if s[i] != '.':
        d[i] += 1
for i in range(n-1, -1, -1):
    if i < (n-1):
        p[i] = p[i+1]
    if s[i] != '#':
        p[i] += 1

d = [0]+d
p = p+[0]
ans = 2**32
for i in range(n):
    t = d[i]+p[i]
    if t < ans:
        ans = t
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 10**7
for i in range(n):
    kuro = s[:i].count("#")
    siro = s[i:].count(".")
    if kuro+siro < ans:
        ans = kuro+siro

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
first_B = S.find('#') #最初の黒より前の白を消去するため
if first_B == -1: #黒がない=全部白-->回数0
    answer = 0
else:
    S = S[first_B:] #最初の白の部分を全部消去
    rev_S = S[::-1] #反転
#    print (rev_S, 'rev_S')
#    print(S)
    last_W = rev_S.find('.') #(反転後で)最初の白より前の黒を消去するため
    S = rev_S[last_W:] #最初の黒の部分を全部消去
    S = S[::-1] #反転
#    print (S)
    n_W = S.count('.')
    n_B = S.count('#')
    if n_W > n_B:
        answer = n_B
    else:
        answer = n_W
print (answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
s_o=input()
s_dot=[len(x) for x in s_o.replace("#"," ").split()]
s_sharp=[len(x) for x in s_o.replace("."," ").split()]
if s_o[0]==".":
  s_dot=s_dot[1:]
if s_o[-1]=="#":
  s_sharp=s_sharp[:-1]
if len(s_dot)==0 or len(s_sharp)==0:
  print(0)
  exit()
sum_sharp=[0]*len(s_sharp)
sum_dot=[0]*len(s_dot)
for i in range(len(sum_sharp)):
  if i==0:
    sum_sharp[i]=s_sharp[i]
  else:
    sum_sharp[i]=sum_sharp[i-1]+s_sharp[i]

for i in reversed(range(len(sum_dot))):
  if i==len(sum_dot)-1:
    sum_dot[i]=s_dot[i]
  else:
    sum_dot[i]=sum_dot[i+1]+s_dot[i]
ans=[1000000]*len(sum_sharp)
for i in range(len(sum_sharp)):
  ans[i]=sum_sharp[i]+sum_dot[-i-1]-max(sum_sharp[i],sum_dot[-i-1])
print(min(ans))

Submission status: Wrong Answer

Solution code:
import string

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

borders = []
count = 0
while s[count:]:
	if s.find('.#', count) != -1:
		borders.append(s.find('.#', count) + 1)
		count = s.find('.#', count) + 1
	else:
		break

numbers = []
for b in borders:
	if s[b:].count('.') is not None:
		numbers.append(s[b+2:].count('.') + s[:b-1].count('#'))
# print(left_black)
# print(right_white)
# print(s[left_black+1:])
# print(s[:right_white])
# print(s[left_black+1:].count('.'))
# print(s[:right_white].count('#'))
# print(borders)
# print(numbers)

if not numbers:
	print(0)
else:
	print(min(numbers))

Submission status: Wrong Answer

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

lsts=list(s)

ans=0


for i in range(n-1):
    if lsts[i]=="#" and lsts[i+1]==".":
            ans+=1
            lsts[i+1]=="#"

p=s.count("#")
q=s.count(".")


print(ans)

Submission status: Wrong Answer

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

# . : white
# # : black

# no '#.' sequence
# All '......'  Start of black is (length + 1)
# All '######'  Start of black is (0)
# ONLY '...###' Start of black is (?)

# a list of tuples of (start,end) for each color
white, black = [], []
nwhite, nblack = 0, 0

i, end = 0, 0
while(i<L):
    while(end<L):
        if S[i] == S[end]:
            end += 1
        else:
            break

    if S[i] == '.':
        white.append((i,end))
        nwhite += end-i
    else:
        black.append((i,end))
        nblack += end-i

    i = end

if nwhite == 0 or nblack == 0:
    print(0)

else:
    ans = 2 * (10 ** 5) + 1
    # set a index that starts sequence of black(#)
    for i, (candidate, curend) in enumerate(black):

        curans = 0

        # then turn over all black(#) left to it
        for (s,e) in black[:i]:
            curans = curans + e -s

        # then turn over all white(.) right to it    
        for (s,e) in white:
            if s > candidate:
                curans = curans + e -s 

        ans = min(ans, curans)

    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
S = S.replace('.','0').replace('#','1')

i = 0
y = 0
for x in range(N):
    if i^int(S[x]) == 1:
        y += 1

j = 1
n = 0
for m in range(N):
    if j^int(S[m]) == 1:
        n += 1

print(min(y, n))

Submission status: Wrong Answer

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

left = stones.find("#")

if left == -1:
    print(0)
else:
    print(stones[left:].count("."))

Submission status: Wrong Answer

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

input = sys.stdin.readline
N = int(input())
S = input().strip()
a = 0

if S.count('#') >= S.count('.'):
    a += (S.count('.'))
    if len(S) > 1:
        if S[-2] == '.' and S[-1] == '#':
            a -= 1
else:
    a += (S.count('#'))

print(a)

Submission status: Wrong Answer

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


def func(input_s):
    count = input_s.count(".")
    for c, i in enumerate(s):
        if c == "." and i != 0 and input_s[i - 1] == "#":
            tmp_str = input_s
            tmp_str[i - 1] = "."
            tmp_count = func(tmp_str)
            count = min(tmp_count + 1, count)
    return count


pre = ""
print(func(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == '.':
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
tw = 0
tb = 0
A = 0
for i in range(N):
    if c == 0 and S[i] == '#':
        if cw[N - 1] - cw[i] >= cb[N - 1] - cb[i] + 1:
            a += 1
        else:
            A = cw[N - 1] - cw[i]
            c = 1
            tb += 1
    elif c == 1 and S[i] == '#':
        tb += 1
    elif c == 1 or c == 2 and S[i] == '.':
        c = 2
        tw += 1
    elif c == 2:
        tb += 1
        if tb > tw:
            a += A
            print(a)
            exit()
        else:
            c = 0
            a += tb
            tw = 0
            tb = 0
            A = 0
print(a + tw)

Submission status: Wrong Answer

Solution code:
#改行入力
N = int(input())
S = input()

count = 0


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

            print(S[i])
            print(i)

            if i == 0:
                S = "." + S[i+1:]
            elif i == len(S) - 2:
                S = S[:i+1] + '#'

            elif S[i-1] == "#":
                S = S[:i+1] + '#' + S[i+2:]
            elif S[i-1] == ".":
                S = S[:i] + "." + S[i+1:]

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
change_list = []
change_list.append(0)
result1 = 0
result2 = 0
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:
		result3=result2-(change_list[-3]-change_list[-4])+change_list[-1]-change_list[-2]
		print(min(result1,result2,result3))
	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:
		result3=result2-(change_list[-3]-change_list[-4])+change_list[-1]-change_list[-2]
		print(min(result1+start,result2+start,result3+start,S.count('.')))
	else:
		print(min(result1+start,result2+start,S.count('.')))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
S = input()
s_list = list(S)
temp_start = temp_end = N+1
count_1 = 0
count_2 = 0
for i in range(N-1):
    if s_list[i] == "#" and s_list[i+1] == ".":
        temp_start = i
        break
if temp_start == N+1:
    print(0)
    sys.exit()
for i in range(N)[::-1]:
    if s_list[i] != "#":
        temp_end = i
        break
if temp_end == N+1:
    temp_end = N-1
for i in range(temp_start,temp_end + 1):
    if s_list[i] == "#":
        count_1 += 1
    else :
        count_2 += 1
print(min(count_1,count_2))

Submission status: Wrong Answer

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

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

if a < 0:
    print('0')

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cmp1,cmp2,cmp3,cmp4 = 0,0,0,0

if s.count('.') == n:
    print('0')
else:
    cmp1 = s[s.index('#'):].count('.')
    reverse_s = s[::-1]
    cmp2 = reverse_s[reverse_s.index('#')+1:].count('#') + reverse_s[:reverse_s.index('#')].count('.')
    cmp3 = reverse_s[reverse_s.index('#'):].count('#')
    cmp4 = reverse_s[reverse_s.index('#')+1:].count('#')
    print(min(cmp1,cmp2,cmp3,cmp4))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	S = input()
	S = S[:-1]

	ans = 0
	counts = 0
	flg = False
	for i in S:
		if i == "#" and flg == False:
			flg = True
			counts += 1
			continue
		if flg == True and i == ".":
			ans += 1
		if i == "#":
			counts += 1
		
	bksp = S.split(".")
	bksp = bksp[-1]

	counts -= len(bksp)


	print(min(ans, counts))

	

	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cnt = [0,0] #[# .]
i=0

while(i<n and s[i] == "."):
	i+=1
for j in range(i,n):
	cnt[s[j] == "."] += 1
print(min(cnt))

Submission status: Wrong Answer

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

a = 0
b = 0

x = 0
y = 0

while x == 0 and y<N:
  if S[y] =='.':
    y += 1
  else:
    x = 1

if y+1 == N:
  print(0)
else:
  for i in range(y, N):
    if S[i] == '.':
      a += 1
    else:
      b += 1
  print(min(a, b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
t = list(s)
a = 0
b = 0
for i in range(s.find("#"), n):
    if t[i]==".":
        a=a+1
for j in range(0, s.rfind(".")+1):
    if t[j]=="#":
        b=b+1     
print(min(a,b))

Submission status: Wrong Answer

Solution code:
num = int(input())
stone = list(input())

count = 0
# 多分、これだと最小値ではない
# for i in range(num - 1):
#     if stone[i] == "#" and stone[i + 1] == ".":
#         if i == 0:
#             stone[i] = "."
#         else:
#             stone[i + 1] = "#"
#         count += 1

for i in range(num - 1):
    if stone[i] == "#" and stone[i + 1] == ".":
        if i == 0 or stone[i - 1] == ".":
            stone[i] = "."
        else:
            stone[i + 1] = "#"
        count += 1
print(count, "".join(stone))
print(count)

Submission status: Wrong Answer

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

#.#






tmp = 0
ans2 = 0

for s in S:
    if s == "#":
        tmp += 1
    else:
        ans2 += tmp
        tmp = 0

S = S[::-1]

tmp = 0
ans1 = 0

for s in S:
    if s == ".":
        tmp += 1
    else:
        ans1 += tmp
        tmp = 0


print (min(ans1,ans2))

Submission status: Wrong Answer

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

si=[]
k=[]
count = 0
flag = 0
for i in range(0,n):
    if flag == 0:
        if s[i] == '.':
            count += 1
            if i == n-1:
                si.append(count)
        else:
            si.append(count)
            count = 1
            flag = 1
            if i == n-1:
                k.append(count)
    else:
        if s[i] == '#':
            count += 1
            if i == n-1:
                k.append(count)
        else:
            k.append(count)
            count = 1
            flag = 0
            if i == n-1:
                si.append(count)

if len(si)>0:
    sa=si[0]
else:
    sa=0
if len(k)>0:
    ka=k[-1]
else: ka = 0

smax = sum(si) - sa - ka

kmax = sum(k) - ka - sa

ans = min(smax,kmax)
print(ans)

Submission status: Wrong Answer

Solution code:
def main(word):
    strs = list(word)

    count = 0
    iRegular = False
    for i, _ in enumerate(strs):
        if i == 0:
            continue
        if strs[i-1] == "#" and strs[i] == ".":
            count += 1
            continue

        if i < 2:
            continue
        if iRegular and strs == ".":
            count += 1
            continue
        else:
            iRegular = False
        if strs[i-2] == "#" and strs[i-1] == "." and strs[i] == ".":
            iRegular = True
            count += 1

    return count


if __name__ == "__main__":
    input()
    word = input()
    print(main(word))

Submission status: Wrong Answer

Solution code:
def minToggle(arr, n): 
  
    zero =[0 for i in range(n + 1+1)] 
    zero[0] = 0
   
    # Fill entries in zero[] 
    # such that zero[i] 
    # stores count of zeroes 
    # to the left of i 
    # (exl 
    for i in range(1, n + 1): 
      
        # If zero found 
        # update zero[] array 
        if (arr[i-1] == 0): 
            zero[i] = zero[i-1] + 1
        else: 
            zero[i] = zero[i-1] 
   
    # Finding the minimum 
    # toggle required from 
    # every index(0 to n-1) 
    ans = n 
    for i in range(1, n + 1): 
        ans = min(ans, i - zero[i] + zero[n] - zero[i]) 
   
    return ans 
      
# Driver Program 
n=int(input())
s=input().rstrip()
arr=[]
for i in s:
    if i=='.':
        arr.append(0)
    else:
        arr.append(1)
n = len(arr) 
  
print(minToggle(arr, n)) 
  
# This code is contributed 
# by Anant Agarwal.

Submission status: Wrong Answer

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

score1 = 0
score2 = 0
length = 1
check = S[0]
A = []
flag = 0

for i in range(N-1):
    if S[i] == S[i+1]:
        length += 1
    else:
        A.append(length)
        length = 1

if length != 1:
    A.append(length)

if len(A) != 0:
    if S[-1] != S[-2]:
        A.append(1)

if len(A) == 0:
    A.append(0)

if S[0] == ".":
    A.pop(0)
    flag = 1

if S[len(S)-1] == "#":
    A.pop(-1)
    flag = 1


for i in range(len(A)):
    if i % 2 == 0:
        score1 += A[i]
    else:
        score2 += A[i]

ans = min(score1,score2)

if flag == 0:
    ans = min(ans, A[0] + A[-1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
r = N - 1
l = 0
while 0<= r and S[r] == "#":
    r -= 1
while l < N and S[l] == ".":
    l += 1
cnt = Counter(S[l:r+1])
print(min(cnt["."], cnt["#"]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
li = []
for i in range(n):
    if s[i] == "#":
        li.append(i)
li.append(len(s))
sum = 0
if len(li) == 1:
    print(0)
else:
    for i in range(len(li)-1):
        sum += li[i+1] - li[i] - 1
    if sum > len(li) -2:
    	print(len(li) -2)
    else:
    	print(sum)

Submission status: Wrong Answer

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