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 = input()
c = 0
sl = list(s)
sl2 = sl
k = 0
for i in range(n-2):
   if sl[i]=="#" and sl[i+1]==".":
      if sl[i+2]=="." and sl[i-1]==".":
        sl[i]='.'
        c = c + 1
      if sl[i+2]=="." and sl[i-1]=="#":
        sl[i+1]='#'
        sl[i+2]='#'
        c = c + 2
      elif sl[i+2]=='#':
        sl[i+1]='#'
        c = c + 1
if sl[n-2]=="#" and sl[n-1]==".":
  sl[i+1]='#'
  c=c+1
print(c)

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if b < a:
        a,b = b,a
    if a <= c <= b:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    s = input()
    a = list(set(list(s)))
    k = II()-1
    for i in a:
        if s[k] != i:
            s = s.replace(i, "*")
    print(s)
    return

#C
def C():
    n = II()
    s = S()
    dp = []
    bf = s[0]
    del s[0]
    a = 1
    flg = False
    if bf == ".":
        flg = True
    for i in s:
        if i == bf:
            a += 1
        else:
            dp.append(a)
            a = 1
            bf = i
    dp.append(a)
    ans = 0
    a, b = 0, 0
    if flg:
        dp[0] = 0
    if s[-1] == "#":
        dp[-1] = 0
    for d in range(len(dp) - 2, -1, -2):
        a += dp[d]
    for d in range(len(dp) - 1, -1, -2):
        b += dp[d]
    print(min(a,b))

    return

#D
def D():
    n = II()
    ai = IR(n)
    ai.sort()
    ruiseki = [0 for i in range(n)]
    for num, a in enumerate(ai):
        ruiseki[num] = a + ruiseki[num-1]
    select = list(itertools.combinations(range(n), 3))
    ans = 0
    for a,b,c in select:
        A = ruiseki[a]
        B = ruiseki[b] - ruiseki[a]
        C = ruiseki[c] - ruiseki[b]
        if A + B > C and B + C > A and A + C > B:
            ans += 6
            ans = ans % mod
    print(ans)
    
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
s_list=list(s)
c=0
if s_list[0] == "#" and s_list[1] == ".":
  c += 1
  s_list[0] = "."
for a in range(n-2):
  if s_list[a+1] == "#" and s_list[a+2] ==  ".":
                     c += 1
                     s_list[a+2] = "#"
print(c)

Submission status: Runtime Error

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

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

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

dots = dot_num ()
hashes = hash_num ()

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

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

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]
print(min(s.count('#'),s.count('.')))

Submission status: Runtime Error

Solution code:
a=input(int())
b=input(str(),len(a))
sum=0
while "#." in b:
     ne=b.replace("#.","##"or"..")
     sum+=1
min(sum)

Submission status: Runtime Error

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

if s.count('.') == len(s):
    print(0)
else:
    for i, wb in enumerate(s):
        if wb == '#':
            break
        else:
            s = s[i+1:]
    
    ans_black_change = s.count('#')
    if s[-1] == '#':
        ans_black_change -= 1
    ans_white_change = s.count('.')
    
    ans = min(ans_black_change, ans_white_change)
    print(ans)

Submission status: Runtime Error

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

a = 0
b = 0

x = 0
y = 0

while x == 0:
  if S[y] =='.':
    y += 1
  else:
    x =1

for i in range(y, N):
  if S[i] == '.':
    a += 1
  else:
    b += 1

print(min(a, b))

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] == '#':
        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:
a = int(input())
b = input()

change = 0
ans = 0
for i in range(a):
  if(b[i] == '#' or change == 1):
    change = 0
    if(i + 1 >= a):
      break
    else:
      if(b[i+1] == '.'):
        ans += 1
        if(i+2 >= a):
          if(b[i+2] != '.'):change = 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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.int8)
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)

Submission status: Runtime Error

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

B = 0
W = 0

for i in range(0,N-1):
    if S[i] == '#':
        if i+1 > N:
            pass
        elif S[i+1] == '.':
        B = B+1
    else:
        W = W+1
if W >= B:
    print(B)
else:
    print(W)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
S = list(S)
K = S.copy()
T = S.copy()

tmp = [0 for _ in range(N)]

if S[0] == '.':
    tmp[0] = 1

for i in range(N-1):
    if S[i] == '.':
        tmp[i+1] = tmp[i] + 1
    else:
        tmp[i+1] = tmp[i]
  
