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=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        #break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        #break

count=0
#print(dot)#左から
#print(sha)#右から
count_a=0
count_b=0

for i in range(N):
    if i<dot and S[i]!=".":
        count_a+=1
for i in range(N):
    if i<sha and s_r[i]!="#":
        count_b+=1
#print(count)
if dot<=sha:
    c=count_a+count_b
else:
    d=min(count_a,count_b)

a=0
b=0

for i in range(N):
    if S[i]!=".":
        a+=1
    if S[i]!="#":
        b+=1

#print(count)
ans=min(a,b,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
ans = stdin.readline().rstrip()
sum = 0
left = 0
right = 0
for itr in range(0,len(ans)):
    count_dot = 0
    count_sharp = 0
    left = itr
    right = left + 1
    if left == len(ans)-1:
        break
    if ans[left] == '#' and ans[right] == '.':
        while(right < N and ans[right] == '.'):
            count_dot += 1
            right += 1
        while(left >= 0 and ans[left] == '#'):
            count_sharp += 1
            left -= 1
        if tmp != 0:
            count += 1
        sum += max(count_dot, count_sharp)
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
#white
i=0
numw=0
while s[i]==".":
    numw+=1
    i+=1
    if i == n:
        break
#  ..##.#..
w = s.count(".")
answ = w-numw

#black
j=-1
numb=0
while s[j]=="#":
    numb+=1
    j-=1
    if j*(-1) == n:
        break
b = s.count('#')
ansb=b-numb

#b&w
bw=0
k=numw
if k!=0:
    while s[k]=="#":
        k+=1
        bw+=1
        if k==n:
            break
wb=0
l=numb*(-1)-1
if l!=-1:
    while s[l]==".":
        l-=1
        wb+=1
        if l==n*(-1):
            break
ans3=bw+wb
print(min(ansb,answ,ans3))

Submission status: Runtime Error

Solution code:
N=int(input())
S=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        #break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        #break

count=0
#print(dot)#左から
#print(sha)#右から
count_a=0
count_b=0

if dot<=sha:
    for i in range(N):
        if i<dot and S[i]!=".":
            count_a+=1
    for i in range(N):
        if i<sha and s_r[i]!="#":
            count_b+=1
    #print(count)
    c=count_a+count_b
else:
    d=min(count_a,count_b)

a=0
b=0

for i in range(N):
    if S[i]!=".":
        a+=1
    if S[i]!="#":
        b+=1

#print(count)
ans=min(a,b,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
def main():
    n = input()
    s = input()

    # 最初に黒い石が出現した後に出現した"."と"#"のそれぞれの総数のうち、最小のものを返す
    b_num = 0
    w_num = 0
    is_start = False
    for c in s[:n]:
        if not is_start:
            if c != "#":
                continue
            else:
                is_start = True
        if c == ".":
            w_num += 1
        else:
            b_num += 1

    return min(w_num, b_num)


print(main())

Submission status: Runtime Error

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

for i in range(N):
    if S[i]=='#':
        break
B = S[i:].count('#')
W = S[i:].count('.') - len(S[i:].split('#')[1])
if S[-1]=="#":
    B -= 1
ans = min(B,W+1)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
#white
i=0
numw=0
while s[i]==".":
    numw+=1
    i+=1
    if i == n:
        break
#  ..##.#..
w = s.count(".")
answ = (w-numw).copy()

#black
j=-1
numb=0
while s[j]=="#":
    numb+=1
    j-=1
    if j*(-1) == n:
        break
b = s.count('#')
ansb=(b-numb).copy()

#b&w
bw=0
k=numw.copy()
if k!=0:
    while s[k]=="#":
        k+=1
        bw+=1
        if k==n:
            break
wb=0
l=(numb*(-1)-1).copy()
if l!=-1:
    while s[l]==".":
        l-=1
        wb+=1
        if l==n*(-1):
            break
ans3=bw+wb
print(min(ansb,answ,ans3))

Submission status: Runtime Error

Solution code:
"""
python3 a.py < input.txt
"""
import math
import itertools as it
import heapq

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

T=[S[0]]
U=[1]
for si in S[1:]:
    if T[-1] == si:
        U[-1] = U[-1]+1
    else:
        T.append(si)
        U.append(1)

lb=None
for i in reversed(range(len(T))):
    if T[i] == "#":
        lb=i
rb=None
for i in range(len(T)):
    if T[i] == "#":
        rb=i
rw=None
for i in range(len(T)):
    if T[i] == ".":
        rw=i

if lb == None or rw == None:
    print(0)
    exit()

nb=0
for i in range(lb, len(T)):
    if T[i] == ".":
        nb = nb+U[i]
nw=0
for i in range(rw):
    if T[i] == "#":
        nw = nw+U[i]
nx=0
for i in range(lb, rb):
    if T[i] == "#":
        nx = nx+U[i]
for i in range(rw, len(T)):
    if T[i] ==x".":
        nx = nw+U[i]
print(S)
print(min([nb, nw, nx]))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
ans = 0
kuro_count = 0
shiro_count = 0
t = 0
i = 0
is_shiro = False
while True:
  if i == N-1:
    break
  if S[i] == "#":
    for j in range(i, N-1):
      if S[j] == "#":
        kuro_count += 1
      else:
        shiro_count += 1
        if S[j+1] == "#":
          t = j
          break
    if kuro_count < shiro_count:
      ans += kuro_count
    i += t
  i += 1
print(ans)

Submission status: Runtime Error

Solution code:
from numpy import*
from itertools import*
n=int(input())
s=input()
t=s.count("#")
r=s.count(".")
 
l=[t,r]
x=[len(list(v))for k,v in groupby(s)if k=="#"]
y=[len(list(v))for k,v in groupby(s)if k=="."]
if len(x)>len(y):
    y=[0]+y
elif len(x)<len(y):
    x=[0]+x
else:
    if s[0]=="#":
        y=[0]+y
        x=x+[0]
    else:
        y=y+[0]
        x=[0]+x
 
x=array([0]+list(accumulate(x)))
y=array(list(accumulate(y[::-1]))[::-1]+[0])
print([min(x+y),t,r]))

Submission status: Runtime Error

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

if S == ['#'] * N or S == ['.'] * N:
    print(0)
    exit()
ans = 0
b, w = 0, 0
for j in range(N):
    if S[j] == '.':
        w += 1
    else:
        b += 1
    if b < w and b != 0 and w != 0:
        ans += b
        num = j
        b, w = 0, 0

b, w = 0, 0
for j in range(N - 1, num, -1):
    if S[j] == '.':
        w += 1
    else:
        b += 1
    if b > w and b != 0 and w != 0:
        ans += w
        b, w = 0, 0

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
sharp=[]
dot=[]
c=s[0]
if s[0]!=".":
    dot.append(0)
cnt=1
i=0
while i<n-1:
    while True:
        if s[i+1]==s[i]:
            cnt+=1
            i+=1
            if i>=n-1:
                if s[i-1]==".":
                    dot.append(cnt)
                else:
                    sharp.append(cnt)
                break
        else:
            if s[i]==".":
                dot.append(cnt)
            else:
                sharp.append(cnt)
            i+=1
            cnt=1
            break
if s[-2]!=s[-1]:
    if s[-1]==".":
        dot.append(1)
    else:
        sharp.append(1)
if len(dot)>len(sharp):
    sharp.append(0)
ans=sum(dot[1:])
tmp=0
for i in range(len(dot)-1):
    tmp=ans-dot[i+1]+sharp[i]
    ans=min(tmp,ans)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
mini=len(s)
for i in range(len(s)+1):
  e=s[0:i].count("#")+s[i:len(s)](".")
  if e<mini:
    mini=e
print(mini)

Submission status: Runtime Error

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

n = int(input())
state = input()
state_list = list(state)
state_list.append(" ")

#specify the locate causing problem
prob_locate = []
prob_num = 0
for i in range(n):
	if state_list[i] == "#" and state_list[i+1] == ".":
		prob_locate.append(i)
		prob_num += 1
if prob_num == 0:
		print(0)
		exit()

#finding optimal position
import random
while prob_num > 0:
	for i in prob_locate:
		r_0 = random.randint(0,1)
		r_1 = random.randint(0,1)
		state_list[(i + r_0)] = ["#", "."][r_1]
	prob_locate = []
	prob_num = 0
	for i in range(n):
		if state_list[i] == "#" and state_list[i+1] == ".":
			prob_locate.append(i)
			prob_num += 1

#checking the difference
statelist.remove(" ")
diff = 0
for i, j in zip(state_list, list(state):
	if i != j: diff += 1

print(diff)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
S=list(input())
count=0
countdot=0
countdot2=0
x=0
for i in range(N-1):
    if S[i]=='#' and S[i+1]=='.':
        count=S[:i].count('#')
        p=i
        break
    else:
        pass
for i in range(p,N):
    if S[i]=='#':
        countdot=S.count('.')
        break
    else:
        pass
x=min(count,countdot)
for i in range(N):
    if S[i]=='.':
        countdot2=countdot2+1
    else:
        pass
print(min(cout+countdot2,countdot))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
count=0
count1=0
now=0
for i in range(n,0,-1):
  if s[i]=="#":
    count=count+1
  else:
    count1=count1+1
  if count<count1:
    now=i-1
    break
for i in range(now,0,-1):
  if s[i]=="#":
    count=count+1
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
s = str(input())
len_s = range(len(s))
count_sharp = s.count("#")
count_dot = s.count(".")
for i in len_s:
    if s[i] == "#":
        s = s[i::]
count_sharp = s.count("#")
count_dot = s.count(".")
print(min(count_dot, count_sharp))

Submission status: Runtime Error

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

a = s[0:s.rfind('.')].count('#')
b = s[s.find('#'):n].count('.')
c = 0

for i in range(n//2):
  if s[i] == "#" and s[i:n].find('.') != -1:
    c += 1
  if s[n-i] == "." and s[i:n].find('#') != -1:
    c += 1
    
ans = min([a, b, c])
print(ans)

Submission status: Runtime Error

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

if S == ['#'] * N or S == ['.'] * N:
    print(0)
    exit()
ans = 0
b, w = 0, 0
for j in range(N):
    if S[j] == '.':
        w += 1
    else:
        b += 1
    if b < w and b != 0 and w != 0:
        ans += b
        num = j
        b, w = 0, 0

b, w = 0, 0
    for j in range(N - 1, num, -1):
        if S[j] == '.':
            w += 1
        else:
            b += 1
        if b > w and b != 0 and w != 0:
            ans += w
            b, w = 0, 0

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
count=0
now=0
for i in range(n,0,-1):
  if s[i]=="#":
    count=count+1
  else:
    count1=count1+1
  if count<count1:
    now=i-1
    break
for i in range(now,0,-1):
  if s[i]=="#":
    count=count+1
print(count)

Submission status: Runtime Error

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

count = 0
counts = []
prev = "."
for i in range(N):
  if S[i] != prev:
    counts.append(count)
    count = 0
    
  if S[i] == ".":
    count += 1
  if S[i] == "#":
    count += 1
    
  prev = S[i]
counts.append(count)

res = 0
for i in range(len(counts)):
  if i % 2 == 1:
    if counts[i] < counts[i+1]:
      res += counts[i]
    else:
      res += counts[i+1]
      
res = 0
cursor = 1
while cursor <= len(counts)-2:
  if cursor % 1 == 1:
    if counts[cursor] < counts[cursor+1]:
      res += counts[cursor]
      counts = counts[:cursor-1] + [counts[cursor-1] + counts[cursor] + counts[cursor+1]] + counts[cursor+2:]
    else:
      res += counts[cursor]
      if cursor == len(counts)-2:
        counts = counts[:cursor-1] + [counts[cursor] + counts[cursor+1]]
      else:
        counts = counts[:cursor-1] + [counts[cursor] + counts[cursor+1] + counts[cursor+2]] + counts[cursor+3:]
        
print(res)

Submission status: Runtime Error

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

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:
N=int(input())
S = input()
left = -1
for i, s in enumerate(S):
    if s == '#':
        left = i
        break

now = ''
left2 = -1
for i, s in enumerate(S[::-1]):
    if s == '.' and now=='':
        now='.'
    elif s=='#' and now=='.':
        now = '#'
    elif s=='.' and now=='#':
        left2 = i
        break
 
left2 = len(S)-left2

if S[-1]=='#':
    mae = len(S.split('.')[-2])
    ato = len(S.split('#')[-2])
    ans = min(S.count('#'), S[left:].count('.'))
    ans = min(ans, S[left:left2].count('#')+min(mae, ato))
    print(ans)
else:
    mae = len(S.split('.')[-2])
    ato = len(S.split('#')[-1])
    ans = min(S.count('#'), S[left:].count('.'))
    ans = min(ans, S[left:left2].count('#')+min(mae, ato))
    print(ans)

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 = list(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(ideals, min(counts))

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:
N = int(input())
S = input()

count = 0
lines = ""

for i in range(N):
    if i == 0 or i ==N:
        if S[i] == "#" and S[i+1] == ".":
            count += 1
            #lines = lines + "#"
        else:
            #lines = lines + [""]
            pass
    else:
        if i == 0 and S[i]=="#":
            if S[i+1] == ".":
                #lines = lines + "."
                count += 1
        else:
            pass
            #lines = lines + S[i]
print(count)

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
count = 0
for j in range(i,N):
    if S[j] == ".":
        count +=1

for i in range(N-1):
    index = (N-1)-i
    if S[i] == "." and S[i-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(count,dot_count))

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()])
ans=N
arr=np.ones((N,N))


if S.sum()==0:
    print(0)
elif S.sum()==N:
    print(0)    
else:
    for i in range(N):
        arr[i,:N-i]=0
        ans=min(ans,(arr[i,:]!=S).sum())
        
    print(ans)

Submission status: Runtime Error

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

s = list(s)

count1 = 0
count2 = 0

for i in range(n):
    if s[i] == '.':
        count1 += 1
    else:
        count2 += 1
        
if s[0] == '.':
    count1 -= 1

if s[n] == '#':
    count2 -= 1
        
print(min(count1,count2))

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
S = list(input())
P = S[:]

wlist = []
blist = []
for i in range(N):
    wlist.append('.')
    blist.append('#')

if S != wlist and S != blist:

    if P[-1] =='#' and P != wlist and P != blist:
        count = 0
        while P[-1] == "#":
            P.pop(-1)
            count += 1
        ls = []
        for i in range(N-count):
            ls.append('.')
        for i in range(count):
            ls.append('#')
    elif P[-1] == "." and P != wlist and P != blist:
        count = 0
        while P[-1] == ".":
            P.pop(-1)
            count += 1
        while P[-1] == "#":
            P.pop(-1)
            count += 1
        ls = []
        for i in range(N-count):
            ls.append('.')
        for i in range(count):
            ls.append('#')
    w = 0
    b = 0
    l = 0
    for i in range(N):
        if S[i] != wlist[i]:
            w += 1
        if S[i] != blist[i]:
            b += 1
        if S[i] != ls[i]:
            l += 1
    print(min(w,b,l))
else:
    w =0
    b = 0
    for i in range(N):
        if S[i] != wlist[i]:
            w += 1
        if S[i] != blist[i]:
            b += 1
    print(min(w,b))

Submission status: Runtime Error

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

change_sum = 0

for i in range(int(N/2)-1):
  if S[int(N/2)-1-i] =="#" and S[int(N/2)-1-i] == ".":
    S = S[int(N/2)-1 -i:] + "." +S[:int(N/2) -i]
    change_sum += 1
  else:
    S = S[:int(N/2)-1 -i:] + "#" +S[:int(N/2) -i]    

for i in range(int(N/2)-1):
  if S[int(N/2)-1+i]=="#" and S[int(N/2)-1+i] == ".":
    S = S[int(N/2)-1+i:] + "#" +S[:int(N/2)+i]
    change_sum += 1
  else:
    S = S[int(N/2)-1 -i:] + "." +S[:int(N/2)+i]    

print(change_sum)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
count = 0;
for i in range(N-1):
    if S[i] == "#":
        if S[i+1] == ".":
            if (S[i-1] == "." and i >= 1) or i == 0:
                S[i] = "."
            else:
                S[i+1] = "#"
            count += 1
        elif S[i+1] == "#":
            if S[i+2] == "#":
                S[i] = "."
                count += 1
print(count)

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
count = 0
for j in range(i,N):
    if S[j] == ".":
        count +=1

for i in range(N-1):
    index = (N-1)-i
    if S[i] == "." and S[i-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(count,dot_count))

Submission status: Runtime Error

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

start = -1
black = 1
white = 0
start2 = -1
black2 = 0
white2 = 1

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

if start != -1:
    for i in range(n):
        if i > start:
            if s[i] == "#":
                black+=1
            else:
                white+=1

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

if start != -1:
    for i in range(n):
        if n-i < start2:
            if s[i] == "#":
                black2+=1
            else:
                white2+=1

if start == -1 or start2 == -1:
    print(0)
else:
    if black < white and black < black2 and black < white2:
        print(black)
    elif white < black and white < black2 and white <white2:
        print(white)
    elif black2 < black and black2 < white and black2 < white2:
        print(black2)
    else:
        print(white2)

Submission status: Runtime Error

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

if S == ['#'] * N or S == ['.'] * N:
    print(0)
    exit()
ans = 0
b, w = 0, 0
for j in range(N):
    if S[j] == '.':
        w += 1
    else:
        b += 1
    if b <= w and b != 0 and w != 0:
        ans += b
        num = j
        b, w = 0, 0

b, w = 0, 0
for j in range(N - 1, num, -1):
    if S[j] == '.':
        w += 1
    else:
        b += 1
    if b >= w and b != 0 and w != 0:
        ans += w
        b, w = 0, 0

print(ans)

Submission status: Runtime Error

Solution code:
def chec(s):
    llis = []
    rlis = []
    clis = 0
    lef = 1
    rig = 1
    rtmp = 0
    ltmp = 0
    flg = 0
    na = len(s)
    for i in range(na):
        if na - i != 1 and s[na-i-1] == '#' and s[na-i] == '.' :
            #clis+= 1
            #print(i)
            rtmp = na - i
            ltmp = na - i-1
            while ltmp != 0 and s[ltmp] == s[ltmp-1]:
                lef += 1
                ltmp -= 1
            llis.append(lef)
            while rtmp != na and s[rtmp] == s[rtmp+1]:
                rig += 1
                rtmp += 1
            rlis.append(rig)
            lef = 1
            rig = 1
            rtmp = 0
            ltmp = 0
    #print(llis)
    #print(rlis)

    clis = min(sum(llis),sum(rlis))
    return clis


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

Submission status: Runtime Error

Solution code:
N = int(input())
stones = input().rstrip()
pre_word = stones[0]
stones_list =[]
counter = 0

for i in range(N):
    stones_list.append(stones[i])

for i in range(N):
    present_word = stones_list[i]
    if pre_word == '#' and present_word =='.':
        counter += 1
    pre_word = stones_list[i]

if stones_list not in '#':
    print(0)
else:
    print(counter)

Submission status: Runtime Error

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

    
change=0
s = list(s_0)

#blackのが多い
for i in range(1,n):
  if s[i-1]=="#" and s[i]==".":
    change=change+1
    s[i]="#"


#白のが多い
if change > n - change:
  change=n-change
  if s[n]=="#":
    change=change-1

print(change)

Submission status: Runtime Error

Solution code:
from sys import stdin
input=[]
for i in range(2):
    input.append(stdin.readline().rstrip())

input[0]=int(input[0])
#print(input)
# #の右に.があってはいけない
output=0
"""
for i in range(0,input[0]-1):
    if input[1][i]=="#":
        if input[1][i+1]==".":
            output+=1
"""
input_str=list(input[1])

#print(input_str.count("."))
#print(input_str.count("#"))
#change="#"
if input_str.count(".")<input_str.count("#"):
    change="#"
    x=0
    i=0
    while(x==0):
        #x=1
        if input_str[i]=="#" and input_str[i+1]==".":
            output+=1
            input_str[i+1]=change
            #x=0
            i=0
        else:
            i+=1
        if i == input[0]-1:
            break

else:
    change="."
    x=0
    i=0
    while(x==0):
        #x=1
        if input_str[i]=="#" and input_str[i+1]==".":
            output+=1
            input_str[i]=change
            #x=0
            i=0
        else:
            i+=1
        if i == input[0]-1:
            break

#print(input_str)
print(output)

Submission status: Runtime Error

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

count_list =[]
wc = 0

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

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

count = min(count_list)
print(count)

Submission status: Runtime Error

Solution code:
def func(s, count):
    if len(s) > 0:
        pos1 = s.find("#")
        pos2 = s.find(".")
        pos3 = s[pos2:].find("#")
        if pos3 == -1:
            pos3 = len(s)
        else:
            pos3 = pos3+pos2
        #print(pos1, pos2, pos3, s)
        if pos1 == -1 or pos2 == -1:
            return count

        if pos2-pos1 < pos3-pos2:
            count += pos2-pos1
        else:
            count += pos3-pos2

        return func(s[pos3:], count)
    else:
        return count

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = lisr(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:

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

first_sharp=S.index("#")
first_dot=S.index(".")

S.reverse()
end_sharp=S.index("#") + 1
end_dot=S.index(".") + 1
S.reverse()
    
    
    
if S[-1]==".":
    sharp=S.count("#")
    dot=S.count(".")

    if sharp>dot:
        print(dot)
    elif sharp<dot:
        print(sharp)
        
        
elif S[-1]=="#":
    all_sharp=S.count("#")
    all_dot=S.count(".")

    sharp=0
    for i in range(n-end_dot):
        if S[i]=="#":
            sharp+=1                #シャープ　→　ドット
        
    dot=0
    for j in range(first_sharp,n):
        if S[j]==".":
            dot+=1                  #ドット　→　シャープ
            
    if S[0]=="#":
        print(min(sharp,all_dot))
    
    elif S[0]==".":
        print(min(sharp,dot))

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N = int(input())
S = input()
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)
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(min(len(d), len(e))):
        ls.append(e[i]+p-d[i])
    print(min(ls))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
L = [0] * N
for i in range(N):
    if S[i] == "#":
        # white
        L[i] = 1
    else:
        L[i] = 0
# L = np.array(L, dtype=np.int8)
L2 = np.zeros(N, dtype=np.int16)
# ans = np.abs((L - L2)).sum()
# for i in range(N):
#     L2[N-1-i] = 1
#     ans_tmp = np.abs((L - L2)).sum()
#     ans = min(ans, ans_tmp)
# print(ans)
all_whitedist = np.abs((L - L2)).sum()
dist = np.zeros(N, dtype=np.int16)
dist[0:] = all_whitedist
dist[0] = all_whitedist
for i in range(N):
    if L[N-1-i] == 1:
        dist[i:] -= 1
    else:
        dist[:i] -= 1
indx = np.where(dist == dist.min())[0][0]
L3 = np.zeros(N, dtype=np.int16)
L3[indx:] = 1
ans_tmp = np.abs((L - L3)).sum()
print(min(all_whitedist, ans_tmp))

Submission status: Runtime Error

Solution code:
from numpy import*
from itertools import*
n=int(input())
s=input()
t=s.count("#")
r=s.count(".")

x=[len(list(v))for k,v in groupby(s)if k=="#"]
y=[len(list(v))for k,v in groupby(s)if k=="."]
if len(x)>len(y):
    y=[0]+y
elif len(x)<len(y):
    x=[0]+x
else:
    if s[0]=="#":
        y=[0]+y
        x=x+[0]
    else:
        y=y+[0]
        x=[0]+x
 
x=array([0]+list(accumulate(x)))
y=array(list(accumulate(y[::-1]))[::-1]+[0])
print(min(x+y,t,r))

Submission status: Runtime Error

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

    
change=0
s = list(s_0)

#blackのが多い
for i in range(1,n):
  print("".join(s))
  if s[i-1]=="#" and s[i]==".":
    change=change+1
    s[i]="#"


#白のが多い
if change > n - change:
  change=n-change
  if s[n]=="#":
    change=change-1

print(change)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
tmp1 = 0
tmp2 = 0
sharp = 0
dot = 0
sharp2 = 0
dot2 = 0
for i in range(1, n + 1):
    if s[-i] == "#":
        tmp1 += 1
    else:
        break
for i in range(1, n + 1):
    if s[-i] == ".":
        tmp2 += 1
    else:
        break
# print(s[:n-tmp1])
# print(tmp1)
#for i in s:
#    if i == "#":
#        sharp += 1
#    if i == ".":
#        dot += 1
for i in s[:n - tmp1]:
    if i == "#":
        sharp2 += 1
    if i == ".":
        dot2 += 1
for i in s[:n - tmp2]:
    if i == "#":
        sharp3 += 1
    if i == ".":
        dot3 += 1
print(min(sharp, dot, sharp2, dot2, sharp3. dot3))

Submission status: Runtime Error

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

if S == ['#'] * N or S == ['.'] * N:
    print(0)
    exit()
ans = 0
b, w = 0, 0
for j in range(N):
    if S[j] == '.':
        w += 1
    else:
        b += 1
    if b == w and b != 0 and w != 0:
        ans += b
        num = j
        b, w = 0, 0

b, w = 0, 0
for j in range(N - 1, num - 1, -1):
    if S[j] == '.':
        w += 1
    else:
        b += 1
    if b == w and b != 0 and w != 0:
        ans += b
        b, w = 0, 0

print(ans)

Submission status: Runtime Error

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

def dot_num ():
    cnt = 0
    for i in range (1, N+1):
        if S [i] == '.':
            cnt += 1
    return cnt

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

dots = dot_num ()
hashes = hash_num ()

if S [0] == '.':
    dots -= 1

if S [N] == '#':
    hashes -= 1
    
print (min (dots, hashes))

Submission status: Runtime Error

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

if S == ['#'] * N or S == ['.'] * N:
    print(0)
    exit()
ans = 0
b, w = 0, 0
for j in range(N):
    if S[j] == '.':
        w += 1
    else:
        b += 1
    if b == w and b != 0 and w != 0:
        ans += b
        num = j
        b, w = 0, 0

b, w = 0, 0
for j in range(N - 1, num + 1, -1):
    if S[j] == '.':
        w += 1
    else:
        b += 1
    if b == w and b != 0 and w != 0:
        ans += b
        b, w = 0, 0

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
#white
i=0
numw=0
while s[i]==".":
    numw+=1
    i+=1
    if i == n:
        break
#  ..##.#..
w = s.count(".")
answ = w-numw

#black
j=-1
numb=0
while s[j]=="#":
    numb+=1
    j-=1
    if j*(-1) == n:
        break
b = s.count('#')
ansb=b-numb

#b&w
bw=0
k=numw-1
if k!=0:
    while s[k]=="#":
        k+=1
        bw+=1
        if k==n:
            break
wb=0
l=numb*(-1)-1
if l!=-1:
    while s[l]==".":
        l-=1
        wb+=1
        if l==n*(-1):
            break
ans3=bw+wb

print(min(ansb,answ,ans3))