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()
min_ans = 2*10**5

ideals = []
for i in range(N+1):
    ideals.append("."*i + "#"*(N-i))
for ideal in ideals:
    ans = 0
    for i in range(N):
        if S[i] != ideal[i]:
            ans += 1
    if ans < min_ans:
        min_ans = ans
print(min_ans)

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 s[i] == '#' and s[i+1] == '.' and s[i+2] == '#':
    s[i] == '.'
    c+=1
    
for i in range(n-1):
  if s[i] == '#' and s[i+1] == '.':
    s[i+1] == '#'
    c+=1
    
print(min(cnt, c))

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())
counter_=0
counter*=0
for i in range(N):
  if(S[i]=="*"):
    counter_*_+=1
  else:
    counter_+=1
if(counter_*_>=counter_):
  print(counter_)
else:
  print(counter_*_)

Submission status: Runtime Error

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

count = 0

for i in range(N):
    if(S[i] == '.'):
        num = i
        break

count = len([ i for i in S[num+1:] if i == '#'])
print(count)

Submission status: Runtime Error

Solution code:
def third_select(S):
    right = N - 1
    change = 0
    sharp_appeared = False
    for i, s in enumerate(S[::-1]):
        if s == '#':
            sharp_appeared = True
        elif sharp_appeared:
            right = N - i
            break
        else:
            change += 1

    for s in S[:right]:
        if s == '#':
            change += 1

    for i,s in enumerate(S):
        if s == '#':
            left = i
            break

    return min(change, S[left:].count('.'))

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

ALL_period = S.count('#')
ALL_sharp = N - ALL_period



print(min(ALL_period, ALL_sharp, third_select(S)))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
S1 = list(S); S2 = list(S)
kuro = 0; shiro = 0
for i in range(N):
    if S1[i+1] == '.' and S1[i] == '#':
        S1[i+1] = '#'
        kuro += 1
for i in range(N):
    if S2[i+1] == '.' and S2[i] == '#':
        S2[i] = '.'
        shiro += 1
    
print(min(N - S.count('#'), N - S.count('.'), kuro, shiro))

Submission status: Runtime Error

Solution code:
N=3
s=".######."
#s=[s[i] for i in range(len(s))]
#N=input()
#s=input()
s=[s[i] for i in range(len(s))]
hit1=0
count1=0
for i in s:
    if i=="#":
        hit1 = 1
    if i==".":
        count1=count1+hit1
count2=0
hit2=0
for i in range(len(s)):
    if s[-1-i]==".":
        hit2 = 1
    if s[-1-i]=="#":
        count2=count2+hit
        
print(min(count1,count2))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
s = str(input())
"""
n = 10
s = "..###...#."
"""
s = s.replace(".", "0").replace('#', "1")
b = s.find("1")

a = 0
for i in range(b, n-b+1):
    a+=int(s[i])
print(n-b-a)

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())
counter_=0
counter*=0
for i in range(N):
  if(S[i]=="*"):
    counter*+=1
  else:
    counter_+=1
if(counter*>=counter_):
  print(counter_)
else:
  print(counter*)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
if S.count('.') == N or S.count('#') == N:
    print(S[0] * N)
elif len(S.count('.')) == len(S.count('#')):
    print(0)
else:
    print(abs(S.count('.') - S.count('#')))

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())
s = list(S)
id = s.index('#')
if id == 0 or id == N:
  print(0)
else:
  s_a = s[0:id]
  s_b = s[id+1:N-1]
  a = s_a.count('#')
  b = s_b.count('.')
  if a > b:
    print(b)
  else:
    print(a)

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())
 
 
S2 = S.split("#")[1:]
#print(S2)
if S2 == S:
        print("0")
else:
    sn = S2.count(".")
    if sn == 0:
        #print(S2[0])
        sn = S2[0].count(".")
    sn2 = S.count("#")
    #print(sn,sn2)
    sn3 = S.split(".")[-1]
    print(min(sn,sn2))

