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

m1=0
m2=0

for i in range(n):
  if s[i] == '#':
    m1+=1
  if s[i] == '.':
    m2+=1

m3=0
a=0
for i in range(n):
  if n-i-1 == a:
    break
  if s[n-i-1] == '.':
    flag=0
    for j in range(a,n):
      if j == n-i-1:
        flag=1
        break
      if s[j] == '#':
        m3+=2
        a=j+1
        flag=1
        break
    if flag == 0:
      break

print(min(m1,m2,m3))

Submission status: Wrong Answer

Solution code:
import math
import re
n = int(raw_input())
s = raw_input()

prev = ''
ar = []
for i in s:
    if prev == '' or prev[0] == i:
        prev += i
    else:
        ar.append(prev)
        prev = i

ar.append(prev)

cnt = 0
if ar[-1].count('#') > 0:
    ar.pop(-1)
while True:
    if len(ar) < 2:
        break
    last = ar[-1]
    last2 = ar[-2]
    if len(last2) >= len(last):
        cnt += len(last)
        ar.pop(-1)
        ar.pop(-1)
    else:
        break

new_s = ''.join(ar)

a = new_s.count('#')
b = new_s.count('.')

cnt += min(a,b)
print cnt

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
a=0
for i in range(1,n):
    if s[i-1]=='#'and s[i]=='.':
        j=i
        k=i-1
        while j+1<n and s[j+1]=='.':j+=1
        while k>0and s[k-1]=='#':k-=1
        if j-i+1<i-k:
            a+=j-i+1
            s[j]='#'
        else:
            a+=i-k
            s[k]='.'
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
s =  input()
 
if len(set(s)) == 1:
  print(0)
else :
  idx1 = s.find('#')
 
  idx2 = s.rfind('.')
  print(min(s[idx1:].count('.'), s[:idx2+1].count('#')))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
a=0
try:
    c=S.index("#")
    b=S.index(".")
    print(min(S[c:].count("."),S[:b+1].count("#")))
except:
    print(0)

Submission status: Wrong Answer

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

    black_count = 0

    for stone in s:
        if stone == "#":
            black_count += 1

        else:
            break

    black = n - black_count - "".join(s).count(".")

    white = n - "".join(s).count(".")

    print(min(black, white))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

dot = True
sharp = True
count_dot = 0
# ....####にする場合
for i in range(n):
    if sharp and s[i] == ".":
        sharp = False
    if dot and s[i] == ".":
        continue
    elif sharp and s[i] == "#":
        count_dot += 1
        continue
    else:
        dot = False
        if s[i] == ".":
            count_dot += 1

# ########にする場合
black_count = 0
for i in range(n):
    if s[i] == "#":
        black_count += 1

# .......にする場合
white_count = 0
for i in range(n):
    if s[i] == ".":
        white_count += 1
    
print(min(count_dot, black_count, white_count))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
if all(S)=="#" or all(S)==".":
    print(0)
    exit
else:
    pass
for i in reversed(range(N)):
    if S[i]==".":
        if i==0:
            break
        else:
            for j in range(1,i+1):
                if S[i-j]=="#":
                    count+=1
                else:
                    break
    else:
        pass
        
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S =(list(input()))
newS=[]
for i in S:
    if i == ".":
        newS.append(0)
    else:
        newS.append(1)

totalblack=0
for i in newS:
    totalblack = totalblack+i
    
before = 0
count = 0
finalS =[]
for i in newS:
    flag = i - before
    if flag < 0:
        finalS.append(1)
        count = count +1
        before = 1
    else:
        finalS.append(i)
        before = i
        
before = 0
flag=0
x=0
for i in reversed(newS):
    if flag==0:
      x=x+i
      if i == 0:
        flag=1
count = min(count, totalblack-x)
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
a=0
try:
    c=S.index("#")
    b=S.index(".")
    print(min(S[c:].count("."),S.count("#"),S[:b+1].count("#"),S.count(".")))
except:
    print(0)

Submission status: Wrong Answer

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

white = 0
black = 0

black_first = n-1
white_last = 0

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

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

l = [0]
for i in range(black_first, white_last):
    if i == black_first:
        l[0]+=1
        continue
    if s[i] == s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

