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 numpy as np

n = int(input())
s = np.array(list(input())) == '.'

if s.sum() == 0 or s.sum() == n:
    print(0)
    exit()

if not s[0]:
    first_index = np.where(s)[0][0]
else:
    first_index = np.where(np.logical_not(s))[0][0]

if first_index < n:
    second_index = np.where(s[first_index:] == s[0])[0][0] + first_index

    if second_index < n:
        check_list = s[second_index:]

        print(min(check_list.sum(), np.logical_not(check_list).sum()) + min(s[:second_index].sum(),
                                                                            np.logical_not(s[:second_index]).sum()))
    else:
        print(min(s.sum(), np.logical_not(s).sum()))
else:
    print(min(s.sum(), np.logical_not(s).sum()))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

countb = 0
countw = 0
check = -1
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)
        countb = 1
        countw = 0
    if(i == N-1 and check == 0):
        if(countb < countw):
            ans.append(countb)
        else:
            ans.append(countw)

print(sum(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
raw = input()
start_idx = 0
count = 0
 
for s in raw:
    if s == '#':
        break
    start_idx = start_idx + 1
 
tmpb = 1
tmpw = 1
flg = '#'
reset = False
for i in range(start_idx, n):
    if reset:
        tmpb = 1
        tmpw = 1
        flg = '#'
        reset = False
    if flg == '#':
        if raw[i] == flg:
            tmpb = tmpb + 1
        else:
            flg = '.'
    else:
        if raw[i] == flg:
            tmpw = tmpw + 1
        else:
            reset = True
            if tmpb >= tmpw:
                count = count + tmpw
            else:
                count = count + tmpb

if raw[-1] = '.' 
    if tmpb >= tmpw:
        count = count + tmpw
    else:
        count = count + tmpb
 
 
print(count)

Submission status: Runtime Error

Solution code:
s = input()
list_s = list(s)
cnt1 = 0
if list_s[0] == "#" :
  cnt1 = list_s.index(".")
else :
  cnt1 = list_s.index(".")
  cnt1 = cnt1 - 1
print(cnt1)

Submission status: Runtime Error

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

for i in range(N):
    if S[i] == '#' and S[i+1] == '.':
       c += 1
    else:
      pass

print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
# 全部白か黒

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

li = []
li2 = []
tmp = 0
tmp2 = 0
for i in s:
    if i == "#":
        tmp += 1
    else:
        li.append(tmp)
        tmp = 0

for i in s:
    if i == ".":
        tmp2 += 1
    else:
        li2.append(tmp2)
        tmp2 = 0

#print(list(filter(lambda a: a != 0, li)))
#print(list(filter(lambda a: a != 0, li2)))

a = li[0] + sum(li2[1:])
b = sum(li)# 全部白
c = sum(li2)# 全部黒
print(min(a, b, c))

Submission status: Runtime Error

Solution code:
import sys

l = raw_input().split()
N = int(l[0])
l = raw_input().split()
S1 = list(l[0])

S = []
found = False
for s in S1:
    if s == '#':
        found = True
    if not found:
        continue
    S.append(s)

i = len(S) - 1
while i >= 0:
    if S[i] == '#':
        del S[i]
    else:
        break
    i -= 1
# print(S)
num_black = 0
num_white = 0

temp_black = 0
for s in S:
    if s == '#':
        temp_black += 1
    else:
        num_white += 1
        num_black += temp_black
        temp_black = 0

A = []
B = []
found_black = False
found_white = False
for i in range(len(S)):
    s = S[i]
    if s == '#':
        if found_white:
            B.append(A)
            found_white = False
            A = []
        A.append(s)
    else:
        A.append(s)
        found_white = True
    if i == len(S) - 1:
        B.append(A)

def count_num_black(S):
    count = 0
    for s in S:
        if s == '#':
            count += 1
    return count

num_black = count_num_black(B[0])
num_white = len(B[0]) - num_black
ret = min(num_black, num_white)
del B[0]
num_black = num_white = 0
for b in B:
    for a in b:
        if a == '#':
            num_black += 1
        else:
            num_white += 1

print(ret + min(num_black, num_white))

Submission status: Runtime Error

Solution code:
#!/usr/bin/python
# coding: UTF-8

def check(n,s):
    for i in range(1,n):
        if s[i-1] == "#" and s[i] == ".":
            return False
    return True

def exe(n,s,count):
    #print(s)
    if check(n,s):
        return count
    for i in range(1,n):
        if s[i-1] == "#" and s[i] == ".":
            return exe(n-2,s[0:i-1]+s[i+1:],count+1)

N = int(input())
S = input()
if S.count("#") == 0 or S.count(".") == 0:
    print("0")
print(exe(N,S,0))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
if N == 1:
    print("0")
    exit()
for i in range(N-1):
    if S[i] == "." and S[i+1] == "#":
        break
sharp_count = 0
for j in range(i+1,N):
    if S[j] == "#":
        sharp_count += 1

for i in range(N-1):
    index = (N-1)-i
    if S[index] == "#" and S[index-1] == ".":
        break

dot_count = 0
for j in range(index,N):
    if S[j] == "#":
        dot_count += 1

for i in range(1,index):
    j = index+1-i
    if S[j] == "." and S[j-1] == "#":
        break
dot_dot_count = 0
for k in range(j-1):
    if S[k] == ".":
        dot_dot_count += 1
dot_sharp_count = 0
for k in range(j-1):
    if S[k] == ".":
        break
for l in range(k, j-1):
    if S[l] == "#":
        dot_sharp_count += 1
dot_count += min(dot_dot_count, dot_sharp_count)

print(min(sharp_count,dot_count))

Submission status: Runtime Error

Solution code:
def solve():
  N = int(input())
  S = input()
  stones = []
  look = S[0]
  cnt = 0

  if S[0] == '.': stones.append(0)
  for s in S:
    if look == s: cnt += 1
    else:
      stones.append(cnt)
      cnt = 1
      look = s
  stones.append(cnt)
  if S[N - 1] == '#': stones.append(0)

  count = sum(stones[1::2])
  ans = count

  for i in range(0, N - 2, 2):
    count = count + stones[i] - stones[i + 1]
    if ans > count: ans = count
  return ans

print(solve())

Submission status: Runtime Error

Solution code:
import Counter

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

black = s.count('.')
white = s.count('#')
count = 0
if black > white:
 for i in range(n):
  if s[i] == '#':
   s[i+1] = '#'
   count += 1
else:
 for i in range(n):
  if s[i] == '.'
   s[i+1] = '.'
   count += 1

print(count)

Submission status: Runtime Error

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

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

for i in range(len(S)):
    if(S[i] == "#"):
        print("i is ",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)
        countb = 1
        countw = 0
    if(i == N-1 and check == 0):
        print("countb is ", countb, "and countw is",countw)
        if(countb < countw):
            ans.append(countb)
        else:
            ans.append(countw)

print(sum(ans))

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
 if first_black_index != N:
   S = S[first_black_index:N+1]

   if S[len(S)-1] == "#":
     N = N-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:
import sys
N = int(input())
S = input()
s_list = list(S)
temp_start = N+1
count_1 = 0
count_2 = 0
for i in range(N-1):
    if s_list[i] == "#":
        temp_start = i
        break
if temp_start == N+1:
    print(0)
    sys.exit()
for i in range(N)[::-1]:
    if s_list[i] != "#":
        temp_end = i
        break
for i in range(temp_start,temp_end + 1):
    if s_list[i] == "#":
        count_1 += 1
    else :
        count_2 += 1
print(min(count_1,count_2))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = list(input())

m = ['#', '.']
m1 = ['#', '.', '#']
m2 = ['#', '.', '.']
m3 = ['#', '#', '.']
m4 = ['.', '#', '.']

def check(i):
    global S
    if S[i-1:i+1] == m:
        matching(i-1)


def matching(i):
    global S, count
    if S[i:i+2] != m:
        return

    flag = True
    if i>=0 and i<= N-3:
        if S[i:i+3] == m1:
            count +=1
            S[i] = '#'
            flag = False
        elif S[i:i+3] == m2:
            count += 1
            S[i] = '.'
            flag = False
    if flag == False:
        check(i)
        return

    if i==0: return

    if S[i-1:i+2] == m3:
        S[i+1] = '#'
        count += 1
    elif S[i-1:i+2] == m4:
        S[i] = '.'
        count += 1
    check(i)

count = 0


for i in range(N):
    matching(i)

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
cums = []
count = 0
count_white = 0
count_black = 0

for i in range(len(s)):
  #count_white = 0
  #count_black = 0
  if s[i] == '.':
    count_white += 1
    if count_black != 0:
      cums.append(count_black)
      count_black = 0
  else:
    count_black -= 1
    if count_white != 0:
      cums.append(count_white)
      count_white = 0
if count_white != 0:
  cums.append(count_white)
if count_black != 0:
  cums.append(count_black)

ans = 0


#for i in range(len(cums)//2):
while len(cums) > 3:
  if abs(cums[0]) <= abs(cums[1]) and cums[0]*cums[1] < 0:
    ans += abs(cums[0])
    cums[1] += -cums[0]
    cums.pop(0)
  elif abs(cums[0]) >= abs(cums[1]) and cums[0]*cums[1] < 0:
    bw = '.'
    ans += abs(cums[1])
    cums[0] += -cums[1]
    cums.pop(1)
  else:
    cums[0] += cums[1]
    cums.pop(1)
  #count += min(cums[2*i], cums[2*i+1])

if cums[0]*cums[1] > 0 or cums[1]*cums[2] > 0:
  pass
else:
  if cums[0] > 0:
    a, b = cums[0], cums[2]
    if a < b:
      ans += a
    else:
      ans += b
  else:
    a, b = cums[0], cums[1]
    if abs(a) < abs(b):
      ans += abs(a)
    else:
      ans += abs(b)

print(ans)

Submission status: Runtime Error

Solution code:
import Counter

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

black = s.count('.')
white = s.count('#')

if black > white:
 for i in range(n):
  if s[i] == '#':
   s[i+1] = '#'
else:
 for i in range(n):
  if s[i] == '#':
   s[i+1] = '#'
print(s)

Submission status: Runtime Error

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

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

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

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

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

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

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
S = list(input())
 
S_1 = copy.copy(S)
S_2 = copy.copy(S)
S_3 = copy.copy(S)
S_4 = copy.copy(S)
count_1 = 0
count_3 = 0

for i in range(N-1):
  if S_1[i] == "#" and S_1[i+1] == ".":
    if i != N - 1:
      if S_1[i+2] == "#":
        S_1[i+1] = "#"
      else:
        S_1[i+1] = "."
    count_1 += 1
    
#for i in range(N-1):
#  if S_2[i] == "#" and S_2[i+1] == ".":
#    S_2[i] = "."
#    count_2 += 1
    
for i in range(N-1):
  if S_3[N - i - 1] == "." and S_3[N - i - 2] == "#":
    if i != N - 1:
      if S_3[N - i -3] == "#":
        S_3[N - i - 1] = "#"
      else:
        S_3[N - i - 2] = "."
    count_3 += 1
    
#for i in range(N-1):
#  if S_4[N - i - 1] == "." and S_4[N - i - 2] == "#":
#    S_4[N - i - 2] = "."
#    count_4 += 1
    
print(min(count_1, count_3))

Submission status: Runtime Error

Solution code:
import Counter

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

black = s.count('.')
white = s.count('#')

if black > white:
 for i in range(n):
  if s[i] == '#':
   s[i+1] = '#'
else:
 for s in S:
   for i in range(n):
  if s[i] == '#':
   s[i+1] = '#'

print(s)

Submission status: Runtime Error

Solution code:
import numpy as np

dic={'.':0,'#':1}
N=int(input())
S=np.array([dic[i] for i in input()])
arr=np.flip(np.triu(np.ones((N,N))),axis=1)==0

if S.sum()==0:
    print(0)
elif S.sum()==N:
    print(0)    
else:
    print(min((arr!=S).sum(axis=1)))

Submission status: Runtime Error

Solution code:
using System;
using static System.Console;
using static cp;
using System.Text;
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var alg = new cp();

        int n = alg.inputInt();
        string s = alg.inputString();
        //累積和
        var sharp = new int[n + 1];
        var dot = new int[n + 1];
        for(int a = 0; a < n+1; a++)
        {
            if (a == 0)
            {
                sharp[a] = 0;
                dot[a] = 0;
            }
            else
            {
                if (s[a-1]=='#')
                {
                    sharp[a] = sharp[a - 1] + 1;
                    dot[a] = dot[a - 1];
                }
                else
                {
                    sharp[a] = sharp[a - 1];
                    dot[a] = dot[a - 1]+1;
                }
                
            }
        }
        int min = 100000000;
        for(int a = 0; a < n + 1; a++)
        {
            int num=sharp[a]+dot[dot.Length-1]-dot[a];
            min = Math.Min(num,min);
        }
        WriteLine(min);
    }
}

