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: Runtime Error

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) == 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
    b = sint.pop(0)
    w = sint.pop()
    
    numSB = _numSB 
    numSW = _numSW 
    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)
    
    

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))
'''
#####.....####..###...
'''
# #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: Runtime Error

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]]

#min_val = min(penals)

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

Submission status: Runtime Error

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

res = 0
res2 = 0

j = 0
while True:
    if S[j]=="#":
        break
    j+=1

for i in range(j+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)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
s = '.'+input()
ans = []

def div(i, s):
  l = s[:i.start()+1]
  r = s[i.end()-1:]
  lb = l.count('#')
  rw = r.count('.')
  return l, lb, r, rw
  
for i in re.finditer(r'#\.', s):
  l, lb, r, rw = div(i, s)
  ans.append(lb+rw)
for i in re.finditer(r'\.#', s):
  l, lb, r, rw = div(i, s)
  ans.append(lb+rw)
if len(ans) > 0:
  print(min(ans))
else:
  print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
s = '.'+input()
ans = []

def div(i, s):
  l = s[:i.start()+1]
  r = s[i.end()-1:]
  lb = l.count('#')
  rw = r.count('.')
  return l, lb, r, rw
  
for i in re.finditer(r'#\.', s):
  l, lb, r, rw = div(i, s)
  print(l, lb, r, rw)
  ans.append(lb+rw)
print()
for i in re.finditer(r'\.#', s):
  l, lb, r, rw = div(i, s)
  print(l, lb, r, rw)
  ans.append(lb+rw)
print('\n',ans)
if len(ans) > 0:
  print(min(ans))
else:
  print(0)

Submission status: Runtime Error

Solution code:
n = input()
s = list(raw_input())
count = [0] * (n-1)

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

print min(count)

Submission status: Runtime Error

Solution code:
import re
n = int(input())
s = input()
anss = []
for i in re.finditer(r'#\.|\.#', s):
  l = s[:i.start()+1]
  r = s[i.end()-1:]
  anss.append(l.count('#')+r.count('.'))
print(min(anss))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
anss = []
for i in re.finditer(r'#\.|\.#', s):
  l = s[:i.start()+1]
  r = s[i.end()-1:]
  anss.append(l.count('#')+r.count('.'))
print(min(anss))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
s = list(input())
res = 10**6
ctw = 0
ctb = 0
w = [0]*n
b = [0]*n

for i in range(n):
     if s[i] == ".":
          ctw += 1
     else:
          ctb += 1
     w[i]= ctw
     b[i]= ctb
for i in range(n):
     res = min(res,b[i]+w[-1]-w[i])
res = min(res,[-1],b[-1])
print(res)

Submission status: Runtime Error

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

def next(s):
  if s == '':  # empty
    return 0, 0, None
  if len(s) == s.count('.') or len(s) == s.count('#'):  # . or # only
    return s.count('#'), s.count('.'), ''

  l = s.index('#')
  if s.count('#.') > 0:
    c = s.index('#.')+1
    if s.count('.#') > 0:
      r = s.index('.#')+1
    else:
      r = len(s)-1
  else:
    c,r = len(s)-1
  b = c - l
  w = r - c
  return b, w, s[r:]

black, white = 0, 0
if s[0] != '#':
  s = s[s.index('.#')+1:]
while(s != None):
  b, w, s = next(s)
  black += b
  white += w
print(min(black, white))

Submission status: Runtime Error

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

#r = S.index('.')
r = 0
l = -1 * S[::-1].index('.')
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: Runtime Error

Solution code:
n = int(input())
S = input()
b = 0
w = S.count('.')
res = w
for s in S:
	if s == '.':
		
	else:
		b += 1
	res = min(res,b+w)
print(res)

Submission status: Runtime Error

Solution code:

import sys
input = sys.stdin.readline

n = int(input())
s = list(input())
res = 10**9



