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

black_sum = [0]*(N+1)
white_sum = [0]*(N+1)
ans = 9999999999999999999
for i in range(N):
    key_black = 0
    key_white = 0
    if S[i]=='#':
        key_black = 1
    else:
        key_white = 1

    black_sum[i+1]=black_sum[i]+key_black
    white_sum[i+1]=white_sum[i]+key_white

for i in range(1,len(black_sum)):
    if black_sum[i] != black_sum[i-1]:
        left = black_sum[i] - 1 #境界左の黒石の数
        right = white_sum[-1]-white_sum[i]  #境界右の白石の数
        tmp = left + right
        ans = min(tmp,ans)
if ans ==9999999999999999999:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input())
ans = 0
for i in range(1,n):
    left =  S[0:i]
    right = S[i:0]
    if left.count('.') + right.count('#') < ans:
        ans = left.count('.') + right.count('#')

print(ans)

Submission status: Wrong Answer

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

x = 0
while S[x] == ".":  #左側から連続した白の個数
  x += 1
  if x == N:
    break

yindex = N - 1
ycount = 0
while S[yindex] == "#":  #右側から連続した黒の個数
  yindex -= 1
  ycount += 1
  if yindex == -1:
    break

w = 0
b = 0
for j in range(N):
  if S[j] == ".":  #白の個数
    w += 1
  else:            #黒の個数
    b += 1
    
if w - x <= b - ycount:  #裏返すべき石の数
  print(w - x)
else:
  print(b - ycount)

Submission status: Wrong Answer

Solution code:
#C 
n = int(input())
stones = input()
score = stones.count(".")
r = score
for i in range(n):
	if stones[i] == ".":
		r -= 1
	else:
		r += 1
	result = (min(r, score))
print(result)

Submission status: Wrong Answer

Solution code:
#C - Stones
#黒い石のすぐ右に白い石があるような箇所がないようにしたいです。 

n = int(input())
stones = input()
score = stones.count(".")
#frac = []
for i in range(n):
	#sum_loss = stones[:i].count("#") + stones[i:].count(".")
	#frac.append(sum_loss)
	if stones[i] == ".":
		score -= 1
	else:
		score += 1
	result = (min(stones.count("."), score))

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
lis = []
rtmp = 0
ltmp = 0
tmp = 0
na = len(s)
for i in range(n-1):
    if s[i] == '#' and s[i+1] == '.' or s[i] == '.' and s[i+1] == '#':
        #clis+= 1
        #print(i)
        rtmp = i+1
        ltmp = i
        for j in range(ltmp):
            if s[j] == '#':
                tmp += 1
        for j in range(rtmp,na):
            if s[j] == '.':
                tmp += 1
        lis.append(tmp)
    rtmp = 0
    ltmp = 0
    tmp = 0

if len(lis) == 0: 
    print(0)
else:
    print(min(lis))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = [0] * (n + 1)
w = [0] * (n + 1)

for i, v in enumerate(s, start=1):
    if v == '#':
        b[i] = b[i-1] + 1
        w[i] = w[i-1]
    else:
        b[i] = b[i-1]
        w[i] = w[i-1] + 1

wn = [w[-1] - i for i in w]

Submission status: Wrong Answer

Solution code:
#C - Stones
#黒い石のすぐ右に白い石があるような箇所がないようにしたいです。 

n = int(input())
stones = input()
score = stones.count(".")
#frac = []
for i in range(n):
	#sum_loss = stones[:i].count("#") + stones[i:].count(".")
	#frac.append(sum_loss)
	if stones[i] == ".":
		score -= 1
	else:
		score += 1
print(min(stones.count("."), score))

Submission status: Wrong Answer

Solution code:
g = int(input())
h = input()

count_list = []
min_count = g
for i in range(0, g+1):
    count = h[:i].count('#') + h[i:].count('.')
    if count == 0:
        break
    if min_count > count:
        min_count = count
print(count)

Submission status: Wrong Answer

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

tmp = True
ct = 0
ct2 = 0

for i in range(N):
    if tmp and S[i] == '#':
        tmp = False
    elif tmp and S[i] == '.':
        ct2 += 1
    if not tmp and S[i] == '.':
        ct += 1

print(min(ct,N-ct2-ct))

Submission status: Wrong Answer

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

tmp = True
ct = 0
ct2 = 0

