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
N = int(input())
S = list(input())
S1, S2 = S[:], S[:]
S2.reverse()
c1, c2 = 0, 0
for i in range(N-1):
    if S1[i] == "#" and S1[i+1] == ".":
        c1 += 1
        S1[i+1] = "#"
for j in range(N-1):
    if S2[j] == "." and S2[j+1] == "#":
        c2 += 1
        S2[j+1] = "."
print(min(c1, c2))

Submission status: Wrong Answer

Solution code:
x = int(input());
s=list(input());
y = s;
z = s;
j = 0;
k = 0;

for i in range(len(s)):
    if str(s[i]) == '#':
        if i != len(s)-1:
         if str(s[i+1]) == '.':
              s[i+1] = '#';
              j = j + 1;

for i in reversed(range(len(z))):
    if str(z[i]) == '#':
        if i != len(s)-1:
         if str(z[i+1]) == '.':
              z[i] = '.';
              k = k + 1;

 
print(max(k,j));

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
c=0
d=0
ListA=[]
for i in range(0,N-1,1):
  if S[i]==".#":
    moji1=S[i:]
    moji2=S[:i]
    c=moji1.count("#")
    d=moji2.count(".")
    ListA.append(c+d)

if len(ListA)>=1:
  ListA.sort()
  print(ListA[0])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from numpy import*
from itertools import*
n=int(input())
s=input()
t=s.count("#")
r=s.count(".")

l=[t,r]
x=[len(list(v))for k,v in groupby(s)if k=="#"]
y=[len(list(v))for k,v in groupby(s)if k=="."]
if len(x)>len(y):
    y=[0]+y
elif len(x)<len(y):
    x=[0]+x
else:
    if s[0]=="#":
        y=[0]+y
        x=x+[0]
    else:
        y=y+[0]
        x=[0]+x

x=array([0]+list(accumulate(x)))
y=array(list(accumulate(y[::-1]))[::-1]+[0])
print(min(x+y))

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

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

n = int(input())

s = list(input())

count = 0

# for i in range(n-1):
#     if s[i] == '#' and s[i+1] == '.':
#         if i == 0:
#             s[0] = '.'
#             count += 1
#             continue
#
#         if s[i-1] == '#':
#             s[i+1] = '#'
#             count += 1
#         elif s[i-1] == '.':
#             s[i] = '.'
#             count += 1


for i in range(n-1):
    if s[i] == '#' and s[i+1] == '.':
        if i == 0:
            s[0] = '.'
            count += 1
            continue

        if i == n-1:
            s[n] = '#'
            count += 1
            continue

        if s[i-1] == '#':
            s[i+1] = '#'
            count += 1
        elif s[i-1] == '.' and s[i+2] == '.':
            s[i] = '.'
            count += 1
        elif s[i-1] == '.' and s[i+2] == '#':
            s[i+1] = '#'
            count += 1


print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10000000)


def check_and_back_or_go_to(li, ind, N, counter, white_charge, black_charge):
    back = True
    # print('see {} {} and {} counter{}'.format(ind, li[ind - 1], li[ind], counter))
    if ind == 0:
        return counter

    # access
    if li[ind - 1] == '#' and li[ind] == '.':
        c = check_and_back_or_go_to(li, ind - 1, N, counter+1, white_charge, black_charge)
        return c
    elif li[ind - 1] == '.' and li[ind] == '.':
        return check_and_back_or_go_to(li, ind - 1, N, counter, white_charge + 1, black_charge)

    elif li[ind - 1] == '#' and li[ind] == '#':
        return check_and_back_or_go_to(li, ind - 1, N, counter, white_charge + 1, black_charge+1)
    elif li[ind - 1] == '.' and li[ind] == '#':
        adder=min([white_charge,black_charge])
        return check_and_back_or_go_to(li, ind - 1, N, counter+adder, 0, 0)
    else:
        c = check_and_back_or_go_to(li, ind - 1, N, counter, white_charge, black_charge)
        return c


N = int(input())
S = list(input())
r = range(N)
if N == 1:
    print(0)
    exit(0)
bsk = False
key = -1
for i in range(len(S)):
    if not bsk:
        if S[i] == '#':
            bsk = True
            key = i
    else:
        if S[i] != '#':
            bsk = False

if bsk and key==0:
    print(0)
    exit(0)

