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:
from __future__ import print_function
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


n=int(input())
S=list(input())

cnt_temp=0
stack=[]
cnt=0

# # eprint(n)
# # eprint(S)

# for i in range(n):
#     # eprint(i)


# flag=0
# flag2=0
start=0




if S[0] == '.':
    for i in range(n-1):
        if S[i]=='#' and S[i+1]=='.':
            for j in range(i+1,n):
                if S[j] =='.':
                    cnt_temp+=1
            break
else:
    for i in range(n):
        if S[i] == '.':
            cnt_temp+=1

        
for _ in S:
    print( _ , end="")
print()
        
for i in range(n-1):
    if S[i]=='#' and S[i+1]=='#':
        stack.append(i)
    elif S[i]=='#' and S[i+1]=='.':
        
        S[i]='.'
        cnt+=1
        
        # for _ in S:
            # eprint(_,end="")
        # eprint()
        
        
        
        while stack!=[]:
            temp=stack.pop()
            S[temp]='.'
            cnt+=1
            # for _ in S:
                # eprint(_,end="")
            # eprint()

            
        
eprint("cnt: ",end="")
eprint(cnt)
# eprint("cnt_temp2: ",end="")
# eprint(cnt_temp2)

print(min(cnt,cnt_temp))
            #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
black = 0
white = 0
black2 = 0
white2 = 0
k = 0
ans = 0
for i in range(N - 1):
    if S[i] == "#" and S[i + 1] == ".":
        # print(i, ans, black, white)
        if ans == 0:
            black = S[:i + 1].count("#")
            white = S[i + 1:].count(".")
            ans += min(black, white)
            k = i
        elif ans >= 1:
            # print( S[k+1:i + 1])
            black2 = S[k+1:i + 1].count("#")
            white2 = S[k+1:i + 1].count(".")
            # print(black2,white2)
            ans += min(black2,white2)
            # black += black2
            # white -= white2
            k = i
        # print(i, ans, black, white)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(N,S):
	border = N
	for i in range(N):
		if(S[i]=='#'):
			border = i
			break
	counter = 0
	for i in range(border, N):
		if(S[i]=='.'):
			counter +=1
	return counter



if __name__ == '__main__':
	N = int(input())
	S = input()
	print(solve(N,S))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
black = 0
white = 0
black2 = 0
white2 = 0
k = 0
ans = 0
for i in range(N - 1):
    if S[i] == "#" and S[i + 1] == ".":
        if k == 0:
            black = S[:i + 1].count("#")
            white = N-black
            ans += min(black, white)
            k = 1
        elif k == 1:
            black2 = S[:i + 1].count("#")
            white2 = N-black2
            ans += min(black2 - black, white - white2)
            black = black2
            white = white2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
i = 0
for i in range(N):
    if S[i] == '#':
        break

T = S[i:]
W = T.count('.')

cntB = 0
cntW = 0
excntB = 0
B = 0
j = 0
for j in range(N - i):
    if T[j] == '#':
        excntB = B
        cntB += 1
        cntW = 0
    else:
        B = cntB
        cntW += 1

print(min(B, W, excntB + cntW))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
i = 0
for i in range(N):
    if S[i] == '#':
        break

T = S[i:]
W = T.count('.')

cnt = 0
B = 0
j = 0
for j in range(N - i):
    if T[j] == '#':
        cnt += 1
    else:
        B = cnt

print(min(B, W))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
i = 0
for i in range(N):
    if S[i] == '#':
        break

T = S[i:]
print(T)
W = T.count('.')

cnt = 0
B = 0
j = 0
for j in range(N - i):
    if T[j] == '#':
        cnt += 1
    else:
        B = cnt

print(min(B, W))

Submission status: Wrong Answer

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

T = S[i - 1:]
W = T.count('.')

cnt = 0
B = 0
j = 0
for j in range(N - i + 1):
    if T[j] == '#':
        cnt += 1
    else:
        B = cnt
    j += 1

print(min(B, W))

Submission status: Wrong Answer

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

T = S[i - 1:]
W = T.count('.')

cnt = 0
x = 0
j = 0
for j in range(N - i + 1):
    if T[j] == '#':
        cnt += 1
    else:
        x = cnt

print(min(x, W))

Submission status: Wrong Answer

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

T = S[i - 1:]
W = T.count('.')