Submission status: Runtime Error

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

num = 0
result = 0

if S[N-1] ==".":
    dot = S.count(".")
    if dot > N-dot:
        print(N-dot)
        break

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

white = S[0:num].count('.')
black = S[0:num].count('#')
if white < black:
    result = white
else:
    result = black
print(result)

#  ##.#.#.###
#  .#..#..###

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

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

for i in range(N):
    leftslice = S[:i]
    rightslice = S[i:]
    print(leftslice)
    print(rightslice)
    leftblack = leftslice.count("#")
    rightwhite = rightslice.count(".")
    if result >= leftblack + rightwhite:
        result = leftblack + rightwhite

print(result)

Submission status: Runtime Error

Solution code:
from sys import stdin
# import math
import numpy as np
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]

N = int(stdin.readline().rstrip().split()[0])
S = stdin.readline().rstrip().split()[0]

white = S.count(".")
ans1=0
if white == N:
  ans1=0
else:
  first_black = S.index("#")
  ans1 = white - first_black
  
ans2=0
black = N-white
last_white = S[::-1].index(".")
ans2=black-last_white

if ans1>ans2:
  print(ans2)
else:
  print(ans1)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
s=input()
A=False
for i in range(n-1):
    if s[i]=='#':
        num=i
        A=True
        break
if A:
    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-1,b))
        else:
            print(min(a,b))
else:
    print(0)

Submission status: Runtime Error

Solution code:
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()

min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

x = len(l)//2
for i in range(x):
    m = black[i] + (white[x] - white[i])
    min_num = min(m, min_num)

print(min_num)

Submission status: Runtime Error

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

"""この方法ではTLE
R=[]
for i in range(N+1):
  R.append(S[0:i].count('#')+S[i:N].count('.'))
print(min(R))
print(R)
"""

#左から順に処理
R=[]
sig=0
for i in range(N-1):
  if (S[i] == '#') and (S[i+1] == '.'):
    #この場合、'##'にするか'..'にするか
    # '##'にする場合
    R.append(S[i+1:N].count('.')+sig)
    # '..'にする場合
    S=S[0:i] + '.' + S[i+1:N]
    sig+=1#累積置換回数

#Sが全て'.'になっている場合が取れていないので追加
flg=True
for i in range(N):
  if S[i]=='#':
    flg=False
if flg:
  R.append(sig)

print(min(R))

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
A=False
for i in range(n-1):
    if s[i]=='#':
        num=i
        A=True
        break
if A:
    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-1,b))
        else:
            print(min(a,b))
else:
    print(0)

Submission status: Runtime Error

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

cont=0
best=n
ans=[]
for i in range(len(s)):
	for j in range(len(s)):
		if j<i and s[j]=='#':
			cont+=1
		if j>i and s[j]=='.':
			cont+=1
	ans.append(cont)
	if cont<best:
		best=cont
	if cont==0 or cont>ans[len(ans)]:
		break
	cont=0
print(best)

Submission status: Runtime Error

Solution code:
#C - Stones
n = int(input())
s = list(input())
isFound = False
cnt = 0
#一番右の白を見つける
for i in range(n):
    if s[i] == '.':
        right = i

#rightまでの黒を数える
for i in range(right):
    if s[i] == '#':
        cnt += 1
        
print(min(s.count('.'), s.count('#'), cnt))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin

def main():
    N = int(input())
    S = input()

    white, black = [], []
    cntw, cntb = 0, 0
    prev = S[0]
    for s in S:
        if prev != s:
            white.append(cntw)
            black.append(cntb)
            cntw, cntb = 0, 0
        if s == '.':
            cntw += 1
        else:
            cntb += 1
        prev = s
    white.append(cntw)
    black.append(cntb)

    if len(white) == 1 and len(black) == 1:
        print(0)
        return
    ans = 0
    for i in range(N-1):
        if black[i] and not black[i+1]:
            ans += min(black[i], white[i+1])
    print(ans)