bw = float('inf')

for i in range(len(l)//2+1):
    bw = min(bw, sum(l[:2*i+1:2])+sum(l[2*i+1::2]))


print(bw)

Submission status: Wrong Answer

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

    black_count = 0

    for stone in s:
        if stone == "#":
            black_count += 1

        else:
            break

    black = n - black_count - "".join(s).count(".")

    white_count = 0

    for stone in s:
        if stone == ".":
            black_count += 1

        else:
            break

    white = n - white_count - "".join(s).count(".")

    print(min(black, white))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
if all(S)=="#" or all(S)==".":
    print(0)
    exit
else:
    pass
for i in reversed(range(N)):
    if S[i]==".":
        if i==0:
            break
        else:
            for j in range(1,i):
                if S[i-j]=="#":
                    count+=1
                else:
                    break
    else:
        pass
        
print(count)

Submission status: Wrong Answer

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

#白と黒の情報を文字列抽出してリスト化(最初は必ず白.)
A = []
last = S[0]
count = 1
for i in range(1,N):
    if last == S[i]:
        count += 1
    else:
        A.append(count)
        last = S[i]
        count = 1
A.append(count)

if len(A) == 1:
    print(0)
    exit()

if S[0] == '#':
    A.insert(0,0)


Wlist = [A[i] for i in range(len(A)) if i%2 == 0]
Blist = [A[i] for i in range(len(A)) if i%2 == 1]

SumBlist = [0,Blist[0]]
for i in range(1,len(Blist)):
    SumBlist.append(SumBlist[i-1]+Blist[i])

SumWlist = [sum(Wlist),sum(Wlist)]
for i in range(1,len(Wlist)):
    SumWlist.append(SumWlist[i-1]-Wlist[i])

if len(SumWlist) != len(SumBlist):
    SumBlist.append(0)

# print(SumBlist)

#偶数indexは黒(黒の開始位置を固定するとその前後の入れ替わりが確定)

c = sum(Wlist)
for i in range(1,len(A)):
    index = int(i/2)
    # print(index)
    # print(SumBlist[index-1])
    count = SumBlist[index-1] + SumWlist[index]
    if count < c:
        c = count

print(c)

Submission status: Wrong Answer

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

count = 0

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

if count == 0:
    print(count)
else:
    print(count - 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
d = S.count(".")
s = S.count("#")
m = False
if s == 1 and S[N - 1] == "#":
    l = 0
else:
    if s < d:
        l = s
    elif d < s:
        if S[0] == ".":
            l = d - 1
        else:
            l = d
    else:
        if S[0] == ".":
            for i in range(d):
                if S[i] != ".":
                    l = d - 1
                    break
                else:
                    l = 0

        else:
            l = s
    if l < 0:
        l = 0
print(l)

Submission status: Wrong Answer

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

S.reverse()

black = 0
white = 0
white_right = 0
f = 0
r = 0
l = 0
for i in range(N):
    if S[i] == '.':
        f = 1
    if f == 1:
        if S[i] == '#':
            black += 1
            r = 1
            l = 1
        elif S[i] == '.':
            white += 1
        elif r == 0 and S[i] == '.':
            white_right += 1

    
    
if l == 0:
    ans = [black, white, white_right]
    ans.sort()

    print(ans[0])
else:
    print(min(black,white))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
a=0
for i in range(1,n):
    if s[i-1]=='#'and s[i]=='.':
        j=i
        k=i-1
        while j+1<n and s[j+1]=='.':j+=1
        while k>0and s[k-1]=='#':k-=1
        if j-i+1<=i-k:
            a+=j-i+1
            s[j]='#'
        else:
            a+=i-k
            s[k]='.'
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = []
for i in range(n):
    if s[i] == '#':
        b.append(i)
if len(b) == 0:
    print(0)
else:
    ans = min(s[b[0]::].count('.'), s.count('#'))
    nb = len(b)
    for i in range(1,len(b)-1):
        ans = min(ans, n-b[i]-nb+i+1)
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
try:
    c=S.index("#")
    print(min(S[c:].count("."),S.count("#")))
except:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sum = 0
ss = 0
    
while True:
#     print(s, sum)
    a = s.find('#')
    if a==-1:
        break
    s = s[a:]
    
    a = s.find('.')
    if a == -1:
        break
    if a == 0:
        ss += 0
        pass
    else:
        s = s[a-1:]
        ss += a-1
    
#     print(s, sum)
    x = s.find('.')
    y = s[x:].find('#')
    if y == -1:
        if x >= 0:
            sum += len(s) - x
        break
    if x == -1:
        break
    if x + ss>y:
        s = s[:x] + '#' * y + s[x+y:]
        sum += y
    else:
        s = '.' * x + s[x:]
        sum += x + ss
        ss = 0

print(sum)

Submission status: Wrong Answer

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

    count = 0

    for stone in s:
        if stone == "#":
            count += 1

        else:
            break

    print(n - count - "".join(s).count("."))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
if all(S)=="#" or all(S)==".":
    print(0)
    exit
else:
    pass
for i in reversed(range(N)):
    if S[i]=="#":
        pass
    else:
        for j in range(1,i):
            if S[i-j]=="#":
                count+=1
            else:
                break
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ss = input()
flag = True
ans =  0
for s in ss:
    if flag:
        if s == '#':
            flag = False
    else:
        if s == '.':
            ans += 1
print(ans)

Submission status: Wrong Answer

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

delete_S = S
count = 0
for i in range(len(S)):
    if S[::-1][i] == "#":
        delete_S = S[:len(S) - i]
    else:
        break

if len(delete_S) == 0:
    print(count)
    exit

white = delete_S.count("#")
black = delete_S.count(".")
print(min(white, black))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
cnt = 0
in_w = 0
in_b = 0

for i in range(N):
    if s[i] == '#':
        in_w = i
        break

for i in range(N)[::-1]:
    if s[i] == '.':
        in_b = i
        break

cnt1 = 0
cnt2 = 0
for i in range(in_w,in_b+1):
    if s[i] == '#':
        cnt1 += 1
    else:
        cnt2 += 1
print(min(cnt1,cnt2))

Submission status: Wrong Answer

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

def trim(n, s):
    i = 0
    while i < n and s[i] == '.':
        i += 1
    start = i

    i = n
    while i > 0 and s[i - 1] == '#':
        i -= 1
    end = i

    return s[start:end]


def f(n, s):
    bs = 0
    ws = 0

    for c in s:
        if c == '#':
            bs += 1
        else:
            ws += 1
    return min(ws, bs)


def g(n, s):
    bs = 0
    ws = 0
    i = 0
    while i < len(s):
        if s[i] == '#':
            bs += 1
        else:
            break
        i += 1

    i = len(s)
    while i > 0:
        if s[i - 1] == '.':
            ws += 1
        else:
            break
        i -= 1

    return bs, ws

def h(n, s):
    s = trim(n, s)
    a = f(len(s), s)

    bs, ws = g(len(s), s)
    s = s[bs:len(s) - ws]
    s = trim(len(s), s)
    b = f(len(s), s) + bs + ws
    return min(a, b)


print(h(n, s))

Submission status: Wrong Answer

Solution code:
read = input
n = int(read())
s = read()
SW = [0 for i in range(n)]
SB = [0 for i in range(n)]
for i,c in enumerate(s):
    if i == 0:
        SW[i] = 1 if c == '.' else 0
        SB[i] = 1 if c == '#' else 0
    else :
        SW[i] = SW[i-1] + 1 if c == '.' else SW[i-1]
        SB[i] = SB[i-1] + 1 if c == '#' else SB[i-1]
cost = n
for i in range(n):
    pass
#     print(i, SW[i], SB[i])
for i in range(n + 1):
    startW = 0
    endW = i # left W is [0,i)
    startB = i 
    endB = n # right B is [i, n)
#     print(i)
    if i == 0: # all B 
        cost = min(cost, n - SW[n-1])
    elif i == n: # all W
        cost = min(cost, n - SB[n-1])
    else:
        cost = min(cost, 
                   i - SB[i-1] + (n-i) - (SW[n-1] - SW[i-1])
                  )
print(cost)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
for i in reversed(range(N)):
    if S[i]=="#":
        pass
    else:
        for j in range(1,i):
            if S[i-j]=="#":
                count+=1
            else:
                break
print(count)

Submission status: Wrong Answer

Solution code:
input()
l = input()
if not '#.' in l:
    print(0)
else:
    s = l.count('#')
    d = l.count('.')

    for c in l:
        if c == '.':
            d-=1
        else:
            break
    for c in l[::-1]:
        if c == '#':
            s-=1
        else:
            break

    print(min(s,d))

Submission status: Wrong Answer

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

count = 0
b_count = 0
b_continue_con = 0
already = False
for i in s:
    if already:
        if i == '.':
            count += 1
            b_continue_con = 0
        else:
            b_count +=1
            b_continue_con +=1
    else:
        if i == '#':
            already = True
            b_count += 1

b_count = b_count - b_continue_con
if (b_count < count):
    print(b_count)
else:
    print(count)

Submission status: Wrong Answer

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

def trim(n, s):
    i = 0
    while i < n and s[i] == '.':
        i += 1
    start = i

    i = n
    while i > 0 and s[i - 1] == '#':
        i -= 1
    end = i

    return s[start:end]


def f(n, s):
    bs = 0
    ws = 0

    for c in s:
        if c == '#':
            bs += 1
        else:
            ws += 1
    return min(ws, bs)


def g(n, s):
    bs = 0
    ws = 0
    i = 0
    while i < len(s):
        if s[i] == '#':
            bs += 1
        else:
            break
        i += 1

    i = len(s)
    while i > 0:
        if s[i - 1] == '.':
            ws += 1
        else:
            break
        i -= 1

    return bs, ws

def h(n, s):
    s = trim(n, s)
    a = f(len(s), s)

    bs, ws = g(len(s), s)
    s = s[bs:len(s) - ws]
    b = f(len(s), s)
    return min(a, b)


print(h(n, s))

Submission status: Wrong Answer

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

flag = False
k = 0
sb = 0
sa = 0 
for i in range(int(l)):
    if S[i] == "#":
        flag=True
        k += 1
    elif flag :
        sa += 1
    else:
        sb +=1


if k == 0:
    print(0)
elif sa == 0:
    print(min(sb, k))
elif  sb == 0:
    print (min(sa,k))
else:
    print (min(sa,k))

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    s = list(input())
 
    white = 0
    black = 0
    color = s[-1]
    counter = 0
    is_black = '#' == s[-1]
    for i in range(n)[::-1]:
        if color != s[i]:
            if color == '.':
                white += counter
            else:
                if is_black is True:
                    counter = 0
                    is_black = False
                black += counter
            counter = 0
        counter += 1
        color = s[i]
 
    if color == '#':
        black += counter
 
    if white < black:
        print(white)
    else:
        print(black)
 
 
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
read = input
n = int(read())
s = read()
SW = [0 for i in range(n)]
SB = [0 for i in range(n)]
for i,c in enumerate(s):
    if i == 0:
        SW[i] = 1 if c == '.' else 0
        SB[i] = 1 if c == '#' else 0
    else :
        SW[i] = SW[i-1] + 1 if c == '.' else SW[i-1]
        SB[i] = SB[i-1] + 1 if c == '#' else SB[i-1]
cost = n
for i in range(n):
    pass
#     print(i, SW[i], SB[i])
for i in range(n + 1):
    startW = 0
    endW = i # left W is [0,i)
    startB = i 
    endB = n # right B is [i, n)
#     print(i)
    if i == 0: # all B 
        cost = min(cost, n - SW[n-1])
    elif i == n: # all W
        cost = min(cost, n - SB[n-1])
    else:
        cost = min(cost, 
                   i - SB[i-1] + (n-i) - (SB[n-1] - SB[i-1])
                  )
print(cost)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
for i in range(N):
    if S[i]=="#":
        pass
    else:
        for j in range(1,N-i):
            if S[i+j]=="#":
                count+=1
            else:
                break
print(count)

Submission status: Wrong Answer

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

    buff = "x"

    count = 0

    for stone in s:
        if buff == "#" and stone == ".":
            count += 1

        else:
            buff = stone

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy
from collections import Counter

def calc(N):
    N = N.replace('#','1')
    N = N.replace('.','0')
    nN = ''.join(sorted(N))
    print(nN)
    cnt = Counter(str(bin(int(N,2)^int(nN,2))).replace('0b',''))
    if '1' in cnt:
        return cnt['1']
    else:
        return 0

if __name__ == '__main__':
    N = input()
    S = input()
    print(calc(S)//2)

Submission status: Wrong Answer

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

    buff = s[0]

    count = 0

    for stone in s:
        if buff == "#" and stone == ".":
            count += 1

        else:
            buff = stone

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

dot = True
count_dot = 0
# ....####にする場合
for i in range(n):
    if dot and s[i] == ".":
        continue
    else:
        dot = False
        if s[i] == ".":
            count_dot += 1
# ########にする場合
black_count = 0
for i in range(n):
    if s[i] == "#":
        black_count += 1

# .......にする場合
white_count = 0
for i in range(n):
    if s[i] == ".":
        white_count += 1
    
print(min(count_dot, black_count, white_count))

Submission status: Wrong Answer

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

a= S.count('.')
b = S.count('#')
if a >= b:
    print(b)
else:
    print(a)

Submission status: Wrong Answer

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

black = False
white = False
counter = 0
s = s.rstrip('#')
s = s.lstrip('.')

if len(set(s)) <= 1:
    print(0)
    exit(0)
# print(s)
black = 0
white = 0
for item in s:
    if item == '#':
        black += 1
    else:
        white += 1
# print(white, black)
print(min(white, black))

Submission status: Wrong Answer

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

    buff = "."

    count = 0

    for stone in s[:n]:
        if buff == "#" and stone == ".":
            count += 1

        else:
            buff = stone

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

m1=0
m2=0

for i in range(n):
  if s[i] == '#':
    m1+=1
  if s[i] == '.':
    m2+=1

d=n
m3=0
for i in range(n):
  if i > d:
    break
  if s[i] == '#':
    for j in reversed(range(i,d)):
      if s[j] == '.':
        d=j
        m3+=2
        break

print(min(m1,m2,m3))

Submission status: Wrong Answer

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

ans = float("inf")
ans = min(ans,s.count("#"))
ans = min(ans,s.count("."))

black = s.count("#.")
count = 0
for i in range(n-1):
  if s[i] == "#":
    count += 1
  
  if str(s[i:i+2]) == "#.":
    black -= 1
    
    if black == 0:
      ans = min(ans,count)

  # ans = min(ans,)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
d = S.count(".")
s = S.count("#")
if s < d:
    if S[0] == ".":
        l = s - 1
    else:
        l = s
elif d < s:
    if S[0] == ".":
        l = d - 1
    else:
        l = d
else:
    if S[0] == ".":
        l = d - 1
    else:
        l = s
if l < 0:
    l = 0
print(l)

Submission status: Wrong Answer

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

c = s.count('.')
if n == c:
  print(n)
elif n>c: 
  print(c)
elif n<c:
  print(n)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
try:
    c=S.index("#")
    print(S[c:].count("."))
except:
    print(0)

Submission status: Wrong Answer

Solution code:
input()
st = input()
state = st[0]
lis = []
problem = 0
cnt = 0
for s in st:
    if s == state:
        cnt += 1
    else:
        problem += (state == '#') and (s == '.')
        state = s
        lis.append(cnt)
        cnt = 1
lis.append(cnt)

if problem:
    # #->.
    first = (st[0] == '.')
    if st[-1] == '#':
        res1 = sum(lis[first:-1][::2])
    else:
        res1 = sum(lis[first:][::2])
    # .->#
    first = 2
    if st[0] == '#':
        first = 1
    res2 = sum(lis[first:][::2])
else:
    res1, res2 = 0, 0

print(min(res1, res2))

Submission status: Wrong Answer

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

c = s.count('.')
if n == c:
  print(n)
elif n>c: 
  print(s)
elif n<c:
  print(n)

Submission status: Wrong Answer

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

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

for i in range(len(s) // 2):
        s[i],s[-1-i] = s[-1-i],s[i]


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


print(min(cnt,cnt2))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
a=0
for i in range(1,n):
    if s[i-1]=='#'and s[i]=='.':
        j=i
        k=i-1
        while j+1<n and s[j+1]=='.':j+=1
        while k>0and s[k-1]=='#':k-=1
        a+=min(j-i+1,i-k)
print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
cnt = 0
in_w = 0
in_b = 0

for i in range(N):
    if s[i] == '#':
        in_w = i -1
        break

for i in range(N)[::-1]:
    if s[i] == '.':
        in_b = i
        break

cnt1 = 0
cnt2 = 0
for i in range(in_w+1,in_b+1):
    if s[i] == '#':
        cnt1 += 1
    else:
        cnt2 += 1
print(cnt2)

Submission status: Wrong Answer

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

    buff = "."

    count = 0

    for stone in s[:n]:
        if buff == "#" and stone == ".":
            count += 1

        else:
            buff = stone

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

print(S)
print(BCS)
ans = N
for i in range(len(BCS)):
    wh_to_bk = i - BCS[i]
    bk_to_wh = BCS[-1] - BCS[i]
    print(wh_to_bk , bk_to_wh)
    ans = min(ans, wh_to_bk + bk_to_wh)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
cnt = 0
in_w = 0
in_b = 0

for i in range(N):
    if s[i] == '#':
        in_w = i -1
        break

for i in range(N)[::-1]:
    if s[i] == '.':
        in_b = i
        break

cnt1 = 0
cnt2 = 0
for i in range(in_w+1,in_b+1):
    if s[i] == '#':
        cnt1 += 1
    else:
        cnt2 += 1
print(cnt1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ctb=0;ctw=0;f=0;cte=0;cts=0;ct=0
lb=[];lw=[];l=[];L=[]
for j in range(n-1):
  if s[j]=='#' and s[j+1]=='.':
    f=+1
for k in range(n-1,-1,-1):
  if s[k]=='#':
    cte+=1
  else:
    break
for l in range(n):
  if s[l]=='.':
    cts+=1
  else:
    break

for i in range(cts,n-cte):
  if ctb==0 and s[i]=='.':
    ctw+=1
  if ctw==0 and s[i]=='#':
    ctb+=1
  if ctb!=0 and s[i]=='.':
    ctw+=1
  if ctw!=0 and s[i]=='#':
    lb.append(ctb)
    lw.append(ctw)
    ctb=1
    ctw=0
lb.append(ctb)
lw.append(ctw)
lw.reverse()
l=lb+lw
x=sum(l[0:len(lb)])
L.append(x)
for m in range(len(lb),len(l)):
  x+=l[m]
  x-=l[m-len(lb)]
  L.append(x)
if f==0:
  print(0)
else:
  print(min(L))

Submission status: Wrong Answer

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

def trim(n, s):
    i = 0
    while i < n and s[i] == '.':
        i += 1
    start = i

    i = n
    while i > 0 and s[i - 1] == '#':
        i -= 1
    end = i

    return s[start:end]


def f(n, s):
    bs = 0
    ws = 0

    for c in s:
        if c == '#':
            bs += 1
        else:
            ws += 1
    return min(ws, bs)


def g(n, s):
    bs = 0
    ws = 0
    i = 0
    while i < len(s):
        if s[i] == '#':
            bs += 1
        else:
            break
        i += 1

    i = len(s)
    while i > 0:
        if s[i - 1] == '.':
            ws += 1
        else:
            break
        i -= 1

    return bs + ws

s = trim(n, s)
print(min(f(n, s), g(n, s)))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sum = 0
while True:
#     print(s, sum)
    a = s.find('#')
    if a==-1:
        break
    s = s[a:]
#     print(s, sum)
    x = s.find('.')
    y = s[x:].find('#')
    if y == -1:
        if x >= 0:
            sum += len(s) - x
        break
    if x == -1:
        break
    if x>y:
        s = s[:x] + '#' * y + s[x+y:]
        sum += y
    else:
        s = '.' * x + s[x:]
        sum += x

print(sum)

Submission status: Wrong Answer

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

    buff = "#"

    count = 0

    for stone in s[:n]:
        if buff == "." and stone == "#":
            count += 1

        else:
            buff = stone

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

flag = False
k = 0
sb = 0
sa = 0 
for i in range(int(l)):
    if S[i] == "#":
        flag=True
        k += 1
    elif flag :
        sa += 1
    else:
        sb +=1


if k == 0:
    print(0)
elif sa == 0:
    print(min(sb, k))
elif  sb == 0:
    print (min(sa,k))
else:
    print (min(min(sa,sb),k))

Submission status: Wrong Answer

Solution code:
l = input()
if not '#.' in l:
    print(0)
else:
    s = l.count('#')
    d = l.count('.')

    for c in l:
        if c == '.':
            d-=1
        else:
            break
    for c in l[::-1]:
        if c == '#':
            s-=1
        else:
            break

    print(min(s,d))

Submission status: Wrong Answer

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

c = s.count('.')
print(n if n - c > n else c)

Submission status: Wrong Answer

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

    buff = "#"

    count = 0

    for stone in s:
        if buff == "." and stone == "#":
            count += 1

        else:
            buff = stone

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
d = S.count(".")
s = S.count("#")
if s < d:
    if S[0] == ".":
        l = s
    else:
        l = s - 1
elif d < s:
    if S[0] == ".":
        l = d - 1
    else:
        l = d
else:
    if S[0] == ".":
        l = d - 1
    else:
        l = s
print(l)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
lst = [[s[0], 1]]
for i in range(1, n):
  if s[i] == lst[-1][0]:
    lst[-1][1] += 1
  else:
    lst.append([s[i], 1])
ans = n
m = len(lst)
if m == 1:
  print(0)
else:
  for i in range(m):
    count = 0
    for j in range(i,m):
      if lst[j][0] == ".":
        count += lst[j][1]
    for j in range(i):
      if lst[j][0] == "#":
        count += lst[j][1]
    ans = min(ans, count)
  print(ans)

Submission status: Wrong Answer

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

#白と黒の情報を文字列抽出してリスト化(最初は必ず白.)
A = []
last = S[0]
count = 1
for i in range(1,N):
    if last == S[i]:
        count += 1
    else:
        A.append(count)
        last = S[i]
        count = 1
A.append(count)

if len(A) == 1:
    print(0)
    exit()

if S[0] == '#':
    A.insert(0,0)


Wlist = [A[i] for i in range(len(A)) if i%2 == 0]
Blist = [A[i] for i in range(len(A)) if i%2 == 1]

SumBlist = [Blist[0]]
for i in range(1,len(Blist)):
    SumBlist.append(SumBlist[i-1]+Blist[i])

SumWlist = [sum(Wlist)]
for i in range(1,len(Wlist)):
    SumWlist.append(SumWlist[i-1]-Wlist[i])

if len(SumWlist) != len(SumBlist):
    SumBlist.append(0)

#偶数indexは黒(黒の開始位置を固定するとその前後の入れ替わりが確定)

c = sum(Wlist)
for i in range(1,len(A)):
    index = int(i/2)
    # print(index)
    count = SumBlist[index-1] + SumWlist[index]
    if count < c:
        c = count

print(c)

Submission status: Wrong Answer

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

# acc = [0]
# for i in range(N):
#     s = S[i]
#     if s == ".":
#         acc.append(acc[-1] + 1)
#     else:
#         acc.append(acc[-1])
# acc.pop(0)
# print(acc)
ans = 0
T1 = S.copy()
f = False
for i in range(N):
    s = T1[i]
    if s == ".":
        continue
    else:
        if i < N - 1 and T1[i+1] == ".":
            if not f and i + 1 < N - 1 and T1[i+2] == ".":
                ans += 1
            else:
                f = True
                ans += 1

        else:
            f = True
ans2 = 0

for i in range(N):
    s = S[i]
    if s == ".":
        continue
    else:
        ans2 += 1

ans3 = 0

for i in range(N):
    s = S[i]
    if s == ".":
        ans3 += 1
    else:
        continue
print(min(ans2, ans, ans3))

Submission status: Wrong Answer

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

count = 0
b_count = 0
already = False
for i in s:
    if already:
        if i == '.':
            count += 1
    else:
        if i == '#':
            already = True
already = False
for i in reversed(s):
    if already:
        if i == '#':
            b_count += 1
    else:
        if i == '.':
            already = True



if (b_count < count):
    print(b_count)
else:
    print(count)