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:
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
    sys.exit()
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
    ind2 = N - num
    s = S[ind1:ind2]
    if len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Submission status: Runtime Error

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

S0 = S[0]
L = []
count = 1
Wk=[]
Bk=[]

for i in range(1,N):
    if S[i-1]!=S[i]:
        L.append(count)
        count =1

    else:
        count +=1
    if i ==N-1:
        L.append(count)

lenL=len(L)
Numw =0
Numb =0
Numx =0

if S0 == '.':
    Wk.append(L[0])
    Bk.append(0)
    if S[-1] =='.':
        for i in range(1,lenL):
            if i%2 == 0:
                Numw +=L[i]
                Wk.append(Wk[-1]+L[i])
                Bk.append(Bk[-1])

            else: 
                Numb +=L[i]
                Bk.append(Bk[-1]+L[i])
                Wk.append(Wk[-1])

        m=(min(Numw,Numb))

        tmp = float("inf")


        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))
        
    else:

        for i in range(1,len(L)-1):
            if i%2 ==0:
                Numw +=L[i]
                Wk.append(Wk[-1]+L[i])
                Bk.append(Bk[-1])
            else:
                Numb +=L[i]
                Bk.append(Bk[-1]+L[i])
                Wk.append(Wk[-1])
        if Bk:
            Bk.append(Bk[-1]+L[-1])
        else:
            Bk.append(L[-1])
        if Wk:
            Wk.append(Wk[-1])
        else:
            Wk.append(0)

        m=(min(Numb,Numw))
        tmp = float("inf")

        for k in range(lenL):
            s =Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

         

else:
    if S[-1]=='.':
        for i in range(len(L)):
            if i%2 ==0:
                Numb += L[i]
                if Bk:
                    Bk.append(Bk[-1]+L[i])
                else:
                    Bk.append(L[i])
                if Wk:
                    Wk.append(Wk[-1])
                else:
                    Wk.append(0)

            else:
                Numw += L[i]
                if Bk:
                    Bk.append(Bk[-1])
                else:
                    Bk.append(0)
                if Wk:
                    Wk.append(Wk[-1]+L[i])
                else:
                    Wk.append(L[i])

        m=(min(Numb,Numw))
        tmp = float("inf")

        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

    else:
        for i in range(len(L)-1):
            if i%2 ==0:
                Numb += L[i]
                if Bk:
                    Bk.append(Bk[-1]+L[i])
                else:
                    Bk.append(L[i])
                if Wk:
                    Wk.append(Wk[-1])
                else:
                    Wk.append(0)

            else:
                Numw += L[i]
                if Bk:
                    Bk.append(Bk[-1])
                else:
                    Bk.append(0)
                if Wk:
                    Wk.append(Wk[-1]+L[i])
                else:
                    Wk.append(L[i])
        if Bk:
            Bk.append(Bk[-1]+L[-1])
        else:
            Bk.append(L[-1])
        if Wk:
            Wk.append(Wk[-1])      
        else:
            Wk.append(0)
        m=(min(Numb,Numw))
        tmp =float("inf")  


        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

Submission status: Runtime Error

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

answer = 200000
b = 0
w = s.count(".")
if w == len(s) or s.count("#"==len(s)):
    print(0)
else:
    for i in range(len(s)):
        if s[i] == "#":
            b += 1
        else:
            w -= 1
        answer = min(answer, b+w)

    print(answer)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
x = s.count("#")
lst = [s[:i].count("#")+s[i+1:].count(".") for i in range(n) if (s[i]=="#")]
x = min(x,min(lst))
print(x)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
b=s.count("#")
w=s.count(".")
cnt=0
ind=n-s[::-1].index(".")
p=s[:ind].count("#")
print(min(b,w,p))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())

l = s.strip()
memo=[]
for i in range(0,n):
    memo.append(-1)
memo[0]=0