ctw = 0
ctb = 0
w = [0]*n
b = [0]*n

for i in range(n):
     if s[i] == ".":
          ctw += 1
     else:
          ctb += 1
     w[i]= ctw
     b[i]= ctb
for i in range(n):
     res = res,b[i]+w[-1]-w[i]
res = min(res,w[-1],b[-1])
print(res)

Submission status: Runtime Error

Solution code:
color=input()
a=int(stone)
result=100000
counter=0
left=[]
right=[]
black = 0
white = 0
xxx=[]
yyy=[]
list=[]
list2=[]
for i in range(a):
    list.append(color[i])
for i in range(a):
	left=color[:i]
    right=color[i:]
	w=left.count('#')
    b=right.count('.')
    if result > w+b:
      result=w+b
print(result)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
 
arr = [0] if S[0] == "." else []
b, w = 0, 0
for i in range(len(S)):
  if S[i] == ".":
    w += 1
  else:
    b += 1
  if S[i:i+2] == "#.":
    arr.append(b)
  if S[i:i+2] == ".#":
    arr.append(w)
if S[-1] == ".":
	arr.append(w)
#print(arr)
 
result = arr[-1]+arr[1]
for i in range(0, len(arr), 2):
  result = min([arr[i]+arr[-1]-arr[i+1], result])

print(result)

Submission status: Runtime Error

Solution code:
import numpy as np

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

ans = [np.zeros(N), np.zeros(N)]

for i in range(N):
    if S[i] == "#":
        ans[0][i:] += 1
    else:
        ans[1][:i+1] += 1

print(min(ans[0][N-1], ans[1][0], np.min(ans[0][1:]+ans[1][:N-1])))

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())
# '.'の場合は白, '#'の場合は黒

if S[0] == '.':
    count_white = [1]
    count_black = [0]
else:
    count_white = [0]
    count_black = [1]


for i in range(1, N):
    if S[i] == '.':
        # 見ている石が白なら
        count_white.append(count_white[i-1]+1)
        count_black.append(count_black[i-1])
    else:
        # 見ている石が黒なら
        count_white.append(count_white[i-1])
        count_black.append(count_black[i-1]+1)

hoge = []
for i in range(1, N):
    min_sum = 0
    min_sum += count_black[i-1]
    min_sum += (count_white[N-1] - count_white[i])
    hoge.append(min_sum)

print(min(hoge))

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())
# '.'の場合は白, '#'の場合は黒

if S[0] == '.':
    count_white = [1]
    count_black = [0]
else:
    count_white = [0]
    count_black = [1]


for i in range(1, N):
    if S[i] == '.':
        # 見ている石が白なら
        count_white.append(count_white[i-1]+1)
        count_black.append(count_black[i-1])
    else:
        # 見ている石が黒なら
        count_white.append(count_white[i-1])
        count_black.append(count_black[i-1]+1)

# print(count_black)
# print(count_white)

# change_count = [x+y for x, y in zip(count_white, count_black)]
change_count = []
for i in range(1, N):
    change_count.append(count_black[i-1] + (count_white[N-1] - count_white[i]))

print(min(change_count))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
min = N
if S.find('#') == -1 or S.find('.') == -1:
    min = 0
else:
    for i in range(S.find('#'),S.rfind('#')):
        if S[i] == '.' and S[i+1] == '#':
            left = S.count('#',0,i)
            right = S.count('.',i+1)
        elif S[i] == '#' and S[i+1] =='.':
            left = S.count('#',0,i)
            right = S.count('.',i)
        if left + right < min:
            min = left + right
print(min)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
min = N
for i in range(N-1):
    if S.find('.') == -1 or S.find('#') == -1:
        min = 0
        break
    if S[i] == '.' and S[i+1] == '#':
        left = S.count('#',0,i)
        right = S.count('.',i+1)
    elif S[i] == '#' and S[i+1] =='.':
        left = S.count('#',0,i)
        right = S.count('.',i)
    if left + right < min:
        min = left + right
