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

count=0
if S.count(".")>S.count("#"):
    for i in range(n):
        if S[n-1]==".":
            if S[n-1-i]=="#":
                count+=1
        else:
            if S[n-1-i]==".":
                for j in range(n-i):
                    if S[n-i-j]=="#":
                        count+=1
                        
else:
    for k in range(n):
        if S[n-1]==".":
            if S[n-1-k]==".":
                count+=1
        else:
            if S[n-1-k]=="#":
                for l in range(n-k):
                    if S[n-k-l]==".":
                        count+=1
                        
print(count)

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]==".":
        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 = [s for s in input()]
s = s[s.index("#"):]
a = s.count(".")
b = len(s) - a
print("a:", a)
print("b:", b)
if a >= b:
    print(b)
else:
    print(a)

Submission status: Runtime Error

Solution code:
l_count = 0
r_count = sum([1 for c in S if c == "."])
count_if_contain_black = l_count+r_count
count_if_all_white = 0
for c in S:
    if c == "#":
        l_count += 1
        count_if_all_white += 1
    else:
        r_count -= 1
        
    count_if_contain_black = min(count_if_contain_black, l_count+r_count)

print(min(count_if_all_white, count_if_contain_black))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
li=[]
if s[0]=='.':
  a=0
  s.insert(0,"あ")
  for i in range (1,n+1):
    if s[i]==s[i-1]:
      a=a+1
    else:
      li.append(a)
      a=1
  li.append(a)
else:
  a=1
  for i in range (0,n-1):
    if s[i+1]==s[i]:
      a=a+1
    else:
      li.append(a)
      a=1
  if s[n-2]==s[n-1]:
    a=a+1
    li.append(a)
  else:
    li.append(a)
if s[n-1]==".":
  li.append(0)
len_li=len(li)
import math
t=math.floor(len_li/2)+1
l=[]
m=0
for j in range (0,t-1):
  m=m+li[2*j+1]
x=0
y=0
for k in range (0,t):
  l.append(m+y-x)
  y=y+li[2*k]
  if k!=t-1:
    x=x+li[2*k+1]
l.sort()
print(l[0])

Submission status: Runtime Error

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


def exe(n,s,count):
    #print(s)
    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)
    return count
N = int(input())
S = input()

print(exe(N,S,0))

Submission status: Runtime Error

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

a=0
b=0
d=0
flag=1

revS = S[::-1]

if S.find("#.") != -1:
    for i in revS:
        if i == "#":
            a+=1
    	if flag=1:
            d+=1
        else:
            b+=1
            flag=-1

    if a>b:
        print(b-d)
    else:
        print(a-d)

else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
k,d = 0,0
s = list(input())

if s[0] == '.':
  c = 0
  for j in s:
    if j == '.':
      c+=1
    else:
      break
  if s[n-1] == '#':
    r = 0
    for p in range(n-1,0,-1):
      if s[p] == "#":
        r += 1
      else:
        break
      
  for i in range(c,n-r):
    if s[i] == '#':
      k+=1
    else:
      d+=1
  
  
else:
  if s[n-1] == '#':
    r = 0
    for o in range(n-1,0,-1):
      if s[o] == "#":
        r += 1
      else:
        break

  for m in range(n-r):
    if s[i] == '#':
      k+=1
    else:
      d+=1
print(min(k,d))

Submission status: Runtime Error

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

w,b = 0,0

for i in range(len(S)):
    if S[i] != '.':
        break

for e in range(len(S)-1,0,-1):
    if S[e] != '#':
        break

for s in range(i,len(S)-e+1):
    if S[s] == '.':
        w += 1
    else:
        b += 1

if b > w:
    print(w)
else:
    print(b)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
cnt = 0
i = 0
j = N-1
while j > i:
        while S[i] == '.':
                i = i + 1
        cnt = cnt + 1
        i = i + 1
        while S[j] == '#':
                j = j -1

        if j <= i:
                break
        cnt = cnt + 1
        j = j - 1