class cp
{

    public cp()
    {
    }
    public int GCD(int a, int b)
    {
        return a % b == 0 ? b : GCD(b, a % b);
    }
    public int LCM(int a, int b)
    {
        return a * b / GCD(a, b);
    }
    public int countChar(string s, string key)
    {
        return s.Length - s.Replace(key, "").Length;
    }
    public string YesNo(bool f, string type = null)
    {
        string str;
        if (f) str = "Yes"; else str = "No";
        if (type == "lower") return str.ToLower(); else if (type == "upper") return str.ToUpper(); else return str;
    }
    public void inputSkip()
    {
        ReadLine();
        return;
    }
    public string inputString()
    {
        return ReadLine();
    }
    public string[] inputSplitString()
    {
        return ReadLine().Split();
    }
    public string[] inputLinesString(int len)
    {
        var arr = new string[len];
        for (int a = 0; a < len; a++)
        {
            arr[a] = ReadLine();
        }
        return arr;
    }
    public string[][] inputJaggedArrayString(int len)
    {
        var arr = new string[len][];
        for (int a = 0; a < len; a++)
        {
            arr[a] = ReadLine().Split();
        }
        return arr;
    }
    public int inputInt()
    {
        return int.Parse(ReadLine());
    }
    public int[] inputSplitInt()
    {
        return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
    }
    public int[] inputLinesInt(int len)
    {
        var arr = new int[len];
        for (int a = 0; a < len; a++)
        {
            arr[a] = int.Parse(ReadLine());
        }
        return arr;
    }
    public int[][] inputJaggedArrayInt(int len)
    {
        var arr = new int[len][];
        for (int a = 0; a < len; a++)
        {
            arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        }
        return arr;
    }
    public long inputLong()
    {
        return long.Parse(ReadLine());
    }
    public long[] inputSplitLong()
    {
        return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
    }
    public long[] inputLinesLong(int len)
    {
        var arr = new long[len];
        for (int a = 0; a < len; a++)
        {
            arr[a] = long.Parse(ReadLine());
        }
        return arr;
    }
    public long[][] inputJaggedArrayLong(int len)
    {
        var arr = new long[len][];
        for (int a = 0; a < len; a++)
        {
            arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray();
        }
        return arr;
    }
    public double inputDouble()
    {
        return double.Parse(ReadLine());
    }
    public double[] inputSplitDouble()
    {
        return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
    }
    public double[] inputLinesDouble(int len)
    {
        var arr = new double[len];
        for (int a = 0; a < len; a++)
        {
            arr[a] = double.Parse(ReadLine());
        }
        return arr;
    }
    public double[][] inputJaggedArrayDouble(int len)
    {
        var arr = new double[len][];
        for (int a = 0; a < len; a++)
        {
            arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray();
        }
        return arr;
    }
}