print(min)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
 
arr = [0] if S[0] == "." else []
count = 0
for i in range(len(S)):
  count += 1
  if S[i:i+2] == "#.":
    arr.append(count)
    count = 0  
  if S[i:i+2] == ".#":
    arr.append(count)
    count = 0
if S[-1] == ".":
  arr.append(count)
#print(arr)
 
result = sum([min(arr[i:i+2]) for i in range(0, len(arr)+1, 2)])
print(result)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
def count(_S):
    _S = _S.rstrip('#').lstrip('.')
    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(count(S))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
def count(_S):
    _S = input().rstrip('#').lstrip('.')
    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(count(S))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input().rstrip('#').lstrip('.')
def count(_S):
    # _S = input().rstrip('#').lstrip('.')
    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(count(S))

Submission status: Runtime Error

Solution code:
N=int(input())
ls_S=list(input())
i=0
cnt_1=0
cnt_2=0

while ls_S[i]==".":
    i+=1

for x in range(i,N):
    if ls_S[x]==".":
        ls_S[x]="#"
        cnt_1+=1
for x in range(i,N-1):
    if ls_S[x]=="#":
        ls_S[x]="."
        cnt_2+=1
if cnt_1>=cnt_2:
    print(cnt_2)
else:
    print(cnt_1)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
 
ans = 0
for i in range(n-2):
    if s[i]+s[i+1] == "#.":
        s.replace(s[i+1],"#")
        ans += 1
    else:
        continue
if s[-2]+s[-1] == "#.":
    s.replace(s[i+1],"#")
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
bs = 0
ws = s.count('.')
ans = n
for c in s:
    if c == '.':
        ws -= 1
            else:
        bs += 1
    now = ws + bs
    if ans > now:
        ans = now
print(ans)

Submission status: Runtime Error

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

# 右全部#にする

b = S.count('W')

ans = 10**9
cost = 0
for c in S:
    if c == '.':
        # 今見てる所以降全部白にする事を考える
        w -= 1
        # まだ見てない白の数 + 今まで白にした黒のコストが答え候補
        if w + cost < ans:
            ans = w + cost
    else:
        # 今見てる所が黒の場合、白の個数は減らない
        if w + cost< ans:
            ans = w + cost
        # 以降の計算に向けてコストを1増やす
        cost += 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
a = []
#  .##..#.##.
w = s.count(".")
b = s.count("#")
m = min(w,b)

bb=0

for i in range(n):
    if s[i]=='.':
        w-=1
    if s[i]=='#':
        bb += 1
        a.append(bb+w)
n=min(a)
print(min(m,n))

Submission status: Runtime Error

Solution code:
n = input()
s = input()
if (s.count("#") == n) or (s.count(".") == n):
    print(0)
else:
    sharp_cnt = s.count("#")
    # print(s.count("#"))
    if s[len(s)-1] == "#":
        for i in reversed(range(0,len(s))):
            if s[i] == ".":
                x = len(s)-i-1
                break
        sharp_cnt -= x

    period_cnt = s.count(".")
    if s[0] == ".":
        for i in range(len(s)):
            if s[i] == "#":
                y = i
                break
        period_cnt -= y
    print(min(period_cnt,sharp_cnt))

Submission status: Runtime Error

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

cnt = 0
for i in range(len(s)-2):
    if s[i] == '#' and s[i+1] == '.':
        if s[i+2] == '.':
            s[i] = '.'
        else:
            s[i+1] = "#"

        cnt += 1

if s[-2] == "#" and  s[-1] == ".":
    s[-1] = "#"
    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()                                                      
list_S = list(S)
N1 = 0
X1 = 0
X2 = 0
list_X = []

for color in list_S:
    if color == '.':
            N1 +=1
    else:
        list_S1 = list_S[N1:]
        list_S2 = list_S[:N1]
        X1 = list_S1.count('.')
        X2 = list_S2.count('#')
        X = X1 + X2
        list_X.append(X)
        N1 +=1