input = lambda: stdin.readline().rstrip()
main()

Submission status: Runtime Error

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

count = 0
white_count = 0
white_count2 = 0

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

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

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

if count > white:
    n = n -white - white_count
    for i in range(n):
        if s[i + white + white_count] == ".":
            white_count2 += 1
    result = white + white_count2
else:
    result = white_count

print(result)

Submission status: Runtime Error

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

ans = 100000
flag=False
cad = S.count('.')
cah = S.count('#')
for i,s in enumerate(S):
  if(i==0):
    last_s = s
    continue
  else:
    if last_s == "." and s == "#":
      flag=True
      cld = S[:i].count('.')
      clh = S[:i].count('#')
      ans=min(ans, min(cld,clh)+min(cad-crd,cah-crh))

    last_s = s

if(not flag): print(0)
else: print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())
b = list(str(input()))

try:
    firstb = b.index('#')
except ValueError:
    firstb = len(b) + 1

numberb = b[firstb:].count('#')
if b[-1] == '#':
    numberb -= 1
numberw = b[firstb:].count('.')

breverse = b
breverse.reverse()
firstw = breverse.index('.')
numberbreverse = breverse[firstw:].count('#')

ttt = []
ttt.append(numberb)
ttt.append(numberw)
ttt.append(numberbreverse)

print(min(ttt))

Submission status: Runtime Error

Solution code:
import numpy

n = int(input())
char = input()

char_list = numpy.array(list(char))

all_write = numpy.full(n,".")
all_black = numpy.full(n,"#")
mix = numpy.full(n,".")
mix[-1] = "#"

print(min(n - sum(all_black == char_list),n - sum(all_write == char_list),n - sum(mix == char_list)))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.zeros((N+1, N))

for i in range(N):
    a[i, :i] = 1
a[N] = 1
L = [0] * N
for i in range(N):
    if S[i] == ".":
        # white
        L[i] = 0
    else:
        L[i] = 1
