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

black = False
white = False
counter = 0
if len(set(s)) == 1:
    print(0)
    exit(0)

position = len(s)
for i in range(len(s)):
    if s[len(s) - i - 1] == '#':
        position = len(s) - i - 1
    else:
        break
s = s[:position]
f_pos = 0
for i in range(len(s)):
    if s[i] == '.':
        f_pos += 1
    else:
        break
s = s[f_pos:]

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:
n=int(input())
s=input()
w=[0]
b=[0]

for i in range(len(s)):
    if s[i]=='#':
        w.append(w[-1]+1)
    else:
        w.append(w[-1])
    if s[-i-1]=='.':
        b.append(b[-1]+1)
    else:
        b.append(b[-1])
print(w)
print(b)
total=[]
for i in range(len(s)+1):
    total.append(w[i]+b[-i-1])
print(total)
print(min(total))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
start = -1
whitecount = 0
blackcount = 0
for i in range(0, N):
    if S[i:i+1] == '#':
        start = i
        break

if start != -1:
    for i in range(start, N):
        if S[i:i+1] == '.':
            whitecount = whitecount + 1

start = 0
S = S[::-1]
for i in range(0, N):
    if S[i:i+1] == '.':
        start = i
        break

if start != -1:
    for i in range(start, N):
        if S[i:i+1] == '#':
            blackcount = blackcount + 1