print(cnt)

Submission status: Runtime Error

Solution code:
import sys

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

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

num = int(a[0])
haichi = a[1]
count_list = []
for i in range(num-1):
    split_haichi_1 = haichi[:i+1]
    split_haichi_2 = haichi[i+1:]
    count_1 = count(split_haichi_1)
    count_2 = count(split_haichi_2)
    count_list.append(count_1 + count_2)

print(min(count_list))

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10000000)


def check_and_back_or_go_to(li, ind, N, counter, white_charge):
    back = True
    # print('see {} {} and {} counter{}'.format(ind, li[ind - 1], li[ind], counter))
    if ind == 0:
        return counter

    # access
    if li[ind - 1] == '#' and li[ind] == '.':
        c = check_and_back_or_go_to(li, ind - 1, N, counter + 1 + white_charge, 0)
        return c
    elif li[ind - 1] == '.' and li[ind] == '.':
        return check_and_back_or_go_to(li, ind - 1, N, counter, white_charge + 1)
    else:
        c = check_and_back_or_go_to(li, ind - 1, N, counter, white_charge)
        return c


N = int(input())
S = list(input())
r = range(N)
if N == 1:
    print(0)
    exit(0)
bsk = False
key = -1
for i in range(len(S)):
    if not bsk:
        if S[i] == '#':
            bsk = True
            key = i
    else:
        if S[i] != '#':
            bsk = False

if bsk:
    # print('bsk occured')
    # print([S[i] for i in range(key)])
    count = check_and_back_or_go_to([S[i] for i in range(key)], key  - 1, N, 0, 0)
    print(min([count, key - count]))
else:
    count = check_and_back_or_go_to(S, len(S) - 1, N, 0, 0)
    print(min([count, N - count]))

Submission status: Runtime Error

Solution code:
def minToggle(arr, n): 
  
    zero =[0 for i in range(n + 1+1)] 
    zero[0] = 0
   
    # Fill entries in zero[] 
    # such that zero[i] 
    # stores count of zeroes 
    # to the left of i 
    # (exl 
    for i in range(1, n + 1): 
      
        # If zero found 
        # update zero[] array 
        if (arr[i-1] == 0): 
            zero[i] = zero[i-1] + 1
        else: 
            zero[i] = zero[i-1] 
   
    # Finding the minimum 
    # toggle required from 
    # every index(0 to n-1) 
    ans = n 
    for i in range(1, n + 1): 
        ans = min(ans, i - zero[i] + zero[n] - zero[i]) 
   
    return ans 
      
# Driver Program 
n=int(input())
s=input().rstrip()
arr=[]
ansi=min(s.count('.'),s.count('#'))
for i in s:
    if i=='.':
        arr.append(0)
    else:
        arr.append(1)
n = len(arr) 
  
p=minToggle(arr, n)) 
ansi=min(ans,p)
print(ans)
  
# This code is contributed 
# by Anant Agarwal.

Submission status: Runtime Error

Solution code:
a=input()
b=input()
scount=0
ccount=0
pp=0
ll=list()
for i in b:
        ll.append(i)
if "#" in ll:
        x=ll.index("#")
        y=ll.count(".")
        z=y-x
        q=ll.count("#")
        ccount=z
        
        for i in range(a):
                scount-=1
                if ll[scount] == ".":
                        break
                else:
                        pp+=1
        if q<z:
                ccount=q
                ccount-=pp
                
        
print(ccount)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
cd = 0
cs = 0
ans = 0

if (s[0] == '#'):
  for i in range(n):
    if (s[i] == '.'):
      break
    elif (s[i] == '#'):
      cs += 1

for i in range(cs, n):
  if (s[i] == '.'):
      cd += 1
  elif (s[i] == '#'):
    break

if (cs < cd):
  ans += cs
  s[0:cs + cd] = ''

s = s[::-1]

if (s[0] == '.'):
  for i in range(n):
    if (s[i] == '#'):
      break
    elif (s[i] == '.'):
      cd += 1