for i in range(N):
    print(i,S[i],tmp)
    if tmp and S[i] == '#':
        tmp = False
    elif tmp and S[i] == '.':
        ct2 += 1
    if not tmp and S[i] == '.':
        ct += 1

print(min(ct,N-ct2-ct))

Submission status: Wrong Answer

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

black_sum = [0]*(N+1)
white_sum = [0]*(N+1)
ans = 9999999999999999999
for i in range(N):
    key_black = 0
    key_white = 0
    if S[i]=='#':
        key_black = 1
    else:
        key_white = 1

    black_sum[i+1]=black_sum[i]+key_black
    white_sum[i+1]=white_sum[i]+key_white

for i in range(1,len(black_sum)):
    if black_sum[i] != black_sum[i-1]:
        left = black_sum[i] - 1 #境界左の黒石の数
        right = white_sum[N]-white_sum[i]  #境界右の白石の数
        tmp = left + right
        ans = min(tmp,ans)
if ans ==9999999999999999999:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
def chec(s):
    lis = []
    rtmp = 0
    ltmp = 0
    tmp = 0
    na = len(s)
    for i in reversed(range(0,na-1)):
        if s[i] == '#' and s[i+1] == '.' or s[i] == '.' and s[i+1] == '#':
            #clis+= 1
            #print(i)
            rtmp = i+1
            ltmp = i
            for j in range(ltmp):
                if s[j] == '#':
                    tmp += 1
            for j in range(rtmp,na):
                if s[j] == '.':
                    tmp += 1
            lis.append(tmp)
        rtmp = 0
        ltmp = 0
        tmp = 0
    
    if len(lis) == 0: 
        return 0
    else:
        return min(lis)

n = int(input())
s = list(input())
print(chec(s))

Submission status: Wrong Answer

Solution code:
n = int(input());s = input();print(min(s.count("#"), s.count(".")))

Submission status: Wrong Answer

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

tmp = True
ct = 0

for i in range(N):
    if tmp and S[i] == '#':
        tmp = False
    if not tmp and S[i] == '.':
        ct += 1

print(min(ct,N-ct))

Submission status: Wrong Answer

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

tmp = True
ct = 0

for i in range(N):
    print(i,S[i],tmp)
    if tmp and S[i] == '#':
        tmp = False
    if not tmp and S[i] == '.':
        ct += 1

print(min(ct,N-ct))

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

black_sum = [0]*(N+1)
white_sum = [0]*(N+1)
ans = 100000000000
for i in range(N):
    key_black = 0
    key_white = 0
    if S[i]=='#':
        key_black = 1
    else:
        key_white = 1

    black_sum[i+1]=black_sum[i]+key_black
    white_sum[i+1]=white_sum[i]+key_white

for i in range(1,len(black_sum)):
    if black_sum[i] != black_sum[i-1]:
        left = black_sum[i] - 1 #境界左の黒石の数
        right = white_sum[N]-white_sum[i]  #境界右の白石の数
        tmp = left + right
        ans = min(tmp,ans)
if ans ==100000000000:
    ans = 0
print(ans)

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:
    y=[0]+y
    x=x+[0]

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 = input()
if s.count("#") == 0:
    print(0)
    exit()

ans = 0
state = False
for _s in s:
    if _s == '#':
        state = True
    elif _s == '.' and state:
        ans += 1

print(ans)

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:
    y=[0]+y
    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 = input()
sharp = []
for i, c in enumerate(s):
  if c == "#": sharp.append(i)
sharp.append(n)
ans1 = 0
for i in range(len(sharp)-1): ans1 += sharp[i+1] - sharp[i] - 1

dot = []
for i, c in enumerate(reversed(s)):
    if c == ".": dot.append(i)
dot.append(n)
ans2 = 0
for i in range(len(dot)-1): ans2 += dot[i+1] - dot[i] - 1

print(min(ans1, ans2))

Submission status: Wrong Answer

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

count_black = 0
count_white = 0
cnt_white = [0] * n
cnt_black = [0] * n
result = []

for i in range(n):
    if s[i] == ".":
        count_white += 1

for i in range(n):
    if s[i] == "#":
        count_black += 1
    else:
        count_white -= 1
    cnt_white[i] = count_white
    cnt_black[i] = count_black

for i in range(n):
    result.append(cnt_black[i] + cnt_white[i])

ans = min(result)

print(ans)

Submission status: Wrong Answer

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