def dfs(i):
    if i < 1:
        return 0

    global memo
    if memo[i] != -1:
        return memo[i]
    if s[i] == ".":
        memo[i] = min(s[:i].count("#"), dfs(i-1)+1)
    else:
        memo[i] = min(dfs(i-1), s[:i].count(".")+1)
    return memo[i]

print dfs(n-1)

Submission status: Runtime Error

Solution code:
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
    sys.exit()
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    ind2 = N - num
    if ind1 > ind2:
        print(0)
        sys.exit()
    s = S[ind1:ind2]
    if s[0] == '.' or s[-1] == '#' or len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Submission status: Runtime Error

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

count_list =[]
wc = 0

A=[0]*N

for i in range(N):
     A[i] = A[i+1] + (S[i] == '#' ? 1 : 0))
A[N] = 0

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

S0 = S[0]
L = []
count = 1
Wk=[]
Bk=[]

for i in range(1,N):
    if S[i-1]!=S[i]:
        L.append(count)
        count =1

    else:
        count +=1
    if i ==N-1:
        L.append(count)

lenL=len(L)
Numw =0
Numb =0
Numx =0

if S0 == '.':
    Wk.append(L[0])
    Bk.append(0)
    if S[-1] =='.':
        for i in range(1,lenL):
            if i%2 == 0:
                Numw +=L[i]
                Wk.append(Wk[-1]+L[i])
                Bk.append(Bk[-1])

            else: 
                Numb +=L[i]
                Bk.append(Bk[-1]+L[i])
                Wk.append(Wk[-1])

        m=(min(Numw,Numb))

        tmp = float("inf")


        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))
        
    else:

        for i in range(1,len(L)-1):
            if i%2 ==0:
                Numw +=L[i]
                Wk.append(Wk[-1]+L[i])
                Bk.append(Bk[-1])
            else:
                Numb +=L[i]
                Bk.append(Bk[-1]+L[i])
                Wk.append(Wk[-1])
        if Bk:
            Bk.append(Bk[-1]+L[-1])
        else:
            Bk.append(L[-1])
        if Wk:
            Wk.append(Wk[-1])
        else:
            Wk.append(0)

        m=(min(Numb,Numw))
        tmp = float("inf")


        for k in range(lenL):
            s =Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

         

else:
    if S[-1]=='.':
        for i in range(len(L)):
            if i%2 ==0:
                Numb += L[i]
                if Bk:
                    Bk.append(Bk[-1]+L[i])
                else:
                    Bk.append(L[i])
                if Wk:
                    Wk.append(Wk[-1])
                else:
                    Wk.append(0)

            else:
                Numw += L[i]
                if Bk:
                    Bk.append(Bk[-1])
                else:
                    Bk.append(0)
                if Wk:
                    Wk.append(Wk[-1]+L[i])
                else:
                    Wk.append(L[i])

        m=(min(Numb,Numw))
        tmp = float("inf")


        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

    else:
        for i in range(len(L)-1):
            if i%2 ==0:
                Numb += L[i]
                if Bk:
                    Bk.append(Bk[-1]+L[i])
                else:
                    Bk.append(L[i])
                if Wk:
                    Wk.append(Wk[-1])
                else:
                    Wk.append(0)

            else:
                Numw += L[i]
                if Bk:
                    Bk.append(Bk[-1])
                else:
                    Bk.append(0)
                if Wk:
                    Wk.append(Wk[-1]+L[i])
                else:
                    Wk.append(L[i])
        if Bk:
            Bk.append(Bk[-1]+L[-1])
        else:
            Bk.append(L[-1])
        if Wk:
            Wk.append(Wk[-1])      
        else:
            Wk.append(0)
        m=(min(Numb,Numw))
        tmp =float("inf")  


        for k in range(lenL):
            s = Bk[k]+(Wk[-1]-Wk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

Submission status: Runtime Error

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

white = 0
black = 0
first_black_index = 0
end_index = N

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

last_black_index = len(S)
if first_black_index != N:
  while S[len(S)] == "#":
    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+1]

  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()
