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:
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 + 1 != 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:
import sys

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

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

# 左側を全部白にする手数 (= 左側の黒の数)
split_left_count = [sum([x == '#' for x in haichi[:i]]) for i, k in enumerate(haichi)]

# 右側を全部黒にする手数 (= 右側の白の数)
split_right_count = [sum([x == '.' for x in haichi[i:]]) for i, k in enumerate(haichi)]

black_all_count = sum([x == '#' for x in haichi])
white_all_count = sum([x == '.' for x in haichi])

black_count = 0
for i in range(num):
    each_haichi = haichi[i]
    if each_haichi == '#':
        
    count_list.append(split_left_count[i]+split_right_count[i])

print(min(count_list))

Submission status: Runtime Error

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

if len(set(S)) == 1:
    print(0)
    quit()

a = S.count(".")
b = S.count("#")
ans2 = min(a,b)

ans = 0

if S[0] == "#":
    i = 1
    while True:
        if S[i] == ".":
            ans = i
            S = S[i:]
            break
        else:
            i += 1
else:
    flag = False
    for i in S:
        if i == "#":
            flag = True
        elif flag :
            break
    else:
        print(0)
        quit()

# if len(set(S)) == 1:
#     print(ans2)
#     quit()

if S[-1] == ".":
    i = 2
    while True:
        if S[-i] == "#":
            ans += (i-1)
            S = S[:-i+1]
            break
        else:
            i += 1


for i in range(len(S)):
    if S[i] == "#":
        S = S[i:]
        break
for i in range(1, len(S)+1):
    if S[-i] == ".":
        S = S[:-(i-1)]
        break

print(min(min(S.count("."), S.count("#")) + ans, ans2))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
count1 = 0
count2 = 0
m = -1
t = n
for x in range(n):
	if s[x] == "#":
		m = x
		break
if m != -1:
	for u in range(m,n):
	    if s[u] == ".":
		    count1 += 1
		else:
			count2 += 1
	while s[t] == "#":
		count2 -= 1
		t = t-1
print(min(count1,count2))

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 += b
        b, w = 0, 0

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=int(input())
c=[]
for i in range(n-1):
	if s[i+1]!=s[i]:
		c.append(i)
if s[0]=="#":
	for i in range(int(c/2)):
		ans+=s[2*i+1]-s[2*i]
else:
	for i in range(int(c/2)-1):
		ans+=s[2*i+2]-s[2*i+1]
return ans

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
memo = 0
count = 0
if "#" in S:
    for i in range(N):
        if S[i] == "#":
            memo = i
            S_right = S[i:]
            count = S_right.count(".")
            count_ = S_right.count("#")
            break

print(min(count,count_))

Submission status: Runtime Error

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

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

for x in range(i,N):
    if ls_S[x]==".":
        ls_S[x]="#"
        cnt_1+=1
for x in range(i,N):
    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:
from __future__ import print_function
import sys

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


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

cnt_temp=0
cnt_temp2=0
stack=[]
cnt=0

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

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


flag=0
flag2=0
start=0

for i in range(n):
    if S[i] == '.':
        cnt_temp+=1



if S[0] == '.':
    flag =1
# eprint("flag: ",end="")
# eprint(flag)

if flag==1:
    for i in range(n-1):
        if S[i]=='#' and S[i+1]=='.':
            flag2=1
            for j in range(i+1,n):
                if S[j] =='.':
                    cnt_temp2+=1
            break
# eprint("flag2: ",end="")
# eprint(flag2)
        

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

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
s1 = '#'
i = 0
slis = []
ini = True

for s in S:
  if s == s1:
    i += 1
  if s != s1:
    if ini:
      slis.append(i)
      ini = False
    else:
      slis.append(i + 1)
    s1 = s
    i = 0

slis.append(i+1)

if S.startswith('.'):
  slis = slis[2:]

if S.endswith('#'):
  slis = slis[:-1]

sssum = 0

for i, ss in enumerate(slis):
  if i == 0:
    sssum += ss
    sum01 = ss + sum(slis[2::2])
    sum02 = ss + sum(slis[3::2])
    sum0 = min(sum01, sum02)
  elif i % 2 == 0:
    sssum += ss
    sum01 = ss + sum(slis[2::2])
    sum02 = ss + sum(slis[3::2])
    sum0 = min(sum0, sum01, sum02)