black_sum = [0]*(N+1)
white_sum = [0]*(N+1)
ans = 100000000000
for i in range(N):
    key_black = 0
    key_white = 0
    if S[i]=='#':
        key_black = 1
    else:
        key_white = 1

    black_sum[i+1]=black_sum[i]+key_black
    white_sum[i+1]=white_sum[i]+key_white

for i in range(1,len(black_sum)):
    if black_sum[i] != black_sum[i-1]:
        if i == 1:
            left = 0
        else:
            left = black_sum[i] #境界左の黒石の数
        right = white_sum[N]-white_sum[i]  #境界右の白石の数
        tmp = left + right
        ans = min(tmp,ans)
if ans ==100000000000:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().rstrip('#').lstrip('.')
numW = S.count('.')
numB = S.count('#')
print(min(numW,numB))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=input()
l1=[]
c=0
for i in range(n):
  if l[i]=="#":
    c+=1
  l1.append(c)
l2=[]
for i in range(n):
  l2.append(n-(i+1)-(c-l1[i])+l1[i])
print(min(l2))

Submission status: Wrong Answer

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

x = 0
while S[x] == ".":
  x += 1
  if x == N:
    break

yindex = N - 1
ycount = 0
while S[yindex] == "#":
  yindex -= 1
  ycount += 1
  if yindex == -1:
    break

w = 0
b = 0
for j in range(N):
  if S[j] == ".":
    w += 1
  else:
    b += 1
    
if w - x <= b - ycount:
  print(w - x)
else:
  print(b - ycount)

Submission status: Wrong Answer

Solution code:

n = input()
s = input()
s_list = list(s)
dot_cnt =0
sharp_cnt = 0
include = 1
for i in range(0, len(s_list)-1):
    # print("i", i)
    if (s_list[i] == "#") and (s_list[i+1] == "."):
        if (i+1) == (len(s_list)-1):
            dot_cnt += 1
        else:
            for h in range(1,(len(s_list)-1)-(i+1) + include):
                # print("h", h)
                # if (i+1)+h == len(s_list):
                #     dot_cnt += h-1
                #     # print("dot_cnt_over", dot_cnt)
                #     break
                if s_list[i+1+h] == "#":
                    dot_cnt += h
                    # print("dot_cnt", dot_cnt)
                    break
                if h == ((len(s_list)-1)-(i+1)) :
                    dot_cnt += (len(s_list)-1) - i
                    # print("dot_cnt_over", dot_cnt)
                # if i+h == len(s_list)-1:
                #     dot_cnt += h+1
                #     break
for i in range(1, len(s_list)):
    if (s_list[i] == ".") and (s_list[i-1] == "#"):
        if (i-1) == 0:
            sharp_cnt += 1
        else:
            for j in reversed(range(0,i-1)):
                if s_list[j] == ".":
                    sharp_cnt += (i-1)-j
                    break
                if j == 0:
                    sharp_cnt += i
                    break

print(min(dot_cnt, sharp_cnt))

Submission status: Wrong Answer

Solution code:

n = input()
s = input()
s_list = list(s)
dot_cnt =0
sharp_cnt = 0
include = 1
for i in range(0, len(s_list)-1):
    print("i", i)
    if (s_list[i] == "#") and (s_list[i+1] == "."):
        if (i+1) == (len(s_list)-1):
            dot_cnt += 1
        else:
            for h in range(1,(len(s_list)-1)-(i+1) + include):
                print("h", h)
                # if (i+1)+h == len(s_list):
                #     dot_cnt += h-1
                #     # print("dot_cnt_over", dot_cnt)
                #     break
                if s_list[i+1+h] == "#":
                    dot_cnt += h
                    print("dot_cnt", dot_cnt)
                    break
                if h == ((len(s_list)-1)-(i+1)) :
                    dot_cnt += (len(s_list)-1) - i
                    print("dot_cnt_over", dot_cnt)
                # if i+h == len(s_list)-1:
                #     dot_cnt += h+1
                #     break
for i in range(1, len(s_list)):
    if (s_list[i] == ".") and (s_list[i-1] == "#"):
        if (i-1) == 0:
            sharp_cnt += 1
        else:
            for j in reversed(range(0,i-1)):
                if s_list[j] == ".":
                    sharp_cnt += (i-1)-j
                    break
                if j == 0:
                    sharp_cnt += i
                    break

print(min(dot_cnt, sharp_cnt))