Submission status: Runtime Error

Solution code:
import Counter

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

black = S.count('.')
white = S.count('#')

if black > white:
 for i in range(n):
  if s[i] == '#':
   s[i+1] = '#'
else:
 for s in S:
   for i in range(n):
  if s[i] == '#':
   s[i+1] = '#'

print(s)

Submission status: Runtime Error

Solution code:
import sys

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

score1 = 0
score2 = 0
length = 1
check = S[0]
A = []
B = []
flag = 0

for i in range(N-1):
    if S[i] == S[i+1]:
        length += 1
    else:
        A.append(length)
        length = 1

if length != 1:
    A.append(length)

if len(A) != 0:
    if S[-1] != S[-2]:
        A.append(1)

if len(A) <= 1:
    print(0)
    sys.exit()

B = A

if S[0] == ".":
    A.pop(0)

if S[len(S)-1] == "#":
    A.pop(-1)


for i in range(len(A)):
    if i % 2 == 0:
        score1 += A[i]
    else:
        score2 += A[i]

ans = min(score1,score2)

if S[0] == "#":
    score3 = A[0] + score2 - A[1]
    ans = min(ans,score3)

if S[0] == ".":
    score4 = A[-1] + score1 - A[len(A)-2]
    ans = min(ans,score4)

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
	n = int(input())
	s = input()
	ans1, ans2 = 0, 0
	ans1 = change1(n, list(s), ans1)
	ans2 = change2(n, list(s), ans2)
	print(min(ans1, ans2))

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

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