sum1 = sum(slis[0::2])
sum2 = sum(slis[1::2])

print(min(sum0, sum1, sum2))

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
A = []
cnt = 1000000

for i in range(N+1):
    cnt = N-(S[:i].count(".")+S[i:].count("#"))
    ans = min(ans,cnt)

print(ans)

Submission status: Runtime Error

Solution code:
n = input()
s = input()
white_change = 0 if s.count("#") == 0 else s[s.index("#"):].count(".")
a = s[::-1]
print(min(white_change, a[a.index("."):].count("#")))

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)


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())
stones = input()

left = stones.find("#")

if left == -1:
    print(0)
else:
    right = stones.rfind("#")
    if right == left:
        print(1)
    elif right != -1:
        stonesToChange = stones[left : right]
    else:
        stonesToChange = stones[left:]


    print(min(stonesToChange.count("."), stonesToChange.count("#")))

Submission status: Runtime Error

Solution code:
import re
n = int(input())
s = input()
if not '#' in s:
    print(0)
else:
    s = '#.' + s.split('#.', 1)[-1] if '#.' in s else  s
    ptn = re.search(re.compile('\.#+?$'), s)
    if ptn:
        s = s[ptn.end()]
    print(min(s.count('.'), s.count('#')))

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())
s = list(S)
if '#' in s:
  for i in range(N):
    if s[-1] == '#':
      s.pop(-1)
  id = s.index('#')
  if id == N-1:
    print(0)
  else:
    s_b = s[id:N-1]
    b1 = s_b.count('#')
    b2 = s_b.count('.')
    if b2 == 0:
      print(0)
    elif b1 > b2:
      print(b2)
    else:
      print(b1)
else:
  print(0)

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

#print(input_str)
print(output)

Submission status: Runtime Error

Solution code:
N=int(input())-1
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):
    if ls_S[x]==".":
        ls_S[x]="#"
        cnt_1+=1
for x in range(I,N):
    if ls_S[x]=="#":
        ls_S[x]="."
        cnt_2+=1
if cnt_1>cnt_2:
    print(cnt_2)
else:
    print(cnt_1)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
memo = 0
count = 0
if "#" in S:
    for i in range(N):
        if S[i] == "#":
            memo = i
            #S_right = S[i+1:]
            break
    for j in range(i,N):
        if S[j] == ".":
            S_right = S[memo:]
            count = S_right.count(".")
            count_ = S_right.count("#")
            break

print(min(count,count_))

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())
s = list(S)
if '#' in s:
  for i in range(N):
    if s.[-1] == '#':
      s.pop(-1)
  id = s.index('#')
  if id == N-1:
    print(0)
  else:
    s_b = s[id:N-1]
    b1 = s_b.count('#')
    b2 = s_b.count('.')
    if b2 == 0:
      print(0)
    elif b1 > b2:
      print(b2)
    else:
      print(b1)
else:
  print(0)

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):
    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
print(cnt)

Submission status: Runtime Error

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

i = 0
ans = 0
cnt = 0
while i < N:
    b = i
    f = i
    if list_S[i] == '.':
        i += 1
    else:
        if i+1 >= N:
            i +=1
        elif list_S[i+1] == '.':
            while True:
                cnt += 1
                b -= 1
                f += 1
                if b < 0:
                    if list_S[f] == '.':
                        for j in range(b+1, i+1):
                            list_S[j] = '.'
                        ans += cnt
                        i = f
                        cnt = 0
                        break
                    else:
                        for j in range(i+1, f):
                            list_S[j] = '#'
                        ans += cnt - 1
                        i = f
                        cnt = 0
                        break
                elif f >= N:
                    ans += cnt -1
                    i = f
                    break
                elif list_S[b] == '.' and list_S[f] == '.':
                    for j in range(b+1, i+1):
                        list_S[j] = '.'
                    ans += cnt
                    i = f
                    cnt = 0
                    break
                elif list_S[b] == '#' and list_S[f] == '.':
                    continue
                elif list_S[b] == '.' and list_S[f] == '#':
                    for j in range(i+1, f):
                        list_S[j] = '#'
                    ans += cnt - 1
                    i = f
                    cnt = 0
                    break
                elif list_S[b] == '#' and list_S[f] == '#':
                    for j in range(i+1, f):
                        list_S[j] = '#'
                    ans += cnt - 1
                    i = f
                    cnt = 0
                    break
        else:
            i += 1