cnt = 0
x = 0
for j in range(N - i - 1):
    if T[j] == '#':
        cnt += 1
    else:
        x = cnt

print(min(x, W))

Submission status: Wrong Answer

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

T = S[i - 1:]
W = T.count('.')

cnt = 0
x = 0
for i in range(i, N):
    if S[i] == '#':
        cnt += 1
    else:
        x = cnt

print(min(x, W))

Submission status: Wrong Answer

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

T = S[i - 1:]

B = T.count('#')
W = T.count('.')

if  S[i - 1] == '#' and B <= W:
    print(min(B, W) - 1)
else:
    print(min(B, W))

Submission status: Wrong Answer

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

T = S[i:]

B = T.count('#')
W = T.count('.')

print(min(B, W))

Submission status: Wrong Answer

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

T = S[i - 1:]

B = T.count('#')
W = T.count('.')

print(min(B, W))

Submission status: Wrong Answer

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

j = i

for i in range(j, N):
    if S[i] == '.':
        cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
min = N
# '#'の累積和
clm_sum = [0]
for s in S:
    if s == '#':
        clm_sum.append(clm_sum[-1] + 1)
    else:
        clm_sum.append(clm_sum[-1])
if S.find('#') == -1 or S.find('.') == -1:
    min = 0
for i in range(1,len(clm_sum)):
    if clm_sum[i] + (N - i - (clm_sum[-1] - clm_sum[i])) < min:
        min = clm_sum[i] + (N - i - (clm_sum[-1] - clm_sum[i]))
print(min)

Submission status: Wrong Answer

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

sm_w = [0]*(N+1)
sm_b = [0]*(N+1)

for i in range(N):
    s = S[i]
    sm_w[i+1] += sm_w[i]
    sm_b[i+1] += sm_b[i]
    if s == '.':
        sm_w[i+1] += 1
    else:
        sm_b[i+1] += 1

ans = 2**12
for i in range(N+1):
    left_b = 0
    if i!=0:
        left_b = sm_b[i]
    right_w = 0
    if i!=N:
        right_w = sm_w[N] - sm_w[i]
    ret = left_b + right_w
    ans = min(ans, ret)
print(ans)

Submission status: Wrong Answer

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

w_sum = [0]
b_sum = [0]
for i in range(len(s)):
    if s[i] == '.':
        w_sum.append(w_sum[-1] + 1) 
        b_sum.append(b_sum[-1])
    else:
        b_sum.append(b_sum[-1] + 1)
        w_sum.append(w_sum[-1])

assert len(w_sum) == len(b_sum)

minSum = 10 ** 5
for i in range(1, len(s)):
    minSum = min(minSum, b_sum[i - 2] + (w_sum[-1] - w_sum[i-2]))
    
print(minSum)

# .##...####... ->
# ......#######

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=0
i=-1
while i!=-n:
    wnum=0
    bnum=0
    while s[i]=='.':
        wnum+=1
        if i==-n:
            break
        else:
            i-=1
    while s[i]=='#':        
        bnum+=1
        if i==-n:
            break
        else:
            i-=1
    cnt+=min(bnum,wnum)
print(cnt)

Submission status: Wrong Answer

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

if s.count('#') < s.count('.'):
    cnt += s.count('#')
else:
    cnt += s.count('.')
    if s.startswith('.'):
        cnt -= 1

if '#' not in s:
    cnt = 0
elif '.' not in s:
    cnt = 0

print(cnt)

Submission status: Wrong Answer

Solution code:
# 2019/04/21
# Tenka1 Programming Contest 2019 - C

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

bl = [0] * (n+1)
wl = [0] * (n+1)

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

# calc minimum Left black and Right white
mins = 10**6
for i in range(1, n+1):
    wks = bl[i] + (wl[n] - wl[i])
    if mins > wks:
        mins = wks

print(mins)

Submission status: Wrong Answer

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

if s.count('#') <= s.count('.'):
    print(s.count('#'))
else:
    print(s.count('.'))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
white = s.count(".")
black = s.count("#")

color_dict = [{"w": 0, "b": 0} for x in range(n)]
for index in range(n):
    if s[index] == ".":
        color_dict[index]["w"] += 1 if index == 0 else color_dict[index-1]["w"] + 1
        color_dict[index]["b"] = color_dict[index-1]["b"]
    else:
        color_dict[index]["b"] += 1 if index == 0 else color_dict[index-1]["b"] + 1
        color_dict[index]["w"] = color_dict[index-1]["w"]