res1 = 10 ** 9
for i in range(N):
    res1 = min( (i + 1) - tmp[i] + tmp[N-1] - tmp[i], res1)
        

b = 0
w = 0
for i in range(N):
    if K[i] == '#':
        b += 1
    else:
        w += 1

res3 = N - max(b, w)

print(min(res1, res2, res3))

Submission status: Runtime Error

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

count = 0

for i, wb in enumerate(s):
    if i != (n-1):
        if wb == '#':
            s2 = s[i:]
            break

count = s2.count('.')
print(count)

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
S = input()
black_stone = S.count('#')
X = copy.copy(S)
num = 0

for i in range(N):
  if X[i] == '#' and X[i+1] == '.':
    num += 1
    X = X.replace(X[i],'#')
    
print(min(black_stone,num))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
S=str(input())
a=0;X=0
while X<N:
  if S[X]=='#' and S[X+1]=='.':
    a+=1
    X+=2
  else:
    X+=1
print(a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    S = lines.pop(0)
    # reverse
    S = S[::-1]
    # 白が現れるまで省く
    idx = S.index('.')
    S = S[idx:]

    res = 0
    while(True):
        w = S.find('#')
        b = S[w:].find('.')

        if w < 0:
            break

        if ( w < b ):
            res += w
            S = S[w+b:]
        else:
            res += min(S.count('.'), S.count('#'))
            break

    print(res)

lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

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())
s=input()
x=n
flag1=False
flag2=False
for i in range(n):
    if s[i]=="#" and flag1==False:
        x=i
        flag1=True
    if s[n-1-i]!="#" and flag2==False:
        y=n-i
        flag2=True
    if flag1==True and flag2==True:
        break

b=s[x:y].count("#") 
w=len(s[x:y])-b
print(b if b<w else w)

Submission status: Runtime Error

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

if s.count('.') == len(s):
    print(0)
else:
    for i, wb in enumerate(s):
        if wb == '#':
            break
        else:
            s = s[i+1:]
    
    ans_black_change = s.count('#')
    if s[-1] == '#':
        ans_black_change -= 1
    ans_white_change = s.count('.')
    
    ans = min(ans_black_change, ans)
    print(ans)

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
input_str=list(input[1])

x=0
i=0
while(x==0):
    #x=1
    if input_str[i]=="#" and input_str[i+1]==".":
        output+=1
        input_str[i]="."
        #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())
S = input()
cnt = 0
if S[0] == '#' and S[1] == '.':
    S.replace(S[0], '.')
    cnt += 1

i = 1
for i in range(N - 2):
    if S[i] == '#' and S[i + 1] == '.':
        if S[i - 1] == '.':
            S.replace(S[i], '.')
        else:
            S.replace(S[i + 1], '#')        
        cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder C
