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:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 19:26:31 2019
Tenka1C
@author: maezawa
"""

n = int(input())
s = input()
#n = len(s)

cnt = 0
k = -1
for i in range(n):
    if s[i] == '#':
        k = i
        break
if k == n-1:
    pass
elif k == -1:
    pass      
else:
    for j in range(k, n):
        if s[j] == '.':
            cnt += 1

s2 = list(reversed(s))
cnt2 = 0
k2 = -1
for i in range(n):
    if s2[i] == '.':
        k2 = i
        break
if k2 == n-1:
    pass
elif k2 == -1:
    pass      
else:
    for j in range(k2, n):
        if s2[j] == '#':
            cnt2 += 1

print(min(cnt,cnt2))

Submission status: Wrong Answer

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

r1=S.count("#")
r2=N-r1
c1=r1
c2=r2


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

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

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

print(r3)

Submission status: Wrong Answer

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

ans = 2*10**5
c_b = 0
c_w = 0
for i in range(N):
    if S[i] == '#':
        c_b += 1
    else:
        c_w += 1

ans = min(ans, c_b, c_w)

nums = []
ns = 0
if S[0] == '#':
    nums.append(0)
    ns = 1

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

if len(nums) < 3:
    print(0)
    quit()

count = 0
for i in range(0, len(nums), 2):
    if i != 0:
        if nums[i-1] != 0:
            count += nums[i-1]
print(min(ans, count))

Submission status: Wrong Answer

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

S = list(S)
white = S.copy()
black = S.copy()
ans1 = 0
ans2 = 0
# for i in range(N):
#     if i+1 < N:
#         if white[i] == '#' and white[i+1] == '.':
#             white[i+1] = '#'
#             ans1 += 1

# for i in range(N):
#     if i+1 < N:
#         if black[i] == '#' and black[i+1] == '.':
#             black[i] = '.'
#             ans2 += 1



# flag = 0
# flag = S.count('#')
# if flag > 0:
#     ans = S.count('.')
last_white = 0
last_white_flag = False
for i in range(N):
    if white[i] == '.':
        last_white_flag = True
        last_white = i
S = S[:last_white+1]
# print(S)
ans1 = S.count('#')
ans2 = S.count('.')

# print(S)
# print(ans1)
# print(ans2)
if ans1 < ans2:
    print(ans1)
else:
    print(ans2)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = 200000
w = 0
b = 0
for i in range(n):
    if s[i] == '.':
        w += 1
    if s[i] == '#':
        b += 1
ans = min(b, w)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
s = list(S)
if '#' in s:
  id = s.index('#')
  if id == N-1:
    print(0)
  else:
    a = s.count('#')
    b = s.count('.')
    if a > b:
      print(b)
    else:
      print(a)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
N=input()
S=list(map(str,input()))
#blcok to white
b_index_num = [n for n,v in enumerate(S) if v =='#' and n!=len(S)-1]

#white to block
w_index_num = [n for n,v in enumerate(S) if v =='.']
print(min([len(b_index_num),len(w_index_num)]))

Submission status: Wrong Answer

Solution code:
size = int(input())
stone= str(input())
cnt=0
cnt2=0
for i in range(size):
    if(stone[i]=="."):
        cnt+=1
    else:
        break
for i in range(size):
    if(stone[i]=="."):
        cnt2+=1
        
if(stone[0]=="#"):
    print(cnt2)
else:
    print(cnt2-cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
c=0
d=0
for i in range(0,N,1):
  if S[i]=="#":
    moji=S[i:]
    c=moji.count(".")
    d=moji.count("#")
    break

if c<=d+1:
  print(c)
elif c>d+1:
  print(d)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
xx = []
ten = []
count = 0#最初
count1 = 0 
count2 = 1
count3 = 0

for i in S:
    if i=="#" and count==0:
        count1 += 1
        count = 1
    elif i =="#" and count2==1 and count==1:
        count1 += 1
    elif i =="." and count2==1 and count==1:
        xx.append(count1)
        count1 = 1
        count2 = 0
    elif i =="." and count2==0 and count==1:
        count1 += 1
    elif i=="#" and count2==0 and count==1:
        ten.append(count1)
        count1 = 1
        count2 = 1

if count2==0 and count1>=1:
    ten.append(count1)

for i in range(len(xx)):
    if xx[i]>=ten[i]:
        count3 += ten[i]
    else:
        count3 += xx[i]

print(count3)

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
f = 0
c = 0
if S[0] == '#':
    f = 0
else:
    f = 1
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()

# count '.'
count_wb = []
count = 0
for i in range(n):
    if s[i] == '.':
        count += 1
    count_wb.append((count, i+1-count, count - (i+1-count))) # (w, b, diff)

max_diff = max(count_wb[i][2] for i in range(n))

for i in range(n):
    if count_wb[i][2] == max_diff:
        print(count_wb[i][1] + count_wb[n-1][0] - count_wb[i][0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s=[]
s1=""
for i in range(N):
    if S[i:i+2]==".#":
        s.append(i)
    elif  S[i:i+2]=="#.":
        s.append(i)
    if len(s)==2:
        break
if len(s)==0:
    print("0")
    sys.exit()
elif len(s)==1:
    if S[0]==".":
        print(0)
    else:
        print(N-s[0]-1)
else:
    cnt=0
    if S[0]=="#":
        cnt+=s[0]+1
    for i in range(N):
        if i-1>=s[1] and S[i]==".":
            cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count1 = 0
count2 = 0
count = 0
counter = []

for i in range(N-1):
    if S[i:i+2] == '#.':
        count1 += 1
        if count:
            counter.append(count)
        count = 0
    elif S[i:i+2] == '##':
        count += 1
    else:
        if count:
            counter.append(count)
        count = 0
        
for i in range(N):
    if S[i] == '.':
        count2 += 1

for i in counter:
    count1 += i
    
print(min(count1, count2))

Submission status: Wrong Answer

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

count1=0
count2=0

for i in range(N):
    if S[i]=='#':
        count1+=1
    elif S[i]=='.':
        count2+=1

if count1==0 or count2==0:
    print('0')
else:
    if count1<count2:
        print(count1)
    elif count1>count2:
        print(count2)
    else:
        print(count1)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S = list(input())
 
S_1 = copy.copy(S)
S_2 = copy.copy(S)
S_3 = copy.copy(S)
S_4 = copy.copy(S)
count_1 = 0
count_2 = 0
count_3 = 0
count_4 = 0

for i in range(N-1):
  if S_1[i] == "#" and S_1[i+1] == ".":
    S_1[i+1] = "#"
    count_1 += 1
    
for i in range(N-1):
  if S_2[i] == "#" and S_2[i+1] == ".":
    S_2[i] = "."
    count_2 += 1
    
for i in range(N-1):
  if S_3[N - i - 1] == "." and S_3[N - i - 2] == "#":
    S_3[N - i - 1] = "#"
    count_3 += 1
    
for i in range(N-1):
  if S_4[N - i - 1] == "." and S_4[N - i - 2] == "#":
    S_4[N - i - 2] = "."
    count_4 += 1
    
print(min(count_1, count_2, count_3, count_4))

Submission status: Wrong Answer

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

leng = len(s)
cnt = 0
flag = True
while leng > 1: #黒を白にする方針
    leng -= 1
    if flag == False:
        if s[leng-1] == '#':
            cnt += 1
        else:
            flag = True
    elif s[leng-1] == '#' and s[leng] == '.':
        cnt += 1
        flag = False

cnt2 = 0
flag = True
leng = len(s)
i = 0
while i < leng-1:
    if flag == False:
        if s[i+1] == '.':
            cnt += 1
        else:
            flag = True
    elif s[i] == '#' and s[i+1] == '.':
        cnt2 += 1
        flag = False
    i += 1

if cnt < cnt2:
    print(cnt)
else:
    print(cnt2)

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[i:])
            count = min(tmp_count + 1, count)
    return count


pre = ""
print(func(s))

Submission status: Wrong Answer

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

left = stones.find("#")

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
blacknum = []
whitenum = []
cnt = 0
now = 0
blackcnt = 0
whitecnt = 0

for i in range(N):
    if now == 0 and S[i] == '#':
        whitenum.append(whitecnt)
        blackcnt += 1
        now = 1
    elif now == 1 and S[i] == '.':
        blacknum.append(blackcnt)
        whitecnt += 1
        now = 0
    elif now == 0 and S[i] == '.':
        whitecnt += 1
    else:
        blackcnt += 1

if now == 0:
    whitenum.append(whitecnt)
else:
    blacknum.append(blackcnt)
if len(whitenum) == len(blacknum):
    whitenum.append(whitecnt)

ans = 0
for i in range(len(blacknum)):
    if blacknum[i] <= (whitenum[-1] - whitenum[i]):
        ans = blacknum[i]
    else:
        ans += whitenum[-1] - whitenum[i]
        break

print(min(whitenum[-1]-whitenum[0], ans))

Submission status: Wrong Answer

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

prev = '.'
ans = 0

for i, s in enumerate(S):
    if s == '.' and prev == '#':
        ans += 1
    if prev == '.' and s == '#':
        prev = '#'

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 2*10**5
c_b = 0
c_w = 0
for i in range(N):
    if S[i] == '#':
        c_b += 1
    else:
        c_w += 1

ans = min(ans, c_b, c_w)

nums = []
ns = 0
if S[0] == '#':
    nums.append(0)
    ns = 1

count = 0
for i in range(N):
    if S[i] == '.':
        if ns == 0:
            count += 1
        else:
            nums.append(count)
            count = 1
            ns = 1 - ns
    if S[i] == '#':
        if ns == 1:
            count += 1
        else:
            nums.append(count)
            count = 1
            ns = 1 - ns
nums.append(count)
print(nums)
if len(nums) < 3:
    print(0)
    quit()

count = 0
for i in range(0, len(nums), 2):
    if i != 0:
        if nums[i-1] != 0:
            count += nums[i-1]
print(min(ans, count))

Submission status: Wrong Answer

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

c = [0]
cc = [0]
for i in range(n):
  if s[i] == ".":
    c.append(c[-1]+1)
    cc.append(cc[-1])
  else:
    c.append(c[-1])
    cc.append(cc[-1]+1)
c = c[1:]
cc = cc[1:]

ans = n
for i in range(n):
  ans = min(ans, cc[i]+c[-1]-c[i])
print(ans)

Submission status: Wrong Answer

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

if s.count('.') == n:
    print('0')
else:
    cmp1 = s.count('#')
    cmp2 = s.count('.')
    print(min(cmp1,cmp2))

Submission status: Wrong Answer

Solution code:
n=int(input())
st=input()
i=st.find('#.')
if i < 0:
	print('0')
else:
	counts=[st.count('#')]
	while i >= 0:
		count = st[0:i].count('#')
		count+= st[i+1:].count('.')
		counts.append(count)
		i=st.find('#.', i+1)
	print(min(counts))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
S=input()

sm1=[0]*N
prev=False
if S[0]=='#':
    sm1[0]=1
    prev=True
for i in range(1, N):
    if S[i]=='#':
        if prev:
            sm1[i]=sm1[i-1]+1
        else:
            sm1[i]=1
            prev=True
    else:
        prev=False
sm2=[0]*N
prev=False
if S[-1]=='.':
    sm2[-1]=1
    prev=True
for i in range(N-1, 0, -1):
    if S[i-1]=='.':
        if prev:
            sm2[i-1]=sm2[i]+1
        else:
            sm2[i-1]=1
            prev=True
    else:
        prev=False

S2=list(S)
cnt=0
for i in range(1, N):
    if S2[i-1]=='#' and S2[i]=='.': 
        if sm1[i-1]>sm2[i]:
            S2[i]='#'
        else:
            S2[i-1]='.'
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

count = 0
while True:
    flag = True
    for i in range(N - 1):
        if S[i] + S[i+1] == "#.":
            S[i+1] = "#"
            flag = False
            count += 1
    if True:
        break

print(count)

Submission status: Wrong Answer

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

WHITE = '.'
BLACK = '#'

ans = 0
w_to_b = [0]
for i in range(1, N):
    if S[i-1] == WHITE and S[i] == BLACK:
        w_to_b.append(i)

p_num = len(w_to_b)
for i in range(p_num):
    start = w_to_b[i]
    if i == p_num - 1:
        w_num = S[start:].count(WHITE)
        b_num = S[start:].count(BLACK)
    else:
        end = w_to_b[i+1]
        w_num = S[start:end].count(WHITE)
        b_num = S[start:end].count(BLACK)
    ans += min(w_num, b_num)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
  
input()
S = np.asarray(list(str(input())))

rw = S[S=="."].size
rb = S[S=="#"].size
lw = 0
lb = 0
res = 2 * 10**5

for i in range(S.size):
 if S[i] == "#":
  rb -= 1
  lb += 1
 else:
  rw -= 1
  lw += 1
 res = min(res,lb+rw)
print(res)

Submission status: Wrong Answer

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

bcnt = []
wcnt = []

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

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

# print(bcnt)


wcnt.reverse()

# print(wcnt)

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

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

# print(nuru)

print(min(nuru))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
counter=0
for i in range(1, 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 = input()

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

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


ans = N
for i in range(N):
    wa = w_list[i] + b_list[N-2-i]
    if ans > wa:
        ans = wa
if b_list[N-1] == 0 or w_list[N-1] == 0:
    print(0)
else:
    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, 0, -1):
        if sLst[i] == SIRO:
            if sLst[i - 1] == KURO:
                sLst[i - 1] = SIRO
                ans += 1
print(ans)

Submission status: Wrong Answer

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

    next_black_num = 0
    pre_white = 0
    is_pre = True
    pre_stone = "."

    for s in S:
        if pre_stone == "." and s == "#":
            is_pre = False
        if is_pre:
            pre_white += 1
        if pre_stone == "#" and s == ".":
            next_black_num += 1
            pre_stone = "#"
        else:
            pre_stone = s

    N -= pre_white
    if S[-1] == "#":
        N -= 1

    print(min([next_black_num, N - next_black_num]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [str(i) for i in input()]

countw = []
countb = []
for i,j in enumerate(s):
    if s[i] == ".":
        countw.append(i)
    elif s[i] == "#":
        countb.append(i)
if len(countb) == 0 or len(countw) == 0:
    print(0)
    
else:
    maxw = max(countw)
    minb = min(countb)    
    trans1 =  s[:(maxw+1)].count("#")
    trans0 =  s[minb:].count('.')

    print(min(trans1,trans0))

Submission status: Wrong Answer

Solution code:
import re

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

kind = []
stone = []
s = 0

for i in range(N):
    if i == 0:
        kind.append(S[i])
        s += 1
    elif S[i-1] != S[i]:
        stone.append(s)
        kind.append(S[i])
        s = 1
    else:
        s += 1
    if i == N-1:
        stone.append(s)

if len(kind)==1:
    print(0)
else: 
    min = 2 * 10 ** 5
    tmp = 0
    if kind[0] == '.':
        start = 1
    else:
        start = 0
    for i in range(start,len(stone),2):
        for j in range(start,i,2):
            tmp += stone[j]
        for j in range(i+1,len(stone),2):
            tmp += stone[j]
        if tmp < min:
            min = tmp
    print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
b = [0]*(n)
w = [0]*(n)
if s[0] ==".":
    w[0] =1
else:
    b[0] =1
for i in range(1,n):
    if s[i] == ".":
        w[i] = w[i-1] + 1
        b[i] =b[i-1]
    else:
        b[i] = b[i-1] + 1
        w[i] = w[i-1]
ans = n

for j in range(n):
    ans = min(ans,b[j]+w[n-1]-w[j])
print(ans)

Submission status: Wrong Answer

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

cb = 0
cw = 0

i = 0
while i < N-1:
    idx = i
    if S[i] == '#' and S[i+1] == '.':
        cb += 1
        i += 1
        j = 1
        while True:
            if idx + j + 1 < N and S[idx +1 +  j] == '.':
                j += 1
                cb += 1
            else:
                break
    i += 1
        
                
i = N-2
while i >= 0:
    idx = i
    if S[i] == '#' and S[i+1] == '.':
        cw += 1
        i -= 1
        j = 1
        while True:
            if idx - j >= 0 and S[idx - j] == '#':
                j += 1
                cw += 1
            else:
                break
    i -= 1
print(min(cb,cw))

Submission status: Wrong Answer

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

li = list(S)
count = 0

if S.count('.') > S.count('#'):
    for i in range(1, N):
        idx = -1 * i
        if '.' == li[idx] and '#' == li[idx-1]:
            li[idx-1] = '.'
            count += 1
else:
    for i in range(1, N):
        idx = -1 * i
        if '.' == li[idx] and '#' == li[idx-1]:
            li[idx] = '#'
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
an = []
def a (str) :
	ans = []
	for i in range(n) :
		k = 0
		if str[i] == "#" :
			for j in s[0:i+1] :
				if j == "#" : k+=1
			for j in s[i:-1] : 
				if j == "." : k += 1
			ans.append(k)
	return (ans)
an = a(s)
if len(an) == 0 : an = {0}
print(min(an))

Submission status: Wrong Answer

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

ans = 0
ans_ = 0
for i, s in enumerate(S):
    if i == N-1:
        break
    if s is '#':
        ans_ += 1
        ans__ = 0
        count = i
        check = -1
        for s_ in S[count+1:]:
            if count + 1 == N or s_ is '#':
                break
            if s_ is '.' :
                ans__ += 1
                check = 1
        if check == 1:
            ans += min(ans_, ans__)
            ans_ = 0

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

stack = []


for i in range(N):
    if S[i] == '.':
        stack.append(i)

if stack:
    ans = min(stack[-1] - (len(stack) - 1), len(stack))
else:
    ans = 0

print(ans)

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] == '.':
    ANS4 = S.count('#') 

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
index = S.find("#")
answer = -1
if(index == -1):
    answer = 0
else:
    test = S[index:N]
    count_s = test.count("#")
    count_d = test.count(".")
    answer = min(count_s,count_d)
    if(count_s == len(test)):
        answer = 0
print(answer)

Submission status: Wrong Answer

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

# when do you replace now char to .
# 

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

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

def calcCount(S , N) : 
    countingChar = S[0]
    rst = []
    count = 1
    for s in S[1:] :
        if countingChar == s : 
            count += 1
        else : 
            rst.append((countingChar , count))
            count = 1
            countingChar = s
    rst.append((countingChar , count))
    return rst

def countRightChange(countingList) : 
    #全部を.に変えるコスト
    cnt = 0
    for elem in countingList : 
        if elem[0] == "#" : 
            cnt += elem[1]
    return cnt

def countLeftChange(countingList) : 
    # 全部を#に変えるコスト
    cnt = 0
    for elem in countingList : 
        if elem[0] == "." : 
            cnt += elem[1]
    return cnt

def calcPoint(countingList) : 
    minVal = 9999999999999
    for i in range(len(countingList)) : 
        a = countRightChange(countingList[ : i])
        b = countLeftChange(countingList[i : ])
        if minVal > a + b : 
            minVal = a + b
    return minVal




#cnt = inorderReplace(S , N)
countingList = calcCount(S , N)
cnt2 = calcPoint(countingList)

print(cnt2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N =  input()
S =  input()

n = S.find(".")
m = S.rfind("#")
if n < 0 or m < 0:
  print(0)
else:
  print(min(S[n:].count("#"), S[:m+1].count(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())

str = input()
count = 0

for i in range(n):
  if str[i] == "#":
    k = i
    for s in range(k,n):
      if str[s] == ".":
        count += 1
    break
print(count)

Submission status: Wrong Answer

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

# . : white
# # : black
# no '#.' sequence

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

cnt_b = [0 for i in range(N)]    # i番目を含んでそれまでにb，wが何個あるか
cnt_w = [0 for i in range(N)]

if S[0] == "#":
    cnt_b[0] = 1
else:
    cnt_w[0] = 1

for i in range(N - 1):
    if S[i] == "#":
        cnt_b[i + 1] = cnt_b[i] + 1
        cnt_w[i + 1] = cnt_w[i]
    else:
        cnt_b[i + 1] = cnt_b[i]
        cnt_w[i + 1] = cnt_w[i] + 1

cnt_change = [0 for i in range(N)]
for i in range(N):
    cnt_change[i] = cnt_b[i] + cnt_w[N - 1] - cnt_w[i]

print(min(cnt_change))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
flag = 0
location1 = 0
location2 = n
for i in range(n):
    #    print(s[i])
    if s[i] == '#':
        location1 = i
        flag = 1
        break

i = 0

for i in range(n):
    #    print(s[n-i-1])
    if s[n-i-1] == '.':
        location2 = n - i
        flag = 2
        break


if flag == 0:
    print(0)
else:
    print(min(s[location1:n].count('.'), s[0:location2].count('#')))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N = makeInt(input_string[0])
    S = input_string[1].rstrip()
    if len(S) == 1:
        return 0
    if S == "#.":
        return 1
    S = list("."+S)
    w = "."
    b = "#"
    c = 0
    b_c = 0
    for i in range(N):
        if S[i] == b:
            b_c += 1
        if S[i] == w and S[i-1] == b:
            b_c = 0
            w_c = 0
            for j in range(i, N+1):
                if S[j] == w:
                    w_c += 1
                else:
                    break
            """
            for k in range(0, i)[::-1]:
                if S[k] == b:
                    b_c += 1
                else:
                    break
            """
            #print(w_c)
            #print(b_c)
            if w_c > b_c:
                for h in range(0, i)[::-1]:
                    if S[h] == b:
                        S[h] = w
                        c += 1
                    else:
                        break
        else:
            b_c = 0
        if S[i] == b:
            if S[i-1] == w and S[i+1] == w:
                S[i] = w
                c += 1
                continue
        if i > 0 and S[i] == w:
            #print(S)
            #print(S[i])
            if S[i-1] == b:
                S[i] = b
                c += 1
        if i > 0 and S[i] == w:
            #print(S)
            #print(S[i])
            if S[i-1] == b:
                S[i] = b
                c += 1
    i = N
    if i == N:
        #print("a")
        #print(S)
        #print(S[i])
        if S[i-1] == b and S[i] == w:
            S[i] = b
            c += 1
    return c


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#n=int(input())
#li=input().split()
#S=input()
#import fractions
#lis=list(map(int,input().split()))

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

count=0 #black
flag=-1 #first black
for i in range(n):
    if s[i]=="#":
        count+=1
        if flag==-1:
            flag=i
if count==0:
    ans=0
elif count==n:
    ans=0
else:
    a=count #black to white
    b=n-count-flag #white to black
    ans=min(a,b)




print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input()) 
s = list(input().split('.'))

num = [i.count('#') for i in s]
m = max(num)
if m == n:
    m = 0
print(m)

Submission status: Wrong Answer

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

count = 0

while s.count("#.") != 0:
    t = re.subn("##.#", '####', s)
    s = t[0]
    count += t[1]
    t = re.subn(".#..", '....', s)
    s = t[0]
    count += t[1]
    t = re.subn(".#.#", '...#', s)
    s = t[0]
    count += t[1]
    t = re.subn("##..", '####', s)
    s = t[0]
    count += t[1] * 2
    t = re.subn("#.", '..', s)
    s = t[0]
    count += t[1]

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
ans = 100000000000
for i in range(0,N):
  if ans > S[:i].count('#')+S[i:].count('.'):
    ans = S[:i].count('#')+S[i:].count('.')
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
bw = []
count = 0
max_num = 0
ind = 0
for i in range(N):
  tmp = S[i:]
  bw.append(tmp.count('#')-tmp.count('.'))
  if bw[i]>max_num:
    max_num = bw[i]
    ind = i
tmp1 = S[:ind]
tmp2 = S[ind:]
ans = 0
if tmp1.count('#') < tmp1.count('.'):
  ans += tmp1.count('#')
  if tmp2.count('#') < tmp2.count('.'):
    ans += tmp2.count('#')
  else:
    ans += tmp2.count('.')
else:
  ans += tmp1.count('.')
  ans += tmp2.count('.')
print(ans)