res = float("inf")
for colors in color_dict:
    w = colors["w"]
    b = colors["b"]
    res = min(res, b+(white-w))
print(res)

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if n<=20:
  print(0)
else:
  t=0
  while t<=2:
    t=t

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if n<=100000:
  print(0)
else:
  t=0
  while t<=2:
    t=t

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
sint = [0]
si = 0
prev = S[0]

for s in S:
    if prev == s:
        sint[si] = sint[si] + 1
    else:
        prev = s
        si = si + 1
        sint.append(1)
if si % 2 == 0:
    if S[0] == '#':
        sint = [0] + sint
    else:
        sint.append(0)
    si = si + 1
elif S[0] == '#':
    sint = [0] + sint + [0]
    si = si + 2
#print(sint)

def count2(numSB,numSW):
    if len(sint) <= 2:
        return 0
    sint.pop(0)
    sint.pop()
    
    #この状態で偶数番号は黒、奇数番号は白(ゼロスタート)
    # numSB = 0
    # numSW = 0
    # for i,v in enumerate(sint):
        
    #     if i % 2 == 0:
    #         numSB = numSB + v
    #     else:
    #         numSW = numSW + v
    b = sint.pop(0)
    w = sint.pop()
    
    numSR =  b + w
    #print(numSB,numSW,numSR)
    # if numSB <= numSW and numSB <= numSR:
    #     return numSB
    # elif numSW <= numSB and numSW <= numSR:
    #     return numSW
    # else:
    #     return numSR + count2(numSB-b,numSW-w)
    if numSB <= numSW :
        return numSB
    else:
        return numSW
    
    

def count(_S,_numSW,_numSB):
    _S = _S.lstrip('.').rstrip('#')
    if len(_S) == 0 :
        return 0
    numSW = _S.count('.')
    numSB = _S.count('#')
    SR = _S.lstrip('#').rstrip('.')
    numSR = len(_S) - len(SR)
    if numSW <= numSB and numSW <= numSR:
        return numSW
    elif numSB <= numSW and numSB <= numSR:
        return numSB
    else:
        return numSR + count(SR)


numSB = 0
numSW = 0
for i,v in enumerate(sint):
    if i % 2 == 1:
        numSB = numSB + v
    else:
        numSW = numSW + v
#print(sint,numSB,numSW)
print(count2(numSB,numSW))
'''
22
#####.....####..###...
'''
# #intS = []
# def xor(A,B):
#     #print(A)
#     #print(B)
#     num = 0
#     for i in range(len(A)):
        
#         if A[i]!=B[i] :
#             num = num + 1
#     return num
# # for s in S :
# #     intS.append(0 if s=='.' else 1)
# minC = N

# mask = ['#' for j in range(len(S) + 1)]
# for i in range(len(S) + 1):
#     mask[i] = '.'
#     c = xor(mask[1::],S)
#     if c < minC:
#         minC = c

# print(minC)
# # def dl(_S):


# #     l = '.'
# #     r = '#'
    
# #     _S = _S.lstrip(l).rstrip(r)
# #     print(_S)
# #     if len(_S) == 0:
# #         return 0
# #     _S2W = _S.lstrip(r)
# #     _S2B = _S.rstrip(l)
# #     _S2 =  _S2W if len(_S2W) <= len(_S2B) else _S2B
# #     return len(_S) - len(_S2) + dl(_S2)
# # print(dl(S))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

black = [0] * N
white = [0] * N

for i, s in enumerate(S):
    if s == "#":
        black[i] = 1
    else:
        white[i] = 1

black = [0] + black
white = [0] + white

black = list(accumulate(black))
white = list(accumulate(white))[::-1]
#print(black, "境目より左にある黒の数")
#print(white, "境目より右にある白の数")


ans = []
for i in range(N+1):
    ans.append(black[i] + white[i])
        
print(min(ans))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

black = [0] * N
white = [0] * N

for i, s in enumerate(S):
    if s == "#":
        black[i] = 1
    else:
        white[i] = 1

black = [0] + black
white = [0] + white

black = list(accumulate(black))
white = list(accumulate(white))[::-1]
#print(black, "境目より左にある黒の数")
#print(white, "境目より右にある白の数")


ans = 10**10
for i in range(N+1):
    if black[i] + white[i] < ans:
        ans = black[i] + white[i]
        