for i in range(cd, n):
  if (s[i] == '#'):
      cs += 1
  elif (s[i] == '.'):
    break

if (cd < cs):
  ans += cd
  s[0:cd + cs] = ''


ans1 = s.count('.')
ans2 = s.count('#')
print(min([ans1, ans2]) + ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
s=input()
B=True
if s=='.'*n:
    B=False
if B:
    num=list(s).index('#')
    if num!=n-1:
        for i in range(num,n-1):
            if s[i]=='.' and s[i+1]=='#':
                A=True
                l=n-i-1
        moji=s[num:]
        lst=dict(Counter(moji).items())
        a=lst['#'];b=lst['.']
        if a==0 or b==0:
            print(0)
        else:
            if s[-1]=='#':
                print(min(a-l,b))
            else:
                print(min(a,b))
    else:
        print(0)
else:
    print(0)

Submission status: Runtime Error

Solution code:
def minToggle(arr, n): 
  
    zero =[0 for i in range(n + 1+1)] 
    zero[0] = 0
   
    # Fill entries in zero[] 
    # such that zero[i] 
    # stores count of zeroes 
    # to the left of i 
    # (exl 
    for i in range(1, n + 1): 
      
        # If zero found 
        # update zero[] array 
        if (arr[i-1] == 0): 
            zero[i] = zero[i-1] + 1
        else: 
            zero[i] = zero[i-1] 
   
    # Finding the minimum 
    # toggle required from 
    # every index(0 to n-1) 
    ans = n 
    for i in range(1, n + 1): 
        ans = min(ans, i - zero[i] + zero[n] - zero[i]) 
   
    return ans 
      
# Driver Program 
n=int(input())
s=input().rstrip()
arr=[]
ans=min(s.count('.'),s.count('#'))
if s.count()
for i in s:
    if i=='.':
        arr.append(0)
    else:
        arr.append(1)
n = len(arr) 
  
p=minToggle(arr, n)) 
ans=min(ans,p)
print(ans)
  
# This code is contributed 
# by Anant Agarwal.

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]==".":
        ls_S[x]="#"
        cnt_1+=1
    else:
        ls_S[x]="."
        cnt_2+=1
if cnt_1>cnt_2:
    print(cnt_2)
else:
    print(cnt_1)

Submission status: Runtime Error

Solution code:

#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <string>
using namespace std;

int main(){
  int N;
  string S;
  bool flag=false;;
  cin >> N >> S;
  int index[N];
  for(int i=0;i<N;i++){
    index[i]=0;
  }
  int c=0;
  while(c<N){
    if(S[c]=='#'){
      index[c]=c;
    }
    c++;
  }
  int counter=0;
  int c2=0;
  int ans=N;
  for(int x : index){
    if(x!=0){
      flag=true;
      c2++;
      for(int i=x;i<N;i++){
        if(S[i]=='.'){
          counter++;
        }
      }
      ans = min(counter,ans);
      counter=c2;
    }
  }
  if(flag){
    cout << min(ans,counter) << '\n';
  }else{
    cout<< 0<<'\n';
  }
}

Submission status: Runtime Error

Solution code:
n = int(input())
s = [s for s in input()]
a = s[s.index("#"):].count(".")
b = n - a
if a >= b:
    print(b)
else:
    print(a)

Submission status: Runtime Error

Solution code:
N=int(input())
S=str(input())
v=[0]*(2*(10**5)+15)
c=0
if S[0]=="#":
    v[0]+=1
    for i in range(N-1):
        if S[i]==S[i+1]:
            v[c]+=1
        else:
            c+=1
            v[c]+=1

    print(v)

else:
    c=1
    for i in range(N-1):
        if S[i]==S[i+1]:
            v[c]+=1
        else:
            c+=1
            v[c]+=1

    print(v)

pp = [0]*((2*(10**5)+5))
pp[0]= v[0]+v[(2*(10**5)+3)]