print(ans)

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

index =[]

for i in range(0,N):
   if S[i] == '.' :
       index.append(i)

print(index)

count = 0

if index[0] == 0:
    del index[0]
    
for j in range(len(index)):
    if S[index[j]] != S[index[j]-1]:
        count += 1

print(count)

Submission status: Runtime Error

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

state = False
counter = 0

for i in range(N):
  if S[i] == ".":
    counter += 1
  else:
    break
S_1 = S[counter:]

for i in range(len(S)):
  if S[i] == "#":
    state = True
    counter += 1
  else:
    counter = 0
    state = False
if state == True:
  S_3 = S_1[:-1*counter]
  S_2 = S[:-1*counter]

b_1 = S_1.count("#")
w_1 = len(S_1) - b_1

b_2 = S_2.count("#")
w_2 = len(S_2) - b_2

b_3 = S_3.count("#")
w_3 = len(S_3) - b_3

print(min(b_1, b_2, b_3, w_1, w_2, w_3))

Submission status: Runtime Error

Solution code:
n = input()
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 = str(input())

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


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 == '.':
    if S[-1] =='.':
        for i in range(1,lenL):
            if i%2 == 0:
                Numw +=L[i]

            else: 
                Numb +=L[i]
        m=(min(Numw,Numb))

        tmp =float("inf")

        for k in range(len(L)):
            counter = 0
            for i in range(k):
                counter += L[2*i+1]
            for i in range(k,int(lenL/2)):
                counter +=L[2*i]
            tmp = min(tmp,counter)
        print(min(m,tmp))


    else:
        for i in range(1,len(L)-1):
            if i%2 ==0:
                Numw +=L[i]
            else:
                Numb +=L[i]
        m=(min(Numb,Numw))
        tmp =float("inf")

        for k in range(len(L)):
            counter = 0
            for i in range(k):
                counter += L[2*i+1]
            for i in range(k,int(lenL/2)-1):
                counter +=L[2*i]
            tmp = min(tmp,counter)
        print(min(m,tmp))
            

else:
    if S[-1]=='.':
        for i in range(len(L)):
            if i%2 ==0:
                Numb += L[i]
            else:
                Numw += L[i]
        m=(min(Numb,Numw))
        tmp =float("inf")

        for k in range(len(L)):
            counter = 0
            for i in range(k):
                counter += L[2*i]
            for i in range(k,int(lenL/2)-1):
                counter +=L[2*i+1]
            tmp = min(tmp,counter)
        print(min(m,tmp))

    else:
        for i in range(len(L)-1):
            if i%2 ==0:
                Numb += L[i]
            else:
                Numw += L[i]
        m=(min(Numb,Numw))
        tmp =float("inf")

        for k in range(len(L)):
            counter = 0
            for i in range(k):
                counter += L[2*i]
            for i in range(k,int(lenL/2)-1):
                counter +=L[2*i+1]
            tmp = min(tmp,counter)
        print(min(m,tmp))

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(list(accumulate(x)))
y=array(list(accumulate(y[::-1]))[::-1]+[0]*(s[-1]=="#"))
print(min(x+y))

Submission status: Runtime Error

Solution code:

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

ans = n
if s.count('#') == n or s.count('.') == n:
    ans = 0
    print(ans)
else:
    if num < ans:
        ans = num
    for i in range(n):
        num = s[:i].count('#') + s[i:].count('.')
        if num < ans:
            ans = num
    print(ans)

Submission status: Runtime Error

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

def inverse(b, w, index, first):
    count = 0
    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:
N = int(input())
S = input()

ans = 2*10**5
c_b = 0
c_w = 0
for i in range(N):
    if S[i] == '#':
        c_b += 1
    else:
        c_w += 1

ans = min(ans, c_b, c_w)

nums = []
ns = 0
if S[0] == '#':
    nums.append(0)
    ns = 1

count = 0
for i in range(N):
    if S[i] == '.':
        if ns == 0:
            count += 1
        else:
            nums.append(count)
            count = 1
            ns = 1 - ns
    if S[i] == '#':
        if ns == 1:
            count += 1
        else:
            nums.append(count)
            count = 1
            ns = 1 - ns
nums.append(count)

if len(nums) < 3:
    print(0)
    quit()

count = 0
for i in range(0, len(nums), 2):
    if i != 0:
        if nums[i-1] != 0:
            count += nums[i-1]