ans = 0
if N == 1:
    print(0)
    exit()
elif N == 2 and (S[0] == '.' and S[1] == '#'):
    print(0)
    exit()
else:
    S = S[0] + S + S[N - 1]
    S = list(S)
    for n in range(N):
        if S[n] == '.' and S[n + 2] == '.' and S[n + 1] == '#':
            ans += 1
            S[n + 1] = '.'
        elif S[n] == '#' and S[n + 2] == '#' and S[n + 1] == '.':
            ans += 1
            S[S + 1] = '#'
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    ind2 = N - num
    if ind1 > ind2:
        print(0)
        sys.exit()
    s = S[ind1:ind2]
    if s[0] == '.' or s[-1] == '#' or len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
list_S = list(S)
N1 = 0
X = list_S.count('.')

if num == X:
    print('0')
else:
    for N in list_S:
        if list_S[N1] == '.':
            N1 += 1
        else:
            list_SS = list_S[N1:]
            X1 = list_SS.count('.')
            print(X1)
            break

Submission status: Runtime Error

Solution code:
def test():
    global count, list_str
    for i, data in enumerate(list_str):
        try:
            if data == '#' and list_str[i + 1] == '.':
                list_str[i + 1] = '#'
                count += 1
                test()
        except IndexError:
            pass


N = input()
S = input()
count = 0

list_str = list(S)


test()

# print(list_str)
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())

l = s.strip()
memo=[]
for i in range(0,n):
    memo.append(-1)
memo[0]=0

def dfs(i):
    global memo
    if memo[i] != -1:
        return memo[i]
    if s[i] == ".":
        memo[i] = min(s[:i].count("#"), dfs(i-1)+1)
    else:
        memo[i] = min(dfs(i-1), s[:i].count(".")+1)
    return memo[i]

print dfs(n-1)

Submission status: Runtime Error

Solution code:
N = input()
S = input()
list_S = list(S)
N1 = 0
X = list_S.count('.')

if num == X:
    print('0')
else:
    for N in list_S:
        if list_S[N1] == '.':
            N1 += 1
        else:
            list_SS = list_S[N1:]
            X1 = list_SS.count('.')
            print(X1)
            break

Submission status: Runtime Error

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

pattern = []
for n in range(N+1):
    pattern.append('.'*n + '#'*(N-n))
box = np.zeros(N+1, int)
for n in range(N+1):
    for n_2 in range(N):
        if S[n_2] != pattern[n][n_2]:
            box[n] += 1
print(min(box))

Submission status: Runtime Error

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

p = s.count('.')
q = 0
r = p

for i in range(n):
    if s[i] == '#':
        q += 1
    else:
        p -= 1
    # r = min(r, p + q)
   	r = r if r < p + q else p + q

print(r)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ans = 1000;
  for (int i = 1; i < N; i++) {
    int B = 0;
    int W = 0;
    if(S[i-1]!=S[i]){
      for (int j = 0; j < i; j++) {
        if(S[j]=='#') B++;
      }
      for (int k = i; k < N; k++) {
        if(S[k]=='.') W++;
      }
      ans = min(ans, B+W);
    }
    if (ans==1000 && i==N-1) ans = 0;
  }
  cout << ans << endl;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
M=S.count('.')
ans=M

for i in range(N):
	if S[i] == '#':
		M = M+1
	else:
		M = M-1
    ans = min(M,ans)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
        if i == N-1:
            print(0)
            sys.exit()
    ind2 = N - num
    s = S[ind1:ind2]
    if s[0] == '.' or s[-1] == '#' or len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Submission status: Runtime Error

Solution code:
# coding: utf-8

N = int(input())
S = input().rstrip('#')

lb = 0
rw = S.count('.')
ans = lb + rw