print(ans)

Submission status: Wrong Answer

Solution code:
tiles = str(input())
size = len(tiles)
one = 0
zero = 0

for i in range(size):
	one_i = (i+1) % 2
	zero_i = i % 2
	one += abs(one_i - int(tiles[i]))
	zero += abs(zero_i - int(tiles[i]))

print(min(one, zero))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

black = [0] * N
white = [0] * N

for i, s in enumerate(S):
    if s == "#":
        black[i] = 1
    else:
        white[i] = 1

black = [0] + black
white = [0] + white

black = list(accumulate(black))
white = list(accumulate(white))[::-1]
#print(black, "境目より左にある黒の数")
#print(white, "境目より右にある白の数")


ans = 10**5 * 2
for i in range(N+1):
    if ans > black[i] + white[i]:
        ans = black[i] + white[i]
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
sint = [0]
si = 0
prev = S[0]

for s in S:
    if prev == s:
        sint[si] = sint[si] + 1
    else:
        prev = s
        si = si + 1
        sint.append(1)
if si % 2 == 0:
    if S[0] == '#':
        sint = [0] + sint
    else:
        sint.append(0)
    si = si + 1
elif S[0] == '#':
    sint = [0] + sint + [0]
    si = si + 2
#print(sint)

def count2():
    if len(sint) == 0:
        return 0
    sint.pop(0)
    sint.pop()
    if len(sint) == 0:
        return 0
    #この状態で偶数番号は黒、奇数番号は白(ゼロスタート)
    numSB = 0
    numSW = 0
    for i,v in enumerate(sint):
        
        if i % 2 == 0:
            numSB = numSB + v
        else:
            numSW = numSW + v
    numSR = sint.pop(0) + sint.pop()
    if numSB <= numSW and numSB <= numSR:
        return numSB
    elif numSW <= numSB and numSW <= numSR:
        return numSR
    else:
        return numSR + count2()
    
    

def count(_S,_numSW,_numSB):
    _S = _S.lstrip('.').rstrip('#')
    if len(_S) == 0 :
        return 0
    numSW = _S.count('.')
    numSB = _S.count('#')
    SR = _S.lstrip('#').rstrip('.')
    numSR = len(_S) - len(SR)
    if numSW <= numSB and numSW <= numSR:
        return numSW
    elif numSB <= numSW and numSB <= numSR:
        return numSB
    else:
        return numSR + count(SR)
print(count2())
'''
#####.....####..###...
'''
# #intS = []
# def xor(A,B):
#     #print(A)
#     #print(B)
#     num = 0
#     for i in range(len(A)):
        
#         if A[i]!=B[i] :
#             num = num + 1
#     return num
# # for s in S :
# #     intS.append(0 if s=='.' else 1)
# minC = N

# mask = ['#' for j in range(len(S) + 1)]
# for i in range(len(S) + 1):
#     mask[i] = '.'
#     c = xor(mask[1::],S)
#     if c < minC:
#         minC = c

# print(minC)
# # def dl(_S):


# #     l = '.'
# #     r = '#'
    
# #     _S = _S.lstrip(l).rstrip(r)
# #     print(_S)
# #     if len(_S) == 0:
# #         return 0
# #     _S2W = _S.lstrip(r)
# #     _S2B = _S.rstrip(l)
# #     _S2 =  _S2W if len(_S2W) <= len(_S2B) else _S2B
# #     return len(_S) - len(_S2) + dl(_S2)
# # print(dl(S))

Submission status: Wrong Answer

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

print(min(b,h))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
S=S+'9'
w=0
b=0
n=S[0]
ans=0
for s in S:
    if s=='#':
        b+=1
    elif s=='.':
        w+=1
    if n!=s:
        if n=='.':
            if b<w:
                ans+=b
            else:
                ans+=w
            b=0
            w=0
        n=s
print(ans)

Submission status: Wrong Answer

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

firstBlackPosition = S.find('#')
if firstBlackPosition < N - 1:
    replacingWhiteCount = S.count('.', firstBlackPosition + 1)

    replacingBlackCount = S.count('#', 0, N - 2)

count = min(replacingBlackCount, replacingWhiteCount)
print(count)

Submission status: Wrong Answer

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

suu = []
s_count = S.count('.')
k_count = 0
for i in range(N):
    if S[i] == "#":
        k_count += 1
    else:
        s_count -= 1
    suu.append(k_count + s_count)