if bsk:
    # print('bsk occured')
    # print([S[i] for i in range(key)])
    count = check_and_back_or_go_to([S[i] for i in range(key)], key  - 1, N, 0, 0,0)
    print(min([count, key - count]))
else:
    count = check_and_back_or_go_to(S, len(S) - 1, N, 0, 0,0)
    print(min([count, N - count]))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
import bisect

def main():
    N = int(input())
    S = list(input())
    # print(S)

    if S.count('.') == N or S.count('#') == N:
        print(0)
        exit()

    total_white = S.count('.')
    total_black = S.count('#')
    ans = min(total_white, total_black)
    rest_white = total_white

    current_ans = 0
    S += '#'  # 番兵
    black_count = 0
    white_count = 0
    for i in range(len(S)):
        if S[i] == '#':
            black_count += 1
            if white_count > 0:
                # consider
                tob = black_count - 1
                current_ans += tob
                ans = min(ans, current_ans + white_count + rest_white, current_ans + tob + rest_white)

                white_count = 0
                black_count = 1
        else:
            if black_count > 0:
                white_count += 1

            rest_white -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

cnt = 0
tmp_cnt = 0
start_flag = False
count_flag = False
sharp_cnt = 0
for i in range(0, n-1):
  if s[i] == '#' and not start_flag:
    start_flag = True
    sharp_cnt += 1
  elif s[i] == '.' and start_flag:
    tmp_cnt += 1
  elif s[i] == '#' and start_flag:
    sharp_cnt += 1
  if s[i] == '.' and s[i+1] == '#':
    count_flag = True
  if tmp_cnt != 0 and count_flag:
    cnt += min(tmp_cnt, sharp_cnt)
    tmp_cnt = 0
    sharp_cnt = 0
    start_flag = False
    count_flag = False

if s[-1] == '.':
  tmp_cnt += 1
if tmp_cnt != 0:
 cnt += min(tmp_cnt, sharp_cnt)

print(cnt)

Submission status: Wrong Answer

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

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

# 最終状態としては、全部黒、全部白、白が続いて残り全部黒、しかない
for i in range(num - 1):
    if stone[i] == ".":
        continue
    else:
        # 黒が出たらそこ以降を全部黒か白にするしかない
        if stone[i:].count(".") > stone[i:].count("#"):
            count = stone[i:].count("#") + 1
        else:
            count = stone[i:].count(".")
        break
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
ans = stdin.readline().rstrip()
count = 0
right = 0
for left in range(0,len(ans)):
    right = left+1
    if left == len(ans)-1:
        break
    if ans[left] == '#':
        while(right < N and ans[right] == '.'):
            count += 1
            right += 1
        left = right
        if left == right:
            right += 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().rstrip()
answer1 = S[:S.rfind(".")+1].count("#")
answer2 = S[S.find("#"):].count(".")
answer3 = 10**9
index = S.rfind(".")
if index == N-1:
    #右黒左白
    S_last = S[S.rfind("#"):index+1]
    S_first = S[:S[:S.rfind("#")].rfind(".")]
    answer3 = S_last.count(".") + S_first.count("#")
index = S.find("#")
print(min([answer1, answer2, answer3]))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=0
s.append('A')
if s[0]=='#':
    a=1
    while s[a]=='.' and a!=n:
        a+=1
        ans+=1
for i in range(1,n):
    if s[i]=='#' and i!=n-1:
        a=i+1
        while s[a]=='.' and a!=n:
            a+=1
            ans+=1

Submission status: Wrong Answer

Solution code:
def remove_fwhite(S):
    fwhite = 0
    for fw in S:
        if fw == '.':
            fwhite += 1
        else:
            break
    return fwhite

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

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

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


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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
start = s[0]
pattern = []

prev = ''
b = 0
w = 0
for i in s:
    if i == '#' and prev == '#' or prev =='':
        b += 1
    elif i == '.' and prev == '.' or prev == '':
        w += 1
    elif i == '#':
        b += 1
        pattern.append(w)
        w = 0
    else:
        w += 1
        pattern.append(b)
        b = 0
    prev = i
    
if prev == '#':
    pattern.append(b)
    end = prev
else:
    pattern.append(w)
    end = prev

totalb = 0
totalw = 0
for i in range(len(pattern)):
    if start == '.':
        if i % 2 == 0:
            totalw += pattern[i]
        else:
            totalb += pattern[i]
    else:
        if i % 2 == 0:
            totalb += pattern[i]
        else:
            totalw += pattern[i]
        
