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

cnt = 0
if N == 1:
    print("0")
    exit()
else:
    for i in range(N-1):
        x = S[i]
        y = S[i+1]
        if x == "#" and y == ".":
            cnt += 1
            S = S.replace(".","#",1)
print(cnt)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sl = []
for i in range(n):
    sl += [s[i]]
cs = []
for i in range(n):
    c = sl[i:].count('.') + sl[:i].count('#')
    cs += [c]
print(min(cs))

Submission status: Wrong Answer

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

    if strs.count('#') < strs.count('.'):
        if strs[len(strs)-1] == "#":
            return strs.count("#")-1
        else:
            return strs.count("#")

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

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

    return count


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

Submission status: Wrong Answer

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

count = 0
s2=''

for i, wb in enumerate(s):
    if i != (n-1):
        if wb == '#':
            s2 = s[i:]
            break

count = s2.count('.')
print(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
                ans = min(ans, current_ans + white_count + rest_white)
                current_ans += (black_count - 1)
                white_count = 0
                black_count = 1
        else:
            if black_count > 0:
                white_count += 1
            # print('w')
            rest_white -= 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

S = str(input())

# cnt = 0
# target = S[0]
# for i in range(1, N):
#     if target == '#' and S[i] == '.':
#         cnt += 1
#         target = '#'  # 黒に変える
#         continue
#
#     if S[i] == '#':
#         target = '#'
#     else:
#         target = '.'
#
# cnt_2 = 0
# aim = S[-1]
# for i in range(N-1, -1, -1):
#     if aim == '.' and S[i] == '#':
#         cnt_2 += 1
#         aim = '.'
#         continue
#
#     if S[i] == '#':
#         aim = '#'
#     else:
#         aim = '.'
#
#
# print(int(min(cnt, cnt_2)))

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

less_color = min(black, white)
if (black <= white) and S[-1] == '#':
    less_color -= 1

print(less_color)

Submission status: Wrong Answer

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

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

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

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

res3 = N - max(b, w)

print(min(res1, res3))

Submission status: Wrong Answer

Solution code:
def read_input():
    n = int(input())
    s = input().strip()

    return n, s


def split_sentence(s):
    temp = s[0]
    result = []

    for i in range(1, len(s)):
        if temp[-1] == '.' and s[i] == '#':
            result.append(temp)
            temp = s[i]
        else:
            temp += s[i]

    result.append(temp)

    return result

def count_min_color(t):
    white = 0
    black = 0

    for c in t:
        if c == '.':
            white += 1
        else:
            black += 1

    return min(white, black)


if __name__ == '__main__':
    n, s = read_input()

    r = split_sentence(s)
    r = [count_min_color(rr) for rr in r]
    print(sum(r))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
p = 0
cnt = 0
while len(S) != 0:
    if S[p] == '#':
        p += 1
        if len(S) <= p:
            break
        elif S[p] == '.':
            cnt += 1
            del S[:p+1]
            p = 0
    else:
        del S[0]
print(cnt)

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

print(min(nuru))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if all([s[i]=="#" for i in range(n)]):
    print(0)
    exit()
if all([s[i]=="." for i in range(n)]):
    print(0)
    exit()
try:
    a=s[::-1].index("#")
    b=s.index("#")
except:a=b=0
count=0
for i in range(b+1,n-a):
    if s[i]=="#":count+=1
print(min(count,s.count("#"),s.count(".")))

Submission status: Wrong Answer

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

if S[0]=='#':
    count+=1
    S[0] = '.'
for i in range(N-2):
    if S[i]=='#' and S[i+1]=='#' and S[i+2]=='.' :
        S[i+2]='#'
        count+=1
print(count)

Submission status: Wrong Answer

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

s1 = 0
s2 = 0

for s in S:
  if s == '.':
    s1 += 1
  else:
    break
    
for s in S[::-1]:
  if s == '#':
    s2 += 1
  else:
    break

print(min(S[s1+1:].count('.'), S[:-(s2+1)].count('#')))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = input()
if b.count('#') < b.count('.'):
    print(b.count('#'))
else :
    print(b.count('.'))

Submission status: Wrong Answer

Solution code:
stone=input()
color=input()
a=int(stone)
counter=0
xxx=[9999]
list=[]
for i in range(a):
    list.append(color[i])
for i in range(a):
    if list[i]=='#':
        xxx.append(i)
if min(xxx)==9999:
    s=9999
else:
    s = min(xxx)
for k in range(s,a):
    if list[k]=='.' :
        counter = 1+ counter
if s==9999:
    print('0')
else:
    print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
flag = 0
result = 0
result2 = 0
apple = 0
for i in range(1,n):
    if s[i] == "." and s[i-1] == "#":
        flag = i
        if i == n-1:
            result += 1
    elif s[i] == "#" and s[i-1] == ".":
        if flag != 0:
            result += i-flag
            flag = 0
    elif flag != 0:
        if s[i] == "." and i == n-1:
            result += i-flag
i = 0
flag = 0

for i in range(n-1,0):
    if s[i] == "." and s[i-1] == "#":
        flag = i
        if i == n-1:
            result2 += 1
    elif s[i] == "#" and s[i-1] == ".":
        if flag != 0:
            result2 += i-flag
            flag = 0
    elif flag != 0:
        if s[i] == "." and i == n-1:
            result2 += i-flag

if result > 0 and result2 > 0:
    apple = min(result,result2)
elif result > 0 and result2 == 0:
    apple = result
elif result == 0 and result2 > 0:
    apple = result2
else:
    apple = 0

print(apple)

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
                ans = min(ans, current_ans + white_count + rest_white)
                current_ans += (black_count - 1)
                white_count = 0
                black_count = 1
        else:
            if black_count > 0:
                white_count += 1
            # print('w')
            rest_white -= 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

b=s.count('#')
# w=s.count('.')

ans=0
sflag=False
pflag=False
snum=0
pnum=0

for i in range(n):
    if s[i] == '#' and sflag and pflag:
        ans+=min(snum,pnum)
        snum=1
        pnum=0
        sflag=True
        pflag=False

    elif s[i] == '#':
        sflag = True
        snum+=1

    elif sflag == True and s[i] == '.':
        pflag=True
        pnum+=1

    elif ans>=b:
        break

#print(min(b,w))
print(min(b,ans+pnum))

Submission status: Wrong Answer

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

count=0
if S.count(".")>S.count("#"):
    for i in range(n):
        if S[n-1]==".":
            if S[n-1-i]=="#":
                count+=1
        else:
            if S[n-1-i]==".":
                for j in range(n-i):
                    if S[n-i-2-j]=="#":
                        count+=1
                        
else:
    for k in range(n):
        if S[n-1]==".":
            if S[n-1-k]==".":
                count+=1
        else:
            if S[n-1-k]=="#":
                for l in range(n-k):
                    if S[n-k-2-l]==".":
                        count+=1
                        
print(count)

Submission status: Wrong Answer

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

def inverse(b, w, index, first):
    count = b[index//2 + 1] + w[-1] - w[(index + 1)//2]
    return count

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

b = [0]
w = [0]
offset = 0
bsum = 0
wsum = 0
if first == '*':
    offset = 1
for i in range(len(num)):
    if i % 2 == offset:
        bsum += num[i]
        b.append(bsum)

offset = abs(offset -1)
for i in range(len(num)):
    if i % 2 == offset:
        wsum += num[i]
        w.append(wsum)

if len(num) == 1:
    print(0)
else:
    minlist = []
    minlist.append(sum(num[::2]))
    minlist.append(sum(num[1::2]))
    for i in range(len(num)):
        minlist.append(inverse(b, w, i, first))
    print(min(minlist))

Submission status: Wrong Answer

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

ans = N
b_list = [0]
w_list = [0]
for i, s in enumerate(S):
    if s == '#':
        b_list.append(b_list[i]+1)
    else:
        b_list.append(b_list[i])
for i, s in enumerate(reversed(S)):
    if s == '.':
        w_list.append(w_list[i]+1)
    else:
        w_list.append(w_list[i])

for i in range(1,N+1):
    ans = min(ans, b_list[i]+w_list[N-i])
print(ans)

Submission status: Wrong Answer

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

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(input_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)
        elif c == ".":
            count -= 1
    return count


pre = ""
print(func(s))

Submission status: Wrong Answer

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

if S.count('.') >= S.count('#'):
    u = 'w'
else:
    u = 'b'

res = 0
for i in range(len(S)-1):
    if S[i] == '#' and S[i+1] == '.':
        if u == 'w':
            res += 1
            S[i] = '.'
        else:
            res += 1
            S[i+1] == '#' 

print(res)

Submission status: Wrong Answer

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

def main_f():
    s = S
    # ドットの数は最初のシャープの後ろのドットの数
    first_sharp = s.find('#')
    dot_num = s[first_sharp:].count('.')
    
    # シャープの数は最後のドットより前にあるシャープの数
    s = s[::-1]
    first_dot = s.find('.')
    sharp_num = s[first_dot:].count('#')
    
    print(min(sharp_num, dot_num))
main_f()

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("#"))
elif S.count("#") == 0 or S.count(".") == 0:
  print(0)

Submission status: Wrong Answer

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

# the number of '#'
p0 = s.count('#')

# the number of '.'
p1 = n - p0

# check if '......#'
if s[-1] == '#':
    p2 = p0 - 1
else:
    p2 = p0

# check if '.#######'
if s[0] == '.':
    p3 = p1
else:
    p3 = p1 + 1

print(min([p0, p1, p2, p3]))

Submission status: Wrong Answer

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

def solve():
    N = int(input())
    S = input()

    # 全部 ############# にするパターン
    ans1 = 0
    for i in range(0, len(S)):
        if S[i] == ".":
            ans1 += 1
    
    # 全部 .............. にするパターン
    ans2 = 0
    for i in range(0, len(S)):
        if S[i] == "#":
            ans2 += 1

    # ...........########### にするパターン
    stones = []
    stones_num = []
    stone = S[0]
    num = 1
    for i in range(1, len(S)):
        if stone == S[i]:
            num += 1
            continue
        else:
            stones.append(stone)
            stones_num.append(num)
            stone = S[i]
            num = 1
    stones.append(stone)
    stones_num.append(num)
    
    ans3 = 2*(10**5)+1
    for i in range(len(stones_num)):
        ans = 0
        if stones[i] == ".":
            ans += stones_num[i]
            for j in range(i+2, len(stones_num), 2):
                ans += stones_num[j]
            for j in range(i-3, -1, -2):
                ans += stones_num[j]
        else:
            ans += stones_num[i]
            for j in range(i+3, len(stones_num), 2):
                ans += stones_num[j]
            for j in range(i-2, -1, -2):
                ans += stones_num[j]

        ans3 = min(ans3, ans)
    
    print(min(ans1, ans2, ans3))





        

        




    
    

    





if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

left = stones.find("#")

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(str(input()))
w=0
b=0
wl=[]
bl=[]
for i in range(n):
    if s[i]==".":
        w+=1
    else:
        b+=1
    wl.append(w)
    bl.append(b)
if "#" not in s or "." not in s:
    print(0)
elif s.count(".")==1 and s[0]=="#":
    print(1)
else:
    ans=[]
    for i in range(n):
        ans.append(bl[i]+wl[-1]-wl[i])
    print(min(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
# . が white
# # が black
right="#"

f_sharp = 0
for i in range(0, N):
  if S[i] == "#":
    f_sharp = i
    break

l_dot = N
for i in range(N-1, -1, -1):
  if S[i] != "#":
    l_dot = i + 1
    break


sharp = S[f_sharp:l_dot].count("#")
dot = S[f_sharp:l_dot].count(".")
print(min(sharp, dot))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
count = 0;
for j in range(2):
    for i in range(N-1):
        if S[i] == "#" and S[i+1] == ".":
            if (S[i-1] == "." and i >= 1) or (S[i+1] == "." and i == 0):
                S[i] = "."
            else:
                S[i+1] = "#"
            count += 1
print(count)

Submission status: Wrong Answer

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

ans = 0
s_count = 0
if len(S) == 1:
    print(ans)
elif len(S) == 2:
    if S == ['#', '.']:
        print("1")
    else:
        print("0")
elif len(S) == 3:
    for i in range(len(S)-1):
        if S[i] == '#' and S[i+1] == '.':
            ans += 1
    print(ans)
            
else:
    for c in S[:-1]:
        if c=='#':
            s_count += 1
    for i in range(1, len(S)-2):
        if S[i] == '#' and S[i+1] == '.':
            if S[i+2] == '.':
                if S[i-1] == '.':
                   S[i] = '.'
                if S[i-1] == '#':
                    S[i+1] = '#'
            else:
                S[i+1] = '#'
            ans += 1
            
    if S[-2:] == ['#', '.']: # -> ##
        ans += 1
    if S[:2] == ['#', '.']: # -> ..
        ans += 1

    print(min(s_count, ans, len(S)-s_count))

Submission status: Wrong Answer

Solution code:
input()
S = input()


if '#' in S:
    sharp = 0
    for c in S[::-1]:
        if c == '#':
            sharp += 1
        else:
            break
    black = S.index('#')
    print(min(S[black:].count('#') - sharp, S[black:].count('.'), sharp))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
inp_num=int(input())
inp=input()
w1=0
b1=0

bf=0
wf=0

for i in range(len(inp)):
    if inp[i]=='#' and wf==0:
        wf=1
    elif inp[i]=='#' and wf==1:
        b1=b1+1
    elif inp[i]=='.' and wf==1:
        w1=w1+1

w2=0
b2=0

for i in range(len(inp)):
    if inp[len(inp)-i-1]=='.' and bf==0:
        bf=1
    elif inp[len(inp)-i-1]=='#' and bf==1:
        b2=b2+1
#    elif inp[len(inp)-i]=='.' and bf==1:
#        w2=w2+1

line=[b1,w1,b2]
#print(line)
print(min(line))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
if ('#' not in s) or ('.' not in s):
    print('0')
else:
    black1 = s.count('#')
    white1 = s.count('.')
    for i in reversed(s):
        if i == '#':
            n -= 1
        else:
            break
    a = s.index('#')
    s1 = s[a:]
    if '.' in s1:
        white2 = s1.count('.')
        s2 = s1[:n]
        if '#' in s2:
            black2 = s2.count('#')
            print(min(white1,white2,black1,black2))
        else:
            print(min(white1,white2,black1))
    else:
        print(min(black1,white1))

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
    b_b_c = 0
    for i in range(N):
        if S[i] == w and S[i-1] == b:
            if b_b_c == 0:
                #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
        if S[i] == b:
            b_c += 1
        else:
            b_b_c = b_c
            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:
n=int(input())
s=input()

si=[]
k=[]
count = 0
flag = 0
flag2 = 0

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

        else:

            si.append(count)
            count = 1
            flag = 1
            if i == n-1:
                k.append(count)
                flag2 = 1

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


if len(si)>0:
    sa=si[0]
else:
    sa=0

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

smax = sum(si) - sa

kmax = sum(k) - ka

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

Submission status: Wrong Answer

Solution code:
N = int(input())

S = str(input())

# cnt = 0
# target = S[0]
# for i in range(1, N):
#     if target == '#' and S[i] == '.':
#         cnt += 1
#         target = '#'  # 黒に変える
#         continue
#
#     if S[i] == '#':
#         target = '#'
#     else:
#         target = '.'
#
# cnt_2 = 0
# aim = S[-1]
# for i in range(N-1, -1, -1):
#     if aim == '.' and S[i] == '#':
#         cnt_2 += 1
#         aim = '.'
#         continue
#
#     if S[i] == '#':
#         aim = '#'
#     else:
#         aim = '.'
#
#
# print(int(min(cnt, cnt_2)))

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

less_color = min(black, white)
if (black < white) and S[-1] == '#':
    less_color -= 1

print(less_color)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
counterB=0
counterW=0
for i in range(1, N):
    if S[i] == '#':
        counterB += 1
    if S[i] == '.':
        counterW += 1
if counterB == N - 1 or counterW == N - 1:
    print(0)
elif counterB < counterW:
    print(counterB)
else:
    print(counterW)

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
scount=0
ccount=0
pp=0
ll=list()
for i in b:
        ll.append(i)
if "#" in ll:
        x=ll.index("#")
        y=ll.count(".")
        z=y-x
        q=ll.count("#")
        ccount=z
        
        for i in range(int(a)):
                scount-=1
                if ll[scount] == ".":
                        break
                else:
                        pp+=1
        if q<z-pp:
                ccount=q
                ccount-=pp
                
        
print(ccount)

Submission status: Wrong Answer

Solution code:

import numpy as np

N = int(input())
s = input()

S = []
for c in s:
    S.append(c)
    
A = np.zeros(N+1)
if S[0] == "#":
    A[0] = 0 
for i in range(1,N+1):
    if S[i-1] == "#":
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]
    

minimum = N
for i in range(N+1):
    num = int(A[i] + (N-i-(A[N]-A[i])))
    if minimum > num:
        minimum = num
print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
b = [0]*(n)
w = [0]*(n)
if n == 1:
    print(0)
    exit()
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 = b[n-1]
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 = list(input())

count = 0
end = 0
for i in range(len(s)-1):
    if s[i] == '.':
        end = i
    if s[i] == '#' and s[i+1] == '.':
        if i == 0:
            s[i] = '.'
            count += 1
        elif i == len(s) -2:
            s[i+1] = '#'
            count += 1
        else:
            if s[i+2] == '.':
                if s[end:i+1].count('#') < s[i:].count('.'):
                    s[end:i] = '.' * len(s[:i])
                    count += len(s[end:i])
            elif s[i-1] == '.':
                s[i] = '.'
                count += 1
            else:
                s[i+1] = '#'
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
h=0
b=0
for i in range(n):
    if s[i]=="#":
        b+=1
    if s[i]=="." and b!=0:
        h+=1
b2=0
h2=0
for i in range(n-1,-1,-1):
    if s[i]=="#" and h2!=0:
        b2+=1
    if s[i]==".":
        h2+=1

print(min(h,b2))

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
s=[s[i] for i in range(len(s))]
tmp=N
for i in range(N):
    count=0
    for j in range(N):
        if j<=i and s[j]=="#":
                count=count+1
       	else:
            if s[j]==".":
                count = count+1
    if tmp>count:
        tmp=count
print(tmp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    S = list(_ for _ in input())

    S_num = []
    index = 0 
    now = ''
    if(S[0]=='#'):
        S_num.append(1)
        now = '#'
    else:
        S_num.append(-1)
        now = '.'
        
    for i in range(1,N):
        if(S[i]=='#' and now =='#'):
            S_num[index] +=1
        elif(S[i]=='.' and now =='.'):
            S_num[index] +=-1
        elif(S[i]=='#' and now !='#'):
            S_num.append(1)
            now = '#'
            index +=1
        elif(S[i]=='.' and now !='.'):
            S_num.append(-1)
            now = '.'
            index +=1
    # print(S_num)
    ans = 0
    b = 0
    w = 0
    # ###.#.. → 3,-1,1,-2 → 5,-2
    # #...#.. → 1,-3,1,-2 → 1,-2
    for i in range(len(S_num)-1):
        if(S_num[i]>0 and S_num[i+1]<0):
            b += S_num[i]
            w += -S_num[i+1]
            # ans += min(S_num[i],-S_num[i+1])
            # if((S_num[i] > -S_num[i+1]) and i+2 < len(S_num)-1):
            #     S_num[i+2] += S_num[i] -S_num[i+1]
    ans = min(b,w)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
i = 0
count = 0
for i in range(N):
    if(S[i:i+2] == "#."):
        count += 1
        i += 1
    else:
        i += 1
print(count)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S1 = list(input())
S2 = copy.copy(S1)
count1 = 0
count2 = 0
for i in range(N - 1):
    if S1[i] == "#" and S1[i + 1] == ".":
        S1[i + 1] = "#"
        count1 += 1

for i in range(N-1, 0, -1):
    if S2[i-1] == "#" and S2[i] == ".":
        S2[i-1] = "."
        count2 += 1
print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
ans = stdin.readline().rstrip()
count = 0
list = ans.split("#")
if len(list) == 1:
    print(0)
    exit()
for itr in list:
    if itr:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
k,d = 0,0
s = list(input())

if s[0] == '.':
  c = 0
  for j in s:
    if j == '.':
      c+=1
    else:
      break
  r = 0    
  if s[n-1] == '#':
    for p in range(n-1,0,-1):
      if s[p] == "#":
        r += 1
      else:
        break
      
  for i in range(c,n-r):
    if s[i] == '#':
      k+=1
    else:
      d+=1
  
  
else:
  r = 0
  if s[n-1] == '#':
    for o in range(n-1,0,-1):
      if s[o] == "#":
        r += 1
      else:
        break

  for m in range(n-r):
    if s[m] == '#':
      k+=1
    else:
      d+=1
print(min(k,d))

Submission status: Wrong Answer

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

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

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

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

res3 = N - max(b, w)

print(min(res1, res3))