for i in range(N):
  if S[i] == '.':
    rw -= 1
  else:
    lb += 1
  ans = min(ans, rw + lb)

print(ans)

Submission status: Runtime Error

Solution code:

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

ans = n
cnt_w = s.count('.')
cnt_k = 0
if cnt == n or cnt == 0:
    ans = 0
    print(ans)
else:
    for i in range(n):
        if s[i] == '.':
            cnt_w -= 1
        else:
            cnt_k += 1
        if ans > cnt_w + cnt_k:
            ans = cnt_w + cnt_k
    print(ans)

Submission status: Runtime Error

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

ans = n
cnt_w = s.count('.')
cnt_k = 0
if cnt == n or cnt == 0:
    ans = 0
    print(ans)
else:
    for i in range(n):
        if s[i] == '.':
            cnt_w -= 1
        else:
            cnt_k += 1
        if ans > cnt_w + cnt_k:
            ans = cnt_w + cnt_k:
    print(ans)

Submission status: Runtime Error

Solution code:
str = input()
minDistance = N
black = "#"
white = "."

for i in range(N):
    distance = 0
    loopnum = 0
    while (distance < minDistance and loopnum < N):
        for j in range(0, i):
            if str[j] == black:
                distance += 1
                loopnum += 1
            else:
                loopnum += 1
        for k in range(i, N - 1):
            if str[k] == white:
                distance += 1
                loopnum += 1
            else:
                loopnum += 1
    print("{}".format(distance))
    if (loopnum >= N-1):
        minDistance = distance

print("{}".format(minDistance))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
s_copy = s + '-'

ideal1 = '#' * n
ideal2 = '.' * n
ideal_idx = [i for i in range(n) if s_copy[i] == '.' and s_copy[i+1] =='#']
ideals = ['.' * (idx + 1) + '#' * (n - idx - 1) for idx in ideal_idx]
ideals.append(ideal1)
ideals.append(ideal2)
ideals = set(ideals)

counts = [0] * len(ideals)
for i, ideal in enumerate(ideals):
  for stone, ideal_stone in zip(s, ideal):
    if stone != ideal_stone:
      counts[i] += 1

print(min(counts))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
preans = 0
pew = 0
bflag = 0
b2w = 0
for i, word in enumerate(s):
    if bflag == 0:
        if word == '#':
            bflag = 1
    else:
        if word == '.':
            b2w = 1
    if b2w == 1:
        if word == '.':
            preans += 1
skip = 1
ans2 = 0
wcount = 0
bcount = 0
for i, word in enumerate(s):
    if b2w > skip:
        ans = min(preans, preans + bcount - wcount)
        preans = preans + bcount - wcount
        skip += 1
        wcount = 0
        bcount = 0

    if word == '#':
        bcount += 1

    if bflag == 0:
        if word == '#':
            bflag = 1
    else:
        if word == '.':
            b2w += 1
            bflag = 0

    if b2w == skip and word == '.':
        wcount += 1
print(ans)

Submission status: Runtime Error

Solution code:
from heapq import *
def main():
    N=int(input())
    line = list(input())
    ans=[]

    for i in range(N+1):
        a=line[:i].count("#")
        b=line[i:].count(".")
        heappush(ans,a+b)
    
    return peappop(ans)

print(main())

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
m=min(s.count('.'),s.count('#'))
if s[0]=='.' and s[n-1]=='#':
  m=m-1
elif s[0]=='.' and s.count('.')<=s.count('#'):
  m=m-1
elif s[n-1]=='#' and s.count('.')=>s.count('#'):
  m=m-1
else:
  m=m
print(m)

Submission status: Runtime Error

Solution code:
import sys
from itertools import accumulate
N = int(input())
S = input()
if S == '.'*N or S == '#'*N:
    print(0)