for i in range((2*(10**5)+6)/2):
    v[i+2]=v[i]+v[i+2]

for i in range((2*(10**5)+4)/2):
    pp[i+1] = v[2*(i+1)]+v[(2*(10**5)+3)]-v[2*i+1]



if max(pp)==0:
    print(max(pp))
else:
    pp.pop(0)
    print(min(pp))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
a=0
temp=0
count=0
for i in range(n-1):
  if a==0:
    if s[i]=="#" and s[i+1]==".":
      count=count+1
      a=1
    try:
      temp=s[i+4]
    except:
    else:
      if temp=="#":
        a=0
  else:
    a=0
print(count)

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
        if flag and i == ".":
            break
    else:
        print(0)
        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()
c = S[::-1]
w,b = 0,0

for i in range(len(S)):
    if S[i] != '.':
        break

for e in range(len(c)):
    if c[e] != '#':
        break

for s in range(i,len(S)-e+1):
    if S[s] == '.':
        w += 1
    else:
        b += 1

if b > w:
    print(w)
else:
    print(b)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
a=0
temp=0
count=0
for i in range(n-1):
  if a==0:
    if s[i]=="#" and s[i+1]==".":
      count=count+1
      a=1
    try:
      temp=s[i+4]
    else:
      if temp=="#":
        a=0
  else:
    a=0
print(count)

Submission status: Runtime Error

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

def count(S, k):
    if k == 1:
        return 0
    if S[k - 1] == '.' and S[k - 2] == '#':
        S1 = []
        S2 = []
        for i in range(len(S)):
            if i == k - 1:
                continue
            if i == k - 2:
                S1.append('.')
                S2.append('#')
            else:
                S1.append(S[i])
                S2.append(S[i])
        return min(count(S1, k - 1) , count(S1, k - 1)) + 1
    else:
        return count(S, k - 1)

print(count(S, n))

Submission status: Runtime Error

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

ans = 0
while s.find('#.') != -1:
    pos = s.find('#.')
    if pos-1 >= 0:
        if s[pos-1] == '#':
            s = s[:pos] + '##' + s[pos+2:]
    if pos+2 <= n-1:
        elif s[pos+2] == '.':
            s = s[:pos] + '..' + s[pos+2:]
    if pos-2 <= 0:
        elif s[pos-2:pos] == '#.':
            s = s[:pos] + '##' + s[pos+2:]
    if pos+4 <= n-1:
        elif s[pos+2:pos+4] == '#.':
            s = s[:pos] + '..' + s[pos+2:]
    else:
        s = s[:pos] + '##' + s[pos+2:]
    ans += 1
print(ans)

Submission status: Runtime Error

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

a=0
b=0
d=0

revS = S[::-1]

if S.find("#.") != -1:

    for i in revS:
        if i == "#":
            revS[d]="."
    	else:
            break
        d+=1

    S = revS

    for i in S:
        if i == "#":
            a+=1
        else:
            b+=1

    if a>b:
        print(b)
    else:
        print(a)

else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
cnt = 0
if S.count('#')>S.count('.'):
  word = '#'
else:
  word = '.'
ans=""
for i in range(N):
  if i==0:
    ans+=S[i]
    pass
  if ans[-1]=='#' and S[i]=='.':
    cnt+=1
    ans+=word
  else:
    ans+=S[i]
  print(ans)
print(cnt)

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 = S[i]
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:
n = int(input())
S = input()
c = S[::-1]
w,b = 0,0

for i in range(len(S)):
    if S[i] != '.':
        break

for e in range(len(c)):
    if c[e] != '#':
        break

for s in range(d,len(S)-e+1):
    if S[s] == '.':
        w += 1
    else:
        b += 1

if b > w:
    print(w)
else:
    print(b)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=list(input()[:-1])
c=0
for i in range(1,N+1):
  if S[i-1]=='#'and S[i]=='.':
    S[i]='#'
    c+=1