L = np.array(L)
ans = (a - L)**2
ans = ans.sum(axis=1).min()
print(int(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
if s[0]==".":
  k[0]="."
  k[1]="#"
else:
  k[0]="#"
  k[1]="."
  
for i in range(n):
  if s[i]!=k[i%2]:
    s[i]=k[i%2]
print(s)

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-1):
                    if S[n-i-1-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-i-1):
                    if S[n-k-1-l]==".":
                        count+=1
                        
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
tmp = S.count('#.')
counter = 0
for i in range(tmp):
    count = S.find('#.') + 1
    while S[count] == '.':
        counter += 1
        S[count] = '#'
        count+= 1
print(counter)

Submission status: Runtime Error

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

si=[]
k=[]
count = 0
flag = 0
for i in range(0,n):
    if flag == 0:
        if s[i] == '.':
            count += 1
        else:
            si.append(count)
            count = 1
            flag = 1
    else:
        if s[i] == '#':
            count += 1
        else:
            k.append(count)
            count = 1
            flag = 0

smax = sum(si) - si[0]

kmax = sum(k) - k[-1]

ans = max(smax,kmax)
print(ans)

Submission status: Runtime Error

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

print(count)

Submission status: Runtime Error

Solution code:
def get_min_cost(S):
    if len(S) == 0:
        return 0
    if len(S) == 1:
        return 0
    return min(1 + get_min_cost(S[1:]), get_cost_change_black(S))

def get_cost_change_black(S):
    return S.count(".")

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

if '#' in S:
    answer = get_min_cost(S[S.index('#'):])
    print(answer)
else:
    print(0)

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 += 1
   elif S[i] == "#" and S[i+1] == ".":
       count += 1
       i += 1
   else:
       i += 1
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
ans = 0
for i in range(n-1):
    if s[i] == '#':
        index = i+1
        if index+1 < n:
            while s[index] == '.':
                ans += 1
                index += 1
            i += index
        else:
            if s[-1] == '.':
                ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def check_and_back_or_go_to(li, ind, N, counter):
    back = True
    # print('see {} {} and {} counter{}'.format(ind, li[ind - 1], li[ind], counter))
    if ind == 0:
        return counter
    elif ind + 1 == N:
        back = False
    # access
    if li[ind - 1] == '#' and li[ind] == '.':
        li[ind] = '#'
        if back:
            c=check_and_back_or_go_to(li, ind + 1, N, counter + 1)
            return c
        c=check_and_back_or_go_to(li, ind - 1, N, counter + 1)
        return c
    else:
        c=check_and_back_or_go_to(li, ind - 1, N, counter)
        return c


N = int(input())
S = list(input())
r = range(N)
count = check_and_back_or_go_to(S, len(S) - 1, N, 0)
print(min([count,N-count]))

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
start,end = 0,0
for i in range(N):
  if S[-i+1] == '.':
    end = N-i+1
    break
for i in range(N):
  if S[i] == '#':
    start = i
    break
M = S[start:end]
print(min(M.count('.'),M.count('#')))

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
S = input()
ans = S.count('.')
num = 0
for x in S:
    if x == '#':
        break
    else:
        num += 1
print(min(ans-num, S.count('#'))

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
ans = 0
for i in range(n-1):
    if s[i] == '#':
        index = i+1
        if index+1 < n:
            while s[index] == '.':
                ans += 1
                index += 1
        else:
            if s[-1] == '.':
                ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
if S == ['*'] * N or S == ['.'] * N:
    print(0)
    exit()

for i in range(N - 1, -1, -1):  # #->.
    if S[i] == '.':
        num1 = i
        break

for j in range(N):  # .->#
    if S[j] == '#':
        num2 = j
        break

ans1 = S[:num1].count('#')
ans2 = S[num2 + 1:].count('.')
print(min(ans1, ans2))

Submission status: Runtime Error

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

index = -1
flag = 0
for i, s in enumerate(S):
    if s == '.' and flag:
        idx = i - 1
        break
    if s == '#':
        flag = 1
        
if idx < 0:
    print(0)
    sys.exit()

S = S[idx:]
num_black = S.count('#')
num_white = S.count('.')
print(min([num_black, num_white]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])
    s = lines[1]

    return (n, s)


def solve(n, s):
    
    ss = []
    for c in s:
        if c == ".":
            ss.append(True)
        else:
            ss.append(False)

    len_ss = len(ss)
    result = 0
    if len_ss == 1:
        result = 0
    else:
        r1 = 0
        for i, d in enumerate(ss):
            if ss[i] is False and ss[i+1] is True:
                ss[i+1] = False
                r1 = r1 + 1
        r2 = 0
        for i, d in enumerate(ss):
            if ss[i] is False and ss[i+1] is True:
                ss[i] = True
                r2 = r2 + 1
        
        result = min(r1, r2)

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Runtime Error

Solution code:
def inorderReplace(S , N): 
    S = list(S)
    cnt = 0
    for i in range(N - 1) : 
        nowChar = S[i]
        nextChar = S[i + 1]
        if nowChar == "#" and nextChar == "." : 
            cnt += 1
            S[i + 1] = "#"
    return cnt

def preorderReplace(S , N) : 
    S = list(S)
    cnt = 0
    for i in reversed(range(1, N)) : 
        nowChar = S[i]
        prevChar = S[i - 1]
        if prevChar == "#" and nowChar == "." : 
            cnt += 1
            S[i - 1] = "."
    return cnt


cnt = inorderReplace(S , N)
cnt2 = preorderReplace(S , N)
print(min(cnt , cnt2))

Submission status: Runtime Error

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

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

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

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

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

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

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

ans = min(score1,score2)


print(ans)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N = int(input())
    S = str(input())

    ok_list = []
    for i in range(0, N+1):
        ok_list.append("."*i + "#" * (N-i))

    answer = N + 1

    for ok_pattern in ok_list:
        different_str_count = 0
        for i in range(0, len(ok_pattern)):
            if ok_pattern[i] != S[i]:
                different_str_count += 1
        if answer >= different_str_count:
            answer = different_str_count

    print(answer)

Submission status: Runtime Error

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

ans = 0
for i in range(n-2):
    if s[i]+s[i+1] == "#.":
        s.replace(s[i+1],"#")
        ans += 1
    else:
        continue
if s[-2]+s[-1] == "#.":
    s.replace(s[i+1],"#")
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
tmp = S.count('#.')
counter = 0
for i in range(tmp):
    count = S.find('#.') + 1
    while S[count] == '.':
        counter += 1
        count+= 1
print(counter)

Submission status: Runtime Error

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

count = 0
while '#.' in S:
    temp = S.replace('#.', '*')
    temp += temp.count('*')
    S = temp.replace('*', '..')
print(temp)

Submission status: Runtime Error

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

count = 0
sList = list(S)
bi = N
wi = -1

def funcCheck(li):
    s = li[0]
    for i in range(len(li)-1):
        if li[i+1] != s:
            break
    if len(set(li[i+1:])) <= 1:
        return True
    else:
        return False
    

for i in range(N):
    if funcCheck(sList[wi+1:bi]):
        break
    while True:
        bi -= 1
        if sList[bi] == ".":
            sList[bi] = "#"
            count += 1
            break
    if funcCheck(sList[wi+1:bi]):
        break
    while True:
        wi += 1
        if sList[wi] == "#":
            sList[wi] = "."
            count += 1
            break

print(count)

Submission status: Runtime Error

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

a=s.count("#")
b=s.count(".")
if a<b:
    if s[n]=="#":
        print(a-1)
    else:
        print(a)
else:
    if s[n]==".":
        print(b-1)
    else:
        print(b)

Submission status: Runtime Error

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

ans = 0

for i in range(len(s)-1):
	if(s[i] == "#" and s[i+1] == "."):
		if(i == 0):
			s[i] = "."
		else if(i > 0 and s[i-1] != "#"):
			s[i] = "."
		else:
			s[i+1] = "#"
		ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
if s.count('#') == 0:
    print('0')
    exit()
ssp = s.split('.')
num = s[s.find('#'):].count('.')
num = min(num,s.count('#') - ssp[-1])
print(num)

Submission status: Runtime Error

Solution code:
n=int(input())  #数値入力
s=input()

pat1  = min(s.count('.'), s.count('#'))

l = []
for i in range(n-1):
#     print(i)
    l.append(s[:i+1].count('#') + s[i+1:].count('.'))
pat2 = min(l)

print(min(pat1, pat2))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
c = 0
for i in range(N - 1, -1, -1):
    if S[i] == ".":
        c1 = i
        break
cc = 0
for i in range(N - 1, c1, -1):
    if S[i] == "#":
        cc += 1
a = S[:i + 1].count(".")
b = S[:i + 1].count("#")
ans = min(a, b, cc)
print(ans)

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:]
    else:
        s = s[:pos] + '##' + s[pos+2:]
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
K=int(input())
tmp=S[K-1]
out=[]
for i in range(N):
    if S[i]!=tmp:
        out.append("*")
    else:
        out.append(S[i])
ttt=""
for i in out:
    ttt="{}{}".format(ttt,i)
print(ttt)
N=input()

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
c = 0
for i in range(N - 1, -1, -1):
    if S[i] == ".":
        c1 = i
        break
cc = 0
for i in range(N - 1, c1, -1):
    if S[i] == "#":
        cc += 1
a = S[:i + 1].count(".")
b = S[:i + 1].count("#")
ans = min(a, b, c2)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])
    s = lines[1]

    return (n, s)