ans = min(ans, count))

count = 0
for i in range(1, len(nums), 2):
    if nums[i-1] != 0:
        count += nums[i-1]
print(min(ans, count))

Submission status: Runtime Error

Solution code:
n=int(input())
s=str(input())
"""n = 8
s = "#.....#."
print(s)
print(len(s))"""

memo = []
countwb=0
now = s[0]
count = 0
if now == "#":
    memo.append(0)
while(count<n):
    if s[count]==now:
        countwb+=1
    else:
        memo.append(countwb)
        countwb = 1
        now = s[count]
    count+=1
memo.append(countwb)
#print(memo)
#print(memo[len(memo)-3])


count_b = []
c_b = 0
for  i in range(1,len(memo),2):
        c_b += memo[i]
        count_b.append(c_b)
#print(count_b)

count_w = []
c_w = 0
for  i in range(0,len(memo),2):
        c_w += memo[i]
        count_w.append(c_w)
#print(count_w)

#白白．．．黒黒にする
w_b = 0
if len(memo)%2==1:
    #最後が白
    w_b += memo[-1]
    if len(count_b)>1:
        w_b += count_b[-2]
else:
    #最後が黒
    if len(count_b)>1:
        w_b += count_b[-2]
#print("w_b",w_b)
#全部白にする
allw = count_b[-1]
#print("allw",allw)
#全部黒にする
allb = count_w[-1]
#print("allb",allb)

print(min(w_b,allb,allw))

Submission status: Runtime Error

Solution code:

###
#main
if __name__ == "__main__":
    N = int(input())
    S = input()
#    count = 0
    countMin = 200001
    counttemp = 0
    isWhite = True
    numlist = []
    for t in S:
        if t == "#" and isWhite:
            isWhite = False
            numlist.append(counttemp)
            counttemp = 0
        if t == "." and not isWhite:
            isWhite = True
            numlist.append(counttemp)
            counttemp = 0
        counttemp += 1
    
    numlist.append(counttemp)
    if len(numlist) <= 2:
        countMin = 0
    else:
        j = 1
        while j < N:
            counttemp = 0
            i = 2
            while i < N:
                if i < j :
                    counttemp += numlist[i-1]
                else:
                    counttemp += numlist[i]
                i += 2
            if counttemp < countMin:
                countMin = counttemp
            j += 1    
#    print(numlist)           
    print(countMin)

Submission status: Runtime Error

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

start = 0
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)

if(start ==0):
    ans = 0

print(sum(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
cnt = 0
i = 0
j = N-1
while True:
        while S[i] == '.':
                i = i + 1
        while S[j] == '#':
                j = j -1
        #print((i, j))
        if i > j:
                break
        elif i + 1 == j:
                cnt = cnt + 1
                break
        else:
                cnt = cnt + 2
        i = i + 1
        j = j - 1

print(cnt)

Submission status: Runtime Error

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

count_A = 0
count_B = 0

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

if count_B > count_A:
 print(count_A)
else:
 print(count_B)

Submission status: Runtime Error

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

count_list =[]
wc = 0

for n in range(N):
    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[-1] = count_list[-1] + 1

count = min(count_list)
print(count)

Submission status: Runtime Error

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


def func(input_s):
    count = input_s.count(".")
    if len(input_s) == 1: return 0;
    c = input_s[-1]
    if c == "." and input_s[-2] == "#":
        tmp_str = input_s
        tmp_str[-2] = "."
        tmp_count = func(tmp_str[:-2])
        count = min(tmp_count + 1, count)
    else:
        tmp_count = func(input_s[:-2])
        count -= 1
        count = min(tmp_count + 1, count)
    return count


pre = ""
print(func(s))

Submission status: Runtime Error

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

count_A = 0
count_B = 0

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

if count_B > count_A:
 print(count_A)
else:
 print(count_B)

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)

if(start ==0):
    ans = 0

print(sum(ans))

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):
    if ls_S[x-1]==".":
        ls_S[x-1]="#"
        cnt_1+=1