X_MIN = min(list_X)
print(X_MIN)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()                                                      
list_S = list(S)
N1 = 0
X1 = 0
X2 = 0
X1MIN = 0
X2MIN = 0
list_X = []

for color in list_S:
    if color == '.':
            N1 +=1
    else:
        list_S1 = list_S[N1:]
        list_S2 = list_S[:N1]
        X1 = list_S1.count('.')
        X2 = list_S2.count('#')
        X = X1 + X2
        list_X.append(X)
        N1 +=1

X_MIN = min(list_X1)
print(X_MIN)

Submission status: Runtime Error

Solution code:
import sys
if __name__ == "__main__":
    N = int(input())
    S = input()

    kuro = S.find("#")
    shiro = S.find(".")
    S_list = list(S)
    if kuro==-1 or shiro==-1:
        print(0)
    
    elif shiro<kuro:
        shikiri=kuro
        while(True):
            if S[shikiri] =="#":
                shikiri += 1
            else:
                break
        match=S[(shikiri):]
        print(min((shikiri-kuro),match.count(".")))
    
    else:
        print(min(S.count("."),S.count("#")))

Submission status: Runtime Error

Solution code:
def chec(s):
    lis = []
    rtmp = 0
    ltmp = 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

    return min(lis)

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

Submission status: Runtime Error

Solution code:
import sys
if __name__ == "__main__":
    N = int(input())
    S = input()

    kuro = S.find("#")
    shiro = S.find(".")
    print(kuro,shiro)
    S_list = list(S)
    if kuro==-1 or shiro==-1:
        print(0)
    
    elif shiro<kuro:
        shikiri=kuro
        while(True):
            if S[shikiri] =="#":
                shikiri += 1
            else:
                break
        match=S[(shikiri):]
        print(min((shikiri-kuro),match.count(".")))
    
    else:
        print(min(S.count("."),S.count("#")))

Submission status: Runtime Error

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
            b_2+=1
print(min(N-w,N-b,w_2))

Submission status: Runtime Error

Solution code:
N=int(input())
ls_S=input()
i=0
cnt_1=0
cnt_2=0

while ls_S[i]==".":
    i+=1

for x in range(i,N):
    if ls_S[x]==".":
        ls_S[x]="#"
        cnt_1+=1
for x in range(i,N):
    if ls_S[x]=="#":
        ls_S[x]="."
        cnt_2+=1
if cnt_1>=cnt_2:
    print(cnt_2)
else:
    print(cnt_1)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()                                                                                                                                                                                                                                                                                                                                                                                                                                            
list_S = list(S)
N1 = 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: Runtime Error

Solution code:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func ini() {
	var buf = make([]byte, 10000)
	sc.Buffer(buf, 1000000)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	ini()
	N, _ := strconv.Atoi(nextLine())
	S := nextLine()
	b := make([]int, N+1)

	for i, s := range S {
		if s == '#' {
			b[i+1] = b[i] + 1
		} else {
			b[i+1] = b[i]
		}
	}
	ans := N
	for i := 1; i < N+1; i++ {
		ans = min(ans, b[i]+N-i-b[N]+b[i-1])
	}
	fmt.Println(ans)
}

Submission status: Runtime Error

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

ct = 0
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: Runtime Error

Solution code:
N=int(input())
S=input()
before=''
count=0
count_list=[]
w_count_list=[0]
b_count_list=[0]
for i,moji in enumerate(S):
    count+=1
    if moji!=before:
        if i!=0:
            count_list.append(count-1)
            if before=='.':
                w_count_list.append(w_count_list[-1]+count-1)
            else:
                b_count_list.append(b_count_list[-1]+count-1)
            count=1 
            before=moji
    if i==len(S)-1:
        count_list.append(count)
        if moji=='.':
            w_count_list.append(w_count_list[-1]+count)
        else:
            b_count_list.append(b_count_list[-1]+count)