def solve(n, s):
    
    ss = []
    for c in s:
        if c == ".":
            ss.append(True)
        else:
            ss.append(False)

    len_ss = len(ss)
    result = 0
    if len_ss == 1:
        result = 0
    else:
        for i, d in enumerate(ss):
            if ss[i] is False and ss[i+1] is True:
                ss[i+1] = False
                result = result + 1




    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Runtime Error

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

count1 = s.count('.')
count2 = s.count('#')

index=0
while(s[index]=="."):
    index+=1
if(count1 < s[index:].count(".") and index!=n):
    print(s[index:].count("."))
else:
    print(min(count1, count2))

Submission status: Runtime Error

Solution code:

ソースコード 

Copy
Copy
N = int(input())
S = input()
 
le=N
 
ans = 0
for i in range(le-1):
  if S[i]=="#" and S[i+1]==".":
    ans += 1
    S = S[:i] + "#" + S[i+1:]
  
if 2*ans < N:
  print(ans)
 
else:
  print(le-ans-1)

Submission status: Runtime Error

Solution code:
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()
    
min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

for i in range(len(l)//2):
    m = black[i] + (white[-1] - white[i])
    min_num = min(m, min_num)

print(min_num)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
first = True
ans = 0
for i in range(N+1):
  if first:
    if S[i] == '#':
      first=False
  else:
    if S[i] == '.':
      ans += 1
print(ans)

Submission status: Runtime Error

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


black=0
white=0
for st in s:
  if st=="#":
    black=black+1
  else:
    white=white+1
change=0

if black>white:
  for i in range(n-1):
    if s[i]=="#" and s[i+1]==".":
      change=change+1
      s[i+1]="#"

else:
  for i in range(n-1):
    if s[i]=="#" and s[i+1]==".":
      change=change+1
      s[i]="."

print(change)

Submission status: Runtime Error

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

count1 = s.count('.')
count2 = s.count('#')

index=0
while(s[index]=="."):
    index+=1
if(count1 < s[index:].count(".")):
    print(s[index:].count("."))
else:
    print(min(count1, count2))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
S = input()
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):
    if S[j] == ".":
        dot_count += 1