"""
import numpy as np
def encode(S):
    code=[]
    code.append([S[0],1])
    for s in S[1:]:
        if s==code[-1][0]:
            code[-1][1]+=1
        else:
            code.append([s,1])
    return code


def main():
    N=input()
    S=list(map(str,input().split()))[0]
    enS=encode(S)
    print(enS)
    if enS[0]=="." and len(enS)!=1:
        enS=enS[1:]
    out=np.zeros([len(enS)+1])
    for j,e in enumerate(enS):
        if e[0]==".":
            out[:j]+=e[1]
        else:
            out[j:]+=e[1]
    print(int(out.min()))
            






    # tmp=False
    # num=0
    # for s in S:
    #     # print(s,tmp)
    #     if s=="#":
    #         tmp=True
    #     elif s=="." and tmp:
    #         num+=1

    # num2=0
    # bl=0
    # for s in S:
    #     # print(s,tmp)
    #     if s=="#":
    #         num2+=1
    #         bl+=1
    #     else:
    #         bl=0

    # print(min(num,num2-bl))
 
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
input()
S = input()

if '#' in S:
    sharp = 0
    for c in S[::-1]:
        if c == '#':
            sharp += 1
        else:
            break
    if sharp != 0:
        S = S[:-sharp]
    black = S.index('#')
    print(min(S[black:].count('#'), S[black:].count('.')))
else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
SS = list(S)
 
D = 0
 
black = S.split("#")
white = S.split(".")
while SS[0] == ".":
  white.pop(0)
  SS.pop(0)
  
while SS[-1] == "#":
  black.pop()
  SS.pop()
while "" in black:
  black.remove("")
  
while "" in white:
  white.remove("")
  
for b, i in zip(black,white):
  D += min(len(b),len(i))
  
print(D)

Submission status: Runtime Error

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

n = int(input())
state = input()
state_list = list(state)
prob_num = 0
state_list.append(" ")
for i in range(n):
	if state_list[i] == "#" and state_list[i+1] == ".":
		prob_num += 1

state_list.remove(" ")
black = state_list.count("#")
white = state_list.count(".")
min_stone = min(black, white)

if min_stone > prob_num:
	if state_list[-1] == "#":
		print(min_ - 1)
	else:
		print(min_)
else:
	print(prob_num)

Submission status: Runtime Error

Solution code:
a=input()
b=input()
scount=0
ccount=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
if q<z:
        ccount=q
print(ccount)

Submission status: Runtime Error

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

result = min(S.count("."),S.count("#"))
i = 0

while i < N:
    leftslice = S[:i]
    rughtslice = S[i:]
    leftblack = leftslice.count("#")
    rightwhite = rightslice.count(".")
    nowresult = leftblack + rightwhite
    if result >= nowresult:
        result = nowresult
    else:
        i += (nowresult - result)
    i += 1

print(result)

Submission status: Runtime Error

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

index_1 = [i for i in range(N) if S[i] == "."]
index_2 = [j for j in range(N) if S[j] == "#"]

if S[0] == "." and S[1] == "#":
  if S[N-1] == "#" and S[N-2] == ".":
    print(min(len(index_1)-2, len(index_2)-2))
  else:
    print(min(len(index_1)-1, len(index_2)-1))
elif S[N-1] == "#" and S[N-2] == ".":
  print(min(len(index_1)-1, len(index_2)-1))
else:
  print(min(len(index_1), len(index_2)))

Submission status: Runtime Error

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

  ans = 10**15
  a = s.count(".")
  b = s.count("#")
  sharp = []
  dot = []
  tp = 1
  if a == n:
    print("0")
  else:
    for i in range(n-1):

        if s[i] == s[i+1]:
           tp += 1
               
        if s[i] != s[i+1]:
            if s[i]==".":
                dot.append(tp)
                sharp.append(0)
            else:
                dot.append(0)
                sharp.append(tp)
            tp = 1
        if i == n-2:
           if s[i+1]==".":
                dot.append(tp)
                sharp.append(0)
           else:
                dot.append(0)
                sharp.append(tp)
           tp = 1
    
    e = len(sharp)
    ans = min(b-sharp[-1],a-dot[0])
    #print(dot,sharp)
    #print(ans)
    for i in range(e):
      do = dot[i]
      sh = sharp[i]
      a += do
      b += sh
      ans = min(ans,min(b-sharp[-1],a-dot[0]))
      
        
    print(ans)
solve()

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
cnt=0
if s[0]=='.':
  cnt=cnt
  if s[n-1]=='#':
    cnt=cnt
    for i in range(1,n-1):
      if s[i]=='.':
        cnt+=1
      else:
        cnt-=1
    if cnt=<0:
      print(s.count('.')-1)
    else:
      print(s.count('#')-1)
  else:
    for i in range(1,n):
      if s[i]=='.':
        cnt+=1
      else:
        cnt-=1
    if cnt=<0:
      print(s.count('.')-1)
    else:
      print(s.count('#'))    
else:
  if s[n-1]=='#':
    cnt=cnt
    for i in range(n-1):
      if s[i]=='.':
        cnt+=1
      else:
        cnt-=1
    if cnt=<0:
      print(s.count('.'))
    else:
      print(s.count('#')-1)
  else:
    for i in range(n):
      if s[i]=='.':
        cnt+=1
      else:
        cnt-=1
    if cnt=<0:
      print(s.count('.'))
    else:
      print(s.count('#'))

Submission status: Runtime Error

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

result = min(S.count("."),S.count("#"))
i = 0

while i < N:
    leftslice = S[:i]
    rughtslice = S[i:]
    print(leftslice)
    print(rightslice)
    leftblack = leftslice.count("#")
    rightwhite = rightslice.count(".")
    nowresult = leftblack + rightwhite
    if result >= nowresult:
        result = nowresult
    else:
        i += (nowresult - result)
    i += 1

print(result)

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("#"):
            for j in range(len(form)):
                if form[j] == "#":
                    form[j] = "."
                    cnt += 1
        if form.count(".") < form.count("#"):
            for j in range(len(form)):
                if form[j] == ".":
                    form[j] = "#"
                    cnt += 1
        for j in range(len(latt)):
            if latt[j] == ".":
                latt[j] = "#"
                cnt += 1
        cnts.append(cnt)
    return cnts




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

Submission status: Runtime Error

Solution code:
#A, B, C = map(int,input().split())


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

count=0
#for i in range(N-1):
#   if S[i] == "#" and S[i+1] == "." and S[i+2] == ".":
#       count += 1
#   if S[i] == "#" and S[i+1] == ".":
#       count += 1
#print(count)

i=0
while(i < N-1):
   if S[i] == "#" and S[i+1] == "." and S[i+2] == ".":
       count += 1
       i += 2
   elif S[i] == "#" and S[i+1] == "." and S[i+2] == "#":
       count += 1
       i += 2
   else:
       i += 1
print(count)

Submission status: Runtime Error

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

for i, wb in enumerate(s):
    if i != (n-1):
        if wb == '#':
            s2 = s[i:]
            break

count = s2.count('.')
print(count)

Submission status: Runtime Error

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

index_1 = [i for i in range(N) if S[i] == "."]
index_2 = [j for j in range(N) if S[j] == "#"]

if S[0] == "." and S[1] == "#":
  print(min(len(index_1)-1, len(index_2)-1))
else:
  print(min(len(index_1), len(index_2)))

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] == '#':
        return count(S, k - 1) + 1
    else:
        return count(S, k - 1)

print(count(S, n))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
c = 0
sl = list(s)
sl2 = sl
k = 0
for i in range(n-2):
   if sl[i]=="#" and sl[i+1]==".":
      if sl[i+2]==".":
        sl[i]='.'
        c = c + 1
      elif sl[i+2]=='#':
        sl[i+1]='#'
        c = c + 1
      #if c == 1:
       # k = i
if sl[n-2]=="#" and sl[n-1]==".":
  sl[i+1]='#'
  c=c+1
print(c)

Submission status: Runtime Error

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

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

if ansb<=answ:
    print(ansb)
else:
    print(answ)

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
S = input()
X = copy.copy(S)
num = 0

for i in range(N):
  if X[i] == '#' and X[i+1] == '.':
    num += 1
    X = X.replace(X[i],'#')
    
print(num)

Submission status: Runtime Error

Solution code:
N=int(input())
S = input()
left = -1
for i, s in enumerate(S):
    if s == '#':
        left = i
        break
if S[-1] == '#':
    sharps = S.split('.')
    t=len(sharps[-1])
    t2=len(sharps[-2])
    a=len(S.split('#')[-2])
    print(min(S.count('#')-t, S[left:].count('.'), S.count('#')-t-t2+a))
else:
    sharps = S.split('.')
    t=len(sharps[-2])
    a=len(S.split('#')[-1])
    print(min(S.count('#'), S[left:].count('.'), S.count('#')-t+a))

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
black1 = s.count('#')
white1 = s.count('.')
if black1 > 0:
    for i in reversed(s):
        if i == '#':
            n -= 1
        else:
            break
    l1 = s[:n]
    black2 = l1.count('#')
    b = l1.index('#')
    l2 = l1[b:]
    white2 = l2.count('.')
    l3 = s[b:]
    black3=l3.count('#')
    print(min(black1,white1,black2,white2,black3))
else:
    print('0')

Submission status: Runtime Error

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

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

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

for j in range(1,index):
    if S[j] == "." and S[j-1] == "#":
        break
for k in range(j-1):
    if S[k] == ".":
        dot_count += 1
        
print(min(sharp_count,dot_count))

Submission status: Runtime Error

Solution code:
N=int(input())
S=list(input())
S_ptn1=S[::-1]
cnt=0
cnt_ptn1=0
for i in range(N-1):
    if S[i]=='#' and S[i+1]=='.':
        S[i+1]='#'
        cnt+=1
for i in range():
    if S_ptn1[i]=='.' and S_ptn1[i+1]=='#':
        S[i+1]='.'
        cnt_ptn1+=1
if cnt<cnt_ptn1:
    print(cnt)
else:
    print(cnt_ptn1)

Submission status: Runtime Error

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

if s == "." * n:
    print(0)
else:
    black = s.index("#")
    white = [i for i, x in enumerate(s) if x == "."]
    wb = [i for i, x in enumerate(s[black:]) if x == "."]
    bw = [i for i, x in enumerate(s[:white[-1]]) if x == "#"]
    print(min(len(wb), len(bw)))

Submission status: Runtime Error

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

if n == 1:
    print(0)
elif n == 2:
    if s[0]=="#" and s[1]==".":
        print(1)
else :
    idx = 0
    t = s[0]
    while t == ".":
        idx += 1
        t = s[idx]
    
    r = []
    cnt = 1
    for i in range(1+idx, n):
        if t == s[i]:
            cnt += 1
        else :
            r.append(cnt)
            cnt = 1
            t = s[i]
    
    r.append(cnt)
    
    if len(r) == 1:
        print(0)
        
    else :
        ans = 0
        if len(r) % 2 == 0:
            for i in range(0, len(r), 2):
                if r[i] > r[i+1]:
                    ans += r[i+1]
                else :
                    ans += r[i]
        else :
            for i in range(0, len(r)-1, 2):
                if r[i] > r[i+1]:
                    ans += r[i+1]
                else :
                    ans += r[i]    
        print(ans)

Submission status: Runtime Error

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

while True:
    if S[-1] == '.':
        break
    if S[-1] == '#':
        s = list(S)
        del s[-1]
        S = ''.join(s)



print(min(S.count('.'),S.count('#')))

Submission status: Runtime Error

Solution code:
stones_count = int(input())
input_str = input()

target = input_str[0]

def set_next_target(target_char):
  if target_char == '#':
    return '.'
  else:
    return '#'

stones = ''
stones_list = []

for i in range(stones_count):
  if input_str[i] == target:
    stones = stones + target
  else:
    stones_list.append(stones)
    target = set_next_target(target)
    stones = target

stones_list.append(stones)
#print(stones_list)

count_0 = 0
count_1 = 0

## ケース: .. or ## の場合、変換は不要
elif len(stones_list) == 1 :
  print(0)
  exit()
## ケース: ..## の場合、変換は不要
elif len(stones_list) == 2 and '#' in stones_list[-1]:
  print(0)
  exit()
## ケース: ..##..##.. の場合、先頭の要素を除いたもので少ない方のみ変換すればよい
else:
  for i in range(1, len(stones_list)):
    if i % 2 == 0:
     count_0 += len(stones_list[i])
    else:
     count_1 += len(stones_list[i])

if count_0 > count_1:
  print(count_1)
else:
  print(count_0)

Submission status: Runtime Error

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

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

if ansb<=answ:
    print(ansb)
else:
    print(answ)

Submission status: Runtime Error

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

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

print(min(black, white))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
data = list()
ans = list()
for i in range(n+1):
    data.append("." * i + "#" * (n-i))
#print(data)
for i2 in data:
    tmp = 0
    for i in range(n):
        if i2[i] != s[i]:
            tmp += 1
    ans.append(tmp)
print(sorted(ans)[0])

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
 
res = 0
tmp = ""

for i in range(N-1,-1,-1):
    if S[i] == "#":
        continue
    dot = S[:i+1].count(".")
    sha = S[:i+1].count("#")
    break
print(min(dot, sha))

Submission status: Runtime Error

Solution code:
from itertools import accumulate

input()
l = [0, *accumulate(c == '.' for c in input())]
print(min(i - x + l[-1] - x for i, x in enumerate(l)))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
 
ans = 0
flag=True

if S[0]=="#":
	flag2 = True
for i in range(N-1):
  if S[i+1]==".":
    if flag2:
    	ans += 1
    flag2 = False
  
  elif S[i+1]=="#":
    flag2 = True
  
  if flag:
    if S[i]=="#":
      x = i
  
if 2*ans < N:
  print(ans)
 
else:
  print(le -ans - x)

Submission status: Runtime Error

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

index_1 = [i for i in range(N) if S[i] == "."]
index_2 = [j for j in range(N) if S[j] == "#"]

if S[0] == "." and S[1] == "#":
  print(min(len(index_1), len(index_2)-1))
else:
  print(min(len(index_1), len(index_2)))

Submission status: Runtime Error

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

  ans = 10**15
  a = s.count(".")
  b = s.count("#")
  sharp = []
  dot = []
  tp = 1
  if a == n:
    print("0")
  else:
    for i in range(n-1):

        if s[i] == s[i+1]:
           tp += 1
               
        if s[i] != s[i+1] or i+1 ==n-1:
            if s[i]==".":
                dot.append(tp)
                sharp.append(0)
            else:
                dot.append(0)
                sharp.append(tp)
            tp = 1
    e = len(sharp)
    ans = min(b-sharp[-1],a-dot[0])
    
    for i in range(e):
      do = dot[i]
      sh = sharp[i]
      a += do
      b += sh
      ans = min(ans,min(b-sharp[-1],a-dot[0]))
      
        
    print(ans)
solve()

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
x=n
for i in range(n):
    if s[i]=="#":
      x=i
      break
for i in range(1,n):
    if s[n-i]=="#":
        s=s[:-i]
    else:
        break
b=s[x:].count("#") 
w=len(s[x:])-b
print(b if b<w else w)

Submission status: Runtime Error

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

index_1 = [i for i in range(N) if S[i] == "."]
index_2 = [j for j in range(N) if S[j] == "#"]

if S[0] == "." and S[1] == "#":
  print(min(len(index_1), len(index_2-1)))
else:
  print(min(len(index_1), len(index_2)))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
SS = list(S)
 
D = 0
 
black = S.split("#")
white = S.split(".")
while SS[0] == ".":
  white.pop(0)
  SS.pop(0)
  
while SS[-1] == "#":
  black.pop()
  SS.pop()
for bb in range(black.count("")):
  black.remove("")
  
for ii in range(white.count("")):
  white.remove("")
  
for b, i in zip(black,white):
  D += min(len(b),len(i))
  
print(D)

Submission status: Runtime Error

Solution code:
N=int(input())
S=str(input())
a=0;X=0
while X!=N-1:
  if S[X]=='#' and S[X+1]=='.':
    a+=1
    X+=2
  else:
    X+=1
print(a)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
arr = []
ans = 0
for i, word in enumerate(s):
    if word == '#':
        arr.append(i)

for i in range(len(arr) - 1):
    ans += arr[i+1] - arr[i]

if arr[-1] != n-1:
    ans += n - arr[-1] - 1

ans -= len(arr) - 1
print(ans)

Submission status: Runtime Error

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

index_1 = [i for i in range(N) if S[i] == "."]
index_2 = [j for j in range(N) if S[j] == "#"]

if S[0] == "." and S[1] == "#":
  index_2 -= 1

print(min(len(index_1), len(index_2)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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)
a = np.zeros((N+1, N), dtype=np.int8)
for i in range(N):
    a[i, :i] = 1
a[N] = 1

ans = (a - L)**2
ans = ans.sum(axis=1).min()
print(ans)

Submission status: Runtime Error

Solution code:
def read_input():
    n = int(input())
    s = input().strip()

    return n, s


# . -> 0, # -> 1とする
def make_answer_pattern(n):
    zeros = n

    result = []
    for ones in range(n + 1):
        result.append('0' * (zeros - ones) + '1' * ones)

    return result

def convert_s(s):
    return s.replace('.', '0').replace('#', '1')


def get_diff(s, t):
    sb = int(s, 2)
    tb = int(t, 2)

    diffb = sb ^ tb
    diff = bin(diffb)

    return sum([1 for d in diff if d == '1'])

if __name__ == '__main__':
    n, s = read_input()
    target = convert_s(s)

    patterns = make_answer_pattern(n)

    min_diff = n
    for p in patterns:
        diff = get_diff(target, p)
        if diff < min_diff:
            min_diff = diff
            if min_diff == 0:
                break

    print(min_diff)

Submission status: Runtime Error

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

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

for i in range(n-2):
  if t[i] == '#' and t[i+1] == '.' and t[i+2] == '#':
    t[i] == '.'
    c+=1
    
for i in range(n-1):
  if t[i] == '#' and t[i+1] == '.':
    t[i+1] == '#'
    c+=1
    
print(min(cnt, c))

Submission status: Runtime Error

Solution code:
import re

N = int(input())
S = list(str(input()))

count = 0

for index, stone in enumerate(S):
    if index is not len(S)-1:
        if stone is '#' and S[index+1] is '.':
            count = count + 1

print(count)