else:
    ind1 = 0
    for i, x in enumerate(S):
        if x == '#':
            ind1 = i
            break
    num = 0
    for i, x in enumerate(S[::-1]):
        if x == '.':
            num = i
            break
    ind2 = N - num
    s = S[ind1:ind2]
    if s[0] == '.' or s[-1] == '#' or len(s) == 0:
        print(0)
        sys.exit()
    else:
        a = s.split('.')
        b = s.split('#')
        aa = []
        bb = []
        for x, y in zip(a, b):
            if len(x) != 0:
                aa.append(len(x))
            if len(y) != 0:
                bb.append(len(y))
        d = [0] + list(accumulate(aa))
        e = [0] + list(accumulate(bb))
        p = d[-1]
        ls = []
        for i in range(len(d)):
            ls.append(e[i]+p-d[i])
        print(min(ls))

Submission status: Runtime Error

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])
    s = lines[1]

    return (n, s)


def solve(n, s):
    
    ss = []
    count_w = 1
    count_b = -1
    before = s[0]
    for i, c in enumerate(s[1:]):
        if before == c:
            if c == ".":
                count_w = count_w + 1
            else:
                count_b = count_b - 1
        else:
            if before == ".":
                ss.append(count_w)
                count_w = 1
            else:
                ss.append(count_b)
                count_b = -1
        before = c

    if before == ".":
        ss.append(count_w)
    else:
        ss.append(count_b)

    if debug:
        log("ss=%s" % ss)


    if ss[0] > 0:
       ss = ss[1:]
    if ss[-1] < 0:
       ss = ss[:-1]
     
    count_w = sum([e for e in ss if e > 0])
    count_b = sum([e for e in ss if e < 0])

    result = min(count_w, abs(count_b))
    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Runtime Error

Solution code:
def pro():
    n, s = int(input()), [s for s in input()]
    if "#" not in s:
        return print(0)
    elif "." not in s:
        return print(0)
    s = s[s.index("#"):]
    for i in range(n):
        if s[-1] == "#":
            s = s[:-1]
        else:
            break
    a = s.count(".")
    b = len(s) - a
    if a > b:
        return print(b)
    else:
        return print(a)
pro()

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
preans = 0
pew = 0
bflag = 0
b2w = 0
for i, word in enumerate(s):
    if bflag == 0:
        if word == '#':
            bflag = 1
    else:
        if word == '.':
            b2w = 1
    if b2w == 1:
        if word == '.':
            preans += 1
skip = 1
ans2 = 0
for i, word in enumerate(s):
    if b2w > skip:
        ans = min(preans, preans + bcount - wcount)
        preans = preans + bcount - wcount
        skip += 1
        wcount = 0
        bcount = 0

    if word == '#':
        bcount += 1

    if bflag == 0:
        if word == '#':
            bflag = 1
        else:
    else:
        if word == '#':
        else:
            b2w += 1
            bflag = 0

    if b2w == skip and word == '.':
        wcount += 1
print(ans)

Submission status: Runtime Error

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

sl = list(s)


def count_black(wb):
    return wb.count('#')


def count_white(wb):
    return wb.count('.')


wb = []
for i in range(1, n):
    if sl[i-1] != sl[i]:
        wb.append(count_black(sl[:i-1]) + count_white(sl[i:]))

print(min(wb))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def pro():
    n, s = input(), [s for s in input()]
    if "#" not in s:
        return print(0)
    elif "." not in s:
        return print(0)
    s = s[s.index("#"):]
    for i in range(n):
        if s[-1] == "#":
            s = s[:-1]
        else:
            break
    a = s.count(".")
    b = len(s) - a
    if a > b:
        return print(b)
    else:
        return print(a)
pro()

Submission status: Runtime Error

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

S0 = S[0]
L = []
count = 1
Wk=[]
Bk=[]

for i in range(1,N):
    if S[i-1]!=S[i]:
        L.append(count)
        count =1

    else:
        count +=1
    if i ==N-1:
        L.append(count)