print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())
white = '.'
black = '#'

cnt = 0
for i in S:
    if(i==black):
        break
    else:
        cnt += 1
#print(cnt)
#print(S)
bS = S[cnt:]
#print(S)

black_chg_cnt = 0
white_chg_cnt = 0
for i in bS:
    if(i==white):
        black_chg_cnt += 1
    else:
        white_chg_cnt += 1
if(bS[-1] == black):
    white_chg_cnt -= 1

if(black_chg_cnt<white_chg_cnt):
    print(black_chg_cnt)
else:
    print(white_chg_cnt)

Submission status: Runtime Error

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

def count(S, k):
    if k == 1:
        return 0
    if S[k - 1] == '.' and S[k - 2] == '#':
        S1 = []
        S2 = []
        for i in range(len(S)):
            if i == k - 1:
                continue
            if i == k - 2:
                S1.append('.')
                S2.append('#')
            else:
                S1.append(S[i])
                S2.append(S[i])
            
        T = ['.' if i == k - 2 else S[i] for i  in range(0, k + 1)]
        return count(T, k - 1) + 1
    else:
        return count(S, k - 1)

print(count(S, n))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
count = 0
count2 = 0

for x in range(N):
    if S[x] == '#':
        flag = True
    if S[x] == '.' and flag == True:
        count += 1

for x in range(N)[::-1]:
    if S[x] == '.':
        flag = True
    if S[x] == '#' and flag == True:
        count2 += 1

print(max(count,count2))

Submission status: Runtime Error

Solution code:
stone=input()
color=input()
a=int(stone)
counter=0
xxx=[]
list=[]
for i in range(a):
    list.append(color[i])
for i in range(a):
    if list[i]=='#':
        xxx.append(i)
s = min(xxx)
for k in range(s,a):
    if list[k]=='.' :
        counter = 1+ counter
print(counter)

Submission status: Runtime Error

Solution code:
N=int(input())
S=[str(i) for i in input().split()][0]        
start=S.index("#")
end=max([n for n,i in enumerate(S) if i=="."])
X=S[start:end]
sharp=X.count("#")
dot=X.count(".")+1
print(min([sharp,dot]))

Submission status: Runtime Error

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

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



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
        if flag and i == ".":
            break
    else:
        print(0)
        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


# odd = []
# even = []
# flag = False
# count = 1
# for i in range(1, len(S)):
#     if not S[i] == S[i-1]:
#         if not flag:
#             odd.append(count)
#         else:
#             even.append(count)
#         count = 1
#         flag = not flag
#     else:
#         count += 1
#
# if flag:
#     even.append(count)
# else:
#     odd.append(count)

# print(min(sum(odd), sum(even))+ans)

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

Submission status: Runtime Error

Solution code:
N = input()
S = input()
f = 0
c1 = 0
c2 = 0
for i, s in enumerate(S):
    if s == '#' and f == 1:
        f = 0
        c += 1
    elif s == '.' and f == 0:
        f = 1
        c += 1
print(c)

Submission status: Runtime Error

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

start = s.find("#")

white_start = s[start:].find(".")
white_end = s[start:].rfind(".")

black = s[start:].count("#")
white = s[start:].count(".")

if start == -1 or end==-1:
    print(0)
else:
    for i in range(white_start+1, white_end+1):
        if s[i] == "#":
            print(min(black, white))
            break
        elif i==white_end:
            print(1)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
a=0
count=0
for i in range(n-1):
  if a==0:
    if s[i]=="#" and s[i+1]==".":
      count=count+1
      a=1
    try:
      if s[i+4]=="#":
        a=0
  else:
    a=0
print(count)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
l=list(input())
m=0
b_ans=n
for i in range(len(l)-1):
    if (l[i]=="#" and l[i+1]=="."):
        lm=[]
        lm2=[]
        m=i+1
        lm=l[m:]
        lm2=l[:m]
        b=lm.count(".")+lm2.count("#")
        b_ans=min(b,b_ans)
        #print(lm)