for x in range(I,N):
    if ls_S[x-1]=="#":
        ls_S[x-1]="."
        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 = str(input())

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

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)
#print(L)
Numw =0
Numb =0
Numx =0

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

            else: 
                Numb +=L[i]
        m=(min(Numw,Numb))

        tmp =float("inf")

        for k in range(len(L)):
            counter = 0
            for i in range(k):
                counter += L[2*i+1]
            for i in range(k,int(N/2)):
                counter +=L[2*i]
            tmp = min(tmp,counter)
        print(min(m,tmp))


    else:
        for i in range(1,len(L)-1):
            if i%2 ==0:
                Numw +=L[i]
            else:
                Numb +=L[i]
        m=(min(Numb,Numw))
        tmp =float("inf")

        for k in range(len(L)):
            counter = 0
            for i in range(k):
                counter += L[2*i+1]
            for i in range(k,int(N/2)-1):
                counter +=L[2*i]
            tmp = min(tmp,counter)
        print(min(m,tmp))
            

else:
    if S[-1]=='.':
        for i in range(len(L)):
            if i%2 ==0:
                Numb += L[i]
            else:
                Numw += L[i]
        m=(min(Numb,Numw))
        tmp =float("inf")

        for k in range(len(L)):
            counter = 0
            for i in range(k):
                counter += L[2*i]
            for i in range(k,int(N/2)-1):
                counter +=L[2*i+1]
            tmp = min(tmp,counter)
        print(min(m,tmp))

    else:
        for i in range(len(L)-1):
            if i%2 ==0:
                Numb += L[i]
            else:
                Numw += L[i]
        m=(min(Numb,Numw))
        tmp =float("inf")

        for k in range(len(L)):
            counter = 0
            for i in range(k):
                counter += L[2*i]
            for i in range(k,int(N/2)-1):
                counter +=L[2*i+1]
            tmp = min(tmp,counter)
        print(min(m,tmp))

Submission status: Runtime Error

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

def judge(s,count):
    if s.count("#.")==0:
        return count

    next=""
    for i in range(0,n-1):
        if s[i]=="#" and s[i+1]==".":
            next1 = s[:i] + "##"
            if i<n-2:
                next1+=s[i+2:]
            pat1 = judge(next1,count+1)

            pat2=pat1
            if i > 0 and s[i-1]==".":
                next2 = s[:i] + ".."
                if i < n-2:
                    next2+=s[i+2:]
                pat2 = judge(next2,count+1)
            return min(pat1,pat2)
    return count

print(judge(s_input,0))

Submission status: Runtime Error

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

dp = [[2*10**5, 2*10**5] for i in range(N)] # n, 0 -> dont replace min, n.1 -> replaced min
dp[N-1] = [0, 1]

def solve():
  for i in range(N-2, 0, -1):
    if(S[i]=="." and S[i-1]=="#"):
      if S[i+1]=="#":
        dp[i][0] = min(dp[i+1])
        dp[i][1] = 1+dp[i+1][1]
      else:
        dp[i][0] = min(dp[i+1])
        dp[i][1] = 1+min(dp[i+1])
    elif(S[i]=="#" and S[i+1]=="."):
      dp[i][0] = dp[i+1][1]
      dp[i][1] = 1+dp[i+1][0]
    else:
      if(S[i]=="." and S[i+1]=="."):
          dp[i][0] = min(dp[i+1])
          dp[i][1] = 1+dp[i+1][1]
      else:
        dp[i][0] = min(dp[i+1])
        dp[i][1] = 1+min(dp[i+1])
  if(S[0]=="#" and S[1]=="."): return min(1+dp[i+1][0], dp[i+1][1])
  elif(S[0]=="." and S[1]=="."): return min(dp[i+1][0], 1+dp[i+1][1])
  else: return min(dp[i+1])

print(solve())

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

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-1):
  if s[i] == '#' and s[i+1] == '.':
   s[i+1] = '#'
   count += 1
else:
 for i in range(n-1):
  if s[i] == '#' and s[i+1] == '.':
   s[i] = '.'
   count += 1

print(count)

Submission status: Runtime Error

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

count = 0
for i in range(N-3):
  s = S[i:i+4]
  # print(s)
  if s[1] == '#' and s[2] == '.':
    if s == '##..':
      count += 2
    else:
      count += 1

shead = '.' + S[:3]
stail = S[-3:] + '#'

if shead[1] == '#' and shead[2] == '.':
  if shead == '##..':
    count += 2
  else:
    count += 1

if stail[1] == '#' and stail[2] == '.':
  if stail == '##..':
    count += 2
  else:
    count += 1

# print(shead)
# print(stail)
print(count)