cand=[]
ki=0
if S[0]=='.':
    count_list=count_list[1:]
    length=len(count_list)
    if length%2==1:
        ki=1
    for i in range(length//2+1):
        cand.append(w_count_list[-1]-w_count_list[i]+b_count_list[-1]-b_count_list[max_num+ki-i])
else:
    length=len(count_list)
    if length%2==1:
        ki=1
    max_num=length//2
    for i in range(length//2+1):
        cand.append(w_count_list[-1]-w_count_list[i]+b_count_list[-1]-b_count_list[max_num+ki-i])
        #print(length-i*2-ki)
        #print(count_list[i*2+1::2])
print(min(cand))
#print(cand)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
list_S = list(S)
N1 = 0
X = list_S.count('.')
for N in list_S:
    if list_S[N1] == '.':
            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: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
S=[str(i) for i in input().split()][0]
S2=[i for i in S]
sharp=[i for i,n in enumerate(S) if n=="#"]
res=[S[0:i].count("#")+S[i:len(S)].count(".") for i in sharp]
print(min(res))

Submission status: Runtime Error

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

count_list =[]
wc = 0

A=[0]*(N)
bc = 0

for i in list(range(N))[::-1]:
    if(S[i] == '#'):
        bc  += 1
    A[i] = bc

for n in range(N-1):
    if(S[n] == '.'):
        num = n
        count_list.append(A[n+1] + wc)
        wc += 1

if(S[N-1] == '.'):
    count_list.append(wc+1)

count = min(count_list)
print(count)

Submission status: Runtime Error

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

count_list =[]
wc = 0

A=[0]*(N)
bc = 0

for i in list(range(N))[::-1]:
    if(S[i] == '#'):
        bc  += 1
    A[i] = bc
print(A)

for n in range(N-1):
    if(S[n] == '.'):
        num = n
        count_list.append(A[n+1] + wc)
        wc += 1

if(S[N-1] == '.'):
    count_list.append(wc+1)
print(count_list)
count = min(count_list)
print(count)

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=_I()
S=input()
for sidx in range(N):
	if S[sidx]=="#":
		S=S[sidx:]
		break
while S[-1] != ".":
	S=S[:len(S)-1]

cd=S.count(".")
cs=S.count("#")

#print(cd,cs)
ans=min(cd,cs)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(input())
b=[]

for i in range(1,n):
  if a[i]=="#" and a[i-1]==".":
  b.append(a[:i].count("#")+a[i:].count("."))

b.append(a.count("."))
b.append(a.count("#"))

print(min(b))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(input())
b=[]

for i in range(1,n):
  if a[i]=="#" and a[i-1]=="."
  b.append(a[:i].count("#")+a[i:].count("."))

b.append(a.count("."))
b.append(a.count("#"))

print(min(b))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
bs = [0] * (N + 1)
ws = [0] * (N + 1)
total = float("inf")
left_b = 0
right_w = 0
for i, s in enumerate(S):
    if s == "#":
        left_b += 1
        bs[i + 1] = left_b
for i in reversed(range(N))
    if S[i] == ".":
        right_w += 1
        ws[i] = right_w

for i in range(N):
    total = min(total, ws[i+1] + bs[i])

print(total)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
min = N
for i in range(N-1):
    if '.' not in S or '#' not in S:
        min = 0
        break
    if S[i] == '.' and S[i+1] == '#':
        left = S.count('#',0,i+1)
        right = S.count('.',i+1)
    elif S[i] == '#' and S[i+1] =='.':
        left = S.count('#',0,i)
        right = S.count('.',i)
    if left + right < min:
        min = left + right
print(min)

Submission status: Runtime Error

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

S_list = [0 if S[i] == "." else 1 for i in range(N)]
S_sum_list = [S_list[0]]
for i in range(1, N):
  S_sum_list[i] = S_sum_list[i-1] + S_list[i]
  
ans = 10 ** 18
for i in range(1, N):
  if i == 0:
    min_num_1 = min(S_sum_list[N-1], N - S_sum_list[N-1])
  else:
    ans = min(ans, S_sum_list[i-1] + N - i - (S_sum_list[N-1] - S_sum_list[i-1]))
print(min(min_num_1, ans))

Submission status: Runtime Error

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

cnt=N
for i in range(N+1):
    if (S[0:i+1].count("#") + S[i+1:N].count(".")) <= cnt:
        cnt = left.count("#") + right.count(".")
print(cnt)

Submission status: Runtime Error

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

count_list =[]
wc = 0

A=[0]*(N)

for i in list(range(N-1))[::-1]:
    if(S[i] == '#'):
        A[i] = A[i+1] + 1

for n in range(N-1):
    if(S[n] == '.'):
        num = n
        count_list.append(A[n+1] + wc)
        wc += 1

if(S[N-1] == '.'):
    count_list.append(wc+1)

count = min(count_list)
print(count)

Submission status: Runtime Error

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

 white = 0
 black = 0
 first_black_index = 0

 while S[first_black_index] == ".":
   first_black_index += 1
   if first_black_index == N:
     print(0)
     break

 last_black_index = N
 if first_black_index != N:
   while S[last_black_index-1] == "#":
     last_black_index -= 1
     if last_black_index == 0:
       print(0)
       break


 if first_black_index != N and last_black_index != 0:
   S = S[first_black_index:last_black_index]

   for i in range(len(S)):
     if S[i] == "#":
       black +=1
     else:
       white +=1

   print(min(white,black))

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
before=''
count=0
count_list=[]
for i,moji in enumerate(S):
    count+=1
    if moji!=before:
        before=moji
        count_list.append(count)
        count=0
    elif i-1==len(S):
        count_list.append(count)
cand=[]

if S[0]=='.':
    count_list=count_list[1:]
    length=len(count_list)
    if length%2==1:
        ki=1
    for i in range(length-1//2+1):
        cand.append(sum(count_list[0:max_num-i*2:2])+sum(count_list[i*2+1::2]))
else:
    length=len(count_list)
    ki=0
    if length%2==1:
        ki=1
    max_num=length//2
    for i in range(length//2+1):
        cand.append(sum(count_list[0:length-i*2-ki:2])+sum(count_list[length-i*2:length:2]))
        #print(length-i*2-ki)
        #print(count_list[i*2+1::2])
print(min(cand))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
min = N
for i in range(N-1):
    if '.' not in S or '#' not in S:
        min = 0
        break
    if S[i] == '.' and S[i+1] == '#':
        left = S.count('#',0,i)
        right = S.count('.',i)
    elif S[i] == '#' and S[i+1] =='.':
        left = S.count('#',0,i)
        right = S.count('.',i)
    if left + right < min:
        min = left + right
print(min)

Submission status: Runtime Error

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

count_list =[]
wc = 0

A=[0]*(N+1)

for i in list(range(N))[::-1]:
    if(S[i] == '#'):
        A[i] = A[i+1] + 1

for n in range(N-1):
    if(S[n] == '.'):
        num = n
        count_list.append(A[n+1] + wc)
        wc += 1

if(S[N-1] == '.'):
    count_list.append(wc+1)

count = min(count_list)
print(count)

Submission status: Runtime Error

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

count_list =[]
wc = 0

A=[0]*(N+1)

for i in list(range(N))[::-1]:
    if(S[i] == '#'):
        A[i] = A[i+1] + 1

print(A)
for n in range(N-1):
    if(S[n] == '.'):
        num = n
        count_list.append(A[n+1] + wc)
        wc += 1

if(S[N-1] == '.'):
    count_list.append(wc+1)

count = min(count_list)
print(count)