a=l.count("#")
c=l.count(".")
ans=min(a,b,c)
print(ans)
#print(lm)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
def check(N, S):
    ls = []
    for i in range(N - 1):
        if S[i] == "#" and S[i + 1] == ".":
                ls.append(True)
        else:
            ls.append(False)
    return ls.count(True)

def change(N, S):
    cnts = []
    for i in range(1, N):
        form = S[:i]
        latt = S[i:]
        cnt = 0
        if form.count(".") >= form.count("#"):
            cnt += form.count("#")
        if form.count(".") < form.count("#"):
            cnt += form.count(".")
        cnt += latt.count("#")
        cnts.append(cnt)
    return cnts

print(min(change(N, S)))

Submission status: Runtime Error

Solution code:
# C - Stones

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

#print(list(S))
cnt = 0


# stones[i] == "#" のときに stones[i+1] == "." なら stones[i+1] = "#"にしてcnt ++する
def BlackToWhite(stones, len, i):
    global cnt
    if stones[0:i + 1]:
        if stones[i] == "#" and stones[i + 1] == ".":
            cnt += 1
            stones[i + 1] = "#"

        i += 1
        if i >= len - 1:
            print(cnt)
            exit()
        else:
            BlackToWhite(stones, len, i)
    else:
        print(cnt)
        exit()


BlackToWhite(list(S), N, 0)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
a=0
count=0
for i in range(n-1):
  if a==0:
    if s[i]=="#" and s[i+1]==".":
      count=count+1
      a=1
    if s[i+4]=="#":
      a=0
  else:
    a=0
print(count)
#.##...

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
c = 0
b = s.count('#')
for i in range(n):
 if s[i] == '#' and s[i + 1] == '.':
  c += 1
  s[i +1] = '#'

print(min(c,b))

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] == "#":
        cnt += 1
print(cnt)

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]==".":
        ls_S[x]="#"
        cnt_1+=1
    else:
        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 collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
r = N - 1
l = 0
while S[r] == "#":
    r -= 1
while S[l] == ".":
    l += 1
cnt = Counter(S[l:r+1])
print(min(cnt["."], cnt["#"]))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
ssp = s.split('.')
num = min(s.count(.),s.count('#') - len(ssp[-1]))
if s.count('#') == 0 or s.count('.') == 0:
    print(0)
    exit()
for i in range(n):
    if s[i - 1] == s[i]:
        continue
    num = min(num,s[:i].count('#') + s[i:].count('.'))
print(num)

Submission status: Runtime Error

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

input = sys.stdin.readline
N = int(input())
S = input().strip()
a = 0

if S.count('#') > S.count('.'):
    a += (S.count('.'))
    if S[-2] == '.' and S[-1] == '#':
        a -= 1
else:
    a += (S.count('#'))

print(a)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
S=S+'9'
ans=0
for i in range(N):
    if S[i]=='#' and S[i+1]=='.':
        cntj=0
        for j in range(i,-1,-1):
            if S[j]=='#':
                cntj+=1
            else:
                break
        cntk=0
        for k in range(i+1,N+1):
            if S[k]=='.':
                cntk+=1
            else:
                break
        if cntj < cntk:
            ans += cntj
            S = S[:i-cntj]+'.'*cntj+S[i+1:]
        else:
            ans += cntk
            S = S[:i]+'#'*cntk+S[i+1+cntk:]
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = str(input())
# ".": 白
# "#": 黒
# 黒い石のすぐ右に白い石があるような箇所がないように

now = "."
encoded = []
if S[0] == "#":
    S = "." + S
#Sは "." からスタート
tmp = 0
for i in S:
    if i == now:
        tmp = tmp + 1
    else:
        encoded.append(tmp)
        if now == ".":
            now = "#"
        else:
            now = "."
        tmp = 1
encoded.append(tmp)