print(min(sharp_count,dot_count))

Submission status: Runtime Error

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

ans = 0
for i in range(n-2):
    if s[i]+s[i+1] == "#.":
        if s[i+2] == "#":
            s.replace(s[i+1],"#")
            ans += 1
        if s[i+2] == ".":
            s.replace(s[i+1],".")
            ans += 1
if s[-2]+s[-1] == "#.":
    s.replace(s[i+1],"#")
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:

###
#main
if __name__ == "__main__":
    N = int(input())
    S = input()
    count = 0
    for t in S:
        if t == "#":
            keepColor = True
        if keepColor and t == ".":
            count += 1
    count2 = 0
    keepColor = False
    for t in S[::-1]:
        if t == ".":
            keepColor = True
        if keepColor and t == "#":
            count2 += 1
    print(min(count,count2))

Submission status: Runtime Error

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

ans = 0
for i in range(N-1):
    if i == 0:
        check1 = S[i]
        check2 = S[i+1]
        check3 = S[i+2]
        if check1 == '#' and check2 == '.':
            ans += 1
    elif i == N-2:
        check1 = S[i]
        check2 = S[i+1]
        if check1 == '#' and check2 == '.':
            ans += 1
    else:
        check1 = S[i-1]
        check2 = S[i]
        check3 = S[i+1]
        check4 = S[i+2]
        if check2 == '#' and check3 == '.':
            if not (check1 == '#' and check4 == '.'):
                ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
ans = 0
bflag = 0
for i, st in enumerate(s):
    if bflag == 1:
        if st == '.':
            ans += 1
        else:
            bflag = 0
    else:
        if st == '#':
            bflag = 1
wflag = 0
ans2 = 0
for i in range(1, N + 1):
    if wflag == 1:
        if s[-i] == '#':
            ans2 += 1
        else:
            wflag == 0:
    else:
        if s[-i] == '.':
            wflag == 1
print(min(ans, ans2))

Submission status: Runtime Error

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

count = 0
for i,char in enumerate(S):
  if (i < len(S)):
    if (char == "#"):
      if (S[i+1] == "."):
        count += 1
      
print(count)