print("{}".format(min(blackcount, whitecount)))

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:
def main():
    n = int(input())
    s = input()[::-1]

    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 =(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
count = min(count, totalblack)
print(count)

Submission status: Wrong Answer

Solution code:
import math                                                                                            
import re                                                                                              
n = int(raw_input())                                                                                   
s = raw_input()                                                                                        
                                                                                                       
prev = ''                                                                                              
cnt = 0                                                                                                
black = 0                                                                                              
white = 0                                                                                              
for i in s:                                                                                            
    if (prev == '' or prev == '.') and i == '#':                                                       
        cnt += min(black, white)                                                                       
        black = 1                                                                                      
        prev = '#'                                                                                     
        white = 0                                                                                      
    elif prev == '#' and i == '#':                                                                     
        black += 1                                                                                     
    elif prev == '#' and i == '.':                                                                     
        white = 1                                                                                      
        prev = '.'                                                                                     
    elif prev == '.' and i == '.':                                                                     
        white += 1                                                                                     
                                                                                                       
cnt += min(black, white)                                                                               
print cnt

Submission status: Wrong Answer

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

length = []
cnt = 0
now = "#"
length_sum = []
length_num = 0

ans = 0
for i in S:
  if now == i:
    cnt += 1
  else:
    if now == "#":
      now = "."
    else:
      now = "#"
    length.append(cnt)
    length_num += 1
    if length_num > 1 and length_num % 2 == 0:
        ans += min(length[length_num-2],length[-1])
    cnt = 1
else:
    length.append(cnt)
    length_num += 1
    if length_num > 1 and length_num % 2 == 0:
      ans += min(length[length_num-2],length[-1])  

if len(length) % 2 == 0:
    pass
else:
    length.append(0)

print(ans)

Submission status: Wrong Answer

Solution code:
def main(n):
	flg = False
	s = "." + input() + "#"
	ans = 0
	blk = 0
	wht = 0
	for i in range(1,n+2):
		if s[i] == "#" and s[i-1] == ".":
			flg = True
			ans += min(wht, blk)
			if wht >= blk:
				blk = 1
				wht = 0
			else:
				blk = blk + wht
		elif s[i] == "#":
			blk += 1
		elif flg and s[i] == ".":
			wht += 1
	print(ans)
main(int(input()))

Submission status: Wrong Answer

Solution code:
n = int(input())
s =  input()
 
if len(set(s)) == 1:
  print(0)
else :
  idx1 = s.find('#')
 
  idx2 = s[::-1].find('.')
  print(min(s[idx1:].count('.'),s[::-1][idx2:].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)
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
count = min(count, N-count)
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
pre=""
tmp=0
st=0
end=0
for i in S:
    end+=1
    if pre=="":
        pre=i
        if pre=="#":
            st=1
        continue
    if (i=="#" or end==N) and pre=="." and st==1:
        if tmp>1:
            ans+=tmp//2
            pre="#"
            tmp=0
            st=1
        else:
            ans+=1
            pre="#"
            tmp=0
            st=1
    elif i==".":
        tmp+=1
        pre=i
    if i=="#":
        st=1
print(ans)

Submission status: Wrong Answer

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


def calc_lefts(_l, _r):
    return S[_l:_r].count('#')


def calc_right(_l, _r):
    return S[_l:_r].count('.')


ans = 0
ll = 0
r = N
while ll != r:
    m = (r - ll) / 2
    if (r - ll) % 2 == 1 and S[m] == '.':
        m += 1
    ls = calc_lefts(ll, m)
    rs = calc_right(m, r)
    if rs == r - m:
        ans += ls
        break
    elif ls == m - ll:
        ans += rs
        break
    elif ls == rs:
        ans += ls + rs
        break
    elif ls < rs:
        ans += ls
        ll = m
    else:
        ans += rs
        r = m

print(ans)

Submission status: Wrong Answer

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

black = False
white = False
counter = 0
if len(set(s)) == 1:
    print(0)
    exit(0)

position = len(s)
for i in range(len(s)):
    if s[len(s) - i - 1] == '#':
        position = len(s) - i - 1
    else:
        break
s = s[:position]

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    s = input()
    dot = 0
    has = 0
    for c in s:
        if c == ".":
            dot += 1
        else:
            has += 1
    left_dots = 0
    left_has = 0
    right_dots = dot
    right_has = has
    ans = min(dot, has)
    for left in range(N):
        c = s[left]
        if c == ".":
            left_dots += 1
            right_dots -= 1
        else:
            left_has += 1
            right_has -= 1
        ans = min(left_has+ right_dots, ans)
    print(min(dot, has))
if __name__ == "__main__":
    main()

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(min(cnt1,cnt2))

Submission status: Wrong Answer

Solution code:
l = input()
if not '#.' in l:
    print(0)
else:
    s = l.count('#')
    d = l.count('.')
    if l[-1] =='#':
        s-=1
    print(min(s,d))

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    s=input()
    if len(set(s)) == 1:
        print(0)
        return
    s = s[s.index('#'):]
    n = len(s)
    ans = n
    b = [0] * (n+1)
    w = [0] * (n+1)
    for i in range(n):
        b[i+1] = b[i] + (1 if s[i] == '#' else 0)
        w[i+1] = w[i] + (0 if s[i] == '#' else 1)

    for i in range(n):
        tmp = (i - b[i]) + (w[n] - w[i])
        ans = min([ans, tmp])
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    s = input()
    print(solve(s))

def solve(s):
    n = len(s)

    blacks = [None for _ in range(n + 2)]
    whites = [None for _ in range(n + 2)]
    b = 0
    w = 0

    for i in range(n):
        if s[i] == '#':
            b += 1
        blacks[i + 1] = b

    for i in reversed(range(n)):
        if s[i] == '.':
            w += 1
        whites[i + 1] = w

    blacks[0] = 0
    blacks[n + 1] = blacks[n]
    whites[0] = whites[1]
    whites[n + 1] = 0

    m = float('inf')
    for i in range(n):
        m = min(m, blacks[i] + whites[i + 1])

    return m

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
lb = 10**9
for i in range(n):
    if s[i] == '#':
        lb = i
        break
if lb == 10**9:
    print(0)
else:
    print(min(s[lb::].count('.'), s.count('#')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
start = -1
whitecount = 0
blackcount = 0
for i in range(0, N):
    if S[i:1] == '#':
        start = i
        break

if start != -1:
    for i in range(start, N):
        if S[i:i+1] == '.':
            whitecount = whitecount + 1

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

if start != -1:
    for i in range(start, N):
        if S[i:i+1] == '#':
            blackcount = blackcount + 1

print("{}".format(min(blackcount, whitecount)))

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

    # print("b: {}, w: {}".format(black, white))

    if white * black == 0:
        print(0)
        return
    if white < black:
        print(white)
    else:
        print(black)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

black = False
white = False
counter = 0
if len(set(s)) == 1:
    print(0)
    exit(0)

position = len(s)
for i in range(len(s)):
    if s[len(s) - i - 1] == '#':
        position = len(s) - i - 1
    else:
        break
s = s[:position]

black = 0
white = 0
for item in s:
    if item == "#":
        black = True
        black +=1
        continue
    if black:
        if item == '#':
            black += 1
        else:
            white += 1
print(min(white, black))

Submission status: Wrong Answer

Solution code:
import re


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

    relst = re.findall(r"#*\.", s)

    stone_count = sum([rel.count("#") for rel in relst])

    print(stone_count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def calc_lefts(_l, _r):
    return S[_l:_r].count('#')


def calc_right(_l, _r):
    return S[_l:_r].count('.')


ans = 0
ll = 0
r = N
m = N / 2
while m != 0 and m != r and ll != r:
    if (r - ll) % 2 == 1 and S[m] == '.':
        m += 1
    ls = calc_lefts(ll, m)
    rs = calc_right(m, r)
    if rs == r - m:
        ans += ls
        break
    elif ls == m - ll:
        ans += rs
        break
    elif ls == rs:
        ans += ls + rs
        break
    elif ls < rs:
        ans += ls
        ll = m
        m = (r - m) / 2
    else:
        ans += rs
        r = m
        m = (m - ll) / 2

print(ans)

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

print(count)

Submission status: Wrong Answer

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

    ans = n
    b = [0] * (n+1)
    w = [0] * (n+1)
    for i in range(n):
        b[i+1] = b[i] + (1 if s[i] == '#' else 0)
        w[i+1] = w[i] + (0 if s[i] == '#' else 1)

    for i in range(n):
        tmp = (i - b[i]) + (w[n] + w[i])
        ans = min([ans, tmp])
    print(ans)
main()

Submission status: Wrong Answer

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

b_tot, w_tot = 0, 0
for s in S:
    if s == '.':
        w_tot += 1
    else:
        b_tot += 1

b_left, w_left = 0, 0
tmp = 3 * 10**5
for s in S:
    if s == '.':
        w_left += 1
    else:
        b_left += 1
    tmp = min(tmp, b_left + w_tot - w_left)
print(tmp)

Submission status: Wrong Answer

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

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
                T1[i+1] = "#"
                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

while len(S) != 0 and S[-1] != ".":
    S.pop()
N = len(S)
ans4 = 0
for i in range(N):
    s = S[i]
    if s == ".":
        continue
    else:
        ans4 += 1

# print(ans, ans2, ans3)
print(min(ans2, ans, ans3, ans4))

Submission status: Wrong Answer

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

s1 = s[::]
s2 = s[::]

ans1 = 0
ans2 = 0

for i in range(1, len(s)):
  if s1[i]=="." and s1[i-1]=="#":
    ans1 += 1
    s1[i] = "#"
for i in range(1, len(s)):
  if s2[len(s)-i-1]=="#" and s2[len(s)-i]==".":
    ans2 += 1
    s2[len(s)-i-1] = "."

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ctb=0;ctw=0;f=0;cte=0;cts=0;ct=0

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]=='#':
    ct+=min(ctb,ctw)
    ctb=1
    ctw=0
ct+=min(ctb,ctw)
if f==0:
  print(0)
else:
  print(ct)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
n=[0]*(N+1)
for i in range(N):
    if S[i]=='#':
        n[i+1]=n[i]+1
    else:
        n[i+1]=n[i]
ans=min(n[-1],N-n[-1])
for i in range(N-1):
    ans=min(ans,N-i-(n[-1]-n[i])+n[i])
print(ans)

Submission status: Wrong Answer

Solution code:

def main():
    buf = input()
    N = int(buf)
    buf = input()
    S = buf
    block = []
    white_count = 0
    black_count = 0
    white_swap_count = 0
    black_swap_count = 0
    minimum = 9999999999999
    count = 0
    is_black = False
    for i in S:
        if i == '#':
            if not is_black:
                is_black = True
                block.append(count)
                count = 0
            black_count += 1
        elif i == '.':
            if is_black:
                is_black = False
                block.append(count)
                count = 0
            white_count += 1
        count += 1
    block.append(count)
    minimum = white_count
    is_black = False
    for i, x in enumerate(block):
        if i % 2 == 0:
            white_count -= x
            if i != 0:
                white_swap_count += x
        else:
            black_count -= x
            swap = black_swap_count + white_count
            black_swap_count += x
            if swap < minimum:
                minimum = swap
    print(minimum)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main(n):
	flg = False
	s = "." + input() + "#"
	ans = 0
	blk = 0
	wht = 0
	for i in range(1,n+2):
		if s[i] == "#" and s[i-1] == ".":
			flg = True
			ans += min(wht, blk)
			wht = 0
			blk = 1
		elif s[i] == "#":
			blk += 1
		elif flg and s[i] == ".":
			wht += 1
	print(ans)
main(int(input()))

Submission status: Wrong Answer

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

print(c)

Submission status: Wrong Answer

Solution code:
import math                                                                                            
import re                                                                                              
n = int(raw_input())                                                                                   
s = raw_input()                                                                                                                                                                                 
                                                                                                       
pattern = '#+\.+'                                                                                      
results = re.findall(pattern, s, re.S)                                                                 
                                                                                                       
cnt = 0                                                                                                
for i in results:                                                                                      
    c = min(i.count('#'), i.count('.'))                                                                
    cnt += c                                                                                           
                                                                                                       
print cnt

Submission status: Wrong Answer

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

if len(set(s)) == 1:
  print(0)
else :
  idx = s.find('#')
  print(min(s[idx:].count('.'),s.count('#')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w = '.'
b = '#'

for i in range(N):
    if S[i] == b:
        break
else:
    i += 1

for j in range(N-1, -1, -1):
    if S[j] == w:
        break

whites = S[i:j+1].count(w)
blacks = S[i:j+1].count(b)

print(min([whites, blacks]))

Submission status: Wrong Answer

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

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 == 0:
        print(0)
        return
    if white < black:
        print(white)
    else:
        print(black)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

s1 = s[::]
s2 = s[::]

ans1 = 0
ans2 = 0

for i in range(1, len(s)):
  if s1[i]=="." and s1[i-1]=="#":
    ans1 += 1
    s1[i] = "#"
for i in range(1, len(s)):
  if s2[len(s)-i-1]=="#" and s2[len(s)-i-2]==".":
    ans2 += 1
    s2[len(s)-i-1] = "."

print(min(ans1, ans2))

Submission status: Wrong Answer

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

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

s = s[start:end]

bs = 0
ws = 0

for c in s:
    if c == '#':
        bs += 1
    else:
        ws += 1
    i += 1


print(min(ws, bs))

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

if s[n-1] == "#":
    for i in range(1, n):
        if s[-i] == "#":
            black_count -= 1
        else:
            break
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 = []
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 S[0] == '#':
    A.insert(0,0)
# print(A)
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]
# print(Wlist)
# print(Blist)

#偶数indexは黒(黒の開始位置を固定するとその前後の入れ替わりが確定)
c = sum(Wlist)
for i in range(1,len(A)):
    index = int(i/2)
    count = 0
    # if i%2 == 0:
    count += sum(Blist[:index+1])
    count += sum(Wlist[index:])
    # else:
    #     count += 
    if count < c:
        c = count

#全部白にするときの変更数
w = S.count('.')

#全部黒にするときの変更数
b = N - w

print(min(c,w,b))

Submission status: Wrong Answer

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

s = s[::-1]

sum = 0
while True:
    s = s[s.find('.'):]
#     print(s)
    y = s.find('#')
    x = s[y:].find('.')
    if x == -1:
        x = len(s[y:])
    if y == -1:
        break
    s = s[x + y:]
    sum += min(x,y)
#     print(s, sum)
print(sum)

Submission status: Wrong Answer

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

if '#' in s :
    i = s.index('#')
    cnt = s[i:].count('.')
    cnt2 = 0
    for x in s[::-1]:
        if x == '#':
            cnt2 += 1
        else:
            break
    cnt = min(cnt,s[i:].count('#') - cnt2)
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    s = input()
    start = 0
    end = N-1
    for c in s:
        if c == ".":
            start += 1
        else:
            break
    for c in s[::-1]:
        if c == "#":
            end -= 1
        else:
            break
    dot = 0
    has = 0
    for c in s[start:end+1]:
        if c == ".":
            dot += 1
        else:
            has += 1
    left_dots = 0
    left_has = 0
    right_dots = dot
    right_has = has
    ans = min(dot, has)
    for left in range(start, end+1):
        c = s[left]
        if c == ".":
            left_dots += 1
            right_dots -= 1
        else:
            left_has += 1
            right_has -= 1
        ans = min(ans, left_has + right_dots)
    print(min(dot, has))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import re


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

    count = 0

    for _ in range(n):

        relst = re.findall(r"#\.", s)

        if len(relst) == 0:
            break

        count += len(relst)

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

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
b=[0 for i in range(N+1)]

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

ans=2*b[0]+N-b[-1]

for i in range(1,N+1):
    ans=min(ans,2*b[i]+N-b[-1])

print(ans)

Submission status: Wrong Answer

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

for i in range(1,len(s)):
    if s[i] == "." and s[i-1] == "#":
        ans += 1

print(ans)

Submission status: Wrong Answer

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

flag = False
kc = 0
sc = 0
for i in range(int(l)):
    if k[i] == "#":
        flag=True
        kc += 1
    elif flag :
        sc += 1


print (min(max(sc,1),kc))

Submission status: Wrong Answer

Solution code:
import sys



fin = sys.stdin.readline
N = int(fin())
S = fin().rstrip("\n")
assert len(S) == N

WHITE, BLACK = 0, 1
# 満たしている状態での処理数
min_changes_at = [[float('inf')] * 2 for _ in range(N)]
min_changes_at[-1] = [1, 0] if S[-1] == "#" else [0, 1]

for i in reversed(range(len(S) - 1)):
    color = S[i]
    if color == "#":
        min_changes_at[i][WHITE] = min(min_changes_at[i + 1]) + 1
        min_changes_at[i][BLACK] = min_changes_at[i + 1][BLACK]
    else:  # WHITE
        min_changes_at[i][WHITE] = min(min_changes_at[i + 1])
        min_changes_at[i][BLACK] = min_changes_at[i][BLACK] + 1
# print(min_changes_at)
print(min(min_changes_at[0]))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if'#.'in s:
    print(min(s.count('#'),s.count('.')))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import re


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

    count = 0

    for _ in range(n):

        relst = re.findall(r"#\.", s)

        if not len(relst):
            break

        count += len(relst)

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

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
start = -1
count = 0
print(S)
for i in range(0, N):
    if S[i:1] == '#':
        start = i
        break

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

print("{}".format(count))

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
        else:
            white += 1
        if r == 0:
            if S[i] == '.':
                white_right += 1
    if r == 1:
        if S[i] == '#':
            l = 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:
import copy

N = int(input())
S = list(input())
count = 0
count_two = 0
A = copy.copy(S)
B = copy.copy(S)
for i in range(N):
    try:
        if A[i] == '#' and A[i+1] == '.':
            A[i] = '.'
            count += 1
        if B[i] == '#' and B[i+1] == '.':
            B[i+1] = '#'
            count_two += 1
    except:
        pass

print(min([count, count_two]))

Submission status: Wrong Answer

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

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

bunsuirei = s.find("#")
if bunsuirei != -1:
  ans = min(ans,s[bunsuirei:].count("."))


print(ans)

Submission status: Wrong Answer

Solution code:
input()
S = input()

contB = 0
for i in range(len(S)-1):
    if S[i] == '#':
        contB += 1
        if S[i+1] == '.':
            S = S[i:]
            break
    else:
        break

print(min(S[1:].count('#')+contB, S.count('.')))

Submission status: Wrong Answer

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

input()
s = input().rstrip('#').lstrip('.')
print(min(s.count('#'), s.count('.')))

Submission status: Wrong Answer

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

black = False
white = False
counter = 0
if len(set(s)) == 1:
    print(0)
    exit(0)

for item in s:
    if item == "#":
        black = True
        continue
    if black:
        if item == '.':
            counter += 1
            white = True
        if white and item == '#':
            white = False
print(counter)

Submission status: Wrong Answer

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

input()
s = input().rstrip('#')
print(min(s.count('#'), s.count('.')))