Submission status: Wrong Answer

Solution code:
#C
N = int(input())
S = str(input())
sign = ('.', '#') #w,b
if N == 1:
    print(0)
else:
    c1, c2 = 0, S.count('.')
    ans = c1 + c2
    for i in range(0,N):
        print(c1, c2)
        if S[i] == '#':
            c1 += 1
        else:
            c2 -= 1
        tmp = c1 + c2
        ans = min(ans, tmp)
    print(ans)

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 (i == '#' and prev ==''):
        b += 1
    elif (i == '.' and prev == '.') or (i == '.' and 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)
else:
    pattern.append(w)

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)
elif (len(pattern) == 2 and start == '#'):
    print(min(totalw, totalb))
elif start == '.' and prev == "#":
    print(min(totalw - pattern[0], totalb - pattern[-1]))
elif start == '.':
    print(min(totalw - pattern[0], totalb))
else:
    print(min(totalw, totalb))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
b=0
w_2=0
w=0
f_b=-1
for i in range(N):
    if S[i]=='.':
        w+=1
        if f_b!=-1:
            w_2+=1
    else:
        b+=1
        if f_b==-1:
            f_b=i
print(min(N-w,N-b,w_2))

Submission status: Wrong Answer

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

ans=0

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

Submission status: Wrong Answer

Solution code:
n = int(input());s = input()
sharp = []
for i, c in enumerate(s):
  if c == "#": sharp.append(i)
sharp.append(n)
ans = 0
for i in range(len(sharp)-1): ans += sharp[i+1] - sharp[i] - 1
print(ans)

Submission status: Wrong Answer

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

tmp = True
ct = 0

for i in range(N):
    if tmp and S[i] == '#':
        tmp = False
    if not tmp and S[i] == '.':
        ct += 1

print(ct)

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)
else:
    pattern.append(w)

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 s[0] == '.':
        totalw -= pattern[0]
    if s[n-1] == '#':
        totalb -= pattern[len(pattern)-1]

    print(min(totalw, totalb))

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 (i == '#' and prev ==''):
        b += 1
    elif (i == '.' and prev == '.') or (i == '.' and 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)
else:
    pattern.append(w)

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)
elif (len(pattern) == 2 and start == '#'):
    print(min(totalw, totalb))
else:
    print(min(totalw - pattern[0], totalb - pattern[-1]))

Submission status: Wrong Answer

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

tmp = True
ct = 0

for i in range(N):
    if tmp and S[i] == '#':
        tmp = False
    if S[i] == '.':
        ct += 1

print(ct)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = 'a'+input()+'a'
ans = 10**9
key = 'b'

for i in range(1,N+2):
    if key != S[i]:
        ans = min(ans,S[:i].count('#')+S[i:].count('.'))
        key = S[i]
        print(S[:i].count('#'),S[i:].count('.'))
print(ans)

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)
else:
    pattern.append(w)

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 == '.':
        print(min(totalw - pattern[0], totalb))
    else:
        print(min(totalw, totalb))

Submission status: Wrong Answer

Solution code:
#C
N = int(input())
S = str(input())
sign = ('.', '#')
if N == 1:
    print(0)
else:
    c1, c2 = S.count('#'), 0
    ans = c1 + c2
    for i in range(0,N):
        if S[i] == '#':
            c1 -= 1
        else:
            c2 += 1
        tmp = c1 + c2
        ans = min(ans, tmp)
    print(ans)

Submission status: Wrong Answer

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

black_sum = [0]*(N+1)
white_sum = [0]*(N+1)
ans = 100000000000
for i in range(N):
    key_black = 0
    key_white = 0
    if S[i]=='#':
        key_black = 1
    else:
        key_white = 1

    black_sum[i+1]=black_sum[i]+key_black
    white_sum[i+1]=white_sum[i]+key_white
for i in range(1,len(black_sum)):
    if black_sum[i]-black_sum[i-1] != 0:
        left = black_sum[i] #境界左の黒石の数
        right = white_sum[-1]-white_sum[i]  #境界右の白石の数
        tmp = left + right
        ans = min(tmp,ans)
if ans ==100000000000:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=input()
l1=[]
l2=[]
rw=0
lb=0
for i in range(n):
  if l[i]=="#":
    lb+=1
  l1.append(lb)
  if l[n-1-i]==".":
    rw+=1
  l2.append(rw)