print(min(suu))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
S=S+'9'
w=0
b=0
n=S[0]
ans=0
for s in S:
    if s=='#':
        b+=1
    else:
        w+=1
    if n!=s:
        if n=='.':
            if b<w:
                ans+=b
            else:
                ans+=w
            b=0
            w=0
        n=s
print(ans)

Submission status: Wrong Answer

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

l = [0] * len(S)
for i, s in enumerate(S):
    if s is '.':
        if i == 0:
            l[i] = 1
        else:
            l[i] = l[i-1] + 1
    else:
        if i == 0:
            l[i] = 0
        else:
            l[i] = l[i-1]

ans = -1
for i in range(len(S)):
    lsh = i + 1 - l[i]
    rdo = l[len(S)-1] - l[i]
    if ans == -1:
        ans = lsh + rdo
    else:
        if lsh + rdo < ans:
            ans = lsh + rdo
if len(S) == 1:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

l = [0] * len(S)
for i, s in enumerate(S):
    if s is '.':
        if i == 0:
            l[i] = 1
        else:
            l[i] = l[i-1] + 1
    else:
        if i == 0:
            l[i] = 0
        else:
            l[i] = l[i-1]

ans = 2*10^5
for i in range(len(S)):
    lsh = i + 1 - l[i]
    rdo = l[-1] - l[i]
    res = lsh + rdo
    if res < ans:
        ans = res

print(ans)

Submission status: Wrong Answer

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

l = [0] * len(S)
for i, s in enumerate(S):
    if s is '.':
        if i == 0:
            l[i] = 1
        else:
            l[i] = l[i-1] + 1
    else:
        l[i] = l[i-1]

ans = -1
for i in range(len(S)):
    lsh = i + 1 - l[i]
    rdo = l[len(S)-1] - l[i]
    if ans == -1:
        ans = lsh + rdo
    else:
        if lsh + rdo < ans:
            ans = lsh + rdo

print(ans)

Submission status: Wrong Answer

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

foundBlack = False
count = 0
for i in range(N):
    if not foundBlack:
        if S[i] == '#':
            foundBlack = True
    else:
        if S[i] == '.':
            count = count + 1

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
compress = []
compress.append([S[0],1])
for idx,s in enumerate(S):
    if idx==0:
        pass
    else:
        if compress[-1][0] == s:
            compress[-1][1] +=1
        else:
            compress.append([s,1])
cnt = []
for i in range(len(compress)):
    cnt_tmp = 0
    for idx,c in enumerate(compress):
        if i <= idx and c[0]==".":
            cnt_tmp += c[1]
        elif i > idx and c[0]=="#":
            cnt_tmp += c[1]
    cnt.append(cnt_tmp)
cnt_tmp = 0
for c in compress:
    if c=="#": cnt_tmp += 1