ans = 0
for i in range(len(encoded)//2):
    idx = 2 * i + 1
    ans = ans + min(encoded[idx], encoded[idx+1])
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
count_list = []

res_list = []

for i in range(n+1):
	str = i*'.' + (n-i)*'#'
	res_list.append(str)

for dif in res_list:
	count = 0
	for index in range(n):
		if(s[index] != dif[index]):
			count += 1
	count_list.append(count)
print(min(count_list))

Submission status: Runtime Error

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

ans = 0
while s.find('#.') != -1:
    pos = s.find('#.')
    if s[pos-1] == '#':
        s = s[:pos] + '##' + s[pos+2:]
    elif s[pos+2] == '.':
        s = s[:pos] + '..' + s[pos+2:]
    elif s[pos-2:pos] == '#.':
        s = s[:pos] + '##' + s[pos+2:]
    elif s[pos+2:pos+4] == '#.':
        s = s[:pos] + '..' + s[pos+2:]
    else:
        s = s[:pos] + '##' + s[pos+2:]
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
b = 0
w = 0
for i in range(n):
    if s[i] == '.':
        b += 1
    else:
        w += 1
print(min(b, w))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
tmp = S.count('.')
if S[0] == '.':
    counter = 0
    count = 0
    while S[count] != '#':
        counter += 1
        count += 1
    tmp -= counter 
print(tmp)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
s_list = list(S)
count_1 = 0
count_2 = 0
for i in range(N-1):
    if s_list[i] == "#" and s_list[i+1] == ".":
        temp_start = i
        break

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:
n=int(input())
s_o=input()
s_dot=[len(x) for x in s_o.replace("#"," ").split()]
s_sharp=[len(x) for x in s_o.replace("."," ").split()]
if s_o[0]==".":
  s_dot=s_dot[1:]
if s_o[-1]=="#":
  s_sharp[:-1]
if len(s_dot)==0 or len(s_sharp)==0:
  print(0)
  exit()
sum_sharp=[0]*len(s_sharp)
sum_dot=[0]*len(s_dot)
for i in range(len(sum_sharp)):
  if i==0:
    sum_sharp[i]=s_sharp[i]
  else:
    sum_sharp[i]=sum_sharp[i-1]+s_sharp[i]

for i in reversed(range(len(sum_dot))):
  if i==len(sum_dot)-1:
    sum_dot[i]=s_dot[i]
  else:
    sum_dot[i]=sum_dot[i+1]+s_dot[i]
ans=[1000000]*len(sum_sharp)
for i in range(len(sum_sharp)):
  ans[i]=sum_sharp[i]+sum_dot[-i-1]
print(min(ans))

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
s=input()
B=True
if s=='.'*n:
    B=False
if B:
    num=list(s).index('#')
    for i in range(n-1):
        if s[i:]=='#'*(n-i):
            A=True
            l=n-i
            break
    if num!=n-1:
        moji=s[num:]
        lst=dict(Counter(moji).items())
        a=lst['#'];b=lst['.']
        if a==0 or b==0:
            print(0)
        else:
            if A:
                print(min(a-l,b))
            else:
                print(min(a,b))
    else:
        print(0)
else:
    print(0)

Submission status: Runtime Error

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

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



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
        if flag and i == ".":
            break
    else:
        print(0)
        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


odd = []
even = []
flag = False
count = 1
for i in range(1, len(S)):
    if not S[i] == S[i-1]:
        if not flag:
            odd.append(count)
        else:
            even.append(count)
        count = 1
        flag = not flag
    else:
        count += 1

if flag:
    even.append(count)
else:
    odd.append(count)

print(min(sum(odd), sum(even))+ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
r = N - 1
while S[r] == "#":
    r -= 1
cnt = Counter(S[:r+1])
print(min(cnt["."], cnt["#"]))

Submission status: Runtime Error

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

i = 0
while i<len(s) and s[i] == '.':
  i+=1
j = n-1
while i>=0 and s[j] == '#':
  j-=1

s = s[i:j+1]
print(min(s.count('#'),s.count('.')))