if __name__ == '__main__':
	import sys
	sys.exit(main())

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
ts = ['.' * i + '#' * (n - i) for i in range(n+1)]
print(min(sum(s[i] != t[i] for i in range(n)) for t in ts))

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
siro = S.count(".")
kuro = S.count("#")
if kuro < siro:
	change_num = kuro
elif kuro > siro:
	change_num = siro
else:
	# kuro == siro
	for i in range(N-1):
		if S[i] == "#" and S[i+1]==".":
			change_num = change_num + 1
print(change_num)

Submission status: Runtime Error

Solution code:
    N = int(input())
    S = input()
    fb = 0
    cand = []
    b = []
    w = []
    cand.append(S.count('#'))
    cand.append(S.count('.'))
    for i in range(N):
        if S[i] == '#':
            b.append(i)
        elif S[i] == '.':
            w.append(i)
    for i in range(len(b) - 1):
        wh = 0
        for j in w:
            if j > b[i + 1]:
                wh += 1
        cand.append(1 + i + wh)
    print(min(cand))
main()

Submission status: Runtime Error

Solution code:
from itertools import groupby
N = int(input())
S = input()
b = 0
w = 0
x = ""
for i, (k, v) in enumerate(groupby(S)):
  if not x:
    if k == ".":
      continue
  v = len(list(v))
  if k == "#":
    b += v
  else:
    w += v
  x += k