l2=l2[::-1]
l3=[]
for i in range(n):
  l3.append(l1[i]+l2[i])
print(min(min(l3),len(l)-rw,len(l)-lb))

Submission status: Wrong Answer

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

index = 0
counter = 0
while index < N:
    if S[index] == '#':
        offset = 1
        while index + offset < N and S[index + offset] == '#':
            offset += 1

        if index + offset >= N:
            break
        else:
            count = 1
            memory = offset
            offset += 1
            while index + offset < N and S[index + offset] == '.':
                count += 1
                offset += 1
            counter += count if count < memory else memory
            index += offset
    else:
        index += 1
print(str(counter))

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 (i == '#' and prev ==''):
        b += 1
    elif (i == '.' and prev == '.') or (i == '.' and 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(w)

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:
    print(min(totalw, totalb))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
b=0
w=0
for i in range(N):
    if S[i]=='.':
        w+=1
    else:
        b+=1
e=S[-1]
if e=='.':
    print(min(N-w,N-b))
else:
    print(min(N-w-1,N-b))

Submission status: Wrong Answer

Solution code:
#C
N = int(input())
S = str(input())
sign = ('.', '#')
ans = 2*10**5
if N == 1:
    print(0)
else:
    for i in range(1,N):
        ls, rs = S[:i], S[i:]
        c1 = ls.count('#')
        c2 = rs.count('.')
        tmp = c1 + c2
        ans = min(ans, tmp)
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
b = []
nb = 0
w = []
nw = 0
for s_ in s:
  if s_ == "#":
    nb += 1
  if s_ == ".":
    nw += 1
  b.append(nb)
  w.append(nw)
ans = []
#print(b)
#print(w)
for i in range(n):
  if i == n-1 and s[i] == ".":
    ans.append(b[i]+1)
  elif i == 0:
    ans.append(w[n-1])
  else:
    ans.append(b[i-1]+w[n-1]-w[i-1])
#print(ans)
if n == 1:
  print("0")
else:
  print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
wtob_res = 0
wtob_flag = False
btow_res = 0
btow_flag = False
for i in range(n):
  wtob_flag = wtob_flag or s[i] == '#'
  if wtob_flag and s[i] == '.':
    wtob_res += 1
  btow_flag = btow_flag or s[n - 1 - i] == '.'
  if btow_flag and s[n - 1 - i] == '#':
    btow_res += 1
    
print(min(btow_res, wtob_res))

Submission status: Wrong Answer

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

cum_sum_b = [0]
cum_sum_w = [0]

sum_b = 0
sum_w = 0
for i, s in enumerate(S):
    if s == '#':
        sum_b += 1
    else:
        sum_w += 1
    cum_sum_b.append(sum_b)
    cum_sum_w.append(sum_w)

ans = N
for i in range(1, len(S)):
    count = cum_sum_b[i] + cum_sum_w[len(S)] - cum_sum_w[i]
    ans = min(ans, count)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()                                                                                                                                                                                                                                                                                                                                                                                                                                            
list_S = list(S)
N1 = 0
X1 = 0
X2 = 0
for color in list_S:
    if color == '.':
            N1 +=1
    else:
        list_S1 = list_S[N1:]
        X1 = list_S1.count('#')
        X2 = list_S1.count('.')
        break

if X1 > X2:
    print(X2)
else:
    print(X1)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
A=S
B=S[:: -1]
ans1=0
ans2=0

for i in range(N-1):
  if A[i]=='#' and A[i+1]=='.':
    A[i+1]='#'
    ans1 += 1

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

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
b = []
nb = 0
w = []
nw = 0
for s_ in s:
  if s_ == "#":
    nb += 1
  if s_ == ".":
    nw += 1
  b.append(nb)
  w.append(nw)
ans = []
#print(b)
#print(w)
for i in range(n):
  if i == n-1 and s[i] == ".":
    ans.append(b[i]+1)
  elif i == 0 and s[i] == "#":
    ans.append(w[n-1]-w[i])
  else:
    ans.append(b[i-1]+w[n-1]-w[i-1])
#print(ans)
if n == 1:
  print("0")
else:
  print(min(ans))

Submission status: Wrong Answer

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

N = int(input())
S = [int(x) for x in input().replace('#', '1').replace('.', '0')]

b_cumsum = numpy.cumsum(S)
b_total = b_cumsum[-1]

min_count = N
for i in range(N):

    # for white
    w_num = i + 1
    # w_cur = w_num - res[i]
    w_rev_num = b_cumsum[i]  # w_num - w_cur

    # for black
    b_num = N - w_num
    b_cur = b_total - b_cumsum[i]
    min_count = min(min_count, w_rev_num + b_num - b_cur)

print(min_count)

Submission status: Wrong Answer

Solution code:
#C
N = int(input())
S = str(input())
sign = ('.', '#')
cnt1 = S.count('#')
cnt2 = S.count('.')
tmp = S
for i in range(N):
    if S[i] == '#':
        tmp = S[i:]
        break
cnt3 = tmp.count('.')
print(min(cnt1, cnt2, cnt3))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
b = []
nb = 0
w = []
nw = 0
for s_ in s:
  if s_ == "#":
    nb += 1
  if s_ == ".":
    nw += 1
  b.append(nb)
  w.append(nw)
ans = []
#print(b)
#print(w)
for i in range(n):
  if i == n-1 and s[i] == ".":
    ans.append(b[i]+1)
  elif i == 0 and s[i] == "#":
    ans.append(w[n-1]-w[i])
  else:
    ans.append(b[i]+w[n-1]-w[i])
#print(ans)
if n == 1:
  print("0")
else:
  print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = 0
b = 0
for i in range(0,n) :
    if s[i] == '.' :
        continue
    elif s[i] == '#' :
        a = i
        break
s = s[a:n]
for j in range(1,n-a+1) :
    if s[-j] == '.' :
        b = j
        break
    elif s[-j] == '#' :
        continue
s = s[0:n-a-b+1]
x = s.count('#')
y = s.count('.')
print(min(x,y))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
x = 0
w = 0
b = 0
while S[x] == ".":
  x += 1
  if x == N:
    break
j = 0
for j in range(N):
  if S[j] == ".":
    w += 1
  else:
    b += 1
if w - x <= b:
  print(int(w - x))
else:
  print(int(b))

Submission status: Wrong Answer

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

ct = 0
if N >= 2:
    if S[0] != S[1]:
        ct += 1

    for i in range(N):
        if i % 4 <= 1:
            if S[i] != S[1]:
                ct += 1
        else:
            if S[i] == S[1]:
                ct += 1

print(ct)

Submission status: Wrong Answer

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

ans = N
for i in range(1, N):
    if lS[i] != lS[i-1]:
        left = lS[:i].count('#')
        right = lS[i:].count('.')
        ans = min(ans, left+right)

if ans == N:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
#C
N = int(input())
S = str(input())
sign = ('.', '#')
tmp = str(S)
for i in range(N):
    if S[i] == '#':
        tmp = S[i:]
        break
cnt1 = tmp.count('#')
cnt2 = tmp.count('.')
print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
b = []
nb = 0
w = []
nw = 0
for s_ in s:
  if s_ == "#":
    nb += 1
  if s_ == ".":
    nw += 1
  b.append(nb)
  w.append(nw)
ans = []
#print(b)
#print(w)
for i in range(n):
  if i == n-1 and s[i] == ".":
    ans.append(1)
  else:
    ans.append(b[i]+w[n-1]-w[i])
#print(ans)
if n == 1:
  print("0")
else:
  print(min(ans))

Submission status: Wrong Answer

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

bi=0
wi=0
b=[]
w=[]
for i in range(n):
	if sl[i] == "#":
		bi = bi+1
	else:
		wi = wi+1
	b.append(bi)
	w.append(wi)

c=0
res=2*10**5
for i in range(n-1):
	if sl[i]=="#" and sl[i+1]==".":
		c = b[i] + w[n-1]-w[i]
		#print(c)
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]
if w0<res:
	res=w0
if b0<res:
	res=b0

print(res)
#print(w)
#print(b)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
x = 0
w = 0
b = 0
while S[x] == ".":
  x += 1
  if x == N:
    break
j = 0
for j in range(N):
  if S[j] == ".":
    w += 1
  else:
    b += 1
if w - x <= b:
  print(w - x)
else:
  print(b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

shiro_num = s.count(".")
kuro_num = n - shiro_num

right_kuro_num = kuro_num
right_siro_num = shiro_num

result = kuro_num

for e in s:
    if e == '.':
        right_siro_num -= 1
    else:
        right_kuro_num -= 1
    num = right_siro_num + kuro_num - right_kuro_num
    result = min(num,result)

print(result)