lenL=len(L)
Numw =0
Numb =0
Numx =0

if S0 == '.':
    Wk.append(L[0])
    Bk.append(0)
    if S[-1] =='.':
        for i in range(1,lenL):
            if i%2 == 0:
                Numw +=L[i]
                Wk.append(Wk[-1]+L[i])
                Bk.append(Bk[-1])

            else: 
                Numb +=L[i]
                Bk.append(Bk[-1]+L[i])
                Wk.append(Wk[-1])

        m=(min(Numw,Numb))

        tmp = float("inf")


        for k in range(lenL):
            s = Wk[k]+(Bk[-1]-Bk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))
        
    else:

        for i in range(1,len(L)-1):
            if i%2 ==0:
                Numw +=L[i]
                Wk.append(Wk[-1]+L[i])
                Bk.append(Bk[-1])
            else:
                Numb +=L[i]
                Bk.append(Bk[-1]+L[i])
                Wk.append(Wk[-1])
        Bk.append(Bk[-1]+L[-1])

        m=(min(Numb,Numw))
        tmp = float("inf")


        for k in range(lenL):
            s = Wk[k]+(Bk[-1]-Bk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

         

else:
    if S[-1]=='.':
        for i in range(len(L)):
            if i%2 ==0:
                Numb += L[i]
                Bk.append(Bk[-1]+L[i])
                if Wk:
                    Wk.append(Wk[-1])
                else:
                    Wk.append(0)

            else:
                Numw += L[i]
                Bk.append(Bk[-1])
                if Wk:
                    Wk.append(Wk[-1]+L[i])
                else:
                    Wk.append(L[i])

        m=(min(Numb,Numw))
        tmp = float("inf")


        for k in range(lenL):
            s = Wk[k]+(Bk[-1]-Bk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

    else:
        for i in range(len(L)-1):
            if i%2 ==0:
                Numb += L[i]
                Bk.append(Bk[-1]+L[i])
                if Wk:
                    Wk.append(Wk[-1])
                else:
                    Wk.append(0)

            else:
                Numw += L[i]
                Bk.append(Bk[-1])
                if Wk:
                    Wk.append(Wk[-1]+L[i])
                else:
                    Wk.append(L[i])
        Bk.append(L[-1])      
        m=(min(Numb,Numw))
        tmp =float("inf")  


        for k in range(lenL):
            s = Wk[k]+(Bk[-1]-Bk[k])
            tmp = min(tmp,s)
        print(min(tmp,m))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  cin >> n;
  string s;
  cin >> s;
  vector<int> lis(n+1,0);
  a = 0;
  b = 0;
  for (int i = 0; i < n; i++){
    if (s.at(i) == '#')
      a ++;
    if (s.at(n-i-1) == "."){
      b ++;
    }
    lis.at(i) += a;
    lis.at(n-i) += b;
  }
  sort(lis.begin(),lis.end());
  cout << lis.at(0) << endl;
}

Submission status: Runtime Error

Solution code:
N = int(input())
S = [i for i in input()]

start = 0
countb = 0
countw = 0
check = -1
check2 = 0
ans = []

for i in range(len(S)):
    if(S[i] == "#"):
        start = i
        break

for i in range(start,len(S)):
    if(S[i] == "#"):
        check = 1
        countb = countb + 1
    else:
        check = 0
        countw = countw + 1
    if(check == 1 and countw != 0):
        if(countb < countw):
            ans.append(countb)
        else:
            ans.append(countw)
            check2 = 1
        countb = 1
        countw = 0
    if(i == N-1 and check == 0):
        if((countb < countw) and check2 = 0):
            ans.append(countb)
        elif((countb > countw) and check2 = 1):
            ans.append(countw)
        else:
            ans.append(countw)
if(start == 0):
    ans.append(0)

print(sum(ans))

Submission status: Runtime Error

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