if x[-1] == "#":
  b -= v
print(min(b,w))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
S = list(input())
 
S_1 = copy.copy(S)
S_2 = copy.copy(S)
S_3 = copy.copy(S)
S_4 = copy.copy(S)
count_1 = 0
count_3 = 0

for i in range(N-1):
  if S_1[i] == "#" and S_1[i+1] == ".":
    if S_1[i+2]:
      if S_1[i+2] == "#":
        S_1[i+1] = "#"
      else:
        S_1[i+1] = "."
    count_1 += 1
    
#for i in range(N-1):
#  if S_2[i] == "#" and S_2[i+1] == ".":
#    S_2[i] = "."
#    count_2 += 1
    
for i in range(N-1):
  if S_3[N - i - 1] == "." and S_3[N - i - 2] == "#":
    if S_3[N - i - 3]:
      if S_3[N - i -3] == "#":
        S_3[N - i - 1] = "#"
      else:
        S_3[N - i - 2] = "."
    count_3 += 1
    
#for i in range(N-1):
#  if S_4[N - i - 1] == "." and S_4[N - i - 2] == "#":
#    S_4[N - i - 2] = "."
#    count_4 += 1
    
print(min(count_1, count_3))

Submission status: Runtime Error

Solution code:
import sys


def count(split_haichi):
    black_count = sum([x == '#' for x in split_haichi])
    white_count = len(split_haichi) - black_count
    return min(black_count, white_count)