if len(pattern) == 1 or (len(pattern) == 2 and start == '.'):
    print(0)
else:
    if start == '.':
        totalw -= pattern[0]
    elif end == '#':
        totalb -= pattern[-1]
    else:
        print(min(totalw, totalb))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
S = input()
black = 0
white = 0
l = [] # 

for s in S:
    if s == "#":
        black += 1
    else:
        white += 1

leftBlack = 0
rightWhite = white
for s in S:
    if s == "#":
        leftBlack += 1
    else:
        rightWhite -= 1
        
    l.append(leftBlack + rightWhite)
    
print(min(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
now = S[0]
start = S[0]
end = S[-1]
for i in range(N):
    if S[i] != now:
        ans += 1
        now = '#' if now == '.' else '.'
if start == '.' and end == '#':
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
def c_stones(N, S):
    import itertools
    if S.count('#') == 0 or S.count('.') == 0:
        return 0
    s = [(k, len(list(v))) for k, v in itertools.groupby(S)]
    ans = float('inf')
    for i in range(len(s)):
        ans1 = 0
        for j in range(len(s)):
            # ここから黒
            if j < i and s[j][0] == '#':
                ans1 += s[j][1]
            elif j >= i and s[j][0] == '.':
                ans1 += s[j][1]
        ans = min(ans1, ans)
    return ans

N = int(input())
S = input()
print(c_stones(N, S))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
w = 0
for si in input():
    if si == '.':
        w += 1
print(min(w, n - w))

Submission status: Wrong Answer

Solution code:
from numpy import cumsum

N = int(input())
S = input()
ss = S.replace("#", "1").replace(".", "0")
* ls, = map(int, ss)
cum_ls = cumsum(ls)

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

print(ans)

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

BLACK = '#'
WHITE = '.'

count = 0
for idx in range(N - 1):
    if S[idx] == BLACK and S[idx + 1] == WHITE:
        if idx > 0:
            if S[idx - 1] == WHITE:
                S[idx] = WHITE
            else:
                S[idx + 1] = BLACK
        else:
            S[idx] = WHITE
        count += 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sr = s[::-1]

if s == "." * n or s == "#" * n:
    print(0)
else:
    black = s.index("#")
    white = sr.index(".")
    wb = s[black:].count(".")
    bw = sr[white:].count("#")
    print(min(wb, bw))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 2*10**5+1
tmp = 0

S_list = list(S)
S_list.insert(0,"+")
S_list.insert(N+1,"+")

for i in reversed(range(1,N+1)):
    if (S_list[i] == "."):
        for j in range(0,i):
            if (S_list[j] == "#"):
                tmp += 1
        for j in range(i+1,len(S_list)):
            if (S_list[j] == "."):
                tmp += 1
        print(tmp)
        if tmp < ans :
            ans = tmp
            tmp = 0

print(ans)

Submission status: Wrong Answer

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


ini_w = 0
for i in range(len(S)):
    if S[i] == '.':
        ini_w = ini_w + 1
    else:
        break
    
if ini_w >= len(S)-1:
    print(0)
    exit()
    


last_b = 0

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

S = S[ini_w:len(S)-last_b]

if S == '':
    print(0)
    exit()

all_w = len(S) - S.count(".")
all_b = len(S) - all_w

print(min(all_w,all_b))

Submission status: Wrong Answer

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

state = False
counter = 0

for i in range(N):
  if S[i] == ".":
    counter += 1
  else:
    break
S_1 = S[counter:]

for i in range(len(S)):
  if S[i] == "#":
    state = True
    counter += 1
  else:
    counter = 0
    state = False
if state == True:
  S_3 = S_1[:-1*counter]
  S_2 = S[:-1*counter]
else:
  S_3 = S_1
  S_2 = S
  
b_1 = S_1.count("#")
w_1 = len(S_1) - b_1

b_2 = S_2.count("#")
w_2 = len(S_2) - b_2

b_3 = S_3.count("#")
w_3 = len(S_3) - b_3

print(min(b_1, b_2, b_3, w_1, w_2, w_3))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
if s.count(".") > s.count("#"):
    print(s.count("#"))
elif s.count("#") > s.count("."):
    print(s.count("."))
else:
    print(s.count("#"))

Submission status: Wrong Answer

Solution code:
n = int(input())
stone = input()
ans = 0
blackCnt = 0
whiteCnt = 0
sw = False
first = True
for i in range(n):
    if blackCnt > 0 and whiteCnt > 0 and stone[i] == '#' and first == True:
        first = False
        if blackCnt > whiteCnt:
            ans = whiteCnt
        else:
            ans = blackCnt
        blackCnt = 1
        whiteCnt = 0

    elif stone[i] == '#':
        sw = True
        blackCnt += 1
    elif stone[i] == '.' and sw == True:
        whiteCnt += 1

if blackCnt > 0 and whiteCnt > 0:
    if blackCnt > whiteCnt:
        ans += whiteCnt
    else:
        ans += blackCnt

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
if "#" in s:
    k = s.index("#")
    print(0 if k == n-1 else min(s[k+1:].count("."),s[k+1:].count("#") + 1))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def get_cost_change_black(S):
    return S.count(".")

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

indexs = [i for i, x in enumerate(S) if x == "#"]
if len(indexs) == 0:
    print(0)
else:
    answer = 10000000
    change_white = 0
    change_black = get_cost_change_black(S[indexs[0]:])
    for i, ind in enumerate(indexs):
        x = change_white + change_black
        if x < answer:
            answer = x
        change_white = change_white + 1
        if i == len(indexs) - 1:
            if change_white < answer:
                answer = change_white
            break
        change_black = change_black + (indexs[i+1] - indexs[i] - 1)
    print(answer)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
count=0
ten_count=[0,0]
if b[0]=="#": 
    ten_count[0]+=1
for i in range(1,a):
    if b[i]=="#" and b[i-1]=="#":
        ten_count[0]+=1
    elif b[i-1]=="#" and b[i]==".":
        ten_count[1]+=1
        if i==a-1:
            count=min(ten_count[0],ten_count[1])
    elif b[i-1]=="." and b[i]=="." :
        ten_count[1]+=1
        if i==a-1:
            count=min(ten_count[0],ten_count[1])
    elif (b[i-1]=="." and b[i]=="#") :
        count=min(ten_count[0], ten_count[1])
        ten_count[0]+=1
print(count)

Submission status: Wrong Answer

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

s_count = 0
d_count = 0
for s in S:
    if s=='#': s_count+=1
    elif s=='.': d_count+=1

print(min(s_count, d_count))

Submission status: Wrong Answer

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

1 <= N <= 2*10^5

if S.count("#") > S.count("."):
  print(S.count("."))
elif S.count(".") > S.count("#"):
  print(S.count("#"))
else:
  print(0)

Submission status: Wrong Answer

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

post = ''
ans=0
data=[]

left=[]
right=[]

tmp=0
for i in range(n):
    if s[i]=='#':
        tmp+=1
    elif tmp!= 0:
        left.append(tmp)
        tmp=0


tmp=0
for i in range(n):
    if s[n-i-1]=='.':
        tmp+=1
    if n-i-1-1 >=0 and s[n-i-1-1]=="#" and tmp!=0:
        right.append(tmp)
        tmp=0

right.reverse()
# print(s)
# print(left)
# print(right)

for i in range(len(left)):
    if i == len(left)-1:
        ans+=min(left[i],right[i])
        break
    l = left[i]
    r = right[i]
    if l > r:
        ans+=r
        left[i+1]=l+r+left[i+1]
    else:
        ans+=l


print(ans)

Submission status: Wrong Answer

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

s=input()

ans = n

for i in range(n):
	tmp_w=[]
	tmp_b=[]
	tmp_t=[]
	tmp_ans=0
	
	tmp_b += ["#" for k in range(i)]
	
	tmp_w += ["." for m in range(n-i)]
	tmp_t = tmp_w + tmp_b
	for loop in range(n):
		if s[loop] != tmp_t[loop]:
			tmp_ans +=1
	ans =min([ans,tmp_ans])

print(ans)

Submission status: Wrong Answer

Solution code:
_ = input()

letter = input()

bk_back = 0
wt_front = 0
for i in range(len(letter)-1):
    if letter[i] == '#' and letter[i+1] == '.':
        for c in letter[:i+1]:
            if c == '#':
                bk_back += 1
            
        for c in letter[i+1:]:
            if c == '.':
                wt_front += 1
                
        break

bk_front = 0
wt_back = 0
for i in range(1, len(letter)):
    if letter[-i] == '.' and letter[-i-1] == '#':
        for c in letter[-i:]:
            if c == '.':
                wt_back += 1
        
        for c in letter[:-i]:
            if c == '#':
                bk_front += 1
                
        break

print(min(bk_back + wt_back, wt_front, bk_front))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s.lstrip(".").rstrip("#")
n = len(s)
count = s.count(".")

if count < n - count:
    print(count)
else:
    print(n - count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
countB=0
flg=False

for i in range(N):
    if flg == False:
      if S[i] == '#':
          flg = True
          P = i
      else:
        continue

    if S[P] == S[i] :
        countB += 1
        continue
    else:
        count +=1

if count <= (N / 2):
    if count > countB:
        print(countB)
    else:
        print(count)
else:
    print(countB)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=2
a=[input() for i in range(n)]
N=int(a[0])
S=list(a[1])
 
kazuXD=0
flg=0
kazu=0
geri=0
for i in range(N):
  if S[i]=="#":
    geri+=1
for i in range(N):
  if flg==0:
    if S[i]==".":
      kazu+=1
    else:
      flg=1
flg=0
for i in range(N):
  if i>kazu:
    if S[i]==".":
      kazuXD+=1

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

Submission status: Wrong Answer

Solution code:
import re
N=int(input())
S=input()
s=[]
kuro = S.count("#")
shiro = S.count(".")
Slist =list(S)
if Slist[N-1] == ".":
	s = (re.split("#*",S))
	if (len(s)) == 2:
		print(1)
	else:
		if Slist[N-1] == "#":
			print(min(kuro-1,shiro))
		else:
			print(min(kuro,shiro))
		
else:
	if Slist[N-1] == "#":
		print(min(kuro-1,shiro))
	else:
		print(min(kuro,shiro))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=str(input())
"""n = 8
s = "########"
print(s)
print(len(s))"""

memo = []
countwb=0
now = s[0]
count = 0
if now == "#":
    memo.append(0)
while(count<n):
    if s[count]==now:
        countwb+=1
    else:
        memo.append(countwb)
        countwb = 1
        now = s[count]
    count+=1
memo.append(countwb)
#print(memo)
#print(memo[len(memo)-3])


count_b = []
c_b = 0
for  i in range(1,len(memo),2):
        c_b += memo[i]
        count_b.append(c_b)
#print(count_b)

count_w = []
c_w = 0
for  i in range(0,len(memo),2):
        c_w += memo[i]
        count_w.append(c_w)
#print(count_w)

#白白．．．黒黒にする
w_b = 0
if len(memo)%2==1:
    #最後が白
    w_b += memo[-1]
    if len(count_b)>1:
        w_b += count_b[-2]
else:
    #最後が黒
    if len(count_b)>1:
        w_b += count_b[-2]
#print("w_b",w_b)
#全部白にする
allw = 0
if count_b!=[]:
    allw = count_b[-1]
#print("allw",allw)
#全部黒にする
allb = 0
if count_w!=[]:
    allb = count_w[-1]
#print("allb",allb)

print(min(w_b,allb,allw))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

post = ''
ans=0
data=[]

left=[]
right=[]

tmp=0
for i in range(n):
    if s[i]=='#':
        tmp+=1
    elif tmp!= 0:
        left.append(tmp)
        tmp=0


tmp=0
for i in range(n):
    if s[n-i-1]=='.':
        tmp+=1
    if n-i-1-1 >=0 and s[n-i-1-1]=="#" and tmp!=0:
        right.append(tmp)
        tmp=0

right.reverse()
print(s)
print(left)
print(right)

for i in range(len(left)):
    if i == len(left)-1:
        ans+=min(left[i],right[i])
        break
    l = left[i]
    r = right[i]
    if l > r:
        ans+=r
        left[i+1]=l+r+left[i+1]
    else:
        ans+=l


print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
b=0
w=0
bx=0
wx=0

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

print(min(bx,wx))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
xx = []
ten = []
count = 0#最初
count1 = 0 
count2 = 1
count3 = 0
count4 = 0
count5 = 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]+count5)>=ten[i]:
        count3 += ten[i]
        count5 += ten[i]+xx[i]
    else:
        count3 += xx[i]
        count5 = 0
count5 = sum(xx)
if count3 > count5:
    count3 = count4
        
print(count3)

Submission status: Wrong Answer

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

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

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

l=len(Color)

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

print ans

Submission status: Wrong Answer

Solution code:
import re
N = int(input())
S = input()
ans=2*10**5

l = []
for i in range(len(S)-1):
    if S[i]+S[i+1] == ".#":
        l.append(i)
        
if S.count("#") == 0 or S.count(".") == 0:
    print(0)

else:
    for i in l:
        a = S[i+2:].count(".")+S[:i].count("#")
        ans = min(a,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
t=-1
for i in range(n):
    if s[-1]=="#":
        s.pop(-1)
print(min(s.count("."),s.count("#")))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def main():
    input()
    s = input()

    # 最初に黒い石が出現した後に出現した"."と"#"のそれぞれの総数のうち、最小のものを返す
    b_num = 0
    w_num = 0
    is_start = False
    for c in s:
        if not is_start:
            if c != "#":
                continue
            else:
                is_start = True
        if is_start:
            if c == ".":
                w_num += 1
            else:
                b_num += 1

    return min(w_num, b_num)


print(main())

Submission status: Wrong Answer

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

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  S = input()

  st = N
  for i in range(N):
    if S[i] != '.':
      st = i
      break
  ed = 0
  for i in range(N):
    if S[N - 1 - i] != '#':
      ed = N - i
      break

  if ed <= st:
    print(0)
    return

  count = 0
  current = '#'
  whites = []
  blacks = []
  for i in range(st, ed):
    if S[i] != current:
      if current == '#':
        blacks.append(count)
      else:
        whites.append(count)
      current = S[i]
      count = 0
    count += 1
  if count > 0:
    whites.append(count)

  accWhites = [0 for _ in range(len(whites) + 1)]
  for i in range(len(whites)):
    accWhites[i+1] = accWhites[i] + whites[i]
  accBlacks = [0 for _ in range(len(blacks) + 1)]
  for i in range(len(blacks)):
    accBlacks[i+1] = accBlacks[i] + blacks[i]

  ans = N
  for i in range(len(blacks)):
    w = accWhites[len(whites)] - accWhites[i]
    b = accBlacks[i] - accBlacks[0]
    ans = min(ans, w + b)
  print(ans)

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

#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:
from numpy import*
from itertools import*
n=int(input())
s=input()
t=s.count("#")
r=s.count(".")

l=[t,r]
x=[len(list(v))for k,v in groupby(s)if k=="#"]
y=[len(list(v))for k,v in groupby(s)if k=="."]
if len(x)>len(y):
    y=[0]+y
elif len(x)<len(y):
    x=[0]+x
else:
    if s[0]=="#":
        y=[0]+y
        x=x+[0]
    else:
        y=y+[0]
        x=[0]+x
x=array(list(accumulate(x)))
y=array(list(accumulate(y[::-1]))[::-1])
print(min(x+y))

Submission status: Wrong Answer

Solution code:
stone=input()
color=input()
a=int(stone)
counter=0
counter2=0
black = 0
white = 0
xxx=[]
yyy=[]
list=[]
for i in range(a):
    list.append(color[i])
for i in range(a):
    if list[i]=='#':
        xxx.append(i)
        black += 1
    if list[i]=='.':
        yyy.append(i)
        white += 1
if white ==0 or black==0:
    print('0')
else:
    s = min(xxx)
    t = max(yyy)
    for k in range(s,a):
        if list[k]=='.' :
            counter = 1+ counter
    for j in range(0,t):
        if list[j]=='#':
            counter2 = 1 +counter2
    if counter < counter2:
        print(counter)
    else:
        print(counter2)

Submission status: Wrong Answer

Solution code:
N=input()
S=raw_input()
u=len(S)
l=0
def check(s):
  a=0
  for i in range(s):
    if S[i]=="#":
        a+=1
  for i in range(s,len(S)):
    if S[i]==".":
      a+=1
  return(a)

w=2*10**5
while True:
    m1=(l+u)/3
    if m1 == l:
        m1=l+1
    m2=(l+u)*2/3
    cm1=check(m1)
    cm2=check(m2)
    if cm1 < cm2:
        u=m2
    else:
        l=m1

    if u-l <= 6:
        for i in range(min(7, u-l)):
            w=min(w,check(l+i))
        break

print(w)