cnt.append(cnt_tmp)
    
    
print(min(cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
b = N
for i in range(1, N):
    c = S[0: i].count("#")
    d = S[i+1: N].count(".")
    if c + d < b:
        b = c + d
print(b)

Submission status: Wrong Answer

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

penals1 = []
tmp1 = 0
for s in S:
    if s == "#":
        tmp1 += 1
    penals1.append(tmp1)


penals2 = []
tmp2 = 0
for s in reversed(S):
    if s == ".":
        tmp2 += 1
    penals2.insert(0, tmp2)

#print(len(penals2))
#penals = [penals2[0]] + [penals1[i] + penals2[i+1] for i in range(1, N-1)] + [penals1[N-1]]
penals = [penals2[0]] + [penals1[i] + penals2[i+1] for i in range(0, N-2)] + [penals1[N-1]]
out = min(penals)
print(out)

Submission status: Wrong Answer

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

w = s.count(".")
b = 0

ans = 2 * 10e5 + 1

for c in s:
    if c == ".":
        w -= 1
    else:
        b += 1

    if w + b < ans:
        ans = w + b
    else:
        continue

print(ans)

Submission status: Wrong Answer

Solution code:
#import numpy as np
N = int(input())
S = input()

penals1 = []
tmp1 = 0
for s in S:
    if s == "#":
        tmp1 += 1
    penals1.append(tmp1)


penals2 = []
tmp2 = 0
for s in reversed(S):
    if s == ".":
        tmp2 += 1
    penals2.insert(0, tmp2)

#print(penals1)
#print(penals2)
penals = [penals2[0]] + [penals1[i] + penals2[i+1] for i in range(1, N-1)] + [penals1[N-1]]
#print(penals)
out = min(penals)
print(out)

Submission status: Wrong Answer

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

penals1 = []
penals2 = []
tmp1 = 0
tmp2 = 0

for i in range(N // 2 + 1):
    if S[i] == "#":
        tmp1 += 1
    
    if S[-(i+1)] == ".":
        tmp2 += 1
    penals1.append(tmp1)
    penals2.append(tmp2)
    #penals2.insert(0, tmp2)

#min_p = [penals2[-1]] + [penals1[i] + penals2[-i] for i in range(N // 2 + 1)]

if N % 2 == 0 and N >= 4: 
    # i = N//2-1
    min_p = tmp1 + tmp2 # save
    #min_p = penals2[-1] + tmp2 # save
    i = N // 2  # right-> N // 2 
    j = N // 2 - 2 # left -> 0
elif N >= 3: 
    val1 = penals1[-1] + penals2[-2]
    #i = N//2-1
    #val1 = tmp1 + penals2[-2]
    #i = N//2-2
    val2 = penals1[-2] + penals2[-1]
    #val2 = penals1[-1] + tmp2
    min_p = min(val1, val2)
    i = (N-1) // 2 + 1  # right -> N // 2 
    j = (N-1) // 2 - 2 # left -> 0
else:
    if N == 1:
        min_p = 2 # dummy


#for i in range(N//2+1, N-1):
while i < N-1 and N >= 3:
    #assert j >= 0, "i=%d, j=%d" % (i, j)
    if S[i] == "#":
        tmp1 += 1
    if S[-(i+1)] == ".":
        tmp2 += 1

    # i = N//2+1 -> N-2
    val1 = tmp1 + penals2[j]
    
    # j = N//2-2 -> 0
    #print(j, penals1[j], tmp2)
    val2 = penals1[j] + tmp2 
    val = min(val1, val2)
    if val < min_p:
        min_p = val
    i += 1
    j -= 1

if N != 2:
    if S[N-1] == "#":
        tmp1 += 1
    if S[0] == ".":
        tmp2 += 1

    val = min(tmp1, tmp2)
    if val < min_p:
        min_p = val
else:
    if S == "#.":
        min_p = 1
    else:
        min_p = 0


print(min_p)

Submission status: Wrong Answer

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

ans = s.count('#.')
print(ans)

Submission status: Wrong Answer

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

w_N = S.count(".")
ans = float('inf')
b = 0
w = 0

for i, s in enumerate(S):
    if s == "#":
        b += 1
    if s == ".":
        w += 1
    ans = min(ans,b + w_N - w)

print(ans)

Submission status: Wrong Answer

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

white = 0
black = 0

for i in range(n):
    if s[i] == "#":
        black += 1
    elif s[i] == ".":
        white += 1

if white != 0:
    if s[0] == ".":
            white -= 1
if black != 0:
    if s[n-1] == "#":
            black -= 1

ans = min(black, white)
print(ans)

Submission status: Wrong Answer

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

white = 0
black = 0

for i in range(n):
    if i == 0:
        if s[i] == "#":
            black += 1
    elif i == n - 1:
        if s[i] == ".":
            white += 1
    
    else:
        if s[i] == "#":
            black += 1
        elif s[i] == ".":
            white += 1

ans = min(black, white)
print(ans)

Submission status: Wrong Answer

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

ans = S.count(".")
ans2 = ans

for i in S:
    if i == "#":
        ans2 += 1
    else:
        ans2 -= 1
print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    _ = int(input()) ###
    S = list(input())

    # C = Counter(S)

    result = 10000
    for i in range(1, len(S)+1):
        left, right = Counter(S[:i]), Counter(S[i:])
        count_sharp = left['#']
        count_dot = right['.']

        total = count_sharp + count_dot
        # print(left, right, count_sharp,count_dot, total)
        result = min(result, total)
    print(result)

main()

Submission status: Wrong Answer

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

accum_black = [0] * n
accum_white = [0] * n

if s[0] == '#':
    accum_black[0] = 1
else:
    accum_white[0] = 1

for i in range(1, n):
    if s[i] == '#':
        accum_black[i] = accum_black[i-1] + 1
        accum_white[i] = accum_white[i-1]
    elif s[i] == '.':
        accum_black[i] = accum_black[i-1]
        accum_white[i] = accum_white[i-1] + 1

# すべて白or黒の場合に備えて，[0]を追加する
accum_black = [0] + accum_black
accum_white = accum_white[::-1] + [0]

ans = []
for i in range(n+1):
    ans += [accum_black[i] + accum_white[i]]

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
str = input()
left_black = 0
right_white = str.count('.')
ans = []
for s in str:
  if( s == '#' ):
    left_black += 1
  if( s == '.' ):
    right_white -= 1
  ans.append(left_black + right_white)
print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count = [0] * n

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

print(min(count))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
white = s.count(".")
black = s.count("#")
res = float("inf")
for index in range(n):
    if index == 0:
        continue
    if s[index-1] == "#" and s[index] == ".":
        res = min(res, s[:index].count("#")+s[index:].count("."))
print(min(res, black, white))

Submission status: Wrong Answer

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

white = 0
while white<N:
    if S[white]=="#":
        break
    white+=1

black = N-1
while black>0:
    if S[black]==".":
        black+=1
        break
    black-=1

cumulativeSum = []
cs = 0
c = "#"
for i in range(white,black):
    if S[i] != c:
        c = S[i]
        cumulativeSum.append(cs)
        cs = 1
    else:
        cs+=1
cumulativeSum.append(cs)

if sum(cumulativeSum[0::2]) > sum(cumulativeSum[1::2]):
    print(sum(cumulativeSum[1::2]))
else:
    print(sum(cumulativeSum[0::2]))

Submission status: Wrong Answer

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

#r = S.index('.')
r = 0
l = 0
if '.' in S:
    l = -1 * S[::-1].index('.')
if '#' in S:
    r = S.index('#')
if l==0:
    target = S[r:]
else:
    target = S[r:l]
# 全部白
#S[r:l].count('#')
# 全部黒
#S[r:l].count('.')
print(min(target.count('#'), target.count('.')))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count = [0] * n
count[0] = s[0:1].count("#") + s[1:n].count(".")

if s.count(".") != n and s.count("#") != n:
 for i in range(1,n):
  if s[i] == "#":
   count[i] = count[i-1] + 1
  else:
   count[i] = count[i-1] - 1

print(min(count))

Submission status: Wrong Answer

Solution code:
n = int(input())
input_str = input()
left_black = 0
right_white = input_str.count('.')
ans = []
for s in input_str:
  if( s == '#' ):
    left_black += 1
  if( s == '.' ):
    right_white -= 1
  ans.append(left_black + right_white)
print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cum_sum = 0
black = s.count("#")
ans = n

for i, c in enumerate(s):
    if c == "#":
        cum_sum += 1
    ans = min(ans, cum_sum + n - i - 1 - (black - cum_sum))
print(ans)

Submission status: Wrong Answer

Solution code:

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

cnt = 0
b_cnt = 0
isBlack = False
for i in range(0,N):
    now = S[i]
    if(now == '#'):
        isBlack = True
        b_cnt += 1
    if(now == '.' and isBlack):
        cnt += 1

print(min(b_cnt,cnt))

Submission status: Wrong Answer

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

cnt = 0
isBlack = False
for i in range(0,N):
    now = S[i]
    if(now == '#'):
        isBlack = True
    if(now == '.' and isBlack):
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = input()
s = list(raw_input())
count = [0] * n
count[0] = s[0:1].count("#") + s[1:n].count(".")

if s.count(".") != n and s.count("#") != n:
 for i in range(1,n):
  if s[i] == "#":
   count[i] = count[i-1] + 1
  else:
   count[i] = count[i-1] - 1
    
print min(count)

Submission status: Wrong Answer

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

#r = S.index('.')
r = 0
if '.' in S:
    l = -1 * S[::-1].index('.')
else:
    l = 0
if r == 0 and l == 0:
    target = S
else:
    target = S[r:l]
# 全部白
#S[r:l].count('#')
# 全部黒
#S[r:l].count('.')
print(min(target.count('#'), target.count('.')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
S2 = S.copy()

res = 0
res2 = 0
for i in range(1,N):
    if S[i]=='.' and S[i-1]=='#':
        S[i]='#'
        res+=1

    if S2[i]=='.' and S2[i-1]=='#':
        S2[i-1]='.'
        res2+=1

if res>res2:
    print(res2)
else:
    print(res)