a = []
for l in sys.stdin:
    a.append(l)

num = int(a[0])
haichi = a[1]
count_list = []

black_all_count = sum([x == '#' for x in haichi])
white_all_count = num - black_all_count
for i in range(num-1):
    if haichi[i] == '#':
        split_haichi_1 = haichi[:i+1]
        split_haichi_2 = haichi[i+1:]

        black_count_1 = sum([x == '#' for x in split_haichi_1])
        white_count_1 = len(split_haichi_1) - black_count_1

        black_count_2 = black_all_count - black_count_1
        white_count_2 = white_all_count - white_count_1

        count_list.append(min(black_count_1, white_count_1) + min(black_count_2, white_count_2))

print(min(count_list))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
S = list(str(input()))
 
#print(N,S)
 
box = []
a = 1
for i in range(N-1):
    #print(S[i],S[i+1])
    if S[i] == "#" and S[i+1] == "." or S[i] == "." and S[i+1] == "#":
        box.append(a)
        a = 1
        
        
    else:
        a += 1
        
    if i == N-2:
            box.append(a)    
 
#print(box)

BLACK = 0
WHITE = 0

if S[0] == ".":
    del box[0]
    
if S[len(box)-1] == "#":
    del box[0]
    
for i in range(0,len(box)):
    if i % 2 == 1:
        BLACK += box[i]
    else:
        WHITE += box[i]

print(min(BLACK,WHITE))

Submission status: Runtime Error

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

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

for i in reversed(S):
    new_S += i

for i in range(N):
    if new_S[i] == ".":
        S_new = S[i:]
        break
else:
    S_new = ""

print(min(S_new.count('#'), S_new.count('.'), len(S_new)))

Submission status: Runtime Error

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

ans1 = 1e7
ans2 = 1e7
ans3 = 1e7
f = False
for i in range(N-1):
    if S[i:i+2] == "#.":
        ans1 = S[i+1:].count(".")
        f = True
        break

for i in range(N-1):
    j = N - i
    if S[j-2:j] == "#.":
        ans2= S[:j-1].count("#")
        f = True
        break
        
for k in range(j-1):
    if S[j-2-k] == ".":
        ans3 = S[:j-1-k].count("#") + S[j-1:].count(".")
        break
    
print(min(ans1, ans2, ans3) if f else 0)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
s = list(s)
cnt = 0
for i in range(n-2):
  if s[i] == '.' and s[i+1] == '#' and s[i+2] == '.':
    s[i+1] = '.'
    cnt+=1
  if s[i] == '#' and t[i+1] == '.' and t[i+2] == '#':
    s[i+1] = '#'
    cnt+=1

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

print(cnt)

Submission status: Runtime Error

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

count = 0
white_count = 0
white_count2 = 0
black_count = 0
black_No = 0

for i in range(n):
    if s[i] == "#":
        black_No = i
        break

for i in range(n - black_No):
    if s[i + black_No] == ".":
        white_No = i + black_No
        break

while True:
    try:
        if s[white_No + count] == ".":
            count += 1
        else:
            break
    except:
        break

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

if count > white_No - black_No:
    t = n - white_No - count
    for i in range(t):
        if s[i + white_No + count] == ".":
            white_count2 += 1
    for j in range(n - t):
        if s[j] == "#":
            black_count += 1
    result = black_count + white_count2
else:
    result = white_count

print(result)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python
# coding: UTF-8

def check(n,s):
    for i in range(1,n):
        if s[i-1] == "#" and s[i] == ".":
            return False
    return True

def exe(n,s,count):
    if check(n,s):
        return count
    for i in range(1,n):
        if s[i-1] == "#" and s[i] == ".":
            return exe(n-2,s[0:i-1]+s[i+1:],count+1)
N = int(input())
S = input()

print(exe(N,S,0))

Submission status: Runtime Error

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


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

for x in range(I,N-1):
    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
w = s.count('.')
for i in range(0,n-1):
    if (s[i]=='#')&&(s[i+1]=='.'):
        ans+=1
        s[i+1]='#'
print(min(ans,w,n-w))

Submission status: Runtime Error

Solution code:
import sys

def count(split_haichi):
    black_count = sum([x == '#' for x in split_haichi])
    white_count = len(split_haichi) - black_count
    return min(black_count, white_count)

a = []
for l in sys.stdin:
    a.append(l)

num = int(a[0])
haichi = a[1]
count_list = []

black_all_count = sum([x == '#' for x in haichi])
white_all_count = num - black_all_count
for i in range(num-1):
    split_haichi_1 = haichi[:i+1]
    split_haichi_2 = haichi[i+1:]

    black_count_1 = sum([x == '#' for x in split_haichi_1])
    white_count_1 = len(split_haichi_1) - black_count_1

    black_count_2 = black_all_count - black_count_1
    white_count_2 = white_all_count - white_count_1

    count_list.append(min(black_count_1, white_count_1) + min(black_count_2, white_count_2))

print(min(count_list))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n=2
a=[input() for i in range(n)]
N=int(a[0])
S=list(a[1])

kazuXD=0
flg=0
kazu=0
for i in range(N):
  if flg==0:
    if S[i]==".":
      kazu+=1
    else:
      flg=1
flag=0
unko=0
for i in range(N):
  if flag==0:
    if S[N-i]=="#":
      unko+=1
    else:
      flag=1
for i in range(kazu,N):
  if S[i]==".":
    S[i]="#"
    kazuXD+=1

kazuta=0
for i in range(unko,N):
  if S[N-i]=="#":
    S[N-i]="."
    kazuta+=1
if kazuXD>=kazuta:
  print(kazuta)
else:
  print(kazuXD)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
white = (S)
white = S.count('.')
black = S.count('#')
for i in range(0,N):
    if S[i] == '.':
        last_white = i+1
l_w = last_white - white
if l_w <= white and l_w <= black:
    print(l_w)
elif white <= l_w and white <= black:
    print(white)
elif black <= l_w and black <= white:
    print(black)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = list(input())

m = ['#', '.']
m1 = ['#', '.', '#']
m2 = ['#', '.', '.']
m3 = ['#', '#', '.']
m4 = ['.', '#', '.']

def check(i):
    global S
    if S[i-1:i+1] == m:
        matching(i-1)


def matching(i):
    global S, count
    if S[i:i+2] != m:
        return

    flag = True
    if i>=0 and i<= N-3:
        if S[i:i+3] == m1:
            count +=1
            S[i] = '.'
            flag = False
        elif S[i:i+3] == m2:
            count += 1
            S[i] = '.'
            flag = False
    if flag == False:
        check(i)
        return

    if i==0: return

    if S[i-1:i+2] == m3:
        S[i+1] = '#'
        count += 1
    elif S[i-1:i+2] == m4:
        S[i] = '.'
        count += 1
    check(i)

count = 0


for i in range(N):
    matching(i)

print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
ans=0
w = s.count('.')
for i in range(0,n-1):
    if (s[i]=='#')&(s[i+1]=='.'):
        ans+=1
        s[i+1]='#'
print(min(ans,w,n-w))